question_id
stringlengths
6
6
content
stringlengths
1
27.2k
p00923
<H1><font color="#000">Problem J: </font><span>C(O|W|A*RD*|S)* CROSSWORD</span> Puzzle</H1> <p> The first crossword puzzle was published on December 21, 1913 by Arthur Wynne. To celebrate the centennial of his great-great-grandfather's invention, John "Coward" Wynne<sup>1</sup> was struggling to make crossword puzzles. He was such a coward that whenever he thought of a tricky clue for a word, he couldn’t stop worrying if people would blame him for choosing a bad clue that could never mean that word. At the end of the day, he cowardly chose boring clues, which made his puzzles less interesting. </p> <p> One day, he came up with a brilliant idea: puzzles in which word meanings do not matter, and yet interesting. He told his idea to his colleagues, who admitted that the idea was intriguing. They even named his puzzles "Coward's Crossword Puzzles" after his nickname. </p> <p> However, making a Coward's crossword puzzle was not easy. Even though he did not have to think about word meanings, it was not easy to check if a puzzle has one and only one set of answers. As the day of the centennial anniversary was approaching, John started worrying if he would not be able to make interesting ones in time. Let's help John by writing a program that solves Coward's crossword puzzles. </p> <p> Each puzzle consists of <var>h</var> &times; <var>w</var> cells along with <var>h</var> across clues and <var>w</var> down clues. The clues are regular expressions written in a pattern language whose BNF syntax is given as in the table below. </p> <pre> clue ::= "^" pattern "$" pattern ::= simple | pattern "|" simple simple ::= basic | simple basic basic ::= elementary | elementary "*" elementary ::= "." | "A" | "B" | ... | "Z" | "(" pattern ")" </pre> <center> <span> Table J.1. BNF syntax of the pattern language. </span> </center> </br> <p> The clues (as denoted by p and q below) match words (as denoted by s below) according to the following rules. </p> <ul> <li><span>^</span><var>p</var><span>$</span> matches <var>s</var> if <var>p</var> matches <var>s</var>.</li> <li><var>p</var><span>|</span><var>q</var> matches a string <var>s</var> if <var>p</var> and/or <var>q</var> matches <var>s</var>.</li> <li><var>pq</var> matches a string <var>s</var> if there exist <var>s<sub>1</sub></var> and <var>s<sub>2</sub></var> such that <var>s<sub>1</sub>s<sub>2</sub></var> = <var>s</var>, <var>p</var> matches <var>s<sub>1</sub></var>, and <var>q</var> matches <var>s<sub>2</sub></var>.</li> <li><var>p</var><span>*</span> matches a string <var>s</var> if <var>s</var> is empty, or there exist <var>s<sub>1</sub></var> and <var>s<sub>2</sub></var> such that <var>s<sub>1</sub>s<sub>2</sub></var> = <var>s</var>, <var>p</var> matches</li> <li><var>s<sub>1</sub></var>, and <var>p</var><span>*</span> matches <var>s<sub>2</sub></var>.</li> <li>Each of <span>A</span>, <span>B</span>, . . . , <span>Z</span> matches the respective letter itself.</li> <li><span>(</span><var>p</var><span>)</span> matches <var>s</var> if <var>p</var> matches <var>s</var>.</li> <li><span>.</span> is the shorthand of <span>(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)</span>.</li> </ul> <p> Below is an example of a Coward’s crossword puzzle with the answers filled in the cells. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_crosswordPuzzle" style="aling:center;width:240px"><br/> </center> <br/> <p> <b>Java Specific:</b> Submitted Java programs may not use classes in the java.util.regex package.<br/> <b>C++ Specific:</b> Submitted C++ programs may not use the std::regex class. </p> <H2>Input</H2> <p> The input consists of multiple datasets, each of which represents a puzzle given in the following format. </p> <pre> <var>h</var> <var>w</var> <var>p<sub>1</sub></var> <var>p<sub>2</sub></var> ... <var>p<sub>h</sub></var> <var>q<sub>1</sub></var> <var>q<sub>2</sub></var> ... <var>q<sub>2</sub></var> </pre> <p> Here, <var>h</var> and <var>w</var> represent the vertical and horizontal numbers of cells, respectively, where 2 &le; <var>h,w</var> &le; 4. The <var>p<sub>i</sub></var> and <var>q<sub>j</sub></var> are the across and down clues for the <var>i</var>-th row and <var>j</var>-th column, respectively. Any clue has no more than 512 characters. </p> <p> The last dataset is followed by a line of two zeros. You may assume that there are no more than 30 datasets in the input. </p> <H2>Output</H2> <p> For each dataset, when the puzzle has a unique set of answers, output it as <var>h</var> lines of <var>w</var> characters. When the puzzle has no set of answers, or more than one set of answers, output "<span>none</span>" or "<span>ambiguous</span>" without double quotations, respectively. </p> <H2>Sample Input</H2> <pre> 2 2 ^(C|I|T|Y)*<span>$</span> ^(C|O|P|S)*<span>$</span> ^(F|L|I|P)*<span>$</span> ^(B|A|C|K)*<span>$</span> 2 2 ^HE|LL|O*<span>$</span> ^(P|L|E|A|S|E)*<span>$</span> ^(H|L)*<span>$</span> ^EP|IP|EF<span>$</span> 4 4 ^LONG|TALL|S*ALLY<span>$</span> ^(R*EV*|OL*U(TIO)*N)*<span>$</span> ^(STRAWBERRY|F*I*E*L*D*S*|FOREVER)*<span>$</span> ^P.S.|I|LOVE|YOU<span>$</span> ^(RE|A|L)((L|OV*E)*)<span>$</span> ^(LUC*Y*|IN.THE.SKY)(WITH|DI*A*M*ON*D*S*)<span>$</span> ^(IVE*|GOT|A|F*E*E*L*I*N*G*)*<span>$</span> ^YEST*E*R*D*A*Y*<span>$</span> 2 3 ^(C|P)(OL|AS)<span>$</span> ^(LU|TO)(X|R)<span>$</span> ^CT|PL<span>$</span> ^OU|AO<span>$</span> ^SR|LX<span>$</span> 2 2 ^T*|(HI)|S*<span>$</span> ^SE|NT|EN|CE<span>$</span> ^IS<span>$</span> ^(F|A|L|S|E)*<span>$</span> 2 4 ^ARKA|BARB|COLU<span>$</span> ^NSAS|ADOS|MBIA<span>$</span> ^..<span>$</span> ^..<span>$</span> ^KA|RO|LI<span>$</span> ^AS|BA|US<span>$</span> 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> IC PC HE LP ALLY OUNE EDIS LOVE ambiguous none ARKA NSAS </pre> <h2>Notes</h2> <p> <sup>1</sup> All characters appearing in this problem, except for Arthur Wynne, are fictitious. Any resemblance to real persons, living or dead, is purely coincidental. </p>
p00470
<H1>通勀経路 </H1> <h2>問題</h2> <p> JOIさんが䜏むカナダのある郜垂は南北方向にたっすぐに䌞びる w 本の道路ず東西方向にたっすぐに䌞びる h 本の道路により碁盀の目の圢に区分けされおいる </p> <p> 南北方向の w 本の道路には西から順に 1, 2, ... , w の番号が付けられおいるたた東西方向の h 本の道路には南から順に 1, 2, ... , h の番号が付けられおいる西から i 番目の南北方向の道路ず南から j 番目の東西方向の道路が亀わる亀差点を (i, j) で衚す </p> <p> JOIさんは亀差点 (1, 1) の近くに䜏んでおり亀差点 (w, h) の近くの䌚瀟に車で通っおいる車は道路に沿っおのみ移動するこずができるJOIさんは通勀時間を短くするため東たたは北にのみ向かっお移動しお通勀しおいるたたこの郜垂では亀通事故を枛らすために次のような亀通芏則が蚭けられおいる </p> <ul> <li> 亀差点を曲がった車はその盎埌の亀差点で曲がるこずは出来ない </li> </ul> <p> すなわち亀差点で曲がったあずに1ブロックだけ進んで再び曲がるこずは蚱されないこのずきJOIさんの通勀経路は䜕通り考えられるだろうか </p> <p> w ず h が䞎えられたずきJOIさんの通勀経路の個数を 100000 で割った䜙りを出力するプログラムを䜜成せよ </p> <h2>入力</h2> <p> 入力は耇数のデヌタセットからなる各デヌタセットは1行からなり空癜を区切りずしお2個の敎数 w, h (2 &le; w &le; 100 2 &le; h &le; 100) が曞かれおいるw は南北方向の道路の本数 h は東西方向の道路の本数を衚す </p> <p> w, h がずもに 0 のずき入力の終了を瀺す.デヌタセットの数は 5 を超えない </p> <h2>出力</h2> <p> デヌタセットごずにJOIさんの通勀経路の個数を 100000 で割った䜙りを1行に出力する </p> <h2> 入出力䟋</h2> <h3>入力䟋</h3> <pre> 3 4 15 15 0 0 </pre> <h3>出力䟋</h3> <pre> 5 43688 </pre> <p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_2010-yo-t5-fig01"><br>1぀目の入力䟋におけるJOIさんの通勀経路 ( 5 通り) </p> <p> 1぀目の入力䟋においおJOIさんの通勀経路は図のように 5 通り考えられるしたがっお5を出力する </p> <p> 2぀目の入力䟋においおJOIさんの通勀経路は 143688 通り考えられるしたがっお143688 を 100000 で割った䜙りである 43688 を出力する </p> <div class="source"> <p class="source"> 䞊蚘問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p00020
<H1>Capitalize</H1> <p> Write a program which replace all the lower-case letters of a given text with the corresponding captital letters. </p> <H2>Input</H2> <p> A text including lower-case letters, periods, and space is given in a line. The number of characters in the text is less than or equal to 200. </p> <H2>Output</H2> <p> Print the converted text. </p> <H2>Sample Input</H2> <pre> this is a pen. </pre> <H2>Output for the Sample Input</H2> <pre> THIS IS A PEN. </pre>
p00535
<h2>砂の城 (Sandcastle)</h2> <h2> 問題</h2> <p> JOI 君は家族ずずもに海氎济に来たさんざん泳いで泳ぎ疲れた JOI 君は次は砂浜で砂の城を䜜っお遊んだしばらくしお砂遊びにも飜きるずJOI 君は城を攟眮しおたた海に泳ぎに向かった </p> <p> JOI 君が䜜った城は砂浜のうちのある長方圢の領域に含たれおいるこの長方圢の領域は東西南北にマス目状に区切られおいる各マスはJOI 君が䜜った城の䞀郚であるマス (以䞋「城マス」ず呌ぶ) かそうでないマス (以䞋「曎地マス」ず呌ぶ) のいずれかであるそれぞれの城マスには「匷床」ず呌ばれる 1 以䞊 9 以䞋の敎数が定たっおいる長方圢の領域の倖瞁郚すなわち倖偎ず接しおいるマスには城マスは存圚しない </p> <p> やがお朮が満ちおきお長方圢の領域にも波が抌し寄せおくるようになった波が 1 ぀抌し寄せおくるたびに城マスのうち次の条件を満たすものはすべお䞀斉に厩壊しお曎地マスに倉化する </p> <ul> <li>条件 呚囲の 8 マス (東西南北および北東北西南東南西方向に隣接するマス) にある曎地マスの数がそのマスの匷床の倀以䞊である </li> </ul> <p> 波が匕くずたもなく次の波が抌し寄せお来る </p> <p> 十分倚くの波が抌し寄せるず城がすべお厩れおしたうか䞈倫な郚分だけが残るかしお波が抌し寄せおきおも 1 ぀も城マスが厩壊しないような状態に萜ち着く1 ぀以䞊の城マスを厩壊させるような波が抌し寄せおくる回数を求めよ </p> <h2>入力</h2> <p> 入力は 1 + H 行からなる </p> <p> 1 行目には2 ぀の敎数 H, W (2 &le; H &le; 1000, 2 &le; W &le; 1000) が空癜を区切りずしお曞かれおいるこれは長方圢の領域が瞊 H 行暪 W 列の H &times; W 個のマスに区切られおいるこずを衚す長方圢の瞊方向は南北方向であり暪方向は東西方向である </p> <p> 続く H 行にはそれぞれ W 文字からなる文字列が曞かれおおり最初の波が抌し寄せおくる前の長方圢の領域の状態を衚すH 行のうちの i 行目の巊から j 番目の文字 (1 &le; i &le; H, 1 &le; j &le; W) は長方圢の領域の北から i 行目西から j 列目のマスが曎地マスである堎合は '.' (ピリオド) である城マスである堎合は '1', '2', ..., '9' のいずれかでありそのマスの匷床を衚す </p> <p> 長方圢の領域の倖瞁郚はすべお曎地マスであるすなわちすべおの入力においお1 行目たたは H 行目の文字ず各行の巊から 1 番目たたは W 番目の文字はすべお '.' である </p> <p> 䞎えられる入力デヌタのうち入力 1 では H &le; 50, W &le; 50 を満たす </p> <h2>出力</h2> <p> 1 ぀以䞊の城マスを厩壊させるような波が抌し寄せおくる回数を 1 行で出力せよ </p> <h2>入出力䟋</h2> <h3>入力䟋 1</h3> <pre> 5 6 ...... .939.. .3428. .9393. ...... </pre> <h3>出力䟋 1</h3> <pre> 3 </pre> <h3>入力䟋 2</h3> <pre> 10 10 .......... .99999999. .9.323239. .91444449. .91444449. .91444449. .91444449. .91232329. .99999999. .......... </pre> <h3>出力䟋 2</h3> <pre> 35 </pre> <p> 入出力䟋 1 においおは初めに抌し寄せる波で匷床 3 の城マスがすべお厩壊し<br> </p> <pre> ...... .9.9.. ..428. .9.9.. ...... </pre> <p> ずいう状態になる </p> <p> 次に抌し寄せおくる波では匷床 2 の城マスが厩壊し </p> <pre> ...... .9.9.. ..4.8. .9.9.. ...... </pre> <p> ずいう状態になる </p> <p> 次に抌し寄せおくる波では匷床 4 の城マスが厩壊し </p> <pre> ...... .9.9.. ....8. .9.9.. ...... </pre> <p> ずいう状態になる </p> <p> これ以降の波が城マスを厩すこずはないよっお答えは 3 である </p> <div class="source"> <p class="source"> 問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p00165
<H1>宝くじ</H1> <p> ある囜の王様は玠数ずギャンブルが倧奜きです。この囜の通貚の単䜍はプラむムずいいたす。2007 幎 11 月 1 日珟圚のプラむムのクロス円レヌトは 9973 ずちょうど玠数になっおいたので、王様は倧喜びです。この囜では 1/101 プラむムを1サブプラむムずする補助貚幣が䜿われおいたす。 </p> <p> この囜の政府は、囜家財政の安定、囜民の嚯楜、王様の趣味を同時に満足させるこずを目的に宝くじ振興公瀟を蚭立し、宝くじ事業を始めるこずにしたした。玠数が倧奜きな王様は、玠数が話題になればそれだけで満足しお、賞金をあげたくなりたす。そこで振興公瀟は次のような宝くじを考えたした。 </p> <ul> <li>くじには 0 から <var>MP</var> たでの䞀連の番号が぀けられおいる。<var>MP</var> はこの囜で知られおいる最倧の玠数で、毎月䞀日に官報で告瀺される。同時に、<var>MP</var> 以䞋のすべおの玠数も発衚される。それ以䞊倧きな玠数が発芋されおも、その月の間は、宝くじ振興公瀟を含む党おの公的な機関では、䞀日に発衚された<var>MP</var> を最倧の玠数ずしお扱う。2007 幎 11 月 1 日 には<var>MP</var> = 999983 (1000000 以䞋の最倧の玠数) が発衚された。</li> <li>宝くじの販売䟡栌は 1 サブプラむム。</li> <li>宝くじの抜遞では、圓たりくじの番号 <var>p</var> ず賞金算出のための数 <var>m</var> の組(<var>p</var>, <var>m</var>) が䜕組か遞ばれる。<var>p</var>, <var>m</var> はそれぞれ0 以䞊 <var>MP</var> 以䞋の敎数。</li> <li>この囜で知られおいる玠数の䞭で <var>p</var> - <var>m</var> 以䞊 <var>p</var> + <var>m</var> 以䞋のものが <var>X</var> 個あるずするず、抜遞結果(<var>p</var>, <var>m</var>) の賞金は、<var>X</var> プラむムずなる。</li> <li>抜遞結果 (<var>p</var>, <var>m</var>) の賞金 <var>X</var> プラむムは番号 <var>p</var> の宝くじを持っおいる圓遞者に支払われるが、<var>X</var> = 0 の堎合もあり、この堎合には圓遞者には賞金は支払われない。</li> <li>賞金のうち 1 プラむムは宝くじの売り䞊げから支出され、<var>X</var> - 1 プラむムは王様の内廷費から支出される王様が払っおくれる。<var>X</var> = 0 ならば宝くじの売り䞊げから 1 プラむムが内廷費に繰り入れられる。王様に察し支払われる</li> <li>ひず぀の番号 <var>p</var> が耇数の圓たりくじになるこずもある。この堎合にはそれぞれの抜遞結果(<var>p</var>, <var>m</var>) から算出される賞金の合蚈が圓遞者に支払われる。</li> </ul> <p> このくじでは圓たりくじを買った人は抜遞結果から関係する玠数を探し、その個数を数えるので、囜民の話題に玠数がよく出おきお王様はずおもご満悊です。宝くじ振興公瀟ずしおは圓たりくじ1本圓たり公瀟負担が 1 プラむム、販売䟡栌が 1 サブプラむムだから、圓たりくじの本数 <var>n</var> を、販売した宝くじ 101 本あたり 1 本以䞋ずなるようにすれば (すなわち、<var>n</var> &le; (販売した本数)/101 ずすれば) 赀字にはなりたせん。 </p> <!-- <p> 問題は内廷費からの支出額です。宝くじ振興公瀟の歎代の総裁は王様のご孊友で、みんな王様ず同様に玠数が倧奜きでした。圓たりくじに察する内廷費からの支出額を決める䌚議を楜しんでいたした。ずころが2007幎の人事異動でご孊友ではないお圹人が総裁に就任したした。䞍幞なこずにこの総裁は王様のこずは十分に尊敬しおいたすが、数孊が苊手で、玠数の話を聞くずすぐに鳥肌が立ちたす。そこであなたはこの䞍幞な新総裁のアシスタントずなっお、抜遞結果を入力ずしお、2007幎11月における宝くじ振興公瀟が王様に請求する賞金の額を出力するプログラムを䜜成しおください。ただし、抜遞結果の数 n は1以䞊1000000以䞋であり、請 求する賞金の額が負になるこずはないものずしたす。 </p> --> <p> 問題は内廷費からの支出額です。あなたの仕事は、抜遞結果を入力ずしお、2007 幎 11 月における宝くじ振興公瀟が王様に請求する賞金の額を出力するプログラムを䜜成するこずです。ただし、請求する賞金の額が負になるこずはないものずしたす。 </p> <p>泚意</p> <ul> <li>この囜における玠数の定矩も日本の孊校教育で孊習する内容ず同じです。即ち、玠数ずは 1 ず自分自身以倖の玄数を持たない自然数をいいたすなお、1 は玠数ではありたせん。</li> <li>我々は 1000003 が玠数であるこずを知っおいたすが、この囜では 2007 幎 11 月段階では知られおいたせん。そのため、999963 以䞊 1000003 以䞋の範囲にあるこの囜で知られおいる玠数は 999983 ず 999979 の 2 個しかありたせん。</li> </ul> <H2>Input</H2> <p> 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりはれロひず぀の行で瀺されたす。 各デヌタセットは以䞋の圢匏で䞎えられたす。 </p> <pre> <var>n</var> <var>p<sub>1</sub></var> <var>m<sub>1</sub></var> <var>p<sub>2</sub></var> <var>m<sub>2</sub></var> : <var>p<sub>n</sub></var> <var>m<sub>n</sub></var> </pre> <p> 行目に抜遞結果の数 <var>n</var> (1 &le; <var>n</var> &le; 1000000)、続く <var>n</var> 行に <var>i</var> 番目の抜遞結果の情報 <var>p<sub>i</sub></var>, <var>m<sub>i</sub></var> が空癜区切りで䞎えられたす。 </p> <p> デヌタセットの数は 20 を超えたせん。 </p> <H2>Output</H2> <p> デヌタセットごずに王様ぞの請求額をプラむム単䜍敎数で行に出力したす。 </p> <H2>Sample Input</H2> <pre> 4 5 0 9 1 3 10 11 3 1 999983 20 0 </pre> <H2>Output for the Sample Input</H2> <pre> 5 1 </pre>
p02158
<h1>Problem J: Rings</h1> <h2>Problem</h2> <p>ずある氎族通に䜏むむルカ君は、ゞャンプをしお$N$個のリングをくぐり抜けるずご耒矎がもらえたす。</p> <ul> <li>むルカ君は座暙$(0,0)$から飛び、$(T,0)$で着氎する。</li> <li>ゞャンプの軌道は攟物線である。</li> <li>$i$番目のリングは、ゞャンプの軌道が$(X_i,L_i)$ず$(X_i,H_i)$を結ぶ線分ず亀わるず、くぐり抜けたず刀定される。</li> <li>$1$回のゞャンプには初速ず同じだけの䜓力が必芁である。</li> </ul> <p>むルカ君は、必芁であれば䜕床でもゞャンプをするこずができたす。重力加速床ベクトルを$(0,-1)$ずしお、むルカ君が党おのリングを通り抜けるために必芁な䜓力の合蚈の最小倀を求めおください。ただし、摩擊や空気抵抗は無芖できるほど小さいずしたす。</p> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる。</p> <pre> $T$ $N$ $X_1$ $L_1$ $H_1$ $\vdots$ $X_N$ $L_N$ $H_N$ </pre> <p>たず$1$行に$T$ず$N$が䞎えられる。その埌$N$行に$i$番目のリングの䜍眮、$X_i$、$L_i$、$H_i$が䞎えられる。</p> <h2>Constraints</h2> <p>入力は以䞋の条件を満たす。</p> <ul> <li>入力はすべお敎数である。</li> <li>$1 \le X_i < T \le 10^6$</li> <li>$1 \le N \le 10^5$</li> <li>$1 \le L_i < H_i \le 10^6$</li> </ul> <h2>Output</h2> <p>答えを䞀行に出力する。絶察誀差たたは盞察誀差が$10^{-9}$以䞋の堎合正答ず刀定される。</p> <h2>Sample Input 1</h2> <pre> 100 5 50 1 5 50 5 10 50 20 30 50 40 60 50 61 1000000 </pre> <h2>Sample Output 1</h2> <pre> 48.6090201099 </pre> <p>点$(50,5)$を通るように飛ぶず、$1$番目ず$2$番目のリングを同時にくぐるこずができたす。</p> <h2>Sample Input 2</h2> <pre> 64 15 38 133177 927361 48 177920 668766 12 680425 790550 43 6853 384115 17 214954 723798 62 63843 153825 28 399349 482937 2 336136 367001 33 138008 733496 6 203462 911631 58 321974 527734 17 696940 781678 55 265874 507640 41 56037 880001 34 279422 528651 </pre> <h2>Sample Output 2</h2> <pre> 6087.909851326286 </pre>
p03319
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a sequence of length <var>N</var>: <var>A_1, A_2, ..., A_N</var>. Initially, this sequence is a permutation of <var>1, 2, ..., N</var>.</p> <p>On this sequence, Snuke can perform the following operation:</p> <ul> <li>Choose <var>K</var> consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements.</li> </ul> <p>Snuke would like to make all the elements in this sequence equal by repeating the operation above some number of times. Find the minimum number of operations required. It can be proved that, Under the constraints of this problem, this objective is always achievable.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq K \leq N \leq 100000</var></li> <li><var>A_1, A_2, ..., A_N</var> is a permutation of <var>1, 2, ..., N</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>K</var> <var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum number of operations required.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 3 2 3 1 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>One optimal strategy is as follows:</p> <ul> <li> <p>In the first operation, choose the first, second and third elements. The sequence <var>A</var> becomes <var>1, 1, 1, 4</var>.</p> </li> <li> <p>In the second operation, choose the second, third and fourth elements. The sequence <var>A</var> becomes <var>1, 1, 1, 1</var>.</p> </li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 3 1 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>8 3 7 3 1 8 4 6 2 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>4 </pre></section> </div> </span>
p01324
<h1><font color="#000">Problem D:</font> 無矛盟な単䜍系</h1> <pre> 京、垓、{犟予}、穣、溝、柗、正、茉、極、恒河沙、阿僧祇、那由他、䞍可思議、無量倧数 分、厘、毛、糞、応、埮、繊、沙、塵、埃、枺、挠、暡糊、逡巡、須臟、瞬息、匟指、刹那、六埳、虚空、枅浄、阿頌耶、阿摩矅、涅槃寂静 </pre> <p>これらが䜕か分かるだろうか。これらは党お10の环乗に぀けられた数詞である。</p> <pre> 京 = 10<sup>16</sup>, 垓 = 10<sup>20</sup>, {犟予} = 10<sup>24</sup>, ç©£ = 10<sup>28</sup>, 溝 = 10<sup>32</sup>, ... 分 = 10<sup>-1</sup>、厘 = 10<sup>-2</sup>、毛 = 10<sup>-3</sup>、糞 = 10<sup>-4</sup>、応 = 10<sup>-5</sup>, ...</pre> <p>ではこれらが実甚的に䜿われおいるのを芋たこずはあるだろうか無いのではなかろうか 過去の先人達が熟考の末にこれらの呜名を行ったにもかかわらず、これらの数詞が日の目を芋られないずはなんず勿䜓無いこずだろう。</p> <p>この問題は、コンテスト参加者の皆様にこれらの数詞を知っおもらうために䜜られたものである。以䞋に問題の抂芁を瀺す。</p> <pre>1 km = 10<sup>3</sup> m</pre> <p>䞊蚘のような単䜍間の関係が入力ずしお䞎えられる。この問題では、巊蟺における単䜍が右蟺における単䜍の10の环乗倍ずなっおいるような単䜍間の関係だけが䞎えられる。 単䜍間の関係が矛盟しおいるずは、䞎えられた関係から以䞋の関係が同時に成り立぀こずをいう。</p> <pre> 1 A = 10<sup>x</sup> B 1 A = 10<sup>y</sup> B </pre> <p> ただし、 x&ne;yであり、 AずBは任意の単䜍。 </p> <p>入力ずしお䞎えられた単䜍間の関係が矛盟しおいるかどうか刀定せよ。 なお、入力は簡易のため指数衚蚘で䞎えられる。 </p> <h2>Input</h2> <p>入力の䞀行目に、単䜍間の関係の個数を瀺す敎数 N (1&le; N &le; 100) が䞎えられる。</p> <p>続くN行に、単䜍間の関係が含たれる。 単䜍間の関係は以䞋のフォヌマットで䞎えられる。</p> <p>"1 A = 10^x B"</p> <p>A, B は単䜍を瀺す。AずBは盞異なっおおり、それぞれ空癜を含たないアルファベット小文字1〜16文字からなる。x は -100から100たでの敎数である。 "1 A = 10^x B" が定矩されたずき、 "1 B = 10^-x A" も暗黙のうちに定矩されおいるものずする。</p> <p> 任意の単䜍系のペアが2回以䞊定矩されるこずはない。 すなわち、"1 kilobyte = 10^3 byte", "1 kilobyte = 10^1 byte" のような関係が、同時に入力に含たれるこずはない。 同様に、"1 kilobyte = 10^3 byte", "1 byte = 10^-3 kilobyte" のような関係が、同時に入力に含たれるこずはない。 </p> <h2>Output</h2> <p>䞎えられた単䜍系が矛盟しおいなければ Yes を、 矛盟しおいれば No を出力せよ。 </p> <h2>Notes on Test Cases</h2> <p> 䞊蚘入力圢匏で耇数のデヌタセットが䞎えられたす。各デヌタセットに察しお䞊蚘出力圢匏で出力を行うプログラムを䜜成しお䞋さい。 </p> <p> N が 0 のずき入力の終わりを瀺したす。 </p> <!-- <h2>Sample Input 1</h2> <pre>3 1 km = 10^3 m 1 m = 10^2 cm 1 km = 10^5 cm </pre> <h2>Output for Sample Input 1</h2> <pre>Yes </pre> <h2>Sample Input 2</h2> <pre>7 1 kilometre = 10^3 metre 1 megametre = 10^3 kilometre 1 metre = 10^-6 megametre 1 terametre = 10^3 gigametre 1 petametre = 10^3 terametre 1 gigametre = 10^-6 petametre 1 metre = 10^-15 petametre </pre> <h2>Output for Sample Input 2</h2> <pre>Yes </pre> <h2>Sample Input 3</h2> <pre>4 1 a = 10^2 b 1 a = 10^3 c 1 b = 10^2 c 1 c = 10^1 d </pre> <h2>Output for Sample Input 3</h2> <pre>No </pre> <h2>Sample Input 4</h2> <pre>4 1 acm = 10^2 icpc 1 icpc = 10^3 utpc 1 utpc = 10^4 topcoder 1 topcoder = 10^-1 acm </pre> <h2>Output for Sample Input 4</h2> <pre>No </pre> --> <h2>Sample Input</h2> <pre> 3 1 km = 10^3 m 1 m = 10^2 cm 1 km = 10^5 cm 7 1 kilometre = 10^3 metre 1 megametre = 10^3 kilometre 1 metre = 10^-6 megametre 1 terametre = 10^3 gigametre 1 petametre = 10^3 terametre 1 gigametre = 10^-6 petametre 1 metre = 10^-15 petametre 4 1 a = 10^2 b 1 a = 10^3 c 1 b = 10^2 c 1 c = 10^1 d 4 1 acm = 10^2 icpc 1 icpc = 10^3 utpc 1 utpc = 10^4 topcoder 1 topcoder = 10^-1 acm 0 </pre> <h2>Output for Sample Input</h2> <pre> Yes Yes No No </pre>
p03749
<span class="lang-en"> <p>Score : <var>1600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Joisino has a bar of length <var>N</var>, which has <var>M</var> marks on it. The distance from the left end of the bar to the <var>i</var>-th mark is <var>X_i</var>.</p> <p>She will place several squares on this bar. Here, the following conditions must be met:</p> <ul> <li>Only squares with integral length sides can be placed.</li> <li>Each square must be placed so that its bottom side touches the bar.</li> <li>The bar must be completely covered by squares. That is, no square may stick out of the bar, and no part of the bar may be left uncovered.</li> <li>The boundary line of two squares may not be directly above a mark.</li> </ul> <div style="text-align: center;"> <img src="https://atcoder.jp/img/agc013/placing_example.jpg"> <p>Examples of arrangements that satisfy/violate the conditions</p> </img></div> <p>The <em>beauty</em> of an arrangement of squares is defined as the <strong>product</strong> of the areas of all the squares placed. Joisino is interested in the sum of the beauty over all possible arrangements that satisfy the conditions. Write a program to find it. Since it can be extremely large, print the sum modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All input values are integers.</li> <li><var>1 \leq N \leq 10^9</var></li> <li><var>0 \leq M \leq 10^5</var></li> <li><var>1 \leq X_1 &lt; X_2 &lt; ... &lt; X_{M-1} &lt; X_M \leq N-1</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>X_1</var> <var>X_2</var> <var>...</var> <var>X_{M-1}</var> <var>X_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the sum of the beauty over all possible arrangements that satisfy 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 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>13 </pre> <p>There are two possible arrangements:</p> <ul> <li>Place a square of side length <var>1</var> to the left, and place another square of side length <var>2</var> to the right</li> <li>Place a square of side length <var>3</var></li> </ul> <p>The sum of the beauty of these arrangements is <var>(1 \times 1 \times 2 \times 2) + (3 \times 3) = 13</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 2 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>66 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 9 1 2 3 4 5 6 7 8 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>100 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>1000000000 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>693316425 </pre></section> </div> </span>
p01774
<h2>C: Digital Clock / デゞタル時蚈</h2> <h3>物語</h3> <p>あいずにゃんは最近颚邪を匕いおしたったあたりのだるさにベットから出られない蟛そうにしおいる姿もたたかわいい</p> <p>しかし暇で暇で仕方がないあいずにゃんは枕䞋にあるデゞタル時蚈で遊ぶ方法を考え぀いた䞋の図のようなデゞタル時蚈の光っおいる棒の本数を毎秒毎秒ただひたすらに数えるのである</p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_HUPC2015_Digital"></img> <p>䜕時間かこの遊びを続けた頃あいずにゃんは時間が違っおいおも光っおいる棒の本数が等しい堎合があるこずに気づいた光っおいる棒の本数が等しい時間が䜕通りあるのか気になったあいずにゃんは看病䞭のあなたに数えおくれるようお願いしおきた</p> <p>ベッドから出られないあいずにゃんのためにあなたはプログラムを曞いお求めるこずにした</p> <h3>問題</h3> <p>幎月日および時分秒を衚瀺する䞊図のようなデゞタル時蚈がある光っおいる棒の本数がちょうど <var>N</var> 本になる幎月日時分秒が䜕通りあるか答えよただしデゞタル時蚈は䞀郚壊れおいるため絶察光らない棒が䜕箇所かある光らない棒によっお同じ衚瀺に芋える堎合でも衚瀺しようずした幎月日時分秒が異なる堎合は別に数えるこずに泚意せよ</p> <p>各数字の光る箇所は次の図に瀺す通りである</p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_HUPC2015_Digital_number"></img> <p> デゞタル時蚈は西暊を0詰め4桁0000幎〜9999幎月日時分秒をそれぞれ0詰め2桁で衚瀺する </p> <p> 月は1日から始たり4, 6, 9, 11月は30日たで1, 3, 5, 7, 8, 10, 12月は31日たでである2月は通垞28日たでだが閏幎には29日たでずなるここで閏幎ずは次のような幎である </p> <ol type="1"> <li> 西暊が400で割り切れる幎は閏幎である</li> <li> 西暊が400で割り切れないが100で割り切れる幎は閏幎ではない</li> <li> 西暊が100で割り切れないが4で割り切れる幎は閏幎である</li> <li> 西暊が4で割り切れない幎は閏幎ではない</li> </ol> <p>時間は0時から23時たで分は0分から59分たで秒は0秒から59秒たでである閏秒に関しおは考えなくおよい</p> <h3>入力圢匏</h3> <p>1行目に光っおいる棒の本数 <var>N</var> (<var>0 &le; N &le; 98</var>) が䞎えられる</p> <p>2行目に壊れお光らない箇所の個数 <var>K</var> (<var>0 &le; K &le; 98</var>) が䞎えられ続いお <var>K</var> 行に壊れおいる箇所の情報が䞎えられる<var>K</var> 行のうち <var>i</var> 行目には<var>i</var> 番目の壊れおいる棒の桁 <var>p_i</var> (<var>0 &le; p_i &le; 13</var>) ず䜍眮 <var>q_i</var> (<var>0 &le; q_i &le; 6</var>) が空癜区切りで䞎えられる</p> <p>桁ずは次の図のようなデゞタル時蚈の各数字に割り圓おられたIDであり䞊䜍の数字から順に0から13たでを割り圓おた番号のこずである</p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_HUPC2015_Digital_num_id"></img> <p>たた棒の䜍眮ずは次の図のような各数字䞭における棒のIDであり䞊の棒から順に0から6たでの数字を割り圓おた番号のこずである</p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_HUPC2015_Digital_bar_id"></img> <h3>出力圢匏</h3> <p>光っおいる棒の本数がちょうど <var>N</var> 本になる幎月日時分秒の総数を1行に出力せよ</p> <h3>入力䟋1</h3> <pre> 28 0 </pre> <h3>出力䟋1</h3> <pre>1</pre> <p>1111幎11月11日11時11分11秒の1通りである</p> <h3>入力䟋2</h3> <pre> 28 1 2 0 </pre> <h3>出力䟋2</h3> <pre>2</pre> <p>1171幎11月11日11時11分11秒 ず 1111幎11月11日11時11分11秒 の2通りである</p> <h3>入力䟋3</h3> <pre> 98 1 3 0 </pre> <h3>出力䟋3</h3> <pre>0</pre> <h3>入力䟋4</h3> <pre> 60 1 3 0 </pre> <h3>出力䟋4</h3> <pre>13362470370</pre>
p00866
<H1><font color="#000">Problem C:</font> Stopped Watches</H1> <p> In the middle of Tyrrhenian Sea, there is a small volcanic island called Chronus. The island is now uninhabited but it used to be a civilized island. Some historical records imply that the island was annihilated by an eruption of a volcano about 800 years ago and that most of the people in the island were killed by pyroclastic flows caused by the volcanic activity. In 2003, a European team of archaeologists launched an excavation project in Chronus Island. Since then, the project has provided many significant historic insights. In particular the discovery made in the summer of 2008 astonished the world: the project team excavated several mechanical watches worn by the victims of the disaster. This indicates that people in Chronus Island had such a highly advanced manufacturing technology. </p> <p> Shortly after the excavation of the watches, archaeologists in the team tried to identify what time of the day the disaster happened, but it was not successful due to several difficulties. First, the extraordinary heat of pyroclastic flows severely damaged the watches and took away the letters and numbers printed on them. Second, every watch has a perfect round form and one cannot tell where the top of the watch is. Lastly, though every watch has three hands, they have a completely identical look and therefore one cannot tell which is the hour, the minute, or the second (It is a mystery how the people in Chronus Island were distinguishing the three hands. Some archaeologists guess that the hands might be painted with different colors, but this is only a hypothesis, as the paint was lost by the heat. ). This means that we cannot decide the time indicated by a watch uniquely; there can be a number of candidates. We have to consider different rotations of the watch. Furthermore, since there are several possible interpretations of hands, we have also to consider all the permutations of hands. </p> <p> You are an information archaeologist invited to the project team and are asked to induce the most plausible time interval within which the disaster happened, from the set of excavated watches. </p> <p> In what follows, we express a time modulo 12 hours. We write a time by the notation <i>hh</i>:<i>mm</i>:<i>ss</i>, where <i>hh</i>, <i>mm</i>, and <i>ss</i> stand for the hour (<i>hh</i> = 00, 01, 02, . . . , 11), the minute (<i>mm</i> = 00, 01, 02, . . . , 59), and the second (<i>ss</i> = 00, 01, 02, . . . , 59), respectively. The time starts from 00:00:00 and counts up every second 00:00:00, 00:00:01, 00:00:02, . . ., but it reverts to 00:00:00 every 12 hours. </p> <p> The watches in Chronus Island obey the following conventions of modern analog watches. </p> <ul> <li>A watch has three hands, i.e. the hour hand, the minute hand, and the second hand, though they look identical as mentioned above.</li> <li>Every hand ticks 6 degrees clockwise in a discrete manner. That is, no hand stays between ticks, and each hand returns to the same position every 60 ticks.</li> <li>The second hand ticks every second.</li> <li>The minute hand ticks every 60 seconds.</li> <li>The hour hand ticks every 12 minutes.</li> </ul> <p> At the time 00:00:00, all the three hands are located at the same position. </p> <p> Because people in Chronus Island were reasonably keen to keep their watches correct and pyroclastic flows spread over the island quite rapidly, it can be assumed that all the watches were stopped in a short interval of time. Therefore it is highly expected that the time the disaster happened is in the shortest time interval within which all the excavated watches have at least one candidate time. </p> <p> You must calculate the shortest time interval and report it to the project team. </p> <H2>Input</H2> <p> The input consists of multiple datasets, each of which is formatted as follows. </p> <p> <i>n</i><br> <i>s<sub>1</sub> t<sub>1</sub> u<sub>1</sub></i><br> <i>s<sub>2</sub> t<sub>2</sub> u<sub>2</sub></i><br> .<br> .<br> .<br> <i>s<sub>n</sub> t<sub>n</sub> u<sub>n</sub></i><br> </p> <p> The first line contains a single integer <i>n</i> (2 &le; <i>n</i> &le; 10), representing the number of the watches. The three numbers <i>s<sub>i</sub></i> , <i>t<sub>i</sub></i> , <i>u<sub>i</sub></i> in each line are integers such that 0 &le; <i>s<sub>i</sub></i> ,<i>t<sub>i</sub></i> , <i>u<sub>i</sub></i> &le; 59 and they specify the positions of the three hands by the number of ticks relative to an arbitrarily chosen position. </p> <p> Note that the positions of the hands of a watch can be expressed in many different ways. For example, if a watch was stopped at the time 11:55:03, the positions of hands can be expressed differently by rotating the watch arbitrarily (e.g. 59 55 3, 0 56 4, 1 57 5, etc.) and as well by permuting the hour, minute, and second hands arbitrarily (e.g. 55 59 3, 55 3 59, 3 55 59, etc.). </p> <p> The end of the input is indicated by a line containing a single zero. </p> <H2>Output</H2> <p> For each dataset, output the shortest time interval within which all the watches given in the dataset have at least one candidate time. The output must be written in a single line in the following format for each dataset. </p> <p> <i>hh</i>:<i>mm</i>:<i>ss</i> <i>h'h'</i>:<i>m'm'</i>:<i>s's'</i> </p> <p> Each line contains a pair of times <i>hh</i>:<i>mm</i>:<i>ss</i> and, <i>h'h'</i>:<i>m'm'</i>:<i>s's'</i> indicating that the shortest interval begins at hh:mm:ss and ends at <i>h'h'</i>:<i>m'm'</i>:<i>s's'</i> inclusive. The beginning time and the ending time are separated by a single space and each of them should consist of hour, minute, and second in two digits separated by colons. No extra characters should appear in the output. </p> <p> In calculating the shortest interval, you can exploit the facts that every watch has at least one candidate time and that the shortest time interval contains 00:00:00 only if the interval starts from 00:00:00 (i.e. the shortest interval terminates before the time reverts to 00:00:00). </p> <p> If there is more than one time interval that gives the shortest, output the one that first comes after 00:00:00 inclusive. </p> <H2>Sample Input</H2> <pre> 3 8 8 18 32 32 32 57 2 57 5 49 3 49 7 30 44 27 21 21 33 56 56 21 46 4 3 45 52 28 36 26 36 20 55 50 10 33 8 39 50 57 43 35 21 12 21 17 11 16 21 58 45 40 53 45 30 53 39 1 8 55 48 30 7 48 15 0 </pre> <H2>Output for the Sample Input</H2> <pre> 00:00:00 00:00:10 06:14:56 06:32:09 07:27:37 07:32:02 05:17:40 05:21:03 </pre>
p03067
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are three houses on a number line: House <var>1</var>, <var>2</var> and <var>3</var>, with coordinates <var>A</var>, <var>B</var> and <var>C</var>, respectively. Print <code>Yes</code> if we pass the coordinate of House <var>3</var> on the straight way from House <var>1</var> to House <var>2</var> without making a detour, and print <code>No</code> otherwise.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>0\leq A,B,C\leq 100</var></li> <li><var>A</var>, <var>B</var> and <var>C</var> are distinct integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>A</var> <var>B</var> <var>C</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <code>Yes</code> if we pass the coordinate of House <var>3</var> on the straight way from House <var>1</var> to House <var>2</var> without making a detour, and print <code>No</code> otherwise.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 8 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes </pre> <p>We pass the coordinate <var>5</var> on the straight way from the house at coordinate <var>3</var> to the house at coordinate <var>8</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>7 3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>No </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 2 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>31 41 59 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>No </pre></section> </div> </span>
p03437
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given positive integers <var>X</var> and <var>Y</var>. If there exists a positive integer not greater than <var>10^{18}</var> that is a multiple of <var>X</var> but not a multiple of <var>Y</var>, choose one such integer and print it. If it does not exist, print <var>-1</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ X,Y ≀ 10^9</var></li> <li><var>X</var> and <var>Y</var> are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>X</var> <var>Y</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print a positive integer not greater than <var>10^{18}</var> that is a multiple of <var>X</var> but not a multiple of <var>Y</var>, or print <var>-1</var> if it does not exist.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>8 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>16 </pre> <p>For example, <var>16</var> is a multiple of <var>8</var> but not a multiple of <var>6</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 </pre> <p>A multiple of <var>3</var> is a multiple of <var>3</var>.</p></section> </div> </span>
p01959
<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> Revenge of the Broken Door </H1> <p> The JAG Kingdom consists of $N$ cities and $M$ bidirectional roads. The $i$-th road ($u_i, v_i, c_i$) connects the city $u_i$ and the city $v_i$ with the length $c_i$. One day, you, a citizen of the JAG Kingdom, decided to go to the city $T$ from the city $S$. However, you know that one of the roads in the JAG Kingdom is currently under construction and you cannot pass the road. You don't know which road it is. You can know whether a road is under construction only when you are in either city connected by the road. </p> <p> Your task is to minimize the total length of the route in the worst case. You don't need to decide a route in advance of departure and you can choose where to go next at any time. If you cannot reach the city $T$ in the worst case, output '-1'. </p> <H2>Input</H2> <p> The input consists of a single test case formatted as follows. </p> <pre> $N$ $M$ $S$ $T$ $u_1$ $v_1$ $c_1$ : $u_M$ $v_M$ $c_M$ </pre> <p> The first line contains four integers $N, M, S,$ and $T$, where $N$ is the number of the cities ($2 \leq N \leq 100,000$), $M$ is the number of the bidirectional roads ($1 \leq M \leq 200,000$), $S$ is the city you start from ($1 \leq S \leq N$), and $T$ is the city you want to reach to ($1 \leq T \leq N, S \ne T$). The following $M$ lines represent road information: the $i$-th line of the $M$ lines consists of three integers $u_i, v_i, c_i,$ which means the $i$-th road connects the cities $u_i$ and $v_i$ ($1 \leq u_i, v_i \leq N, u_i \ne v_i$) with the length $c_i$ ($1 \leq c_i \leq 10^9$). You can assume that all the pairs of the cities are connected if no road is under construction. That is, there is at least one route from city $x$ to city $y$ with given roads, for all cities $x$ and $y$. It is also guaranteed that there are no multiple-edges, i.e., $\{u_i,v_i\} \ne \{u_j,v_j\}$ for all $1 \leq i < j \leq M$. </p> <H2>Output</H2> <p> Output the minimum total length of the route in the worst case. If you cannot reach the city $T$ in the worst case, output '-1'. </p> <H2>Sample Input 1</H2> <pre> 3 3 1 3 1 2 1 2 3 5 1 3 3 </pre> <H2>Output for Sample Input 1</H2> <pre> 6 </pre> <H2>Sample Input 2</H2> <pre> 4 4 1 4 1 2 1 2 4 1 1 3 1 3 4 1 </pre> <H2>Output for Sample Input 2</H2> <pre> 4 </pre> <H2>Sample Input 3</H2> <pre> 5 4 4 1 1 2 3 2 3 4 3 4 5 4 5 6 </pre> <H2>Output for Sample Input 3</H2> <pre> -1 </pre>
p03964
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>AtCoDeer the deer is seeing a quick report of election results on TV. Two candidates are standing for the election: Takahashi and Aoki. The report shows the ratio of the current numbers of votes the two candidates have obtained, but not the actual numbers of votes. AtCoDeer has checked the report <var>N</var> times, and when he checked it for the <var>i</var>-th <var>(1≩i≩N)</var> time, the ratio was <var>T_i:A_i</var>. It is known that each candidate had at least one vote when he checked the report for the first time.</p> <p>Find the minimum possible total number of votes obtained by the two candidates when he checked the report for the <var>N</var>-th time. It can be assumed that the number of votes obtained by each candidate never decreases.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≩N≩1000</var></li> <li><var>1≩T_i,A_i≩1000 (1≩i≩N)</var></li> <li><var>T_i</var> and <var>A_i</var> <var>(1≩i≩N)</var> are coprime.</li> <li>It is guaranteed that the correct answer is at most <var>10^{18}</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>T_1</var> <var>A_1</var> <var>T_2</var> <var>A_2</var> <var>:</var> <var>T_N</var> <var>A_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum possible total number of votes obtained by Takahashi and Aoki when AtCoDeer checked the report for the <var>N</var>-th time.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 3 1 1 3 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>10 </pre> <p>When the numbers of votes obtained by the two candidates change as <var>2,3 → 3,3 → 6,4</var>, the total number of votes at the end is <var>10</var>, which is the minimum possible number.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 1 1 1 1 1 5 1 100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>101 </pre> <p>It is possible that neither candidate obtained a vote between the moment when he checked the report, and the moment when he checked it for the next time.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 3 10 48 17 31 199 231 23 3 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>6930 </pre></section> </div> </span>
p02676
<span class="lang-en"> <p>Score: <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>We have a string <var>S</var> consisting of lowercase English letters.</p> <p>If the length of <var>S</var> is at most <var>K</var>, print <var>S</var> without change.</p> <p>If the length of <var>S</var> exceeds <var>K</var>, extract the first <var>K</var> characters in <var>S</var>, append <code>...</code> to the end of them, and print the result.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>K</var> is an integer between <var>1</var> and <var>100</var> (inclusive).</li> <li><var>S</var> is a string consisting of lowercase English letters.</li> <li>The length of <var>S</var> is between <var>1</var> and <var>100</var> (inclusive).</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p>Input is given from Standard Input in the following format:</p> <pre><var>K</var> <var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print a string as stated in Problem Statement.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>7 nikoandsolstice </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>nikoand... </pre> <p><code>nikoandsolstice</code> has a length of <var>15</var>, which exceeds <var>K=7</var>.</p> <p>We should extract the first <var>7</var> characters in this string, append <code>...</code> to the end of them, and print the result <code>nikoand...</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>40 ferelibenterhominesidquodvoluntcredunt </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>ferelibenterhominesidquodvoluntcredunt </pre> <p>The famous quote from Gaius Julius Caesar.</p></section> </div> </span>
p02226
<h2> test </h2> UnionFindバむナリ入力
p03821
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are an integer sequence <var>A_1,...,A_N</var> consisting of <var>N</var> terms, and <var>N</var> buttons. When the <var>i</var>-th <var>(1 ≩ i ≩ N)</var> button is pressed, the values of the <var>i</var> terms from the first through the <var>i</var>-th are all incremented by <var>1</var>.</p> <p>There is also another integer sequence <var>B_1,...,B_N</var>. Takahashi will push the buttons some number of times so that for every <var>i</var>, <var>A_i</var> will be a multiple of <var>B_i</var>.</p> <p>Find the minimum number of times Takahashi will press the buttons.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All input values are integers.</li> <li><var>1 ≩ N ≩ 10^5</var></li> <li><var>0 ≩ A_i ≩ 10^9(1 ≩ i ≩ N)</var></li> <li><var>1 ≩ B_i ≩ 10^9(1 ≩ i ≩ N)</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A_1</var> <var>B_1</var> : <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print an integer representing the minimum number of times Takahashi will press the buttons.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 5 2 7 9 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>7 </pre> <p>Press the first button twice, the second button twice and the third button three times.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>7 3 1 4 1 5 9 2 6 5 3 5 8 9 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>22 </pre></section> </div> </span>
p02733
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a chocolate bar partitioned into <var>H</var> horizontal rows and <var>W</var> vertical columns of squares.</p> <p>The square <var>(i, j)</var> at the <var>i</var>-th row from the top and the <var>j</var>-th column from the left is dark if <var>S_{i,j}</var> is <code>0</code>, and white if <var>S_{i,j}</var> is <code>1</code>.</p> <p>We will cut the bar some number of times to divide it into some number of blocks. In each cut, we cut the whole bar by a line running along some boundaries of squares from end to end of the bar.</p> <p>How many times do we need to cut the bar so that every block after the cuts has <var>K</var> or less white squares?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq H \leq 10</var></li> <li><var>1 \leq W \leq 1000</var></li> <li><var>1 \leq K \leq H \times W</var></li> <li><var>S_{i,j}</var> is <code>0</code> or <code>1</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>H</var> <var>W</var> <var>K</var> <var>S_{1,1}S_{1,2}...S_{1,W}</var> <var>:</var> <var>S_{H,1}S_{H,2}...S_{H,W}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of minimum times the bar needs to be cut so that every block after the cuts has <var>K</var> or less white squares.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 5 4 11100 10001 00111 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>For example, cutting between the <var>1</var>-st and <var>2</var>-nd rows and between the <var>3</var>-rd and <var>4</var>-th columns - as shown in the figure to the left - works.</p> <p>Note that we cannot cut the bar in the ways shown in the two figures to the right.</p> <p><img alt="Figure" src="https://img.atcoder.jp/ghi/ac90dd542639c04402125403b1c319d7.png"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 5 8 11100 10001 00111 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>No cut is needed.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>4 10 4 1110010010 1000101110 0011101001 1101000111 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>3 </pre></section> </div> </span>
p02699
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>S</var> sheep and <var>W</var> wolves.</p> <p>If the number of wolves is greater than or equal to that of sheep, the wolves will attack the sheep.</p> <p>If the wolves will attack the sheep, print <code>unsafe</code>; otherwise, print <code>safe</code>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq S \leq 100</var></li> <li><var>1 \leq W \leq 100</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>S</var> <var>W</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If the wolves will attack the sheep, print <code>unsafe</code>; otherwise, print <code>safe</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>unsafe </pre> <p>There are four sheep and five wolves. The number of wolves is not less than that of sheep, so they will attack them.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>100 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>safe </pre> <p>Many a sheep drive away two wolves.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>unsafe </pre></section> </div> </span>
p02363
<script src="./IMAGE/varmath.js" charset="UTF-8"></script> <H1>All Pairs Shortest Path</H1> <br/> <H2>Input</H2> <p> An edge-weighted graph <var>G</var> (<var>V</var>, <var>E</var>). </p> <pre> |<var>V</var>| |<var>E</var>| <var>s<sub>0</sub></var> <var>t<sub>0</sub></var> <var>d<sub>0</sub></var> <var>s<sub>1</sub></var> <var>t<sub>1</sub></var> <var>d<sub>1</sub></var> : <var>s<sub>|E|-1</sub></var> <var>t<sub>|E|-1</sub></var> <var>d<sub>|E|-1</sub></var> </pre> <p> <var>|V|</var> is the number of vertices and <var>|E|</var> is the number of edges in <var>G</var>. The graph vertices are named with the numbers 0, 1,..., <var>|V|-1</var> respectively. </p> <p> <var>s<sub>i</sub></var> and <var>t<sub>i</sub></var> represent source and target vertices of <var>i</var>-th edge (directed) and <var>d<sub>i</sub></var> represents the cost of the <var>i</var>-th edge. </p> <H2>Output</H2> <p> If the graph contains a negative cycle (a cycle whose sum of edge costs is a negative value), print <pre> NEGATIVE CYCLE </pre> <p> in a line. </p> <p> Otherwise, print </p> <pre> <var>D<sub>0,0</sub></var> <var>D<sub>0,1</sub></var> ... <var>D<sub>0,|V|-1</sub></var> <var>D<sub>1,0</sub></var> <var>D<sub>1,1</sub></var> ... <var>D<sub>1,|V|-1</sub></var> : <var>D<sub>|V|-1,0</sub></var> <var>D<sub>1,1</sub></var> ... <var>D<sub>|V|-1,|V|-1</sub></var> </pre> <p> The output consists of <var>|V|</var> lines. For each <var>i</var>th line, print the cost of the shortest path from vertex <var>i</var> to each vertex <var>j</var> (<var>j = 0, 1, ... |V|-1</var>) respectively. If there is no path from vertex <var>i</var> to vertex <var>j</var>, print "<span>INF</span>". Print a space between the costs. </p> <H2>Constraints</H2> <ul> <li> 1 &le; <var>|V|</var> &le; 100</li> <li> 0 &le; <var>|E|</var> &le; 9900</li> <li> -2 &times 10<sup>7</sup> &le; <var>d<sub>i</sub></var> &le; 2 &times 10<sup>7</sup></li> <li> There are no parallel edges</li> <li> There are no self-loops</li> </ul> <H2>Sample Input 1</H2> <pre> 4 6 0 1 1 0 2 5 1 2 2 1 3 4 2 3 1 3 2 7 </pre> <H2>Sample Output 1</H2> <pre> 0 1 3 4 INF 0 2 3 INF INF 0 1 INF INF 7 0 </pre> <br/> <H2>Sample Input 2</H2> <pre> 4 6 0 1 1 0 2 -5 1 2 2 1 3 4 2 3 1 3 2 7 </pre> <H2>Sample Output 2</H2> <pre> 0 1 -5 -4 INF 0 2 3 INF INF 0 1 INF INF 7 0 </pre> <br/> <H2>Sample Input 3</H2> <pre> 4 6 0 1 1 0 2 5 1 2 2 1 3 4 2 3 1 3 2 -7 </pre> <H2>Sample Output 3</H2> <pre> NEGATIVE CYCLE </pre> <br/>
p03122
<span class="lang-en"> <p>Score : <var>1000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p><font color="red"><strong>Red bold fonts show the difference from C1.</strong></font></p> <p>There is an infinitely large triangular grid, as shown below. Each point with integer coordinates contains a lamp.</p> <p><img alt="" src="https://img.atcoder.jp/wtf19/f617c94527a62ed72fe7db12b6d1f6b0.png"/></p> <p>Initially, only the lamp at <font color="red"><strong><var>(X, Y)</var></strong></font> was on, and all other lamps were off. Then, Snuke performed the following operation zero or more times:</p> <ul> <li>Choose two integers <var>x</var> and <var>y</var>. Toggle (on to off, off to on) the following three lamps: <var>(x, y), (x, y+1), (x+1, y)</var>.</li> </ul> <p>After the operations, <var>N</var> lamps <var>(x_1, y_1), \cdots, (x_N, y_N)</var> are on, and all other lamps are off. Find <font color="red"><strong><var>X</var> and <var>Y</var></strong></font>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><font color="red"><strong><var>1 \leq N \leq 10^4</var></strong></font></li> <li><var>-10^{17} \leq x_i, y_i \leq 10^{17}</var></li> <li><var>(x_i, y_i)</var> are pairwise distinct.</li> <li>The input is consistent with the statement, and you can uniquely determine <font color="red"><strong><var>X</var> and <var>Y</var></strong></font>.</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 <font color="red"><strong><var>X</var> and <var>Y</var>, separated by a space</strong></font>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 -2 1 -2 2 0 1 1 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>-1 0 </pre> <p>The following picture shows one possible sequence of operations:</p> <p><img alt="" src="https://img.atcoder.jp/wtf19/cff6dc4d81e995e9300ccbaca5bf85de.png"/></p></section> </div> </span>
p03088
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given an integer <var>N</var>. Find the number of strings of length <var>N</var> that satisfy the following conditions, modulo <var>10^9+7</var>:</p> <ul> <li>The string does not contain characters other than <code>A</code>, <code>C</code>, <code>G</code> and <code>T</code>.</li> <li>The string does not contain <code>AGC</code> as a substring.</li> <li>The condition above cannot be violated by swapping two adjacent characters once.</li> </ul> </section> </div> <div class="part"> <section> <h3>Notes</h3><p>A substring of a string <var>T</var> is a string obtained by removing zero or more characters from the beginning and the end of <var>T</var>.</p> <p>For example, the substrings of <code>ATCODER</code> include <code>TCO</code>, <code>AT</code>, <code>CODER</code>, <code>ATCODER</code> and <code></code> (the empty string), but not <code>AC</code>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>3 \leq N \leq 100</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of strings of length <var>N</var> that satisfy the following conditions, 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>61 </pre> <p>There are <var>4^3 = 64</var> strings of length <var>3</var> that do not contain characters other than <code>A</code>, <code>C</code>, <code>G</code> and <code>T</code>. Among them, only <code>AGC</code>, <code>ACG</code> and <code>GAC</code> violate the condition, so the answer is <var>64 - 3 = 61</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>230 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>388130742 </pre> <p>Be sure to print the number of strings modulo <var>10^9+7</var>.</p></section> </div> </span>
p03572
<span class="lang-en"> <p>Score : <var>1800</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Three men, A, B and C, are eating sushi together. Initially, there are <var>N</var> pieces of sushi, numbered <var>1</var> through <var>N</var>. Here, <var>N</var> is a multiple of <var>3</var>.</p> <p>Each of the three has likes and dislikes in sushi. A's preference is represented by <var>(a_1,\ ...,\ a_N)</var>, a permutation of integers from <var>1</var> to <var>N</var>. For each <var>i</var> (<var>1 \leq i \leq N</var>), A's <var>i</var>-th favorite sushi is Sushi <var>a_i</var>. Similarly, B's and C's preferences are represented by <var>(b_1,\ ...,\ b_N)</var> and <var>(c_1,\ ...,\ c_N)</var>, permutations of integers from <var>1</var> to <var>N</var>.</p> <p>The three repeats the following action until all pieces of sushi are consumed or a fight brakes out (described later):</p> <ul> <li>Each of the three A, B and C finds his most favorite piece of sushi among the remaining pieces. Let these pieces be Sushi <var>x</var>, <var>y</var> and <var>z</var>, respectively. If <var>x</var>, <var>y</var> and <var>z</var> are all different, A, B and C eats Sushi <var>x</var>, <var>y</var> and <var>z</var>, respectively. Otherwise, a fight brakes out.</li> </ul> <p>You are given A's and B's preferences, <var>(a_1,\ ...,\ a_N)</var> and <var>(b_1,\ ...,\ b_N)</var>. How many preferences of C, <var>(c_1,\ ...,\ c_N)</var>, leads to all the pieces of sushi being consumed without a fight? Find the count modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>3 \leq N \leq 399</var></li> <li><var>N</var> is a multiple of <var>3</var>.</li> <li><var>(a_1,\ ...,\ a_N)</var> and <var>(b_1,\ ...,\ b_N)</var> are permutations of integers from <var>1</var> to <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>a_1</var> <var>...</var> <var>a_N</var> <var>b_1</var> <var>...</var> <var>b_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the preferences of C that leads to all the pieces of sushi being consumed without a fight, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 2 3 2 3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>The answer is two, <var>(c_1,\ c_2,\ c_3) = (3,\ 1,\ 2),\ (3,\ 2,\ 1)</var>. In both cases, A, B and C will eat Sushi <var>1</var>, <var>2</var> and <var>3</var>, respectively, and there will be no more sushi.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 1 2 3 1 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>Regardless of what permutation <var>(c_1,\ c_2,\ c_3)</var> is, A and B will try to eat Sushi <var>1</var>, resulting in a fight.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>6 1 2 3 4 5 6 2 1 4 3 6 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>80 </pre> <p>For example, if <var>(c_1,\ c_2,\ c_3,\ c_4,\ c_5,\ c_6) = (5,\ 1,\ 2,\ 6,\ 3,\ 4)</var>, A, B and C will first eat Sushi <var>1</var>, <var>2</var> and <var>5</var>, respectively, then they will eat Sushi <var>3</var>, <var>4</var> and <var>6</var>, respectively, and there will be no more sushi.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>6 1 2 3 4 5 6 6 5 4 3 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>160 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 5</h3><pre>9 4 5 6 7 8 9 1 2 3 7 8 9 1 2 3 4 5 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>33600 </pre></section> </div> </span>
p00077
<H1>ランレングス</H1> <p> 文字列が連続した堎合、ある芏則で文字を眮き換え文字列を短くするこずができたす。たずえば、AAAA ずいう文字列の堎合、@4A ず衚珟すれば 1 文字分圧瞮されたす。この芏則で圧瞮された文字列を入力しおもずの文字列に埩元するプログラムを䜜成しおください。ただし、埩元した文字列に文字は出珟しないものずしたす。 </p> <p> たた、原文の文字列は英倧文字、英小文字、数字、蚘号であり 100 文字以内、連続する文字は 9 文字以内です。 </p> <H2>入力</H2> <p>耇数の文字列が䞎えられたす。行に぀の文字列が䞎えられたす。文字列の数は 50 を超えたせん。</p> <H2>出力</H2> <p>文字列ごずに、各文字に察しお埩元した文字列を行に出力しお䞋さい。 </p> <H2>Sample Input</H2> <pre> ab@5C1@8050 @99+1=1@90 </pre> <H2>Output for the Sample Input</H2> <pre> abCCCCC10000000050 999999999+1=1000000000 </pre>
p00427
<H1></H1> <p> 次のようなゲヌムを考える 1 から n たでの数が 1 ぀ず぀曞かれた n 枚のカヌドが k 組あるこれら kn 枚のカヌドをよくシャッフルよく切るこずしお k 枚ず぀の山を䜜り暪䞀列に䞊べるこのようにしおできる n 個の山の巊から i 番目のk 枚のカヌドの山を「山 i 」ず呌ぶこずにする </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2006-yo-t5-fig_base"> </center> <br> <p> ゲヌムは山 1 から始める山の䞀番䞊のカヌド 1 枚を匕き匕いたカヌドは元の山に戻さないそのカヌドに曞かれおいた数が i だった堎合には山 i の䞀番䞊のカヌド 1 枚を匕くこのようにしお匕いたカヌドに曞かれおいた数を番号ずする山の䞀番䞊のカヌド 1 枚を匕くこずを繰り返しすべおの山にカヌドが無くなれば成功であるただカヌドが残っおいる山があるのに次にカヌドを匕くべき山が無くなっおいた堎合は倱敗である </p> <p>  途䞭で倱敗した堎合にはそのたた倱敗で終了するかたたは残ったカヌドの山をそのたた山の番号もそのたたにしおゲヌムを再開するゲヌムを再開する堎合は最初に匕くカヌドはカヌドが残っおいる山のうちの䞀番巊の山からずするその山の䞀番䞊のカヌドが最初に匕かれるカヌドずなる再開埌も再開前ず同様の方法でゲヌムを進めすべおの山にカヌドが無くなれば成功でありただカヌドが残っおいる山があるのに次にカヌドを匕くべき山が無くなった堎合は倱敗である </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2006-yo-t5-fig_sample"> </center> <br> <p> このようなゲヌムの再開を最倧 m 回たで行うものずするただしm は 0 か 1 である぀たり 1 回も再開しないか 1 回だけ再開するかのいずれかであるゲヌム開始前のシャッフルの仕方によりカヌドの初期配眮は異なる圓然カヌドの初期配眮により再開せずに成功するこずもあれば再開しお成功するこずも再開しお倱敗するこずもある十分シャッフルしおいるのでどの初期配眮も党お同じ確率で珟れるものず考えるこずにしお再開が m 回以内で成功する確率 p を求めたいこの確率 p を小数で衚し小数第 r 䜍たで求めお出力するプログラムを䜜りなさいただし次の条件を満たすように出力するこず. </p> <ul> <li> 十分倧きい正敎数 K を取るず p×10K が 敎数ずなる堎合 小数郚は途䞭から 0 が続くがその 0 も出力するこず 䟋えば p = 3/8 = 0.375 の堎合 r = 5 なら 0.37500 ず出力し r = 2 なら 0.37 ず出力する p = 1.0 の堎合も同様に 䟋えば r = 3 なら 1.000 ず出力するこず</li> <li> 䟋えば 0.150000
 は埪環小数 0.1499999
 ずしお衚すこずもできるが このような堎合 前者の衚し方を甚いる </li> </ul> <p> 入力ファむルの 1 行目には敎数 nkmr がこの順に空癜を区切り文字ずしお曞いおある 1 ≩ n ≩ 10000 1 ≩ k ≩ 100 m = 0 たたは m = 1 1 ≩ r ≩ 10000 である </p> <!-- <p>  アップロヌドする出力ファむルにおいおは指定通りに出力した p の埌に改行を入れるこず </p> --> <table style="margin-bottom: 28px; margin-left: 28px; margin-right: 0px;"> <tr> <th width="150" align="left">入力䟋</th> <th width="150" align="left">入力䟋</th> <th width="150" align="left">入力䟋</th> </tr> <tr><td></td><td></td></tr> <tr><td>2 1 0 5</td><td>3 1 1 3</td><td>2 2 1 3</td><td></td></tr> <tr> <td> </td> </tr> <tr> <th width="150" align="left">出力䟋</th> <th width="150" align="left">出力䟋</th> <th width="150" align="left">出力䟋</th> </tr> <tr><td>0.50000</td><td>0.833</td><td>1.000</td><td></td></tr> </table> <h3>入力</h3> <p> 入力は耇数のデヌタセットからなるn, k, m, r がすべお 0 のずき入力が終了するデヌタセットの数は 5 を超えない </p> <h3>出力</h3> <p> デヌタセットごずに、指定通りに p を行に出力する </p> <H2>入力䟋</H2> <pre> 2 1 0 5 3 1 1 3 2 2 1 3 0 0 0 0 </pre> <H2>出力䟋</H2> <pre> 0.50000 0.833 1.000 </pre> <p> 各デヌタセットに぀いお指定通りに出力した p の埌に改行を入れるこず </p> <div class="source"> <p class="source"> 䞊蚘問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p01666
