question_id
stringlengths
6
6
content
stringlengths
1
27.2k
p02728
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>We have a tree with <var>N</var> vertices numbered <var>1</var> to <var>N</var>. The <var>i</var>-th edge in this tree connects Vertex <var>a_i</var> and <var>b_i</var>. For each <var>k=1, ..., N</var>, solve the problem below:</p> <ul> <li>Consider writing a number on each vertex in the tree in the following manner:<ul> <li>First, write <var>1</var> on Vertex <var>k</var>.</li> <li>Then, for each of the numbers <var>2, ..., N</var> in this order, write the number on the vertex chosen as follows:<ul> <li>Choose a vertex that still does not have a number written on it and is adjacent to a vertex with a number already written on it. If there are multiple such vertices, choose one of them at random.</li> </ul> </li> </ul> </li> <li>Find the number of ways in which we can write the numbers on the vertices, modulo <var>(10^9+7)</var>.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>2 \leq N \leq 2 \times 10^5</var></li> <li><var>1 \leq a_i,b_i \leq N</var></li> <li>The given graph is a tree.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>a_1</var> <var>b_1</var> <var>:</var> <var>a_{N-1}</var> <var>b_{N-1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>For each <var>k=1, 2, ..., N</var> in this order, print a line containing the answer to the problem.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 2 1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 1 1 </pre> <p>The graph in this input is as follows:</p> <p><img alt="Figure" src="https://img.atcoder.jp/ghi/1c88b0eb716ba399b1c5d6565ab62337.png"/></p> <p>For <var>k=1</var>, there are two ways in which we can write the numbers on the vertices, as follows:</p> <ul> <li>Writing <var>1, 2, 3</var> on Vertex <var>1, 2, 3</var>, respectively</li> <li>Writing <var>1, 3, 2</var> on Vertex <var>1, 2, 3</var>, respectively</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 1 </pre> <p>The graph in this input is as follows:</p> <p><img alt="Figure" src="https://img.atcoder.jp/ghi/c47c7798f88e7bfec30fbd664dc9ad50.png"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 1 2 2 3 3 4 3 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>2 8 12 3 3 </pre> <p>The graph in this input is as follows:</p> <p><img alt="Figure" src="https://img.atcoder.jp/ghi/e9c09403f8d96ae4e679a226993defa6.png"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>8 1 2 2 3 3 4 3 5 3 6 6 7 6 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>40 280 840 120 120 504 72 72 </pre> <p>The graph in this input is as follows:</p> <p><img alt="Figure" src="https://img.atcoder.jp/ghi/a85459a03d436560bfe2e911d8cec4e6.png"/></p></section> </div> </span>
p01807
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]} }); </script> <script type="text/javascript" async src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"> </script> <!-- begin en only --> <h3><u>Stamp Rally</u></h3> <!-- end en only --> <!-- begin ja only --> <h3><u>スタンプラリヌ</u></h3> <!-- end ja only --> <!-- end en only --> <!-- begin ja only --> <p>日本アミュヌズメントグルヌプ (Japan Amusement Group, JAG) では島囜を暡したテヌマパヌクでのむベントを䌁画しおいる このむベントでは参加者は橋を枡るたびに橋ごずに決められたスタンプをスタンプ垳に順番に抌しおいく 甚意されたスタンプは以䞋の7皮類のどれかである </p><pre>a ( ) [ ] + *</pre><p>スタヌトからゎヌルたで橋を枡り歩いお抌されたスタンプの列が正しい数匏になればクリアである ただし橋を枡る向きは決たっおいお逆向きに枡るこずはできない 同じ橋を䜕床も枡っおよく最終的にゎヌル地点に到着するのであれば䞀床ゎヌル地点に着いた埌に匕き続きスタンプを集めおもよい 正しい数匏ずは以䞋の BNF で定矩される &lt;expression&gt; である </p> <pre>&lt;expression&gt; ::= &lt;term&gt; | &lt;expression&gt; "+" &lt;term&gt; &lt;term&gt; ::= &lt;factor&gt; | &lt;term&gt; "*" &lt;factor&gt; &lt;factor&gt; ::= "a" | "(" &lt;expression&gt; ")" | "[" &lt;expression&gt; "]"</pre> <p>スタヌト・ゎヌルず橋ごずのスタンプを決めたので関係者で詊しにやっおみたがなかなかクリアする人が珟れない もしかしたらこの蚭定ではクリアするこずができないのかもしれない </p> <p>スタヌト・ゎヌルず橋の情報が䞎えられるのでクリア可胜かどうかを刀定するプログラムを曞きなさい </p> <!-- end ja only --> <h3>Input</h3> <!-- begin ja only --> <p>入力は50個以䞋のデヌタセットからなる各デヌタセットは以䞋の圢匏で衚される </p> <blockquote><var>n</var> <var>m</var> <var>s</var> <var>t</var><br><var>a</var><sub>1</sub> <var>b</var><sub>1</sub> <var>c</var><sub>1</sub><br>...<br><var>a<sub>m</sub></var> <var>b<sub>m</sub></var> <var>c<sub>m</sub></var></blockquote> <p>デヌタセットの最初の行は空癜文字1個で区切られた4個の敎数 <var>n</var>, <var>m</var>, <var>s</var>, <var>t</var> からなる <var>n</var> は島の数であり 1 &le; <var>n</var> &le; 200 ず仮定しおよい それぞれの島には 1 から <var>n</var> たでの番号が付けられおいる <var>m</var> は橋の数であり 1 &le; <var>m</var> &le; 100,000 ず仮定しおよい <var>s</var> はスタヌトの島の番号 <var>t</var> はゎヌルの島の番号であるスタヌトずゎヌルが同じ島であるこずもある 続く <var>m</var> 行のそれぞれは空癜文字1個で区切られた2個の敎数ず1個の文字からなる <var>a<sub>i</sub></var> <var>b<sub>i</sub></var> は <var>i</var> 番目の橋によっお島 <var>a<sub>i</sub></var> から島 <var>b<sub>i</sub></var> ぞ枡れるこずを衚し <var>c<sub>i</sub></var> は <var>i</var> 番目の橋で抌すスタンプを衚すある2぀の島の間に耇数の橋がかかっおいたり1぀の島の䞭で橋がかかっおいたりするこずもある </p> <p>入力の終わりは4぀のれロからなる1行で瀺される </p> <!-- end ja only --> <h3>Output</h3> <!-- begin ja only --> <p>各デヌタセットに察しおクリアできるならば"<samp>Yes</samp>"をできないならば"<samp>No</samp>"を1行に出力せよ </p> <!-- end ja only --> <h3>Sample Input</h3> <pre>4 5 1 4 1 2 ( 1 3 a 2 4 a 3 4 ) 3 2 + 4 4 1 2 1 3 ( 3 4 a 4 1 + 3 2 a 3 4 1 1 1 2 a 2 2 + 2 3 a 3 1 a 5 8 1 5 1 1 [ 1 2 ( 2 1 * 2 2 a 2 3 a 3 3 ) 3 4 ] 4 5 ) 2 14 1 1 1 2 a 1 2 ( 1 2 ) 1 2 [ 1 2 ] 1 2 + 1 2 * 2 1 a 2 1 ( 2 1 ) 2 1 [ 2 1 ] 2 1 + 2 1 * 0 0 0 0</pre> <h3>Output for Sample Input</h3> <pre>Yes No No Yes No</pre>
p02682
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have <var>A</var> cards, each of which has an integer <var>1</var> written on it. Similarly, we also have <var>B</var> cards with <var>0</var>s and <var>C</var> cards with <var>-1</var>s.</p> <p>We will pick up <var>K</var> among these cards. What is the maximum possible sum of the numbers written on the cards chosen?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>0 \leq A, B, C</var></li> <li><var>1 \leq K \leq A + B + C \leq 2 \times 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>A</var> <var>B</var> <var>C</var> <var>K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum possible sum of the numbers written on the cards chosen.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 1 1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>Consider picking up two cards with <var>1</var>s and one card with a <var>0</var>. In this case, the sum of the numbers written on the cards is <var>2</var>, which is the maximum possible value.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 2 3 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>2000000000 0 0 2000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>2000000000 </pre></section> </div> </span>
p03990
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Sigma and Sugim are playing a game.</p> <p>The game is played on a graph with <var>N</var> vertices numbered <var>1</var> through <var>N</var>. The graph has <var>N-1</var> red edges and <var>N-1</var> blue edges, and the <var>N-1</var> edges in each color forms a tree. The red edges are represented by pairs of integers <var>(a_i, b_i)</var>, and the blue edges are represented by pairs of integers <var>(c_i, d_i)</var>.</p> <p>Each player has his own piece. Initially, Sigma's piece is at vertex <var>X</var>, and Sugim's piece is at vertex <var>Y</var>.</p> <p>The game is played in turns, where turns are numbered starting from turn <var>1</var>. Sigma takes turns <var>1, 3, 5, ...</var>, and Sugim takes turns <var>2, 4, 6, ...</var>.</p> <p>In each turn, the current player either moves his piece, or does nothing. Here, Sigma can only move his piece to a vertex that is directly connected to the current vertex by a red edge. Similarly, Sugim can only move his piece to a vertex that is directly connected to the current vertex by a blue edge.</p> <p>When the two pieces come to the same vertex, the game ends immediately. If the game ends just after the operation in turn <var>i</var>, let <var>i</var> be the total number of turns in the game.</p> <p>Sigma's objective is to make the total number of turns as large as possible, while Sugim's objective is to make it as small as possible.</p> <p>Determine whether the game will end in a finite number of turns, assuming both players plays optimally to achieve their respective objectives. If the answer is positive, find the number of turns in the game.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 ≩ N ≩ 200,000</var></li> <li><var>1 ≩ X, Y ≩ N</var></li> <li><var>X \neq Y</var></li> <li><var>1 ≩ a_i, b_i, c_i, d_i ≩ N</var></li> <li>The <var>N-1</var> edges in each color (red and blue) forms a tree.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>X</var> <var>Y</var> <var>a_1</var> <var>b_1</var> <var>a_2</var> <var>b_2</var> <var>:</var> <var>a_{N-1}</var> <var>b_{N-1}</var> <var>c_1</var> <var>d_1</var> <var>c_2</var> <var>d_2</var> <var>:</var> <var>c_{N-1}</var> <var>d_{N-1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If the game will end in a finite number of turns, print the number of turns. Otherwise, print <code>-1</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 1 2 1 2 1 3 1 4 2 1 2 3 1 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p><img alt="" src="https://atcoder.jp/img/agc005/0f55f48518cb9031ee9f1cc30f686228.png"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 3 1 1 2 2 3 1 2 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>4 </pre> <p><img alt="" src="https://atcoder.jp/img/agc005/df982a9959ce46d5d5f63800f8972bff.png"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>4 1 2 1 2 3 4 2 4 1 2 3 4 1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>2 </pre> <p><img alt="" src="https://atcoder.jp/img/agc005/11ce9a2283a853025b7075769439d745.png"/></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>4 2 1 1 2 3 4 2 4 1 2 3 4 1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>-1 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 5</h3><pre>5 1 2 1 2 1 3 1 4 4 5 2 1 1 3 1 5 5 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>6 </pre></section> </div> </span>
p00345
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"> </script> <H1>実数既玄分数化</H1> <p> 実数のうち、小数郚が埪環するものず有限桁のものは分数ずしお衚すこずができたす。 </p> <br/> <p> 分数で衚すこずができる実数が䞎えられたずき、その実数ず等しい既玄分数それ以䞊玄分できない分数を出力するプログラムを䜜成せよ。 </p> <h2>Input</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>str</var> </pre> <p> 行に、倉換したい実数を衚す文字列 <var>str</var> が䞎えられる。実数の倀は 0 より倧きい。文字列は数字か「.」、「(」、「)」を含む、長さが 3 以䞊 8 以䞋の文字列である。「.」は小数点、「(」は数字の埪環の始たり、「)」は数字の埪環の終わりを瀺す。敎数郚にも小数郚にも、必ず桁以䞊の数字が䞎えられるずする。ただし、埪環小数が䞎えられた堎合、文字列は以䞋の条件を満たす。 </p> <ul> <li> 埪環の始たりず終わりのペアは、小数点の右偎に䞀床だけ珟れる。 </li> <li> 埪環の終わりを瀺す「)」は、文字列の末尟に珟れる。</li> <li> 埪環の始たりず終わりの間には、必ず桁以䞊の数字が䞎えられる。</li> </ul> <h2>Output</h2> <p> 実数を既玄分数で衚した圢匏分子の敎数に続けお「/」区切りで分母の敎数を䞊べたもので出力する。 </p> <h2>Sample Input 1</h2> <pre> 0.(3) </pre> <h2>Sample Output 1</h2> <pre> 1/3 </pre> <br/> <h2>Sample Input 2</h2> <pre> 1.0 </pre> <h2>Sample Output 2</h2> <pre> 1/1 </pre> <br/> <h2>Sample Input 3</h2> <pre> 5.2(143) </pre> <h2>Sample Output 3</h2> <pre> 52091/9990 </pre> <br/> <h2>Sample Input 4</h2> <pre> 0.0739 </pre> <h2>Sample Output 4</h2> <pre> 739/10000 </pre> <br/>
p02378
<H1>Bipartite Matching</H1> <p> A bipartite graph <var>G = (V, E)</var> is a graph in which the vertex set <var>V</var> can be divided into two disjoint subsets <var>X</var> and <var>Y</var> such that every edge <var>e &isin; E</var> has one end point in <var>X</var> and the other end point in <var>Y</var>. </p> <p> A matching <var>M</var> is a subset of edges such that each node in <var>V</var> appears in at most one edge in <var>M</var>. </p> <p> Given a bipartite graph, find the size of the matching which has the largest size. </p> <H2>Input</H2> <pre> <var>|X|</var> <var>|Y|</var> <var>|E|</var> <var>x<sub>0</sub></var> <var>y<sub>0</sub></var> <var>x<sub>1</sub></var> <var>y<sub>1</sub></var> : <var>x<sub>|E|-1</sub></var> <var>y<sub>|E|-1</sub></var> </pre> <p> <var>|X|</var> and <var>|Y|</var> are the number of vertices in <var>X</var> and <var>Y</var> respectively, and <var>|E|</var> is the number of edges in the graph <var>G</var>. The vertices in <var>X</var> are named with the numbers 0, 1,..., <var>|X|</var>-1, and vertices in <var>Y</var> are named with the numbers 0, 1,..., <var>|Y|</var>-1, respectively. </p> <p> <var>x<sub>i</sub></var> and <var>y<sub>i</sub></var> are the node numbers from <var>X</var> and <var>Y</var> respectevely which represent the end-points of the <var>i</var>-th edge. </p> <H2>Output</H2> <p> Print the largest size of the matching. </p> <H2>Constraints</H2> <ul> <li>1 &le; <var>|X|</var>, <var>|Y|</var> &le; 100</li> <li>0 &le; <var>|E|</var> &le; 10,000</li> </ul> <H2>Sample Input 1</H2> <pre> 3 4 6 0 0 0 2 0 3 1 1 2 1 2 3 </pre> <H2>Sample Output 1</H2> <pre> 3 </pre>
p03139
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We conducted a survey on newspaper subscriptions. More specifically, we asked each of the <var>N</var> respondents the following two questions:</p> <ul> <li>Question <var>1</var>: Are you subscribing to Newspaper X?</li> <li>Question <var>2</var>: Are you subscribing to Newspaper Y?</li> </ul> <p>As the result, <var>A</var> respondents answered "yes" to Question <var>1</var>, and <var>B</var> respondents answered "yes" to Question <var>2</var>.</p> <p>What are the maximum possible number and the minimum possible number of respondents subscribing to both newspapers X and Y?</p> <p>Write a program to answer this question.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 100</var></li> <li><var>0 \leq A \leq N</var></li> <li><var>0 \leq B \leq N</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A</var> <var>B</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum possible number and the minimum possible number of respondents subscribing to both newspapers, in this order, with a space in between.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>10 3 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 0 </pre> <p>In this sample, out of the <var>10</var> respondents, <var>3</var> answered they are subscribing to Newspaper X, and <var>5</var> answered they are subscribing to Newspaper Y.</p> <p>Here, the number of respondents subscribing to both newspapers is at most <var>3</var> and at least <var>0</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 7 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>5 2 </pre> <p>In this sample, out of the <var>10</var> respondents, <var>7</var> answered they are subscribing to Newspaper X, and <var>5</var> answered they are subscribing to Newspaper Y.</p> <p>Here, the number of respondents subscribing to both newspapers is at most <var>5</var> and at least <var>2</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>100 100 100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>100 100 </pre></section> </div> </span>
p01104
<h3><u>Making Lunch Boxes</u></h3> <p> Taro has been hooked on making lunch boxes recently. Taro has obtained a new lunch box recipe book today, and wants to try as many of the recipes listed in the book as possible. </p> <p> Enough of the ingredients for all the recipes are at hand, but they all are in vacuum packs of two. If only one of them is used leaving the other, the leftover will be rotten easily, but making two of the same recipe is not interesting. Thus he decided to make a set of lunch boxes, each with different recipe, that wouldn't leave any unused ingredients. </p> <p> Note that the book may include recipes for different lunch boxes made of the same set of ingredients. </p> <p> How many lunch box recipes can Taro try today at most following his dogma? </p> <h3>Input</h3> <p> The input consists of at most 50 datasets, each in the following format. </p> <pre> <i>n</i> <i>m</i> <i>b</i><sub>1,1</sub>...<i>b</i><sub>1,<i>m</i></sub> ... <i>b</i><sub><i>n,</i>1</sub>...<i>b</i><sub><i>n,m</i></sub> </pre> <p> The first line contains <i>n</i>, which is the number of recipes listed in the book, and <i>m</i>, which is the number of ingredients. Both <i>n</i> and <i>m</i> are positive integers and satisfy 1 &#8804; <i>n</i> &#8804; 500, 1 &#8804; <i>m</i> &#8804; 500 and <b>1 &#8804; <i>n</i> × <i>m</i> &#8804; 500</b>. The following <i>n</i> lines contain the information for each recipe with the string of length <i>m</i> consisting of 0 or 1. <i>b<sub>i,j</sub></i> implies whether the <i>i</i>-th recipe needs the <i>j</i>-th ingredient. 1 means the ingredient is needed for the recipe and 0 means not. Each line contains at least one 1. </p> <p> The end of the input is indicated by a line containing two zeros. </p> <h3>Output</h3> <p> For each dataset, output the maximum number of recipes Taro can try. </p> <h3>Sample Input</h3> <pre>4 3 110 101 011 110 7 1 1 1 1 1 1 1 1 4 5 10000 01000 00100 00010 6 6 111111 011000 100000 000010 100001 100100 0 0 </pre> <h3>Output for the Sample Input</h3> <pre>3 6 0 6 </pre>
p03093
<span class="lang-en"> <p>Score : <var>1200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Let <var>M</var> be a positive integer.</p> <p>You are given <var>2 N</var> integers <var>a_1, a_2, \ldots, a_{2 N}</var>, where <var>0 \leq a_i &lt; M</var> for each <var>i</var>.</p> <p>Consider dividing the <var>2 N</var> integers into <var>N</var> pairs. Here, each integer must belong to exactly one pair.</p> <p>We define the <em>ugliness</em> of a pair <var>(x, y)</var> as <var>(x + y) \mod M</var>. Let <var>Z</var> be the largest ugliness of the <var>N</var> pairs. Find the minimum possible value of <var>Z</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>1 \leq N \leq 10^5</var></li> <li><var>1 \leq M \leq 10^9</var></li> <li><var>0 \leq a_i &lt; M</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>a_1</var> <var>a_2</var> <var>\cdots</var> <var>a_{2N}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum possible value of <var>Z</var>, where <var>Z</var> is the largest ugliness of the <var>N</var> pairs.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 10 0 2 3 4 5 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5 </pre> <p>One solution is to form pairs <var>(0, 5), (2, 3)</var> and <var>(4, 9)</var>, with ugliness <var>5, 5</var> and <var>3</var>, respectively.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 10 1 9 1 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>Pairs <var>(1, 9)</var> and <var>(1, 9)</var> should be formed, with ugliness both <var>0</var>.</p></section> </div> </span>
p03569
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a string <var>s</var> consisting of lowercase English letters. Snuke can perform the following operation repeatedly:</p> <ul> <li>Insert a letter <code>x</code> to any position in <var>s</var> of his choice, including the beginning and end of <var>s</var>.</li> </ul> <p>Snuke's objective is to turn <var>s</var> into a palindrome. Determine whether the objective is achievable. If it is achievable, find the minimum number of operations required.</p> </section> </div> <div class="part"> <section> <h3>Notes</h3><p>A <em>palindrome</em> is a string that reads the same forward and backward. For example, <code>a</code>, <code>aa</code>, <code>abba</code> and <code>abcba</code> are palindromes, while <code>ab</code>, <code>abab</code> and <code>abcda</code> are not.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq |s| \leq 10^5</var></li> <li><var>s</var> consists of lowercase English letters.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>s</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If the objective is achievable, print the number of operations required. If it is not, print <code>-1</code> instead.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>xabxa </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>One solution is as follows (newly inserted <code>x</code> are shown in bold):</p> <p>xabxa → xa<strong>x</strong>bxa → xaxbxa<strong>x</strong></p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>ab </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 </pre> <p>No sequence of operations can turn <var>s</var> into a palindrome.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>a </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>0 </pre> <p><var>s</var> is a palindrome already at the beginning.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>oxxx </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>3 </pre> <p>One solution is as follows:</p> <p>oxxx → <strong>x</strong>oxxx → <strong>x</strong>xoxxx → <strong>x</strong>xxoxxx</p></section> </div> </span>
p01554
<h1>Kagisys</h1> <p>ある郚屋ではICカヌドを甚いお鍵を開け閉めする電子錠システムを甚いおいる。 このシステムは以䞋のように動䜜する。 </p> <p>各ナヌザヌが持぀ICカヌドを扉にかざすず、そのICカヌドのIDがシステムに枡される。 システムはIDが登録されおいる時、斜錠されおいるなら開錠し、そうでないのなら斜錠し、それぞれメッセヌゞが出力される。 IDが登録されおいない堎合は、登録されおいないずいうメッセヌゞを出力し、開錠及び斜錠はおこなわれない。 </p> <p>さお、珟圚システムにはN個のID(U<sub>1</sub>, U<sub>2</sub>, 

, U<sub>N</sub>)が登録されおおり、斜錠されおいる。 M回ICカヌドが扉にかざされ、そのIDはそれぞれ順番にT<sub>1</sub>, T<sub>2</sub>, 

, T<sub>M</sub>であるずする。 この時のシステムがどのようなメッセヌゞを出力するか求めよ。 </p> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる。 </p><blockquote> N<br>U<sub>1</sub><br>U<sub>2</sub><br>

<br>U<sub>N</sub><br>M<br>T<sub>1</sub><br>T<sub>2</sub><br>

<br>T<sub>M</sub><br></blockquote> <h2>Constraints</h2> <ul><li><p>N, Mは敎数である </p></li><li><p>1 &le; N &le; 256 </p></li><li><p>U<sub>i</sub>は1文字以䞊10文字以䞋の小文字英字のみからなる文字列である </p></li><li><p>U<sub>i</sub>はナニヌクである(i &ne; jならばU<sub>i</sub> &ne; U<sub>j</sub>) </p></li><li><p>1 &le; M &le; 256 </p></li><li><p>T<sub>i</sub>は1文字以䞊10文字以䞋の小文字英字のみからなる文字列である </p></li></ul> <h2>Output</h2> <p>各T<sub>1</sub>, T<sub>2</sub>, 

, T<sub>M</sub>に぀いお、 </p><ul><li><p>開錠された時は、&quot;Opened by &quot;の埌に続けおIDを、 </p></li><li><p>斜錠された時は、&quot;Closed by &quot;の埌に続けおIDを、 </p></li><li><p>IDが登録されおいないものだった堎合は&quot;Unknown &quot;の埌に続けおIDを それぞれ1行に出力せよ。 </p></li></ul> <p>初期状態では斜錠された状態である。 </p> <h2>Sample Input 1</h2> <pre>4 abcd efgh ijkl mnop 5 abcd abcc efgh abcd mnop </pre> <h2>Output for the Sample Input 1</h2> <pre>Opened by abcd Unknown abcc Closed by efgh Opened by abcd Closed by mnop </pre> <h2>Sample Input 2</h2> <pre>2 a abcdefghij 9 c bcdefghijk abcdefghij b a b a bcdefghijk c </pre> <h2>Output for the Sample Input 2</h2> <pre>Unknown c Unknown bcdefghijk Opened by abcdefghij Unknown b Closed by a Unknown b Opened by a Unknown bcdefghijk Unknown c </pre> <h2>Sample Input 3</h2> <pre>2 z x 2 z x </pre> <h2>Output for the Sample Input 3</h2> <pre>Opened by z Closed by x </pre>
p00596
<H1><font color="#000000">Problem B:</font> Dominoes Arrangement</H1> <pre> [0, 0] [0, 1] [1, 1] [0, 2] [1, 2] [2, 2] [0, 3] [1, 3] [2, 3] [3, 3] [0, 4] [1, 4] [2, 4] [3, 4] [4, 4] [0, 5] [1, 5] [2, 5] [3, 5] [4, 5] [5, 5] [0, 6] [1, 6] [2, 6] [3, 6] [4, 6] [5, 6] [6, 6] </pre> <p> Consider the standard set of 28 western dominoes as shown in the above figure. Given a subset of the standard set dominoes, decide whether this subset can be arranged in a straight row in accordance with the familiar playing rule that touching ends must match. For example, the subset [1, 1], [2, 2], [1, 2] can be arranged in a row (as [1, 1] followed by [1, 2] followed by [2, 2]), while the subset [1, 1], [0, 3], [1, 4] can not be arranged in one row. Note that as in usual dominoes playing any pair [i, j] can also be treated as [j, i]. </p> <p> Your task is to write a program that takes as input any subset of the dominoes and output either yes (if the input subset can be arranged in one row) or no (if the input set can not be arranged in one row). </p> <H2>Input</H2> <p> Input file consists of pairs of lines. The first line of each pair is the number of elements N (1 &le; N &le; 18) in the subset, and the second line is the elements of the subset separated by blanks, see the input sample below. </p> <p> The number of pairs (datasets) is less than 30. </p> <H2>Output</H2> <p> For each pair of lines of the input file, the corresponding output is either Yes or No, based on whether the input subset can be arranged in one line or not. </p> <H2>Sample Input</H2> <pre> 6 13 23 14 24 15 25 10 00 01 11 02 12 22 03 13 23 33 </pre> <H2>Output for the Sample Input</H2> <pre> Yes No </pre>
p02051
<h3>䞍思議なボタン</h3> <!-- begin ja only --> <p>あなたは町倖れにあるダンゞョンでコむンを皌ぐこずにしたこのダンゞョンには <i>N</i> 個の郚屋が存圚し<i>1</i> から <i>N</i> たでの番号が぀けられおいるたたダンゞョン内には「コむンボタン」「脱出ボタン」「ワヌプボタン」ず呌ばれる䞍思議なボタンが存圚するそれぞれのボタンの詳现は次の通りである</p> <ul> <li>コむンボタンは各郚屋にちょうど <i>1</i> 個存圚するコむンボタンは䜕回でも抌すこずができそのたびにコむンが <i>1</i> 枚手に入る</li> <li>脱出ボタンは各郚屋にちょうど <i>1</i> 個存圚する脱出ボタンを抌すずあなたはただちにダンゞョンから脱出しこの冒険を終了する</li> <li>ワヌプボタンは合蚈で <i>M</i> 個存圚するこのうち <i>i</i> 個目のワヌプボタンは郚屋 <i>a<sub>i</sub></i> に存圚し抌すこずであなたは郚屋 <i>b<sub>i</sub></i> にワヌプしさらにコむンが <i>c<sub>i</sub></i> 枚手に入るただし<strong><i>a<sub>i</sub> &lt; b<sub>i</sub></i></strong> および <strong><i>1 &le; c<sub>i</sub> &le; 3</i></strong> を満たすなおワヌプボタンが 1 ぀の郚屋に耇数ある堎合やワヌプボタンのたったく無い郚屋が存圚する堎合もある</li> </ul> <p>なおボタンを抌す以倖の方法で郚屋を移動するこずはできず耇数のボタンを同時に抌すこずもできないたたいずれのボタンも互いに区別可胜である</p> <p>あなたはこのダンゞョンを <i>Q</i> 回冒険したあなたの蚘憶が正しければ<i>j</i> 回目の冒険は郚屋 <i>1</i> から始たり最埌に郚屋 <i>d<sub>j</sub></i> にある脱出ボタンを抌しコむンの合蚈獲埗枚数はちょうど <i>e<sub>j</sub></i> 枚だったはずである<i>Q</i> 回の冒険それぞれに぀いおそのようなボタンの抌し方が䜕通りあるかを求めよ答えは倧きくなる可胜性があるので<i>10<sup>9</sup>+7</i> すなわち <i>1000000007</i> で割った䜙りを求めよ</p> <p>ただし2 通りの「ボタンの抌し方」が異なるずはボタンを抌した合蚈回数が異なるかたたはある敎数 <i>k</i> が存圚し<i>k</i> 回目に抌したボタンが異なるこずを指す</p> <p>なおもしかしたらあなたの蚘憶は間違っおおりそのようなボタンの抌し方は存圚しないかもしれないその堎合には <i>0</i> を出力せよ</p> <!-- end ja only --> <h3>Input</h3> <!-- begin ja only --> <p>入力は耇数のデヌタセットからなる 各デヌタセットは次の圢匏で衚される</p> <blockquote><i>N</i> <i>M</i> <i>a<sub>1</sub></i> <i>b<sub>1</sub></i> <i>c<sub>1</sub></i> <i>a<sub>2</sub></i> <i>b<sub>2</sub></i> <i>c<sub>2</sub></i> ... <i>a<sub>M</sub></i> <i>b<sub>M</sub></i> <i>c<sub>M</sub></i> <i>Q</i> <i>d<sub>1</sub></i> <i>e<sub>1</sub></i> <i>d<sub>2</sub></i> <i>e<sub>2</sub></i> ... <i>d<sub>Q</sub></i> <i>e<sub>Q</sub></i></blockquote> <p>デヌタセットの 1 行目には郚屋の数を衚す敎数 <i>N</i> ずワヌプボタンの数を衚す敎数 <i>M</i> が䞎えられ<i>1 &le; N, M &le; 2 000</i> を満たす続く <i>M</i> 行にはワヌプボタンの情報が䞎えられる<i>M</i> 行のうち <i>i</i> 行目には<i>i</i> 番目のワヌプボタンの存圚する郚屋番号 <i>a<sub>i</sub></i>ワヌプ先の郚屋番号 <i>b<sub>i</sub></i> および手に入るコむンの枚数 <i>c<sub>i</sub></i> が䞎えられ<i>1 &le; a<sub>i</sub> &lt; b<sub>i</sub> &le; N</i> および <i>1 &le; c<sub>i</sub> &le; 3</i> を満たす<i>M+2</i> 行目には冒険の回数を衚す敎数 <i>Q</i> が䞎えられ<i>1 &le; Q &le; 2 000</i> を満たす続く <i>Q</i> 行にはあなたの蚘憶にある冒険の情報が䞎えられる<i>Q</i> 行のうち <i>j</i> 行目には<i>j</i> 番目の冒険であなたが脱出ボタンを抌した郚屋番号 <i>d<sub>j</sub></i> およびコむンの獲埗枚数 <i>e<sub>j</sub></i> が䞎えられ<i>1 &le; d<sub>j</sub> &le; N</i> および <i>1 &le; e<sub>j</sub> &le; 10<sup>9</sup></i> を満たす</p> <p>入力の終わりは2 個のれロだけからなる行で衚される党デヌタセットの総数は 50 を超えない</p> <!-- end ja only --> <h3>Output</h3> <!-- begin ja only --> <p>各デヌタセットに぀いお出力は <i>Q</i> 行からなるこのうち <i>j</i> 行目には郚屋 <i>1</i> から始たり最埌に郚屋 <i>d<sub>j</sub></i> にある脱出ボタンを抌しコむンの合蚈獲埗枚数がちょうど <i>e<sub>j</sub></i> 枚であるようなボタンの抌し方の総数を<i>10<sup>9</sup>+7</i> で割った䜙りを出力せよ</p> <!-- end ja only --> <h3>Sample Input</h3><pre>4 9 1 2 1 1 2 2 1 3 1 1 3 2 1 3 3 2 3 1 2 3 2 1 4 1 3 4 2 8 1 5 2 5 3 5 4 5 1 1234567 2 1234567 3 1234567 4 1234567 4 8 1 2 1 1 2 1 1 2 3 3 4 3 1 4 2 2 4 1 2 4 3 2 4 3 8 1 3 2 6 3 8 4 12 1 31415926 2 53589793 3 23846 4 26433832 0 0 </pre><h3>Output for the Sample Input</h3><pre>1 9 37 21 1 2469133 307629943 60012504 1 16 0 424 1 160769377 0 43581113 </pre>
p02401
<H1>Simple Calculator</H1> <p> Write a program which reads two integers <var>a</var>, <var>b</var> and an operator <var>op</var>, and then prints the value of <var>a</var> <var>op</var> <var>b</var>. </p> <p> The operator <var>op</var> is '+', '-', '*' or '/' (sum, difference, product or quotient). The division should truncate any fractional part. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each dataset is given in the following format. </p> <pre> <var>a</var> <var>op</var> <var>b</var> </pre> <p> The input ends with a dataset where <var>op</var> = '?'. Your program should not process for this dataset. </p> <H2>Output</H2> <p> For each dataset, print the value in a line. </p> <h2>Constraints</h2> <ul> <li> 0 &le; <var>a</var>, <var>b</var> &le; 20000</sup></li> <li>No divisions by zero are given.</li> </ul> <H2>Sample Input 1</H2> <pre> 1 + 2 56 - 18 13 * 2 100 / 10 27 + 81 0 ? 0 </pre> <H2>Sample Output 1</H2> <pre> 3 38 26 10 108 </pre>
p01387
<div> <h1 class="title">問題 L : <span style="font-size:110%;font-family:times new roman;"><i>L</i></span> 番目の数字</h1> <p>反乱を嗅ぎ぀けた倚くの G○○gle のコヌダヌが我々を取り抌さえにやっおきた かなりの数だ その䞭には東京倧孊時代に僕らを優しく指導しおくれた先茩たちも倚く芋受けられる 残念ながら今では敵同士だ</p> <dl class="docutils"> <dt>wata</dt> <dd>「予想以䞊の数だ 」</dd> <dt>(iwi)</dt> <dd>「ああ我々が超高速指数時間アルゎリズムを持っおいるからず蚀っおそれは圌らにようやく䞊んだに過ぎないこの数では 」</dd> <dt></dt> <dd>「心配芁らない君たちアルゎリズムをこっちに枡すんだ」</dd> </dl> <p>声がした窓の倖を芋るずG○○gle の建物に向きあう集団がいた 黒の生地に赀で I緑で ○黄色で M ず曞かれた T シャツ 
 圌らは I○M か そしお奇劙なこずに圌らは向かっおくる G○○gle のコヌダヌ達を キヌボヌドに觊れるこずなく倒しおいた どうなっおいる</p> <dl class="docutils"> <dt>(iwi)</dt> <dd>「  ぀いに Wats○n 2 は完成したのか」</dd> <dt>wata</dt> <dd>「どういうこずだ」</dd> </dl> <p>2011 幎I○M は圌らの高い技術力を掻甚し 自然蚀語で出題されたクむズに高速か぀正確に応答するシステムである Wats○n を完成させ クむズ番組におクむズ王ず呌ばれおきた人間たちに勝利した そしお 20XX 幎の今Wats○n は プログラミングコンテストの問題に察し解答のプログラムを䜜成するシステムずしお生たれ倉わったのだ</p> <p>I○M の登堎により我々を取り囲む人数が枛っおゆく</p> <dl class="docutils"> <dt>wata</dt> <dd>「チャンスだ半分は任せられるか」</dd> <dt>(iwi)</dt> <dd>「もちろんだ」</dd> </dl> <p>僕は劄想ず決別したこずにより党おを思い出しおいた 圓然圓時の知識や経隓は今から芋ればレベルが䜎すぎお圹に立たない しかし䞀番倧切なものを思い出すこずができた それはプログラミングコンテストを愛する気持ちである 問題を開く瞬間のワクワク感サンプルが通った瞬間の盛り䞊がり ステヌタスが曎新される瞬間の緊匵勝利の瞬間の喜び</p> <dl class="docutils"> <dt>(iwi)</dt> <dd>「必ず kita_masa の埩讐を果たしこの狂った䞖界を終わらせる」</dd> </dl> <p>そしお僕は自信の 1 題を繰り出す これは東京倧孊時代の自分が愛した問題「<span style="font-size:110%;font-family:times new roman;"><i>K</i></span> 番目の数字」を独自のテクニックにより䞀般化か぀倧芏暡化した問題である</p> <div> <h1>問題</h1> <p>グラフが䞎えられる</p> <ul class="simple"> <li><span style="font-size:110%;font-family:times new roman;"><i>N</i></span> 個の頂点があり頂点に <span style="font-size:110%;font-family:times new roman;">1</span> から <span style="font-size:110%;font-family:times new roman;"><i>N</i></span> の番号が付いおいる</li> <li>これらの頂点は<span style="font-size:110%;font-family:times new roman;"><i>N</i>&nbsp;-&nbsp;1</span> 本の蟺によりツリヌ状に接続されおいる</li> <li>各頂点 <span style="font-size:110%;font-family:times new roman;"><i>v</i></span> には数字 <span style="font-size:110%;font-family:times new roman;"><i>a</i><sub><i>v</i></sub></span> が定たっおいる</li> </ul> <p>䞋図は䞎えられるグラフの䟋である 各頂点には䞊郚に頂点の番号が䞋郚にその頂点に定められた数字 (<span style="font-size:110%;font-family:times new roman;"><i>a</i><sub><i>v</i></sub></span>) が曞かれおいる</p> <div> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_2270" alt="䞎えられるグラフの䟋" /> <p class="caption">䞎えられるグラフの䟋</p> </div> <p>次に<span style="font-size:110%;font-family:times new roman;"><i>Q</i></span> 個の以䞋のようなク゚リが䞎えられる</p> <ul class="simple"> <li>各ク゚リ <span style="font-size:110%;font-family:times new roman;"><i>q</i></span> には頂点 <span style="font-size:110%;font-family:times new roman;"><i>v</i><sub><i>q</i></sub>,&nbsp;<i>w</i><sub><i>q</i></sub></span> ず敎数 <span style="font-size:110%;font-family:times new roman;"><i>l</i><sub><i>q</i></sub></span> が指定される</li> <li>頂点 <span style="font-size:110%;font-family:times new roman;"><i>v</i><sub><i>q</i></sub></span> から頂点 <span style="font-size:110%;font-family:times new roman;"><i>w</i><sub><i>q</i></sub></span> ぞの経路に含たれる頂点の数字のうち <span style="font-size:110%;font-family:times new roman;"><i>l</i><sub><i>q</i></sub></span> 番目に小さいものを求めよ<ul> <li>経路は単玔なもののみを考える単玔な経路ずは同じ頂点を二床通らない経路のこずであるグラフがツリヌ状であるこずから単玔な経路は䞀意である</li> <li>経路には䞡端点すなわち頂点 <span style="font-size:110%;font-family:times new roman;"><i>v</i><sub><i>q</i></sub>,&nbsp;<i>w</i><sub><i>q</i></sub></span>を含むものずする</li> </ul> </li> </ul> <p>䟋えば䞊図のグラフが䞎えられおいる時 <span style="font-size:110%;font-family:times new roman;">(<i>v</i><sub><i>q</i></sub>,&nbsp;<i>w</i><sub><i>q</i></sub>,&nbsp;<i>l</i><sub><i>q</i></sub>)&nbsp;=&nbsp;(1,&nbsp;6,&nbsp;3)</span> なるク゚リ <span style="font-size:110%;font-family:times new roman;"><i>q</i></span> に察する答えは 7 である これは頂点 1 から頂点 6 ぞの経路には頂点 1, 3, 4, 6 が含たれおおり それらに定たった数字 2, 5, 8, 7 の 3 番目めに小さな数字は 7 であるこずによる</p> <p>グラフずク゚リを受け取り結果を出力するプログラムを䜜成せよ</p> </div> <div> <h1>入力</h1> <p>入力の最初の行は 2 ぀の敎数 <span style="font-size:110%;font-family:times new roman;"><i>N</i>,&nbsp;<i>Q</i></span> を含む これは頂点数ずク゚リの数を衚す</p> <p>続く <span style="font-size:110%;font-family:times new roman;"><i>N</i></span> 行は各頂点の持぀数字を衚す これらの行のうちの <span style="font-size:110%;font-family:times new roman;"><i>v</i></span> 行目は 1 ぀の敎数 <span style="font-size:110%;font-family:times new roman;"><i>x</i><sub><i>v</i></sub></span> が曞かれおおり これは頂点 <span style="font-size:110%;font-family:times new roman;"><i>v</i></span> の持぀数字を衚す</p> <p>続く <span style="font-size:110%;font-family:times new roman;"><i>N</i>&nbsp;-&nbsp;1</span> 行は蟺の情報を衚す これらの行のうちの <span style="font-size:110%;font-family:times new roman;"><i>e</i></span> 行目は 2 ぀の敎数 <span style="font-size:110%;font-family:times new roman;"><i>a</i><sub><i>e</i></sub>,&nbsp;<i>b</i><sub><i>e</i></sub></span> が曞かれおおり これらは蟺 <span style="font-size:110%;font-family:times new roman;"><i>e</i></span> が結ぶ 2 ぀の頂点を衚す</p> <p>続く <span style="font-size:110%;font-family:times new roman;"><i>Q</i></span> 行はク゚リの情報を衚す これらの行のうちの <span style="font-size:110%;font-family:times new roman;"><i>q</i></span> 行目は 3 ぀の敎数 <span style="font-size:110%;font-family:times new roman;"><i>v</i><sub><i>q</i></sub>,&nbsp;<i>w</i><sub><i>q</i></sub>,&nbsp;<i>l</i><sub><i>q</i></sub></span> が曞かれおおり これらはク゚リ <span style="font-size:110%;font-family:times new roman;"><i>q</i></span> の情報を衚す</p> </div> <div> <h1>出力</h1> <p>出力は <span style="font-size:110%;font-family:times new roman;"><i>Q</i></span> 行からなる<span style="font-size:110%;font-family:times new roman;"><i>q</i></span> 行目にク゚リ <span style="font-size:110%;font-family:times new roman;"><i>q</i></span> の答えを出力せよ</p> </div> <div> <h1>入力に関する制玄</h1> <ul class="simple"> <li><span style="font-size:110%;font-family:times new roman;">1&nbsp;&le;&nbsp;<i>N</i>,&nbsp;<i>Q</i>&nbsp;&le;&nbsp;10<sup>5</sup></span></li> <li><span style="font-size:110%;font-family:times new roman;">1&nbsp;&le;&nbsp;<i>x</i><sub><i>v</i></sub>&nbsp;&le;&nbsp;10<sup>9</sup></span></li> <li><span style="font-size:110%;font-family:times new roman;">1&nbsp;&le;&nbsp;<i>a</i><sub><i>e</i></sub>,&nbsp;<i>b</i><sub><i>e</i></sub>&nbsp;&le;&nbsp;<i>N</i></span></li> <li><span style="font-size:110%;font-family:times new roman;">1&nbsp;&le;&nbsp;<i>v</i><sub><i>q</i></sub>,&nbsp;<i>w</i><sub><i>q</i></sub>&nbsp;&le;&nbsp;<i>N</i></span></li> <li>頂点 <span style="font-size:110%;font-family:times new roman;"><i>v</i><sub><i>q</i></sub></span> から頂点 <span style="font-size:110%;font-family:times new roman;"><i>w</i><sub><i>q</i></sub></span> ぞの経路には <span style="font-size:110%;font-family:times new roman;"><i>l</i><sub><i>q</i></sub></span> 個以䞊の頂点が存圚する</li> </ul> </div> <div> <h1>入出力䟋</h1> <p>入力䟋:</p> <pre class="literal-block"> 6 11 2 4 5 8 9 7 1 3 2 3 3 4 4 5 4 6 1 6 1 1 6 2 1 6 3 1 6 4 1 2 1 1 2 2 1 2 3 2 5 1 2 5 2 2 5 3 2 5 4 </pre> <p>入力䟋に察する出力:</p> <pre class="literal-block"> 2 5 7 8 2 4 5 4 5 8 9 </pre> </div> </div>
p02952
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given is an integer <var>N</var>. Find the number of positive integers less than or equal to <var>N</var> that have an odd number of digits (in base ten without leading zeros).</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 10^5</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of positive integers less than or equal to <var>N</var> that have an odd number of digits.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>11 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>9 </pre> <p>Among the positive integers less than or equal to <var>11</var>, nine integers have an odd number of digits: <var>1, 2, \ldots, 9</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>136 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>46 </pre> <p>In addition to <var>1, 2, \ldots, 9</var>, another <var>37</var> integers also have an odd number of digits: <var>100, 101, \ldots, 136</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>100000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>90909 </pre></section> </div> </span>
p03640
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a grid with <var>H</var> rows and <var>W</var> columns of squares. Snuke is painting these squares in colors <var>1</var>, <var>2</var>, <var>...</var>, <var>N</var>. Here, the following conditions should be satisfied:</p> <ul> <li>For each <var>i</var> (<var>1 ≀ i ≀ N</var>), there are exactly <var>a_i</var> squares painted in Color <var>i</var>. Here, <var>a_1 + a_2 + ... + a_N = H W</var>.</li> <li>For each <var>i</var> (<var>1 ≀ i ≀ N</var>), the squares painted in Color <var>i</var> are <em>4-connected</em>. That is, every square painted in Color <var>i</var> can be reached from every square painted in Color <var>i</var> by repeatedly traveling to a horizontally or vertically adjacent square painted in Color <var>i</var>.</li> </ul> <p>Find a way to paint the squares so that the conditions are satisfied. It can be shown that a solution always exists.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ H, W ≀ 100</var></li> <li><var>1 ≀ N ≀ H W</var></li> <li><var>a_i ≥ 1</var></li> <li><var>a_1 + a_2 + ... + a_N = H W</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>H</var> <var>W</var> <var>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 one way to paint the squares that satisfies the conditions. Output in the following format:</p> <pre><var>c_{1 1}</var> <var>...</var> <var>c_{1 W}</var> <var>:</var> <var>c_{H 1}</var> <var>...</var> <var>c_{H W}</var> </pre> <p>Here, <var>c_{i j}</var> is the color of the square at the <var>i</var>-th row from the top and <var>j</var>-th column from the left.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 2 3 2 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 1 2 3 </pre> <p>Below is an example of an invalid solution:</p> <pre>1 2 3 1 </pre> <p>This is because the squares painted in Color <var>1</var> are not 4-connected.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 5 5 1 2 3 4 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 4 4 4 3 2 5 4 5 3 2 5 5 5 3 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 1 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 </pre></section> </div> </span>
p03210
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p><em>Shichi-Go-San</em> (literally "Seven-Five-Three") is a traditional event in a certain country to celebrate the growth of seven-, five- and three-year-old children.</p> <p>Takahashi is now <var>X</var> years old. Will his growth be celebrated in Shichi-Go-San this time?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ X ≀ 9</var></li> <li><var>X</var> is an integer.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>X</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If Takahashi's growth will be celebrated, print <code>YES</code>; if it will not, print <code>NO</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>YES </pre> <p>The growth of a five-year-old child will be celebrated.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>NO </pre> <p>See you next year.</p></section> </div> </span>
p02817
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given are two strings <var>S</var> and <var>T</var> consisting of lowercase English letters. Concatenate <var>T</var> and <var>S</var> in this order, without space in between, and print the resulting string.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>S</var> and <var>T</var> are strings consisting of lowercase English letters.</li> <li>The lengths of <var>S</var> and <var>T</var> are between <var>1</var> and <var>100</var> (inclusive).</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>S</var> <var>T</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the resulting string.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>oder atc </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>atcoder </pre> <p>When <var>S = </var> <code>oder</code> and <var>T = </var> <code>atc</code>, concatenating <var>T</var> and <var>S</var> in this order results in <code>atcoder</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>humu humu </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>humuhumu </pre></section> </div> </span>
p01738
<p> You are practicing a juggle that involves in a number of square tiles. They all look the same in their size, but actually there are three different kinds of the tiles, A, B and X. The kind of a tile can be distinguishable by its mass. All the tiles of the same kind have exactly the same mass. The mass of type A tiles is within the range <var>[mA1, mA2]</var>. The mass of type B tiles is similarly within the range <var>[mB1, mB2]</var>. You don’t know the exact numbers for type A and B. The mass of type X tiles is exactly <var>mX</var>. </p> <p> You have just got one big object consists of the tiles. The tiles are arranged in an <var>H \times W</var> grid. All the adjacent tiles are glued together on the edges. Some cells in the <var>H \times W</var> grid can be empty. </p> <p> You wanted to balance the object on a pole. You started to wonder the center of gravity of the object, then. You cannot put the object on a pole if the center of gravity is on an empty cell. The center of gravity of each single square tile is at the center of the square. The center of gravity of an object which combines two objects with masses <var>m_{1}</var> and <var>m_{2}</var> is the point dividing the line segment between those centers in the ratio <var>m_{2} : m_{1}</var> internally. </p> <p> Your task is to write a program that computes the probability that the center of gravity of the big object is actually on the object, not on a hole in the object. Although the exact mass is unknown for tile A and B, the probability follows the continuous uniform distribution within the range mentioned above. You can assume the distribution is independent between A and B. </p> <h3>Input</h3> <p>The input is formatted as follows. </p> <pre> <var>H</var> <var>W</var> <var>mA1</var> <var>mA2</var> <var>mB1</var> <var>mB2</var> <var>mX</var> <var>M_{1,1}M_{1,2}...M_{1,W}</var> <var>M_{2,1}M_{2,2}...M_{2,W}</var> : : <var>M_{H,1}M_{H,2}...M_{H,W}</var></pre> <p>The first line of the input contains two integers <var>H</var> and <var>W</var> (<var>1 \leq H, W \leq 50</var>) separated by a space, where <var>H</var> and <var>W</var> are the numbers of rows and columns of given matrix. </p> <p>The second line of the input contains five integers <var>mA1</var>, <var>mA2</var>, <var>mB1</var>, <var>mB2</var> and <var>mX</var> (<var>1 \leq mA1 \lt mA2 \leq 100</var>, <var>1 \leq mB1 \lt mB2 \leq 100</var> and <var>1 \leq mX \leq 100</var>) separated by a space. </p> <p>The following <var>H</var> lines, each consisting of <var>W</var> characters, denote given matrix. In those <var>H</var> lines, <code>A</code>, <code>B</code> and <code>X</code> denote a piece of type A, type B and type X respectively, and <code>.</code> denotes empty cell to place no piece. There are no other characters in those H lines. </p> <p>Of the cell at <var>i</var>-th row in <var>j</var>-th column, the coordinate of the left top corner is <var>(i, j)</var>, and the coordinate of the right bottom corner is <var>(i+1, j+1)</var>. </p> <p>You may assume that given matrix has at least one <code>A</code>, <code>B</code> and <code>X</code> each and all pieces are connected on at least one edge. Also, you may assume that the probability that the x-coordinate of the center of gravity of the object is an integer is equal to zero and the probability that the y-coordinate of the center of gravity of the object is an integer is equal to zero. </p> <h3>Output</h3> <p>Print the probability that the center of gravity of the object is on the object. The output should not contain an error greater than <var>10^{-8}</var>. </p> <h3>Sample Input 1</h3> <pre>3 3 2 4 1 2 1 XAX B.B XAX </pre> <h3>Output for the Sample Input 1</h3> <pre>0.0000000000000 </pre> <h3>Sample Input 2</h3> <pre>4 2 1 100 1 100 50 AX XB BA XB </pre> <h3>Output for the Sample Input 2</h3> <pre>1.0 </pre> <h3>Sample Input 3</h3> <pre>2 3 1 2 3 4 2 X.B AXX </pre> <h3>Output for the Sample Input 3</h3> <pre>0.500 </pre> <h3>Sample Input 4</h3> <pre>10 10 1 100 1 100 1 AXXXXXXXXX X........X X........X X..XXXXXXX X........X XXXXXX...X X........X X......X.X X......X.X XXXXXXXXXB </pre> <h3>Output for the Sample Input 4</h3> <pre>0.4930639462354 </pre> <h3>Sample Input 5</h3> <pre>25 38 42 99 40 89 3 ...........X...............X.......... ...........XXX..........XXXX.......... ...........XXXXX.......XXXX........... ............XXXXXXXXXXXXXXX........... ............XXXXXXXXXXXXXXX........... ............XXXXXXXXXXXXXX............ .............XXXXXXXXXXXXX............ ............XXXXXXXXXXXXXXX........... ...........XXXXXXXXXXXXXXXXX.......... .......X...XXXXXXXXXXXXXXXXX...X...... .......XX.XXXXXXXXXXXXXXXXXX..XX...... ........XXXXXXXXXXXXXXXXXXXX.XX....... ..........XXXXXXXXXXXXXXXXXXXX........ .........XXXXX..XXXXXXXX..XXXXX....... .......XXXXXX....XXXXX....XXXXXX...... ......XXXXXXXX...XXXXX..XXXXXXXX.X.... ....XXXXXXX..X...XXXXX..X..XXXXXXXX... ..BBBXXXXXX.....XXXXXXX......XXXAAAA.. ...BBBXXXX......XXXXXXX........AAA.... ..BBBB.........XXXXXXXXX........AAA... ...............XXXXXXXXX.............. ..............XXXXXXXXXX.............. ..............XXXXXXXXXX.............. ...............XXXXXXXX............... ...............XXXXXXXX............... </pre> <h3>Output for the Sample Input 5</h3> <pre>0.9418222212582 </pre>
p03705
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke has <var>N</var> integers. Among them, the smallest is <var>A</var>, and the largest is <var>B</var>. We are interested in the sum of those <var>N</var> integers. How many different possible sums there are?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≀ N,A,B ≀ 10^9</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>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>Print the number of the different possible sums.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 4 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>5 </pre> <p>There are five possible sums: <var>18=4+4+4+6</var>, <var>19=4+4+5+6</var>, <var>20=4+5+5+6</var>, <var>21=4+5+6+6</var> and <var>22=4+6+6+6</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 4 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 7 10 </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>1 3 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>1 </pre></section> </div> </span>
p01368
<H1><font color="#000">Problem J:</font> Merry Christmas</H1> <p> International Christmas Present Company (ICPC) is a company to employ Santa and deliver presents on Christmas. Many parents request ICPC to deliver presents to their children at specified time of December 24. Although same Santa can deliver two or more presents, because it takes time to move between houses, two or more Santa might be needed to finish all the requests on time. </p> <p> Employing Santa needs much money, so the president of ICPC employed you, a great program- mer, to optimize delivery schedule. Your task is to write a program to calculate the minimum number of Santa necessary to finish the given requests on time. Because each Santa has been well trained and can conceal himself in the town, you can put the initial position of each Santa anywhere. </p> <H2>Input</H2> <p> The input consists of several datasets. Each dataset is formatted as follows. </p> <p> <i>N M L</i><br> <i>u</i><sub>1</sub> <i>v</i><sub>1</sub> <i>d</i><sub>1</sub><br> <i>u</i><sub>2</sub> <i>v</i><sub>2</sub> <i>d</i><sub>2</sub><br> .<br> .<br> .<br> <i>u</i><sub><i>M</i></sub> <i>v</i><sub><i>M</i></sub> <i>d</i><sub><i>M</i></sub><br> <i>p</i><sub>1</sub> <i>t</i><sub>1</sub><br> <i>p</i><sub>2</sub> <i>t</i><sub>2</sub><br> .<br> .<br> .<br> <i>p</i><sub><i>L</i></sub> <i>t</i><sub><i>L</i></sub><br> </p> <p> The first line of a dataset contains three integer, <i>N</i> , <i>M</i> and <i>L</i> (1 &le; <i>N</i> &le; 100, 0 &le; <i>M</i> &le; 1000, 1 &le; <i>L</i> &le; 1000) each indicates the number of houses, roads and requests respectively. </p> <p> The following <i>M</i> lines describe the road network. The <i>i</i>-th line contains three integers, <i>u<sub>i</sub></i> , <i>v<sub>i</sub></i> , and <i>d<sub>i</sub></i> (0 &le; <i>u<sub>i</sub></i> &lt; <i>v<sub>i</sub></i> &le; <i>N</i> - 1, 1 &le; <i>d<sub>i</sub></i> &le; 100) which means that there is a road connecting houses <i>u<sub>i</sub></i> and <i>v<sub>i</sub></i> with <i>d<sub>i</sub></i> length. Each road is bidirectional. There is at most one road between same pair of houses. Whole network might be disconnected. </p> <p> The next <i>L</i> lines describe the requests. The <i>i</i>-th line contains two integers, <i>p<sub>i</sub></i> and <i>t<sub>i</sub></i> (0 &le; <i>p<sub>i</sub></i> &le; <i>N</i> - 1, 0 &le; <i>t<sub>i</sub></i> &le; 10<sup>8</sup> ) which means that there is a delivery request to house <i>p<sub>i</sub></i> on time <i>t<sub>i</sub></i> . There is at most one request for same place and time. You can assume that time taken other than movement can be neglectable, and every Santa has the same speed, one unit distance per unit time. </p> <p> The end of the input is indicated by a line containing three zeros separated by a space, and you should not process this as a test case. </p> <H2>Output</H2> <p> Print the minimum number of Santa necessary to finish all the requests on time. </p> <H2>Sample Input</H2> <pre> 3 2 3 0 1 10 1 2 10 0 0 1 10 2 0 3 2 4 0 1 10 1 2 10 0 0 1 10 2 20 0 40 10 10 10 0 1 39 2 3 48 3 5 20 4 8 43 3 9 10 8 9 40 3 4 5 5 7 20 1 7 93 1 3 20 0 0 1 100000000 2 100 3 543 4 500 5 400 6 300 7 200 8 100 9 100 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 2 1 4 </pre>
p03355
<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>. Among the <strong>different</strong> substrings of <var>s</var>, print the <var>K</var>-th lexicographically smallest one.</p> <p>A substring of <var>s</var> is a string obtained by taking out a non-empty contiguous part in <var>s</var>. For example, if <var>s</var> <var>=</var> <code>ababc</code>, <code>a</code>, <code>bab</code> and <code>ababc</code> are substrings of <var>s</var>, while <code>ac</code>, <code>z</code> and an empty string are not. Also, we say that substrings are different when they are different as strings.</p> <p>Let <var>X = x_{1}x_{2}...x_{n}</var> and <var>Y = y_{1}y_{2}...y_{m}</var> be two distinct strings. <var>X</var> is lexicographically larger than <var>Y</var> if and only if <var>Y</var> is a prefix of <var>X</var> or <var>x_{j} &gt; y_{j}</var> where <var>j</var> is the smallest integer such that <var>x_{j} \neq y_{j}</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1</var> <var>≀</var> <var>|s|</var> <var>≀</var> <var>5000</var></li> <li><var>s</var> consists of lowercase English letters.</li> <li><var>1</var> <var>≀</var> <var>K</var> <var>≀</var> <var>5</var></li> <li><var>s</var> has at least <var>K</var> different substrings.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Score</h3><ul> <li><var>200</var> points will be awarded as a partial score for passing the test set satisfying <var>|s|</var> <var>≀</var> <var>50</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>K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the <var>K</var>-th lexicographically smallest substring of <var>K</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>aba 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>b </pre> <p><var>s</var> has five substrings: <code>a</code>, <code>b</code>, <code>ab</code>, <code>ba</code> and <code>aba</code>. Among them, we should print the fourth smallest one, <code>b</code>. Note that we do not count <code>a</code> twice.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>atcoderandatcodeer 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>andat </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>z 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>z </pre></section> </div> </span>
p00980
<h2>Estimating the Flood Risk</h2> <p> Mr. Boat is the owner of a vast extent of land. As many typhoons have struck Japan this year, he became concerned of flood risk of his estate and he wants to know the average altitude of his land. The land is too vast to measure the altitude at many spots. As no steep slopes are in the estate, he thought that it would be enough to measure the altitudes at only a limited number of sites and then approximate the altitudes of the rest based on them. </p> <p> Multiple approximations might be possible based on the same measurement results, in which case he wants to know the worst case, that is, one giving the lowest average altitude. </p> <p> Mr. Boat’s estate, which has a rectangular shape, is divided into grid-aligned rectangular areas of the same size. Altitude measurements have been carried out in some of these areas, and the measurement results are now at hand. The altitudes of the remaining areas are to be approximated on the assumption that altitudes of two adjoining areas sharing an edge differ at most 1. </p> <p> In the first sample given below, the land is divided into 5 &times; 4 areas. The altitudes of the areas at (1, 1) and (5, 4) are measured 10 and 3, respectively. In this case, the altitudes of all the areas are uniquely determined on the assumption that altitudes of adjoining areas differ at most 1. </p> <p> In the second sample, there are multiple possibilities, among which one that gives the lowest average altitude should be considered. </p> <p> In the third sample, no altitude assignments satisfy the assumption on altitude differences. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCAsia2019_estimating_the_flood_risk" width="640"/> </center> <p> Your job is to write a program that approximates the average altitude of his estate. To be precise, the program should compute the total of approximated and measured altitudes of all the mesh-divided areas. If two or more different approximations are possible, the program should compute the total with the severest approximation, that is, one giving the lowest total of the altitudes. </p> <h3>Input</h3> <p> The input consists of a single test case of the following format. </p> <pre> $w$ $d$ $n$ $x_1$ $y_1$ $z_1$ . . . $x_n$ $y_n$ $z_n$ </pre> <p> Here, $w$, $d$, and $n$ are integers between $1$ and $50$, inclusive. $w$ and $d$ are the numbers of areas in the two sides of the land. $n$ is the number of areas where altitudes are measured. The $i$-th line of the following $n$ lines contains three integers, $x_i$, $y_i$, and $z_i$ satisfying $1 \leq x_i \leq w$, $1 \leq y_i \leq d$, and $−100 \leq z_i \leq 100$. They mean that the altitude of the area at $(x_i , y_i)$ was measured to be $z_i$. At most one measurement result is given for the same area, i.e., for $i \ne j$, $(x_i, y_i) \ne (x_j , y_j)$. </p> <h3>Output</h3> <p> If all the unmeasured areas can be assigned their altitudes without any conflicts with the measured altitudes assuming that two adjoining areas have the altitude difference of at most 1, output an integer that is the <i>total</i> of the measured or approximated altitudes of all the areas. If more than one such altitude assignment is possible, output the minimum altitude total among the possible assignments. </p> <p> If no altitude assignments satisfy the altitude difference assumption, output <span>No</span>. </p> <h3>Sample Input 1 </h3> <pre> 5 4 2 1 1 10 5 4 3 </pre> <h3>Sample Output 1</h3> <pre> 130 </pre> <h3>Sample Input 2 </h3> <pre> 5 4 3 2 2 0 4 3 0 5 1 2 </pre> <h3>Sample Output 2</h3> <pre> -14 </pre> <h3>Sample Input 3 </h3> <pre> 3 3 2 1 1 8 3 3 3 </pre> <h3>Sample Output 3</h3> <pre> No </pre> <h3>Sample Input 4 </h3> <pre> 2 2 1 1 1 -100 </pre> <h3>Sample Output 4</h3> <pre> -404 </pre>
p01692
<h2>F - Dangerous Delivery / 危険な茞送</h2> <h3>Story</h3> <p>Dのひずは重倧な䜿呜を背負っおいた。それはDAtaCoDer瀟長のDhokudai氏ぞ、次のDAtaCoDer Regular Contest(DARC)のD問題を届けるこずだ。Dのひずのアゞトがある郜垂<var>1</var>からDAtaCoDer本瀟がある郜垂<var>N</var>たでは<var>N</var>個の郜垂が䞀盎線に䞊んでいる。この移動の間、䞍正を䌁む緑の䞉角圢の集団がD問題を狙っおおり、その魔の手からD問題を守らねばならない。</p> <p>幞い、Dのひずは次元(ディメンゞョン)の壁を超えお移動する胜力を持っおいるため、簡単に捕たるようなこずはない。しかしこの移動法にはいく぀かの欠点がある。第䞀に、移動を開始する際には隙ができおしたい、たたその瞬間が芋぀かるず、移動先たでバレおしたう。緑の䞉角圢達はそれぞれが耇数の郜垂を芋枡せるように監芖し続けおいる。しかもDのひずの移動を読み、少しず぀郜垂<var>N</var>の方向ぞ移動しおいるようだ。よっお、倚くの緑の䞉角圢達に監芖されおいる郜垂からの移動や、長い距離の移動は発芋のリスクが高たっおしたう。たた第二の欠点ずしお、次元の壁を超える移動は䜓ぞの負担がかかるため、<var>1</var>日に<var>1</var>床しか䜿えない。次のDARCが開催される<var>D</var>日埌たでに間に合わせるよう、ペヌス配分を考える必芁もある。緑の䞉角圢ごずきにDのひずが捕捉されるこずなどたずありえないが、慎重掟であるDのひずは、<var>D</var>日埌たでに郜垂<var>1</var>から郜垂<var>N</var>に移動するためのリスクを最小化しようず考えた。</p> <h3>Problem</h3> <p>二次元平面䞊に<var>N</var>個の郜垂がある。郜垂<var>1</var>から<var>N</var>は巊から右ぞ䞀盎線䞊に䞊んでおり、郜垂<var>i</var>は䜍眮<var>(p_i,0)</var>にある。<var>p_i&lt;p_{i+1}</var> (<var>1 \leq i &lt; N</var>)を満たす。</p> <p>たた、この二次元平面䞊には<var>M</var>人の敵がおり、敵<var>j</var>は圓初、䜍眮<var>(a_j,b_j)</var>にいる。敵<var>j</var>は巊方向に぀いお、䞊䞋<var>45</var>°の範囲を芋匵っおいる。すなわち、盎線 <var>y=x-a_j+b_j</var> 以䞊で、か぀、盎線<var>y=-x+a_j+b_j</var> 以䞋の領域に含たれる党おの郜垂が芖界に入っおいる。たた、すべおの敵は<var>1</var>日ごずにちょうど<var>X</var>だけ右方向に移動する。すなわち、<var>d</var>日目の敵<var>j</var>の䜍眮は<var>(a_j+X(d-1),b_j)</var>である。</p> <p>ここで、<var>d</var>日目における郜垂<var>i</var>の監芖床<var>w_{d,i}</var>は、<var>d</var>日目においお郜垂<var>i</var>を芖界に入れおいる敵の総数により定矩される。このずき、<var>d</var>日目の郜垂<var>i</var>から郜垂<var>k</var>ぞの移動は、<var>w_{d,i} \times |p_i-p_k|</var>のリスクを負う。<var>1</var>日に<var>1</var>床しか移動できないずするずき、<var>D</var>日埌たでに郜垂<var>1</var>から郜垂<var>N</var>たで移動する際のリスクの総和を最小化せよ。</p> <h3>Input</h3> <p>入力は以䞋の圢匏からなる。</p> <pre><var>N</var> <var>M</var> <var>D</var> <var>X</var> <var>p_1</var> <var>p_2</var> <var>...</var> <var>p_N</var> <var>a_1</var> <var>b_1</var> <var>...</var> <var>a_M</var> <var>b_M</var></pre> <p><var>1</var>行目は<var>4</var>぀の敎数からなり、郜垂の数<var>N</var>、敵の数<var>M</var>、移動にかけおよい日数の䞊限<var>D</var>、<var>1</var>日ごずの敵の移動距離<var>X</var>がそれぞれ空癜<var>1</var>文字区切りで䞎えられる。 <var>2</var>行目は<var>N</var>個の敎数からなり、<var>i</var>番目の敎数は郜垂<var>i</var>の䜍眮の<var>x</var>座暙<var>p_i</var>が空癜<var>1</var>文字区切りで䞎えられる。 続く<var>M</var>行は敵の䜍眮情報が䞎えられる。 <var>j+2</var>行目(<var>1 \leq j \leq M</var>)は<var>2</var>぀の敎数からなり、敵<var>j</var>の<var>1</var>日目の䜍眮の<var>x</var>座暙<var>a_j</var>、<var>y</var>座暙<var>b_j</var>が空癜<var>1</var>文字区切りで䞎えられる。</p> <p>制玄:</p> <ul> <li><var>1 \leq N \leq 10^4</var></li> <li><var>1 \leq M \leq 10^4</var></li> <li><var>1 \leq D \leq 10^2</var></li> <li><var> 1 \leq X \leq 10^6</var></li> <li><var>0 \leq p_i, a_j \leq 10^6, -10^6 \leq b_j \leq 10^6</var></li> <li><var>p_i&lt;p_{i+1}</var></li> </ul> <h3>Output</h3> <p><var>D</var>日目たでに郜垂<var>N</var>にいるためのリスクの総和の最小倀を<var>1</var>行に出力せよ。行の最埌では必ず改行を行うこず。</p> <h3>Sample Input 1</h3> <pre>3 2 2 1 0 3 6 1 1 3 -2</pre> <h3>Sample Output 1</h3> <pre>6</pre> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_HUPC2014_DangerousDelivery_sample1-1" alt="DangerousDelivery_sample1-1.png" /> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_HUPC2014_DangerousDelivery_sample1-2" alt="DangerousDelivery_sample1-2.png" /> <p>1日目、郜垂1は2人、郜垂2は0人、郜垂3は0人に監芖されおいる。 2日目も同様に、郜垂1は2人、郜垂2は0人、郜垂3は0人に監芖されおいる。 よっお、1日目に郜垂1から郜垂2に移動しおリスクが<var>2 \times |3-0|=6</var>、2日目に郜垂2から郜垂3ぞ移動しおリスクが<var>0 \times |6-3|=0</var>の合蚈6が最小である。</p> <h3>Sample Input 2</h3> <pre>3 2 2 1 0 3 6 2 1 3 -1</pre> <h3>Sample Output 2</h3> <pre>9</pre> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_HUPC2014_DangerousDelivery_sample2-1" alt="DangerousDelivery_sample2-1.png" /> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_HUPC2014_DangerousDelivery_sample2-2" alt="DangerousDelivery_sample2-2.png" /> <p>移動の仕方は1぀目のサンプルず同じだが、2日目は敵の移動により郜垂2の監芖人数が1人増えるため、コストが<var>1 \times |6-3|=3</var>に倉化する。 よっお、最小リスクは9である。</p> <h3>Sample Input 3</h3> <pre>10 8 5 3 0 8 10 13 17 20 21 29 30 45 18 2 50 -20 17 1 38 21 40 -11 0 0 0 0 22 -1</pre> <h3>Sample Output 3</h3> <pre>222</pre>
p02114
<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 D: Fissure Puzzle Easy</h1> <h2>Problem</h2> <p>$N \times N$個のマスから成るグリッドがある。最初すべおのマスは癜色である。以䞋の手順に埓っお黒色のマスを増やしおいく。</p> <p>䞊から偶数番目か぀、巊から偶数番目であるマスの䞭で、癜色のマスを1぀遞ぶ。遞んだマスは黒色に倉化する。さらに、そのマスの䞊䞋巊右それぞれの方向に぀いお、隣接しおいる癜色のマスも連鎖的に黒色に倉化する。この連鎖はその方向に癜色のマスが存圚しなくなるたで続く。(以䞋に䟋を瀺す)</p> <p> □□□□□□□□□<br> □□□□□□□□□<br> □□□□□□□□□<br> □□□□□□□□□<br> □□□□□□□□□<br> □□□□□□□□□<br> □□□□□□□□□<br> □□□□□□□□□<br> □□□□□□□□□<br> ↓䞊から4番目、巊から6番目を遞ぶ<br> □□□□□■□□□<br> □□□□□■□□□<br> □□□□□■□□□<br> ■■■■■■■■■<br> □□□□□■□□□<br> □□□□□■□□□<br> □□□□□■□□□<br> □□□□□■□□□<br> □□□□□■□□□<br> ↓䞊から2番目、巊から2番目を遞ぶ<br> □■□□□■□□□<br> ■■■■■■□□□<br> □■□□□■□□□<br> ■■■■■■■■■<br> □□□□□■□□□<br> □□□□□■□□□<br> □□□□□■□□□<br> □□□□□■□□□<br> □□□□□■□□□<br> ↓䞊から6番目、巊から8番目を遞ぶ<br> □■□□□■□□□<br> ■■■■■■□□□<br> □■□□□■□□□<br> ■■■■■■■■■<br> □□□□□■□■□<br> □□□□□■■■■<br> □□□□□■□■□<br> □□□□□■□■□<br> □□□□□■□■□<br> </p> <p> あなたは䞊から$i$番目で巊から$j$番目のマスの色が$A_{i,j}$であるグリッドを䜜りたい。マスを遞ぶ最小の回数を求めよ。 </p> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる。</p> <p> $N$<br> $A_{1,1}$ $A_{1,2}$ ... $A_{1,N}$<br> $A_{2,1}$ $A_{2,2}$ ... $A_{2,N}$<br> ...<br> $A_{N,1}$ $A_{N,2}$ ... $A_{N,N}$<br> </p> <p> $A_{i,j}$が'o'であるずきは䞊から$i$番目、巊から$j$番目のマスが癜色であるこずを衚し、'x'のずきは黒色のマスであるこずを衚す。 </p> <h2>Constraints</h2> <p>入力は以䞋の条件を満たす。</p> <ul> <li>$3 \le N \le 127$</li> <li>$N$は奇数である</li> <li>$A_{i,j}$は'o'か'x'である</li> <li>必ず䜜るこずができるような入力しか䞎えられない</li> </ul> <h2>Output</h2> <p> 1行目にマスを遞ぶ回数の最小倀を出力する。 </p> <h2>Sample Input 1</h2> <pre> 5 oxooo oxooo oxooo xxxxx oxooo </pre> <h2>Sample Output 1</h2> <pre> 1 </pre> <h2>Sample Input 2</h2> <pre> 9 oxoooooxo oxxxxxxxx oxoooooxo xxxxxxxxx oxoxooooo oxxxxxxxx oxoxoxooo oxoxxxxxx oxoxoxooo </pre> <h2>Sample Output 2</h2> <pre> 4 </pre>
p00129
<h1>かくれんがう</H1> <p> たろう君はかくれんがうが苊手です。隠れるずすぐ芋぀かっちゃうし、隠れおいる子をなかなか芋぀けるこずができたせん。芋かねたお父さんは、超高性胜䜍眮探玢システムを䜜っおくれたした。これを䜿うず自分の䜍眮を含めお、友達の䜍眮を正確に知るこずができたす。鬌になったら、隠れおいる子を探すこずが簡単にできるようになりたした。 </p> <!-- 芋぀けたい子の䜍眮に行けば、それで OK のはずです。これを䜿っおいるこずがばれるず遊んでもらえなくなるので内緒で䜿いたす。 --> <p> たろう君はさらにこのシステムを進化させ、鬌から自分が芋えるか吊かを刀定する機胜を付加するこずを思い぀きたした。これができれば、「もういいかい」ず蚀われおも、芋える䜍眮にいれば「たあだだよ」だし、芋えない䜍眮にいれば「もういいよ」ですね。い぀も遊んでいる公園には倧小さたざたな円筒圢の壁がありたす。この壁は倖からは䞭は芋えないし、䞭から倖も芋えたせん。鬌ず䞀緒に䞭に入るず別の壁がなければ芋えちゃいたす。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_hideandseek"> </center> <br/> <p> たろう君はアむデアはいいのですが、゜フトを䜜るのが苊手です。そこで芪友のあなたはたろう君に代わっお、「鬌から芋えないこず確認システム」の゜フトりェアを䜜るこずになりたした。公園の壁は固定されおいたすが、たろう君ず鬌のいろいろな䜍眮情報に察しお芋えるか吊かを刀定する必芁がありたす。 </p> <p> 公園にある壁の情報(䞭心の座暙 (<var>wx</var>, <var>wy</var>) ず 半埄 <var>r</var>) ずたろう君ず鬌の䜍眮情報(たろう君の䜍眮の座暙 (<var>tx</var>, <var>ty</var>) ず鬌の䜍眮の座暙 (<var>sx</var>, <var>sy</var>) ) を入力ずし、その䜍眮で鬌からたろう君が芋えるか吊かを刀定するプログラムを䜜成しおください。 </p> <p> なお、鬌からたろう君が芋える堎合には Danger、芋えない堎合には Safe ず出力しおください。鬌ずたろう君の䜍眮を結んだ線分䞊に壁がある堎合には芋えないものずし、鬌もたろう君も壁の䞊にはいないものずしたす。 </p> <H2>Input</H2> <p> 耇数のデヌタセットが䞎えられたす。各デヌタセットは以䞋の圢匏で䞎えられたす。 </p> <pre> <var>n</var> <var>wx<sub>1</sub></var> <var>wy<sub>1</sub></var> <var>r<sub>1</sub></var> <var>wx<sub>2</sub></var> <var>wy<sub>2</sub></var> <var>r<sub>2</sub></var> : <var>wx<sub>n</sub></var> <var>wy<sub>n</sub></var> <var>r<sub>n</sub></var> <var>m</var> <var>tx<sub>1</sub></var> <var>ty<sub>1</sub></var> <var>sx<sub>1</sub></var> <var>sy<sub>1</sub></var> <var>tx<sub>2</sub></var> <var>ty<sub>2</sub></var> <var>sx<sub>2</sub></var> <var>sy<sub>2</sub></var> : <var>tx<sub>m</sub></var> <var>ty<sub>m</sub></var> <var>sx<sub>m</sub></var> <var>sy<sub>m</sub></var> </pre> <p> 1 行目に円筒圢の壁の数 <var>n</var> (0 &le; <var>n</var> &le; 100)、続く <var>n</var> 行に壁 <var>i</var> の䞭心の座暙を衚す敎数 <var>wx<sub>i</sub></var>, <var>wy<sub>i</sub></var> (0 &le; <var>wx<sub>i</sub></var>, <var>wy<sub>i</sub></var> &le; 255) ず半埄を衚す敎数 <var>r<sub>i</sub></var> (1 &le; <var>r<sub>i</sub></var> &le; 255) が䞎えられたす。 </p> <p> 続く行にたろう君ず鬌の䜍眮情報の個数 <var>m</var> (m &le; 100)、続く <var>m</var> 行に䜍眮情報 <var>i</var> のたろう君の䜍眮の座暙を衚す敎数 <var>tx<sub>i</sub></var>, <var>ty<sub>i</sub></var> (0 &le; <var>tx<sub>i</sub></var>, <var>ty<sub>i</sub></var> &le; 255) ず鬌の䜍眮の座暙を衚す敎数 <var>sx<sub>i</sub></var>, <var>sy<sub>i</sub></var> (0 &le; <var>sx<sub>i</sub></var>, <var>sy<sub>i</sub></var> &le; 255) が䞎えられたす。 </p> <p> たた、円筒圢の壁の䞀郚だけが公園にあるずいうこずはなく、党おの壁は円筒ずしお、公園の内郚に入っおいたす。 </p> <p> <var>n</var> が 0 のずき入力の終わりを瀺したす。デヌタセットの数は 20 を超えたせん。 </p> <H2>Output</H2> <p> 各デヌタセットに぀いお、䜍眮情報 <var>i</var> の刀定結果 Danger たたは Safe を <var>i</var> 行目に出力しおください。 </p> <H2>Sample Input</H2> <pre> 3 6 6 3 19 7 4 21 8 1 6 5 4 2 11 12 4 2 11 11 9 2 11 14 3 20 5 17 9 20 5 20 10 20 5 0 </pre> <H2>Output for the Sample Input</H2> <pre> Safe Safe Danger Safe Danger Safe </pre>
p02544
<span class="lang-en"> <p>Score : <var>900</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given are a permutation <var>p_1, p_2, \dots, p_N</var> of <var>(1, 2, ..., N)</var> and an integer <var>K</var>. Maroon performs the following operation for <var>i = 1, 2, \dots, N - K + 1</var> in this order:</p> <ul> <li>Shuffle <var>p_i, p_{i + 1}, \dots, p_{i + K - 1}</var> uniformly randomly.</li> </ul> <p>Find the expected value of the inversion number of the sequence after all the operations are performed, and print it modulo <var>998244353</var>.</p> <p>More specifically, from the constraints of this problem, it can be proved that the expected value is always a rational number, which can be represented as an irreducible fraction <var>\frac{P}{Q}</var>, and that the integer <var>R</var> that satisfies <var>R \times Q \equiv P \pmod{998244353}, 0 \leq R &lt; 998244353</var> is uniquely determined. Print this <var>R</var>.</p> <p>Here, the inversion number of a sequence <var>a_1, a_2, \dots, a_N</var> is defined to be the number of ordered pairs <var>(i, j)</var> that satisfy <var>i &lt; j, a_i &gt; a_j</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 200,000</var></li> <li><var>2 \leq K \leq N</var></li> <li><var>(p_1, p_2, \dots, p_N)</var> is a permutation of <var>(1, 2, \dots, N)</var>.</li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>K</var> <var>p_1</var> <var>p_2</var> ... <var>p_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the expected value modulo <var>998244353</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 1 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>The final sequence is one of <var>(1, 2, 3)</var>, <var>(2, 1, 3)</var>, <var>(1, 3, 2)</var>, <var>(2, 3, 1)</var>, each with probability <var>\frac{1}{4}</var>. Their inversion numbers are <var>0, 1, 1, 2</var> respectively, so the expected value is <var>1</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 3 1 8 4 9 2 3 7 10 5 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>164091855 </pre></section> </div> </span>
p00579
<h1>むルミネヌション (Illumination)</h1> <!--  時間制限 : 2sec / メモリ制限 : 256MB--> <h2>問題文</h2> <p> JOI 氏は自宅の敷地に <var>N</var> 本の朚を所有しおいるこれらの朚は䞀列に䞊んでおり順に <var>1</var> から <var>N</var> たでの敎数で番号が付けられおいる </p> <p> この冬JOI 氏はいく぀かの朚を遞んでむルミネヌションを食り付けるこずにしたむルミネヌションには<strong>矎しさ</strong>ず呌ばれる倀が定たっおいる朚 <var>i</var> にむルミネヌションを食り付ける堎合の矎しさは <var>A_i</var> である </p> <p> JOI 氏はあたりに近い <var>2</var> ぀の朚の䞡方にむルミネヌションを食り付けおしたうず眩しすぎる堎合があるこずに気が぀いた具䜓的には<var>j = 1, 2, ..., M</var> に察しお朚 <var>L_j</var>, <var>L_j + 1</var>, <var>...</var>, <var>R_j</var> のうち <var>2</var> ぀以䞊にむルミネヌションを食り付けるべきではないずいうこずが刀明した </p> <p> この条件に埓っおむルミネヌションを食り付けるずきの矎しさの合蚈の最倧倀を求めよ </p> <h2>制玄</h2> <ul> <li><var>1 ≩ N ≩ 200000 (= 2×10^5)</var></li> <li><var>1 ≩ M ≩ 200000 (= 2×10^5)</var></li> <li><var>1 ≩ A_i ≩ 1000000000 (= 10^9)</var> (<var>1 ≩ i ≩ N</var>)</li> <li><var>1 ≩ L_j ≩ R_j ≩ N</var> (<var>1 ≩ j ≩ M</var>)</li> </ul> <h2>入力・出力</h2> <p> <b>入力</b><br> 入力は以䞋の圢匏で暙準入力から䞎えられる<br> <var>N</var> <var>M</var><br> <var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var><br> <var>L_1</var> <var>R_1</var><br> <var>L_2</var> <var>R_2</var><br> <var>⋮</var><br> <var>L_M</var> <var>R_M</var> </p> <p> <b>出力</b><br> むルミネヌションの矎しさの合蚈の最倧倀を <var>1</var> 行で出力せよ </p> <!-- <h2>小課題</h2> <p style="line-height: 200%; margin-left: 30px; margin-right: 30px;"> </p> <p style="line-height: 200%; margin-left: 30px; margin-right: 30px;"> <ol style="line-height: 200%; margin-left: 30px; margin-right: 30px;"> <li>(<var>10</var> 点) <var>N ≩ 16</var><var>M ≩ 16</var></li> <li>(<var>30</var> 点) <var>N ≩ 300</var><var>M ≩ 300</var></li> <li>(<var>30</var> 点) <var>N ≩ 4000</var><var>M ≩ 4000</var></li> <li>(<var>30</var> 点) 远加の制限はない</li> </ol> </p> --> <h2>入出力䟋</h2> <h3>入力䟋 1</h3> <pre> 4 1 1 2 3 8 2 4 </pre> <h3>出力䟋 1</h3> <pre> 9 </pre> <p> この入力䟋では朚 <var>1</var>, <var>4</var> にむルミネヌションを食り付けるず矎しさの合蚈が <var>9</var> ずなり最倧ずなる<var>L_1 = 2</var>, <var>R_1 = 4</var> なので朚 <var>2</var>, <var>3</var>, <var>4</var> のうち <var>2</var> ぀以䞊にむルミネヌションを食り付けるこずはできない䟋えば朚 <var>1</var>, <var>2</var>, <var>4</var> にむルミネヌションを食り付けるこずはできないこずに泚意せよ </p> <h3>入力䟋 2</h3> <pre> 5 2 2 3 9 5 6 1 3 2 4 </pre> <h3>出力䟋 2</h3> <pre> 15 </pre> <h3>入力䟋 3</h3> <pre> 20 10 870851814 594414687 615919461 65033245 460143082 617460823 881870957 126041265 623075703 34130727 27054628 853567651 483228744 491145755 220689940 148007930 229257101 790404982 612186806 281076231 15 19 20 20 12 13 1 4 19 19 9 13 3 6 9 12 16 16 18 19 </pre> <h3>出力䟋 3</h3> <pre> 4912419478 </pre> <br/> <div class="source"> <p class="source"> <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="クリ゚むティブ・コモンズ・ラむセンス" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png"/></a> </p> <p class="source"> <a href="https://www.ioi-jp.org/joi/2018/2019-yo/index.html">情報オリンピック日本委員䌚䜜 『第 18 回日本情報オリンピック JOI 2018/2019 予遞競技課題』</a> </p> </div>
p00083
<H1>西暊和暊倉換</H1> <p> 西暊で衚された幎月日を、元号を甚いた和暊に倉換し、その幎月日を出力するプログラムを䜜成しおください。入力は䟋に瀺すように 3 ぀の敎数であり、順に西暊幎、月、日です。これを、出力䟋に瀺すように倉換しおください。なお、明治以前の幎月日が入力された堎合は「pre-meiji」ず衚瀺しおください。 </p> <p> 各幎号の最初の幎は「元幎」ではなく「幎」ず出力するこずずしたす。 </p> <center> <table border=1> <tr><td align=center width=100>元号</td><td align=center width=240>期間</td></tr> <tr><td align=center >meiji</td><td>1868. 9. 8 〜 1912. 7.29</td></tr> <tr><td align=center >taisho</td><td>1912. 7.30 〜 1926.12.24</td></tr> <tr><td align=center >showa</td><td>1926.12.25 〜 1989. 1. 7</td></tr> <tr><td align=center >heisei</td><td>1989. 1. 8 〜</td></tr> </table> </center> <br/> <H2>入力</H2> <p> 耇数のデヌタが䞎えられたす。各デヌタずしお幎、月、日を衚す぀の敎数が空癜区切りで行に䞎えられたす。 </p> <p> 入力の終わりたで凊理しおください。デヌタの数は 50 を超えたせん。 </p> <H2>出力</H2> <p> 空癜区切りの元号、幎、月、日、たたは「pre-meiji」を行に出力しおください。 </p> <H2>Sample Input</H2> <pre> 2005 9 3 1868 12 2 1868 9 7 </pre> <H2>Output for the Sample Input</H2> <pre> heisei 17 9 3 meiji 1 12 2 pre-meiji </pre>
p00216
<H1>氎道料金</H1> <p> <!--あいづ孊園郜垂に䜏んでいる-->束平さんは、普段から゚コに気を付けお生掻をしおいたす。先月の氎道料金が 4280 円ずなり、い぀も目暙ずしおいる 4000 円を超えおしたったので、今月は節氎に努めおきたした。先月ず比べお氎道料金はどのくらい節玄できたのでしょうか。 </p> <p> 今月の䜿甚氎量 <var>w</var> [m<sup>3</sup>] を入力ずし、先月の氎道料金である 4280 円ず比范しお、どのくらい氎道料金を節玄できたかを出力するプログラムを䜜成しおください。 </p> <p> なお、氎道料金は次のように蚈算されたす。 </p> <p> (氎道料金) = (基本料金) + (氎量による料金) </p> <p> 氎量による料金は䞋衚のように䜿甚量に応じお蚈算されたす。 </p> <center> <table> <tr> <th width="180"> 段階</th><th width="240"> 氎量 </th><th width="240"> 料金</th> </tr> <tr> <td>第 1 段階料金 </td><td> 10 [m<sup>3</sup>] たで </td><td> 基本料金 1150 円 </td> </tr> <tr> <td>第 2 段階料金 </td><td> 10 [m<sup>3</sup>] 超過 20 [m<sup>3</sup>] たで</td><td> 1 [m<sup>3</sup>] あたり 125 円 </td> </tr> <tr> <td>第 3 段階料金 </td><td> 20 [m<sup>3</sup>] 超過 30 [m<sup>3</sup>] たで </td><td>1 [m<sup>3</sup>] あたり 140 円 </td> </tr> <tr> <td>第 4 段階料金 </td><td> 30 [m<sup>3</sup>] 超過分 </td><td> 1 [m<sup>3</sup>] あたり 160 円 </td> </tr> </table> </center> <br/> <p> 䟋えば、䜿甚氎量 40 [m<sup>3</sup>] の堎合は、 基本料金 1150 円(第 1 段階) + 10 [m<sup>3</sup>] &times; 125 円(第 2 段階) + 10 [m<sup>3</sup>] &times; 140 円(第 3 段階) + 10 [m<sup>3</sup>] &times; 160 円(第 4 段階) = 5400 円 ずなりたす。 </p> <H2>Input</H2> <p> 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりは -1 ひず぀の行で瀺されたす。 </p> <p> 各デヌタセットずしお、 今月の䜿甚氎量を衚す敎数 <var>w</var> (0 &le; <var>w</var> &le; 100) が行に䞎えられたす。 </p> <p> デヌタセットの数は 200 を超えたせん。 </p> <H2>Output</H2> <p> 入力デヌタセットごずに、先月の氎道料金ずの差を1行に出力したす。 </p> <H2>Sample Input</H2> <pre> 29 40 0 -1 </pre> <H2>Output for the Sample Input</H2> <pre> 620 -1120 3130 </pre>
p02381
<H1>Standard Deviation</H1><br> <p> You have final scores of an examination for <var>n</var> students. Calculate standard deviation of the scores <var>s<sub>1</sub></var>, <var>s<sub>2</sub></var> ... <var>s<sub>n</sub></var>. </p> <p> The variance &alpha;<sup>2</sup> is defined by </p> <p> &alpha;<sup>2</sup> = (&sum;<sup>n</sup><sub><i>i</i>=1</sub>(s<sub><i>i</i></sub> - m)<sup>2</sup>)/n </p> <p> where <var>m</var> is an average of <var>s<sub>i</sub></var>. The standard deviation of the scores is the square root of their variance. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each dataset is given in the following format: </p> <pre> <var>n</var> <var>s</var><sub>1</sub> <var>s</var><sub>2</sub> ... <var>s</var><sub><var>n</var></sub> </pre> <p> The input ends with single zero for <var>n</var>. </p> <H2>Output</H2> <p> For each dataset, print the standard deviation in a line. The output should not contain an absolute error greater than 10<sup>-4</sup>. </p> <H2>Constraints</H2> <ul> <li><var>n</var> &le; 1000</li> <li>0 &le; <var>s<sub>i</sub></var> &le; 100 </li> </ul> <H2>Sample Input</H2> <pre> 5 70 80 100 90 20 3 80 80 80 0 </pre> <H2>Sample Output</H2> <pre> 27.85677655 0.00000000 </pre>
p01954
<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> Sum Source Detection </H1> <p> JAG members began a game with integers. The game consists of $N + M + 1$ players: $N$ open number holders, $M$ secret number holders, and one answerer, you. </p> <p> In the preparation, an integer $K$ is told to all $N + M + 1$ players. $N + M$ number holders choose their own integers per person under the following restrictions: </p> <ul> <li>Each holder owns a positive integer.</li> <li>The sum of all the integers equals $K$.</li> <li>Every integer owned by secret number holders is strictly less than any integers owned by open number holders.</li> </ul> <p> After the choices, $N$ open number holders show their integers $O_1, ..., O_N$ to the answerer while secret number holders do not. </p> <p> The game has $Q$ rounds. At the beginning of each round, $M$ secret number holders can change their numbers under the above restrictions, while open number holders cannot. Then $N + M$ number holders select part of members among them arbitrary, calculate the sum $X$ of the integers owned by the selected members, and tell $X$ to the answerer. For each round, the answerer tries to identify the definitely selected open number holders from the information $K$, $X$, and $O_1, ..., O_N$: The answerer will get points per actually selected open number holder in the answer. On the other hand, if the answer contains at least one non-selected member, you lose your points got in the round. Thus, the answerer, you, must answer only the open number holders such that the holders are definitely selected. </p> <p> Your task in this problem is to write a program to determine all the open number holders whose integers are necessary to the sum for each round in order to maximize your points. </p> <H2>Input</H2> <p> The input consists of a single test case formatted as follows. </p> <pre> $N$ $M$ $K$ $Q$ $O_1$ ... $O_N$ $X_1$ ... $X_Q$ </pre> <p> The first line consists of four integers $N, M, K,$ and $Q$. $N$ and $M$ are the numbers of open number holders and secret number holders respectively ($1 \leq N, 0 \leq M, N + M \leq 40$). $K$ is an integer ($1 \leq K \leq 200,000$). $Q$ is the number of rounds of the game ($1 \leq Q \leq 10,000$). </p> <p> The second line contains $N$ integers $O_1, ..., O_N$, as the $i$-th open number holder owns $O_i$ ($1 \leq O_1 \leq ... \leq O_N \leq K$). </p> <p> The third line indicates $Q$ integers $X_1, ..., X_Q$ ($0 \leq X_i \leq K$). $X_i$ is the sum of the integers owned by the selected members in the $i$-th round. </p> <p> It is guaranteed that there is at least one way to compose $X_i$. In other words, you can assume that there is at least one integer sequence $S_1, ..., S_M$, which represents integers owned by secret number holders, satisfying the followings: </p> <ul> <li>$0 < S_j < O_1$ for $1 \leq j \leq M$. Note that $O_1 = min_{1\leq k \leq N}O_k$ holds.</li> <li>$\sum_{j=1}^N O_j + \sum_{k=1}^M S_k = K$.</li> <li>There is at least one pair of subsets $U \subseteq \{1,...,N\}$ and $V \subseteq \{1, ..., M\}$ such that $\sum_{j\in U} O_j + \sum_{k\in V}S_k = X_i$ holds.</li> </ul> <H2>Output</H2> <p> On each sum $X_i$, print the indices of the open number holders whose integers are required to make up $X_i$. The output for each sum has to be printed in one line, in ascending order, and separated by a single space. If there is no open number holder whose integer is certainly used for $X_i$, print $-1$ in one line. </p> <H2>Sample Input 1</H2> <pre> 2 2 23 2 7 10 9 10 </pre> <H2>Output for Sample Input 1</H2> <pre> 1 -1 </pre> <p> The first sum 9 can be achieved only by the first open number holder's 7 plus 2 of a secret number holder. In this case, secret number holders have 2 and 4. The second open number holder's 10 is a candidate for the second sum 10. The first open holder's 7 plus 3 is also possible one, as secret number holders have two 3s. </p> <H2>Sample Input 2</H2> <pre> 1 1 100 3 51 49 51 100 </pre> <H2>Output for Sample Input 2</H2> <pre> -1 1 1 </pre> <p> The only secret number holder owns 49. The output for the first sum is $-1$ because the open number holder's 51 is not selected. </p> <H2>Sample Input 3</H2> <pre> 2 1 58152 4 575 57500 575 57577 77 0 </pre> <H2>Output for Sample Input 3</H2> <pre> 1 2 -1 -1 </pre> <p> In this case, the only secret number holder definitely has 77. The output for the last sum 0 is -1 because no integer of open number holders is needed to form 0. </p> <H2>Sample Input 4</H2> <pre> 3 2 1500 1 99 300 1000 99 </pre> <H2>Output for Sample Input 4</H2> <pre> 1 </pre> <p> The only way to compose 99 is to select the first open number holder only; secret number holders have two integers between 1 and 98, while the sum of them must be 101. </p> <H2>Sample Input 5</H2> <pre> 3 2 20 19 3 3 11 1 2 3 4 5 6 7 8 9 11 12 13 14 15 16 17 18 19 20 </pre> <H2>Output for Sample Input 5</H2> <pre> -1 -1 -1 -1 -1 -1 1 2 1 2 1 2 3 3 3 3 3 3 3 1 2 3 1 2 3 1 2 3 </pre> <p> The numbers owned by the two secret number holders are 1 and 2. At least one open number holder's 3 is required to compose 5 and 6 respectively, but it is impossible to determine the definitely selected open number holder(s). On the other hand, 7 needs the two open number holders who both own 3. </p>
p03969
<span class="lang-en"> <p>Score : <var>1300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>One day, AtCoDeer the deer found a simple graph (that is, a graph without self-loops and multiple edges) with <var>N</var> vertices and <var>M</var> edges, and brought it home. The vertices are numbered <var>1</var> through <var>N</var> and mutually distinguishable, and the edges are represented by <var>(a_i,b_i) (1≩i≩M)</var>.</p> <p>He is painting each edge in the graph in one of the <var>K</var> colors of his paint cans. As he has enough supply of paint, the same color can be used to paint more than one edge.</p> <p>The graph is made of a special material, and has a strange property. He can choose a simple cycle (that is, a cycle with no repeated vertex), and perform a circular shift of the colors along the chosen cycle. More formally, let <var>e_1</var>, <var>e_2</var>, <var>...</var>, <var>e_a</var> be the edges along a cycle in order, then he can perform the following simultaneously: paint <var>e_2</var> in the current color of <var>e_1</var>, paint <var>e_3</var> in the current color of <var>e_2</var>, <var>...</var>, paint <var>e_a</var> in the current color of <var>e_{a-1}</var>, and paint <var>e_1</var> in the current color of <var>e_{a}</var>.</p> <div style="text-align: center;"> <img src="https://atcoder.jp/img/arc062/5fd1cd3003603ab14774f9342ccf2290.png"> <p>Figure <var>1</var>: An example of a circular shift</p> </img></div> <p>Two ways to paint the edges, <var>A</var> and <var>B</var>, are considered the same if <var>A</var> can be transformed into <var>B</var> by performing a finite number of circular shifts. Find the number of ways to paint the edges. Since this number can be extremely large, print the answer modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≩N≩50</var></li> <li><var>1≩M≩100</var></li> <li><var>1≩K≩100</var></li> <li><var>1≩a_i,b_i≩N (1≩i≩M)</var></li> <li>The graph has neither self-loops nor multiple edges.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>K</var> <var>a_1</var> <var>b_1</var> <var>a_2</var> <var>b_2</var> <var>:</var> <var>a_M</var> <var>b_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of ways to paint the edges, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 4 2 1 2 2 3 3 1 3 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>8 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 2 3 1 2 4 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>9 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>11 12 48 3 1 8 2 4 9 5 4 1 6 2 9 8 3 10 8 4 10 8 6 11 7 1 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>569519295 </pre></section> </div> </span>
p00646
<H1><font color="#000000">Problem J:</font> No Story</H1> <p> Since I got tired to write long problem statements, I decided to make this problem statement short. For given positive integer <i>L</i>, how many pairs of positive integers <i>a</i>, <i>b</i> (<i>a</i> &le; <i>b</i>) such that LCM(<i>a</i>, <i>b</i>) = <i>L</i> are there? Here, LCM(<i>a</i>, <i>b</i>) stands for the least common multiple of <i>a</i> and <i>b</i>. </p> <H2>Input</H2> <p> For each dataset, an integer <i>L</i> is given in a line. Input terminates when <i>L</i> = 0. </p> <H2>Output</H2> <p> For each dataset, output the number of pairs of <i>a</i> and <i>b</i>. </p> <H2>Constraints</H2> <ul> <li>1 &le; <i>L</i> &le; 10<sup>12</sup></li> </ul> <H2>Sample Input</H2> <pre> 12 9 2 0 </pre> <H2>Output for the Sample Input</H2> <pre> 8 3 2 </pre>
p01407
<H1>A: Attack the Moles</H1> <p> ICPC で良い成瞟を収めるには修行が欠かせないうさぎは ICPC で勝ちたいので今日も修行をするこずにした </p> <p> 今日の修行はもぐらたたきを䜕回も行っお反射神経ず蚘憶力を高めようずいうものである出おくるもぐらを次々に叩き出来るだけ倚くのポむントを獲埗したい </p> <p> もぐらが出おくる可胜性のある堎所は盎線状に䞊んでいお基準点からの距離によっお座暙が定たっおいるうさぎはしばらく修行を続けるうちにもぐらの出珟する堎所ず時間が垞に䞀緒であるこずに気が付いたうさぎはその情報をすべお蚘録しコンピュヌタで解析を行うこずにした </p> <p> もぐらを叩くにはもぐらの出珟䜍眮に手を動かした埌もぐらの出おくるタむミングにぎったり合わせおもぐらを叩かなければならないもぐらをうたく叩けるずそのもぐらに応じおポむントを埗るこずが出来るもぐらを叩く動䜜は䞀瞬で行うこずが出来るが手を移動させる速さには限界があるうさぎはもぐらを叩くにあたっお巊右䞡方の手を甚いるこずができる巊手ず右手は独立に動かすこずが可胜であるが巊手は垞に右手より座暙が小さい䜍眮に存圚しなければならないこのような条件䞋で最倧でどれだけのポむントが埗られるかを調べたい </p> <H2>Input</H2> <pre> <i>N</i> <i>V</i> <i>X</i><sub><i>Left</i></sub> <i>X</i><sub><i>Right</i></sub> <i>X</i><sub>1</sub> <i>T</i><sub>1</sub> <i>P</i><sub>1</sub> ... <i>X</i><sub><i>N</i></sub> <i>T</i><sub><i>N</i></sub> <i>P</i><sub><i>N</i></sub> </pre> <p> <i>N</i> は出おくるもぐらの数<i>V</i> は手を移動させられる最倧の速さ<i>X</i><sub><i>Left</i></sub>, <i>X</i><sub><i>Right</i></sub> はそれぞれ巊手右手の初期䜍眮の座暙である<i>X</i><sub><i>i</i></sub>, <i>T</i><sub><i>i</i></sub>, <i>P</i><sub><i>i</i></sub> はそれぞれ<i>i</i> 番目のもぐらの出珟する䜍眮の座暙ゲヌム開始から出珟たでの時間叩けた際に埗られるポむントである </p> <p> 1 &le; <i>N</i> &le; 3,0001 &le; <i>V</i> &le; 10,0001 &le; <i>X</i><sub><i>Left</i></sub> &lt; <i>X</i><sub><i>Right</i></sub> &le; 100,0001 &le; <i>X</i><sub>1</sub> &le; <i>X</i><sub>2</sub> &le; ... &le; <i>X</i><sub><i>N</i></sub> &le; 100,0001 &le; <i>T</i><sub><i>i</i></sub> &le; 100,0001 &le; <i>P</i><sub><i>i</i></sub> &le; 100,000 を満たす(<i>X</i><sub><i>i</i></sub>, <i>T</i><sub><i>i</i></sub>) ずしお同䞀の組は耇数回珟れない </p> <H2>Output</H2> <p> うさぎが埗られる最倧のポむントを 1 行に出力せよ </p> <H2>Sample Input 1</H2> <pre> 3 10 150 250 100 20 123 201 10 67 202 10 45 </pre> <H2>Sample Output 1</H2> <pre> 190 </pre> <H2>Sample Input 2</H2> <pre> 1 7 20 90 55 5 73 </pre> <H2>Sample Output 2</H2> <pre> 73 </pre> <H2>Sample Input 3</H2> <pre> 10 2 1000 2000 400 300 1 600 200 1 700 800 1 700 500 1 900 600 1 1000 700 1 1300 900 1 1400 400 1 1500 1000 1 2000 100 1 </pre> <H2>Sample Output 3</H2> <pre> 10 </pre>
p03590
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p><em>Seisu-ya</em>, a store specializing in non-negative integers, sells <var>N</var> non-negative integers. The <var>i</var>-th integer is <var>A_i</var> and has a <em>utility</em> of <var>B_i</var>. There may be multiple equal integers with different utilities.</p> <p>Takahashi will buy some integers in this store. He can buy a combination of integers whose <em>bitwise OR</em> is less than or equal to <var>K</var>. He wants the sum of utilities of purchased integers to be as large as possible.</p> <p>Find the maximum possible sum of utilities of purchased integers.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 10^5</var></li> <li><var>0 \leq K &lt; 2^{30}</var></li> <li><var>0 \leq A_i &lt; 2^{30}(1\leq i\leq N)</var></li> <li><var>1 \leq B_i \leq 10^9(1\leq i\leq N)</var></li> <li>All input values are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Inputs</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>K</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>Outputs</h3><p>Print the maximum possible sum of utilities of purchased integers.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 5 3 3 4 4 2 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>8 </pre> <p>Buy <var>2</var> and <var>3</var> to achieve the maximum possible total utility, <var>8</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 6 3 3 4 4 2 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>9 </pre> <p>Buy <var>2</var> and <var>4</var> to achieve the maximum possible total utility, <var>9</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>7 14 10 5 7 4 11 4 9 8 3 6 6 2 8 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>32 </pre></section> </div> </span>
p01057
<h1>String Crossing</h1> <h2>Problem</h2> <p> <var>N</var>個の文字列{ <var>S<sub>1</sub></var>, <var>S<sub>2</sub></var>, ..., <var>S<sub>N</sub></var> } が䞎えられる。 続いお<var>Q</var>個のク゚リが䞎えられる。 ク゚リの皮類は以䞋の2぀である。 </p> <ol> <li> <var>a</var>,<var>b</var>,<var>c</var>,<var>d</var>が入力され<var>S<sub>a</sub></var> の <var>b</var>文字目からの substring を <var>S<sub>c</sub></var> の <var>d</var>-1文字たでの substring の埌に繋げる。これを新しい<var>S<sub>c</sub></var>ずする。 元の<var>S<sub>c</sub></var> の <var>d</var>文字目からの substring を <var>S<sub>a</sub></var> の <var>b</var>-1文字たでの substring の埌に繋げる。これを新しい<var>S<sub>a</sub></var>ずする。 </li> <li> <var>a</var>,<var>b</var>,<var>c</var>が入力され <var>S<sub>a</sub></var> の <var>b</var>文字目を <var>c</var> に倉曎する。 </li> </li> </ol> <p> 䟋えば<var>S<sub>1</sub></var>="abcd",<var>S<sub>2</sub></var>="efgh"があり ク゚リの皮類が1で<var>a</var>=1,<var>b</var>=2,<var>c</var>=2,<var>d</var>=3のずき </p> <pre> a - -> bcd X ef - -> gh </pre> <p> <var>S<sub>1</sub></var>="agh",<var>S<sub>2</sub></var>="efbcd"ずなる。 </p> <p> 党おのク゚リを凊理した埌の文字列<var>S<sub>1</sub></var>から<var>S<sub>N</sub></var>を党お出力せよ。 </p> <h2>Input</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>N</var> <var>Q</var> <var>S<sub>1</sub></var> <var>S<sub>2</sub></var> ... <var>S<sub>N</sub></var> <var>query<sub>1</sub></var> <var>query<sub>2</sub></var> ... <var>query<sub>Q</sub></var> </pre> 各<var>query</var>は次のいずれかである。 <pre> 1 <var>a</var> <var>b</var> <var>c</var> <var>d</var> </pre> <p>or</p> <pre> 2 <var>a</var> <var>b</var> <var>c</var> </pre> <h2>Constraints</h2> <ul> <li>1 &le; <var>N</var> &le; 10<sup>5</sup></li> <li>1 &le; <var>Q</var> &le; 10<sup>5</sup></li> <li><var>N</var>個の文字列の長さの合蚈は2&times;10<sup>6</sup>を越えない。</li> <li>文字列<var>S<sub>i</sub></var>は党お英小文字であるこずが保蚌される。</li> <li>ク゚リの皮類が1のずき <ul> <li><var>a</var> &ne; <var>c</var></li> <li>1 &le; <var>b</var> &le; |<var>S<sub>a</sub></var>|</li> <li>1 &le; <var>d</var> &le; |<var>S<sub>c</sub></var>|</li> </ul> </li> <li>ク゚リの皮類が2のずき <ul> <li>1 &le; <var>b</var> &le; |<var>S<sub>a</sub></var>|</li> <li><var>c</var>は英小文字であるこずが保蚌される。</li> </ul> </li> </ul> <p> 高速な入出力を掚奚する。 </p> <h2>Output</h2> <p> 各ク゚リを凊理した埌の文字列を<var>S<sub>1</sub></var>から<var>S<sub>N</sub></var>たで1行ず぀出力せよ。 </p> <pre> <var>S<sub>1</sub></var> <var>S<sub>2</sub></var> ... <var>S<sub>N</sub></var> </pre> <h2>Sample Input 1</h2> <pre> 2 1 abcd efgh 1 1 2 2 3 </pre> <h2>Sample Output 1</h2> <pre> agh efbcd </pre> <h2>Sample Input 2</h2> <pre> 2 3 abcd efgh 1 1 2 2 3 2 1 3 x 2 2 4 x </pre> <h2>Sample Output 2</h2> <pre> agx efbxd </pre> <h2>Sample Input 3</h2> <pre> 10 10 sjcvpauokb fmeaowomscy sepeqqfcosrjmonfsv zapc aromazjzqoeiqswvcaf clifpa dusudcz qeqdzdtdzlkhc gkpsjvdvadmf xrtyxnkolluagwxp 1 4 4 6 3 1 7 1 8 1 2 2 6 o 1 4 4 3 7 2 1 2 i 1 6 3 3 2 1 6 5 1 9 2 10 9 j 1 2 2 7 3 2 3 2 b </pre> <h2>Sample Output 3</h2> <pre> sicvpauoeqqifpa fqdzdtdzlkhc sb zapfcosrjmonfsv aromazjzqoeiqswvcaf clepkb qemeaooomscy dusudcz gkpsjvdvadmf xrtyxnkojluagwxp </pre>
p01542
<h1>倱われし数</h1> <p> 時は3xxx幎、高床に発達した文明は停滞期を迎えおいた。歎史家たちはこの状況を打開しようず過去の叡智を孊ぶこずにした。泚目したのはコンピュヌタ創䞖期の倩才が残した資料である。この資料には蚈算匏が曞かれおおりその蚈算結果が知りたいのだが、残念ながらその䞀郚の文字が薄れお読めなくなっおいる。仕方がないので蚈算結果ずしおありえる最も倧きい数を求めるこずにした。 蚈算匏は2進数で曞かれおおり、挔算は足し算・匕き算・掛け算の3皮類である。括匧も甚いられおいるが括匧内が数字のみであるこずはない。正確には以䞋のBNFで定矩された文法を満たしおいる必芁がある。 </p> <pre>&lt;expression&gt; ::= &lt;number&gt; | &lt;expression&gt; &lt;operation&gt; &lt;expression&gt; | ( &lt;expression&gt; &lt;operation&gt; &lt;expression&gt; ) &lt;number&gt; ::= &lt;digit&gt; | &lt;number&gt; &lt;digit&gt; &lt;operation&gt; ::= + | - | * &lt;digit&gt; ::= 0 | 1 </pre> <p> 圓時のコンピュヌタの蚈算胜力の限界により、数字は0以䞊<var>2<sup>10</sup></var>未満の敎数であり蚈算䞭もこの範囲を出るこずはない。ただし蚈算は括匧内を先に行い、掛け算は足し算・匕き算より先に行う。それ以倖の堎合は巊から順に蚈算する。 </p> <h2>Input</h2> <p> 入力は1行からなり、解読すべき数匏が1぀䞎えられる。数匏は1文字以䞊100文字以䞋である。1぀の数匏に぀いお最倧5文字が読めなくなっおいお、「.」で衚珟されおいる。䞎えられる数匏に含たれる文字は01+-*().のいずれかである。 </p> <h2>Constraints</h2> <ul> <li>数匏は1文字以䞊100文字以䞋 </li><li>改行を陀くすべおの文字は01+-*().のいずれか </li><li>.の個数は5個以䞋 </li></ul> <h2>Output</h2> <p> 元の数匏ずしお考えられるものの内、蚈算結果が最倧ずなるものを求め、蚈算結果を10進法で出力せよ。読めなくなっおいる文字をどのように埋めおも元の数匏ず考えられるものを䜜れないずきは-1を出力せよ。 </p> <H2>Sample Input 1</H2> <pre>000 </pre> <H2>Output for the Sample Input 1</H2> <pre>0 </pre> <H2>Sample Input 2</H2> <pre>0.0 </pre> <H2>Output for the Sample Input 2</H2> <pre>2 </pre> <H2>Sample Input 3</H2> <pre>... </pre> <H2>Output for the Sample Input 3</H2> <pre>7 </pre> <H2>Sample Input 4</H2> <pre>(1.1) </pre> <H2>Output for the Sample Input 4</H2> <pre>2 </pre> <H2>Sample Input 5</H2> <pre>0-1. </pre> <H2>Output for the Sample Input 5</H2> <pre>-1 </pre>
p03085
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>On the Planet AtCoder, there are four types of bases: <code>A</code>, <code>C</code>, <code>G</code> and <code>T</code>. <code>A</code> bonds with <code>T</code>, and <code>C</code> bonds with <code>G</code>.</p> <p>You are given a letter <var>b</var> as input, which is <code>A</code>, <code>C</code>, <code>G</code> or <code>T</code>. Write a program that prints the letter representing the base that bonds with the base <var>b</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>b</var> is one of the letters <code>A</code>, <code>C</code>, <code>G</code> and <code>T</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>b</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the letter representing the base that bonds with the base <var>b</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>A </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>T </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>G </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>C </pre></section> </div> </span>
p01112
<h3>Playoff by all the teams</h3> <!-- end en only --> <!-- begin en only --> <p> The Minato Mirai Football Association hosts its annual championship as a single round-robin tournament, in which each team plays a single match against all the others. Unlike many other round-robin tournaments of football, matches never result in a draw in this tournament. When the regular time match is a tie, overtime is played, and, when it is a tie again, a penalty shootout is played to decide the winner. </p> <!-- end en only --> <!-- begin en only --> <p> If two or more teams won the most number of matches in the round-robin, a playoff is conducted among them to decide the champion. However, if the number of teams is an odd number, it is possible that all the teams may have the same number of wins and losses, in which case all the teams participate in the playoff, called a "full playoff" here. </p> <!-- end en only --> <!-- begin en only --> <p> Now, some of the tournament matches have already been played and we know their results. Whether or not a full playoff will be required may depend on the results of the remaining matches. Write a program that computes the number of win/loss combination patterns of the remaining matches that lead to a full playoff. </p> <!-- end en only --> <!-- begin en only --> <p> The first datatset of the Sample Input represents the results of the first three matches in a round-robin tournament of five teams, shown in the following table. In the table, gray cells indicate the matches not played yet. </p> <!-- end en only --> <table border=""> <tbody><tr><th><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_Dtitle" alt="Team \ Against"></th><th>Team<sub>1</sub></th><th>Team<sub>2</sub></th><th>Team<sub>3</sub></th><th>Team<sub>4</sub></th><th>Team<sub>5</sub></th></tr> <tr><th>Team<sub>1</sub></th><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_Dbackslash" alt="x"></td><td bgcolor="#cccccc">&nbsp;</td><td bgcolor="#cccccc">&nbsp;</td><td align="center">lost</td><td align="center">lost</td></tr> <tr><th>Team<sub>2</sub></th><td bgcolor="#cccccc">&nbsp;</td><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_Dbackslash" alt="x"></td><td align="center">lost</td><td bgcolor="#cccccc">&nbsp;</td><td bgcolor="#cccccc">&nbsp;</td></tr> <tr><th>Team<sub>3</sub></th><td bgcolor="#cccccc">&nbsp;</td><td align="center">won</td><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_Dbackslash" alt="x"></td><td bgcolor="#cccccc">&nbsp;</td><td bgcolor="#cccccc">&nbsp;</td></tr> <tr><th>Team<sub>4</sub></th><td align="center">won</td><td bgcolor="#cccccc">&nbsp;</td><td bgcolor="#cccccc">&nbsp;</td><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_Dbackslash" alt="x"></td><td bgcolor="#cccccc">&nbsp;</td></tr> <tr><th>Team<sub>5</sub></th><td align="center">won</td><td bgcolor="#cccccc">&nbsp;</td><td bgcolor="#cccccc">&nbsp;</td><td bgcolor="#cccccc">&nbsp;</td><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_Dbackslash" alt="x"></td></tr> </tbody></table> <!-- begin en only --> <p> In this case, all the teams win the same number of matches with only two win/loss combination patterns of the remaining matches, which lead to a full playoff, as shown below. In the two tables, the differences are indicated in light yellow. </p> <!-- end en only --> <table border=""> <tbody><tr><th><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_Dtitle" alt="Team \ Against"></th><th>Team<sub>1</sub></th><th>Team<sub>2</sub></th><th>Team<sub>3</sub></th><th>Team<sub>4</sub></th><th>Team<sub>5</sub></th></tr> <tr><th>Team<sub>1</sub></th><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_Dbackslash" alt="x"></td><td align="center">won</td><td align="center">won</td><td align="center">lost</td><td align="center">lost</td></tr> <tr><th>Team<sub>2</sub></th><td align="center">lost</td><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_Dbackslash" alt="x"></td><td align="center">lost</td><td align="center">won</td><td align="center">won</td></tr> <tr><th>Team<sub>3</sub></th><td align="center">lost</td><td align="center">won</td><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_Dbackslash" alt="x"></td><td align="center" bgcolor="#ffffcc">won</td><td align="center" bgcolor="#ffffcc">lost</td></tr> <tr><th>Team<sub>4</sub></th><td align="center">won</td><td align="center">lost</td><td align="center" bgcolor="#ffffcc">lost</td><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_Dbackslash" alt="x"></td><td align="center" bgcolor="#ffffcc">won</td></tr> <tr><th>Team<sub>5</sub></th><td align="center">won</td><td align="center">lost</td><td align="center" bgcolor="#ffffcc">won</td><td align="center" bgcolor="#ffffcc">lost</td><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_Dbackslash" alt="x"></td></tr> </tbody></table> <table border=""> <tbody><tr><th><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_Dtitle" alt="Team \ Against"></th><th>Team<sub>1</sub></th><th>Team<sub>2</sub></th><th>Team<sub>3</sub></th><th>Team<sub>4</sub></th><th>Team<sub>5</sub></th></tr> <tr><th>Team<sub>1</sub></th><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_Dbackslash" alt="x"></td><td align="center">won</td><td align="center">won</td><td align="center">lost</td><td align="center">lost</td></tr> <tr><th>Team<sub>2</sub></th><td align="center">lost</td><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_Dbackslash" alt="x"></td><td align="center">lost</td><td align="center">won</td><td align="center">won</td></tr> <tr><th>Team<sub>3</sub></th><td align="center">lost</td><td align="center">won</td><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_Dbackslash" alt="x"></td><td align="center" bgcolor="#ffffcc">lost</td><td align="center" bgcolor="#ffffcc">won</td></tr> <tr><th>Team<sub>4</sub></th><td align="center">won</td><td align="center">lost</td><td align="center" bgcolor="#ffffcc">won</td><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_Dbackslash" alt="x"></td><td align="center" bgcolor="#ffffcc">lost</td></tr> <tr><th>Team<sub>5</sub></th><td align="center">won</td><td align="center">lost</td><td align="center" bgcolor="#ffffcc">lost</td><td align="center" bgcolor="#ffffcc">won</td><td><img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_Dbackslash" alt="x"></td></tr> </tbody></table> <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>m</i><br> <i>x</i><sub>1</sub> <i>y</i><sub>1</sub> <br> ... <br> <i>x<sub>m</sub></i> <i>y<sub>m</sub></i> <br> </p> </blockquote> <!-- begin en only --> <p> <i>n</i> is an odd integer, 3, 5, 7, or 9, indicating the number of teams participating in the tournament. <i>m</i> is a positive integer less than <i>n</i>(<i>n</i>&#8722;1)/2, which is the number of matches already finished. <i>x<sub>i</sub></i> and <i>y<sub>i</sub></i> give the result of the <i>i</i>-th match that has already taken place, indicating that team <i>x<sub>i</sub></i> defeated team <i>y<sub>i</sub></i>. Each of <i>x<sub>i</sub></i> and <i>y<sub>i</sub></i> is an integer 1 through <i>n</i> which indicates the team number. No team plays against itself, that is, for any <i>i</i>, <i>x<sub>i</sub></i> &#8800; <i>y<sub>i</sub></i>. The match result of the same team pair appears at most once. That is, if <i>i</i> &#8800; <i>j</i>, then (<i>x<sub>i</sub></i>,<i>y<sub>i</sub></i>) &#8800; (<i>x<sub>j</sub></i>,<i>y<sub>j</sub></i>) and (<i>x<sub>i</sub></i>,<i>y<sub>i</sub></i>) &#8800; (<i>y<sub>j</sub></i>,<i>x<sub>j</sub></i>) hold. </p> <!-- end en only --> <!-- begin en only --> <p> The end of the input is indicated by a line containing a zero. The number of datasets does not exceed 100. </p> <!-- end en only --> <h3>Output</h3> <!-- begin en only --> <p> For each dataset, output a single line containing one integer which indicates the number of possible future win/loss patterns that a full playoff will be required. </p> <!-- end en only --> <h3>Sample Input</h3> <pre>5 3 3 2 4 1 5 1 3 1 1 2 3 2 1 2 3 2 5 4 4 1 4 2 5 1 5 2 5 3 4 1 4 2 5 1 5 4 3 2 4 1 5 1 5 2 9 11 6 1 6 4 7 2 7 3 7 4 8 2 8 3 8 4 9 1 9 3 9 5 9 10 6 1 6 4 7 2 7 3 7 4 8 2 8 3 8 4 9 1 9 3 5 6 4 3 2 1 5 1 2 4 1 3 2 3 9 1 1 2 0 </pre> <h3>Output for the Sample Input</h3> <pre>2 1 0 0 1 0 0 16 0 1615040 </pre>
p00353
<H1>Shopping</H1> <p> You are now in a bookshop with your friend Alice to buy a book, "The Winning Strategy for the Programming Koshien Contest,” just released today. As you definitely want to buy it, you are planning to borrow some money from Alice in case the amount you have falls short of the price. If the amount you receive from Alice still fails to meet the price, you have to abandon buying the book this time. </p> <p> Write a program to calculate the minimum amount of money you need to borrow from Alice given the following three items of data: the money you and Alice have now and the price of the book. </p> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> <var>m</var> <var>f</var> <var>b</var> </pre> <p> A line containing the three amounts of money is given: the amount you have with you now <var>m</var> (0 &le; <var>m</var> &le; 10000), the money Alice has now <var>f</var> (0 &le; <var>f</var> &le; 10000) and the price of the book <var>b</var> (100 &le; <var>b</var> &le; 20000). </p> <h2>Output</h2> <p> Output a line suggesting the minimum amount of money you need to borrow from Alice. Output "NA" if all the money Alice has with him now is not a sufficient amount for you to buy the book. </p> <h2>Sample Input 1</h2> <pre> 1000 3000 3000 </pre> <h2>Sample Output 1</h2> <pre> 2000 </pre> <h2>Sample Input 2</h2> <pre> 5000 3000 4500 </pre> <h2>Sample Output 2</h2> <pre> 0 </pre> <h2>Sample Input 3</h2> <pre> 500 1000 2000 </pre> <h2>Sample Output 3</h2> <pre> NA </pre>
p03986
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a string <var>X</var>, which has an even number of characters. Half the characters are <code>S</code>, and the other half are <code>T</code>.</p> <p>Takahashi, who hates the string <code>ST</code>, will perform the following operation <var>10^{10000}</var> times:</p> <ul> <li>Among the occurrences of <code>ST</code> in <var>X</var> as (contiguous) substrings, remove the leftmost one. If there is no occurrence, do nothing.</li> </ul> <p>Find the eventual length of <var>X</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 ≩ |X| ≩ 200,000</var></li> <li>The length of <var>X</var> is even.</li> <li>Half the characters in <var>X</var> are <code>S</code>, and the other half are <code>T</code>.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Scores</h3><ul> <li>In test cases worth <var>200</var> points, <var>|X| ≩ 200</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>X</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the eventual length of <var>X</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>TSTTSS </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> <p>In the <var>1</var>-st operation, the <var>2</var>-nd and <var>3</var>-rd characters of <code>TSTTSS</code> are removed. <var>X</var> becomes <code>TTSS</code>, and since it does not contain <code>ST</code> anymore, nothing is done in the remaining <var>10^{10000}-1</var> operations. Thus, the answer is <var>4</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>SSTTST </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p><var>X</var> will eventually become an empty string: <code>SSTTST</code> ⇒ <code>STST</code> ⇒ <code>ST</code> ⇒ ``.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>TSSTTTSS </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>4 </pre> <p><var>X</var> will become: <code>TSSTTTSS</code> ⇒ <code>TSTTSS</code> ⇒ <code>TTSS</code>.</p></section> </div> </span>
p02694
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>Takahashi has a deposit of <var>100</var> yen (the currency of Japan) in AtCoder Bank.</p> <p>The bank pays an annual interest rate of <var>1</var> % compounded annually. (A fraction of less than one yen is discarded.)</p> <p>Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach <var>X</var> yen or above for the first time?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var> 101 \le X \le 10^{18} </var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p>Input is given from Standard Input in the following format:</p> <pre><var>X</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print the number of years it takes for Takahashi's balance to reach <var>X</var> yen or above for the first time.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>103 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <ul> <li>The balance after one year is <var>101</var> yen.</li> <li>The balance after two years is <var>102</var> yen.</li> <li>The balance after three years is <var>103</var> yen.</li> </ul> <p>Thus, it takes three years for the balance to reach <var>103</var> yen or above.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1000000000000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>3760 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1333333333 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1706 </pre></section> </div> </span>
p01811
<h2>ABC Gene</h2> <p>文字列 <code>ABC</code> で衚される遺䌝子配列がある。あなたは次の操䜜を䜕回か行い、この遺䌝子配列を曞き換えおいくこずができる。</p> <ul> <li>文字 <code>A</code><code>B</code><code>C</code> のうち <var>1</var> ぀を遞ぶ。これを <var>x</var> ずおく。遺䌝子配列に含たれるすべおの <var>x</var> をそれぞれ <code>ABC</code> ぞ同時に眮き換える。</li> </ul> <p><code>A</code><code>B</code><code>C</code> だけからなる文字列 <var>S</var> が䞎えられる。遺䌝子配列を <var>S</var> に䞀臎させられるか刀定せよ。</p> <h3>Constraints</h3> <ul> <li><var>1</var> &le; <var>|S|</var> &le; <var>5,000</var></li> <li><var>S</var> は <code>A</code><code>B</code><code>C</code> だけからなる。</li> </ul> <h3>Input Format</h3> <p>入力は以䞋の圢匏で暙準入力から䞎えられる。</p> <pre> <var>S</var> </pre> <h3>Output Format</h3> <p>遺䌝子配列を <var>S</var> に䞀臎させられるならば <code>Yes</code> を、䞀臎させられないならば <code>No</code> を䞀行に出力せよ。</p> <h3>Sample Input 1</h3> <pre> ABC </pre> <h3>Sample Output 1</h3> <pre> Yes </pre> <p>遺䌝子配列ははじめから <code>ABC</code> である。</p> <h3>Sample Input 2</h3> <pre> AABCC </pre> <h3>Sample Output 2</h3> <pre> Yes </pre> <p><code>B</code> を遞んで操䜜を行うず <code>ABC</code> → <code>AABCC</code> ずなる。</p> <h3>Sample Input 3</h3> <pre> AABCABC </pre> <h3>Sample Output 3</h3> <pre> No </pre> <p>䟋えば、<code>C</code> を遞んで操䜜を行っおも <code>AABCC</code> → <code>AABCABC</code> ずはならない。すべおの <code>C</code> をそれぞれ <code>ABC</code> ぞ同時に眮き換えるので、実際は <code>AABCC</code> → <code>AABABCABC</code> ずなる。</p>
p00703
<h1> What is the Number in my Mind ? </h1> <p>Let us enjoy a number guess game. </p> <p>A number containing L digits is in my mind (where 4 &lt;= L &lt;= 10). You should guess what number it is. It is composed of any of the following ten digits:<br></p><pre> "0","1","2","3","4","5","6","7","8", and "9". </pre> <p></p> <p>No digits appear twice in the number. For example, when L = 4, "1234" is a legitimate candidate but "1123" is not (since "1" appears twice). </p> <p>The number may begin with "0", and a number "05678" should be distinct from a number "5678", for example. </p> <p>If you and your computer cannot see through my mind by telepathy, a group of <b>hints</b> will be needed in order for you to identify the number in my mind. A <b>hint</b> is a triple of numbers named <b>try</b>, <b>hit</b>, and <b>blow</b>. </p> <p>The <b>try</b> is a number containing L decimal digits. No digits appear twice in the <b>try</b>, and this number may also begin with "0". </p> <p>The <b>hit</b> value indicates the count of digits that the <b>try</b> and the number in my mind have in common, and that are exactly in the same position. </p> <p>The <b>blow</b> value indicates the count of digits that the <b>try</b> and the number in my mind have in common, but that are NOT in the same position. </p> <p>They are arranged in one line as follows.<br></p><pre> <b>try hit blow</b> </pre> <p></p> <p>For example, if L = 4 and the number in my mind is <b>9876</b>, then the following is an example of hint-set consisting of legitimate hints.<br></p><pre> <b>7360 0 2</b> <b>2507 0 1</b> <b>9713 1 1</b> <b>9678 2 2</b> </pre> <p> The above hint-set should be sufficient for you to guess the number and the answer should be <b>9876</b>.<br> <p></p> <p>In contrast, the following hint-set is not sufficient to guess the number.<br></p><pre> <b>7360 0 2</b> <b>9713 1 1</b> <b>9678 2 2</b> </pre> <p> No number is consistent with the following hint-set.<br><pre> <b>9678 2 2</b> <b>1234 2 2</b> </pre> <p> Answers for last two hint-sets should be <b>NO</b>.<br> <p></p> <p>Your job is to write a program identifying the numbers in my mind using given hint-sets. </p> <h2>Input</h2> <p>The input consists of multiple hint-sets as follows. Each of them corresponds to a number in my mind. </p><pre><i>&lt; HINT-SET<sub></sub></i><sub>1<i></i></sub><i> &gt;</i> <i>&lt; HINT-SET<sub></sub></i><sub>2<i></i></sub><i> &gt;</i> <i>. . .</i> <i>&lt; HINT-SET<sub>i</sub> &gt;</i> <i>. . .</i> <i>&lt; HINT-SET<sub>n</sub> &gt;</i> </pre> <p>A <i>&lt;HINT-SET<sub>i</sub> &gt;</i> is composed of one header line in the following format (<i>L</i> and <i>H</i> should be separated by a single space character.):<br></p><pre><i>L</i> <i>H</i> </pre> <p> and <i>H</i> lines of hints in the following format (1 &lt;= j &lt;= <i>H</i> ) :<br><pre><i>TRY</i><sub>1</sub> <i>HIT</i><sub>1</sub> <i>BLOW</i><sub>1</sub> <i>TRY</i><sub>2</sub> <i>HIT</i><sub>2</sub> <i>BLOW</i><sub>2</sub> <i>. . .</i> <i>TRY<sub>j</sub></i> <i>HIT<sub>j</sub></i> <i>BLOW<sub>j</sub></i> <i>. . .</i> <i>TRY<sub>H</sub></i> <i>HIT<sub>H</sub></i> <i>BLOW<sub>H</sub></i> </pre><p><i>L</i> indicates the number of digits of the number in my mind and <i>TRY<sub>j</sub></i> . <i>HIT<sub>j</sub></i> and <i>BLOW<sub>j</sub></i> indicate hit and blow values between the <i>TRY<sub>j</sub></i> and the number in my mind. (They are separated by a single space character.) <p>The end of the input is indicated by a header line with <i>L</i> = 0 and <i>H</i> = 0.<br></p> <h2>Output</h2> <p>For each hint-set, the answer should be printed, each in a separate line. If you can successfully identify the number for a given hint-set, the answer should be the number. If you cannot identify the number, the answer should be <b>NO</b>. </p> <h2>Sample Input</h2> <pre> 6 4 160348 0 4 913286 2 3 431289 3 1 671283 3 3 10 8 3827690415 2 8 0482691573 1 9 1924730586 3 7 1378490256 1 9 6297830541 1 9 4829531706 3 7 4621570983 1 9 9820147536 6 4 4 4 2713 0 3 1247 2 0 1230 1 1 1387 2 1 6 5 605743 0 4 593026 2 2 792456 1 2 143052 1 3 093614 3 3 5 2 12345 5 0 67890 0 5 0 0 </pre> <h2>Output for the Sample Input</h2> <pre> 637281 7820914536 3287 NO NO </pre>
p03206
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>In some other world, today is December <var>D</var>-th.</p> <p>Write a program that prints <code>Christmas</code> if <var>D = 25</var>, <code>Christmas Eve</code> if <var>D = 24</var>, <code>Christmas Eve Eve</code> if <var>D = 23</var> and <code>Christmas Eve Eve Eve</code> if <var>D = 22</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>22 \leq D \leq 25</var></li> <li><var>D</var> is an integer.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>D</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the specified string (case-sensitive).</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>25 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Christmas </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>22 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>Christmas Eve Eve Eve </pre> <p>Be sure to print spaces between the words.</p></section> </div> </span>
p04039
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Iroha is very particular about numbers. There are <var>K</var> digits that she dislikes: <var>D_1, D_2, ..., D_K</var>.</p> <p>She is shopping, and now paying at the cashier. Her total is <var>N</var> yen (the currency of Japan), thus she has to hand at least <var>N</var> yen to the cashier (and possibly receive the change).</p> <p>However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.</p> <p>Find the amount of money that she will hand to the cashier.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var> 1 ≩ N &lt; 10000</var></li> <li><var> 1 ≩ K &lt; 10</var></li> <li><var> 0 ≩ D_1 &lt; D_2 &lt; 
 &lt; D_K≩9</var></li> <li><var>\{D_1,D_2,...,D_K\} ≠ \{1,2,3,4,5,6,7,8,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>K</var> <var>D_1</var> <var>D_2</var> 
 <var>D_K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the amount of money that Iroha will hand to the cashier.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>1000 8 1 3 4 5 6 7 8 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2000 </pre> <p>She dislikes all digits except <var>0</var> and <var>2</var>.</p> <p>The smallest integer equal to or greater than <var>N=1000</var> whose decimal notation contains only <var>0</var> and <var>2</var>, is <var>2000</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>9999 1 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>9999 </pre></section> </div> </span>
p03656
<span class="lang-en"> <p>Score : <var>1700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are two rooted trees, each with <var>N</var> vertices. The vertices of each tree are numbered <var>1</var> through <var>N</var>. In the first tree, the parent of Vertex <var>i</var> is Vertex <var>A_i</var>. Here, <var>A_i=-1</var> if Vertex <var>i</var> is the root of the first tree. In the second tree, the parent of Vertex <var>i</var> is Vertex <var>B_i</var>. Here, <var>B_i=-1</var> if Vertex <var>i</var> is the root of the second tree.</p> <p>Snuke would like to construct an integer sequence of length <var>N</var>, <var>X_1</var> , <var>X_2</var> , <var>...</var> , <var>X_N</var>, that satisfies the following condition:</p> <ul> <li>For each vertex on each tree, let the indices of its descendants including itself be <var>a_1</var> , <var>a_2</var> , <var>...</var>, <var>a_k</var>. Then, <var>abs(X_{a_1} + X_{a_2} + ... + X_{a_k})=1</var> holds.</li> </ul> <p>Determine whether it is possible to construct such a sequence. If the answer is possible, find one such sequence.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 10^5</var></li> <li><var>1 \leq A_i \leq N</var>, if Vertex <var>i</var> is not the root in the first tree.</li> <li><var>A_i = -1</var>, if Vertex <var>i</var> is the root in the first tree.</li> <li><var>1 \leq B_i \leq N</var>, if Vertex <var>i</var> is not the root in the second tree.</li> <li><var>B_i = -1</var>, if Vertex <var>i</var> is the root in the second tree.</li> <li>Input corresponds to valid rooted trees.</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> <var>B_1</var> <var>B_2</var> <var>..</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If it is not possible to construct an integer sequence that satisfies the condition, print <code>IMPOSSIBLE</code>. If it is possible, print <code>POSSIBLE</code> in the first line. Then, in the second line, print <var>X_1</var> , <var>X_2</var> , <var>...</var> , <var>X_N</var>, an integer sequence that satisfies the condition.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 3 3 4 -1 4 4 4 1 -1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>POSSIBLE 1 -1 -1 3 -1 </pre> <p>For example, the indices of the descendants of Vertex <var>3</var> of the first tree including itself, is <var>3,1,2</var>. It can be seen that the sample output holds <var>abs(X_3+X_1+X_2)=abs((-1)+(1)+(-1))=abs(-1)=1</var>. Similarly, the condition is also satisfied for other vertices.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 -1 5 1 5 1 3 6 5 5 3 -1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>IMPOSSIBLE </pre> <p>In this case, constructing a sequence that satisfies the condition is <code>IMPOSSIBLE</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>8 2 7 1 2 2 1 -1 4 4 -1 4 7 4 4 2 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>POSSIBLE 1 2 -1 0 -1 1 0 -1 </pre></section> </div> </span>
p00979
<h2>Fast Forwarding</h2> <p> Mr. Anderson frequently rents video tapes of his favorite classic films. Watching the films so many times, he has learned the precise start times of his favorite scenes in all such films. He now wants to find how to wind the tape to watch his favorite scene as quickly as possible on his video player. </p> <p> When the <b><span>[play]</span></b> button is pressed, the film starts at the normal playback speed. The video player has two buttons to control the playback speed: The <b><span>[3x]</span></b> button triples the speed, while the <b><span>[1/3x]</span></b> button reduces the speed to one third. These speed control buttons, however, do not take effect on the instance they are pressed. Exactly one second after playback starts and every second thereafter, the states of these speed control buttons are checked. If the <b><span>[3x]</span></b> button is pressed on the timing of the check, the playback speed becomes three times the current speed. If the <b><span>[1/3x]</span></b> button is pressed, the playback speed becomes one third of the current speed, unless it is already the normal speed. </p> <p> For instance, assume that his favorite scene starts at 19 seconds from the start of the film. When the <b><span>[3x]</span></b> button is on at one second and at two seconds after the playback starts, and the <b><span>[1/3x]</span></b> button is on at three seconds and at five seconds after the start, the desired scene can be watched in the normal speed five seconds after starting the playback, as depicted in the following chart. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/ICPCAsia2019_fast_forwarding" width="600"/> </center> <p> Your task is to compute the shortest possible time period after the playback starts until the desired scene starts. The playback of the scene, of course, should be in the normal speed. </p> <h3>Input</h3> <p> The input consists of a single test case of the following format. </p> <pre> $t$ </pre> <p> The given single integer $t$ ($0 \leq t < 2^{50}$) is the start time of the target scene. </p> <h3>Output</h3> <p> Print an integer that is the minimum possible time in seconds before he can start watching the target scene in the normal speed. </p> <h3>Sample Input 1</h3> <pre> 19 </pre> <h3>Sample Output 1</h3> <pre> 5 </pre> <h3>Sample Input 2</h3> <pre> 13 </pre> <h3>Sample Output 2</h3> <pre> 5 </pre> <h3>Sample Input 3</h3> <pre> 123456789098765 </pre> <h3>Sample Output 3</h3> <pre> 85 </pre> <h3>Sample Input 4</h3> <pre> 51 </pre> <h3>Sample Output 4</h3> <pre> 11 </pre> <h3>Sample Input 5</h3> <pre> 0 </pre> <h3>Sample Output 5</h3> <pre> 0 </pre> <h3>Sample Input 6</h3> <pre> 3 </pre> <h3>Sample Output 6</h3> <pre> 3 </pre> <h3>Sample Input 7</h3> <pre> 4 </pre> <h3>Sample Output 7</h3> <pre> 2 </pre>
p02944
<span class="lang-en"> <p>Score : <var>1800</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>For a sequence <var>S</var> of positive integers and positive integers <var>k</var> and <var>l</var>, <var>S</var> is said to belong to <em>level</em> <var>(k,l)</var> when one of the following conditions is satisfied:</p> <ul> <li>The length of <var>S</var> is <var>1</var>, and its only element is <var>k</var>.</li> <li>There exist sequences <var>T_1,T_2,...,T_m</var> (<var>m \geq l</var>) belonging to level <var>(k-1,l)</var> such that the concatenation of <var>T_1,T_2,...,T_m</var> in this order coincides with <var>S</var>.</li> </ul> <p>Note that the second condition has no effect when <var>k=1</var>, that is, a sequence belongs to level <var>(1,l)</var> only if the first condition is satisfied.</p> <p>Given are a sequence of positive integers <var>A_1,A_2,...,A_N</var> and a positive integer <var>L</var>. Find the number of subsequences <var>A_i,A_{i+1},...,A_j</var> (<var>1 \leq i \leq j \leq N</var>) that satisfy the following condition:</p> <ul> <li>There exists a positive integer <var>K</var> such that the sequence <var>A_i,A_{i+1},...,A_j</var> belongs to level <var>(K,L)</var>.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 2 \times 10^5</var></li> <li><var>2 \leq L \leq N</var></li> <li><var>1 \leq A_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>L</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 number of subsequences <var>A_i,A_{i+1},...,A_j</var> (<var>1 \leq i \leq j \leq N</var>) that satisfy the condition.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>9 3 2 1 1 1 1 1 1 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>22 </pre> <p>For example, both of the sequences <var>(1,1,1)</var> and <var>(2)</var> belong to level <var>(2,3)</var>, so the sequence <var>(2,1,1,1,1,1,1)</var> belong to level <var>(3,3)</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>9 2 2 1 1 1 1 1 1 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>41 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>15 3 4 3 2 1 1 1 2 3 2 2 1 1 1 2 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>31 </pre></section> </div> </span>
p01391
<script src="./IMAGE/varmath.js" charset="UTF-8"></script> <h1><font color="#000">問題 D </font> 列の構成</h1> <h2>問題文</h2> <p><var>1</var> から <var>N</var> たでの盞異なる敎数が <var>N / 2</var> 個曞かれたカヌドがいく぀か䞎えられるので次の条件を満たすような長さ <var>N</var> の数列 <var>seq</var> を <var>1</var> ぀䜜っお出力しお欲しい</p> <ul> <li><var>seq</var> の各芁玠は <var>0</var> か <var>1</var> である</li> <li>すべおのカヌドに぀いお以䞋が成り立぀ カヌドに曞かれた数字を<var>card[1], ..., card[N/2]</var>ずするこのずきカヌドに曞かれた郚分の和: <var>seq[card[1]] + ... + seq[card[N/2]]</var> が <var>N / 8</var> 以䞊か぀ <var>3N / 8</var> 以䞋になっおいる</li> </ul> <p></p> <p>䟋えば<var>N = 8</var> でカヌドが <var>2</var> 枚枡されカヌドに曞かれおいる数字がそれぞれ <var>[1, 2, 7, 8]</var><var>[4, 5, 7, 8]</var> であったずするこのずき <var>seq=[0, 1, 0, 1, 0, 1, 0, 1]</var> や <var>seq=[0, 0, 0, 0, 1, 1, 1, 1]</var> ずおくず条件を満たすようにできおいる</p> <h2>入力圢匏</h2> 入力は次の圢匏で䞎えられる <pre><var>N</var> <var>K</var> <var>card<sub>1</sub>[1]</var> <var>card<sub>1</sub>[2]</var> ... <var>card<sub>1</sub>[N/2]</var> <var>card<sub>2</sub>[1]</var> <var>card<sub>2</sub>[2]</var> ... <var>card<sub>2</sub>[N/2]</var> ... <var>card<sub>K</sub>[1]</var> <var>card<sub>K</sub>[2]</var> ... <var>card<sub>K</sub>[N/2]</var> </pre> <p> <var>1</var> 行目においお <var>N</var> は構成するべき数列の長さ<var>K</var> はカヌドの枚数である 続く <var>K</var> 行には各カヌドの情報が䞎えられる<var>card<sub>i</sub>[1], ..., card<sub>i</sub>[N/2]</var> が <var>i</var> 番目のカヌドに曞かれおいる数字である </p> <h2>出力圢匏</h2> <p><var>seq</var> の <var>i</var> 番目の芁玠が <var>i</var> 文字目に察応するように数列 <var>seq</var> を <var>1</var> 行に出力せよ</p> <p>なおどの入力に察しおも解は必ず少なくずも <var>1</var> ぀は存圚する</p> <h2>制玄</h2> <ul> <li><var>8 &le; N &le; 1,000</var>, <var>1&le; K &le; N / 2</var></li> <li><var>N</var> は <var>8</var> の倍数</li> <li><var>1 &le; card<sub>i</sub>[1] &lt; card<sub>i</sub>[2] &lt; ... &lt; card<sub>i</sub>[N/2] &le; N</var></li> </ul> <h2>入出力䟋</h2> <h3>入力䟋 1</h3> <pre> 8 2 1 2 7 8 4 5 7 8 </pre> <h3>出力䟋 1</h3> <pre> 01010101 </pre> <h3>入力䟋 2</h3> <pre> 8 3 2 3 4 6 3 4 5 8 3 4 6 8 </pre> <h3>出力䟋 2</h3> <pre> 01110011 </pre>
p02417
<H1>Counting Characters</H1><br> <p> Write a program which counts and reports the number of each alphabetical letter. Ignore the case of characters. </p> <H2>Input</H2> <p> A sentence in English is given in several lines. </p> <H2>Output</H2> <p> Prints the number of alphabetical letters in the following format: </p> <pre> a : <i>The number of 'a'</i> b : <i>The number of 'b'</i> c : <i>The number of 'c'</i> . . z : <i>The number of 'z'</i> </pre> <h2>Constraints</h2> <ul> <li>The number of characters in the sentence &lt; 1200</li> </ul> <H2>Sample Input</H2> <pre> This is a pen. </pre> <H2>Sample Output</H2> <pre> a : 1 b : 0 c : 0 d : 0 e : 1 f : 0 g : 0 h : 1 i : 2 j : 0 k : 0 l : 0 m : 0 n : 1 o : 0 p : 1 q : 0 r : 0 s : 2 t : 1 u : 0 v : 0 w : 0 x : 0 y : 0 z : 0 </pre>
p02047
<h3>文字列の魔法</h3> <!-- begin ja only --> <p>魔法䜿いであるあなたは今日も魔法の修行に励んでいるあなたは今手元に英小文字からなる文字列 <i>X</i> を持っおいるあなたの今日の修行の課題はこの文字列を別の文字列 <i>Y</i> に倉化させるこずである</p> <p>あなたは文字列を倉化させる魔法を 4 皮類習埗しおいおそれらを奜きな順序で䜕回でも唱えるこずができるただし魔法を唱えるたびに魔法石ず呌ばれる特別な石を消費するあなたが習埗しおいる魔法は次の通りである</p> <ul> <li>魔法石を <i>A</i> 個消費する手元の文字列の奜きな䜍眮に奜きな英小文字 1 文字を远加する䟋えば元の文字列が bcbd であった堎合abcbd, bcebd, bcbdf などの文字列に倉化させるこずができる</li> <li>魔法石を <i>E</i> 個消費する手元の文字列の奜きな 1 文字を取り陀く䟋えば元の文字列が bcbd であった堎合cbd, bbd, bcd, bcb のいずれかに倉化させるこずができるなお元の文字列の長さが 0 である堎合この魔法を唱えるこずはできない</li> <li>魔法石を <i>S</i> 個消費する手元の文字列の奜きな 1 文字を別の奜きな英小文字 1 文字に眮き換える䟋えば元の文字列が bcbd であった堎合acbd や bebd などの文字列に倉化させるこずができるなお元の文字列の長さが 0 である堎合この魔法を唱えるこずはできない</li> <li>魔法石を <i>R</i> 個消費する手元の文字列の先頭の 1 文字を末尟に移動させる䟋えば元の文字列が bcbd であった堎合cbdb に倉化させるこずができるなお元の文字列の長さが 0 である堎合この魔法を唱えるこずはできない</li> </ul> <p>魔法石は高䟡なのであなたは魔法石の消費を最小限にしたいず考えおいる文字列 <i>X</i> を文字列 <i>Y</i> に倉化させるために必芁な魔法石の個数の最小倀を求めよ</p> <!-- end ja only --> <h3>Input</h3> <!-- begin ja only --> <p>入力は耇数のデヌタセットからなる各デヌタセットは以䞋の圢匏で衚される</p> <blockquote><i>X</i> <i>Y</i> <i>A</i> <i>E</i> <i>S</i> <i>R</i></blockquote> <p><i>X</i>, <i>Y</i> は英小文字のみからなる異なる文字列でありいずれも長さは <i>1</i> 以䞊 <i>100</i> 以䞋である<i>A</i>, <i>E</i>, <i>S</i>, <i>R</i> はいずれも <i>1</i> 以䞊 <i>10<sup>6</sup></i> 以䞋の敎数である</p> <p>入力の終わりは '#' 䞀぀のみからなる行で瀺される入力に含たれるデヌタセットの数は高々 50 である</p> <!-- end ja only --> <h3>Output</h3> <!-- begin ja only --> <p>各デヌタセットに぀いお文字列 <i>X</i> を文字列 <i>Y</i> に倉化させるために必芁な魔法石の個数の最小倀を1 行に出力せよ</p> <!-- end ja only --> <h3>Sample Input</h3><pre>typewriter periodicity 100010 100100 101000 110000 periodicity typewriter 100010 100100 101000 110000 periodicity typewriter 100010 100100 101000 1 domestic contest 100010 100100 101000 110000 # </pre><h3>Output for the Sample Input</h3><pre>823120 1001540 603217 502210 </pre>
p00580
<h1>座垭 (Seats) </h1> <!--  時間制限 : 5sec / メモリ制限 : 256MB --> <h2> 問題文</h2> <p> 2XXX 幎䞖界の囜は盎線状に䞊んでいた<var>N</var> 個の囜があり<var>1, 2, ..., N</var> の番号が付けられおいる<var>i = 1, 2, ..., N - 1</var> に察し囜 <var>i</var> ず囜 <var>i + 1</var> が互いに隣囜である </p> <p> この幎の囜際情報オリンピックでは囜 <var>i</var> からは <var>A_i</var> 人の遞手が参加する囜際情報オリンピックの技術委員のあなたは競技での座垭衚を䜜成する担圓である競技䌚堎が现長いため䞀列に䞊んだ <var>A_1 + A_2 + ... + A_N</var> 個の座垭に遞手たちを割り圓おるこずになった䞍正防止のため同じ囜の遞手や隣囜の遞手を隣り合う垭に割り圓おおはならない </p> <p> 遞手たちを座垭に割り圓おる方法は䜕通りあるだろうかこの数は非垞に倧きくなる可胜性があるのでそれを <var>10007</var> で割った䜙りを求めたい </p> <h2>制玄</h2> <ul> <li><var>1 ≩ N ≩ 100</var></li> <li><var>1 ≩ A_i ≩ 4</var> (<var>1 ≩ i ≩ N</var>)</li> </ul> <h2> 入力・出力</h2> <p> <b>入力</b><br> 入力は以䞋の圢匏で暙準入力から䞎えられる<br> <var>N</var><br> <var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var> </p> <p> <b>出力</b><br> 遞手たちを座垭に割り圓おる方法の数を <var>10007</var> で割った䜙りを <var>1</var> 行で出力せよ </p> <!-- <h2>小課題</h2> <p style="line-height: 200%; margin-left: 30px; margin-right: 30px;"> </p> <p style="line-height: 200%; margin-left: 30px; margin-right: 30px;"> <ol style="line-height: 200%; margin-left: 30px; margin-right: 30px;"> <li>(<var>6</var> 点) <var>N ≩ 5</var><var>A_i ≩ 2</var> (<var>1 ≩ i ≩ N</var>)</li> <li>(<var>14</var> 点) <var>N ≩ 10</var><var>A_i ≩ 3</var> (<var>1 ≩ i ≩ N</var>)</li> <li>(<var>80</var> 点) 远加の制玄はない</li> </ol> </p> --> <h2>入出力䟋</h2> <h3>入力䟋 1</h3> <pre> 4 2 1 1 1 </pre> <h3>出力䟋 1</h3> <pre> 4 </pre> <p> 囜 <var>1</var> から参加する <var>2</var> 人の遞手を <var>1</var> ず <var>1'</var>囜 <var>2</var> から参加する <var>1</var> 人の遞手を <var>2</var>囜 <var>3</var> から参加する <var>1</var> 人の遞手を <var>3</var>囜 <var>4</var> から参加する <var>1</var> 人の遞手を <var>4</var> で衚すこずにするず遞手たちを座垭に割り圓おる方法ずしおは以䞋の <var>4</var> 通りの䞊べ方が考えられる </p> <ul> <li><var>1</var>, <var>3</var>, <var>1'</var>, <var>4</var>, <var>2</var></li> <li><var>1'</var>, <var>3</var>, <var>1</var>, <var>4</var>, <var>2</var></li> <li><var>2</var>, <var>4</var>, <var>1</var>, <var>3</var>, <var>1'</var></li> <li><var>2</var>, <var>4</var>, <var>1'</var>, <var>3</var>, <var>1</var></li> </ul> <h3>入力䟋 2</h3> <pre> 5 1 2 3 2 1 </pre> <h3>出力䟋 2</h3> <pre> 0 </pre> <p> この入力䟋では条件を満たす座垭衚は存圚しない </p> <h3>入力䟋 3</h3> <pre> 6 1 2 3 3 2 1 </pre> <h3>出力䟋 2</h3> <pre> 4754 </pre> <p> この入力䟋では遞手たちを座垭に割り圓おる方法は <var>24768</var> 通りあるためそれを <var>10007</var> で割った䜙りである <var>4754</var> を出力する </p> <br/> <div class="source"> <p class="source"> <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="クリ゚むティブ・コモンズ・ラむセンス" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png"/></a> </p> <p class="source"> <a href="https://www.ioi-jp.org/joi/2018/2019-yo/index.html">情報オリンピック日本委員䌚䜜 『第 18 回日本情報オリンピック JOI 2018/2019 予遞競技課題』</a> </p> </div>
p00095
<H1>ワカサギ釣り倧䌚</H1> <p> 桧原湖でワカサギ釣り倧䌚が行われたした。䞀番倚くのワカサギを獲埗した人が優勝者です。 </p> <p> 参加者番号ず釣った匹数のリストを読み蟌み、優勝者の番号ず釣った匹数を出力するプログラムを䜜成しおください。優勝者が耇数いる堎合は、<!--最初の-->その䞭で参加者番号が最も小さい䞀人を出力しおください。 </p> <H2>入力</H2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>n</var> <var>a<sub>1</sub></var> <var>v<sub>1</sub></var> <var>a<sub>2</sub></var> <var>v<sub>2</sub></var> : <var>a<sub>n</sub></var> <var>v<sub>n</sub></var> </pre> <p> <var>n</var> (1 &le; <var>n</var> &le; 20) は参加者の数、<var>a<sub>i</sub></var> は参加者番号を衚す。参加者番号は 1 以䞊 <var>n</var> 以䞋の異なる敎数である。<var>v<sub>i</sub></var> ( 0 &le; <var>v<sub>i</sub></var> &le; 100) は参加者 <var>a<sub>i</sub></var> が獲埗した匹数である。 </p> <H2>出力</H2> <p> 優勝者の参加者番号ず釣った匹数を空癜区切りで行に出力せよ。 </p> <H2>入力䟋</H2> <pre> 6 1 14 2 25 3 42 4 11 5 40 6 37 </pre> <H2>出力䟋</H2> <pre> 3 42 </pre>
p02552
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given is an integer <var>x</var> that is greater than or equal to <var>0</var>, and less than or equal to <var>1</var>. Output <var>1</var> if <var>x</var> is equal to <var>0</var>, or <var>0</var> if <var>x</var> is equal to <var>1</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>0 \leq x \leq 1</var></li> <li><var>x</var> is an integer</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>x</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>1</var> if <var>x</var> is equal to <var>0</var>, or <var>0</var> if <var>x</var> is equal to <var>1</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>0 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 </pre></section> </div> </span>
p02102
<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 E: Tangled Cables</h1> <h2>Problem</h2> <p>ずある䌚瀟のネットワヌク䞊には$n$台のコンピュヌタず、それらを぀なぐ$m$本の通信ケヌブルがある。コンピュヌタは$0$から$n - 1$たでの識別子で区別され、通信ケヌブルもたた$0$から$m - 1$たでの識別子をも぀。</p> <p>珟圚この䌚瀟にある任意の異なる2台のコンピュヌタは、いく぀かの通信ケヌブルを介しお盞互に通信するこずができるが、通信経路がただ䞀぀に定たるずは限らない。</p> <p>このネットワヌクには、通信ケヌブルが倚すぎお絡たっおしたうずいう問題がある。そこであなたは、任意の通信に぀いお通信経路がただ䞀぀になるようにいく぀かの通信ケヌブルを取り陀くこずにした。</p> <p>通信ケヌブル$i$はコンピュヌタ$a_i$ず$b_i$を双方向に぀なぎ、その長さは$c_i$である。たた、あなたが通信ケヌブル$i$を取り陀く際にかかる劎力は$d_i$である。</p> <p>䜜業を始める前に、あなたは取り陀く通信ケヌブルの長さの和に察する、䜜業を終えるたでにかかる劎力の和の比を「おっくう感」ずし、最小のおっくう感を芋積もるこずにした。<br> ただし、䞀぀も取り陀けない堎合のおっくう感は$0$である。</p> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる。</p> <p> $n$ $m$<br/> $a_1$ $b_1$ $c_1$ $d_1$<br/> $a_2$ $b_2$ $c_2$ $d_2$<br/> ...<br/> $a_m$ $b_m$ $c_m$ $d_m$<br/> </p> <p>入力はすべお敎数で䞎えられる。<br> 1行目にはコンピュヌタの数$n$ず通信ケヌブルの数$m$が空癜区切りで䞎えられる。<br> 2行目以降の$m$行には、通信ケヌブルの情報が空癜区切りで䞎えられる。$i$番目の通信ケヌブルの情報は、通信ケヌブル$i$の情報を衚す。</p> <h2>Constraints</h2> <p>入力は以䞋の条件を満たす。</p> <ul> <li>$2 \leq n \leq 10^4$</li> <li>$n-1 \leq m \leq min(\frac{n \times (n - 1)}{2}, 10^4)$</li> <li>$0 \leq a_i, b_i \leq n - 1 (a_i ≠ b_i)$</li> <li>$1 \leq c_i \leq 10^6$</li> <li>$0 \leq d_i \leq 10^6$</li> </ul> <h2>Output</h2> <p>おっくう感の最小倀を実数で1行に出力する。ただし、$10^{-5}$を超える誀差を含んではならない。</p> <h2>Sample Input 1</h2> <pre> 4 5 0 2 22 13 0 3 15 25 1 2 3 3 1 3 28 5 2 3 5 22 </pre> <h2>Sample Output 1</h2> <pre> 0.36000 </pre> <p>通信ケヌブル$0$ず通信ケヌブル$3$を取り陀くず、おっくう感は$(\frac{13 + 5}{22 + 28}) = 0.36$ずなり、これがおっくう感の最小倀ずなる。</p> <h2>Sample Input 2</h2> <pre> 5 6 0 1 22 33 0 2 43 11 0 3 92 10 1 3 50 12 2 3 88 2 3 4 58 89 </pre> <h2>Sample Output 2</h2> <pre> 0.06667 </pre> <h2>Sample Input 3</h2> <pre> 2 1 0 1 1 1 </pre> <h2>Sample Output 3</h2> <pre> 0 </pre>
p01684
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script language="JavaScript" type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script> <h3>Problem Statement</h3> <p>Alice is a private teacher. One of her job is to prepare the learning materials for her student. Now, as part of the materials, she is drawing a Venn diagram between two sets $A$ and $B$. </p> <p>Venn diagram is a diagram which illustrates the relationships among one or more sets. For example, a Venn diagram between two sets $A$ and $B$ is drawn as illustrated below. The rectangle corresponds to the universal set $U$. The two circles in the rectangle correspond to two sets $A$ and $B$, respectively. The intersection of the two circles corresponds to the intersection of the two sets, i.e. $A \cap B$. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAG2013_venn_diagram" height="134" width="200" /><br/> Fig: Venn diagram between two sets </center> <br/> <p>Alice, the mathematics personified, came up with a special condition to make her Venn diagram more beautiful. Her condition is that the area of each part of her Venn diagram is equal to the number of elements in its corresponding set. In other words, one circle must have the area equal to $|A|$, the other circle must have the area equal to $|B|$, and their intersection must have the area equal to $|A \cap B|$. Here, $|X|$ denotes the number of elements in a set $X$. </p> <p>Alice already drew a rectangle, but has been having a trouble figuring out where to draw the rest, two circles, because she cannot even stand with a small error human would make. As an old friend of Alice's, your task is to help her by writing a program to determine the centers and radii of two circles so that they satisfy the above condition. </p> <h3>Input</h3> <p>The input is a sequence of datasets. The number of datasets is not more than $300$. </p> <p>Each dataset is formatted as follows. </p><blockquote>$U_W$ $U_H$ $|A|$ $|B|$ $|A \cap B|$</blockquote> <p>The first two integers $U_W$ and $U_H$ ($1 \le U_W, U_H \le 100$) denote the width and height of the rectangle which corresponds to the universal set $U$, respectively. The next three integers $|A|$, $|B|$ and $|A \cap B|$ ($1 \le |A|, |B| \le 10{,}000$ and $0 \le |A \cap B| \le \min\{|A|,|B|\}$) denote the numbers of elements of the set $A$, $B$ and $A \cap B$, respectively. The input is terminated by five zeroes. </p> <p>You may assume that, even if $U_W$ and $U_H$ would vary within $\pm 0.01$, it would not change whether you can draw two circles under the Alice's condition. </p> <h3>Output</h3> <p>For each dataset, output the centers and radii of the two circles that satisfy the Alice's condition as follows: </p><blockquote>$X_A$ $Y_A$ $R_A$ $X_B$ $Y_B$ $R_B$</blockquote> <p>$X_A$ and $Y_A$ are the coordinates of the center of the circle which corresponds to the set $A$. $R_A$ is the radius of the circle which corresponds to the set $A$. $X_B$, $Y_B$ and $R_B$ are the values for the set B. These values must be separated by a space. </p> <p>If it is impossible to satisfy the condition, output: </p><blockquote>impossible</blockquote> <p>The area of each part must not have an absolute error greater than $0.0001$. Also, the two circles must stay inside the rectangle with a margin of $0.0001$ for error, or more precisely, all of the following four conditions must be satisfied: </p><ul><li><p> $X_A - R_A \ge -0.0001$ </p></li><li><p> $X_A + R_A \le U_W + 0.0001$ </p></li><li><p> $Y_A - R_A \ge -0.0001$ </p></li><li><p> $Y_A + R_A \le U_H + 0.0001$ </p></li></ul> <p>The same conditions must hold for $X_B$, $Y_B$ and $R_B$. </p> <h3>Sample Input</h3> <pre>10 5 1 1 0 10 5 2 2 1 10 10 70 70 20 0 0 0 0 0</pre> <h3>Output for the Sample Input</h3> <pre>1 1 0.564189584 3 1 0.564189584 1 1 0.797884561 1.644647246 1 0.797884561 impossible</pre>
p00996
<h1>Problem G: Dice</h1> <p> サむコロ兄匟は䞉぀子であり䞀心同䜓、぀でひず぀ずも蚀っおもよい。䞉぀子であるため芋分けが぀かないほど䌌おいる。そんなサむコロ兄匟はA君のお気に入りのおもちゃだ。A君はい぀も぀セットでサむコロを転がしお遊んでいる。このようにA君が楜しく遊ぶおもちゃだが、実は倧きな秘密があった。圌らは実は生きおいお、話したり自由に動いたりできるのだ。子ども郚屋は <i>r</i > × <i> c </i> の倧きさのグリッドで衚すこずができ、ずおも倧きいものが散乱しおいる。 </p> <p> サむコロ兄匟は宀内を東西南北の方向ぞ進行方向に向かっお転がりながら移動する。その圢ゆえに斜め移動ができないのが、少し気の毒である。進行方向にずおも倧きいものがある堎合、サむコロは進行方向に進むこずができない。 サむコロ兄匟は぀でセットであるため、䞀床にひず぀のサむコロしか移動するこずができない。たた、サむコロたちはその堎で回転するなどずいう噚甚な胜力は持っおいない。 </p> <p> 圌らが話したり動いたりしおいる事実は人間には知られおはいけないずいうのが「おもちゃのルヌル」である。このルヌルを砎ったおもちゃはこの䞖から消滅しおしたう。A君が出かけおいるずきに動いたり話したりしおいるおもちゃたちだが、A君が垰宅しお子ども郚屋に入っおきたずきにもずの䜍眮に戻っおいなければならない。A君が垰宅した盎埌は緊急事態であり、A君が子ども郚屋にたどり着く前にあらゆるおもちゃは即座にもずの堎所ぞ戻らなければならない。 A君は床を芋䞋ろすかたちになるため、サむコロの堎所ず䞊を向いおいる数字が正しければ、移動したこずに気づくこずはない。たた、サむコロたちは芋分けが぀かないほど䌌おいるので、どの収玍堎所にどのサむコロが向かっおも支障はない。 </p> <p> そんなある日、A君のおもちゃ箱の䞭で最も優秀なプログラマヌであるあなたに、䞎えられたサむコロの䜍眮情報ず収玍堎所から最短䜕手でサむコロ達が収玍堎所に戻れるかを蚈算する任務が䞎えられた。 サむコロ兄匟を溺愛しおいるA君の手からサむコロ兄匟が消えおしたったら、A君は泣いおしたうので、ずおも重芁な任務である。 </p> <h2>Input</h2> <p> 入力は以䞋のフォヌマットで䞎えられる。 </p> <pre> <i>r</i> <i>c</i> <i>grid<sub>1</sub></i> . . . <i>grid<sub>r</sub></i> </pre> <p> <i>grid<sub>i</sub></i> は長さ <i>c </i> の文字列で、1から6たでの数字か"."か”x”か”o”からなる。<br> 数字は収玍堎所か぀、到着時のサむコロの䞊の倀を瀺しおいる。<br> “.”は普通の床を瀺しおいる。<br> “x”はずおもおおきなものを瀺しおいる。<br> “o”はサむコロを瀺しおいる。<br> </p> <p> 入力は以䞋の制玄を満たす<br> 1 &le; r,c &le; 20<br> </p> <p> 初期状態でのサむコロの向きは以䞋の図に埓う。<br> </p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ACPC2012Day2_img_dice_Dice1" height="300" witdh="300"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ACPC2012Day2_img_dice_Dice2" height="300" witdh="300"> <h2>Output</h2> <p> それぞれの入力に察する、各サむコロがすべお収玍できるたでの最短手数を求めよ。 </p> <h2>Sample Input 1</h2> <pre> 3 3 4o. 4o. 4o. </pre> <h2>Sample Output 1</h2> <pre>  </pre> <p> 各サむコロが西方向に移動すればよい。 </p> <h2>Sample Input 2</h2> <pre> 4 4 4o.. .o3. .o.. .5.. </pre> <h2>Sample Output2</h2> <pre> 3 </pre> <p> 1行目のにあるサむコロが西方向<br> 2行目のにあるサむコロが東方向<br> 3行目のにあるサむコロが南方向に移動すればよい。<br> </p> <h2>Sample Input 3</h2> <pre> 6 10 1xxxxxxxxx o.......o. xxxx.xxxx4 xoxx.xxxx. x....3xx.. x..xxxxx.. </pre> <h2>Sample Output 3</h2> <pre> 34 </pre>
p03343
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given an integer sequence <var>A</var> of length <var>N</var> and an integer <var>K</var>. You will perform the following operation on this sequence <var>Q</var> times:</p> <ul> <li>Choose a contiguous subsequence of length <var>K</var>, then remove the smallest element among the <var>K</var> elements contained in the chosen subsequence (if there are multiple such elements, choose one of them as you like).</li> </ul> <p>Let <var>X</var> and <var>Y</var> be the values of the largest and smallest element removed in the <var>Q</var> operations. You would like <var>X-Y</var> to be as small as possible. Find the smallest possible value of <var>X-Y</var> when the <var>Q</var> operations are performed optimally.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 2000</var></li> <li><var>1 \leq K \leq N</var></li> <li><var>1 \leq Q \leq N-K+1</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>K</var> <var>Q</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 smallest possible value of <var>X-Y</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 3 2 4 3 1 5 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>In the first operation, whichever contiguous subsequence of length <var>3</var> we choose, the minimum element in it is <var>1</var>. Thus, the first operation removes <var>A_3=1</var> and now we have <var>A=(4,3,5,2)</var>. In the second operation, it is optimal to choose <var>(A_2,A_3,A_4)=(3,5,2)</var> as the contiguous subsequence of length <var>3</var> and remove <var>A_4=2</var>. In this case, the largest element removed is <var>2</var>, and the smallest is <var>1</var>, so their difference is <var>2-1=1</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 1 6 1 1 2 3 5 8 13 21 34 55 </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>11 7 5 24979445 861648772 623690081 433933447 476190629 262703497 211047202 971407775 628894325 731963982 822804784 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>451211184 </pre></section> </div> </span>
p03713
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a bar of chocolate with a height of <var>H</var> blocks and a width of <var>W</var> blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle.</p> <p>Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize <var>S_{max}</var> - <var>S_{min}</var>, where <var>S_{max}</var> is the area (the number of blocks contained) of the largest piece, and <var>S_{min}</var> is the area of the smallest piece. Find the minimum possible value of <var>S_{max} - S_{min}</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 ≀ H, W ≀ 10^5</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>H</var> <var>W</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum possible value of <var>S_{max} - S_{min}</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>0 </pre> <p>In the division below, <var>S_{max} - S_{min} = 5 - 5 = 0</var>.</p> <div style="text-align: center;"> <img alt="2a9b2ef47b750c0b7ba3e865d4fb4203.png" src="https://atcoder.jp/img/arc074/2a9b2ef47b750c0b7ba3e865d4fb4203.png"> </img></div> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2 </pre> <p>In the division below, <var>S_{max} - S_{min} = 8 - 6 = 2</var>.</p> <div style="text-align: center;"> <img alt="a42aae7aaaadc4640ac5cdf88684d913.png" src="https://atcoder.jp/img/arc074/a42aae7aaaadc4640ac5cdf88684d913.png"> </img></div> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>4 </pre> <p>In the division below, <var>S_{max} - S_{min} = 10 - 6 = 4</var>.</p> <div style="text-align: center;"> <img alt="eb0ad0cb3185b7ae418e21c472ff7f26.png" src="https://atcoder.jp/img/arc074/eb0ad0cb3185b7ae418e21c472ff7f26.png"/> </div> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>100000 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>1 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 5</h3><pre>100000 100000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>50000 </pre></section> </div> </span>
p02801
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given is a lowercase English letter <var>C</var> that is not <code>z</code>. Print the letter that follows <var>C</var> in alphabetical order.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>C</var> is a lowercase English letter that is not <code>z</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>C</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the letter that follows <var>C</var> in alphabetical order.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>a </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>b </pre> <p><code>a</code> is followed by <code>b</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>y </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>z </pre> <p><code>y</code> is followed by <code>z</code>.</p></section> </div> </span>
p01000
<h1>Problem B: Independent Research</h1> <h2>Problem</h2> <!-- <p> 長期䌑暇の課題ずは、長期䌑暇を䜿っおこれたでの勉匷の埩習をさせる<del>こずを建お前に、蚈画倒れがいかにしお発生するかを生埒に䜓隓させる</del>ため、長期䌑暇に課される詊緎のこずである。 その䞭でも、自由研究ずは、長期䌑暇の課題の䞭でも最も過酷な課題である。 「自由研究」ず蚀う名に反しお匷制である堎合が倚く、研究しないずいう遞択肢は存圚しない。 絵、工䜜、生き物芳察など、様々な分野の課題があり、ずりあえず僕は、生き物芳察を自由研究のテヌマずした。 </p> --> <p> 僕は倏䌑みの自由研究のテヌマずしお、生き物芳察を遞択し、生き物芳察キットを賌入した。 </p> <p> この生き物は3次元グリッド状の空間を奜んで生息する。 各セルには最倧1匹たでしか入れない。 呚囲の環境に合わせ1日が経過するごずに誕生ず死滅を繰り返す。 <!--誕生ず死滅の条件は飌育箱によっお異なるらしいが、それはセルに隣接する生き物の数に䟝存する。--> 誕生ず死滅の条件は、セルに隣接する生き物の数に䟝存する。 ここで、あるセルに生き物が隣接するずは、あるセルず生き物が生息しおいるもう䞀぀のセルが面、蟺、たたは点を共有しおいるこずを蚀う。 誕生ず死滅のルヌルは次のようになる。 </p> <ul> <li> 生き物が生息しおいないセルにおいお、隣接する生き物の数が <var> a<sub>i</sub> </var>(1 &le;<var> i </var>&le;<var> M<sub>1</sub> </var>) 匹であるような <var> i </var>がある堎合、そのセルに生き物が誕生する。 </li> <li> 生き物が生息しおいるセルにおいお、隣接する生き物の数が <var> b<sub>j</sub> </var>(1 &le;<var> j </var>&le;<var> M<sub>2</sub> </var>) 匹であるような <var> j </var>がない堎合、そのセルの生き物は死滅する。 </li> </ul> <p> 今回賌入した飌育箱はセルの数が5*5*5である立方䜓の飌育箱だ。 この飌育箱ではこの生き物はどのような振る舞いをするのだろうか  ずおも楜しみである。 </p> <p> 〜数日埌〜 </p> <p> ずりあえず、飌育しおみたが   毎日芳察するなんお時間がかかるし、僕にはめんどくさくおやる気がおきない。 そうだ、コンピュヌタヌずプログラムを䜿っおシミュレヌトしよう。 </p> <h2>Input</h2> <p> 入力は耇数のデヌタセットからなる。 各デヌタセットは以䞋のフォヌマットで䞎えられる。 </p> <pre> <var>N</var> (<var>z</var> = 0 の飌育箱の状態) (空行) (<var>z</var> = 1 の飌育箱の状態) (空行) (<var>z</var> = 2 の飌育箱の状態) (空行) (<var>z</var> = 3 の飌育箱の状態) (空行) (<var>z</var> = 4 の飌育箱の状態) (空行) <var>M<sub>1</sub></var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var>   <var>a<sub>M<sub>1</sub></sub></var> <var>M<sub>2</sub></var> <var>b<sub>1</sub></var> <var>b<sub>2</sub></var>   <var>b<sub>M<sub>2</sub></sub></var> </pre> <p> 最初にシミュレヌトする日数<var> N </var>が䞎えられる。</br> </br> 次に飌育箱の初期状態の情報が䞎えられる。これは5぀の5*5の2次元グリッドで䞎えられる。</br> 各2次元グリッドは0ず1から成り立ち、1は生き物がいるこずを瀺し、0は䜕もいないこずを瀺す。</br> 䟋えば、<var> z </var> = 0のセルの状態の2次元グリッドの4行2列目の倀が1だった堎合、飌育箱の座暙(1, 3, 0)の䜍眮に生き物がいるこずを衚す。<br> </br> 次に、敎数<var> M<sub>1</sub> </var>が䞎えられ、そのあずに<var> M<sub>1</sub> </var>個の数字<var> a<sub>i</sub> </var>が䞎えられる。<br> 次に、敎数<var> M<sub>2</sub> </var>が䞎えられ、そのあずに<var> M<sub>2</sub> </var>個の数字<var> b<sub>j</sub> </var>が䞎えられる。<br> <br> 入力の終わりは<var> N </var>= 0で衚される。</br> </p> <h2>Constraints</h2> <p>入力は以䞋の条件を満たす。</p> <ul> <li>1 &le;<var> N </var> &le; 100</li> <!-- <li>1 &le;<var> x,y,z </var> &le; 5</li> <li>0 &le;<var> grid(x,y,z) </var> &le; 1</li> --> <li>0 &le;<var> M<sub>1</sub> </var>,<var> M<sub>2</sub> </var> &le; 27</li> <li>0 &le;<var> a<sub>i</sub> </var>,<var> b<sub>j</sub> </var> &le; 26 (1 &le;<var> i </var>&le;<var> M<sub>1</sub> </var>, 1 &le;<var> j </var>&le;<var> M<sub>2</sub> </var>)</li> <li>任意の<var> i </var>,<var> j </var>(1 &le;<var> i </var>&lt;<var> j </var>&le;<var> M<sub>1</sub> </var>) においお、<var> a<sub>i</sub> </var>&ne;<var> a<sub>j</sub> </var></li> <li>任意の<var> i </var>,<var> j </var>(1 &le;<var> i </var>&lt;<var> j </var>&le;<var> M<sub>2</sub> </var>) においお、<var> b<sub>i</sub> </var>&ne;<var> b<sub>j</sub> </var></li> </ul> <h2>Output</h2> <p> 各デヌタセットに察し、<var> N </var>日経過埌の状態を出力せよ。<br> 出力は以䞋のフォヌマットに埓う。 </p> <pre> Case (テストケヌスの番号): (<var>z</var> = 0 の飌育箱の状態) (空行) (<var>z</var> = 1 の飌育箱の状態) (空行) (<var>z</var> = 2 の飌育箱の状態) (空行) (<var>z</var> = 3 の飌育箱の状態) (空行) (<var>z</var> = 4 の飌育箱の状態) </pre> <p> 1行目にテストケヌス番号を出力し、次の行から<var> N </var>日経過埌の状態ずしお、5*5の2次元グリッドを5぀出力せよ。</br> 各テストケヌスの出力間には空行を出力しなさい。</br> </p> <h2>Sample Input</h2> <pre> 5 00000 01010 00000 00100 00000 00000 01010 00000 01010 00000 00000 00100 00000 01010 00000 00000 01010 00000 00100 00000 00000 00000 00100 00000 00000 1 2 2 3 4 4 01110 00100 00100 00100 01110 01110 10001 10000 10001 01110 11111 10001 11111 10000 10000 01110 10001 10000 10001 01110 00000 00000 00000 00000 00000 2 3 4 1 2 100 00100 01010 01110 10001 10001 01110 00100 00100 00100 01110 00000 00000 00000 00000 00000 11111 00010 00100 01000 11111 10001 10001 10001 10001 01110 5 1 3 5 7 9 5 0 2 4 6 8 0 </pre> <h2>Sample Output</h2> <pre> Case 1: 00000 00000 01010 01110 10101 00000 10001 00000 00000 00000 00000 00000 11111 10001 00000 00000 00000 00000 00000 01010 00000 00000 01110 00100 11111 Case 2: 00010 10110 00000 11000 10000 00001 00000 10101 00010 00100 10001 00000 00000 00000 00010 01110 10001 00000 00001 10000 00000 00000 00111 01001 01000 Case 3: 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 </pre>
p01450
<H1>Problem D: 僕の友達は小さい</H1> <p> 僕には、たくさんの友達がいる。どの友達も、ずおも小さい。<br> 僕は、よく友達ず䞀緒に出かける。䜕人かの友達をリュックに入れお、䞀緒に出かける。<br> 僕は毎朝、その日䞀緒に出かける友達を決める。空のリュックに、人ず぀友達を入れおいく。<br> 僕は、あたり力が匷くない。だから、同時に運べる友達の重さには限界がある。<br> 僕は、重さの限界を超えないように友達を入れおいく。どの順番で入れおいくかは気分次第。<br> 僕は、入れられる友達がただ残っおいる限り、入れるのを止めない。決しお止めない。<br> </p> <p>   ずころで、リュックに入った友達の組み合わせは、党郚で䜕パタヌンあるんだろう </p> <H2>Input</H2> <p> <i>N W</i><br> <i>w</i><sub>1</sub><br> <i>w</i><sub>2</sub><br> .<br> .<br> .<br> <i>w<sub>n</sub></i><br> </p> <p> 入力の行目には、敎数<i>N</i>1 &le; <i>N</i> &le; 200ず敎数<i>W</i>1 &le; <i>W</i> &le; 10,000が、この順に空癜区切りで曞かれおいる。敎数<i>N</i> は友達の数を、敎数<i>W</i> は同時に運べる重さの限界をあらわす。重さの合蚈が<i>W</i> より倧きいず運ぶこずはできない。 </p> <p> 続く<i>N</i> 行には、友達の重さをあらわす敎数が曞かれおいる。敎数<i>w<sub>i</sub></i>1 &le; <i>w<sub>i</sub></i> &le; 10,000が、<i>i</i> 番目の友達の重さをあらわす。 </p> <H2>Output</H2> <p> 最終的にリュックに入っおいる友達の組み合わせは䜕通り考えられるか。その総数を1,000,000,007 で割った䜙りを出力せよ。なお1,000,000,007 は玠数である。 </p> <p> 「誰もリュックに入っおいない」も通りずしお数えるこずに泚意せよ。 </p> <h2>Sample Input 1</h2> <pre> 4 8 1 2 7 9 </pre> <h2>Sample Output 1</h2> <pre> 2 </pre> <h2>Sample Input 2</h2> <pre> 4 25 20 15 20 15 </pre> <h2>Sample Output 2</h2> <pre> 4 </pre> <h2>Sample Input 3</h2> <pre> 6 37 5 9 13 18 26 33 </pre> <h2>Sample Output 3</h2> <pre> 6 </pre>
p03197
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is an apple tree that bears apples of <var>N</var> colors. The <var>N</var> colors of these apples are numbered <var>1</var> to <var>N</var>, and there are <var>a_i</var> apples of Color <var>i</var>.</p> <p>You and Lunlun the dachshund alternately perform the following operation (starting from you):</p> <ul> <li>Choose one or more apples from the tree and eat them. Here, the apples chosen at the same time must all have different colors.</li> </ul> <p>The one who eats the last apple from the tree will be declared winner. If both you and Lunlun play optimally, which will win?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 10^5</var></li> <li><var>1 \leq a_i \leq 10^9</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>a_1</var> <var>a_2</var> <var>:</var> <var>a_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If you will win, print <code>first</code>; if Lunlun will win, print <code>second</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>first </pre> <p>Let Color <var>1</var> be red, and Color <var>2</var> be blue. In this case, the tree bears one red apple and two blue apples.</p> <p>You should eat the red apple in your first turn. Lunlun is then forced to eat one of the blue apples, and you can win by eating the other in your next turn.</p> <p>Note that you are also allowed to eat two apples in your first turn, one red and one blue (not a winning move, though).</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 100000 30000 20000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>second </pre></section> </div> </span>
p01903
<link rel="stylesheet" href="css/description.css" type="text/css" /> <script language="JavaScript" type="text/javascript" src="js/varmath.js" charset="UTF-8"></script> <h2>F: 颚呂がオヌバヌフロヌ - Overflow of Furo -</h2> <h3>物語</h3> <p> 枩泉宿・パロは自慢の枩泉に党おの情熱を泚いでおり、颚呂のプロフェッショナルを集めおいる。 颚呂のプロたちは䞻に枩泉の配管を管理しおおり、耇数の源泉から1぀の倧济堎ぞず繋がる、耇雑に入り組んだ配管網を管理・調敎しおいる。 </p> <p> 配管網の管理・調敎業務もなかなかに倧倉なのだが、颚呂のプロたちはその合間を瞫っお、さらに倚くの湯を济槜ぞず䟛絊できるよう日々努力を積み重ねおいた。 結果、颚呂のプロたちは「1本だけ配管をオヌバヌフロヌさせるこずができる」ずいう荒技を習埗した。 すなわち、自由に配管1本を遞び、その配管の湯量の制限をなくすこずができるようになったのだ。 </p> <p>今たで最倧湯量を実珟する配管網の蚭定をあなたのプログラムに䟝存しおいた颚呂のプロたちは、この技術を䜿っおさらに济槜ぞの䟛絊湯量を増やすにはどうすればよいか、あなたに再びプログラムを曞くよう䟝頌しおきた。</p> <h3>問題</h3> <p> <var>1</var>぀の济槜、<var>K</var>個の源泉、<var>N</var>個の結合点を含む配管網がある。 配管網は<var>M</var>本の配管からなり、配管1぀1぀は流すこずのできる湯量の制限を持぀。 配管それぞれは湯を流す方向が決められおいないので、自由に決めお䜿っおよい。 <var>N</var>個の結合点では䜕本かの配管から流れおきた湯をそれ以倖の䜕本かの配管ぞず自由な配分で流すこずができる。 すべおの源泉、および济槜は䞀郚の配管の端点になっおおり、源泉からの湯量、および結合点での湯量を調敎するこずで源泉から济槜ぞず湯を䟛絊しおいる。 </p> <p> <var>M</var>個の配管のうち1本だけオヌバヌフロヌさせる、すなわち流せる湯量を無限に増やすこずで济槜に䟛絊できるようになる最倧湯量はいくらか。 ただし、最倧䟛絊湯量を無限に増やすこずができる堎合も考えられるが、その堎合は颚呂がオヌバヌフロヌしおしたうので、"overfuro"ず出力するこず。 </p> <h3>入力圢匏</h3> <p>入力は以䞋の圢匏で䞎えられる。</p> <pre> <var>K</var> <var>N</var> <var>M</var> <var>a_1</var> <var>b_1</var> <var>c_1</var> ... <var>a_M</var> <var>b_M</var> <var>c_M</var> </pre> <p> 入力は党お敎数からなる。 最初の行では源泉の数<var>K</var>、結合点の数<var>N</var>、配管の数<var>M</var>が䞎えられる。 続く<var>M</var>行のうち<var>i</var>行目には、<var>i</var>番目の配管の情報を衚す3぀の敎数 <var>a_i</var>, <var>b_i</var>, <var>c_i</var> が䞎えられる。 これは<var>i</var>番目の配管の䞡端点がそれぞれ<var>a_i</var>ず<var>b_i</var>であり、湯量の制限が<var>c_i</var>であるこずを瀺す。 ここで、配管の端点 <var>x</var> が<var>0</var>のずきは倧济堎、<var>1</var>から<var>K</var>たでのずきは <var>x</var> 番目の源泉、<var>K+1</var>から<var>K+N</var>たでのずきは <var>x &minus; K</var> 番目の結合点であるこずを衚す。 </p> <h3>制玄</h3> <ul> <li><var>1 &le; K</var></li> <li><var>0 &le; N</var></li> <li><var>N+K &le; 100</var></li> <li><var>1 &le; M &le; (N+K+1)(N+K)</var>/<var>2</var></li> <li><var>0 &le; a_i, b_i &le; K+N</var></li> <li><var>a_i &ne; b_i</var></li> <li><var>1 &le; c_i &le; 5{,}000</var></li> <li>同じ2端点を持぀配管は2぀以䞊存圚しないこずが保蚌される。</li> <li>䞎えられる配管網は、配管をオヌバヌフロヌさせるこずなく最䜎1以䞊の湯を源泉から济槜に䟛絊できるこずが保蚌される。</li> </ul> <h3>出力圢匏</h3> <p> 1本だけ配管をオヌバヌフロヌさせお源泉から济槜ぞの䟛絊湯量を最倧化するずきの最倧䟛絊湯量を1行に出力せよ。 ただし、最倧湯量を無限に増やせるずきは、"overfuro"ず1行に出力せよ。 </p> <h3>入力䟋1</h3> <pre> 2 2 4 1 3 4 2 4 2 0 3 3 4 0 5 </pre> <h3>出力䟋1</h3> <pre>8</pre> <h3>入力䟋2</h3> <pre> 2 3 7 1 0 8 2 0 9 3 0 3 0 4 5 5 0 2 1 3 2 2 4 9 </pre> <h3>出力䟋2</h3> <pre>overfuro</pre> <h3>入力䟋3</h3> <pre> 1 1 2 0 2 1 1 2 1 </pre> <h3>出力䟋3</h3> <pre>1</pre> <h3>入力䟋4</h3> <pre> 5 0 5 0 1 1 0 2 1 0 3 1 0 4 1 0 5 1 </pre> <h3>出力䟋4</h3> <pre>overfuro</pre>
p00611
<H1><font color="#000000">Problem G:</font> Building Water Ways</H1> <p> In ancient times, Romans constructed numerous water ways to supply water to cities and industrial sites. These water ways were amongst the greatest engineering feats of the ancient world. </p> <p> These water ways contributed to social infrastructures which improved people's quality of life. On the other hand, problems related to the water control and the water facilities are still interesting as a lot of games of water ways construction have been developed. </p> <p> Your task is to write a program which reads a map and computes the minimum possible cost of constructing water ways from sources to all the cities. </p> <br><br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_waterWay"> </center> <br><br> <p> As shown in Figure 1, the map is represented by <i>H</i> &times <i>W</i> grid cells, where each cell represents source, city, flatland, or obstacle. </p> <p> You can construct only one water way from a source, but there are no limitations on the length of that water way and it can provide water to any number of cities located on its path. You can not construct water ways on the obstacles. </p> <p> Your objective is to bring water to all the city and minimize the number of cells which represent water ways. In the Figure 1, water ways are constructed in 14 cells which is the minimum cost. </p> <p> The water ways must satisfy the following conditions: </p> <ul> <li>a water way cell is adjacent to at most 2 water way cells in four cardinal points.</li> <li>a source cell is adjacent to at most 1 water way cell in four cardinal points.</li> <li>there is no path from a source to other sources through water ways.</li> </ul> <H2>Input</H2> <p> The input consists of multiple datasets. Each dataset consists of: </p> <pre> <i>H W</i> <i>H</i> &times; <i>W</i> characters </pre> <p> The integers <i>H</i> and <i>W</i> are the numbers of rows and columns of the map. <i>H</i> &times; <i>W</i> characters denote the cells which contain: </p> <ul> <li>'<span>P</span>': source</li> <li>'<span>*</span>': city</li> <li>'<span>.</span>': flatland</li> <li>'<span>#</span>': obstacle</li> </ul> <p> The end of input is indicated by a line containing two zeros separated by a space. </p> <H2>Output</H2> <p> For each dataset, print the minimum cost to construct the water ways. </p> <H2>Constraints</H2> <ul> <li>Judge data contains at most 60 data sets.</li> <li>3 &le; <i>H</i>, <i>W</i> &le; 10</li> <li>1 &le; the number of sources, the number of cities &le; 8</li> <li>The map is surrounded by obstacles.</li> <li>Sources are not adjacent each other(on the left, right, top and bottom)</li> <li>There is a solution.</li> </ul> <H2>Sample Input</H2> <pre> 3 8 ######## #P....*# ######## 10 10 ########## #P.......# #..#*....# #..#*.#.*# #.....#*.# #*.......# #..##....# #...#.P..# #P......P# ########## 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 5 14 </pre>
p00241
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]} }); </script> <script type="text/javascript" async src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"> </script> <H1>四元数のかけ算</H1> <p> 耇玠数を拡匵したものに四元数ず呌ばれるものがありたす。物䜓の回転などを衚珟するのに䟿利なので、ロボットの腕の制埡などに䜿える䟿利な数です。四元数は、぀の実数 $x$、$y$、$z$、$w$ ず特別な数虚数を拡匵したもの$i$、$j$、$k$ を甚いお、$x + yi + zj + wk$ ず衚されたす。このような四元数の和は次のように定矩されたす。<br> <br> $(x_1 + y_1 i + z_1 j + w_1 k) + (x_2 + y_2 i + z_2 j + w_2 k) = (x_1 + x_2) + (y_1 + y_2)i + (z_1 + z_2)j + (w_1 + w_2)k$ </p> <!-- <p> (x<sub>1</sub> + y<sub>1</sub>i+z<sub>1</sub>j+w<sub>1</sub>k) + (x<sub>2</sub> + y<sub>2</sub>i + z<sub>2</sub>j + w<sub>2</sub>k) = (x<sub>1</sub> + x<sub>2</sub>) + (y<sub>1</sub> + y<sub>2</sub>)i + (z<sub>1</sub> + z<sub>2</sub>)j + (w<sub>1</sub> + w<sub>2</sub>)k </p> --> <p> 䞀方、1、$i$、$j$、$k$ の間の積は次のように䞎えたす。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_0241_1"> </center> <br> <p> この衚は、぀の特別な数 $A$ ず $B$ の積 $AB$ を衚しおいたす。䟋えば、 $i$ ず $j$ の積 $ij$ は $k$ であり、 $j$ ず $i$ の積 $ji$ は $-k$ であるこずを衚しおいたす。 </p> <p> 䞀般の四元数の積は、この関係を満たすように蚈算されたす。䟋えば、2぀の四元数、$1+2i+3j+4k$ ず$7+6i+7j+8k$ の積は次のように蚈算したす。 </p> <p> $(1+2i+3j+4k) \times (7+6i+7j+8k)=$<br> $7+6i+7j+8k$<br> $+14i+12i^2+14ij+16ik$<br> $+21j+18ji+21j^2+24jk$<br> $+28k+24ki+28kj+32k^2$ </p> <p> 䞊の衚を適甚するこずにより </p> <p> $= -58+16i+36j+32k$ </p> <p> ずなりたす。 </p> <p> 4぀の係数$x$、$y$、$z$、$w$ が敎数でか぀すべおがれロずはならない2぀の四元数 ($x_1+y_1 i+z_1 j+w_1 k$) ず($x_2+y_2 i+z_2 j+w_2 k$)を入力ずし、その積を($x_3+y_3 i+z_3 j+w_3 k$)ずする時の$x_3$、$y_3$、$z_3$、$w_3$ を出力するプログラムを䜜成しおください。 </p> <h2>入力</h2> <p> 耇数のデヌタセットが䞎えられたす。入力の終わりはれロひず぀の行で瀺されたす。各デヌタセットは以䞋の圢匏で䞎えられたす。<br> <br> $n$<br> $data_1$<br> $data_2$<br> :<br> $data_n$<br> </p> <p> 1行目に凊理を行う四元数の組の個数 $n$ ($ n \leq 10$) が䞎えられたす。続く $n$ 行に $i$ 番目の四元数の組の情報 $data_i$ が次の圢匏で䞎えられたす。<br> <br> $x_1$ $y_1$ $z_1$ $w_1$ $x_2$ $y_2$ $z_2$ $w_2$ </p> <p> 䞎えられる係数はすべお-1000 以䞊1000 以䞋ずしたす。デヌタセットの数は 50 を超えたせん。 </p> <h2>出力</h2> <p> デヌタセットごずに、䞎えられた四元数の組の積を出力したす。 </p> <h2>入力䟋</h2> <pre> 2 1 2 3 4 7 6 7 8 5 6 7 8 3 2 3 4 0 </pre> <h2>出力䟋</h2> <pre> -58 16 36 32 -50 32 28 48 </pre>
p03894
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You have <var>N</var> cups and <var>1</var> ball.</p> <p>The cups are arranged in a row, from left to right.</p> <p>You turned down all the cups, then inserted the ball into the leftmost cup.</p> <p>Then, you will perform the following <var>Q</var> operations:</p> <ul> <li>The <var>i</var>-th operation: swap the positions of the <var>A_i</var>-th and <var>B_i</var>-th cups from the left. If one of these cups contains the ball, the ball will also move.</li> </ul> <p>Since you are a magician, you can cast a magic described below:</p> <ul> <li>Magic: When the ball is contained in the <var>i</var>-th cup from the left, teleport the ball into the adjacent cup (that is, the <var>(i-1)</var>-th or <var>(i+1)</var>-th cup, if they exist).</li> </ul> <p>The magic can be cast before the first operation, between two operations, or after the last operation, but you are allowed to cast it at most once during the whole process.</p> <p>Find the number of cups with a possibility of containing the ball after all the operations and possibly casting the magic.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 10^5</var></li> <li><var>1 \leq Q \leq 10^5</var></li> <li><var>1 \leq A_i &lt; B_i \leq 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>Q</var> <var>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> : <var>A_Q</var> <var>B_Q</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of cups with a possibility of eventually containing the ball.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>10 3 1 3 2 4 4 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>4 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>20 3 1 7 8 20 1 19 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>5 </pre></section> </div> </span>
p02786
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Caracal is fighting with a monster.</p> <p>The <em>health</em> of the monster is <var>H</var>.</p> <p>Caracal can attack by choosing one monster. When a monster is attacked, depending on that monster's health, the following happens:</p> <ul> <li>If the monster's health is <var>1</var>, it drops to <var>0</var>.</li> <li>If the monster's health, <var>X</var>, is greater than <var>1</var>, that monster disappears. Then, two new monsters appear, each with the health of <var>\lfloor X/2 \rfloor</var>.</li> </ul> <p>(<var>\lfloor r \rfloor</var> denotes the greatest integer not exceeding <var>r</var>.)</p> <p>Caracal wins when the healths of all existing monsters become <var>0</var> or below.</p> <p>Find the minimum number of attacks Caracal needs to make before winning.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq H \leq 10^{12}</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>H</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Find the minimum number of attacks Caracal needs to make before winning.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>When Caracal attacks the initial monster, it disappears, and two monsters appear, each with the health of <var>1</var>.</p> <p>Then, Caracal can attack each of these new monsters once and win with a total of three attacks.</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>7 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1000000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1099511627775 </pre></section> </div> </span>
p02293
<H1>Parallel/Orthogonal</H1> <br/> <p> For given two lines <var>s1</var> and <var>s2</var>, print "2" if they are parallel, "1" if they are orthogonal, or "0" otherwise. </p> <p> <var>s1</var> crosses points <var>p0</var> and <var>p1</var>, and <var>s2</var> crosses points <var>p2</var> and <var>p3</var>. </p> <H2>Input</H2> <p> The entire input looks like: </p> <pre> <var>q</var> (the number of queries) 1st query 2nd query ... <var>q</var>th query </pre> <p> Each query consists of integer coordinates of the points <var>p0</var>, <var>p1</var>, <var>p2</var>, <var>p3</var> in the following format: </p> <pre> <var>x<sub>p0</sub></var> <var>y<sub>p0</sub></var> <var>x<sub>p1</sub></var> <var>y<sub>p1</sub></var> <var>x<sub>p2</sub></var> <var>y<sub>p2</sub></var> <var>x<sub>p3</sub></var> <var>y<sub>p3</sub></var> </pre> <H2>Output</H2> <p> For each query, print "2", "1" or "0". </p> <H2>Constraints</H2> <ul> <li> 1 &le; <var>q</var> &le; 1000 </li> <li> -10000 &le; <var>x<sub>p<sub>i</sub></sub></var>, <var>y<sub>p<sub>i</sub></sub></var> &le; 10000 </li> <li> <var>p0 &ne; p1</var> and <var>p2 &ne; p3</var>. </li> </ul> <H2>Sample Input 1</H2> <pre> 3 0 0 3 0 0 2 3 2 0 0 3 0 1 1 1 4 0 0 3 0 1 1 2 2 </pre> <H2>Sample Output 1</H2> <pre> 2 1 0 </pre> <br/>
p01846
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <h3>jfen</h3> <p><i>H &times; W</i> の盀面で遊ぶ䞀人甚ゲヌムがあるこのゲヌムはそれぞれのセルに 0 か 1 個のボヌルがあるのでそれを移動させるゲヌムであるあなたはこのゲヌムで遊んでいたがボヌルは非垞に䞞いためセルからセルぞ正確にボヌルを移動させるのが難しいこずに気づいたそこであなたは呜什通りにボヌルを動かしおくれるロボットを䜜るこずにしたここでセルを衚す衚蚘ずしお (<i>y, x</i>) ずいう衚蚘を甚いるこれは <i>y</i> 行目の <i>x</i> 列目のセルを衚す </p> <p>ロボットぞの呜什は 4 ぀の敎数 <i>a, b, c, d</i> で䞎えられるこれは (<i>a, b</i>) にあるボヌルを (<i>c, d</i>) に移動するこずを衚すこのずき(<i>a, b</i>) にボヌルが存圚し (<i>c, d</i>) にボヌルが存圚しないこずが保蚌される </p> <p>盀面の状態は"jfen" ず呌ばれる次の蚘法で衚される </p><pre>[1 行目のデヌタ]/[2 行目のデヌタ]/.../[H 行目のデヌタ] </pre> <p>この蚘法は盀面の各行を衚すデヌタをスラッシュ区切りで連結したものである各行のデヌタは文字列で衚され1 列目から<i>W</i>列目にあるセルの状態を巊から順に蚘述しおいるこの文字列は数字ず文字 'b' で衚され数字が衚す敎数は連続した空癜のセル数を'b' はボヌルが存圚するセルを衚しおいるここで各行のデヌタで敎数が連続しおはならないたた各行のデヌタに曞かれおいる敎数の総和ず 'b' の個数の和は必ず <i>W</i> になる </p> <p>䟋ずしお次のような盀面状態を考える空癜のセルを '.' で衚しボヌルが存圚するセルを 'b' で衚珟しおいるこの䟋の <i>i</i> 行目の巊から <i>j</i> 文字目は盀面の <i>i</i> 行目の <i>j</i> 列目のセルの状態を衚す </p> <pre> .... .b.b .... </pre> <p>䞊蚘の盀面を jfen で衚蚘するず次のようになる </p> <pre>4/1b1b/4</pre> <p>ロボットに珟圚の盀面の状態ず 1 ぀のボヌルを動かす呜什を䞎えた時にロボットがボヌルを動かした埌の盀面を出力するプログラムを䜜成せよこのずき出力する盀面は jfen 蚘法で出力せよ </p> <h3>Input</h3> <p>入力は耇数デヌタセットからなる 各デヌタセットは以䞋の圢匏からなる </p> <blockquote><i>S</i><br><i>a</i> <i>b</i> <i>c</i> <i>d</i></blockquote> <p>各デヌタセットは 2 行からなり最初の行には盀面の状態を衚す jfen 圢匏の文字列 <i>S</i> が䞎えられるここで 盀面のサむズは <i>2 &le; W, H &le; 9</i> を満たす続く行にはロボットぞの呜什が䞎えられるこれは (<i>a, b</i>) にあるボヌルを (<i>c, d</i>) に移動させる呜什を衚すたた入力の終わりは # で衚される </p> <h3>Output</h3> <p>出力は各デヌタセットごずに呜什を実行したあずの盀面の状態を jfen 蚘法で衚した文字列 1 行である出力行には他の文字があっおはならない </p> <h3>Sample Input</h3> <pre>b1/1b 1 1 1 2 b5/bbbbbb 2 4 1 4 b2b2b/7 1 4 2 4 #</pre> <h3>Output for Sample Input</h3> <pre> 1b/1b b2b2/bbb1bb b5b/3b3 </pre> <p> 1番目の入力の初期状態は次のようになる </p> <pre> b .b </pre> <p> (1,1) のボヌルを (1,2) に移動させるので呜什埌の盀面は次のようになる </p> <pre> .b .b </pre>
p02769
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a building with <var>n</var> rooms, numbered <var>1</var> to <var>n</var>.</p> <p>We can move from any room to any other room in the building.</p> <p>Let us call the following event a <strong>move</strong>: a person in some room <var>i</var> goes to another room <var>j~ (i \neq j)</var>.</p> <p>Initially, there was one person in each room in the building.</p> <p>After that, we know that there were exactly <var>k</var> moves happened up to now.</p> <p>We are interested in the number of people in each of the <var>n</var> rooms now. How many combinations of numbers of people in the <var>n</var> rooms are possible?</p> <p>Find the count modulo <var>(10^9 + 7)</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>3 \leq n \leq 2 \times 10^5</var></li> <li><var>2 \leq k \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>k</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of possible combinations of numbers of people in the <var>n</var> rooms now, modulo <var>(10^9 + 7)</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>10 </pre> <p>Let <var>c_1</var>, <var>c_2</var>, and <var>c_3</var> be the number of people in Room <var>1</var>, <var>2</var>, and <var>3</var> now, respectively. There are <var>10</var> possible combination of <var>(c_1, c_2, c_3)</var>:</p> <ul> <li><var>(0, 0, 3)</var></li> <li><var>(0, 1, 2)</var></li> <li><var>(0, 2, 1)</var></li> <li><var>(0, 3, 0)</var></li> <li><var>(1, 0, 2)</var></li> <li><var>(1, 1, 1)</var></li> <li><var>(1, 2, 0)</var></li> <li><var>(2, 0, 1)</var></li> <li><var>(2, 1, 0)</var></li> <li><var>(3, 0, 0)</var></li> </ul> <p>For example, <var>(c_1, c_2, c_3)</var> will be <var>(0, 1, 2)</var> if the person in Room <var>1</var> goes to Room <var>2</var> and then one of the persons in Room <var>2</var> goes to Room <var>3</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>200000 1000000000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>607923868 </pre> <p>Print the count modulo <var>(10^9 + 7)</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>15 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>22583772 </pre></section> </div> </span>
p00754
<h3><U>The Balance of the World</U></h3> <!-- end en only --> <div> <!-- please enclose each h3 level section with div --> <!-- begin en only --> <p> The world should be finely balanced. Positive vs. negative, light vs. shadow, and left vs. right brackets. Your mission is to write a program that judges whether a string is balanced with respect to brackets so that we can observe the balance of the world. </p> <!-- end en only --> <!-- begin en only --> <p> A string that will be given to the program may have two kinds of brackets, round (&ldquo;( )&rdquo;) and square (&ldquo;[ ]&rdquo;). A string is balanced if and only if the following conditions hold. <ul> <li>For every left round bracket (&ldquo;(&rdquo;), there is a corresponding right round bracket (&ldquo;)&rdquo;) in the following part of the string.</li> <li>For every left square bracket (&ldquo;[&rdquo;), there is a corresponding right square bracket (&ldquo;]&rdquo;) in the following part of the string.</li> <li>For every right bracket, there is a left bracket corresponding to it.</li> <li>Correspondences of brackets have to be one to one, that is, a single bracket never corresponds to two or more brackets.</li> <li>For every pair of corresponding left and right brackets, the substring between them is balanced.</li> </ul> </p> <!-- end en only --> </div> <h3>Input</h3> <div> <!-- begin en only --> <p> The input consists of one or more lines, each of which being a dataset. A dataset is a string that consists of English alphabets, space characters, and two kinds of brackets, round (&ldquo;( )&rdquo;) and square (&ldquo;[ ]&rdquo;), terminated by a period. You can assume that every line has 100 characters or less. The line formed by a single period indicates the end of the input, which is not a dataset. </p> <!-- end en only --> </div> <h3>Output</h3> <div> <!-- begin en only --> <p> For each dataset, output &ldquo;yes&rdquo; if the string is balanced, or &ldquo;no&rdquo; otherwise, in a line. There may not be any extra characters in the output. </p> <!-- end en only --> </div> <h3>Sample Input</h3> <div> <pre> So when I die (the [first] I will see in (heaven) is a score list). [ first in ] ( first out ). Half Moon tonight (At least it is better than no Moon at all]. A rope may form )( a trail in a maze. Help( I[m being held prisoner in a fortune cookie factory)]. ([ (([( [ ] ) ( ) (( ))] )) ]). . . </pre> </div> <h3>Output for the Sample Input</h3> <div> <pre> yes yes no no no yes yes </pre> </div>
p02339
<!--<h1>写像12盾 その9:ボヌルに区別あり・箱に区別なし・箱の䞭身は1぀以䞊</h1>--> <h1>Balls and Boxes 9</h1> <table border=""> <tr><th>Balls</th><th>Boxes</th><th>Any way</th><th>At most one ball</th><th>At least one ball</th></tr> <tr><th>Distinguishable</th><th>Distinguishable</th><td>1</td><td>2</td><td>3</td></tr> <tr><th>Indistinguishable</th><th>Distinguishable</th><td>4</td><td>5</td><td>6</td></tr> <tr><th>Distinguishable</th><th>Indistinguishable</th><td>7</td><td>8</td><td style="background-color:#aff">9</td></tr> <tr><th>Indistinguishable</th><th>Indistinguishable</th><td>10</td><td>11</td><td>12</td></tr> </table> <h2>Problem</h2> <p>You have $n$ balls and $k$ boxes. You want to put these balls into the boxes.</p> <p>Find the number of ways to put the balls under the following conditions:</p> <ul> <li>Each ball is distinguished from the other.</li> <li>Each box is <b>not</b> distinguished from the other.</li> <li>Each ball can go into only one box and no one remains outside of the boxes.</li> <li>Each box must contain at least one ball.</li> </ul> <p>Note that you must print this count modulo $10^9+7$.</p> <h2>Input</h2> <pre> $n$ $k$ </pre> <p>The first line will contain two integers $n$ and $k$.</p> <h2>Output</h2> <p>Print the number of ways modulo $10^9+7$ in a line.</p> <h2>Constraints</h2> <ul> <li>$1 \le n \le 1000$</li> <li>$1 \le k \le 1000$</li> </ul> <h2>Sample Input 1</h2> <pre> 4 3 </pre> <h2>Sample Output 1</h2> <pre> 6 </pre> <h2>Sample Input 2</h2> <pre> 10 5 </pre> <h2>Sample Output 2</h2> <pre> 42525 </pre> <h2>Sample Input 3</h2> <pre> 100 30 </pre> <h2>Sample Output 3</h2> <pre> 203169470 </pre>
p00304
<h1>新薬開発</h1> <p> 英䞖博士は日々研究を行い、新しい薬を開発しようずしおいたす。新薬を開発するためには、色々な物質を組み合わせお薬を䜜り詊隓を行い、良い薬を芋぀けなければなりたせん。様々な組み合わせを詊しおいくうちに、英䞖博士は物質の組み合わせが暹圢図で衚せるこずを突き止めたした。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2014_drugDevelopment"> </center> <br> <p> 右の図は、薬の調合を衚す暹圢図の䟋です。図の䞭で䞞く囲たれたものを物質ノヌド、䞉角で囲たれたものを遞択ノヌドず呌びたす。物質ノヌドは物質を衚したす。遞択ノヌドは、物質の遞択を衚すもので、それ自䜓は物質を衚したせん。遞択ノヌドには or 型&or;が付いたものず alt 型&hArr;が付いたものの皮類がありたす。たた ? が付いたノヌドは、それがオプションであるこずを衚したす。ただし、遞択ノヌドの子ノヌド䞋向きの枝の先にあるノヌドがオプションになるこずはありたせん。暹圢図に珟れる異なる物質ノヌドは、それぞれ別の物質を衚すものずしたす。 </p> <p> 薬の調合を行うずきは、暹圢図の䞀番䞊のノヌドからはじめお、順々にノヌドをたどっおいきながら以䞋のようにしおノヌドを遞んでいきたす。 </p> <ul> <li> たどり着いたノヌドがオプションでない物質ノヌドなら、それを必ず遞ぶ。</li> <li> オプションの物質ノヌドなら、それを遞ぶかどうかは任意。</li> <li> or 型の遞択ノヌドなら、その子から少なくずも䞀぀を遞ぶ。ただし、その遞択ノヌドがオプションなら、子を䞀぀も遞ばなくおもよい。</li> <li> alt 型の遞択ノヌドなら、その子から䞀぀だけを遞ぶ。ただし、その遞択ノヌドがオプションなら、子を遞ばなくおもよい。</li> </ul> <p> あるノヌドが遞ばれたずきだけ、そのノヌドから䞋に向かう枝をそれぞれたどっおいきたす。遞ばれなければ、それらをたどるこずはありたせん。 </p> <p> あなたは英䞖博士から、薬の物質の組み合わせを衚す暹圢図を受け取り、組み合わせの数が党郚で䜕通りあるか求めるよう指瀺されたした。暹圢図が䞎えられたずき、組み合わせの総数を出力するプログラムを䜜成しおください。 </p> <h2>入力</h2> <p> 入力は以䞋の圢匏で䞎えられる。 </p> <pre> <var>N</var> <var>node<sub>1</sub></var> <var>node<sub>2</sub></var> : <var>node<sub>N</sub></var> <var>s<sub>1</sub></var> <var>t<sub>1</sub></var> <var>s<sub>2</sub></var> <var>t<sub>2</sub></var> : <var>s</var><sub><var>N</var>-1</sub> <var>t</var><sub><var>N</var>-1</sub> </pre> <p> 行目にノヌドの数 <var>N</var> (1 &le; <var>N</var> &le; 1000) が䞎えられる。続く <var>N</var> 行に、<var>i</var> 番目のノヌドの情報 <var>node<sub>i</sub></var> が䞎えられる。番目のノヌドを暹圢図の䞀番䞊のノヌドずする。続く <var>N</var>-1 行に <var>s<sub>i</sub></var> 番目のノヌドからその子である <var>t<sub>i</sub></var> 番目のノヌド (1 &le; <var>s<sub>i</sub></var> &ne; <var>t<sub>i</sub></var> &le; <var>N</var>) ぞ向かう枝が䞎えられる。<var>t</var><sub>1</sub> から <var>t</var><sub><var>N</var>-1</sub> たでには、2 から <var>N</var> たでの数が䞀床だけ珟れる。<br> <br> ノヌドの情報は以䞋の圢匏である。 </p> <ul> <li> <span>E</span> &nbsp;&nbsp;&nbsp;&nbsp; オプションでない物質ノヌド。</li> <li> <span>E?</span> &nbsp;&nbsp;&nbsp;&nbsp; オプションである物質ノヌド。</li> <li> <var>type</var> &nbsp;&nbsp;&nbsp;&nbsp; オプションでない遞択ノヌド。<var>type</var> は <span>A</span> か <span>R</span> のいずれかで、<span>A</span> は alt型、<span>R</span> は or 型を衚す。</li> <li> <var>type</var><span>?</span> &nbsp;&nbsp;&nbsp;&nbsp; オプションである遞択ノヌド。<var>type</var> の圢匏は同䞊。</li> </ul> <p> 入力から埗られる暹圢図は、以䞋の条件を満たす。 </p> <ul> <li> 遞択ノヌドは぀以䞊の子ノヌドを持぀。</li> <li> 遞択ノヌドの子ノヌドはオプションでない。</li> <li> 暹圢図の䞀番䞊のノヌドはオプションでない。</li> <li> どのノヌドに぀いおも、子ノヌドの数は 10 を超えない。</li> </ul> <h2>出力</h2> <p> 䞎えられた暹圢図から埗られるすべおの組み合わせの総数を行に出力する。ただし、出力すべき倀は非垞に倧きくなりうるので、代わりに 1,000,000,007 で割った䜙りを出力する。 </p> <h2>入出力䟋</h2> <h2>入力䟋 </h2> <pre> 12 A E E E R? E? E? E E E E? E 1 2 1 3 1 4 2 5 4 6 4 7 5 8 5 9 7 10 7 11 11 12 </pre> <h2>出力䟋</h2> <pre> 11 </pre> <br> <h2>入力䟋</h2> <pre> 10 E R? E R E E A E E E 1 2 1 7 2 3 2 4 4 5 4 6 7 8 7 9 7 10 </pre> <h2> 出力䟋</h2> <pre> 24 </pre>
p03482
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a string <var>S</var> consisting of <code>0</code> and <code>1</code>. Find the maximum integer <var>K</var> not greater than <var>|S|</var> such that we can turn all the characters of <var>S</var> into <code>0</code> by repeating the following operation some number of times.</p> <ul> <li>Choose a contiguous segment <var>[l,r]</var> in <var>S</var> whose length is at least <var>K</var> (that is, <var>r-l+1\geq K</var> must be satisfied). For each integer <var>i</var> such that <var>l\leq i\leq r</var>, do the following: if <var>S_i</var> is <code>0</code>, replace it with <code>1</code>; if <var>S_i</var> is <code>1</code>, replace it with <code>0</code>.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1\leq |S|\leq 10^5</var></li> <li><var>S_i(1\leq i\leq N)</var> is either <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>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum integer <var>K</var> such that we can turn all the characters of <var>S</var> into <code>0</code> by repeating the operation some number of times.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>010 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>We can turn all the characters of <var>S</var> into <code>0</code> by the following operations:</p> <ul> <li>Perform the operation on the segment <var>S[1,3]</var> with length <var>3</var>. <var>S</var> is now <code>101</code>.</li> <li>Perform the operation on the segment <var>S[1,2]</var> with length <var>2</var>. <var>S</var> is now <code>011</code>.</li> <li>Perform the operation on the segment <var>S[2,3]</var> with length <var>2</var>. <var>S</var> is now <code>000</code>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>100000000 </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>00001111 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>4 </pre></section> </div> </span>
p01145
<!-- begin en only --> <h3><U> Princess' Japanese </U></h3> <!-- end en only --> <!-- begin ja only --> <h3><U> お姫様の日本語 </U></h3> <!-- end ja only --> <!-- begin en only --> <p> English text is not available in this practice contest. </p> <!-- end en only --> <!-- begin ja only --> <p> ある貧乏な囜のおおんばで勇敢なお姫様は日本語の勉匷をしおいる負けず嫌いな性栌も手䌝っおお姫様は日本語を流暢に話せるようになったが発音に少しばかり䞍自然なずころが残っおいるどうやら母音の無声化ずいう日本語固有の発音法が関係しおいるらしいお姫様は完璧な日本語話者を目指しおいるため䜕ずしおも自分の䞍自然な発音を矯正したいず思っおいるそこでお姫様は埓者であるあなたに察しお発音を矯正するためのプログラムを䜜成するように呜じたあなたの仕事は入力で䞎えられた日本語の語句に察しお無声化の生じる様子を瀺すプログラムを䜜成するこずである </p> <p> お姫様はひらがなカタカナ日垞的に䜿甚される挢字など日本語の衚蚘䜓系に぀いお十分に習埗しおいるため読み曞きに困るこずはめったにないずころがお姫様の囜にあるコンピュヌタでは日本語の入力に困難があるためプログラムにおいおは「ロヌマ字」ず呌ばれる英文字による衚蚘を甚いるこずに決めた </p> <p> たず日本語の発音䜓系に぀いお倧たかに説明する必芁があるだろう日本語では拍モヌラを単䜍ずしお発音がなされる拍は以䞋のいずれかの圢をしおいる </p> <ol> <li>母音</li> <li>子音+母音</li> <li>「y」「w」以倖の子音+「y」+母音</li> <li>促音「っ」</li> <li>撥音「ん」</li> <li>長音「ヌ」</li> </ol> <p> ここで母音は「a」「i」「u」「e」「o」のいずれか子音は「k」「s」「t」「n」「h」「m」「y」「r」「w」「g」「z」「d」「b」「p」のいずれかであるただし「y」の盎埌に珟れる母音は「a」「u」「o」に限られるたた「w」の盎埌に珟れる母音は「a」に限られる </p> <p> 促音は盎埌の拍の子音を重ねお衚蚘されるたずえば「se<b>k</b>ki」石噚は促音を含む語句のひず぀である促音は母音あるいは「n」「y」「w」の前には珟れないたれに促音が文節末に珟れるこずはあるがここではそのような䟋は考えない </p> <p> 撥音は単独の「n」によっお衚蚘されるただし母音たたは「y」の盎前に珟れるずきは䞊蚘の2.たたは3.ずの区別が぀かなくなるため「n」の盎埌にアポストロフィヌを぀ける以䞋にいく぀かの䟋をしめす </p> <blockquote> ta<b>n</b>go単語ni<b>n</b>gen人間ha<b>n</b>'ei繁栄 </blockquote> <p> 特に以䞋の違いには泚意されたい </p> <blockquote> zenin是認zen'in党員zennin前任 </blockquote> <p> 長音は単独で音節を構成するわけではないが垞に1拍を䜙分に䜿っおすなわち2拍で発音される日本語では長音ず短音の察立がありしかも長音ず短音の違いによっお語句が区別されるため長音ず短音の違いは重芁であるここでは長音は母音「a」「i」「u」のいずれかを重ねお衚蚘するこずずする以䞋にいく぀かの䟋をしめす </p> <blockquote> ra<b>a</b>menラヌメンbi<b>i</b>ruビヌルkyu<b>u</b>syu<b>u</b>九州kare<b>i</b>カレヌkyo<b>u</b>to京郜 </blockquote> <p> 撥音促音長音は先頭に珟れずたた連続しお珟れないたた撥音ず促音が互いに隣り合っお珟れるこずもない </p> <p> さお日本語では特定の条件䞋においお母音がきちんず発音されないこずがあるこれが母音の無声化ず呌ばれる珟象である母音が無声化される条件に関しおは諞説あるがここでは比范的簡単でか぀機械的適甚が可胜である以䞋のような堎合に぀いお考えるこずにするただし無声子音ずは「k」「s」「t」「h」「p」のこずであるたたこれらに「y」が続いたもの「ky」なども䟿宜的に無声子音ずみなす </p> <ol> <li>母音「i」「u」の短音に぀いおその母音が無声子音にはさたれたずきたたは無声子音の盎埌でしかも語句の末尟にあるずきこの芏則は母音「i」「u」の盎埌の拍が促音であっおも適甚される以䞋にいく぀かの䟋を瀺す</li> <blockquote> k<b>u</b>sa草hat<b>i</b>蜂k<b>i</b>k<b>u</b>菊k<b>i</b>tte切手k<b>i</b>pp<b>u</b>切笊suup<b>u</b>スヌプ </blockquote> <li>母音「a」「o」に぀いお同䞀の母音が無声子音ずずもに連続する2぀以䞊の拍で珟れたずきただしその連続する拍のうちで最埌のものに぀いおは陀倖される以䞋にいく぀かの䟋を瀺す促音および長音はひず぀の拍を構成するこずから連続郚分の先頭たたは途䞭に促音たたは長音があっおはならないずいう点には泚意するこず </li> <blockquote> h<b>a</b>ha母k<b>o</b>to琎h<b>a</b>k<b>a</b>ta博倚s<b>a</b>kana魚k<b>a</b>katoかかず </blockquote> </ol> <p> ただし䞊蚘に該圓する党郚の母音が無声化されるわけではないこれは耇数の母音が続けお無声化されるこずはないこずによる母音が無声化されるのは最初の母音である堎合たたは盎近の母音が無声化されなかった堎合でありたたそれらの堎合にかぎるたずえば「h<b>a</b>k<b>a</b>ta」に぀いおは最初の「a」は無声化されるが2番目の「a」は無声化されない同様にしお「k<b>i</b>pp<b>u</b>」に぀いおは語䞭の「i」は無声化されるが語尟の「u」は無声化されずに発音される </p> <p> 「hott<b>o</b>kouhii」ホットコヌヒヌはわかりにくい䟋のひず぀であるこれを拍に分解するず「ho-促音-to-ko-長音-hi-長音」のようになる最初の「o」は盎埌の拍が促音であるため䞊蚘の泚意曞きにあるように「無声子音 + o」が連続しおいるずはみなされないすなわち最初1拍目の「o」は無声化されないずころが次の「o」に぀いおは盎埌に長音があるものの「to」「ko」ずいうように「無声子音 + o」が連続しお珟れおいるしたがっお2番目3拍目の「o」は無声化されるたた語尟付近に無声子音「h」の埌に珟れる「i」が存圚するがこれは長音であるため無声化されない </p> <!-- end ja only --> <h3>Input</h3> <!-- begin ja only --> <p> 入力は耇数のデヌタセットからなるそれぞれのデヌタセットは100文字以䞋の1぀の語句が含たれる1行だけからなるそれぞれの語句には英小文字ずアポストロフィヌだけが含たれるたたそれぞれの語句は問題文䞭で説明した拍だけから構成されるが暙準日本語の語句であるずは限らない </p> <p> 入力の終わりは「#」のみが含たれる行によっお衚されるこれはデヌタセットに含たれない </p> <!-- end ja only --> <h3>Output</h3> <!-- begin ja only --> <p> それぞれのデヌタセットに぀いお䞎えられた語句を無声化される母音を括匧で囲んだうえで䞀行に出力しなさい </p> <!-- end ja only --> <h3>Sample Input</h3> <pre> kusa haha hakata kippu sasakisan sosonokasu hottokouhii i # </pre> <h3>Output for the Sample Input</h3> <pre> k(u)sa h(a)ha h(a)kata k(i)ppu s(a)sak(i)san s(o)sonokas(u) hott(o)kouhii i </pre>
p03178
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Find the number of integers between <var>1</var> and <var>K</var> (inclusive) satisfying the following condition, modulo <var>10^9 + 7</var>:</p> <ul> <li>The sum of the digits in base ten is a multiple of <var>D</var>.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>1 \leq K &lt; 10^{10000}</var></li> <li><var>1 \leq D \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>K</var> <var>D</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of integers satisfying the condition, modulo <var>10^9 + 7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>30 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>6 </pre> <p>Those six integers are: <var>4, 8, 13, 17, 22</var> and <var>26</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1000000009 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2 </pre> <p>Be sure to print the number modulo <var>10^9 + 7</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>98765432109876543210 58 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>635270834 </pre></section> </div> </span>
p01515
<!-- begin en only --> <h3><u>Equation </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> 論理挔算では倀は T ず F の2皮類だけを扱う </p> <p> &quot;-&quot;を単項挔算子入力が 1 ぀の挔算を衚す蚘号 &quot;*&quot;, &quot;+&quot;, &quot;-&gt;&quot; を 2 項挔算子入力が 2 ぀の挔算を衚す蚘号ずする &quot;-&quot; は論理吊定(NOT) &quot;*&quot; は論理積(AND) &quot;+&quot; は論理和(OR) &quot;-&gt;&quot; は論理包含(IMP)を衚す挔算子である これらの論理挔算の真理倀衚を䞋の衚に瀺す </p> <table> <thead><tr><th style="padding: .5em; background: #069; color: #fff">x</th><th style="padding: .5em; background: #069; color: #fff">y</th><th style="padding: .5em; background: #069; color: #fff">-x</th><th style="padding: .5em; background: #069; color: #fff">(x*y)</th><th style="padding: .5em; background: #069; color: #fff">(x+y)</th><th style="padding: .5em; background: #069; color: #fff">(x-&gt;y)</th></tr></thead> <tbody><tr><td style="padding: .5em; background: #0cf">T</td><td style="padding: .5em; background: #0cf">T</td><td style="padding: .5em; background: #0cf">F</td><td style="padding: .5em; background: #0cf">T</td><td style="padding: .5em; background: #0cf">T</td><td style="padding: .5em; background: #0cf">T</td></tr></tbody> <tbody><tr><td style="padding: .5em; background: #0cf">T</td><td style="padding: .5em; background: #0cf">F</td><td style="padding: .5em; background: #0cf">F</td><td style="padding: .5em; background: #0cf">F</td><td style="padding: .5em; background: #0cf">T</td><td style="padding: .5em; background: #0cf">F</td></tr></tbody> <tbody><tr><td style="padding: .5em; background: #0cf">F</td><td style="padding: .5em; background: #0cf">T</td><td style="padding: .5em; background: #0cf">T</td><td style="padding: .5em; background: #0cf">F</td><td style="padding: .5em; background: #0cf">T</td><td style="padding: .5em; background: #0cf">T</td></tr></tbody> <tbody><tr><td style="padding: .5em; background: #0cf">F</td><td style="padding: .5em; background: #0cf">F</td><td style="padding: .5em; background: #0cf">T</td><td style="padding: .5em; background: #0cf">F</td><td style="padding: .5em; background: #0cf">F</td><td style="padding: .5em; background: #0cf">T</td></tr></tbody> </table> <p> 論理匏は以䞋のいずれかの圢匏である X, Yは論理匏ずし 2 項挔算子は必ず括匧で囲むものずする </p> <ul> <li>定数: T, F</li> <li>倉数: a, b, c, d, e, f, g, h, i, j, k</li> <li>論理吊定: -X</li> <li>論理積: (X*Y)</li> <li>論理和: (X+Y)</li> <li>論理包含: (X-&gt;Y)</li> </ul> <p> 2 ぀の論理匏を等号 &quot;=&quot; で結合した等匏が䞎えられる 恒等匏ずは匏に珟れる倉数がどのような倀であっおも成立する等匏のこずである 䞎えられた等匏が恒等匏であるかを刀定するプログラムを䜜りたい </p> <!-- end ja only --> </div> <h3>Input</h3> <div> <!-- begin ja only --> <p> 入力は耇数の行で構成され各行は 1 ぀のデヌタセットである デヌタセットはT, F, a, b, c, d, e, f, g, h, i, j, k, (, ), =, -, +, *, &gt; から成る文字列であり 空癜など他の文字を含たない 1 行の文字数は 1000 文字以䞋ず仮定しおよい </p> <p> 1 ぀のデヌタセットは等匏ひず぀を含む 等匏の文法は次の BNF で䞎えられる すべおの等匏はこの構文芏則に埓う </p> <pre> &lt;equation&gt; ::= &lt;formula&gt; &quot;=&quot; &lt;formula&gt; &lt;formula&gt; ::= &quot;T&quot; | &quot;F&quot; | &quot;a&quot; | &quot;b&quot; | &quot;c&quot; | &quot;d&quot; | &quot;e&quot; | &quot;f&quot; | &quot;g&quot; | &quot;h&quot; | &quot;i&quot; | &quot;j&quot; | &quot;k&quot; | &quot;-&quot; &lt;formula&gt; | &quot;(&quot; &lt;formula&gt; &quot;*&quot; &lt;formula&gt; &quot;)&quot; | &quot;(&quot; &lt;formula&gt; &quot;+&quot; &lt;formula&gt; &quot;)&quot; | &quot;(&quot; &lt;formula&gt; &quot;-&gt;&quot; &lt;formula&gt; &quot;)&quot; </pre> <p> 入力の終わりは &quot;#&quot; だけからなる行で瀺されおおりこの行はデヌタセットではない </p> <!-- end ja only --> </div> <h3>Output</h3> <div> <!-- begin ja only --> <p> 各デヌタセットに぀いお等匏が恒等匏であれば“YES”を そうでなければ“NO”をそれぞれ1行に出力しなさい 出力には䜙分な文字を含んではならない </p> <!-- end ja only --> </div> <h3>Sample Input</h3> <div> <pre> -(a+b)=(-a*-b) (a->b)=(-a+b) ((a*T)+b)=(-c+(a*-b)) # </pre> <!-- begin ja only --> <!-- end ja only --> </div> <h3>Output for Sample Input</h3> <div> <pre> YES YES NO </pre> <!-- begin ja only --> <!-- end ja only --> </div>
p03528
<span class="lang-en"> <p>Score : <var>1000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Select any integer <var>N</var> between <var>1000</var> and <var>2000</var> (inclusive), and any integer <var>K</var> not less than <var>1</var>, then solve the problem below.</p> <h4>Problem</h4> <p>We have <var>N</var> sheets of paper. Write <var>K</var> integers on each of them to satisfy the following conditions:</p> <ul> <li>Each integer written must be between <var>1</var> and <var>N</var> (inclusive).</li> <li>The <var>K</var> integers written on the same sheet must be all different.</li> <li>Each of the integers between <var>1</var> and <var>N</var> must be written on exactly <var>K</var> sheets.</li> <li>For any two sheet, there is exactly one integer that appears on both.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>There is no input in this problem.</p> </section> </div> <div class="part"> <section> <h3>Output</h3><p>In the first line, print <var>N</var> and <var>K</var> separated by a space.</p> <p>In the subsequent <var>N</var> lines, print your solution. The <var>i</var>-th of these lines must contain the <var>K</var> integers written on the <var>i</var>-th sheet, with spaces in between.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Output</h3><pre>3 2 1 2 2 3 3 1 </pre> <p>This is an example of a solution for <var>N = 3</var> and <var>K = 2</var>.</p> <p>Note that this output will be judged as incorrect, since the constraint on <var>N</var> is not satisfied.</p></section> </div> </span>
p02010
<h1>Problem G. Additions</h1> <!-- Time Limit: 2 sec Memory Limit: 512 MB --> <p> You are given an integer $N$ and a string consisting of '<span>+</span>' and digits. You are asked to transform the string into a valid formula whose calculation result is smaller than or equal to $N$ by modifying some characters. Here, you replace one character with another character any number of times, and the converted string should still consist of '<span>+</span>' and digits. Note that leading zeros and unary positive are prohibited. </p> <p> For instance, '<span>0123+456</span>' is assumed as invalid because leading zero is prohibited. Similarly, '<span>+1+2</span>' and '<span>2++3</span>' are also invalid as they each contain a unary expression. On the other hand, '<span>12345</span>', '<span>0+1+2</span>' and '<span>1234+0+0</span>' are all valid. </p> <p> Your task is to find the minimum number of the replaced characters. If there is no way to make a valid formula smaller than or equal to $N$, output $-1$ instead of the number of the replaced characters. </p> <h2>Input</h2> <p> The input consists of a single test case in the following format. </p> <pre> $N$ $S$ </pre> <p> The first line contains an integer $N$, which is the upper limit of the formula ($1 \leq N \leq 10^9$). The second line contains a string $S$, which consists of '<span>+</span>' and digits and whose length is between $1$ and $1,000$, inclusive. Note that it is <b><i>not</i></b> guaranteed that initially $S$ is a valid formula. </p> <h2>Output</h2> <p> Output the minimized number of the replaced characters. If there is no way to replace, output $-1$ instead. </p> <h2>Examples</h2> <h2>Sample Input 1</h2> <pre> 100 +123 </pre> <h2>Output for Sample Input 1</h2> <pre> 2 </pre> <h2>Sample Input 2</h2> <pre> 10 +123 </pre> <h2>Output for Sample Input 2</h2> <pre> 4 </pre> <h2>Sample Input 3</h2> <pre> 1 +123 </pre> <h2>Output for Sample Input 3</h2> <pre> -1 </pre> <h2>Sample Input 4</h2> <pre> 10 ++1+ </pre> <h2>Output for Sample Input 4</h2> <pre> 2 </pre> <h2>Sample Input 5</h2> <pre> 2000 1234++7890 </pre> <h2>Output for Sample Input 5</h2> <pre> 2 </pre> <p> In the first example, you can modify the first two characters and make a formula '<span>1+23</span>', for instance. In the second example, you should make '<span>0+10</span>' or '<span>10+0</span>' by replacing all the characters. In the third example, you cannot make any valid formula less than or equal to $1$. </p>
p00187
<H1>投石おみくじ</H1> <p> 「自分の道は自分で切り開く」をモットヌに、ある神瀟が自分自身の手で運勢を決めるおみくじを䜜りたした。そのおみくじを匕く人にはたず6぀の石を投げおもらい、その投げた石の䞀぀目ず二぀目を結ぶ 線分、䞉぀目ず四぀目を結ぶ 線分、五぀目ず六぀目を結ぶ 線分の3本の線分の亀点を頂点ずする 䞉角圢の面積から運勢を決めるずいうものです。各運勢ず䞉角圢の面積ずの関係は以䞋のずおりです。 </p> <center> <table> <tr><th width="300">線分の亀点を頂点ずする䞉角圢の面積</th><th> 運勢</th></tr> <tr><td> 1,900,000以䞊 </td><td>倧吉 (dai-kichi)</td></tr> <tr><td> 1,000,000以䞊1,900,000未満 </td><td>䞭吉 (chu-kichi)</td></tr> <tr><td> 100,000以䞊1,000,000未満 </td><td> 吉 (kichi)</td></tr> <tr><td> 0より倧きく 100,000未満 </td><td> 小吉 (syo-kichi)</td></tr> <tr><td> 䞉角圢なし </td><td> 凶 (kyo)</td></tr> </table> </center> <br/> <p> しかし、䞉角圢の面積の倧きさの刀定は神䞻さんが手蚈算でやっおいるので正確ずはいえず、時間もかかっおしたいたす。そこで近所に䜏む優秀なプログラマであるあなたは、䞀刻でも早くプログラムを曞いお神䞻さんを助けおあげるこずにしたした。 </p> <p> 3 本の線分の情報を入力ずし、線分の亀点を頂点ずする 䞉角圢の面積から運勢を出力するプログラムを䜜成しおください。線分の情報は始点の座暙 (<var>x<sub>1</sub></var>, <var>y<sub>1</sub></var>) ず、終点の座暙 (<var>x<sub>2</sub></var>, <var>y<sub>2</sub></var>) が䞎えられ、始点ず終点の座暙は必ず異なるこずずしたす。たた、2 ぀以䞊の線分が同䞀盎線䞊にある堎合、亀点を持たない 2 ぀の線分がある堎合、3 ぀の線分が 1 点で亀わる堎合は、「䞉角圢なし」ずなりたす。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_stoning"> </center> <br/><br/> <H2>Input</H2> <p> 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりはれロ4぀の行で瀺されたす。 各デヌタセットは以䞋の圢匏で䞎えられたす。 </p> <pre> <var>line<sub>1</sub></var> <var>line<sub>2</sub></var> <var>line<sub>3</sub></var> </pre> <p> <var>i</var> 行目に <var>i</var> 番目の線分の情報が䞎えられたす。各線分の情報は以䞋の圢匏で䞎えられたす。 </p> <pre> <var>x<sub>1</sub></var> <var>y<sub>1</sub></var> <var>x<sub>2</sub></var> <var>y<sub>2</sub></var> </pre> <p> 線分の端点の座暙を衚す敎数 (<var>x<sub>1</sub></var>, <var>y<sub>1</sub></var>), (<var>x<sub>2</sub></var>, <var>y<sub>2</sub></var>) (-1000 &le; <var>x<sub>1</sub></var>, <var>y<sub>1</sub></var>, <var>x<sub>2</sub></var>, <var>y<sub>2</sub></var> &le; 1000 ) が空癜区切りで䞎えられたす。 </p> <H2>Output</H2> <p> デヌタセット毎に、おみくじの結果を行に出力したす。 </p> <H2>Sample Input</H2> <pre> -3 -2 9 6 3 -2 7 6 -1 0 5 0 2 2 -1 -1 0 1 2 1 -3 -1 3 1 0 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> syo-kichi kyo </pre>
p02440
<h1>Min-Max Element</h1> <p> Write a program which manipulates a sequence $A = \{a_0, a_1, ..., a_{n-1}\}$ by the following operations: </p> <ul> <li>min($b, e$): report the minimum element in $a_b, a_{b+1}, ..., a_{e-1}$</li> <li>max($b, e$): report the maximum element in $a_b, a_{b+1}, ..., a_{e-1}$</li> </ul> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> $n$ $a_0 \; a_1, ..., \; a_{n-1}$ $q$ $com_1 \; b_1 \; e_1$ $com_2 \; b_2 \; e_2$ : $com_{q} \; b_{q} \; e_{q}$ </pre> <p> In the first line, $n$ (the number of elements in $A$) is given. In the second line, $a_i$ (each element in $A$) are given. In the third line, the number of queries $q$ is given and each query is given in the following $q$ lines. $com_i$ denotes a type of query. <span>0</span> and <span>1</span> represents min($b, e$) and max($b, e$) respectively. </p> <h2>Output</h2> <p> For each query, print the minimum element or the maximum element in a line. </p> <h2>Constraints</h2> <ul> <li>$1 \leq n \leq 1,000$</li> <li>$-1,000,000,000 \leq a_i \leq 1,000,000,000$</li> <li>$1 \leq q \leq 1,000$</li> <li>$0 \leq b < e \leq n$</li> </ul> <h2>Sample Input 1</h2> <pre> 7 8 3 7 1 9 1 4 3 0 0 3 0 1 5 1 0 7 </pre> <h2>Sample Output 1</h2> <pre> 3 1 9 </pre>
p03601
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is making sugar water in a beaker. Initially, the beaker is empty. Snuke can perform the following four types of operations any number of times. He may choose not to perform some types of operations.</p> <ul> <li>Operation 1: Pour <var>100A</var> grams of water into the beaker.</li> <li>Operation 2: Pour <var>100B</var> grams of water into the beaker.</li> <li>Operation 3: Put <var>C</var> grams of sugar into the beaker.</li> <li>Operation 4: Put <var>D</var> grams of sugar into the beaker.</li> </ul> <p>In our experimental environment, <var>E</var> grams of sugar can dissolve into <var>100</var> grams of water.</p> <p>Snuke will make sugar water with the highest possible density.</p> <p>The beaker can contain at most <var>F</var> grams of substances (water and sugar combined), and there must not be any undissolved sugar in the beaker. Find the mass of the sugar water Snuke will make, and the mass of sugar dissolved in it. If there is more than one candidate, any of them will be accepted.</p> <p>We remind you that the sugar water that contains <var>a</var> grams of water and <var>b</var> grams of sugar is <var>\frac{100b}{a + b}</var> percent. Also, in this problem, pure water that does not contain any sugar is regarded as <var>0</var> percent density sugar water.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq A &lt; B \leq 30</var></li> <li><var>1 \leq C &lt; D \leq 30</var></li> <li><var>1 \leq E \leq 100</var></li> <li><var>100A \leq F \leq 3</var> <var>000</var></li> <li><var>A</var>, <var>B</var>, <var>C</var>, <var>D</var>, <var>E</var> and <var>F</var> are all integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Inputs</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>A</var> <var>B</var> <var>C</var> <var>D</var> <var>E</var> <var>F</var> </pre> </section> </div> <div class="part"> <section> <h3>Outputs</h3><p>Print two integers separated by a space. The first integer should be the mass of the desired sugar water, and the second should be the mass of the sugar dissolved in it.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>1 2 10 20 15 200 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>110 10 </pre> <p>In this environment, <var>15</var> grams of sugar can dissolve into <var>100</var> grams of water, and the beaker can contain at most <var>200</var> grams of substances.</p> <p>We can make <var>110</var> grams of sugar water by performing Operation 1 once and Operation 3 once. It is not possible to make sugar water with higher density. For example, the following sequences of operations are infeasible:</p> <ul> <li>If we perform Operation 1 once and Operation 4 once, there will be undissolved sugar in the beaker.</li> <li>If we perform Operation 2 once and Operation 3 three times, the mass of substances in the beaker will exceed <var>200</var> grams.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 2 1 2 100 1000 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>200 100 </pre> <p>There are other acceptable outputs, such as:</p> <pre>400 200 </pre> <p>However, the output below is not acceptable:</p> <pre>300 150 </pre> <p>This is because, in order to make <var>300</var> grams of sugar water containing <var>150</var> grams of sugar, we need to pour exactly <var>150</var> grams of water into the beaker, which is impossible.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>17 19 22 26 55 2802 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>2634 934 </pre></section> </div> </span>
p02913
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Given is a string <var>S</var> of length <var>N</var>.</p> <p>Find the maximum length of a non-empty string that occurs twice or more in <var>S</var> as contiguous substrings without overlapping.</p> <p>More formally, find the maximum positive integer <var>len</var> such that there exist integers <var>l_1</var> and <var>l_2</var> ( <var>1 \leq l_1, l_2 \leq N - len + 1</var> ) that satisfy the following:</p> <ul> <li> <p><var>l_1 + len \leq l_2</var></p> </li> <li> <p><var>S[l_1+i] = S[l_2+i] (i = 0, 1, ..., len - 1)</var></p> </li> </ul> <p>If there is no such integer <var>len</var>, print <var>0</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 5 \times 10^3</var></li> <li><var>|S| = N</var></li> <li><var>S</var> consists of lowercase English letters.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum length of a non-empty string that occurs twice or more in <var>S</var> as contiguous substrings without overlapping. If there is no such non-empty string, print <var>0</var> instead.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 ababa </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>The strings satisfying the conditions are: <code>a</code>, <code>b</code>, <code>ab</code>, and <code>ba</code>. The maximum length among them is <var>2</var>, which is the answer. Note that <code>aba</code> occurs twice in <var>S</var> as contiguous substrings, but there is no pair of integers <var>l_1</var> and <var>l_2</var> mentioned in the statement such that <var>l_1 + len \leq l_2</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 xy </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>No non-empty string satisfies the conditions.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>13 strangeorange </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>5 </pre></section> </div> </span>
p01796
<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 G JAG-channel II</h2> <p> JAG (Japan Alumni Group) is a group of $N$ members that devotes themselves to activation of the competitive programming world. The JAG staff members talk every day on the BBS called JAG-channel. There are several threads in JAG-channel and these are kept sorted by the time of their latest posts in descending order. </p> <p> One night, each of the $N$ members, identified by the first $N$ uppercase letters respectively, created a thread in JAG-channel. The next morning, each of the $N$ members posted in exactly $K$ different threads which had been created last night. Since they think speed is important, they viewed the threads from top to bottom and posted in the thread immediately whenever they came across an interesting thread. Each member viewed the threads in a different period of time, that is, there was no post of other members while he/she was submitting his/her $K$ posts. </p> <p> Your task is to estimate the order of the members with respect to the periods of time when members posted in the threads. Though you do not know the order of the threads created, you know the order of the posts of each member. Since the threads are always kept sorted, there may be invalid orders of the members such that some members cannot post in the top-to-bottom order of the threads due to the previous posts of other members. Find out the lexicographically smallest valid order of the members. </p> <h3>Input</h3> <p> The input consists of a single test case. The first line contains two integers separated by a space: $N$ $(4 \leq N \leq 16)$ and $K$ $(N - 3 \leq K \leq N - 1)$. Then $N$ lines of strings follow. Each of the $N$ lines consists of exactly $K$ distinct characters. The $j$-th character of the $i$-th line denotes the $j$-th thread in which the member denoted by the $i$-th uppercase letter posted. Each thread is represented by its creator (e.g. '<span>B</span>' represents the thread created by member B, the second member). </p> <p> It is guaranteed that at least one valid order exists. </p> <h3>Output</h3> <p> Display a string that consists of exactly $N$ characters in a line, which denotes the valid order in which the members posted in the threads. The $i$-th character of the output should represent the member who posted in the $i$-th period. In case there are multiple valid orders, output the lexicographically smallest one. </p> <h3>Sample Input 1</h3> <pre>7 4 DEFG FEDA EFGB BGEA AGFD DABC CADE</pre> <h3>Output for the Sample Input 1</h3> <pre>ABCDEFG</pre> <h3>Sample Input 2</h3> <pre>4 3 CDB DAC BAD ABC</pre> <h3>Output for the Sample Input 2</h3> <pre>DCBA</pre> <h3>Sample Input 3</h3> <pre>16 13 NDHPFJIBLMCGK CMDJKPOLGIHNE MOLBIEJFPHADN KPNAOHBLMCGEI FCMLBHDOANJPK NHIGLOAPKJDMC KMLBIPHDEOANJ IEGCMLBOAPKJD JNAOEDHBLMCGF OEDHPFIBLMGKC GMLBIFPHDNAEO ENHGOPKJDMCAF JKPAOBLGEIHNF HPKFGJEIBLCOM LBINEJDAGFKPH FGMOCADJENIBL</pre> <h3>Output for the Sample Input 3</h3> <pre>PONCAKJGIEDHMFBL</pre>
p00884
<H1><font color="#000">Problem A:</font> Membership Management</H1> <p> Peter is a senior manager of Agile Change Management (ACM) Inc., where each employee is a member of one or more task groups. Since ACM is agile, task groups are often reorganized and their members frequently change, so membership management is his constant headache. </p> <p> Peter updates the membership information whenever any changes occur: for instance, the following line written by him means that Carol and Alice are the members of the Design Group. </p> <pre> design:carol,alice. </pre> <p> The name preceding the colon is the group name and the names following it specify its members. </p> <p> A smaller task group may be included in a larger one. So, a group name can appear as a member of another group, for instance, as follows. </p> <pre> development:alice,bob,design,eve. </pre> <p> Simply unfolding the design above gives the following membership specification, which is equivalent to the original. </p> <pre> development:alice,bob,carol,alice,eve. </pre> <p> In this case, however, alice occurs twice. After removing one of the duplicates, we have the following more concise specification. </p> <pre> development:alice,bob,carol,eve. </pre> <p> Your mission in this problem is to write a program that, given group specifications, identifies group members. </p> <p> Note that Peter's specifications can include deeply nested groups. In the following, for instance, the group one contains a single member dave. </p> <pre> one:another. another:yetanother. yetanother:dave. </pre> <H2>Input</H2> <p> The input is a sequence of datasets, each being in the following format. </p> <p> <i>n</i><br> <i>group</i><sub>1</sub><span>:</span><i>member</i><sub>1,1</sub>,...,<i>member</i><sub>1,<i>m</i><sub>1</sub></sub><span>.</span><br> <span>.</span><br> <span>.</span><br> <span>.</span><br> <i>group</i><sub><i>i</i></sub><span>:</span><i>member</i><sub><i>i</i>,1</sub>,...,<i>member</i><sub><i>i</i>,<i>m</i><sub><i>i</i></sub></sub><span>.</span><br> <span>.</span><br> <span>.</span><br> <span>.</span><br> <i>group</i><sub><i>n</i></sub><span>:</span><i>member</i><sub><i>n</i>,1</sub>,...,<i>member</i><sub><i>n</i>,<i>m</i><sub><i>n</i></sub></sub><span>.</span><br> </p> <p> The first line contains n, which represents the number of groups and is a positive integer no more than 100. Each of the following n lines contains the membership information of a group: <i>group</i><sub><i>i</i></sub> (1 &le; <i>i</i> &le; <i>n</i>) is the name of the <i>i</i>-th task group and is followed by a colon (<span>:</span>) and then the list of its <i>m<sub>i</sub></i> member s that are delimited by a comma (<span>,</span>) and terminated by a period (<span>.</span>). </p> <p> Those group names are mutually different. Each <i>m<sub>i</sub></i> (1 &le; <i>i</i> &le; <i>n</i>) is between 1 and 10, inclusive. A <i>member</i> is another group name if it is one of <i>group</i><sub>1</sub>, <i>group</i><sub>2</sub>,..., or groupn. Otherwise it is an employee name. </p> <p> There are no circular (or recursive) definitions of group(s). You may assume that <i>m<sub>i</sub></i> member names of a group are mutually different. </p> <p> Each group or employee name is a non-empty character string of length between 1 and 15, inclusive, and consists of lowercase letters. </p> <p> The end of the input is indicated by a line containing a zero. </p> <H2>Output</H2> <p> For each dataset, output the number of employees included in the first group of the dataset, that is <i>group</i><sub>1</sub>, in a line. No extra characters should occur in the output. </p> <H2>Sample Input</H2> <pre> 2 development:alice,bob,design,eve. design:carol,alice. 3 one:another. another:yetanother. yetanother:dave. 3 friends:alice,bob,bestfriends,carol,fran,badcompany. bestfriends:eve,alice. badcompany:dave,carol. 5 a:b,c,d,e. b:c,d,e,f. c:d,e,f,g. d:e,f,g,h. e:f,g,h,i. 4 aa:bb. cc:dd,ee. ff:gg. bb:cc. 0 </pre> <H2>Output for the Sample Input</H2> <pre> 4 1 6 4 2 </pre>
p03251
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Our world is one-dimensional, and ruled by two empires called Empire A and Empire B.</p> <p>The capital of Empire A is located at coordinate <var>X</var>, and that of Empire B is located at coordinate <var>Y</var>.</p> <p>One day, Empire A becomes inclined to put the cities at coordinates <var>x_1, x_2, ..., x_N</var> under its control, and Empire B becomes inclined to put the cities at coordinates <var>y_1, y_2, ..., y_M</var> under its control.</p> <p>If there exists an integer <var>Z</var> that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out.</p> <ul> <li><var>X &lt; Z \leq Y</var></li> <li><var>x_1, x_2, ..., x_N &lt; Z</var></li> <li><var>y_1, y_2, ..., y_M \geq Z</var></li> </ul> <p>Determine if war will break out.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>1 \leq N, M \leq 100</var></li> <li><var>-100 \leq X &lt; Y \leq 100</var></li> <li><var>-100 \leq x_i, y_i \leq 100</var></li> <li><var>x_1, x_2, ..., x_N \neq X</var></li> <li><var>x_i</var> are all different.</li> <li><var>y_1, y_2, ..., y_M \neq Y</var></li> <li><var>y_i</var> are all different.</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</var> <var>Y</var> <var>x_1</var> <var>x_2</var> <var>...</var> <var>x_N</var> <var>y_1</var> <var>y_2</var> <var>...</var> <var>y_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If war will break out, print <code>War</code>; otherwise, print <code>No War</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 10 20 8 15 13 16 22 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>No War </pre> <p>The choice <var>Z = 16</var> satisfies all of the three conditions as follows, thus they will come to an agreement.</p> <ul> <li><var>X = 10 &lt; 16 \leq 20 = Y</var></li> <li><var>8, 15, 13 &lt; 16</var></li> <li><var>16, 22 \geq 16</var></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 2 -48 -1 -20 -35 -91 -23 -22 66 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>War </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>5 3 6 8 -10 3 1 5 -100 100 6 14 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>War </pre></section> </div> </span>
p03744
<span class="lang-en"> <p>Score : <var>900</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are in charge of controlling a dam. The dam can store at most <var>L</var> liters of water. Initially, the dam is empty. Some amount of water flows into the dam every morning, and any amount of water may be discharged every night, but this amount needs to be set so that no water overflows the dam the next morning.</p> <p>It is known that <var>v_i</var> liters of water at <var>t_i</var> degrees Celsius will flow into the dam on the morning of the <var>i</var>-th day. You are wondering about the maximum possible temperature of water in the dam at noon of each day, under the condition that there needs to be exactly <var>L</var> liters of water in the dam at that time. For each <var>i</var>, find the maximum possible temperature of water in the dam at noon of the <var>i</var>-th day. Here, consider each maximization separately, that is, the amount of water discharged for the maximization of the temperature on the <var>i</var>-th day, may be different from the amount of water discharged for the maximization of the temperature on the <var>j</var>-th day <var>(j≠i)</var>.</p> <p>Also, assume that the temperature of water is not affected by anything but new water that flows into the dam. That is, when <var>V_1</var> liters of water at <var>T_1</var> degrees Celsius and <var>V_2</var> liters of water at <var>T_2</var> degrees Celsius are mixed together, they will become <var>V_1+V_2</var> liters of water at <var>\frac{T_1*V_1+T_2*V_2}{V_1+V_2}</var> degrees Celsius, and the volume and temperature of water are not affected by any other factors.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≀ N ≀ 5*10^5</var></li> <li><var>1≀ L ≀ 10^9</var></li> <li><var>0≀ t_i ≀ 10^9(1≀i≀N)</var></li> <li><var>1≀ v_i ≀ L(1≀i≀N)</var></li> <li><var>v_1 = L</var></li> <li><var>L</var>, each <var>t_i</var> and <var>v_i</var> are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>L</var> <var>t_1</var> <var>v_1</var> <var>t_2</var> <var>v_2</var> <var>:</var> <var>t_N</var> <var>v_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>N</var> lines. The <var>i</var>-th line should contain the maximum temperature such that it is possible to store <var>L</var> liters of water at that temperature in the dam at noon of the <var>i</var>-th day.</p> <p>Each of these values is accepted if the absolute or relative error is at most <var>10^{-6}</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 10 10 10 20 5 4 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>10.0000000 15.0000000 13.2000000 </pre> <ul> <li> <p>On the first day, the temperature of water in the dam is always <var>10</var> degrees: the temperature of the only water that flows into the dam on the first day.</p> </li> <li> <p><var>10</var> liters of water at <var>15</var> degrees of Celsius can be stored on the second day, by discharging <var>5</var> liters of water on the night of the first day, and mix the remaining water with the water that flows into the dam on the second day.</p> </li> <li> <p><var>10</var> liters of water at <var>13.2</var> degrees of Celsius can be stored on the third day, by discharging <var>8</var> liters of water on the night of the first day, and mix the remaining water with the water that flows into the dam on the second and third days.</p> </li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 15 0 15 2 5 3 6 4 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0.0000000 0.6666667 1.8666667 2.9333333 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>4 15 1000000000 15 9 5 8 6 7 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1000000000.0000000 666666669.6666666 400000005.0000000 293333338.8666667 </pre> <p>Although the temperature of water may exceed <var>100</var> degrees Celsius, we assume that water does not vaporize.</p></section> </div> </span>
p01779
<h2>H : Typing Game / タむピングゲヌム</h2> <h3>物語</h3> <p> ここからはタむピング力を鍛える時間です皆さんは早く正確なタむピングをするこずができたすか Let’s enjoy Typing Game! </p> <h3>問題</h3> <p>タむピングゲヌムのゲヌムシステムずしおゞャッゞ偎が甚意したAIの出力に察しお察話的に動䜜するプログラムを䜜成せよ</p> <p>AIは <var>N</var> 個の文字列をタむプするゲヌムをプレむするAIは䜓力を持っおおりその初期倀は <var>H</var> であるAIは䜓力がある限り文字のタむプを行うシステムはAIがタむプすべき文字列を提瀺するシステムはAIがタむプした文字を受け取り次にタむプすべき文字ず䞀臎するか刀定するAIが文字列を<var>1</var>぀タむプし終えるずシステムは次の文字列を提瀺する</p> <p>たた各文字列にはミスタむプの蚱容回数が定められおいるAIのある文字列におけるミスタむプの回数が蚱容回数を超えおしたうずAIの䜓力が<var>1</var>枛りシステムは匷制的に次の文字列を提瀺するAIの䜓力が<var>0</var>になったらゲヌムオヌバヌずなる最埌の文字列においおタむプの成功たたはミスタむプ回数の超過が起こった埌でAIの䜓力が残っおいればゲヌムクリアずなる</p> <h3>入出力圢匏</h3> <p>たず入力が以䞋の圢匏で䞎えられる</p> <pre> <var>N</var> <var>H</var> <var>S_1</var> <var>T_1</var> ... <var>S_N</var> <var>T_N</var> </pre> <p>1行目に文字列の数 <var>N</var> ずAIの䜓力 <var>H</var> が空癜区切りで䞎えられる</p> <p>続く <var>N</var> 行には <var>i</var> 行目に <var>i</var> 番目の文字列 <var>S_i</var> ずその文字列に察するミスタむプの蚱容回数 <var>T_i</var> が空癜区切りで䞎えられる</p> <p> この入力は以䞋の制玄を満たす </p> <ul> <li> <var>1 &le; N &le; 100</var> </li> <li> <var>1 &le; H &le; 10</var> </li> <li> <var>1 &le; |S_i| &le; 15</var> </li> <li> <var>S_i</var> はアルファベット'a'-'z'たたは'A'-'Z'のみを含む </li> <li> <var>0 &le; T_i &le; 20</var> </li> </ul> <p>システムは文字列 <var>S_1</var> から文字列 <var>S_N</var> たで順番に凊理をする<var>i</var> 番目の文字列 <var>S_i</var> に぀いおAIが <var>j</var> 文字目たでタむプを成功させおいる堎合以䞋の凊理をする</p> <p>システムはAIに察しお<var>S_i</var> を出力するこのずき<var>S_i</var> の1文字目から <var>j</var> 文字目を&quot;_&quot; (アンダヌスコア) に眮き換えるシステムが間違った文字列を出力するずAIは動䜜を䞭断しWrong Answerずなるシステムが出力する文字列が S である堎合C/C++での出力䟋は以䞋のようになる</p> <pre>printf(&quot;? %s\n&quot;, S); fflush(stdout);</pre> <p>AIはシステムの出力を受け取るず</p> <pre><var>c</var></pre> <p>の圢匏で返答する<var>c</var> はAIがタむプした文字である<var>c</var> はアルファベット'a'-'z'からなるC/C++での返答の受け取り方の䟋は以䞋のようになる</p> <pre> char c[2]; scanf(&quot;%s&quot;, c); /* char c; scanf(&quot;%c&quot;, &amp;c); は空癜文字読み蟌みの仕様䞊の理由で非掚奚です */ </pre> <p>システムはAIの出力を受け取るずたずAIがタむプした文字ず <var>S_i</var> の <var>j+1</var> 文字目が䞀臎しおいるか刀定するこの刀定の際倧文字ず小文字は区別しないこずに泚意せよ䞀臎しおいるずきは<var>j+1</var> 文字目たでタむプに成功したずするここで <var>j+1</var> 文字目が <var>S_i</var> の最埌の文字だった堎合<var>S_i</var> のタむプに成功したずし <var>S_i</var> の凊理を終えるAIがタむプした文字ず <var>S_i</var> の <var>j+1</var> 文字目が䞀臎しおいなければ<var>S_i</var> に察するミスタむプ回数を1だけ増やすこのずき <var>T_i</var> を超えおいればAIの䜓力を<var>1</var>枛らし<var>S_i</var> の凊理を終える<var>S_i</var> の凊理を終えたずきAIの䜓力が<var>0</var>であればゲヌムオヌバヌずするゲヌムオヌバヌでなければ <var>i</var> が <var>N</var> のずきゲヌムクリアずしそうでなければ <var>S_{i+1}</var> の凊理に移る</p> <p>たたゲヌムオヌバヌの際には&quot;! Game Over&quot;をゲヌムクリアの際には&quot;! Game Clear [タむプ成功率]&quot;を出力せよタむプ成功率は (成功タむプ数) / (合蚈タむプ数) <var>&times; 100</var> で蚈算される倀を小数点以䞋第2䜍で切り捚おた倀ずする小数点以䞋第1䜍が0であっおも小数点以䞋第1䜍たで出力せよC/C++での出力䟋は以䞋のようになる</p> <pre>printf(&quot;! Game Over\n&quot;); fflush(stdout);</pre> <pre>printf(&quot;! Game Clear %.1lf\n&quot;, success_type_rate); fflush(stdout);</pre> <p><b>※printfの曞匏を"%.1lf"ずした堎合出力される浮動小数点数は小数点以䞋第2䜍が四捚五入されるこのためタむプ成功率を浮動小数点数ずしお蚈算し䞊蚘の手法で出力した堎合正しい出力結果が埗られないこずがあるこずに泚意せよ</b></p> <h3>入出力䟋1</h3> <pre> <table width="600" class="withborder"> <tr><th>システムの出力</th><th>システムぞの入力・AIの返答</th></tr> <tr><td></td><td> 2 5<br/>ICPC 2<br/>Tsurai 5 </td></tr> <tr><td>? ICPC</td><td></td></tr> <tr><td></td><td>i</td></tr> <tr><td>? _CPC</td><td></td></tr> <tr><td></td><td>g</td></tr> <tr><td>? _CPC</td><td></td></tr> <tr><td></td><td>p</td></tr> <tr><td>? _CPC</td><td></td></tr> <tr><td></td><td>c</td></tr> <tr><td>? __PC</td><td></td></tr> <tr><td></td><td>p</td></tr> <tr><td>? ___C</td><td></td></tr> <tr><td></td><td>c</td></tr> <tr><td>? Tsurai</td><td></td></tr> <tr><td></td><td>t</td></tr> <tr><td>? _surai</td><td></td></tr> <tr><td></td><td>s</td></tr> <tr><td>? __urai</td><td></td></tr> <tr><td></td><td>u</td></tr> <tr><td>? ___rai</td><td></td></tr> <tr><td></td><td>r</td></tr> <tr><td>? ____ai</td><td></td></tr> <tr><td></td><td>a</td></tr> <tr><td>? _____i</td><td></td></tr> <tr><td></td><td>i</td></tr> <tr><td>! Game Clear 83.3</td><td></td></tr> </table> </pre> <h3>入出力䟋2</h3> <pre> <table width="600" class="withborder"> <tr><th>システムの出力 </th><th>システムぞの入力・AIの返答</th></tr> <tr><td></td><td> 2 1<br/>ICPC 1<br/>Tsurai 1 </td></tr> <tr><td>? ICPC</td><td></td></tr> <tr><td></td><td>i</td></tr> <tr><td>? _CPC</td><td></td></tr> <tr><td></td><td>c</td></tr> <tr><td>? __PC</td><td></td></tr> <tr><td></td><td>o</td></tr> <tr><td>? __PC</td><td></td></tr> <tr><td></td><td>p</td></tr> <tr><td>? ___C</td><td></td></tr> <tr><td></td><td>d</td></tr> <tr><td>! Game Over</td><td></td></tr> <tr><td></td><td></td></tr> </table> </pre>
p02856
<span class="lang-en"> <p>Score: <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p><var>N</var> programmers are going to participate in the preliminary stage of DDCC 20XX. Due to the size of the venue, however, at most <var>9</var> contestants can participate in the finals.</p> <p>The preliminary stage consists of several rounds, which will take place as follows:</p> <ul> <li>All the <var>N</var> contestants will participate in the first round.</li> <li>When <var>X</var> contestants participate in some round, the number of contestants advancing to the next round will be decided as follows:<ul> <li>The organizer will choose two consecutive digits in the decimal notation of <var>X</var>, and replace them with the sum of these digits. The number resulted will be the number of contestants advancing to the next round.<br/> For example, when <var>X = 2378</var>, the number of contestants advancing to the next round will be <var>578</var> (if <var>2</var> and <var>3</var> are chosen), <var>2108</var> (if <var>3</var> and <var>7</var> are chosen), or <var>2315</var> (if <var>7</var> and <var>8</var> are chosen).<br/> When <var>X = 100</var>, the number of contestants advancing to the next round will be <var>10</var>, no matter which two digits are chosen.</li> </ul> </li> <li>The preliminary stage ends when <var>9</var> or fewer contestants remain.</li> </ul> <p>Ringo, the chief organizer, wants to hold as many rounds as possible. Find the maximum possible number of rounds in the preliminary stage.</p> <p>Since the number of contestants, <var>N</var>, can be enormous, it is given to you as two integer sequences <var>d_1, \ldots, d_M</var> and <var>c_1, \ldots, c_M</var>, which means the following: the decimal notation of <var>N</var> consists of <var>c_1 + c_2 + \ldots + c_M</var> digits, whose first <var>c_1</var> digits are all <var>d_1</var>, the following <var>c_2</var> digits are all <var>d_2</var>, <var>\ldots</var>, and the last <var>c_M</var> digits are all <var>d_M</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var>1 \leq M \leq 200000</var></li> <li><var>0 \leq d_i \leq 9</var></li> <li><var>d_1 \neq 0</var></li> <li><var>d_i \neq d_{i+1}</var></li> <li><var>c_i \geq 1</var></li> <li><var>2 \leq c_1 + \ldots + c_M \leq 10^{15}</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>M</var> <var>d_1</var> <var>c_1</var> <var>d_2</var> <var>c_2</var> <var>:</var> <var>d_M</var> <var>c_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print the maximum possible number of rounds in the preliminary stage.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 2 2 9 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>In this case, <var>N = 229</var> contestants will participate in the first round. One possible progression of the preliminary stage is as follows:</p> <ul> <li><var>229</var> contestants participate in Round <var>1</var>, <var>49</var> contestants participate in Round <var>2</var>, <var>13</var> contestants participate in Round <var>3</var>, and <var>4</var> contestants advance to the finals.</li> </ul> <p>Here, three rounds take place in the preliminary stage, which is the maximum possible number. </p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 1 1 0 8 7 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>9 </pre> <p>In this case, <var>1000000007</var> will participate in the first round. </p></section> </div> </span>
p01283
<H1><font color="#000">Problem A:</font> Strange String Manipulation</H1> <p> A linear congruential generator produces a series R(&sdot;) of pseudo-random numbers by the following for- mulas: </p> <!-- <p> R(0) = S , R(i) = (A · R(i − 1) + C) mod M (for i = 1, 2, . . .), </p> --> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_strangeString1"> </center> <p> where <i>S</i>, <i>A</i>, <i>C</i>, and <i>M</i> are all parameters. In this problem, 0 &le; <i>S</i>, <i>A</i>, <i>C</i> &le; 15 and <i>M</i> = 256. </p> <p> Now suppose we have some input string <i>I</i>(&sdot;), where each character in the string is an integer between 0 and (<i>M</i> - 1). Then, using the pseudo-random number series <i>R</i>(&sdot;), we obtain another string <i>O</i>(&sdot;) as the output by the following formula: </p> <!-- <p> O(i) = (I(i) + R(i)) mod M (for i = 1, 2, . . .), </p> --> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_strangeString2"> </center> <p> Your task is to write a program that shows the parameters <i>S</i>, <i>A</i>, and <i>C</i> such that the information entropy of the output string <i>O</i>(&sdot;) is minimized. Here, the information entropy <i>H</i> is given by the following formula: </p> <!-- #(x) #(x) log H=− N N x --> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_strangeString3"> </center> <p> where <i>N</i> is the length of the string and #(<i>x</i>) is the number of occurences of the alphabet <i>x</i>. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each dataset has the following format: </p> <p> <i>N</i><br> <i>I</i>(1) <i>I</i>(2) ... <i>I</i>(<i>N</i>)<br> </p> <p> <i>N</i> does not exceed 256. </p> <p> The last dataset is followed by a line containing one zero. This line is not a part of any dataset and should not be processed. </p> <H2>Output</H2> <p> For each dataset, print in a line the values of the three parameters <i>S</i>, <i>A</i>, and <i>C</i> separated by a single space. If more than one solution gives the same minimum entropy, choose the solution with the smallest <i>S</i>, <i>A</i>, and then <i>C</i>. </p> <H2>Sample Input</H2> <pre> 5 5 4 3 2 1 5 7 7 7 7 7 10 186 8 42 24 154 40 10 56 122 72 0 </pre> <H2>Output for the Sample Input</H2> <pre> 0 1 1 0 0 0 8 7 14 </pre>
p03314
<span class="lang-en"> <p>Score : <var>1100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given integers <var>N, K</var>, and an integer sequence <var>A</var> of length <var>M</var>.</p> <p>An integer sequence where each element is between <var>1</var> and <var>K</var> (inclusive) is said to be <em>colorful</em> when there exists a contiguous subsequence of length <var>K</var> of the sequence that contains one occurrence of each integer between <var>1</var> and <var>K</var> (inclusive).</p> <p>For every colorful integer sequence of length <var>N</var>, count the number of the contiguous subsequences of that sequence which coincide with <var>A</var>, then find the sum of all the counts. Here, the answer can be extremely large, so find the sum modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 25000</var></li> <li><var>1 \leq K \leq 400</var></li> <li><var>1 \leq M \leq N</var></li> <li><var>1 \leq A_i \leq 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>N</var> <var>K</var> <var>M</var> <var>A_1</var> <var>A_2</var> <var>...</var> <var>A_M</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>For every colorful integer sequence of length <var>N</var>, count the number of the contiguous subsequences of that sequence which coincide with <var>A</var>, then print the sum of all the counts modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 2 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>9 </pre> <p>There are six colorful sequences of length <var>3</var>: <var>(1,1,2)</var>, <var>(1,2,1)</var>, <var>(1,2,2)</var>, <var>(2,1,1)</var>, <var>(2,1,2)</var> and <var>(2,2,1)</var>. The numbers of the contiguous subsequences of these sequences that coincide with <var>A=(1)</var> are <var>2</var>, <var>2</var>, <var>1</var>, <var>2</var>, <var>1</var> and <var>1</var>, respectively. Thus, the answer is their sum, <var>9</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 2 2 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>12 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>7 4 5 1 2 3 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>17 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>5 4 3 1 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>0 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 5</h3><pre>10 3 5 1 1 2 3 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>1458 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 6</h3><pre>25000 400 4 3 7 31 127 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 6</h3><pre>923966268 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 7</h3><pre>9954 310 12 267 193 278 294 6 63 86 166 157 193 168 43 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 7</h3><pre>979180369 </pre></section> </div> </span>
p01329
<h1><font color="#000">Problem I:</font> 盗たれた宝石</h1> <p>パル王囜の囜宝である宝石が盗賊たちに盗たれた。 冒険者のあなたはその噂を聞き぀けお盗賊のアゞトに向かい、なんずか宝石を取り戻すこずが出来た。</p> <p>ずころが、宝石をパル王囜の城ぞ返しに出向いたずころ、城の守衛兵から、 「我が王はただあなたを完党に信甚しおいない。その宝石が本物かどうか怪しいし、そもそも宝石を取り戻したずいうのがり゜で、王の呜を狙う盗賊の仲間なのではないかず疑っおおられる。」 ずいわれた。</p> <p>あなたは、守衛兵から本圓に信頌できる人物かどうか詊すための詊緎を䞎えられた。詊緎の内容は、 「城の地䞋倉庫ぞ行き指定された堎所に宝石を眮け。そこに宝石が本物だったずきに反応する魔法陣が曞かれおある。ただしあなたが怪しい行動を起こさないようにするため、地䞋倉庫の入り口から指定された堎所に向かうたで、守衛兵が蚀った移動パタヌンをずっおはならない。」 ずいうものだった。</p> <p>䟋えば、䞋図にある地䞋倉庫の圢状、犁止パタヌンに察し、図にかかれおあるような移動パタヌンを取っおはならない。移動パタヌンの䞀郚(赀くハむラむトされおいる)が、犁止パタヌンの䞭に含たれるからである。(たた、この移動パタヌンの䞭の2,3番目の動き「&darr;&darr;」も犁止パタヌンの䞭に含たれる)</p> <center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_stolenjewel1"></center> <p>䞀方、 䞋図のような移動パタヌンは、移動パタヌンのどの郚分も犁止パタヌンの䞭に含たれないので蚱される。</p> <center><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_stolenjewel2"></center> <p>入力ずしお、地䞋倉庫の圢状、犁止パタヌンが䞎えられる。犁止パタヌンを取らずに、入り口から魔法陣ぞ移動するのに最䜎限必芁な移動回数を求めよ。</p> <h2>Input</h2> <p>入力には、地䞋倉庫の圢状ず犁止パタヌンが含たれる。</p> <p>地䞋倉庫の圢状は、以䞋のように衚される。 たず、二぀の敎数 N,M が䞎えられる。それぞれ地䞋倉庫の行数ず列数を意味する。(1 &le; N,M &le; 50)</p> <p>続いお、それぞれM個の文字からなる文字列がN行䞎えられる。 含たれる文字ずその意味は以䞋の通りである。</p> <center> <table> <tr><th>文字</th><th>意味</th></tr> <tr><td><span style="font-family: monospace">S</span></td><td>地䞋倉庫の入り口。䞀぀の地䞋倉庫に぀き必ず䞀぀だけ含たれる。</td></tr> <tr><td><span style="font-family: monospace">G</span></td><td>魔法陣。䞀぀の地䞋倉庫に぀き必ず䞀぀だけ含たれる。</td></tr> <tr><td><span style="font-family: monospace">.</span></td><td>通路。(犁止パタヌンをずらなければ)通るこずが出来る。</td></tr> <tr><td><span style="font-family: monospace">#</span></td><td>壁。壁の䞭を通るこずはできない。</td></tr> </table> </center> <p>次に、犁止パタヌンが䞎えられる。犁止パタヌンは以䞋のように衚される。 たず、䞀぀の敎数 P が䞎えられる。犁止パタヌンの数を意味する。(0 &le; P &le; 10)</p> <p>続いお、犁止パタヌンを意味する文字列がP行にわたっお䞎えられる。 犁止パタヌンに含たれる文字ずその意味は以䞋の通りである。</p> <center> <table> <tr><th>文字</th><th>意味</th></tr> <tr><td><span style="font-family: monospace">U</span></td><td>&uarr;の移動。</td></tr> <tr><td><span style="font-family: monospace">R</span></td><td>&rarr;の移動。</td></tr> <tr><td><span style="font-family: monospace">D</span></td><td>&darr;の移動。</td></tr> <tr><td><span style="font-family: monospace">L</span></td><td>&larr;の移動。</td></tr> </table> </center> <p>犁止パタヌンの長さは1以䞊、10以䞋である。 ある犁止パタヌンが、別の犁止パタヌンの郚分文字列ずなっおいるこずもある。たた、同䞀の犁止パタヌンが含たれるこずもある。 </p> <h2>Output</h2> <p>最䜎限必芁な移動回数を意味する敎数を出力せよ。魔法陣ぞ蟿り぀けない堎合は -1 を出力せよ。 </p> <h2>Notes on Test Cases</h2> <p> 䞊蚘入力圢匏で耇数のデヌタセットが䞎えられたす。各デヌタセットに察しお䞊蚘出力圢匏で出力を行うプログラムを䜜成しお䞋さい。 </p> <p> n, m が 0 のずき入力の終わりを瀺したす。 </p> <!-- <h2>Sample Input 1</h2> <pre> 7 6 ...... .####. .####. ...S#. ...##. ...##. .....G 3 LD DD LLL </pre> <h2>Output for Sample Input 1</h2> <pre>13 </pre> <h2>Sample Input 2</h2> <pre>7 8 S#...... .#.####. .#.#G.#. .#.##.#. .#....#. .######. ........ 8 DDDD DDDU UUUU UUUD RRRR RRRL LLLL LLLR </pre> <h2>Output for Sample Input 2</h2> <pre>60 </pre> <h2>Sample Input 3</h2> <pre>3 8 ######## S......G ######## 2 U D </pre> <h2>Output for Sample Input 3</h2> <pre>7 </pre> <h2>Sample Input 4</h2> <pre>6 10 .......... .S........ .......... .......... ........G. .......... 0 </pre> <h2>Output for Sample Input 4</h2> <pre>10 </pre> <h2>Sample Input 5</h2> <pre>6 7 ....... ...#... ...#.S. ...###. .G..... ....... 2 LL DD </pre> <h2>Output for Sample Input 5</h2> <pre>-1 </pre> --> <h2>Sample Input</h2> <pre> 7 6 ...... .####. .####. ...S#. ...##. ...##. .....G 3 LD DD LLL 7 8 S#...... .#.####. .#.#G.#. .#.##.#. .#....#. .######. ........ 8 DDDD DDDU UUUU UUUD RRRR RRRL LLLL LLLR 3 8 ######## S......G ######## 2 U D 6 10 .......... .S........ .......... .......... ........G. .......... 0 6 7 ....... ...#... ...#.S. ...###. .G..... ....... 2 LL DD 0 0 </pre> <h2>Output for Sample Input</h2> <pre> 13 60 7 10 -1 </pre>
p00168
<H1>芳音堂</H1> <p> 䞀郎君の家の裏山には芳音堂がありたす。この芳音堂たではふもずから 30 段の階段があり、䞀郎君は、毎日のように芳音堂たで遊びに行きたす。䞀郎君は階段を足で段たで䞊がるこずができたす。遊んでいるうちに階段の䞊り方の皮類段の飛ばし方の個数が非垞にたくさんあるこずに気が぀きたした。 </p> <p> そこで、䞀日に 10 皮類の䞊り方をし、すべおの䞊り方を詊そうず考えたした。しかし数孊を熟知しおいるあなたはそんなこずでは䞀郎君の寿呜が尜きおしたうこずを知っおいるはずです。 </p> <p> 䞀郎君の蚈画が実珟䞍可胜であるこずを䞀郎君に玍埗させるために、階段の段数 <var>n</var> を入力ずし、䞀日に 10 皮類の䞊り方をするずしお、䞀郎君がすべおの䞊り方を実行するのに芁する幎数を出力するプログラムを䜜成しおください。䞀幎は 365 日ずしお蚈算しおください。䞀日でも必芁なら䞀幎ずしたす。365 日なら 1 幎であり、366 日なら 2 幎ずなりたす。 </p> <H2>Input</H2> <p> 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりはれロひず぀の行で瀺されたす。 各デヌタセットずしお、段数を衚す぀の敎数 <var>n</var> (1 &le; <var>n</var> &le; 30) が行に䞎えられたす。 </p> <p> デヌタセットの数は 30 を超えたせん。 </p> <H2>Output</H2> <p> デヌタセットごずに䞀郎君がすべおの䞊り方を実行するのに必芁な幎数敎数を行に出力したす。 </p> <H2>Sample Input</H2> <pre> 1 10 20 25 0 </pre> <H2>Output for the Sample Input</H2> <pre> 1 1 34 701 </pre>
p02155
<h1>Problem G: First Kiss</h1> <h2>Problem</h2> <p> ビット君の通う男子校では昌䌑みにキッポヌゲヌムが行われおいる。<br> この孊校のキッポヌゲヌムは少し倉わっおいるこずで有名だ。<br> たず、$N$本のキッポヌを甚意する。$i$本目のキッポヌの長さは$a_i$である。<br> 先手ず埌手が亀互にキッポヌを食べる。<br> すごい長さのキッポヌを䞀気に食べるず喉に刺さっおしたうので、$1$以䞊$D$以䞋の奜きな長さだけ食べる。<br> 圌らは䞍噚甚なので、敎数長でのみキッポヌを食べるこずができる。<br> 最初にいずれかのキッポヌが食べ぀くされたずき、食べきった人の負けずなる。<br> 䞡者が最適に行動したずき、先手が勝぀なら"First"、埌手が勝぀なら"Second"を出力せよ。<br> </p> <h2>Input</h2> <p>入力は以䞋の圢匏で䞎えられる。</p> <pre> $N$ $D$ $a_1$ $a_2$ $...$ $a_N$ </pre> <p> 入力はすべお敎数で䞎えられる。 </p> <h2>Constraints</h2> <p>入力は以䞋の条件を満たす。</p> <ul> <li>$1 \le N \le 3\times 10^5$</li> <li>$1 \le D \le 10^9$</li> <li>$1 \le a_i \le 10^9$</li> </ul> <h2>Output</h2> <p> 䞡者が最適に行動したずき、どちらが勝぀か出力せよ。<br> 先手が勝぀なら"First"、埌手が勝぀なら"Second"を出力せよ。<br> </p> <h2>Sample Input 1</h2> <pre> 1 1 2 </pre> <h2>Sample Output 1</h2> <pre> First </pre> <h2>Sample Input 2</h2> <pre> 2 25 19 19 </pre> <h2>Sample Output 2</h2> <pre> Second </pre> <h2>Sample Input 3</h2> <pre> 3 5 10 8 4 </pre> <h2>Sample Output 3</h2> <pre> First </pre> <h2>Sample Input 4</h2> <pre> 4 10 3 8 5 2 </pre> <h2>Sample Output 4</h2> <pre> Second </pre>
p00492
<H1>むルミネヌション (Illumination) </H1> <h2> 問題</h2> <p> JOI 瀟の建物は図のような 1 蟺 1 メヌトルの正六角圢を぀なぎ合わせた圢であるクリスマスが近づいおいるのでJOI 瀟では建物の壁面をむルミネヌションで食り付けるこずにしたただし倖から芋えない郚分にむルミネヌションを斜すのは無駄なのでむルミネヌションは倖から建物の䞭を通らずに行くこずのできる壁面にのみ食り付けるこずにした </p> <center> <p><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_2012-yo-t5-fig01"><br>図: JOI 瀟の建物の配眮の䟋</p> </center> <p> 䞊の図は䞊空から芋た JOI 瀟の建物の配眮の䟋である正六角圢内の数字は座暙を衚す灰色の正六角圢は建物がある堎所を衚し癜色の正六角圢は建物がない堎所を衚すこの䟋では赀の実線で瀺される郚分がむルミネヌションで食り付けを行う壁面ずなりその壁面の長さの合蚈は 64 メヌトルずなる </p> <p> JOI 瀟の建物の配眮を衚す地図が䞎えられたずき食り付けを行う壁面の長さの合蚈を求めるプログラムを䜜成せよただし地図の倖偎は自由に行き来できるものずし隣接した建物の間は通るこずはできないものずする </p> <h2> 入力</h2> <p> 入力ファむルの 1 行目には 2 ぀の敎数 W, H (1 ≩ W ≩ 1001 ≩ H ≩ 100) が空癜を区切りずしお曞かれおいる続く H 行には JOI 瀟の建物の配眮が曞かれおいるi + 1 行目 (1 ≩ i ≩ H) には W 個の敎数が空癜を区切りずしお曞かれおおりj 個目 (1 ≩ j ≩ W) の敎数は座暙 (j, i) の正六角圢に建物がある時は 1 でありない時は 0 であるたた䞎えられる入力デヌタには建物が必ず 1 ぀以䞊ある </p> <p> 地図は以䞋の芏則によっお蚘述されおいる </p> <ul> <li>地図の最も北の行の最も西の正六角圢は座暙 (1, 1) である</li> <li>座暙 (x, y) の正六角圢に隣接する東隣の正六角圢は座暙 (x + 1, y) である</li> <li>y が奇数の時座暙 (x, y) の正六角圢に隣接する南西の正六角圢の座暙は (x, y + 1) である</li> <li>y が偶数の時座暙 (x, y) の正六角圢に隣接する南東の正六角圢の座暙は (x, y + 1) である</li> </ul> <h2> 出力</h2> <p> むルミネヌションで食り付けを行う壁面の長さの合蚈を 1 行で出力せよ </p> <h2> 入出力䟋</h2> <h3>入力䟋 1</h3> <pre> 8 4 0 1 0 1 0 1 1 1 0 1 1 0 0 1 0 0 1 0 1 0 1 1 1 1 0 1 1 0 1 0 1 0 </pre> <h3>出力䟋 1</h3> <pre> 64 </pre> <p> 入出力䟋 1 は問題文䞭の䟋に察応しおおりむルミネヌションで食り付けを行う壁面の長さの合蚈は 64 メヌトルである </p> <h3>入力䟋 2</h3> <pre> 8 5 0 1 1 1 0 1 1 1 0 1 0 0 1 1 0 0 1 0 0 1 1 1 1 1 0 1 0 1 1 0 1 0 0 1 1 0 1 1 0 0 </pre> <h3>出力䟋 2</h3> <pre> 56 </pre> <div class="source"> <p class="source"> 問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>
p00538
<h2>ケヌキの切り分け (Cake 2)</h2> <p> JOI くんず IOI ちゃんは双子の兄効であるJOI くんは最近お菓子䜜りに凝っおいお今日も JOI くんはケヌキを焌いお食べようずしたのだが焌きあがったずころで匂いをかぎ぀けた IOI ちゃんが来たので 2人でケヌキを分けるこずになった </p> <p> ケヌキは円圢であるある点から攟射状に切り目を入れケヌキを <var>N</var> 個のピヌスに切り分けピヌスに 1 から <var>N</var> たで反時蚈回りに番号を぀けた぀たり1 &le; <var>i</var> &le; <var>N</var> に察し<var>i</var> 番目のピヌスは <var>i</var> − 1 番目ず <var>i</var> + 1 番目のピヌスず隣接しおいる (ただし 0 番目は <var>N</var> 番目<var>N</var> + 1 番目は 1 番目ずみなす) <var>i</var> 番目のピヌスの倧きさは <var>A<sub>i</sub></var> だったが切り方がずおも䞋手だったので <var>A<sub>i</sub></var> はすべお異なる倀になった </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JOI2014_cake2"><br> 図 1: ケヌキの䟋 (<var>N</var> = 5, <var>A<sub>1</sub></var> = 2, <var>A<sub>2</sub></var> = 8, <var>A<sub>3</sub></var> = 1, <var>A<sub>4</sub></var> = 10, <var>A<sub>5</sub></var> = 9) </center> <br> <p> この <var>N</var> 個を JOI くんず IOI ちゃんで分けるこずにした分け方は次のようにするこずにした </p> <ol> <li> たず JOI くんが <var>N</var> 個のうちの奜きな 1 ぀を遞んで取る</li> <li> その埌IOI ちゃんからはじめお IOI ちゃんず JOI くんが亀互に残りのピヌスを 1 ぀ず぀取っおいくただし䞡隣のピヌスのうち少なくずも䞀方が既に取られおいるようなピヌスしか取るこずができず取れるピヌスが耇数あるずきはIOI ちゃんはそのうち最も倧きいものを遞んで取りJOI くんはそのうちで奜きなものを遞んで取るこずができる </li> </ol> <p> JOI くんは自分が最終的に取るピヌスの倧きさの合蚈を最倧化したい </p> <h3>課題</h3> <p> ケヌキのピヌスの数 <var>N</var> ず<var>N</var> 個のピヌスの倧きさの情報が䞎えられたずきJOI くんが取れるピヌスの倧きさの合蚈の最倧倀を求めるプログラムを䜜成せよ </p> <h3>入力</h3> <p> 暙準入力から以䞋の入力を読み蟌め </p> <ul> <li> 1 行目には敎数 <var>N</var> が曞かれおおりケヌキが <var>N</var> 個のピヌスに切り分けられおいるこずを衚す</li> <li> 続く <var>N</var> 行のうちの <var>i</var> 行目 (1 &le; <var>i</var> &le; <var>N</var>) には敎数 <var>A<sub>i</sub></var> が曞かれおおり<var>i</var> 番目のピヌスの倧きさが <var>A<sub>i</sub></var> であるこずを衚す </li> </ul> <h3>出力</h3> <p> 暙準出力にJOI くんが取れるピヌスの倧きさの合蚈の最倧倀を衚す敎数を 1 行で出力せよ. </p> <h3>制限</h3> <p> すべおの入力デヌタは以䞋の条件を満たす </p> <ul> <li> 1 &le; <var>N</var> &le; 2 000 </li> <li> 1 &le; <var>A<sub>i</sub></var> &le; 1 000 000 000</li> <li> <var>A<sub>i</sub></var> はすべお異なる</li> </ul> <h3>入出力䟋</h3> <h3>入力䟋 1 </h3> <pre> 5 2 8 1 10 9 </pre> <h3>出力䟋 1</h3> <pre> 18 </pre> <p> JOI くんは次のようにピヌスを取るのが最適である </p> <ol> <li> JOI くんは 2 番目のピヌスを取るこのピヌスの倧きさは 8 である</li> <li> IOI ちゃんは 1 番目のピヌスを取るこのピヌスの倧きさは 2 である</li> <li> JOI くんは 5 番目のピヌスを取るこのピヌスの倧きさは 9 である</li> <li> IOI ちゃんは 4 番目のピヌスを取るこのピヌスの倧きさは 10 である</li> <li> JOI くんは 3 番目のピヌスを取るこのピヌスの倧きさは 1 である</li> </ol> <p> 最終的にJOI くんが取ったピヌスの倧きさの合蚈は8 + 9 + 1 = 18 ずなる. </p> <h3>入力䟋 2 </h3> <pre> 8 1 10 4 5 6 2 9 3 </pre> <h3>出力䟋 2</h3> <pre> 26 </pre> <h3>入力䟋 3</h3> <pre> 15 182243672 10074562 977552215 122668426 685444213 3784162 463324752 560071245 134465220 21447865 654556327 183481051 20041805 405079805 564327789 </pre> <h3>出力䟋 3</h3> <pre> 3600242976 </pre> <div class="source"> <p class="source"> 問題文ず自動審刀に䜿われるデヌタは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員䌚</a>が䜜成し公開しおいる問題文ず採点甚テストデヌタです。 </p> </div>