task
stringlengths
0
154k
__index_level_0__
int64
0
39.2k
Score : 400 points Problem Statement We have a grid with H rows and W columns. At first, all cells were painted white. Snuke painted N of these cells. The i -th ( 1 \leq i \leq N ) cell he painted is the cell at the a_i -th row and b_i -th column. Compute the following: For each integer j ( 0 \leq j \leq 9 ), how many subrectangles of size 3×3 of the grid contains exactly j black cells, after Snuke painted N cells? Constraints 3 \leq H \leq 10^9 3 \leq W \leq 10^9 0 \leq N \leq min(10^5,H×W) 1 \leq a_i \leq H (1 \leq i \leq N) 1 \leq b_i \leq W (1 \leq i \leq N) (a_i, b_i) \neq (a_j, b_j) (i \neq j) Input The input is given from Standard Input in the following format: H W N a_1 b_1 : a_N b_N Output Print 10 lines. The (j+1) -th ( 0 \leq j \leq 9 ) line should contain the number of the subrectangles of size 3×3 of the grid that contains exactly j black cells. Sample Input 1 4 5 8 1 1 1 4 1 5 2 3 3 1 3 2 3 4 4 4 Sample Output 1 0 0 0 2 4 0 0 0 0 0 There are six subrectangles of size 3×3 . Two of them contain three black cells each, and the remaining four contain four black cells each. Sample Input 2 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 Sample Output 2 4 26 22 10 2 0 0 0 0 0 Sample Input 3 1000000000 1000000000 0 Sample Output 3 999999996000000004 0 0 0 0 0 0 0 0 0
36,403
Problem H Rotating Cutter Bits 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. To show the usefulness of the mechanism, you are asked to simulate the cutting process by such a lathe. 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. 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. 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 points of interest, or POI in short. 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. 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. 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. 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. Figure H.1. The workpiece and the cutter bit in Sample 1 Input The input consists of a single test case with the following format. $M$ $N$ $L$ $x_{w1}$ $y_{w1}$ ... $x_{wM}$ $y_{wM}$ $x_{c1}$ $y_{c1}$ ... $x_{cN}$ $y_{cN}$ 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)$. 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. $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} )$. 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$. 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. 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. Note that $(0, 0)$ is not always inside the workpiece and $(L, 0)$ is not always inside the cutter bit. Output Output the number of POI remaining strictly inside the workpiece. Sample Input 1 4 6 5 -2 5 -2 -1 2 -1 2 5 -2 1 -2 0 0 0 0 -2 2 -2 2 1 Sample Output 1 8 Sample Input 2 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 Sample Output 2 6785772 Sample Input 3 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 Sample Output 3 966 Sample Input 4 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 Sample Output 4 64
36,404
Problem Statement There is a maze which can be described as a W \times H grid. The upper-left cell is denoted as (1, 1), and the lower-right cell is (W, H) . You are now at the cell (1, 1) and have to go to the cell (W, H) . 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. ...#...... a###.##### .bc...A... ##.#C#d#.# .#B#.#.### .#...#e.D. .#A..###.# ..e.c#..E. ####d###.# #....#.#.# ##E...d.C. In the maze, some cells are free (denoted by . ) and some cells are occupied by rocks (denoted by # ), 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 a contains a jewel of type A, and a cell denoted by A 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. 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. On the way from cell (1, 1) to cell (W, H) , how many jewels can you place to correct holes? Input 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. H W C_{11} C_{12} ... C_{1W} C_{21} C_{22} ... C_{2W} ... C_{H1} C_{H2} ... C_{HW} Here, H and W are the height and width of the grid. You may assume 1 \leq W, H \leq 50 . The rest of the datasets consists of H lines, each of which is composed of W letters. Each letter C_{ij} specifies the type of the cell (i, j) as described before. It is guaranteed that C_{11} and C_{WH} are never # . You may also assume that each lowercase or uppercase alphabet appear at most 10 times in each dataset. Output For each dataset, output the maximum number of jewels that you can place to corresponding holes. If you cannot reach the cell (W, H) , output -1. Sample Input 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 Output for the Sample Input 2 0 -1 25 25 1 25 4
36,405
Score : 1600 points Problem Statement Taichi thinks a binary string X of odd length N is beautiful if it is possible to apply the following operation \frac{N-1}{2} times so that the only character of the resulting string is 1 : Choose three consecutive bits of X and replace them by their median. For example, we can turn 00110 into 010 by applying the operation to the middle three bits. Taichi has a string S consisting of characters 0 , 1 and ? . Taichi wants to know the number of ways to replace the question marks with 1 or 0 so that the resulting string is beautiful, modulo 10^{9} + 7 . Constraints 1 \leq |S| \leq 300000 |S| is odd. All characters of S are either 0 , 1 or ? . Input Input is given from Standard Input in the following format: S Output Print the number of ways to replace the question marks so that the resulting string is beautiful, modulo 10^{9} + 7 . Sample Input 1 1??00 Sample Output 1 2 There are 4 ways to replace the question marks with 0 or 1 : 11100 : This string is beautiful because we can first perform the operation on the last 3 bits to get 110 and then on the only 3 bits to get 1 . 11000 : This string is beautiful because we can first perform the operation on the last 3 bits to get 110 and then on the only 3 bits to get 1 . 10100 : This string is not beautiful because there is no sequence of operations such that the final string is 1 . 10000 : This string is not beautiful because there is no sequence of operations such that the final string is 1 . Thus, there are 2 ways to form a beautiful string. Sample Input 2 ? Sample Output 2 1 In this case, 1 is the only beautiful string. Sample Input 3 ?0101???10???00?1???????????????0????????????1????0 Sample Output 3 402589311 Remember to output your answer modulo 10^{9} + 7 .
36,406
目盛りのないストップりォッチ 図のようなストップりォッチがありたす。このストップりォッチにはを瀺す目印が䞀぀あるだけで、目盛りがありたせん。起動した瞬間、針は目印を指し、そこから針は軞を䞭心に䞀定の割合で時蚈回りに回転したす。目盛りがないので、起動からの経過時間を盎接読み取るこずはできたせん。その代わり、針が目印から時蚈回りに$a$床回ったずきの経過時間が$t$秒であるこずがわかっおいたす。ただし、$a$は360床未満ずしたす。 角床$a$ず経過時間$t$が䞎えられたずき、ストップりォッチ起動埌に読み取った針の角床rが衚す経過時間を求めるプログラムを䜜成せよ。ただし、針が呚しおいないこずはわかっおいるものずする。 入力 入力は以䞋の圢匏で䞎えられる。 $a$ $t$ $r$ 行に角床$a$ ($1 \leq a \leq 359$)ず角床$a$のずきの経過時間$t$ ($1 \leq t \leq 1,000$)、読み取った角床$r$ ($0 \leq r \leq 359$)がすべお敎数で䞎えられる。ただし、$a$ず$r$の単䜍は床、$t$の単䜍は秒ずする。 出力 読み取った針の角床が衚す経過時間を秒で行に実数で出力する。ただし、誀差がプラスマむナス0.001を超えおはならない。 入出力䟋 入力䟋 180 120 90 出力䟋 60.0 入力䟋 90 100 120 出力䟋 133.333333
36,407
匏 䞎えられた 4 ぀の 1 から 9 の敎数を䜿っお、答えが 10 になる匏を぀くりたす。 4 ぀の敎数 a, b, c, d を入力したずき、䞋蚘の条件に埓い、答えが 10 になる匏を出力するプログラムを䜜成しおください。たた、答えが耇数ある時は、最初に芋぀かった答えだけを出力するものずしたす。答えがない時は、0 ず出力しおください。 挔算子ずしお、加算 (+)、枛算 (-)、乗算 (*) だけを䜿いたす。陀算 (/) は䜿いたせん。䜿甚できる挔算子は個です。 数を4぀ずも䜿わなければいけたせん。 4぀の数の順番は自由に入れ換えおかたいたせん。 カッコを䜿っおもかたいたせん。䜿甚できるカッコは組個以䞋です。 Input 耇数のデヌタセットが䞎えられたす。各デヌタセットの圢匏は以䞋のずおり a b c d 入力は぀の 0 で終了したす。デヌタセットの数は 40 を超えたせん。 Output 各デヌタセットに぀いお、䞎えられた 4 ぀の敎数ず䞊蚘の挔算蚘号およびカッコを組み合わせお倀が 10 ずなる匏たたは 0 を行に出力しおください。匏の文字列が 1024 文字を超えおはいけたせん。 Sample Input 8 7 9 9 4 4 4 4 5 5 7 5 0 0 0 0 Output for the Sample Input ((9 * (9 - 7)) - 8) 0 ((7 * 5) - (5 * 5))
36,408
Score : 500 points Problem Statement There are K items placed on a grid of squares with R rows and C columns. Let (i, j) denote the square at the i -th row ( 1 \leq i \leq R ) and the j -th column ( 1 \leq j \leq C ). The i -th item is at (r_i, c_i) and has the value v_i . Takahashi will begin at (1, 1) , the start, and get to (R, C) , the goal. When he is at (i, j) , he can move to (i + 1, j) or (i, j + 1) (but cannot move to a non-existent square). 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. Find the maximum possible sum of the values of items he picks up. Constraints 1 \leq R, C \leq 3000 1 \leq K \leq \min(2 \times 10^5, R \times C) 1 \leq r_i \leq R 1 \leq c_i \leq C (r_i, c_i) \neq (r_j, c_j) (i \neq j) 1 \leq v_i \leq 10^9 All values in input are integers. Input Input is given from Standard Input in the following format: R C K r_1 c_1 v_1 r_2 c_2 v_2 : r_K c_K v_K Output Print the maximum possible sum of the values of items Takahashi picks up. Sample Input 1 2 2 3 1 1 3 2 1 4 1 2 5 Sample Output 1 8 He has two ways to get to the goal: Visit (1, 1) , (1, 2) , and (2, 2) , in this order. In this case, the total value of the items he can pick up is 3 + 5 = 8 . Visit (1, 1) , (2, 1) , and (2, 2) , in this order. In this case, the total value of the items he can pick up is 3 + 4 = 7 . Thus, the maximum possible sum of the values of items he picks up is 8 . Sample Input 2 2 5 5 1 1 3 2 4 20 1 2 1 1 3 4 1 4 2 Sample Output 2 29 We have four items in the 1 -st row. The optimal choices are as follows: Visit (1, 1) (1, 2) , (1, 3) , (1, 4) , (2, 4) , and (2, 5) , in this order, and pick up all items except the one on (1, 2) . Then, the total value of the items he picks up will be 3 + 4 + 2 + 20 = 29 . Sample Input 3 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 Sample Output 3 142
36,409
Problem J: Substring Expression Trees are sometimes represented in the form of strings. Here is one of the most popular ways to represent unlabeled trees: Leaves are represented by " () ". Other nodes (i.e. internal nodes) are represented by " ( S 1 S 2 ... S n ) ", where S i is the string representing the i -th subnode. For example, the tree depicted in the figure below is represented by a string " ((()())()) ". 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 " ((() ())( )) " results in " ((())) ", which represents the tree depicted below. 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. Input The input contains a string that represents some unlabeled tree. The string consists of up to 100,000 characters. Output Print the number of portions of the given string such that removing them results in strings that represent other valid trees. Sample Input 1 ((()())()) Output for the Sample Input 1 10
36,410
Score : 200 points Problem Statement It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers. You are given an integer N . Find the N -th Lucas number. Here, the i -th Lucas number L_i is defined as follows: L_0=2 L_1=1 L_i=L_{i-1}+L_{i-2} (i≥2) Constraints 1≀N≀86 It is guaranteed that the answer is less than 10^{18} . N is an integer. Input Input is given from Standard Input in the following format: N Output Print the N -th Lucas number. Sample Input 1 5 Sample Output 1 11 L_0=2 L_1=1 L_2=L_0+L_1=3 L_3=L_1+L_2=4 L_4=L_2+L_3=7 L_5=L_3+L_4=11 Thus, the 5 -th Lucas number is 11 . Sample Input 2 86 Sample Output 2 939587134549734843
36,411
Problem L: RedBlue Story 倩空郜垂AIZUのUZIA高校では、競技プログラミングの郚掻動がずおも盛んである。 この郚掻には、 n 人のRed Coderず n 人のBlue Coderが所属しおいる。 ある日の郚掻の時間に、Red CoderずBlue Coderでペアを組み、この郚掻から n 組、KCPずいうコンテストに参加するこずずなった。この高校では、ペアを組む孊生同士は握手するずいう習わしがあるので、郚員たちは今すぐ自分のパヌトナヌを芋぀けるこずにした。 郚員たちは党速力で走るため、たっすぐにしか進めない。たた、郚員たちは、それぞれの郚員が移動する距離の総和をできるだけ小さくしたいず思っおいる。 なお、郚宀には2぀の円圢のテヌブルが眮いおある。 Problem 二次元平面䞊に2぀の円、 n 個の赀色の点、 n 個の青色の点がある。 2぀の円の䞭心座暙はそれぞれ( x 1 , y 1 ), ( x 2 , y 2 )であり、半埄はそれぞれ r 1 , r 2 である。 赀い点 i は、座暙( rx i , ry i )にあり、青い点 j は、座暙( bx j , by j )にある。 あなたは、以䞋の操䜜を n 回繰り返す必芁がある。 ただ遞ばれおいない点の䞭から、赀色の点ず青色の点を぀ず぀遞んで、2点の共通の目的地を蚭定し、その目的地に向かっお2点をそれぞれたっすぐ移動させる。 目的地は二次元平面䞊であれば、どこに蚭定しおも構わない。ただし、遞んだ2点は移動の際に円の内郚を通過するこずはできないので、そのような移動が発生する目的地を蚭定するこずはできない。 n 回の操䜜をしたずきの移動距離の総和を最小化せよ。 n 回の操䜜を行えない堎合は、代わりに"Impossible" (""は陀く) ず出力せよ。 Input 入力は以䞋の圢匏で䞎えられる。 n x 1 y 1 r 1 x 2 y 2 r 2 rx 1 ry 1 rx 2 ry 2 ... rx n ry n bx 1 by 1 bx 2 by 2 ... bx n by n 入力は党お敎数で䞎えられる。 1行目に n が䞎えられる。 2行目に x 1 , y 1 , r 1 が空癜区切りで䞎えられる。 3行目に x 2 , y 2 , r 2 が空癜区切りで䞎えられる。 4から3+ n 行に赀い点の座暙( rx i , ry i )が空癜区切りで䞎えられる。 4+ n から3+2× n 行に青い点の座暙( bx j , by j )が空癜区切りで䞎えられる。 Constraints 入力は以䞋の条件を満たす。 1 ≀ n ≀ 100 -1000 ≀ x i , y i ≀ 1000 1 ≀ r i ≀ 50 -1000 ≀ rx i , ry i , bx i , by i ≀ 1000 同じ座暙に耇数の点が存圚しおいるこずはない 任意の円の半埄を絶察倀10 -9 以内で倉化させおも、高々絶察倀10 -3 しか倉化しない 任意の円の半埄を絶察倀10 -9 以内で倉化させおも、"Impossible"なケヌスは"Impossible"のたたである 解は10000を超えない どの点も、円から10 -3 以䞊離れおいお、点が円呚䞊に存圚したり、点が円に内包されるこずはない 2぀の円は共通面積を持たず、10 -3 以䞊離れおいるこずが保蚌される Output n 回の操䜜をしたずきの移動距離の総和の最小倀を1行に出力せよ。なお、出力はゞャッゞ解の出力ずの絶察誀差が10 -2 以内であれば蚱容される。 n 回の操䜜を行えない堎合は、代わりに"Impossible" (""は陀く) ず出力せよ。 Sample Input 1 2 3 3 2 8 3 2 0 3 3 7 8 0 8 7 Sample Output 1 13.8190642862 Sample Input 2 2 3 3 2 8 3 2 3 0 3 7 8 0 8 7 Sample Output 2 10.0000000000 Sample Input 3 2 3 3 2 8 3 2 0 0 0 5 11 0 11 5 Sample Output 3 22.0000000000 Sample Input 4 1 10 10 10 31 10 10 15 19 26 1 Sample Output 4 Impossible 点同士を぀なぐこずはできたせん。
36,412
Data Center on Fire 今から少し未来の話である高密床蚘憶および長期保存可胜である蚘録デバむスが開発されおきたがコンテンツが生み出される速床が異垞なほどに速かったためデヌタセンタヌを蚭立したデヌタセンタヌを蚭立した圓初は小さな建物だったが増え続けるデヌタにあわせお䜕床も拡匵工事をしたため性胜の異なる゚レベヌタを䜕基も持぀こずずなった ずころがデヌタセンタヌで火灜が発生した火は䞀定時間だけ経過するず䞊の階ないし䞋の階に燃え広がるたた火が぀いおから䞀定時間だけ経過するずその階は焌倱しおしたうそこで゚レベヌタを䜿っおデバむスを運び出すこずずしたこの゚レベヌタは耐火性胜が完璧であるため階の焌倱に関わらず任意の階ぞ移動できるたた非垞に匷力な加速枛速装眮を持぀こずから加速および枛速にかかる時間は無芖できるほど小さいため䞀瞬にしお定垞速床に加速するこずあるいは停止するこずができるたた緊急時においおはいわゆる「開」ボタンが機胜しないようにプログラムされおいるため゚レベヌタの停止時間は運び出すあるいは降ろすデバむスの個数にかかわらず䞀定であるたた階の焌倱前に到着した゚レベヌタによっお運び出されるデバむスに぀いおはたずえ゚レベヌタの出発前に階が焌倱したずしおも焌倱の圱響を受けないただし゚レベヌタに乗せるこずができなかったデバむスは圓然ながら焌倱する ゚レベヌタはどの階から回収しおよいか分からないためデバむスのある最䞊階を目指すようにプログラムされおいるただし゚レベヌタ同士は通信可胜であり別の゚レベヌタが目的階に到着した瞬間に情報が通信される到着した゚レベヌタに党おのデバむスが積みこめるこずがわかったずきは目的階よりも䞋にあり回収可胜なデバむスが残っおいる階のうちで最䞊階に目的階を倉曎するたた焌倱のために目的階に向かう必芁性が倱われたずきも同様にしお目的階を倉曎する目的階を倉曎するずきに移動方向を倉曎する必芁があるずきは即座に移動方向を倉曎するたた゚レベヌタが満杯になっおそれ以䞊のデバむスを積みこむこずができないずきあるいは回収可胜なデバむスが残っおいないずきは 1 階を目指す あなたの仕事は䞊蚘の条件のもずで退避させるこずのできたデバむスの個数および到着時刻を求めるプログラムを䜜成するこずである Input 入力は耇数のデヌタセットから構成されるそれぞれのデヌタセットは次の圢匏で䞎えられる N M d n 1 n 2 ... n N c 1 v 1 ts 1 x 1 c 2 v 2 ts 2 x 2 ... c M v M ts M x M k tx ty tz 蚘号の意味は次のずおりである入力䞭の倀はすべお敎数である N (2 <= N <= 30) M (1 <= M <= 10)はそれぞれビルの階数゚レベヌタの基数を衚す d (1000 <= d <= 10000)は階ず階の間の距離を衚す n i (0 <= n i <= 100) は i 階にあるデバむスの個数を衚す c i (1 <= c i <= 50) v i (1 <= v i <= 2000) ts i (1 <= ts i <= 20) x i (1 <= x i <= N )はそれぞれ i 番目の゚レベヌタの容量速床停止時間初期䜍眮をあらわす初期䜍眮は䜕階にあるかで衚される k (2 <= k <= N ) tx (30 <= tx <= 300) ty (30 <= ty <= 300) tz (30 <= tz <= 300)はそれぞれ火元の階火が぀いおから焌倱するたでの時間䞊に燃え移るたでの時間䞋に燃え移るたでの時間を衚す 入力の終了は 2 ぀の 0 を含む行によっおあらわされるこれはデヌタセットの䞀郚ではない それぞれのデヌタセットは次の条件を満たすず仮定しおよい 単䜍時間の 1/1000 よりも短い時間の間に耇数の階の消倱が起こるこずはない 単䜍時間の 1/1000 よりも短い時間の間に耇数の゚レベヌタが同䞀の階で 1 階より䞊にある階に到着するこずない 単䜍時間の 1/1000 よりも短い時間の間に゚レベヌタの到着ずその゚レベヌタが到着しようずした階の焌倱が起こるこずはない Output それぞれのテストケヌスに぀いお回収されたデバむスの個数および最埌に回収されたデバむスが 1 階に到着しお゚レベヌタから降ろされるたでの時間を単䞀の空癜で区切っお 1 行で出力しなさいただし時間に぀いおは小数点以䞋に䜕個の数字を出力しおも構わないが0.001 を超える誀差を含めおはならないたた1 階にあるデバむス以倖は回収できなかったずきは時間ずしおれロを出力しなさい Sample Input 5 2 5000 10 20 0 30 5 10 1000 6 1 20 500 8 1 3 40 25 30 0 0 Output for the Sample Input 50 84.000
36,413
Score : 1400 points Problem Statement Count the number of strings S that satisfy the following constraints, modulo 10^9 + 7 . The length of S is exactly N . S consists of digits ( 0 ... 9 ). You are given Q intervals. For each i (1 \leq i \leq Q) , the integer represented by S[l_i \ldots r_i] (the substring of S between the l_i -th ( 1 -based) character and the r_i -th character, inclusive) must be a multiple of 9 . Here, the string S and its substrings may have leading zeroes. For example, 002019 represents the integer 2019 . Constraints 1 \leq N \leq 10^9 1 \leq Q \leq 15 1 \leq l_i \leq r_i \leq N Input Input is given from Standard Input in the following format: N Q l_1 r_1 : l_Q r_Q Output Print the number of strings that satisfy the conditions, modulo 10^9 + 7 . Sample Input 1 4 2 1 2 2 4 Sample Output 1 136 For example, S = 9072 satisfies the conditions because both S[1 \ldots 2] = 90 and S[2 \ldots 4] = 072 represent multiples of 9 . Sample Input 2 6 3 2 5 3 5 1 3 Sample Output 2 2720 Sample Input 3 20 10 2 15 5 6 1 12 7 9 2 17 5 15 2 4 16 17 2 12 8 17 Sample Output 3 862268030
36,414
The Smallest Window II 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. Constraints $1 \leq N \leq 10^5$ $1 \leq K \leq 10^5$ $1 \leq a_i \leq 10^5$ Input The input is given in the following format. $N$ $K$ $a_1$ $a_2$ ... $a_N$ Output Print the smallest sub-array size in a line. Sample Input 1 6 2 4 1 2 1 3 5 Sample Output 1 2 Sample Input 2 6 3 4 1 2 1 3 5 Sample Output 2 3 Sample Input 3 3 4 1 2 3 Sample Output 3 0
36,415
Checkered Pattern 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 W = 5 and H = 5 ). 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. Create a program to determine, starting from the given cross-section paper, if you can re-arrange them into a checkered pattern. Input The input is given in the following format. W H c 1,1 c 1,2 ... c 1,W c 2,1 c 2,2 ... c 2,W : c H,1 c H,2 ... c H,W The first line provides the number of squares in horizontal direction W (2≀ W ≀1000) and those in vertical direction H (2≀ H ≀1000). Each of subsequent H lines provides an array of W integers c i,j corresponding to a square of i -th row and j -th column. The color of the square is white if c i,j is 0, and black if it is 1. Output Output "yes" if the goal is achievable and "no" otherwise. Sample Input 1 3 2 1 1 0 0 0 1 Sample Output 1 yes Sample Input 2 2 2 0 0 1 1 Sample Output 2 no
36,416
Patience As the proverb says, "Patience is bitter, but its fruit is sweet." Writing programs within the limited time may impose some patience on you, but you enjoy it and win the contest, we hope. 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. Let's play a patience in this problem. 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. At the beginning, the twenty cards are laid in five rows by four columns (See Figure 1). All the cards are dealt face up. An example of the initial layout is shown in Figure 2. Figure 1: Initial layout Figure 2: Example of the initial layout 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 matching pair . The phrase "a pair of neighboring cards" means a pair of cards which are adjacent to each other. For example, in Figure 1, C 6 is adjacent to any of the following eight cards: C 1 , C 2 , C 3 , C 5 , C 7 , C 9 , C 10 and C 11 . In contrast, C 3 is adjacent to only the following three cards: C 2 , C 6 and C 7 . Every time you remove a pair, you must rearrange the remaining cards as compact as possible. To put it concretely, each remaining card C i must be examined in turn in its subscript order to be shifted to the uppermost-leftmost space. How to play: Search a matching pair. When you find more than one pair, choose one. In Figure 3, you decided to remove the pair of C 6 and C 9 . Remove the pair. (See Figure 4) Shift the remaining cards to the uppermost-leftmost space (See Figure 5, 6). Repeat the above procedure until you cannot remove any pair. Figure 3: A matching pair found Figure 4: Remove the matching pair Figure 5: Shift the remaining cards Figure 6: Rearranged layout 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. 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. Your job is to write a program which answers the minimal penalty for each initial layout. Input The input consists of multiple card layouts. The input is given in the following format. N Layout 0 Layout 1 ... Layout N -1 N 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. C 0 C 1 C 2 C 3 C 4 C 5 C 6 C 7 C 8 C 9 C 10 C 11 C 12 C 13 C 14 C 15 C 16 C 17 C 18 C 19 C i (0 <= i <= 19) is an integer from 1 to 5 which represents the face value of the card. Output For every initial card layout, the minimal penalty should be output, each in a separate line. Sample Input 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 Output for the Sample Input 0 4 12 0
36,417
G: ゚レベヌタ 問題 株匏䌚瀟AORは $N$ 階建おのビルである。地䞋階は存圚しない。 AORむカちゃんはむカであるため、階段を䞋りるこずは可胜だが、䞊るこずは䞍可胜である。 䞊の階に登れないず䞍䟿なため、$M$ 個の゚レベヌタをビルに蚭眮するこずにした。 ゚レベヌタを蚭眮するには時間がかかり、$i$ 番目の゚レベヌタは $D_i$ 日埌の倜に蚭眮が完了し、 $A_i$ 階以䞊 $B_i$ 階以䞋の党おの階を移動可胜にする。 あなたはAORむカちゃんに $Q$ 個の質問をされた。$i$ 番目の質問は「 $E_i$ 日埌の昌に、$S_i$ 階から $T_i$ 階に移動可胜か」ずいう質問である。 移動に䜿える手段は階段ず゚レベヌタのみである。たた移動にかかる時間は無芖できるものずする。 制玄 $2 \le N \le 10^5$ $1 \le M \le 10^5$ $1 \le Q \le 10^5$ $1 \le D_i , E_i \le 10^9$ $1 \le A_i < B_i \le N$ $1 \le S_i , T_i \le N$ 入力は党お敎数 入力 $N \ M\ Q$ $D_1 \ A_1 \ B_1$ $\vdots$ $D_M \ A_M \ B_M$ $E_1 \ S_1 \ T_1$ $\vdots$ $E_Q \ S_Q \ T_Q$ 出力 各質問ごずに䞀行で Yes たたは No を出力せよ。ただし質問された順に答えるこず。たた末尟に改行を出力せよ。 サンプル サンプル入力 1 5 1 2 3 1 5 3 1 5 4 1 5 サンプル出力 1 No Yes ゚レベヌタが蚭眮されるのは䞉日目の倜であるため、䞉日目の昌に移動するこずはできない。 サンプル入力 2 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 サンプル出力 2 Yes Yes Yes Yes No
36,418
Score : 100 points Problem Statement Print the circumference of a circle of radius R . Constraints 1 \leq R \leq 100 All values in input are integers. Input Input is given from Standard Input in the following format: R Output 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 10^{-2} . Sample Input 1 1 Sample Output 1 6.28318530717958623200 Since we accept an absolute or relative error of at most 10^{-2} , 6.28 is also an acceptable output, but 6 is not. Sample Input 2 73 Sample Output 2 458.67252742410977361942
36,419
Problem E: Roll-A-Big-Ball 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. 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. 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. The positions of the ball and a block can be like in Figure E-1 (a) and (b). Figure E-1: Possible positions of the ball and a block Input The input consists of a number of datasets. Each dataset is formatted as follows. N sx sy ex ey minx 1 miny 1 maxx 1 maxy 1 h 1 minx 2 miny 2 maxx 2 maxy 2 h 2 ... minx N miny N maxx N maxy N h N A dataset begins with a line with an integer N , the number of blocks (1 ≀ N ≀ 50). The next line consists of four integers, delimited by a space, indicating the start point ( sx , sy ) and the end point ( ex , ey ). The following N 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 ( minx , miny ), ( maxx , maxy ) of the bottom surface and the height h of the block. The integers sx , sy , ex , ey , minx , miny , maxx , maxy and h satisfy the following conditions. -10000 ≀ sx , sy , ex , ey ≀ 10000 -10000 ≀ minx i < maxx i ≀ 10000 -10000 ≀ miny i < maxy i ≀ 10000 1 ≀ h i ≀ 1000 The last dataset is followed by a line with a single zero in it. Output 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. Sample Input 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 Output for the Sample Input 30 1 18.16666666667 717.7857142857 50.5 50 18.16666666667 0 0
36,420
Score : 300 points Problem Statement Snuke has decided to play with a six-sided die. Each of its six sides shows an integer 1 through 6 , and two numbers on opposite sides always add up to 7 . Snuke will first put the die on the table with an arbitrary side facing upward, then repeatedly perform the following operation: Operation: Rotate the die 90° toward one of the following directions: left, right, front (the die will come closer) and back (the die will go farther). Then, obtain y points where y is the number written in the side facing upward. For example, let us consider the situation where the side showing 1 faces upward, the near side shows 5 and the right side shows 4 , as illustrated in the figure. If the die is rotated toward the right as shown in the figure, the side showing 3 will face upward. Besides, the side showing 4 will face upward if the die is rotated toward the left, the side showing 2 will face upward if the die is rotated toward the front, and the side showing 5 will face upward if the die is rotated toward the back. Find the minimum number of operation Snuke needs to perform in order to score at least x points in total. Constraints 1 ≩ x ≩ 10^{15} x is an integer. Input The input is given from Standard Input in the following format: x Output Print the answer. Sample Input 1 7 Sample Output 1 2 Sample Input 2 149696127901 Sample Output 2 27217477801
36,421
五等分のケヌキ (Divide Cake into Five) Segtree 君は五぀子の家庭教垫をしおいたす。今日はクリスマスむブなので、五぀子のために円圢のケヌキを五等分しようずしおいたす。 ケヌキは䞭心から扇圢状に $N$ 個のピヌスに分けられおおり、 $i$ 番目ず $i + 1$ 番目($1 \leq i \leq N - 1$) 、 $N$ 番目ず $1$ 番目のピヌスは隣り合っおいたす。 $i$ 番目のピヌスの倧きさは $A_i$ です。党おのピヌスの倧きさの和を $S$ ずするず、党おの入力に぀いお $S$ が $5$ の倍数であるこずが保蚌されたす。 ある非負敎数 $Y$ が䞎えられたす。以䞋の条件を満たすようなケヌキの五぀子ぞの分け方を、「ケヌキの五等分」ず呌びたす。 党おの人が1぀以䞊のピヌスを取る。 ケヌキの䞭でそれぞれが取るピヌスたちは連結である。぀たり、取る人でピヌスをグルヌプ分けしたずき、同じグルヌプか぀隣り合っおいるピヌスに移動するこずを繰り返しお蟿り着けないような同じグルヌプ内のピヌスの組は存圚しない。 誰も取らないピヌスは存圚しない。 党おの人に぀いお、取るピヌスの倧きさを $X$ ずしたずき、必ず $X + Y \geq S / 5$ を満たす。 「ケヌキの五等分」になるようなケヌキの分け方の通り数が䜕通りあるか求めおください。 入力 入力は以䞋の圢匏で暙準入力から䞎えられる。 $N$ $Y$ $A_1$ $A_2$ $\ldots$ $A_N$ 出力 「ケヌキの五等分」になるようなケヌキの分け方の通り数を出力しおください。 ただし、最埌には改行を入れるこず。 制玄 $5 \leq N \leq 300$ $1 \leq A_i \leq 10^9$ $0 \leq Y \leq 10^9$ 入力は党お敎数である。 入力䟋1 5 0 1 1 1 1 1 出力䟋1 1 入力䟋2 10 27 3 1 4 1 5 9 2 6 5 4 出力䟋2 252
36,422
Party Dress 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. 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. 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. Input The input is given in the following format. $A$ $B$ 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$). Output Output the frequency she has to wear the most reused dress. Sample Input 1 3 5 Sample Output 1 2 Sample Input 2 25 10 Sample Output 2 1
36,423
Score : 200 points Problem Statement There are some animals in a garden. Each of them is a crane with two legs or a turtle with four legs. Takahashi says: "there are X animals in total in the garden, and they have Y legs in total." Determine whether there is a combination of numbers of cranes and turtles in which this statement is correct. Constraints 1 \leq X \leq 100 1 \leq Y \leq 100 All values in input are integers. Input Input is given from Standard Input in the following format: X Y Output If there is a combination of numbers of cranes and turtles in which the statement is correct, print Yes ; otherwise, print No . Sample Input 1 3 8 Sample Output 1 Yes The statement "there are 3 animals in total in the garden, and they have 8 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. Sample Input 2 2 100 Sample Output 2 No There is no combination of numbers of cranes and turtles in which this statement is correct. Sample Input 3 1 2 Sample Output 3 Yes We also consider the case in which there are only cranes or only turtles.
36,424
Score : 400 points Problem Statement We have a pyramid with N steps, built with blocks. The steps are numbered 1 through N from top to bottom. For each 1≀i≀N , step i consists of 2i-1 blocks aligned horizontally. The pyramid is built so that the blocks at the centers of the steps are aligned vertically. A pyramid with N=4 steps Snuke wrote a permutation of ( 1 , 2 , ... , 2N-1 ) into the blocks of step N . Then, he wrote integers into all remaining blocks, under the following rule: The integer written into a block b must be equal to the median of the three integers written into the three blocks directly under b , or to the lower left or lower right of b . Writing integers into the blocks Afterwards, he erased all integers written into the blocks. Now, he only remembers that the integer written into the block of step 1 was x . Construct a permutation of ( 1 , 2 , ... , 2N-1 ) that could have been written into the blocks of step N , or declare that Snuke's memory is incorrect and such a permutation does not exist. Constraints 2≀N≀10^5 1≀x≀2N-1 Input The input is given from Standard Input in the following format: N x Output If no permutation of ( 1 , 2 , ... , 2N-1 ) could have been written into the blocks of step N , print No . Otherwise, print Yes in the first line, then print 2N-1 lines in addition. The i -th of these 2N-1 lines should contain the i -th element of a possible permutation. Sample Input 1 4 4 Sample Output 1 Yes 1 6 3 7 4 5 2 This case corresponds to the figure in the problem statement. Sample Input 2 2 1 Sample Output 2 No No matter what permutation was written into the blocks of step N , the integer written into the block of step 1 would be 2 .
36,425
Score : 300 points Problem Statement There are N sightseeing spots on the x -axis, numbered 1, 2, ..., N . Spot i is at the point with coordinate A_i . It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis. You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0 , then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0 . However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i . 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 0 at the beginning and the end, as planned. For each i = 1, 2, ..., N , find the total cost of travel during the trip when the visit to Spot i is canceled. Constraints 2 \leq N \leq 10^5 -5000 \leq A_i \leq 5000 ( 1 \leq i \leq N ) All input values are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print N lines. In the i -th line, print the total cost of travel during the trip when the visit to Spot i is canceled. Sample Input 1 3 3 5 -1 Sample Output 1 12 8 10 Spot 1 , 2 and 3 are at the points with coordinates 3 , 5 and -1 , respectively. For each i , the course of the trip and the total cost of travel when the visit to Spot i is canceled, are as follows: For i = 1 , the course of the trip is 0 \rightarrow 5 \rightarrow -1 \rightarrow 0 and the total cost of travel is 5 + 6 + 1 = 12 yen. For i = 2 , the course of the trip is 0 \rightarrow 3 \rightarrow -1 \rightarrow 0 and the total cost of travel is 3 + 4 + 1 = 8 yen. For i = 3 , the course of the trip is 0 \rightarrow 3 \rightarrow 5 \rightarrow 0 and the total cost of travel is 3 + 2 + 5 = 10 yen. Sample Input 2 5 1 1 1 2 0 Sample Output 2 4 4 4 2 4 Sample Input 3 6 -679 -2409 -3258 3095 -3291 -4462 Sample Output 3 21630 21630 19932 8924 21630 19288
36,426
Problem F: Magnum Tornado 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. 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. 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. Figure 1 shows the solution for the first sample input. Figure 1: The solution for the first sample input Input The input begins with a line that solely consists of an integer N (2 <= N <= 100), the number of line segments in the circuit. This is followed by N lines, where the i -th line corresponds to the i -th line segment (1 <= i <= N ). Each of these N lines contains 4 integers x 0 , y 0 , x 1 and y 1 (-100 <= x 0 , y 0 , x 1 , y 1 <= 100) in this order, separated by a space. Here ( x 0 , y 0 ) is the starting point and ( x 1 , y 1 ) is the ending point of the i -th line segment. For each i , the i -th and (i+1) -th line segments are connected smoothly by a circular arc, which you may assume exists uniquely (for simplicity, we consider the (N+1) -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. Output 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. Sample Input 1 5 0 1 0 2 1 3 2 3 2 2 1 2 1 1 2 1 2 0 1 0 Output for the Sample Input 1 9.712 Sample Input 2 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 Output for the Sample Input 2 27.406
36,427
Score : 800 points Problem Statement The beauty of a sequence a of length n is defined as a_1 \oplus \cdots \oplus a_n , where \oplus denotes the bitwise exclusive or (XOR). You are given a sequence A of length N . Snuke will insert zero or more partitions in A to divide it into some number of non-empty contiguous subsequences. There are 2^{N-1} possible ways to insert partitions. How many of them divide A into sequences whose beauties are all equal? Find this count modulo 10^{9}+7 . Constraints All values in input are integers. 1 \leq N \leq 5 \times 10^5 0 \leq A_i < 2^{20} Input Input is given from Standard Input in the following format: N A_1 A_2 \ldots A_{N} Output Print the answer. Sample Input 1 3 1 2 3 Sample Output 1 3 Four ways of dividing A shown below satisfy the condition. The condition is not satisfied only if A is divided into (1),(2),(3) . (1,2,3) (1),(2,3) (1,2),(3) Sample Input 2 3 1 2 2 Sample Output 2 1 Sample Input 3 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 Sample Output 3 147483634 Find the count modulo 10^{9}+7 . Sample Input 4 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 Sample Output 4 292
36,428
Problem F: Power Calculus Starting with x and repeatedly multiplying by x , we can compute x 31 with thirty multiplications: x 2 = x × x , x 3 = x 2 × x , x 4 = x 3 × x , ... , x 31 = x 30 × x . The operation of squaring can appreciably shorten the sequence of multiplications. The following is a way to compute x 31 with eight multiplications: x 2 = x × x , x 3 = x 2 × x , x 6 = x 3 × x 3 , x 7 = x 6 × x , x 14 = x 7 × x 7 , x 15 = x 14 × x , x 30 = x 15 × x 15 , x 31 = x 30 × x . This is not the shortest sequence of multiplications to compute x 31 . There are many ways with only seven multiplications. The following is one of them: x 2 = x × x , x 4 = x 2 × x 2 , x 8 = x 4 × x 4 , x 10 = x 8 × x 2 , x 20 = x 10 × x 10 , x 30 = x 20 × x 10 , x 31 = x 30 × x . There however is no way to compute x 31 with fewer multiplications. Thus this is one of the most eficient ways to compute x 31 only by multiplications. If division is also available, we can find a shorter sequence of operations. It is possible to compute x 31 with six operations (five multiplications and one division): x 2 = x × x , x 4 = x 2 × x 2 , x 8 = x 4 × x 4 , x 16 = x 8 × x 8 , x 32 = x 16 × x 16 , x 31 = x 32 ÷ x . This is one of the most eficient ways to compute x 31 if a division is as fast as a multiplication. Your mission is to write a program to find the least number of operations to compute x n by multiplication and division starting with x for the given positive integer n . Products and quotients appearing in the sequence of operations should be x to a positive integer's power. In other words, x -3 , for example, should never appear. Input The input is a sequence of one or more lines each containing a single integer n . n is positive and less than or equal to 1000. The end of the input is indicated by a zero. Output Your program should print the least total number of multiplications and divisions required to compute x n starting with x for the integer n . The numbers should be written each in a separate line without any superfluous characters such as leading or trailing spaces. Sample Input 1 31 70 91 473 512 811 953 0 Output for the Sample Input 0 6 8 9 11 9 13 12
36,429
すぬけ君の蟞曞には n 個の英小文字からなる単語 s 1 , . . ., s n がのっおいるこれは蟞曞順で比范したずき s 1 < . . . < s n をみたす残念ながらいく぀かの文字はかすれお読めなくなっおしたっおいる読めなくなった文字は ? で衚される ? を英小文字で眮き換えお蟞曞を埩元する方法は䜕通りあるかmod 1,000,000,007 でもずめよ Constraints 1 ≀ n ≀ 50 1 ≀ |s i | ≀ 20 s i に珟れる文字は英小文字たたは ? である Input n s 1 . . . s n Output 答えを䞀行に出力せよ Sample Input 1 2 ?sum??mer c??a??mp Sample Output 1 703286064 Sample Input 2 3 snuje ????e snule Sample Output 2 1
36,430
Score : 200 points Problem Statement La Confiserie d'ABC sells cakes at 4 dollars each and doughnuts at 7 dollars each. Determine if there is a way to buy some of them for exactly N 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. Constraints N is an integer between 1 and 100 , inclusive. Input Input is given from Standard Input in the following format: N Output If there is a way to buy some cakes and some doughnuts for exactly N dollars, print Yes ; otherwise, print No . Sample Input 1 11 Sample Output 1 Yes If you buy one cake and one doughnut, the total will be 4 + 7 = 11 dollars. Sample Input 2 40 Sample Output 2 Yes If you buy ten cakes, the total will be 4 \times 10 = 40 dollars. Sample Input 3 3 Sample Output 3 No The prices of cakes ( 4 dollars) and doughnuts ( 7 dollars) are both higher than 3 dollars, so there is no such way.
36,431
Problem J: ねこ泥棒ず金曜日のお屋敷 な぀めは倧のねこ奜きである。な぀めの通孊路には通称ねこ屋敷ず呌ばれおいる家がある。その家はたくさんのねこを飌っおいるこずで有名で、な぀めは通孊途䞭によくこの家の前で飌いねこに遭遇し、䞀緒に遊んでいた。そんなある日、な぀めは衝撃的な事実を知っおしたった。それは、実はねこ屋敷の䞻人は、機嫌が悪くなるずよく飌いねこたちを虐埅しおいる、ずいうこずだった。ねこ屋敷の䞻人を蚱せなくなったな぀めは、ねこたちを救うため、䞻人の居ない間にねこたちを盗みだすこずにした。 な぀めはねこ屋敷の䞻人の行動パタヌンを芳察し、毎週決たっお出掛けおいるタむミングをねらっおねこたちを盗みだすこずにした。ねこ屋敷は二次元平面ずしお衚わされおおり、な぀めが屋敷の䞭に忍びこむ時点でのそれぞれのねこの䜍眮は分かっおいる。ねこたちはそれぞれ決たったルヌトを垞に50メヌトル毎分のスピヌドでたわっおいる。䞀方、な぀めは最倧80メヌトル毎分のスピヌドで移動できる。な぀めは屋敷のずある堎所から䟵入し、屋敷内を移動し、䞻人が垰っおくるたでに脱出口から出る。な぀めがねこず同じ地点に到達するず、な぀めはねこを抱えるこずができる。これを行なうのにかかる時間は無芖できる。な぀めは䜕匹でもねこを抱えるこずができるし、䜕匹抱えおいおも移動速床が萜ちるこずはないが、必ず䞻人が垰っおくる前に屋敷を脱出しなければならない。 残念ながら、な぀めはねこ屋敷のねこを党員盗みだすこずはできないかもしれない。しかし、1匹でも倚くのねこを幞せにするために、できるだけ倚くのねこを盗みだすこずにした。たた、同じ数のねこを盗みだせるのであれば、屋敷の䞻人に捕たるリスクを抑えるため、できるだけ早い時間に屋敷から脱出する。 な぀めが屋敷に䟵入する時刻ず䜍眮、屋敷の䞻人が戻っおくる時刻、脱出口の堎所、およびねこの初期䜍眮ず巡回ルヌトが䞎えられる。な぀めが䜕匹のねこを盗みだしお、どの時刻に屋敷を脱出できるかを答えるプログラムを曞いおほしい。 Input 入力の1行目には、䟵入口の x , y 座暙が1぀の空癜文字で区切られお䞎えられる。2行目には同様に脱出口の䜍眮が䞎えられる。3行目にはな぀めが屋敷に䟵入した時刻、4行目には屋敷の䞻人が垰っおくる時刻が24時間制のHH:MM:SSの圢匏で䞎えられる。 5行目はねこの総数 m であり、続く m 行に各ねこの行動パタヌンが䞎えられる。5+ i 行目 ( i = 1, 2, ..., m ) が i 番目のねこの巡回ルヌトに察応しおいる。各行の初めには自然数 k i が䞎えられ、続いおねこの巡回ルヌトが k i 個の x , y 座暙倀を䞊べたものずしお䞎えられる。ねこの巡回ルヌトは、これらの連続する点および最埌ず最初の点を線分で぀ないだものである。な぀めが屋敷に䟵入した時点で、ねこは䞎えられた最初の点におり、以降ずっず巡回ルヌト䞊を等速で移動する。䞎えられたルヌトの連続する点が同じ座暙であるこずはない。 なお、スタヌト時間ずゎヌル時間は同じ日でのものであるこずが保蚌されおいるな぀めが䞻人の垰っおくる前に脱出する方法は必ず存圚する。同じ行にある数は党お1぀の空癜文字で区切られおいる。 ねこの数は1以䞊14以䞋、ねこの巡回ルヌトを衚わす点の数は2以䞊1000以䞋であり、党おの座暙倀は絶察倀が100000を越えない敎数であるこずが保蚌されおいる。 座暙倀の単䜍は党おメヌトルである。 Output 1行目に、な぀めが盗み出すこずのできるねこの最倧数を出力せよ。2行目には、な぀めがなるべく倚い数のねこを盗みだす方法の䞭で、最も早く脱出口に到達できる時刻を、HH MM SS.nnnnnn (空癜区切り)の圢匏で答えよ。秒の小数点以䞋は6桁出力せよ。なお、10 -6 秒を越える誀差があっおはならない。 なお、䞻人の垰っおくる時間が±1ms倉化しおも、最倚遭遇可胜数は倉化しないこずが保蚌されおいる。 Notes on Submission 䞊蚘圢匏で耇数のデヌタセットが䞎えられたす。入力デヌタの 1 行目にデヌタセットの数が䞎えられたす。各デヌタセットに察する出力を䞊蚘圢匏で順番に出力するプログラムを䜜成しお䞋さい。 Sample Input 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 Output for the Sample Input 1 17 59 59.076923 0 15 00 00.000000
36,432
䞉角圢ず円 平面䞊にある䞉角圢ず円の䜍眮関係を刀定するプログラムを䜜成しおください。察象ずなる図圢はいずれも境界を含むものずしたす。 䞉角圢は 3 頂点の䜍眮が䞎えられ、円は䞭心の䜍眮ず半埄が䞎えられたす。䜍眮は盎亀座暙系による぀の敎数の組によっお䞎えられたす。半埄も敎数で䞎えられたす。 Input 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりはれロふた぀の行で瀺されたす。 各デヌタセットは以䞋の圢匏で䞎えられたす。 x 1 y 1 x 2 y 2 x 3 y 3 x c y c r 行目から行目に、䞉角圢の第 i の頂点座暙 x i , y i が䞎えられたす。行目に円の䞭心の座暙 x c , y c 、行目に円の半埄 r が䞎えられたす。䞎えられる入力はすべお、1 以䞊 10,000 以䞋の敎数ずしたす。 デヌタセットの数は 100 を超えたせん。 Output 入力デヌタセットごずに以䞋の圢匏で刀定結果を行に出力したす。 円が䞉角圢に含たれる堎合 a 䞉角圢が円に含たれる堎合 b それ以倖の堎合で、共通郚分がある堎合には c 共通郚分がない堎合には d Sample Input 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 Output for the Sample Input b c d a
36,433
魚の生息範囲 (Fish) 問題 オヌストラリア倧陞の西には広いむンド掋が広がっおいる海掋研究者である JOI 氏はむンド掋に生息しおいるある N 皮類の魚の性質に぀いお研究しおいる それぞれの魚の皮類に察しお海の䞭に盎方䜓状の生息範囲が定たっおいる魚は境界も含めお生息範囲の䞭のどの堎所にも移動できるが生息範囲の倖に出るこずは決しおない海の䞭の点は3 ぀の実数 (x, y, d) によっお衚される (x, y, d) は䞊空から芋たずきにある地点を基準にしお東に x北に y 進んだ䜍眮であり海面からの深さが d の点を衚すただし海面は平面であるずする JOI 氏はK 皮類以䞊の魚の生息範囲が重なる堎所がどのくらいあるかを知りたいそのような堎所党䜓の䜓積を求めるプログラムを䜜成せよ 入力 入力は 1 + N 行からなる 1 行目には2 ぀の敎数 N, K (1 ≩ K ≩ N ≩ 50) が空癜を区切りずしお曞かれおいるこれは魚が N 皮類でありK 皮類以䞊の魚の生息範囲が重なる堎所の䜓積を求めたいこずを衚す 続く N 行のうちの i 行目 (1 ≩ i ≩ N) には6 ぀の敎数 X i,1 , Y i,1 , D i,1 , X i,2 , Y i,2 , D i,2 (0 ≩ X i,1  X i,2 ≩ 1000000 (= 10 6 )0 ≩ Y i,1  Y i,2 ≩ 1000000 (= 10 6 )0 ≩ D i,1  D i,2 ≩ 1000000 (= 10 6 )) が曞かれおいるこれはi 皮類目の魚の生息範囲が 8 点 (X i,1 , Y i,1 , D i,1 ), (X i,2 , Y i,1 , D i,1 ), (X i,2 , Y i,2 , D i,1 ), (X i,1 , Y i,2 , D i,1 ), (X i,1 , Y i,1 , D i,2 ), (X i,2 , Y i,1 , D i,2 ), (X i,2 , Y i,2 , D i,2 ), (X i,1 , Y i,2 , D i,2 ) を頂点ずする盎方䜓であるこずを衚す 出力 K 皮類以䞊の魚の生息範囲が重なる堎所党䜓の䜓積を 1 行で出力せよ 入出力䟋 入力䟋 1 3 2 30 50 0 50 70 100 10 20 20 70 90 60 40 60 20 90 90 70 出力䟋 1 49000 入出力䟋 1 においお䟋えば点 (45, 65, 65) は 1 皮類目の魚ず 3 皮類目の魚の生息範囲であるので条件を満たす堎所である䞀方点 (25, 35, 45) は 2 皮類目の魚のみの生息範囲であるので条件を満たす堎所ではないたた魚の生息範囲は䞋の図のようになっおいる点 O は海面䞊の基準の地点を衚す 入力䟋 2 1 1 0 0 0 1000000 1000000 1000000 出力䟋 2 1000000000000000000 問題文ず自動審刀に䜿われるデヌタは、 情報オリンピック日本委員䌚 が䜜成し公開しおいる問題文ず採点甚テストデヌタです。
36,434
Treasure Hunt When a boy was cleaning up after his grand father passing, he found an old paper: 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". 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. For simplicity, 1 step is equivalent to 1 meter. Input consists of several pairs of two integers d (the first integer) and t (the second integer) separated by a comma. Input ends with "0, 0". Your program should print the coordinate ( x , y ) 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. You can assume that d ≀ 100 and -180 ≀ t ≀ 180. Input A sequence of pairs of integers d and t which end with " 0,0 ". Output Print the integer portion of x and y in a line respectively. Sample Input 56,65 97,54 64,-4 55,76 42,-27 43,80 87,-86 55,-6 89,34 95,5 0,0 Output for the Sample Input 171 -302
36,435
G: AOR-String 問題 $N$ 個の文字列 $S_i$ が䞎えられる. $S_i$ を任意の順に繋げお埗られる文字列に含たれる "AOR" の数の最倧倀を求めよ. 制玄 $1 \leq N \leq 10^5$ $1 \leq |S_i| \leq 20$ $S_i$ は倧文字アルファベットのみからなる 入力圢匏 入力は以䞋の圢匏で䞎えられる. $N$ $S_1$ 
 $S_N$ 出力 $S_i$ を任意の順に繋げお埗られる文字列に含たれる "AOR" の数の最倧倀を出力せよ. たた, 末尟に改行も出力せよ. サンプル サンプル入力 1 2 AORA OR サンプル出力 1 2 サンプル入力 2 5 AB CA ORA XX AOR サンプル出力 2 2
36,436
カヌドゲヌム 問題 次のような2人で行うカヌドゲヌムがある このゲヌムでは 1から2nたでの各敎数が曞かれた党郚で2n枚のカヌドを䜿甚する ここでnは1以䞊100以䞋の敎数である このカヌドを2人にn枚ず぀配る 次のルヌルに埓っお亀互にカヌドを1枚ず぀堎に出す 堎にカヌドが出おいないならば 奜きなカヌドを出すこずができる 堎にカヌドが出おいるならば 最埌に堎に出たカヌドよりも倧きい数の曞かれたカヌドを出すこずができる カヌドが出せる堎合は必ず堎にカヌドを出す必芁がある 出せるカヌドが無い堎合はパスずなり盞手の番になる このずき堎に出おいるカヌドは無くなる ゲヌムは堎にカヌドが出おいない状態で始める どちらかの手持ちのカヌドが無くなった時点でゲヌムは終了する ゲヌム終了時に盞手の持っおいるカヌドの枚数を埗点ずする 倪郎ず花子はこのゲヌムで察戊するこずになったゲヌムは倪郎の番から始める 2人は共に出すこずのできるカヌドのうち必ず䞀番小さい数が曞かれたカヌドを出すこずにしおいる 倪郎に配られるカヌドが入力されたずき倪郎ず花子の埗点を出力するプログラムを䜜成せよ 入力 入力は耇数のデヌタセットからなる各デヌタセットは以䞋の圢匏で䞎えられる 入力は n+1 行ある 1行目には敎数nが曞かれおいる 2行目からn+1行目たでの各行には敎数が1぀ず぀曞かれおおり倪郎に配られるカヌドに曞かれた敎数を衚す n が 0 のずき入力の終了を瀺す. デヌタセットの数は 5 を超えない 出力 デヌタセットごずに 1行目には倪郎の埗点を 2行目には花子の埗点を出力せよ 入出力䟋 入力䟋 5 1 7 9 6 10 10 8 7 14 18 4 11 3 17 5 19 0 出力䟋 3 0 2 0 䞊蚘問題文ず自動審刀に䜿われるデヌタは、 情報オリンピック日本委員䌚 が䜜成し公開しおいる問題文ず採点甚テストデヌタです。
36,437
Problem B: The Last Ant 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. 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. 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. Figure B.1 corresponds to the first dataset of the sample input. Figure B.1. Movements of ants Input The input consists of one or more datasets. Each dataset is formatted as follows. n l d 1 p 1 d 2 p 2 ... d n p n The first line of a dataset contains two integers separated by a space. n (1 ≀ n ≀ 20) represents the number of ants, and l ( n + 1 ≀ l ≀ 100) represents the length of the tunnel in centimeters. The following n lines describe the initial states of ants. Each of the lines has two items, d i and p i , separated by a space. Ants are given numbers 1 through n . The ant numbered i has the initial direction d i and the initial position p i . The initial direction d i (1 ≀ i ≀ n ) is L (to the left) or R (to the right). The initial position p i (1 ≀ i ≀ n ) 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 ≀ p 1 < p 2 < ... < p n ≀ l - 1. The last dataset is followed by a line containing two zeros separated by a space. Output 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. Sample Input 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 Output for the Sample Input 5 1 9 1 7 1 8 2 98 2 8 2 8 3
36,438
Score : 300 points Problem Statement We have a sequence of N integers A~=~A_0,~A_1,~...,~A_{N - 1} . Let B be a sequence of K \times N integers obtained by concatenating K copies of A . For example, if A~=~1,~3,~2 and K~=~2 , B~=~1,~3,~2,~1,~3,~2 . Find the inversion number of B , modulo 10^9 + 7 . Here the inversion number of B is defined as the number of ordered pairs of integers (i,~j)~(0 \leq i < j \leq K \times N - 1) such that B_i > B_j . Constraints All values in input are integers. 1 \leq N \leq 2000 1 \leq K \leq 10^9 1 \leq A_i \leq 2000 Input Input is given from Standard Input in the following format: N K A_0 A_1 ... A_{N - 1} Output Print the inversion number of B , modulo 10^9 + 7 . Sample Input 1 2 2 2 1 Sample Output 1 3 In this case, B~=~2,~1,~2,~1 . We have: B_0 > B_1 B_0 > B_3 B_2 > B_3 Thus, the inversion number of B is 3 . Sample Input 2 3 5 1 1 1 Sample Output 2 0 A may contain multiple occurrences of the same number. Sample Input 3 10 998244353 10 9 8 7 5 6 3 4 2 1 Sample Output 3 185297239 Be sure to print the output modulo 10^9 + 7 .
36,439
魔法陣 Problem Statement 〜魔法陣の描き方〜 十分広くお真っ癜な床を甚意したす 床の座暙 (0,0) の点を䞭心にしお半埄 1, 2, ..., R の円を描きたす 半埄 1 の円ず半埄 2 の円の間半埄 3 の円ず半埄 4 の円の間 ... を青色で塗りたすなお半埄 R の円の倖には色を塗っおはいけたせん 床に頂点数 N の倚角圢を䞀぀描きたす 倚角圢の内郚の癜色の領域を青色で青色の領域を癜色で塗りなおしたす 魔法陣の力は魔法陣に青色が倚く含たれるほど匷くなるずいう そこであなたには魔法陣に含たれる青い領域の面積を求めおほしい 次の図はこの手順で描くこずのできる魔法陣の䞀䟋である Input 入力は以䞋の圢匏に埓う䞎えられる数は党お敎数である N R x_1 y_1 ... x_N y_N (x_i, y_i) は倚角圢の i 番目の頂点である Constraints 3 ≩ N ≩ 100 1 ≩ R ≩ 100 倚角圢は半埄 R の円の内郚たたは円呚䞊に含たれる 倚角圢は自己亀差をもたない 倚角圢の頂点は反時蚈回りの順番で䞎えられる Output 青い領域の面積を 1 行に出力せよ 出力する倀は真の倀ずの絶察誀差たたは盞察誀差が 10^{-8} 未満でなければならない Sample Input 1 3 1 0 0 1 0 0 1 Output for the Sample Input 1 0.500000000 Sample Input 2 3 2 0 0 2 0 0 2 Output for the Sample Input 2 8.995574288 Sample Input 3 3 2 1 -1 1 1 -2 0 Output for the Sample Input 3 11.123246567 Sample Input 4 4 3 1 1 -1 1 -1 -1 1 -1 Output for the Sample Input 4 11.707963268
36,440
Score : 400 points Problem Statement Takahashi has a water bottle with the shape of a rectangular prism whose base is a square of side a~\mathrm{cm} and whose height is b~\mathrm{cm} . (The thickness of the bottle can be ignored.) We will pour x~\mathrm{cm}^3 of water into the bottle, and gradually tilt the bottle around one of the sides of the base. When will the water be spilled? More formally, find the maximum angle in which we can tilt the bottle without spilling any water. Constraints All values in input are integers. 1 \leq a \leq 100 1 \leq b \leq 100 1 \leq x \leq a^2b Input Input is given from Standard Input in the following format: a b x Output 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 10^{-6} . Sample Input 1 2 2 4 Sample Output 1 45.0000000000 This bottle has a cubic shape, and it is half-full. The water gets spilled when we tilt the bottle more than 45 degrees. Sample Input 2 12 21 10 Sample Output 2 89.7834636934 This bottle is almost empty. When the water gets spilled, the bottle is nearly horizontal. Sample Input 3 3 1 8 Sample Output 3 4.2363947991 This bottle is almost full. When the water gets spilled, the bottle is still nearly vertical.
36,441
Score : 1700 points Problem Statement There is a railroad in Takahashi Kingdom. The railroad consists of N sections, numbered 1 , 2 , ..., N , and N+1 stations, numbered 0 , 1 , ..., N . Section i directly connects the stations i-1 and i . A train takes exactly A_i minutes to run through section i , regardless of direction. Each of the N sections is either single-tracked over the whole length, or double-tracked over the whole length. If B_i = 1 , section i is single-tracked; if B_i = 2 , section i 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. Snuke is creating the timetable for this railroad. In this timetable, the trains on the railroad run every K minutes, as shown in the following figure. Here, bold lines represent the positions of trains running on the railroad. (See Sample 1 for clarification.) When creating such a timetable, find the minimum sum of the amount of time required for a train to depart station 0 and reach station N , and the amount of time required for a train to depart station N and reach station 0 . It can be proved that, if there exists a timetable satisfying the conditions in this problem, this minimum sum is always an integer. Formally, the times at which trains arrive and depart must satisfy the following: Each train either departs station 0 and is bound for station N , or departs station N and is bound for station 0 . Each train takes exactly A_i minutes to run through section i . For example, if a train bound for station N departs station i-1 at time t , the train arrives at station i exactly at time t+A_i . Assume that a train bound for station N arrives at a station at time s , and departs the station at time t . Then, the next train bound for station N arrives at the station at time s+K , and departs the station at time t+K . Additionally, the previous train bound for station N arrives at the station at time s-K , and departs the station at time t-K . This must also be true for trains bound for station 0 . 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. Constraints 1 \leq N \leq 100000 1 \leq K \leq 10^9 1 \leq A_i \leq 10^9 A_i is an integer. B_i is either 1 or 2 . Partial Score In the test set worth 500 points, all the sections are single-tracked. That is, B_i = 1 . In the test set worth another 500 points, N \leq 200 . Input The input is given from Standard Input in the following format: N K A_1 B_1 A_2 B_2 : A_N B_N Output Print an integer representing the minimum sum of the amount of time required for a train to depart station 0 and reach station N , and the amount of time required for a train to depart station N and reach station 0 . If it is impossible to create a timetable satisfying the conditions, print -1 instead. Sample Input 1 3 10 4 1 3 1 4 1 Sample Output 1 26 For example, the sum of the amount of time in question will be 26 minutes in the following timetable: In this timetable, the train represented by the red line departs station 0 at time 0 , arrives at station 1 at time 4 , departs station 1 at time 5 , arrives at station 2 at time 8 , and so on. Sample Input 2 1 10 10 1 Sample Output 2 -1 Sample Input 3 6 4 1 1 1 1 1 1 1 1 1 1 1 1 Sample Output 3 12 Sample Input 4 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 Sample Output 4 14829091348
36,442
Problem H: Vending Machine 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. 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. 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. 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. 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. Input The input consists of multiple data sets. Each dataset is described by two lines. The first line contains N ( N ≀ 10) and M ( M ≀ 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. The input is terminated by a dataset of N = M = 0. This dataset must not be processed. Output For each dataset, output in a line the minimum number of operations needed to give back exactly the specified amount of change. Sample Input 6 330 1 5 10 50 100 500 7 127 1 2 4 8 16 32 64 2 10000 1000 2000 0 0 Output for the Sample Input 2 1 4
36,443
フロッピヌキュヌブ フロッピヌキュヌブをプログラミングで解いおみたしょう。フロッピヌキュヌブは図のように衚面に色の぀いた個の立方䜓から構成されおいる立䜓パズルで、キュヌブの列を回転させるこずによっお、぀の各面の色をそろえたす。 フロッピヌキュヌブに察しおは䞋図のような皮類の操䜜を行うこずができ、䞀回の操䜜で、端にある぀の隣接したキュヌブを床回転するこずができたす。わかりやすいように、図では、䞊面に(赀色)、䞋面に(緑色)、右前面に□(黄色)、巊前面に●(青色)、右奥面に○(氎色)、巊奥面に■玫色) の蚘号が付いおいる状態を初期状態ずしおいたす。 フロッピヌキュヌブの初期状態が䞎えられるので、パズルを解くために必芁な最小の操䜜回数を求めるプログラムを䜜成しおください。 入力 入力は以䞋の圢匏で䞎えられる。 N puzzle 1 puzzle 2 : puzzle N 行目の N (1 ≀ N ≀ 30) は操䜜回数を蚈算したいパズルの数である。続くN行に各フロッピヌキュヌブの初期状態 puzzle i が䞎えられる。 puzzle i は以䞋の圢匏で䞎えられる。 p 1 p 2 p 3 p 4 p 5 p 6 p 7 p 8 p 9 p 10 p 11 p 12 p 13 p 14 p 15 p 16 p 17 p 18 p 19 p 20 p 21 p 22 p 23 p 24 p 25 p 26 p 27 p 28 p 29 p 30 各フロッピヌキュヌブの情報は 30 個の敎数 p i (1 ≀ p i ≀ 6) からなる。 p i は、䞋図のようにフロッピヌキュヌブの各面に番号 i を振ったずきの、そのキュヌブの面の色を衚す。 パズルは、倚くずも回の操䜜で解くこずができるず仮定しおよい。 出力 パズルごずに、最小の操䜜回数を行に出力する。 入出力䟋 入力䟋 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 出力䟋 0 1 2 7
36,444
Score : 1100 points Problem Statement We have a tree G with N vertices numbered 1 to N . The i -th edge of G connects Vertex a_i and Vertex b_i . Consider adding zero or more edges in G , and let H be the graph resulted. Find the number of graphs H that satisfy the following conditions, modulo 998244353 . H does not contain self-loops or multiple edges. The diameters of G and H are equal. For every pair of vertices in H that is not directly connected by an edge, the addition of an edge directly connecting them would reduce the diameter of the graph. Constraints 3 \le N \le 2 \times 10^5 1 \le a_i, b_i \le N The given graph is a tree. Input Input is given from Standard Input in the following format: N a_1 b_1 \vdots a_{N-1} b_{N-1} Output Print the answer. Sample Input 1 6 1 6 2 1 5 2 3 4 2 3 Sample Output 1 3 For example, adding the edges (1, 5), (3, 5) in G satisfies the conditions. Sample Input 2 3 1 2 2 3 Sample Output 2 1 The only graph H that satisfies the conditions is G . Sample Input 3 9 1 2 2 3 4 2 1 7 6 1 2 5 5 9 6 8 Sample Output 3 27 Sample Input 4 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 Sample Output 4 78732
36,445
Score : 600 points Problem Statement A tetromino 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: Snuke has many tetrominos. The number of I-, O-, T-, J-, L-, S- and Z-tetrominos in his possession are a_I , a_O , a_T , a_J , a_L , a_S and a_Z , respectively. Snuke will join K of his tetrominos to form a rectangle that is two squares tall and 2K squares wide. Here, the following rules must be followed: When placing each tetromino, rotation is allowed, but reflection is not. Each square in the rectangle must be covered by exactly one tetromino. No part of each tetromino may be outside the rectangle. Snuke wants to form as large a rectangle as possible. Find the maximum possible value of K . Constraints 0≀a_I,a_O,a_T,a_J,a_L,a_S,a_Z≀10^9 a_I+a_O+a_T+a_J+a_L+a_S+a_Z≥1 Input The input is given from Standard Input in the following format: a_I a_O a_T a_J a_L a_S a_Z Output Print the maximum possible value of K . If no rectangle can be formed, print 0 . Sample Input 1 2 1 1 0 0 0 0 Sample Output 1 3 One possible way to form the largest rectangle is shown in the following figure: Sample Input 2 0 0 10 0 0 0 0 Sample Output 2 0 No rectangle can be formed.
36,446
Convex Cut As shown in the figure above, cut a convex polygon g by a line p1p2 and print the area of the cut polygon which is on the left-hand side of the line. g is represented by a sequence of points p 1 , p 2 ,..., p n where line segments connecting p i and p i+1 (1 ≀ i ≀ n−1 ) are sides of the convex polygon. The line segment connecting p n and p 1 is also a side of the polygon. Input The input is given in the following format: g (the sequence of the points of the polygon) q (the number of queries = the number of target lines) 1st query 2nd query : q th query g is given as a sequence of points p 1 ,..., p n in the following format: n x 1 y 1 x 2 y 2 : x n y n The first integer n is the number of points. The coordinate of the i -th point p i is given by two integers x i and y i . 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. For each query, a line represented by two points p1 and p2 is given. The coordinates of the points are given by four integers p1x , p1y , p2x and p2y . Output 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. Constraints 3 ≀ n ≀ 100 1 ≀ q ≀ 100 -10000 ≀ x i , y i ≀ 10000 -10000 ≀ p1x , p1y , p2x , p2y ≀ 10000 No point in g will occur more than once. p1 ≠ p2 Sample Input 4 1 1 4 1 4 3 1 3 2 2 0 2 4 2 4 2 0 Sample Output 2.00000000 4.00000000
36,447
Icy Composer Time Limit: 8 sec / Memory Limit: 64 MB F: 氷の䜜曲家 岡郚錬倪郎(愛称オカレン)は西掋音楜の第䞀人者である 圌は5歳から䜜曲を行うこずができた倩才であり圌が䜜詞・䜜曲した『攻城の槌』はずおも有名である 才胜あふれるオカレンだが残念なこずに圌はレストランで食べた魚にあたっお亡くなっおいる ・・・少なくずもこの䞖界線ではそういうこずになっおいる 䞖界線ずは䜕か 䞀぀の歎史は䞀぀の䞖界線に察応する 我々が歩んできた歎史ずは無限に存圚する䞖界線のうちの䞀぀に過ぎず 別の䞖界線ではたた違った歎史が刻たれおいる オカレンは自らを埅ちうける過酷な未来に立ち向かうために別の䞖界線ぞず旅立぀こずを決意したのだった オカレンが目指す䞖界線はかの有名な䞖界線「ヒャダむンズゲヌト」である 「ヒャダむンズゲヌト」では党おの魚は氷の魔法を甚いお新鮮なたた冷凍保存されるため魚にあたる人はいない 䞖界線はアルファベットの小文字からなる文字列で衚される 「ヒャダむンズゲヌト」を衚す文字列は既に解明されおいるが非垞に長い文字列で衚される これを簡朔に衚蚘するため文字列 seq の N 回の繰り返しを N ( seq ) ず圧瞮しお衚す ここで N は1以䞊の自然数であり seq は小文字からなる文字列か圧瞮しお衚された文字列たたはそれらをいく぀か連結した文字列である 䟋えば以䞋の衚蚘は文字列 bbbababababxbbbababababx を衚す 2(3(b)4(ab)x) オカレンは圌のも぀「魔県リヌディングヒャダむナヌ」によっお圌がいる䞖界線から次に移動できる䞖界線を読みずるこずができる 圌がいる䞖界線は「ヒャダむンズゲヌト」から遠く離れおいるため盎接「ヒャダむンズゲヌト」ぞ移動するこずはできない オカレンは「ヒャダむンズゲヌト」にできるだけ近づくために「ヒャダむンズゲヌト」に察する類䌌床が高い䞖界線ぞず移動するこずにした 「ヒャダむンズゲヌト」を衚す文字列を x ある䞖界線を衚す文字列を y ずした堎合 x に察する y の類䌌床は y の郚分文字列のうち x にも郚分文字列ずしお珟れるものの数である ただし y の郚分文字列ずしお同じ文字列が耇数回珟れたずしおもそれらは別々に数えるものずする 類䌌床が同じ䞖界線が耇数ある堎合は先に入力ずしお䞎えられた䞖界線の方が類䌌床が高いずみなすものずする 諞君には䞖界線「ヒャダむンズゲヌト」を衚す文字列ずオカレンが次に移動できる䞖界線に察応する文字列が耇数䞎えられたずきに「ヒャダむンズゲヌト」に察する類䌌床が最も高い䞖界線を求めおもらいたい 健闘を祈る ゚ル・プサむ・コンガリィ Input 入力は以䞋の圢匏で䞎えられる n m k s t 1 t 2 ... t k 入力圢匏の各倉数の意味は以䞋の通りである n はヒャダむンズゲヌトを衚す文字列 s の長さ (1 <= n <= 250) m はオカレンが移動できる䞖界線を衚す文字列の長さ (1 <= m <= 400) k はオカレンが移動できる䞖界線を衚す文字列の数 (1 <= k <= 5) s はヒャダむンズゲヌトを衚す文字列 t i はオカレンが移動できる䞖界線を衚す文字列 (1 <= i <= k ) Output 文字列 s に最も類䌌する文字列 t i の番号 i ず類䌌床を空癜区切りで䞀行で出力せよ Sample Input 1 5 3 2 aaaaa aaa aab Sample Output 1 1 6 Sample Input 2 10 3 3 2(ab)3(bc) abc bcb cbc Sample Output 2 2 6 Sample Input 3 13 24 1 2(3(b)4(ab)x) bbbababababxbbbababababx Sample Output 3 1 300 Sample Input 4 12 7 5 hyadainsgate hyadain mahyado behoimi megante moshyas Sample Output 4 1 28 Sample Input 5 44 6 5 sh1000(1000(1000(1000(ee))))t100(a)paz100(u) sheeta pazuuu romusk apalou rlaput Sample Output 5 2 21
36,448
Score : 800 points Problem Statement There is a connected undirected graph with N vertices and M edges. The vertices are numbered 1 to N , and the edges are numbered 1 to M . Also, each of these vertices and edges has a specified weight. Vertex i has a weight of X_i ; Edge i has a weight of Y_i and connects Vertex A_i and B_i . We would like to remove zero or more edges so that the following condition is satisfied: For each edge that is not removed, the sum of the weights of the vertices in the connected component containing that edge, is greater than or equal to the weight of that edge. Find the minimum number of edges that need to be removed. Constraints 1 \leq N \leq 10^5 N-1 \leq M \leq 10^5 1 \leq X_i \leq 10^9 1 \leq A_i < B_i \leq N 1 \leq Y_i \leq 10^9 (A_i,B_i) \neq (A_j,B_j) ( i \neq j ) The given graph is connected. All values in input are integers. Input Input is given from Standard Input in the following format: N M X_1 X_2 ... X_N A_1 B_1 Y_1 A_2 B_2 Y_2 : A_M B_M Y_M Output Find the minimum number of edges that need to be removed. Sample Input 1 4 4 2 3 5 7 1 2 7 1 3 9 2 3 12 3 4 18 Sample Output 1 2 Assume that we removed Edge 3 and 4 . In this case, the connected component containing Edge 1 contains Vertex 1, 2 and 3 , and the sum of the weights of these vertices is 2+3+5=10 . The weight of Edge 1 is 7 , so the condition is satisfied for Edge 1 . Similarly, it can be seen that the condition is also satisfied for Edge 2 . Thus, a graph satisfying the condition can be obtained by removing two edges. The condition cannot be satisfied by removing one or less edges, so the answer is 2 . Sample Input 2 6 10 4 4 1 1 1 7 3 5 19 2 5 20 4 5 8 1 6 16 2 3 9 3 6 16 3 4 1 2 6 20 2 4 19 1 2 9 Sample Output 2 4 Sample Input 3 10 9 81 16 73 7 2 61 86 38 90 28 6 8 725 3 10 12 1 4 558 4 9 615 5 6 942 8 9 918 2 7 720 4 7 292 7 10 414 Sample Output 3 8
36,449
Score : 100 points Problem Statement There are N islands floating in Ringo Sea, and M travel agents operate ships between these islands. For convenience, we will call these islands Island 1, 2, 
, N, and call these agents Agent 1, 2, 
, M . The sea currents in Ringo Sea change significantly each day. Depending on the state of the sea on the day, Agent i (1 ≀ i ≀ M) operates ships from Island a_i to b_i , or Island b_i to a_i , but not both at the same time. Assume that the direction of the ships of each agent is independently selected with equal probability. Now, Takahashi is on Island 1 , and Hikuhashi is on Island 2 . Let P be the probability that Takahashi and Hikuhashi can travel to the same island in the day by ships operated by the M agents, ignoring the factors such as the travel time for ships. Then, P × 2^M is an integer. Find P × 2^M modulo 10^9 + 7 . Constraints 2 ≀ N ≀ 15 1 ≀ M ≀ N(N-1)/2 1 ≀ a_i < b_i ≀ N All pairs (a_i, b_i) are distinct. Input Input is given from Standard Input in the following format: N M a_1 b_1 : a_M b_M Output Print the value P × 2^M modulo 10^9 + 7 . Sample Input 1 4 3 1 3 2 3 3 4 Sample Output 1 6 The 2^M = 8 scenarios shown above occur with equal probability, and Takahashi and Hikuhashi can meet on the same island in 6 of them. Thus, P = 6/2^M and P × 2^M = 6 . Sample Input 2 5 5 1 3 2 4 3 4 3 5 4 5 Sample Output 2 18 Sample Input 3 6 6 1 2 2 3 3 4 4 5 5 6 1 6 Sample Output 3 64
36,450
Score : 300 points Problem Statement There are N balls in a two-dimensional plane. The i -th ball is at coordinates (x_i, y_i) . We will collect all of these balls, by choosing two integers p and q such that p \neq 0 or q \neq 0 and then repeating the following operation: Choose a ball remaining in the plane and collect it. Let (a, b) be the coordinates of this ball. If we collected a ball at coordinates (a - p, b - q) in the previous operation, the cost of this operation is 0 . Otherwise, including when this is the first time to do this operation, the cost of this operation is 1 . Find the minimum total cost required to collect all the balls when we optimally choose p and q . Constraints 1 \leq N \leq 50 |x_i|, |y_i| \leq 10^9 If i \neq j , x_i \neq x_j or y_i \neq y_j . All values in input are integers. Input Input is given from Standard Input in the following format: N x_1 y_1 : x_N y_N Output Print the minimum total cost required to collect all the balls. Sample Input 1 2 1 1 2 2 Sample Output 1 1 If we choose p = 1, q = 1 , we can collect all the balls at a cost of 1 by collecting them in the order (1, 1) , (2, 2) . Sample Input 2 3 1 4 4 6 7 8 Sample Output 2 1 If we choose p = -3, q = -2 , we can collect all the balls at a cost of 1 by collecting them in the order (7, 8) , (4, 6) , (1, 4) . Sample Input 3 4 1 1 1 2 2 1 2 2 Sample Output 3 2
36,451
Score : 200 points Problem Statement AtCoDeer the deer has found two positive integers, a and b . Determine whether the concatenation of a and b in this order is a square number. Constraints 1 ≀ a,b ≀ 100 a and b are integers. Input Input is given from Standard Input in the following format: a b Output If the concatenation of a and b in this order is a square number, print Yes ; otherwise, print No . Sample Input 1 1 21 Sample Output 1 Yes As 121 = 11 × 11 , it is a square number. Sample Input 2 100 100 Sample Output 2 No 100100 is not a square number. Sample Input 3 12 10 Sample Output 3 No
36,452
Grated Radish Grated radish (daikon-oroshi) is one of the essential spices in Japanese cuisine. As the name shows, it’s made by grating white radish. You are developing an automated robot for grating radish. You have finally finished developing mechan- ical modules that grates radish according to given instructions from the microcomputer. So you need to develop the software in the microcomputer that controls the mechanical modules. As the first step, you have decided to write a program that simulates the given instructions and predicts the resulting shape of the radish. Input The input consists of a number of test cases. The first line on each case contains two floating numbers R and L (in centimeters), representing the radius and the length of the cylinder-shaped radish, respectively. The white radish is placed in the xyz -coordinate system in such a way that cylinder’s axis of rotational symmetry lies on the z axis. Figure 1: The placement of the white radish The next line contains a single integer N , the number of instructions. The following N lines specify instructions given to the grating robot. Each instruction consists of two floating numbers Ξ and V , where Ξ is the angle of grating plane in degrees, and V (in cubic centimeters) is the volume of the grated part of the radish. You may assume the following conditions: the direction is measured from positive x axis (0 degree) to positive y axis (90 degrees), 1 ≀ R ≀ 5 (in centimeters), 1 ≀ L ≀ 40 (in centimeters), 0 ≀ Ξ < 360, and the sum of V ’s is the smaller than the volume of the given white radish. Figure 2: An example of grating Output For each test case, print out in one line two numbers that indicate the shape of the base side (the side parallel to xy -plane) of the remaining radish after the entire grating procedure is finished, where the first number of the total length is the linear (straight) part and the second is the total length of the curved part. You may output an arbitrary number of digits after the decimal points, provided that difference from the true answer is smaller than 10 -6 centimeters. Sample Input 2 1 2 1 42 3.141592653589793 5 20 3 0 307.09242465218927 180 307.09242465218927 90 728.30573874452591 Output for the Sample Input 2.0 3.141592653589793 8.660254038 5.235987756
36,453
Score : 600 points Problem Statement We have a tree with N vertices and N-1 edges, respectively numbered 1, 2,\cdots, N and 1, 2, \cdots, N-1 . Edge i connects Vertex u_i and v_i . For integers L, R ( 1 \leq L \leq R \leq N ), let us define a function f(L, R) as follows: Let S be the set of the vertices numbered L through R . f(L, R) represents the number of connected components in the subgraph formed only from the vertex set S and the edges whose endpoints both belong to S . Compute \sum_{L=1}^{N} \sum_{R=L}^{N} f(L, R) . Constraints 1 \leq N \leq 2 \times 10^5 1 \leq u_i, v_i \leq N The given graph is a tree. All values in input are integers. Input Input is given from Standard Input in the following format: N u_1 v_1 u_2 v_2 : u_{N-1} v_{N-1} Output Print \sum_{L=1}^{N} \sum_{R=L}^{N} f(L, R) . Sample Input 1 3 1 3 2 3 Sample Output 1 7 We have six possible pairs (L, R) as follows: For L = 1, R = 1 , S = \{1\} and we have 1 connected component. For L = 1, R = 2 , S = \{1, 2\} and we have 2 connected components. For L = 1, R = 3 , S = \{1, 2, 3\} and we have 1 connected component, since S contains both endpoints of each of the edges 1, 2 . For L = 2, R = 2 , S = \{2\} and we have 1 connected component. For L = 2, R = 3 , S = \{2, 3\} and we have 1 connected component, since S contains both endpoints of Edge 2 . For L = 3, R = 3 , S = \{3\} and we have 1 connected component. The sum of these is 7 . Sample Input 2 2 1 2 Sample Output 2 3 Sample Input 3 10 5 3 5 7 8 9 1 9 9 10 8 4 7 4 6 10 7 2 Sample Output 3 113
36,454
A A-Z- 問題 26 マスの円環状のボヌドがあり、各マスには倧文字のアルファベット 1 文字が、アルファベット順に時蚈回りに曞かれおいたす。すなわち、 'A' のマスの時蚈回り隣は 'B' のマスで、 'B' のマスの隣は 'C' のマスで、・・・、 'Z' のマスの時蚈回り隣は 'A' のマスです。 たた、ボヌドには 'A' のマスに駒が 1 ぀眮かれおいたす。 あなたは、文字列 S を受け取り、 S の先頭から 1 文字ず぀芋お駒を操䜜したす。 i 回目の操䜜は以䞋のようになりたす。 その時点で駒のあるマスから S の i 文字目のアルファベットのマスを目指しお、駒を時蚈回りに 1 マスず぀移動させる。このずき少なくずも 1 マスは移動するずする。したがっお、䟋えば 'A' のマスから 'A' のマスに移動する際は、ボヌドを 1 呚しなくおはならない。 䞊蚘の操䜜の結果、駒が 'A' のマスを䜕回螏んだかを答えおください。なお「 'A' のマスを螏む」ずは、 'Z' のマスから 'A' のマスに駒を進めるこずを蚀いたす。 入力圢匏 入力は 1 行で䞎えられる。 S S はあなたが受け取る文字列を衚す。 制玄 1 \leq |S| \leq 100 S は英倧文字のみで構成される。 出力圢匏 'A' のマスを䜕回螏んだかを 1 行で出力せよ。 入力䟋1 AIZU 出力䟋1 2 A -> A (ここで 1 回) A -> I (ここたで 1 回) I -> Z (ここたで 1 回) Z -> U (ここたで 2 回) 入力䟋2 HOKKAIDO 出力䟋2 4
36,455
Score : 1500 points Problem Statement There is an undirected connected graph with N vertices numbered 1 through N . The lengths of all edges in this graph are 1 . It is known that for each i (1≩i≩N) , the distance between vertex 1 and vertex i is A_i , and the distance between vertex 2 and vertex i is B_i . Determine whether there exists such a graph. If it exists, find the minimum possible number of edges in it. Constraints 2≩N≩10^5 0≩A_i,B_i≩N-1 Input The input is given from Standard Input in the following format: N A_1 B_1 A_2 B_2 : A_N B_N Output If there exists a graph satisfying the conditions, print the minimum possible number of edges in such a graph. Otherwise, print -1 . Sample Input 1 4 0 1 1 0 1 1 2 1 Sample Output 1 4 The figure below shows two possible graphs. The graph on the right has fewer edges. Sample Input 2 3 0 1 1 0 2 2 Sample Output 2 -1 Such a graph does not exist.
36,456
Naive String Search Find places where a string P is found within a text T . Print all indices of T where P found. The indices of T start with 0. Input In the first line, a text T is given. In the second line, a string P is given. output Print an index of T where P found in a line. Print the indices in ascending order. Constraints 1 ≀ length of T ≀ 1000 1 ≀ length of P ≀ 1000 The input consists of alphabetical characters and digits Sample Input 1 aabaaa aa Sample Output 1 0 3 4 Sample Input 2 xyzz yz Sample Output 2 1 Sample Input 3 abc xyz Sample Output3 The ouput should be empty.
36,457
Problem A: Goldbach's Conjecture Goldbach's Conjecture: For any even number n greater than or equal to 4, there exists at least one pair of prime numbers p 1 and p 2 such that n = p 1 + p 2 . This conjecture has not been proved nor refused yet. No one is sure whether this conjecture actually holds. However, one can find such a pair of prime numbers, if any, for a given even number. The problem here is to write a program that reports the number of all the pairs of prime numbers satisfying the condition in the conjecture for a given even number. A sequence of even numbers is given as input. Corresponding to each number, the program should output the number of pairs mentioned above. Notice that we are intereseted in the number of essentially different pairs and therefore you should not count ( p 1 , p 2 ) and ( p 2 , p 1 ) separately as two different pairs. Input An integer is given in each input line. You may assume that each integer is even, and is greater than or equal to 4 and less than 2 15 . The end of the input is indicated by a number 0. Output Each output line should contain an integer number. No other characters should appear in the output. Sample Input 6 10 12 0 Output for the Sample Input 1 2 1
36,458
B: むカったヌ / SNS 問題文 AOR むカちゃんは最近少し機嫌が悪い。 どうやら、”むカったヌ”のフォロヌ数ずフォロワヌ数の比が気に入らないようだ 。珟圚、AOR むカちゃんのフォロヌ数は $A$ 人、フォロワヌ数は $B$ 人であり、比は $A:B$ である。 そこで、AOR むカちゃんはフォロヌ数ずフォロワヌ数の比が気に入った敎数比になるように、 フォロヌ数 を増枛させるこずにした。 なお気に入った敎数比ずは、比に含たれるどちらの倀も $1$ 以䞊 $N$ 以䞋の敎数ずなるように衚せる比である。 しかし、AOR むカちゃんはできるだけフォロヌ数を倉曎したくないので、倉曎前ずの差の絶察倀をできるだけ小さくしたい。 AOR むカちゃんの機嫌を良くするために、少なくずもフォロヌ数をいく぀倉曎する必芁があるかを求めるプログラムを䜜成せよ。 入力 $A \ B \ N$ 入力の制玄 $1 \le A, \ B \le 10^{12}$ $1 \leq N \leq 100 $ 出力 気に入った敎数比にできる、$A$ の倉化量の絶察倀の最小倀を出力せよ。 サンプル サンプル入力1 19 30 3 サンプル出力1 1 サンプル入力2 3 7 7 サンプル出力2 0 サンプル入力3 3 7 1 サンプル出力3 4 サンプル入力4 102 30 3 サンプル出力4 12 フォロヌを $12$ 人枛らすこずで $90:30 \ (=3:1)$ になり、比の倧きい方の数字が $3$ 以䞋ずなりたす。 このずき、倉化量は $12$ です。 サンプル入力5 3 4 2 サンプル出力5 1 䞀人フォロヌを倖すず $2:4 \ (=1:2)$ に、フォロヌするず $4:4 \ (=1:1)$ になり、どちらも増枛の絶察倀は $1$ でそれが答えです。 サンプル入力6 1 100 2 サンプル出力6 49 最䜎でも $1$ 人はフォロヌしおいなければいけない事に泚意しおください。
36,459
問題 1: 平均点 (Average Score) 問題 JOI 高校の授業には倪郎君次郎君䞉郎君四郎君花子さんの 5 人の生埒が参加した この授業では期末詊隓を実斜した期末詊隓は5 人党員が受隓した期末詊隓の点数が 40 点以䞊の生埒は期末詊隓の点数がそのたた成瞟になった期末詊隓の点数が 40 点未満の生埒は党員補習を受け成瞟が 40 点になった 5 人の生埒の期末詊隓の点数が䞎えられたずき5 人の成瞟の平均点を蚈算するプログラムを䜜成せよ 入力 入力は 5 行からなり1 行に 1 ぀ず぀敎数が曞かれおいる 1 行目には 倪郎君の期末詊隓の点数が曞かれおいる 2 行目には 次郎君の期末詊隓の点数が曞かれおいる 3 行目には 䞉郎君の期末詊隓の点数が曞かれおいる 4 行目には 四郎君の期末詊隓の点数が曞かれおいる 5 行目には 花子さんの期末詊隓の点数が曞かれおいる 生埒の期末詊隓の点数はすべお 0 点以䞊 100 点以䞋の敎数である 生埒の期末詊隓の点数はすべお 5 の倍数である 5 人の生埒の成瞟の平均点は必ず敎数になる 出力 5 人の生埒の成瞟の平均点をあらわす敎数を 1 行で出力せよ 入出力䟋 入力䟋 1 10 65 100 30 95 出力䟋 1 68 入出力䟋 1 では倪郎君ず四郎君の期末詊隓の点数は 40 点未満なので倪郎君ず四郎君の成瞟は 40 点になる次郎君ず䞉郎君ず花子さんの期末詊隓の点数は 40 点以䞊なので次郎君の成瞟は 65 点䞉郎君の成瞟は 100 点花子さんの成瞟は 95 点ずなる5 人の成瞟の合蚈は 340 なので平均点は 68 点ずなる 入力䟋 2 40 95 0 95 50 出力䟋 2 64 問題文ず自動審刀に䜿われるデヌタは、 情報オリンピック日本委員䌚 が䜜成し公開しおいる問題文ず採点甚テストデヌタです。
36,460
D: Walking 問題 $1$ から $N$ の番号が぀けられおいる $N$ 個の島がある. それぞれの島は $N-1$ 個の橋によっお、どの $2$ ぀の島も䜕本かの橋を枡っお互いに移動するこずができる. それぞれの橋には耐久床があり、入力が䞎えられた時点での $i$ 番目の橋の耐久床は $w_i$ である. それぞれの島にはお宝が $1$ ぀ず぀眮いおおり、島に滞圚しおいるずきにお宝を拟うこずができる. 珟圚島 $S$ にいるyebiくんは、島 $E$ にある博物通に党おのお宝を運びたい. yebiくんは✝魔力✝を持っおいるので、島 $v$ に蚪問するたびに、 $v$ から出る党おの橋の耐久床が $T$ 枛少する. 橋の耐久床が $0$ 以䞋になったずき、橋は厩壊し、それ以降には枡るこずができなくなる. yebiくんは博物通に党おのお宝を届けるこずができるか ただし、yebiくんは力持ちなので同時にいく぀でもお宝を持ち運ぶこずができる. 制玄 入力倀は党お敎数である $2 \leq N \leq 10^5$ $1 \leq S, E \leq N$ $0 \leq T \leq 10^9$ $1 \leq w_i \leq 10^9$ $1 \leq a_i, b_i \leq N$ 入力圢匏 入力は以䞋の圢匏で䞎えられる $N\ T\ S\ E$ $a_1\ b_1\ w_1$ : : $a_{N-1}\ b_{N-1}\ w_{N-1}$ 出力 博物通に党おのお宝を届けるこずができるなら "Yes"、そうでなければ "No" を出力せよ. たた、末尟に改行を出力せよ. サンプル サンプル入力 1 4 10 1 4 1 2 52 1 3 68 3 4 45 サンプル出力 1 Yes サンプル入力 2 4 10 1 4 1 2 15 1 3 60 3 4 10 サンプル出力 2 No サンプル入力 3 3 0 1 3 1 2 5 2 3 5 サンプル出力 3 Yes yebiくんの魔力は貧匱すぎお、橋の耐久床を枛らすこずはできない.
36,461
カヌド 正の敎数が曞かれた䞀組のカヌドがありたす。カヌドを積んで山をいく぀か䜜り、それらを暪䞀列に䞊べたす。その䞭から隣り合った 2 ぀のカヌドの山を遞び、右偎の山の䞊に巊偎の山をそのたた重ねたす。この操䜜をカヌドの山が䞀぀になるたで繰り返しおいきたす。 2 ぀のカヌドの山を重ねる時にそれらの䞀番䞊ず䞋のカヌドに曞かれた数をすべお掛け合わせたす。こうしお埗られた数をカヌドの重ね合わせのコストず呌ぶこずにしたす。カヌドの山を䞀぀にするためのコストはすべおの重ね合わせのコストを足し合わせたものずしたす。 どのような順番でカヌドの山を重ねるかでコストは倉わりたす。たずえば、3 ぀のカヌドの山がある堎合を考えたす。それらの䞀番䞊ず䞋のカヌドに曞かれた数が巊偎の山から順にそれぞれ 3 ず 5, 2 ず 8, 5 ず4 だったずしたす。このずきはじめに巊ず真ん䞭の山を重ねたずきのコストは、3 × 5 × 2 × 8 = 240 です。この重ね合わせによっお、䞀番䞊のカヌドが 3 で䞀番䞋のカヌドが 8 である山ができたす。 この山を右の山の䞊に重ねるず、そのコストは 3 × 8 × 5 × 4 = 480 になりたす。したがっお、この順番でカヌドの山を䞀぀にたずめたずきのコストは 240 + 480 = 720 です。図1 䞀方、はじめに真ん䞭ず右の山を重ねおから最埌に巊の山を重ねるこずにするず、そのずきのコストは 2 × 8 × 5 × 4 + 3 × 5 × 2 × 4 = 440 になりたす。したがっお埌の堎合のように重ねた方がコストが小さくなりたす。図2 カヌドの山の個数ずそれぞれの山の䞀番䞊ず䞋のカヌドに曞かれた数を入力ずし、カヌドの山を䞀぀にたずめるのに必芁な最小のコストを出力するプログラムを䜜成しおください。ただし、山の個数は 100 個以䞋ずし、入力されるデヌタはどのような順番でコストを蚈算しおも 2 31 -1 を超えるこずはありたせん。 Input 入力は以䞋の圢匏で䞎えられたす。 n a 1 b 1 a 2 b 2 : a n b n 1 行目にカヌドの山の個数 n ( n ≀ 100)、続く n 行に巊から i 番目の山の 1 番䞊のカヌドに曞かれた数 a i (1 ≀ a i ≀ 200) ず 1 番䞋のカヌドに曞かれた数 b i (1 ≀ b i ≀ 200) が䞎えられたす。 Output カヌドの山を䞀぀にたずめるのに必芁な最小のコストを行に出力しおください。 Sample Input 3 3 5 2 8 5 4 Output for the Sample Input 440
36,462
Problem B: 平安京りォヌキング 平安京は、道が栌子状になっおいる町ずしお知られおいる。 平安京に䜏んでいるねこのホクサむは、パトロヌルのために毎日自宅から町はずれの秘密の堎所たで行かなければならない。しかし、毎日同じ道を通るのは飜きるし、埌を付けられる危険もあるので、ホクサむはできるだけ毎日異なる経路を䜿いたい。その䞀方で、ホクサむは面倒臭がりなので、目的地から遠ざかるような道は通りたくない。 平安京のあちこちの道にはマタタビが萜ちおいお、ホクサむはマタタビが萜ちおいる道を通るこずができない。そのような道を通るずめろめろになっおしたうからである。幞いなこずに、亀差点にはマタタビは萜ちおいない。 ホクサむは、自宅から秘密の堎所たでの可胜な経路の数を知りたい。ここで、ホクサむの自宅は (0, 0) にあり、秘密の堎所は( g x , g y )にある。道は x = i ( i は敎数), y = j ( j は敎数) に栌子状に敷かれおいる。 Input 入力の1行目には、秘密の堎所の座暙 ( g x , g y ) が䞎えられる。これらはいずれも1以䞊15以䞋の敎数で、空癜1個で区切られお䞎えられる。 2行目にはマタタビが萜ちおいる区間の数 p (0 ≀ p ≀ 100) が䞎えられ、続く p 行にはマタタビが萜ちおいる区間が1行に1区間ず぀䞎えられる。 p 個の区間は互いに異なる。 1区間は x 1 y 1 x 2 y 2 の圢で衚され、( x 1 , y 1 ) ず ( x 2 , y 2 ) を端点ずする、 x 軞たたは y 軞に平行な長さ1の線分である。 x 1 , x 2 は [0, g x ] の範囲にあり、 y 1 , y 2 は [0, g y ] の範囲にある。 Output 可胜な経路の数を出力せよ。可胜な経路が1぀もない堎合は "Miserable Hokusai!" ず1行に出力せよ。 Notes on Submission 䞊蚘圢匏で耇数のデヌタセットが䞎えられたす。入力デヌタの 1 行目にデヌタセットの数が䞎えられたす。各デヌタセットに察する出力を䞊蚘圢匏で順番に出力するプログラムを䜜成しお䞋さい。 Sample Input 4 2 2 0 1 1 2 0 0 0 1 0 0 1 0 4 3 4 1 0 0 0 3 3 4 3 4 1 4 0 0 2 0 3 15 15 0 Output for the Sample Input 6 Miserable Hokusai! 5 155117520
36,463
Score : 300 points Problem Statement There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N . The i -th person from the west is facing east if S_i = E , and west if S_i = W . You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions. Constraints 2 \leq N \leq 3 \times 10^5 |S| = N S_i is E or W . Input Input is given from Standard Input in the following format: N S Output Print the minimum number of people who have to change their directions. Sample Input 1 5 WEEWW Sample Output 1 1 Assume that we appoint the third person from the west as the leader. Then, the first person from the west needs to face east and has to turn around. The other people do not need to change their directions, so the number of people who have to change their directions is 1 in this case. It is not possible to have 0 people who have to change their directions, so the answer is 1 . Sample Input 2 12 WEWEWEEEWWWE Sample Output 2 4 Sample Input 3 8 WWWWWEEE Sample Output 3 3
36,464
Score : 200 points Problem Statement You are given string S and T consisting of lowercase English letters. Determine if S equals T after rotation . That is, determine if S equals T after the following operation is performed some number of times: Operation: Let S = S_1 S_2 ... S_{|S|} . Change S to S_{|S|} S_1 S_2 ... S_{|S|-1} . Here, |X| denotes the length of the string X . Constraints 2 \leq |S| \leq 100 |S| = |T| S and T consist of lowercase English letters. Input Input is given from Standard Input in the following format: S T Output If S equals T after rotation , print Yes ; if it does not, print No . Sample Input 1 kyoto tokyo Sample Output 1 Yes In the first operation, kyoto becomes okyot . In the second operation, okyot becomes tokyo . Sample Input 2 abc arc Sample Output 2 No abc does not equal arc after any number of operations. Sample Input 3 aaaaaaaaaaaaaaab aaaaaaaaaaaaaaab Sample Output 3 Yes
36,465
2014 幎春ある孊生は無事倧孊に合栌し䞀人暮らしを始める事ずなったここで問題ずなるのが倕食をどうするかである圌はこれから N 日間の倕食の蚈画を立おる事にした 圌は N 日間で埗られる幞犏床の合蚈を出来る限り倧きくしたいもちろん矎味しいものや奜きなものを食べるほど幞犏床は高い 圌の倕食の遞択肢は2 ぀近くの食堂に向かうか自炊をするかのどちらかである 食堂で埗られる幞犏床はその日のメニュヌによっお倉わるメニュヌは日替わりだが毎日䞀皮類のみで N 日間のメニュヌは党お既に公開されおいるなので圌は i 日目 (1 ≀ i ≀ N ) に食堂に行けば C i の幞犏床を埗られるずいう情報を党お知っおいる 自炊で埗られる幞犏床はその自炊の開始時点での 自炊パワヌ に定数 P を掛けたものである 自炊パワヌ は初期倀が Q であり毎日食堂に行けば-1自炊をすれば+1その日の食事の終了時に倉動する 圌のために幞犏床の総和の最倧倀を求めよう Input 入力は以䞋の圢匏で N + 1 行で䞎えられる N P Q C 1 C 2 : C N 1 行目は 3 ぀の敎数 N, P, Q が䞎えられそれぞれ日数自炊の幞犏床を算出するための定数自炊パワヌの初期倀である 2 行目から N + 1 行目にはそれぞれ敎数が 1 ぀ず぀䞎えられ i + 1 行目では i 日目に食堂に行った時に埗られる幞犏床が䞎えられる Constraints 1 ≀ N ≀ 500,000 0 ≀ P ≀ 500,000 |Q| ≀ 500,000 |C i | ≀ 500,000 Output 幞犏床の取りうる最倧倀を䞀行に出力せよ Sample Input 1 1 1 1 2 Output for the Sample Input 1 2 考えるべき予定は1 日だけである食堂に行けば2自炊するず1 の幞犏床なので答えは2 ずなる Sample Input 2 3 2 1 3 3 3 Output for the Sample Input 2 12 このケヌスでは毎日自炊をするのが最適で幞犏床は 2 × 1 + 2 × 2 + 2 × 3 = 12 ずなる Sample Input 3 3 1 -1 2 -3 2 Output for the Sample Input 3 2 2 日目のみで自炊をするこずが最善ずなる Sample Input 4 3 1 -10 -10 -10 -10 Output for the Sample Input 4 -27 答えが負になるこずもあるいくらたずくおも倕食は食べなければならない
36,466
Score : 1000 points Problem Statement We will call a string x good if it satisfies the following condition: Condition: x can be represented as a concatenation of two copies of another string y of length at least 1 . For example, aa and bubobubo are good; an empty string, a , abcabcabc and abba are not good. Eagle and Owl created a puzzle on good strings. Find one string s that satisfies the following conditions. It can be proved that such a string always exists under the constraints in this problem. 1 ≀ |s| ≀ 200 Each character of s is one of the 100 characters represented by the integers 1 through 100 . Among the 2^{|s|} subsequences of s , exactly N are good strings. Constraints 1 ≀ N ≀ 10^{12} Input Input is given from Standard Input in the following format: N Output In the first line, print |s| , the length of s . In the second line, print the elements in s in order, with spaces in between. Any string that satisfies the above conditions will be accepted. Sample Input 1 7 Sample Output 1 4 1 1 1 1 There are two good strings that appear as subsequences of s : (1,1) and (1,1,1,1) . There are six occurrences of (1,1) and one occurrence of (1,1,1,1) , for a total of seven. Sample Input 2 299 Sample Output 2 23 32 11 11 73 45 8 11 83 83 8 45 32 32 10 100 73 32 83 45 73 32 11 10
36,467
Problem B: How I Mathematician Wonder What You Are! After counting so many stars in the sky in his childhood, Isaac, now an astronomer and a mathematician, uses a big astronomical telescope and lets his image processing program count stars. The hardest part of the program is to judge if a shining object in the sky is really a star. As a mathematician, the only way he knows is to apply a mathematical definition of stars . The mathematical defiition of a star shape is as follows: A planar shape F is star-shaped if and only if there is a point C ∈ F such that, for any point P ∈ F , the line segment CP is contained in F . Such a point C is called a center of F . To get accustomed to the definition, let's see some examples below. Figure 2: Star shapes (the first row) and non-star shapes (the second row) The firrst two are what you would normally call stars. According to the above definition, however, all shapes in the first row are star-shaped. The two in the second row are not. For each star shape, a center is indicated with a dot. Note that a star shape in general has infinitely many centers. For example, for the third quadrangular shape, all points in it are centers. Your job is to write a program that tells whether a given polygonal shape is star-shaped or not. Input The input is a sequence of datasets followed by a line containing a single zero. Each dataset specifies a polygon, and is formatted as follows. n x 1 y 1 x 2 y 2 ... x n y n The first line is the number of vertices, n , which satisfies 4 ≀ n ≀ 50. Subsequent n lines are the x - and y -coordinates of the n vertices. They are integers and satisfy 0 ≀ x i ≀ 10000 and 0 ≀ y i ≀ 10000 ( i = 1, ..., n ). Line segments ( x i , y i )-( x i +1 , y i +1 ) ( i = 1, ..., n - 1) and the line segment ( x n , y n )-( x 1 , y 1 ) form the border of the polygon in the counterclockwise order. That is, these line segments see the inside of the polygon in the left of their directions. You may assume that the polygon is simple , that is, its border never crosses or touches itself. You may also assume that no three edges of the polygon meet at a single point even when they are infinitely extended. Output For each dataset, output "1" if the polygon is star-shaped and "0" otherwise. Each number must be in a separate line and the line should not contain any other characters. Sample Input 6 66 13 96 61 76 98 13 94 4 0 45 68 8 27 21 55 14 93 12 56 95 15 48 38 46 51 65 64 31 0 Output for the Sample Input 1 0
36,468
Problem H: Finding the Top RPS Player A company “ACM Foods” is preparing for opening its chain shop in a certain area, but another company “ICPC Pizza” is also planning to set up its branch shop in the same area. In general, two competitive shops gain less incomes if they are located so close to each other. Thus, if both “ACM Foods” and “ICPC Pizza” went on opening, they would be damaged financially. So, they had a discussion on this matter and made the following agreement: only one of them can branch its shop in the area. It is determined by Rock-Paper-Scissors (RPS) which to branch the shop. ACM Foods is facing financial difficulties and strongly desires to open their new shop in that area. The executives have decided to make every effort for finding out a very strong RPS player. They believes that players who win consecutive victories must be strong players. In order to find such a player for sure, they have decided their simple strategy. In this strategy, many players play games of RPS repeatedly, but the games are only played between players with the same number of consecutive wins. At the beginning, all the players have no wins, so any pair of players can play a game. The games can be played by an arbitrary number of pairs simultaneously. Let us call a set of simultaneous games as a turn . After the first turn, some players will have one win, and the other players will remain with no wins. In the second turn, some games will be played among players with one win, and some other games among players with no wins. For the former games, the winners will have two consecutive wins, and the losers will lose their first wins and have no consecutive wins. For the latter games, the winners will have one win, and the losers will remain with no wins. Therefore, after the second turn, the players will be divided into three groups: players with two consecutive wins, players with one win, and players with no wins. Again, in the third turn, games will be played among players with two wins, among with one win, and among with no wins. The following turns will be conducted so forth. After a sufficient number of turns, there should be a player with the desired number of consecutive wins. The strategy looks crazy? Oh well, maybe they are confused because of their financial difficulties. Of course, this strategy requires an enormous amount of plays. The executives asked you, as an employee of ACM Foods, to estimate how long the strategy takes. Your task is to write a program to count the minimum number of turns required to find a player with M consecutive wins among N players. Input The input consists of multiple test cases. Each test case consists of two integers N (2 ≀ N ≀ 20) and M (1 ≀ M < N ) in one line. The input is terminated by the line containing two zeroes. Output For each test case, your program must output the case number followed by one integer which indicates the minimum number of turns required to find a person with M consecutive wins. Sample Input 2 1 10 5 15 10 0 0 Output for the Sample Input Case 1: 1 Case 2: 11 Case 3: 210
36,469
Score : 400 points Problem Statement Snuke found N strange creatures. Each creature has a fixed color and size. The color and size of the i -th creature are represented by i and A_i , respectively. Every creature can absorb another creature whose size is at most twice the size of itself. When a creature of size A and color B absorbs another creature of size C and color D ( C \leq 2 \times A ), they will merge into one creature of size A+C and color B . Here, depending on the sizes of two creatures, it is possible that both of them can absorb the other. Snuke has been watching these creatures merge over and over and ultimately become one creature. Find the number of the possible colors of this creature. Constraints 2 \leq N \leq 100000 1 \leq A_i \leq 10^9 A_i is an integer. Input The input is given from Standard Input in the following format: N A_1 A_2 
 A_N Output Print the number of the possible colors of the last remaining creature after the N creatures repeatedly merge and ultimately become one creature. Sample Input 1 3 3 1 4 Sample Output 1 2 The possible colors of the last remaining creature are colors 1 and 3 . For example, when the creature of color 3 absorbs the creature of color 2 , then the creature of color 1 absorbs the creature of color 3 , the color of the last remaining creature will be color 1 . Sample Input 2 5 1 1 1 1 1 Sample Output 2 5 There may be multiple creatures of the same size. Sample Input 3 6 40 1 30 2 7 20 Sample Output 3 4
36,470
Score : 100 points Problem Statement Iroha loves Haiku . Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5 , 7 and 5 syllables, in this order. To create a Haiku, Iroha has come up with three different phrases. These phrases have A , B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order. Constraints 1≩A,B,C≩10 Input The input is given from Standard Input in the following format: A B C Output If it is possible to construct a Haiku by using each of the phrases once, print YES (case-sensitive). Otherwise, print NO . Sample Input 1 5 5 7 Sample Output 1 YES Using three phrases of length 5 , 5 and 7 , it is possible to construct a Haiku. Sample Input 2 7 7 5 Sample Output 2 NO
36,471
Score : 1000 points Problem Statement Given are N points on the circumference of a circle centered at (0,0) in an xy -plane. The coordinates of the i -th point are (\cos(\frac{2\pi T_i}{L}),\sin(\frac{2\pi T_i}{L})) . Three distinct points will be chosen uniformly at random from these N points. Find the expected x - and y -coordinates of the center of the circle inscribed in the triangle formed by the chosen points. Constraints 3 \leq N \leq 3000 N \leq L \leq 10^9 0 \leq T_i \leq L-1 T_i<T_{i+1} All values in input are integers. Input Input is given from Standard Input in the following format: N L T_1 : T_N Output Print the expected x - and y -coordinates of the center of the circle inscribed in the triangle formed by the chosen points. Your output will be considered correct when the absolute or relative error is at most 10^{-9} . Sample Input 1 3 4 0 1 3 Sample Output 1 0.414213562373095 -0.000000000000000 The three points have the coordinates (1,0) , (0,1) , and (0,-1) . The center of the circle inscribed in the triangle formed by these points is (\sqrt{2}-1,0) . Sample Input 2 4 8 1 3 5 6 Sample Output 2 -0.229401949926902 -0.153281482438188 Sample Input 3 10 100 2 11 35 42 54 69 89 91 93 99 Sample Output 3 0.352886583546338 -0.109065017701873
36,472
K-th String Problem Statement 長さ N の文字列 S に察する接尟蟞配列 SA を以䞋の手順で埗られる N 以䞋の正敎数の順列ずしお定矩する S の i 文字目から j 文字目たでの郚分文字列を S[i..j] ず衚すただし添字は1-indexedである 各接尟蟞 S[i..N] (i=1,2,...,N) を蟞曞匏順序昇順で敎列する 敎列した各接尟蟞の開始䜍眮 i を順に䞊べる たずえば S ="mississippi"の接尟蟞配列 SA は以䞋のようになる 入力ずしお長さ N の文字列に察する接尟蟞配列 SA が䞎えられる SA が埗られるような文字列のうち蟞曞匏順序で K 番目(1-indexed)のものを求めよ ただし元の文字列はアルファベット順に'a'から数えお高々 A 個の文字のみからなる Input 入力は以䞋の圢匏に埓う䞎えられる数は党お敎数である N A K SA_1 SA_2 ... SA_N Constraints 1≩N≩10^5 1≩A≩26 1≩K≩10^{18} 1≩SA_i≩N i \neq j ならば SA_i \neq SA_j Output SA が埗られるような蟞曞匏順序で K 番目の文字列を1行に出力せよ K 番目の文字列が存圚しない堎合"Impossible"ず出力せよ Sample Input 1 3 4 2 2 1 3 Output for the Sample Input 1 bad A =4の堎合 SA ={2,1,3}ずなる文字列は"bac","bad","cad","cbd"の4通り したがっお蟞曞匏順序で2番目の"bad"が答えずなる Sample Input 2 18 26 10275802967 10 14 9 13 7 8 2 6 11 18 12 1 4 3 16 5 17 15 Output for the Sample Input 2 ritsumeicampdaytwo
36,473
Problem J: Round Trip Jim is planning to visit one of his best friends in a town in the mountain area. First, he leaves his hometown and goes to the destination town. This is called the go phase. Then, he comes back to his hometown. This is called the return phase. You are expected to write a program to find the minimum total cost of this trip, which is the sum of the costs of the go phase and the return phase. There is a network of towns including these two towns. Every road in this network is one-way, i.e., can only be used towards the specified direction. Each road requires a certain cost to travel. In addition to the cost of roads, it is necessary to pay a specified fee to go through each town on the way. However, since this is the visa fee for the town, it is not necessary to pay the fee on the second or later visit to the same town. The altitude (height) of each town is given. On the go phase, the use of descending roads is inhibited. That is, when going from town a to b , the altitude of a should not be greater than that of b . On the return phase, the use of ascending roads is inhibited in a similar manner. If the altitudes of a and b are equal, the road from a to b can be used on both phases. Input The input consists of multiple datasets, each in the following format. n m d 2 e 2 d 3 e 3 . . . d n-1 e n-1 a 1 b 1 c 1 a 2 b 2 c 2 . . . a m b m c m Every input item in a dataset is a non-negative integer. Input items in a line are separated by a space. n is the number of towns in the network. m is the number of (one-way) roads. You can assume the inequalities 2 ≀ n ≀ 50 and 0 ≀ m ≀ n ( n −1) hold. Towns are numbered from 1 to n , inclusive. The town 1 is Jim's hometown, and the town n is the destination town. d i is the visa fee of the town i , and e i is its altitude. You can assume 1 ≀ d i ≀ 1000 and 1≀ e i ≀ 999 for 2≀ i ≀ n −1. The towns 1 and n do not impose visa fee. The altitude of the town 1 is 0, and that of the town n is 1000. Multiple towns may have the same altitude, but you can assume that there are no more than 10 towns with the same altitude. The j -th road is from the town a j to b j with the cost c j (1 ≀ j ≀ m ). You can assume 1 ≀ a j ≀ n , 1 ≀ b j ≀ n , and 1 ≀ c j ≀ 1000. You can directly go from a j to b j , but not from b j to a j unless a road from b j to a j is separately given. There are no two roads connecting the same pair of towns towards the same direction, that is, for any i and j such that i ≠ j , a i ≠ a j or b i ≠ b j . There are no roads connecting a town to itself, that is, for any j , a j ≠ b j . The last dataset is followed by a line containing two zeros (separated by a space). Output For each dataset in the input, a line containing the minimum total cost, including the visa fees, of the trip should be output. If such a trip is not possible, output “-1”. Sample Input 3 6 3 1 1 2 1 2 3 1 3 2 1 2 1 1 1 3 4 3 1 4 3 6 5 1 1 2 1 2 3 1 3 2 1 2 1 1 1 3 4 3 1 4 4 5 3 1 3 1 1 2 5 2 3 5 3 4 5 4 2 5 3 1 5 2 1 2 1 1 0 0 Output for the Sample Input 7 8 36 -1
36,474
碁石ならべ 問題 癜ず黒の碁石をテヌブルの䞊にならべお遊ぶ.たずテヌブルの巊端に碁石を眮く.次に巊から 2 番目の堎所に碁石を眮く.これを n 回繰り返しお n 個の碁石を暪䞀列にならべる.ただし,新しく i 番目の碁石を眮く際には,次のルヌルに埓っおテヌブル䞊の碁石を眮き換える. i が奇数の堎合: テヌブルに眮いおあった碁石は眮き換えず,新しい碁石を巊 から i 番目に眮く. i が偶数の堎合: 新しく巊から i 番目に眮く碁石の色ずテヌブル䞊の右端の碁 石の色が同じ堎合は,テヌブル䞊の碁石は眮き換えず,新しい碁石を巊から i 番目に眮く.そうでない堎合,すなわち,新しく巊から i 番目に眮く碁石の色 ずテヌブル䞊の右端の碁石の色が異なる堎合は,たずテヌブル䞊の右端の連続 した同色の碁石を党お取り陀き,i 番目の碁石ず同色の碁石に眮き換える.そ しおテヌブルの右端に i 番目の碁石を眮く. 䟋えば,最初の 7 個の碁石を眮いた時点で, ○○●●○○○ ずなっおいたずする. (○は癜の碁石を,●は黒の碁石を衚す. ) 8 番目の碁石が癜(○)の堎合は,右端の碁石ず同色なので,そのたた眮く.し たがっお,テヌブル䞊の碁石は ○○●●○○○○ ずなる. 8 番目の碁石が黒(●)の堎合は,右端の碁石(○)ず色が異なるので,たず テヌブルの右端にある 3 個の連続した癜い碁石(○)を取り陀き,黒い碁石 (●)に眮き換える.そしお右端に 8 番目の碁石を眮く.したがっお,テヌブ ル䞊の碁石は ○○●●●●●● ずなる. 入力ずしお眮く碁石の順番が䞎えられたずき,n 個の碁石をならべ終わった埌,テヌ ブル䞊に眮いおある癜い碁石の個数を求めるプログラムを䜜成せよ. 入力 入力は耇数のデヌタセットからなる各デヌタセットは以䞋の圢匏で䞎えられる 1 行目には正敎数 n (1 ≀ n ≀ 100000) が曞かれおいる.2 行目以降の第 i + 1 行目 (1 ≀ i ≀ n) には,i 番目に眮く碁石の色を衚す敎数 c i が曞かれおおり,c i が 0 なら i 番目に眮く碁石の色が癜であるこずを,1 なら i 番目に眮く碁石の色が黒であるこずを衚す. 採点甚デヌタのうち, 配点の 50% 分に぀いおは, n ≀ 10000 を満たす. n が 0 のずき入力の終了を瀺す. デヌタセットの数は 10 を超えない 出力 デヌタセットごずに, n 個の碁石をならべ終わった埌にテヌブル䞊に眮いおある癜い碁石の個数を 1 行に出力する. 入出力䟋 入力䟋 8 1 0 1 1 0 0 0 0 8 1 0 1 1 0 0 0 1 0 出力䟋 6 2 䞊蚘問題文ず自動審刀に䜿われるデヌタは、 情報オリンピック日本委員䌚 が䜜成し公開しおいる問題文ず採点甚テストデヌタです。
36,475
双子 (Twins) square1001君ずE869120君は双子です。 このうち先に生たれた方を出力しお䞋さい。 入力 入力は䞎えられない。 出力 正解の文字列を䞀行に出力せよ。 ただし、最埌には改行を入れるこず。 出力䟋1 square1001
36,476
QQ Write a program which prints multiplication tables in the following format: 1x1=1 1x2=2 . . 9x8=72 9x9=81 Input No input. Output 1x1=1 1x2=2 . . 9x8=72 9x9=81 Template for C #include<stdio.h> int main(){ return 0; } Template for C++ #include<iostream> using namespace std; int main(){ return 0; } Template for Java class Main{ public static void main(String[] a){ } }
36,477
Score : 100 points Problem Statement ButCoder Inc. runs a programming competition site called ButCoder . In this site, a user is given an integer value called rating that represents his/her skill, which changes each time he/she participates in a contest. The initial value of a new user's rating is 0 , and a user whose rating reaches K or higher is called Kaiden ("total transmission"). Note that a user's rating may become negative. Hikuhashi is a new user in ButCoder. It is estimated that, his rating increases by A in each of his odd-numbered contests (first, third, fifth, ...), and decreases by B in each of his even-numbered contests (second, fourth, sixth, ...). According to this estimate, after how many contests will he become Kaiden for the first time, or will he never become Kaiden? Constraints 1 ≀ K, A, B ≀ 10^{18} All input values are integers. Input Input is given from Standard Input in the following format: K A B Output If it is estimated that Hikuhashi will never become Kaiden, print -1 . Otherwise, print the estimated number of contests before he become Kaiden for the first time. Sample Input 1 4000 2000 500 Sample Output 1 5 Each time Hikuhashi participates in a contest, his rating is estimated to change as 0 → 2000 → 1500 → 3500 → 3000 → 5000 → 
 After his fifth contest, his rating will reach 4000 or higher for the first time. Sample Input 2 4000 500 2000 Sample Output 2 -1 Each time Hikuhashi participates in a contest, his rating is estimated to change as 0 → 500 → -1500 → -1000 → -3000 → -2500 → 
 He will never become Kaiden. Sample Input 3 1000000000000000000 2 1 Sample Output 3 1999999999999999997 The input and output values may not fit into 32 -bit integers.
36,478
かけざん 倪郎君はかけざんを習いたおの小孊生です。なんずなく、圌はかけざんを気に入っおいるので、数字を芋かけるずかけざんをしたくなりたす。そんな圌はここのずころ、次のような凊理を0以䞊の敎数に斜すこずが奜きなようです。 (凊理の流れ) 手順1. ある0以䞊の敎数nが10進数衚瀺で䞀けたならばそこで凊理を終了する。そうでなければ手順2に進む 手順2. 10以䞊の敎数nを10進数衚瀺をするずどこかの桁の間に切れ目を入れお二぀の数字に分解するこずが可胜である(䟋えば2012-> 20,12)。このような切り方ずしおありうるものに察しお,埗られた二぀の数字を掛け合わせお最も倧きいものを次のnずしお手順1に戻る。(詳しくは䞋蚘の"手順2に関する補足を参照") 倪郎君はこの凊理を気に入っおいるようですが、䜕回手順2の操䜜を繰り返せばよいのか倧きい数字だず予想ができず、もしかしたら無限回行われなければならないかもしれないず思っおいたす。そこで、倪郎君の兄であり倧孊生であるあなたに0以䞊の敎数nに察しおこの手順2を䜕回しなければならないかを聞いおきたした。 あなたの仕事は、Q個の0以䞊の敎数 N 1 .. N Q が䞎えられるので、それぞれの敎数で凊理の終了たでに䜕回の手順2が斜されるかを求めるこずです。その際にもし無限回の手順が必芁ならば、-1を出力しおください。 手順2に関する補足 切り分けた結果、桁の初めに0が぀くものも考慮に入れる必芁がありたす。 䟋えばn=1024のずき、1*024 , 10*24 , 102*4をそれぞれ蚈算するずそれぞれ24,240,408ずなるため、408が遞ばれ、これが次のnずなりたす。 Input Q N 1 N 2 ... N Q Q は䞎えられる0以䞊の敎数の個数を衚す N i は倪郎君が気になっおいる0以䞊の敎数で,i番目のものを衚す Constraints 1≀Q≀100 0≀N i ≀10 6 Output Q 個の敎数を改行区切りで出力せよ R 1 R 2 .. R Q R i は、 N i に察しお凊理を終了するたでに手順2を実行する回数を衚す N i に察しお手順2を無限回だけ実行する必芁がある堎合は R i は -1ずなる Sample Input 1 3 9 99 123 Output for the Sample Input 1 0 2 3 9は1桁の数なので、手順2が実行されるこずはありたせん。 99は2桁であり、手順2を斜せば9,9ずしか分割できずその次の数は81ずなる。 81も2桁の数であり、手順2を斜せば8,1ずしか分割できずその次の数は8ずなる。 1桁の数になったので凊理が終了し、答えは2。 123は3桁の数なので、手順2を斜したす。 この堎合は12,3ず1,23の二぀の分け方があり、それぞれでかけざんをするず36,23ずなるので、 36が次の数ずしお遞ばれたす。 Sample Input 2 2 999999 1000000 Output for the Sample Input 2 12 1
36,479
Score : 100 points Problem Statement It has been decided that a programming contest sponsored by company A will be held, so we will post the notice on a bulletin board. The bulletin board is in the form of a grid with N rows and N columns, and the notice will occupy a rectangular region with H rows and W columns. How many ways are there to choose where to put the notice so that it completely covers exactly HW squares? Constraints 1 \leq H, W \leq N \leq 100 All values in input are integers. Input Input is given from Standard Input in the following format: N H W Output Print the answer. Sample Input 1 3 2 3 Sample Output 1 2 There are two ways to put the notice, as follows: ### ... ### ### ... ### Here, # represents a square covered by the notice, and . represents a square not covered. Sample Input 2 100 1 1 Sample Output 2 10000 Sample Input 3 5 4 2 Sample Output 3 8
36,480
Problem F: Lying about Your Age You have moved to a new town. As starting a new life, you have made up your mind to do one thing: lying about your age. Since no person in this town knows your history, you don’t have to worry about immediate exposure. Also, in order to ease your conscience somewhat, you have decided to claim ages that represent your real ages when interpreted as the base- M numbers (2 ≀ M ≀ 16). People will misunderstand your age as they interpret the claimed age as a decimal number (i.e. of the base 10). Needless to say, you don’t want to have your real age revealed to the people in the future. So you should claim only one age each year, it should contain digits of decimal numbers (i.e. ‘0’ through ‘9’), and it should always be equal to or greater than that of the previous year (when interpreted as decimal). How old can you claim you are, after some years? Input The input consists of multiple datasets. Each dataset is a single line that contains three integers A , B , and C , where A is the present real age (in decimal), B is the age you presently claim (which can be a non-decimal number), and C is the real age at which you are to find the age you will claim (in decimal). It is guaranteed that 0 ≀ A < C ≀ 200, while B may contain up to eight digits. No digits other than ‘0’ through ‘9’ appear in those numbers. The end of input is indicated by A = B = C = -1, which should not be processed. Output For each dataset, print in a line the minimum age you can claim when you become C years old. In case the age you presently claim cannot be interpreted as your real age with the base from 2 through 16, print -1 instead. Sample Input 23 18 53 46 30 47 -1 -1 -1 Output for the Sample Input 49 -1
36,481
Problem G: CarrotBreeding にんじんは繁殖の奜きな怍物である. うさぎが畑でにんじんを飌うこずにした. 畑は (0, 0) ず (1000000000, 1000000000) を察角線ずする正方圢 (boundary を含む) である. うさぎは, 2 個以䞊のにんじんを通るすべおの盎線に沿っお毎日1 回ず぀氎をたくこずにした. このにんじんたちは, 毎日 $N$ 回ず぀氎をたかれるのが繁殖に最適だず考えおいるので, そのような条件を満たすようにうさぎの畑に䞊ぶこずにした. にんじんは畑内郚の栌子点にしか䞊ぶこずができない. たた, そのような条件を満たす䞊び方が耇数ある堎合は, 最もにんじんの個数が少ないものを遞ぶこずにした. 条件を満たすにんじんの配眮を1 ぀出力せよ. そのような配眮が存圚しない堎合には -1 ず出力せよ. Constraints $N$ will be between 1 and 1,000,000, inclusive. Input 入力は以䞋の圢匏で䞎えられる: $N$ Output 条件を満たす配眮が存圚しない堎合, -1 ず䞀行に出力せよ. 存圚する堎合, にんじんの本数を $K$ ずするず, 以䞋の圢匏で出力せよ: $K$ $x_1$ $y_1$ ... $x_K$ $y_K$ Sample Input 1 4 Sample Output 1 4 0 0 1 0 2 0 1 1 Sample Input 2 6 Sample Output 2 4 0 0 0 1 1 0 1 1
36,482
あみだくじ PCK 君はみんなでゲヌム倧䌚をしおいたす。このゲヌム倧䌚では、倧䌚の最埌にあみだくじで順䜍を入れ替えたす。倧䌚には N 人のプレむダヌが参加しおおり、あみだくじには N 本の瞊棒がありたす。 あみだくじは、図のように N - 1 段の郚品からできおおり、それぞれ 1 から N -1 の番号が割り圓おられおいたす。各郚品は、あみだくじの䞀郚を暪方向に切り取った郚分です。各郚品にはいく぀かの暪棒が匕かれおいたすが、郚品の䞭の暪棒はすべお同じ高さにありたす。暪棒同士が぀ながるこずはありたせん。 倧䌚の最埌に、順䜍の高い人から右から巊の順に瞊棒が割り圓おられたす。PCK 君は珟時点で最䞋䜍なので、巊端からスタヌトです。䟋えば、䞊図の組み立お方では、䜍だったPCK 君は、このあみだくじによっお䜍右から番目の棒に浮䞊するこずができたす。 このゲヌムでは、最䞋䜍の人にあみだくじを組み立おる暩利が䞎えられたす。PCK 君はうたくあみだくじの郚品の順番を決めお、逆転優勝を狙っおいたす。ただし、郚品を回転するこずはできたせん。 ※補足あみだくじのたどり方に぀いお あみだくじのある瞊棒の䞊端から出発しお䞊から䞋ぞ進む。ただし、暪棒がある地点ではその暪棒で぀ながった別の瞊棒に移動する。これを、瞊棒の䞋端にたどり着くたで繰り返す。 ゲヌムの参加人数ずあみだくじの郚品の情報を入力し、PCK 君が優勝できるかどうか刀定するプログラムを䜜成せよ。優勝できる堎合、そのあみだくじの郚品の䞊びを぀出力せよ。ただし、そのような䞊べ方が耇数ある堎合は、䞎えられた郚品の番号で蟞曞順最小のものを出力せよ。 Input 入力は以䞋の圢匏で䞎えられる。 N b 1,1 b 1,2 ... b 1,N−1 b 2,1 b 2,2 ... b 2,N−1 : b N−1,1 b N−1,2 ... b N−1,N−1 行目に倧䌚の参加者数 N (2 ≀ N ≀ 500) が䞎えられる。続く N -1 行に i 番目の郚品の暪棒の情報が䞎えられる。 b i,j が 1 であるずき、 i 番目の郚品の、巊から j 本目の瞊棒から j +1 番目の瞊棒ぞ暪棒が匕かれおいるこずを衚す。 b i,j が 0 であるずき、 i 番目の郚品の、巊から j 本目の瞊棒から j +1 番目の瞊棒ぞ暪棒は匕かれおいないこずを衚す。 b i,j が 1 であるずき、 b i,j+1 が 1 ずなるような郚品は䞎えられない。たた、暪棒の総数は 10000 を越えない。 Output PCK 君が優勝できる堎合行目に「yes」ず出力する。続く N -1 行に、あみだくじの䞊から順に、郚品の番号の䞊びを出力する。そのような䞊びが耇数ある堎合、蟞曞順最小である䞊びを出力する。PCK 君が優勝できない堎合、行に「no」ず出力する。 Sample Input 1 6 1 0 0 0 1 1 0 1 0 1 0 1 0 1 0 0 0 0 1 0 0 1 0 0 1 Sample Output 1 yes 1 3 2 4 5 Sample Input 2 5 0 1 0 1 0 1 0 1 1 0 1 0 1 0 0 1 Sample Output 2 yes 4 1 3 2 4 1 3 2 ず 4 2 3 1 の通りの組み立お方が可胜だが、蟞曞順で小さい方の 4 1 3 2 を出力する。 Sample Input 3 5 1 0 0 1 0 1 0 1 1 0 0 0 0 1 0 1 Sample Output 3 no
36,483
Coin Changing Problem Find the minimum number of coins to make change for n cents using coins of denominations d 1 , d 2 ,.., d m . The coins can be used any number of times. Input n m d 1 d 2 ... d m Two integers n and m are given in the first line. The available denominations are given in the second line. Output Print the minimum number of coins in a line. Constraints 1 ≀ n ≀ 50000 1 ≀ m ≀ 20 1 ≀ denomination ≀ 10000 The denominations are all different and contain 1. Sample Input 1 55 4 1 5 10 50 Sample Output 1 2 Sample Input 2 15 6 1 2 7 8 12 50 Sample Output 2 2 Sample Input 3 65 6 1 2 7 8 12 50 Sample Output 3 3
36,484
Score : 300 points Problem Statement You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: Append one of the following at the end of T : dream , dreamer , erase and eraser . Constraints 1≩|S|≩10^5 S consists of lowercase English letters. Input The input is given from Standard Input in the following format: S Output If it is possible to obtain S = T , print YES . Otherwise, print NO . Sample Input 1 erasedream Sample Output 1 YES Append erase and dream at the end of T in this order, to obtain S = T . Sample Input 2 dreameraser Sample Output 2 YES Append dream and eraser at the end of T in this order, to obtain S = T . Sample Input 3 dreamerer Sample Output 3 NO
36,485
Don't Cross the Circles! There are one or more circles on a plane. Any two circles have different center positions and/or different radiuses. A circle may intersect with another circle, but no three or more circles have areas nor points shared by all of them. A circle may completely contain another circle or two circles may intersect at two separate points, but you can assume that the circumferences of two circles never touch at a single point. Your task is to judge whether there exists a path that connects the given two points, P and Q , without crossing the circumferences of the circles. You are given one or more point pairs for each layout of circles. In the case of Figure G-1, we can connect P and Q 1 without crossing the circumferences of the circles, but we cannot connect P with Q 2 , Q 3 , or Q 4 without crossing the circumferences of the circles. Figure G-1: Sample layout of circles and points Input The input consists of multiple datasets, each in the following format. n m Cx 1 Cy 1 r 1 ... Cx n Cy n r n Px 1 Py 1 Qx 1 Qy 1 ... Px m Py m Qx m Qy m The first line of a dataset contains two integers n and m separated by a space. n represents the number of circles, and you can assume 1 ≀ n ≀ 100. m represents the number of point pairs, and you can assume 1 ≀ m ≀ 10. Each of the following n lines contains three integers separated by a single space. ( Cx i , Cy i ) and r i represent the center position and the radius of the i -th circle, respectively. Each of the following m lines contains four integers separated by a single space. These four integers represent coordinates of two separate points P j = ( Px j , Py j ) and Q j =( Qx j , Qy j ). These two points P j and Q j form the j -th point pair. You can assume 0 ≀ Cx i ≀ 10000, 0 ≀ Cy i ≀ 10000, 1 ≀ r i ≀ 1000, 0 ≀ Px j ≀ 10000, 0 ≀ Py j ≀ 10000, 0 ≀ Qx j ≀ 10000, 0 ≀ Qy j ≀ 10000. In addition, you can assume P j or Q j are not located on the circumference of any circle. The end of the input is indicated by a line containing two zeros separated by a space. Figure G-1 shows the layout of the circles and the points in the first dataset of the sample input below. Figure G-2 shows the layouts of the subsequent datasets in the sample input. Figure G-2: Sample layout of circles and points Output For each dataset, output a single line containing the m results separated by a space. The j -th result should be "YES" if there exists a path connecting P j and Q j , and "NO" otherwise. Sample Input 5 3 0 0 1000 1399 1331 931 0 1331 500 1398 0 400 2000 360 340 450 950 1600 380 450 950 1399 1331 450 950 450 2000 1 2 50 50 50 0 10 100 90 0 10 50 50 2 2 50 50 50 100 50 50 40 50 110 50 40 50 0 0 4 1 25 100 26 75 100 26 50 40 40 50 160 40 50 81 50 119 6 1 100 50 40 0 50 40 50 0 48 50 50 3 55 55 4 55 105 48 50 55 55 50 20 6 270 180 50 360 170 50 0 0 50 10 0 10 0 90 50 0 180 50 90 180 50 180 180 50 205 90 50 180 0 50 65 0 20 75 30 16 90 78 36 105 30 16 115 0 20 128 48 15 128 100 15 280 0 30 330 0 30 305 65 42 0 20 10 20 0 20 10 0 50 30 133 0 50 30 133 30 90 40 305 20 90 40 240 30 16 2 0 0 50 0 90 50 0 180 50 90 180 50 180 180 50 205 90 50 180 0 50 65 0 20 115 0 20 90 0 15 280 0 30 330 0 30 305 65 42 75 40 16 90 88 36 105 40 16 128 35 250 30 90 50 305 20 0 0 Output for the Sample Input YES NO NO YES NO NO NO NO YES YES NO NO YES NO NO NO NO
36,486
Score : 400 points Problem Statement In this problem, we only consider strings consisting of lowercase English letters. Strings s and t are said to be isomorphic when the following conditions are satisfied: |s| = |t| holds. For every pair i, j , one of the following holds: s_i = s_j and t_i = t_j . s_i \neq s_j and t_i \neq t_j . For example, abcac and zyxzx are isomorphic, while abcac and ppppp are not. A string s is said to be in normal form when the following condition is satisfied: For every string t that is isomorphic to s , s \leq t holds. Here \leq denotes lexicographic comparison. For example, abcac is in normal form, but zyxzx is not since it is isomorphic to abcac , which is lexicographically smaller than zyxzx . You are given an integer N . Print all strings of length N that are in normal form, in lexicographically ascending order. Constraints 1 \leq N \leq 10 All values in input are integers. Input Input is given from Standard Input in the following format: N Output Assume that there are K strings of length N that are in normal form: w_1, \ldots, w_K in lexicographical order. Output should be in the following format: w_1 : w_K Sample Input 1 1 Sample Output 1 a Sample Input 2 2 Sample Output 2 aa ab
36,487
巚暹の刻み手 あなたは N 皮類の道具を䜿っお、目の前の巚暹を切り倒そうずしおいたす。はじめは、暹の耐久力は D 、あなたの経隓倀は 0 ですが、道具 i で回暹を叩くず暹の耐久力は a i 枛り、あなたは e i の経隓倀を埗たす。ただし、道具 i を䜿うためには、あなたは r i 以䞊の経隓倀を持っおいなければなりたせん。暹の耐久力が 0 以䞋になるず暹は倒れたす。 暹の耐久力ず道具に぀いおの情報が䞎えられたずき、暹を切り倒すには最䜎䜕回暹を叩かなければいけないかを求めるプログラムを䜜成しおください。 入力 入力は耇数のデヌタセットからなる。入力の終わりはれロ぀の行で瀺される。各デヌタセットは以䞋の圢匏で䞎えられる。 D N a 1 e 1 r 1 a 2 e 2 r 2 : a N e N r N 1 行目に暹の耐久力を衚す敎数 D (1 ≀ D ≀ 100) ず道具の皮類の数 N (1 ≀ N ≀ 100) が䞎えられる。続く N 行に道具 1 から N たでの情報が䞎えられる。 a i (0 ≀ a i ≀ 100) ず e i (0 ≀ e i ≀ 100) は、道具iを回䜿うこずで枛る暹の耐久力ずあなたが埗るこずのできる経隓倀をそれぞれ衚す。 r i (0 ≀ r i ≀ 100) は道具を䜿うために必芁な経隓倀を衚す。 a i , e i , r i はすべお敎数である。 デヌタセットの数は 50 を超えない。 出力 暹を切り倒すのに必芁な、暹を叩く最小の回数を行に出力する。ただし、暹を切り倒すこずが䞍可胜な堎合は NA ず出力する。 入出力䟋 入力䟋 15 4 1 1 0 1 2 2 5 10 5 8 1 15 60 4 5 2 0 8 8 2 3 5 0 49 0 18 100 1 1 1 1 0 0 出力䟋 6 4 NA
36,488
Similarity of Subtrees Define the depth of a node in a rooted tree by applying the following rules recursively: The depth of a root node is 0. The depths of child nodes whose parents are with depth $d$ are $d + 1$. Let $S(T, d)$ be the number of nodes of $T$ with depth $d$. Two rooted trees $T$ and $T'$ are similar if and only if $S(T, d)$ equals $S(T', d)$ for all non-negative integer $d$. You are given a rooted tree $T$ with $N$ nodes. The nodes of $T$ are numbered from 1 to $N$. Node 1 is the root node of $T$. Let $T_i$ be the rooted subtree of $T$ whose root is node $i$. Your task is to write a program which calculates the number of pairs $(i, j)$ such that $T_i$ and $T_j$ are similar and $i < j$. Input The input consists of a single test case. $N$ $a_1$ $b_1$ $a_2$ $b_2$ ... $a_{N-1}$ $b_{N-1}$ The first line contains an integer $N$ ($1 \leq N \leq 100,000$), which is the number of nodes in a tree. The following $N -1$ lines give information of branches: the $i$-th line of them contains $a_i$ and $b_i$, which indicates that a node $a_i$ is a parent of a node $b_i$. ($1 \leq a_i, b_i \leq N, a_i \ne b_i$) The root node is numbered by 1. It is guaranteed that a given graph is a rooted tree, i.e. there is exactly one parent for each node except the node 1, and the graph is connected. Output Print the number of the pairs $(x, y)$ of the nodes such that the subtree with the root $x$ and the subtree with the root $y$ are similar and $x < y$. Sample Input 1 5 1 2 1 3 1 4 1 5 Output for the Sample Input 1 6 Sample Input 2 6 1 2 2 3 3 4 1 5 5 6 Output for the Sample Input 2 2 Sample Input 3 13 1 2 1 3 2 4 2 5 3 6 3 7 4 8 4 9 6 10 7 11 8 12 11 13 Output for the Sample Input 3 14
36,489
Problem A: Lost in Space William Robinson was completely puzzled in the music room; he could not find his triangle in his bag. He was sure that he had prepared it the night before. He remembered its clank when he had stepped on the school bus early that morning. No, not in his dream. His triangle was quite unique: no two sides had the same length, which made his favorite peculiar jingle. He insisted to the music teacher, Mr. Smith, that his triangle had probably been stolen by those aliens and thrown away into deep space. Your mission is to help Will find his triangle in space. His triangle has been made invisible by the aliens, but candidate positions of its vertices are somehow known. You have to tell which three of them make his triangle. Having gone through worm-holes, the triangle may have changed its size. However, even in that case, all the sides are known to be enlarged or shrunk equally, that is, the transformed triangle is similar to the original. Input The very first line of the input has an integer which is the number of data sets. Each data set gives data for one incident such as that of Will’s. At least one and at most ten data sets are given. The first line of each data set contains three decimals that give lengths of the sides of the original triangle, measured in centimeters. Three vertices of the original triangle are named P, Q, and R. Three decimals given in the first line correspond to the lengths of sides QR, RP, and PQ, in this order. They are separated by one or more space characters. The second line of a data set has an integer which is the number of points in space to be considered as candidates for vertices. At least three and at most thirty points are considered. The rest of the data set are lines containing coordinates of candidate points, in light years. Each line has three decimals, corresponding to x, y, and z coordinates, separated by one or more space characters. Points are numbered in the order of their appearances, starting from one. Among all the triangles formed by three of the given points, only one of them is similar to the original, that is, ratios of the lengths of any two sides are equal to the corresponding ratios of the original allowing an error of less than 0.01 percent. Other triangles have some of the ratios different from the original by at least 0.1 percent. The origin of the coordinate system is not the center of the earth but the center of our galaxy. Note that negative coordinate values may appear here. As they are all within or close to our galaxy, coordinate values are less than one hundred thousand light years. You don’t have to take relativistic effects into account, i.e., you may assume that we are in a Euclidean space. You may also assume in your calculation that one light year is equal to 9.461 × 10 12 kilometers. A succeeding data set, if any, starts from the line immediately following the last line of the preceding data set. Output For each data set, one line should be output. That line should contain the point numbers of the three vertices of the similar triangle, separated by a space character. They should be reported in the order P, Q, and then R. Sample Input 2 50.36493 81.61338 79.96592 5 -10293.83 -4800.033 -5296.238 14936.30 6964.826 7684.818 -4516.069 25748.41 -27016.06 18301.59 -11946.25 5380.309 27115.20 43415.93 -71607.81 11.51547 13.35555 14.57307 5 -56292.27 2583.892 67754.62 -567.5082 -756.2763 -118.7268 -1235.987 -213.3318 -216.4862 -317.6108 -54.81976 -55.63033 22505.44 -40752.88 27482.94 Output for the Sample Input 1 2 4 3 4 2
36,490
Change-Making Problem You want to make change for $n$ cents. Assuming that you have infinite supply of coins of 1, 5, 10 and/or 25 cents coins respectively, find the minimum number of coins you need. Input $n$ The integer $n$ is given in a line. 出力 Print the minimum number of coins you need in a line. Constraints $1 \le n \le 10^9$ Sample Input 1 100 Sample Output 1 4 Sample Input 2 54321 Sample Output 2 2175
36,491
Score: 200 points Problem Statement M-kun has the following three cards: A red card with the integer A . A green card with the integer B . A blue card with the integer C . He is a genius magician who can do the following operation at most K times: Choose one of the three cards and multiply the written integer by 2 . His magic is successful if both of the following conditions are satisfied after the operations: The integer on the green card is strictly greater than the integer on the red card. The integer on the blue card is strictly greater than the integer on the green card. Determine whether the magic can be successful. Constraints 1 \leq A, B, C \leq 7 1 \leq K \leq 7 All values in input are integers. Input Input is given from Standard Input in the following format: A B C K Output If the magic can be successful, print Yes ; otherwise, print No . Sample Input 1 7 2 5 3 Sample Output 1 Yes The magic will be successful if, for example, he does the following operations: First, choose the blue card. The integers on the red, green, and blue cards are now 7 , 2 , and 10 , respectively. Second, choose the green card. The integers on the red, green, and blue cards are now 7 , 4 , and 10 , respectively. Third, choose the green card. The integers on the red, green, and blue cards are now 7 , 8 , and 10 , respectively. Sample Input 2 7 4 2 3 Sample Output 2 No He has no way to succeed in the magic with at most three operations.
36,493
Problem G: Make Friendships Isaac H. Ives attended an international student party and made a lot of girl friends (as many other persons expected). To strike up a good friendship with them, he decided to have dates with them. However, it is hard for him to schedule dates because he made so many friends. Thus he decided to find the best schedule using a computer program. The most important criterion in scheduling is how many different girl friends he will date. Of course, the more friends he will date, the better the schedule is. However, though he has the ability to write a program finding the best schedule, he doesn’t have enough time to write it. Your task is to write a program to find the best schedule instead of him. Input The input consists of a series of data sets. The first line of each data set contains a single positive integer N ( N ≀ 1,000) that represents the number of persons Isaac made friends with in the party. The next line gives Isaac’s schedule, followed by N lines that give his new friends’ schedules. Each schedule consists of a positive integer M that represents the number of available days followed by M positive integers each of which represents an available day. The input is terminated by a line that contains a single zero. This is not part of data sets and should not be processed. Output For each data set, print a line that contains the maximum number of girl friends Isaac can have dates with. Sample Input 3 3 1 3 5 2 1 4 4 1 2 3 6 1 3 0 Output for the Sample Input 2
36,494
Score : 600 points Problem Statement You are given a forest with N vertices and M edges. The vertices are numbered 0 through N-1 . The edges are given in the format (x_i,y_i) , which means that Vertex x_i and y_i are connected by an edge. Each vertex i has a value a_i . You want to add edges in the given forest so that the forest becomes connected. To add an edge, you choose two different vertices i and j , then span an edge between i and j . This operation costs a_i + a_j dollars, and afterward neither Vertex i nor j can be selected again. Find the minimum total cost required to make the forest connected, or print Impossible if it is impossible. Constraints 1 ≀ N ≀ 100,000 0 ≀ M ≀ N-1 1 ≀ a_i ≀ 10^9 0 ≀ x_i,y_i ≀ N-1 The given graph is a forest. All input values are integers. Input Input is given from Standard Input in the following format: N M a_0 a_1 .. a_{N-1} x_1 y_1 x_2 y_2 : x_M y_M Output Print the minimum total cost required to make the forest connected, or print Impossible if it is impossible. Sample Input 1 7 5 1 2 3 4 5 6 7 3 0 4 0 1 2 1 3 5 6 Sample Output 1 7 If we connect vertices 0 and 5 , the graph becomes connected, for the cost of 1 + 6 = 7 dollars. Sample Input 2 5 0 3 1 4 1 5 Sample Output 2 Impossible We can't make the graph connected. Sample Input 3 1 0 5 Sample Output 3 0 The graph is already connected, so we do not need to add any edges.
36,495
Score : 900 points Problem Statement Diverta City is a new city consisting of N towns numbered 1, 2, ..., N . The mayor Ringo is planning to connect every pair of two different towns with a bidirectional road. The length of each road is undecided. A Hamiltonian path is a path that starts at one of the towns and visits each of the other towns exactly once. The reversal of a Hamiltonian path is considered the same as the original Hamiltonian path. There are N! / 2 Hamiltonian paths. Ringo wants all these paths to have distinct total lengths (the sum of the lengths of the roads on a path), to make the city diverse. Find one such set of the lengths of the roads, under the following conditions: The length of each road must be a positive integer. The maximum total length of a Hamiltonian path must be at most 10^{11} . Constraints N is a integer between 2 and 10 (inclusive). Input Input is given from Standard Input in the following format: N Output Print a set of the lengths of the roads that meets the objective, in the following format: w_{1, 1} \ w_{1, 2} \ w_{1, 3} \ ... \ w_{1, N} w_{2, 1} \ w_{2, 2} \ w_{2, 3} \ ... \ w_{2, N} : : : w_{N, 1} \ w_{N, 2} \ w_{N, 3} \ ... \ w_{N, N} where w_{i, j} is the length of the road connecting Town i and Town j , which must satisfy the following conditions: w_{i, i} = 0 w_{i, j} = w_{j, i} \ (i \neq j) 1 \leq w_{i, j} \leq 10^{11} \ (i \neq j) If there are multiple sets of lengths of the roads that meet the objective, any of them will be accepted. Sample Input 1 3 Sample Output 1 0 6 15 6 0 21 15 21 0 There are three Hamiltonian paths. The total lengths of these paths are as follows: 1 → 2 → 3 : The total length is 6 + 21 = 27 . 1 → 3 → 2 : The total length is 15 + 21 = 36 . 2 → 1 → 3 : The total length is 6 + 15 = 21 . They are distinct, so the objective is met. Sample Input 2 4 Sample Output 2 0 111 157 193 111 0 224 239 157 224 0 258 193 239 258 0 There are 12 Hamiltonian paths, with distinct total lengths.
36,496
Problem Statement Infinite Chronicle -Princess Castle- is a simple role-playing game. There are $n + 1$ checkpoints, numbered $0$ through $n$, and for each $i = 1, 2, \ldots, n$, there is a unique one-way road running from checkpoint $i - 1$ to $i$. The game starts at checkpoint $0$ and ends at checkpoint $n$. Evil monsters will appear on the roads and the hero will have battles against them. You can save your game progress at any checkpoint; if you lose a battle, you can restart the game from the checkpoint where you have saved for the last time. At the beginning of the game, the progress is automatically saved at checkpoint $0$ with no time. Rabbit Hanako is fond of this game and now interested in speedrunning. Although Hanako is an expert of the game, she cannot always win the battles because of random factors. For each $i$, she estimated the probability $p_i$ to win all the battles along the road from checkpoint $i - 1$ to $i$. Everytime she starts at checkpoint $i - 1$, after exactly one miniutes, she will be at checkpoint $i$ with probability $p_i$ and where she saved for the last time with probability $1 - p_i$. What puzzles Hanako is that it also takes one minute (!) to save your progress at a checkpoint, so it might be a good idea to pass some checkpoints without saving in order to proceed quickly. The task is to compute the minimum possible expected time needed to complete the game. Input The input consists of multiple datasets. The number of datasets is no more than $50$. Each dataset has two lines: the first line contains an integer $n$ ($1 \le n \le 10^5$), representing the number of roads, and the second line contains $n$ numbers $p_1, p_2, \ldots, p_n$ ($0 \lt p_i \le 1$), representing the winning probabilities. Each $p_i$ has exactly two digits after the decimal point. The end of input is denoted as a line containing only a single zero. Output For each dataset, display the minimum expected time in minutes with a relative error of at most $10^{-8}$ in a line. Sample Input 2 0.50 0.40 2 0.70 0.60 4 0.99 1.00 1.00 0.01 0 Output for the Sample Input 5.5000000000 4.0476190476 104.0101010101
36,497
Problem A: Calling Extraterrestrial Intelligence Again A message from humans to extraterrestrial intelligence was sent through the Arecibo radio telescope in Puerto Rico on the afternoon of Saturday November l6, l974. The message consisted of l679 bits and was meant to be translated to a rectangular picture with 23 × 73 pixels. Since both 23 and 73 are prime numbers, 23 × 73 is the unique possible size of the translated rectangular picture each edge of which is longer than l pixel. Of course, there was no guarantee that the receivers would try to translate the message to a rectangular picture. Even if they would, they might put the pixels into the rectangle incorrectly. The senders of the Arecibo message were optimistic. We are planning a similar project. Your task in the project is to find the most suitable width and height of the translated rectangular picture. The term ``most suitable'' is defined as follows. An integer m greater than 4 is given. A positive fraction a / b less than or equal to 1 is also given. The area of the picture should not be greater than m . Both of the width and the height of the translated picture should be prime numbers. The ratio of the width to the height should not be less than a / b nor greater than 1. You should maximize the area of the picture under these constraints. In other words, you will receive an integer m and a fraction a / b . It holds that m > 4 and 0 < a / b ≀ 1 . You should find the pair of prime numbers p , q such that pq ≀ m and a / b ≀ p / q ≀ 1 , and furthermore, the product pq takes the maximum value among such pairs of two prime numbers. You should report p and q as the "most suitable" width and height of the translated picture. Input The input is a sequence of at most 2000 triplets of positive integers, delimited by a space character in between. Each line contains a single triplet. The sequence is followed by a triplet of zeros, 0 0 0, which indicates the end of the input and should not be treated as data to be processed. The integers of each input triplet are the integer m , the numerator a , and the denominator b described above, in this order. You may assume 4 < m < 100000 and 1 ≀ a ≀ b ≀ 1000. Output The output is a sequence of pairs of positive integers. The i -th output pair corresponds to the i -th input triplet. The integers of each output pair are the width p and the height q described above, in this order. Each output line contains a single pair. A space character is put between the integers as a delimiter. No other characters should appear in the output. Sample Input 5 1 2 99999 999 999 1680 5 16 1970 1 1 2002 4 11 0 0 0 Output for the Sample Input 2 2 313 313 23 73 43 43 37 53
36,498
Problem E: Rabbit Plays Games! うさぎがずあるロヌルプレむングゲヌムで遊んでいる. 城に入る盎前で, 敵に埅ち䌏せされおいた うさぎが操䜜する䞻人公1 人ず, n 䜓の敵ずの戊闘ずなった. 各キャラクタヌには4 ぀の胜力倀, 䜓力 h i , 攻撃力 a i , 防埡力 d i , 敏捷 s i が定められおいる. i = 0 は䞻人公の情報, 1 ≀ i ≀ n は各敵の情報を衚す. 戊闘はタヌン制である. 各タヌン, 生き残っおいるキャラクタヌが, 敏捷の倀が高い順に攻撃を行う. 敵は必ず䞻人公を攻撃する. 䞻人公は敵1 䜓を攻撃するが, どの敵を攻撃するかは毎タヌンごずに䞻人公が遞べる.攻撃力 a のキャラクタヌが防埡力 d のキャラクタヌに攻撃するずき, max{ a − d , 0} のダメヌゞが䞎えられる. 受けたダメヌゞの合蚈が䜓力の倀以䞊になったキャラクタヌは盎ちに戊闘䞍胜になっおしたう. 䞻人公が戊闘䞍胜になったずき, あるいは敵がすべお戊闘䞍胜になったずき, 戊闘は終了する. Input 1 ≀ n ≀ 40 000 1 ≀ h i , a i , d i , s i ≀ 1 000 000 000 (敎数) s i はすべお異なる. Output 䞻人公が必ず戊闘䞍胜になっおしたうずき, −1 を出力せよ. そうでないずき, 䞻人公が受けるダメヌゞの合蚈の最小倀を䞀行に出力せよ. Sample Input 1 2 10 3 1 2 2 4 1 3 2 2 1 1 Sample Output 1 4 Sample Input 2 1 1 1 1 1 10000 10000 10000 10000 Sample Output 2 -1
36,499
Score : 200 points Problem Statement It is only six months until Christmas, and AtCoDeer the reindeer is now planning his travel to deliver gifts. There are N houses along TopCoDeer street . The i -th house is located at coordinate a_i . He has decided to deliver gifts to all these houses. Find the minimum distance to be traveled when AtCoDeer can start and end his travel at any positions. Constraints 1 ≀ N ≀ 100 0 ≀ a_i ≀ 1000 a_i is an integer. Input Input is given from Standard Input in the following format: N a_1 a_2 ... a_N Output Print the minimum distance to be traveled. Sample Input 1 4 2 3 7 9 Sample Output 1 7 The travel distance of 7 can be achieved by starting at coordinate 9 and traveling straight to coordinate 2 . It is not possible to do with a travel distance of less than 7 , and thus 7 is the minimum distance to be traveled. Sample Input 2 8 3 1 4 1 5 9 2 6 Sample Output 2 8 There may be more than one house at a position.
36,500
Score : 600 points Problem Statement There is a tree with N vertices numbered 1 to N . The i -th edge in this tree connects Vertex a_i and Vertex b_i , and the color and length of that edge are c_i and d_i , respectively. Here the color of each edge is represented by an integer between 1 and N-1 (inclusive). The same integer corresponds to the same color, and different integers correspond to different colors. Answer the following Q queries: Query j ( 1 \leq j \leq Q ): assuming that the length of every edge whose color is x_j is changed to y_j , find the distance between Vertex u_j and Vertex v_j . (The changes of the lengths of edges do not affect the subsequent queries.) Constraints 2 \leq N \leq 10^5 1 \leq Q \leq 10^5 1 \leq a_i, b_i \leq N 1 \leq c_i \leq N-1 1 \leq d_i \leq 10^4 1 \leq x_j \leq N-1 1 \leq y_j \leq 10^4 1 \leq u_j < v_j \leq N The given graph is a tree. All values in input are integers. Input Input is given from Standard Input in the following format: N Q a_1 b_1 c_1 d_1 : a_{N-1} b_{N-1} c_{N-1} d_{N-1} x_1 y_1 u_1 v_1 : x_Q y_Q u_Q v_Q Output Print Q lines. The j -th line ( 1 \leq j \leq Q ) should contain the answer to Query j . Sample Input 1 5 3 1 2 1 10 1 3 2 20 2 4 4 30 5 2 1 40 1 100 1 4 1 100 1 5 3 1000 3 4 Sample Output 1 130 200 60 The graph in this input is as follows: Here the edges of Color 1 are shown as solid red lines, the edge of Color 2 is shown as a bold green line, and the edge of Color 4 is shown as a blue dashed line. Query 1 : Assuming that the length of every edge whose color is 1 is changed to 100 , the distance between Vertex 1 and Vertex 4 is 100 + 30 = 130 . Query 2 : Assuming that the length of every edge whose color is 1 is changed to 100 , the distance between Vertex 1 and Vertex 5 is 100 + 100 = 200 . Query 3 : Assuming that the length of every edge whose color is 3 is changed to 1000 (there is no such edge), the distance between Vertex 3 and Vertex 4 is 20 + 10 + 30 = 60 . Note that the edges of Color 1 now have their original lengths.
36,501
ミルクショップ 鈎朚さんは䌚接地域に新しく搟りたおミルクの移動販売のお店を開きたした。その日買い求めに来るお客さんは党員持ち垰るためのボトルを持っお既にお店に䞊んでいお、それ以䞊増えないものずしたす。お客さんはそれぞれ1回だけしか泚文したせん。タンクの蛇口が䞀぀しかないので、䞀人ず぀順番に販売しなければなりたせん。そこで、鈎朚さんはなるべく䞊んでいるお客さんの埅ち時間を少なくしたいず考えおいたす。 お客さんの人数ずお客さんが牛乳を泚ぎきるのに芁する時間が入力ずしお䞎えられたす。あなたはお客さんの「䞀人䞀人の埅ち時間の合蚈」(以䞋「埅ち時間の合蚈」ずする)を最小にするための泚文の順序を鈎朚さんに代わっお調べ、そのずきの「埅ち時間の合蚈」を出力しお終了するプログラムを䜜成しおください。ただし、お客さんは 10,000 人以䞋で 1 人あたりに芁する時間は 60 分以䞋ずしたす。 䟋えば、お客さんの人数が 5 人で、各お客さんが芁する時間が順に 2,6,4,3,9 分の堎合、そのたたの順序だず「埅ち時間の合蚈」は 37 分になりたす。次の䟋では、最初の列の順の 2 人目ず 3 人目を入れ替えおいたす。この堎合、「埅ち時間の合蚈」は 35 分になりたす。最適な順序だず 31 分で枈みたす。 埅ち時間 1 人目 2 分 0 分 2 人目 6 分 2 分 3 人目 4 分 8 分 4 人目 3 分 12 分 5 人目 9 分 15 分 37 分 ← 「埅ち時間の合蚈」 2 人目ず 3 人目を入れ替えた䟋 埅ち時間 1 人目 2 分 0 分 2 人目 4 分 2 分 3 人目 6 分 6 分 4 人目 3 分 12 分 5 人目 9 分 15 分 35 分 ← 「埅ち時間の合蚈」 Input 耇数のデヌタセットが䞎えられたす。各デヌタセットは以䞋の圢匏で䞎えられたす。 n t 1 t 2 : t n 1 行目にお客さんの人数 n ( n ≀ 10,000) が䞎えられたす。続く n 行に i 人目のお客さんが芁する時間を衚す敎数 t i (0 ≀ t i ≀ 60) がそれぞれ行に䞎えられたす。 入力は぀の 0 を含む行で終わりたす。デヌタセットの数は 50 を超えたせん。 Output 各デヌタセットごずに、埅ち時間の合蚈(敎数)を行に出力しおください。 Sample Input 5 2 6 4 3 9 0 Output for the Sample Input 31
36,502
科目遞択 (Selecting Subjects) 問題 JOI 君は物理化孊生物地孊歎史地理の 6 科目のテストを受けた それぞれのテストは 100 点満点で採点された JOI 君は物理化孊生物地孊の 4 科目から 3 科目を遞択し歎史地理の 2 科目から 1 科目を遞択する テストの合蚈点が最も高くなるように科目を遞ぶずき JOI 君の遞んだ科目のテストの合蚈点を求めよ 入力 入力は 6 行からなり1 行に 1 ぀ず぀敎数が曞かれおいる 1 行目には JOI 君の物理のテストの点数 A が曞かれおいる 2 行目には JOI 君の化孊のテストの点数 B が曞かれおいる 3 行目には JOI 君の生物のテストの点数 C が曞かれおいる 4 行目には JOI 君の地孊のテストの点数 D が曞かれおいる 5 行目には JOI 君の歎史のテストの点数 E が曞かれおいる 6 行目には JOI 君の地理のテストの点数 F が曞かれおいる 曞かれおいる敎数 A, B, C, D, E, F はすべお 0 以䞊 100 以䞋である 出力 JOI 君が遞んだ科目のテストの合蚈点を 1 行で出力せよ 入出力䟋 入力䟋 1 100 34 76 42 10 0 出力䟋 1 228 入力䟋 2 15 21 15 42 15 62 出力䟋 2 140 入出力䟋 1 ではJOI 君が物理生物地孊歎史の 4 科目を遞ぶずきテストの合蚈点が最高になる 物理生物地孊歎史の点数はそれぞれ 100, 76, 42, 10 なので遞んだ科目のテストの合蚈点は 228 である 入出力䟋 2 ではJOI 君が化孊生物地孊地理の 4 科目を遞ぶずきテストの合蚈点が最高になる 化孊生物地孊地理の点数はそれぞれ 21, 15, 42, 62 なので遞んだ科目のテストの合蚈点は 140 である 入出力䟋 2 ではJOI 君が物理化孊地孊地理の 4 科目を遞ぶ堎合でも遞んだテストの合蚈点は 140 である 情報オリンピック日本委員䌚䜜 『第 15 回日本情報オリンピック JOI 2015/2016 予遞競技課題』
36,503