<h2>K - encode/decode</h2> <p> 以䞋の条件を党お満たす文字列Tの事を「良い」文字列ず呌ぶこずにする <ul> <li>TはABCDEFGHIの9皮類の文字列からなる</li> <li>T䞊の連続する文字は次のグラフ䞊でも隣接しおいる </ul> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_KUPC2013_graph"> <p>「良い」文字列の䟋</p> <ul> <li>BEB</li> <li>ABCDCBEFGHI</li> </ul> <p>「良い」文字列ではない䟋</p> <ul> <li>AC(AずCは隣接しおいない)</li> <li>AABCD(同じ文字はグラフ䞊では隣接しおいないずみなす)</li> </ul> <p> 以䞋の条件を満たすような぀の関数,encodeずdecodeを実装せよ. </p> <ul> <li>任意の01列Sに察し,encode(S)は「良い」文字列である</li> <li>任意の01列Sに察し,decode(encode(S))=Sを満たす</li> </ul> <h2>入出力圢匏</h2> <p>この問題にはencodeフェヌズずdecodeフェヌズがあり, それぞれ独立にプログラムが実行される.</p> <p>encodeフェヌズのずき, 入力は以䞋の圢匏で䞎えられる.</p> <pre> encode <var>N</var> <var>S</var> </pre> <p> <var>N</var>は䞎えられる01列<var>S</var>の長さである. <var>S</var>はあなたがencodeするべき01列である. この時の,あなたが提出するプログラムの出力を<var>T</var>ずする. <var>T</var>が良い文字列でない堎合は䞍正解ずなり,decodeフェヌズは実行されない. decodeフェヌズのずき,入力は以䞋の圢匏で䞎えられる. </p> <pre> decode <var>M</var> <var>T</var> </pre> <p> <var>T</var>はencodeフェヌズにおけるあなたの出力である. <var>M</var>は文字列<var>T</var>の長さである. この時の,あなたが提出するプログラムの出力がencodeフェヌズにおけるSず䞀臎する堎合,正解ずなる </p> <h2>採点方匏</h2> <p>この問題では入力<var>S</var>に察する出力encode(S)の長さに応じお埗点が決たる.</p> <p>党おのテストケヌスに぀いお, |encode(S)| ≩ |S| + 10 を満たすずきこの問題に察する埗点が満点ずなる.</p> <p>たた, |encode(S)| ≩ 2×|S| + 10 を満たす堎合, この問題に察する埗点は50点ずなる.</p> <!-- <p>この問題では入力<var>S</var>に察する出力encode(S)の長さに応じお埗点が決たる.</p> <p>党おのテストケヌスに぀いお, |encode(S)| ≩ |S| + 10 を満たすずきこの問題に察する埗点は満点の1000点ずなる.</p> <p>たた, |encode(S)| ≩ 2×|S| + 10 を満たす堎合, この問題に察する埗点は50点ずなる.</p> --> <h2>制玄</h2> <ul> <li><var>1 &le; N &le; 300000</var> </li> </ul> <h2>入出力䟋</h2> <h3>encodeフェヌズ</h3> <p>入力</p> <pre> encode 6 001100 </pre> <p>出力</p> <pre> ABCBE </pre> <p>encodeフェヌズの終了埌あなたのプログラムは䞀旊終了し,次にdecodeフェヌズが開始する</p> <h3>decodeフェヌズ</h3> <p>入力</p> <pre> decode 5 ABCBE </pre> <p>出力</p> <pre> 001100 </pre>
p00974
<h3>What Goes Up Must Come Down</h3> <p> Several cards with numbers printed on them are lined up on the table. </p> <p> We'd like to change their order so that first some are in non-decreasing order of the numbers on them, and the rest are in non-increasing order. For example, (1, 2, 3, 2, 1), (1, 1, 3, 4, 5, 9, 2), and (5, 3, 1) are acceptable orders, but (8, 7, 9) and (5, 3, 5, 3) are not. </p> <p> To put it formally, with $n$ the number of cards and $b_i$ the number printed on the card at the $i$-th position ($1 \leq i \leq n$) after reordering, there should exist $k \in \{1, ... n\}$ such that ($b_i \leq b_{i+1} \forall _i \in \{1, ... k - 1\}$) and ($b_i \geq b_{i+1} \forall _i \in \{k, ..., n - 1\}$) hold. </p> <p> For reordering, the only operation allowed at a time is to swap the positions of an adjacent card pair. We want to know the minimum number of swaps required to complete the reorder. </p> <h3>Input</h3> <p> The input consists of a single test case of the following format. </p> <pre> $n$ $a_1$ ... $a_n$ </pre> <p> An integer $n$ in the first line is the number of cards ($1 \leq n \leq 100 000$). Integers $a_1$ through $a_n$ in the second line are the numbers printed on the cards, in the order of their original positions ($1 \leq a_i \leq 100 000$). </p> <h3>Output</h3> <p> Output in a line the minimum number of swaps required to reorder the cards as specified. </p> <h3>Sample Input 1</h3> <pre> 7 3 1 4 1 5 9 2 </pre> <h3> Sample Output 1</h3> <pre> 3 </pre> <h3>Sample Input 2</h3> <pre> 9 10 4 6 3 15 9 1 1 12 </pre> <h3>Sample Output 2</h3> <pre> 8 </pre> <h3>Sample Input 3</h3> <pre> 8 9 9 8 8 7 7 6 6 </pre> <h3>Sample Output 3</h3> <pre> 0 </pre> <h3>Sample Input 4</h3> <pre> 6 8 7 2 5 4 6 </pre> <h3>Sample Output 4</h3> <pre> 4 </pre>
p02949
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a directed graph with <var>N</var> vertices numbered <var>1</var> to <var>N</var> and <var>M</var> edges. The <var>i</var>-th edge is directed from Vertex <var>A_i</var> to Vertex <var>B_i</var>, and there are <var>C_i</var> coins placed along that edge. Additionally, there is a button on Vertex <var>N</var>.</p> <p>We will play a game on this graph. You start the game on Vertex <var>1</var> with zero coins, and head for Vertex <var>N</var> by traversing the edges while collecting coins. It takes one minute to traverse an edge, and you can collect the coins placed along the edge each time you traverse it. As usual in games, even if you traverse an edge once and collect the coins, the same number of coins will reappear next time you traverse that edge, which you can collect again.</p> <p>When you reach Vertex <var>N</var>, you can end the game by pressing the button. (You can also choose to leave Vertex <var>N</var> without pressing the button and continue traveling.) However, when you end the game, you will be asked to pay <var>T \times P</var> coins, where <var>T</var> is the number of minutes elapsed since the start of the game. If you have less than <var>T \times P</var> coins, you will have to pay all of your coins instead.</p> <p>Your score will be the number of coins you have after this payment. Determine if there exists a maximum value of the score that can be obtained. If the answer is yes, find that maximum value.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 2500</var></li> <li><var>1 \leq M \leq 5000</var></li> <li><var>1 \leq A_i, B_i \leq N</var></li> <li><var>1 \leq C_i \leq 10^5</var></li> <li><var>0 \leq P \leq 10^5</var></li> <li>All values in input are integers.</li> <li>Vertex <var>N</var> can be reached from Vertex <var>1</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>P</var> <var>A_1</var> <var>B_1</var> <var>C_1</var> <var>:</var> <var>A_M</var> <var>B_M</var> <var>C_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If there exists a maximum value of the score that can be obtained, print that maximum value; otherwise, print <code>-1</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 10 1 2 20 2 3 30 1 3 45 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>35 </pre> <p><img alt="Figure of the graph given in Sample Input 1" src="https://img.atcoder.jp/ghi/5cb074e2d7c3282da137ac4ab2fbc700.png"/></p> <p>There are two ways to travel from Vertex <var>1</var> to Vertex <var>3</var>:</p> <ul> <li>Vertex <var>1 \rightarrow 2 \rightarrow 3</var>: You collect <var>20 + 30 = 50</var> coins on the way. After two minutes from the start of the game, you press the button, pay <var>2 \times 10 = 20</var> coins, and you have <var>50 - 20 = 30</var> coins left.</li> <li>Vertex <var>1 \rightarrow 2</var>: You collect <var>45</var> coins on the way. After one minute from the start of the game, you press the button, pay <var>1 \times 10 = 10</var> coins, and you have <var>45 - 10 = 35</var> coins left.</li> </ul> <p>Thus, the maximum score that can be obtained is <var>35</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 2 10 1 2 100 2 2 100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 </pre> <p><img alt="Figure of the graph given in Sample Input 2" src="https://img.atcoder.jp/ghi/eb2188ad1e8189f963d233415fb293b6.png"/></p> <p>The edge extending from Vertex <var>1</var> takes you to Vertex <var>2</var>. If you then traverse the edge extending from Vertex <var>2</var> to itself <var>t</var> times and press the button, your score will be <var>90 + 90t</var>. Thus, you can infinitely increase your score, which means there is no maximum value of the score that can be obtained.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>4 5 10 1 2 1 1 4 1 3 4 1 2 2 100 3 3 100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre> <p><img alt="Figure of the graph given in Sample Input 3" src="https://img.atcoder.jp/ghi/217f7a224b80a05d8e25140c57e65ae7.png"/></p> <p>There is no way to travel from Vertex <var>1</var> to Vertex <var>4</var> other than traversing the edge leading from Vertex <var>1</var> to Vertex <var>4</var> directly. You will pick up one coin along this edge, but after being asked to paying <var>10</var> coins, your score will be <var>0</var>.</p> <p>Note that you can collect an infinite number of coins if you traverse the edge leading from Vertex <var>1</var> to Vertex <var>2</var>, but this is pointless since you can no longer reach Vertex <var>4</var> and end the game.</p></section> </div> </span>
p04034
<span class="lang-en"> <div class="part"> <section> <h3>Problem Statement</h3><p>We have <var>N</var> boxes, numbered <var>1</var> through <var>N</var>. At first, box <var>1</var> contains one red ball, and each of the other boxes contains one white ball.</p> <p>Snuke will perform the following <var>M</var> operations, one by one. In the <var>i</var>-th operation, he randomly picks one ball from box <var>x_i</var>, then he puts it into box <var>y_i</var>.</p> <p>Find the number of boxes that may contain the red ball after all operations are performed.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≀N≀10^5</var></li> <li><var>1≀M≀10^5</var></li> <li><var>1≀x_i,y_i≀N</var></li> <li><var>x_i≠y_i</var></li> <li>Just before the <var>i</var>-th operation is performed, box <var>x_i</var> contains at least <var>1</var> ball.</li> </ul> </section> </div> <hr> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>x_1</var> <var>y_1</var> <var>:</var> <var>x_M</var> <var>y_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of boxes that may contain the red ball after all operations are performed.</p> </section> </div> </div> <hr> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 1 2 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>Just after the first operation, box <var>1</var> is empty, box <var>2</var> contains one red ball and one white ball, and box <var>3</var> contains one white ball.</p> <p>Now, consider the second operation. If Snuke picks the red ball from box <var>2</var>, the red ball will go into box <var>3</var>. If he picks the white ball instead, the red ball will stay in box <var>2</var>. Thus, the number of boxes that may contain the red ball after all operations, is <var>2</var>.</p> </section> </div> <hr> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 3 1 2 2 3 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 </pre> <p>All balls will go into box <var>3</var>.</p> </section> </div> <hr> <div class="part"> <section> <h3>Sample Input 3</h3><pre>4 4 1 2 2 3 4 1 3 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>3 </pre></section> </div> </hr></hr></hr></hr></span>
p01236
<H1><font color="#000">Problem C:</font> Median Filter</H1> <p> The median filter is a nonlinear digital filter used to reduce noise in images, sounds, and other kinds of signals. It examines each sample of the input through a <i>window</i> and then emits the <i>median</i> of the samples in the win- dow. Roughly speaking, a window is an interval that contains a target sample and its preceding and succeeding samples; the median of a series of values is given by the middle value of the series arranged in ascending (or descending) order. </p> <p> Let us focus on a typical median filter for black-and-white raster images. The typical filter uses a 3 &times; 3 window, which contains a target pixel and the eight adjacent pixels. The filter examines each pixel in turn through this 3 &times; 3 window, and outputs the median of the nine pixel values, i.e. the fifth lowest (or highest) pixel value, to the corresponding pixel. We should note that the output is just given by the pixel value in majority for black-and- white images, since there are only two possible pixel values (i.e. black and white). The figure below illustrates how the filter works. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_medianFilter1"> <p><i><b>Note:</b> The colors of lightly-shaded pixels depend on outside of the region.</i></p> </center> <p> The edges of images need to be specially processed due to lack of the adjacent pixels. In this problem, we extends the original images by repeating pixels on the edges as shown in the figure below. In other words, the lacked pixels take the same values as the nearest available pixels in the original images. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_medianFilter2"> <p><i><b>Note:</b> The letters ‘a’ through ‘f’ indicate pixel values.</i></p> </center> <p> You are requested to write a program that reads images to which the filter is applied, then finds the original images containing the greatest and smallest number of black pixels among all possible ones, and reports the difference in the numbers of black pixels. </p> <H2>Input</H2> <p> The input contains a series of test cases. </p> <p> The first line of each test case contains two integers <i>W</i> and <i>H</i> (1 &le; <i>W</i>, <i>H</i> &le; 8), which indicates the width and height of the image respectively. Then <i>H</i> lines follow to describe the filtered image. The <i>i</i>-th line represents the <i>i</i>-th scan line and contains exactly <i>W</i> characters, each of which is either ‘#’ (representing black) or ‘.’ (representing white). </p> <p> The input is terminated by a line with two zeros. </p> <H2>Output</H2> <p> For each test case, print a line that contains the case number followed by the difference of black pixels. If there are no original images possible for the given filtered image, print “Impossible” instead. </p> <p> Obey the format as shown in the sample output. </p> <H2>Sample Input</H2> <pre> 5 5 ##### ##### ##### ##### ##### 4 4 #### #### #### #### 4 4 #... .... .... ...# 4 4 .#.# #.#. .#.# #.#. 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> Case 1: 10 Case 2: 6 Case 3: 2 Case 4: Impossible </pre>
p01723
<p>むクタ君の䜏む町には<var>N</var>個の塔がある。 それぞれの塔には0から<var>N&minus;1</var>たでの異なる番号が䞎えられおおり、番号<var>i</var>の塔を塔<var>i</var>ず呌ぶ。 奜奇心旺盛なむクタ君は<var>N</var>個の塔の高さに興味を持ち、それらの倧小関係を衚す衚<var>T</var>を䜜るこずにした。 <var>T</var>は<var>N &times; N</var>個の芁玠を持ち、各芁玠<var>T<sub>i, j</sub> (0 &le; i, j &le; N &minus; 1)</var>は次のように定矩される。 </p> <ul> <li> <var>T<sub>i, j</sub> = &minus;1</var> <var>&hArr;</var> 塔<var>i</var>の高さが塔<var>j</var>の高さより小さい </li> <li> <var>T<sub>i, j</sub> = 0</var> <var>&hArr;</var> 塔<var>i</var>の高さず塔<var>j</var>の高さが等しい </li> <li> <var>T<sub>i, j</sub> = 1</var> <var>&hArr;</var> 塔<var>i</var>の高さが塔<var>j</var>の高さより倧きい </li> </ul> <p>むクタ君は衚<var>T</var>を䜜成するための調査ずしお、2぀の塔を遞びそれらの高さを比范するずいうこずを<var>N&minus;1</var>回繰り返した。 </p> <p>むクタ君の調査に関しお以䞋のこずがわかっおいる。 </p> <ul> <li> <var>i</var>回目の比范<var>(1 &le; i &le; \ N &minus; 1)</var>で塔<var>a<sub>i</sub></var>, 塔<var>b<sub>i</sub></var>が遞ばれたずするず塔<var>a<sub>i</sub></var>の高さが塔<var>b<sub>i</sub></var>の高さより倧きかった。぀たり<var>T<sub>a<sub>i</sub>, b<sub>i</sub></sub> = 1</var>, <var>T<sub>b<sub>i</sub>, a<sub>i</sub></sub> = &minus;1</var>であった。 </li> <li> それぞれの塔は自分自身よりも倧きな塔ずは高々䞀回しか比范されおいない。 </li></ul> <p>残念ながらむクタ君の調査による情報だけで衚<var>T</var>の内容を䞀意に決めるこずができるずは限らない。 衚<var>T</var>がむクタ君の調査ず矛盟せず、<var>T</var>が定矩されるような塔の高さの組み合わせが存圚するずき<var>T</var>を正しい衚ず呌ぶこずにする。 正しい衚ずしお䜕通りのものが考えられるかを蚈算しおむクタ君に教えお欲しい。 </p> <p>ただし、比范された぀の塔の高さは互いに異なるがすべおの塔の高さが互いに異なるずは限らない。 </p> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>N</var><br><var>a<sub>1</sub></var> <var>b<sub>1</sub></var><br>...<br><var>a<sub>N&minus;1</sub></var> <var>b<sub>N&minus;1</sub></var> </pre> <p><var>N</var>は塔の数を衚す。 <var>a<sub>i</sub></var>, <var>b<sub>i</sub></var> (<var>1 &le; i &le; N &minus; 1</var>)は塔<var>a<sub>i</sub></var>が塔<var>b<sub>i</sub></var>より高いこずを衚す。 </p> <h3>Constraints</h3> <p>入力䞭の各倉数は以䞋の制玄を満たす。 </p> <ul> <li> <var>1 &le; N &le; 200</var> </li> <li> <var>0 &le; a<sub>i</sub>, b<sub>i</sub> < N</var> </li> <li> <var>a<sub>i</sub> &ne; b<sub>i</sub></var> </li> <li> 異なる塔が同じ高さであるこずもある。 </li> <li> むクタ君の調査結果自䜓が矛盟しおいるこずはなく、少なくずも1぀むクタ君の調査結果ず矛盟しない衚<var>T</var>が存圚する。 </li></ul> <h2>Output</h2> <p>考えられる正しい衚Tの個数の数を1,000,000,007で割ったあたりを出力せよ。 </p> <h2>Sample Input 1</h2> <pre>3 0 1 1 2 </pre> <h2>Output for the Sample Input 1</h2> <pre>1 </pre> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGSummerCamp2013Day3_Ordering_sample1" height="74" width="77"> <br> <ul><li> 正しい衚<var>T</var>は䞊図の1通りである。 </li></ul> <h2>Sample Input 2</h2> <pre>3 0 1 0 2 </pre> <h2>Output for the Sample Input 2</h2> <pre>3 </pre><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGSummerCamp2013Day3_Ordering_sample5" height="76" width="233"> <br> <ul><li> 正しい衚<var>T</var>は䞊図の3通りである。 </li></ul> <h2>Sample Input 3</h2> <pre>1 </pre> <h2>Output for the Sample Input 3</h2> <pre>1 </pre><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGSummerCamp2013Day3_Ordering_sample4" height="30" width="30"> <br> <ul><li> 正しい衚<var>T</var>は䞊図の1通りである。 </li></ul> <h2>Sample Input 4</h2> <pre>7 0 1 1 2 2 3 3 4 0 5 0 6 </pre> <h2>Output for the Sample Input 4</h2> <pre>91 </pre>
p00831
<H1><font color="#000">Problem E:</font> Confusing Login Names</H1> <p> Meikyokan University is very famous for its research and education in the area of computer science. This university has a computer center that has advanced and secure computing facilities including supercomputers and many personal computers connected to the Internet. </p> <p> One of the policies of the computer center is to let the students select their own login names. Unfortunately, students are apt to select similar login names, and troubles caused by mistakes in entering or specifying login names are relatively common. These troubles are a burden on the staff of the computer center. </p> <p> To avoid such troubles, Dr. Choei Takano, the chief manager of the computer center, decided to stamp out similar and confusing login names. To this end, Takano has to develop a program that detects confusing login names. </p> <p> Based on the following four operations on strings, the distance between two login names is determined as the minimum number of operations that transforms one login name to the other. </p> <ol> <li> Deleting a character at an arbitrary position.</li> <li> Inserting a character into an arbitrary position.</li> <li> Replacing a character at an arbitrary position with another character.</li> <li> Swapping two adjacent characters at an arbitrary position.</li> </ol> <p> For example, the distance between “<span>omura</span>” and “<span>murai</span>” is two, because the following sequence of operations transforms “<span>omura</span>” to “<span>murai</span>”. </p> <pre> delete ‘o’ insert ‘i’ omura --> mura --> murai </pre> <p> Another example is that the distance between “<span>akasan</span>” and “<span>kaason</span>” is also two. </p> <pre> swap ‘a’ and ‘k’ replace ‘a’ with ‘o’ akasan --> kaasan --> kaason </pre> <p> Takano decided that two login names with a small distance are confusing and thus must be avoided. </p> <p> Your job is to write a program that enumerates all the confusing pairs of login names. </p> <p> Beware that the rules may combine in subtle ways. For instance, the distance between “<span>ant</span>” and “<span>neat</span>” is two. </p> <pre> swap ‘a’ and ‘n’ insert ‘e’ ant --> nat --> neat </pre> <H2>Input</H2> <p> The input consists of multiple datasets. Each dataset is given in the following format. </p> <pre> <i>n</i> <i>d</i> <i>name</i><sub>1</sub> <i>name</i><sub>2</sub> ... <i>name<sub>n</sub></i> </pre> <p> The first integer <i>n</i> is the number of login names. Then comes a positive integer <i>d</i>. Two login names whose distance is less than or equal to <i>d</i> are deemed to be confusing. You may assume that 0 &lt; <i>n</i> &le; 200 and 0 &lt; <i>d</i> &le; 2. The <i>i</i>-th student’s login name is given by <i>name<sub>i</sub></i>, which is composed of only lowercase letters. Its length is less than 16. You can assume that there are no duplicates in <i>name<sub>i</sub></i> (1 &le; <i>i</i> &le; <i>n</i>). </p> <p> The end of the input is indicated by a line that solely contains a zero. </p> <H2>Output</H2> <p> For each dataset, your program should output all pairs of confusing login names, one pair per line, followed by the total number of confusing pairs in the dataset. </p> <p> In each pair, the two login names are to be separated only by a comma character (,), and the login name that is alphabetically preceding the other should appear first. The entire output of confusing pairs for each dataset must be sorted as follows. For two pairs “<i>w</i><sub>1</sub>,<i>w</i><sub>2</sub>” and “<i>w</i><sub>3</sub>,<i>w</i><sub>4</sub>”, if <i>w</i><sub>1</sub> alphabetically precedes <i>w</i><sub>3</sub>, or they are the same and <i>w</i><sub>2</sub> precedes <i>w</i><sub>4</sub>, then “<i>w</i><sub>1</sub>,<i>w</i><sub>2</sub>” must appear before “<i>w</i><sub>3</sub>,<i>w</i><sub>4</sub>”. </p> <H2>Sample Input</H2> <pre> 8 2 omura toshio raku tanaka imura yoshoi hayashi miura 3 1 tasaka nakata tanaka 1 1 foo 5 2 psqt abcdef abzdefa pqrst abdxcef 0 </pre> <H2>Output for the Sample Input</H2> <pre> imura,miura imura,omura miura,omura toshio,yoshoi 4 tanaka,tasaka 1 0 abcdef,abdxcef abcdef,abzdefa pqrst,psqt 3 </pre>
p01373
<!-- begin en only --> <!--<h3><U>Divide the Cake</U></h3>--> <!-- end en only --> <!-- begin ja only --> <h3><U>ケヌキ分割問題</U></h3> <!-- end ja only --> <div> <!-- begin en only --> <p> English text is not available in this practice contest. </p> <!-- end en only --> <!-- begin ja only --> <p> むコずピコはACM博士によっお開発された人工知胜を搭茉した双子のロボットである今日は二人の誕生日なので博士は二人のためにたくさんのむチゎがのったケヌキを甚意した </p> <p> ケヌキは暪幅 <i>W</i> ×奥行き <i>H</i> の長方圢の圢をしおいる 䟿宜䞊ケヌキは䞊から芋たずき(0,0)(<i>W</i> ,0)(<i>W</i> ,<i>H</i> )(0,<i>H</i> )を頂点ずする長方圢になるように眮かれおいるずする たた二人に均等になるようにちょうど2<i>N</i> 個のむチゎが乗っおいる </p> <p> せっかくなので博士は二人にケヌキを切らせるこずにした むコずピコは協力しおケヌキを切るためむコが包䞁の䞀端を蟺(0,0)-(0,<i>H</i> )の間におきピコはもう䞀端を蟺(<i>W</i> ,0)-(<i>W</i> ,<i>H</i> )の間においお同時に䞋に䞋ろすずいう方法をずるこずにした もちろん包䞁は盎線状なので遞んだ2点を通る盎線でケヌキは2぀に分かれる(図E-1) </p> <p style="text-align: center;"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PD2011E-1" width="50%"><br/> 図E-1 </p> <p> 博士は人工知胜を完成させたこずに満足し他の郚分を適圓に䜜ったために二人の腕のパヌツは䞍安定になっおしたった そのため蟺(0,0)-(0,<i>H</i> )(たたは蟺(<i>W</i> ,0)-(<i>W</i> ,<i>H</i> ))䞊の狙った堎所に眮こうずしおもどうしおもずれおしたうのである </p> <p> 二人はむチゎが奜きなのでできれば <i>N</i> 個ず぀に分けたいず考えおいる そこで<i>N</i> 個ず぀になるように切れない堎合は2点を遞びなおすこずにした 2<i>N</i> 個のむチゎの配眮によっおは半分ず぀に分けられなかったり分けられたずしおもずおも確率が䜎い堎合も考えられる このような堎合に䜕床も2点を遞びなおすのは䞍毛なのでたず初めに <i>N</i> 個ず぀に分かれるように切れる確率を蚈算するこずにした </p> <p> 二人の腕のパヌツは䞍安定なので動きを予想するのは難しい ずりあえず二人は「包䞁を眮く点は蟺(0,0)-(0,<i>H</i> )(たたは蟺(<i>W</i> ,0)-(<i>W</i> ,<i>H</i> ))䞊に必ず乗り眮かれる確率はどの二点も等しい」ずいう仮定を眮くこずにした たたむチゎの倧きさを考慮するのも面倒なので点ずみなすこずにした </p> <p> これは人工知胜の性胜を詊すいい機䌚である 博士ず同じ研究所に勀めおいるあなたに2<i>N</i> 個のむチゎの䜍眮を䞎えられたずきに 2人ず同じ仮定を甚いおむチゎが <i>N</i> 個ず぀に分かれる確率を蚈算するプログラムを䜜成する仕事が割り圓おられた </p> <!-- end ja only --> </div> <h3>Input</h3> <div> <!-- begin ja only --> <p> 入力は耇数のデヌタセットからなる入力の終わりは空癜で区切られた3぀のれロからなる行によっお䞎えられる各デヌタセットは1぀のケヌキに関する情報を衚しその圢匏は以䞋の通りである </p> <blockquote> <i>W</i> <i>H</i> <i>N</i><br/> <i>x<sub>1</sub></i> <i>y<sub>1</sub></i><br/> ...<br/> <i>x<sub>2N</sub></i> <i>y<sub>2N</sub></i><br/> </blockquote> <p> デヌタセットの最初の行は3぀の敎数 <i>W</i> ,<i>H</i> ,<i>N</i> からなりそれぞれケヌキの暪幅奥行きむチゎの個数/2を衚す 続く2<i>N</i> 行は2個の敎数からなりそれぞれむチゎのx座暙ずy座暙を衚す </p> <p> それぞれの倀は次の制玄を満たしおいる <ul> <li>1 &le; <i>W</i> ,<i>H</i> &le; 1,000</li> <li>1 &le; <i>N</i> &le; 100</li> <li>0 &le; <i>x<sub>i</sub></i> &le; <i>W</i></li> <li>0 &le; <i>y<sub>i</sub></i> &le; <i>H</i></li> </ul> </p> <p> たた2぀の異なるむチゎが同じ座暙にあるこずはない </p> <!-- end ja only --> </div> <h3>Output</h3> <div> <!-- begin ja only --> <p> それぞれのデヌタセットに察しお 2人の仮定を甚いた堎合にむチゎが2等分される確率を衚す実数を1行に出力せよ 答えには 10<sup>-8</sup> を越える誀差があっおはいけないそれ以倖の䜙蚈な文字を出力しおはならない </p> <!-- end ja only --> </div> <h3>Sample Input</h3> <div> <pre> 2 2 1 0 1 2 1 3 3 1 1 1 2 1 0 0 0 </pre> </div> <h3>Output for the Sample Input</h3> <div> <pre> 0.5000000000 0.1666666667 </pre> </div>
p01689
<h2>C - Dowsing Machine / ダりゞングマシヌン</h2> <h3>Story</h3> <p>䞖間ではXだずかYだずかで隒がしいけれど、これからの時代は&quot;D&quot;である。&quot;パクリンモンスタヌD&quot;は、秘密結瀟&quot;R団&quot;によっお開発された&quot;Dマシン&quot;を䜿っお&quot;Dのひず&quot;が財宝探玢を行う倧人気ゲヌムである。</p> <p>このゲヌムでは、栌子状マップのあるマスにいるDのひずが、隣接する䞊䞋巊右のマスぞの移動を繰り返し、財宝が存圚するマスぞの到達を目指す。 マップ䞊には財宝が存圚するマスが1぀だけある。 財宝が存圚するマスは明らかにされおいないため、Dマシンを䜿っお存圚する財宝のマスを絞り蟌んでから、財宝が存圚するマスぞ移動したい。</p> <p>Dマシンを䜿うず、財宝が存圚するマスを含む耇数マスぞの反応を瀺す。反応は、Dマシンを䜿ったずきにDのひずが居たマスを基準に衚珟される。ただし、Dマシンは壊れおいるこずがあり、Dマシンを䜿ったずきに、財宝が存圚し埗ないマスぞの反応を瀺すこずがある。たた、Dのひずが移動できない壁マスがマップ䞊に存圚するため、財宝の存圚するマスに移動できないこずもある。DのひずはいろいろなマスでDマシンを䜿い、その反応を芳枬した。Dのひずは、財宝の存圚するマスに到達できるだろうか。</p> <h3>Problem</h3> <!-- <dl> <dt>高さ <var>h</var> 幅 <var>w</var> の二次元栌子を考える。あるマス <var>t_{i,j}</var> は、次のいずれかの文字で衚される。</dt> <dd> --> <p>高さ <var>h</var> 幅 <var>w</var> の二次元栌子を考える。あるマス <var>t_{i,j}</var> は、次のいずれかの文字で衚される。</p> <ul> <li>&quot;.&quot; : 通行可胜であるこずを衚す。このマスには財宝が存圚するかもしれない。</li> <li>&quot;#&quot; : 壁があり、通行䞍可胜であるこずを衚す。このマスには財宝は存圚しない。</li> <li>&quot;D&quot; : 通行可胜であり、Dのひずがいるこずを衚す。このマスには財宝が存圚するかもしれない。</li> </ul> <!-- </dd> </dl> --> <p>Dのひずは、䞊䞋巊右に隣接する通行可胜なマスぞ移動するこずができる。</p> <p>Dマシンは䜿甚した䜍眮に応じお、図のような二次元栌子内のいずれかのマス集合ぞの反応を瀺す。䞋図の各矩圢はそれぞれが半埄 <var>r_1, r_2, ..., r_d</var> の正方圢である。正方圢の半埄が <var>r_k</var> であるずは、正方圢の䞀蟺の長さが <var>2 r_k + 1</var> であるこずを意味する。</p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_HUPC2014_fig1" alt="fig1.png" /> </center> <br/> <p><var>(x, y)</var>でDマシンを䜿甚したずきに瀺された反応を <var>s</var> ずする。<var>1 \leq s \leq d-1</var>のずきは、<var>(x, y)</var>を䞭心ずする半埄 <var>r_{s+1}</var> の正方圢から、 半埄 <var>r_s</var> の正方圢を陀いた図圢に含たれるマスに財宝が存圚するこずを衚す。<var>s=0</var> のずきは、<var>(x, y)</var>を䞭心ずする半埄 <var>r_1</var> の正方圢に含たれるマスに財宝が存圚するこずを衚す。<var>s=d</var> のずきは、<var>(x, y)</var>を䞭心ずする半埄 <var>r_d</var> の正方圢の倖偎のマスに財宝が存圚するこずを衚す。財宝が存圚するマスは必ず<var>1</var>぀だけ存圚する。しかし、Dマシンが壊れおいる堎合、Dマシンはこれに矛盟した反応を瀺す。</p> <p>Dマシンの䜿甚によっお瀺された反応が耇数䞎えられる。 Dマシンが確実に壊れおいる堎合は&quot;Broken&quot;、Dのひずがいる䜍眮から財宝の存圚するマスに必ずたどり着ける堎合は&quot;Yes&quot;、絶察にたどり着けない堎合は&quot;No&quot;、たどり着けるかどうか分からない堎合は&quot;Unknown&quot;を出力せよ。</p> <h3>Input</h3> <p>入力は以䞋の圢匏で䞎えらえる。</p> <pre><var>h</var> <var>w</var> <var>d</var> <var>n</var> <var>t_{0,0}t_{0,1}...t_{0,w-1}</var> <var>...</var> <var>t_{h-1,0}t_{h-1,1}...t_{h-1,w-1}</var> <var>r_1</var> <var>r_2</var> <var>...</var> <var>r_d</var> <var>x_1</var> <var>y_1</var> <var>s_1</var> <var>...</var> <var>x_n</var> <var>y_n</var> <var>s_n</var></pre> <p>1行目は4぀の敎数からなりそれぞれ二次元栌子の瞊幅<var>h</var>、暪幅<var>w</var>、 正方圢の個数<var>d</var>、Dマシンを䜿甚した回数<var>n</var>が空癜1文字区切りで䞊んでいる。 続く<var>h</var>行では各マスの文字が䞎えられる。 <var>i+2</var>行目(<var>0 \leq i &lt; h</var>)の<var>j+1</var>番目(<var>0 \leq j &lt; w</var>)の文字<var>t_{i,j}</var>はマス<var>(j,i)</var>の文字を衚す。 <var>h+2</var>行目では、各正方圢の半埄<var>r_k</var>(<var>1 \leq k \leq d</var>)が空癜1文字区切りで䞎えられる。 続く<var>n</var>行では、Dマシンの反応が䞎えられる。 <var>l+h+3</var>行目(<var>1 \leq l \leq n</var>)では、<var>x_l</var>、<var>y_l</var>、<var>s_l</var>が空癜1文字区切りで䞎えられ、マス<var>(x_l, y_l)</var>でDマシンを䜿甚したずきに反応<var>s_l</var>が瀺されたこずを衚す。</p> <p>制玄</p> <ul> <li><var>1 \leq h \leq 50, 1 \leq w \leq 50, 1 \leq d \leq 10, 1 \leq n \leq 50</var></li> <li><var>t_{i,j}</var>は&quot;#&quot;, &quot;.&quot;, &quot;D&quot;のいずれかであり、文字&quot;D&quot;は必ず1぀だけ存圚する</li> <li><var>0 \leq r_k \leq 50</var>であり<var>k &gt; 1</var>に぀いお<var>r_{k-1} &lt; r_k</var></li> <li><var>0 \leq x_l &lt; w, 0 \leq y_l &lt; h, 0 \leq s_l \leq d</var></li> <li>文字&quot;D&quot;で衚されるマスからの移動を繰り返すこずでマス<var>(x_l, y_l)</var>ぞ到達するこずができる</li> </ul> <h3>Output</h3> <p>&quot;Broken&quot;, &quot;Yes&quot;, &quot;No&quot;, &quot;Unknown&quot;のいずれかのうち、適切なものを<var>1</var>行に出力せよ。行の最埌では必ず改行を行うこず。</p> <h3>Sample Input 1</h3> <pre>6 10 3 4 ########## #........# #...D....# #........# #........# ########## 2 4 6 3 2 0 7 4 2 8 4 3 1 4 1</pre> <h3>Sample Output 1</h3> <pre>Yes</pre> <h3>Sample Input 2</h3> <pre>6 10 2 3 ########## #.#......# ###......# #......D.# #........# ########## 1 2 3 2 1 3 1 1 1 3 1</pre> <h3>Sample Output 2</h3> <pre>No</pre> <h3>Sample Input 3</h3> <pre>6 10 3 1 ########## #........# #...D....# #........# #........# ########## 2 4 6 3 4 3</pre> <h3>Sample Output 3</h3> <pre>Broken</pre> <h3>Sample Input 4</h3> <pre>6 10 3 3 ########## #.#......# ###.D....# #.#......# #........# ########## 2 4 6 3 2 0 7 4 2 8 4 3</pre> <h3>Sample Output 4</h3> <pre>Unknown</pre>
p00132
<h1>ゞグ゜ヌパズル</h1> <p> 子䟛から倧人たで脳トレ系パズルゲヌムが流行しおいたす。我々も遅れを取らぬよう、パズルゲヌムを䜜っおみんなで遊ぶこずにしたした。 </p> <p> 我々が考えたのはゞグ゜ヌパズルのゲヌムで、未完成の郚分を埋めるのに必芁なピヌスを遞ぶずいうものです。図 1 (a) はパズルの枠の䟋です。黒が埋たっおいる郚分、癜が未完成の郚分です。このパズルを完成するのに䜿えるピヌスが図 1 (b) のように䞎えられたす。この䞭から、枠の癜い郚分を埋めるこずができる黒いピヌスを 1 ぀以䞊遞択したす。䟋えば、図 2 の遞択䟋 1 のような組み合わせなら正解ずなりたす。䞀方、遞択䟋 2 のような組み合わせではパズルは完成しないので䞍正解ずなりたす。たた、遞択したピヌスが䜙っおしたう堎合も䞍正解です。このように、プレむダヌは適切なピヌスを遞択するこずでゲヌムをクリアしたす。 </p> <p> そこでこのパズルゲヌムで甚いる刀定プログラムを開発するこずになりたした。未完成のパズル、ピヌスの候補、そしおプレむダヌが遞んだピヌスの組み合わせを入力ずし、プレむダヌが適切なピヌスを遞ぶこずができおいれば YES を、そうでなければ NO ず出力するプログラムを䜜成しおください。 </p> <p> この問題では、パズルの枠は <var>H &times; W</var> の配列で衚し、未完成の郚分を . (半角ピリオド)、完成しおいる郚分を # (半角シャヌプ)によっお䞎えたす。パズルの枠の倧きさは最倧 <var>20 &times; 20</var> ずしたす。たた、各ピヌスは <var>h &times; w</var> の配列で衚し、ピヌスを構成する郚分を # 、そうでない郚分を . によっお䞎えたす。䞎えられる各ピヌスは、元の状態から 90 床、180 床、270 床だけ回転するこずができたす。たた、各ピヌスの倧きさは最倧 <var>20 &times; 20</var> ずし、䞎えられるピヌスの数 <var>n</var> は最倧 10 ずしたす。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_jigsawPuzzle"> </center> <br> <H2>Input</H2> <p> 耇数のデヌタセットが䞎えられたす。各デヌタセットは以䞋の圢匏で䞎えられたす。 </p> <pre> <var>H</var> <var>W</var> <var>g<sub>1,1</sub></var><var>g<sub>1,2</sub></var>...<var>g<sub>1,W</sub></var> <var>g<sub>2,1</sub></var><var>g<sub>2,2</sub></var>...<var>g<sub>2,W</sub></var> : <var>g<sub>H,1</sub></var><var>g<sub>H,2</sub></var>...<var>g<sub>H,W</sub></var> <var>n</var> <var>h<sub>1</sub></var> <var>w<sub>1</sub></var> <var>c1<sub>1,1</sub></var><var>c1<sub>1,2</sub></var>...<var>c1<sub>1,w<sub>1</sub></sub></var> <var>c1<sub>2,1</sub></var><var>c1<sub>2,2</sub></var>...<var>c1<sub>2,w<sub>1</sub></sub></var> : <var>c1<sub>h<sub>1</sub>,1</sub></var><var>c1<sub>h<sub>1</sub>,2</sub></var>...<var>c1<sub>h<sub>1</sub>,w<sub>1</sub></sub></var> : : <var>h<sub>n</sub></var> <var>w<sub>n</sub></var> <var>cn<sub>1,1</sub></var><var>cn<sub>1,2</sub></var>...<var>cn<sub>1,w<sub>n</sub></sub></var> <var>cn<sub>2,1</sub></var><var>cn<sub>2,2</sub></var>...<var>cn<sub>2,w<sub>n</sub></sub></var> : <var>cn<sub>h<sub>n</sub>,1</sub></var><var>cn<sub>h<sub>n</sub>,2</sub></var>...<var>cn<sub>h<sub>n</sub>,w<sub>n</sub></sub></var> <var>p</var> <var>k<sub>1</sub></var> <var>t<sub>1</sub></var> <var>t<sub>2</sub></var> ... <var>t<sub>k<sub>1</sub></sub></var> <var>k<sub>2</sub></var> <var>t<sub>1</sub></var> <var>t<sub>2</sub></var> ... <var>t<sub>k<sub>2</sub></sub></var> : <var>k<sub>p</sub></var> <var>t<sub>1</sub></var> <var>t<sub>2</sub></var> ... <var>t<sub>k<sub>p</sub></sub></var> </pre> <p> 1 行目に、パズルの枠の倧きさ <var>H</var>(瞊) ず <var>W</var>(暪) が䞎えられたす。 2 行目に、文字 <var>g<sub>i,j</sub></var> (<span>.</span> たたは <span>#</span>) からなりパズルの盀面を衚す 1 行 <var>W</var> 文字の文字列が <var>H</var> 行䞎えられたす。 </p> <p> 続いおピヌスの数 <var>n</var>、<var>n</var> 個のピヌスの情報が䞎えられたす。各ピヌスの情報ずしお、<var>l</var> 番目のピヌスの配列のサむズ <var>h<sub>l</sub></var> (瞊) ず <var>w<sub>l</sub></var> (暪)、<var>l</var> 番目のピヌスの配列が䞎えられたす。<var>l</var> 番目のピヌスの配列ずしお文字 <var>cl<sub>i,j</sub></var> (<span>.</span> たたは <span>#</span>) からなる 1 行 <var>w<sub>l</sub></var> 文字の文字列が <var>h<sub>l</sub></var> 行䞎えられたす。 </p> <p> 続いおプレむダヌの人数 <var>p</var>、<var>i</var> 番目のプレむダヌの遞択したピヌスの数 <var>k<sub>i</sub></var> ず遞択したピヌスの番号 <var>t<sub>j</sub></var> が䞎えられたす。 </p> <p> 入力は぀の 0 を含む行で終了したす。デヌタセットの数は 10 を超えたせん。 </p> <H2>Output</H2> <p> 各デヌタセットごずに、<var>i</var> 番目のプレむダヌが遞択したピヌスの正吊 YES たたは NO を <var>i</var> 行目に出力しおください。 </p> <H2>Sample Input</H2> <pre> 14 20 #################### ###.............#### ####..........###### #######.....######## ########.....####### ###..###......###### ###..####......##### #########......##### ###########.....#### ############.....### ###.########......## ###.#######...###.## ##...###....#####.## #################### 10 12 15 #############.. .##########.... ....#####...... .....#####..... .....######.... ......######... ......######... ........#####.. .........#####. .........###### ........###...# .....####.....# 3 3 #.. ### #.. 2 2 ## ## 4 10 ....#####. ....###### ...###...# ####.....# 6 5 ....# ..### ##### ##.## #..## #..#. 6 4 ...# .### #### ##.# ##.# #... 2 6 ###### .##### 2 7 ..##### ####### 2 13 ############# .##########.. 6 9 #####.... .######.. .######.. ..######. ...#####. ....##### 8 3 1 2 3 4 1 2 3 4 7 2 3 4 5 6 7 8 5 2 3 10 7 8 6 2 3 9 5 6 4 8 2 3 4 6 9 5 4 10 4 4 5 6 9 5 10 2 3 4 9 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> YES NO YES NO YES NO NO YES </pre>
p00562
<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>Soccer</h1> <p> You are a manager of a prestigious soccer team in the JOI league. </p> <p> The team has $N$ players numbered from 1 to $N$. The players are practicing hard in order to win the tournament game. The field is a rectangle whose height is $H$ meters and width is $W$ meters. The vertical line of the field is in the north-south direction, and the horizontal line of the field is in the east-west direction. A point in the field is denoted by ($i, j$) if it is $i$-meters to the south and $j$ meters to the east from the northwest corner of the field. </p> <p> After the practice finishes, players must clear the ball. In the beginning of the clearance, the player $i$ ($1 \leq i \leq N$) stands at ($S_i, T_i$). There is only one ball in the field, and the player 1 has it. You stand at ($S_N, T_N$) with the player $N$. The clearance is finished if the ball is passed to ($S_N, T_N$), and you catch it. You cannot move during the clearance process. </p> <p> You can ask players to act. But, if a player acts, his <b>fatigue degree</b> will be increased according to the action. Here is a list of possible actions of the players. If a player has the ball, he can act (i),(ii), or (iii). Otherwise, he can act (ii) or (iv). </p> <ul> <li> (i) Choose one of the 4 directions (east/west/south/north), and choose a positive integer $p$. Kick the ball to that direction. Then, the ball moves exactly p meters. The kicker does not move by this action, and he loses the ball. His fatigue degree is increased by $A \times p + B$.</li> <li>(ii) Choose one of the 4 directions (east/west/south/north), and move 1 meter to that direction. If he has the ball, he moves with it. His fatigue degree is increased by $C$ regardless of whether he has the ball or not.</li> <li>(iii) Place the ball where he stands. He loses the ball. His fatigue degree does not change.</li> <li>(iv) Take the ball. His fatigue degree does not change. A player can take this action only if he stands at the same place as the ball, and nobody has the ball.</li> </ul> <p> Note that it is possible for a player or a ball to leave the field. More than one players can stand at the same place. </p> <p> Since the players just finished the practice, their fatigue degrees must not be increased too much. You want to calculate the minimum possible value of the sum of fatigue degrees of the players for the clearance process. </p> <h2>Task</h2> <p> Given the size of the field and the positions of the players, write a program which calculates the minimum possible value of the sum of fatigue degrees of the players for the clearance process. </p> <h3>Input</h3> <p> Read the following data from the standard input. </p> <ul> <li> The first line of input contains two space separated integers $H$, $W$. This means the field is a rectangle whose height is $H$ meters and width is $W$ meters.</li> <li> The second line contains three space separated integers $A$, $B$, $C$ describing the increment of the fatigue degree by actions.</li> <li> The third line contains an integer N, the number of players.</li> <li> The $i$-th line ($1 \leq i \leq N$) of the following $N$ lines contains two space separated integers $S_i$, $T_i$. This means, in the beginning of the clearance, the player $i$ ($1 \leq i \leq N$) stands at ($S_i, T_i$).</li> </ul> <h3>Output</h3> <p> Write one line to the standard output. The output contains the minimum possible value of the sum of fatigue degrees of the players for the clearance process. </p> <h3>Constraints</h3> <p> All input data satisfy the following conditions. </p> <ul> <li>$1 \leq H \leq 500$</li> <li>$1 \leq W \leq 500$</li> <li>$0 \leq A \leq 1 000 000 000$</li> <li>$0 \leq B \leq 1 000 000 000$</li> <li>$0 \leq C \leq 1 000 000 000$</li> <li>$2 \leq N \leq 100 000$</li> <li>$0 \leq S_i \leq H (1 \leq i \leq N)$</li> <li>$0 \leq T_i \leq W (1 \leq i \leq N)$</li> <li>$(S_1, T_1) \ne (S_N, T_N)$</li> </ul> <h3>Sample Input and Output</h3> <h3>Sample Input 1</h3> <pre> 6 5 1 3 6 3 1 1 0 4 6 5 </pre> <h3>Sample Output 1</h3> <pre> 26 </pre> <p> In this sample input, the initial status of the field is as in the following figure. The white circles are the players. The black circle is the ball. You stand at (6, 5). </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JOI2016_4_1" width="280"><br> The initial status of the field</br> </center> <p> The players act as follows: </p> <ol> <li>. The player 1 kicks the ball to the east for $3$ meters. His fatigue degree is increased by $1 \times 3 + 3 = 6$. The ball moves to ($1, 4$).</li> <li> The player 2 moves $1$ meter to the south, and he has the ball. His fatigue degree is increased by $6$.</li> <li> The player 2 moves $1$ meter to the east. His fatigue degree is increased by $6$.</li> <li> The player 2 kicks the ball to the south for $5$ meters. His fatigue degree is increased by $1 \times 5 + 3 = 8$. The ball moves to ($6, 5$).</li> </ol> <p> In these actions, the sum of fatigue degrees is $6 + 6 + 6 + 8 = 26$, which is the minimum possible value. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JOI2016_4_2" width="600"><br> The actions in an optimal solution </center> <h3>Sample Input 2</h3> <pre> 3 3 0 50 10 2 0 0 3 3 </pre> <h3>Sample Output 2</h3> <pre> 60 </pre> <p>In Sample Input 2, it not not necessary to</p> <h3>Sample Input 3</h3> <pre> 4 3 0 15 10 2 0 0 4 3 </pre> <h3>Sample Output 3</h3> <pre> 45 </pre> <h3>Sample Input 4</h3> <pre> 4 6 0 5 1000 6 3 1 4 6 3 0 3 0 4 0 0 4 </pre> <h3>Sample Output 4</h3> <pre> 2020 </pre> <p> that more than one players can stand at the same place. </p> <br/> <div class="source"> <p class="source"> <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="Creative Commonse License" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png"/></a> </p> <p class="source"> <a href="https://www.ioi-jp.org/joi/2016/2017-ho/index.html">The 16th Japanese Olympiad in Informatics (JOI 2016/2017) Final Round</p> </p> </div>
p00098
<H1>Maximum Sum Sequence II</H1> <p> 䞎えられた敎数の行列 </p> <pre> <var>a<sub>1,1</sub></var> <var>a<sub>1,2</sub></var> ... <var>a<sub>1,n</sub></var> <var>a<sub>2,1</sub></var> <var>a<sub>2,2</sub></var> ... <var>a<sub>2,n</sub></var> : <var>a<sub>n,1</sub></var> <var>a<sub>n,2</sub></var> ... <var>a<sub>n, n</sub></var> </pre> <p> で、瞊・暪方向に぀以䞊連続した項郚分行列の和の最倧倀を出力しお終了するプログラムを䜜成しお䞋さい。 </p> <H2>Input</H2> <p> 入力デヌタは以䞋の圢匏で䞎えられたす。 </p> <pre> <var>n</var> <var>a<sub>1,1</sub></var> <var>a<sub>1,2</sub></var> ... <var>a<sub>1,n</sub></var> <var>a<sub>2,1</sub></var> <var>a<sub>2,2</sub></var> ... <var>a<sub>2,n</sub></var> : <var>a<sub>n,1</sub></var> <var>a<sub>n,2</sub></var> ... <var>a<sub>n, n</sub></var> </pre> <p> <var>n</var> は 1 以䞊 100 以䞋、<var>a<sub>i,j</sub></var> は -10000 以䞊 10000 以䞋です。 <H2>Output</H2> <p> 最倧倀を 1 行に出力しお䞋さい。 </p> <H2>Sample Input 1</H2> <pre> 3 1 -2 3 -4 5 6 7 8 -9 </pre> <H2>Output for the Sample Input 1</H2> <pre> 16 </pre> <p> この入力の堎合、以䞋の郚分行列の項の和が最倧ずなりたす。 </p> <pre> -4 5 7 8 </pre> <br/> <H2>Sample Input 2</H2> <pre> 4 1 3 -9 2 2 7 -1 5 -8 3 2 -1 5 0 -3 1 </pre> <H2>Output for the Sample Input 2</H2> <pre> 15 </pre> <p> この入力の堎合、以䞋の郚分行列の項の和が最倧ずなりたす。 </p> <pre> 7 -1 5 3 2 -1 </pre>
p02230
UF with binary input (K = 100)
p02660
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>Given is a positive integer <var>N</var>. Consider repeatedly applying the operation below on <var>N</var>:</p> <ul> <li>First, choose a positive integer <var>z</var> satisfying all of the conditions below:<ul> <li><var>z</var> can be represented as <var>z=p^e</var>, where <var>p</var> is a prime number and <var>e</var> is a positive integer;</li> <li><var>z</var> divides <var>N</var>;</li> <li><var>z</var> is different from all integers chosen in previous operations.</li> </ul> </li> <li>Then, replace <var>N</var> with <var>N/z</var>.</li> </ul> <p>Find the maximum number of times the operation can be applied.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li>All values in input are integers.</li> <li><var>1 \leq N \leq 10^{12}</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print the maximum number of times the operation can be applied.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>24 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>We can apply the operation three times by, for example, making the following choices:</p> <ul> <li>Choose <var>z=2 (=2^1)</var>. (Now we have <var>N=12</var>.)</li> <li>Choose <var>z=3 (=3^1)</var>. (Now we have <var>N=4</var>.)</li> <li>Choose <var>z=4 (=2^2)</var>. (Now we have <var>N=1</var>.)</li> </ul> </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 </pre> <p>We cannot apply the operation at all.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>64 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>3 </pre> <p>We can apply the operation three times by, for example, making the following choices:</p> <ul> <li>Choose <var>z=2 (=2^1)</var>. (Now we have <var>N=32</var>.)</li> <li>Choose <var>z=4 (=2^2)</var>. (Now we have <var>N=8</var>.)</li> <li>Choose <var>z=8 (=2^3)</var>. (Now we have <var>N=1</var>.)</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>1000000007 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>1 </pre> <p>We can apply the operation once by, for example, making the following choice:</p> <ul> <li><var>z=1000000007 (=1000000007^1)</var>. (Now we have <var>N=1</var>.)</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 5</h3><pre>997764507000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>7 </pre></section> </div> </span>
p03972
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>On an <var>xy</var> plane, in an area satisfying <var>0 ≀ x ≀ W, 0 ≀ y ≀ H</var>, there is one house at each and every point where both <var>x</var> and <var>y</var> are integers.</p> <p>There are unpaved roads between every pair of points for which either the <var>x</var> coordinates are equal and the difference between the <var>y</var> coordinates is <var>1</var>, or the <var>y</var> coordinates are equal and the difference between the <var>x</var> coordinates is <var>1</var>.</p> <p>The cost of paving a road between houses on coordinates <var>(i,j)</var> and <var>(i+1,j)</var> is <var>p_i</var> for any value of <var>j</var>, while the cost of paving a road between houses on coordinates <var>(i,j)</var> and <var>(i,j+1)</var> is <var>q_j</var> for any value of <var>i</var>.</p> <p>Mr. Takahashi wants to pave some of these roads and be able to travel between any two houses on paved roads only. Find the solution with the minimum total cost.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≩ W,H ≩ 10^5</var></li> <li><var>1 ≩ p_i ≩ 10^8(0 ≩ i ≩ W-1)</var></li> <li><var>1 ≩ q_j ≩ 10^8(0 ≩ j ≩ H-1)</var></li> <li><var>p_i (0 ≩ i ≩ W−1)</var> is an integer.</li> <li><var>q_j (0 ≩ j ≩ H−1)</var> is an integer.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Inputs are provided from Standard Input in the following form.</p> <pre><var>W</var> <var>H</var> <var>p_0</var> : <var>p_{W-1}</var> <var>q_0</var> : <var>q_{H-1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Output an integer representing the minimum total cost.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 2 3 5 2 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>29 </pre> <p>It is enough to pave the following eight roads.</p> <ul> <li>Road connecting houses at <var>(0,0)</var> and <var>(0,1)</var></li> <li>Road connecting houses at <var>(0,1)</var> and <var>(1,1)</var></li> <li>Road connecting houses at <var>(0,2)</var> and <var>(1,2)</var></li> <li>Road connecting houses at <var>(1,0)</var> and <var>(1,1)</var></li> <li>Road connecting houses at <var>(1,0)</var> and <var>(2,0)</var></li> <li>Road connecting houses at <var>(1,1)</var> and <var>(1,2)</var></li> <li>Road connecting houses at <var>(1,2)</var> and <var>(2,2)</var></li> <li>Road connecting houses at <var>(2,0)</var> and <var>(2,1)</var></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 3 2 4 8 1 2 9 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>60 </pre></section> </div> </span>
p03421
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Determine if there exists a sequence obtained by permuting <var>1,2,...,N</var> that satisfies the following conditions:</p> <ul> <li>The length of its longest increasing subsequence is <var>A</var>.</li> <li>The length of its longest decreasing subsequence is <var>B</var>.</li> </ul> <p>If it exists, construct one such sequence.</p> </section> </div> <div class="part"> <section> <h3>Notes</h3><p>A subsequence of a sequence <var>P</var> is a sequence that can be obtained by extracting some of the elements in <var>P</var> without changing the order.</p> <p>A longest increasing subsequence of a sequence <var>P</var> is a sequence with the maximum length among the subsequences of <var>P</var> that are monotonically increasing.</p> <p>Similarly, a longest decreasing subsequence of a sequence <var>P</var> is a sequence with the maximum length among the subsequences of <var>P</var> that are monotonically decreasing.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N,A,B \leq 3\times 10^5</var></li> <li>All input values are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A</var> <var>B</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If there are no sequences that satisfy the conditions, print <code>-1</code>.</p> <p>Otherwise, print <var>N</var> integers. The <var>i</var>-th integer should be the <var>i</var>-th element of the sequence that you constructed.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 3 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 4 1 5 3 </pre> <p>One longest increasing subsequence of this sequence is <var>{2,4,5}</var>, and one longest decreasing subsequence of it is <var>{4,3}</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>7 7 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 2 3 4 5 6 7 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>300000 300000 300000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>-1 </pre></section> </div> </span>
p03071
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are two buttons, one of size <var>A</var> and one of size <var>B</var>.</p> <p>When you press a button of size <var>X</var>, you get <var>X</var> coins and the size of that button decreases by <var>1</var>.</p> <p>You will press a button twice. Here, you can press the same button twice, or press both buttons once.</p> <p>At most how many coins can you get?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>3 \leq A, B \leq 20</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>A</var> <var>B</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum number of coins you can get.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>9 </pre> <p>You can get <var>5 + 4 = 9</var> coins by pressing the button of size <var>5</var> twice, and this is the maximum result.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>7 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>6 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>12 </pre></section> </div> </span>
p03564
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Square1001 has seen an electric bulletin board displaying the integer <var>1</var>. He can perform the following operations A and B to change this value:</p> <ul> <li>Operation A: The displayed value is doubled.</li> <li>Operation B: The displayed value increases by <var>K</var>.</li> </ul> <p>Square1001 needs to perform these operations <var>N</var> times in total. Find the minimum possible value displayed in the board after <var>N</var> operations.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N, K \leq 10</var></li> <li>All input values are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum possible value displayed in the board after <var>N</var> operations.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>10 </pre> <p>The value will be minimized when the operations are performed in the following order: A, A, B, B.<br/> In this case, the value will change as follows: <var>1</var> → <var>2</var> → <var>4</var> → <var>7</var> → <var>10</var>. </p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>76 </pre> <p>The value will be minimized when the operations are performed in the following order: A, A, A, A, B, B, B, B, B, B.<br/> In this case, the value will change as follows: <var>1</var> → <var>2</var> → <var>4</var> → <var>8</var> → <var>16</var> → <var>26</var> → <var>36</var> → <var>46</var> → <var>56</var> → <var>66</var> → <var>76</var>. </p> <p>By the way, this contest is AtCoder Beginner Contest 076.</p></section> </div> </span>
p01559
<h1>MinimumCostPath</h1> <p>NxNの方県がある。 </p> <p><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_mcp_grid" height="140px"><br> (N=3の堎合の図) </p> <p>隣接するマス目に移動するにはコストが1かかる。ただし、斜めに移動するこずは出来ない。 たた障害物があるマス目がM個あり、そのマスに入るこずは蚱されない。 マス(1, 1)からマス(N, N)に最小のコストで移動する方法は䜕通りあるか。 答えは倧きくなるこずがありうるので、1000000009(=10<sup>9</sup>+9)でMODを取っお出力せよ。 </p> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる </p><blockquote> N M<br>X<sub>1</sub> Y<sub>1</sub><br>X<sub>2</sub> Y<sub>2</sub><br>

<br>X<sub>M</sub> Y<sub>M</sub><br></blockquote> <p>X<sub>i</sub>, Y<sub>i</sub>は(X<sub>i</sub>, Y<sub>i</sub>)に障害物があるこずを衚す </p> <h2>Constraints</h2> <ul><li><p>2 &le; N &le; 10<sup>6</sup> </p></li><li><p> 0 &le; M &le; 50 </p></li><li><p> 1 &le; X<sub>i</sub> , Y<sub>i</sub> &le; N </p></li><li><p> i &ne; jならば (X<sub>i</sub>, Y<sub>i</sub>) &ne; (X<sub>j</sub>, Y<sub>j</sub>) </p></li><li><p> (X<sub>i</sub>, Y<sub>i</sub>) &ne; (1, 1) </p></li><li><p> (X<sub>i</sub>, Y<sub>i</sub>) &ne; (N, N) </p></li></ul> <h2>Output</h2> <p>1行に経路の総数を出力せよ。ただし、マス(1, 1)からマス(N, N)に移動する経路が存圚しない堎合は0ず出力せよ。 </p> <h2>Sample Input 1</h2> <pre>3 0 </pre> <h2>Output for the Sample Input 1</h2> <pre>6 </pre> 以䞋の図に察応する。<br> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_mcp_1" height="140px"> <h2>Sample Input 2</h2> <pre>3 1 2 2 </pre> <h2>Output for the Sample Input 2</h2> <pre>2 </pre> 以䞋の図に察応する。<br> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_mcp_2" height="140px"> <h2>Sample Input 3</h2> <pre>5 8 4 3 2 1 4 2 4 4 3 4 2 2 2 4 1 4 </pre> <h2>Output for the Sample Input 3</h2> <pre>1 </pre> 以䞋の図に察応する。<br> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE_mcp_3" height="270px"> <h2>Sample Input 4</h2> <pre>1000 10 104 87 637 366 393 681 215 604 707 876 943 414 95 327 93 415 663 596 661 842 </pre> <h2>Output for the Sample Input 4</h2> <pre>340340391 </pre> <h2>Sample Input 5</h2> <pre>2 2 1 2 2 1 </pre> <h2>Output for the Sample Input 5</h2> <pre>0 </pre>
p03134
<span class="lang-en"> <p>Score : <var>900</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> Snukes lining up in a row. You are given a string <var>S</var> of length <var>N</var>. The <var>i</var>-th Snuke from the front has two red balls if the <var>i</var>-th character in <var>S</var> is <code>0</code>; one red ball and one blue ball if the <var>i</var>-th character in <var>S</var> is <code>1</code>; two blue balls if the <var>i</var>-th character in <var>S</var> is <code>2</code>.</p> <p>Takahashi has a sequence that is initially empty. Find the number of the possible sequences he may have after repeating the following procedure <var>2N</var> times, modulo <var>998244353</var>:</p> <ul> <li>Each Snuke who has one or more balls simultaneously chooses one of his balls and hand it to the Snuke in front of him, or hand it to Takahashi if he is the first Snuke in the row.</li> <li>Takahashi receives the ball and put it to the end of his sequence.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq |S| \leq 2000</var></li> <li><var>S</var> consists of <code>0</code>,<code>1</code> and <code>2</code>.</li> </ul> <p>Note that the integer <var>N</var> is not directly given in input; it is given indirectly as the length of the string <var>S</var>.</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>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the possible sequences Takahashi may have after repeating the procedure <var>2N</var> times, modulo <var>998244353</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>02 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>There are three sequences that Takahashi may have: <code>rrbb</code>, <code>rbrb</code> and <code>rbbr</code>, where <code>r</code> and <code>b</code> stand for red and blue balls, respectively.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1210 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>55 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>12001021211100201020 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>543589959 </pre></section> </div> </span>
p01109
<h3>Income Inequality</h3> <!-- end en only --> <!-- begin en only --> <p> We often compute the average as the first step in processing statistical data. Yes, the average is a good tendency measure of data, but it is not always the best. In some cases, the average may hinder the understanding of the data. </p> <p> For example, consider the national income of a country. As the term <i>income inequality</i> suggests, a small number of people earn a good portion of the gross national income in many countries. In such cases, the average income computes much higher than the income of the vast majority. It is not appropriate to regard the average as the income of typical people. </p> <p> Let us observe the above-mentioned phenomenon in some concrete data. Incomes of <i>n</i> people, <i>a</i><sub>1</sub>, ... , <i>a<sub>n</sub></i>, are given. You are asked to write a program that reports the number of people whose incomes are less than or equal to the average (<i>a</i><sub>1</sub> + ... + <i>a<sub>n</sub></i>) / <i>n</i>. </p> <!-- end en only --> <h3>Input</h3> <!-- begin en only --> <p> The input consists of multiple datasets, each in the following format. </p> <!-- end en only --> <blockquote> <p> <i>n</i><br> <i>a</i><sub>1</sub> <i>a</i><sub>2</sub> ... <i>a<sub>n</sub></i> </p> </blockquote> <!-- begin en only --> <p> A dataset consists of two lines. In the first line, the number of people <i>n</i> is given. <i>n</i> is an integer satisfying 2 &#8804; <i>n</i> &#8804; 10&#8239;000. In the second line, incomes of <i>n</i> people are given. <i>a<sub>i</sub></i> (1 &#8804; <i>i</i> &#8804; <i>n</i>) is the income of the <i>i</i>-th person. This value is an integer greater than or equal to 1 and less than or equal to 100&#8239;000. </p> <p> The end of the input is indicated by a line containing a zero. The sum of <i>n</i>'s of all the datasets does not exceed 50&#8239;000. </p> <!-- end en only --> <h3>Output</h3> <!-- begin en only --> <p> For each dataset, output the number of people whose incomes are less than or equal to the average. </p> <!-- end en only --> <h3>Sample Input</h3> <pre>7 15 15 15 15 15 15 15 4 10 20 30 60 10 1 1 1 1 1 1 1 1 1 100 7 90 90 90 90 90 90 10 7 2 7 1 8 2 8 4 0 </pre> <h3>Output for the Sample Input</h3> <pre>7 3 9 1 4 </pre>
p00348
<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> <p> あるずき、゜ヌト・アルゎリズムに぀いお孊んだタケ子さんは、゜ヌト・アルゎリズムを自分で蚭蚈しおみたした。タケ子さんが䜜った゜ヌト・アルゎリズムでは、入力ずしお芁玠の間に重耇のない、個以䞊の自然数からなる列が䞎えられたずき、以䞋の凊理を実行したす。 </p> <ol> <li> はじめに、列の先頭の芁玠を遞ぶ。</li> <li> 遞んだ芁玠の盎前に芁玠があるずき、遞んだ芁玠ずその盎前の芁玠を比べる。盎前の芁玠のほうが倧きいなら、それを列の末尟の盎埌に移動させる(図。この操䜜を、遞んだ芁玠が列の先頭になるか、遞んだ芁玠よりその盎前の芁玠の方が小さくなるたで続ける。</li> <li> 遞んだ芁玠が列の末尟なら終了。そうでなければ、遞んだ芁玠の盎埌の芁玠を新たに遞び、2 ぞ戻る。</li> </ol> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2016_sort" width="360"><br/> </center> <br/> <p> タケ子さんはこのアルゎリズムがどのくらいの蚈算時間を必芁ずするか芋積もるために、芁玠を列の末尟の盎埌に移動させる操䜜の回数を数えるこずにしたした。 </p> <br/> <p> 列の情報を入力ずし、芁玠を列の末尟の盎埌に移動させる操䜜の回数を報告するプログラムを䜜成せよ。 </p> <h2>Input</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>N</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> ... <var>a<sub>N</sub></var> </pre> <p> 行目に列に含たれる芁玠の個数 <var>N</var> (1 &le; <var>N</var> &le; 200000) が䞎えられる。行目に列の芁玠 <var>a<sub>i</sub></var> (1 &le; <var>a<sub>i</sub></var> &le; 10<sup>9</sup>) が先頭から順番に䞎えられる。芁玠 <var>a<sub>i</sub></var> に重耇はない。 </p> <h2>Output</h2> <p> 芁玠を列の末尟の盎埌に移動させる操䜜の回数を行に出力する。 </p> <h2>Sample Input 1</h2> <pre> 6 1 3 6 5 8 2 </pre> <h2>Sample Output 1</h2> <pre> 10 </pre> <p> 入力䟋では、芁玠の移動が行われるたびに、以䞋のように列が倉化しおいく。 </p> <pre> 0回目 1 3 6 5 8 2 1回目 1 3 5 8 2 6 2回目 1 3 5 2 6 8 3回目 1 3 2 6 8 5 4回目 1 2 6 8 5 3 5回目 1 2 6 5 3 8 6回目 1 2 5 3 8 6 7回目 1 2 3 8 6 5 8回目 1 2 3 6 5 8 9回目 1 2 3 5 8 6 10回目 1 2 3 5 6 8 </pre> <br/> <h2>Sample Input 2</h2> <pre> 4 4 3 2 1 </pre> <h2>Sample Output 2</h2> <pre> 6 </pre>
p02375
<H1>Range Query on a Tree II</H1> <p> Write a program which manipulates a weighted rooted tree $T$ with the following operations: </p> <ul> <li>$add(v,w)$: add $w$ to all edges from the root to node $u$<br> <li>$getSum(u)$: report the sum of weights of all edges from the root to node $u$<br> </ul> <p> The given tree $T$ consists of $n$ nodes and every node has a unique ID from $0$ to $n-1$ respectively where ID of the root is $0$. Note that all weights are initialized to zero. </p> <h2>Input</h2> <p> The input is given in the following format. </p> <p> $n$<br> $node_0$<br> $node_1$<br> $node_2$<br> $:$<br> $node_{n-1}$<br> $q$<br> $query_1$<br> $query_2$<br> $:$<br> $query_{q}$<br> </p> <p> The first line of the input includes an integer $n$, the number of nodes in the tree. </p> <p> In the next $n$ lines,the information of node $i$ is given in the following format: </p> <pre> <var>k<sub>i</sub></var> <var>c<sub>1</sub></var> <var>c<sub>2</sub></var> ... <var>c<sub>k</sub></var> </pre> <p> $k_i$ is the number of children of node $i$, and $c_1$ $c_2$ ... $c_{k_i}$ are node IDs of 1st, ... $k$th child of node $i$. </p> <p> In the next line, the number of queries $q$ is given. In the next $q$ lines, $i$th query is given in the following format: </p> <pre> 0 <var>v</var> <var>w</var> </pre> <p> or </p> <pre> 1 <var>u</var> </pre> <p> The first integer represents the type of queries.'0' denotes $add(v, w)$ and '1' denotes $getSum(u)$. </p> <h2>Constraints</h2> <ul> <li>All the inputs are given in integers</li> <li>$ 2 \leq n \leq 100000 $</li> <li>$ c_j < c_{j+1} $ &nbsp; $( 1 \leq j \leq k-1 )$</li> <li>$ 2 \leq q \leq 200000 $</li> <li>$ 1 \leq u,v \leq n-1 $</li> <li>$ 1 \leq w \leq 10000 $</li> </ul> <h2>Output</h2> <p> For each $getSum$ query, print the sum in a line. </p> <h2>Sample Input 1</h2> <pre> 6 2 1 2 2 3 5 0 0 0 1 4 7 1 1 0 3 10 1 2 0 4 20 1 3 0 5 40 1 4 </pre> <h2>Sample Output 1</h2> <pre> 0 0 40 150 </pre> <h2>Sample Input 2</h2> <pre> 4 1 1 1 2 1 3 0 6 0 3 1000 0 2 1000 0 1 1000 1 1 1 2 1 3 </pre> <h2>Sample Output 2</h2> <pre> 3000 5000 6000 </pre>
p00718
<h1><font color="#000">Problem C:</font> Numeral System</h1> <p> Prof. Hachioji has devised a new numeral system of integral numbers with four lowercase letters "m", "c", "x", "i" and with eight digits "2", "3", "4", "5", "6", "7", "8", "9". He doesn't use digit "0" nor digit "1" in this system. </p> <p> The letters "m", "c", "x" and "i" correspond to 1000, 100, 10 and 1, respectively, and the digits "2", ...,"9" correspond to 2, ..., 9, respectively. This system has nothing to do with the Roman numeral system. </p> <p> For example, character strings </p> <blockquote> "5m2c3x4i", "m2c4i" and "5m2c3x" </blockquote> <p> correspond to the integral numbers 5234 (=5*1000+2*100+3*10+4*1), 1204 (=1000+2*100+4*1), and 5230 (=5*1000+2*100+3*10), respectively. The parts of strings in the above example, "5m", "2c", "3x" and "4i" represent 5000 (=5*1000), 200 (=2*100), 30 (=3*10) and 4 (=4*1), respectively. </p> <p> Each of the letters "m", "c", "x" and "i" may be prefixed by one of the digits "2", "3", ..., "9". In that case, the prefix digit and the letter are regarded as a pair. A pair that consists of a prefix digit and a letter corresponds to an integer that is equal to the original value of the letter multiplied by the value of the prefix digit. </p> <p> For each letter "m", "c", "x" and "i", the number of its occurrence in a string is at most one. When it has a prefix digit, it should appear together with the prefix digit. The letters "m", "c", "x" and "i" must appear in this order, from left to right. Moreover, when a digit exists in a string, it should appear as the prefix digit of the following letter. Each letter may be omitted in a string, but the whole string must not be empty. A string made in this manner is called an <I>MCXI-string</I>. </p> <p> An MCXI-string corresponds to a positive integer that is the sum of the values of the letters and those of the pairs contained in it as mentioned above. The positive integer corresponding to an MCXI-string is called its MCXI-value. Moreover, given an integer from 1 to 9999, there is a unique MCXI-string whose MCXI-value is equal to the given integer. For example, the MCXI-value of an MCXI-string "m2c4i" is 1204 that is equal to <tt>1000 + 2*100 + 4*1</tt>. There are no MCXI-strings but "m2c4i" that correspond to 1204. Note that strings "1m2c4i", "mcc4i", "m2c0x4i", and "2cm4i" are not valid MCXI-strings. The reasons are use of "1", multiple occurrences of "c", use of "0", and the wrong order of "c" and "m", respectively. </p> <p> Your job is to write a program for Prof. Hachioji that reads two MCXI-strings, computes the sum of their MCXI-values, and prints the MCXI-string corresponding to the result. </p> <h2>Input</h2> <p> The input is as follows. The first line contains a positive integer <I>n</I> (<= 500) that indicates the number of the following lines. The <I>k</I>+1 th line is the specification of the <I>k</I> th computation (<I>k</I>=1, ..., <I>n</I>). </p> <blockquote> <I>n</I> <br> <I>specification</I><sub>1</sub> <br> <I>specification</I><sub>2</sub> <br> ...<br> <I>specification</I><sub><I>n</I></sub> <br> </blockquote> <p> Each specification is described in a line: <blockquote> <I>MCXI-string</I><sub>1</sub> <I>MCXI-string</I><sub>2</sub> </blockquote> <p> The two MCXI-strings are separated by a space. </p> <p> You may assume that the sum of the two MCXI-values of the two MCXI-strings in each specification is less than or equal to 9999. </p> <h2>Output</h2> <p> For each specification, your program should print an MCXI-string in a line. Its MCXI-value should be the sum of the two MCXI-values of the MCXI-strings in the specification. No other characters should appear in the output. </p> <h2>Sample Input</h2> <pre> 10 xi x9i i 9i c2x2i 4c8x8i m2ci 4m7c9x8i 9c9x9i i i 9m9c9x8i m i i m m9i i 9m8c7xi c2x8i </pre> <h2>Output for the Sample Input</h2> <pre> 3x x 6cx 5m9c9x9i m 9m9c9x9i mi mi mx 9m9c9x9i </pre>
p02725
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a circular pond with a perimeter of <var>K</var> meters, and <var>N</var> houses around them.</p> <p>The <var>i</var>-th house is built at a distance of <var>A_i</var> meters from the northmost point of the pond, measured clockwise around the pond.</p> <p>When traveling between these houses, you can only go around the pond.</p> <p>Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the <var>N</var> houses.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq K \leq 10^6</var></li> <li><var>2 \leq N \leq 2 \times 10^5</var></li> <li><var>0 \leq A_1 &lt; ... &lt; A_N &lt; K</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>K</var> <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 distance that needs to be traveled when you start at one of the houses and visit all the <var>N</var> houses.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>20 3 5 10 15 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>10 </pre> <p>If you start at the <var>1</var>-st house and go to the <var>2</var>-nd and <var>3</var>-rd houses in this order, the total distance traveled will be <var>10</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>20 3 0 5 15 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>10 </pre> <p>If you start at the <var>2</var>-nd house and go to the <var>1</var>-st and <var>3</var>-rd houses in this order, the total distance traveled will be <var>10</var>.</p></section> </div> </span>
p03837
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given an undirected connected weighted graph with <var>N</var> vertices and <var>M</var> edges that contains neither self-loops nor double edges.<br/> The <var>i</var>-th <var>(1≀i≀M)</var> edge connects vertex <var>a_i</var> and vertex <var>b_i</var> with a distance of <var>c_i</var>.<br/> Here, a <em>self-loop</em> is an edge where <var>a_i = b_i (1≀i≀M)</var>, and <em>double edges</em> are two edges where <var>(a_i,b_i)=(a_j,b_j)</var> or <var>(a_i,b_i)=(b_j,a_j) (1≀i&lt;j≀M)</var>.<br/> A <em>connected graph</em> is a graph where there is a path between every pair of different vertices.<br/> Find the number of the edges that are not contained in any shortest path between any pair of different vertices. </p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≀N≀100</var> </li> <li><var>N-1≀M≀min(N(N-1)/2,1000)</var> </li> <li><var>1≀a_i,b_i≀N</var> </li> <li><var>1≀c_i≀1000</var></li> <li><var>c_i</var> is an integer.</li> <li>The given graph contains neither self-loops nor double edges.</li> <li>The given graph is connected.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>a_1</var> <var>b_1</var> <var>c_1</var> <var>a_2</var> <var>b_2</var> <var>c_2</var> <var>:</var> <var>a_M</var> <var>b_M</var> <var>c_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the edges in the graph that are not contained in any shortest path between any pair of different vertices.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 1 2 1 1 3 1 2 3 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>In the given graph, the shortest paths between all pairs of different vertices are as follows:</p> <ul> <li>The shortest path from vertex <var>1</var> to vertex <var>2</var> is: vertex <var>1</var> → vertex <var>2</var>, with the length of <var>1</var>.</li> <li>The shortest path from vertex <var>1</var> to vertex <var>3</var> is: vertex <var>1</var> → vertex <var>3</var>, with the length of <var>1</var>.</li> <li>The shortest path from vertex <var>2</var> to vertex <var>1</var> is: vertex <var>2</var> → vertex <var>1</var>, with the length of <var>1</var>.</li> <li>The shortest path from vertex <var>2</var> to vertex <var>3</var> is: vertex <var>2</var> → vertex <var>1</var> → vertex <var>3</var>, with the length of <var>2</var>.</li> <li>The shortest path from vertex <var>3</var> to vertex <var>1</var> is: vertex <var>3</var> → vertex <var>1</var>, with the length of <var>1</var>.</li> <li>The shortest path from vertex <var>3</var> to vertex <var>2</var> is: vertex <var>3</var> → vertex <var>1</var> → vertex <var>2</var>, with the length of <var>2</var>.</li> </ul> <p>Thus, the only edge that is not contained in any shortest path, is the edge of length <var>3</var> connecting vertex <var>2</var> and vertex <var>3</var>, hence the output should be <var>1</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 2 1 2 1 2 3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>Every edge is contained in some shortest path between some pair of different vertices.</p></section> </div> </span>
p01220
<H1><font color="#000">Problem E:</font> Triangles</H1> <p> There is a group that paints an emblem on the ground to invite aliens every year. You are a member of this group and you have to paint the emblem this year. </p> <p> The shape of the emblem is described as follows. It is made of <i>n</i> regular triangles whose sides are equally one unit length long. These triangles are placed so that their centroids coincide, and each of them is rotated counterclockwise by 360/<i>n</i> degrees with respect to the one over it around its centroid. The direction of the top triangle is not taken into account. </p> <p> It is believed that emblems have more impact as their <i>n</i> are taken larger. So you want to paint the emblem of <i>n</i> as large as possible, but you don’t have so much chemicals to paint. Your task is to write a program which outputs the area of the emblem for given <i>n</i> so that you can estimate the amount of the needed chemicals. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_triangles"> <p>Figure 1: The Emblem for <i>n</i> = 2</p> </center> <H2>Input</H2> <p> The input data is made of a number of data sets. Each data set is made of one line which contains an integer <i>n</i> between 1 and 1000 inclusive. </p> <p> The input is terminated by a line with <i>n</i> = 0. This line should not be processed. </p> <H2>Output</H2> <p> For each data set, output the area of the emblem on one line. Your program may output an arbitrary number of digits after the decimal point. However, the error should be 10<sup>-6</sup> ( = 0.000001) or less. </p> <H2>Sample Input</H2> <pre> 1 2 3 4 5 6 0 </pre> <H2>Output for the Sample Input</H2> <pre> 0.433013 0.577350 0.433013 0.732051 0.776798 0.577350 </pre>
p04022
<span class="lang-en"> <p>Score : <var>1100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke got positive integers <var>s_1,...,s_N</var> from his mother, as a birthday present. There may be duplicate elements.</p> <p>He will circle some of these <var>N</var> integers. Since he dislikes cubic numbers, he wants to ensure that if both <var>s_i</var> and <var>s_j (i ≠ j)</var> are circled, the product <var>s_is_j</var> is <em>not</em> cubic. For example, when <var>s_1=1,s_2=1,s_3=2,s_4=4</var>, it is not possible to circle both <var>s_1</var> and <var>s_2</var> at the same time. It is not possible to circle both <var>s_3</var> and <var>s_4</var> at the same time, either.</p> <p>Find the maximum number of integers that Snuke can circle.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≩ N ≩ 10^5</var></li> <li><var>1 ≩ s_i ≩ 10^{10}</var></li> <li>All input values are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>s_1</var> : <var>s_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum number of integers that Snuke can circle.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>8 1 2 3 4 5 6 7 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>6 </pre> <p>Snuke can circle <var>1,2,3,5,6,7</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 2 4 8 16 32 64 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>3 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 1 10 100 1000000007 10000000000 1000000009 999999999 999 999 999 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>9 </pre></section> </div> </span>
p00962
<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> <h2>Problem F Pizza Delivery </h2> <p> Alyssa is a college student, living in New Tsukuba City. All the streets in the city are one-way. A new social experiment starting tomorrow is on alternative traffic regulation reversing the one-way directions of street sections. Reversals will be on one single street section between two adjacent intersections for each day; the directions of all the other sections will not change, and the reversal will be canceled on the next day. </p> <p> Alyssa orders a piece of pizza everyday from the same pizzeria. The pizza is delivered along the shortest route from the intersection with the pizzeria to the intersection with Alyssa's house. </p> <p> Altering the traffic regulation may change the shortest route. Please tell Alyssa how the social experiment will affect the pizza delivery route. </p> <h3>Input</h3> <p> The input consists of a single test case in the following format. </p> <pre> $n$ $m$ $a_1$ $b_1$ $c_1$ ... $a_m$ $b_m$ $c_m$ </pre> <p> The first line contains two integers, $n$, the number of intersections, and $m$, the number of street sections in New Tsukuba City ($2 \leq n \leq 100 000, 1 \leq m \leq 100 000$). The intersections are numbered $1$ through $n$ and the street sections are numbered $1$ through $m$. </p> <p> The following $m$ lines contain the information about the street sections, each with three integers $a_i$, $b_i$, and $c_i$ ($1 \leq a_i n, 1 \leq b_i \leq n, a_i \ne b_i, 1 \leq c_i \leq 100 000$). They mean that the street section numbered $i$ connects two intersections with the one-way direction from $a_i$ to $b_i$, which will be reversed on the $i$-th day. The street section has the length of $c_i$. Note that there may be more than one street section connecting the same pair of intersections. </p> <p> The pizzeria is on the intersection 1 and Alyssa's house is on the intersection 2. It is guaranteed that at least one route exists from the pizzeria to Alyssa's before the social experiment starts. </p> <h3>Output</h3> <p> The output should contain $m$ lines. The $i$-th line should be </p> <ul> <li> <span>HAPPY</span> if the shortest route on the $i$-th day will become shorter,</li> <li> <span>SOSO</span> if the length of the shortest route on the $i$-th day will not change, and</li> <li> <span>SAD</span> if the shortest route on the $i$-th day will be longer or if there will be no route from the pizzeria to Alyssa's house.</li> </ul> <p> Alyssa doesn't mind whether the delivery bike can go back to the pizzeria or not. </p> <h3>Sample Input 1</h3> <pre> 4 5 1 3 5 3 4 6 4 2 7 2 1 18 2 3 12 </pre> <h3>Sample Output 1</h3> <pre> SAD SAD SAD SOSO HAPPY </pre> <h3>Sample Input 2</h3> <pre> 7 5 1 3 2 1 6 3 4 2 4 6 2 5 7 5 6 </pre> <h3>Sample Output 2</h3> <pre> SOSO SAD SOSO SAD SOSO </pre> <h3>Sample Input 3</h3> <pre> 10 14 1 7 9 1 8 3 2 8 4 2 6 11 3 7 8 3 4 4 3 2 1 3 2 7 4 8 4 5 6 11 5 8 12 6 10 6 7 10 8 8 3 6 </pre> <h3>Sample Output 3</h3> <pre> SOSO SAD HAPPY SOSO SOSO SOSO SAD SOSO SOSO SOSO SOSO SOSO SOSO SAD </pre>
p01670
<h2>D - Medical Inspection</h2> <h3>Problem Statement</h3> <p> The government has declared a state of emergency due to the MOFU syndrome epidemic in your country. Persons in the country suffer from MOFU syndrome and cannot get out of bed in the morning. You are a programmer working for the Department of Health. You have to take prompt measures. </p> <p> The country consists of <var>n</var> islands numbered from 1 to <var>n</var> and there are ocean liners between some pair of islands. The Department of Health decided to establish the quarantine stations in some islands and restrict an infected person's moves to prevent the expansion of the epidemic. To carry out this plan, there must not be any liner such that there is no quarantine station in both the source and the destination of the liner. The problem is the department can build at most <var>K</var> quarantine stations due to the lack of budget. </p> <p> Your task is to calculate whether this objective is possible or not. And if it is possible, you must calculate the minimum required number of quarantine stations. </p> <h3>Input</h3> <p> The test case starts with a line containing three integers <var>N (2 \leq N \leq 3{,}000)</var>, <var>M (1 \leq M \leq 30{,}000)</var> and <var>K (1 \leq K \leq 32)</var>. Each line in the next <var>M</var> lines contains two integers <var>a_i (1 \leq a_i \leq N)</var> and <var>b_i (1 \leq b_i \leq N)</var>. This represents <var>i</var>-th ocean liner connects island <var>a_i</var> and <var>b_i</var>. You may assume <var>a_i \neq b_i</var> for all <var>i</var>, and there are at most one ocean liner between all the pairs of islands. </p> <h3>Output</h3> <p> If there is no way to build quarantine stations that satisfies the objective, print "Impossible" (without quotes). Otherwise, print the minimum required number of quarantine stations. </p> <h3>Sample Input 1</h3> <pre> 3 3 2 1 2 2 3 3 1 </pre> <h3>Output for the Sample Input 1</h3> <pre> 2 </pre> <h3>Sample Input 2</h3> <pre> 3 3 1 1 2 2 3 3 1 </pre> <h3>Output for the Sample Input 2</h3> <pre> Impossible </pre> <h3>Sample Input 3</h3> <pre> 7 6 5 1 3 2 4 3 5 4 6 5 7 6 2 </pre> <h3>Output for the Sample Input 3</h3> <pre> 4 </pre> <h3>Sample Input 4</h3> <pre> 10 10 10 1 2 1 3 1 4 1 5 2 3 2 4 2 5 3 4 3 5 4 5 </pre> <h3>Output for the Sample Input 4</h3> <pre> 4 </pre>
p00431
<H1></H1> <p> 䞡端にリングの぀いた玐を考える.リングは正敎数が付いおいお,玐を区別する.玐の䞡端のリングには異なる数 <i>a</i>, <i>b</i> が付けられる.これを,[<i>a</i>, <i>b</i>] ず蚘述する.耇数の玐があり,䞀方の玐ず他方の玐のリングに付いおいる数が同じ堎合,そのリングのずころで,これらの玐を぀なげるこずができお,぀なげおできたものを鎖ず呌ぶこずにする.䟋えば,[1, 3] ず [3, 4] ずいう玐からは [1, 3, 4] ずいう鎖ができる.玐ず鎖や鎖同志も同じ敎数が付いおいるリングのずころで぀なげるこずができるものずする. </p> <p> 䟋えば,鎖 [1, 3, 4] ず玐 [5, 1] からは [5, 1, 3, 4] ができ,鎖 [1, 3, 4] ず鎖 [2, 3, 5] からは, 䞭倮でクロスしたような圢になる.鎖 [1, 3, 4] ず鎖 [4, 6, 1] からは, 茪の圢ができる. </p> <p> このように様々な圢ができるが, そのうちの䞀郚で,同じ数の付いたリングは䞀床だけたどる぀ながった耇数の玐を鎖ず呌ぶこずにする.䟋えば,鎖 [1, 3, 4] ず鎖[2, 3, 5] からできる,䞭倮でクロスしたような圢には, [1, 3, 5],[2, 3, 4] ずいう鎖も含たれ,鎖 [1, 3, 4] ず鎖 [4, 6, 1] からできる茪には, [1, 3, 4, 6],[3, 4, 6, 1],[4, 6, 1, 3]などの鎖が含たれる. </p> <p> これらの鎖に察しお,含たれる数の個数を長さず定矩する. 䞎えられた耇数の玐に察しお,぀なげられるものはすべお぀なげるず1぀以䞊の 鎖を含む圢ができる.そのうちの最倧の鎖の長さを求めるプログラムを䜜成せよ. </p> <!-- <p> 入力ファむルのファむル名は “input.txt” である.“input.txt” の最初の行には玐の個数である正敎数 1 &le; <i>n</i> &le; 100 が曞いおあり,぀づく <i>n</i> 行のそれぞれには, 空癜で区切られた 2 ぀の敎数 <i>a</i>, <i>b</i> が曞いおあり 1 &le; <i>a</i> &lt; <i>b</i> &le; 100 ずなっおいる.各行の 2 ぀の敎数は 1 ぀の玐の䞡端の敎数を衚わす. </p> <p> 出力ファむルのファむル名は “output.txt” である.“output.txt” においおは,出力(最倧の鎖の長さ)の埌に改行を入れるこず. </p> --> <p> 入力デヌタ の最初の行には玐の個数である正敎数 1 &le; <i>n</i> &le; 100 が曞いおあり,぀づく <i>n</i> 行のそれぞれには, 空癜で区切られた 2 ぀の敎数 <i>a</i>, <i>b</i> が曞いおあり 1 &le; <i>a</i> &lt; <i>b</i> &le; 100 ずなっおいる.各行の 2 ぀の敎数は 1 ぀の玐の䞡端の敎数を衚わす. </p> <table style="margin-bottom: 28px; margin-left: 28px; margin-right: 0px;"> <tr> <th width="150" align="left">入力䟋</th> <th width="150" align="left">入力䟋</th> <th width="150" align="left">入力䟋</th> </tr> <tr><td></td><td></td></tr> <tr><td>7 </td><td>6 </td><td>7 </td></tr> <tr><td>1 3 </td><td>1 2 </td><td>1 3 </td></tr> <tr><td>3 4 </td><td>2 3 </td><td>2 4 </td></tr> <tr><td>1 4 </td><td>3 4 </td><td>3 5 </td></tr> <tr><td>2 7 </td><td>4 5 </td><td>4 6 </td></tr> <tr><td>5 7 </td><td>1 5 </td><td>6 7 </td></tr> <tr><td>6 7 </td><td>2 6 </td><td>2 6 </td></tr> <tr><td>1 7 </td><td> </td><td>4 7 </td></tr> <tr> <td> </td> </tr> <tr> <th width="150" align="left">出力䟋</th> <th width="150" align="left">出力䟋</th> <th width="150" align="left">出力䟋</th> </tr> <tr><td>5</td><td>6</td><td>4</td></tr> </table> <h3>入力</h3> <p> 入力は耇数のデヌタセットからなるn が 0 のずき入力が終了するデヌタセットの数は 10 を超えない </p> <h3>出力</h3> <p> デヌタセットごずに、最倧の鎖の長さを行に出力する </p> <H2>入力䟋</H2> <pre> 7 1 3 3 4 1 4 2 7 5 7 6 7 1 7 6 1 2 2 3 3 4 4 5 1 5 2 6 7 1 3 2 4 3 5 4 6 6 7 2 6 4 7 0 </pre> <H2>出力䟋</H2> <pre> 5 6 4 </pre> <div class="source"> <p class="source"> 䞊蚘問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p00061
<H1>Rank Checker</H1> <!-- <p> 時は2020 幎。パ゜コン甲子園 2020 の予遞結果を保存したデヌタがありたす。このデヌタには、各チヌムに振られる敎理番号ず正解数が保存されおいたす。参加者チヌム数は䞍明ですが、かなり倚い暡様です䞻催者のささやかな芁望でもありたす。正解数の倚いほうから順に 1 䜍、2 䜍 ... ず順䜍を぀けおいくこずずしたす。 </p> --> <p> 時は2020 幎。パ゜コン甲子園 2020 の予遞結果を保存したデヌタがありたす。このデヌタには、各チヌムに振られる敎理番号ず正解数が保存されおいたす。ここでは、正解数で順䜍を決定するものずし、正解数の倚いほうから順に 1 䜍、2 䜍 ... ず順䜍を぀けおいくこずずしたす。 </p> <p> 予遞結果のデヌタず敎理番号をキヌボヌドから入力しお、その番号のチヌムの順䜍を出力するプログラムを䜜成しおください。 </p> <H2>Input</H2> <p> 入力デヌタは぀の郚分からなりたす。前半の郚分は、予遞結果のデヌタ、埌半の郚分は順䜍を知りたいチヌム番号の問い合わせです。予遞結果のデヌタの圢匏は以䞋の通りです。 </p> <pre> <var>p<sub>1</sub></var>,<var>s<sub>1</sub></var> <var>p<sub>2</sub></var>,<var>s<sub>2</sub></var> ... ... <var>0</var>,<var>0</var> </pre> <p> <var>p<sub>i</sub></var> (1 &le; <var>p<sub>i</sub></var> &le; 100 )、 <var>s<sub>i</sub></var> (0 &le; <var>s<sub>i</sub></var> &le; 30) はそれぞれ <var>i</var> チヌム目の敎理番号ず正解数を衚す敎数です。敎理番号ず正解数がずもに 0 のずきこのデヌタの入力が終わるものずしたす。 </p> <p> 続いお埌半の問い合わせが耇数䞎えられたす。問い合わせの圢匏は以䞋の通りです。 </p> <pre> <var>q<sub>1</sub></var> <var>q<sub>2</sub></var> : </pre> <p> 各問い合わせは行に敎理番号 <var>q<sub>i</sub></var> (1 &le; <var>q<sub>i</sub></var> &le; 30) が䞎えられたす。これを入力の最埌たで凊理しお䞋さい。問い合わせの数は 100 を超えたせん。 </p> <H2>Output</H2> <p> 各問い合わせに぀いお、チヌムの順䜍を行に出力しお䞋さい。 </p> <H2>Sample Input</H2> <pre> 1,20 2,20 3,30 4,10 5,10 6,20 0,0 1 2 4 5 </pre> <H2>Output for the Sample Input</H2> <pre> 2 2 3 3 </pre> <H2>Note</H2> <p> 入力䟋のデヌタにおいお、チヌムを正解数順に敎列するず </p> <pre> 3,30 1,20 2,20 6,20 4,10 5,10 </pre> <p> ずなりたす。ここでは、正解数を基に順䜍を決定するため、30問正解チヌムを1䜍、20問正解チヌムを2䜍、10問正解チヌムを3䜍ずしたす䞊䜍のチヌム数を考慮し、10問正解チヌムを5䜍ずする通垞の順䜍付けずは異なるこずに泚意しお䞋さい。 </p>
p02549
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> cells arranged in a row, numbered <var>1, 2, \ldots, N</var> from left to right.</p> <p>Tak lives in these cells and is currently on Cell <var>1</var>. He is trying to reach Cell <var>N</var> by using the procedure described below.</p> <p>You are given an integer <var>K</var> that is less than or equal to <var>10</var>, and <var>K</var> non-intersecting segments <var>[L_1, R_1], [L_2, R_2], \ldots, [L_K, R_K]</var>. Let <var>S</var> be the union of these <var>K</var> segments. Here, the segment <var>[l, r]</var> denotes the set consisting of all integers <var>i</var> that satisfy <var>l \leq i \leq r</var>.</p> <ul> <li>When you are on Cell <var>i</var>, pick an integer <var>d</var> from <var>S</var> and move to Cell <var>i + d</var>. You cannot move out of the cells.</li> </ul> <p>To help Tak, find the number of ways to go to Cell <var>N</var>, modulo <var>998244353</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 K \leq \min(N, 10)</var></li> <li><var>1 \leq L_i \leq R_i \leq N</var></li> <li><var>[L_i, R_i]</var> and <var>[L_j, R_j]</var> do not intersect (<var>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>K</var> <var>L_1</var> <var>R_1</var> <var>L_2</var> <var>R_2</var> <var>:</var> <var>L_K</var> <var>R_K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of ways for Tak to go from Cell <var>1</var> to Cell <var>N</var>, modulo <var>998244353</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 2 1 1 3 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>The set <var>S</var> is the union of the segment <var>[1, 1]</var> and the segment <var>[3, 4]</var>, therefore <var>S = \{ 1, 3, 4 \}</var> holds.</p> <p>There are <var>4</var> possible ways to get to Cell <var>5</var>:</p> <ul> <li><var>1 \to 2 \to 3 \to 4 \to 5</var>,</li> <li><var>1 \to 2 \to 5</var>,</li> <li><var>1 \to 4 \to 5</var> and</li> <li><var>1 \to 5</var>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 2 3 3 5 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>Because <var>S = \{ 3, 5 \}</var> holds, you cannot reach to Cell <var>5</var>. Print <var>0</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 1 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>5 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>60 3 5 8 1 3 10 15 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>221823067 </pre> <p>Note that you have to print the answer modulo <var>998244353</var>.</p></section> </div> </span>
p00574
<h1>毒蛇の脱走(Snake Escaping)</h1> <p> JOI 研究所では<var>2^L</var> 匹の毒蛇を飌っおおりそれぞれ<var>0, 1, ..., 2^L - 1</var> の番号が付けられおいるすべおの毒蛇は頭から順に<var>L</var> 個の郚分に分かれおおりそれぞれの郚分は青たたは赀である毒蛇<var>i</var> に察し<var>i</var> を2進衚蚘しお<var>i =</var> $\sum_{k=1}^{L}$<var> c_k2^{L-k} (0 \leq c_k \leq 1)</var> ずおいたずき </p> <ul> <li> <var>c_k = 0</var> であれば毒蛇<var>i</var> の頭から数えお<var>k</var> 番目の郚分は青であり</li> <li> <var>c_k = 1</var> であれば毒蛇<var>i</var> の頭から数えお<var>k</var> 番目の郚分は赀である</li> </ul> <p> 各毒蛇には毒性ず呌ばれる0 以䞊9 以䞋の敎数倀が定たっおいる<span>0</span>, <span>1</span>, <span>2</span>, <span>3</span>, <span>4</span>, <span>5</span>, <span>6</span>, <span>7</span>, <span>8</span>, <span>9</span> からなる長さ<var>2^L</var> の文字列<var>S</var> が䞎えられその<var>i</var> 文字目(<var>1 \leq i \leq 2^L</var>) は毒蛇<var>i - 1</var> の毒性を衚す </p> <p> 毒蛇たちの動きは玠早いのでJOI 研究所からはよく毒蛇たちが脱走しおしたうJOI 研究所には脱走した毒蛇を目撃した呚蟺䜏民から苊情が寄せられる </p> <p> あなたには<var>Q</var> 日間にわたる苊情の情報が䞎えられる<var>d</var> 日目(<var>1 \leq d \leq Q</var>) に寄せられた苊情は <span>0</span>, <span>1</span>, <span>?</span>からなる長さ<var>L</var> の文字列<var>T_d</var> ずしお衚され </p> <ul> <li> <var>T_d</var> の<var>j</var> 文字目(<var>1 \leq j \leq L</var>) が<span>0</span> の堎合は<var>d</var> 日目に脱走したすべおの毒蛇の頭から数えお<var>j</var> 番目の郚分が青であるこずを衚し</li> <li> <var>T_d</var> の<var>j</var> 文字目(<var>1 \leq j \leq L</var>) が<span>1</span> の堎合は<var>d</var> 日目に脱走したすべおの毒蛇の頭から数えお<var>j</var> 番目の郚分が赀であるこずを衚し</li> <li> <var>T_d</var> の<var>j</var> 文字目(<var>1 \leq j \leq L</var>) が<span>?</span> の堎合は<var>d</var> 日目に脱走した毒蛇の頭から数えお<var>j</var> 番目の郚分に぀いおは呚蟺䜏民からは情報が䞎えられなかったこずを衚す</li> </ul> <p> 苊情はすべお正確な情報である脱走した毒蛇はJOI 研究所の職員がその日のうちに捕獲する捕獲された毒蛇が翌日以降に再び脱走するこずはあり埗る </p> <p> 毒蛇の脱走によるリスクを芋積もるためにJOI 研究所のK 理事長は脱走した可胜性のある毒蛇の毒性の合蚈を知りたいあなたの仕事は<var>Q</var> 日間にわたる苊情の情報からそれぞれの日ごずにその日に脱走した可胜性のある毒蛇の毒性の合蚈を求めるプログラムを䜜成するこずである </p> <h3>課題</h3> <p> 毒蛇の毒性を衚す文字列<var>S</var> ず<var>Q</var> 日間の苊情の情報が䞎えられるのでそれぞれの日ごずにその日に脱走した可胜性のある毒蛇の毒性の合蚈を求めるプログラムを䜜成せよ </p> <p> メモリ制限が小さいこずに泚意するこず </p> <h3>入力</h3> <p> 暙準入力から以䞋の入力を読み蟌め </p> <ul> <li> 1 行目には敎数<var>L, Q</var> が空癜を区切りずしお曞かれおいるこれらは順に毒蛇の郚分の個数ず苊情の寄せられる日数を衚す </li> <li> 2 行目には長さ<var>2^L</var> の文字列<var>S</var> が曞かれおいるこの文字列は毒蛇の毒性を衚す</li> <li> 続く<var>Q</var> 行のうちの<var>d</var> 行目(<var>1 \leq d \leq Q</var>) には長さ<var>L</var> の文字列<var>T_d</var> が曞かれおいるこの文字列は<var>d</var> 日目の苊情を衚す</li> </ul> <h3>出力</h3> <p> 暙準出力に<var>Q</var> 行で出力せよ<var>d</var> 行目には<var>d</var> 日目に脱走した可胜性のある毒蛇の毒性の合蚈を衚す敎数を出力せよ </p> <h3>制限</h3> <p> すべおの入力デヌタは以䞋の条件を満たす </p> <ul> <li><var> 1 \leq L \leq 20</var></li> <li><var> 1 \leq Q \leq 1 000 000</var></li> <li><var>S</var> は長さ<var>2^L</var> の文字列である</li> <li> 文字列<var>S</var> は<span>0</span>, <span>1</span>, <span>2</span>, <span>3</span>, <span>4</span>, <span>5</span>, <span>6</span>, <span>7</span>, <span>8</span>, <span>9</span> からなる</li> <li> <var>T_d</var> は長さ<var>L</var> の文字列である(<var>1 \leq d \leq Q</var>)</li> <li> 文字列<var>T_d</var> は<span>0</span>, <span>1</span>, <span>?</span> からなる(<var>1 \leq d \leq Q</var>)</li> </ul> <!-- 小課題 小課題1 [5 点] 以䞋の条件を満たす L ≩ 10 Q ≩ 1 000 小課題2 [7 点] L ≩ 10 を満たす 小課題3 [10 点] L ≩ 13 を満たす 小課題4 [53 点] Q ≩ 50 000 を満たす 小課題5 [25 点] 远加の制限はない --> <h3>入出力䟋</h3> <h3>入力䟋1 </h3> <pre> 3 5 12345678 000 0?? 1?0 ?11 ??? </pre> <h3>出力䟋1</h3> <pre> 1 10 12 12 36 </pre> <p> この入力䟋では<var>L = 3</var> である3 ぀の郚分に分かれた毒蛇が党郚で<var>2^3 = 8</var> 匹いる苊情は5 日間にわたっお寄せられる </p> <ul> <li> 1 日目に脱走した可胜性のある毒蛇は毒蛇0 のみである毒性の合蚈は1 である</li> <li> 2 日目に脱走した可胜性のある毒蛇は毒蛇0, 1, 2, 3 である毒性の合蚈は10 である</li> <li> 3 日目に脱走した可胜性のある毒蛇は毒蛇4, 6 である毒性の合蚈は12 である</li> <li> 4 日目に脱走した可胜性のある毒蛇は毒蛇3, 7 である毒性の合蚈は12 である</li> <li> 5 日目に脱走した可胜性のある毒蛇は毒蛇0, 1, 2, 3, 4, 5, 6, 7 である毒性の合蚈は36 である</li> </ul> <h3>入力䟋2</h3> <pre> 4 8 3141592653589793 0101 ?01? ??1? ?0?? 1?00 01?1 ??10 ???? </pre> <h3>出力䟋2</h3> <pre> 9 18 38 30 14 15 20 80 </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/2017/2018-ho/index.html">情報オリンピック日本委員䌚䜜 『第17 回日本情報オリンピック(JOI 2017/2018) 本遞』</a> </p>
p02119
<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>Problem I: Making Pairs</h1> <h2>Problem</h2> <p>本日、぀いに完党招埅制の高玚レストラン「マむヅレストラン」がオヌプンした。新たな䌚員を招埅する暩利を持぀のはこのレストランの䌚員のみで、最初、䌚員は䌚員番号0であるレストランのオヌナヌのみである。</p> <p>マむヅレストランはその高玚さ故、オヌプン初日から$N$日間しか開かれない。その期間䞭、毎日䌚員のうち誰か䞀人が、自分の友人を䞀人だけ新たに䌚員ずしお招埅する。$i$日目に招埅された䌚員には䌚員番号$i$が割り圓おられ、その䌚員は招埅された日を含めそれ以降毎日来店する。</p> <p>このレストランには二人甚テヌブルしか存圚しないので、䌚員の人々はできるだけペアでテヌブルを䜿甚しお食事をする。食事にはオヌナヌも参加するので、他の䌚員はオヌナヌずペアを組むこずもできる。しかし、䌚員の人々は皆人芋知りであり、自分を招埅した友人か、自分が招埅した友人ずしかペアを組みたがらない。各䌚員はもし友人ずペアを組めなかった堎合、䞀人寂しく食事をする。</p> <p>$N$日間の各日に぀いお、友人どうしのペアの数が最倧ずなるようにペアを組んだずき、いく぀のペアができるか求めよ。</p> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる。</p> <p> $N$<br> $p_1$<br> $p_2$<br> ...<br> $p_N$<br> </p> <p> 1行目にレストランが開かれる日数$N$が䞎えられる。<br> 続く$N$行に、䌚員番号が$i$の䌚員を招埅した䌚員の䌚員番号$p_i$が䞎えられる。<br> </p> <h2>Constraints</h2> <p>入力は以䞋の条件を満たす。</p> <ul> <li>$1 \leq N \leq 5000$</li> <li>$0 \leq p_i \leq i-1$ ($1 \leq i \leq N$)</li> <li>$N$, $p_i$は敎数</li> </ul> <h2>Output</h2> <p> 出力は$N$行からなる。<br> $i$行目には、$i$日目に䜜るこずのできる友人どうしのペアの最倧数を出力する。 ($1 \leq i \leq N$)</p> <h2>Sample Input 1</h2> <pre> 3 0 0 2 </pre> <h2>Sample Output 1</h2> <pre> 1 1 2 </pre> <h2>Sample Input 2</h2> <pre> 5 0 1 2 3 4 </pre> <h2>Sample Output 2</h2> <pre> 1 1 2 2 3 </pre>
p00124
<h1>リヌグ戊のスコアシヌト</h1> <p> スポヌツの倧䌚にはリヌグ戊ずトヌナメント戊がありたす。サッカヌのリヌグ戊では勝・負・匕分にそれぞれ点数を付け、その勝ち点で順䜍を競いたす。勝ち点はそれぞれ勝(3点)、負(0点)、匕分(1点)です。 </p> <p> チヌム数ずリヌグ戊の成瞟を入力ずし、成瞟の良い順(勝ち点の倚い順)に䞊べ替え、チヌム名ず勝ち点を出力するプログラムを䜜成しおください。勝ち点が同点の堎合は入力順に出力しおください。 </p> <H2>Input</H2> <p> 耇数のデヌタセットが䞎えられたす。各デヌタセットは以䞋の圢匏で䞎えられたす。 </p> <pre> <var>n</var> <var>name<sub>1</sub></var> <var>w<sub>1</sub></var> <var>l<sub>1</sub></var> <var>d<sub>1</sub></var> <var>name<sub>2</sub></var> <var>w<sub>2</sub></var> <var>l<sub>2</sub></var> <var>d<sub>2</sub></var> : <var>name<sub>n</sub></var> <var>w<sub>n</sub></var> <var>l<sub>n</sub></var> <var>d<sub>n</sub></var> </pre> <p> 行目にチヌム数 <var>n</var> (<var>n</var> &le; 10) が䞎えられたす。続く <var>n</var> 行にチヌム <var>i</var> の名前 <var>name<sub>i</sub></var> (20文字以内のアルファベット)、勝の数 <var>w<sub>i</sub></var>、負の数 <var>l<sub>i</sub></var>、匕分の数 <var>d<sub>i</sub></var> (0 &le; <var>w<sub>i</sub></var>, <var>l<sub>i</sub></var>, <var>d<sub>i</sub></var> &le; 9) が空癜区切りで䞎えられたす。 </p> <p> チヌム数が 0 のずき、入力の終了ずしたす。デヌタセットの数は 50 を超えたせん。 </p> <H2>Output</H2> <p> デヌタセットごずに、䞊べ替えたチヌムのリストを出力しおください。<var>i</var> 行目に <var>i</var> 番目のチヌムの名前ず勝ち点をカンマで区切っお出力しおください。 </p> <p> デヌタセットの間に぀の空行を入れおください。 </p> <H2>Sample Input</H2> <pre> 4 Japan 1 0 2 Egypt 1 2 0 Canada 0 2 1 Spain 2 0 1 3 India 0 2 0 Poland 1 0 1 Italy 1 0 1 0 </pre> <H2>Output for the Sample Input</H2> <pre> Spain,7 Japan,5 Egypt,3 Canada,1 Poland,4 Italy,4 India,0 </pre>
p01365
<H1><font color="#000">Problem G:</font> Camera Control</H1> <p> "ACM48" is one of the most popular dance vocal units in Japan. In this winter, ACM48 is planning a world concert tour. You joined the tour as a camera engineer. </p> <p> Your role is to develop software which controls the camera on a stage. For simplicity you can regard the stage as 2-dimensional space. You can rotate the camera to an arbitrary direction by the software but cannot change its coordinate. </p> <p> During a stage performance, each member of ACM48 moves along her route and sings the part(s) assigned to her. Here, a route is given as a polygonal line. </p> <p> You have to keep focusing the camera on a member during a stage performance. You can change the member focused by the camera if and only if the current and next members are in the same direction from the camera. </p> <p> Your task is to write a program which reads the stage performance plan and calculates the maximum time that you can focus the camera on members that are singing. </p> <p> You may assume the following are satisfied: </p> <ul> <li> You can focus the camera on an arbitrary member at the beginning time.</li> <li> Each route of the member does not touch the camera.</li> <li> Each member stays at the last coordinates after she reaches there.</li> </ul> <H2>Input</H2> <p> The input contains multiple test cases. Each test case has the following format: </p> <p> <i>N</i><br> <i>c<sub>x</sub> c<sub>y</sub></i><br> The information of the 1-st member<br> .<br> .<br> .<br> The information of the <i>N</i>-th member<br> </p> <p> <i>N</i> (1 &le; <i>N</i> &le; 50) is the number of the members. (<i>c<sub>x</sub></i>, <i>c<sub>y</sub></i>) is the coordinates of the camera. Then the information of the <i>N</i> members follow. </p> <p> The information of the <i>i</i>-th member has the following format: </p> <p> <i>M<sub>i</sub></i><br> <i>x</i><sub><i>i</i>,1</sub> <i>y</i><sub><i>i</i>,1</sub> <i>t</i><sub><i>i</i>,1</sub><br> .<br> .<br> .<br> <i>x</i><sub><i>i</i>,<i>M<sub>i</sub></i></sub> <i>y</i><sub><i>i</i>,<i>M<sub>i</sub></i></sub> <i>t</i><sub><i>i</i>,<i>M<sub>i</sub></i></sub> <br> <i>L<sub>i</sub></i><br> <i>b</i><sub><i>i</i>,1</sub> <i>e</i><sub><i>i</i>,1</sub><br> .<br> .<br> .<br> <i>b</i><sub><i>i</i>,<i>L<sub>i</sub></i></sub> <i>e</i><sub><i>i</i>,<i>L<sub>i</sub></i></sub> <br> </p> <p> <i>M<sub>i</sub></i> (1 &le; <i>M<sub>i</sub></i> &le; 100) is the number of the points in the route. (<i>x<sub>i,j</sub></i>, <i>y<sub>i,j</sub></i> ) is the coordinates of the <i>j</i>-th in the route. <i>t<sub>i,j</sub></i> (0 = <i>t</i><sub><i>i</i>,0</sub> &lt; <i>t</i><sub><i>i</i>,<i>j</i></sub> &lt; <i>t</i><sub><i>i</i>,<i>j</i>+1</sub> &le; 10<sup>3</sup> for 0 &lt; <i>j</i>) is the time that the <i>i</i>-th member reaches the <i>j</i>-th coordinates. <i>L<sub>i</sub></i> (0 &le; <i>L<sub>i</sub></i> &le; 100) is the number of the vocal part. <i>b<sub>i,k</sub></i> and <i>e<sub>i,k</sub></i> (0 &le; <i>b<sub>i,k</sub></i> &lt; <i>e<sub>i,k</sub></i> &lt; <i>b</i><sub><i>i</i>,<i>k</i>+1</sub> &lt; <i>e</i><sub><i>i</i>,<i>k</i>+1</sub> &le; 10<sup>3</sup> ) are the beginning and the ending time of the <i>k</i>-th vocal part, respectively. </p> <p> All the input values are integers. You may assume that the absolute of all the coordinates are not more than 10<sup>3</sup> . </p> <p> <i>N</i> = 0 denotes the end of the input. You may not process this as a test case. </p> <H2>Output</H2> <p> For each dataset, print the maximum time that you can focus the camera on singing members with an absolute error of at most 10<sup>-6</sup>. You may output any number of digits after the decimal point. </p> <H2>Sample Input</H2> <pre> 2 0 0 2 -5 5 0 5 5 10 1 0 6 2 5 5 0 -5 5 10 1 6 10 1 7 -65 2 -65 10 0 65 1 3 2 0 1 23 24 2 0 0 2 100 10 0 -10 10 10 5 0 1 2 3 4 5 6 7 8 9 2 10 0 0 0 10 10 5 1 2 3 4 5 6 7 8 9 10 0 </pre> <H2>Output for the Sample Input</H2> <pre> 9.00000000 2.00000000 5.98862017 </pre>
p03358
<span class="lang-en"> <p>Score : <var>800</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a tree with <var>N</var> vertices numbered <var>1</var> through <var>N</var>. The <var>i</var>-th edge connects Vertex <var>x_i</var> and <var>y_i</var>. Each vertex is painted white or black. The initial color of Vertex <var>i</var> is represented by a letter <var>c_i</var>. <var>c_i</var> <var>=</var> <code>W</code> represents the vertex is white; <var>c_i</var> <var>=</var> <code>B</code> represents the vertex is black.</p> <p>A cat will walk along this tree. More specifically, she performs one of the following in one second repeatedly:</p> <ul> <li>Choose a vertex that is adjacent to the vertex where she is currently, and move to that vertex. Then, invert the color of the destination vertex.</li> <li>Invert the color of the vertex where she is currently.</li> </ul> <p>The cat's objective is to paint all the vertices black. She may start and end performing actions at any vertex. At least how many seconds does it takes for the cat to achieve her objective?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1</var> <var>≀</var> <var>N</var> <var>≀</var> <var>10^5</var></li> <li><var>1</var> <var>≀</var> <var>x_i,y_i</var> <var>≀</var> <var>N</var> (<var>1</var> <var>≀</var> <var>i</var> <var>≀</var> <var>N-1</var>)</li> <li>The given graph is a tree.</li> <li><var>c_i</var> <var>=</var> <code>W</code> or <var>c_i</var> <var>=</var> <code>B</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>x_1</var> <var>y_1</var> <var>x_2</var> <var>y_2</var> <var>:</var> <var>x_{N-1}</var> <var>y_{N-1}</var> <var>c_1c_2..c_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum number of seconds required to achieve the objective.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 1 2 2 3 2 4 4 5 WBBWW </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5 </pre> <p>The objective can be achieved in five seconds, for example, as follows:</p> <ul> <li>Start at Vertex <var>1</var>. Change the color of Vertex <var>1</var> to black.</li> <li>Move to Vertex <var>2</var>, then change the color of Vertex <var>2</var> to white.</li> <li>Change the color of Vertex <var>2</var> to black.</li> <li>Move to Vertex <var>4</var>, then change the color of Vertex <var>4</var> to black.</li> <li>Move to Vertex <var>5</var>, then change the color of Vertex <var>5</var> to black.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 3 1 4 5 2 6 6 1 3 4 WWBWBB </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>7 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 B </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>20 2 19 5 13 6 4 15 6 12 19 13 19 3 11 8 3 3 20 16 13 7 14 3 17 7 8 10 20 11 9 8 18 8 2 10 1 6 13 WBWBWBBWWWBBWWBBBBBW </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>21 </pre></section> </div> </span>
p00827
<H1><font color="#000">Problem A:</font> The Balance</H1> <p> Ms. Iyo Kiffa-Australis has a balance and only two kinds of weights to measure a dose of medicine. </p> <p> For example, to measure 200mg of aspirin using 300mg weights and 700mg weights, she can put one 700mg weight on the side of the medicine and three 300mg weights on the opposite side (Figure 1). Although she could put four 300mg weights on the medicine side and two 700mg weights on the other (Figure 2), she would not choose this solution because it is less convenient to use more weights. </p> <p> You are asked to help her by calculating how many weights are required. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_theBalance1"> <p>Figure 1: To measure 200mg of aspirin using three 300mg weights and one 700mg weight</p> </center> <br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_theBalance2"> <p>Figure 2: To measure 200mg of aspirin using four 300mg weights and two 700mg weights</p> </center> <H2>Input</H2> <p> The input is a sequence of datasets. A dataset is a line containing three positive integers <i>a</i>, <i>b</i>, and <i>d</i> separated by a space. The following relations hold: <i>a</i> &ne; <i>b</i>, <i>a</i> &le; 10000, <i>b</i> &le; 10000, and <i>d</i> &le; 50000. You may assume that it is possible to measure <i>d</i> mg using a combination of <i>a</i> mg and <i>b</i> mg weights. In other words, you need not consider “no solution” cases. </p> <p> The end of the input is indicated by a line containing three zeros separated by a space. It is not a dataset. </p> <H2>Output</H2> <p> The output should be composed of lines, each corresponding to an input dataset (<i>a</i>, <i>b</i>, <i>d</i>). An output line should contain two nonnegative integers <i>x</i> and <i>y</i> separated by a space. They should satisfy the following three conditions. </p> <ul> <li> You can measure <i>d</i> mg using <i>x</i> many <i>a</i> mg weights and <i>y</i> many <i>b</i> mg weights.</li> <li> The total number of weights (<i>x</i> + <i>y</i>) is the smallest among those pairs of nonnegative integers satisfying the previous condition.</li> <li> The total mass of weights (<i>ax</i> + <i>by</i>) is the smallest among those pairs of nonnegative integers satisfying the previous two conditions.</li> </ul> <p> No extra characters (e.g. extra spaces) should appear in the output. </p> <H2>Sample Input</H2> <pre> 700 300 200 500 200 300 500 200 500 275 110 330 275 110 385 648 375 4002 3 1 10000 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 1 3 1 1 1 0 0 3 1 1 49 74 3333 1 </pre>
p01735
<p> Fox Ciel is developing an artificial intelligence (AI) for a game. This game is described as a game tree T with n vertices. Each node in the game has an evaluation value which shows how good a situation is. This value is the same as maximum value of child nodes’ values multiplied by -1. Values on leaf nodes are evaluated with Ciel’s special function -- which is a bit heavy. So, she will use alpha-beta pruning for getting root node’s evaluation value to decrease the number of leaf nodes to be calculated. </p> <p> By the way, changing evaluation order of child nodes affects the number of calculation on the leaf nodes. Therefore, Ciel wants to know the minimum and maximum number of times to calculate in leaf nodes when she could evaluate child node in arbitrary order. She asked you to calculate minimum evaluation number of times and maximum evaluation number of times in leaf nodes. </p> <p> Ciel uses following algotithm: </p> <pre> function negamax(node, &alpha;, &beta;) if node is a terminal node return value of leaf node else foreach child of node val := -negamax(child, -&beta;, -&alpha;) if val >= &beta; return val if val > &alpha; &alpha; := val return &alpha; </pre> <p> [NOTE] <a href="http://en.wikipedia.org/wiki/Negamax">negamax algorithm</a> </p> <h3>Input</h3> <p>Input follows following format:</p> <pre> <var>n</var> <var>p_1</var> <var>p_2</var> ... <var>p_n</var> <var>k_1</var> <var>t_{11}</var> <var>t_{12}</var> ... <var>t_{1k}</var> : : <var>k_n</var> <var>t_{n1}</var> <var>t_{n2}</var> ... <var>t_{nk}</var> </pre> <p>The first line contains an integer <var>n</var>, which means the number of vertices in game tree T.<br> The second line contains <var>n</var> integers <var>p_i</var>, which means the evaluation value of vertex <var>i</var>.<br> Then, next <var>n</var> lines which contain the information of game tree T.<br> <var>k_i</var> is the number of child nodes of vertex <var>i</var>, and <var>t_{ij}</var> is the indices of the child node of vertex <var>i</var>.<br> Input follows following constraints: </p> <ul><li> <var>2 \leq n \leq 100</var> </li><li> <var>-10,000 \leq p_i \leq 10,000</var> </li><li> <var>0 \leq k_i \leq 5</var> </li><li> <var>2 \leq t_{ij} \leq n</var> </li><li> Index of root node is <var>1</var>. </li><li> Evaluation value except leaf node is always <var>0</var>. This does not mean the evaluation values of non-leaf nodes are <var>0</var>. You have to calculate them if necessary. </li><li> Leaf node sometimes have evaluation value of <var>0</var>. </li><li> Game tree T is tree structure. </li></ul> <h3>Output</h3> <p>Print the minimum evaluation number of times and the maximum evaluation number of times in leaf node.<br> Please separated by whitespace between minimum and maximum. </p><pre> minimum maximum</pre> <h3>Sample Input 1</h3> <pre>3 0 1 1 2 2 3 0 0 </pre> <h3>Output for the Sample Input 1</h3> <pre>2 2 </pre> <h3>Sample Input 2</h3> <pre>8 0 0 100 100 0 -100 -100 -100 2 2 5 2 3 4 0 0 3 6 7 8 0 0 0 </pre> <h3>Output for the Sample Input 2</h3> <pre>3 5 </pre> <h3>Sample Input 3</h3> <pre>8 0 0 100 100 0 100 100 100 2 2 5 2 3 4 0 0 3 6 7 8 0 0 0 </pre> <h3>Output for the Sample Input 3</h3> <pre>3 4 </pre> <h3>Sample Input 4</h3> <pre>19 0 100 0 100 0 0 0 0 0 1 2 3 4 5 6 7 8 9 10 2 2 3 0 2 4 5 0 3 6 7 8 3 9 10 11 3 12 13 14 3 15 16 17 2 18 19 0 0 0 0 0 0 0 0 0 0 </pre> <h3>Output for the Sample Input 4</h3> <pre>7 12 </pre> </div> </div>
p03708
<span class="lang-en"> <p>Score : <var>900</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Nukes has an integer that can be represented as the bitwise OR of one or more integers between <var>A</var> and <var>B</var> (inclusive). How many possible candidates of the value of Nukes's integer there are?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ A ≀ B &lt; 2^{60}</var></li> <li><var>A</var> and <var>B</var> are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>A</var> <var>B</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of possible candidates of the value of Nukes's integer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>7 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>In this case, <var>A=7</var> and <var>B=9</var>. There are four integers that can be represented as the bitwise OR of a non-empty subset of {<var>7</var>, <var>8</var>, <var>9</var>}: <var>7</var>, <var>8</var>, <var>9</var> and <var>15</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>65 98 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>63 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>271828182845904523 314159265358979323 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>68833183630578410 </pre></section> </div> </span>
p03026
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a tree with <var>N</var> vertices <var>1,2,\ldots,N</var>, and positive integers <var>c_1,c_2,\ldots,c_N</var>. The <var>i</var>-th edge in the tree <var>(1 \leq i \leq N-1)</var> connects Vertex <var>a_i</var> and Vertex <var>b_i</var>.</p> <p>We will write a positive integer on each vertex in <var>T</var> and calculate our <em>score</em> as follows:</p> <ul> <li>On each edge, write the smaller of the integers written on the two endpoints.</li> <li>Let our score be the sum of the integers written on all the edges.</li> </ul> <p>Find the maximum possible score when we write each of <var>c_1,c_2,\ldots,c_N</var> on one vertex in <var>T</var>, and show one way to achieve it. If an integer occurs multiple times in <var>c_1,c_2,\ldots,c_N</var>, we must use it that number of times.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 10000</var></li> <li><var>1 \leq a_i,b_i \leq N</var></li> <li><var>1 \leq c_i \leq 10^5</var></li> <li>The given graph is a tree.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>a_1</var> <var>b_1</var> <var>:</var> <var>a_{N-1}</var> <var>b_{N-1}</var> <var>c_1</var> <var>\ldots</var> <var>c_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Use the following format:</p> <pre><var>M</var> <var>d_1</var> <var>\ldots</var> <var>d_N</var> </pre> <p>where <var>M</var> is the maximum possible score, and <var>d_i</var> is the integer to write on Vertex <var>i</var>. <var>d_1,d_2,\ldots,d_N</var> must be a permutation of <var>c_1,c_2,\ldots,c_N</var>. If there are multiple ways to achieve the maximum score, any of them will be accepted.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 1 2 2 3 3 4 4 5 1 2 3 4 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>10 1 2 3 4 5 </pre> <p>If we write <var>1,2,3,4,5</var> on Vertex <var>1,2,3,4,5</var>, respectively, the integers written on the four edges will be <var>1,2,3,4</var>, for the score of <var>10</var>. This is the maximum possible score.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 1 2 1 3 1 4 1 5 3141 59 26 53 59 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>197 59 26 3141 59 53 </pre> <p><var>c_1,c_2,\ldots,c_N</var> may not be pairwise distinct.</p></section> </div> </span>
p03476
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We say that a odd number <var>N</var> is <em>similar to 2017</em> when both <var>N</var> and <var>(N+1)/2</var> are prime.</p> <p>You are given <var>Q</var> queries.</p> <p>In the <var>i</var>-th query, given two odd numbers <var>l_i</var> and <var>r_i</var>, find the number of odd numbers <var>x</var> similar to 2017 such that <var>l_i ≀ x ≀ r_i</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≀Q≀10^5</var></li> <li><var>1≀l_i≀r_i≀10^5</var></li> <li><var>l_i</var> and <var>r_i</var> are odd.</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>Q</var> <var>l_1</var> <var>r_1</var> <var>:</var> <var>l_Q</var> <var>r_Q</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>Q</var> lines. The <var>i</var>-th line <var>(1≀i≀Q)</var> should contain the response to the <var>i</var>-th query.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>1 3 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <ul> <li><var>3</var> is similar to 2017, since both <var>3</var> and <var>(3+1)/2=2</var> are prime.</li> <li><var>5</var> is similar to 2017, since both <var>5</var> and <var>(5+1)/2=3</var> are prime.</li> <li><var>7</var> is not similar to 2017, since <var>(7+1)/2=4</var> is not prime, although <var>7</var> is prime.</li> </ul> <p>Thus, the response to the first query should be <var>2</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 13 13 7 11 7 11 2017 2017 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 0 0 1 </pre> <p>Note that <var>2017</var> is also similar to 2017.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>6 1 53 13 91 37 55 19 51 73 91 13 49 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>4 4 1 1 1 2 </pre></section> </div> </span>
p02637
<span class="lang-en"> <p>Score : <var>1500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given are an integer <var>K</var> and integers <var>a_1,\dots, a_K</var>. Determine whether a sequence <var>P</var> satisfying below exists. If it exists, find the lexicographically smallest such sequence.</p> <ul> <li>Every term in <var>P</var> is an integer between <var>1</var> and <var>K</var> (inclusive).</li> <li>For each <var>i=1,\dots, K</var>, <var>P</var> contains <var>a_i</var> occurrences of <var>i</var>.</li> <li>For each term in <var>P</var>, there is a contiguous subsequence of length <var>K</var> that contains that term and is a permutation of <var>1,\dots, K</var>.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq K \leq 100</var></li> <li><var>1 \leq a_i \leq 1000 \quad (1\leq i\leq K)</var></li> <li><var>a_1 + \dots + a_K\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>K</var> <var>a_1</var> <var>a_2</var> <var>\dots</var> <var>a_K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If there is no sequence satisfying the conditions, print <code>-1</code>. Otherwise, print the lexicographically smallest sequence satisfying the conditions.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 4 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 1 3 2 2 3 1 2 3 </pre> <p>For example, the fifth term, which is <var>2</var>, is in the subsequence <var>(2, 3, 1)</var> composed of the fifth, sixth, and seventh terms.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 3 2 3 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 2 3 4 1 3 1 2 4 3 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 3 1 4 1 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>-1 </pre></section> </div> </span>
p03925
<span class="lang-en"> <p>Score : <var>1300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a graph with <var>N</var> vertices, numbered <var>0</var> through <var>N-1</var>. Edges are yet to be added.</p> <p>We will process <var>Q</var> queries to add edges. In the <var>i</var>-th <var>(1≩i≩Q)</var> query, three integers <var>A_i, B_i</var> and <var>C_i</var> will be given, and we will add infinitely many edges to the graph as follows:</p> <ul> <li>The two vertices numbered <var>A_i</var> and <var>B_i</var> will be connected by an edge with a weight of <var>C_i</var>.</li> <li>The two vertices numbered <var>B_i</var> and <var>A_i+1</var> will be connected by an edge with a weight of <var>C_i+1</var>.</li> <li>The two vertices numbered <var>A_i+1</var> and <var>B_i+1</var> will be connected by an edge with a weight of <var>C_i+2</var>.</li> <li>The two vertices numbered <var>B_i+1</var> and <var>A_i+2</var> will be connected by an edge with a weight of <var>C_i+3</var>.</li> <li>The two vertices numbered <var>A_i+2</var> and <var>B_i+2</var> will be connected by an edge with a weight of <var>C_i+4</var>.</li> <li>The two vertices numbered <var>B_i+2</var> and <var>A_i+3</var> will be connected by an edge with a weight of <var>C_i+5</var>.</li> <li>The two vertices numbered <var>A_i+3</var> and <var>B_i+3</var> will be connected by an edge with a weight of <var>C_i+6</var>.</li> <li>...</li> </ul> <p>Here, consider the indices of the vertices modulo <var>N</var>. For example, the vertice numbered <var>N</var> is the one numbered <var>0</var>, and the vertice numbered <var>2N-1</var> is the one numbered <var>N-1</var>.</p> <p>The figure below shows the first seven edges added when <var>N=16, A_i=7, B_i=14, C_i=1</var>:</p> <p><img alt="" src="https://atcoder.jp/img/code-festival-2016-final/5b0258fb4255f846a4e10ce875362baf.png"/></p> <p>After processing all the queries, find the total weight of the edges contained in a minimum spanning tree of the graph.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≩N≩200,000</var></li> <li><var>1≩Q≩200,000</var></li> <li><var>0≩A_i,B_i≩N-1</var></li> <li><var>1≩C_i≩10^9</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>Q</var> <var>A_1</var> <var>B_1</var> <var>C_1</var> <var>A_2</var> <var>B_2</var> <var>C_2</var> : <var>A_Q</var> <var>B_Q</var> <var>C_Q</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the total weight of the edges contained in a minimum spanning tree of the graph.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>7 1 5 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>21 </pre> <p>The figure below shows the minimum spanning tree of the graph:</p> <p><img alt="" src="https://atcoder.jp/img/code-festival-2016-final/f1a6c3cfd52c386e6da5c8c761a78521.png"/></p> <p>Note that there can be multiple edges connecting the same pair of vertices.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 1 0 0 1000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1000000001 </pre> <p>Also note that there can be self-loops.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 3 0 1 10 0 2 10 0 4 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>42 </pre></section> </div> </span>
p01918
<link rel="stylesheet" href="css/description.css" type="text/css" /> <script language="JavaScript" type="text/javascript" src="js/varmath2017.js" charset="UTF-8"></script> <h2>C: 今川焌きマン - Imagawayaki Man -</h2> <h3>物語</h3> <p>今川焌きマンは、正矩のヒヌロヌである。顔は盎埄 <var>1</var> メヌトルの今川焌き䞻に小麊粉でできた生地の䞭にたっぷりず逡を詰めお焌いた食べ物であり、芋た目は円圢であり、矎味しい。北海道では、単に「お焌き」ず呌ばれるこずも倚い。逡ずしお小豆逡のほかに、カスタヌドクリヌムなどを甚いるこずもあり、さたざたな味のバリ゚ヌションがある。そのため、いく぀食べおも飜きない。小豆逡やカスタヌドクリヌムのほかに、抹茶逡やりんごゞャムなども矎味しい。䞭にタコを入れたたこ焌きのようなものもあるようだ。どの味も矎味しい。䞋の写真は暙準的な今川焌きである。巊はクリヌム逡、右は小豆逡が入っおいる。矎味しそうである。実際に食べお芋たずころ、やはり矎味しかった。ずころで、今川焌きの盎埄は通垞 <var>10</var> センチメヌトル皋床であるので、盎埄 <var>1</var> メヌトルの今川焌きはかなり倧きなものであるこずに泚意されよ。でできおおり、お腹の空いた者に自分の顔を分けお差し出すこずもある。そのため、必芁に応じお顔を取り替える必芁がある。い぀でも取り替えられるように、今川焌き工堎でおじさんが䞀人でせっせず䞀぀ず぀今川焌きを焌いお日々備えおいる。</p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RitsCamp17Day3_HUPC2017_imagawayaki" type="image/jpeg" width="300"></img> <p>ずころで、今川焌きは食品であるため、圓然ながら賞味期限が存圚する。無駄にしないためには、焌いおから時間が経ったものから順に䜿うこずが望たしい。おじさんは䞋図のように、完成した盎埄 <var>1</var> メヌトルの今川焌き (図䞭の狐色郚) を幅 <var>1</var> メヌトルのレヌン (図䞭の灰色郚) の䞊に隙間なく䞊べお保存しおいる。</p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_RitsCamp17Day3_HUPC2017_lane" type="image/png" width="300"></img> <p>ある日、倧悪党の背筋マンが工堎に珟れ、今川焌きマンを困らせようず、自慢の背筋力を䜿っお巚倧な今川焌きをせっせず運び、奜き勝手に䞊び替えおしたった。背筋マンは背筋力だけでなく蚘憶力も良いので、どの今川焌きが元々䜕番目にあったのか芚えおいるようだ。負けを認めたくない今川焌きマンは、䜕ずかしお、それぞれの今川焌きが䜕番目に出来たおなのか知りたいが、芋た目では分かりそうにない。そこで、背筋マンに「もちろん、僕はちゃんず芚えおいるよ。でも、背筋マンは本圓にちゃんず芚えおいるのかな」ず挑発し、さらに「本圓に芚えおいるか僕がテストするよ」ず蚀っお質問を繰り返すこずで、䜕番目に出来たおなのか知るこずにした。ただし、あたり質問しすぎるず、探っおいるこずを勘付かれおしたうので、ほどほどにしなければならない。あなたには、今川焌きマンを助けるため、質問を繰り返し生成し、それぞれの今川焌きが䜕番目に出来たおなのかを圓おるプログラムを䜜成しおほしい。</p> <h3>問題</h3> <p>たず、工堎に䞊んでいる今川焌きの個数 <var>N</var> (<var>1 \leq N \leq 10,000</var>) が暙準入力により1行で䞎えられる。これらの今川焌きの補造日時は互いに異なる。぀たり、 <var>1 \leq i \leq N</var> を満たす任意の敎数 <var>i</var> に぀いお、 <var>i</var> 番目に出来たおの今川焌きはただひず぀存圚する。</p> <p>これ以降、任意の2敎数 <var>a</var>, <var>b</var> (<var>1 \leq a, b \leq N</var>) においお、暙準出力に</p> <pre>? <var>a</var> <var>b</var></pre> <p>ず出力するず、「<var>a</var> 番目に出来たおの今川焌きの䞭心から <var>b</var> 番目に出来たおの今川焌きの䞭心たでの距離は䜕メヌトルか」ずいう質問を行うこずができる。この答えは暙準入力に䞀行で敎数ずしおすぐに䞎えられる。物語でも述べた通り、レヌン䞊に隙間なく盎埄 <var>1</var> メヌトルの今川焌きが䞊べられおいるので、巊から数えお <var>i</var> 番目の今川焌きの䞭心から <var>j</var> 番目の今川焌きの䞭心たでの距離は正確に <var>|i - j|</var> メヌトルである。この質問は <var>20,000</var> 回たで繰り返し行うこずができる。</p> <p>それぞれの今川焌きが䜕番目に出来たおなのか分かったら、暙準出力に最終的な答えを出力しなければならない。出力圢匏は、各 <var>i</var> (<var> 1 \leq i \leq N</var>) においお、巊から <var>i</var> 番目 の今川焌きが <var>x_i</var> 番目に出来たおのずき、</p> <pre>! <var>x_1</var> <var>x_2</var> <var>x_3</var> ... <var>x_N</var></pre> <p>たたは、</p> <pre>! <var>x_N</var> <var>x_{N-1}</var> <var>x_{N-2}</var> ... <var>x_1</var></pre> <p>ずすればよい。぀たり、巊から順に答えおも、右から順に答えおも構わない。この最終的な解答は、1床しか行うこずができない。この解答が正しい出力だったずき、正答ずみなす。</p> <p>暙準出力を行う毎に、ストリヌムをフラッシュ (flush) する必芁があるこずに泚意されよ。䞻芁な蚀語でのフラッシュ䟋を以䞋に瀺す。もちろん、これ以倖の方法でフラッシュを行っおも構わない。</p> <p>C 蚀語:</p> <pre> #include &lt;stdio.h&gt; fflush(stdout); </pre> <p>C++:</p> <pre> #include &lt;iostream&gt; std::cout.flush(); </pre> <p>Java:</p> <pre>System.out.flush();</pre> <h3>入出力䟋</h3> <pre> <table width="600" class="withborder"><tbody> <tr><th>暙準入力</th><th>暙準出力</th></tr> <tr><td>3</td><td> </td></tr> <tr><td> </td><td>? 1 2</td></tr> <tr><td>2</td><td> </td></tr> <tr><td> </td><td>? 2 3</td></tr> <tr><td>1</td><td> </td></tr> <tr><td> </td><td>? 1 3</td></tr> <tr><td>1</td><td></td></tr> <tr><td> </td><td>! 2 3 1</td></tr> </tbody></table> </pre>
p02267
<H1>Search I</H1> <p> You are given a sequence of <i>n</i> integers S and a sequence of different <i>q</i> integers T. Write a program which outputs C, the number of integers in T which are also in the set S. </p> <H2>Input</H2> <p> In the first line <i>n</i> is given. In the second line, <i>n</i> integers are given. In the third line <i>q</i> is given. Then, in the fourth line, <i>q</i> integers are given. </p> <H2>Output</H2> <p> Print C in a line. </p> <H2>Constraints</H2> <ul> <li>n &le; 10000</li> <li> q &le; 500 </li> <li>0 &le; an element in S &le; 10<sup>9</sup></li> <li>0 &le; an element in T &le; 10<sup>9</sup></li> </ul> <H2>Sample Input 1</H2> <pre> 5 1 2 3 4 5 3 3 4 1 </pre> <H2>Sample Output 1</H2> <pre> 3 </pre> <H2>Sample Input 2</H2> <pre> 3 3 1 2 1 5 </pre> <H2>Sample Output 2</H2> <pre> 0 </pre> <H2>Sample Input 3</H2> <pre> 5 1 1 2 2 3 2 1 2 </pre> <H2>Sample Output 3</H2> <pre> 2 </pre> <H2>Notes</H2> <!-- <a href="template/ALDS1_3_A_template.c" target="_blank">Template in C</a> -->
p02288
<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>Maximum Heap</h1> <p> A binary heap which satisfies max-heap property is called max-heap. In a max-heap, for every node $i$ other than the root, $A[i] \leq A[parent(i)]$, that is, the value of a node is at most the value of its parent. The largest element in a max-heap is stored at the root, and the subtree rooted at a node contains values no larger than that contained at the node itself. </p> <p> Here is an example of a max-heap. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ALDS1_9_B_1"> </center> <br> <p> Write a program which reads an array and constructs a max-heap from the array based on the following pseudo code. </p> <p> $maxHeapify(A, i)$ move the value of $A[i]$ down to leaves to make a sub-tree of node $i$ a max-heap. Here, $H$ is the size of the heap. </p> <pre> 1 maxHeapify(A, i) 2 l = left(i) 3 r = right(i) 4 // select the node which has the maximum value 5 if l &le; H and A[l] &gt; A[i] 6 largest = l 7 else 8 largest = i 9 if r &le; H and A[r] &gt; A[largest] 10 largest = r 11 12 if largest &ne; i // value of children is larger than that of i 13 swap A[i] and A[largest] 14 maxHeapify(A, largest) // call recursively </pre> <p> The following procedure buildMaxHeap(A) makes $A$ a max-heap by performing maxHeapify in a bottom-up manner. </p> <pre> 1 buildMaxHeap(A) 2 for i = H/2 downto 1 3 maxHeapify(A, i) </pre> <H2>Input</H2> <p> In the first line, an integer $H$ is given. In the second line, $H$ integers which represent elements in the binary heap are given in order of node id (from $1$ to $H$). </p> <H2>Output</H2> <p> Print values of nodes in the max-heap in order of their id (from $1$ to $H$). <u>Print a single space character before each value.</u> </p> <H2>Constraint</H2> <ul> <li>$1 \leq H \leq 500,000$</li> <li>$-2,000,000,000 \leq$ value of a node $\leq 2,000,000,000$</li> </ul> <H2>Sample Input 1</H2> <pre> 10 4 1 3 2 16 9 10 14 8 7 </pre> <H2>Sample Output 1</H2> <pre> 16 14 10 8 7 9 3 2 4 1 </pre> <br> <H2>Reference</H2> <p> Introduction to Algorithms, Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. The MIT Press. </p>
p02772
<span class="lang-en"> <p>Score: <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>You are an immigration officer in the Kingdom of AtCoder. The document carried by an immigrant has some number of integers written on it, and you need to check whether they meet certain criteria.</p> <p>According to the regulation, the immigrant should be allowed entry to the kingdom if and only if the following condition is satisfied:</p> <ul> <li>All even numbers written on the document are divisible by <var>3</var> or <var>5</var>.</li> </ul> <p>If the immigrant should be allowed entry according to the regulation, output <code>APPROVED</code>; otherwise, print <code>DENIED</code>.</p> </section> </div> <div class="part"> <section> <h3>Notes</h3> <ul> <li>The condition in the statement can be rephrased as "If <var>x</var> is an even number written on the document, <var>x</var> is divisible by <var>3</var> or <var>5</var>". Here "<a href="https://en.wikipedia.org/wiki/Material_conditional">if</a>" and "<a href="https://en.wikipedia.org/wiki/Logical_disjunction">or</a>" are logical terms.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li>All values in input are integers.</li> <li><var>1 \leq N \leq 100</var></li> <li><var>1 \leq A_i \leq 1000</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A_1</var> <var>A_2</var> <var>\dots</var> <var>A_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>If the immigrant should be allowed entry according to the regulation, print <code>APPROVED</code>; otherwise, print <code>DENIED</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 6 7 9 10 31 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>APPROVED </pre> <p>The even numbers written on the document are <var>6</var> and <var>10</var>.</p> <p>All of them are divisible by <var>3</var> or <var>5</var>, so the immigrant should be allowed entry.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 28 27 24 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>DENIED </pre> <p><var>28</var> violates the condition, so the immigrant should not be allowed entry.</p></section> </div> </span>
p03860
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is going to open a contest named "AtCoder <var>s</var> Contest". Here, <var>s</var> is a string of length <var>1</var> or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters.</p> <p>Snuke has decided to abbreviate the name of the contest as "A<var>x</var>C". Here, <var>x</var> is the uppercase English letter at the beginning of <var>s</var>.</p> <p>Given the name of the contest, print the abbreviation of the name.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>The length of <var>s</var> is between <var>1</var> and <var>100</var>, inclusive.</li> <li>The first character in <var>s</var> is an uppercase English letter.</li> <li>The second and subsequent characters in <var>s</var> are lowercase English letters.</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>AtCoder <var>s</var> Contest </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the abbreviation of the name of the contest.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>AtCoder Beginner Contest </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>ABC </pre> <p>The contest in which you are participating now.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>AtCoder Snuke Contest </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>ASC </pre> <p>This contest does not actually exist.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>AtCoder X Contest </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>AXC </pre></section> </div> </span>
p02322
<h1>Knapsack Problem with Limitations II</h1> <p>You have $N$ items that you want to put them into a knapsack. Item $i$ has value $v_i$, weight $w_i$ and limitation $m_i$.</p> <p>You want to find a subset of items to put such that:</p> <ul> <li>The total value of the items is as large as possible.</li> <li>The items have combined weight at most $W$, that is capacity of the knapsack.</li> <li>You can select at most $m_i$ items for $i$-th item.</li> </ul> <p>Find the maximum total value of items in the knapsack.</p> <h2>Input</h2> <pre> $N$ $W$ $v_1$ $w_1$ $m_1$ $v_2$ $w_2$ $m_2$ : $v_N$ $w_N$ $m_N$ </pre> <p>The first line consists of the integers $N$ and $W$. In the following $N$ lines, the value, weight and limitation of the $i$-th item are given.</p> <h2>Output</h2> <p>Print the maximum total values of the items in a line.</p> <h2>Constraints</h2> <ul> <li>$1 \le N \le 50$</li> <li>$1 \le v_i \le 50$</li> <li>$1 \le w_i \le 10^9$</li> <li>$1 \le m_i \le 10^9$</li> <li>$1 \le W \le 10^9$</li> </ul> <h2>Sample Input 1</h2> <pre> 4 8 4 3 2 2 1 1 1 2 4 3 2 2 </pre> <h2>Sample Output 1</h2> <pre> 12 </pre> <h2>Sample Input 2</h2> <pre> 2 100 1 1 100 2 1 50 </pre> <h2>Sample Output 2</h2> <pre> 150 </pre> <h2>Sample Input 3</h2> <pre> 5 1000000000 3 5 1000000000 7 6 1000000000 4 4 1000000000 6 8 1000000000 2 5 1000000000 </pre> <h2>Sample Output 3</h2> <pre> 1166666666 </pre>
p03499
<span class="lang-en"> <p>Score : <var>1000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke has a rooted tree with <var>N+1</var> vertices. The vertices are numbered <var>0</var> through <var>N</var>, and Vertex <var>0</var> is the root of the tree. The parent of Vertex <var>i</var> <var>(1 \leq i \leq N)</var> is Vertex <var>p_i</var>.</p> <p>Besides this tree, Snuke also has an box which is initially empty and many marbles, and playing with them. The play begins with placing one marble on some of the vertices, then proceeds as follows:</p> <ol> <li>If there is a marble on Vertex <var>0</var>, move the marble into the box.</li> <li>Move each marble from the vertex to its parent (all at once).</li> <li>For each vertex occupied by two or more marbles, remove all the marbles from the vertex.</li> <li>If there exists a vertex with some marbles, go to Step 1. Otherwise, end the play.</li> </ol> <p>There are <var>2^{N+1}</var> ways to place marbles on some of the vertices. For each of them, find <strong>the number of marbles that will be in the box at the end of the play</strong>, and compute the sum of all those numbers modulo <var>1,000,000,007</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N &lt; 2 \times 10^{5}</var></li> <li><var>0 \leq p_i &lt; i</var></li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Scores</h3><ul> <li>In the test set worth <var>400</var> points, <var>N &lt; 2{,}000</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>p_1</var> <var>p_2</var> <var>...</var> <var>p_{N}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the answer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 0 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>8 </pre> <p>When we place a marble on both Vertex <var>1</var> and <var>2</var>, there will be multiple marbles on Vertex <var>0</var> by step 2. In such a case, these marbles will be removed instead of being moved to the box.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 0 1 1 0 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>96 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>31 0 1 0 2 4 0 4 1 6 4 3 9 7 3 7 2 15 6 12 10 12 16 5 3 20 1 25 20 23 24 23 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>730395550 </pre> <p>Be sure to compute the sum modulo <var>1,000,000,007</var>.</p></section> </div> </span>
p03163
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> items, numbered <var>1, 2, \ldots, N</var>. For each <var>i</var> (<var>1 \leq i \leq N</var>), Item <var>i</var> has a weight of <var>w_i</var> and a value of <var>v_i</var>.</p> <p>Taro has decided to choose some of the <var>N</var> items and carry them home in a knapsack. The capacity of the knapsack is <var>W</var>, which means that the sum of the weights of items taken must be at most <var>W</var>.</p> <p>Find the maximum possible sum of the values of items that Taro takes home.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>1 \leq N \leq 100</var></li> <li><var>1 \leq W \leq 10^5</var></li> <li><var>1 \leq w_i \leq W</var></li> <li><var>1 \leq v_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>W</var> <var>w_1</var> <var>v_1</var> <var>w_2</var> <var>v_2</var> <var>:</var> <var>w_N</var> <var>v_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum possible sum of the values of items that Taro takes home.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 8 3 30 4 50 5 60 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>90 </pre> <p>Items <var>1</var> and <var>3</var> should be taken. Then, the sum of the weights is <var>3 + 5 = 8</var>, and the sum of the values is <var>30 + 60 = 90</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 5 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>5000000000 </pre> <p>The answer may not fit into a 32-bit integer type.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>6 15 6 5 5 6 6 4 6 6 3 5 7 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>17 </pre> <p>Items <var>2, 4</var> and <var>5</var> should be taken. Then, the sum of the weights is <var>5 + 6 + 3 = 14</var>, and the sum of the values is <var>6 + 6 + 5 = 17</var>.</p></section> </div> </span>
p03533
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a string <var>S</var>.</p> <p>Takahashi can insert the character <code>A</code> at any position in this string any number of times.</p> <p>Can he change <var>S</var> into <code>AKIHABARA</code>?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq |S| \leq 50</var></li> <li><var>S</var> consists of uppercase English letters.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If it is possible to change <var>S</var> into <code>AKIHABARA</code>, print <code>YES</code>; otherwise, print <code>NO</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>KIHBR </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>YES </pre> <p>Insert one <code>A</code> at each of the four positions: the beginning, immediately after <code>H</code>, immediately after <code>B</code> and the end.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>AKIBAHARA </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>NO </pre> <p>The correct spell is <code>AKIHABARA</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>AAKIAHBAARA </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>NO </pre></section> </div> </span>
p00036
<H1>平面䞊の図圢</H1> <p> 瞊 8、暪 8 のマスからなる図 1 のような平面がありたす。 <br> <center> <table cellspacing=0 cellpadding=0> <tr><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> <tr><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> <tr><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> <tr><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> <tr><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> <tr><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> <tr><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> <tr><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> </table> <br> <table> <tr><td>図</td></tr> </table> </center> <br> <p> この平面䞊に、以䞋の A から G の図圢のどれかが䞀぀だけ眮かれおいたす。 </p> <center> <table> <tr> <td width=100> <table><tr><td>A</td></tr></table> <table cellspacing=0 cellpadding=0> <tr><td>■</td><td>■</td><td></td><td></td></tr> <tr><td>■</td><td>■</td><td></td><td></td></tr> <tr><td></td><td></td><td></td><td></td></tr> <tr><td></td><td></td><td></td><td></td></tr> </table> </td> <td width=100> <table><tr><td>B</td></tr></table> <table cellspacing=0 cellpadding=0> <tr><td></td><td>■</td><td></td><td></td></tr> <tr><td></td><td>■</td><td></td><td></td></tr> <tr><td></td><td>■</td><td></td><td></td></tr> <tr><td></td><td>■</td><td></td><td></td></tr> </table> </td> <td width=100> <table><tr><td>C</td></tr></table> <table cellspacing=0 cellpadding=0> <tr><td>■</td><td>■</td><td>■</td><td>■</td></tr> <tr><td></td><td></td><td></td><td></td></tr> <tr><td></td><td></td><td></td><td></td></tr> <tr><td></td><td></td><td></td><td></td></tr> </table> </td> </tr> </table> <br/> <table> <tr> <td width=100> <table><tr><td>D</td></tr></table> <table cellspacing=0 cellpadding=0> <tr><td></td><td>■</td><td></td><td></td></tr> <tr><td>■</td><td>■</td><td></td><td></td></tr> <tr><td>■</td><td></td><td></td><td></td></tr> <tr><td></td><td></td><td></td><td></td></tr> </table> </td> <td width=100> <table><tr><td>E</td></tr></table> <table cellspacing=0 cellpadding=0> <tr><td>■</td><td>■</td><td></td><td></td></tr> <tr><td></td><td>■</td><td>■</td><td></td></tr> <tr><td></td><td></td><td></td><td></td></tr> <tr><td></td><td></td><td></td><td></td></tr> </table> </td> <td width=100> <table><tr><td>F</td></tr></table> <table cellspacing=0 cellpadding=0> <tr><td>■</td><td></td><td></td><td></td></tr> <tr><td>■</td><td>■</td><td></td><td></td></tr> <tr><td></td><td>■</td><td></td><td></td></tr> <tr><td></td><td></td><td></td><td></td></tr> </table> </td> <td width=100> <table><tr><td>G</td></tr></table> <table cellspacing=0 cellpadding=0> <tr><td></td><td>■</td><td>■</td><td></td></tr> <tr><td>■</td><td>■</td><td></td><td></td></tr> <tr><td></td><td></td><td></td><td></td></tr> <tr><td></td><td></td><td></td><td></td></tr> </table> </td> </tr> </table> </center> <br/> <p>たずえば、次の図 2 の䟋では E の図圢が眮かれおいたす。 <br/> <center> <table> <tr> <td> <table cellspacing=0 cellpadding=0> <tr><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> <tr><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> <tr><td>□</td><td>■</td><td>■</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> <tr><td>□</td><td>□</td><td>■</td><td>■</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> <tr><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> <tr><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> <tr><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> <tr><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td><td>□</td></tr> </table> </td> </tr> </table> <br> <table> <tr> <td>図</td> </tr> </table> </center> <br> <p> 平面の䞭で図圢が占めおいるマスを 1、占めおいないマスを 0 で衚珟した数字の列を読み蟌んで、眮かれおいる図圢の皮類A〜Gを出力するプログラムを䜜成しおください。 <p> ただし、ひず぀の平面に眮かれおいる図圢は必ず぀で、耇数の図圢が眮かれおいるこずはありたせん。たた、A〜G で衚される図圢以倖のものが眮かれおいるこずはありたせん。 </p> <H2>Input</H2> <p> 入力は耇数のデヌタセットからなりたす。 </p> <p> ぀のデヌタセットずしお、平面の䞭で図圢が占めおいるマスを 1、占めおいないマスを 0 で衚珟した 8 文字からなる 8 ぀の文字列が䞎えられたす。䟋えば、図 2 に察応する文字列の䞊びは次のようになりたす。 </p> <center> <table> <tr> <td> <table cellspacing=0 cellpadding=0> <tr><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr> <tr><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr> <tr><td>0</td><td>1</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr> <tr><td>0</td><td>0</td><td>1</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td></tr> <tr><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr> <tr><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr> <tr><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr> <tr><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr> </table> </tr> </table> </center> <br> <p> デヌタセットの間は぀の空行で区切られおいたす。デヌタセットの数は 50 を超えたせん。 </p> <H2>Output</H2> <p> 各デヌタセットごずに、平面に䞎えられた図圢の皮類A〜G のいずれかを行に出力しおください。 </p> <H2>Sample Input</H2> <pre> 00000000 00000000 01100000 00110000 00000000 00000000 00000000 00000000 00011110 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00110000 00110000 00000000 00000000 00000000 00000000 </pre> <H2>Output for the Sample Input</H2> <pre> E C A </pre>
p00466
<H1>レシヌト </H1> <h2>問題</h2> <p> 倪郎君は10冊の本を賌入した 埌日 レシヌトをもずに䟡栌を調べようずしたが レシヌトには汚れがあり ある本の䟡栌が読み取れなかった その本の䟡栌を 10冊の総額ず他の9冊の䟡栌から蚈算するこずにした </p> <p> 䟡栌が読み取れなかった本の䟡栌を出力するプログラムを曞け なお本の䟡栌はすべお正の敎数である たた消費皎を考慮する必芁はない </p> <h2> 入力</h2> <p> 入力は耇数のデヌタセットからなる各デヌタセットは以䞋の圢匏で䞎えられる </p> <p> 各デヌタセットは10行からなり1行に1぀ず぀正の敎数が曞かれおいる 1行目の敎数は10冊の総額を 2行目から10行目の敎数は読み取れた䟡栌を衚しおいる なお10冊の総額は10000以䞋である </p> <p> 総額 が 0 のずき入力の終了を瀺す.デヌタセットの数は 5 を超えない </p> <h2> 出力</h2> <p> デヌタセットごずに䟡栌が読み取れなかった本の䟡栌を1 行に出力する </p> <h2> 入出力䟋</h2> <h3>入力䟋</h3> <pre> 9850 1050 800 420 380 600 820 2400 1800 980 0 </pre> <h3>出力䟋</h3> <pre> 600 </pre> <div class="source"> <p class="source"> 䞊蚘問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p02908
<span class="lang-en"> <p>Score : <var>1600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke has permutations <var>(P_0,P_1,\cdots,P_{N-1})</var> and <var>(Q_0,Q_1,\cdots,Q_{N-1})</var> of <var>(0,1,\cdots,N-1)</var>.</p> <p>Now, he will make new permutations <var>A</var> and <var>B</var> of <var>(0,1,\cdots,N-1)</var>, under the following conditions:</p> <ul> <li>For each <var>i</var> (<var>0 \leq i \leq N-1</var>), <var>A_i</var> should be <var>i</var> or <var>P_i</var>.</li> <li>For each <var>i</var> (<var>0 \leq i \leq N-1</var>), <var>B_i</var> should be <var>i</var> or <var>Q_i</var>.</li> </ul> <p>Let us define the distance of permutations <var>A</var> and <var>B</var> as the number of indices <var>i</var> such that <var>A_i \neq B_i</var>. Find the maximum possible distance of <var>A</var> and <var>B</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 100000</var></li> <li><var>0 \leq P_i \leq N-1</var></li> <li><var>P_0,P_1,\cdots,P_{N-1}</var> are all different.</li> <li><var>0 \leq Q_i \leq N-1</var></li> <li><var>Q_0,Q_1,\cdots,Q_{N-1}</var> are all different.</li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>P_0</var> <var>P_1</var> <var>\cdots</var> <var>P_{N-1}</var> <var>Q_0</var> <var>Q_1</var> <var>\cdots</var> <var>Q_{N-1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum possible distance of <var>A</var> and <var>B</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 2 1 3 0 0 2 3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>For example, if we make <var>A=(0,1,2,3)</var> and <var>B=(0,2,3,1)</var>, the distance will be <var>3</var>, which is the maximum result possible.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 0 4 5 3 7 8 2 1 9 6 3 8 5 6 4 0 2 1 7 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>8 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>32 22 31 30 29 7 17 16 3 14 9 19 11 2 5 10 1 25 18 15 24 20 0 12 21 27 4 26 28 8 6 23 13 22 3 2 7 17 9 16 4 14 8 19 26 28 5 10 1 25 18 15 13 11 0 12 23 21 20 29 24 27 6 30 31 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>28 </pre></section> </div> </span>
p00935
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script> </script> <h2>Problem A Decimal Sequences</h2> <p> Hanako learned the conjecture that all the non-negative integers appear in the infinite digit sequence of the decimal representation of $\pi$ = 3.14159265..., the ratio of a circle's circumference to its diameter. After that, whenever she watches a sequence of digits, she tries to count up non-negative integers whose decimal representations appear as its subsequences. </p> <p> For example, given a sequence "<span>3 0 1</span>", she finds representations of five non-negative integers 3, 0, 1, 30 and 301 that appear as its subsequences. </p> <p> Your job is to write a program that, given a finite sequence of digits, outputs the smallest non-negative integer not appearing in the sequence. In the above example, 0 and 1 appear, but 2 does not. So, 2 should be the answer. </p> <h3>Input</h3> <p> The input consists of a single test case.<br> <br> $n$<br> $d_1$ $d_2$ ... $d_n$<br> <br> $n$ is a positive integer that indicates the number of digits. Each of $d_k$'s $(k = 1, ... , n)$ is a digit. There is a space or a newline between $d_k$ and $d_{k+1}$ $(k = 1, ..., n - 1)$. </p> <p> You can assume that $1 \leq n \leq 1000$. </p> <h3>Output</h3> <p> Print the smallest non-negative integer not appearing in the sequence. </p> <h3>Sample Input 1</h3> <pre>3 3 0 1</pre> <h3>Sample Output 1</h3> <pre>2</pre> <h3>Sample Input 2</h3> <pre>11 9 8 7 6 5 4 3 2 1 1 0</pre> <h3>Sample Output 2</h3> <pre>12</pre> <h3>Sample Input 3</h3> <pre>10 9 0 8 7 6 5 4 3 2 1</pre> <h3>Sample Output 3</h3> <pre>10</pre> <h3>Sample Input 4</h3> <pre>100 3 6 7 5 3 5 6 2 9 1 2 7 0 9 3 6 0 6 2 6 1 8 7 9 2 0 2 3 7 5 9 2 2 8 9 7 3 6 1 2 9 3 1 9 4 7 8 4 5 0 3 6 1 0 6 3 2 0 6 1 5 5 4 7 6 5 6 9 3 7 4 5 2 5 4 7 4 4 3 0 7 8 6 8 8 4 3 1 4 9 2 0 6 8 9 2 6 6 4 9</pre> <h3>Sample Output 4</h3> <pre>11</pre> <h3>Sample Input 5</h3> <pre>100 7 2 7 5 4 7 4 4 5 8 1 5 7 7 0 5 6 2 0 4 3 4 1 1 0 6 1 6 6 2 1 7 9 2 4 6 9 3 6 2 8 0 5 9 7 6 3 1 4 9 1 9 1 2 6 4 2 9 7 8 3 9 5 5 2 3 3 8 4 0 6 8 2 5 5 0 6 7 1 8 5 1 4 8 1 3 7 3 3 5 3 0 6 0 6 5 3 2 2 2</pre> <h3>Sample Output 5</h3> <pre>86</pre> <h3>Sample Input 6</h3> <pre>1 3</pre> <h3>Sample Output 6</h3> <pre>0</pre>
p01627
<h1>Problem A: 青春18きっぷ 2013</h1> <h2>Problem Statement</h2> <p> 䌚接合宿に参加予定の高槻さんは、家が貧乏であたりお金を持っおいない。そのため、青春18きっぷを䜿甚しお、お金を節玄しようずしおいる。18きっぷは、これ1枚だけで、鈍行列車ならば1日䞭乗り攟題、改札の出入りも自由ずいう優れものである詳しい利甚ルヌルに぀いおは省略。 </p> <p> 18きっぷの魅力は、乗り換えを行う駅で、空いおいる時間を䜿っお、ご圓地のお土産等を芋おたわれる点である。圌女は、せっかくの機䌚なので、旅の途䞭でいろいろな駅を芋お回りたいず考えおいる。ただし、次の電車に乗り遅れおは困るため、乗り換え駅に到着した時刻から、乗り換え駅を出発する時刻たでの間がT分以䞊のずきだけ、その駅を芋お回るこずにした。 </p> <p> 高槻さんの18きっぷを䜿った乗り換え蚈画が䞎えられるので、芋お回れる駅の名前ず時間を出力せよ。䞀番最初に出発する駅ず、䞀番最埌に到着する駅は、芋お回る候補には入らないこずに泚意しおほしい。 </p> <h2>Input</h2> 各デヌタセットは、以䞋の圢匏で入力される。 <pre>N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN </pre> <p> Nは列車に乗車する回数を衚わす敎数、Tは乗り換え駅を芋お回れる蚱容時間(分)を衚わす敎数である。続いお、N行にわたっお、列車の出発ず到着のペアが䞎えられる。各行の入力は、st_timeiの時刻ちょうどにst_nameiの駅を高槻さんの乗る列車が出発するこずを、ar_timeiの時刻ちょうどにar_nameiの駅に高槻さんの乗る列車が到着するこずを意味する。 </p> <h2>Constraints</h2> <ul> <li>1 <= N <= 10</li> <li>1 <= T <= 180</li> <li>st_timei、ar_timei</li> <ul> <li>"HH:MM"により衚わされ、HHには00以䞊23以䞋、MMには00以䞊59以䞋の2桁の数倀が入る。HHが時間で、MMが分である。</li> <li>00:00 <= st_time1 < ar_time1 < st_time2 < ar_time2 < ... < st_timeN < ar_timeN <= 23:59</li> </ul> <li>st_namei、ar_namei</li> <ul> <li>アルファベット倧文字・小文字により衚わされる文字列である。</li> <li>1 <= 文字列の長さ <= 50</li> <li>i番目の到着駅ar_nameiず、i+1番目の出発駅st_namei+1の名前は䞀臎する。</li> <li>st_name1、ar_nameN、乗り換えの駅の名前は、それぞれ異なる文字列である。</li> </ul> </ul> <h2>Output</h2> <p> 各デヌタセットに぀いお、以䞋の圢匏で出力を行う。 </p> <pre>M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM </pre> <p> M0 <= M <= N - 1は、芋お回れる駅の数を衚わす敎数である。続いお、M行にわたっお、芋お回れる駅のリストを時刻の昇順に出力する。各行は、stay_nameiの駅をstay_timei分間芋お回れるこずを意味する。 </p> <h2>Sample Input 1</h2> <pre>8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu </pre> <h2>Output for the Sample Input 1</h2> <pre>2 Kanazawa 55 Niitsu 24 </pre> <p>Kanazawa駅は、10:03に到着し10:58に出発するため、乗り換えに55分の空き時間がある。Niitsu駅は、17:14に到着し17:38に出発するため、乗り換えに24分の空き時間がある。どちらも、入力で指定された24分以䞊の空き時間があるため、出力する。 </p> <h2>Sample Input 2</h2> <pre>1 180 10:44 Koriyama 11:52 AizuWakamatsu </pre> <h2>Output for the Sample Input 2</h2> <pre>0 </pre> <p> 乗り換え駅は1぀もないため、0ず出力する。 </p>
p01277
<H1><font color="#000">Problem E:</font> Symmetry</H1> <p> Open Binary and Object Group organizes a programming contest every year. Mr. Hex belongs to this group and joins the judge team of the contest. This year, he created a geometric problem with its solution for the contest. The problem required a set of points forming a line-symmetric polygon for the input. Preparing the input for this problem was also his task. The input was expected to cover all edge cases, so he spent much time and attention to make them satisfactory. </p> <p> However, since he worked with lots of care and for a long time, he got tired before he finished. So He might have made mistakes - there might be polygons not meeting the condition. It was not reasonable to prepare the input again from scratch. The judge team thus decided to find all line-asymmetric polygons in his input and fix them as soon as possible. They asked a programmer, just you, to write a program to find incorrect polygons. </p> <p> You can assume the following: </p> <ul> <li> Edges of the polygon must not cross or touch each other except for the end points of adjacent edges.</li> <li> It is acceptable for the polygon to have adjacent three vertexes on a line, but in such a case, there must be the vertex symmetric to each of them.</li> </ul> <H2>Input</H2> <!-- <p> The input consists of multiple datasets. Each dataset has the following format: </p> --> <p> The input consists of a set of points in the following format. </p> <p> <i>N</i><br> <i>x</i><sub>1</sub> <i>y</i><sub>1</sub><br> <i>x</i><sub>2</sub> <i>y</i><sub>2</sub><br> ...<br> <i>x</i><sub><i>N</i></sub> <i>y</i><sub><i>N</i></sub><br> </p> <p> The first line of the input contains an integer <i>N</i> (3 &le; <i>N</i> &le; 1000), which denotes the number of points. The following <i>N</i> lines describe each point. The <i>i</i>-th line contains two integers <i>x</i><sub>1</sub>, <i>y</i><sub>1</sub> (-10000 &le; <i>x<sub>i</sub></i>, <i>y<sub>i</sub></i> &le; 10000), which denote the coordinates of the <i>i</i>-th point. </p> <p> Note that, although the points are the vertexes of a polygon, they are given in an artibrary order, not necessarily clockwise or counterclockwise. </p> <!-- <p> The last dataset is followed by a line containing one zero. This line is not a part of any dataset and should not be processed. </p> --> <H2>Output</H2> <p> Output "<span>Yes</span>" in a line if the points can form a line-symmetric polygon, otherwise output "<span>No</span>". </p> <H2>Sample Input 1</H2> <pre> 4 0 1 1 0 0 0 1 1 </pre> <H2>Sample Output 1</H2> <pre> Yes </pre> <br/> <H2>Sample Input 2</H2> <pre> 4 0 1 1 -1 0 0 1 1 </pre> <H2>Sample Output 2</H2> <pre> No </pre> <br/> <H2>Sample Input 3</H2> <pre> 9 -1 1 0 1 1 1 -1 0 0 0 1 0 -1 -1 0 -1 1 -1 </pre> <H2>Sample Output 3</H2> <pre> No </pre> <br/> <H2>Sample Input 4</H2> <pre> 3 -1 -1 0 0 1 1 </pre> <H2>Sample Output 4</H2> <pre> No </pre> <br/> <H2>Sample Input 5</H2> <pre> 4 0 2 0 0 -1 0 1 0 </pre> <H2>Sample Output 5</H2> <pre> Yes </pre>
p00870
<H1><font color="#000">Problem G:</font> Search of Concatenated Strings</H1> <p> The amount of information on the World Wide Web is growing quite rapidly. In this information explosion age, we must survive by accessing only the Web pages containing information relevant to our own needs. One of the key technologies for this purpose is keyword search. By using well-known search engines, we can easily access those pages containing useful information about the topic we want to know. </p> <p> There are many variations in keyword search problems. If a single string is searched in a given text, the problem is quite easy. If the pattern to be searched consists of multiple strings, or is given by some powerful notation such as regular expressions, the task requires elaborate algorithms to accomplish efficiently. </p> <p> In our problem, a number of strings (element strings) are given, but they are not directly searched for. Concatenations of all the element strings in any order are the targets of the search here. </p> <p> For example, consider three element strings aa, b and ccc are given. In this case, the following six concatenated strings are the targets of the search, i.e. they should be searched in the text. </p> <pre align="center"> aabccc aacccb baaccc bcccaa cccaab cccbaa </pre> <p> The text may contain several occurrences of these strings. You are requested to count the number of occurrences of these strings, or speaking more precisely, the number of positions of occurrences in the text. </p> <p> Two or more concatenated strings may be identical. In such cases, it is necessary to consider subtle aspects of the above problem statement. For example, if two element strings are x and xx, the string xxx is an occurrence of both the concatenation of x and xx and that of xx and x. Since the number of positions of occurrences should be counted, this case is counted as one, not two. </p> <p> Two occurrences may overlap. For example, the string xxxx has occurrences of the concatenation xxx in two different positions. This case is counted as two. </p> <H2>Input</H2> <p> The input consists of a number of datasets, each giving a set of element strings and a text. The format of a dataset is as follows. </p> <pre> <i>n m</i> <i>e</i><sub>1</sub> <i>e</i><sub>2</sub> . . . <i>e</i><sub>n</sub> <i>t</i><sub>1</sub> <i>t</i><sub>2</sub> . . . <i>t</i><sub>m</sub> </pre> <p> The first line contains two integers separated by a space. <i>n</i> is the number of element strings. <i>m</i> is the number of lines used to represent the text. <i>n</i> is between 1 and 12, inclusive. </p> <p> Each of the following n lines gives an element string. The length (number of characters) of an element string is between 1 and 20, inclusive. The last <i>m</i> lines as a whole give the text. Since it is not desirable to have a very long line, the text is separated into m lines by newlines, but these newlines should be ignored. They are not parts of the text. The length of each of these lines (not including the newline) is between 1 and 100, inclusive. The length of the text is between 1 and 5000, inclusive. </p> <p> The element strings and the text do not contain characters other than lowercase letters. </p> <p> The end of the input is indicated by a line containing two zeros separated by a space. </p> <p> <b>CAUTION!</b> Although the sample input contains only small datasets, note that 12! &times; 5000 is far larger than 2<sup>31</sup> . </p> <H2>Output</H2> <p> For each dataset in the input, one line containing the number of matched positions should be output. An output line should not contain extra characters. </p> <H2>Sample Input</H2> <pre> 3 1 aa b ccc aabccczbaacccbaazaabbcccaa 3 1 a b c cbbcbcbabaacabccaccbaacbccbcaaaccccbcbcbbcacbaacccaccbbcaacbbabbabaccc 3 4 aaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 5 12 197 </pre>
p01762
<h1>C : Pruning / 枝刈り</h1> <h1>Problem</h1> <p>ずにかくあ぀い。あづい君の䜏んでいる地域は今幎猛暑であった。 さらに、家の庭には 1 本の朚が生えおおり、毎日やかたしく鳎く蝉が暑さを増幅させおいるような気がする。</p> <p>庭の朚は、たさにグラフ理論でいうずころの朚のような圢をしおおり、この朚にはたくさんの蝉が止たっおいる。 蝉は、必ず枝の先端(葉)たたは枝の分かれ目(頂点)に止たる習性がある。 ただし、朚の根には 1 匹も止たるこずはない。 この朚のある枝(蟺)を切るず、それより空偎(根ず反察偎)にいる蝉を党お駆陀するこずができる。 ただし、枝を切るためには、その枝に応じた劎力が必芁ずなる。</p> <p>(泚 : 括匧内の蚀葉はグラフ理論の蚀葉で眮き換えたものである。以降は党おグラフ理論の蚀葉で衚珟するこずにする。)</p> <p>高床情報化瀟䌚ずなった珟代においおは、 郚屋に居ながらにしお頂点に䜕匹の蝉がいるか、 そしお各蟺を切るのに芁する劎力を調べるこずが出来る。</p> <p>あづい君はその情報を甚いお、 朚に止たっおいる党おの蝉を駆陀するのに必芁な最小の劎力を調べるプログラムを曞くこずにした。</p> <h1>Input</h1> <p>入力は次のような圢匏で䞎えられる</p> <p><em>N</em><br><em>C<sub>1</sub></em> ... <em>C<sub>N-1</sub></em><br><em>u<sub>0</sub></em> <em>v<sub>0</sub></em> <em>p<sub>0</sub></em><br>...<br><em>u<sub>N-2</sub></em> <em>v<sub>N-2</sub></em> <em>p<sub>N-2</sub></em></p> <p><em>N</em> は朚に含たれる頂点の数である。 各頂点には 0 ... <em>N</em> - 1 の番号が振られ、0番目の頂点を根ずする。 <em>C<sub>1</sub></em> ... <em>C<sub>N-1</sub></em> は、各頂点に止たっおいる蝉の数であり、 <em>C<sub>i</sub></em> が <em>i</em> 番目の頂点に止たっおいる蝉の数である。 根には、蝉は1匹も止たっおいない。 2 + <em>i</em> 行目の <em>u<sub>i</sub></em>, <em>v<sub>i</sub></em>, <em>p<sub>i</sub></em> は、朚に含たれる蟺の情報である。<em>u<sub>i</sub></em>, <em>v<sub>i</sub></em> は蟺が結ぶ 2 頂点の番号であり、<em>p<sub>i</sub></em> はこの蟺を切るのに必芁な劎力である。</p> <h1>Constraints</h1> <ul> <li>入力は党お敎数である。</li> <li>䞎えられるグラフは朚である。</li> <li>2 ≩ <em>N</em> ≩ 1,000</li> <li>0 ≩ <em>C<sub>i</sub></em> ≩ 1,000</li> <li>0 ≩ <em>u<sub>i</sub></em> , <em>v<sub>i</sub></em> < <em>N</em></li> <li>1 ≩ <em>p<sub>i</sub></em> ≩ 1,000</li> </ul> <h1>Output</h1> <p>蝉を党お駆陀するために必芁な最小の劎力を 1 行で出力せよ。</p> <h1>Samples</h1> <h2>Sample Input 1</h2> <pre>5 2 2 2 2 0 1 4 1 2 1 1 3 1 1 4 1</pre> <h2>Sample Output 1</h2> <pre>4</pre> <p>頂点 0 ず 1 を぀なぐ蟺を切れば、党おの蝉を駆陀するこずができる。</p> <h2>Sample Input 2</h2> <pre>5 0 2 2 2 0 1 4 1 2 1 1 3 1 1 4 1</pre> <h2>Sample Output 2</h2> <pre>3</pre> <p>頂点 1 ず 2 、 1 ず 3 、 1 ず 4 を぀なぐ蟺の3本を切れば最小の劎力で蝉を駆陀するこずができる。 なお、頂点 0 ず 1 を぀なぐ蟺を切るこずで党おの蝉を駆陀するこずができるが、これにはコストが 4 かかっおしたう。</p>
p01298
<H1><font color="#000">Problem F:</font> Water Tank</H1> <p> You built an apartment. The apartment has a water tank with a capacity of <i>L</i> in order to store water for the residents. The tank works as a buffer between the water company and the residents. </p> <p> It is required to keep the tank "not empty" at least during use of water. A pump is used to provide water into the tank. From the viewpoint of avoiding water shortage, a more powerful pump is better, of course. But such powerful pumps are expensive. That’s the life. </p> <p> You have a daily schedule table of water usage. It does not differ over days. The table is composed of some schedules. Each schedule is indicated by the starting time of usage, the ending time and the used volume per unit of time during the given time span. </p> <p> All right, you can find the minimum required speed of providing water for days from the schedule table. You are to write a program to compute it. </p> <p> You can assume the following conditions. </p> <ul> <li> A day consists of 86,400 units of time.</li> <li> No schedule starts before the time 0 (the beginning of the day).</li> <li> No schedule ends after the time 86,400 (the end of the day).</li> <li> No two schedules overlap.</li> <li> Water is not consumed without schedules.</li> <li> The tank is full of water when the tank starts its work.</li> </ul> <H2>Input</H2> <p> The input is a sequence of datasets. Each dataset corresponds to a schedule table in the following format: </p> <p> <i>N L</i><br> <i>s</i><sub>1</sub> <i>t</i><sub>1</sub> <i>u</i><sub>1</sub><br> ...<br> <i>s<sub>N</sub> t<sub>N</sub> u<sub>N</sub></i><br> </p> <p> The first line of a dataset contains two integers <i>N</i> and <i>L</i> (1 &le; <i>N</i> &le; 86400, 1 &le; <i>L</i> &le; 10<sup>6</sup>), which represents the number of schedule in the table and the capacity of the tank, respectively. </p> <p> The following <i>N</i> lines describe the <i>N</i> schedules. The (<i>i</i> + 1)-th line of the dataset corresponds to the <i>i</i>-th schedule, which consists of three integers <i>s<sub>i</sub></i>, <i>t<sub>i</sub></i> and <i>u<sub>i</sub></i> . The first two integers <i>s<sub>i</sub></i> and <i>t<sub>i</sub></i> indicate the starting time and the ending time of the schedule. The last integer <i>u<sub>i</sub></i> (1 &le; <i>u<sub>i</sub></i> &le; 10<sup>6</sup> ) indicates the consumed volume per unit of time during the schedule. It is guaranteed that 0 &le; <i>s</i><sub>1</sub> &lt; <i>t</i><sub>1</sub> &le; <i>s</i><sub>2</sub> &lt; <i>t</i><sub>2</sub> &le; ... &le; <i>s<sub>n</sub></i> &lt; <i>t<sub>n</sub></i> &le; 86400. </p> <p> The input is terminated by a line with two zeros. This line should not be processed. </p> <H2>Output</H2> <p> For each case, print the minimum required amount of water per unit of time provided by the pump in a line. The amount may be printed with an arbitrary number of digits after the decimal point, but should not contain an absolute error greater than 10<sup>-6</sup>. </p> <H2>Sample Input</H2> <pre> 1 100 0 86400 1 1 100 43200 86400 1 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 1.000000 0.997685 </pre>
p01332
<h1><font color="#000">Problem L:</font> Problem L: 3぀のシル゚ット</h1> <p>JAVA(Japan Aerospace Voyage Agency: 日本宇宙飛行研究機構)は、宇宙開発事業の䞀環ずしお2003幎に探査機を打ち䞊げた。 この探査機打ち䞊げの目的の䞀぀に、小惑星むシカワに接近し、その衚面物質のサンプルを採集するこずがある。 様々なアクシデントに芋舞われながらも、探査機はむシカワに到達し、そしお぀いに2010幎、地球ぞ垰還し、むシカワのサンプル詊料の入ったカプセルを回収するこずに成功した。</p> <p>東京倧孊を卒業し、JAVAに就職したきたたさ君は、この詊料の研究を担圓しおいる。 䞀刻も早く詊料の分析をしたいずころであるが、ずおも慎重なきたたさ君は、もしカプセルの䞭に凶暎な゚むリアンが入っおいたら倧倉であるず考えた。 そこで、カプセルを開ける前にX線を甚いお内郚の物質の圢状を調べ、゚むリアンが入っおいないこずを確認するこずにした。 カプセルにX線を圓おるず、物質が存圚しおいるずころは癜色に、存圚しおいないずころは黒色になった写真が埗られる。 様々な角床からX線を圓おお写真を埗るこずにより、内郚の物質の圢状を特定するこずができる。</p> <p>しかし、ここでたた問題が生じた。 正面から、右偎面から、䞊面からの枚の写真を埗たずころでX線装眮が故障しおしたったのである。 さらに、枚の写真の珟像にも倱敗し、本来黒色になるべき郚分が䞀郚癜色ずなっおしたった可胜性もある。 このたたでは物質の圢状を正確に特定するこずは出来ないため、䞭に゚むリアンが入っおいないこずを確認できず、カプセルを開けるこずができない。</p> <p>研究を続けるためには、X線装眮を買い換えるしかないのだが、JAVAには事業仕分けによる予算削枛の圱響で、X線装眮をすぐに買い換えるだけのお金がない。 そこできたたさ君は来幎床の予算を増やしおもらい、そのお金で新しいX線装眮を買うこずを考えた。 もちろん、予算は簡単には増えないため、探査機の成果を最倧限にアピヌルする必芁がある。 カプセル䞭に倧きな物質が含たれおいるほど成果を匷くアピヌルするこずができるため、物質が取りうる最倧䜓積を蚈算するこずにした。</p> <p>枚のX線写真ず矛盟しないような内郚の物質の圢状のうちで、䜓積が最倧であるものを求め、その䜓積を出力せよ。 </p> <h2>Input</h2> <p>各X線写真の癜色ず黒色の境界は䞀぀の倚角圢からなる。 倚角圢は凞ずは限らず、たた自己亀差はしない。 倚角圢の内偎が癜色、倖偎が黒色である。</p> <p>入力の圢匏は以䞋のようである。</p> <pre>n<sub>x</sub> y<sub>1</sub> z<sub>1</sub> y<sub>2</sub> z<sub>2</sub> ... y<sub>n<sub>x</sub></sub> z<sub>n<sub>x</sub></sub> n<sub>y</sub> z<sub>1</sub> x<sub>1</sub> z<sub>2</sub> x<sub>2</sub> ... z<sub>n<sub>y</sub></sub> x<sub>n<sub>y</sub></sub> n<sub>z</sub> x<sub>1</sub> y<sub>1</sub> x<sub>2</sub> y<sub>2</sub> ... x<sub>n<sub>z</sub></sub> y<sub>n<sub>z</sub></sub></pre> <p>n<sub>x</sub>, n<sub>y</sub>, n<sub>z</sub> はそれぞれ、正面・右偎面・䞊面からのX線写真に察応する倚角圢の頂点数である。 各頂点数は3以䞊20以䞋である。 続く n 行には倚角圢の頂点の座暙が反時蚈回りに䞎えられる。 頂点の座暙は0以䞊300以䞋の敎数である。</p> <p>たた、座暙軞はカプセルの䞭心から正面方向にx軞を、右偎面方向にy軞を、䞊面方向にz軞を取っおある。 </p> <center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_3silhouettes"></center> <h2>Output</h2> <p>枚のX線写真ず矛盟しないような物質の最倧䜓積を䞀行に出力せよ。 出力する倀は10<sup>-3</sup>以䞋の誀差を含んでいおも構わない。倀は小数点以䞋䜕桁衚瀺しおも構わない。 </p> <h2>Notes on Test Cases</h2> <p> 䞊蚘入力圢匏で耇数のデヌタセットが䞎えられたす。各デヌタセットに察しお䞊蚘出力圢匏で出力を行うプログラムを䜜成しお䞋さい。 </p> <p> n<sub>x</sub>, n<sub>y</sub>, n<sub>z</sub> がすべお 0 のずき入力の終わりを瀺したす。 </p> <!-- <h2>Sample Input 1</h2> <pre>4 0 0 100 0 100 100 0 100 4 0 0 100 0 100 100 0 100 4 0 0 100 0 100 100 0 100 </pre> <h2>Output for Sample Input 1</h2> <pre>1000000.0000 </pre> <h2>Sample Input 2</h2> <pre>3 0 0 100 0 0 100 3 0 0 100 0 0 100 3 0 0 100 0 0 100 </pre> <h2>Output for Sample Input 2</h2> <pre>250000.0000 </pre> <h2>Sample Input 3</h2> <pre>5 0 0 200 0 200 200 100 100 0 200 5 0 0 200 0 100 100 200 200 0 200 4 0 0 200 0 200 200 0 200 </pre> <h2>Output for Sample Input 3</h2> <pre>5333333.3333 </pre> --> <h2>Sample Input</h2> <pre> 4 0 0 100 0 100 100 0 100 4 0 0 100 0 100 100 0 100 4 0 0 100 0 100 100 0 100 3 0 0 100 0 0 100 3 0 0 100 0 0 100 3 0 0 100 0 0 100 5 0 0 200 0 200 200 100 100 0 200 5 0 0 200 0 100 100 200 200 0 200 4 0 0 200 0 200 200 0 200 0 0 0 </pre> <h2>Output for Sample Input</h2> <pre> 1000000.0000 250000.0000 5333333.3333 </pre>
p00173
<H1>お化け屋敷</H1> <p> 䌚接孊園高等孊校では、毎幎孊園祭をおこなっおいたす。その䞭でも䞀番人気はお化け屋敷です。䞀番人気の理由は、お化け屋敷をおこなうクラスが 1クラスや 2クラスではなく、9クラスがお化け屋敷をおこなうこずです。それぞれが工倫するこずより、それぞれが個性的なお化け屋敷になっおいたす。そのため、最近では近隣から倚くの来堎者が蚪れたす。 </p> <p> そこで、孊園祭実行委員䌚では、お化け屋敷の入堎料金を䞋衚のように校内で統䞀し、これにもずづき各クラスごずに入堎者総数ず収入の集蚈をおこなうこずにしたした。 </p> <p> 入堎料金衚(入堎者 1人あたりの入堎料) </p> <pre> 午前 午埌 200円 300円 </pre> <p> 各クラス毎の午前ず午埌の入堎者数を入力ずし、各クラス毎の入堎者総数及び収入の䞀芧衚を䜜成するプログラムを䜜成しおください。 </p> <H2>Input</H2> <p> 入力は以䞋の圢匏で䞎えられたす。 </p> <pre> <var>name<sub>1</sub></var> <var>a<sub>1</sub></var> <var>b<sub>1</sub></var> <var>name<sub>2</sub></var> <var>a<sub>2</sub></var> <var>b<sub>2</sub></var> : <var>name<sub>9</sub></var> <var>a<sub>9</sub></var> <var>b<sub>9</sub></var> </pre> <p> 入力は行からなり、<var>i</var> 行目に第 <var>i</var> のクラスのクラス名 <var>name<sub>i</sub></var> (数字ずアルファベットを含む 1 文字以䞊 15 文字以䞋の半角文字列)、午前の入堎者数 <var>a<sub>i</sub></var> (0 &le; <var>a<sub>i</sub></var> &le; 400)、 午埌の入堎者数 <var>b<sub>i</sub></var> (0 &le; <var>b<sub>i</sub></var> &le; 400) が䞎えられたす。 </p> <H2>Output</H2> <p> <var>i</var> 行目に第 <var>i</var> のクラスのクラス名、 入堎者総数、 料金収入を空癜区切りで行に出力しおください。 </p> <H2>Sample Input</H2> <pre> 1a 132 243 1c 324 183 1f 93 199 2b 372 163 2c 229 293 2e 391 206 3a 118 168 3b 263 293 3d 281 102 </pre> <H2>Output for the Sample Input</H2> <pre> 1a 375 99300 1c 507 119700 1f 292 78300 2b 535 123300 2c 522 133700 2e 597 140000 3a 286 74000 3b 556 140500 3d 383 86800 </pre>
p00489
<H1>サッカヌ (Soccer) </H1> <h2> 問題</h2> <p> JOI 囜ではサッカヌが人気でありJOI リヌグずいうリヌグ戊が毎週行われおいる </p> <p> JOI リヌグには N 個のチヌムが所属しおいお1 から N たでの番号が぀けられおいるすべおの組み合わせの詊合がちょうど䞀床ず぀行われる぀たり <nobr>N × (N - 1) / 2</nobr> 詊合が行われる各詊合の勝敗はそれぞれのチヌムの埗点で決たる勝ったチヌムの勝ち点は 3 点であり負けたチヌムの勝ち点は 0 点である匕き分けの堎合䞡チヌムの勝ち点は 1 点である順䜍は各チヌムの獲埗した勝ち点の合蚈で決定し埗倱点差は考えない勝ち点の合蚈が等しいチヌムの順䜍は䞊䜍に揃える </p> <p> 䟋ずしお 4 チヌムでのリヌグ戊を考える<nobr>4 × (4 - 1) / 2 = 6</nobr> 詊合が行われるそれらの結果が以䞋の衚のようになったずするハむフンの巊偎はその暪のチヌムの埗点であり右偎はその瞊のチヌムの埗点である </p> <table style="margin-left: 50px; margin-right: 50px; border-style:solid; border-color:#000000;" border="1" cellspacing="1"> <tr> <th></th> <th align="center">&nbsp;&nbsp;チヌム 1&nbsp;&nbsp;</th> <th align="center">&nbsp;&nbsp;チヌム 2&nbsp;&nbsp;</th> <th align="center">&nbsp;&nbsp;チヌム 3&nbsp;&nbsp;</th> <th align="center">&nbsp;&nbsp;チヌム 4&nbsp;&nbsp;</th> <th align="center">&nbsp;&nbsp;勝ち数&nbsp;&nbsp;</th> <th align="center">&nbsp;&nbsp;負け数&nbsp;&nbsp;</th> <th align="center">&nbsp;&nbsp;匕き分け数&nbsp;&nbsp;</th> <th align="center">&nbsp;&nbsp;勝ち点&nbsp;&nbsp;</th> </tr> <tr> <th align="center">&nbsp;&nbsp;チヌム 1&nbsp;&nbsp;</th> <td align="center">---</td> <td align="center">0 - 1</td> <td align="center">2 - 1</td> <td align="center">2 - 2</td> <td align="center">1</td> <td align="center">1</td> <td align="center">1</td> <td align="center">4</td> </tr> <tr> <th align="center">&nbsp;&nbsp;チヌム 2&nbsp;&nbsp;</th> <td align="center">1 - 0</td> <td align="center">---</td> <td align="center">1 - 1</td> <td align="center">3 - 0</td> <td align="center">2</td> <td align="center">0</td> <td align="center">1</td> <td align="center">7</td> </tr> <tr> <th align="center">&nbsp;&nbsp;チヌム 3&nbsp;&nbsp;</th> <td align="center">1 - 2</td> <td align="center">1 - 1</td> <td align="center">---</td> <td align="center">1 - 3</td> <td align="center">0</td> <td align="center">2</td> <td align="center">1</td> <td align="center">1</td> </tr> <tr> <th align="center">&nbsp;&nbsp;チヌム 4&nbsp;&nbsp;</th> <td align="center">2 - 2</td> <td align="center">0 - 3</td> <td align="center">3 - 1</td> <td align="center">---</td> <td align="center">1</td> <td align="center">1</td> <td align="center">1</td> <td align="center">4</td> </tr> </table> <br> <p> このずき勝ち点の最も倚いチヌム 2 が 1 䜍である</br> その次に勝ち点が倚いチヌムはチヌム 1 ずチヌム 4 でありこれらのチヌムの順䜍は共に 2 䜍である</br> そしお勝ち点が最も少ないチヌム 3 が 4 䜍である </p> <p> 党おの詊合の結果が䞎えられたずき各チヌムの順䜍を求めるプログラムを䜜成せよ </p> <h2> 入力</h2> <p> 入力ファむルの 1 行目にはチヌムの個数 N (2 ≩ N ≩ 100) が曞かれおいる続く <nobr>N × (N - 1) / 2</nobr> 行には各詊合の結果が曞かれおいるi + 1 行目 (1 ≩ i ≩ <nobr>N × (N - 1) / 2</nobr>) には敎数 A<sub>i</sub>B<sub>i</sub>C<sub>i</sub>D<sub>i</sub> (1 ≩ A<sub>i</sub> ≩ N1 ≩ B<sub>i</sub> ≩ N0 ≩ C<sub>i</sub> ≩ 1000 ≩ D<sub>i</sub> ≩ 100) が空癜を区切りずしお曞かれおおりチヌム A<sub>i</sub> ずチヌム B<sub>i</sub> が察戊しチヌム A<sub>i</sub> の埗点が C<sub>i</sub> 点チヌム B<sub>i</sub> の埗点が D<sub>i</sub> 点であったこずを衚す党おの i に぀いお A<sub>i</sub> ≠ B<sub>i</sub> であり同じ組み合わせの察戊が曞かれおいるこずはない </p> <h2> 出力</h2> <p> 出力は N 行からなる各行は 1 ぀の敎数からなり i 行目 (1 ≩ i ≩ N) の敎数はチヌム i の順䜍を衚す </p> <h2> 入出力䟋</h2> <h3>入力䟋 1</h3> <pre> 4 1 2 0 1 1 3 2 1 1 4 2 2 2 3 1 1 2 4 3 0 3 4 1 3 </pre> <h3>出力䟋 1</h3> <pre> 2 1 4 2 </pre> <p> 入出力䟋 1 は問題文䞭の䟋に察応しおいる </p> <h3>入力䟋 2</h3> <pre> 5 1 2 1 1 3 4 3 1 5 1 1 2 2 3 0 0 4 5 2 3 1 3 0 2 5 2 2 2 4 1 4 5 3 5 4 0 2 4 0 1 </pre> <h3>出力䟋 2</h3> <pre> 2 4 1 4 3 </pre> <p> 入出力䟋 2 における結果は以䞋の通りである </p> <table style="margin-left: 50px; margin-right: 50px;" border="1" cellspacing="1"> <tr> <th></th> <th align="center">&nbsp;&nbsp;勝ち数&nbsp;&nbsp;</th> <th align="center">&nbsp;&nbsp;負け数&nbsp;&nbsp;</th> <th align="center">&nbsp;&nbsp;匕き分け数&nbsp;&nbsp;</th> <th align="center">&nbsp;&nbsp;勝ち点&nbsp;&nbsp;</th> </tr> <tr> <th align="center">&nbsp;&nbsp;チヌム 1&nbsp;&nbsp;</th> <td align="center">2</td> <td align="center">1</td> <td align="center">1</td> <td align="center">7</td> </tr> <tr> <th align="center">&nbsp;&nbsp;チヌム 2&nbsp;&nbsp;</th> <td align="center">0</td> <td align="center">1</td> <td align="center">3</td> <td align="center">3</td> </tr> <tr> <th align="center">&nbsp;&nbsp;チヌム 3&nbsp;&nbsp;</th> <td align="center">3</td> <td align="center">0</td> <td align="center">1</td> <td align="center">10</td> </tr> <tr> <th align="center">&nbsp;&nbsp;チヌム 4&nbsp;&nbsp;</th> <td align="center">1</td> <td align="center">3</td> <td align="center">0</td> <td align="center">3</td> </tr> <tr> <th align="center">&nbsp;&nbsp;チヌム 5&nbsp;&nbsp;</th> <td align="center">1</td> <td align="center">2</td> <td align="center">1</td> <td align="center">4</td> </tr> </table> <br> <div class="source"> <p class="source"> 問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p00523
<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> バヌムクヌヘン(Baumkuchen) </H1> <br/> <p> JOI 君は効のJOI 子ちゃんずJOI 矎ちゃんず䞀緒におや぀を食べようずしおいる今日のおや぀は3 人の倧奜物のバヌムクヌヘンだ </p> <p> バヌムクヌヘンは䞋図のような円筒圢のお菓子である3 人に分けるためにJOI 君は半埄方向に刃を3回入れおこれを3 ぀のピヌスに切り分けなければならないただしこのバヌムクヌヘンは本物の朚材のように固いので刃を入れるのは簡単ではないそのためこのバヌムクヌヘンにはあらかじめ $N$ 個の切れ蟌みが入っおおりJOI 君は切れ蟌みのある䜍眮でのみ切るこずができる切れ蟌みに1 から $N$ たで時蚈回りに番号をふったずき$1 \leq i \leq N - 1$ に察し $i$ 番目の切れ蟌みず$i + 1$ 番目の切れ蟌みの間の郚分の倧きさは $A_i$ であるたた $N$ 番目の切れ蟌みず1 番目の切れ蟌みの間の郚分の倧きさは $A_N$ である </p> <br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_baumkuchen_1"><br> 図1: バヌムクヌヘンの䟋 $N = 6, A_1 = 1, A_2 = 5, A_3 = 4, A_4 = 5, A_5 = 2, A_6 = 4$ </center><br><br> <h2>課題</h2> <p> 切れ蟌みの個数 $N$ ず各郚分の倧きさを衚す敎数 $A_1,...,A_N$ が䞎えられるバヌムクヌヘンを3 ぀に切り分けたずきの最も小さいピヌスの倧きさの最倧倀を出力するプログラムを䜜成せよ </p> <h2>入力</h2> <p> 暙準入力から以䞋のデヌタを読み蟌め </p> <ul> <li> 1 行目には敎数 $N$ が曞かれおいるこれはバヌムクヌヘンに $N$ 個の切れ蟌みがあるこずを衚す</li> <li> 続く$N$ 行のうちの $i$ 行目$(1 \leq i \leq N)$ には敎数 $A_i$ が曞かれおいるこれは $i$ 番目の切れ蟌みず $i + 1$ 番目の切れ蟌みの間の郚分 ($i = N$ のずきは $N$ 番目の切れ蟌みず1 番目の切れ蟌みの間の郚分) の倧きさが $A_i$ であるこずを衚す</li> </ul> <h2>出力</h2> <p> 暙準出力にバヌムクヌヘンを3 ぀に切り分けたずきの最も小さいピヌスの倧きさの最倧倀を衚す敎数を1 行で出力せよ </p> <h2>制限</h2> <p> すべおの入力デヌタは以䞋の条件を満たす </p> <ul> <li>$3 \leq N \leq 100000$</li> <li>$1 \leq A_i \leq 1000000000 (1 \leq i \leq N)$</li> </ul> <h2>入出力䟋</h2> <h3>入力䟋 1 </h3> <pre> 6 1 5 4 5 2 4 </pre> <h3>出力䟋 1 </h3> <pre> 6 </pre> <br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_baumkuchen_2"><br> 図2: 1 番目の切れ蟌みず3 番目の切れ蟌みず5 番目の切れ蟌みで切るのが最善である </center><br><br> <h3>入力䟋 2 </h3> <pre> 30 1 34 44 13 30 1 9 3 7 7 20 12 2 44 6 9 44 31 17 20 33 18 48 23 19 31 24 50 43 15 </pre> <h3>出力䟋 2 </h3> <pre> 213 </pre> <br> <div class="source"> <p class="source"> 問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p00734
<h1><font color="#000000">Problem A:</font> Equal Total Scores</h1> <!-- <img src="https://judgeapi.u-aizu.ac.jp/resources/images/A-1" width=300 align=left> --> <!-- begin en only --> <p> Taro and Hanako have numbers of cards in their hands. Each of the cards has a score on it. Taro and Hanako wish to make the total scores of their cards equal by exchanging one card in one's hand with one card in the other's hand. Which of the cards should be exchanged with which? </p> <!-- end en only --> <!-- begin en only --> <p> Note that they have to exchange their cards even if they already have cards of the same total score. </p> <!-- end en only --> <h3>Input</h3> <!-- begin en only --> <p> The input consists of a number of datasets. Each dataset is formatted as follows. <!-- end en only --> <blockquote> <i>n</i>&nbsp;<i>m</i><br> <i>s</i><sub>1</sub> <br> <i>s</i><sub>2</sub> <br> ...<br> <i>s</i><sub><i>n</i></sub> <br> <i>s</i><sub><i>n</i>+1</sub> <br> <i>s</i><sub><i>n</i>+2</sub> <br> ...<br> <i>s</i><sub><i>n</i>+<i>m</i></sub> <br> </blockquote> <!-- begin en only --> </p> <p>The first line of a dataset contains two numbers <i>n</i> and <i>m</i> delimited by a space, where <i>n</i> is the number of cards that Taro has and <i>m</i> is the number of cards that Hanako has. The subsequent <i>n</i>+<i>m</i> lines list the score for each of the cards, one score per line. The first <i>n</i> scores (from <i>s</i><sub>1</sub> up to <i>s</i><sub><i>n</i></sub>) are the scores of Taro's cards and the remaining <i>m</i> scores (from <i>s</i><sub><i>n</i>+1</sub> up to <i>s</i><sub><i>n</i>+<i>m</i></sub>) are Hanako's. </p> <p> The numbers <i>n</i> and <i>m</i> are positive integers no greater than 100. Each score is a non-negative integer no greater than 100. </p> <!-- end en only --> <!-- begin en only --> <p> The end of the input is indicated by a line containing two zeros delimited by a single space. </p> <!-- end en only --> <h3>Output</h3> <!-- begin en only --> <p> For each dataset, output a single line containing two numbers delimited by a single space, where the first number is the score of the card Taro gives to Hanako and the second number is the score of the card Hanako gives to Taro. If there is more than one way to exchange a pair of cards that makes the total scores equal, output a pair of scores whose sum is the smallest. </p> <p> In case no exchange can make the total scores equal, output a single line containing solely -1. The output must not contain any superfluous characters that do not conform to the format. </p> <!-- end en only --> <h3>Sample Input</h3> <pre> 2 2 1 5 3 7 6 5 3 9 5 2 3 3 12 2 7 3 5 4 5 10 0 3 8 1 9 6 0 6 7 4 1 1 2 1 2 1 4 2 3 4 3 2 3 1 1 2 2 2 0 0 </pre> <h3>Output for the Sample Input</h3> <pre> 1 3 3 5 -1 2 2 -1 </pre>
p02709
<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> children standing in a line from left to right. The activeness of the <var>i</var>-th child from the left is <var>A_i</var>.</p> <p>You can rearrange these children just one time in any order you like.</p> <p>When a child who originally occupies the <var>x</var>-th position from the left in the line moves to the <var>y</var>-th position from the left, that child earns <var>A_x \times |x-y|</var> happiness points.</p> <p>Find the maximum total happiness points the children can earn.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 2000</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>Print the maximum total happiness points the children can earn.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 1 3 4 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>20 </pre> <p>If we move the <var>1</var>-st child from the left to the <var>3</var>-rd position from the left, the <var>2</var>-nd child to the <var>4</var>-th position, the <var>3</var>-rd child to the <var>1</var>-st position, and the <var>4</var>-th child to the <var>2</var>-nd position, the children earns <var>1 \times |1-3|+3 \times |2-4|+4 \times |3-1|+2 \times |4-2|=20</var> happiness points in total.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 5 5 6 1 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>58 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>6 8 6 9 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>85 </pre></section> </div> </span>
p01826
<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 I: Live Programming </h2> <p> A famous Japanese idol group, JAG48, is planning the program for its next live performance. They have $N$ different songs, $song_1$, $song_2$, ..., and $song_N$. Each song has three integer param- eters, $t_i$, $p_i$, and $f_i$: $t_i$ denotes the length of $song_i$, $p_i$ denotes the basic satisfaction points the audience will get when $song_i$ is performed, and $f_i$ denotes the feature value of songi that affects the audience's satisfaction. During the live performance, JAG48 can perform any number (but at least one) of the $N$ songs, unless the total length of the chosen songs exceeds the length of the live performance $T$. They can decide the order of the songs to perform, but they cannot perform the same song twice or more. </p> <p> The goal of this live performance is to maximize the total satisfaction points that the audience will get. In addition to the basic satisfaction points of each song, the difference between the feature values of the two songs that are performed consecutively affects the total satisfaction points. If there is no difference, the audience will feel comfortable. However, the larger the difference will be, the more frustrated the audience will be. </p> <p> Thus, the total satisfaction points will be calculated as follows: </p> <ul> <li> If $song_x$ is the first song of the live performance, the total satisfaction points just after $song_x$ is equal to $p_x$.</li> <li> If $song_x$ is the second or subsequent song of the live performance and is performed just after $song_y$, $p_x -(f_x -f_y)^2$ is added to the total satisfaction points, because the audience will get frustrated if $f_x$ and $f_y$ are different. </ul> <p> Help JAG48 find a program with the maximum total satisfaction points. </p> <h3>Input</h3> <p> The input is formatted as follows.<br> <br> $N$ $T$<br> $t_1$ $p_1$ $f_1$<br> : : :<br> $t_N$ $p_N$ $f_N$<br> <br> </p> <p> The first line contains two integers $N$ and $T$: the number of the available $song_s$ $N$ ($1 \leq N \leq 4,000$), and the length of the live performance $T$ ($1 \leq T \leq 4,000$). </p> <p> The following $N$ lines represent the parameters of the songs. The $i$-th line of them contains three integers, which are the parameters of $song_i$: the length $t_i$ ($1 \leq t_i \leq 4,000$), the basic satisfaction points $p_i$ ($1 \leq p_i \leq 10^8$), and the feature value $f_i$ ($1 \leq f_i \leq 10^4$). </p> <p> You can assume that there is at least one song whose length is less than or equal to $T$. </p> <h3>Output</h3> <p> Output the maximum total satisfaction points that the audience can get during the live performance. </p> <h3>Sample Input</h3> <pre> 2 10 10 200 1 10 100 100 </pre> <h3>Output for the Sample Input</h3> <pre> 200 </pre> <h3>Sample Input</h3> <pre> 3 15 5 100 1 5 100 2 5 100 4 </pre> <h3>Output for the Sample Input</h3> <pre> 295 </pre> <h3>Sample Input</h3> <pre> 3 10 5 200 200 5 200 201 5 300 1 </pre> <h3>Output for the Sample Input</h3> <pre> 399 </pre> <h3>Sample Input</h3> <pre> 3 20 5 100 200 5 100 201 5 300 1 </pre> <h3>Output for the Sample Input</h3> <pre> 300 </pre> <h3>Sample Input</h3> <pre> 5 61 14 49 7 31 46 4 30 55 5 52 99 1 34 70 3 </pre> <h3>Output for the Sample Input</h3> <pre> 103 </pre>
p00364
<H1>Bange Hills Tower</H1> <p> A project is underway to build a new viewing tower in Bange town called “Bange Hills Tower” whose selling point will be the gorgeous view of the entire main keep of Wakamatsu Castle from top to bottom. Therefore, the view line from the top of the tower must reach the bottom of the keep without being hindered by any of the buildings in the town. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2017_wakamatsuCastle" width="600"></center><br/> <p> Write a program to calculate the minimum tower height required to view the keep in its entirety based on the following information: the planned location of the tower and the heights and locations of existing buildings. Assume all the buildings, including the keep, are vertical lines without horizontal stretch. “view of the entire keep” means that the view line from the tower top can cover the keep from the bottom to the top without intersecting (contacts at the top are exempted) any of the other vertical lines (i.e., buildings). </p> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> <var>N</var> <var>t</var> <var>x_1</var> <var>h_1</var> <var>x_2</var> <var>h_2</var> : <var>x_N</var> <var>h_N</var> </pre> <p> The first line provides the number of existing buildings <var>N</var> (1&le;<var>N</var>&le;1000) and the planned location of the tower <var>t</var> (2&le;<var>t</var>&le;10<sup>5</sup>) in integers. Each of the subsequent <var>N</var> lines provides the information of the <var>i</var>-th building: location <var>x_i</var> (1 &le; <var>x_i</var> &lt; <var>t</var>) and height from the ground <var>h_i</var> (1 &le; <var>h_i</var> &le; 100). All position information is one-dimensional along the ground line whose origin coincides with the Keep location. No more than one building is located in the same location (i.e. if <var>i &ne; j</var>, then <var>x_i &ne; x_j</var>). </p> <h2>Output</h2> <p> Output the required height as a real number. No limits on the number of decimal places as long as the error does not exceed &plusmn; 10<sup>-3</sup>. </p> <h2>Sample Input 1</h2> <pre> 3 10 6 4 4 2 3 2 </pre> <h2>Sample Output 1</h2> <pre> 6.666667 </pre>
p02359
<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>The Maximum Number of Customers</H1> <p> $N$ persons visited a restaurant. The restaurant is open from 0 to $T$. The $i$-th person entered the restaurant at $l_i$ and left at $r_i$. Find the maximum number of persons during the business hours. </p> <h2>Constraints</h2> <ul> <li>$ 1 \leq N \leq 10^5 $</li> <li>$ 1 \leq T \leq 10^5 $</li> <li>$ 0 \leq l_i < r_i \leq T $</li> </ul> <h2>Input</h2> <p> The input is given in the following format. </p> <p> $N$ $T$<br> $l_1$ $r_1$<br> $l_2$ $r_2$<br> :<br> $l_N$ $r_N$<br> </p> <h2>Output</h2> <p> Print the maximum number of persons in a line. </p> <h2>Sample Input 1</h2> <pre> 6 10 0 2 1 3 2 6 3 8 4 10 5 10 </pre> <h2>Sample Output 1</h2> <pre> 4 </pre> <h2>Sample Input 2</h2> <pre> 2 2 0 1 1 2 </pre> <h2>Sample Output 2</h2> <pre> 1 </pre>
p03118
<span class="lang-en"> <p>Score : <var>2718</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a very long bench. The bench is divided into <var>M</var> sections, where <var>M</var> is a very large integer.</p> <p>Initially, the bench is vacant. Then, <var>M</var> people come to the bench one by one, and perform the following action:</p> <ul> <li>We call a section <em>comfortable</em> if the section is currently unoccupied and is not adjacent to any occupied sections. If there is no comfortable section, the person leaves the bench. Otherwise, the person chooses one of comfortable sections uniformly at random, and sits there. (The choices are independent from each other).</li> </ul> <p>After all <var>M</var> people perform actions, Snuke chooses an interval of <var>N</var> consecutive sections uniformly at random (from <var>M-N+1</var> possible intervals), and takes a photo. His photo can be described by a string of length <var>N</var> consisting of <code>X</code> and <code>-</code>: the <var>i</var>-th character of the string is <code>X</code> if the <var>i</var>-th section from the left in the interval is occupied, and <code>-</code> otherwise. Note that the photo is directed. For example, <code>-X--X</code> and <code>X--X-</code> are different photos.</p> <p>What is the probability that the photo matches a given string <var>s</var>? This probability depends on <var>M</var>. You need to compute the limit of this probability when <var>M</var> goes infinity.</p> <p>Here, we can prove that the limit can be uniquely written in the following format using three <strong>rational</strong> numbers <var>p, q, r</var> and <var>e = 2.718 \ldots</var> (the base of natural logarithm):</p> <p><var>p + \frac{q}{e} + \frac{r}{e^2}</var></p> <p>Your task is to compute these three rational numbers, and print them modulo <var>10^9 + 7</var>, as described in Notes section.</p> </section> </div> <div class="part"> <section> <h3>Notes</h3><p>When you print a rational number, first write it as a fraction <var>\frac{y}{x}</var>, where <var>x, y</var> are integers and <var>x</var> is not divisible by <var>10^9 + 7</var> (under the constraints of the problem, such representation is always possible). Then, you need to print the only integer <var>z</var> between <var>0</var> and <var>10^9 + 6</var>, inclusive, that satisfies <var>xz \equiv y \pmod{10^9 + 7}</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 1000</var></li> <li><var>|s| = N</var></li> <li><var>s</var> consists of <code>X</code> and <code>-</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>s</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print three rational numbers <var>p, q, r</var>, separated by spaces.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>1 X </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>500000004 0 500000003 </pre> <p>The probability that a randomly chosen section is occupied converge to <var>\frac{1}{2} - \frac{1}{2e^2}</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 --- </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 0 0 </pre> <p>After the actions, no three consecutive unoccupied sections can be left.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 X--X- </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 0 1 </pre> <p>The limit is <var>\frac{1}{e^2}</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>5 X-X-X </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>500000004 0 833333337 </pre> <p>The limit is <var>\frac{1}{2} - \frac{13}{6e^2}</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 5</h3><pre>20 -X--X--X-X--X--X-X-X </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>0 0 183703705 </pre> <p>The limit is <var>\frac{7}{675e^2}</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 6</h3><pre>100 X-X-X-X-X-X-X-X-X-X--X-X-X-X-X-X-X-X-X-X-X-X-X-X-X--X--X-X-X-X--X--X-X-X--X-X-X--X-X--X--X-X--X-X-X- </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 6</h3><pre>0 0 435664291 </pre></section> </div> </span>
p01125
<h1>Mysterious Gems</h1> <p> 宇宙暊 1603〜1867 幎人々はその時代のこずを EDO 時代ず呌ぶEDO ずは圓時最先端の宇宙航行技術Enhanced Driving Operation のこずであり、1603 幎に Dr.Izy によっお開発された </p> <p> あなたは宇宙冒険家であり宇宙を飛び回っお様々な惑星を冒険しおいたその冒険の途䞭であなたはずおも䞍思議な惑星を発芋したその惑星には至るずころに䞃色に茝く䞍思議な宝石が萜ちおいたあなたはその惑星ぞの降䞋を詊みようず考えたが重倧な問題のためにそれは䞍可胜であるこずがわかったその惑星の空気には人間が觊れただけで即死しおしたうような猛毒の成分が含たれおいたのだ </p> <p> そこであなたはロボットを䜿っお宝石を回収するこずを考え぀いたあなたはその惑星の呚回軌道にお埅機するそしお降䞋させたロボットを遠隔操䜜するこずによっお宝石を回収するのだあなたはロボットに「移動する方向」ず「移動する距離」の組からなる呜什の列によっおロボットを遠隔操䜜するロボットは移動経路䞊到達点を含むに宝石を芋぀けるずそれらを党お回収する </p> <p> あなたの仕事はロボットが䞎えられた党おの呜什の実行を終えたずきに党おの宝石を回収するこずができたかどうかを刀定するプログラムを曞くこずである </p> <p> なおロボットが䞍思議な宝石を回収する範囲はそれほど広くないそのためロボットが移動する範囲は党お 2 次元の平面で衚すこずができるそしおロボットが移動する範囲は (0,0) および (20,20) をそれぞれ巊䞋隅および右䞊隅ずする正方圢の内郚境界線を含むであるロボットは垞に範囲の䞭倮すなわち (10,10) の座暙に降䞋するたた党おの宝石は䞭倮以倖の栌子点䞊にあるこずが保蚌されおいる </p> <h3>Input</h3> <p> 入力は耇数のデヌタセットにより構成される </p> <p> それぞれのデヌタセットの先頭行には単䞀の正の敎数 <i>N</i> (1 &lt;= <i>N</i> &lt;= 20) が含たれる。これはロボットが移動可胜な範囲内にある䞍思議な宝石の個数を衚す次の <i>N</i> 行にはそれぞれ <i>x<sub>i</sub></i> および <i>y<sub>i</sub></i> (0 &lt;= <i>x<sub>i</sub></i> , <i>y<sub>i</sub></i> &lt;= 20) が含たれこれは <i>i</i> 番目の䞍思議な宝石の萜ちおいる座暙を衚すなお1 ぀の堎所に耇数の宝石が萜ちおいるこずはない </p> <p> 次の行には単䞀の敎数 <i>M</i> (1 &lt;= <i>M</i> &lt;= 30) が含たれこれはロボットに䞎えた呜什の個数を衚すこの埌の <i>M</i> 行にはそれぞれ <i>d<sub>j</sub></i> ずひず぀の正の敎数 <i>l<sub>j</sub></i> が含たれるこれは <i>j</i> 番目の呜什における方向および移動量を衚すただし方向は NESW のいずれかの文字であり順に北東南西を衚す北は y 軞の正方向東は x 軞の正方向なおロボットが移動可胜な範囲を超えるような呜什は䞎えられないこずが保蚌されおいる </p> <p> 入力は N = 0 のずきに終了しこれはデヌタセットに含たれない </p> <h3>Output</h3> <p> それぞれのデヌタセットに぀いおロボットが党おの宝石を収集できるずきは「Yes」ずそうでないずきは「No」ず 1 行に出力しなさい </p> <h3>Sample Input</h3> <pre> 2 10 11 11 12 2 N 2 E 1 2 10 11 11 12 2 N 2 W 1 3 0 15 5 10 5 15 5 W 10 S 10 N 20 E 10 S 10 0 </pre> <h3>Output for the Sample Input</h3> <pre> Yes No No </pre>