question_id
stringlengths
6
6
content
stringlengths
1
27.2k
p00714
<h1> <font color="#000">Problem E:</font> Water Tank </h1> <p> Mr. Denjiro is a science teacher. Today he has just received a specially ordered water tank that will certainly be useful for his innovative experiments on water flow. </p> <CENTER> <TABLE> <TR> <TD ALIGN="center"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_water1"></TD> </TR> <TR> <TD ALIGN="center">Figure 1: The water tank</TD> </TR> </TABLE> </CENTER> <p> The size of the tank is 100cm (Width) * 50cm (Height) * 30cm (Depth) (see Figure 1). For the experiments, he fits several partition boards inside of the tank parallel to the sideboards. The width of each board is equal to the depth of the tank, i.e. 30cm. The height of each board is less than that of the tank, i.e. 50 cm, and differs one another. The boards are so thin that he can neglect the thickness in the experiments. </p> <CENTER> <TABLE> <TR> <TD ALIGN="center"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_water2"></TD> </TR> <TR> <TD ALIGN="center">Figure 2: The front view of the tank</TD> </TR> </TABLE> </CENTER> <P> The front view of the tank is shown in Figure 2. </P> <P> There are several faucets above the tank and he turns them on at the beginning of his experiment. The tank is initially empty. Your mission is to write a computer program to simulate water flow in the tank. </P> <h2>Input</h2> <p> The input consists of multiple data sets. <I>D</I> is the number of the data sets. </p> <DIR> <I>D</I><BR> <I>DataSet</I><SUB>1</SUB><BR> <I>DataSet</I><SUB>2</SUB><BR> ...<BR> <I>DataSet</I><SUB><I>D</I></SUB><BR> </DIR> <p> The format of each data set (<I>DataSet</I><SUB><I>d</I></SUB> , 1 &lt;= <I>d</I> &lt;= <I>D</I>) is as follows. </p> <DIR> <I>N</I><BR> <I>B</I><SUB>1</SUB> <I>H</I><SUB>1</SUB><BR> <I>B</I><SUB>2</SUB> <I>H</I><SUB>2</SUB><BR> ...<BR> <I>B</I><SUB><I>N</I></SUB> <I>H</I><SUB><I>N</I></SUB><BR> <I>M</I><BR> <I>F</I><SUB>1</SUB> <I>A</I><SUB>1</SUB><BR> <I>F</I><SUB>2</SUB> <I>A</I><SUB>2</SUB><BR> ...<BR> <I>F</I><SUB><I>M</I></SUB> <I>A</I><SUB><I>M</I></SUB><BR> <I>L</I><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> <I>P</I><SUB><I>L</I></SUB> <I>T</I><SUB><I>L</I></SUB><BR> </DIR> <P> Each line in the data set contains one or two integers. </P> <P> <I>N</I> is the number of the boards he sets in the tank . <I>B<SUB>i</SUB></I> and <I>H<SUB>i</SUB></I> are the <I>x</I>-position (cm) and the height (cm) of the <I>i</I>-th board, where 1 &lt;= <I>i</I> &lt;= <I>N</I> . </P> <P> <I>H<SUB>i</SUB></I> s differ from one another. You may assume the following. </P> <BLOCKQUOTE> 0 &lt; <I>N</I> &lt; 10 , <BR> 0 &lt; <I>B</I><SUB>1</SUB> &lt; <I>B</I><SUB>2</SUB> &lt; ... &lt; <I>B<SUB>N</SUB></I> &lt; 100 , <BR> 0 &lt; <I>H</I><SUB>1</SUB> &lt; 50 , 0 &lt; <I>H</I><SUB>2</SUB> &lt; 50 , ..., 0 &lt; <I>H<SUB>N</SUB></I> &lt; 50. </BLOCKQUOTE> <P> <I>M</I> is the number of the faucets above the tank . <I>F<SUB>j</SUB></I> and <I>A<SUB>j</SUB></I> are the <I>x</I>-position (cm) and the amount of water flow (cm<SUP>3</SUP>/second) of the <I>j</I>-th faucet , where 1 &lt;= <I>j</I> &lt;= <I>M</I> . </P> <P> There is no faucet just above any boards . Namely, none of <I>F<SUB>j</SUB></I> is equal to <I>B<SUB>i</SUB></I> . </P> <P> You may assume the following . </P> </P> <BLOCKQUOTE> 0 &lt; <I>M</I> &lt;10 , <BR> 0 &lt; <I>F<SUB>1</SUB></I> &lt; <I>F<SUB>2</SUB></I> &lt; ... &lt; <I>F<SUB>M</SUB></I> &lt; 100 ,<BR> 0 &lt; <I>A</I><SUB>1</SUB> &lt; 100, 0 &lt; <I>A</I><SUB>2</SUB> &lt; 100, ... 0 &lt; <I>A<SUB>M</SUB></I> &lt; 100. </BLOCKQUOTE> <P> <I>L</I> is the number of observation time and location. <I>P<SUB>k</SUB></I> is the <I>x</I>-position (cm) of the <I>k</I>-th observation point. <I>T<SUB>k</SUB></I> is the <I>k</I>-th observation time in seconds from the beginning. </P> <P> None of <I>P<SUB>k</SUB></I> is equal to <I>B<SUB>i</SUB></I> . </P> <P> You may assume the following . </P> <BLOCKQUOTE> 0 &lt; <I>L</I> &lt; 10 , <BR> 0 &lt; <I>P</I><SUB>1</SUB> &lt; 100, 0 &lt; <I>P</I><SUB>2</SUB> &lt; 100, ..., 0 &lt; <I>P<SUB>L</SUB></I> &lt; 100 , <BR> 0 &lt; <I>T</I><SUB>1</SUB> &lt; 1000000, 0 &lt; <I>T</I><SUB>2</SUB> &lt; 1000000, ... , 0 &lt; <I>T<SUB>L</SUB></I> &lt; 1000000. </BLOCKQUOTE> <h2>Output</h2> <P> For each data set, your program should output <I>L</I> lines each containing one real number which represents the height (cm) of the water level specified by the <I>x</I>-position <I>P</I><SUB><I>k</I></SUB> at the time <I>T</I><SUB><I>k</I></SUB>. </p> <P> Each answer may not have an error greater than 0.001. As long as this condition is satisfied, you may output any number of digits after the decimal point. </P> <P> After the water tank is filled to the brim, the water level at any <I>P<SUB>k</SUB></I> is equal to the height of the tank, that is, 50 cm. </P> <h2>Sample Input</h2> <pre> 2 5 15 40 35 20 50 45 70 30 80 10 3 20 3 60 2 65 2 6 40 4100 25 7500 10 18000 90 7000 25 15000 25 22000 5 15 40 35 20 50 45 70 30 80 10 2 60 4 75 1 3 60 6000 75 6000 85 6000 </pre> <h2>Output for the Sample Input</h2> <pre> 0.666667 21.4286 36.6667 11.1111 40.0 50.0 30.0 13.3333 13.3333 </pre>
p01806
<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>Dice Stamp</u></h3> <!-- end en only --> <!-- begin ja only --> <h3><u>サイコロスタンプ</u></h3> <!-- end ja only --> <!-- end en only --> <!-- begin ja only --> <p>あなたは地元の縁日で,今までに見たことがないゲームの出店を発見した. <var>N</var> 個の6面サイコロを,ボード上に落として転がすゲームだ. より正確には, <var>N</var> 個のボタンが <var>N</var> 個のサイコロに1対1に紐付いており,ボタンを押すことで対応したサイコロがボードに落ちる. ボタンを好きなように <var>N</var> 回押し,サイコロを <var>N</var> 回落として転がすことで得点を得るゲームである. </p> <p>ゲームのより詳細なルールを説明しよう. ゲームで使用する <var>N</var> 個のサイコロはすべて各辺の長さが1の立方体であり,ボードは長さが1の正方形のマスに区切られた十分に広い平面である. ゲーム開始前,ボードの各マスにはすべて0が書かれている. 各サイコロの各面には整数が書かれている.これは1から6までとは限らないし,サイコロごとに違う数が書かれていることもある. </p> <p>ゲームで用いる筐体には <var>N</var> 個のボタンが付いており, <var>N</var> 個のサイコロと1対1に紐付いている. いずれかのボタンを押すと,対応したサイコロが機械から排出されてボードに落ち,何度か回転する. 回転の途中,サイコロの下面は必ずボードのいずれかのマスにぴったりと重なる. 下面がマスに触れる度,そのマスに書かれていた数が,サイコロの下面に書かれた数で上書きされる. これは落下により初めてボードに触れたときも含む. 回転が止まった後,サイコロはボードから取り除かれ,元の排出装置へと戻される. ボタンを <var>N</var> 回押した後,ボードに書かれた数の和が最終得点となる. 同じボタンを複数回押すことはできるが,1つ前に排出したサイコロの回転が終わり,排出装置に戻るまで次のボタンを押すことはできない. </p> <p>さて,出店のおっちゃんはサイコロの排出の仕方はランダムだと主張しているが,注意深いあなたは,他の客が遊ぶ様子を観察することで,同じボタンを押した時の挙動がそれまでのボタンの押し方に依らず完全に同一であることに気付いた. より具体的には, <var>i</var> 番目のボタンを押したときの挙動は以下のように決定的である. </p><ol><li> <var>i</var> 番目のサイコロが排出される. </li><li> このサイコロは内部で決められたマスに決められた向きで落下する.この向きは必ず,マスの正方形と下面の正方形とがぴったりと重なる向きである. </li><li> サイコロは前後左右4方向いずれかに回転することを繰り返す.回転回数やそれぞれの回転の方向も,内部で決められている. </li><li> 決められた回転が終了すると,サイコロはボードから取り除かれ,排出装置に戻される. </li></ol> <p>ここで,便宜上3次元空間を考え,マスの辺に平行な向きにそれぞれ <var>x</var> 軸と <var>y</var> 軸をとり,サイコロ上面が向く方向を <var>z</var> 軸正方向とする. この時,サイコロの回転は <var>x</var>, <var>y</var> 軸の正,負方向の4通りであり,それぞれ下図のようになる.ただし,図中の記号は後述の入力形式に対応している. </p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_JAGDomestic2015_dice" height="576" width="768" /> <p>決定的に動くとはなんて詐欺だ,と憤りを感じたものの,あなたは <var>N</var> 回のボタンの押し方によって最終得点を変えられることに気が付いた. </p> <p>あなたは入念な観察により各サイコロの各面に書かれた数や落とされる初期位置・向き・その後の回転の仕方に至るまで完全な情報を揃えた. 集めた情報に基づいて,最善のボタンの押し方で得られるこのゲームの最高得点を求めよ. </p> <!-- end ja only --> <h3>Input</h3> <!-- begin ja only --> <p>入力は40個以下のデータセットからなる.各データセットは以下の形式で表される. </p> <blockquote><var>N</var><br>1番目のサイコロの情報<br>...<br><var>N</var> 番目のサイコロの情報</blockquote> <p>入力の最初の行は,サイコロの個数を表す1つの整数 <var>N</var> からなる.1 &le; <var>N</var> &le; 15 と仮定してよい. 以降, <var>N</var> 個のサイコロの情報が続く. </p> <p>それぞれのサイコロの情報は,以下の形式で表される. </p><blockquote><var>x</var> <var>y</var><br><var>l</var> <var>r</var> <var>f</var> <var>b</var> <var>d</var> <var>u</var><br><var>rot</var></blockquote> <p>1行目は2つの整数 <var>x</var>, <var>y</var> からなり,排出されたときにサイコロが落とされるマスの中心の座標 (<var>x</var>, <var>y</var>) を表す.-1,000 &le; <var>x</var>, <var>y</var> &le; 1,000 と仮定してよい. </p> <p>2行目は6つの整数 <var>l</var>, <var>r</var>, <var>f</var>, <var>b</var>, <var>d</var>, <var>u</var> からなり,各面に書かれた数を表す. <var>l</var>, <var>r</var>, <var>f</var>, <var>b</var>, <var>d</var>, <var>u</var> はそれぞれ,落とされたときに <var>x</var> 軸負方向, <var>x</var> 軸正方向, <var>y</var> 軸負方向, <var>y</var> 軸正方向, <var>z</var> 軸負方向, <var>z</var> 軸正方向を向いている面に書かれた数である.1 &le; <var>l</var>, <var>r</var>, <var>f</var>, <var>b</var>, <var>d</var>, <var>u</var> &le; 100 と仮定してよい. </p> <p>3行目は回転の仕方を表す文字列 <var>rot</var> からなる. <var>rot</var> は '<samp>L</samp>', '<samp>R</samp>', '<samp>F</samp>', '<samp>B</samp>' のみからなる文字列であり,1文字以上,30文字以下である. rot の j 番目の文字は j 回目の回転の方向を表しており,文字が '<samp>L</samp>', '<samp>R</samp>', '<samp>F</samp>', '<samp>B</samp>' のときそれぞれ, <var>x</var> 軸負方向,<var>x</var> 軸正方向,<var>y</var> 軸負方向,<var>y</var> 軸正方向に回転することを示す. </p> <p>入力の終わりは,1つのゼロを含む1行で示される. </p> <!-- end ja only --> <h3>Output</h3> <!-- begin ja only --> <p>各データセットについて, <var>N</var> 回のボタンの押し方を工夫することで得られる最高得点を1行で出力せよ. 各出力行はこの数値以外の文字を含んではならない. </p> <!-- end ja only --> <h3>Sample Input</h3> <pre>1 0 0 1 2 3 4 5 6 RRRRBBBBLLLLFFFF 2 0 0 1 1 1 1 1 1 RRR 2 2 100 100 100 100 100 100 FFF 1 1000 -1000 1 2 3 4 5 6 LFRB 4 -3 -4 1 2 3 4 5 6 BBBBBBBB 4 -3 11 12 13 14 15 16 LLLLLLLL 3 4 21 22 23 24 25 26 FFFFFFFF -4 3 31 32 33 34 35 36 RRRRRRRR 3 -2 -2 9 3 1 1 1 1 RRRRBLLLBRRBLB 0 -3 2 5 2 5 2 1 BBLBBRBB 3 0 10 7 2 10 1 5 LLFLLBLL 0</pre> <h3>Output for Sample Input</h3> <pre>64 403 10 647 96</pre>
p02683
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem</h3><p>Takahashi, who is a novice in competitive programming, wants to learn <var>M</var> algorithms. Initially, his <em>understanding level</em> of each of the <var>M</var> algorithms is <var>0</var>.</p> <p>Takahashi is visiting a bookstore, where he finds <var>N</var> books on algorithms. The <var>i</var>-th book (<var>1\leq i\leq N</var>) is sold for <var>C_i</var> yen (the currency of Japan). If he buys and reads it, his understanding level of the <var>j</var>-th algorithm will increase by <var>A_{i,j}</var> for each <var>j</var> (<var>1\leq j\leq M</var>). There is no other way to increase the understanding levels of the algorithms.</p> <p>Takahashi's objective is to make his understanding levels of all the <var>M</var> algorithms <var>X</var> or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.</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 12</var></li> <li><var>1\leq X\leq 10^5</var></li> <li><var>1\leq C_i \leq 10^5</var></li> <li><var>0\leq A_{i, j} \leq 10^5</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>X</var> <var>C_1</var> <var>A_{1,1}</var> <var>A_{1,2}</var> <var>\cdots</var> <var>A_{1,M}</var> <var>C_2</var> <var>A_{2,1}</var> <var>A_{2,2}</var> <var>\cdots</var> <var>A_{2,M}</var> <var>\vdots</var> <var>C_N</var> <var>A_{N,1}</var> <var>A_{N,2}</var> <var>\cdots</var> <var>A_{N,M}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If the objective is not achievable, print <code>-1</code>; otherwise, print the minimum amount of money needed to achieve it.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 10 60 2 2 4 70 8 7 9 50 2 3 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>120 </pre> <p>Buying the second and third books makes his understanding levels of all the algorithms <var>10</var> or higher, at the minimum cost possible.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 3 10 100 3 1 4 100 1 5 9 100 2 6 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 </pre> <p>Buying all the books is still not enough to make his understanding levels of all the algorithms <var>10</var> or higher.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>8 5 22 100 3 7 5 3 1 164 4 5 2 7 8 334 7 2 7 2 9 234 4 7 2 8 2 541 5 4 3 3 6 235 4 8 6 9 7 394 3 6 1 6 2 872 8 4 3 7 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1067 </pre></section> </div> </span>
p03991
<span class="lang-en"> <p>Score : <var>1900</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><style> #nck { width: 30px; height: auto; } </style> <p>One day, Takahashi was given the following problem from Aoki:</p> <ul> <li>You are given a tree with <var>N</var> vertices and an integer <var>K</var>. The vertices are numbered <var>1</var> through <var>N</var>. The edges are represented by pairs of integers <var>(a_i, b_i)</var>.</li> <li>For a set <var>S</var> of vertices in the tree, let <var>f(S)</var> be the minimum number of the vertices in a subtree of the given tree that contains all vertices in <var>S</var>.</li> <li>There are <img id="nck" src="https://atcoder.jp/img/agc005/ea29e9345ef75e7d965febb790a5aad1.png"/> ways to choose <var>K</var> vertices from the trees. For each of them, let <var>S</var> be the set of the chosen vertices, and find the sum of <var>f(S)</var> over all <img id="nck" src="https://atcoder.jp/img/agc005/ea29e9345ef75e7d965febb790a5aad1.png"/> ways.</li> <li>Since the answer may be extremely large, print it modulo <var>924844033</var>(prime).</li> </ul> <p>Since it was too easy for him, he decided to solve this problem for all <var>K = 1,2,...,N</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 ≦ N ≦ 200,000</var></li> <li><var>1 ≦ a_i, b_i ≦ 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>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>a_1</var> <var>b_1</var> <var>a_2</var> <var>b_2</var> <var>:</var> <var>a_{N-1}</var> <var>b_{N-1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>N</var> lines. The <var>i</var>-th line should contain the answer to the problem where <var>K=i</var>, modulo <var>924844033</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 2 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 7 3 </pre> <p><img alt="" src="https://atcoder.jp/img/agc005/44e2fd5d5e0fe66d1d238ee502639e4e.png"/></p> <p>The diagram above illustrates the case where <var>K=2</var>. The chosen vertices are colored pink, and the subtrees with the minimum number of vertices are enclosed by red lines.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 1 2 1 3 1 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>4 15 13 4 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>7 1 2 2 3 2 4 4 5 4 6 6 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>7 67 150 179 122 45 7 </pre></section> </div> </span>
p02379
<H1>Distance</H1><br> <p> Write a program which calculates the distance between two points P1(x1, y1) and P2(x2, y2). </p> <H2>Input</H2> <p> Four real numbers x1, y1, x2 and y2 are given in a line. </p> <H2>Output</H2> <p> Print the distance in real number. The output should not contain an absolute error greater than 10<sup>-4</sup>. </p> <H2>Sample Input</H2> <pre> 0 0 1 1 </pre> <H2>Sample Output</H2> <pre> 1.41421356 </pre>
p00344
<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> ユキさんは、子供会の催しでみんなで遊べるようにすごろくを作りました。このすごろくでは、環状にマスが並んでいて、それぞれのマスには1以上の整数が書いてあります。 </p> <p> プレイヤーは出発点としてどこかのマスを選んで自分の駒を置きます。そのマスに書いてある数だけ、時計回りに駒を進めます。止まったマスに書いてある数だけ、再び時計回りに駒を進めます。これを繰り返して、出発点に選んだマスの上で駒が止まったら「あがり」です。 </p> <p> 実際には、マスの選び方によっては絶対に「あがり」にならない場合もあります。ユキさんは、このすごろくで「あがり」にたどり着けるマスの個数を数えようとしています。 </p> <br/> <p> すごろくの情報を入力とし、「あがり」にたどり着けるマスの個数を報告するプログラムを作成せよ。 </p> <h2>Input</h2> <p> 入力は以下の形式で与えられる。 </p> <pre> <var>N</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> ... <var>a<sub>N</sub></var> </pre> <p> 1行目にすごろくに含まれるすべてのマスの個数 <var>N</var> (1 &le; <var>N</var> &le; 100000) が与えられる。2行目に、それぞれのマスに書かれた数 <var>a<sub>i</sub></var> (1 &le; <var>a<sub>i</sub></var> &le; 10<sup>9</sup>) が、時計回りに順番に与えられる。 </p> <h2>Output</h2> <p> 「あがり」にたどり着けるマスの個数を1行に出力する。 </p> <h2>Sample Input 1</h2> <pre> 3 1 1 1 </pre> <h2>Sample Output 1</h2> <pre> 3 </pre> <br/> <h2>Sample Input 2</h2> <pre> 3 1 1 2 </pre> <h2>Sample Output 2</h2> <pre> 2 </pre> <br/> <h2>Sample Input 3</h2> <pre> 8 2 3 7 3 3 3 4 4 </pre> <h2>Sample Output 3</h2> <pre> 6 </pre> <br/>
p01105
<h3><u>Boolean Expression Compressor</u></h3> <p> You are asked to build a compressor for Boolean expressions that transforms expressions to the shortest form keeping their meaning. </p> <p> The grammar of the Boolean expressions has terminals <tt>0</tt>&nbsp;<tt>1</tt>&nbsp;<tt>a</tt>&nbsp;<tt>b</tt>&nbsp;<tt>c</tt>&nbsp;<tt>d</tt>&nbsp;<tt>-</tt>&nbsp;<tt>^</tt>&nbsp;<tt>*</tt>&nbsp;<tt>(</tt>&nbsp;<tt>)</tt>, start symbol &lt;E&gt; and the following production rule: </p> <blockquote> &lt;E&gt; &nbsp;::=&nbsp; <tt>0</tt> &nbsp;|&nbsp; <tt>1</tt> &nbsp;|&nbsp; <tt>a</tt> &nbsp;|&nbsp; <tt>b</tt> &nbsp;|&nbsp; <tt>c</tt> &nbsp;|&nbsp; <tt>d</tt> &nbsp;|&nbsp; <tt>-</tt>&lt;E&gt; &nbsp;|&nbsp; <tt>(</tt>&lt;E&gt;<tt>^</tt>&lt;E&gt;<tt>)</tt> &nbsp;|&nbsp; <tt>(</tt>&lt;E&gt;<tt>*</tt>&lt;E&gt;<tt>)</tt> </blockquote> <p> Letters <tt>a</tt>, <tt>b</tt>, <tt>c</tt> and <tt>d</tt> represent Boolean variables that have values of either <tt>0</tt> or <tt>1</tt>. Operators are evaluated as shown in the Table below. In other words, <tt>-</tt> means negation (NOT), <tt>^</tt> means exclusive disjunction (XOR), and <tt>*</tt> means logical conjunction (AND). </p> <center> Table: Evaluations of operators<br> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCDomestic2017_E01"> </center> <p> Write a program that calculates the length of the shortest expression that evaluates equal to the given expression with whatever values of the four variables. </p> <p> For example, <tt>0</tt>, that is the first expression in the sample input, cannot be shortened further. Therefore the shortest length for this expression is 1. </p><p> For another example, <tt>(a*(1*b))</tt>, the second in the sample input, always evaluates equal to <tt>(a*b)</tt> and <tt>(b*a)</tt>, which are the shortest. The output for this expression, thus, should be <tt>5</tt>. </p> <h3>Input</h3> <p> The input consists of multiple datasets. A dataset consists of one line, containing an expression conforming to the grammar described above. The length of the expression is less than or equal to 16 characters. </p> <p> The end of the input is indicated by a line containing one ‘<tt>.</tt>’ (period). The number of datasets in the input is at most 200. </p> <h3>Output</h3> <p> For each dataset, output a single line containing an integer which is the length of the shortest expression that has the same value as the given expression for all combinations of values in the variables. </p> <h3>Sample Input</h3> <pre>0 (a*(1*b)) (1^a) (-(-a*-b)*a) (a^(b^(c^d))) . </pre> <h3>Output for the Sample Input</h3> <pre>1 5 2 1 13 </pre>
p03138
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given <var>N</var> non-negative integers <var>A_1, A_2, ..., A_N</var> and another non-negative integer <var>K</var>.</p> <p>For a integer <var>X</var> between <var>0</var> and <var>K</var> (inclusive), let <var>f(X) = (X</var> XOR <var>A_1)</var> <var>+</var> <var>(X</var> XOR <var>A_2)</var> <var>+</var> <var>...</var> <var>+</var> <var>(X</var> XOR <var>A_N)</var>.</p> <p>Here, for non-negative integers <var>a</var> and <var>b</var>, <var>a</var> XOR <var>b</var> denotes the bitwise exclusive OR of <var>a</var> and <var>b</var>.</p> <p>Find the maximum value of <var>f</var>.</p> <p><details> <summary style="display: list-item; outline: none;">What is XOR?</summary></details></p> <p>The bitwise exclusive OR of <var>a</var> and <var>b</var>, <var>X</var>, is defined as follows:</p> <ul> <li>When <var>X</var> is written in base two, the digit in the <var>2^k</var>'s place (<var>k \geq 0</var>) is <var>1</var> if, when written in base two, exactly one of <var>A</var> and <var>B</var> has <var>1</var> in the <var>2^k</var>'s place, and <var>0</var> otherwise.</li> </ul> <p>For example, <var>3</var> XOR <var>5 = 6</var>. (When written in base two: <var>011</var> XOR <var>101 = 110</var>.)</p> <p></p></section></div></span>
p03092
<span class="lang-en"> <p>Score : <var>1000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a permutation <var>p = (p_1, \ldots, p_N)</var> of <var>\{ 1, \ldots, N \}</var>. You can perform the following two kinds of operations repeatedly in any order:</p> <ul> <li>Pay a cost <var>A</var>. Choose integers <var>l</var> and <var>r</var> (<var>1 \leq l &lt; r \leq N</var>), and shift <var>(p_l, \ldots, p_r)</var> to the left by one. That is, replace <var>p_l, p_{l + 1}, \ldots, p_{r - 1}, p_r</var> with <var>p_{l + 1}, p_{l + 2}, \ldots, p_r, p_l</var>, respectively.</li> <li>Pay a cost <var>B</var>. Choose integers <var>l</var> and <var>r</var> (<var>1 \leq l &lt; r \leq N</var>), and shift <var>(p_l, \ldots, p_r)</var> to the right by one. That is, replace <var>p_l, p_{l + 1}, \ldots, p_{r - 1}, p_r</var> with <var>p_r, p_l, \ldots, p_{r - 2}, p_{r - 1}</var>, respectively.</li> </ul> <p>Find the minimum total cost required to sort <var>p</var> in ascending order.</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 5000</var></li> <li><var>1 \leq A, B \leq 10^9</var></li> <li><var>(p_1 \ldots, p_N)</var> is a permutation of <var>\{ 1, \ldots, N \}</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A</var> <var>B</var> <var>p_1</var> <var>\cdots</var> <var>p_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum total cost required to sort <var>p</var> in ascending order.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 20 30 3 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>20 </pre> <p>Shifting <var>(p_1, p_2, p_3)</var> to the left by one results in <var>p = (1, 2, 3)</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 20 30 4 2 3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>50 </pre> <p>One possible sequence of operations is as follows:</p> <ul> <li>Shift <var>(p_1, p_2, p_3, p_4)</var> to the left by one. Now we have <var>p = (2, 3, 1, 4)</var>.</li> <li>Shift <var>(p_1, p_2, p_3)</var> to the right by one. Now we have <var>p = (1, 2, 3, 4)</var>.</li> </ul> <p>Here, the total cost is <var>20 + 30 = 50</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 10 10 1 </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>4 1000000000 1000000000 4 3 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>3000000000 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 5</h3><pre>9 40 50 5 3 4 7 6 1 2 9 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>220 </pre></section> </div> </span>
p01555
<h1>FizzBuzz</h1> <p>FizzBuzzとは、1以上の整数を順に、以下のルールに従って発言していくゲームである。 </p><ul><li><p> 3で割り切れる時には「Fizz」 </p></li><li><p> 5で割り切れる時には「Buzz」 </p></li><li><p> 3と5の両方で割り切れる時には「FizzBuzz」 </p></li><li><p> それ以外の時はその数字 </p></li></ul> <p>ゲームの進行状況の例を以下に示す。 </p> <p>1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, … </p> <p>得られた発言を1つの文字列に結合し得られた文字列をFizzBuzz Stringと呼ぶ。インデックスsが与えられるので、FizzBuzz Stringのs文字目から20文字を出力せよ。但し、インデックスは1から始まるものとし、得られた文字列の長さは十分に大きい(s+20以上)としてよい。 </p> <h2>Input</h2> <p>入力は以下の形式で与えられる </p><blockquote> s<br></blockquote> <h2>Constraints</h2> <ul><li><p> <var>s</var>は整数である </p></li><li><p> 1 &le; <var>s</var> &le; 10<sup>18</sup> </p></li></ul> <h2>Output</h2> <p>FizzBuzz Stringのs文字目から20文字を1行に出力せよ </p> <h2>Sample Input 1</h2> <pre>1 </pre> <h2>Output for the Sample Input 1</h2> <pre>12Fizz4BuzzFizz78Fiz </pre> <h2>Sample Input 2</h2> <pre>20 </pre> <h2>Output for the Sample Input 2</h2> <pre>zzBuzz11Fizz1314Fizz </pre> <h2>Sample Input 3</h2> <pre>10000000000 </pre> <h2>Output for the Sample Input 3</h2> <pre>93FizzBuzz1418650796 </pre>
p03568
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We will say that two integer sequences of length <var>N</var>, <var>x_1, x_2, ..., x_N</var> and <var>y_1, y_2, ..., y_N</var>, are <em>similar</em> when <var>|x_i - y_i| \leq 1</var> holds for all <var>i</var> (<var>1 \leq i \leq N</var>).</p> <p>In particular, any integer sequence is similar to itself.</p> <p>You are given an integer <var>N</var> and an integer sequence of length <var>N</var>, <var>A_1, A_2, ..., A_N</var>.</p> <p>How many integer sequences <var>b_1, b_2, ..., b_N</var> are there such that <var>b_1, b_2, ..., b_N</var> is similar to <var>A</var> and the product of all elements, <var>b_1 b_2 ... b_N</var>, is even?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 10</var></li> <li><var>1 \leq A_i \leq 100</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <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 integer sequences that satisfy the condition.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>7 </pre> <p>There are seven integer sequences that satisfy the condition:</p> <ul> <li><var>1, 2</var></li> <li><var>1, 4</var></li> <li><var>2, 2</var></li> <li><var>2, 3</var></li> <li><var>2, 4</var></li> <li><var>3, 2</var></li> <li><var>3, 4</var></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 3 3 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>26 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>10 90 52 56 71 44 8 13 30 57 84 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>58921 </pre></section> </div> </span>
p03246
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>A sequence <var>a_1,a_2,... ,a_n</var> is said to be /\/\/\/ when the following conditions are satisfied:</p> <ul> <li>For each <var>i = 1,2,..., n-2</var>, <var>a_i = a_{i+2}</var>.</li> <li>Exactly two different numbers appear in the sequence.</li> </ul> <p>You are given a sequence <var>v_1,v_2,...,v_n</var> whose length is even. We would like to make this sequence /\/\/\/ by replacing some of its elements. Find the minimum number of elements that needs to be replaced.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq n \leq 10^5</var></li> <li><var>n</var> is even.</li> <li><var>1 \leq v_i \leq 10^5</var></li> <li><var>v_i</var> is an integer.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>n</var> <var>v_1</var> <var>v_2</var> <var>...</var> <var>v_n</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum number of elements that needs to be replaced.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 3 1 3 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>The sequence <var>3,1,3,2</var> is not /\/\/\/, but we can make it /\/\/\/ by replacing one of its elements: for example, replace the fourth element to make it <var>3,1,3,1</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 105 119 105 119 105 119 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>The sequence <var>105,119,105,119,105,119</var> is /\/\/\/.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>4 1 1 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>2 </pre> <p>The elements of the sequence <var>1,1,1,1</var> are all the same, so it is not /\/\/\/.</p></section> </div> </span>
p00893
<H1><font color="#000">Problem J:</font> Matrix Calculator</H1> <p> Dr. Jimbo, an applied mathematician, needs to calculate matrices all day for solving his own problems. In his laboratory, he uses an excellent application program for manipulating matrix expressions, however, he cannot use it outside his laboratory because the software consumes much of resources. He wants to manipulate matrices outside, so he needs a small program similar to the excellent application for his handheld computer. </p> <p> Your job is to provide him a program that computes expressions of matrices. </p> <p> Expressions of matrices are described in a simple language. Its syntax is shown in Table J.1. Note that even a space and a newline have meaningful roles in the syntax. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_matrixCalculator"> </center> <p> The start symbol of this syntax is program that is defined as a sequence of assignments in Table J.1. Each assignment has a variable on the left hand side of an equal symbol ("<span>=</span>") and an expression of matrices on the right hand side followed by a period and a newline (<span>NL</span>). It denotes an assignment of the value of the expression to the variable. The variable (var in Table J.1) is indicated by an uppercase Roman letter. The value of the expression (<span>expr</span>) is a matrix or a scalar, whose elements are integers. Here, a scalar integer and a 1 &times; 1 matrix whose only element is the same integer can be used interchangeably. </p> <p> An expression is one or more terms connected by "<span>+</span>" or "<span>-</span>" symbols. A term is one or more factors connected by "<span>*</span>" symbol. These operators ("<span>+</span>", "<span>-</span>", "<span>*</span>") are left associative. </p> <p> A factor is either a primary expression (primary) or a "<span>-</span>" symbol followed by a factor. This unary operator "<span>-</span>" is right associative. </p> <p> The meaning of operators are the same as those in the ordinary arithmetic on matrices: Denoting matrices by <i>A</i> and <i>B</i>, <i>A</i> + <i>B</i>, <i>A</i> - <i>B</i>, <i>A</i> * <i>B</i>, and -A are defined as the matrix sum, difference, product, and negation. The sizes of <i>A</i> and <i>B</i> should be the same for addition and subtraction. The number of columns of <i>A</i> and the number of rows of <i>B</i> should be the same for multiplication. </p> <p> Note that all the operators +, -, * and unary - represent computations of addition, subtraction, multiplication and negation modulo <i>M</i> = 2<sup>15</sup> = 32768, respectively. Thus all the values are nonnegative integers between 0 and 32767, inclusive. For example, the result of an expression 2 - 3 should be 32767, instead of -1. </p> <p> <span>inum</span> is a non-negative decimal integer less than <i>M</i>. </p> <p> <span>var</span> represents the matrix that is assigned to the variable var in the most recent preceding assignment statement of the same variable. </p> <p> <span>matrix</span> represents a mathematical matrix similar to a 2-dimensional array whose elements are integers. It is denoted by a <span>row-seq</span> with a pair of enclosing square brackets. <span>row-seq</span> represents a sequence of rows, adjacent two of which are separated by a semicolon. row represents a sequence of expressions, adjacent two of which are separated by a space character. </p> <p> For example, <span>[1 2 3;4 5 6]</span> represents a matrix <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_matrixCalculatorE1" valign="middle">. The first row has three integers separated by two space characters, i.e. "1 2 3". The second row has three integers, i.e. "4 5 6". Here, the <span>row-seq</span> consists of the two rows separated by a semicolon. The matrix is denoted by the <span>row-seq</span> with a pair of square brackets. </p> <p> Note that elements of a row may be matrices again. Thus the nested representation of a matrix may appear. The number of rows of the value of each expression of a row should be the same, and the number of columns of the value of each row of a <span>row-seq</span> should be the same. </p> <p> For example, a matrix represented by </p> <pre> [[1 2 3;4 5 6] [7 8;9 10] [11;12];13 14 15 16 17 18] </pre> <p> is <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_matrixCalculatorE2" valign="middle"> The sizes of matrices should be consistent, as mentioned above, in order to form a well-formed matrix as the result. For example, <span>[[1 2;3 4] [5;6;7];6 7 8]</span> is not consistent since the first row "<span>[1 2;3 4] [5;6;7]</span>" has two matrices (2 &times; 2 and 3 &times; 1) whose numbers of rows are different. <span>[1 2;3 4 5]</span> is not consistent since the number of columns of two rows are different. </p> <p> The multiplication of 1 &times; 1 matrix and <i>m</i> &times; <i>n</i> matrix is well-defined for arbitrary <i>m</i> &gt; 0 and <i>n</i> &gt; 0, since a 1 &times; 1 matrices can be regarded as a scalar integer. For example, <span>2*[1 2;3 4]</span> and <span>[1 2;3 4]*3</span> represent the products of a scalar and a matrix <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_matrixCalculatorE3" valign="middle"> and <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_matrixCalculatorE4" valign="middle">. <span>[2]*[1 2;3 4]</span> and <span>[1 2;3 4]*[3]</span> are also well-defined similarly. </p> <p> An indexed-primary is a primary expression followed by two expressions as indices. The first index is 1 &times; <i>k</i> integer matrix denoted by (<i>i</i><sub>1</sub> <i>i</i><sub>2</sub> ... <i>i<sub>k</sub></i>), and the second index is 1 &times; <i>l</i> integer matrix denoted by (<i>j</i><sub>1</sub> <i>j</i><sub>2</sub> ... <i>j<sub>l</sub></i>). The two indices specify the submatrix extracted from the matrix which is the value of the preceding primary expression. The size of the submatrix is <i>k</i> &times; <i>l</i> and whose (<i>a</i>, <i>b</i>)-element is the (<i>i<sub>a</sub></i>, <i>j<sub>b</sub></i>)-element of the value of the preceding primary expression. The way of indexing is one-origin, i.e., the first element is indexed by 1. </p> <p> For example, the value of <span>([1 2;3 4]+[3 0;0 2])([1],[2])</span> is equal to 2, since the value of its primary expression is a matrix <span>[4 2;3 6]</span>, and the first index <span>[1]</span> and the second <span>[2]</span> indicate the (1, 2)-element of the matrix. The same integer may appear twice or more in an index matrix, e.g., the first index matrix of an expression <span>[1 2;3 4]([2 1 1],[2 1])</span> is <span>[2 1 1]</span>, which has two 1's. Its value is <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_matrixCalculatorE5" valign="middle">. </p> <p> A <span>transposed-primary</span> is a primary expression followed by a single quote symbol ("<span>'</span>"), which indicates the transpose operation. The transposed matrix of an <i>m</i> &times; <i>n</i> matrix <i>A</i> = (<i>a<sub>ij</sub></i>) (<i>i</i> = 1, ..., <i>m</i> and <i>j</i> = 1, ... , <i>n</i>) is the <i>n</i> &times; <i>m</i> matrix <i>B</i> = (<i>b<sub>ij</sub></i>) (<i>i</i> = 1, ... , <i>n</i> and <i>j</i> = 1, ... , <i>m</i>), where <i>b<sub>ij</sub></i> = <i>a<sub>ji</sub></i>. For example, the value of <span>[1 2;3 4]'</span> is <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_matrixCalculatorE6" valign="middle">. </p> <H2>Input</H2> <p> The input consists of multiple datasets, followed by a line containing a zero. Each dataset has the following format. </p> <p> <i>n</i><br> <i>program</i><br> </p> <p> <i>n</i> is a positive integer, which is followed by a program that is a sequence of single or multiple lines each of which is an assignment statement whose syntax is defined in Table J.1. <i>n</i> indicates the number of the assignment statements in the program. All the values of vars are undefined at the beginning of a program. </p> <p> You can assume the following: </p> <ul> <li> 1 &le; <i>n</i> &le; 10,</li> <li> the number of characters in a line does not exceed 80 (excluding a newline),</li> <li>there are no syntax errors and semantic errors (e.g., reference of undefined <span>var</span>),</li> <li> the number of rows of matrices appearing in the computations does not exceed 100, and</li> <li> the number of columns of matrices appearing in the computations does not exceed 100.</li> </ul> <H2>Output</H2> <p> For each dataset, the value of the expression of each assignment statement of the program should be printed in the same order. All the values should be printed as non-negative integers less than <i>M</i>. </p> <p> When the value is an <i>m</i> &times; <i>n</i> matrix <i>A</i> = (<i>a<sub>ij</sub></i>) (<i>i</i> = 1, ... ,<i>m</i> and <i>j</i> = 1, ... , <i>n</i>), <i>m</i> lines should be printed. In the <i>k</i>-th line (1 &le; <i>k</i> &le; <i>m</i>), integers of the <i>k</i>-th row, i.e., <i>a</i><sub><i>k</i>1</sub>, ... , <i>a</i><sub><i>kn</i></sub>, should be printed separated by a space. </p> <p> After the last value of a dataset is printed, a line containing five minus symbols '<span>-----</span>' should be printed for human readability. </p> <p> The output should not contain any other extra characters. </p> <H2>Sample Input</H2> <pre> 1 A=[1 2 3;4 5 6]. 1 A=[[1 2 3;4 5 6] [7 8;9 10] [11;12];13 14 15 16 17 18]. 3 B=[3 -2 1;-9 8 7]. C=([1 2 3;4 5 6]+B)(2,3). D=([1 2 3;4 5 6]+B)([1 2],[2 3]). 5 A=2*[1 2;-3 4]'. B=A([2 1 2],[2 1]). A=[1 2;3 4]*3. A=[2]*[1 2;3 4]. A=[1 2;3 4]*[3]. 2 A=[11 12 13;0 22 23;0 0 33]. A=[A A';--A''' A]. 2 A=[1 -1 1;1 1 -1;-1 1 1]*3. A=[A -A+-A;-A'([3 2 1],[3 2 1]) -A']. 1 A=1([1 1 1],[1 1 1 1]). 3 A=[1 2 -3;4 -5 6;-7 8 9]. B=A([3 1 2],[2 1 3]). C=A*B-B*A+-A*-B-B*-A. 3 A=[1 2 3 4 5]. B=A'*A. C=B([1 5],[5 1]). 3 A=[-11 12 13;21 -22 23;31 32 -33]. B=[1 0 0;0 1 0;0 0 1]. C=[(A-B) (A+B)*B (A+B)*(B-A)([1 1 1],[3 2 1]) [1 2 3;2 1 1;-1 2 1]*(A-B)]. 3 A=[11 12 13;0 22 23;0 0 33]. B=[1 2]. C=------A((((B))),B)(B,B)''''''. 2 A=1+[2]+[[3]]+[[[4]]]+2*[[[[5]]]]*3. B=[(-[([(-A)]+-A)])]. 8 A=[1 2;3 4]. B=[A A+[1 1;0 1]*4;A+[1 1;0 1]'*8 A+[1 1;0 1]''*12]. C=B([1],[1]). C=B([1],[1 2 3 4]). C=B([1 2 3 4],[1]). C=B([2 3],[2 3]). A=[1 2;1 2]. D=(A*-A+-A)'(A'(1,[1 2]),A'(2,[1 2])). 0 </pre> <H2>Output for the Sample Input</H2> <pre> 1 2 3 4 5 6 ----- 1 2 3 7 8 11 4 5 6 9 10 12 13 14 15 16 17 18 ----- 3 32766 1 32759 8 7 13 0 4 13 13 ----- 2 32762 4 8 8 4 32762 2 8 4 3 6 9 12 2 4 6 8 3 6 9 12 ----- 11 12 13 0 22 23 0 0 33 11 12 13 11 0 0 0 22 23 12 22 0 0 0 33 13 23 33 11 0 0 11 12 13 12 22 0 0 22 23 13 23 33 0 0 33 ----- 3 32765 3 3 3 32765 32765 3 3 3 32765 3 32762 6 32762 3 3 32765 32762 32762 6 32765 3 3 6 32762 32762 32765 3 32765 32765 32765 3 32765 32765 3 3 32765 32765 3 32765 32765 32765 3 32765 ----- 1 1 1 1 1 1 1 1 1 1 1 1 ----- 1 2 32765 4 32763 6 32761 8 9 8 32761 9 2 1 32765 32763 4 6 54 32734 32738 32752 32750 174 32598 186 32702 ----- 1 2 3 4 5 1 2 3 4 5 2 4 6 8 10 3 6 9 12 15 4 8 12 16 20 5 10 15 20 25 5 1 25 5 ----- 32757 12 13 21 32746 23 31 32 32735 1 0 0 0 1 0 0 0 1 32756 12 13 32758 12 13 32573 32588 180 123 62 32725 21 32745 23 21 32747 23 32469 32492 276 28 33 15 31 32 32734 31 32 32736 32365 32396 372 85 32742 32767 ----- 11 12 13 0 22 23 0 0 33 1 2 11 12 0 22 ----- 40 80 ----- 1 2 3 4 1 2 5 6 3 4 3 8 9 2 13 14 11 12 3 16 1 1 2 5 6 1 3 9 11 4 3 2 13 1 2 1 2 32764 32764 32764 32764 ----- </pre>
p01781
<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>B - Cube Coloring</h2> <h3>Problem Statement</h3> <p> Great painter Cubic is famous for using cubes for his art. Now, he is engaged in a new work of art. He tries to form an $X \times Y \times Z$ rectangular parallelepiped by arranging and piling up many $1 \times 1 \times 1$ cubes such that the adjacent surfaces of cubes are fully shared. </p> <p> Of course, he won't finish his work only arranging and piling up cubes. The position of each cube is denoted by $(0,0,0)$ through $(X-1,Y-1,Z-1)$ as by the ordinary coordinate system, and Cubic calls the cube $(A,B,C)$ the <i>origin cube</i>. Then, he paints a pattern on the rectangular parallelepiped with different colors according to the distance between each cube and the origin cube. He paints all cubes regardless of whether or not a cube is visible externally. This is his artistic policy. He uses <i>Manhattan distance</i> as the distance between cubes. The Manhattan distance between two cubes $(x_1,y_1,z_1)$ and $(x_2,y_2,z_2)$ is defined as $|x_1-x_2| + |y_1-y_2| + |z_1-z_2|$. </p> <p> On the current work, Cubic decides to use $N$ colors, which are numbered from $1$ to $N$. He paints a cube with the $(i+1)$-th color if the distance $D$ between the cube and the origin cube satisfies $D \equiv i \pmod{N}$. </p> <p> Cubic wants to estimate the consumption of each color in order to prepare for the current work. He asks a great programmer, you, to write a program calculating the number of cubes that will be painted by each color. </p> <h3>Input</h3> <p> The input contains seven integers $X$, $Y$, $Z$, $A$, $B$, $C$, and $N$. All integers are in one line and separated by a single space. Three integers $X$, $Y$, and $Z$ ($1 \leq X, Y, Z \leq 10^6$) represent the length of each side of the rectangular parallelepiped that Cubic tries to form. Three integers $A$, $B$, and $C$ ($0 \leq A \lt X$, $0 \leq B \lt Y$, $0 \leq C \lt Z$) represent the position of the origin cube. The number of kinds of colors is denoted by $N$ ($1 \leq N \leq 1{,}000$). </p> <h3>Output</h3> <p> The output contains $N$ integers in one line. The $i$-th integer ($1 \leq i \leq N$) represents the number of the cubes that will be painted by the $i$-th color. All integers must be separated by a single space. </p> <h3>Sample Input 1</h3> <pre>2 2 2 0 0 0 5</pre> <h3>Output for the Sample Input 1</h3> <pre>1 3 3 1 0</pre> <h3>Sample Input 2</h3> <pre>4 3 3 1 1 1 3</pre> <h3>Output for the Sample Input 2</h3> <pre>13 10 13</pre> <h3>Sample Input 3</h3> <pre>2000 2000 2000 1000 1000 1000 1</pre> <h3>Output for the Sample Input 3</h3> <pre>8000000000</pre>
p00939
<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 E Bringing Order to Disorder</h2> <p> A sequence of digits usually represents a number, but we may define an alternative interpretation. In this problem we define a new interpretation with the order relation $\prec$ among the digit sequences of the same length defined below. </p> <p> Let $s$ be a sequence of $n$ digits, $d_1d_2 ... d_n$, where each $d_i$ $(1 \leq i \leq n)$ is one of 0, 1, ... , and 9. Let sum($s$), prod($s$), and int($s$) be as follows:<br> <br> sum($s$) = $d_1 + d_2 + ... + d_n$<br> prod($s$) = $(d_1 + 1) \times (d_2 + 1) \times ... \times (d_n + 1)$<br> int($s$) = $d_1 \times 10^{n-1} + d_2 \times 10^{n-2} + ... + d_n \times 10^0$<br> <br> int($s$) is the integer the digit sequence $s$ represents with normal decimal interpretation. </p> <p> Let $s_1$ and $s_2$ be sequences of the same number of digits. Then $s_1 \prec s_2$ ($s_1$ is less than $s_2$) is satisfied if and only if one of the following conditions is satisfied. </p> <ol> <li> sum($s_1$) $<$ sum($s_2$)</li> <li> sum($s_1$) $=$ sum($s_2$) and prod($s_1$) $<$ prod($s_2$)</li> <li> sum($s_1$) $=$ sum($s_2$), prod($s_1$) $=$ prod($s_2$), and int($s_1$) $<$ int($s_2$)</li> </ol> <p> For 2-digit sequences, for instance, the following relations are satisfied.<br> <br> $00 \prec 01 \prec 10 \prec 02 \prec 20 \prec 11 \prec 03 \prec 30 \prec 12 \prec 21 \prec ... \prec 89 \prec 98 \prec 99$<br> </p> <p> Your task is, given an $n$-digit sequence $s$, to count up the number of $n$-digit sequences that are less than $s$ in the order $\prec$ defined above. </p> <h3>Input</h3> <p> The input consists of a single test case in a line.<br> <br> $d_1d_2 ... d_n$<br> <br> $n$ is a positive integer at most 14. Each of $d_1, d_2, ...,$ and $d_n$ is a digit. </p> <h3>Output</h3> <p> Print the number of the $n$-digit sequences less than $d_1d_2 ... d_n$ in the order defined above. </p> <h3>Sample Input 1</h3> <pre>20</pre> <h3>Sample Output 1</h3> <pre>4</pre> <h3>Sample Input 2</h3> <pre>020</pre> <h3>Sample Output 2</h3> <pre>5</pre> <h3>Sample Input 3</h3> <pre>118</pre> <h3>Sample Output 3</h3> <pre>245</pre> <h3>Sample Input 4</h3> <pre>11111111111111</pre> <h3>Sample Output 4</h3> <pre>40073759</pre> <h3>Sample Input 5</h3> <pre>99777222222211</pre> <h3>Sample Output 5</h3> <pre>23733362467675</pre>
p02904
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke has a permutation <var>(P_0,P_1,\cdots,P_{N-1})</var> of <var>(0,1,\cdots,N-1)</var>.</p> <p>Now, he will perform the following operation <strong>exactly once</strong>:</p> <ul> <li>Choose <var>K</var> consecutive elements in <var>P</var> and sort them in ascending order.</li> </ul> <p>Find the number of permutations that can be produced as <var>P</var> after the operation.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 200000</var></li> <li><var>2 \leq K \leq N</var></li> <li><var>0 \leq P_i \leq N-1</var></li> <li><var>P_0,P_1,\cdots,P_{N-1}</var> are all different.</li> <li>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_0</var> <var>P_1</var> <var>\cdots</var> <var>P_{N-1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of permutations that can be produced as <var>P</var> after the operation.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 3 0 2 1 4 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>Two permutations can be produced as <var>P</var> after the operation: <var>(0,1,2,4,3)</var> and <var>(0,2,1,3,4)</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 4 0 1 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 4 2 0 1 3 7 5 4 6 8 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>6 </pre></section> </div> </span>
p03616
<span class="lang-en"> <p>Score : <var>700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a sandglass consisting of two bulbs, bulb A and bulb B. These bulbs contain some amount of sand. When we put the sandglass, either bulb <var>A</var> or <var>B</var> lies on top of the other and becomes the <em>upper bulb</em>. The other bulb becomes the <em>lower bulb</em>.</p> <p>The sand drops from the upper bulb to the lower bulb at a rate of <var>1</var> gram per second. When the upper bulb no longer contains any sand, nothing happens.</p> <p>Initially at time <var>0</var>, bulb A is the upper bulb and contains <var>a</var> grams of sand; bulb B contains <var>X-a</var> grams of sand (for a total of <var>X</var> grams).</p> <p>We will turn over the sandglass at time <var>r_1,r_2,..,r_K</var>. Assume that this is an instantaneous action and takes no time. Here, time <var>t</var> refer to the time <var>t</var> seconds after time <var>0</var>.</p> <p>You are given <var>Q</var> queries. Each query is in the form of <var>(t_i,a_i)</var>. For each query, assume that <var>a=a_i</var> and find the amount of sand that would be contained in bulb A at time <var>t_i</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≤X≤10^9</var></li> <li><var>1≤K≤10^5</var></li> <li><var>1≤r_1&lt;r_2&lt; .. &lt;r_K≤10^9</var></li> <li><var>1≤Q≤10^5</var></li> <li><var>0≤t_1&lt;t_2&lt; .. &lt;t_Q≤10^9</var></li> <li><var>0≤a_i≤X (1≤i≤Q)</var></li> <li>All input values are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>X</var> <var>K</var> <var>r_1</var> <var>r_2</var> .. <var>r_K</var> <var>Q</var> <var>t_1</var> <var>a_1</var> <var>t_2</var> <var>a_2</var> <var>:</var> <var>t_Q</var> <var>a_Q</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>For each query, print the answer in its own line.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>180 3 60 120 180 3 30 90 61 1 180 180 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>60 1 120 </pre> <p>In the first query, <var>30</var> out of the initial <var>90</var> grams of sand will drop from bulb A, resulting in <var>60</var> grams. In the second query, the initial <var>1</var> gram of sand will drop from bulb A, and nothing will happen for the next <var>59</var> seconds. Then, we will turn over the sandglass, and <var>1</var> second after this, bulb <var>A</var> contains <var>1</var> gram of sand at the time in question.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>100 1 100000 4 0 100 90 100 100 100 101 100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>100 10 0 0 </pre> <p>In every query, the upper bulb initially contains <var>100</var> grams, and the question in time comes before we turn over the sandglass.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>100 5 48 141 231 314 425 7 0 19 50 98 143 30 231 55 342 0 365 100 600 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>19 52 91 10 58 42 100 </pre></section> </div> </span>
p02457
<h1>Set: Range Search</h1> <p> For a set $S$ of integers, perform a sequence of the following operations. Note that <u>each value in $S$ must be unique</u>. </p> <ul> <li>insert($x$): Insert $x$ to $S$ and report the number of elements in $S$ after the operation.</li> <li>find($x$): Report the number of $x$ in $S$ (0 or 1).</li> <li>delete($x$): Delete $x$ from $S$.</li> <li>dump($L$, $R$): Print elements $x$ in $S$ such that $L \leq x \leq R$.</li> </ul> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> $q$ $query_1$ $query_2$ : $query_q$ </pre> <p> Each query $query_i$ is given by </p> <pre> 0 $x$ </pre> <p>or</p> <pre> 1 $x$ </pre> <p>or</p> <pre> 2 $x$ </pre> <p>or</p> <pre> 3 $L$ $R$ </pre> <p> where the first digits <span>0</span>, <span>1</span>, <span>2</span> and <span>3</span> represent insert, find, delete and dump operations respectively. </p> <h2>Output</h2> <p> For each insert operation, print the number of elements in $S$.<br> For each find operation, print the number of specified elements in $S$.<br> For each dump operation, print the corresponding elements in ascending order. Print an element in a line. </p> <h2>Constraints</h2> <ul> <li>$1 \leq q \leq 200,000$</li> <li>$0 \leq x \leq 1,000,000,000$</li> <li>The total number of elements printed by dump operations does not exceed $1,000,000$</li> </ul> <h2>Sample Input 1</h2> <pre> 9 0 1 0 2 0 3 2 2 1 1 1 2 1 3 0 4 3 2 4 </pre> <h2>Sample Output 1</h2> <pre> 1 2 3 1 0 1 3 3 4 </pre>
p00190
<H1>11 パズル</H1> <p> 太郎君は 8 パズルが大得意で休み時間などにいつも友達に並び替えてもらって遊んでいます。そんなとき、友達から「もっと複雑なパズルは解ける?」と聞かれたのですが、他のパズルはやったことはありません。どうやらその友達は自作で 11 パズルを作っていたみたいです。そのパズルは以下のような形をしています。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_elevenPuzzle"> </center> <br/> <p> 11 パズルは 11 枚の正方形のカードと、図 1 のような形の枠を使って行います。最初に 11 枚のカードを枠に入れます。すると 2 カ所の空きスペースができますので、この空きスペースに隣接したカードを動かすことができます。これを繰り返し、カードをきれいに整列して、図 2 の完成型にすることが 11 パズルの目的です。 </p> <p> 太郎君はこのパズルに挑戦することにしました。ところが太郎君はこの 11 パズルをいとも簡単に解いてしまいました。そこで友達は「動かす数を一番少なくして解いてよ!」と無茶なことを言ってきました。太郎君は答えがわからないので、プログラムのできるあなたに 11 パズルを解くときの最小ステップ数を出すプログラムを作成してもらってから挑戦することにしました。このとき、2 カ所動かせるところがあるのですが、一つの数字を 1 スペース分移動させることを1ステップとして考えることとします。 </p> <p> 11 パズルの初期状態を入力とし、11 パズルを解くときの最小ステップ数を出力するプログラムを作成してください。ただし、パズルを解くときの最小ステップ数が 20 ステップより多くかかってしまう場合は、「NA」と出力してください。パズルの状態は、一行目の情報から順に入力されるものとし、数字の 0 は空きスペースを表します。例えば、図 1 の状態を表す入力は以下のようになります。 </p> <pre> 6 2 1 3 10 5 7 0 8 9 4 11 0 </pre> <H2>Input</H2> <p> 複数のデータセットの並びが入力として与えられます。入力の終わりは-1ひとつの行で示されます。 各データセットは以下の形式で与えられます。 </p> <pre> <var>p<sub>1</sub></var> <var>p<sub>2</sub></var> <var>p<sub>3</sub></var> <var>p<sub>4</sub></var> <var>p<sub>5</sub></var> <var>p<sub>6</sub></var> <var>p<sub>7</sub></var> <var>p<sub>8</sub></var> <var>p<sub>9</sub></var> <var>p<sub>10</sub></var> <var>p<sub>11</sub></var> <var>p<sub>12</sub></var> <var>p<sub>13</sub></var> </pre> <p> <var>i</var> 行目にパズルの <var>i</var> 行目の情報 <var>p<sub>i</sub></var> (0 &le; <var>p<sub>i</sub></var> &le; 11) が空白区切りで与えられます。 </p> <p> データセットの数は 100 を超えません。 </p> <H2>Output</H2> <p> データセット毎に、最小ステップ数または NA を1行に出力します。 </p> <H2>Sample Input</H2> <pre> 2 1 0 3 4 5 6 7 8 9 0 11 10 0 1 2 3 4 5 6 7 8 9 10 11 0 0 11 10 9 8 7 6 5 4 3 2 1 0 -1 </pre> <H2>Output for the Sample Input</H2> <pre> 2 0 NA </pre>
p02007
<h1>Problem D. Prefix Suffix Search</h1> <!-- Time Limit: 3 sec Memory Limit: 512 MB --> <p> As an English learner, sometimes you cannot remember the entire spelling of English words perfectly, but you can only remember their prefixes and suffixes. For example, you may want to use a word which begins with '<span>appr</span>' and ends with '<span>iate</span>', but forget the middle part of the word. It may be '<span>appreciate</span>', '<span>appropriate</span>', or something like them. </p> <p> By using an ordinary dictionary, you can look up words beginning with a certain prefix, but it is inconvenient for further filtering words ending with a certain suffix. Thus it is helpful to achieve dictionary functionality which can be used for finding words with a given prefix and suffix. In the beginning, let's count the number of such words instead of explicitly listing them. </p> <p> More formally, you are given a list of $N$ words. Next, you are given $Q$ queries consisting of two strings. Your task is to write a program which outputs the number of words with the prefix and suffix for each query in the given list. </p> <h2>Input</h2> <p> The input consists of a single test case in the following format. </p> <pre> $N$ $Q$ $w_1$ $...$ $w_N$ $p_1$ $s_1$ $...$ $p_Q$ $s_Q$ </pre> <p> The first line contains two integers $N$ and $Q$, where $N$ ($1 \leq N \leq 10^5$) is the number of words in the list, and $Q$ ($1 \leq Q \leq 10^5$) is the number of queries. The $i$-th line of the following $N$ lines contains a string $w_i$. The $i$-th of the following $Q$ lines contains two strings $p_i$ and $s_i$, which are a prefix and suffix of words to be searched, respectively. </p> <p> You can assume the followings: </p> <ul> <li>All the strings in an input are non-empty and consist only of lowercase English letters.</li> <li>The total length of input strings does not exceed $2,500,000$.</li> <li>Words in the given list are unique: $w_i \ne w_j$ if $i \ne j$.</li> <li>Pairs of a prefix and suffix are unique: $(p_i, s_i) \ne (p_j, s_j)$ if $i \ne j$.</li> </ul> <h2>Output</h2> <p> For each query, output the number of words with a given prefix and suffix in the given list per a line. </p> <h2>Examples</h2> <h2>Sample Input 1</h2> <pre> 6 7 appreciate appropriate acceptance ace acm acetylene appr iate a e a a ac ce ace e acceptance acceptance no match </pre> <h2>Output for Sample Input 1</h2> <pre> 2 5 0 2 2 1 0 </pre> <h2>Sample Input 2</h2> <pre> 5 5 d dd ddd dddd ddddd d d dd dd ddd ddd d dddd ddddd dd </pre> <h2>Output for Sample Input 2</h2> <pre> 5 4 3 2 1 </pre> <h2>Sample Input 3</h2> <pre> 7 4 connected disconnected graph directed diameter distance minor c ed di ed dis ed dis e </pre> <h2>Output for Sample Input 3</h2> <pre> 1 2 1 1 </pre>
p00485
<H1> JOI 国の買い物事情(Shopping in JOI Kingdom) </H1> <p> JOI 国には<i>N</i> 個の町があり,それらの間は<i>M</i> 本の双方向に通行可能な道路で結ばれている.<i>K</i> 個の町にはショッピングモールがあり,国民は道路を通ってそれらの町のいずれかに行き買い物をする. </p> <p> 家の場所によっては,買い物に行くために長い距離を移動する必要があり,それは非常に不便である.国王はこの実情を把握するため,ショッピングモールのある町までの最短距離が家の場所によってどれだけ長くなりうるのかを調べることにした.家は道路の途中に建てられることもあるので(入力例1 の説明を参照),この調査は非常に大変である.そこで国王は,優秀なプログラマーであるあなたに,調査を行うプログラムの作成を依頼した. </p> <h2>課題</h2> <p> 道路の情報とショッピングモールのある町の情報が与えられるとき,ショッピングモールのある町からもっとも遠い道路上の点(端点も含む) までの距離を求めるプログラムを作成せよ.町の中を移動するのにかかる距離は無視してよい. </p> <h2>制限</h2> <p> 2 &le; <i>N</i> &le; 3000 &nbsp;&nbsp;&nbsp; JOI 国の町の個数<br> 1 &le; <i>M</i> &le; 100000 = 10<sup>5</sup> &nbsp;&nbsp;&nbsp; JOI 国の道路の本数<br> 1 &le; <i>K</i> &le; <i>N</i> &nbsp;&nbsp;&nbsp; ショッピングモールがある町の個数<br> 1 &le; <i>l<sub>i</sub></i> &le; 1000 &nbsp;&nbsp;&nbsp; <i>i</i> 番目の道路の長さ<br> </p> <h2>入力</h2> <p> 標準入力から以下の入力を読み込め. </p> <ul> <li> 1 行目には整数<i>N</i>, <i>M</i>, <i>K</i> が空白区切りで書かれている.<i>N</i> はJOI 国の町の個数を,<i>M</i> はJOI 国の道路の本数を,i>K</i> はショッピングモールがある町の個数をそれぞれ表す.町には1, 2, ..., <i>N</i> の番号がつけられている. </li> <li> 続く<i>M</i> 行は道路の情報を表す.<i>i</i> + 1 行目(1 &le; <i>i</i> &le; <i>M</i>) には整数<i>a<sub>i</sub></i>, <i>b<sub>i</sub></i>, <i>l<sub>i</sub></i> (1 &le; <i>a<sub>i</sub></i> &le; <i>N</i>, 1 &le; <i>b<sub>i</sub></i> &le; <i>N</i>, 1 &le; <i>l<sub>i</sub></i> &le; 1000) が空白区切りで書かれている.これは,<i>i</i> 本目の道路が町<i>a<sub>i</sub></i> と町<i>b<sub>i</sub></i> を結んでおり,長さが<i>l<sub>i</sub></i> であることを表す.道路の両端が同じ町であることはない.また,任意の2 つの町<i>p</i>, <i>q</i> に対し,<i>p</i>と<i>q</i> を結ぶ道路は2 本以上存在しない.どの町からどの町へもいくつかの道路をたどって行くことができる. <li>続く<i>K</i> 行はショッピングモールの情報を表す.<i>i</i>+<i>M</i>+1 行目(1 &le; <i>i</i> &le; <i>K</i>) には1 つの整数<i>s<sub>i</sub></i> (1 &le; <i>s<sub>i</sub></i> &le; <i>N</i>)が書かれている.これは町<i>s<sub>i</sub></i> にショッピングモールがあることを表す.<i>s</i><sub>1</sub>, ..., <i>s<sub>K</sub></i> の中に同じ値が2 回以上現れることはない. </ul> <h2>出力</h2> <p> 標準出力に,ショッピングモールのある町までの最短距離の最大値の小数点以下を四捨五入した整数1 つを出力せよ. </p> <h2>採点基準</h2> <p> 採点用データのうち,配点の40% 分については,<i>K</i> = 1 を満たす. </p> <h2>入出力の例</h2> <h3>入力例1</h3> <pre> 3 3 1 1 2 1 2 3 1 3 1 1 1 </pre> <h3>出力例1</h3> <pre> 2 </pre> <p> 入力例1 は次のような町を表す.道路の長さはすべて1 である.ショッピングモールは町1 にしかない. </p> <p> ショッピングモールのある町までもっとも遠い点は,町2 と町3 を結ぶ道路上の,町2 から距離0.5 の位置にある点であり,ショッピングモールのある町までの距離は1.5 である.よって,それを四捨五入した値である2 を出力する. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_shoppingInJOIKingdom"> </center> <br> <h3>入力例2</h3> <pre> 4 5 2 1 2 4 1 3 1 2 3 2 2 4 2 3 4 1 2 4 </pre> <h3>出力例2</h3> <pre> 3 </pre> <div class="source"> <p class="source"> 問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。 </p> </div>
p02142
<h1>Problem F: Timing</h1> <h2>Problem</h2> <p>$N$頂点$M$辺の無向グラフが与えられる。各頂点には相異なる$1$から$N$までの番号が定められている。あなたは時刻$0$に頂点$S$を出発し、頂点$G$まで移動したい。各辺にはパラメータ$a, b$が設定されていて、時刻$t$にその辺の片側の頂点から出発した場合、もう片側の頂点には時刻$t+ceil\left(\cfrac{b}{t+a}\right)$に到達することがわかっている。ここで、$ceil(x)$は$x$以上の最小の整数を表す。また、各頂点では任意の非負整数時間を余分に消費することができる。つまり、時刻$t$にある頂点にいるとき、任意の非負整数$k$を選び、時刻$t+k$になるまで待機することができる。最速最強アルゴリズマーを目指すあなたは、頂点$S$から頂点$G$まで移動するためにかかる時間の最小値を求めたくなった。</p> <h2>Input</h2> <p>入力は以下の形式で与えられる。</p> <pre> $N$ $M$ $S$ $G$ $U_1$ $V_1$ $A_1$ $B_1$ $U_2$ $V_2$ $A_2$ $B_2$ : $U_M$ $V_M$ $A_M$ $B_M$ </pre> <p> $1$行目に、与えられるグラフの頂点数$N$、辺数$M$、スタートの頂点番号$S$、ゴールの頂点番号$G$が空白区切りで与えられる。<br> 続く$M$行に、各辺の情報が空白区切りで与えられる。$i$行目の情報は、頂点$U_i$と頂点$V_i$の間に$(a, b) = (A_i, B_i)$であるような辺が存在することを表す。 </p> <h2>Constraints</h2> <p>入力は以下の条件を満たす。</p> <ul> <li>$1 \le N, M \le 2 \times 10^5$</li> <li>$1 \le S, G \le N$, $S \neq G$</li> <li>$1 \le U_i, V_i \le N$, $U_i \neq V_i (1 \le i \le M)$</li> <li>$1 \le A_i, B_i \le 10^{15} (1 \le i \le M)$</li> <li>与えられる入力は全て整数である</li> </ul> <h2>Output</h2> <p>頂点$S$から頂点$G$まで移動するためにかかる時間の最小値を出力せよ。頂点$S$から頂点$G$に移動できない場合は、代わりに$-1$を出力せよ。</p> <h2>Sample Input 1</h2> <pre> 2 1 1 2 1 2 1 100 </pre> <h2>Sample Output 1</h2> <pre> 19 </pre> 頂点$1$で時間を$9$消費し、時刻$9$に辺$1$を使うと、辺の所要時間は$ceil\left(\cfrac{100}{10}\right) = 10$となり、時刻$19$に頂点$2$に到達できる。これが最短である。 <h2>Sample Input 2</h2> <pre> 2 1 1 2 1 2 50 100 </pre> <h2>Sample Output 2</h2> <pre> 2 </pre> 時刻$0$に辺$1$を使うのが最適である。 <h2>Sample Input 3</h2> <pre> 3 1 1 3 1 2 1 1 </pre> <h2>Sample Output 3</h2> <pre> -1 </pre> 頂点$S$から頂点$G$に移動できない場合もある。 <h2>Sample Input 4</h2> <pre> 3 3 1 3 1 2 1 1 2 3 1 6 2 3 50 100 </pre> <h2>Sample Output 4</h2> <pre> 3 </pre> <h2>Sample Input 5</h2> <pre> 3 3 1 3 1 2 10 100 2 3 1 6 2 3 50 100 </pre> <h2>Sample Output 5</h2> <pre> 11 </pre>
p03303
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a string <var>S</var> consisting of lowercase English letters. We will write down this string, starting a new line after every <var>w</var> letters. Print the string obtained by concatenating the letters at the beginnings of these lines from top to bottom.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq w \leq |S| \leq 1000</var></li> <li><var>S</var> consists of lowercase English letters.</li> <li><var>w</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>S</var> <var>w</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the desired string in one line.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>abcdefgh 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>adg </pre> <p>When we write down <code>abcdefgh</code>, starting a new line after every three letters, we get the following:</p> <p>abc<br/> def<br/> gh</p> <p>Concatenating the letters at the beginnings of these lines, we obtain <code>adg</code>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>lllll 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>lllll </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>souuundhound 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>suudon </pre></section> </div> </span>
p01294
<H1><font color="#000">Problem B:</font> For the Peace</H1> <p> This is a story of a world somewhere far from the earth. In this world, the land is parted into a number of countries ruled by empires. This world is not very peaceful: they have been involved in army race. </p> <p> They are competing in production of missiles in particular. Nevertheless, no countries have started wars for years. Actually they have a reason they can’t get into wars - they have missiles much more than enough to destroy the entire world. Once a war would begin among countries, none of them could remain. </p> <p> These missiles have given nothing but scare to people. The competition has caused big financial and psychological pressure to countries. People have been tired. Military have been tired. Even empires have been tired. No one wishes to keep on missile production. </p> <p> So empires and diplomats of all countries held meetings quite a few times toward renouncement of missiles and abandon of further production. The meetings were quite difficult as they have different matters. However, they overcame such difficulties and finally came to the agreement of a treaty. The points include: </p> <ul> <li> Each country will dispose all the missiles of their possession by a certain date.</li> <li> The war potential should not be different by greater than a certain amount <i>d</i> among all countries.</li> </ul> <p> Let us describe more details on the second point. Each missile has its capability, which represents how much it can destroy the target. The war potential of each country is measured simply by the sum of capability over missiles possessed by that country. The treaty requires the difference to be not greater than <i>d</i> between the maximum and minimum potential of all the countries. </p> <p> Unfortunately, it is not clear whether this treaty is feasible. Every country is going to dispose their missiles only in the order of time they were produced, from the oldest to the newest. Some missiles have huge capability, and disposal of them may cause unbalance in potential. </p> <p> Your task is to write a program to see this feasibility. </p> <H2>Input</H2> <p> The input is a sequence of datasets. Each dataset is given in the following format: </p> <p> <i>n d</i><br> <i>m</i><sub>1</sub> <i>c</i><sub>1,1</sub> ... <i>c</i><sub>1,<i>m</i><sub>1</sub></sub><br> ...<br> <i>m<sub>n</sub></i> <i>c</i><sub><i>n</i>,1</sub> ... <i>c</i><sub><i>n</i>,<i>m</i><sub><i>n</i></sub></sub><br> </p> <p> The first line contains two positive integers <i>n</i> and <i>d</i>, the number of countries and the tolerated difference of potential (<i>n</i> &le; 100, <i>d</i> &le; 1000). Then <i>n</i> lines follow. The <i>i</i>-th line begins with a non-negative integer <i>m<sub>i</sub></i>, the number of the missiles possessed by the <i>i</i>-th country. It is followed by a sequence of <i>m<sub>i</sub></i> positive integers. The <i>j</i>-th integer <i>c</i><sub><i>i</i>,<i>j</i></sub> represents the capability of the <i>j</i>-th newest missile of the <i>i</i>-th country (<i>c</i><sub><i>i</i>,<i>j</i></sub> &le; 1000). These integers are separated by a single space. Note that the country disposes their missiles in the reverse order of the given sequence. </p> <p> The number of missiles is not greater than 10000. Also, you may assume the difference between the maximum and minimum potential does not exceed <i>d</i> in any dataset. </p> <p> The input is terminated by a line with two zeros. This line should not be processed. </p> <H2>Output</H2> <p> For each dataset, print a single line. If they can dispose all their missiles according to the treaty, print "<span>Yes</span>" (without quotes). Otherwise, print "<span>No</span>". </p> <p> Note that the judge is performed in a <i>case-sensitive</i> manner. No extra space or character is allowed. </p> <H2>Sample Input</H2> <pre> 3 3 3 4 1 1 2 1 5 2 3 3 3 3 3 2 3 1 2 1 5 2 3 3 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> Yes No </pre>
p02841
<span class="lang-en"> <p>Score: <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>In this problem, a date is written as Y-M-D. For example, <var>2019</var>-<var>11</var>-<var>30</var> means November <var>30</var>, <var>2019</var>.</p> <p>Integers <var>M_1, D_1, M_2</var>, and <var>D_2</var> will be given as input.<br/> It is known that the date <var>2019</var>-<var>M_2</var>-<var>D_2</var> follows <var>2019</var>-<var>M_1</var>-<var>D_1</var>.<br/> Determine whether the date <var>2019</var>-<var>M_1</var>-<var>D_1</var> is the last day of a month.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li>Both <var>2019</var>-<var>M_1</var>-<var>D_1</var> and <var>2019</var>-<var>M_2</var>-<var>D_2</var> are valid dates in the Gregorian calendar.</li> <li>The date <var>2019</var>-<var>M_2</var>-<var>D_2</var> follows <var>2019</var>-<var>M_1</var>-<var>D_1</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> <p>Input is given from Standard Input in the following format:</p> <pre><var>M_1</var> <var>D_1</var> <var>M_2</var> <var>D_2</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>If the date <var>2019</var>-<var>M_1</var>-<var>D_1</var> is the last day of a month, print <code>1</code>; otherwise, print <code>0</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>11 16 11 17 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>0 </pre> <p>November <var>16</var> is not the last day of a month.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>11 30 12 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 </pre> <p>November <var>30</var> is the last day of November.</p></section> </div> </span>
p03753
<span class="lang-en lang-child hidden-lang"> <div id="task-statement"> Max Score: <var>500</var> Points <br/> <section> <h3>Problem Statement</h3> We have a grid with <var>n</var> rows and <var>7</var> columns. We call it a calendar. The cell at <var>i</var>-th row and <var>j</var>-th column is denoted <var>(i, j)</var>. <br/> <div align="left" class="img-nocaption"> <img src="https://atcoder.jp/img/s8pc-4/1bef402eeaddb846eb2ea4d386a1ed3d.png" width="500"/> </div> Initially, each cell at <var>(i, j)</var> contains the integer <var>7i + j - 8</var>, and each cell is white. <br/> <br/> Snuke likes painting, so he decided integer <var>m</var>, and did <var>q</var> operations with a calendar. <br/> ・In <var>i</var>-th operation, he paint black on the cell in which an integer is written such remainder of dividing by <var>m</var> is <var>a_i</var>. <br/> <br/> Please count the number of connected white parts. <br/> Note that if two adjacent cells are white, the cells belong to the same connected part. <br/> </section> </div> <div class="io-style"> <div class="part"> <section> <h3>Input Format</h3> The input format is following:<br/> <pre> <var>n</var> <var>m</var> <var>q</var> <var>a_1</var> <var>a_2</var> ... <var>a_q</var> </pre> </section> </div> <div class="part"> <section> <h3>Output Format</h3> Print the number of connected part in one line.<br/> </section> <section> <h3>Constraints</h3> <ul> <li><var>n</var> ≤ <var>10^{12}</var></li> <li><var>7n</var> is divisible by <var>m</var>.</li> <li>1 ≤ <var>q</var> ≤ <var>m</var> ≤ <var>10^5</var></li> <li><var>0</var> ≤ <var>a_1</var> &lt; <var>a_2</var> &lt; ... &lt; <var>a_q</var> &lt; m</li> </ul> </section> <section> <h3>Scoring</h3> Subtask 1 [<var>100</var> points] <br/> <ul> <li><var>n</var> ≤ <var>100000</var>.</li> </ul> Subtask 2 [<var>90</var> points] <br/> <ul> <li><var>m</var> is divisible by <var>7</var>.</li> <li><var>a_{i + 1} - a_i = 1</var>.</li> </ul> Subtask 3 [<var>200</var> points] <br/> <ul> <li><var>m</var> is divisible by <var>7</var>.</li> </ul> Subtask 4 [<var>110</var> points] <br/> <ul> <li>There are no additional constraints.</li> </ul> </section> </div> <div class="part"> <section> <h3>Sample Input 1</h3> <pre> 7 7 3 1 3 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3> <pre> 4 </pre> The calendar looks like this: <br/> <!-- ここにカレンダーの画像を貼る --> <div align="left" class="img-nocaption"> <img src="https://atcoder.jp/img/s8pc-4/b7ae283b5c0a566376d05aeff63b100a.png" width="500"/> </div> </section> </div> <div class="part"> <section> <h3>Sample Input 2</h3> <pre> 10 14 8 5 6 7 8 9 10 11 12 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3> <pre> 10 </pre> The calendar looks like this: <br/> <div align="left" class="img-nocaption"> <img src="https://atcoder.jp/img/s8pc-4/42a03c02d737a1c97005360832707eaa.png" width="500"/> </div> </section> </div> </div> </span>
p02791
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>Given is a permutation <var>P_1, \ldots, P_N</var> of <var>1, \ldots, N</var>. Find the number of integers <var>i</var> <var>(1 \leq i \leq N)</var> that satisfy the following condition: </p> <ul> <li>For any integer <var>j</var> <var>(1 \leq j \leq i)</var>, <var>P_i \leq P_j</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>P_1, \ldots, P_N</var> is a permutation of <var>1, \ldots, 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>P_1</var> <var>...</var> <var>P_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print the number of integers <var>i</var> that satisfy the condition.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 4 2 5 1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p><var>i=1</var>, <var>2</var>, and <var>4</var> satisfy the condition, but <var>i=3</var> does not - for example, <var>P_i &gt; P_j</var> holds for <var>j = 1</var>.<br/> Similarly, <var>i=5</var> does not satisfy the condition, either. Thus, there are three integers that satisfy the condition.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 4 3 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>4 </pre> <p>All integers <var>i</var> <var>(1 \leq i \leq N)</var> satisfy the condition.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>6 1 2 3 4 5 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 </pre> <p>Only <var>i=1</var> satisfies the condition.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>8 5 7 4 2 6 8 1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>4 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 5</h3><pre>1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 5</h3><pre>1 </pre></section> </div> </span>
p03883
<span class="lang-en"> <p>Score : <var>1000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><style> #nck { width: 30px; height: auto; } </style> <p>Snuke received <var>N</var> intervals as a birthday present. The <var>i</var>-th interval was <var>[-L_i, R_i]</var>. It is guaranteed that both <var>L_i</var> and <var>R_i</var> are positive. In other words, the origin is strictly inside each interval.</p> <p>Snuke doesn't like overlapping intervals, so he decided to move some intervals. For any positive integer <var>d</var>, if he pays <var>d</var> dollars, he can choose one of the intervals and move it by the distance of <var>d</var>. That is, if the chosen segment is <var>[a, b]</var>, he can change it to either <var>[a+d, b+d]</var> or <var>[a-d, b-d]</var>.</p> <p>He can repeat this type of operation arbitrary number of times. After the operations, the intervals must be pairwise disjoint (however, they may touch at a point). Formally, for any two intervals, the length of the intersection must be zero.</p> <p>Compute the minimum cost required to achieve his goal.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≤ N ≤ 5000</var></li> <li><var>1 ≤ L_i, R_i ≤ 10^9</var></li> <li>All values in the input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>L_1</var> <var>R_1</var> : <var>L_N</var> <var>R_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum cost required to achieve his goal.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 2 7 2 5 4 1 7 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>22 </pre> <p>One optimal solution is as follows:</p> <ul> <li>Move the interval <var>[-2, 7]</var> to <var>[6, 15]</var> with <var>8</var> dollars</li> <li>Move the interval <var>[-2, 5]</var> to <var>[-1, 6]</var> with <var>1</var> dollars</li> <li>Move the interval <var>[-4, 1]</var> to <var>[-6, -1]</var> with <var>2</var> dollars</li> <li>Move the interval <var>[-7, 5]</var> to <var>[-18, -6]</var> with <var>11</var> dollars</li> </ul> <p>The total cost is <var>8 + 1 + 2 + 11 = 22</var> dollars.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>20 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>7337 </pre></section> </div> </span>
p00256
<H1>マヤの大予言</H1> <p> 真也君はテレビで「マヤの大予言!2012年で世界が終る?」という番組を見ました。結局、世界が終るかどうかはよくわかりませんでしたが、番組で紹介されていたマヤの「長期暦」という暦に興味を持ちました。その番組では以下のような説明をしていました。 </p> <table cellpadding="18" cellspacing="18"> <tr> <td> <p> マヤ長期暦は、右の表のような単位からなる、全部で13バクトゥン(187万2000日)で構成される非常に長い暦である。ある計算法では、この暦は紀元前3114年8月11日に始まり2012年12月21日に終わると考えられていて、このため今年の12月21日で世界が終るという説が唱えられている。しかし、13バクトゥンで1サイクルとなり、今の暦が終わったら新しいサイクルに入るだけという考えもある。 </p> </td> <td width="200" style="border:solid 1px #000000"> 1キン=1日<br/> 1ウィナル=20キン<br/> 1トゥン=18ウィナル<br/> 1カトゥン=20トゥン<br/> 1バクトゥン=20カトゥン </td> <td>&nbsp;</td> </tr> </table> <br/> <p> 「ぼくの二十歳の誕生日はマヤ暦だと何日になるのかな?」真也君はいろいろな日をマヤ長期暦で表してみたくなりました。 </p> <p> では、真也君の代わりに、西暦とマヤ長期暦とを相互変換するプログラムを作成してください。 </p> <h2>入力</h2> <p> 入力は複数のデータセットからなる。入力の終わりは#1つの行で示される。各データセットは以下の形式で与えられる。 </p> <pre> b.ka.t.w.ki </pre> <p> または </p> <pre> y.m.d </pre> <p> データセットは1つの文字列を含む1行からなる。b.ka.t.w.ki はマヤ長期暦の日付、y.m.d は西暦の日付である。与えられる単位は以下の通りである。 </p> <b>マヤ長期暦</b><br/> <table> <tr> <td width="40">b</td> <td width="100">バクトゥン</td> <td width="200">(0 &le; b&lt; 13)</td> </tr> <tr> <td>ka</td> <td>カトゥン</td> <td>(0 &le; ka &lt; 20)</td> </tr> <tr> <td>t</td> <td>トゥン</td> <td>(0 &le; t&lt; 20)</td> </tr> <tr> <td>w</td> <td>ウィナル</td> <td>(0 &le; w &lt; 18)</td> </tr> <tr> <td>ki</td> <td>キン</td> <td>(0 &le; ki &lt; 20)</td> </tr> </table> <br/> <b>西暦</b><br/> <table> <tr> <td width="40">y</td> <td width="100">年</td> <td width="200">(2012 &le; y &le; 10,000,000)</td> </tr> <tr> <td>m</td> <td>月</td> <td>(1 &le; m &le; 12)</td> </tr> <tr> <td>d</td> <td>日</td> <td>(1 &le; d &le; 31)</td> </tr> </table> <br/> <p> 西暦の日の最大値は、大の月、小の月、うるう年かどうかで変わる(うるう年は 4 の倍数の年のうち、100 で割り切れない年か、400 で割り切れる年である)。マヤ長期暦の日付の範囲は 0.0.0.0.0 から 12.19.19.17.19 までとする。ただし、マヤ長期暦の 0.0.0.0.0 は西暦の 2012.12.21 に対応する。また、西暦の日付の範囲は 2012.12.21から 10000000.12.31 までとする。 </p> <p> データセットの数は 500 を超えない。 </p> <h2>出力</h2> <p> 入力が西暦のときはマヤ長期暦を、マヤ長期暦のときは西暦を、それぞれ入力と同じ形式で出力する。 入力された西暦を換算した結果、マヤ長期暦の次のサイクルに入った場合でも b.ka.t.w.ki の形式で出力してよい。 </p> <h2>入力例</h2> <pre> 2012.12.31 2.12.16.14.14 7138.5.13 10.5.2.1.5 10000000.12.31 # </pre> <h2>出力例</h2> <pre> 0.0.0.0.10 3054.8.15 0.0.0.0.10 6056.2.29 8.19.3.13.2 </pre>
p00606
<H1><font color="#000000">Problem B:</font> Cleaning Robot</H1> <p> Dr. Asimov, a robotics researcher, loves to research, but hates houseworks and his house were really dirty. So, he has developed a cleaning robot. </p> <p> As shown in the following figure, his house has 9 rooms, where each room is identified by an alphabet: </p> <br> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_cleaningRobot"> </center> <br> <p> The robot he developed operates as follows: </p> <ul> <li> If the battery runs down, the robot stops. </li> <li> If not so, the robot chooses a direction from four cardinal points with the equal probability, and moves to the room in that direction. Then, the robot clean the room and consumes 1 point of the battery. </li> <li> However, if there is no room in that direction, the robot does not move and remains the same room. In addition, there is a junk room in the house where the robot can not enter, and the robot also remains when it tries to enter the junk room. The robot also consumes 1 point of the battery when it remains the same place. </li> </ul> <p> A battery charger for the robot is in a room. It would be convenient for Dr. Asimov if the robot stops at the battery room when its battery run down. </p> <p> Your task is to write a program which computes the probability of the robot stopping at the battery room. </p> <H2>Input</H2> <p> The input consists of several datasets. Each dataset consists of: </p> <pre> <i>n</i> <i>s t b</i> </pre> <p> <i>n</i> is an integer that indicates the initial battery point. <i>s</i>, <i>t</i>, <i>b</i> are alphabets respectively represent the room where the robot is initially, the battery room, and the junk room. </p> <p> The input ends with a dataset which consists of single 0 for <i>n</i>. Your program should not output for this dataset. </p> <H2>Output</H2> <p> For each dataset, print the probability as a floating point number in a line. The answer may not have an error greater than 0.000001. </p> <H2>Constraints</H2> <ul> <li>Judge data includes at most 100 data sets.</li> <li><i>n</i> &le; 15</li> <li><i>s</i>, <i>t</i>, <i>b</i> are distinct.</li> </ul> <H2>Sample Input</H2> <pre> 1 E A C 1 E B C 2 E A B 0 </pre> <H2>Output for the Sample Input</H2> <pre> 0.00000000 0.25000000 0.06250000 </pre>
p01914
<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>J: エナジードリンク</h1> <h2>問題</h2> <p> ixmel、Pulmn 兄弟は $N$ 種類のエナジードリンクをそれぞれ 1 本ずつ持っています。 現在、ixmel と Pulmn のエネルギーはともに 0 で、時刻は午前 0 時です。 ixmel と Pulmn はエネルギーが 0 以下のまま正午になると「たいへんなこと」になります。 エネルギーが正の数では「たいへんなこと」にはなりません。 ixmel とPulmn は「たいへんなこと」にならないために、 毎日朝 6 時に 1 本のエナジードリンクを 2 人で分けて飲むことにしました。 i 番目のエナジードリンクを ixmel が飲むとエネルギーが $a_i$ 増えますが、副作用として 24 時間後にエネルギーが $b_i$ 減ってしまいます。 一方、Pulmn が飲むとエネルギーが $b_i$ 増え、24 時間後にエネルギーが $a_i$ 減ります。 また、ixmel と Pulmn は日が変わった直後、エネルギーは 0 になります。 ixmel と Pulmn は今持っているエナジードリンクだけで、どちらか一方、または両方が「たいへんなこと」になるまでの日数を少しでも長くしたいと思いました。 </p> <p> ixmel、Pulmn 兄弟のために最初にどちらか片方、または両方が「たいへんなこと」になるまでの日数の最大値を求めてください。なお、エナジードリンクを飲む時間は無視できるものとし、「たいへんなこと」が起こる日は求める日数に含まないものとします。 </p> <h2>入力</h2> <p> 入力は $1+n$ 行からなります。 1 行目には 1 個の整数 $N$ が与えられます。 続く $N$ 行の内、$i$ 行目は 2 個の整数 $a_i, b_i$ が与えられます。 </p> <h2>制約</h2> <ul> <li>$1 \le N \le 10^5$</li> <li>$1 \le a_i, b_i \le 10^9$</li> </ul> <h2>出力</h2> <p> 考えられる「たいへんなこと」になるまでの日数の最大値を出力しましょう。 また、末尾に改行を出力しましょう。 </p> <h2>サンプル</h2> <h3>サンプル入力 1</h3> <pre> 5 3 5 7 4 11 9 3 7 7 8 </pre> <h3>サンプル出力 1</h3> <pre> 4 </pre> <p> 1 日目から 5 日目に飲むドリンクは、それぞれ 1, 2, 5, 3, 4 とするのが最適です。 各日のエナジードリンクを飲んだあとの (ixmel の体力, Pulmn の体力) は、それぞれ $(3, 5), (2, 1), (1, 3), (3, 2), (-6, -4)$ と変化し、 5 日目に「たいへんなこと」になるので答えは 4 です。 </p> <h3>サンプル入力 2</h3> <pre> 2 1 1 1 1 </pre> <h3>サンプル出力 2</h3> <pre> 1 </pre> <p> 異なる種類で成分が同じエナジードリンクもあります。また、「たいへんなこと」が起こるのは、エネルギーの量が 0 以下の時であることに注意してください。 </p> <h3>サンプル入力 2</h3> <pre> 3 5 9 3 2 7 4 </pre> <h3>サンプル出力 2</h3> <pre> 3 </pre> <p> 4 日目に飲むエナジードリンクはありません。 </p>
p03929
<span class="lang-en lang-child hidden-lang"> <div class="part"> Max Score: $250$ Points <br/> <section> <h3>Problem Statement</h3> Snuke has a very long calendar. It has a grid with $n$ rows and $7$ columns. One day, he noticed that calendar has a following regularity. <br/> <ul> <li>The cell at the $i$-th row and $j$-th column contains the integer $7i+j-7$.</li> </ul> A good sub-grid is a $3 \times 3$ sub-grid and the sum of integers in this sub-grid mod $11$ is $k$. <br/> How many good sub-grid are there? Write a program and help him. <br/> </section> </div> <div class="io-style"> <div class="part"> <section> <h3>Input</h3> The input is given from standard input in the following format. <br/> <br/> <blockquote>$n \quad k$ </blockquote> </section> </div> <div class="part"> <section> <h3>Output</h3> <ul> <li>Print the number of good sub-grid. If there are no solution exists, print <code>0</code>.</li> </ul> </section> <section> <h3>Constraints</h3> <ul> <li>$1 \le n \le 10^9$</li> <li>$0 \le k \le 10$</li> </ul> </section> <section> <h3>Subtasks</h3> <p>Subtask 1 [ $150$ points ]</p> <ul> <li>The testcase in the subtask satisfies $1 \le n \le 100$.</li> </ul> <br/> <p>Subtask 2 [ $100$ points ]</p> <ul> <li>There are no additional constraints.</li> </ul> <br/> </section> </div> </div> <div class="part"> <section> <h3>Sample Input 1</h3> <pre> 7 7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3> <pre> 2 </pre> </section> </div> <div class="part"> <section> In this case, the calendar likes this matrix.<br/> <table class="table-striped table-bordered table-condensed"> <tr align="center"> <th></th> <td width="75">Sun.</td> <td width="75">Mon.</td> <td width="75">Tue.</td> <td width="75">Wed.</td> <td width="75">Thu.</td> <td width="75">Fri.</td> <td width="75">Sat.</td> </tr> <tr align="center"> <th>Week 1</th> <td>1</td> <td>2</td> <td>3</td> <td>4</td> <td>5</td> <td>6</td> <td>7</td> </tr> <tr align="center"> <th>Week 2</th> <td>8</td> <td>9</td> <td>10</td> <td>11</td> <td>12</td> <td>13</td> <td>14</td> </tr> <tr align="center"> <th>Week 3</th> <td>15</td> <td>16</td> <td>17</td> <td>18</td> <td>19</td> <td>20</td> <td>21</td> </tr> <tr align="center"> <th>Week 4</th> <td>22</td> <td>23</td> <td>24</td> <td>25</td> <td>26</td> <td>27</td> <td>28</td> </tr> <tr align="center"> <th>Week 5</th> <td>29</td> <td>30</td> <td>31</td> <td>32</td> <td>33</td> <td>34</td> <td>35</td> </tr> <tr align="center"> <th>Week 6</th> <td>36</td> <td>37</td> <td>38</td> <td>39</td> <td>40</td> <td>41</td> <td>42</td> </tr> <tr align="center"> <th>Week 7</th> <td>43</td> <td>44</td> <td>45</td> <td>46</td> <td>47</td> <td>48</td> <td>49</td> </tr> </table> <br/> The cell at $i$-th row and $j$-th column is denoted $(i, j)$. <br/> <ul> <li>If upper-left is $(1, 5)$, the sum of integers is $5+6+7+12+13+14+19+20+21=117$.</li> <li>If upper-left is $(3, 2)$, the sum of integers is $16+17+18+23+24+25+30+31+32=216$.</li> </ul> Therefore, there are 2 good sub-grids.<br/> </section> </div> <div class="part"> <section> <h3>Sample Input 2</h3> <pre> 6 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3> <pre> 2 </pre> If upper-left is $(1, 3)$ or $(4, 4)$, it is a good sub-grid.<br/> </section> </div> <div class="part"> <section></section> </div> <div class="part"> <h3>Sample Input 3</h3> <pre> 18 10 </pre> </div></span>
p03180
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> rabbits, numbered <var>1, 2, \ldots, N</var>.</p> <p>For each <var>i, j</var> (<var>1 \leq i, j \leq N</var>), the compatibility of Rabbit <var>i</var> and <var>j</var> is described by an integer <var>a_{i, j}</var>. Here, <var>a_{i, i} = 0</var> for each <var>i</var> (<var>1 \leq i \leq N</var>), and <var>a_{i, j} = a_{j, i}</var> for each <var>i</var> and <var>j</var> (<var>1 \leq i, j \leq N</var>).</p> <p>Taro is dividing the <var>N</var> rabbits into some number of groups. Here, each rabbit must belong to exactly one group. After grouping, for each <var>i</var> and <var>j</var> (<var>1 \leq i &lt; j \leq N</var>), Taro earns <var>a_{i, j}</var> points if Rabbit <var>i</var> and <var>j</var> belong to the same group.</p> <p>Find Taro's maximum possible total score.</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 16</var></li> <li><var>|a_{i, j}| \leq 10^9</var></li> <li><var>a_{i, i} = 0</var></li> <li><var>a_{i, j} = a_{j, i}</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>a_{1, 1}</var> <var>\ldots</var> <var>a_{1, N}</var> <var>:</var> <var>a_{N, 1}</var> <var>\ldots</var> <var>a_{N, N}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print Taro's maximum possible total score.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 0 10 20 10 0 -100 20 -100 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>20 </pre> <p>The rabbits should be divided as <var>\{1, 3\}, \{2\}</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 0 -10 -10 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>The rabbits should be divided as <var>\{1\}, \{2\}</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>4 0 1000000000 1000000000 1000000000 1000000000 0 1000000000 1000000000 1000000000 1000000000 0 -1 1000000000 1000000000 -1 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>4999999999 </pre> <p>The rabbits should be divided as <var>\{1, 2, 3, 4\}</var>. Note that the answer may not fit into a 32-bit integer type.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>16 0 5 -4 -5 -8 -4 7 2 -4 0 7 0 2 -3 7 7 5 0 8 -9 3 5 2 -7 2 -7 0 -1 -4 1 -1 9 -4 8 0 -9 8 9 3 1 4 9 6 6 -6 1 8 9 -5 -9 -9 0 -7 6 4 -1 9 -3 -5 0 1 2 -4 1 -8 3 8 -7 0 -5 -9 9 1 -9 -6 -3 -8 3 4 3 -4 5 9 6 -5 0 -6 1 -2 2 0 -5 -2 3 1 2 7 2 3 4 -9 -6 0 -2 -2 -9 -3 9 -2 9 2 -5 2 -7 1 -1 9 1 -2 0 -6 0 -6 6 4 -1 -7 8 -4 2 4 9 1 -2 -2 -6 0 8 -6 -2 -4 8 7 7 0 -7 9 -3 -9 2 -9 0 8 0 0 1 -3 3 -6 -6 7 0 6 -5 -6 0 -3 -6 -6 0 0 5 7 -1 -5 3 0 -1 6 0 -3 -5 9 6 -2 1 5 0 -2 7 -8 0 2 -4 -6 1 -8 -2 -2 4 -4 -3 7 -2 0 -9 7 1 -3 1 1 2 3 3 9 -1 8 3 -1 7 -9 0 -6 -8 7 -1 8 -4 4 1 2 -7 7 -6 -5 -8 7 -6 0 -9 7 9 9 1 3 2 -5 8 7 -6 3 0 1 -8 -9 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>132 </pre></section> </div> </span>
p01447
<H1>Problem A: 雅先生の地球侵略日誌</H1> <p> クァークゴ帝国遠征軍は、地球侵略をもくろむ悪の組織である。彼らは侵略者の伝統にのっとり、日 本の東京周辺をターゲットに、毎週1体のペースで怪人を送りこみ続けていた。しかし、そのたびに 人類戦隊アースファイブと名乗る5人の戦士があらわれ、街で暴れまわっていた怪人はあっさりと倒 されてしまうのであった。 </p> <p> ワルザード・スルー(地球名:源雅)は、そんな現状を本気で憂いている、クァークゴ帝国遠征軍の 女幹部である。彼女は、毎週の敗北から何も学ぼうとしない司令官や、どこかズレた発明を繰り返す 天才科学者らの下で、頭の痛い日々を過ごしていた。 </p> <p> そんな中、次の作戦は吸血怪人ドラキュラスを日本に送りこむことに決まった。ドラキュラスは、血 を吸った人間をドラキュラスに変えてしまう恐るべき怪人である。ドラキュラスに血を吸われた人間 もまた、他の人間の血を吸って仲間のドラキュラスを増やしていく。こうして地球全土をドラキュラ スで埋めつくしてしまおうという作戦だ。 </p> <p> これを聞いたワルザードは、すぐに悟った。この作戦は、幼稚園バスの乗っ取りのような普段やって いるセコい作戦とは訳が違う。あのダメ司令官が立案したものにしては珍しく、本当に地球を征服で きる可能性を秘めていると。 </p> <p> 倍々ゲームの勢いは恐ろしい。地上に降りたったドラキュラスは、またたく間に仲間の数を増やして いった。このまま行けば地球侵略は目と鼻の先だと思われた。だがその瞬間、ワルザードの脳裏を、 強烈にいやな予感が走り抜けた。まさか、この怪人、オリジナルが倒されると仲間も全滅するなんて ことはないよな? </p> <p> 慌ててドラキュラスを設計開発した科学者を問いつめたところ、やはりワルザードの危惧していた通 りだった。オリジナルのドラキュラスがやられると、血を吸われた人間はすべて元に戻るように設計 してあるのだという。ふざけんなよ開発者。どうしてそんな余計な機能をつけた! </p> <p> ワルザードは、開発担当者に飛び膝蹴りをきめると、すぐさまオリジナルの回収作業にとりかかっ た。いくらオリジナルと偽物は見た目がまったく同じだといっても、このままでは、駆けつけたアー スファイブに何かしらの理由でオリジナルを見抜かれて敗北するのが目に見えている。 </p> <p> 開発者の話によると、ドラキュラス化した人間の重さはすべて同じだが、オリジナルのドラキュラス はそれよりも少しだけ重いらしい。それならば、天秤ばかりを使えばオリジナルを見つけることがで きるはずだ。アースファイブがあらわれる前に、できるだけ早くオリジナルのドラキュラスを見つけ て回収しなければ。 </p> <H2>Input</H2> <p> <i>N</i> </p> <p> 入力の1行目には、整数 <i>N</i>(2 &le; <i>N</i> &le; 2,000,000,000)が書かれている。これは、オリジナルと偽物を合わせたドラキュラスの数をあらわす。 </p> <H2>Output</H2> <p> 天秤ばかりを使ってN 体のドラキュラスの中から1体のオリジナルを見つけるには、最悪の場合で も天秤ばかりを何回使えれば十分か。その最小値を出力せよ。ただし、天秤ばかりの左と右の皿に、 それぞれ何体かのドラキュラスを乗せて重さを比較することを、1回とカウントする。 </p> <h2>Sample Input 1</h2> <pre> 8 </pre> <h2>Sample Output 1</h2> <pre> 2 </pre> <h2>Sample Input 2</h2> <pre> 30 </pre> <h2>Sample Output 2</h2> <pre> 4 </pre> <h2>Sample Input 3</h2> <pre> 2000000000 </pre> <h2>Sample Output 3</h2> <pre> 20 </pre>
p01017
<h1>Problem B: Yu-kun Likes Rectangles</h1> <h2>Background</h2> <p> 会津大学付属幼稚園はプログラミングが大好きな子供が集まる幼稚園である。園児の一人であるゆう君は、プログラミングと同じくらい長方形が大好きだ。そんなゆう君は3つの長方形を使って得点を得る新たな遊びを考え、得られる最大の得点を計算するためのプログラムを書くことにした。 </p> <h2>Problem</h2> <p> <var>H</var> <var>×</var> <var>W</var> マスの長方形 A , B と<var>h</var> <var>×</var> <var>w</var> マスの長方形 C が与えられる。 ( <var>H</var>, <var>W</var>はそれぞれ長方形A, Bの縦, 横のマスの数を, <var>h</var>, <var>w</var>はそれぞれ長方形Cの縦, 横のマスの数を表す ) </p> <p> 図1のように A の各マスには整数が書かれており、Bの各マスには白または黒の色がついている。 Cの各マスにも同様に白または黒の色がついている。 </p> <br> <center> <img width="80%" src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_RitsCamp14Day2_yukun_rectangles1.png" alt="図1"><br> 図1<br> </center> <p> B の中に C と全く同じ模様の長方形があった場合、A の中でその長方形内に対応するマスに書かれている整数の和が得点として手に入る。 </p> <p> 例えば図1のような長方形 A, B, C を使う場合、図2の赤線で示すように B の中に C と同じ模様が含まれているので、その場所から193点が得られる。 </p> <br> <center> <img width="80%" src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_RitsCamp14Day2_yukun_rectangles2.png" alt="図2"><br> 図2<br> </center> <p> B の中に C と全く同じ模様の長方形が1つ以上存在する場合、そのような長方形の中で最大何点を得ることができるだろうか? </p> <p> ただし、B の中に C と同じ模様の長方形が存在しない場合は"NA” ( “ は除く ) と出力すること。 また、長方形を回転したり反転することはできない。 </p> <h2>Input</h2> <p> 入力の形式は以下の通りである。 </p> <pre> <var>H</var> <var>W</var> <var>a<sub>(1,1)</sub></var> <var>a<sub>(1,2)</sub></var> ... <var>a<sub>(1,W)</sub></var> <var>a<sub>(2,1)</sub></var> <var>a<sub>(2,2)</sub></var> ... <var>a<sub>(2,W)</sub></var> : <var>a<sub>(H,1)</sub></var> <var>a<sub>(H,2)</sub></var> ... <var>a<sub>(H,W)</sub></var> <var>b<sub>(1,1)</sub></var> <var>b<sub>(1,2)</sub></var> ... <var>b<sub>(1,W)</sub></var> <var>b<sub>(2,1)</sub></var> <var>b<sub>(2,2)</sub></var> ... <var>b<sub>(2,W)</sub></var> : <var>b<sub>(H,1)</sub></var> <var>b<sub>(H,2)</sub></var> ... <var>b<sub>(H,W)</sub></var> <var>h</var> <var>w</var> <var>c<sub>(1,1)</sub></var> <var>c<sub>(1,2)</sub></var> ... <var>c<sub>(1,w)</sub></var> <var>c<sub>(2,1)</sub></var> <var>c<sub>(2,2)</sub></var> ... <var>c<sub>(2,w)</sub></var> : <var>c<sub>(h,1)</sub></var> <var>c<sub>(h,2)</sub></var> ... <var>c<sub>(h,w)</sub></var> </pre> <p> <var>a<sub>(i,j)</sub></var> は長方形 A のマス <var>(i, j)</var> に書かれている整数を、<var>b<sub>(i,j)</sub></var>は長方形 B のマス<var>(i,j)</var>の色を、<var>c<sub>(i,j)</sub></var> は長方形 C のマス<var>(i,j)</var>の色を表す。 マスの色は0 が白、1 が黒を表す。 </p> <h2>Constraints</h2> <p>入力は以下の条件を満たす。</p> <ul> <li>入力は全て整数</li> <li>1 &le; <var>H</var>,<var>W</var> &le; 50 </li> <li>1 &le; <var>h</var> &le; <var>H</var> </li> <li>1 &le; <var>w</var> &le; <var>W</var> </li> <li>-100 &le; <var>a<sub>(i, j)</sub></var> &le; 100 </li> <li><var>b<sub>(i, j)</sub></var>,<var>c<sub>(i, j)</sub></var> は0か1</li> </ul> <h2>Output</h2> <p> 長方形<var>B</var>の中に長方形<var>C</var>と全く同じ模様の場所が存在する場合、そのような場所の中でもっとも得点が高いものを出力せよ。 </p> <p> そのような場所が存在しない場合, “NA” ( “ は除く ) と出力せよ。 </p> <h2>Sample Input 1</h2> <pre> 4 4 10 2 -1 6 8 1 -100 41 22 47 32 11 -41 99 12 -8 1 0 0 1 0 0 1 0 0 1 0 1 0 0 1 0 2 3 1 0 1 0 1 0 </pre> <h2>Sample Output 1</h2> <pre> 193 </pre> <h2>Sample Input 2</h2> <pre> 3 3 5 1 3 2 5 9 0 1 5 1 0 0 0 1 1 0 1 1 1 1 1 </pre> <h2>Sample Output 2</h2> <pre> 9 </pre> <h2>Sample Input 3</h2> <pre> 3 4 4 1 9 1 9 1 -1 3 2 -4 1 10 1 1 0 1 0 1 1 1 1 1 0 0 1 4 1 1 1 1 </pre> <h2>Sample Output 3</h2> <pre> NA </pre>
p01502
<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 H: Sightseeing Tour </h2> <p> KM city has $N$ sightseeing areas. Currently every pair of area is connected by a bidirectional road. </p> <p> However for some reason, Mr. KM, the mayor of this city, decided to make all of these roads one-way . It costs $C_{i, j}$ dollars to renovate the road between area $i$ and area $j$ to a one-way road from area $i$ to area $j$. Of course, Mr. KM is economic and wants to minimize the total cost of the renovation. </p> <p> On the other hand, because tourism is the most important industry for KM city, there must exists a tour that goes through all the sightseeing areas, visiting each area exactly once. The first and last area of the path need not to be the same. Can you calculate the minimum total cost required for the renovation, given this situation? </p> <h3>Input</h3> <p> The first line contains the number of sightseeing area $N$ ($1 \leq N \leq 100$). Next $N$ lines describe the integer matrix $C$, where the $j$-th element of the $i$-th row of the input describes $C_{i,j}$ ($0 \leq C_{i,j} \leq 1,000,000$). For each $i$, you can assume $C_{i,i}$ is always zero. </p> <h3>Output</h3> <p> Output the minimum cost in a line. </p> <h3>Sample Input 1</h3> <pre>3 0 2 7 2 0 4 5 8 0</pre> <h3>Sample Output 1</h3> <pre>11</pre>
p01152
<H1><font color="#000">Problem E:</font> Reading a Chord</H1> <p> In this problem, you are required to write a program that enumerates all chord names for given tones. </p> <p> We suppose an ordinary scale that consists of the following 12 tones: </p> <p> C, C<sup><i>#</i></sup> , D, D<sup><i>#</i></sup> , E, F, F<sup><i>#</i></sup> , G, G<sup><i>#</i></sup> , A, A<sup><i>#</i></sup> , B </p> <p> Two adjacent tones are different by a <i>half</i> step; the right one is higher. Hence, for example, the tone G is higher than the tone E by three half steps. In addition, the tone C is higher than the tone B by a half step. Strictly speaking, the tone C of the next octave follows the tone B, but octaves do not matter in this problem. </p> <p> A chord consists of two or more different tones, and is called by its <i>chord name</i>. A chord may be represented by multiple chord names, but each chord name represents exactly one set of tones. </p> <p> In general, a chord is represented by a basic chord pattern (<i>base chord</i>) and additional tones (<i>tension</i>) as needed. In this problem, we consider five basic patterns as listed below, and up to one additional tone. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_readingChord1"> <p>Figure 1: Base chords (only shown those built on C)</p> </center> <p> The chords listed above are built on the tone C, and thus their names begin with C. The tone that a chord is built on (the tone C for these chords) is called the <i>root</i> of the chord. </p> <p> A chord specifies its root by an absolute tone, and its other components by tones relative to its root. Thus we can obtain another chord by shifting all components of a chord. For example, the chord name D represents a chord consisting of the tones D, F<sup><i>#</i></sup> and A, which are the shifted-up tones of C, E and G (which are components of the chord C) by two half steps. </p> <p> An additional tone, a tension, is represented by a number that may be preceding a plus or minus sign, and designated parentheses after the basic pattern. The figure below denotes which number is used to indicate each tone. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_readingChord2"> <p>Figure 2: Tensions for C chords</p> </center> <p> For example, C(9) represents the chord C with the additional tone D, that is, a chord that consists of C, D, E and G. Similarly, C(+11) represents the chord C plus the tone F<sup><i>#</i></sup>. </p> <p> The numbers that specify tensions denote relative tones to the roots of chords like the compo- nents of the chords. Thus change of the root also changes the tones specified by the number, as illustrated below. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_readingChord3"> <p>Figure 3: Tensions for E chords</p> </center> <p> +5 and -5 are the special tensions. They do not indicate to add another tone to the chords, but to sharp (shift half-step up) or flat (shift half-step down) the fifth tone (the tone seven half steps higher than the root). Therefore, for example, C(+5) represents a chord that consists of C, E and G<sup><i>#</i></sup> , not C, E, G and G<sup><i>#</i></sup>. </p> <p> Figure 4 describes the syntax of chords in Backus-Naur Form. </p> <p> Now suppose we find chord names for the tones C, E and G. First, we easily find the chord C consists of the tones C, E and G by looking up the base chord table shown above. Therefore ‘C’ should be printed. We have one more chord name for those tones. The chord Em obviously represents the set of tones E, G and B. Here, if you sharp the tone B, we have the set of tones E, G and C. Such modification can be specified by a tension, +5 in this case. Thus ‘Em(+5)’ should also be printed. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_readingChord4"> <p>Figure 4: Syntax of chords in BNF</p> </center> <H2>Input</H2> <p> The first line of input contains an integer <i>N</i>, which indicates the number of test cases. </p> <p> Each line after that contains one test case. A test case consists of an integer m (3 &le; <i>m</i> &le; 5) followed by <i>m</i> tones. There is exactly one space character between each tones. The same tone does not appear more than once in one test case. </p> <p> Tones are given as described above. </p> <H2>Output</H2> <p> Your program should output one line for each test case. </p> <p> It should enumerate all chord names that completely match the set of tones given as input (i.e. the set of tones represented by each chord name must be equal to that of input) in any order. </p> <p> No chord name should be output more than once. Chord names must be separated by exactly one space character. No extra space is allowed. </p> <p> If no chord name matches the set of tones, your program should just print ‘UNKNOWN’ (note that this word must be written in capital letters). </p> <H2>Sample Input</H2> <pre> 5 3 C E G 3 C E G# 4 C A G E 5 F A C E D 3 C D E </pre> <H2>Output for the Sample Input</H2> <pre> C Em(+5) C(+5) E(+5) G#(+5) C(13) Am7 Am(+13) Dm7(9) FM7(13) UNKNOWN </pre>
p03495
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi has <var>N</var> balls. Initially, an integer <var>A_i</var> is written on the <var>i</var>-th ball.</p> <p>He would like to rewrite the integer on some balls so that there are at most <var>K</var> different integers written on the <var>N</var> balls.</p> <p>Find the minimum number of balls that Takahashi needs to rewrite the integers on them.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq K \leq N \leq 200000</var></li> <li><var>1 \leq A_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>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>K</var> <var>A_1</var> <var>A_2</var> ... <var>A_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum number of balls that Takahashi needs to rewrite the integers on them.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 2 1 1 2 2 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>For example, if we rewrite the integer on the fifth ball to <var>2</var>, there are two different integers written on the balls: <var>1</var> and <var>2</var>. On the other hand, it is not possible to rewrite the integers on zero balls so that there are at most two different integers written on the balls, so we should print <var>1</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>4 4 1 1 2 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>Already in the beginning, there are two different integers written on the balls, so we do not need to rewrite anything.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 3 5 1 3 2 4 1 1 2 3 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>3 </pre></section> </div> </span>
p00313
<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> 秘密の組織アイヅアナリティクス(AiZu AnalyticS)は、極秘の調査を開始した。ターゲットになっている人物は <var>N</var> 人いて、1 から <var>N</var> の識別番号が付けられている。AZAS 情報戦略調査員であるあなたは、 ターゲットの中から、以下の条件を少なくとも一つ満たす人物の数を割り出すことにした。 </p> <ul> <li> 組織 $A$ に属さず、かつ、商品 $C$ を所持している者。</li> <li> 組織 $B$ に属し、かつ、商品 $C$ を所持している者。</li> </ul> <p> 組織 $A$ に属している者、組織 $B$ に属している者、商品 $C$ を所持している者の識別番号が入力として与えられたとき、条件を満たす人物の数を割り出すプログラムを作成せよ。ただし、どちらの条件も満たす人物を重複して数えないように注意せよ。 </p> <p> (補足:上記の条件について)<br> 1 から $N$ までの自然数の集合から、いくつかの要素を選んだ集合を $A$,$B$,$C$ とする。条件を満たす人物の数は、$(\bar{A} \cap C) \cup (B \cap C)$ (図の塗られた部分) を満たす要素の個数である。ただし、$\bar{A}$ は集合 $A$ の補集合とする。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2015_azas"> </center> <br/> <h2>Input</h2> <p> 入力は以下の形式で与えられる。 </p> <pre> <var>N</var> <var>X</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> ... <var>a<sub>X</sub></var> <var>Y</var> <var>b<sub>1</sub></var> <var>b<sub>2</sub></var> ... <var>b<sub>Y</sub></var> <var>Z</var> <var>c<sub>1</sub></var> <var>c<sub>2</sub></var> ... <var>c<sub>Z</sub></var> </pre> <p> 入力は4行であり、1行目に調査対象の人数 <var>N</var> (1 &le; <var>N</var> &le; 100) が与えられる。2行目に、組織 $A$ に属している者の数 <var>X</var> (0 &le; <var>X</var> &le; <var>N</var>)と、それに続いて組織 $A$ に属している者の識別番号 <var>a<sub>i</sub></var> (1 &le; <var>a<sub>i</sub></var> &le; <var>N</var>) が与えられる。3行目に、組織 $B$ に属している者の数 <var>Y</var> (0 &le; <var>Y</var> &le; <var>N</var>) と、それに続いて組織 $B$ に属している者の識別番号 <var>b<sub>i</sub></var> (1 &le; <var>b<sub>i</sub></var> &le; <var>N</var>) が与えられる。4行目に、商品 $C$ を所持している者の数 <var>Z</var> (0 &le; <var>Z</var> &le; <var>N</var>) と、それに続いて商品 $C$ を所持している者の識別番号 <var>c<sub>i</sub></var> (1 &le; <var>c<sub>i</sub></var> &le; <var>N</var>) が与えられる。 </p> <h2>Output</h2> <p> 条件を満たす人物の数を1行に出力する。 </p> <h2>Sample Input 1</h2> <pre> 5 3 1 2 3 2 4 5 2 3 4 </pre> <h2>Sample Output 1</h2> <pre> 1 </pre> <br/> <h2>Sample Input 2</h2> <pre> 100 3 1 100 4 0 2 2 3 </pre> <h2>Sample Output 2</h2> <pre> 2 </pre>
p00743
<h1><font color="#000000">Problem D:</font> Discrete Speed</h1> <p> Consider car trips in a country where there is no friction. Cars in this country do not have engines. Once a car started to move at a speed, it keeps moving at the same speed. There are acceleration devices on some points on the road, where a car can increase or decrease its speed by 1. It can also keep its speed there. Your job in this problem is to write a program which determines the route with the shortest time to travel from a starting city to a goal city. </p> <p> There are several cities in the country, and a road network connecting them. Each city has an acceleration device. As mentioned above, if a car arrives at a city at a speed <i>v </i>, it leaves the city at one of <i>v </i>- 1, <i>v </i>, or <i>v </i>+ 1. The first road leaving the starting city must be run at the speed 1. Similarly, the last road arriving at the goal city must be run at the speed 1. </p> <p> The starting city and the goal city are given. The problem is to find the best route which leads to the goal city going through several cities on the road network. When the car arrives at a city, it cannot immediately go back the road it used to reach the city. No U-turns are allowed. Except this constraint, one can choose any route on the road network. It is allowed to visit the same city or use the same road multiple times. The starting city and the goal city may be visited during the trip. </p> <p> For each road on the network, its distance and speed limit are given. A car must run a road at a speed less than or equal to its speed limit. The time needed to run a road is the distance divided by the speed. The time needed within cities including that for acceleration or deceleration should be ignored. </li></ul> <h3>Input</h3> <p> The input consists of multiple datasets, each in the following format. </p> <blockquote> <i>n </i> <i>m </i><br> <i>s </i> <i>g </i><br> <i>x</i><sub> 1</sub> <i>y</i><sub> 1</sub> <i>d</i><sub> 1</sub> <i>c</i><sub> 1</sub><br> ...<br> <i>x<sub>m</sub> </i> <i>y<sub>m</sub> </i> <i>d<sub>m</sub> </i> <i>c<sub>m</sub> </i><br> </blockquote> <!-- begin en only --> <p> Every input item in a dataset is a non-negative integer. Input items in the same line are separated by a space. </p> <p> The first line gives the size of the road network. <i>n </i> is the number of cities in the network. You can assume that the number of cities is between 2 and 30, inclusive. <i>m </i> is the number of roads between cities, which may be zero. </p> <p> The second line gives the trip. <i>s </i> is the city index of the starting city. <i>g </i> is the city index of the goal city. <i>s </i> is not equal to <i>g </i>. You can assume that all city indices in a dataset (including the above two) are between 1 and <i>n </i>, inclusive. </p> <p> The following <i>m </i> lines give the details of roads between cities. The <i>i </i>-th road connects two cities with city indices <i>x<sub>i</sub> </i> and <i>y<sub>i</sub> </i>, and has a distance <i>d<sub>i</sub> </i> (1 &le; <i>i </i>&le; <i>m </i>). You can assume that the distance is between 1 and 100, inclusive. The speed limit of the road is specified by <i>c<sub>i</sub> </i>. You can assume that the speed limit is between 1 and 30, inclusive. </p> <p> No two roads connect the same pair of cities. A road never connects a city with itself. Each road can be traveled in both directions. </p> <p> The last dataset is followed by a line containing two zeros (separated by a space). </p> <h3>Output</h3> <p> For each dataset in the input, one line should be output as specified below. An output line should not contain extra characters such as spaces. </p> <p> If one can travel from the starting city to the goal city, the time needed for the best route (a route with the shortest time) should be printed. The answer should not have an error greater than 0.001. You may output any number of digits after the decimal point, provided that the above accuracy condition is satisfied. </p> <p> If it is impossible to reach the goal city, the string "<tt>unreachable</tt>" should be printed. Note that all the letters of "<tt>unreachable</tt>" are in lowercase. </p> <h3>Sample Input</h3> <pre> 2 0 1 2 5 4 1 5 1 2 1 1 2 3 2 2 3 4 2 2 4 5 1 1 6 6 1 6 1 2 2 1 2 3 2 1 3 6 2 1 1 4 2 30 4 5 3 30 5 6 2 30 6 7 1 6 1 2 1 30 2 3 1 30 3 1 1 30 3 4 100 30 4 5 1 30 5 6 1 30 6 4 1 30 0 0 </pre> <h3>Output for the Sample Input</h3> <pre> unreachable 4.00000 5.50000 11.25664 </pre>
p01851
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"> </script> <h3>野球観戦</h3> <p>先日,あなたの競技プログラミング仲間であるOさんは野球観戦に出かけた. 観戦した試合は,チームXとチームYの合計 4 試合の対戦だったが,一方的な展開となり,全試合でチームXが勝利した. しかも,4 試合を通じたXの合計得点は 33 点だったのに対し,Yの合計得点はたったの 4 点だった. </p> <p>あまりに一方的な内容のため,試合内容への興味が薄れてしまったOさんは,試合を観戦している間も競技プログラミングの作問ネタをついつい考えてしまっていた. その甲斐もあって,Oさんは以下のような問題を思いついた. </p> <p>野球チームXとYが対戦し,Xが勝った試合数,Yが勝った試合数,引き分けの試合数がそれぞれ <i>A, B, C</i> 試合だったとする. また,全 <i>A+B+C</i> 試合を通じたX,Yの総得点は,それぞれ <i>S<sub>X</sub></i> 点,<i>S<sub>Y</sub></i> 点だったとする.得点は全て 0 以上の整数である. XとYが合計 <i>A+B+C</i> 試合対戦したとき,全試合の結果としてこのような条件を満たす各試合のスコアの並びは何通り有り得るだろうか? </p> <p>ここで,ある試合で勝利する条件は,その試合における得点が,相手チームの得点よりも多いことであり,等しい場合は引き分けとなる. </p> <p>また,各試合のスコアの並びを求める際,対戦した全試合の結果を比べた時,XとYの得点の組み合わせが同じでも,その順序が異なれば区別する必要がある. 例えば,XとYが 2 試合対戦した結果,共に 1 勝ずつし,引き分けが無く,XとYの総得点が共に 1 点ずつだったとする. この場合,各試合におけるX,Yの得点を (Xの得点) - (Yの得点) という表記で表し,合計 2 試合の結果を並べると,以下の 2 通りが与えられた条件を満たす. </p><ul><li> 1 - 0, 0 - 1 </li><li> 0 - 1, 1 - 0 </li></ul> <p>試合の順序を区別して数えるので,これらは区別される. </p> <p>あなたにはこの答えを求めるプログラムを作って欲しい. ただし,求める数はとても大きい数になり得るため,求める数を 1,000,000,007 で割った余りを答えるようにして欲しい. </p> <h3>Input</h3> <p>入力は複数のデータセットからなる. 各データセットは 1 行からなり,次の形式で表される. </p> <blockquote><i>A</i> <i>B</i> <i>C</i> <i>S<sub>X</sub></i> <i>S<sub>Y</sub></i></blockquote> <p>ここで,<i>A</i> はチームXの勝利数,<i>B</i> はチームYの勝利数,<i>C</i> は引き分けの試合数,<i>S<sub>X</sub></i> はチームXの総得点,<i>S<sub>Y</sub></i> はチームYの総得点を表す. <i>A, B, C, S<sub>X</sub>, S<sub>Y</sub></i> は全て 0 以上 1,000,000 以下の整数であり,かつ <i>0 &lt; A+B+C</i> を満たす. </p> <p>入力の終わりは,5 つのゼロからなる行で示される. </p> <h3>Output</h3> <p>各データセットについて,与えられた条件を満たす場合の数を 1,000,000,007 で割った余りのみからなる行を 1 行で出力せよ. </p> <h3>Sample Input</h3> <pre>1 1 0 1 1 0 0 2 3 2 4 0 0 33 4 5 4 2 20 25 4726 87361 2742 23497 162843 328324 420923 12782 834286 538297 0 0 0 0 0</pre> <h3>Output for Sample Input</h3> <pre>2 0 114660 512095631 673703234 166259450</pre>
p02284
<H1>Binary Search Tree II</H1> <p> Write a program which performs the following operations to a binary search tree $T$ by adding the find operation to A: Binary Search Tree I. </p> <ul> <li><span>insert </span> $k$: Insert a node containing $k$ as key into $T$.</li> <li><span>find </span>$k$: Report whether $T$ has a node containing $k$. </li> <li><span>print</span>: Print the keys of the binary search tree by inorder tree walk and preorder tree walk respectively.</li> </ul> <H2>Input</H2> <p> In the first line, the number of operations $m$ is given. In the following $m$ lines, operations represented by <span>insert </span>$k$, <span>find </span>$k$ or <span>print</span> are given. </p> <H2>Output</H2> <p> For each <span>find </span>$k$ operation, print "<span>yes</span>" if $T$ has a node containing $k$, "<span>no</span>" if not. </p> <p> In addition, for each <span>print</span> operation, print a list of keys obtained by inorder tree walk and preorder tree walk in a line respectively. Put a space character <u>before each key</u>. </p> <H2>Constraints</H2> <ul> <li>The number of operations $\leq 500,000$</li> <li>The number of print operations $\leq 10$.</li> <li>$-2,000,000,000 \leq key \leq 2,000,000,000$</li> <li>The height of the binary tree does not exceed 100 if you employ the above pseudo code.</li> <li>The keys in the binary search tree are all different.</li> </ul> <H2>Sample Input 1</H2> <pre> 10 insert 30 insert 88 insert 12 insert 1 insert 20 find 12 insert 17 insert 25 find 16 print </pre> <H2>Sample Output 1</H2> <pre> yes no 1 12 17 20 25 30 88 30 12 1 20 17 25 88 </pre> <H2>Reference</H2> <p> Introduction to Algorithms, Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. The MIT Press. </p>
p02093
<h2>F: Invariant Tree</h2> <h3>Problem Statement</h3> <p>You have a permutation <var>p_1, p_2, ... , p_N</var> of integers from <var>1</var> to <var>N</var>. You also have vertices numbered <var>1</var> through <var>N</var>. Find the number of trees while satisfying the following condition. Here, two trees <var>T</var> and <var>T'</var> are different if and only if there is a pair of vertices where <var>T</var> has an edge between them but <var>T’</var> does not have an edge between them.</p> <ul> <li> For all integer pairs <var>i, j</var> (<var>1\leq i &lt; j \leq N</var>), if there is an edge between vertices <var>i</var> and <var>j</var>, there is an edge between vertices <var>p_i</var> and <var>p_j</var> as well.</li> </ul> <p>Since this number can be extremely large, output the number modulo <var>998244353</var>.</p> <h3>Input</h3> <pre> <var>N</var> <var>p_1</var> <var>p_2</var> <var>...</var> <var>p_N</var> </pre> <h3>Constraints</h3> <ul> <li> <var>1\leq N \leq 3 \times 10^5</var></li> <li> <var>p_1, p_2, ... , p_N</var> is a permutation of integers <var>1</var> through <var>N</var>.</li> </ul> <h3>Output</h3> <p>Output the number in a single line.</p> <h3>Sample Input 1</h3> <pre> 4 2 1 4 3 </pre> <h3>Output for Sample Input 1</h3> <pre>4</pre> <p>Let <var>(u, v)</var> denote that there is an edge between <var>u</var> and <var>v</var>. The following <var>4</var> ways can make a tree satisfying the condition.</p> <ul> <li> (<var>1, 2</var>), (<var>1, 3</var>), (<var>2, 4</var>)</li> <li> (<var>1, 2</var>), (<var>1, 4</var>), (<var>2, 3</var>)</li> <li> (<var>1, 3</var>), (<var>2, 4</var>), (<var>3, 4</var>)</li> <li> (<var>1, 4</var>), (<var>2, 3</var>), (<var>3, 4</var>)</li> </ul> <h3>Sample Input 2</h3> <pre> 3 1 2 3 </pre> <h3>Output for Sample Input 2</h3> <pre>3</pre> <h3>Sample Input 3</h3> <pre> 3 2 3 1 </pre> <h3>Output for Sample Input 3</h3> <pre>0</pre> <h3>Sample Input 4</h3> <pre> 20 9 2 15 16 5 13 11 18 1 10 7 3 6 14 12 4 20 19 8 17 </pre> <h3>Output for Sample Input 4</h3> <pre>98344960</pre>
p00554
<h1>ポイントカード (Point Card)</h1> <h2>問題</h2> <p> JOI 商店街ではポイントカードのサービスを行っている.各ポイントカードには 2N 個のマスがある.商品を購入すると,くじを引くことができ,結果によって「当たり」か「はずれ」の印がマスに押される.同じマスに印が 2 回押されることはない.2N 個のマスのうち N 個以上のマスに当たりの印が書かれたポイントカードは,景品と交換することができる. また,ポイントカードの印は,1 マスにつき 1 円で書き換えてもらうことができる. </p> <p> JOI 君は 2N 個のマスが全て埋まっているポイントカードを M 枚持っている.ポイントカード i (1 ≦ i ≦ M) には,A<sub>i</sub> 個の当たり印と,B<sub>i</sub> 個のはずれ印が押されている.JOI 君は M - 1 個以上の景品が欲しい. </p> <p> JOI 君が M - 1 個以上の景品を得るために必要な費用の最小値を求めよ. </p> <h2>入力</h2> <p> 入力は M + 1 行からなる. </p> <p> 1 行目には,2 個の整数 N, M (1 ≦ N ≦ 1000, 1 ≦ M ≦ 1000) が空白を区切りとして書かれている.これは,ポイントカードには 2N 個のマスがあり,JOI 君が M 枚のポイントカードを持っていることを表す. </p> <p> 続く M 行のうちの i 行目 (1 ≦ i ≦ M) には,それぞれ 2 個の整数 A<sub>i</sub>, B<sub>i</sub> (0 ≦ A<sub>i</sub> ≦ 2N, 0 ≦ B<sub>i</sub> ≦ 2N, A<sub>i</sub> + B<sub>i</sub> = 2N) が書かれており,ポイントカード i には A<sub>i</sub> 個の当たり印と B<sub>i</sub> 個のはずれ印が押されていることを表す. </p> <h2> 出力</h2> <p> JOI 君が M - 1 個以上の景品を得るために必要な費用の最小値を 1 行で出力せよ. </p> <h2>入出力例</h2> <h3>入力例 1</h3> <pre> 4 5 1 7 6 2 3 5 4 4 0 8 </pre> <h3>出力例 1</h3> <pre> 4 </pre> <br/> <h3>入力例 2</h3> <pre> 5 4 5 5 8 2 3 7 8 2 </pre> <h3>出力例 2</h3> <pre> 0 </pre> <br/> <p> 入力例 1 においては,ポイントカード 1 のはずれ印を 3 つ当たり印に書き換えてもらい,ポイントカード 3 のはずれ印を 1 つ当たり印に書き換えてもらうと,4 円で 4 (= 5 - 1) 枚のカードが景品と交換可能になり,これが最小の費用である. </p> <p> 入力例 2 においては,既に 3 (= 4 - 1) 枚のカードが景品と交換可能なので,書き換えてもらう必要ない. </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/2016/2017-yo/index.html">情報オリンピック日本委員会作 『第 16 回日本情報オリンピック JOI 2016/2017 予選競技課題』</a> </p> </div>
p02569
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a binary array <var>A=(A_1,A_2,\cdots,A_N)</var> of length <var>N</var>. </p> <p>Process <var>Q</var> queries of the following types. The <var>i</var>-th query is represented by three integers <var>T_i,L_i,R_i</var>.</p> <ul> <li><var>T_i=1</var>: Replace the value of <var>A_j</var> with <var>1-A_j</var> for each <var>L_i \leq j \leq R_i</var>.</li> <li><var>T_i=2</var>: Calculate the inversion(*) of the array <var>A_{L_i},A_{L_i+1},\cdots,A_{R_i}</var>.</li> </ul> <p>Note:The inversion of the array <var>x_1,x_2,\cdots,x_k</var> is the number of the pair of integers <var>i,j</var> with <var>1 \leq i &lt; j \leq k, x_i &gt; x_j</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 2 \times 10^5</var></li> <li><var>0 \leq A_i \leq 1</var></li> <li><var>1 \leq Q \leq 2 \times 10^5</var></li> <li><var>1 \leq T_i \leq 2</var></li> <li><var>1 \leq L_i \leq R_i \leq N</var></li> <li>All values in Input are integer.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>Q</var> <var>A_1</var> <var>A_2</var> <var>\cdots</var> <var>A_N</var> <var>T_1</var> <var>L_1</var> <var>R_1</var> <var>T_2</var> <var>L_2</var> <var>R_2</var> <var>\vdots</var> <var>T_Q</var> <var>L_Q</var> <var>R_Q</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>For each query with <var>T_i=2</var>, print the answer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 5 0 1 0 0 1 2 1 5 1 3 4 2 2 5 1 1 3 2 1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 0 1 </pre> <ul> <li>First query: Print <var>2</var>, which is the inversion of <var>(A_1,A_2,A_3,A_4,A_5)=(0,1,0,0,1)</var>.</li> <li>Second query: Replace the value of <var>A_3</var> and <var>A_4</var> with <var>1</var> and <var>1</var>, respectively.</li> <li>Third query: Print <var>0</var>, which is the inversion of <var>(A_2,A_3,A_4,A_5)=(1,1,1,1)</var>.</li> <li>Fourth query: Replace the value of <var>A_1</var>, <var>A_2</var> and <var>A_4</var> with <var>1</var>, <var>0</var> and <var>0</var>, respectively.</li> <li>Fifth query: Print <var>1</var>, which is the inversion of <var>(A_1,A_2)=(1,0)</var>.</li> </ul></section> </div> </span>
p00104
<H1>Magic Tile</H1> <p> There is a magic room in a homestead. The room is paved with H &times W tiles. There are five different tiles: </p> <ul> <li>Tile with a east-pointing arrow</li> <li>Tile with a west-pointing arrow</li> <li>Tile with a south-pointing arrow</li> <li>Tile with a north-pointing arrow</li> <li>Tile with nothing</li> </ul> <p> Once a person steps onto a tile which has an arrow, the mystic force makes the person go to the next tile pointed by the arrow. If the next tile has an arrow, the person moves to the next, ans so on. The person moves on until he/she steps onto a tile which does not have the arrow (the tile with nothing). The entrance of the room is at the northwest corner. </p> <p> Your task is to write a program which simulates the movement of the person in the room. The program should read strings which represent the room and print the last position of the person. </p> <p> The input represents the room as seen from directly above, and up, down, left and right side of the input correspond to north, south, west and east side of the room respectively. The horizontal axis represents <i>x</i>-axis (from 0 to W-1, inclusive) and the vertical axis represents <i>y</i>-axis (from 0 to H-1, inclusive). The upper left tile corresponds to (0, 0). </p> <p> The following figure shows an example of the input: </p> <pre> 10 10 >>>v..>>>v ...v..^..v ...>>>^..v .........v .v<<<<...v .v...^...v .v...^<<<< .v........ .v...^.... .>>>>^.... </pre> <p> Characters represent tiles as follows: </p> <pre> '>': Tile with a east-pointing arrow '<': Tile with a west-pointing arrow '^': Tile with a north-pointing arrow 'v': Tile with a south-pointing arrow '.': Tile with nothing </pre> <p> If the person goes in cycles forever, your program should print "LOOP". You may assume that the person never goes outside of the room. </p> <H2>Input</H2> <p> The input consists of multiple datasets. The input ends with a line which contains two 0. Each dataset consists of: </p> <pre class="exp"> H W H lines where each line contains W characters </pre> <p> You can assume that 0 &lt; W, H &lt; 101. </p> <H2>Output</H2> <p> For each dataset, print the coordinate (X, Y) of the person or "LOOP" in a line. X and Y should be separated by a space. </p> <H2>Sample Input</H2> <pre> 10 10 >>>v..>>>v ...v..^..v >>>>>>^..v .........v .v<<<<...v .v.v.^...v .v.v.^<<<< .v.v.....v .v...^...v .>>>>^.... 6 10 >>>>>>>>>v .........v .........v >>>>v....v ^...v....v ^<<<<<<<<< 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 5 7 LOOP </pre>
p02139
<h1>Problem C: Round And Round</h1> <h2>Problem</h2> <p> 長さ$N$の数列$A=${$a_{1},a_{2},a_{3},...,a_{n}$}が与えられる。<br> $a_{i}$ ($i=1,2,3,...,n$)は、$i$で初期化されているものとする。<br><br> 以下の二種類のクエリを合計$Q$回処理せよ。<br> <ul> <li>数列$A$の先頭から$k$番目の要素の値を出力する。</li> <li>数列$A$の先頭から$k$と$k+1$番目を境界に二つの数列をスワップする。</li> </ul> <br>詳しくはサンプル入出力を参考にせよ。<br> </p> <h2>Input</h2> <p>入力は以下の形式で与えられる。</p> <pre> $N$ $Q$ $query_1$ $query_2$ ... $query_Q$ </pre> <p>各クエリは以下の二種類のいずれかの形式で与えられる。</p> クエリ$0$<br> $0$ $k$<br> 数列$A$の先頭から$k$番目の要素の値を出力する。<br> <br>クエリ$1$<br> $1$ $k$<br> 数列$A$の先頭から$k$と$k+1$番目を境界に二つの数列をスワップする。<br> <p> 入力はすべて整数で与えられる。<br><br> $1$行目に$N$, $Q$が空白区切りで与えられる。<br> $2$行目以降の$Q$行にクエリが改行区切りで与えられる。<br> 各クエリ内の数値は全て空白区切りである。 </p> <h2>Constraints</h2> <p>入力は以下の条件を満たす。</p> <ul> <li>$2 \leq N \leq 10^9 $</li> <li>$1 \leq Q \leq 10^5 $</li> </ul> <p>各クエリについて、入力は以下の条件を満たす。 <ul> クエリ$0$<br> <li>$1 \leq k \leq N $</li> <br>クエリ$1$<br> <li>$1 \leq k \leq N-1 $</li> </ul> <h2>Output</h2> <p> 各クエリ$1$に対し値を一行に出力せよ。<br> </p> <h2>Sample Input 1</h2> <pre> 5 4 1 2 0 2 1 1 0 3 </pre> <h2>Sample Output 1</h2> <pre> 4 1 </pre> 長さ$5$の数列$A=[1,2,3,4,5]$が与えられる<br> $1$番目のクエリで $[1,2,3,4,5]$ -> $[1,2] [3,4,5]$ -> $[3,4,5] [1,2]$ -> $[3,4,5,1,2]$ と数列が変化する。<br> $2$番目のクエリで先頭から$2$番目の要素の値である$4$を出力する。<br> $3$番目のクエリで $[3,4,5,1,2]$ -> $[3] [4,5,1,2]$ -> $[4,5,1,2] [3]$ -> $[4,5,1,2,3]$ と数列が変化する。<br> $4$番目のクエリで先頭から$3$番目の要素の値である$1$を出力する。<br> <h2>Sample Input 2</h2> <pre> 4 4 1 2 1 1 0 1 0 4 </pre> <h2>Sample Output 2</h2> <pre> 4 3 </pre> <h2>Sample Input 3</h2> <pre> 10 6 1 1 0 1 1 9 0 5 1 1 0 10 </pre> <h2>Sample Output 3</h2> <pre> 2 5 1 </pre>
p02990
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>K</var> blue balls and <var>N-K</var> red balls. The balls of the same color cannot be distinguished. Snuke and Takahashi are playing with these balls.</p> <p>First, Snuke will arrange the <var>N</var> balls in a row from left to right.</p> <p>Then, Takahashi will collect only the <var>K</var> blue balls. In one move, he can collect any number of consecutive blue balls. He will collect all the blue balls in the fewest moves possible.</p> <p>How many ways are there for Snuke to arrange the <var>N</var> balls in a row so that Takahashi will need exactly <var>i</var> moves to collect all the blue balls? Compute this number modulo <var>10^9+7</var> for each <var>i</var> such that <var>1 \leq i \leq K</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq K \leq N \leq 2000</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>K</var> lines. The <var>i</var>-th line (<var>1 \leq i \leq K</var>) should contain the number of ways to arrange the <var>N</var> balls so that Takahashi will need exactly <var>i</var> moves to collect all the blue balls, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 6 1 </pre> <p>There are three ways to arrange the balls so that Takahashi will need exactly one move: (B, B, B, R, R), (R, B, B, B, R), and (R, R, B, B, B). (R and B stands for red and blue, respectively).</p> <p>There are six ways to arrange the balls so that Takahashi will need exactly two moves: (B, B, R, B, R), (B, B, R, R, B), (R, B, B, R, B), (R, B, R, B, B), (B, R, B, B, R), and (B, R, R, B, B).</p> <p>There is one way to arrange the balls so that Takahashi will need exactly three moves: (B, R, B, R, B).</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2000 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1998 3990006 327341989 </pre> <p>Be sure to print the numbers of arrangements modulo <var>10^9+7</var>.</p></section> </div> </span>
p03682
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> towns on a plane. The <var>i</var>-th town is located at the coordinates <var>(x_i,y_i)</var>. There may be more than one town at the same coordinates.</p> <p>You can build a road between two towns at coordinates <var>(a,b)</var> and <var>(c,d)</var> for a cost of <var>min(|a-c|,|b-d|)</var> yen (the currency of Japan). It is not possible to build other types of roads.</p> <p>Your objective is to build roads so that it will be possible to travel between every pair of towns by traversing roads. At least how much money is necessary to achieve this?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 ≤ N ≤ 10^5</var></li> <li><var>0 ≤ x_i,y_i ≤ 10^9</var></li> <li>All input values are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>x_1</var> <var>y_1</var> <var>x_2</var> <var>y_2</var> : <var>x_N</var> <var>y_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the minimum necessary amount of money in order to build roads so that it will be possible to travel between every pair of towns by traversing roads.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 5 3 9 7 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>Build a road between Towns <var>1</var> and <var>2</var>, and another between Towns <var>2</var> and <var>3</var>. The total cost is <var>2+1=3</var> yen.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 8 3 4 9 12 19 18 1 13 5 7 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>8 </pre></section> </div> </span>
p03378
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N + 1</var> squares arranged in a row, numbered <var>0, 1, ..., N</var> from left to right.</p> <p>Initially, you are in Square <var>X</var>. You can freely travel between adjacent squares. Your goal is to reach Square <var>0</var> or Square <var>N</var>. However, for each <var>i = 1, 2, ..., M</var>, there is a toll gate in Square <var>A_i</var>, and traveling to Square <var>A_i</var> incurs a cost of <var>1</var>. It is guaranteed that there is no toll gate in Square <var>0</var>, Square <var>X</var> and Square <var>N</var>.</p> <p>Find the minimum cost incurred before reaching the goal.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 100</var></li> <li><var>1 \leq M \leq 100</var></li> <li><var>1 \leq X \leq N - 1</var></li> <li><var>1 \leq A_1 &lt; A_2 &lt; ... &lt; A_M \leq N</var></li> <li><var>A_i \neq X</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>M</var> <var>X</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>Print the minimum cost incurred before reaching the goal.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 3 3 1 2 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>1 </pre> <p>The optimal solution is as follows:</p> <ul> <li>First, travel from Square <var>3</var> to Square <var>4</var>. Here, there is a toll gate in Square <var>4</var>, so the cost of <var>1</var> is incurred.</li> <li>Then, travel from Square <var>4</var> to Square <var>5</var>. This time, no cost is incurred.</li> <li>Now, we are in Square <var>5</var> and we have reached the goal.</li> </ul> <p>In this case, the total cost incurred is <var>1</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>7 3 2 4 5 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>We may be able to reach the goal at no cost.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 7 5 1 2 3 4 6 8 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>3 </pre></section> </div> </span>
p01345
<H1><font color="#000">Problem G: </font> DON'T PANIC!</H1> <p> Arthur is an innocent man who used to live on the Earth. He had lived a really commonplace life, until the day when the Earth was destroyed by aliens, who were not evil invaders but just contractors ordered to build a hyperspace bypass. In the moment when the demolition beams were shot at the Earth by them, Arthur was in front of his house and almost about to be decomposed into hydrogen, oxygen, carbon and some other atoms. However, fortunately, he survived; one of his friend Ford, who was actually an alien and had come to the Earth in the course of his trip around the universe, took him up to a spaceship just before the beam reached him. </p> <p> Arthur and Ford successfully escaped, but it was only the beginning of their hardships. Soon it turned out that actually the spaceship was the contractor’s one itself, and as it can be easily imagined, they disliked humans. Therefore as soon as they found Arthur and Ford, they stopped at the nearest unexplored planet and dropped the two pity men out of the spaceship from 10 miles up above the land surface. </p> <p> Again they’re in a pinch! Fortunately our hero Ford has a special item that let them safely land to the planet, known as a parachute, so they don’t worry about that. The problem is that they are just falling freely and can’t change the landing point, which may be on ground or sea. They want to know if they can land peacefully or need some swimming to the nearest coast. </p> <p> Ford’s universal GPS gadget displays their expected position of landing by latitude/longitude. Also he has a guidebook that describes almost all the planets in the universe. According to it, the planet has the only one continent and hence only one sea. It has a description of the shape of the continent but, unfortunately, not in a intuitive way of graphical maps. So your task is to make a program to decide whether the point is on the land or not. </p> <H2>Input</H2> <p> <i>N</i><br> <i>P</i><sub>0</sub> <i>T</i><sub>0</sub><br> .<br> .<br> .<br> <i>P<sub>N</sub></i> <i>T<sub>N</sub></i><br> </p> <p> The first line of the input contains an integer <i>N</i> (3 &le; <i>N</i> &le; 1000). The second line contains two integers <i>P</i><sub>0</sub>, <i>T</i><sub>0</sub> which represents the latitude and the longitude of the point where Arthur and Ford are going to land. The following <i>N</i> lines describe the shape of the only continent on the planet. The <i>k</i>-th line contains two integers <i>P<sub>k</sub></i> and <i>T<sub>k</sub></i>, which represents the latitude and the longitude of a point <i>V<sub>k</sub></i>. The continent is described as a polygon with <i>N</i> vertices <i>V<sub>k</sub></i> on a sphere. The coastline of it is formed by cyclically connecting consecutive points with the shortest line. </p> <p> (<i>P<sub>k</sub></i>, <i>T<sub>k</sub></i>) (<i>k</i> = 0, 1, ...., <i>N</i>) satisfies -90 &le; <i>P<sub>k</sub></i> &le; 90, -180 &le; <i>T<sub>k</sub></i> &le; 180. Positive latitude means north and negative means south. Positive longitude means east and negative means west. The border of the continent is given by counterclockwise order and you can assume there is always exactly one way to connect given two consecutive points by minimum distance, and the shape of the continent is not selfcrossing. The landing point will be never on the coastline. </p> <H2>Output</H2> <p> If Arthur and Ford are going to land on the continent, print “Yes”. Otherwise “No”. </p> <H2>Sample Input 1</H2> <pre> 4 0 0 10 10 10 -10 -10 -10 -10 10 </pre> <H2>Output for the Sample Input 1</H2> <pre> Yes </pre> <H2>Sample Input 2</H2> <pre> 4 89 0 0 0 0 90 0 180 0 -90 </pre> <H2>Output for the Sample Input 2</H2> <pre> Yes </pre> <H2>Sample Input 3</H2> <pre> 4 89 0 0 0 0 -90 0 180 0 90 </pre> <H2>Output for the Sample Input 3</H2> <pre> No </pre>
p00807
<H1><font color="#000">Problem E:</font> Beehives</H1> <p> Taro and Hanako, students majoring in biology, have been engaged long in observations of beehives. Their interest is in finding any egg patterns laid by queen bees of a specific wild species. A queen bee is said to lay a batch ofeggs in a short time. Taro and Hanako have never seen queen bees laying eggs. Thus, every time they find beehives, they find eggs just laid in hive cells. </p> <p> Taro and Hanako have a convention to record an egg layout.. they assume the queen bee lays eggs, moving from one cell to an adjacent cell along a path containing no cycles. They record the path of cells with eggs. There is no guarantee in biology for them to find an acyclic path in every case. Yet they have never failed to do so in their observations. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_beehives1"> </center> <p> There are only six possible movements from a cell to an adjacent one, and they agree to write down those six by letters a, b, c, d, e, and f ounterclockwise as shown in Figure 2. Thus the layout in Figure 1 may be written down as "faafd". </p> <p> Taro and Hanako have investigated beehives in a forest independently. Each has his/her own way to approach beehives, protecting oneself from possible bee attacks. </p> <p> They are asked to report on their work jointly at a conference, and share their own observation records to draft a joint report. At this point they find a serious fault in their convention. They have never discussed which direction, in an absolute sense, should be taken as "a", and thus Figure 2 might be taken as, e.g., Figure 3 or Figure 4. The layout shown in Figure 1 may be recorded differently, depending on the direction looking at the beehive and the path assumed: "bcbdb" with combination of Figure 3 and Figure 5, or "bccac" with combination of Figure 4 and Figure 6. </p> <p> A beehive can be observed only from its front side and never from its back, so a layout cannot be confused with its mirror image. </p> <p> Since they may have observed the same layout independently, they have to find duplicated records in their observations (Of course, they do not record the exact place and the exact time of each observation). Your mission is to help Taro and Hanako by writing a program that checks whether two observation records are made from the same layout. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_beehives2"> </center> <H2>Input</H2> <p> The input starts with a line containing the number of record pairs that follow. The number is given with at most three digits. </p> <p> Each record pair consists of two lines of layout records and a line containing a hyphen. Each layout record consists of a sequence of letters a, b, c, d, e, and f. Note that a layout record may be an empty sequence if a queen bee laid only one egg by some reason. You can trust Taro and Hanako in that any of the paths in the input does not force you to visit any cell more than once. Any of lines in the input contain no characters other than those described above, and contain at most one hundred characters. </p> <H2>Output</H2> <p> For each pair of records, produce a line containing either "<span>true</span>" or "<span>false</span>": "<span>true</span>" if the two records represent the same layout, and "<span>false</span>" otherwise. A line should not contain any other characters. </p> <H2>Sample Input</H2> <pre> 5 faafd bcbdb - bcbdb bccac - faafd aafdd - aaafddd aaaeff - aaedd aafdd - </pre> <H2>Output for the Sample Input</H2> <pre> true true false false false </pre>
p03728
<span class="lang-en"> <p>Score : <var>2400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi loves sorting.</p> <p>He has a permutation <var>(p_1,p_2,...,p_N)</var> of the integers from <var>1</var> through <var>N</var>. Now, he will repeat the following operation until the permutation becomes <var>(1,2,...,N)</var>:</p> <ul> <li>First, we will define <em>high</em> and <em>low</em> elements in the permutation, as follows. The <var>i</var>-th element in the permutation is high if the maximum element between the <var>1</var>-st and <var>i</var>-th elements, inclusive, is the <var>i</var>-th element itself, and otherwise the <var>i</var>-th element is low.</li> <li>Then, let <var>a_1,a_2,...,a_k</var> be the values of the high elements, and <var>b_1,b_2,...,b_{N-k}</var> be the values of the low elements in the current permutation, <strong>in the order they appear in it</strong>.</li> <li>Lastly, rearrange the permutation into <var>(b_1,b_2,...,b_{N-k},a_1,a_2,...,a_k)</var>.</li> </ul> <p>How many operations are necessary until the permutation is sorted?</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≤ N ≤ 2×10^5</var></li> <li><var>(p_1,p_2,...,p_N)</var> is a permutation of the integers from <var>1</var> through <var>N</var>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>p_1</var> <var>p_2</var> ... <var>p_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of operations that are necessary until the permutation is sorted.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>5 3 5 1 2 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>The initial permutation is <var>(3,5,1,2,4)</var>, and each operation changes it as follows:</p> <ul> <li>In the first operation, the <var>1</var>-st and <var>2</var>-nd elements are high, and the <var>3</var>-rd, <var>4</var>-th and <var>5</var>-th are low. The permutation becomes: <var>(1,2,4,3,5)</var>.</li> <li>In the second operation, the <var>1</var>-st, <var>2</var>-nd, <var>3</var>-rd and <var>5</var>-th elements are high, and the <var>4</var>-th is low. The permutation becomes: <var>(3,1,2,4,5)</var>.</li> <li>In the third operation, the <var>1</var>-st, <var>4</var>-th and <var>5</var>-th elements are high, and the <var>2</var>-nd and <var>3</var>-rd and <var>5</var>-th are low. The permutation becomes: <var>(1,2,3,4,5)</var>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 5 4 3 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>4 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 2 10 5 7 3 6 4 9 8 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>6 </pre></section> </div> </span>
p01715
<h1>問題 D : TiMe Table </h1> <h2>問題文</h2> <p> ある学生は朝にいつも乗る通学バスで,あることに気がついた. そのバスの利用者がいつも同じなのだ. 気になってバスに乗っている利用者たちに聞いてみると,毎日決まった時刻にバス停に来ているようである. それなら,乗客にとってもっとよいバスの時間割があるのではないかとその学生は考えた. </p> <p> 学生の乗る通学路には,バスの営業所から終点までに<var>s</var>個のバス停が一直線に並んでいる.(営業所はバス停には含まれないが,終点はバス停に含まれる.) 各バス停には,営業所から近い方から順に<var>1</var> から <var>s</var> までの番号が付けられている. 営業所と <var>i</var> 番目のバス停の距離は <var>x_i</var> である. バスはまず営業所を出発し,それから <var>x_i</var> 経った後に <var>i</var> 番目のバス停に到着する. バス停には <var>n</var> 人の利用者がやって来る. <var>i</var> 番目の利用者は時刻 <var>t_i</var> にバス停 <var>p_i</var> にやって来る. </p> <p> この通学路には1日にちょうど <var>m</var> 本のバスが営業所から終点まで走ることになっている. バスはバス停に止まると,そのバス停で待っていた利用者を全員回収して,次のバス停に向かう. バス停で利用者を回収する時間は無視出来ると仮定する. いま各バスが営業所から出発する時刻を自由に決めることができるとき,利用者の待ち時間の和を最小化しよう. </p> <h2>入力形式</h2> <p> 入力は以下の形式で与えられる. <pre> <var>s</var> <var>n</var> <var>m</var> <var>x_1</var> <var>...</var> <var>x_s</var> <var>t_1</var> <var>p_1</var> <var>...</var> <var>t_n</var> <var>p_n</var> </pre> <h2>出力形式</h2> <p> 待ち時間の和の最小値を一行に出力せよ. </p> <h2>制約</h2> <ul> <li><var>1 &le; s, &ensp; n, &ensp; m &le; 2000</var></li> <li><var>1 &le; x_1 < x_2 < …< x_s &le; 10^4</var></li> <li><var>0 &le; t_i &le; 10^4</var></li> <li><var>1 &le; p_i &le; s</var></li> <li>入力値はすべて整数である.</li> </ul> <h2>入出力例</h2> <h3>入力例 1</h3> <pre> 2 2 1 1 5 0 1 0 2 </pre> <h3>出力例 1</h3> <pre> 4 </pre> <h3>入力例 2</h3> <pre> 2 3 2 1 15 0 1 5 1 5 2 </pre> <h3>出力例 2</h3> <pre> 5 </pre> この例では,バスを時刻 <var>&minus;10</var> と <var>4</var> に出発させることが最適である. <h3>入力例 3</h3> <pre> 4 8 1 6 38 105 390 14 1 4 2 39 3 89 2 32 4 1 1 25 1 60 4 </pre> <h3>出力例 3</h3> <pre> 1123 </pre>
p01200
<H1><font color="#000"></font>Resource</H1> <!-- Problem G --> <p> Dr. Keith Miller is a researcher who studies the history of Island of Constitutional People’s Country (ICPC). Many studies by him and his colleagues have revealed various facts about ICPC. Although it is a single large island today, it was divided in several smaller islands in some ancient period, and each island was ruled by a king. In addition to the islands, there were several <i>resource regions</i> on the sea, and people living in the islands used energy resource obtained in those regions. </p> <p> Recently Dr. Miller discovered some ancient documents that described the agreements made among the kings. Some of them focused on resource regions, and can be summarized as follows: each island was allowed to mine resource only in its exclusive resource zone (ERZ). The ERZ of each island was defined as a sea area within an agreed distance <i>d</i> from the boundary of the island. In case areas occur where more than one ERZ overwrapped, such areas were divided by equidistant curves, and each divided area belonged to the ERZ of the nearest island. </p> <p> Now Dr. Miller wants to know how much resource allocated to each island, which will help him to grasp the power balance among the islands. For that purpose, he called you as a talented programmer. Your task is to write a program that makes rough estimation about the amount of resource available for each island. For simplicity, the world map is represented on a two-dimensional plane, where each of the islands and the resource regions is represented as a convex polygon. Because of the difference in the resource deposit among the regions, the amount of resource per unit area is also given for each region. In this settings, the amount of resource available in a (partial) area of a region is given by &lt;<i>the amount per unit area</i>&gt; &times &lt;<i>the area size</i>&gt;. The total amount of resource for each island is given by the sum of the amount of resource available in all (partial) areas of the regions included in the ERZ. </p> <H2>Input</H2> <p> The input consists of no more than five test cases. </p> <p> The first line of each test case contains two integers <i>M</i> and <i>N</i> (1 &le; <i>M</i>, <i>N</i> &le; 5) that indicate the numbers of islands and resource regions, respectively. The next line contains a single real number <i>d</i> (0 &lt; <i>d</i> &le; 10) that represents the agreed distance for the ERZs. After that <i>M</i> lines appear to describe the islands: the <i>i</i>-th line specifies the shape of the <i>i</i>-th island as stated below. Then <i>N</i> lines appear to describe the resource regions: the <i>j</i>-th line contains a single real number <i>a<sub>j</sub></i> (0 &lt; <i>a<sub>j</sub></i> &le; 1), the amount of resource per unit area in the <i>j</i>-th region, followed by the specification for the shape of the <i>j</i>-th region. </p> <p> Each of the (polygonal) shapes is specified by a single integer <i>n</i> (3 &le; <i>n</i> &le; 6), the number of vertices in the shape, followed by <i>n</i> pairs of integers where the <i>k</i>-th pair <i>x<sub>k</sub></i> and <i>y<sub>k</sub></i> gives the coordinates of the <i>k</i>-th vertex. Each coordinate value ranges from 0 to 50 inclusive. The vertices are given in the counterclockwise order. No shape has vertices other than the endpoints of edges. No pair of shapes overwrap. </p> <p> Each real number in the input is given with up to two fractional digits. </p> <p> The input is terminated by a line that contains two zeros. </p> <H2>Output</H2> <p> For each test case, print <i>M</i> lines where the <i>i</i>-th line represents the total amount of resource for the <i>i</i>-th island. Each amount should be printed with one fractional digit, and should not contain an error greater than 0.1. </p> <p> Print an empty line between two consecutive cases. </p> <H2>Sample Input</H2> <pre> 2 3 10.00 3 10 10 20 10 10 20 4 30 10 40 10 40 20 30 20 1.00 3 0 0 10 0 0 10 0.50 4 20 15 25 15 25 20 20 20 0.75 6 40 35 50 40 40 50 30 50 25 45 30 40 4 1 5.00 3 0 0 24 0 0 24 3 50 0 50 24 26 0 3 0 50 0 26 24 50 3 50 50 26 50 50 26 1.00 4 25 0 50 25 25 50 0 25 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 35.4 5.6 133.3 133.3 133.3 133.3 </pre>
p04002
<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. At first, all cells were painted white.</p> <p>Snuke painted <var>N</var> of these cells. The <var>i</var>-th ( <var>1 \leq i \leq N</var> ) cell he painted is the cell at the <var>a_i</var>-th row and <var>b_i</var>-th column.</p> <p>Compute the following:</p> <ul> <li>For each integer <var>j</var> ( <var>0 \leq j \leq 9</var> ), how many subrectangles of size <var>3×3</var> of the grid contains exactly <var>j</var> black cells, after Snuke painted <var>N</var> cells?</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>3 \leq H \leq 10^9</var></li> <li><var>3 \leq W \leq 10^9</var></li> <li><var>0 \leq N \leq min(10^5,H×W)</var></li> <li><var>1 \leq a_i \leq H</var> <var>(1 \leq i \leq N)</var></li> <li><var>1 \leq b_i \leq W</var> <var>(1 \leq i \leq N)</var></li> <li><var>(a_i, b_i) \neq (a_j, b_j)</var> <var>(i \neq j)</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>H</var> <var>W</var> <var>N</var> <var>a_1</var> <var>b_1</var> : <var>a_N</var> <var>b_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>10</var> lines. The <var>(j+1)</var>-th ( <var>0 \leq j \leq 9</var> ) line should contain the number of the subrectangles of size <var>3×3</var> of the grid that contains exactly <var>j</var> black cells.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 5 8 1 1 1 4 1 5 2 3 3 1 3 2 3 4 4 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>0 0 0 2 4 0 0 0 0 0 </pre> <p><img alt="" src="https://atcoder.jp/img/arc061/30326702be007759dce81231012a8353.png"/></p> <p>There are six subrectangles of size <var>3×3</var>. Two of them contain three black cells each, and the remaining four contain four black cells each.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>10 10 20 1 1 1 4 1 9 2 5 3 10 4 2 4 7 5 9 6 4 6 6 6 7 7 1 7 3 7 7 8 1 8 5 8 10 9 2 10 4 10 9 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>4 26 22 10 2 0 0 0 0 0 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1000000000 1000000000 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>999999996000000004 0 0 0 0 0 0 0 0 0 </pre></section> </div> </span>
p00942
<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 H Rotating Cutter Bits</h2> <p> The machine tool technology never stops its development. One of the recent proposals is more flexible lathes in which not only the workpiece but also the cutter bit rotate around parallel axles in synchronization. When the lathe is switched on, the workpiece and the cutter bit start rotating at the same angular velocity, that is, to the same direction and at the same rotational speed. On collision with the cutter bit, parts of the workpiece that intersect with the cutter bit are cut out. </p> <p> To show the usefulness of the mechanism, you are asked to simulate the cutting process by such a lathe. </p> <p> Although the workpiece and the cutter bit may have complex shapes, focusing on cross sections of them on a plane perpendicular to the spinning axles would suffice. We introduce an $xy$-coordinate system on a plane perpendicular to the two axles, in which the center of rotation of the workpiece is at the origin $(0, 0)$, while that of the cutter bit is at $(L, 0)$. You can assume both the workpiece and the cutter bit have polygonal cross sections, not necessarily convex. </p> <p> Note that, even when this cross section of the workpiece is divided into two or more parts, the workpiece remain undivided on other cross sections. </p> <p> We refer to the lattice points (points with both $x$ and $y$ coordinates being integers) strictly inside, that is, inside and not on an edge, of the workpiece before the rotation as <i>points</i> of interest, or POI in short. </p> <p> Our interest is in how many POI will remain after one full rotation of 360 degrees of both the workpiece and the cutter bit. POI are said to remain if they are strictly inside the resultant workpiece. Write a program that counts them for the given workpiece and cutter bit configuration. </p> <p> Figure H.1(a) illustrates the workpiece (in black line) and the cutter bit (in blue line) given in Sample Input 1. Two circles indicate positions of the rotation centers of the workpiece and the cutter bit. The red cross-shaped marks indicate the POI. </p> <p> Figure H.1(b) illustrates the workpiece and the cutter bit in progress in case that the rotation direction is clockwise. The light blue area indicates the area cut-off. </p> <p> Figure H.1(c) illustrates the result of this sample. Note that one of POI is on the edge of the resulting shape. You should not count this point. There are eight POI remained. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ICPCAsia2015_RotatingCutterBits"><br> <p> Figure H.1. The workpiece and the cutter bit in Sample 1 </p> </center> <h3>Input</h3> <p> The input consists of a single test case with the following format.<br> <br> $M$ $N$ $L$<br> $x_{w1}$ $y_{w1}$<br> ...<br> $x_{wM}$ $y_{wM}$<br> $x_{c1}$ $y_{c1}$<br> ...<br> $x_{cN}$ $y_{cN}$<br> <br> The first line contains three integers. $M$ is the number of vertices of the workpiece $(4 \leq M \leq 20)$ and $N$ is the number of vertices of the cutter bit $(4 \leq N \leq 20)$. $L$ specifies the position of the rotation center of the cutter bit $(1 \leq L \leq 10000)$. </p> <p> Each of the following $M$ lines contains two integers. The $i$-th line has $x_{wi}$ and $y_{wi}$, telling that the position of the $i$-th vertex of the workpiece has the coordinates $(x_{wi}, y_{wi})$. The vertices are given in the counter-clockwise order. </p> <p> $N$ more following lines are positions of the vertices of the cutter bit, in the same manner, but the coordinates are given as offsets from its center of rotation, $(L, 0)$. That is, the position of the $j$-th vertex of the cutter bit has the coordinates $(L + x_{cj} , y_{cj} )$. </p> <p> You may assume $-10000 \leq x_{wi}, y_{wi}, x_{cj} , y_{cj} \leq 10000$ for $1 \leq i \leq M$ and $1 \leq j \leq N$. </p> <p> All the edges of the workpiece and the cutter bit at initial rotation positions are parallel to the $x$-axis or the $y$-axis. In other words, for each $i$ $(1 \leq i \leq M), x_{wi} = x_{wi'}$ or $y_{wi} = y_{wi'}$ holds, where $i' = (i $ mod$ M) + 1$. Edges are parallel to the $x$- and the $y$-axes alternately. These can also be said about the cutter bit. </p> <p> You may assume that the cross section of the workpiece forms a simple polygon, that is, no two edges have common points except for adjacent edges. The same can be said about the cutter bit. The workpiece and the cutter bit do not touch or overlap before starting the rotation. </p> <p> Note that $(0, 0)$ is not always inside the workpiece and $(L, 0)$ is not always inside the cutter bit. </p> <h3>Output</h3> <p> Output the number of POI remaining strictly inside the workpiece. </p> <h3>Sample Input 1</h3> <pre>4 6 5 -2 5 -2 -1 2 -1 2 5 -2 1 -2 0 0 0 0 -2 2 -2 2 1</pre> <h3>Sample Output 1</h3> <pre>8</pre> <h3>Sample Input 2</h3> <pre>14 14 6000 -3000 3000 -3000 -3000 3000 -3000 3000 -2000 2000 -2000 2000 -1000 1000 -1000 1000 0 0 0 0 1000 -1000 1000 -1000 2000 -2000 2000 -2000 3000 3000 3000 -3000 3000 -3000 2000 -2000 2000 -2000 1000 -1000 1000 -1000 0 0 0 0 -1000 1000 -1000 1000 -2000 2000 -2000 2000 -3000 3000 -3000</pre> <h3>Sample Output 2</h3> <pre>6785772</pre> <h3>Sample Input 3</h3> <pre>12 12 11 -50 45 -50 -45 40 -45 40 25 -10 25 -10 -5 0 -5 0 15 30 15 30 -35 -40 -35 -40 45 50 -45 50 45 -40 45 -40 -25 10 -25 10 5 0 5 0 -15 -30 -15 -30 35 40 35 40 -45</pre> <h3>Sample Output 3</h3> <pre>966</pre> <h3>Sample Input 4</h3> <pre>20 4 11 -5 5 -5 -10 -4 -10 -4 -1 -3 -1 -3 -10 1 -10 1 -4 0 -4 0 -1 1 -1 1 0 4 0 4 -1 10 -1 10 3 1 3 1 4 10 4 10 5 0 0 3 0 3 3 0 3</pre> <h3>Sample Output 4</h3> <pre>64</pre>
p01650
<h2>Problem Statement</h2> <p> There is a maze which can be described as a <var>W \times H</var> grid. The upper-left cell is denoted as (1, 1), and the lower-right cell is <var>(W, H)</var>. You are now at the cell (1, 1) and have to go to the cell <var>(W, H)</var>. However, you can only move to the right adjacent cell or to the lower adjacent cell. The following figure is an example of a maze. </p> <pre> ...#...... a###.##### .bc...A... ##.#C#d#.# .#B#.#.### .#...#e.D. .#A..###.# ..e.c#..E. ####d###.# #....#.#.# ##E...d.C. </pre> <p> In the maze, some cells are free (denoted by <code>.</code>) and some cells are occupied by rocks (denoted by <code>#</code>), where you cannot enter. Also there are jewels (denoted by lowercase alphabets) in some of the free cells and holes to place jewels (denoted by uppercase alphabets). Different alphabets correspond to different types of jewels, i.e. a cell denoted by <code>a</code> contains a jewel of type A, and a cell denoted by <code>A</code> contains a hole to place a jewel of type A. It is said that, when we place a jewel to a corresponding hole, something happy will happen. </p> <p> At the cells with jewels, you can choose whether you pick a jewel or not. Similarly, at the cells with holes, you can choose whether you place a jewel you have or not. Initially you do not have any jewels. You have a very big bag, so you can bring arbitrarily many jewels. However, your bag is a stack, that is, you can only place the jewel that you picked up last. </p> <p> On the way from cell (1, 1) to cell <var>(W, H)</var>, how many jewels can you place to correct holes? </p> <h2>Input</h2> <p> The input contains a sequence of datasets. The end of the input is indicated by a line containing two zeroes. Each dataset is formatted as follows. </p> <pre> <var>H</var> <var>W</var> <var>C_{11}</var> <var>C_{12}</var> ... <var>C_{1W}</var> <var>C_{21}</var> <var>C_{22}</var> ... <var>C_{2W}</var> ... <var>C_{H1}</var> <var>C_{H2}</var> ... <var>C_{HW}</var> </pre> <p> Here, <var>H</var> and <var>W</var> are the height and width of the grid. You may assume <var>1 \leq W, H \leq 50</var>. The rest of the datasets consists of <var>H</var> lines, each of which is composed of <var>W</var> letters. Each letter <var>C_{ij}</var> specifies the type of the cell <var>(i, j)</var> as described before. It is guaranteed that <var>C_{11}</var> and <var>C_{WH}</var> are never <code>#</code>. </p> <p> You may also assume that each lowercase or uppercase alphabet appear at most 10 times in each dataset. </p> <h2>Output</h2> <p> For each dataset, output the maximum number of jewels that you can place to corresponding holes. If you cannot reach the cell <var>(W, H)</var>, output -1. </p> <h2>Sample Input</h2> <pre> 3 3 ac# b#C .BA 3 3 aaZ a#Z aZZ 3 3 ..# .#. #.. 1 50 abcdefghijklmnopqrstuvwxyYXWVUTSRQPONMLKJIHGFEDCBA 1 50 aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyY 1 50 abcdefghijklmnopqrstuvwxyABCDEFGHIJKLMNOPQRSTUVWXY 1 50 aaaaaaaaaabbbbbbbbbbcccccCCCCCBBBBBBBBBBAAAAAAAAAA 10 10 ...#...... a###.##### .bc...A... ##.#C#d#.# .#B#.#.### .#...#e.D. .#A..###.# ..e.c#..E. ####d###.# ##E...D.C. 0 0 </pre> <h2>Output for the Sample Input</h2> <pre> 2 0 -1 25 25 1 25 4 </pre>
p03397
<span class="lang-en"> <p>Score : <var>1600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Taichi thinks a binary string <var>X</var> of odd length <var>N</var> is <strong>beautiful</strong> if it is possible to apply the following operation <var>\frac{N-1}{2}</var> times so that the only character of the resulting string is <code>1</code> :</p> <ul> <li>Choose three <strong>consecutive</strong> bits of <var>X</var> and replace them by their median. For example, we can turn <code>00110</code> into <code>010</code> by applying the operation to the middle three bits.</li> </ul> <p>Taichi has a string <var>S</var> consisting of characters <code>0</code>, <code>1</code> and <code>?</code>. Taichi wants to know the number of ways to replace the question marks with <code>1</code> or <code>0</code> so that the resulting string is beautiful, modulo <var>10^{9} + 7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq |S| \leq 300000</var></li> <li><var>|S|</var> is odd.</li> <li>All characters of <var>S</var> are either <code>0</code>, <code>1</code> or <code>?</code>.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>S</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of ways to replace the question marks so that the resulting string is beautiful, modulo <var>10^{9} + 7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>1??00 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> <p>There are <var>4</var> ways to replace the question marks with <code>0</code> or <code>1</code> :</p> <ul> <li> <p><code>11100</code> : This string is beautiful because we can first perform the operation on the last <var>3</var> bits to get <code>110</code> and then on the only <var>3</var> bits to get <code>1</code>.</p> </li> <li> <p><code>11000</code> : This string is beautiful because we can first perform the operation on the last <var>3</var> bits to get <code>110</code> and then on the only <var>3</var> bits to get <code>1</code>.</p> </li> <li> <p><code>10100</code> : This string is not beautiful because there is no sequence of operations such that the final string is <code>1</code>.</p> </li> <li> <p><code>10000</code> : This string is not beautiful because there is no sequence of operations such that the final string is <code>1</code>.</p> </li> </ul> <p>Thus, there are <var>2</var> ways to form a beautiful string.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>? </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 </pre> <p>In this case, <code>1</code> is the only beautiful string.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>?0101???10???00?1???????????????0????????????1????0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>402589311 </pre> <p>Remember to output your answer modulo <var>10^{9} + 7</var>.</p></section> </div> </span>
p00411
<h1>目盛りのないストップウォッチ</h1>   <p> 図のようなストップウォッチがあります。このストップウォッチには0を示す目印が一つあるだけで、目盛りがありません。起動した瞬間、針は目印を指し、そこから針は軸を中心に一定の割合で時計回りに回転します。目盛りがないので、起動からの経過時間を直接読み取ることはできません。その代わり、針が目印から時計回りに$a$度回ったときの経過時間が$t$秒であることがわかっています。ただし、$a$は360度未満とします。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/PCK2019_stop_watch"></img> </center> <p> 角度$a$と経過時間$t$が与えられたとき、ストップウォッチ起動後に読み取った針の角度rが表す経過時間を求めるプログラムを作成せよ。ただし、針が1周していないことはわかっているものとする。 </p> <h2>入力</h2> <p> 入力は以下の形式で与えられる。 </p> <pre> $a$ $t$ $r$ </pre> <p> 1行に角度$a$ ($1 \leq a \leq 359$)と角度$a$のときの経過時間$t$ ($1 \leq t \leq 1,000$)、読み取った角度$r$ ($0 \leq r \leq 359$)がすべて整数で与えられる。ただし、$a$と$r$の単位は度、$t$の単位は秒とする。 </p> <h2>出力</h2> <p> 読み取った針の角度が表す経過時間を秒で1行に実数で出力する。ただし、誤差がプラスマイナス0.001を超えてはならない。<!--この条件を満たせば小数点以下何桁表示してもよい。--> </p> <h2>入出力例</h2> <h3>入力例1</h3> <pre> 180 120 90 </pre> <h3>出力例1</h3> <pre> 60.0 </pre> <h3>入力例2</h3> <pre> 90 100 120 </pre> <h3>出力例2</h3> <pre> 133.333333 </pre>
p00041
<H1>式</H1> <p> 与えられた 4 つの 1 から 9 の整数を使って、答えが 10 になる式をつくります。 4 つの整数 <var>a, b, c, d</var> を入力したとき、下記の条件に従い、答えが 10 になる式を出力するプログラムを作成してください。また、答えが複数ある時は、最初に見つかった答えだけを出力するものとします。答えがない時は、0 と出力してください。 </p> <ul> <li>演算子として、加算 (+)、減算 (-)、乗算 (*) だけを使います。除算 (/) は使いません。使用できる演算子は3個です。</li> <li>数を4つとも使わなければいけません。</li> <li>4つの数の順番は自由に入れ換えてかまいません。</li> <li>カッコを使ってもかまいません。使用できるカッコは3組(6個)以下です。</li> </ul> <H2>Input</H2> <p> 複数のデータセットが与えられます。各データセットの形式は以下のとおり: </p> <pre><var>a</var> <var>b</var> <var>c</var> <var>d</var></pre> <p> 入力は4つの 0 で終了します。データセットの数は 40 を超えません。 </p> <H2>Output</H2> <p> 各データセットについて、与えられた 4 つの整数と上記の演算記号およびカッコを組み合わせて値が 10 となる式または 0 を1行に出力してください。式の文字列が 1024 文字を超えてはいけません。 </p> <H2>Sample Input</H2> <pre> 8 7 9 9 4 4 4 4 5 5 7 5 0 0 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> ((9 * (9 - 7)) - 8) 0 ((7 * 5) - (5 * 5)) </pre>
p02586
<span class="lang-en"> <p>Score : <var>500</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>K</var> items placed on a grid of squares with <var>R</var> rows and <var>C</var> columns. Let <var>(i, j)</var> denote the square at the <var>i</var>-th row (<var>1 \leq i \leq R</var>) and the <var>j</var>-th column (<var>1 \leq j \leq C</var>). The <var>i</var>-th item is at <var>(r_i, c_i)</var> and has the value <var>v_i</var>.</p> <p>Takahashi will begin at <var>(1, 1)</var>, the start, and get to <var>(R, C)</var>, the goal. When he is at <var>(i, j)</var>, he can move to <var>(i + 1, j)</var> or <var>(i, j + 1)</var> (but cannot move to a non-existent square).</p> <p>He can pick up items on the squares he visits, including the start and the goal, but at most three for each row. It is allowed to ignore the item on a square he visits.</p> <p>Find the maximum possible sum of the values of items he picks up.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq R, C \leq 3000</var></li> <li><var>1 \leq K \leq \min(2 \times 10^5, R \times C)</var></li> <li><var>1 \leq r_i \leq R</var></li> <li><var>1 \leq c_i \leq C</var></li> <li><var>(r_i, c_i) \neq (r_j, c_j) (i \neq j)</var></li> <li><var>1 \leq v_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>R</var> <var>C</var> <var>K</var> <var>r_1</var> <var>c_1</var> <var>v_1</var> <var>r_2</var> <var>c_2</var> <var>v_2</var> <var>:</var> <var>r_K</var> <var>c_K</var> <var>v_K</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum possible sum of the values of items Takahashi picks up.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 2 3 1 1 3 2 1 4 1 2 5 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>8 </pre> <p>He has two ways to get to the goal:</p> <ul> <li>Visit <var>(1, 1)</var>, <var>(1, 2)</var>, and <var>(2, 2)</var>, in this order. In this case, the total value of the items he can pick up is <var>3 + 5 = 8</var>.</li> <li>Visit <var>(1, 1)</var>, <var>(2, 1)</var>, and <var>(2, 2)</var>, in this order. In this case, the total value of the items he can pick up is <var>3 + 4 = 7</var>.</li> </ul> <p>Thus, the maximum possible sum of the values of items he picks up is <var>8</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 5 5 1 1 3 2 4 20 1 2 1 1 3 4 1 4 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>29 </pre> <p>We have four items in the <var>1</var>-st row. The optimal choices are as follows:</p> <ul> <li>Visit <var>(1, 1)</var> <var>(1, 2)</var>, <var>(1, 3)</var>, <var>(1, 4)</var>, <var>(2, 4)</var>, and <var>(2, 5)</var>, in this order, and pick up all items except the one on <var>(1, 2)</var>. Then, the total value of the items he picks up will be <var>3 + 4 + 2 + 20 = 29</var>.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>4 5 10 2 5 12 1 5 12 2 3 15 1 2 20 1 1 28 2 4 26 3 2 27 4 5 21 3 5 10 1 3 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>142 </pre></section> </div> </span>
p01579
<H1><font color="#000">Problem J:</font> Substring Expression</H1> <p> Trees are sometimes represented in the form of strings. Here is one of the most popular ways to represent unlabeled trees: </p> <ul> <li> Leaves are represented by "<span>()</span>".</li> <li> Other nodes (i.e. internal nodes) are represented by "<span>(</span> <i>S</i><sub>1</sub> <i>S</i><sub>2</sub> ... <i>S<sub>n</sub></i> <span>)</span>", where <i>S<sub>i</sub></i> is the string representing the <i>i</i>-th subnode.</li> </ul> <p> For example, the tree depicted in the figure below is represented by a string "<span style="font-family:courier new">((()())())</span>". </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_substringExpression1"> </center> <p> A strange boy Norward is playing with such strings. He has found that a string sometimes remains valid as the representation of a tree even after one successive portion is removed from it. For example, removing the underlined portion from the string "<span style="font-family:courier new">((()<span style="text-decoration: underline;">())(</span>))</span>" results in "<span style="font-family:courier new">((()))</span>", which represents the tree depicted below. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_substringExpression2"> </center> <p> However, he has no way to know how many ways of such removal there are. Your task is to write a program for it, so that his curiosity is fulfilled. </p> <H2>Input</H2> <p> The input contains a string that represents some unlabeled tree. The string consists of up to 100,000 characters. </p> <H2>Output</H2> <p> Print the number of portions of the given string such that removing them results in strings that represent other valid trees. </p> <H2>Sample Input 1</H2> <pre> ((()())()) </pre> <H2>Output for the Sample Input 1</H2> <pre> 10 </pre>
p03544
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>It is November <var>18</var> now in Japan. By the way, <var>11</var> and <var>18</var> are adjacent Lucas numbers.</p> <p>You are given an integer <var>N</var>. Find the <var>N</var>-th Lucas number.</p> <p>Here, the <var>i</var>-th Lucas number <var>L_i</var> is defined as follows:</p> <ul> <li><var>L_0=2</var></li> <li><var>L_1=1</var></li> <li><var>L_i=L_{i-1}+L_{i-2} (i≥2)</var></li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1≤N≤86</var></li> <li>It is guaranteed that the answer is less than <var>10^{18}</var>.</li> <li><var>N</var> is an integer.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the <var>N</var>-th Lucas number.</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>11 </pre> <ul> <li><var>L_0=2</var></li> <li><var>L_1=1</var></li> <li><var>L_2=L_0+L_1=3</var></li> <li><var>L_3=L_1+L_2=4</var></li> <li><var>L_4=L_2+L_3=7</var></li> <li><var>L_5=L_3+L_4=11</var></li> </ul> <p>Thus, the <var>5</var>-th Lucas number is <var>11</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>86 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>939587134549734843 </pre></section> </div> </span>
p01083
<h1>Problem L: RedBlue</h1> <h2>Story</h2> <p> 天空都市AIZUのUZIA高校では、競技プログラミングの部活動がとても盛んである。 この部活には、<var>n</var>人のRed Coderと<var>n</var>人のBlue Coderが所属している。 </p> <p> ある日の部活の時間に、Red CoderとBlue Coderでペアを組み、この部活から<var>n</var>組、KCPというコンテストに参加することとなった。この高校では、ペアを組む学生同士は握手するという習わしがあるので、部員たちは今すぐ自分のパートナーを見つけることにした。 </p> <p> 部員たちは全速力で走るため、まっすぐにしか進めない。また、部員たちは、それぞれの部員が移動する距離の総和をできるだけ小さくしたいと思っている。 </p> <p> なお、部室には2つの円形のテーブルが置いてある。 </p> <h2>Problem</h2> <p> 二次元平面上に2つの円、<var>n</var>個の赤色の点、<var>n</var>個の青色の点がある。 2つの円の中心座標はそれぞれ(<var>x<sub>1</sub></var>, <var>y<sub>1</sub></var>), (<var>x<sub>2</sub></var>, <var>y<sub>2</sub></var>)であり、半径はそれぞれ<var>r<sub>1</sub></var>, <var>r<sub>2</sub></var>である。 赤い点<var>i</var>は、座標(<var>rx<sub>i</sub></var>, <var>ry<sub>i</sub></var>)にあり、青い点<var>j</var>は、座標(<var>bx<sub>j</sub></var>, <var>by<sub>j</sub></var>)にある。 </p> <p> あなたは、以下の操作を<var>n</var>回繰り返す必要がある。<br> まだ選ばれていない点の中から、赤色の点と青色の点を1つずつ選んで、2点の共通の目的地を設定し、その目的地に向かって2点をそれぞれまっすぐ移動させる。 目的地は二次元平面上であれば、どこに設定しても構わない。ただし、選んだ2点は移動の際に円の内部を通過することはできないので、そのような移動が発生する目的地を設定することはできない。 </p> <p> <var>n</var>回の操作をしたときの移動距離の総和を最小化せよ。 <var>n</var>回の操作を行えない場合は、代わりに"Impossible" (""は除く) と出力せよ。 </p> <h2>Input</h2> <p>入力は以下の形式で与えられる。</p> <pre> <var>n</var> <var>x<sub>1</sub></var> <var>y<sub>1</sub></var> <var>r<sub>1</sub></var> <var>x<sub>2</sub></var> <var>y<sub>2</sub></var> <var>r<sub>2</sub></var> <var>rx<sub>1</sub></var> <var>ry<sub>1</sub></var> <var>rx<sub>2</sub></var> <var>ry<sub>2</sub></var> ... <var>rx<sub>n</sub></var> <var>ry<sub>n</sub></var> <var>bx<sub>1</sub></var> <var>by<sub>1</sub></var> <var>bx<sub>2</sub></var> <var>by<sub>2</sub></var> ... <var>bx<sub>n</sub></var> <var>by<sub>n</sub></var></pre> <p> 入力は全て整数で与えられる。<br> 1行目に<var>n</var>が与えられる。<br> 2行目に<var>x<sub>1</sub></var>, <var>y<sub>1</sub></var>, <var>r<sub>1</sub></var>が空白区切りで与えられる。<br> 3行目に<var>x<sub>2</sub></var>, <var>y<sub>2</sub></var>, <var>r<sub>2</sub></var>が空白区切りで与えられる。<br> 4から3+<var>n</var>行に赤い点の座標(<var>rx<sub>i</sub></var>, <var>ry<sub>i</sub></var>)が空白区切りで与えられる。<br> 4+<var>n</var>から3+2&times;<var>n</var>行に青い点の座標(<var>bx<sub>j</sub></var>, <var>by<sub>j</sub></var>)が空白区切りで与えられる。 </p> <h2>Constraints</h2> <p>入力は以下の条件を満たす。</p> <ul> <li>1 &le; <var>n</var> &le; 100</li> <li>-1000 &le; <var>x<sub>i</sub></var>, <var>y<sub>i</sub></var> &le; 1000</li> <li>1 &le; <var>r<sub>i</sub></var> &le; 50</li> <li>-1000 &le; <var>rx<sub>i</sub></var>, <var>ry<sub>i</sub></var>, <var>bx<sub>i</sub></var>, <var>by<sub>i</sub></var> &le; 1000</li> <li>同じ座標に複数の点が存在していることはない</li> <li>任意の円の半径を絶対値10<sup>-9</sup>以内で変化させても、高々絶対値10<sup>-3</sup>しか変化しない</li> <li>任意の円の半径を絶対値10<sup>-9</sup>以内で変化させても、"Impossible"なケースは"Impossible"のままである</li> <li>解は10000を超えない</li> <li>どの点も、円から10<sup>-3</sup>以上離れていて、点が円周上に存在したり、点が円に内包されることはない</li> <li>2つの円は共通面積を持たず、10<sup>-3</sup>以上離れていることが保証される</li> </ul> <h2>Output</h2> <p> <var>n</var>回の操作をしたときの移動距離の総和の最小値を1行に出力せよ。なお、出力はジャッジ解の出力との絶対誤差が10<sup>-2</sup>以内であれば許容される。<br> <var>n</var>回の操作を行えない場合は、代わりに"Impossible" (""は除く) と出力せよ。 </p> <h2>Sample Input 1</h2> <pre> 2 3 3 2 8 3 2 0 3 3 7 8 0 8 7 </pre> <h2>Sample Output 1</h2> <pre> 13.8190642862 </pre> <p><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2016Day2AIZU_L_sample1" alt="Sample1の図示"></p> <h2>Sample Input 2</h2> <pre> 2 3 3 2 8 3 2 3 0 3 7 8 0 8 7 </pre> <h2>Sample Output 2</h2> <pre> 10.0000000000 </pre> <p><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2016Day2AIZU_L_sample2" alt="Sample2の図示"></p> <h2>Sample Input 3</h2> <pre> 2 3 3 2 8 3 2 0 0 0 5 11 0 11 5 </pre> <h2>Sample Output 3</h2> <pre> 22.0000000000 </pre> <p><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2016Day2AIZU_L_sample3" alt="Sample3の図示"></p> <h2>Sample Input 4</h2> <pre> 1 10 10 10 31 10 10 15 19 26 1 </pre> <h2>Sample Output 4</h2> <pre> Impossible </pre> <p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_ACPC2016Day2AIZU_L_sample4" alt="Sample4の図示"><br> 点同士をつなぐことはできません。 </p>
p01129
<h1>Data Center on Fire</h1> <p> 今から少し未来の話である.高密度記憶および長期保存可能である記録デバイスが開発されてきたが,コンテンツが生み出される速度が異常なほどに速かったため,データセンターを設立した.データセンターを設立した当初は小さな建物だったが,増え続けるデータにあわせて何度も拡張工事をしたため,性能の異なるエレベータを何基も持つこととなった. </p> <p> ところが,データセンターで火災が発生した.火は一定時間だけ経過すると上の階ないし下の階に燃え広がる.また,火がついてから一定時間だけ経過するとその階は焼失してしまう.そこでエレベータを使ってデバイスを運び出すこととした.このエレベータは耐火性能が完璧であるため,階の焼失に関わらず任意の階へ移動できる.また,非常に強力な加速減速装置を持つことから,加速および減速にかかる時間は無視できるほど小さいため,一瞬にして定常速度に加速すること,あるいは停止することができる.また,緊急時においてはいわゆる「開」ボタンが機能しないようにプログラムされているため,エレベータの停止時間は運び出す(あるいは降ろす)デバイスの個数にかかわらず一定である.また,階の焼失前に到着したエレベータによって運び出されるデバイスについては,たとえエレベータの出発前に階が焼失したとしても,焼失の影響を受けない.ただし,エレベータに乗せることができなかったデバイスは当然ながら焼失する. </p> <p> エレベータはどの階から回収してよいか分からないため,デバイスのある最上階を目指すようにプログラムされている.ただし,エレベータ同士は通信可能であり,別のエレベータが目的階に到着した瞬間に情報が通信される.到着したエレベータに全てのデバイスが積みこめることがわかったときは,目的階よりも下にあり,回収可能なデバイスが残っている階のうちで最上階に目的階を変更する.また,焼失のために目的階に向かう必要性が失われたときも,同様にして目的階を変更する.目的階を変更するときに,移動方向を変更する必要があるときは,即座に移動方向を変更する.また,エレベータが満杯になってそれ以上のデバイスを積みこむことができないとき,あるいは回収可能なデバイスが残っていないときは 1 階を目指す. </p> <p> あなたの仕事は,上記の条件のもとで,退避させることのできたデバイスの個数および到着時刻を求めるプログラムを作成することである. </p> <h3>Input</h3> <p> 入力は複数のデータセットから構成される.それぞれのデータセットは次の形式で与えられる. <blockquote> <i>N</i> <i>M</i><br> <i>d</i><br> <i>n</i><sub>1</sub> <i>n</i><sub>2</sub> ... <i>n</i><sub><i>N</i></sub><br> <i>c</i><sub>1</sub> <i>v</i><sub>1</sub> <i>ts</i><sub>1</sub> <i>x</i><sub>1</sub><br> <i>c</i><sub>2</sub> <i>v</i><sub>2</sub> <i>ts</i><sub>2</sub> <i>x</i><sub>2</sub><br> ...<br> <i>c</i><sub><i>M</i></sub> <i>v</i><sub><i>M</i></sub> <i>ts</i><sub><i>M</i></sub> <i>x</i><sub><i>M</i></sub> <i>k</i> <i>tx</i> <i>ty</i> <i>tz</i> </blockquote> <p> 記号の意味は次のとおりである.入力中の値はすべて整数である. </p> <ul> <li><i>N</i> (2 &lt;= <i>N</i> &lt;= 30),<i>M</i> (1 &lt;= <i>M</i> &lt;= 10)はそれぞれビルの階数,エレベータの基数を表す.</li> <li><i>d</i> (1000 &lt;= <i>d</i> &lt;= 10000)は階と階の間の距離を表す.</li> <li><i>n</i><sub><i>i</i></sub> (0 &lt;= <i>n</i><sub><i>i</i></sub> &lt;= 100) は <i>i</i> 階にあるデバイスの個数を表す.</li> <li><i>c</i><sub><i>i</i></sub> (1 &lt;= <i>c</i><sub><i>i</i></sub> &lt;= 50),<i>v</i><sub><i>i</i></sub> (1 &lt;= <i>v</i><sub><i>i</i></sub> &lt;= 2000),<i>ts</i><sub><i>i</i></sub> (1 &lt;= <i>ts</i><sub><i>i</i></sub> &lt;= 20),<i>x</i><sub><i>i</i></sub> (1 &lt;= <i>x</i><sub><i>i</i></sub> &lt;= <i>N</i>)はそれぞれ <i>i</i> 番目のエレベータの容量,速度,停止時間,初期位置をあらわす.初期位置は何階にあるかで表される.</li> <li><i>k</i> (2 &lt;= <i>k</i> &lt;= <i>N</i>),<i>tx</i> (30 &lt;= <i>tx</i> &lt;= 300),<i>ty</i> (30 &lt;= <i>ty</i> &lt;= 300),<i>tz</i> (30 &lt;= <i>tz</i> &lt;= 300)はそれぞれ火元の階,火がついてから焼失するまでの時間,上に燃え移るまでの時間,下に燃え移るまでの時間を表す.</li> </ul> <p> 入力の終了は 2 つの 0 を含む行によってあらわされる.これはデータセットの一部ではない. </p> <p> それぞれのデータセットは次の条件を満たすと仮定してよい. </p> <ul> <li>単位時間の 1/1000 よりも短い時間の間に複数の階の消失が起こることはない.</li> <li>単位時間の 1/1000 よりも短い時間の間に複数のエレベータが同一の階で 1 階より上にある階に到着することない.</li> <li>単位時間の 1/1000 よりも短い時間の間にエレベータの到着とそのエレベータが到着しようとした階の焼失が起こることはない.</li> </ul> <h3>Output</h3> <p> それぞれのテストケースについて,回収されたデバイスの個数,および最後に回収されたデバイスが 1 階に到着してエレベータから降ろされるまでの時間を,単一の空白で区切って 1 行で出力しなさい.ただし,時間については,小数点以下に何個の数字を出力しても構わないが,0.001 を超える誤差を含めてはならない.また,1 階にあるデバイス以外は回収できなかったときは時間としてゼロを出力しなさい. </p> <h3>Sample Input</h3> <pre> 5 2 5000 10 20 0 30 5 10 1000 6 1 20 500 8 1 3 40 25 30 0 0 </pre> <h3>Output for the Sample Input</h3> <pre> 50 84.000 </pre>
p03114
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Count the number of strings <var>S</var> that satisfy the following constraints, modulo <var>10^9 + 7</var>.</p> <ul> <li>The length of <var>S</var> is exactly <var>N</var>.</li> <li><var>S</var> consists of digits (<code>0</code>...<code>9</code>).</li> <li>You are given <var>Q</var> intervals. For each <var>i (1 \leq i \leq Q)</var>, the integer represented by <var>S[l_i \ldots r_i]</var> (the substring of <var>S</var> between the <var>l_i</var>-th (<var>1</var>-based) character and the <var>r_i</var>-th character, inclusive) must be a multiple of <var>9</var>.</li> </ul> <p>Here, the string <var>S</var> and its substrings may have leading zeroes. For example, <code>002019</code> represents the integer <var>2019</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 10^9</var></li> <li><var>1 \leq Q \leq 15</var></li> <li><var>1 \leq l_i \leq r_i \leq N</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>Q</var> <var>l_1</var> <var>r_1</var> <var>:</var> <var>l_Q</var> <var>r_Q</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of strings that satisfy the conditions, modulo <var>10^9 + 7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 2 1 2 2 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>136 </pre> <p>For example, <var>S = </var><code>9072</code> satisfies the conditions because both <var>S[1 \ldots 2] = </var><code>90</code> and <var>S[2 \ldots 4] = </var><code>072</code> represent multiples of <var>9</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>6 3 2 5 3 5 1 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>2720 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>20 10 2 15 5 6 1 12 7 9 2 17 5 15 2 4 16 17 2 12 8 17 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>862268030 </pre></section> </div> </span>
p02355
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }}); </script> <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"> </script> <H1>The Smallest Window II</H1> <p> For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $K$, find the smallest sub-array size (smallest window length) where the elements in the sub-array contains all integers in range [$1, 2, ..., K$]. If there is no such sub-array, report 0. </p> <h2>Constraints</h2> <ul> <li> $1 \leq N \leq 10^5$ </li> <li> $1 \leq K \leq 10^5$</li> <li> $1 \leq a_i \leq 10^5$</li> </ul> <h2>Input</h2> <p>The input is given in the following format.</p> <p> $N$ $K$<br> $a_1$ $a_2$ ... $a_N$<br> </p> <h2>Output</h2> <p> Print the smallest sub-array size in a line. </p> <h2>Sample Input 1</h2> <pre> 6 2 4 1 2 1 3 5 </pre> <h2>Sample Output 1</h2> <pre> 2 </pre> <h2>Sample Input 2</h2> <pre> 6 3 4 1 2 1 3 5 </pre> <h2>Sample Output 2</h2> <pre> 3 </pre> <h2>Sample Input 3</h2> <pre> 3 4 1 2 3 </pre> <h2>Sample Output 3</h2> <pre> 0 </pre>
p00368
<H1>Checkered Pattern</H1> <p> You have a cross-section paper with W x H squares, and each of them is painted either in white or black. You want to re-arrange the squares into a neat checkered pattern, in which black and white squares are arranged alternately both in horizontal and vertical directions (the figure shown below is a checkered patter with <var>W = 5</var> and <var>H = 5</var>). To achieve this goal, you can perform the following two operations as many times you like in an arbitrary sequence: swapping of two arbitrarily chosen columns, and swapping of two arbitrarily chosen rows. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2017_checkerBoard" width="280"> </center><br/> <p> Create a program to determine, starting from the given cross-section paper, if you can re-arrange them into a checkered pattern. </p> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> <var>W</var> <var>H</var> <var>c<sub>1,1</sub></var> <var>c<sub>1,2</sub></var> ... <var>c<sub>1,W</sub></var> <var>c<sub>2,1</sub></var> <var>c<sub>2,2</sub></var> ... <var>c<sub>2,W</sub></var> : <var>c<sub>H,1</sub></var> <var>c<sub>H,2</sub></var> ... <var>c<sub>H,W</sub></var> </pre> <p> The first line provides the number of squares in horizontal direction <var>W</var> (2&le;<var>W</var>&le;1000) and those in vertical direction <var>H</var>(2&le;<var>H</var>&le;1000). Each of subsequent <var>H</var> lines provides an array of <var>W</var> integers <var>c<sub>i,j</sub></var> corresponding to a square of <var>i</var>-th row and <var>j</var>-th column. The color of the square is white if <var>c<sub>i,j</sub></var> is 0, and black if it is 1. </p> <h2>Output</h2> <p> Output "yes" if the goal is achievable and "no" otherwise. </p> <h2>Sample Input 1</h2> <pre> 3 2 1 1 0 0 0 1 </pre> <h2>Sample Output 1</h2> <pre> yes </pre> <h2>Sample Input 2</h2> <pre> 2 2 0 0 1 1 </pre> <h2>Sample Output 2</h2> <pre> no </pre>
p00692
<H1> Patience </H1> <p> As the proverb says, </p> <BLOCKQUOTE> <I>"Patience is bitter, but its fruit is sweet."</I> </BLOCKQUOTE> <p> Writing programs within the limited time may impose some patience on you, but you enjoy it and win the contest, we hope. </P> <p> The word "patience" has the meaning of perseverance, but it has another meaning in card games. Card games for one player are called "patience" in the UK and "solitaire" in the US. </p> <P> Let's play a patience in this problem. </p> <P> In this card game, you use only twenty cards whose face values are positive and less than or equal to 5 (Ace's value is 1 as usual). Just four cards are available for each face value. </p> <P> At the beginning, the twenty cards are laid in five rows by four columns (See Figure 1). All the cards are dealt face up. </p> <p> An example of the initial layout is shown in Figure 2.</P> <TABLE> <TR> <TD ALIGN="center"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_card_initial"></TD> <TD ALIGN="center"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_card_example"></TD> </TR> <TR> <TD ALIGN="center">Figure 1: Initial layout</TD> <TD ALIGN="center">Figure 2: Example of the initial layout</TD> </TR> </TABLE> <P> The purpose of the game is to remove as many cards as possible by repeatedly removing a pair of neighboring cards of the same face value. Let us call such a pair a <i>matching pair</i>. </P> <p> The phrase "a pair of neighboring cards" means a pair of cards which are adjacent to each other. For example, in Figure 1, <I>C</i><SUB>6</SUB> is adjacent to any of the following eight cards: </p> <I>C</i><SUB>1</SUB>, <I>C</i><SUB>2</SUB>, <I>C</i><SUB>3</SUB>, <I>C</i><SUB>5</SUB>, <I>C</i><SUB>7</SUB>, <I>C</i><SUB>9</SUB>, <I>C</i><SUB>10</SUB> and <I>C</i><SUB>11</SUB>. In contrast, <I>C</i><SUB>3</SUB> is adjacent to only the following three cards: <I>C</i><SUB>2</SUB>, <I>C</i><SUB>6</SUB> and <I>C</i><SUB>7</SUB>. <P> Every time you remove a pair, you must rearrange the remaining cards as compact as possible.<BR> To put it concretely, each remaining card <I>C<SUB>i</SUB></I> must be examined in turn in its subscript order to be shifted to the uppermost-leftmost space. </p> <P> How to play: </p> <OL> <LI> Search a matching pair. <LI> When you find more than one pair, choose one.<BR> In Figure 3, you decided to remove the pair of <I>C</i><SUB>6</SUB> and <I>C</i><SUB>9</SUB>. <LI> Remove the pair. (See Figure 4) <LI> Shift the remaining cards to the uppermost-leftmost space (See Figure 5, 6). <LI> Repeat the above procedure until you cannot remove any pair. </OL> <TABLE> <TR> <TD ALIGN="center"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_card_match1"></TD> <TD ALIGN="center"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_card_remove1"></TD> </TR> <TR> <TD ALIGN="center">Figure 3: A matching pair found</TD> <TD ALIGN="center">Figure 4: Remove the matching pair</TD> </TR> </TABLE> <TABLE> <TR> <TD ALIGN="center"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_card_shift1"></TD> <TD ALIGN="center"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_card_removed1"></TD> </TR> <TR> <TD ALIGN="center">Figure 5: Shift the remaining cards</TD> <TD ALIGN="center">Figure 6: Rearranged layout</TD> </TR> </TABLE> <P> If you can remove all the twenty cards, you win the game and your penalty is 0. If you leave some cards, you lose the game and your penalty is the number of the remaining cards. </p> <P> Whenever you find multiple matching pairs, you must choose one pair out of them as in the step 2 of the above procedure. The result of the game depends on these choices. </P> <p> Your job is to write a program which answers the minimal penalty for each initial layout. </p> <H2>Input</H2> <p> The input consists of multiple card layouts. The input is given in the following format. </p> <PRE> <I>N</I> <I>Layout</i><SUB>0</SUB> <I>Layout</i><SUB>1</SUB> ... <I>Layout</i><SUB><i>N</i>-1</SUB> </PRE> <p> <I>N</I> is the number of card layouts. Each card layout gives the initial state of a game. A card layout is given in the following format. </p> <PRE> <I>C</i><SUB>0</SUB> <I>C</i><SUB>1</SUB> <I>C</i><SUB>2</SUB> <I>C</i><SUB>3</SUB> <I>C</i><SUB>4</SUB> <I>C</i><SUB>5</SUB> <I>C</i><SUB>6</SUB> <I>C</i><SUB>7</SUB> <I>C</i><SUB>8</SUB> <I>C</i><SUB>9</SUB> <I>C</i><SUB>10</SUB> <I>C</i><SUB>11</SUB> <I>C</i><SUB>12</SUB> <I>C</i><SUB>13</SUB> <I>C</i><SUB>14</SUB> <I>C</i><SUB>15</SUB> <I>C</i><SUB>16</SUB> <I>C</i><SUB>17</SUB> <I>C</i><SUB>18</SUB> <I>C</i><SUB>19</SUB> </PRE> <p> <I>C<SUB>i</SUB></I> (0 &lt;= <I>i</I> &lt;= 19) is an integer from 1 to 5 which represents the face value of the card. </P> <H2>Output</H2> <p> For every initial card layout, the minimal penalty should be output, each in a separate line. </p> <H2>Sample Input</H2> <pre> 4 1 4 5 2 3 1 4 3 5 4 2 2 4 5 2 3 1 1 3 5 5 1 5 1 4 5 3 2 3 2 1 4 1 4 5 3 2 3 4 2 1 2 1 2 5 4 5 4 2 1 2 1 3 5 3 4 3 3 5 4 4 2 3 1 2 5 3 1 3 5 4 2 1 5 4 1 4 5 3 2 </pre> <H2>Output for the Sample Input</H2> <pre> 0 4 12 0 </pre>
p01980
<h1>G: エレベータ</h1> <h2>問題</h2> <p> 株式会社AORは $N$ 階建てのビルである。地下階は存在しない。<br> AORイカちゃんはイカであるため、階段を下りることは可能だが、上ることは不可能である。 </p> <p> 上の階に登れないと不便なため、$M$ 個のエレベータをビルに設置することにした。<br> エレベータを設置するには時間がかかり、$i$ 番目のエレベータは $D_i$ 日後の夜に設置が完了し、 $A_i$ 階以上 $B_i$ 階以下の全ての階を移動可能にする。 </p> <p> あなたはAORイカちゃんに $Q$ 個の質問をされた。$i$ 番目の質問は「 $E_i$ 日後の昼に、$S_i$ 階から $T_i$ 階に移動可能か?」という質問である。<br> 移動に使える手段は階段とエレベータのみである。また移動にかかる時間は無視できるものとする。 </p> <h2>制約</h2> <ul> <li>$2 \le N \le 10^5$</li> <li>$1 \le M \le 10^5$</li> <li>$1 \le Q \le 10^5$</li> <li>$1 \le D_i , E_i \le 10^9$</li> <li>$1 \le A_i &lt; B_i \le N$</li> <li>$1 \le S_i , T_i \le N$</li> <li>入力は全て整数</li> </ul> <h2>入力</h2> <p> $N \ M\ Q$<br> $D_1 \ A_1 \ B_1$<br> $\vdots$<br> $D_M \ A_M \ B_M$<br> $E_1 \ S_1 \ T_1$<br> $\vdots$<br> $E_Q \ S_Q \ T_Q$<br> </p> <h2>出力</h2> <p> 各質問ごとに一行で <strong>Yes</strong> または <strong>No</strong> を出力せよ。ただし質問された順に答えること。また末尾に改行を出力せよ。 </p> <h2>サンプル</h2> <h3>サンプル入力 1</h3> <pre> 5 1 2 3 1 5 3 1 5 4 1 5 </pre> <h3>サンプル出力 1</h3> <pre> No Yes </pre> <p> エレベータが設置されるのは三日目の夜であるため、三日目の昼に移動することはできない。 </p> <h3>サンプル入力 2</h3> <pre> 8 6 5 30 6 7 21 3 8 5 2 4 10 1 2 2 7 8 15 5 7 16 5 8 11 1 3 22 3 7 30 6 7 15 5 8 </pre> <h3>サンプル出力 2</h3> <pre> Yes Yes Yes Yes No </pre> <!-- - - - - - end nicebody - - - - - -->
p02705
<span class="lang-en"> <p>Score : <var>100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Print the circumference of a circle of radius <var>R</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq R \leq 100</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>R</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the circumference of the circle. Your output is considered correct if and only if its absolute or relative error from our answer is at most <var>10^{-2}</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>6.28318530717958623200 </pre> <p>Since we accept an absolute or relative error of at most <var>10^{-2}</var>, <var>6.28</var> is also an acceptable output, but <var>6</var> is not.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>73 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>458.67252742410977361942 </pre></section> </div> </span>
p00738
<h1><font color="#000000">Problem E:</font> Roll-A-Big-Ball</h1> <!-- end en only --> <!-- <img src="https://judgeapi.u-aizu.ac.jp/resources/images/A-1" width=300 align=left> --> <!-- begin en only --> <p> ACM University holds its sports day in every July. The "Roll-A-Big-Ball" is the highlight of the day. In the game, players roll a ball on a straight course drawn on the ground. There are rectangular parallelepiped blocks on the ground as obstacles, which are fixed on the ground. During the game, the ball may not collide with any blocks. The bottom point of the ball may not leave the course. </p> <p> To have more fun, the university wants to use the largest possible ball for the game. You must write a program that finds the largest radius of the ball that can reach the goal without colliding any obstacle block. </p> <p> The ball is a perfect sphere, and the ground is a plane. Each block is a rectangular parallelepiped. The four edges of its bottom rectangle are on the ground, and parallel to either x- or y-axes. The course is given as a line segment from a start point to an end point. The ball starts with its bottom point touching the start point, and goals when its bottom point touches the end point. </p> <p> The positions of the ball and a block can be like in Figure E-1 (a) and (b). </p> <!-- end en only --> <p align="center"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_2008E1"><br> <!-- begin en only --> Figure E-1: Possible positions of the ball and a block <!-- end en only --> </p> <h3>Input</h3> <!-- begin en only --> <p> The input consists of a number of datasets. Each dataset is formatted as follows. </p> <!-- end en only --> <p> <blockquote> <i>N</i><br> <i>sx</i> <i>sy</i> <i>ex</i> <i>ey</i><br> <i>minx</i><sub>1</sub> <i>miny</i><sub>1</sub> <i>maxx</i><sub>1</sub> <i>maxy</i><sub>1</sub> <i>h</i><sub>1</sub><br> <i>minx</i><sub>2</sub> <i>miny</i><sub>2</sub> <i>maxx</i><sub>2</sub> <i>maxy</i><sub>2</sub> <i>h</i><sub>2</sub><br> ...<br> <i>minx</i><sub><i>N</i></sub> <i>miny</i><sub><i>N</i></sub> <i>maxx</i><sub><i>N</i></sub> <i>maxy</i><sub><i>N</i></sub> <i>h</i><sub><i>N</i></sub><br> </blockquote> </p> <!-- begin en only --> <p> A dataset begins with a line with an integer <i>N</i>, the number of blocks (1 &le; <i>N</i> &le; 50). The next line consists of four integers, delimited by a space, indicating the start point (<i>sx</i>, <i>sy</i>) and the end point (<i>ex</i>, <i>ey</i>). The following <i>N</i> lines give the placement of blocks. Each line, representing a block, consists of five integers delimited by a space. These integers indicate the two vertices (<i>minx</i>, <i>miny</i>), (<i>maxx</i>, <i>maxy</i>) of the bottom surface and the height <i>h</i> of the block. The integers <i>sx</i>, <i>sy</i>, <i>ex</i>, <i>ey</i>, <i>minx</i>, <i>miny</i>, <i>maxx</i>, <i>maxy</i> and <i>h</i> satisfy the following conditions. </p> <!-- end en only --> <blockquote> -10000 &le; <i>sx</i>, <i>sy</i>, <i>ex</i>, <i>ey</i> &le; 10000<br> -10000 &le; <i>minx<sub>i</sub></i> &lt; <i>maxx<sub>i</sub></i> &le; 10000<br> -10000 &le; <i>miny<sub>i</sub></i> &lt; <i>maxy<sub>i</sub></i> &le; 10000<br> 1 &le; <i>h<sub>i</sub></i> &le; 1000<br> </blockquote> <!-- begin en only --> <p> The last dataset is followed by a line with a single zero in it. </p> <!-- end en only --> <h3>Output</h3> <!-- begin en only --> <p> For each dataset, output a separate line containing the largest radius. You may assume that the largest radius never exceeds 1000 for each dataset. If there are any blocks on the course line, the largest radius is defined to be zero. The value may contain an error less than or equal to 0.001. You may print any number of digits after the decimal point. </p> <!-- end en only --> <h3>Sample Input</h3> <pre> 2 -40 -40 100 30 -100 -100 -50 -30 1 30 -70 90 -30 10 2 -4 -4 10 3 -10 -10 -5 -3 1 3 -7 9 -3 1 2 -40 -40 100 30 -100 -100 -50 -30 3 30 -70 90 -30 10 2 -400 -400 1000 300 -800 -800 -500 -300 7 300 -700 900 -300 20 3 20 70 150 70 0 0 50 50 4 40 100 60 120 8 130 80 200 200 1 3 20 70 150 70 0 0 50 50 4 40 100 60 120 10 130 80 200 200 1 3 20 70 150 70 0 0 50 50 10 40 100 60 120 10 130 80 200 200 3 1 2 4 8 8 0 0 10 10 1 1 1 4 9 9 2 2 7 7 1 0 </pre> <h3>Output for the Sample Input</h3> <pre> 30 1 18.16666666667 717.7857142857 50.5 50 18.16666666667 0 0 </pre>
p03817
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke has decided to play with a six-sided die. Each of its six sides shows an integer <var>1</var> through <var>6</var>, and two numbers on opposite sides always add up to <var>7</var>.</p> <p>Snuke will first put the die on the table with an arbitrary side facing upward, then repeatedly perform the following operation:</p> <ul> <li>Operation: Rotate the die <var>90°</var> toward one of the following directions: left, right, front (the die will come closer) and back (the die will go farther). Then, obtain <var>y</var> points where <var>y</var> is the number written in the side facing upward.</li> </ul> <p>For example, let us consider the situation where the side showing <var>1</var> faces upward, the near side shows <var>5</var> and the right side shows <var>4</var>, as illustrated in the figure. If the die is rotated toward the right as shown in the figure, the side showing <var>3</var> will face upward. Besides, the side showing <var>4</var> will face upward if the die is rotated toward the left, the side showing <var>2</var> will face upward if the die is rotated toward the front, and the side showing <var>5</var> will face upward if the die is rotated toward the back.</p> <div style="text-align: center;"> <img alt="864abc2e4a08c26015ffd007a30aab03.png" src="https://atcoder.jp/img/arc068/864abc2e4a08c26015ffd007a30aab03.png"> </img></div> <p>Find the minimum number of operation Snuke needs to perform in order to score at least <var>x</var> points in total.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 ≦ x ≦ 10^{15}</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>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 answer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>7 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>149696127901 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>27217477801 </pre></section> </div> </span>
p02210
<h2>五等分のケーキ (Divide Cake into Five)</h2> <p> Segtree 君は五つ子の家庭教師をしています。今日はクリスマスイブなので、五つ子のために円形のケーキを五等分しようとしています。</p> <p>ケーキは中心から扇形状に $N$ 個のピースに分けられており、 $i$ 番目と $i + 1$ 番目($1 \leq i \leq N - 1$) 、 $N$ 番目と $1$ 番目のピースは隣り合っています。</p> <p>$i$ 番目のピースの大きさは $A_i$ です。全てのピースの大きさの和を $S$ とすると、全ての入力について $S$ が $5$ の倍数であることが保証されます。</p> <p>ある非負整数 $Y$ が与えられます。以下の条件を満たすようなケーキの五つ子への分け方を、「ケーキの五等分」と呼びます。</p> <ul> <li>全ての人が1つ以上のピースを取る。</li> <li>ケーキの中でそれぞれが取るピースたちは連結である。つまり、取る人でピースをグループ分けしたとき、同じグループかつ隣り合っているピースに移動することを繰り返して辿り着けないような同じグループ内のピースの組は存在しない。</li> <li>誰も取らないピースは存在しない。</li> <li>全ての人について、取るピースの大きさを $X$ としたとき、必ず $X + Y \geq S / 5$ を満たす。</li> </ul> <p>「ケーキの五等分」になるようなケーキの分け方の通り数が何通りあるか求めてください。</p> <h3>入力</h3> <p>入力は以下の形式で標準入力から与えられる。</p> <pre> $N$ $Y$ $A_1$ $A_2$ $\ldots$ $A_N$ </pre> <h3>出力</h3> <p>「ケーキの五等分」になるようなケーキの分け方の通り数を出力してください。</p> <p>ただし、最後には改行を入れること。</p> <h3>制約</h3> <ul> <li>$5 \leq N \leq 300$</li> <li>$1 \leq A_i \leq 10^9$</li> <li>$0 \leq Y \leq 10^9$</li> <li>入力は全て整数である。</li> </ul> <h3>入力例1</h3> <pre> 5 0 1 1 1 1 1 </pre> <h3>出力例1</h3> <pre> 1 </pre> <h3>入力例2</h3> <pre> 10 27 3 1 4 1 5 9 2 6 5 4 </pre> <h3>出力例2</h3> <pre> 252 </pre>
p00387
<h1>Party Dress</h1> <p> Yae joins a journey plan, in which parties will be held several times during the itinerary. She wants to participate in all of them and will carry several dresses with her. But the number of dresses she can carry with her may be smaller than that of the party opportunities. In that case, she has to wear some of her dresses more than once. </p> <p> Fashion-conscious Yae wants to avoid that. At least, she wants to reduce the maximum number of times she has to wear the same dress as far as possible. </p> <p> Given the number of dresses and frequency of parties, make a program to determine how she can reduce the maximum frequency of wearing the most reused dress. </p> <h2>Input</h2> <p> The input is given in the following format. </p> <pre> $A$ $B$ </pre> <p> The input line provides the number of dresses $A$ ($1 \leq A \leq 10^5$) and frequency of parties $B$ ($1 \leq B \leq 10^5$). </p> <h2>Output</h2> <p> Output the frequency she has to wear the most reused dress. </p> <h2>Sample Input 1</h2> <pre> 3 5 </pre> <h2>Sample Output 1</h2> <pre> 2 </pre> <h2>Sample Input 2</h2> <pre> 25 10 </pre> <h2>Sample Output 2</h2> <pre> 1 </pre>
p02640
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are some animals in a garden. Each of them is a crane with two legs or a turtle with four legs.</p> <p>Takahashi says: "there are <var>X</var> animals in total in the garden, and they have <var>Y</var> legs in total." Determine whether there is a combination of numbers of cranes and turtles in which this statement is correct.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq X \leq 100</var></li> <li><var>1 \leq Y \leq 100</var></li> <li>All values in input are integers.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>X</var> <var>Y</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If there is a combination of numbers of cranes and turtles in which the statement is correct, print <code>Yes</code>; otherwise, print <code>No</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes </pre> <p>The statement "there are <var>3</var> animals in total in the garden, and they have <var>8</var> legs in total" is correct if there are two cranes and one turtle. Thus, there is a combination of numbers of cranes and turtles in which the statement is correct.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 100 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>No </pre> <p>There is no combination of numbers of cranes and turtles in which this statement is correct.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>1 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>Yes </pre> <p>We also consider the case in which there are only cranes or only turtles.</p></section> </div> </span>
p03952
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a pyramid with <var>N</var> steps, built with blocks. The steps are numbered <var>1</var> through <var>N</var> from top to bottom. For each <var>1≤i≤N</var>, step <var>i</var> consists of <var>2i-1</var> blocks aligned horizontally. The pyramid is built so that the blocks at the centers of the steps are aligned vertically.</p> <div style="text-align: center;"> <img src="https://atcoder.jp/img/agc006/a2bde72df5ad036d1699f4a74d74a370.png"> <p>A pyramid with <var>N=4</var> steps</p> </img></div> <p>Snuke wrote a permutation of (<var>1</var>, <var>2</var>, <var>...</var>, <var>2N-1</var>) into the blocks of step <var>N</var>. Then, he wrote integers into all remaining blocks, under the following rule:</p> <ul> <li>The integer written into a block <var>b</var> must be equal to the median of the three integers written into the three blocks directly under <var>b</var>, or to the lower left or lower right of <var>b</var>.</li> </ul> <div style="text-align: center;"> <img src="https://atcoder.jp/img/agc006/a940f1d8303f255e1f91d17a5696633f.png"> <p>Writing integers into the blocks</p> </img></div> <p>Afterwards, he erased all integers written into the blocks. Now, he only remembers that the integer written into the block of step <var>1</var> was <var>x</var>.</p> <p>Construct a permutation of (<var>1</var>, <var>2</var>, <var>...</var>, <var>2N-1</var>) that could have been written into the blocks of step <var>N</var>, or declare that Snuke's memory is incorrect and such a permutation does not exist.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≤N≤10^5</var></li> <li><var>1≤x≤2N-1</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>x</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If no permutation of (<var>1</var>, <var>2</var>, <var>...</var>, <var>2N-1</var>) could have been written into the blocks of step <var>N</var>, print <code>No</code>.</p> <p>Otherwise, print <code>Yes</code> in the first line, then print <var>2N-1</var> lines in addition.</p> <p>The <var>i</var>-th of these <var>2N-1</var> lines should contain the <var>i</var>-th element of a possible permutation.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>Yes 1 6 3 7 4 5 2 </pre> <p>This case corresponds to the figure in the problem statement.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>No </pre> <p>No matter what permutation was written into the blocks of step <var>N</var>, the integer written into the block of step <var>1</var> would be <var>2</var>.</p></section> </div> </span>
p03401
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There are <var>N</var> sightseeing spots on the <var>x</var>-axis, numbered <var>1, 2, ..., N</var>. Spot <var>i</var> is at the point with coordinate <var>A_i</var>. It costs <var>|a - b|</var> yen (the currency of Japan) to travel from a point with coordinate <var>a</var> to another point with coordinate <var>b</var> along the axis.</p> <p>You planned a trip along the axis. In this plan, you first depart from the point with coordinate <var>0</var>, then visit the <var>N</var> spots in the order they are numbered, and finally return to the point with coordinate <var>0</var>.</p> <p>However, something came up just before the trip, and you no longer have enough time to visit all the <var>N</var> spots, so you decided to choose some <var>i</var> and cancel the visit to Spot <var>i</var>. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate <var>0</var> at the beginning and the end, as planned.</p> <p>For each <var>i = 1, 2, ..., N</var>, find the total cost of travel during the trip when the visit to Spot <var>i</var> is canceled.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2 \leq N \leq 10^5</var></li> <li><var>-5000 \leq A_i \leq 5000</var> (<var>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>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A_1</var> <var>A_2</var> <var>...</var> <var>A_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print <var>N</var> lines. In the <var>i</var>-th line, print the total cost of travel during the trip when the visit to Spot <var>i</var> is canceled.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 3 5 -1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>12 8 10 </pre> <p>Spot <var>1</var>, <var>2</var> and <var>3</var> are at the points with coordinates <var>3</var>, <var>5</var> and <var>-1</var>, respectively. For each <var>i</var>, the course of the trip and the total cost of travel when the visit to Spot <var>i</var> is canceled, are as follows:</p> <ul> <li>For <var>i = 1</var>, the course of the trip is <var>0 \rightarrow 5 \rightarrow -1 \rightarrow 0</var> and the total cost of travel is <var>5 + 6 + 1 = 12</var> yen.</li> <li>For <var>i = 2</var>, the course of the trip is <var>0 \rightarrow 3 \rightarrow -1 \rightarrow 0</var> and the total cost of travel is <var>3 + 4 + 1 = 8</var> yen.</li> <li>For <var>i = 3</var>, the course of the trip is <var>0 \rightarrow 3 \rightarrow 5 \rightarrow 0</var> and the total cost of travel is <var>3 + 2 + 5 = 10</var> yen.</li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 1 1 1 2 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>4 4 4 2 4 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>6 -679 -2409 -3258 3095 -3291 -4462 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>21630 21630 19932 8924 21630 19288 </pre></section> </div> </span>
p01596
<h2>Problem F: Magnum Tornado</h2> <p>We have a toy that consists of a small racing circuit and a tiny car. For simplicity you can regard the circuit as a 2-dimensional closed loop, made of line segments and circular arcs. The circuit has no branchings. All segments and arcs are connected smoothly, i.e. there are no sharp corners.</p> <p>The car travels on this circuit with one distinct feature: it is capable of jumping, which enables short cuts. It can jump at any time for any distance. The constraints are that 1) the traveling direction will never change during each jump, 2) the jumping direction needs to match the traveling direction at the time of take-off, and 3) the car must land on the circuit in parallel to the tangent at the landing point. Note that, however, the traveling direction at the landing point may be the opposite of the forward direction (we define forward direction as the direction from the starting point to the ending point of each line segment in the circuit.) That is, the car can traverse part of the circuit in the reverse direction.</p> <p>Your job is to write a program which, given the shape of the circuit, calculates the per-lap length of the shortest route. You can ignore the height of the jump, i.e. just project the route onto the plane on which the circuit resides. The car must start from the starting point of the first line segment, heading towards the ending point of that segment, and must come back to the same starting point heading in the same direction.</p> <p>Figure 1 shows the solution for the first sample input.</p> <div align="center"><img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_magnum"><br> Figure 1: The solution for the first sample input</div> <h2>Input</h2> <p>The input begins with a line that solely consists of an integer <var>N</var> (2 <= <var>N</var> <= 100), the number of line segments in the circuit. This is followed by <var>N</var> lines, where the <var>i</var>-th line corresponds to the <var>i</var>-th line segment (1 <= <var>i</var> <= <var>N</var>). Each of these <var>N</var> lines contains 4 integers <var>x<sub>0</sub></var>, <var>y<sub>0</sub></var>, <var>x<sub>1</sub></var> and <var>y<sub>1</sub></var> (-100 <= <var>x<sub>0</sub></var>, <var>y<sub>0</sub></var>, <var>x<sub>1</sub></var>, <var>y<sub>1</sub></var> <= 100) in this order, separated by a space. Here (<var>x<sub>0</sub></var>, <var>y<sub>0</sub></var>) is the starting point and (<var>x<sub>1</sub></var>, <var>y<sub>1</sub></var>) is the ending point of the <var>i</var>-th line segment. For each <var>i</var>, the <var>i</var>-th and <var>(i+1)</var>-th line segments are connected smoothly by a circular arc, which you may assume exists uniquely (for simplicity, we consider the <var>(N+1)</var>-th line as the 1st line). You may also assume that, while two line segments or circular arcs may cross each other, they will never overlap nor be tangent to each other.</p> <h2>Output</h2> <!-- <p>For each test case, output one line that solely consists of a decimal value, representing the per-lap length. The output value should be printed with three digits after the decimal point, and should not contain an error greater than 0.001.</p> --> <p>For each test case, output one line that solely consists of a decimal value, representing the per-lap length. The output value should be in a decimal fraction and should not contain an error greater than 0.001.</p> <h2>Sample Input 1</h2> <pre> 5 0 1 0 2 1 3 2 3 2 2 1 2 1 1 2 1 2 0 1 0 </pre> <h2>Output for the Sample Input 1</h2> <pre> 9.712 </pre> <h2>Sample Input 2</h2> <pre> 12 4 5 4 6 3 7 1 7 0 8 0 10 1 11 3 11 4 10 4 9 5 8 99 8 100 7 100 4 99 3 4 3 3 2 3 1 2 0 1 0 0 1 0 3 1 4 3 4 </pre> <h2>Output for the Sample Input 2</h2> <pre> 27.406 </pre>
p03051
<span class="lang-en"> <p>Score : <var>800</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>The <em>beauty</em> of a sequence <var>a</var> of length <var>n</var> is defined as <var>a_1 \oplus \cdots \oplus a_n</var>, where <var>\oplus</var> denotes the bitwise exclusive or (XOR).</p> <p>You are given a sequence <var>A</var> of length <var>N</var>. Snuke will insert zero or more partitions in <var>A</var> to divide it into some number of non-empty contiguous subsequences.</p> <p>There are <var>2^{N-1}</var> possible ways to insert partitions. How many of them divide <var>A</var> into sequences whose beauties are all equal? Find this 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>1 \leq N \leq 5 \times 10^5</var></li> <li><var>0 \leq A_i &lt; 2^{20}</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>A_1</var> <var>A_2</var> <var>\ldots</var> <var>A_{N}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the answer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>Four ways of dividing <var>A</var> shown below satisfy the condition. The condition is not satisfied only if <var>A</var> is divided into <var>(1),(2),(3)</var>.</p> <ul> <li><var>(1,2,3)</var></li> <li><var>(1),(2,3)</var></li> <li><var>(1,2),(3)</var></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 1 2 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>32 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>147483634 </pre> <p>Find the count modulo <var>10^{9}+7</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>24 1 2 5 3 3 6 1 1 8 8 0 3 3 4 6 6 4 0 7 2 5 4 6 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>292 </pre></section> </div> </span>
p00850
<H1><font color="#000">Problem F:</font> Power Calculus</H1> <p> Starting with <i>x</i> and repeatedly multiplying by <i>x</i>, we can compute <i>x</i><sup>31</sup> with thirty multiplications: </p> <center> <p> <i>x</i><sup>2</sup> = <i>x</i> &times; <i>x</i>, <i>x</i><sup>3</sup> = <i>x</i><sup>2</sup> &times; <i>x</i>, <i>x</i><sup>4</sup> = <i>x</i><sup>3</sup> &times; <i>x</i>, ... , <i>x</i><sup>31</sup> = <i>x</i><sup>30</sup> &times; <i>x</i>. </p> </center> <p> The operation of squaring can appreciably shorten the sequence of multiplications. The following is a way to compute x<sup>31</sup> with eight multiplications: </p> <center> <p> <i>x</i><sup>2</sup> = <i>x</i> &times; <i>x</i>, <i>x</i><sup>3</sup> = <i>x</i><sup>2</sup> &times; <i>x</i>, <i>x</i><sup>6</sup> = <i>x</i><sup>3</sup> &times; <i>x</i><sup>3</sup>, <i>x</i><sup>7</sup> = <i>x</i><sup>6</sup> &times; <i>x</i>, <i>x</i><sup>14</sup> = <i>x</i><sup>7</sup> &times; <i>x</i><sup>7</sup>,<br> <i>x</i><sup>15</sup> = <i>x</i><sup>14</sup> &times; <i>x</i>, <i>x</i><sup>30</sup> = <i>x</i><sup>15</sup> &times; <i>x</i><sup>15</sup>, <i>x</i><sup>31</sup> = <i>x</i><sup>30</sup> &times; <i>x</i>. </p> </center> <p> This is not the shortest sequence of multiplications to compute <i>x</i><sup>31</sup>. There are many ways with only seven multiplications. The following is one of them: </p> <center> <p> <i>x</i><sup>2</sup> = <i>x</i> &times; <i>x</i>, <i>x</i><sup>4</sup> = <i>x</i><sup>2</sup> &times; <i>x</i><sup>2</sup>, <i>x</i><sup>8</sup> = <i>x</i><sup>4</sup> &times; <i>x</i><sup>4</sup>, <i>x</i><sup>10</sup> = <i>x</i><sup>8</sup> &times; <i>x</i><sup>2</sup>,<br> <i>x</i><sup>20</sup> = <i>x</i><sup>10</sup> &times; <i>x</i><sup>10</sup>, <i>x</i><sup>30</sup> = <i>x</i><sup>20</sup> &times; <i>x</i><sup>10</sup>, <i>x</i><sup>31</sup> = <i>x</i><sup>30</sup> &times; <i>x</i>. </p> </center> <p> There however is no way to compute <i>x</i><sup>31</sup> with fewer multiplications. Thus this is one of the most eficient ways to compute <i>x</i><sup>31</sup> only by multiplications. </p> <p> If division is also available, we can find a shorter sequence of operations. It is possible to compute <i>x</i><sup>31</sup> with six operations (five multiplications and one division): </p> <center> <p> <i>x</i><sup>2</sup> = <i>x</i> &times; <i>x</i>, <i>x</i><sup>4</sup> = <i>x</i><sup>2</sup> &times; <i>x</i><sup>2</sup>, <i>x</i><sup>8</sup> = <i>x</i><sup>4</sup> &times; <i>x</i><sup>4</sup>, <i>x</i><sup>16</sup> = <i>x</i><sup>8</sup> &times; <i>x</i><sup>8</sup>, <i>x</i><sup>32</sup> = <i>x</i><sup>16</sup> &times; <i>x</i><sup>16</sup>,<br> <i>x</i><sup>31</sup> = <i>x</i><sup>32</sup> &divide; <i>x</i>. </p> </center> <p> This is one of the most eficient ways to compute <i>x</i><sup>31</sup> if a division is as fast as a multiplication. </p> <p> Your mission is to write a program to find the least number of operations to compute <i>x<sup>n</sup></i> by multiplication and division starting with <i>x</i> for the given positive integer <i>n</i>. Products and quotients appearing in the sequence of operations should be <i>x</i> to a positive integer's power. In other words, <i>x</i><sup>-3</sup>, for example, should never appear. </p> <H2>Input</H2> <p> The input is a sequence of one or more lines each containing a single integer <i>n</i>. <i>n</i> is positive and less than or equal to 1000. The end of the input is indicated by a zero. </p> <H2>Output</H2> <p> Your program should print the least total number of multiplications and divisions required to compute <i>x<sup>n</sup></i> starting with <i>x</i> for the integer <i>n</i>. The numbers should be written each in a separate line without any superfluous characters such as leading or trailing spaces. </p> <H2>Sample Input</H2> <pre> 1 31 70 91 473 512 811 953 0 </pre> <H2>Output for the Sample Input</H2> <pre> 0 6 8 9 11 9 13 12 </pre>
p01742
<p> すぬけ君の辞書には,<var>n</var> 個の英小文字からなる単語 <var>s<sub>1</sub>, . . ., s<sub>n</sub></var> がのっている.これは辞書順で比較したとき <var>s<sub>1</sub> &lt; . . . &lt; s<sub>n</sub></var> をみたす.残念ながらいくつかの文字はかすれて読めなくなってしまっている.読めなくなった文字は <span>?</span> で表される.<span>?</span> を英小文字で置き換えて辞書を復元する方法は何通りあるか,mod 1,000,000,007 でもとめよ. </p> <h2>Constraints</h2> <ul> <li> 1 &le; <var>n</var> &le; 50</li> <li> 1 &le; <var>|s<sub>i</sub>|</var> &le; 20</li> <li> <var>s<sub>i</sub></var> に現れる文字は英小文字または <span>?</span> である</li> </ul> <h2>Input</h2> <pre> <var>n</var> <var>s<sub>1</sub></var> . . . <var>s<sub>n</sub></var> </pre> <h2>Output</h2> <p> 答えを一行に出力せよ. </p> <h2>Sample Input 1</h2> <pre> 2 ?sum??mer c??a??mp </pre> <h2>Sample Output 1</h2> <pre> 703286064 </pre> <h2>Sample Input 2</h2> <pre> 3 snuje ????e snule </pre> <h2>Sample Output 2</h2> <pre> 1 </pre>
p03285
<span class="lang-en"> <p>Score : <var>200</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p><em>La Confiserie d'ABC</em> sells cakes at <var>4</var> dollars each and doughnuts at <var>7</var> dollars each. Determine if there is a way to buy some of them for exactly <var>N</var> dollars. You can buy two or more doughnuts and two or more cakes, and you can also choose to buy zero doughnuts or zero cakes.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>N</var> is an integer between <var>1</var> and <var>100</var>, inclusive.</li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>If there is a way to buy some cakes and some doughnuts for exactly <var>N</var> dollars, print <code>Yes</code>; otherwise, print <code>No</code>.</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>Yes </pre> <p>If you buy one cake and one doughnut, the total will be <var>4 + 7 = 11</var> dollars.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>40 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>Yes </pre> <p>If you buy ten cakes, the total will be <var>4 \times 10 = 40</var> dollars.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>No </pre> <p>The prices of cakes (<var>4</var> dollars) and doughnuts (<var>7</var> dollars) are both higher than <var>3</var> dollars, so there is no such way.</p></section> </div> </span>
p01312
<h1><font color="#000">Problem J:</font> ねこ泥棒と金曜日のお屋敷</h1> <p> なつめは大のねこ好きである。なつめの通学路には通称ねこ屋敷と呼ばれている家がある。その家はたくさんのねこを飼っていることで有名で、なつめは通学途中によくこの家の前で飼いねこに遭遇し、一緒に遊んでいた。そんなある日、なつめは衝撃的な事実を知ってしまった。それは、実はねこ屋敷の主人は、機嫌が悪くなるとよく飼いねこたちを虐待している、ということだった。ねこ屋敷の主人を許せなくなったなつめは、ねこたちを救うため、主人の居ない間にねこたちを盗みだすことにした。 </p> <p> なつめはねこ屋敷の主人の行動パターンを観察し、毎週決まって出掛けているタイミングをねらってねこたちを盗みだすことにした。ねこ屋敷は二次元平面として表わされており、なつめが屋敷の中に忍びこむ時点でのそれぞれのねこの位置は分かっている。ねこたちはそれぞれ決まったルートを常に50メートル毎分のスピードでまわっている。一方、なつめは最大80メートル毎分のスピードで移動できる。なつめは屋敷のとある場所から侵入し、屋敷内を移動し、主人が帰ってくるまでに脱出口から出る。なつめがねこと同じ地点に到達すると、なつめはねこを抱えることができる。これを行なうのにかかる時間は無視できる。なつめは何匹でもねこを抱えることができるし、何匹抱えていても移動速度が落ちることはないが、必ず主人が帰ってくる前に屋敷を脱出しなければならない。 </p> <p> 残念ながら、なつめはねこ屋敷のねこを全員盗みだすことはできないかもしれない。しかし、1匹でも多くのねこを幸せにするために、できるだけ多くのねこを盗みだすことにした。また、同じ数のねこを盗みだせるのであれば、屋敷の主人に捕まるリスクを抑えるため、できるだけ早い時間に屋敷から脱出する。 </p> <p> なつめが屋敷に侵入する時刻と位置、屋敷の主人が戻ってくる時刻、脱出口の場所、およびねこの初期位置と巡回ルートが与えられる。なつめが何匹のねこを盗みだして、どの時刻に屋敷を脱出できるかを答えるプログラムを書いてほしい。 </p> <h2>Input</h2> <p> 入力の1行目には、侵入口の <var>x</var>, <var>y</var> 座標が1つの空白文字で区切られて与えられる。2行目には同様に脱出口の位置が与えられる。3行目にはなつめが屋敷に侵入した時刻、4行目には屋敷の主人が帰ってくる時刻が24時間制のHH:MM:SSの形式で与えられる。 </p> <p> 5行目はねこの総数 <var>m</var> であり、続く <var>m</var> 行に各ねこの行動パターンが与えられる。5+<var>i</var> 行目 (<var>i</var> = 1, 2, ..., <var>m</var>) が <var>i</var> 番目のねこの巡回ルートに対応している。各行の初めには自然数 <var>k</var><sub><var>i</var></sub> が与えられ、続いてねこの巡回ルートが <var>k</var><sub><var>i</var></sub> 個の <var>x</var>, <var>y</var> 座標値を並べたものとして与えられる。ねこの巡回ルートは、これらの連続する点および最後と最初の点を線分でつないだものである。なつめが屋敷に侵入した時点で、ねこは与えられた最初の点におり、以降ずっと巡回ルート上を等速で移動する。与えられたルートの連続する点が同じ座標であることはない。 </p> <p> なお、スタート時間とゴール時間は同じ日でのものであることが保証されている.なつめが主人の帰ってくる前に脱出する方法は必ず存在する。同じ行にある数は全て1つの空白文字で区切られている。 </p> <p> ねこの数は1以上14以下、ねこの巡回ルートを表わす点の数は2以上1000以下であり、全ての座標値は絶対値が100000を越えない整数であることが保証されている。 座標値の単位は全てメートルである。 </p> <h2>Output</h2> <p> 1行目に、なつめが盗み出すことのできるねこの最大数を出力せよ。2行目には、なつめがなるべく多い数のねこを盗みだす方法の中で、最も早く脱出口に到達できる時刻を、HH MM SS.nnnnnn (空白区切り)の形式で答えよ。秒の小数点以下は6桁出力せよ。なお、10<sup>-6</sup> 秒を越える誤差があってはならない。 </p> <p> なお、主人の帰ってくる時間が±1ms変化しても、最多遭遇可能数は変化しないことが保証されている。 </p> <h2>Notes on Submission</h2> <p> 上記形式で複数のデータセットが与えられます。入力データの 1 行目にデータセットの数が与えられます。各データセットに対する出力を上記形式で順番に出力するプログラムを作成して下さい。 </p> <h2>Sample Input</h2> <pre> 2 0 0 0 0 15:00:00 18:00:00 1 4 0 7199 1125 7199 1125 8324 0 8324 0 0 0 0 15:00:00 18:00:00 1 4 0 7201 1125 7201 1125 8326 0 8326 </pre> <h2>Output for the Sample Input</h2> <pre> 1 17 59 59.076923 0 15 00 00.000000 </pre> <hr>
p00153
<H1>三角形と円</H1> <p> 平面上にある三角形と円の位置関係を判定するプログラムを作成してください。対象となる図形はいずれも境界を含むものとします。 三角形は 3 頂点の位置が与えられ、円は中心の位置と半径が与えられます。位置は直交座標系による2つの整数の組によって与えられます。半径も整数で与えられます。 </p> <H2>Input</H2> <p> 複数のデータセットの並びが入力として与えられます。入力の終わりはゼロふたつの行で示されます。 各データセットは以下の形式で与えられます。 </p> <pre> <var>x<sub>1</sub></var> <var>y<sub>1</sub></var> <var>x<sub>2</sub></var> <var>y<sub>2</sub></var> <var>x<sub>3</sub></var> <var>y<sub>3</sub></var> <var>x<sub>c</sub></var> <var>y<sub>c</sub></var> <var>r</var> </pre> <p> 1行目から3行目に、三角形の第 <var>i</var> の頂点座標 <var>x<sub>i</sub></var>, <var>y<sub>i</sub></var> が与えられます。4行目に円の中心の座標 <var>x<sub>c</sub></var>, <var>y<sub>c</sub></var>、5行目に円の半径 <var>r</var> が与えられます。与えられる入力はすべて、1 以上 10,000 以下の整数とします。 </p> <p> データセットの数は 100 を超えません。 </p> <H2>Output</H2> <p> 入力データセットごとに以下の形式で判定結果を1行に出力します。<br/> <br/> 円が三角形に含まれる場合 <span>a</span><br/> 三角形が円に含まれる場合 <span>b</span><br/> それ以外の場合で、共通部分がある場合には <span>c</span><br/> 共通部分がない場合には <span>d</span><br/> </p> <H2>Sample Input</H2> <pre> 1 1 3 1 3 3 3 2 3 3 12 9 3 11 12 8 7 5 15 3 17 7 22 5 7 6 4 6 11 8 2 16 9 10 8 2 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> b c d a </pre>
p00503
<H1>魚の生息範囲 (Fish) </H1> <br/> <h2> 問題</h2> <p> オーストラリア大陸の西には,広いインド洋が広がっている.海洋研究者である JOI 氏は,インド洋に生息しているある N 種類の魚の性質について研究している. </p> <p> それぞれの魚の種類に対して,海の中に直方体状の生息範囲が定まっている.魚は境界も含めて生息範囲の中のどの場所にも移動できるが,生息範囲の外に出ることは決してない.海の中の点は,3 つの実数 (x, y, d) によって表される: (x, y, d) は,上空から見たときにある地点を基準にして東に x,北に y 進んだ位置であり,海面からの深さが d の点を表す.ただし,海面は平面であるとする. </p> <p> JOI 氏は,K 種類以上の魚の生息範囲が重なる場所がどのくらいあるかを知りたい.そのような場所全体の体積を求めるプログラムを作成せよ. </p> <h2> 入力</h2> <p> 入力は 1 + N 行からなる. </p> <p> 1 行目には,2 つの整数 N, K (1 ≦ K ≦ N ≦ 50) が空白を区切りとして書かれている.これは,魚が N 種類であり,K 種類以上の魚の生息範囲が重なる場所の体積を求めたいことを表す. </p> <p> 続く N 行のうちの i 行目 (1 ≦ i ≦ N) には,6 つの整数 X<sub>i,1</sub>, Y<sub>i,1</sub>, D<sub>i,1</sub>, X<sub>i,2</sub>, Y<sub>i,2</sub>, D<sub>i,2</sub> (0 ≦ X<sub>i,1</sub> < X<sub>i,2</sub> ≦ 1000000 (= 10<sup>6</sup>),0 ≦ Y<sub>i,1</sub> < Y<sub>i,2</sub> ≦ 1000000 (= 10<sup>6</sup>),0 ≦ D<sub>i,1</sub> < D<sub>i,2</sub> ≦ 1000000 (= 10<sup>6</sup>)) が書かれている.これは,i 種類目の魚の生息範囲が 8 点 (X<sub>i,1</sub>, Y<sub>i,1</sub>, D<sub>i,1</sub>), (X<sub>i,2</sub>, Y<sub>i,1</sub>, D<sub>i,1</sub>), (X<sub>i,2</sub>, Y<sub>i,2</sub>, D<sub>i,1</sub>), (X<sub>i,1</sub>, Y<sub>i,2</sub>, D<sub>i,1</sub>), (X<sub>i,1</sub>, Y<sub>i,1</sub>, D<sub>i,2</sub>), (X<sub>i,2</sub>, Y<sub>i,1</sub>, D<sub>i,2</sub>), (X<sub>i,2</sub>, Y<sub>i,2</sub>, D<sub>i,2</sub>), (X<sub>i,1</sub>, Y<sub>i,2</sub>, D<sub>i,2</sub>) を頂点とする直方体であることを表す. </p> <h2> 出力</h2> <p> K 種類以上の魚の生息範囲が重なる場所全体の体積を 1 行で出力せよ. </p> <h2> 入出力例</h2> <h3>入力例 1</h3> <pre> 3 2 30 50 0 50 70 100 10 20 20 70 90 60 40 60 20 90 90 70 </pre> <h3>出力例 1</h3> <pre> 49000 </pre> <p> 入出力例 1 において,例えば,点 (45, 65, 65) は 1 種類目の魚と 3 種類目の魚の生息範囲であるので,条件を満たす場所である.一方,点 (25, 35, 45) は 2 種類目の魚のみの生息範囲であるので,条件を満たす場所ではない.また,魚の生息範囲は下の図のようになっている.点 O は海面上の基準の地点を表す. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_2013-yo-t5-fig01"> </center> <br/> <h3>入力例 2</h3> <pre> 1 1 0 0 0 1000000 1000000 1000000 </pre> <h3>出力例 2</h3> <pre> 1000000000000000000 </pre> <div class="source"> <p class="source"> 問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。 </p> </div>
p00016
<H1>Treasure Hunt</H1> <p> When a boy was cleaning up after his grand father passing, he found an old paper: </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_treasure_en"><br> </center> <br/> <!-- <center> <table> <tr> <td align="top"> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_treasure"> </td> <td align="top"> Stand facing to north from "Sanbonmatsu", and go according to the following steps. You will come across a treasure at the end point.<br> <pre> 30, 10 50, -40 20, 15 . . </pre> </td> </tr> </table> </center> --> <p> In addition, other side of the paper says that "go ahead a number of steps equivalent to the first integer, and turn clockwise by degrees equivalent to the second integer". </p> <p> His grand mother says that Sanbonmatsu was standing at the center of town. However, now buildings are crammed side by side and people can not walk along exactly what the paper says in. Your task is to write a program which hunts for the treature on the paper. </p> <p> For simplicity, 1 step is equivalent to 1 meter. Input consists of several pairs of two integers <var>d</var> (the first integer) and <var>t</var> (the second integer) separated by a comma. Input ends with "0, 0". Your program should print the coordinate (<var>x</var>, <var>y</var>) of the end point. There is the treature where x meters to the east and y meters to the north from the center of town. </p> <p> You can assume that <var>d</var> &le; 100 and -180 &le; <var>t</var> &le; 180. </p> <H2>Input</H2> <p> A sequence of pairs of integers <var>d</var> and <var>t</var> which end with "<span>0,0</span>". </p> <H2>Output</H2> <p> Print the integer portion of <var>x</var> and <var>y</var> in a line respectively. </p> <H2>Sample Input</H2> <pre> 56,65 97,54 64,-4 55,76 42,-27 43,80 87,-86 55,-6 89,34 95,5 0,0 </pre> <H2>Output for the Sample Input</H2> <pre> 171 -302 </pre>
p02181
<h1>G: AOR-String</h1> <h2>問題</h2> <p> $N$ 個の文字列 $S_i$ が与えられる. </p> <p> $S_i$ を任意の順に繋げて得られる文字列に含まれる "AOR" の数の最大値を求めよ. </p> <h2>制約</h2> <ul> <li>$1 \leq N \leq 10^5$</li> <li>$1 \leq |S_i| \leq 20$</li> <li>$S_i$ は大文字アルファベットのみからなる</li> </ul> <h2>入力形式</h2> <p> 入力は以下の形式で与えられる. </p> <p> $N$<br> $S_1$<br> …<br> $S_N$<br> </p> <h2>出力</h2> <p> $S_i$ を任意の順に繋げて得られる文字列に含まれる "AOR" の数の最大値を出力せよ. また, 末尾に改行も出力せよ. </p> <h2>サンプル</h2> <h3>サンプル入力 1</h3> <pre> 2 AORA OR </pre> <h3>サンプル出力 1</h3> <pre> 2 </pre> <h3>サンプル入力 2</h3> <pre> 5 AB CA ORA XX AOR </pre> <h3>サンプル出力 2</h3> <pre> 2 </pre>
p00446
<H1> カードゲーム </H1> <h2>問題</h2> <p> 次のような2人で行うカードゲームがある. </p> <ul> <li> このゲームでは, 1から2nまでの各整数が書かれた全部で2n枚のカードを使用する. ここで,nは1以上100以下の整数である.</li> <li> このカードを2人にn枚ずつ配る.</li> <li> 次のルールに従って交互にカードを1枚ずつ場に出す.</li> <ul> <li> 場にカードが出ていないならば, 好きなカードを出すことができる.</li> <li> 場にカードが出ているならば, 最後に場に出たカードよりも大きい数の書かれたカードを出すことができる.</li> <li> カードが出せる場合は,必ず場にカードを出す必要がある.</li> <li> 出せるカードが無い場合はパスとなり,相手の番になる. このとき,場に出ているカードは無くなる. </li> </ul> <li> ゲームは場にカードが出ていない状態で始める.</li> <li> どちらかの手持ちのカードが無くなった時点でゲームは終了する.</li> <li> ゲーム終了時に相手の持っているカードの枚数を得点とする.</li> </ul> <p> 太郎と花子は,このゲームで対戦することになった.ゲームは太郎の番から始める. 2人は共に,出すことのできるカードのうち必ず一番小さい数が書かれたカードを出すことにしている. </p> <p> 太郎に配られるカードが入力されたとき,太郎と花子の得点を出力するプログラムを作成せよ. </p> <h2>入力</h2> <p> 入力は複数のデータセットからなる.各データセットは以下の形式で与えられる. </p> <p> 入力は n+1 行ある. 1行目には整数nが書かれている. 2行目からn+1行目までの各行には整数が1つずつ書かれており,太郎に配られるカードに書かれた整数を表す. </p> <p> n が 0 のとき入力の終了を示す. データセットの数は 5 を超えない. </p> <h2>出力</h2> <p> <!--提出する出力ファイルは2行からなる. 1行目には太郎の得点を, 2行目には花子の得点を出力せよ. --> データセットごとに 1行目には太郎の得点を, 2行目には花子の得点を出力せよ. </p> <h2>入出力例</h2> <h3>入力例</h3> <pre> 5 1 7 9 6 10 10 8 7 14 18 4 11 3 17 5 19 0 </pre> <h3>出力例</h3> <pre> 3 0 2 0 </pre> <div class="source"> <p class="source"> 上記問題文と自動審判に使われるデータは、<a href="http://www.ioi-jp.org">情報オリンピック日本委員会</a>が作成し公開している問題文と採点用テストデータです。 </p> </div>
p00915
<H1><font color="#000">Problem B: </font>The Last Ant</H1> <p> A straight tunnel without branches is crowded with busy ants coming and going. Some ants walk left to right and others right to left. All ants walk at a constant speed of 1 cm/s. When two ants meet, they try to pass each other. However, some sections of the tunnel are narrow and two ants cannot pass each other. When two ants meet at a narrow section, they turn around and start walking in the opposite directions. When an ant reaches either end of the tunnel, it leaves the tunnel. </p> <p> The tunnel has an integer length in centimeters. Every narrow section of the tunnel is integer centimeters distant from the both ends. Except for these sections, the tunnel is wide enough for ants to pass each other. All ants start walking at distinct narrow sections. No ants will newly enter the tunnel. Consequently, all the ants in the tunnel will eventually leave it. Your task is to write a program that tells which is the last ant to leave the tunnel and when it will. </p> <p> Figure B.1 shows the movements of the ants during the first two seconds in a tunnel 6 centimeters long. Initially, three ants, numbered 1, 2, and 3, start walking at narrow sections, 1, 2, and 5 centimeters distant from the left end, respectively. After 0.5 seconds, the ants 1 and 2 meet at a wide section, and they pass each other. Two seconds after the start, the ants 1 and 3 meet at a narrow section, and they turn around. </p> <p> Figure B.1 corresponds to the first dataset of the sample input. </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_theLastAnt1" style="aling:center;width:480px"><br/> <span>Figure B.1. Movements of ants</span> </center> <H2>Input</H2> <p> The input consists of one or more datasets. Each dataset is formatted as follows. </p> <pre> <var>n</var> <var>l</var> <var>d<sub>1</sub></var> <var>p<sub>1</sub></var> <var>d<sub>2</sub></var> <var>p<sub>2</sub></var> ... <var>d<sub>n</sub></var> <var>p<sub>n</sub></var> </pre> <p> The first line of a dataset contains two integers separated by a space. <var>n</var> (1 &le; <var>n</var> &le; 20) represents the number of ants, and <var>l</var> (<var>n</var> + 1 &le; <var>l</var> &le; 100) represents the length of the tunnel in centimeters. The following <var>n</var> lines describe the initial states of ants. Each of the lines has two items, <var>d<sub>i</sub></var> and <var>p<sub>i</sub></var>, separated by a space. Ants are given numbers 1 through <var>n</var>. The ant numbered <var>i</var> has the initial direction <var>d<sub>i</sub></var> and the initial position <var>p<sub>i</sub></var>. The initial direction <var>d<sub>i</sub></var> (1 &le; <var>i</var> &le; <var>n</var>) is <b>L</b> (to the left) or <b>R</b> (to the right). The initial position <var>p<sub>i</sub></var> (1 &le; <var>i</var> &le; <var>n</var>) is an integer specifying the distance from the left end of the tunnel in centimeters. Ants are listed in the left to right order, that is, 1 &le; <var>p<sub>1</sub></var> &lt; <var>p<sub>2</sub></var> &lt; ... &lt; <var>p<sub>n</sub></var> &le; <var>l</var> - 1. </p> <p> The last dataset is followed by a line containing two zeros separated by a space. </p> <H2>Output</H2> <p> For each dataset, output how many seconds it will take before all the ants leave the tunnel, and which of the ants will be the last. The last ant is identified by its number. If two ants will leave at the same time, output the number indicating the ant that will leave through the left end of the tunnel. </p> <H2>Sample Input</H2> <pre> 3 6 R 1 L 2 L 5 1 10 R 1 2 10 R 5 L 7 2 10 R 3 L 8 2 99 R 1 L 98 4 10 L 1 R 2 L 8 R 9 6 10 R 2 R 3 L 4 R 6 L 7 L 8 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 5 1 9 1 7 1 8 2 98 2 8 2 8 3 </pre>
p02928
<span class="lang-en"> <p>Score : <var>300</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a sequence of <var>N</var> integers <var>A~=~A_0,~A_1,~...,~A_{N - 1}</var>.</p> <p>Let <var>B</var> be a sequence of <var>K \times N</var> integers obtained by concatenating <var>K</var> copies of <var>A</var>. For example, if <var>A~=~1,~3,~2</var> and <var>K~=~2</var>, <var>B~=~1,~3,~2,~1,~3,~2</var>.</p> <p>Find the inversion number of <var>B</var>, modulo <var>10^9 + 7</var>.</p> <p>Here the inversion number of <var>B</var> is defined as the number of ordered pairs of integers <var>(i,~j)~(0 \leq i &lt; j \leq K \times N - 1)</var> such that <var>B_i &gt; B_j</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 2000</var></li> <li><var>1 \leq K \leq 10^9</var></li> <li><var>1 \leq A_i \leq 2000</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>Input is given from Standard Input in the following format:</p> <pre><var>N</var> <var>K</var> <var>A_0</var> <var>A_1</var> <var>...</var> <var>A_{N - 1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the inversion number of <var>B</var>, modulo <var>10^9 + 7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 2 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>In this case, <var>B~=~2,~1,~2,~1</var>. We have:</p> <ul> <li><var>B_0 &gt; B_1</var></li> <li><var>B_0 &gt; B_3</var></li> <li><var>B_2 &gt; B_3</var></li> </ul> <p>Thus, the inversion number of <var>B</var> is <var>3</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 5 1 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p><var>A</var> may contain multiple occurrences of the same number.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>10 998244353 10 9 8 7 5 6 3 4 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>185297239 </pre> <p>Be sure to print the output modulo <var>10^9 + 7</var>.</p></section> </div> </span>
p01607
<h2>魔法陣</h2> <h2>Problem Statement</h2> <p>〜魔法陣の描き方〜</p> <ol class="list1" style="padding-left:16px;margin-left:16px"><li>十分広くて真っ白な床を用意します.</li> <li>床の座標 <var>(0,0)</var> の点を中心にして,半径 <var>1, 2, ..., R</var> の円を描きます.</li> <li>半径 <var>1</var> の円と半径 <var>2</var> の円の間,半径 <var>3</var> の円と半径 <var>4</var> の円の間,<var>...</var> を青色で塗ります.なお,半径 <var>R</var> の円の外には色を塗ってはいけません.</li> <li>床に頂点数 <var>N</var> の多角形を一つ描きます.</li> <li>多角形の内部の白色の領域を青色で,青色の領域を白色で塗りなおします.</li></ol> <p>魔法陣の力は,魔法陣に青色が多く含まれるほど強くなるという.<br /> そこであなたには,魔法陣に含まれる青い領域の面積を求めてほしい.</p> <p>次の図はこの手順で描くことのできる魔法陣の一例である.</p> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE3_Rits_Camp13_Day2_G_example"> <h2>Input</h2> <p>入力は以下の形式に従う.与えられる数は全て整数である.</p> <pre><var>N</var> <var>R</var> <var>x_1</var> <var>y_1</var> <var>...</var> <var>x_N</var> <var>y_N</var></pre> <p><var>(x_i, y_i)</var> は多角形の <var>i</var> 番目の頂点である.</p> <h2>Constraints</h2> <ul class="list1" style="padding-left:16px;margin-left:16px"><li><var>3 ≦ N ≦ 100</var></li> <li><var>1 ≦ R ≦ 100</var></li> <li>多角形は半径 <var>R</var> の円の内部または円周上に含まれる.</li> <li>多角形は自己交差をもたない.</li> <li>多角形の頂点は反時計回りの順番で与えられる.</li></ul> <h2>Output</h2> <p>青い領域の面積を 1 行に出力せよ.<br /> 出力する値は,真の値との絶対誤差または相対誤差が <var>10^{-8}</var> 未満でなければならない.</p> <h2>Sample Input 1</h2> <pre>3 1 0 0 1 0 0 1</pre> <h2>Output for the Sample Input 1</h2> <pre>0.500000000</pre> <h2>Sample Input 2</h2> <pre>3 2 0 0 2 0 0 2</pre> <h2>Output for the Sample Input 2</h2> <pre>8.995574288</pre> <h2>Sample Input 3</h2> <pre>3 2 1 -1 1 1 -2 0</pre> <h2>Output for the Sample Input 3</h2> <pre>11.123246567</pre> <h2>Sample Input 4</h2> <pre>4 3 1 1 -1 1 -1 -1 1 -1</pre> <h2>Output for the Sample Input 4</h2> <pre>11.707963268</pre>
p02882
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Takahashi has a water bottle with the shape of a rectangular prism whose base is a square of side <var>a~\mathrm{cm}</var> and whose height is <var>b~\mathrm{cm}</var>. (The thickness of the bottle can be ignored.)</p> <p>We will pour <var>x~\mathrm{cm}^3</var> of water into the bottle, and gradually tilt the bottle around one of the sides of the base.</p> <p>When will the water be spilled? More formally, find the maximum angle in which we can tilt the bottle without spilling any water.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li>All values in input are integers.</li> <li><var>1 \leq a \leq 100</var></li> <li><var>1 \leq b \leq 100</var></li> <li><var>1 \leq x \leq a^2b</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>x</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum angle in which we can tilt the bottle without spilling any water, in degrees. Your output will be judged as correct when the absolute or relative error from the judge's output is at most <var>10^{-6}</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 2 4 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>45.0000000000 </pre> <p>This bottle has a cubic shape, and it is half-full. The water gets spilled when we tilt the bottle more than <var>45</var> degrees.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>12 21 10 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>89.7834636934 </pre> <p>This bottle is almost empty. When the water gets spilled, the bottle is nearly horizontal.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>3 1 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>4.2363947991 </pre> <p>This bottle is almost full. When the water gets spilled, the bottle is still nearly vertical.</p></section> </div> </span>
p03790
<span class="lang-en"> <p>Score : <var>1700</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>There is a railroad in Takahashi Kingdom. The railroad consists of <var>N</var> sections, numbered <var>1</var>, <var>2</var>, ..., <var>N</var>, and <var>N+1</var> stations, numbered <var>0</var>, <var>1</var>, ..., <var>N</var>. Section <var>i</var> directly connects the stations <var>i-1</var> and <var>i</var>. A train takes exactly <var>A_i</var> minutes to run through section <var>i</var>, regardless of direction. Each of the <var>N</var> sections is either single-tracked over the whole length, or double-tracked over the whole length. If <var>B_i = 1</var>, section <var>i</var> is single-tracked; if <var>B_i = 2</var>, section <var>i</var> is double-tracked. Two trains running in opposite directions can cross each other on a double-tracked section, but not on a single-tracked section. Trains can also cross each other at a station.</p> <p>Snuke is creating the timetable for this railroad. In this timetable, the trains on the railroad run every <var>K</var> minutes, as shown in the following figure. Here, bold lines represent the positions of trains running on the railroad. (See Sample 1 for clarification.)</p> <p><img alt="" src="https://atcoder.jp/img/agc011/a5c221ce77ab6ee8aee48e75a4e5c969.png"/></p> <p>When creating such a timetable, find the minimum sum of the amount of time required for a train to depart station <var>0</var> and reach station <var>N</var>, and the amount of time required for a train to depart station <var>N</var> and reach station <var>0</var>. It can be proved that, if there exists a timetable satisfying the conditions in this problem, this minimum sum is always an integer.</p> <p>Formally, the times at which trains arrive and depart must satisfy the following:</p> <ul> <li>Each train either departs station <var>0</var> and is bound for station <var>N</var>, or departs station <var>N</var> and is bound for station <var>0</var>.</li> <li>Each train takes exactly <var>A_i</var> minutes to run through section <var>i</var>. For example, if a train bound for station <var>N</var> departs station <var>i-1</var> at time <var>t</var>, the train arrives at station <var>i</var> exactly at time <var>t+A_i</var>.</li> <li>Assume that a train bound for station <var>N</var> arrives at a station at time <var>s</var>, and departs the station at time <var>t</var>. Then, the next train bound for station <var>N</var> arrives at the station at time <var>s+K</var>, and departs the station at time <var>t+K</var>. Additionally, the previous train bound for station <var>N</var> arrives at the station at time <var>s-K</var>, and departs the station at time <var>t-K</var>. This must also be true for trains bound for station <var>0</var>.</li> <li>Trains running in opposite directions must not be running on the same single-tracked section (except the stations at both ends) at the same time.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>1 \leq N \leq 100000</var></li> <li><var>1 \leq K \leq 10^9</var></li> <li><var>1 \leq A_i \leq 10^9</var></li> <li><var>A_i</var> is an integer.</li> <li><var>B_i</var> is either <var>1</var> or <var>2</var>.</li> </ul> </section> </div> <div class="part"> <section> <h3>Partial Score</h3><ul> <li>In the test set worth <var>500</var> points, all the sections are single-tracked. That is, <var>B_i = 1</var>.</li> <li>In the test set worth another <var>500</var> points, <var>N \leq 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>N</var> <var>K</var> <var>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> : <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print an integer representing the minimum sum of the amount of time required for a train to depart station <var>0</var> and reach station <var>N</var>, and the amount of time required for a train to depart station <var>N</var> and reach station <var>0</var>. If it is impossible to create a timetable satisfying the conditions, print <var>-1</var> instead.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 10 4 1 3 1 4 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>26 </pre> <p>For example, the sum of the amount of time in question will be <var>26</var> minutes in the following timetable:</p> <p><img alt="" src="https://atcoder.jp/img/agc011/a5c221ce77ab6ee8aee48e75a4e5c969.png"/></p> <p>In this timetable, the train represented by the red line departs station <var>0</var> at time <var>0</var>, arrives at station <var>1</var> at time <var>4</var>, departs station <var>1</var> at time <var>5</var>, arrives at station <var>2</var> at time <var>8</var>, and so on.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>1 10 10 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>-1 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>6 4 1 1 1 1 1 1 1 1 1 1 1 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>12 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>20 987654321 129662684 2 162021979 1 458437539 1 319670097 2 202863355 1 112218745 1 348732033 1 323036578 1 382398703 1 55854389 1 283445191 1 151300613 1 693338042 2 191178308 2 386707193 1 204580036 1 335134457 1 122253639 1 824646518 2 902554792 2 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>14829091348 </pre></section> </div> </span>
p01257
<H1><font color="#000">Problem H:</font> Vending Machine</H1> <p> There has been marketing warfare among beverage vendors, and they have been working hard for in- crease of their sales. The Kola-Coqua Company is one of the most successful vendors among those: their impressive advertisements toward the world has brought the overwhelming market share of their representative product called Koque. </p> <p> This time, Kola-Coqua is focusing on vending machines. They think cusomters will be more pleasant as the machines respond more quickly, so they have improved many parts of the machines. </p> <p> In particular, they have developed a new device of change return. The new device can give one or more kinds of coins at a time (in a single operation), although it can give only one coin for each kind at once. For example, suppose there are 500-yen, 100-yen, 50-yen and 10-yen coins, change of 6540 yen can be made by four operations of giving 500-yen and 10-yen coins and nine operations of giving 500-yen coins. In conclusion, 6540 yen can be returned by thirteen operations. It is supposed that the new device allows customers to make their purchase more quickly and so helps Kola-Coqua’s market share grow up. </p> <p> However, the project leader says “No, it’s not optimal yet.” His suggesion is as follows: the real opti- mization is to minimize the number of operations. For example, change of 6540 yen should be made with ten of 500-yen coins, ten of 100-yen coins, ten of 50-yen coins, and four of 10-yen coins. This way, 6540 yen can be returned only with ten operations. This allows full speed-up in giving back change, even though it sometimes results in a huge amount of coins. </p> <p> Given which kinds of coins are available and how much change should be given back, you are to write a program that calculates the minimum number of operations according to the above suggestion. You may assume that there are enough amount of coins inside the vending machines. </p> <H2>Input</H2> <p> The input consists of multiple data sets. Each dataset is described by two lines. The first line contains <i>N</i> (<i>N</i> &le; 10) and <i>M</i> (<i>M</i> &le; 100000) indicating the number of kinds of coins and the amount of change to be made, respectively. The second line contains N integers representing the value of each kind of coin. </p> <p> The input is terminated by a dataset of <i>N</i> = <i>M</i> = 0. This dataset must not be processed. </p> <H2>Output</H2> <p> For each dataset, output in a line the minimum number of operations needed to give back exactly the specified amount of change. </p> <H2>Sample Input</H2> <pre> 6 330 1 5 10 50 100 500 7 127 1 2 4 8 16 32 64 2 10000 1000 2000 0 0 </pre> <H2>Output for the Sample Input</H2> <pre> 2 1 4 </pre>
p00295
<h1>フロッピーキューブ</h1> <p> フロッピーキューブをプログラミングで解いてみましょう。フロッピーキューブは図のように表面に色のついた9個の立方体から構成されている立体パズルで、キューブの列を回転させることによって、6つの各面の色をそろえます。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2014_floppyCube1" width="300"> </center> <br> <p> フロッピーキューブに対しては下図のような4種類の操作を行うことができ、一回の操作で、端にある3つの隣接したキューブを180度回転することができます。わかりやすいように、図では、上面に+(赤色)、下面に*(緑色)、右前面に□(黄色)、左前面に●(青色)、右奥面に○(水色)、左奥面に■紫色) の記号が付いている状態を初期状態としています。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2014_floppyCube2" width="600"> </center> <br> <p> フロッピーキューブの初期状態が与えられるので、パズルを解くために必要な最小の操作回数を求めるプログラムを作成してください。 </p> <h2>入力</h2> <p> 入力は以下の形式で与えられる。 </p> <pre> <var>N</var> <var>puzzle</var><sub>1</sub> <var>puzzle</var><sub>2</sub> : <var>puzzle</var><sub>N</sub> </pre> <p> 1行目の<var>N</var> (1 &le; <var>N</var> &le; 30) は操作回数を計算したいパズルの数である。続くN行に各フロッピーキューブの初期状態 <var>puzzle<sub>i</sub></var> が与えられる。<var>puzzle<sub>i</sub></var> は以下の形式で与えられる。 </p> <pre> <var>p</var><sub>1</sub> <var>p</var><sub>2</sub> <var>p</var><sub>3</sub> <var>p</var><sub>4</sub> <var>p</var><sub>5</sub> <var>p</var><sub>6</sub> <var>p</var><sub>7</sub> <var>p</var><sub>8</sub> <var>p</var><sub>9</sub> <var>p</var><sub>10</sub> <var>p</var><sub>11</sub> <var>p</var><sub>12</sub> <var>p</var><sub>13</sub> <var>p</var><sub>14</sub> <var>p</var><sub>15</sub> <var>p</var><sub>16</sub> <var>p</var><sub>17</sub> <var>p</var><sub>18</sub> <var>p</var><sub>19</sub> <var>p</var><sub>20</sub> <var>p</var><sub>21</sub> <var>p</var><sub>22</sub> <var>p</var><sub>23</sub> <var>p</var><sub>24</sub> <var>p</var><sub>25</sub> <var>p</var><sub>26</sub> <var>p</var><sub>27</sub> <var>p</var><sub>28</sub> <var>p</var><sub>29</sub> <var>p</var><sub>30</sub> </pre> <p> 各フロッピーキューブの情報は 30 個の整数 <var>p<sub>i</sub></var> (1 &le; <var>p<sub>i</sub></var> &le; 6) からなる。<var>p<sub>i</sub></var> は、下図のようにフロッピーキューブの各面に番号 <var>i</var> を振ったときの、そのキューブの面の色を表す。 </p> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2014_floppyCube3" width="600"> </center> <br> <p> パズルは、多くとも8回の操作で解くことができると仮定してよい。 </p> <h2>出力</h2> <p> パズルごとに、最小の操作回数を1行に出力する。 </p> <h2>入出力例</h2> <br> <h2>入力例 </h2> <pre> 4 1 1 1 1 1 1 1 1 1 2 2 2 4 4 4 6 6 6 5 5 5 3 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 2 2 2 4 4 6 4 6 6 5 5 5 3 3 3 3 3 3 1 1 1 3 3 3 1 1 3 1 1 1 2 2 5 6 4 4 4 6 6 2 5 5 3 3 3 1 3 3 1 1 1 1 3 1 3 1 3 3 1 3 2 2 2 6 4 4 6 6 4 5 5 5 1 3 1 1 3 1 3 1 3 </pre> <h2>出力例</h2> <pre> 0 1 2 7 </pre>
p02752
<span class="lang-en"> <p>Score : <var>1100</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3> <p>We have a tree <var>G</var> with <var>N</var> vertices numbered <var>1</var> to <var>N</var>. The <var>i</var>-th edge of <var>G</var> connects Vertex <var>a_i</var> and Vertex <var>b_i</var>.</p> <p>Consider adding zero or more edges in <var>G</var>, and let <var>H</var> be the graph resulted.</p> <p>Find the number of graphs <var>H</var> that satisfy the following conditions, modulo <var>998244353</var>.</p> <ul> <li><var>H</var> does not contain self-loops or multiple edges.</li> <li>The diameters of <var>G</var> and <var>H</var> are equal.</li> <li>For every pair of vertices in <var>H</var> that is not directly connected by an edge, the addition of an edge directly connecting them would reduce the diameter of the graph.</li> </ul> </section> </div> <div class="part"> <section> <h3>Constraints</h3> <ul> <li><var> 3 \le N \le 2 \times 10^5 </var></li> <li><var> 1 \le a_i, b_i \le 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>\vdots</var> <var>a_{N-1}</var> <var>b_{N-1}</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3> <p>Print the answer.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>6 1 6 2 1 5 2 3 4 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>For example, adding the edges <var>(1, 5), (3, 5)</var> in <var>G</var> satisfies the conditions.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>3 1 2 2 3 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 </pre> <p>The only graph <var>H</var> that satisfies the conditions is <var>G</var>.</p> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>9 1 2 2 3 4 2 1 7 6 1 2 5 5 9 6 8 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>27 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 4</h3><pre>19 2 4 15 8 1 16 1 3 12 19 1 18 7 11 11 15 12 9 1 6 7 14 18 2 13 12 13 5 16 13 7 1 11 10 7 17 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 4</h3><pre>78732 </pre></section> </div> </span>
p03840
<span class="lang-en"> <p>Score : <var>600</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>A <em>tetromino</em> is a figure formed by joining four squares edge to edge. We will refer to the following seven kinds of tetromino as I-, O-, T-, J-, L-, S- and Z-tetrominos, respectively:</p> <div style="text-align: center;"> <img alt="a60bcb8e9e8f22e3af51049eda063392.png" src="https://atcoder.jp/img/agc008/a60bcb8e9e8f22e3af51049eda063392.png"> </img></div> <p>Snuke has many tetrominos. The number of I-, O-, T-, J-, L-, S- and Z-tetrominos in his possession are <var>a_I</var>, <var>a_O</var>, <var>a_T</var>, <var>a_J</var>, <var>a_L</var>, <var>a_S</var> and <var>a_Z</var>, respectively. Snuke will join <var>K</var> of his tetrominos to form a rectangle that is two squares tall and <var>2K</var> squares wide. Here, the following rules must be followed:</p> <ul> <li>When placing each tetromino, rotation is allowed, but reflection is not.</li> <li>Each square in the rectangle must be covered by exactly one tetromino.</li> <li>No part of each tetromino may be outside the rectangle.</li> </ul> <p>Snuke wants to form as large a rectangle as possible. Find the maximum possible value of <var>K</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>0≤a_I,a_O,a_T,a_J,a_L,a_S,a_Z≤10^9</var></li> <li><var>a_I+a_O+a_T+a_J+a_L+a_S+a_Z≥1</var></li> </ul> </section> </div> <hr/> <div class="io-style"> <div class="part"> <section> <h3>Input</h3><p>The input is given from Standard Input in the following format:</p> <pre><var>a_I</var> <var>a_O</var> <var>a_T</var> <var>a_J</var> <var>a_L</var> <var>a_S</var> <var>a_Z</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the maximum possible value of <var>K</var>. If no rectangle can be formed, print <code>0</code>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>2 1 1 0 0 0 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>3 </pre> <p>One possible way to form the largest rectangle is shown in the following figure:</p> <div style="text-align: center;"> <img alt="45515ed2a1dd5e41c5e4ca1f39323d8e.png" src="https://atcoder.jp/img/agc008/45515ed2a1dd5e41c5e4ca1f39323d8e.png"> </img></div> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>0 0 10 0 0 0 0 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>0 </pre> <p>No rectangle can be formed.</p></section> </div> </span>
p02302
<H1>Convex Cut</H1> <center> <img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_CGL_CGL_4_C"> </center> <br> <p> As shown in the figure above, cut a convex polygon <var>g</var> by a line <var>p1p2</var> and print the area of the cut polygon which is on the left-hand side of the line. </p> <p> <var>g</var> is represented by a sequence of points <var>p<sub>1</sub></var>, <var>p<sub>2</sub></var>,..., <var>p<sub>n</sub></var> where line segments connecting <var>p<sub>i</sub></var> and <var>p<sub>i+1</sub></var> (1 &le; <var>i</var> &le; <var>n&minus;1</var>) are sides of the convex polygon. The line segment connecting <var>p<sub>n</sub></var> and <var>p<sub>1</sub></var> is also a side of the polygon. </p> <H2>Input</H2> <p> The input is given in the following format: </p> <pre> <var>g</var> (the sequence of the points of the polygon) <var>q</var> (the number of queries = the number of target lines) 1st query 2nd query : <var>q</var>th query </pre> <p> <var>g</var> is given as a sequence of points <var>p<sub>1</sub></var>,..., <var>p<sub>n</sub></var> in the following format: </p> <pre> <var>n</var> <var>x<sub>1</sub></var> <var>y<sub>1</sub></var> <var>x<sub>2</sub></var> <var>y<sub>2</sub></var> : <var>x<sub>n</sub></var> <var>y<sub>n</sub></var> </pre> <p> The first integer <var>n</var> is the number of points. The coordinate of the <var>i</var>-th point <var>p<sub>i</sub></var> is given by two integers <var>x<sub>i</sub></var> and <var>y<sub>i</sub></var>. The coordinates of points are given in the order of counter-clockwise visit of them. Note that all interior angles of given convex polygons are less than or equal to 180. </p> <p> For each query, a line represented by two points <var>p1</var> and <var>p2</var> is given. The coordinates of the points are given by four integers <var>p1x</var>, <var>p1y</var>, <var>p2x</var> and <var>p2y</var>. </p> <H2>Output</H2> <p> For each query, print the area of the cut polygon. The output values should be in a decimal fraction with an error less than 0.00001. </p> <H2>Constraints</H2> <ul> <li> 3 &le; <var>n</var> &le; 100 </li> <li> 1 &le; <var>q</var> &le; 100 </li> <li>-10000 &le; <var>x<sub>i</sub></var>, <var>y<sub>i</sub></var> &le; 10000</li> <li>-10000 &le; <var>p1x</var>,<var>p1y</var>,<var>p2x</var>,<var>p2y</var> &le; 10000</li> <li>No point in <var>g</var> will occur more than once.</li> <li><var>p1</var> &ne; <var>p2</var></li> </ul> <H2>Sample Input</H2> <pre> 4 1 1 4 1 4 3 1 3 2 2 0 2 4 2 4 2 0 </pre> <H2>Sample Output</H2> <pre> 2.00000000 4.00000000 </pre>