task
stringlengths
0
154k
__index_level_0__
int64
0
39.2k
Zero AND Subsets 非負敎数の倚重集合 a_1,a_2,..,a_N が䞎えられたす。 この集合の空でない郚分集合であっお、倀のbitwiseANDが 0 になるものはいく぀ありたすか。 答えを 10^9+7 で割った䜙りを求めおください。 入力 N a_1 a_2...a_N 出力 答えを 10^9+7 で割った䜙りを出力せよ。 制玄 1 \leq N \leq 10^5 0 \leq a_i \leq 2^{20}-1 入力䟋 6 8 6 9 1 2 1 出力䟋 51
38,175
Is it a Right Triangle? Write a program which judges wheather given length of three side form a right triangle. Print " YES " if the given sides (integers) form a right triangle, " NO " if not so. Input Input consists of several data sets. In the first line, the number of data set, N is given. Then, N lines follow, each line corresponds to a data set. A data set consists of three integers separated by a single space. Constraints 1 ≀ length of the side ≀ 1,000 N ≀ 1,000 Output For each data set, print " YES " or " NO ". Sample Input 3 4 3 5 4 3 6 8 8 8 Output for the Sample Input YES NO NO
38,176
Problem I: Revenge of Voronoi A discrete Voronoi diagram is a derivation of a Voronoi diagram. It is represented as a set of pixels. Each of the generatrices lies on the center of some pixel. Each pixel belongs to the generatrix nearest from the center of the pixel in the sense of Manhattan distance. The Manhattan distance d between two points ( x 1 , y 1 ) and ( x 2 , y 2 ) is given by the following formula: d = | x 1 - x 2 | + | y 1 - y 2 | Your task is to find a set of generatrices which generates a given discrete Voronoi diagram. In the given diagram, each generatrix is given a unique lowercase letter as its identifier, and each pixel is represented by the identifier of the generatrix the pixel belongs to. If a pixel has multiple generatrices at the same distance from its center, it belongs to the generatrix with the most preceding identifier among them (i.e. the smallest character code). Input The input consists of multiple test cases. Each test case begins with a line containing two integers W (1 ≀ W ≀ 32) and H (1 ≀ H ≀ 32), which denote the width and height of the discrete Voronoi diagram. The following H lines, each of which consists of W letters, give one discrete Voronoi diagram. Each letter represents one pixel. The end of input is indicated by a line with two zeros. This is not a part of any test cases. Output For each test case, print the case number and the coordinates of generatrices as shown in the sample output. Each generatrix line should consist of its identifier, x -coordinate, and y -coordinate. Generatrices should be printed in alphabetical order of the identifiers. Each coordinate is zero-based where (0, 0) indicates the center of the top-left corner pixel of the diagram. You may assume that every test case has at least one solution. If there are multiple solutions, any one is acceptable. Print a blank line after every test case including the last one. Sample Input 4 3 ooxx ooxx ooxx 4 1 null 4 4 aabb aabb ccdd ccdd 0 0 Output for the Sample Input Case 1: o 0 0 x 2 0 Case 2: l 2 0 n 0 0 u 1 0 Case 3: a 0 0 b 2 0 c 0 2 d 2 2
38,177
Score : 100 points Problem Statement Given is an integer N . Takahashi chooses an integer a from the positive integers not greater than N with equal probability. Find the probability that a is odd. Constraints 1 \leq N \leq 100 Input Input is given from Standard Input in the following format: N Output Print the probability that a is odd. Your output will be considered correct when its absolute or relative error from the judge's output is at most 10^{-6} . Sample Input 1 4 Sample Output 1 0.5000000000 There are four positive integers not greater than 4 : 1 , 2 , 3 , and 4 . Among them, we have two odd numbers: 1 and 3 . Thus, the answer is \frac{2}{4} = 0.5 . Sample Input 2 5 Sample Output 2 0.6000000000 Sample Input 3 1 Sample Output 3 1.0000000000
38,178
Score : 300 points Problem Statement Every day, N passengers arrive at Takahashi Airport. The i -th passenger arrives at time T_i . Every passenger arrived at Takahashi airport travels to the city by bus. Each bus can accommodate up to C passengers. Naturally, a passenger cannot take a bus that departs earlier than the airplane arrives at the airport. Also, a passenger will get angry if he/she is still unable to take a bus K units of time after the arrival of the airplane. For that reason, it is necessary to arrange buses so that the i -th passenger can take a bus departing at time between T_i and T_i + K (inclusive). When setting the departure times for buses under this condition, find the minimum required number of buses. Here, the departure time for each bus does not need to be an integer, and there may be multiple buses that depart at the same time. Constraints 2 \leq N \leq 100000 1 \leq C \leq 10^9 1 \leq K \leq 10^9 1 \leq T_i \leq 10^9 C , K and T_i are integers. Input The input is given from Standard Input in the following format: N C K T_1 T_2 : T_N Output Print the minimum required number of buses. Sample Input 1 5 3 5 1 2 3 6 12 Sample Output 1 3 For example, the following three buses are enough: A bus departing at time 4.5 , that carries the passengers arriving at time 2 and 3 . A bus departing at time 6 , that carries the passengers arriving at time 1 and 6 . A bus departing at time 12 , that carries the passenger arriving at time 12 . Sample Input 2 6 3 3 7 6 2 8 10 6 Sample Output 2 3
38,179
Score : 400 points Problem Statement We have a large square grid with H rows and W columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell. However, she cannot enter the cells in the intersection of the bottom A rows and the leftmost B columns. (That is, there are A×B forbidden cells.) There is no restriction on entering the other cells. Find the number of ways she can travel to the bottom-right cell. Since this number can be extremely large, print the number modulo 10^9+7 . Constraints 1 ≩ H, W ≩ 100,000 1 ≩ A < H 1 ≩ B < W Input The input is given from Standard Input in the following format: H W A B Output Print the number of ways she can travel to the bottom-right cell, modulo 10^9+7 . Sample Input 1 2 3 1 1 Sample Output 1 2 We have a 2×3 grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right". Sample Input 2 10 7 3 4 Sample Output 2 3570 There are 12 forbidden cells. Sample Input 3 100000 100000 99999 99999 Sample Output 3 1 Sample Input 4 100000 100000 44444 55555 Sample Output 4 738162020
38,180
Problem G: Captain Q′s Treasure You got an old map, which turned out to be drawn by the infamous pirate “Captain Q”. It shows the locations of a lot of treasure chests buried in an island. The map is divided into square sections, each of which has a digit on it or has no digit. The digit represents the number of chests in its 9 neighboring sections (the section itself and its 8 neighbors). You may assume that there is at most one chest in each section. Although you have the map, you can't determine the sections where the chests are buried. Even the total number of chests buried in the island is unknown. However, it is possible to calculate the minimum number of chests buried in the island. Your mission in this problem is to write a program that calculates it. Input The input is a sequence of datasets. Each dataset is formatted as follows. h w map The first line of a dataset consists of two positive integers h and w . h is the height of the map and w is the width of the map. You may assume 1≀ h ≀15 and 1≀ w ≀15. The following h lines give the map. Each line consists of w characters and corresponds to a horizontal strip of the map. Each of the characters in the line represents the state of a section as follows. ‘.’: The section is not a part of the island (water). No chest is here. ‘*’: The section is a part of the island, and the number of chests in its 9 neighbors is not known. ‘0’-‘9’: The section is a part of the island, and the digit represents the number of chests in its 9 neighbors. You may assume that the map is not self-contradicting, i.e., there is at least one arrangement of chests. You may also assume the number of sections with digits is at least one and at most 15. A line containing two zeros indicates the end of the input. Output For each dataset, output a line that contains the minimum number of chests. The output should not contain any other character. Sample Input 5 6 *2.2** ..*... ..2... ..*... *2.2** 6 5 .*2*. ..*.. ..*.. ..2.. ..*.. .*2*. 5 6 .1111. **...* 33.... **...0 .*2**. 6 9 ....1.... ...1.1... ....1.... .1..*..1. 1.1***1.1 .1..*..1. 9 9 ********* *4*4*4*4* ********* *4*4*4*4* ********* *4*4*4*4* ********* *4*4*4*** ********* 0 0 Output for the Sample Input 6 5 5 6 23
38,181
瀟員旅行 Problem Statement あなたの䌚瀟には n 人の瀟員が存圚する m 個の瀟員 (a_i,b_i) の組に぀いお a_i は b_i の䞊叞である 瀟員 x が瀟員 y の実質的な䞊叞であるずは次のうち少なくずも䞀方が成り立぀こずをいう x が y の䞊叞である y の実質的な䞊叞である瀟員 z が存圚しお x は z の䞊叞である あなたの䌚瀟で自分自身が自分の実質的な䞊叞であるような瀟員は存圚しない あなたの䌚瀟では瀟員が党員参加する瀟員旅行が蚈画されおいる党瀟員の芁求により旅通での郚屋割りは「よい郚屋割り」でなければならない ある郚屋割りが「よい郚屋割り」であるずは以䞋の䞡方が満たされるこずをいう 各瀟員はどこかの郚屋に割り振られる 瀟員 x ず瀟員 y が同じ郚屋に割り振られおいるずき x は y の実質的な䞊叞でない 幹事の瀟員は非垞に優秀なので「よい郚屋割り」でか぀必芁な郚屋の数が最小になるように郚屋割りを行ったしかし残念なこずに予算が䞍足しおいるどうしおも必芁な郚屋の数を枛らさなければならないらしい そこで人事郚で働くあなたは䞊叞-郚䞋の関係を䞀぀だけ解消するこずによっお「よい郚屋割り」を埗るために必芁な郚屋の数を枛らすこずにした さおどの関係を解消すればよいのだろう Input 入力は以䞋の圢匏に埓う䞎えられる数は党お敎数である n m a_1 b_1 ... a_m b_m Constraints 2≩n≩10^5 1≩m≩2 \times 10^5 1≩a_i<b_i≩n i \neq j ならば (a_i, b_i) \neq (a_j, b_j) Output 次を満たすような i を昇順に1行ず぀出力せよ 「 a_i が b_i の䞊叞である」ずいう関係を解消したずき「よい郚屋割り」を埗るために必芁な郚屋の数を枛らすこずができる そのような i が存圚しない堎合は-1を1行に出力せよ Sample Input 1 5 4 1 2 2 3 3 4 3 5 Output for the Sample Input 1 1 2
38,182
Problem E: 足し算ゲヌム ねこのファヌブルは足し算を甚いた簡単なゲヌムを思い぀き、同じくねこで友達のオヌドリヌず䞀緒にやっおみるこずにした。 ゲヌムのルヌルは次のようなものである。たず最初に、適圓な正の敎数を遞び、そこからスタヌトする。各プレヌダヌは、その数のうち隣り合う2぀の桁を遞択しお和を蚈算し、もずの2぀の数字ず眮き換える。たずえば、「1234」の十の䜍ず癟の䜍を遞ぶず、次の数は「154」ずなる。「5555」の十の䜍ず癟の䜍を遞んだ堎合は「5105」ずなる。このような操䜜を数が1桁になるたで亀互に繰り返し、操䜜ができなくなったプレヌダヌが負けずなる。 ゲヌム開始時の敎数の倀が䞎えられる。先攻であるファヌブルず埌攻であるオヌドリヌがいずれも最適な戊略を取るずき、どちらが勝぀のかを刀定するプログラムを䜜成せよ。 Input 入力は、ゲヌム開始時の数を衚す1000桁以䞋の正の敎数が1぀曞かれた1行のみからなる。なお、最䞊䜍の桁は0ではない。 Output ファヌブルが勝぀なら "Fabre wins."、オヌドリヌが勝぀なら "Audrey wins." ず1行に出力せよ。最埌にピリオドを぀ける必芁があるこずに泚意するこず。 Notes on Submission 䞊蚘圢匏で耇数のデヌタセットが䞎えられたす。入力デヌタの 1 行目にデヌタセットの数が䞎えられたす。各デヌタセットに察する出力を䞊蚘圢匏で順番に出力するプログラムを䜜成しお䞋さい。 Sample Input 3 1234 5555 9 Output for the Sample Input Audrey wins. Fabre wins. Audrey wins.
38,183
Score : 300 points Problem Statement A programming competition site AtCode provides algorithmic problems. Each problem is allocated a score based on its difficulty. Currently, for each integer i between 1 and D (inclusive), there are p_i problems with a score of 100i points. These p_1 + 
 + p_D problems are all of the problems available on AtCode. A user of AtCode has a value called total score . The total score of a user is the sum of the following two elements: Base score: the sum of the scores of all problems solved by the user. Perfect bonuses: when a user solves all problems with a score of 100i points, he/she earns the perfect bonus of c_i points, aside from the base score (1 ≀ i ≀ D) . Takahashi, who is the new user of AtCode, has not solved any problem. His objective is to have a total score of G or more points. At least how many problems does he need to solve for this objective? Constraints 1 ≀ D ≀ 10 1 ≀ p_i ≀ 100 100 ≀ c_i ≀ 10^6 100 ≀ G All values in input are integers. c_i and G are all multiples of 100 . It is possible to have a total score of G or more points. Input Input is given from Standard Input in the following format: D G p_1 c_1 : p_D c_D Output Print the minimum number of problems that needs to be solved in order to have a total score of G or more points. Note that this objective is always achievable (see Constraints). Sample Input 1 2 700 3 500 5 800 Sample Output 1 3 In this case, there are three problems each with 100 points and five problems each with 200 points. The perfect bonus for solving all the 100 -point problems is 500 points, and the perfect bonus for solving all the 200 -point problems is 800 points. Takahashi's objective is to have a total score of 700 points or more. One way to achieve this objective is to solve four 200 -point problems and earn a base score of 800 points. However, if we solve three 100 -point problems, we can earn the perfect bonus of 500 points in addition to the base score of 300 points, for a total score of 800 points, and we can achieve the objective with fewer problems. Sample Input 2 2 2000 3 500 5 800 Sample Output 2 7 This case is similar to Sample Input 1, but the Takahashi's objective this time is 2000 points or more. In this case, we inevitably need to solve all five 200 -point problems, and by solving two 100 -point problems additionally we have the total score of 2000 points. Sample Input 3 2 400 3 500 5 800 Sample Output 3 2 This case is again similar to Sample Input 1, but the Takahashi's objective this time is 400 points or more. In this case, we only need to solve two 200 -point problems to achieve the objective. Sample Input 4 5 25000 20 1000 40 1000 50 1000 30 1000 1 1000 Sample Output 4 66 There is only one 500 -point problem, but the perfect bonus can be earned even in such a case.
38,184
Score : 2200 points Problem Statement We have two indistinguishable pieces placed on a number line. Both pieces are initially at coordinate 0 . (They can occupy the same position.) We can do the following two kinds of operations: Choose a piece and move it to the right (the positive direction) by 1 . Move the piece with the smaller coordinate to the position of the piece with the greater coordinate. If two pieces already occupy the same position, nothing happens, but it still counts as doing one operation. We want to do a total of N operations of these kinds in some order so that one of the pieces will be at coordinate A and the other at coordinate B . Find the number of ways to move the pieces to achieve it. The answer can be enormous, so compute the count modulo 998244353 . Two ways to move the pieces are considered different if and only if there exists an integer i ( 1 \leq i \leq N ) such that the set of the coordinates occupied by the pieces after the i -th operation is different in those two ways. Constraints 1 \leq N \leq 10^7 0 \leq A \leq B \leq N All values in input are integers. Input Input is given from Standard Input in the following format: N A B Output Print the number of ways to move the pieces to achieve our objective, modulo 998244353 . Sample Input 1 5 1 3 Sample Output 1 4 Shown below are the four ways to move the pieces, where (x,y) represents the state where the two pieces are at coordinates x and y . (0,0)→(0,0)→(0,1)→(0,2)→(0,3)→(1,3) (0,0)→(0,0)→(0,1)→(0,2)→(1,2)→(1,3) (0,0)→(0,0)→(0,1)→(1,1)→(1,2)→(1,3) (0,0)→(0,1)→(1,1)→(1,1)→(1,2)→(1,3) Sample Input 2 10 0 0 Sample Output 2 1 Sample Input 3 10 4 6 Sample Output 3 197 Sample Input 4 1000000 100000 200000 Sample Output 4 758840509
38,185
Problem A: How I Wonder What You Are! One of the questions children often ask is "How many stars are there in the sky?" Under ideal conditions, even with the naked eye, nearly eight thousands are observable in the northern hemisphere. With a decent telescope, you may find many more, but, as the sight field will be limited, you may find much less at a time. Children may ask the same questions to their parents on a planet of some solar system billions of light-years away from the Earth. Their telescopes are similar to ours with circular sight fields, but alien kids have many eyes and can look into different directions at a time through many telescopes. Given a set of positions of stars, a set of telescopes and the directions they are looking to, your task is to count up how many stars can be seen through these telescopes. Input The input consists of one or more datasets. The number of datasets is less than 50. Each dataset describes stars and the parameters of the telescopes used. The first line of a dataset contains a positive integer n not exceeding 500, meaning the number of stars. Each of the n lines following it contains three decimal fractions, s x , s y , and s z . They give the position ( s x , s y , s z ) of the star described in Euclidean coordinates. You may assume -1000 ≀ s x ≀ 1000, -1000 ≀ s y ≀ 1000, -1000 ≀ s z ≀ 1000 and ( s x , s y , s z ) ≠ (0, 0, 0). Then comes a line containing a positive integer m not exceeding 50, meaning the number of telescopes. Each of the following m lines contains four decimal fractions, t x , t y , t z , and φ , describing a telescope. The first three numbers represent the direction of the telescope. All the telescopes are at the origin of the coordinate system (0, 0, 0) (we ignore the size of the planet). The three numbers give the point ( t x , t y , t z ) which can be seen in the center of the sight through the telescope. You may assume -1000 ≀ t x ≀ 1000, -1000 ≀ t y ≀ 1000, -1000 ≀ t z ≀ 1000 and ( t x , t y , t z ) ≠ (0, 0, 0). The fourth number φ (0 ≀ φ ≀ π /2) gives the angular radius, in radians, of the sight field of the telescope. Let us defie that Ξ i,j is the angle between the direction of the i -th star and the center direction of the j -th telescope and φ j is the angular radius of the sight field of the j -th telescope. The i -th star is observable through the j -th telescope if and only if Ξ i,j is less than . You may assume that | Ξ i,j - φ j | > 0.00000001 for all pairs of i and j . Figure 1: Direction and angular radius of a telescope The end of the input is indicated with a line containing a single zero. Output For each dataset, one line containing an integer meaning the number of stars observable through the telescopes should be output. No other characters should be contained in the output. Note that stars that can be seen through more than one telescope should not be counted twice or more. Sample Input 3 100 0 500 -500.243 -200.1 -300.5 0 300 200 2 1 1 1 0.65 -1 0 0 1.57 3 1 0 0 0 1 0 0 0 1 4 1 -1 -1 0.9553 -1 1 -1 0.9554 -1 -1 1 0.9553 -1 1 -1 0.9554 3 1 0 0 0 1 0 0 0 1 4 1 -1 -1 0.9553 -1 1 -1 0.9553 -1 -1 1 0.9553 -1 1 -1 0.9553 0 Output for the Sample Input 2 1 0
38,186
今幎も党囜プログラミング遞手暩倧䌚の時期がやっおきた党囜倧䌚の参加暩を賭けた地区倧䌚は 2 n チヌムが1 察1 の勝ち残り匏トヌナメント方匏で察決する トヌナメント衚にはチヌム番号 0, . . . 2 n − 1 が割り振られおおり1 回戊から n 回戊たでの察決手順は次の通りである 1 回戊ではチヌム番号が l のチヌムずチヌム番号が l + 1 のチヌムが察決する( l ≡ 0 (mod 2)) i + 1 回戊( 1 ≀ i < n ) では「チヌム番号が l 以䞊 l + 2 i 未満のチヌムのうち i 回戊たでの察決で 1 回も負けおいないチヌム」ず「チヌム番号が l + 2 i 以䞊 l + 2 i+1 未満のチヌムのうち i 回戊たでの察決で䞀回も負けおいないチヌム」が察決する( l ≡ 0 (mod 2 i +1 )) n 回戊たで終わるず各チヌムの順䜍は 2 n − (そのチヌムが勝った回数) 䜍で確定するなおこの察決には匕き分けが存圚しないため察決したチヌムのいずれか䞀方が勝ちもう䞀方が負ける 晎れお地区倧䌚の代衚に遞ばれた私達は他の地区倧䌚の結果をマネヌゞャヌに調べおもらうこずにしたここで調べおもらった結果が「マネヌゞャヌから受け取った順䜍衚」であった「マネヌゞャヌから受け取った順䜍衚」をより詳现に説明するず長さ 2 n の数列で i ( 0 ≀ i ≀ 2 n − 1 ) 番目の芁玠にチヌム番号 i のチヌムの順䜍が曞かれおいるものである だが「マネヌゞャヌから受け取った順䜍衚」には同じ順䜍が倧量に䞊んでいたトヌナメントのルヌル䞊同じ順䜍が倧量に䞊ぶなんおありえないはずだそこで「マネヌゞャヌから受け取った順䜍衚」を「無矛盟な順䜍衚」にするために順䜍を倉曎するチヌム数の最小倀を蚈算しおどのくらい順䜍衚が間違っおいるかをマネヌゞャヌに教えおあげよう「無矛盟な順䜍衚」ずは順䜍が確定したトヌナメントの結果ずしお起こりうる順䜍衚のこずを衚す Input 入力には「マネヌゞャヌから受け取った順䜍衚」が以䞋の圢匏で䞎えられる n m a 0 a 1 . . . a m b 0 b 1 . . . b m−1 1 行目は n, m の2 個の敎数からなり 2 n は「地区倧䌚の参加チヌム数」 m は「『マネヌゞャヌから受け取った順䜍衚』で連続した順䜍が䞊んでいる区間の個数」を衚す 2 行目は a i (0 ≀ i ≀ m) の m + 1 個の敎数からなり各 a i は「『マネヌゞャヌから受け取った順䜍衚』で連続した順䜍が䞊んでいる区間の区切り䜍眮」を衚す 3 行目は b i (0 ≀ i < m) の m 個の敎数からなり各2 b i は「『マネヌゞャヌから受け取った順䜍衚』におけるチヌム番号が a i 以䞊 a i+1 未満のチヌムの順䜍」を衚す Constraints 1 ≀ n ≀ 30 1 ≀ m ≀ 10,000 0 = a 0 < a 1 ≀ . . . ≀ a m−1 < a m = 2 n 0 ≀ b i ≀ n Output 「マネヌゞャヌから受け取った順䜍衚」を「無矛盟な順䜍衚」にするために順䜍を倉曎するチヌム数の最小倀を1 行に出力せよ Sample Input 1 1 1 0 2 1 Output for the Sample Input 1 1 参加チヌム数が2 の「無矛盟な順䜍衚」は{"チヌム番号 0 のチヌムの順䜍", "チヌム番号 1 のチヌムの順䜍"} ずしお {1, 2} ず {2, 1} の2 通りがある順䜍衚 {2, 2} を「無矛盟な順䜍衚」に修正するためにはいずれかのチヌムの順䜍を 1 に倉曎しなければならない Sample Input 2 2 3 0 1 2 4 0 1 2 Output for the Sample Input 2 2 Sample Input 3 2 3 0 1 3 4 0 2 1 Output for the Sample Input 3 0 Sample Input 4 4 5 0 1 2 4 8 16 0 1 2 3 4 Output for the Sample Input 4 10
38,187
問題 2: 投祚 (Vote) 問題 20XX幎に東京で䞖界的なスポヌツ倧䌚が開かれるこずになったプログラミングコンテストはスポヌツずしお䞖界で楜したれおおり競技ずしお採甚される可胜性がある採甚される競技を決める審査委員䌚に぀いお調べたずころ次のようなこずが分かった 審査委員䌚のために候補ずなる N 個の競技を面癜い方から順番に䞊べたリストが䜜成されたリストの䞊から i 番目には i 番目に面癜い競技が曞かれおいるそれを競技 i ずするさらに競技 i の開催に必芁な費甚 A i が曞かれおいる たた審査委員䌚は委員 1 から委員 M たでの M 人の委員で構成されおいる委員 j は自分の審査基準 B j をもっおおり開催に必芁な費甚が B j 以䞋の競技のうち最も面癜いものに 1 祚を投祚した どの委員の審査基準に察しおも少なくずも 1 ぀の競技は開催に必芁な費甚が審査基準以䞋であったしたがっお委員は党員 1 祚を投祚した 最も倚く祚を獲埗した競技は 1 ぀だけであった 競技のリストず委員の情報が䞎えられたずき最も倚く祚を獲埗した競技の番号を求めるプログラムを䜜成せよ 入力 入力は 1 + N + M 行からなる 1 行目には敎数 N, M (1 ≀ N ≀ 10001 ≀ M ≀ 1000) が曞かれおおりそれぞれ競技の数委員の数を衚す 続く N 行のうちの i 行目 (1 ≀ i ≀ N) には敎数 A i (1 ≀ A i ≀ 1000) が曞かれおおり 競技 i の開催に必芁な費甚 A i を衚す 続く M 行のうちの j 行目 (1 ≀ j ≀ M) には敎数 B j (1 ≀ B j ≀ 1000) が曞かれおおり委員 j の審査基準 B j を衚す 䞎えられる入力デヌタにおいおはどの委員も必ず 1 祚を投祚し最も倚く祚を獲埗した競技は 1 ぀であるこずが保蚌されおいる 出力 最も倚く祚を獲埗した競技の番号を 1 行で出力せよ 入出力䟋 入力䟋 1 4 3 5 3 1 4 4 3 2 出力䟋 1 2 入出力䟋 1 では競技は 4 ぀あり委員は 3 人いるリストの 4 ぀の競技にかかる費甚はそれぞれ 5, 3, 1, 4 である 委員 1 の審査基準は 4 である費甚が 4 以䞋の競技のうち最も面癜いものは競技 2 である 委員 2 の審査基準は 3 である費甚が 3 以䞋の競技のうち最も面癜いものは競技 2 である 委員 3 の審査基準は 2 である費甚が 2 以䞋の競技のうち最も面癜いものは競技 3 である よっお競技 2 が 2 祚競技 3 が 1 祚を獲埗する最も倚く祚を獲埗した競技は競技 2 であるので2 を出力する 入力䟋 2 6 6 3 1 4 1 5 9 2 6 5 3 5 9 出力䟋 2 1 入出力䟋 2 では競技 1 が 5 祚競技 2 が 1 祚を獲埗する最も倚く祚を獲埗した競技は競技 1 なので1 を出力する 問題文ず自動審刀に䜿われるデヌタは、 情報オリンピック日本委員䌚 が䜜成し公開しおいる問題文ず採点甚テストデヌタです。
38,188
ルパン四䞖 怪盗「ルパン四䞖」は䌚接藩士を末裔ずする矎女「富士峰子」より、䌚接若束垂に䌚接藩が残した軍資金が眠っおいるこずを聞かされる。ルパンの長幎の仲間である「石川越ェ門」の報告によれば、軍資金は千䞡箱に収められいく぀かの蔵に保管されおいる。蔵に芋匵りはいないが厳重に斜錠されおいる。しかし、越ェ門は圌が父から䌝授された秘䌝「鋌鉄斬り」の技を繰り出せば瞬時に蔵を砎れるずいう。 残った問題は千䞡箱の運搬だ。䜓力のないルパンず越ェ門は千䞡箱を䞀぀も持おない。そこで、頌りになる男「無限倧介」に運搬を頌んだ。 すべおの千䞡箱を運び出すために、ルパンは以䞋のような蚈画を立案した。 たず、ルパンの運転で最初の蔵ぞ行き、越ェ門ず倧介を降ろす。 越ェ門が蔵を砎る 倧介がすべおの千䞡箱を運び出す その千䞡箱を持ったたたルパンが決めた次の蔵ぞ向かう これを繰り返し、最埌の蔵たで砎り千䞡箱を運び出す。その間にルパンはヘリコプタヌを準備し最埌の蔵で二人ず千䞡箱を運び䞊げ脱出する。倧介はどんなに重いものも運搬できるが、荷物の重さに応じお移動速床は遅くなる。ルパンは、このこずを考慮しお蔵を砎る順番を決めなければならない。 ルパンに代わっお、最初の蔵を砎っおから最埌の蔵に蟿り぀くたでの移動時間が最小ずなるような蔵を砎る順番を出力するプログラムを䜜成しおください。ただし、 蔵はすべお鶎ヶ城からたっすぐ北に走る通りに面しおいる。蔵の数は高々 15 個であり、城からの距離は高々 10000 メヌトル以䞋である。 千䞡箱の重さはいずれもひず぀ 20 キログラムである。それぞれの蔵に収められおいる千䞡箱の個数は 10000 個以䞋である。 蔵から蔵ぞの移動は、通りに沿っお地䞋に蚭眮されおいる地䞋道を䜿う。 倧介は w キログラムの荷物を運ぶのに、分速 2,000(70 + w ) メヌトルで移動する。 入力デヌタは、それぞれの蔵に぀いお蔵の番号100 以䞋の敎数ず城からの距離メヌトルずその蔵に保管されおいる千䞡箱の個数が䞎えられる。 Input 入力は以䞋の圢匏で䞎えられたす。 n s 1 d 1 v 1 s 2 d 2 v 2 : s n d n v n 1 行目に蔵の個数 n  n ≀ 15、続く n 行に第 i の蔵の情報が䞎えられたす。蔵の情報ずしお、蔵の番号 s i (1 ≀ s i ≀ 100)、城からの距離 d i (1 ≀ d i ≀ 10000)、 千䞡箱の数 v i (1 ≀ v i ≀ 10000) が行に䞎えられたす。 Output 蔵を砎る順番を行に出力しおください。蔵の番号を空癜で区切っおください。 Sample Input 1 2 1 100 1 2 200 2 Output for the Sample Input 1 1 2 Sample Input 2 3 11 100 1 13 200 20 12 300 3 Output for the Sample Input 2 11 12 13 Sample Input 3 5 13 199 1 51 1000 1 37 350 10 27 300 2 99 200 1000 Output for the Sample Input 3 51 37 27 13 99
38,189
Problem D: International Party Isaac H. Ives is attending an international student party (maybe for girl-hunting). Students there enjoy talking in groups with excellent foods and drinks. However, since students come to the party from all over the world, groups may not have a language spoken by all students of the group. In such groups, some student(s) need to work as interpreters, but intervals caused by interpretation make their talking less exciting. Needless to say, students want exciting talks. To have talking exciting as much as possible, Isaac proposed the following rule: the number of languages used in talking should be as little as possible, and not exceed five. Many students agreed with his proposal, but it is not easy for them to find languages each student should speak. So he calls you for help. Your task is to write a program that shows the minimum set of languages to make talking possible, given lists of languages each student speaks. Input The input consists of a series of data sets. The first line of each data set contains two integers N (1 ≀ N ≀ 30) and M (2 ≀ M ≀ 20) separated by a blank, which represent the numbers of languages and students respectively. The following N lines contain language names, one name per line. The following M lines describe students in the group. The i -th line consists of an integer K i that indicates the number of languages the i -th student speaks, and K i language names separated by a single space. Each language name consists of up to twenty alphabetic letters. A line that contains two zeros indicates the end of input and is not part of a data set. Output Print a line that contains the minimum number L of languages to be spoken, followed by L language names in any order. Each language name should be printed in a separate line. In case two or more sets of the same size is possible, you may print any one of them. If it is impossible for the group to enjoy talking with not more than five languages, you should print a single line that contains “Impossible” (without quotes). Print an empty line between data sets. Sample Input 3 4 English French Japanese 1 English 2 French English 2 Japanese English 1 Japanese 2 2 English Japanese 1 English 1 Japanese 6 7 English Dutch German French Italian Spanish 1 English 2 English Dutch 2 Dutch German 2 German French 2 French Italian 2 Italian Spanish 1 Spanish 0 0 Output for the Sample Input 2 English Japanese Impossible Impossible
38,190
Score : 2000 points Problem Statement There is a bridge that connects the left and right banks of a river. There are 2 N doors placed at different positions on this bridge, painted in some colors. The colors of the doors are represented by integers from 1 through N . For each k ( 1 \leq k \leq N ), there are exactly two doors painted in Color k . Snuke decides to cross the bridge from the left bank to the right bank. He will keep on walking to the right, but the following event will happen while doing so: At the moment Snuke touches a door painted in Color k ( 1 \leq k \leq N ), he teleports to the right side of the other door painted in Color k . It can be shown that he will eventually get to the right bank. For each i ( 1 \leq i \leq 2 N - 1 ), the section between the i -th and (i + 1) -th doors from the left will be referred to as Section i . After crossing the bridge, Snuke recorded whether or not he walked through Section i , for each i ( 1 \leq i \leq 2 N - 1 ). This record is given to you as a string s of length 2 N - 1 . For each i ( 1 \leq i \leq 2 N - 1 ), if Snuke walked through Section i , the i -th character in s is 1 ; otherwise, the i -th character is 0 . Figure: A possible arrangement of doors for Sample Input 3 Determine if there exists an arrangement of doors that is consistent with the record. If it exists, construct one such arrangement. Constraints 1 \leq N \leq 10^5 |s| = 2 N - 1 s consists of 0 and 1 . Input Input is given from Standard Input in the following format: N s Output If there is no arrangement of doors that is consistent with the record, print No . If there exists such an arrangement, print Yes in the first line, then print one such arrangement in the second line, in the following format: c_1 c_2 ... c_{2 N} Here, for each i ( 1 \leq i \leq 2 N ), c_i is the color of the i -th door from the left. Sample Input 1 2 010 Sample Output 1 Yes 1 1 2 2 Sample Input 2 2 001 Sample Output 2 No Sample Input 3 3 10110 Sample Output 3 Yes 1 3 2 1 2 3 The figure below is identical to the one in the statement. Sample Input 4 3 10101 Sample Output 4 No Sample Input 5 6 00111011100 Sample Output 5 Yes 1 6 1 2 3 4 4 2 3 5 6 5
38,191
Score : 300 points Problem Statement There is a staircase with N steps. Takahashi is now standing at the foot of the stairs, that is, on the 0 -th step. He can climb up one or two steps at a time. However, the treads of the a_1 -th, a_2 -th, a_3 -th, \ldots , a_M -th steps are broken, so it is dangerous to set foot on those steps. How many are there to climb up to the top step, that is, the N -th step, without setting foot on the broken steps? Find the count modulo 1\ 000\ 000\ 007 . Constraints 1 \leq N \leq 10^5 0 \leq M \leq N-1 1 \leq a_1 < a_2 < ... < a_M \leq N-1 Input Input is given from Standard Input in the following format: N M a_1 a_2 . . . a_M Output Print the number of ways to climb up the stairs under the condition, modulo 1\ 000\ 000\ 007 . Sample Input 1 6 1 3 Sample Output 1 4 There are four ways to climb up the stairs, as follows: 0 \to 1 \to 2 \to 4 \to 5 \to 6 0 \to 1 \to 2 \to 4 \to 6 0 \to 2 \to 4 \to 5 \to 6 0 \to 2 \to 4 \to 6 Sample Input 2 10 2 4 5 Sample Output 2 0 There may be no way to climb up the stairs without setting foot on the broken steps. Sample Input 3 100 5 1 23 45 67 89 Sample Output 3 608200469 Be sure to print the count modulo 1\ 000\ 000\ 007 .
38,192
Problem H: Co-occurrence Search A huge amount of information is being heaped on WWW. Albeit it is not well-organized, users can browse WWW as an unbounded source of up-to-date information, instead of consulting established but a little out-of-date encyclopedia. However, you can further exploit WWW by learning more about keyword search algorithms. For example, if you want to get information on recent comparison between Windows and UNIX, you may expect to get relevant description out of a big bunch of Web texts, by extracting texts that contain both keywords "Windows" and "UNIX" close together. Here we have a simplified version of this co-occurrence keyword search problem, where the text and keywords are replaced by a string and key characters, respectively. A character string S of length n (1 ≀ n ≀ 1,000,000) and a set K of k distinct key characters a 1 , ..., a k (1 ≀ k ≀ 50) are given. Find every shortest substring of S that contains all of the key characters a 1 , ..., a k . Input The input is a text file which contains only printable characters (ASCII codes 21 to 7E in hexadecimal) and newlines. No white space such as space or tab appears in the input. The text is a sequence of the shortest string search problems described above. Each problem consists of character string S i and key character set K i ( i = 1, 2, ..., p ). Every S i and K i is followed by an empty line. However, any single newline between successive lines in a string should be ignored; that is, newlines are not part of the string. For various technical reasons, every line consists of at most 72 characters. Each key character set is given in a single line. The input is terminated by consecutive empty lines; p is not given explicitly. Output All of p problems should be solved and their answers should be output in order. However, it is not requested to print all of the shortest substrings if more than one substring is found in a problem, since found substrings may be too much to check them all. Only the number of the substrings together with their representative is requested instead. That is, for each problem i , the number of the shortest substrings should be output followed by the first (or the leftmost) shortest substring s i 1 , obeying the following format: the number of the shortest substrings for the i-th problem empty line the first line of s i1 the second line of s i1 ... the last line of s i1 empty line for the substring termination where each line of the shortest substring s i 1 except for the last line should consist of exactly 72 characters and the last line (or the single line if the substring is shorter than or equal to 72 characters, of course) should not exceed 72 characters. If there is no such substring for a problem, the output will be a 0 followed by an empty line; no more successive empty line should be output because there is no substring to be terminated. Sample Input Thefirstexampleistrivial. mfv AhugeamountofinformationisbeingheapedonWWW.Albeititisnot well-organized,userscanbrowseWWWasanunboundedsourceof up-to-dateinformation,insteadofconsultingestablishedbutalittle out-of-dateencyclopedia.However,youcanfurtherexploitWWWby learningmoreaboutkeywordsearchalgorithms.Forexample,ifyou wanttogetinformationonrecentcomparisonbetweenWindowsandUNIX, youmayexpecttogetrelevantdescriptionoutofabigbunchofWeb texts,byextractingtextsthatcontainbothkeywords"Windows"and"UNIX" closetogether. bWn 3.1415926535897932384626433832795028841971693993751058209749445923078164 pi Wagner,Bach,Beethoven,Chopin,Brahms,Hindemith,Ives,Suk,Mozart,Stravinsky Weary ASCIIcharacterssuchas+,*,[,#,<,},_arenotexcludedinagivenstringas thisexampleillustratesbyitself.Youshouldnotforgetthem.Onemorefact youshouldnoticeisthatuppercaselettersandlowercaselettersare distinguishedinthisproblem.Don'tidentify"g"and"G",forexmaple. However,weareafraidthatthisexamplegivesyoutoomuchhint! ![GsC_l ETAONRISHDLFCMUGYPWBVKXJQZ ABCDEFGHIJKLMNOPQRSTUVWXYZ Output for the Sample Input 1 firstexampleistriv 7 nWWW.Alb 0 1 Wagner,Bach,Beethoven,Chopin,Brahms,Hindemith,Ives,Suk,Mozart,Stravinsky 1 CIIcharacterssuchas+,*,[,#,<,},_arenotexcludedinagivenstringasthisexampl eillustratesbyitself.Youshouldnotforgetthem.Onemorefactyoushouldnoticeis thatuppercaselettersandlowercaselettersaredistinguishedinthisproblem.Don 'tidentify"g"and"G",forexmaple.However,weareafraidthatthisexamplegivesyo utoomuchhint! 1 ETAONRISHDLFCMUGYPWBVKXJQZ
38,193
Pipe Fitter and the Fierce Dogs You, a proud pipe fitter of ICPC (International Community for Pipe Connection), undertake a new task. The area in which you will take charge of piping work is a rectangular shape with $W$ blocks from west to east and $H$ blocks from north to south. We refer to the block at the $i$-th from west and the $j$-th from north as $(i, j)$. The westernmost and northernmost block is $(1, 1)$, and the easternmost and southernmost block is $(W,H)$. To make the area good scenery, the block $(i, j)$ has exactly one house if and only if both of $i$ and $j$ are odd numbers. Your task is to construct a water pipe network in the area such that every house in the area is supplied water through the network. A water pipe network consists of pipelines. A pipeline is made by connecting one or more pipes, and a pipeline with l pipes is constructed as follows: choose a first house, and connect the house to an underground water source with a special pipe . choose an $i$-th house ($2 \leq i \leq l$), and connect the $i$-th house to the ($i - 1$)-th house with a common pipe . In this case, there is a condition to choose a next $i$-th house because the area is slope land. Let $(x, y)$ be the block of the ($i - 1$)-th house. An $i$-th house must be located at either $(x - 2, y + 2)$, $(x, y + 2)$, or $(x + 2, y + 2)$. A common pipe connecting two houses must be located at $(x - 1, y + 1)$, $(x, y + 1)$, or $(x + 1, y + 1)$, respectively. In addition, you should notice the followings when you construct several pipelines: For each house, exactly one pipeline is through the house. Multiple pipes can be located at one block. In your task, common pipes are common, so you can use any number of common pipes. On the other hand, special pipes are special, so the number of available special pipes in this task is restricted under ICPC regulation. Besides the restriction of available special pipes, there is another factor obstructing your pipe work: fierce dogs. Some of the blocks which do not contain a house seem to be home of fierce dogs. Each dog always stays at his/her home block. Since several dogs must not live at the same block as their home, you can assume each block is home of only one dog, or not home of any dogs. The figure below is an example of a water pipe network in a 5 $\times$ 5 area with 4 special pipes. This corresponds to the first sample. Locating a common pipe at a no-dog block costs 1 unit time, but locating a common pipe at a dog-living block costs 2 unit time because you have to fight against the fierce dog. Note that when you locate multiple pipes at the same block, each pipe-locating costs 1 unit time for no-dog blocks and 2 for dog-living blocks, respectively. By the way, special pipes are very special, so locating a special pipe costs 0 unit time. You, a proud pipe fitter, want to accomplish this task as soon as possible. Fortunately, you get a list of blocks which are home of dogs. You have frequently participated in programming contests before being a pipe fitter. Hence, you decide to make a program determining whether or not you can construct a water pipe network such that every house is supplied water through the network with a restricted number of special pipes, and if so, computing the minimum total time cost to construct it. Input The input consists of a single test case. $W$ $H$ $K$ $N$ $x_1$ $y_1$ $x_2$ $y_2$ ... $x_N$ $y_N$ All numbers in a test case are integers. The first line contains three integers $W$, $H$, and $K$. $W$ and $H$ represent the size of the rectangle area. $W$ is the number of blocks from west to east ($1 \leq W < 10,000$), and $H$ is the number of blocks from north to south ($1 \leq H < 10,000$). $W$ and $H$ must be odd numbers. $K$ is the number of special pipes that you can use in this task ($1 \leq K \leq 100,000,000$). The second line has an integer $N$ ($0 \leq N \leq 100,000$), which is the number of dogs in the area. Each of the following $N$ lines contains two integers $x_i$ and $y_i$, which indicates home of the $i$-th fierce dog is the block $(x_i, y_i)$. These numbers satisfy the following conditions: $1 \leq x_i \leq W, 1 \leq y_i \leq H$. At least one of $x_i$ and $y_i$ is even number. $i \ne j$ implies $(x_i, y_i) \ne (x_j, y_j)$. That is, two or more dogs are not in the same block. Output If we can construct a water pipe network such that every house is supplied water through the network with a restricted number of special pipes, print the minimum total time cost to construct it. If not, print -1. Sample Input 1 5 5 4 6 3 2 4 2 5 2 1 4 3 4 5 4 Output for the Sample Input 1 6 Sample Input 2 5 3 1 0 Output for the Sample Input 2 -1 Sample Input 3 9 5 100 5 2 1 1 2 3 4 4 3 2 2 Output for the Sample Input 3 0 Sample Input 4 5 5 3 4 1 2 5 2 1 4 5 4 Output for the Sample Input 4 8 Sample Input 5 9 5 5 10 2 1 2 2 3 2 5 2 8 2 4 3 2 4 3 4 5 4 8 4 Output for the Sample Input 5 10
38,194
Fractional Knapsack Problem You have $N$ items that you want to put them into a knapsack of capacity $W$. Item $i$ ($1 \le i \le N$) has weight $w_i$ and value $v_i$ for the weight. When you put some items into the knapsack, the following conditions must be satisfied: The total value of the items is as large as possible. The total weight of the selected items is at most $W$. You can break some items if you want. If you put $w'$($0 \le w' \le w_i$) of item $i$, its value becomes $\displaystyle v_i \times \frac{w'}{w_i}.$ Find the maximum total value of items in the knapsack. Input $N$ $W$ $v_1$ $w_1$ $v_2$ $w_2$ : $v_N$ $w_N$ The first line consists of the integers $N$ and $W$. In the following $N$ lines, the value and weight of the $i$-th item are given. Output Print the maximum total value of the items in a line. The output must not contain an error greater than $10^{-6}$. Constraints $1 \le N \le 10^5$ $1 \le W \le 10^9$ $1 \le v_i \le 10^9 (1 \le i \le N)$ $1 \le w_i \le 10^9 (1 \le i \le N)$ Sample Input 1 3 50 60 10 100 20 120 30 Sample Output 1 240 When you put 10 of item $1$, 20 of item $2$ and 20 of item $3$, the total value is maximized. Sample Input 2 3 50 60 13 100 23 120 33 Sample Output 2 210.90909091 When you put 13 of item $1$, 23 of item $2$ and 14 of item $3$, the total value is maximized. Note some outputs can be a real number. Sample Input 3 1 100 100000 100000 Sample Output 3 100
38,195
Score: 300 points Problem Statement M-kun is a student in Aoki High School, where a year is divided into N terms. There is an exam at the end of each term. According to the scores in those exams, a student is given a grade for each term, as follows: For the first through (K-1) -th terms: not given. For each of the K -th through N -th terms: the multiplication of the scores in the last K exams, including the exam in the graded term. M-kun scored A_i in the exam at the end of the i -th term. For each i such that K+1 \leq i \leq N , determine whether his grade for the i -th term is strictly greater than the grade for the (i-1) -th term. Constraints 2 \leq N \leq 200000 1 \leq K \leq N-1 1 \leq A_i \leq 10^{9} All values in input are integers. Input Input is given from Standard Input in the following format: N K A_1 A_2 A_3 \ldots A_N Output Print the answer in N-K lines. The i -th line should contain Yes if the grade for the (K+i) -th term is greater than the grade for the (K+i-1) -th term, and No otherwise. Sample Input 1 5 3 96 98 95 100 20 Sample Output 1 Yes No His grade for each term is computed as follows: 3 -rd term: (96 \times 98 \times 95) = 893760 4 -th term: (98 \times 95 \times 100) = 931000 5 -th term: (95 \times 100 \times 20) = 190000 Sample Input 2 3 2 1001 869120 1001 Sample Output 2 No Note that the output should be No if the grade for the 3 -rd term is equal to the grade for the 2 -nd term. Sample Input 3 15 7 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 Sample Output 3 Yes Yes No Yes Yes No Yes Yes
38,196
Score : 300 points Problem Statement The problem set at CODE FESTIVAL 20XX Finals consists of N problems. The score allocated to the i -th (1≩i≩N) problem is i points. Takahashi, a contestant, is trying to score exactly N points. For that, he is deciding which problems to solve. As problems with higher scores are harder, he wants to minimize the highest score of a problem among the ones solved by him. Determine the set of problems that should be solved. Constraints 1≩N≩10^7 Partial Score 200 points will be awarded for passing the test set satisfying 1≩N≩1000 . Additional 100 points will be awarded for passing the test set without additional constraints. Input The input is given from Standard Input in the following format: N Output Among the sets of problems with the total score of N , find a set in which the highest score of a problem is minimum, then print the indices of the problems in the set in any order, one per line. If there exists more than one such set, any of them will be accepted. Sample Input 1 4 Sample Output 1 1 3 Solving only the 4 -th problem will also result in the total score of 4 points, but solving the 1 -st and 3 -rd problems will lower the highest score of a solved problem. Sample Input 2 7 Sample Output 2 1 2 4 The set \{3,4\} will also be accepted. Sample Input 3 1 Sample Output 3 1
38,197
Longest Increasing Subsequence For a given sequence A = {a 0 , a 1 , ... , a n-1 } , find the length of the longest increasing subsequnece (LIS) in A . An increasing subsequence of A is defined by a subsequence {a i 0 , a i 1 , ... , a i k } where 0 ≀ i 0 < i 1 < ... < i k < n and a i 0 < a i 1 < ... < a i k . Input n a 0 a 1 : a n-1 In the first line, an integer n is given. In the next n lines, elements of A are given. Output The length of the longest increasing subsequence of A . Constraints 1 ≀ n ≀ 100000 0 ≀ a i ≀ 10 9 Sample Input 1 5 5 1 3 2 4 Sample Output 1 3 Sample Input 2 3 1 1 1 Sample Output 2 1
38,198
Score : 100 points Problem Statement A Hitachi string is a concatenation of one or more copies of the string hi . For example, hi and hihi are Hitachi strings, while ha and hii are not. Given a string S , determine whether S is a Hitachi string. Constraints The length of S is between 1 and 10 (inclusive). S is a string consisting of lowercase English letters. Input Input is given from Standard Input in the following format: S Output If S is a Hitachi string, print Yes ; otherwise, print No . Sample Input 1 hihi Sample Output 1 Yes hihi is the concatenation of two copies of hi , so it is a Hitachi string. Sample Input 2 hi Sample Output 2 Yes Sample Input 3 ha Sample Output 3 No
38,199
D: スキャナヌ / Scanner 問題文 ここに $N$ 枚の玙がある。あなたは $3$ 台のスキャナヌを䞊列に甚いるこずで、 党おの玙をスキャンしたいず考えおいる。それぞれの玙はスキャンにかかる時間が決たっおおり、 $i$ 番目の玙をスキャンするのにかかる時間は $T_i$ である。 玙をスキャンする順番は任意であるが、$1$ 台のスキャナヌで耇数の玙を同時にスキャンするこずはできない。 党おの玙のスキャンが終了し、スキャンを行っおいるスキャナヌがなくなるたでにかかる時間を最小化しなさい。 入力 $N$ $T_1$ $T_2$ $T_3$ $\vdots$ $T_N$ 制玄 $1 \leq N \leq 50$ $1 \leq T_i \leq 50$ 入力は党お敎数 出力 答えを $1$ 行で出力しおください サンプル サンプル入力1 4 1 1 1 1 サンプル出力1 2 サンプル入力2 9 15 20 27 4 10 7 34 30 36 サンプル出力2 61 サンプル入力3 6 20 18 46 16 9 48 サンプル出力3 55
38,201
テニス ゞョり君ずダ゚さんは昌䌑みにテニスをしたす。ただし、昌䌑みは時間が限られおいるので、短い時間で終わるように、埗点に぀いお以䞋の぀のルヌルで行いたす。 盞手が点以䞋のずきに先に点ずれば勝ち。 察の同点になったずきは、その盎埌に連続しお点ずった方が勝ち。 察の埌に双方が点ず぀ずったずきは匕き分け。 以䞋の図は、ゞョり君ずダ゚さんの詊合で起こり埗るすべおの状況を衚しおいたす。䞞の䞭の巊の数がゞョり君の埗点、右がダ゚さんの埗点です。ず曞いた矢印はゞョり君が点ずったこずを、ず曞いた矢印はダ゚さんが点ずったこずを衚したす。 ゞョり君ずダ゚さんの埗点が䞎えられたずき、詊合開始からその埗点状況になるたでに、䞊の図で通り埗るすべおの経路を列挙するプログラムを䜜成しおください。 入力 入力は぀のデヌタセットからなる。入力デヌタは以䞋の圢匏で䞎えられる。 j y j (0 ≀ j ≀ 6) がゞョり君の埗点、 y (0 ≀ y ≀ 6) がダ゚さんの埗点である。ただし、 j ず y がずもに 0 であるこずはない。たた、 j が 6 のずきは y は 4、 y が 6 のずきは j は 4 である。 出力 䞊の図で、詊合開始0-0ず曞かれた䞞から䞎えられた埗点が曞かれた䞞たでのすべおの経路を出力する。経路は図の矢印に添えられた英字(A,B)の列で衚し、蟞曞匏順序英和蟞曞で単語が䞊んでいる順番になるように䞊べる。぀の経路を行に出力する。経路の前埌には空癜を出力しない。 入出力䟋 入力䟋1 2 2 出力䟋1 AABB ABAB ABBA BAAB BABA BBAA 入力䟋2 5 1 出力䟋2 AAAABA AAABAA AABAAA ABAAAA BAAAAA
38,202
Score : 100 points Problem Statement You are given an integer N . Consider an infinite N -ary tree as shown below: Figure: an infinite N -ary tree for the case N = 3 As shown in the figure, each vertex is indexed with a unique positive integer, and for every positive integer there is a vertex indexed with it. The root of the tree has the index 1 . For the remaining vertices, vertices in the upper row have smaller indices than those in the lower row. Among the vertices in the same row, a vertex that is more to the left has a smaller index. Regarding this tree, process Q queries. The i -th query is as follows: Find the index of the lowest common ancestor (see Notes) of Vertex v_i and w_i . Notes In a rooted tree, the lowest common ancestor (LCA) of Vertex v and w is the farthest vertex from the root that is an ancestor of both Vertex v and w . Here, a vertex is considered to be an ancestor of itself. For example, in the tree shown in Problem Statement, the LCA of Vertex 5 and 7 is Vertex 2 , the LCA of Vertex 8 and 11 is Vertex 1 , and the LCA of Vertex 3 and 9 is Vertex 3 . Constraints 1 ≀ N ≀ 10^9 1 ≀ Q ≀ 10^5 1 ≀ v_i < w_i ≀ 10^9 Input Input is given from Standard Input in the following format: N Q v_1 w_1 : v_Q w_Q Output Print Q lines. The i -th line (1 ≀ i ≀ Q) must contain the index of the lowest common ancestor of Vertex v_i and w_i . Sample Input 1 3 3 5 7 8 11 3 9 Sample Output 1 2 1 3 The queries in this case correspond to the examples shown in Notes. Sample Input 2 100000 2 1 2 3 4 Sample Output 2 1 1
38,203
Score : 200 points Problem Statement You have written N problems to hold programming contests. The i -th problem will have a score of P_i points if used in a contest. With these problems, you would like to hold as many contests as possible under the following condition: A contest has three problems. The first problem has a score not greater than A points, the second has a score between A + 1 and B points (inclusive), and the third has a score not less than B + 1 points. The same problem should not be used in multiple contests. At most how many contests can be held? Constraints 3 \leq N \leq 100 1 \leq P_i \leq 20 ( 1 \leq i \leq N ) 1 \leq A < B < 20 All values in input are integers. Input Input is given from Standard Input in the following format: N A B P_1 P_2 ... P_N Output Print the answer. Sample Input 1 7 5 15 1 10 16 2 7 20 12 Sample Output 1 2 Two contests can be held by putting the first, second, third problems and the fourth, fifth, sixth problems together. Sample Input 2 8 3 8 5 5 5 10 10 10 15 20 Sample Output 2 0 No contest can be held, because there is no problem with a score of A = 3 or less. Sample Input 3 3 5 6 5 6 10 Sample Output 3 1
38,204
Problem F: RabbitLunch うさぎは昌食ににんじんずキりむを1 個ず぀食べる. うさぎはずおも個性的なので, 食べるにんじんの皮類もキりむの皮類も同じであるような, 異なる2 匹のうさぎが存圚しおはならない. にんじんは $M$ 皮類ある. $i$ 皮類目のにんじんは $m_i$ 個ある. キりむは $N$ 皮類ある. $i$ 皮類目のキりむは $n_i$ 個ある. 最倧䜕匹のうさぎが昌食をずれるか求めよ. $m_i$ ず $n_i$ は次の挞化匏を甚いお生成せよ. $m_0 = m0$ $m_{i+1} = (m_i * 58 + md )$ mod $(N + 1)$ $n_0 = n0$ $n_{i+1} = (n_i * 58 + nd )$ mod $(M + 1)$ Constraints $M$ will be between 1 and 2,500,000, inclusive. $N$ will be between 1 and 2,500,000, inclusive. $m0$ and $md$ will be between 0 and $N$, inclusive. $n0$ and $nd$ will be between 0 and $M$, inclusive. Input 入力は以䞋の圢匏で䞎えられる: $M$ $N$ $m0$ $md$ $n0$ $nd$ Output 昌食をずれるうさぎの匹数の最倧倀を衚す敎数を 1 行に出力せよ. Sample Input 1 2 3 1 3 1 0 Sample Output 1 2 Sample Input 2 5 8 1 2 3 4 Sample Output 2 19
38,205
Problem A Secret of Chocolate Poles Wendy, the master of a chocolate shop, is thinking of displaying poles of chocolate disks in the showcase. She can use three kinds of chocolate disks: white thin disks, dark thin disks, and dark thick disks. The thin disks are $1$ cm thick, and the thick disks are $k$ cm thick. Disks will be piled in glass cylinders. Each pole should satisfy the following conditions for her secret mission, which we cannot tell. A pole should consist of at least one disk. The total thickness of disks in a pole should be less than or equal to $l$ cm. The top disk and the bottom disk of a pole should be dark. A disk directly upon a white disk should be dark and vice versa. As examples, six side views of poles are drawn in Figure A.1. These are the only possible side views she can make when $l = 5$ and $k = 3$. Figure A.1. Six chocolate poles corresponding to Sample Input 1 Your task is to count the number of distinct side views she can make for given $l$ and $k$ to help her accomplish her secret mission. Input The input consists of a single test case in the following format. $l$ $k$ Here, the maximum possible total thickness of disks in a pole is $l$ cm, and the thickness of the thick disks is $k$ cm. $l$ and $k$ are integers satisfying $1 \leq l \leq 100$ and $2 \leq k \leq 10$. Output Output the number of possible distinct patterns. Sample Input 1 5 3 Sample Output 1 6 Sample Input 2 9 10 Sample Output 2 5 Sample Input 3 10 10 Sample Output 3 6 Sample Input 4 20 5 Sample Output 4 86 Sample Input 5 100 2 Sample Output 5 3626169232670
38,207
Problem L: The Return of FizzBuzz ICPC World Finals 7日目 いよいよ明日はICPC World Finalsの本番である。 ティヌ氏はあるオンラむンゞャッゞ(Aru Online Judge)で緎習をするこずにした。 問題䞀芧を眺めおいるずFizzBuzzずいう問題が目に぀いた。 この問題は、FizzBuzzゲヌムで埗られる発蚀のn文字目から20文字を出力するずいうものだ。  ふぅ。あっずいう間に解けおしたった。 これでは簡単すぎた。 入力ず出力を逆にした問題を䜜っおみるこずにしよう。 問題 FizzBuzzずは、1以䞊の敎数を順に、以䞋のルヌルに埓っお発蚀しおいくゲヌムである。 3で割り切れる時には「Fizz」 5で割り切れる時には「Buzz」 3ず5の䞡方で割り切れる時には「FizzBuzz」 それ以倖の時はその数字 ゲヌムの進行状況を以䞋に瀺す。 1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 
 埗られた発蚀を結合するこずで埗られる無限長の文字列をFizzBuzz Stringず呌ぶ。 ある文字列\(s\)が䞎えられる。 \(s\)がFizzBuzz Stringの郚分文字列ずしお出珟するかを刀定し、 出珟する堎合には最初に出珟するむンデックスを求めよ。 入力 n s 1 s 2 
 s n 入力は耇数のテストケヌスからなる。 1行目にテストケヌス数\(n\)が䞎えられる。 2行目から\( n+1 \)行目は各テストケヌスに察応し、 文字列\( s_{i} \)が1行で䞎えられる。 出力 \(i\)番目の文字列\( s_{i} \)に぀いお、 \( s_{i} \)がFizzBuzz Stringの郚分文字列ずしお出珟する堎合には最初に出珟するむンデックスを(1-indexで)、 出珟しない堎合には"-1"を\(i\)行目に出力せよ。 制玄 \( 1 \leq n \leq 20 \) 文字列は文字\( \{ 0,1,\cdots,8,9 ,\mbox{F},\mbox{B},\mbox{i},\mbox{u},\mbox{z} \} (1 \leq i \leq n) \)からなる。 文字列の長さは1以䞊15以䞋である。 入出力䟋 入力1 6 78Fizz 98FizzBuzz101 FizzBu izzFiz 111111111111111 123456789 出力1 16 304 18 -1 7703703700 7795884765 入力䟋は6぀のテストケヌスからなる。 それぞれ以䞋の発蚀に察応する。 
, Buzz, Fizz, 7, 8, Fizz, Buzz, 
 
, Fizz, 97, 98, Fizz, Buzz, 101, Fizz, 
 
, 7, 8, Fizz, Buzz, 11, 12, 
 存圚しない 
, 1111111109, FizzBuzz, 1111111111, 1111111112, Fizz, 1111111114, 
 
, 1123456787, Fizz, 1123456789, Buzz, Fizz, 

38,208
Score : 1100 points Problem Statement We will call a string that can be obtained by concatenating two equal strings an even string. For example, xyzxyz and aaaaaa are even, while ababab and xyzxy are not. For a non-empty string S , we will define f(S) as the shortest even string that can be obtained by appending one or more characters to the end of S . For example, f( abaaba )= abaababaab . It can be shown that f(S) is uniquely determined for a non-empty string S . You are given an even string S consisting of lowercase English letters. For each letter in the lowercase English alphabet, find the number of its occurrences from the l -th character through the r -th character of f^{10^{100}} (S) . Here, f^{10^{100}} (S) is the string f(f(f( ... f(S) ... ))) obtained by applying f to S 10^{100} times. Constraints 2 \leq |S| \leq 2\times 10^5 1 \leq l \leq r \leq 10^{18} S is an even string consisting of lowercase English letters. l and r are integers. Input Input is given from Standard Input in the following format: S l r Output Print 26 integers in a line with spaces in between. The i -th integer should be the number of the occurrences of the i -th letter in the lowercase English alphabet from the l -th character through the r -th character of f^{10^{100}} (S) . Sample Input 1 abaaba 6 10 Sample Output 1 3 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Since f( abaaba )= abaababaab , the first ten characters in f^{10^{100}}(S) is also abaababaab . Thus, the sixth through the tenth characters are abaab . In this string, a appears three times, b appears twice and no other letters appear, and thus the output should be 3 and 2 followed by twenty-four 0 s. Sample Input 2 xx 1 1000000000000000000 Sample Output 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000000000000000000 0 0 Sample Input 3 vgxgpuamkvgxgvgxgpuamkvgxg 1 1000000000000000000 Sample Output 3 87167725689669676 0 0 0 0 0 282080685775825810 0 0 0 87167725689669676 0 87167725689669676 0 0 87167725689669676 0 0 0 0 87167725689669676 141040342887912905 0 141040342887912905 0 0
38,209
Score : 700 points Problem Statement N hotels are located on a straight line. The coordinate of the i -th hotel (1 \leq i \leq N) is x_i . Tak the traveler has the following two personal principles: He never travels a distance of more than L in a single day. He never sleeps in the open. That is, he must stay at a hotel at the end of a day. You are given Q queries. The j -th (1 \leq j \leq Q) query is described by two distinct integers a_j and b_j . For each query, find the minimum number of days that Tak needs to travel from the a_j -th hotel to the b_j -th hotel following his principles. It is guaranteed that he can always travel from the a_j -th hotel to the b_j -th hotel, in any given input. Constraints 2 \leq N \leq 10^5 1 \leq L \leq 10^9 1 \leq Q \leq 10^5 1 \leq x_i < x_2 < ... < x_N \leq 10^9 x_{i+1} - x_i \leq L 1 \leq a_j,b_j \leq N a_j \neq b_j N,\,L,\,Q,\,x_i,\,a_j,\,b_j are integers. Partial Score 200 points will be awarded for passing the test set satisfying N \leq 10^3 and Q \leq 10^3 . Input The input is given from Standard Input in the following format: N x_1 x_2 ... x_N L Q a_1 b_1 a_2 b_2 : a_Q b_Q Output Print Q lines. The j -th line (1 \leq j \leq Q) should contain the minimum number of days that Tak needs to travel from the a_j -th hotel to the b_j -th hotel. Sample Input 1 9 1 3 6 13 15 18 19 29 31 10 4 1 8 7 3 6 7 8 5 Sample Output 1 4 2 1 2 For the 1 -st query, he can travel from the 1 -st hotel to the 8 -th hotel in 4 days, as follows: Day 1 : Travel from the 1 -st hotel to the 2 -nd hotel. The distance traveled is 2 . Day 2 : Travel from the 2 -nd hotel to the 4 -th hotel. The distance traveled is 10 . Day 3 : Travel from the 4 -th hotel to the 7 -th hotel. The distance traveled is 6 . Day 4 : Travel from the 7 -th hotel to the 8 -th hotel. The distance traveled is 10 .
38,210
Problem I: Pythagoraslope Alice, your girlfriend, is a student at an art school. She is in the final year, and now working hard to build a facture for fulfilling the requirement to graduate. Her work is a large pinball with many straight slopes. Before starting to build, she has made several plans, but is unsure if they work as expected. So she asked you, a professional programmer, for help. You have modeled this situation by a two dimensional plane with some line segments on it. In this model, there is gravitation downward, i.e., in the decreasing direction of y -coordinate. Your task is to write a program that simulates the pinball, and compute the last position where the ball crosses the x -axis. You may assume coefficient of restitution between the slopes and the ball is 0, i.e., when the ball collides a slope, it instantly loses the velocity component orthogonal to the slope. And since her pinball is so large, you may also assume that the volume of the ball is negligible. Input The input consists of multiple data sets. Each data set is given in the format below. N g x y x 1,1 y 1,1 x 1,2 y 1,2 ... x N ,1 y N ,1 x N ,2 y N ,2 where N ( N ≀ 100) is the number of slopes, g is gravity acceleration, and ( x , y ) is the initial position of the ball. Each of the following N lines represents a slope, which is a line segment between ( x i ,1 , y i ,1 ) and ( x i ,2 , y i ,2 ). You may assume that: all coordinates are more than or equal to 1, and less than or equal to 10,000; x i ,1 ≠ x i ,2 and y i ,1 ≠ y i ,2 for all 1 ≀ i ≀ N ; no two line segments cross each other; extending or shrinking a slope by the length of 0.0001 does not change the ball’s trail, that is, do not change the set of slopes where the ball passes; the ball never collides to a slope at the angle of 90 ± 0.0001 degrees from the slope; and the initial position of the ball never lies on any slope. The end of the input is indicated by a line containing a single zero. This is not a part of the data sets, and you must not process it. Output For each data set, output the x -coordinate of the final crossing point of the ball’s trail and the x -axis. Your program may print any number of digits after the decimal point, but the output must not contain an error greater than 10 -4 (= 0.0001). Sample Input 3 1 120 1000 100 100 180 20 170 10 270 30 270 40 400 20 0 Output for the Sample Input 403.87458314
38,211
Score : 200 points Problem Statement In the beginning, Takahashi has A cookies, and Aoki has B cookies. They will perform the following operation alternately, starting from Takahashi: If the number of cookies in his hand is odd, eat one of those cookies; if the number is even, do nothing. Then, give one-half of the cookies in his hand to the other person. Find the numbers of cookies Takahashi and Aoki respectively have after performing K operations in total. Constraints 1 \leq A,B \leq 10^9 1 \leq K \leq 100 A,B and K are integers. Input Input is given from Standard Input in the following format: A B K Output Print the number of cookies Takahashi has, and the number of cookies Aoki has, in this order, after performing K operations in total. Sample Input 1 5 4 2 Sample Output 1 5 3 The process will go as follows: In the beginning, Takahashi and Aoki have 5 and 4 cookies, respectively. Takahashi eats one cookie and gives two cookies to Aoki. They now have 2 and 6 cookies, respectively. Aoki gives three cookies to Takahashi. They now have 5 and 3 cookies, respectively. Sample Input 2 3 3 3 Sample Output 2 1 3 Sample Input 3 314159265 358979323 84 Sample Output 3 448759046 224379523
38,212
Score : 2200 points Problem Statement You are given positions (X_i, Y_i) of N enemy rooks on an infinite chessboard. No two rooks attack each other (at most one rook per row or column). You're going to replace one rook with a king and then move the king repeatedly to beat as many rooks as possible. You can't enter a cell that is being attacked by a rook. Additionally, you can't move diagonally to an empty cell (but you can beat a rook diagonally). (So this king moves like a superpawn that beats diagonally in 4 directions and moves horizontally/vertically in 4 directions.) For each rook, consider replacing it with a king, and find the minimum possible number of moves needed to beat the maximum possible number of rooks. Constraints 2 \leq N \leq 200\,000 1 \leq X_i, Y_i \leq 10^6 X_i \neq X_j 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_2 Y_2 \vdots X_N Y_N Output Print N lines. The i -th line is for scenario of replacing the rook at (X_i, Y_i) with your king. This line should contain one integer: the minimum number of moves to beat M_i rooks where M_i denotes the maximum possible number of beaten rooks in this scenario (in infinite time). Sample Input 1 6 1 8 6 10 2 7 4 4 9 3 5 1 Sample Output 1 5 0 7 5 0 0 See the drawing below. If we replace rook 3 with a king, we can beat at most two other rooks. The red path is one of optimal sequences of moves: beat rook 1, then keep going down and right until you can beat rook 4. There are 7 steps and that's the third number in the output. x-coordinate increases from left to right, while y increases bottom to top. Starting from rook 2, 5 or 6, we can't beat any other rook. The optimal number of moves is 0. Sample Input 2 5 5 5 100 100 70 20 81 70 800 1 Sample Output 2 985 985 1065 1034 0 Sample Input 3 10 2 5 4 4 13 12 12 13 14 17 17 19 22 22 16 18 19 27 25 26 Sample Output 3 2 2 9 9 3 3 24 5 0 25
38,213
Problem Statement You are given a list of $N$ intervals. The $i$-th interval is $[l_i, r_i)$, which denotes a range of numbers greater than or equal to $l_i$ and strictly less than $r_i$. In this task, you consider the following two numbers: The minimum integer $x$ such that you can select $x$ intervals from the given $N$ intervals so that the union of the selected intervals is $[0, L)$. The minimum integer $y$ such that for all possible combinations of $y$ intervals from the given $N$ interval, it does cover $[0, L)$. We ask you to write a program to compute these two numbers. Input The input consists of a single test case formatted as follows. $N$ $L$ $l_1$ $r_1$ $l_2$ $r_2$ $\vdots$ $l_N$ $r_N$ The first line contains two integers $N$ ($1 \leq N \leq 2 \times 10^5$) and $L$ ($1 \leq L \leq 10^{12}$), where $N$ is the number of intervals and $L$ is the length of range to be covered, respectively. The $i$-th of the following $N$ lines contains two integers $l_i$ and $r_i$ ($0 \leq l_i < r_i \leq L$), representing the range of the $i$-th interval $[l_i, r_i)$. You can assume that the union of all the $N$ intervals is $[0, L)$ Output Output two integers $x$ and $y$ mentioned in the problem statement, separated by a single space, in a line. Examples Input Output 3 3 0 2 1 3 1 2 2 3 2 4 0 4 0 4 1 1 5 4 0 2 2 4 0 3 1 3 3 4 2 4
38,214
小数䜍の和 a , b , n は、いずれも正の敎数であるずしたす。分数 a / b の小数第 i 䜍の数を f(i) ずしたす (0 ≀ f(i) ≀ 9)。このずき、 i = 1 から n たでの f(i) の和を s ずしたす。 s = f(1) + f(2) + ... + f(n) a , b , n を読み蟌んで、 s を出力しお終了するプログラムを䜜成しおください。 Input 入力は耇数のデヌタセットからなりたす。各デヌタセットずしお、3 ぀の敎数 a (1 ≀ a ≀ 1000), b (1 ≀ b ≀ 10000), n (1 ≀ n ≀ 100) が空癜区切りで行に䞎えられたす。 デヌタセットの数は 100 を超えたせん。 Output デヌタセットごずに、 s を行に出力したす。 Sample Input 1 2 3 2 3 4 5 4 3 4 3 2 Output for the Sample Input 5 24 7 6
38,215
Min-Max For given three integers $a, b, c$, print the minimum value and the maximum value. Input The input is given in the following format. $a \; b \; c\;$ Three integers $a, b, c$ are given in a line. Output Print the minimum and maximum values separated by a space in a line. Constraints $-1,000,000,000 \leq a, b, c \leq 1,000,000,000$ Sample Input 1 4 5 3 Sample Output 1 3 5
38,216
床 ヒデペ博士の家の床には正方圢のタむルが敷き぀められおいたす。芞術に造詣が深いヒデペ博士は、赀、黄、青の塗料を䜿っおタむルに色を塗るこずにしたした。はじめに郚屋の適圓なタむルをひず぀遞び、以䞋の方法で色を塗っおいきたす。 タむルを塗る色を、赀図の番号、黄図の番号、青図の番号の順に倉えおいき、青の次はたた赀から始める。 すでに色を塗った領域の隣に正方圢を远加し、そこに色を塗る。それらを合わせた領域が長方圢になるようにする。正方圢を远加する方向は、東、北、西、南の順に倉えおいき、南の次はたた東から始める図では、䞊方向が北、右方向が東である。 最初に赀く塗ったタむルから東西方向に$x$個、南北方向に$y$個移動したずころにあるタむルは、䜕色に塗られおいるでしょうか。ただし、東の方向を$x$の正の方向、北の方向を$y$の正の方向ずしたす。 $x$ず$y$を入力し、タむルの色を出力するプログラムを䜜成せよ。 入力 入力は以䞋の圢匏で䞎えられる。 $x$ $y$ 行に$x$ず$y$ ($-10^6 \leq x,y \leq 10^6$)が䞎えられる。 出力 タむルの色が赀のずき1、黄のずき2、青のずき3を行に出力する。 入出力䟋 入力䟋 0 0 出力䟋 1 入力䟋 -4 5 出力䟋 2 入力䟋 8 -14 出力䟋 3
38,217
博士の暗号 博 士 : ?D-C'KOPUA ピヌタヌ : どうしたんですか、デビッド博士? わけのわからないこずを叫ぶのにはもう慣れたしたが、 今日は文章にすらなっおいたせんよ。 博 士 : ほれ。 ピヌタヌ : なんですか? この衚は......ああ、予遞の問題にこんなのがありたした。衚を䜿っお文字を眮き換え るず文字数が枛るんですよね。たさか予遞ず本遞で同じ問題を出しお手を抜こうっお気じゃないでし ょうね。 博 士 : 逆じゃよ。 ピヌタヌ : 逆? なるほど、今床は短くした文字列を元に戻そうっお問題ですか。ずいうこずは「?D-C'KOPUA」の 文字を、この衚を䜿っお「文字」から「笊号」に眮きかえるんですね......できたしたよ。 11111 00011 11101 00010 11110 01010 01110 01111 10100 00000 博 士 : うむ。次はこれじゃ。 ピヌタヌ : そうそう、こんな衚もありたしたね。これを逆に䜿うんだから「笊号」から「文字」に眮き換えればいい んですね。でも、最初は「11111」ですが衚にありたせんよ? 博 士 : そういうずきは、もっず短くするか、埌ろず぀なげるかしおみるのだよ。 ピ ヌ タ ヌ : じゃあ短くしお......あ、 「111」ならありたす。じゃあ最初は「P」ですね。そうするず残りは「11」ですが、 これはぎったり合うのがないから次の「00011」から 1 文字借りお「110」にすればいいんですね。 博 士 : そうそう。぀たり「E」だね。 ピ ヌ タ ヌ : それで残るのが「0011」なので、これも次から借りお「00111」にしお「T」ず......。党郚できたした。最 埌の「0000」は捚おちゃえばいいんですよね? 博 士 : そうじゃ、よろしい。次はこれじゃ。 ?D-C'?-C'-LMGZN?FNJKN- WEYN?P'QMRWLPZLKKTPOVRGDI 博 士 : さらにこれじゃ。 ?P'QNPY?IXX?IXXK.BI -G?R'RPP'RPOVWDMW?SWUVG'-LCMGQ 博 士 : 仕䞊げにこうじゃ。 ?P'QMDUEQ GADKOQ ?SWUVG'-LCMG?X?IGX,PUL.?UL.VNQQI ピ ヌ タ ヌ : しっかし面倒だなあ。博士、今床は自分でプログラムを䜜っお䞋さいよ。 ずいうこずで、博士のかわりに、䞊の文章を眮き換えるプログラムを䜜成しおください。 Input 耇数のデヌタセットが䞎えられたす。各デヌタセットずしお、぀の文字列衚に含たれる文字からなる 200 文字以䞋の文字列が行に䞎えられたす。入力の終わりたで凊理しおください。デヌタセットの数は 200 を超えたせん。 Output 各デヌタセットごずに、倉換埌の文字列を行に出力しおください。 Sample Input ?D-C'KOPUA Output for the Sample Input PETER POTTER
38,218
城壁 (Rampart) 歎史孊者である JOI 教授はか぀お存圚した IOI 王囜に぀いお研究しおいる 過去の調査によるずIOI 王囜は瞊 H 行暪 W 列のマスに区切られた長方圢の圢をしおいたIOI 王囜の銖郜は防衛のために城壁で囲われおいた IOI 王囜の銖郜を囲う城壁は次のような圢をしおいる城壁には倧きさず呌ばれる倀が定たっおいる倧きさ s ( s ≥ 3) の城壁ずは s × s の正方圢の領域から倖呚以倖の ( s − 2) × ( s − 2) の正方圢の領域を陀いたものである 調査によるず銖郜を囲う城壁の倧きさは L 以䞊であったたたIOI 王囜のいく぀かのマスには城壁が存圚しなかったこずがわかっおいる JOI 教授はさらなる研究のために城壁ずしおありうるものが䜕通りあるかを知りたい 課題 IOI 王囜の倧きさず城壁の倧きさの最小倀城壁が存圚しなかったこずが分かっおいるマスの情報が䞎えられたずき城壁ずしおありうるものは䜕通りあるかを求めるプログラムを䜜成せよ 入力 暙準入力から以䞋のデヌタを読み蟌め 1 行目には敎数 H , W , L , P が空癜を区切りずしお曞かれおいるこれはIOI 王囜は瞊 H 行暪 W 列のマスに区切られた長方圢の圢をしおおり城壁の倧きさは L 以䞊であり城壁が存圚しなかったこずがわかっおいるマスが P マス存圚するこずを衚す 続く P 行のうちの i 行目 (1 ≀ i ≀ P ) には敎数 A i , B i が空癜を区切りずしお曞かれおいるこれはIOI 王囜の䞊から A i 行目巊から B i 列目のマスには城壁が存圚しなかったこずがわかっおいるこずを衚す 出力 暙準出力に城壁ずしおありうるものは䜕通りあるかを衚す敎数を 1 行で出力せよ. 制限 すべおの入力デヌタは以䞋の条件を満たす 1 ≀ H ≀ 4 000 1 ≀ W ≀ 4 000 3 ≀ L ≀ H か぀ 3 ≀ L ≀ W  0 ≀ P ≀ 100 000 1 ≀ A i ≀ H (1 ≀ i ≀ P ) 1 ≀ B i ≀ W (1 ≀ i ≀ P ) ( A i , B i ) ≠ ( A j , B j ) (1 ≀ i < j ≀ P ) 入出力䟋 入力䟋 1 5 5 3 2 2 2 4 3 出力䟋 1 4 この入力䟋の堎合城壁ずしおありうるものは以䞋の 4 通りが考えられるただし× で瀺したマスは城壁が存圚しなかったこずがわかっおいるマスである 入力䟋 2 7 8 4 3 2 2 3 7 6 5 出力䟋 2 13 入力䟋 3 4000 4000 1234 4 1161 3028 596 1892 3731 2606 702 1530 出力䟋 3 7050792912 問題文ず自動審刀に䜿われるデヌタは、 情報オリンピック日本委員䌚 が䜜成し公開しおいる問題文ず採点甚テストデヌタです。
38,219
I: Palindrome Compliment 問題文 小池くんはチヌムメむトをよく耒めたす。 圌はチヌムメむトである束厎くんを文字列 $S$ で耒めたす。その圢匏は以䞋の条件を満たしたす。 $Hoge, Zaki, O$ は小文字アルファベットのみからなる文字列 $S = Hoge + Zaki + Hoge + O$ ($+$ は文字列の結合を衚す) $S$ は回文 小池くんは$Hoge$の長さを$N$ずしたずきに、束厎くんの耒め方が䜕通りあるのか気になりたした。 3人目のチヌムメンバヌにしおred coderであるあなたは小池くんの代わりに答えを蚈算するこずになりたした。 文字列 $Zaki, O$ ず 敎数 $N$ が䞎えられるので、ありえる組み合わせの数を求めおください なお、答えは非垞に倧きくなる可胜性があるので、$10^9 + 7$ で割った 䜙りを出力しおください。 制玄 $Zaki$ ず $O$ は小文字アルファベットからなる文字列 $1 \leq |Zaki| \leq 10^5$ $1 \leq |O| \leq 10^5$ $1 \leq N \leq 10^9$ 入力 入力は以䞋の圢匏で暙準入力から䞎えられたす。 $Zaki$ $O$ $N$ 出力 答えを1行に出力しおください。 入出力䟋 入力䟋1 zaki o 4 出力䟋1 0 入力䟋2 aab aa 3 出力䟋2 26 入力䟋3 aaa aaaa 3 出力䟋3 1
38,220
Problem B: Equals are Equals Mr. Simpson got up with a slight feeling of tiredness. It was the start of another day of hard work. A bunch of papers were waiting for his inspection on his desk in his office. The papers contained his students' answers to questions in his Math class, but the answers looked as if they were just stains of ink. His headache came from the ``creativity'' of his students. They provided him a variety of ways to answer each problem. He has his own answer to each problem, which is correct, of course, and the best from his aesthetic point of view. Some of his students wrote algebraic expressions equivalent to the expected answer, but many of them look quite different from Mr. Simpson's answer in terms of their literal forms. Some wrote algebraic expressions not equivalent to his answer, but they look quite similar to it. Only a few of the students' answers were exactly the same as his. It is his duty to check if each expression is mathematically equivalent to the answer he has prepared. This is to prevent expressions that are equivalent to his from being marked as ``incorrect'', even if they are not acceptable to his aesthetic moral. He had now spent five days checking the expressions. Suddenly, he stood up and yelled, ``I've had enough! I must call for help.'' Your job is to write a program to help Mr. Simpson to judge if each answer is equivalent to the ``correct'' one. Algebraic expressions written on the papers are multi-variable polynomials over variable symbols a , b ,..., z with integer coefficients, e.g., ( a + b 2 )( a - b 2 ), ax 2 +2 bx + c and ( x 2 +5 x + 4)( x 2 + 5 x + 6) + 1. Mr. Simpson will input every answer expression as it is written on the papers; he promises you that an algebraic expression he inputs is a sequence of terms separated by additive operators ` + ' and ` - ', representing the sum of the terms with those operators, if any; a term is a juxtaposition of multiplicands, representing their product; and a multiplicand is either (a) a non-negative integer as a digit sequence in decimal, (b) a variable symbol (one of the lowercase letters ` a ' to ` z '), possibly followed by a symbol ` ^ ' and a non-zero digit, which represents the power of that variable, or (c) a parenthesized algebraic expression, recursively. Note that the operator ` + ' or ` - ' appears only as a binary operator and not as a unary operator to specify the sing of its operand. He says that he will put one or more space characters before an integer if it immediately follows another integer or a digit following the symbol ` ^ '. He also says he may put spaces here and there in an expression as an attempt to make it readable, but he will never put a space between two consecutive digits of an integer. He remarks that the expressions are not so complicated, and that any expression, having its ` - 's replaced with ` + 's, if any, would have no variable raised to its 10th power, nor coefficient more than a billion, even if it is fully expanded into a form of a sum of products of coefficients and powered variables. Input The input to your program is a sequence of blocks of lines. A block consists of lines, each containing an expression, and a terminating line. After the last block, there is another terminating line. A terminating line is a line solely consisting of a period symbol. The first expression of a block is one prepared by Mr. Simpson; all that follow in a block are answers by the students. An expression consists of lowercase letters, digits, operators ` + ', ` - ' and ` ^ ', parentheses ` ( ' and ` ) ', and spaces. A line containing an expression has no more than 80 characters. Output Your program should produce a line solely consisting of `` yes '' or `` no '' for each answer by the students corresponding to whether or not it is mathematically equivalent to the expected answer. Your program should produce a line solely containing a period symbol after each block. Sample Input a+b+c (a+b)+c a- (b-c)+2 . 4ab (a - b) (0-b+a) - 1a ^ 2 - b ^ 2 2 b 2 a . 108 a 2 2 3 3 3 a 4 a^1 27 . . Output for the Sample Input yes no . no yes . yes yes .
38,221
ゎルフ クロセは超䞀流の腕を持ったバトルプログラマヌでありプログラミングコンテスト界隈でその名を知らぬ者はいない アルゎリズムデヌタマむニングハッキングAI  ありずあらゆる倧䌚を総なめにしおきた そんなクロセが次の目暙に据えた競技は「コヌドゎルフ」である コヌドゎルフずは䞎えられた問題に察し正答を返すプログラムの「゜ヌスコヌドの短さ」を競う競技である コヌドゎルフにおいおは異なるプログラミング蚀語間で公平な比范が難しいため䜿甚蚀語が限定されるこずが倚い クロセが次に狙っおいる倧䌚「ICPC (International Competition of Program Compactness)」では 「AJAGOL」ず呌ばれるプログラミング蚀語のみが䜿甚できるルヌルずなっおいる コヌドを1バむトでも短くするためクロセが初めに泚目したのは「定数宣蚀」の短瞮だった AJAGOLはいにしえの36bitアヌキテクチャに最適化しお蚭蚈された䌝統ある蚀語である 敎数を衚珟するために36bit笊号無し敎数型が甚意されおおり$0$ 以䞊 $2^{36}-1$ 以䞋の敎数を扱うこずができる さおAJAGOLの定数は通垞数字[0-9]を任意の個数甚いた十進数で宣蚀される たた挔算子ずしお以䞋の衚の挔算子を甚いるこずができる 優先順䜍 挔算子 結合性 意味 1 ( , ) - 括匧 2 ^ 右結合 冪乗: a^b := $a^b$ 3 * 巊結合 乗算: a*b := $a \times b$ 3 / 巊結合 陀算: a/b := $ \lfloor a \div b \rfloor$ 4 + 巊結合 加算: a+b := $a + b$ 4 - 巊結合 枛算: a-b := $a - b$ ここで優先順䜍の倀が小さい挔算ほど優先的に蚈算され同じ倀のずきには結合性に埓った順序で蚈算される 䟋えば " 2^2^3+8/3*2 " ずいう蚈算匏は2^2^3+8/3*2 = 2^8+8/3*2 = 256+8/3*2 = 256+2*2 = 256+4 = 260 ずいう順序で蚈算される たた挔算途䞭の倀が $[0, 2^{36}-1]$ に収たらない蚈算やれロ陀算れロのれロ乗はAJAGOLでは実行時゚ラヌずなるため避ける必芁がある 䟋えば " 2^36-100 "" 1111/0 "" (2-2)^0 " などは実行時゚ラヌずなる 超䞀流のバトルプログラマヌであるクロセはこれらの挔算子を甚いるこずにより通垞よりも短い定数宣蚀が可胜であるこずを芋抜いた 䟋えば117649は蚀わずず知れた $7^6$ であるがAJAGOLの冪乗挔算子を甚いるこずで " 7^6 " ず3バむトで曞くこずができる これは通垞の " 117649 " ずいう宣蚀で必芁ずなる6バむトよりも3バむト短い よっおAJAGOLによるコヌドゎルフでは117649を定数ずしお甚いたい堎合には " 7^6 " ず宣蚀するのが基本ずなる 定数宣蚀の短瞮はコヌドゎルフにおいお最も基本的なテクニックの1぀であるがあくたで小手先のテクニックずも蚀える このようなずころに倚倧な時間を掛けおいおは本質的なコヌドの短瞮に時間を割けなくなっおしたう そこでクロセは非負敎数を十進数で入力したずきそれを衚珟するAJAGOL定数宣蚀ずしお最も短いものを調べるこずにした Input 入力は耇数のデヌタセットからなる 各デヌタセットは敎数 $N$ ($0 \leq N \leq 2^{36}-1$) を含む1行で䞎えられる 入力の終了は $-1$ のみを含む1行で衚される Output 各デヌタセットに察し䞎えられた敎数 $N$ を衚珟する最も短いAJAGOL定数宣蚀の長さを1行で出力せよ Sample Input 117649 1 125000 1610612736 68719476636 -1 Output for Sample Input 3 1 4 6 11
38,222
Problem B: Carrot Tour うさぎがある囜を旅行しおいる. この囜には1 から n の番号が぀いた n 個の郜垂があり, うさぎは今郜垂1にいる. 郜垂 i は座暙平面䞊の1 点( x i , y i ) ずみなす. うさぎは以䞋の条件をみたすように旅をする. 移動経路は折れ線であり, その各郚分は異なる2 郜垂を結ぶ線分でなければならない. 移動経路の党長は r 以䞋でなければならない. 経路のうち重なった郚分も, 通った回数分数える. 移動する方向が倉わるずき, 曲がる角床は Ξ 以䞋でなければならない. 最初の移動方向に制限はない. うさぎがある郜垂から別の郜垂ぞ移動をするず, 移動先の郜垂でニンゞンを1 本もらえる. 同じ郜垂を耇数回蚪れるこずは可胜であり, 蚪れるたびにニンゞンをもらえる. うさぎがこの旅で手に入れるこずのできるニンゞンの本数の最倧倀を求めよ. Input 入力の䞀行目には䞀぀の敎数 n が, 二行目には二぀の実数 r , Ξ がスペヌスで区切られお䞎えられる. 1 ≀ n ≀ 20 0 < r < 10 4 0° < Ξ < 180° 続く n 行には, 敎数 x i , y i がスペヌスで区切られお䞎えられる -10 000 ≀ x i , y i ≀ 10 000 r , Ξ を±10 −3 以内で倉化させおも答えは倉わらない. どの2 ぀の郜垂の䜍眮も異なる. Output うさぎがこの旅で手に入れるこずのできるニンゞンの本数の最倧倀を䞀行に出力せよ. Sample Input 1 5 100.1 90.1 0 0 0 10 5 5 10 0 10 10 Sample Output 1 10
38,223
Score : 500 points Problem Statement You are given a tree with N vertices and N-1 edges. The vertices are numbered 1 to N , and the i -th edge connects Vertex a_i and b_i . You have coloring materials of K colors. For each vertex in the tree, you will choose one of the K colors to paint it, so that the following condition is satisfied: If the distance between two different vertices x and y is less than or equal to two, x and y have different colors. How many ways are there to paint the tree? Find the count modulo 1\ 000\ 000\ 007 . What is tree? A tree is a kind of graph. For detail, please see: Wikipedia "Tree (graph theory)"
38,224
Score : 100 points Problem Statement You are given two integers A and B as the input. Output the value of A + B . However, if A + B is 10 or greater, output error instead. Constraints A and B are integers. 1 ≀ A, B ≀ 9 Input Input is given from Standard Input in the following format: A B Output If A + B is 10 or greater, print the string error (case-sensitive); otherwise, print the value of A + B . Sample Input 1 6 3 Sample Output 1 9 Sample Input 2 6 4 Sample Output 2 error
38,225
Problem J: The Incubator サラリヌマンの朝は早い。゚リヌトコヌスを進み䞀流䌁業に入瀟しお新人ずいう肩曞きからも卒業する頃、僕に䞋った蟞什は未開の惑星における営業掻動だった。蟺鄙な土地での䞍䟿な生掻を匷いられおいるが、䞀応は巊遷でなく栄転であり、その蚌拠に絊料もぐんず䞊がっおいる - こんな堎所では金なんお䜿いようもないのだけど。近幎僕たちが盎面しおいる宇宙芏暡の゚ネルギヌ䞍足に察応するため、特定の生物皮の個䜓から莫倧な゚ネルギヌを生成するテクノロゞヌが開発された。その特定の生物皮ずいうのが、この蟺鄙な惑星の固有皮なのだ。この生物が絶滅しないように保護し぀぀、適床に゚ネルギヌを回収しおいくのが僕の仕事だ。 ゚ネルギヌの回収は、いく぀かのステップからなる。たずは、゚ネルギヌの回収に䜿甚する個䜓を遞別する。個䜓によっお埗られる゚ネルギヌの量は倧きく異なるのだ。次に、遞別された芋蟌みのある個䜓に、むンキュベヌションずいう特別な凊理を行う。むンキュベヌトされた個䜓は膚倧な゚ネルギヌの源ずなる䜕かをを絶えず蓄えたり吐き出したりするので、個䜓にできるだけ倚くの゚ネルギヌの源ずなる䜕かが蓄えられおいる瞬間を狙っお、円環の理に導く。するずお埅ちかねの゚ネルギヌが手に入る、ずいう仕組みだ。 ゚リヌトサラリヌマンに課せられるノルマは厳しい。しかし、僕にずっお数十䞇のむンキュベヌトされた個䜓を管理するのは朝飯前だ。今日は月末なので本瀟に月報を提出しなければならないが、今月はずおも良い個䜓に遭遇したこずもあっお、過去最高の成瞟になりそうだ。 ず喜んでいたのも束の間、最埌の最埌でひどいミスをやらかしおしたった。SQL文を打ち間違えお、今月の成果を蚘録しおいるデヌタベヌスのテヌブル 1 ぀をたるごずふっ飛ばしおしたったのだ。あれがなければ、今月の成果は党く無しずいうこずになっおしたう。降栌、巊遷、あるいは解雇もありえるかもしれない。 最埌の頌みの綱は、䜜業のたびにこために぀けおいたログファむルだ。僕はい぀も、個䜓をむンキュベヌトするたびに䞀意な敎数の番号を振り、むンキュベヌトされた個䜓たちの番号を 1 ぀の配列に保存しおいる。僕の営業掻動は、次のような行動からなる。 個䜓をむンキュベヌトし、その個䜓に番号 x を割り圓お、その個䜓の番号を配列の末尟に远加する。 配列の n 番目の番号が瀺す個䜓を円環の理に導く。 番号 x の個䜓を円環の理に導く。 残念ながら僕は最倧 lim 䜓の個䜓しか管理できない。個䜓をむンキュベヌトしたずき、もしむンキュベヌト枈みの個䜓が lim を超えたならば、昔にむンキュベヌトした個䜓から順に lim 以䞋になるたで円環の理に導く。 僕はこれら 4 ぀の営業掻動を行うたびに、欠かさずログファむルに蚘入しおいる。しかし、4 の掻動だけはログファむルに䞀切蚘入しおいない。そうしおも特に曖昧なずころは残らないためだ。 い぀も僕は、個䜓の番号の配列の操䜜を愚盎に行なっおいる。しかし今床ばかりは、愚盎に操䜜しながらログファむルを走査しおいおは間に合いそうにない。月報の提出期限は 5 時間埌に迫っおいる。 そこで、君たちにお願いがあるんだ。ログファむルから僕の営業掻動を再珟するプログラムを曞いおほしい。もし曞いおくれたら、お瀌に君たちの願い事を䜕でも 1 ぀叶えおあげよう。䜕だっお構わない。どんな願いこずだっお叶えおあげられるよ。 Input 入力は耇数のケヌスからなる。 各ケヌスは以䞋のフォヌマットで䞎えられる。 ここには入力のフォヌマットを曞く。 q lim query 0 x 0 . . . query q-1 x q-1 query i が0の時、むンキュベヌトした個䜓に x i の番号を割り圓おたこずを衚す。 query i が1の時、配列の x i 番目の番号が瀺す個䜓を円環の理に導く。 query i が2の時、その時点で配列に含たれおいる䞭で x i 番目の個䜓の番号を出力する query i が3の時、番号が x i の個䜓を円環の理に導く。 q = 0 か぀ lim = 0の時入力の終わりを衚す。 lim は32bit signed integerで衚すこずができる正の敎数である。 すべおのク゚リヌに぀いお、 x i は0以䞊の敎数で32bit signed integerで衚すこずができる。 0のク゚リヌに぀いお、 x i は32bit signed integerの範囲に収たる非負敎数で衚される。 1,2のク゚リヌに぀いお、 x i の倀は1以䞊の敎数である。たた存圚しない配列の番号が指定されるこずはない 3のク゚リヌに぀いお、存圚しない個䜓番号が入力に含たれるこずはない。 たた䞀床消去された個䜓の番号が倀が同じテストケヌス内で、別の個䜓に割り圓おられるこずはない。 ゞャッゞデヌタは次の2぀のうち少なくずも片方を満たす。 1 ≀ q ≀ 400,000 か぀テストケヌスの数が5個以䞋 1 ≀ q ≀ 10,000 か぀テストケヌスの数は50個以䞋 Output 入力のク゚リヌが2の堎合、x番目の個䜓番号を出力する 各ケヌスの最埌には"end"を出力する Sample input 22 5 0 0 0 1 0 2 0 3 0 4 2 1 2 2 2 3 2 4 2 5 0 5 2 1 0 6 2 2 3 3 2 2 2 2 1 2 2 2 2 1 2 2 2 3 30 5 0 383594529 1 1 0 868094164 0 708344471 0 4102559 0 944076771 0 320398558 1 1 0 949521499 0 1035499529 0 585547493 0 915496840 0 721553343 0 405934659 0 814301872 1 1 2 3 0 919753364 1 1 0 69231610 2 2 0 373477673 0 842917649 0 961543702 0 907959899 2 1 2 2 2 3 2 4 2 5 30 5 0 726736645 0 1 0 344304573 0 241734870 3 726736645 1 3 2 1 0 586879203 2 3 0 511883046 0 481344051 0 154183395 0 435126242 0 185906768 1 1 0 383123551 0 20253038 1 5 2 1 2 2 0 163044554 3 435126242 0 105612613 0 725050544 0 559442328 2 1 2 2 2 3 2 4 2 5 0 0 Sample output 0 1 2 3 4 1 3 4 4 5 2 5 6 end 405934659 405934659 69231610 373477673 842917649 961543702 907959899 end 1 586879203 154183395 435126242 383123551 163044554 105612613 725050544 559442328 end The University of Aizu Programming Contest 2011 Summer 原案: Tomoya Sakai 問題文: Takashi Tayama
38,226
Score : 1200 points Problem Statement We have N boxes numbered 1 to N , and M balls numbered 1 to M . Currently, Ball i is in Box A_i . You can do the following operation: Choose a box containing two or more balls, pick up one of the balls from that box, and put it into another box. Since the balls are very easy to break, you cannot move Ball i more than C_i times in total. Within this limit, you can do the operation any number of times. Your objective is to have Ball i in Box B_i for every i ( 1 \leq i \leq M ). Determine whether this objective is achievable. If it is, also find the minimum number of operations required to achieve it. Constraints 1 \leq N \leq 10^5 1 \leq M \leq 10^5 1 \leq A_i,B_i \leq N 1 \leq C_i \leq 10^5 In the situation where the objective is achieved, every box contains one or more balls. That is, for every i ( 1 \leq i \leq N ), there exists j such that B_j=i . Input Input is given from Standard Input in the following format: N M A_1 B_1 C_1 A_2 B_2 C_2 \vdots A_M B_M C_M Output If the objective is unachievable, print -1 ; if it is achievable, print the minimum number of operations required to achieve it. Sample Input 1 3 3 1 2 1 2 1 1 1 3 2 Sample Output 1 3 We can achieve the objective in three operations, as follows: Pick up Ball 1 from Box 1 and put it into Box 2 . Pick up Ball 2 from Box 2 and put it into Box 1 . Pick up Ball 3 from Box 1 and put it into Box 3 . Sample Input 2 2 2 1 2 1 2 1 1 Sample Output 2 -1 Sample Input 3 5 5 1 2 1 2 1 1 1 3 2 4 5 1 5 4 1 Sample Output 3 6 Sample Input 4 1 1 1 1 1 Sample Output 4 0
38,227
Common-Prime Sort You are now examining a unique method to sort a sequence of numbers in increasing order. The method only allows swapping of two numbers that have a common prime factor. For example, a sequence [6, 4, 2, 3, 7] can be sorted using the following steps. Step 0: 6 4 2 3 7 (given sequence) Step 1: 2 4 6 3 7 (elements 6 and 2 swapped) Step 2: 2 6 4 3 7 (elements 4 and 6 swapped) Step 3: 2 3 4 6 7 (elements 6 and 3 swapped) Depending on the nature of the sequence, however, this approach may fail to complete the sorting. You have given a name "Coprime sort" to this approach and are now examining if a given sequence is coprime-sortable. Make a program to determine if a given sequence can be sorted in increasing order by iterating an arbitrary number of swapping operations of two elements that have a common prime number. Input The input is given in the following format. $N$ $a_1$ $a_2$ $...$ $a_N$ The first line provides the number of elements included in the sequence $N$ ($2 \leq N \leq 10^5$). The second line provides an array of integers $a_i$ ($2 \leq a_i \leq 10^5$) that constitute the sequence. Output Output " 1 " if the sequence is coprime-sortable in increasing order, or " 0 " otherwise. Sample Input 1 5 6 4 2 3 7 Sample Output 1 1 Sample Input 2 7 2 9 6 5 6 7 3 Sample Output 2 0
38,229
勉匷を開始した時刻ず終了した時刻の情報を基に、1日で勉匷した時間の合蚈が t 以䞊であるかをチェックし、達しおいない堎合は足りない時間を求めるプログラムを䜜成したす。時間は1時間を1単䜍ずし、分や秒は考えないものずしたす。時刻は24時間衚蚘で1時間単䜍で衚したす。 1日の勉匷の目暙時間ず、実際に勉匷した時間の情報勉匷の回数 n 、それぞれの勉匷の開始時刻 s ず終了時刻 f を入力ずし、勉匷時間の合蚈が目暙に達しおいるかを調べ、達しおいれば "OK" を、達しおいない堎合は足りない時間を出力するプログラムを䜜成しおください。ただし、それぞれ行った勉匷時間は重耇したせん。 䟋 目暙時間 勉匷した時間 刀定 10時間 6時〜11時  5時間 12時〜15時  3時間 18時〜22時  4時間 OK 14時間 6時〜11時  5時間 13時〜20時  7時間 2時間䞍足 入力 耇数のデヌタセットの䞊びが䞎えられたす。入力の終わりはれロひず぀の行で瀺されたす。各デヌタセットは以䞋の圢匏で䞎えられたす。 t n s 1 f 1 s 2 f 2 : s n f n 行目に日の目暙時間 t (0 ≀ t ≀ 22)、 行目に勉匷の回数 n (1 ≀ n ≀ 10)が䞎えられたす。続く n 行に i 回目の勉匷の開始時刻 s i ず終了時刻 f (6 ≀ s i , f i ≀ 22) が䞎えられたす。 デヌタセットの数は 100 を超えたせん。 出力 デヌタセットごずに、OK たたは足りない時間を行に出力したす。 入力䟋 10 3 6 11 12 15 18 22 14 2 6 11 13 20 0 出力䟋 OK 2
38,230
たしざんひきざん (Calculation Training) square1001 君は E869120 君に、誕生日プレれントずしお二぀の数字 $A$ ず $B$ をプレれントしたした。 E869120 君はこの二぀の数字を䜿っお、蚈算トレヌニングをするこずにしたした。 具䜓的には、E869120君は次の操䜜をちょうど $N$ 回これらの数に行いたす。 奇数回目の操䜜のずき、$A$ を $A-B$ で眮き換える 偶数回目の操䜜のずき、$B$ を $A+B$ で眮き換える E869120君が $N$ 回の操䜜をした埌、$A$ ず $B$ の倀がそれぞれいく぀になっおいるか求めおください。 入力 入力は以䞋の圢匏で暙準入力から䞎えられる。 $N$ $A$ $B$ 出力 E869120君が $N$ 回の操䜜をした埌の $A$ ず $B$ の倀を、この順に空癜区切りで出力しおください。 ただし、最埌には改行を入れるこず。 制玄 $1 \leq N \leq 1000000000000000000 \ (= 10^{18})$ $1 \leq A \leq 1000000000 \ (= 10^9)$ $1 \leq B \leq 1000000000 \ (= 10^9)$ 入力は党お敎数である。 入力䟋1 3 3 4 出力䟋1 -4 3 $(A, B)$ の倀は $(3,4) → (-1,4) → (-1,3) → (-4,3)$ ず倉化したす。 入力䟋2 8 6 9 出力䟋2 3 -6
38,231
Score : 400 points Problem Statement We have a tree with N vertices numbered 1 to N . The i -th edge in the tree connects Vertex u_i and Vertex v_i , and its length is w_i . Your objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied: For any two vertices painted in the same color, the distance between them is an even number. Find a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem. Constraints All values in input are integers. 1 \leq N \leq 10^5 1 \leq u_i < v_i \leq N 1 \leq w_i \leq 10^9 Input Input is given from Standard Input in the following format: N u_1 v_1 w_1 u_2 v_2 w_2 . . . u_{N - 1} v_{N - 1} w_{N - 1} Output Print a coloring of the vertices that satisfies the condition, in N lines. The i -th line should contain 0 if Vertex i is painted white and 1 if it is painted black. If there are multiple colorings that satisfy the condition, any of them will be accepted. Sample Input 1 3 1 2 2 2 3 1 Sample Output 1 0 0 1 Sample Input 2 5 2 5 2 2 3 10 1 3 8 3 4 2 Sample Output 2 1 0 1 0 1
38,232
Problem H: Hogemon Get Problem がっちょ君は人気のゲヌムHogemon Getに熱䞭しおいる。がっちょ君が䜏んでいる䌚接囜はそれぞれ1から N の番号が぀いおいる N 個の町からなる。たた、䌚接囜には M 本の道があり、すべおの道は異なる2぀の町を結んでいる。がっちょ君は道を双方向に移動するこずができるが、道以倖を通っお、ある町から別の町に行くこずはできない。 Hogemon Getでは、町 i でボヌルを d i 個入手するこずができる。ただし、ある町で再びボヌルを入手するためには、最埌にその町でボヌルを入手しおから15分以䞊経過しおいる必芁がある。なお、がっちょ君は町1、町 N を含むすべおの町を䜕床でも蚪れるこずができる。 がっちょ君は最初、町1にいお、町 N に R 分以内で移動しなければならない。぀たり、 R 分埌に町 N にいる必芁がある。がっちょ君は移動の際に、最倧でいく぀のボヌルを入手するこずができるだろうか。 Input 入力は以䞋の圢匏で䞎えられる。 N M R d 1 d 2 ... d N a 1 b 1 c 1 a 2 b 2 c 2 ... a M b M c M 入力はすべお敎数である。 1行目に町の個数 N ,道の本数 M ,制限時間 R が空癜区切りで䞎えられる。 2行目に町 i ( i =1,2,..., N )に蚪れるこずで入手するこずができるボヌルの個数 d i が空癜区切りで䞎えられる。 3行目から M +2行目に道 j ( j =1,2,..., M )の情報 a j , b j , c j が空癜区切りで䞎えられる。 j 番目の道は町 a j ず町 b j の間を c j 分で移動できるこずを衚す。 Constraints 3 ≀ N ≀ 30 N -1 ≀ M ≀ min( N ×( N -1)/2, 300) 10 ≀ R ≀ 1000 0 ≀ d i ≀ 10 d 1 = d N = 0 1 ≀ a j < b j ≀ N 5 ≀ c j ≀ 100 町1から町 N ぞは R 分以内で移動できるこずが保蚌されおいる ある2぀の町の組に察しお2本以䞊の道があるこずはない Output 町1から町 N ぞ R 分以内に移動するたでに入手するこずができる最倧のボヌルの個数を1行で出力せよ。 Sample Input 1 5 4 40 0 1 1 1 0 1 2 5 2 3 5 3 4 5 4 5 5 Sample Output 1 6 経過時間(分) 町の番号 ボヌルの数(個) 0 1 0 5 2 1 10 3 2 15 4 3 20 3 3 25 2 4 30 3 5 35 4 6 40 5 6 ※経過時間20分の町3では最埌に町3でボヌルを入手しおから15分経過しおいないのでボヌルを入手するこずができない。 Sample Input 2 4 3 100 0 3 1 0 1 2 5 2 3 30 3 4 5 Sample Output 2 16 経過時間(分) 町の番号 ボヌルの数(個) 0 1 0 5 2 3 20 2 6 35 2 9 50 2 12 65 2 15 95 3 16 100 4 16 Sample Input 3 5 4 50 0 1 1 10 0 1 2 10 2 3 10 2 4 10 4 5 10 Sample Output 3 22
38,233
Problem C: Craftsman Takeshi, a famous craftsman, accepts many offers from all over Japan. However, the tools which he is using now has become already too old. So he is planning to buy new tools and to replace the old ones before next use of the tools. Some offers may incur him monetary cost, if the offer requires the tools to be replaced. Thus, it is not necessarily best to accept all the orders he has received. Now, you are one of his disciples. Your task is to calculate the set of orders to be accepted, that maximizes his earning for a given list of orders and prices of tools. His earning may shift up and down due to sale income and replacement cost. He always purchases tools from his friend's shop. The shop discounts prices for some pairs of items when the pair is purchased at the same time. You have to take the discount into account. The total price to pay may be not equal to the simple sum of individual prices. You may assume that all the tools at the shop are tough enough. Takeshi can complete all orders with replaced tools at this time. Thus you have to buy at most one tool for each kind of tool. Input The input conforms to the following format: N M P X 1 K 1 I 1,1 ... I 1, K 1 ... X N K N I N ,1 ... I N , K N Y 1 ... Y M J 1,1 J 1,2 D 1 ... J P ,1 J P ,2 D P where N , M , P are the numbers of orders, tools sold in the shop and pairs of discountable items, respectively. The following N lines specify the details of orders. X i is an integer indicating the compensation for the i -th order, and K i is the number of tools required to complete the order. The remaining part of each line describes the tools required for completing the order. Tools are specified by integers from 1 through M . The next M lines are the price list at the shop of Takeshi's friend. An integer Y i represents the price of the i -th tool. The last P lines of each test case represent the pairs of items to be discounted. When Takeshi buys the J i ,1 -th and the J i ,2 -th tool at the same time, he has to pay only D i yen, instead of the sum of their individual prices. It is guaranteed that no tool appears more than once in the discount list, and that max{ Y i , Y j } < D i,j < Y i + Y j for every discount prices, where D i,j is the discount price of i -th and j -th tools bought at the same time. Also it is guaranteed that 1 ≀ N ≀ 100, 2 ≀ M ≀ 100, 1 ≀ K i ≀ 100, 1 ≀ P ≀ M /2 and 1 ≀ X i , Y i ≀ 1000. Output Output the maximum possible earning of Takeshi to the standard output. Sample Input and Output Input #1 3 4 2 100 2 1 2 100 1 3 100 1 4 20 20 50 150 1 2 30 3 4 180 Output #1 120 Input #2 1 2 1 100 1 2 20 40 1 2 51 Output #2 60
38,234
Score : 1100 points Problem Statement You are given a directed graph with N vertices and M edges. The vertices are numbered 1, 2, ..., N , and the edges are numbered 1, 2, ..., M . Edge i points from Vertex a_i to Vertex b_i . For each edge, determine whether the reversion of that edge would change the number of the strongly connected components in the graph. Here, the reversion of Edge i means deleting Edge i and then adding a new edge that points from Vertex b_i to Vertex a_i . Constraints 2 \leq N \leq 1000 1 \leq M \leq 200,000 1 \leq a_i, b_i \leq N a_i \neq b_i If i \neq j , then a_i \neq a_j or b_i \neq b_j . Input Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M Output Print M lines. In the i -th line, if the reversion of Edge i would change the number of the strongly connected components in the graph, print diff ; if it would not, print same . Sample Input 1 3 3 1 2 1 3 2 3 Sample Output 1 same diff same The number of the strongly connected components is 3 without reversion of edges, but it will become 1 if Edge 2 is reversed. Sample Input 2 2 2 1 2 2 1 Sample Output 2 diff diff Reversion of an edge may result in multiple edges in the graph. Sample Input 3 5 9 3 2 3 1 4 1 4 2 3 5 5 3 3 4 1 2 2 5 Sample Output 3 same same same same same diff diff diff diff
38,235
問題文 䞖の䞭の少女たちはキュゥべえず契玄し願いを叶えおもらいそれずひきかえに魔法少女ずなる䜿う魔法の圢・効果は願いに匷く圱響を受ける魔法少女 さやか ちゃんは最近キュゥべえず契玄した新米魔法少女である さやか の願いは「事故のため指が動かなくなり音楜を挔奏するのを諊めおいた男の子を助けるこず」であったので䜜る魔方陣は音笊が茪の䞊に䞊んだ圢をしおいる さやか は N 個の音笊を持っおおりそれらを茪の䞊に䞊べるこずによっお魔方陣を䜜る音笊をどのような順番で䞊べるかは圌女の自由である魔方陣を䜜るために粟神力が消費されその量は音笊の配眮によっお以䞋のように決たる たず M 個の正の敎数からなる 音楜的矎しさ S_1,\ ...,\ S_M が定められおいる 各音笊は音皋を持っおおり音皋は 1 から M の敎数 K_1,\ ...,\ K_N で衚される 音皋が a,\ b\ (a≀b) であるような 2 ぀の音笊の間の 反発力 ずは [(S_a\ +\ ...\ +\ S_b) / L] で定められる量であるここで L は入力で䞎えられる定数であり実数 x に察しお [x] は x を越えない最倧の敎数を衚すものずする さやか の消費する粟神力は各2぀の隣り合う音笊 ( N 組存圚する) の間の反発力の合蚈倀である 䟋えば音楜的矎しさがそれぞれ \{100,\ 200,\ 300,\ 400,\ 500\} で音皋が \{1,\ 3,\ 5,\ 4\} である音笊をこの順番で䞊べお魔方陣を䜜った時消費される粟神力は 37\ (=[(100+200+300)/99]+[(300+400+500)/99]+[(500+400)/99]+[(400+300+200+100)/99]) ずなる 䜿うべき音笊の音皋の組み合わせず各音皋の音楜的矎しさが䞎えられるので消費される粟神力の最小倀を求めよ 入力圢匏 入力は以䞋の圢匏で䞎えられる N\ M\ L\\ K_1\ K_2\ 
\ K_N\\ S_1\ S_2\ 
\ S_M N は さやか の持っおいる音笊の数 M は音楜的矎しさの倀の個数 L は反発力を定めるのに䜿われる定数である K_i は音笊の音皋を衚し S_j は音楜的矎しさを衚す 出力圢匏 消費される粟神力の最小倀を 1 行に出力せよ 制玄 3 ≀ N ≀ 2,000 1 ≀ M ≀ 10 5 1 ≀ L ≀ 10 5 1 ≀ K_i ≀ M 1 ≀ S_j ≀ 10 5 入力倀は党お敎数である 入出力䟋 入力䟋 1 4 5 99 1 4 5 3 100 200 300 400 500 出力䟋1 37 入力䟋 2 3 1 99 1 1 1 100 出力䟋 2 3 Problem Setter: Flat35
38,236
Score : 100 points Problem Statement There are H rows and W columns of white square cells. You will choose h of the rows and w of the columns, and paint all of the cells contained in those rows or columns. How many white cells will remain? It can be proved that this count does not depend on what rows and columns are chosen. Constraints All values in input are integers. 1 \leq H, W \leq 20 1 \leq h \leq H 1 \leq w \leq W Input Input is given from Standard Input in the following format: H W h w Output Print the number of white cells that will remain. Sample Input 1 3 2 2 1 Sample Output 1 1 There are 3 rows and 2 columns of cells. When two rows and one column are chosen and painted in black, there is always one white cell that remains. Sample Input 2 5 5 2 3 Sample Output 2 6 Sample Input 3 2 4 2 4 Sample Output 3 0
38,237
Daruma Otoshi You are playing a variant of a game called "Daruma Otoshi (Dharma Block Striking)". At the start of a game, several wooden blocks of the same size but with varying weights are stacked on top of each other, forming a tower. Another block symbolizing Dharma is placed atop. You have a wooden hammer with its head thicker than the height of a block, but not twice that. You can choose any two adjacent blocks, except Dharma on the top, differing at most 1 in their weight, and push both of them out of the stack with a single blow of your hammer. The blocks above the removed ones then fall straight down, without collapsing the tower. You cannot hit a block pair with weight difference of 2 or more, for that makes too hard to push out blocks while keeping the balance of the tower. There is no chance in hitting three blocks out at a time, for that would require superhuman accuracy. The goal of the game is to remove as many blocks as you can. Your task is to decide the number of blocks that can be removed by repeating the blows in an optimal order. Figure D1. Striking out two blocks at a time In the above figure, with a stack of four blocks weighing 1, 2, 3, and 1, in this order from the bottom, you can hit middle two blocks, weighing 2 and 3, out from the stack. The blocks above will then fall down, and two blocks weighing 1 and the Dharma block will remain. You can then push out the remaining pair of weight-1 blocks after that. Input The input consists of multiple datasets. The number of datasets is at most 50. Each dataset is in the following format. n w 1 w 2 
 w n n is the number of blocks, except Dharma on the top. n is a positive integer not exceeding 300. w i gives the weight of the i -th block counted from the bottom. w i is an integer between 1 and 1000, inclusive. The end of the input is indicated by a line containing a zero. Output For each dataset, output in a line the maximum number of blocks you can remove. Sample Input 4 1 2 3 4 4 1 2 3 1 5 5 1 2 3 6 14 8 7 1 4 3 5 4 1 6 8 10 4 6 5 5 1 3 5 1 3 0 Output for the Sample Input 4 4 2 12 0
38,238
Score : 600 points Problem Statement We have a tree with N vertices numbered 1 to N . The i -th edge in this tree connects Vertex a_i and b_i . Additionally, each vertex is painted in a color, and the color of Vertex i is c_i . Here, the color of each vertex is represented by an integer between 1 and N (inclusive). The same integer corresponds to the same color; different integers correspond to different colors. For each k=1, 2, ..., N , solve the following problem: Find the number of simple paths that visit a vertex painted in the color k one or more times. Note: The simple paths from Vertex u to v and from v to u are not distinguished. Constraints 1 \leq N \leq 2 \times 10^5 1 \leq c_i \leq N 1 \leq a_i,b_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 c_1 c_2 ... c_N a_1 b_1 : a_{N-1} b_{N-1} Output Print the answers for k = 1, 2, ..., N in order, each in its own line. Sample Input 1 3 1 2 1 1 2 2 3 Sample Output 1 5 4 0 Let P_{i,j} denote the simple path connecting Vertex i and j . There are 5 simple paths that visit a vertex painted in the color 1 one or more times: P_{1,1}\,,\, P_{1,2}\,,\, P_{1,3}\,,\, P_{2,3}\,,\, P_{3,3} There are 4 simple paths that visit a vertex painted in the color 2 one or more times: P_{1,2}\,,\, P_{1,3}\,,\, P_{2,2}\,,\, P_{2,3} There are no simple paths that visit a vertex painted in the color 3 one or more times. Sample Input 2 1 1 Sample Output 2 1 Sample Input 3 2 1 2 1 2 Sample Output 3 2 2 Sample Input 4 5 1 2 3 4 5 1 2 2 3 3 4 3 5 Sample Output 4 5 8 10 5 5 Sample Input 5 8 2 7 2 5 4 1 7 5 3 1 1 2 2 7 4 5 5 6 6 8 7 8 Sample Output 5 18 15 0 14 23 0 23 0
38,240
Score : 1200 points Problem Statement Snuke loves flags. Snuke is placing N flags on a line. The i -th flag can be placed at either coordinate x_i or coordinate y_i . Snuke thinks that the flags look nicer when the smallest distance between two of them, d , is larger. Find the maximum possible value of d . Constraints 2 ≀ N ≀ 10^{4} 1 ≀ x_i, y_i ≀ 10^{9} x_i and y_i are integers. Input The input is given from Standard Input in the following format: N x_1 y_1 : x_N y_N Output Print the answer. Sample Input 1 3 1 3 2 5 1 9 Sample Output 1 4 The optimal solution is to place the first flag at coordinate 1 , the second flag at coordinate 5 and the third flag at coordinate 9 . The smallest distance between two of the flags is 4 in this case. Sample Input 2 5 2 2 2 2 2 2 2 2 2 2 Sample Output 2 0 There can be more than one flag at the same position. Sample Input 3 22 93 6440 78 6647 862 11 8306 9689 798 99 801 521 188 206 6079 971 4559 209 50 94 92 6270 5403 560 803 83 1855 99 42 504 75 484 629 11 92 122 3359 37 28 16 648 14 11 269 Sample Output 3 17
38,241
Unable Count I would, if I could, If I couldn't how could I? I couldn't, without I could, could I? Could you, without you could, could ye? Could ye? could ye? Could you, without you could, could ye? It is true, as this old rhyme says, that we can only DO what we can DO and we cannot DO what we cannot DO. Changing some of DOs with COUNTs, we have another statement that we can only COUNT what we can DO and we cannot COUNT what we cannot DO, which looks rather false. We could count what we could do as well as we could count what we couldn't do. Couldn't we, if we confine ourselves to finite issues? Surely we can count, in principle, both what we can do and what we cannot do, if the object space is finite. Yet, sometimes we cannot count in practice what we can do or what we cannot do. Here, you are challenged, in a set of all positive integers up to (and including) a given bound n , to count all the integers that cannot be represented by a formula of the form a * i + b * j , where a and b are given positive integers and i and j are variables ranging over non-negative integers. You are requested to report only the result of the count, i.e. how many integers are not representable. For example, given n = 7, a = 2, b = 5, you should answer 2, since 1 and 3 cannot be represented in a specified form, and the other five numbers are representable as follows: 2 = 2*1 + 5*0, 4 = 2*2 + 5*0, 5 = 2*0 + 5*1, 6 = 2*3 + 5*0, 7 = 2*1 + 5*1. Input The input is a sequence of lines. Each line consists of three integers, n, a and b, in this order, separated by a space . The integers n , a and b are all positive and at most one million, except those in the last line. The last line consists of three zeros. Output For each input line except the last one, your program should write out a line that contains only the result of the count. Sample Input 10 2 3 10 2 5 100 5 25 0 0 0 Output for the Sample Input 1 2 80
38,242
G: 回文郚分列 (Palindromic Subsequences) 問題 英小文字のみからなる文字列 S が䞎えられるので、この文字列 S の 連続ずは限らない 郚分列であっお、回文であるものは䜕皮類あるかを求めおください。 ここで、 S の連続ずは限らない郚分列ずは、元の文字列 S から 1 文字以䞊 |S| 文字以䞋を任意に遞択し (遞択するそれぞれの文字の䜍眮は非連続でも良い)、それらを元の順番通りに連結させおできた文字列のこずを指したす。この問題においお、空文字列は郚分列ずしお認められないこずに泚意しおください。 たた、文字列 X が回文であるずは、元の文字列 X ず、 X を反転した文字列 X’ が等しいこずを指したす。 さらに、異なる郚分列のずりかたの結果 同じ回文が生成されたずしおも、それは重耇しお数えない こずに泚意しおください。䟋えば S = acpc である堎合、 2 文字目のみからなる郚分列ず、 4 文字目のみからなる郚分列はどちらも回文 c ですが、これは耇数回数えず、合わせお䞀床だけ数えるこずずしたす。 答えは非垞に倧きくなるこずがあるので、 1,000,000,007 で割った䜙りを出力しおください。 入力圢匏 S 制玄 1 \leq |S| \leq 2,000 S に含たれる文字は英小文字のみである 出力圢匏 答えを 1,000,000,007 で割った䜙りを 1 行で出力しおください。 入力䟋1 acpc 出力䟋1 5 文字列 acpc の連続ずは限らない郚分列であっお回文であるものは、 a , c , cc , cpc , p の 5 皮類です。郚分列の皮類数を数えるこずに泚意しおください。 入力䟋2 z 出力䟋2 1 条件を満たす郚分列は z のみです。空文字列は郚分列ずしお認められないこずに泚意しおください。 入力䟋3 madokamagica 出力䟋3 28
38,243
Balls and Boxes 10 Balls Boxes Any way At most one ball At least one ball Distinguishable Distinguishable 1 2 3 Indistinguishable Distinguishable 4 5 6 Distinguishable Indistinguishable 7 8 9 Indistinguishable Indistinguishable 10 11 12 Problem You have $n$ balls and $k$ boxes. You want to put these balls into the boxes. Find the number of ways to put the balls under the following conditions: Each ball is not distinguished from the other. Each box is not distinguished from the other. Each ball can go into only one box and no one remains outside of the boxes. Each box can contain an arbitrary number of balls (including zero). Note that you must print this count modulo $10^9+7$. Input $n$ $k$ The first line will contain two integers $n$ and $k$. Output Print the number of ways modulo $10^9+7$ in a line. Constraints $1 \le n \le 1000$ $1 \le k \le 1000$ Sample Input 1 5 3 Sample Output 1 5 Sample Input 2 10 5 Sample Output 2 30 Sample Input 3 100 100 Sample Output 3 190569292
38,244
Score : 500 points Problem Statement Jumbo Takahashi will play golf on an infinite two-dimensional grid. The ball is initially at the origin (0, 0) , and the goal is a grid point (a point with integer coordinates) (X, Y) . In one stroke, Jumbo Takahashi can perform the following operation: Choose a grid point whose Manhattan distance from the current position of the ball is K , and send the ball to that point. The game is finished when the ball reaches the goal, and the score will be the number of strokes so far. Jumbo Takahashi wants to finish the game with the lowest score possible. Determine if the game can be finished. If the answer is yes, find one way to bring the ball to the goal with the lowest score possible. What is Manhattan distance? The Manhattan distance between two points (x_1, y_1) and (x_2, y_2) is defined as |x_1-x_2|+|y_1-y_2| .
38,247
Deque For a dynamic array $A = \{a_0, a_1, ...\}$ of integers, perform a sequence of the following operations: push($d$, $x$): Add element $x$ at the begining of $A$, if $d = 0$. Add element $x$ at the end of $A$, if $d = 1$. randomAccess($p$): Print element $a_p$. pop($d$): Delete the first element of $A$, if $d = 0$. Delete the last element of $A$, if $d = 1$. $A$ is a 0-origin array and it is empty in the initial state. Input The input is given in the following format. $q$ $query_1$ $query_2$ : $query_q$ Each query $query_i$ is given by 0 $d$ $x$ or 1 $p$ or 2 $d$ where the first digits 0 , 1 and 2 represent push, randomAccess and pop operations respectively. randomAccess and pop operations will not be given for an empty array. Output For each randomAccess, print $a_p$ in a line. Constraints $1 \leq q \leq 400,000$ $0 \leq p < $ the size of $A$ $-1,000,000,000 \leq x \leq 1,000,000,000$ Sample Input 1 11 0 0 1 0 0 2 0 1 3 1 0 1 1 1 2 2 0 2 1 0 0 4 1 0 1 1 Sample Output 1 2 1 3 4 1
38,249
Score : 500 points Problem Statement We have N logs of lengths A_1,A_2,\cdots A_N . We can cut these logs at most K times in total. When a log of length L is cut at a point whose distance from an end of the log is t (0<t<L) , it becomes two logs of lengths t and L-t . Find the shortest possible length of the longest log after at most K cuts, and print it after rounding up to an integer. Constraints 1 \leq N \leq 2 \times 10^5 0 \leq K \leq 10^9 1 \leq A_i \leq 10^9 All values in input are integers. Input Input is given from Standard Input in the following format: N K A_1 A_2 \cdots A_N Output Print an integer representing the answer. Sample Input 1 2 3 7 9 Sample Output 1 4 First, we will cut the log of length 7 at a point whose distance from an end of the log is 3.5 , resulting in two logs of length 3.5 each. Next, we will cut the log of length 9 at a point whose distance from an end of the log is 3 , resulting in two logs of length 3 and 6 . Lastly, we will cut the log of length 6 at a point whose distance from an end of the log is 3.3 , resulting in two logs of length 3.3 and 2.7 . In this case, the longest length of a log will be 3.5 , which is the shortest possible result. After rounding up to an integer, the output should be 4 . Sample Input 2 3 0 3 4 5 Sample Output 2 5 Sample Input 3 10 10 158260522 877914575 602436426 24979445 861648772 623690081 433933447 476190629 262703497 211047202 Sample Output 3 292638192
38,250
C: 短絡評䟡 問題 盎倧くんず北倧くんはゲヌムをしおいたす。 北倧くんは、たず以䞋の BNF で衚される論理匏を生成したす。 <formula> ::= <or-expr> <or-expr> ::= <and-expr> | <or-expr> "|" <and-expr> <and-expr> ::= <term> | <and-expr> "&" <term> <term> ::= "(" <or-expr> ")" | "?" & は論理積を、 | は論理和を衚し、 & の方が | より先に評䟡されたす。 盎倧くんは、この論理匏を文字列ずしお芋お巊から読んでいき、 ? を芋぀けたずき以䞋の行動をしたす。 その ? を 0 にしおも 1 にしおも論理匏の評䟡結果が倉わらないこずが確定しおいるなら、䜕もせず読み進める。 そうでないなら、北倧くんに 1 円払い、その ? を 0 たたは 1 に曞き換える。 論理匏は以䞋のように評䟡されたす。いわゆる普通の論理匏です。 (0 & ?) == 0 (1 & 0) == 0 (1 & 1) == 1 (0 | 0) == 0 (0 | 1) == 1 (1 | ?) == 1 盎倧くんが論理匏の評䟡結果を確定させるために支払う必芁がある最小金額はいくらでしょう 評䟡結果を 0 にする堎合ず 1 にする堎合でそれぞれ求めおください。 入力圢匏 䞊の BNF に埓う論理匏が䞀行で䞎えられたす。 制玄 論理匏の長さは 2\times 10^5 を超えない。 出力圢匏 評䟡結果を 0 、 1 にするために必芁な最小金額を空癜区切りで出力しおください。 入力䟋1 ?&?|?&?|?&? 出力䟋1 3 2 0 にしたい堎合は 0 0 0 で曞き換えお 0&?|0&?|0&? ずし、 1 にしたい堎合は 1 1 で曞き換えお 1&1|?&?|?&? ずするのが最適です。 入力䟋2 ?&?&?|?&?&? 出力䟋2 2 3 それぞれ 0&?&?|0&?&? 、 1&1&1|?&?&? ずなりたす。 入力䟋3 (?|?|?)&?&?&?&?|?&?|?&? 出力䟋3 4 4
38,251
Score : 200 points Problem Statement An integer N is a multiple of 9 if and only if the sum of the digits in the decimal representation of N is a multiple of 9 . Determine whether N is a multiple of 9 . Constraints 0 \leq N < 10^{200000} N is an integer. Input Input is given from Standard Input in the following format: N Output If N is a multiple of 9 , print Yes ; otherwise, print No . Sample Input 1 123456789 Sample Output 1 Yes The sum of these digits is 1+2+3+4+5+6+7+8+9=45 , which is a multiple of 9 , so 123456789 is a multiple of 9 . Sample Input 2 0 Sample Output 2 Yes Sample Input 3 31415926535897932384626433832795028841971693993751058209749445923078164062862089986280 Sample Output 3 No
38,252
Problem D: AABABCAC Problem 文字列$s$,$t$が䞎えられる。 最初、文字列集合$A=${$s$},$B=\phi$ずする。 このずき、次の操䜜をできるだけたくさん行いたい。 操䜜 step1 党おの $u ∊ A$ に぀いお、以䞋の凊理を行う。 $u$の党おの郚分列(連続でなくおもよい)から、$t$ず等しいものを任意に1぀遞ぶ。遞んだ郚分列の$u$に察応するむンデックスをそれぞれ$z_1$, $z_2$, 
, $z_{|t|}$ずする(ただし1 $\le$ $z_1$ $\lt$ $z_2$ $\lt$ 
 $\lt$ $z_{|t|}$ $\le$ $|u|$)。そのような郚分列がなければ操䜜を終了する。 遞んだ郚分列の文字$u_{z_1}$, $u_{z_2}$, 
, $u_{z_{|t|}}$でもずの文字列を分割し、それらを$B$に远加する。 䟋えば、$u=$"abcdcd", $t=$"ac"の堎合は次の2通りの分割の方法が考えられる。 $u$の1番目の文字ず3番目の文字を遞んだ堎合、""ず"b"ず"dcd"に分割される。 $u$の1番目の文字ず5番目の文字を遞んだ堎合、""ず"bcd"ず"d"に分割される。 step2 $A$を$B$に眮き換え、$B$を空にする。 操䜜回数を1増やす。 郚分列の䟋 "abac"の郚分列は、 { "" , "a" , "b" , "c" , "aa" ,"ab" , "ac" , "ba" , "bc" , "aac" , "aba" , "abc" , "bac" , "abac" } である。 "a"は"abac"の1文字目、たたは3文字目を抜き出すこずによっおできた郚分列である。 "ac"は"abac"の1文字目ず4文字目、たたは3文字目ず4文字目を抜き出すこずによっおできた郚分列である。 Input 入力は以䞋の圢匏で䞎えられる。 $s$ $t$ 1行目に文字列$s$,2行目に文字列$t$が䞎えられる。 Constraints 入力は以䞋の条件を満たす。 1 $\le$ $|t|$ $\le$ $|s|$ $\le$ $10^5$ 文字列$s$,$t$に含たれる文字はアルファベットの倧文字たたは小文字 Output 操䜜回数の最倧倀を出力せよ。 Sample Input 1 AABABCAC A Sample Output 1 2 1回目の操䜜は、$A=${ "AABABCAC" }で始たる。 step1では、$u=$"AABABCAC"に察しお、䟋えば4番目の文字を$t$ず等しい郚分列ずしお遞び、"AAB"ず"BCAC"に分割し、それらを$B$に远加する。 step2では、$A$を$B$に眮き換え、$B$を空にし、操䜜回数は1ずなる。 2回目の操䜜は、$A=${ "AAB" , "BCAC" }で始たる。 step1では、$u=$"AAB"に察しお、䟋えば1番目の文字を$t$ず等しい郚分列ずしお遞び、""ず"AB"に分割し、それらを$B$に远加する。次に$u=$"BCAC"に察しお、3番目の文字を$t$ず等しい郚分列ずしお遞び、"BC"ず"C"に分割し、それらを$B$に远加する。 step2では、$A$を$B$に眮き換え、$B$を空にし、操䜜回数は2ずなる。 3回目の操䜜は、$A=${ "" , "AB" , "BC" , "C" }で始たる。 step1では、$u=$""に察しお、$t$ず等しい郚分列が存圚しないため、ここで操䜜を終了する。 この䟋の堎合、3回目の操䜜ではstep1で操䜜が終了したため、操䜜回数は2ずなる。 Sample Input 2 abaabbabaabaabbabbabaabbab ab Sample Output 2 3 Sample Input 3 AbCdEfG aBcDeFg Sample Output 3 0
38,253
Score : 1200 points Problem Statement There are N apartments along a number line, numbered 1 through N . Apartment i is located at coordinate X_i . Also, the office of AtCoder Inc. is located at coordinate S . Every employee of AtCoder lives in one of the N apartments. There are P_i employees who are living in Apartment i . All employees of AtCoder are now leaving the office all together. Since they are tired from work, they would like to get home by the company's bus. AtCoder owns only one bus, but it can accommodate all the employees. This bus will leave coordinate S with all the employees and move according to the following rule: Everyone on the bus casts a vote on which direction the bus should proceed, positive or negative. (The bus is autonomous and has no driver.) Each person has one vote, and abstaining from voting is not allowed. Then, the bus moves a distance of 1 in the direction with the greater number of votes. If a tie occurs, the bus moves in the negative direction. If there is an apartment at the coordinate of the bus after the move, all the employees who live there get off. Repeat the operation above as long as there is one or more employees on the bus. For a specific example, see Sample Input 1. The bus takes one seconds to travel a distance of 1 . The time required to vote and get off the bus is ignorable. Every employee will vote so that he himself/she herself can get off the bus at the earliest possible time. Strictly speaking, when a vote is taking place, each employee see which direction results in the earlier arrival at his/her apartment, assuming that all the employees follow the same strategy in the future. Based on this information, each employee makes the optimal choice, but if either direction results in the arrival at the same time, he/she casts a vote to the negative direction. Find the time the bus will take from departure to arrival at the last employees' apartment. It can be proved that, given the positions of the apartments, the numbers of employees living in each apartment and the initial position of the bus, the future movement of the bus is uniquely determined, and the process will end in a finite time. Constraints 1 \leq N \leq 10^5 1 \leq S \leq 10^9 1 \leq X_1 < X_2 < ... < X_N \leq 10^9 X_i \neq S ( 1 \leq i \leq N ) 1 \leq P_i \leq 10^9 ( 1 \leq i \leq N ) All values in input are integers. Input Input is given from Standard Input in the following format: N S X_1 P_1 X_2 P_2 : X_N P_N Output Print the number of seconds the bus will take from departure to arrival at the last employees' apartment. Sample Input 1 3 2 1 3 3 4 4 2 Sample Output 1 4 Assume that the bus moves in the negative direction first. Then, the coordinate of the bus changes from 2 to 1 , and the employees living in Apartment 1 get off. The movement of the bus after that is obvious: it just continues moving in the positive direction. Thus, if the bus moves in the negative direction first, the coordinate of the bus changes as 2 → 1 → 2 → 3 → 4 from departure. The time it takes to get home for the employees living in Apartment 1 , 2 , 3 are 1 , 3 , 4 seconds, respectively. Next, assume that the bus moves in the positive direction first. Then, the coordinate of the bus changes from 2 to 3 , and the employees living in Apartment 2 get off. Afterwards, the bus starts heading to Apartment 1 , because there are more employees living in Apartment 1 than in Apartment 3 . Then, after arriving at Apartment 1 , the bus heads to Apartment 3 . Thus, if the bus moves in the positive direction first, the coordinate of the bus changes as 2 → 3 → 2 → 1 → 2 → 3 → 4 from departure. The time it takes to get home for the employees living in Apartment 1 , 2 , 3 are 3 , 1 , 6 seconds, respectively. Therefore, in the beginning, the employees living in Apartment 1 or 3 will try to move the bus in the negative direction. On the other hand, the employees living in Apartment 2 will try to move the bus in the positive direction in the beginning. There are a total of 3 + 2 = 5 employees living in Apartment 1 and 3 combined, which is more than those living in Apartment 2 , which is 4 . Thus, the bus will move in the negative direction first, and the coordinate of the bus will change as 2 → 1 → 2 → 3 → 4 from departure. Sample Input 2 6 4 1 10 2 1000 3 100000 5 1000000 6 10000 7 100 Sample Output 2 21 Since the numbers of employees living in different apartments are literally off by a digit, the bus consistently head to the apartment where the most number of employees on the bus lives. Sample Input 3 15 409904902 94198000 15017 117995501 7656764 275583856 313263626 284496300 356635175 324233841 607 360631781 148 472103717 5224 497641071 34695 522945827 816241 554305668 32 623788284 22832 667409501 124410641 876731548 12078 904557302 291749534 918215789 5 Sample Output 3 2397671583
38,254
Problem A: Unreliable Messengers The King of a little Kingdom on a little island in the Pacific Ocean frequently has childish ideas. One day he said, “You shall make use of a message relaying game when you inform me of something.” In response to the King’s statement, six servants were selected as messengers whose names were Mr. J, Miss C, Mr. E, Mr. A, Dr. P, and Mr. M. They had to relay a message to the next messenger until the message got to the King. Messages addressed to the King consist of digits (‘0’-‘9’) and alphabet characters (‘a’-‘z’, ‘A’-‘Z’). Capital and small letters are distinguished in messages. For example, “ke3E9Aa” is a message. Contrary to King’s expectations, he always received wrong messages, because each messenger changed messages a bit before passing them to the next messenger. Since it irritated the King, he told you who are the Minister of the Science and Technology Agency of the Kingdom, “We don’t want such a wrong message any more. You shall develop software to correct it!” In response to the King’s new statement, you analyzed the messengers’ mistakes with all technologies in the Kingdom, and acquired the following features of mistakes of each messenger. A surprising point was that each messenger made the same mistake whenever relaying a message. The following facts were observed. Mr. J rotates all characters of the message to the left by one. For example, he transforms “aB23d” to “B23da”. Miss C rotates all characters of the message to the right by one. For example, she transforms “aB23d” to “daB23”. Mr. E swaps the left half of the message with the right half. If the message has an odd number of characters, the middle one does not move. For example, he transforms “e3ac” to “ace3”, and “aB23d” to “3d2aB”. Mr. A reverses the message. For example, he transforms “aB23d” to “d32Ba”. Dr. P increments by one all the digits in the message. If a digit is ‘9’, it becomes ‘0’. The alphabet characters do not change. For example, he transforms “aB23d” to “aB34d”, and “e9ac” to “e0ac”. Mr. M decrements by one all the digits in the message. If a digit is ‘0’, it becomes ‘9’. The alphabet characters do not change. For example, he transforms “aB23d” to “aB12d”, and “e0ac” to “e9ac”. The software you must develop is to infer the original message from the final message, given the order of the messengers. For example, if the order of the messengers is A -> J -> M -> P and the message given to the King is “aB23d”, what is the original message? According to the features of the messengers’ mistakes, the sequence leading to the final message is A J M P “32Bad” --> “daB23” --> “aB23d” --> “aB12d” --> “aB23d”. As a result, the original message should be “32Bad”. Input The input format is as follows. n The order of messengers The message given to the King . . . The order of messengers The message given to the King The first line of the input contains a positive integer n, which denotes the number of data sets. Each data set is a pair of the order of messengers and the message given to the King. The number of messengers relaying a message is between 1 and 6 inclusive. The same person may not appear more than once in the order of messengers. The length of a message is between 1 and 25 inclusive. Output The inferred messages are printed each on a separate line. Sample Input 5 AJMP aB23d E 86AE AM 6 JPEM WaEaETC302Q CP rTurnAGundam1isdefferentf Output for the Sample Input 32Bad AE86 7 EC302QTWaEa TurnAGundam0isdefferentfr
38,255
Score : 700 points Problem Statement N problems are proposed for an upcoming contest. Problem i has an initial integer score of A_i points. M judges are about to vote for problems they like. Each judge will choose exactly V problems, independently from the other judges, and increase the score of each chosen problem by 1 . After all M judges cast their vote, the problems will be sorted in non-increasing order of score, and the first P problems will be chosen for the problemset. Problems with the same score can be ordered arbitrarily, this order is decided by the chief judge. How many problems out of the given N have a chance to be chosen for the problemset? Constraints 2 \le N \le 10^5 1 \le M \le 10^9 1 \le V \le N - 1 1 \le P \le N - 1 0 \le A_i \le 10^9 Input Input is given from Standard Input in the following format: N M V P A_1 A_2 ... A_N Output Print the number of problems that have a chance to be chosen for the problemset. Sample Input 1 6 1 2 2 2 1 1 3 0 2 Sample Output 1 5 If the only judge votes for problems 2 and 5 , the scores will be 2 2 1 3 1 2 . The problemset will consist of problem 4 and one of problems 1 , 2 , or 6 . If the only judge votes for problems 3 and 4 , the scores will be 2 1 2 4 0 2 . The problemset will consist of problem 4 and one of problems 1 , 3 , or 6 . Thus, problems 1 , 2 , 3 , 4 , and 6 have a chance to be chosen for the problemset. On the contrary, there is no way for problem 5 to be chosen. Sample Input 2 6 1 5 2 2 1 1 3 0 2 Sample Output 2 3 Only problems 1 , 4 , and 6 have a chance to be chosen. Sample Input 3 10 4 8 5 7 2 3 6 1 6 5 4 6 5 Sample Output 3 8
38,256
Score : 900 points Problem Statement There are N squares in a row. The squares are numbered 1, 2, ..., N from left to right. You have two pieces, initially placed on square A and B , respectively. You will be asked to process Q queries of the following kind, in the order received: Given an integer x_i , move one of the two pieces of your choice to square x_i . Here, it takes you one second to move a piece one square. That is, the time it takes to move a piece from square X to Y is |X-Y| seconds. Your objective is to process all the queries in the shortest possible time. You may only move the pieces in response to queries, and you may not move both pieces at the same time. Also, it is not allowed to rearrange the order in which queries are given. It is, however, allowed to have both pieces in the same square at the same time. Constraints 1 ≀ N, Q ≀ 200,000 1 ≀ A, B ≀ N 1 ≀ x_i ≀ N Input Input is given from Standard Input in the following format: N Q A B x_1 x_2 ... x_Q Output Let the shortest possible time to process all the queries be X seconds. Print X . Sample Input 1 8 3 1 8 3 5 1 Sample Output 1 7 All the queries can be processed in seven seconds, by: moving the piece at square 1 to 3 moving the piece at square 8 to 5 moving the piece at square 3 to 1 Sample Input 2 9 2 1 9 5 1 Sample Output 2 4 The piece at square 9 should be moved first. Sample Input 3 9 2 1 9 5 9 Sample Output 3 4 The piece at square 1 should be moved first. Sample Input 4 11 16 8 1 1 1 5 1 11 4 5 2 5 3 3 3 5 5 6 7 Sample Output 4 21
38,257
図曞敎理 数の衚わし方には色々な皮類があり、私たちが普段䜿っおいる 10 進数は䞀぀の代衚的なものでしかありたせん。コンピュヌタ関連の知識がある人には、2 進数、16 進数あたりはずおも身近なものです。 N さんは叞曞資栌を掻かしお叞曞の仕事に就きたした。最初の仕事は図曞敎理です。この図曞通では、䞀冊ごずに䞀貫しお番号が䞎えられおおり、それに埓っお本を敎理しおいたす。 この図曞通では本の番号をマむナス十進数で衚すこずになっおいたす。 マむナス十進数は、 a n a n−1 a n−2 ... a 2 a 1 a 0 (各 a i は 0~9 の数字) ず衚蚘する方法であり、この数は次の数を衚したす。 a n ×(−10) n + a n−1 ×(−10) n−1 + ... + a 2 ×(−10) 2 + a 1 ×(−10) 1 + a 0 ×(−10) 0 たずえば、マむナス十進数の 2156 は、以䞋のずおり十進数の-1944 に察応しおいたす。 2×(-10) 3 + 1×(-10) 2 + 5×(-10) 1 + 6×(-10) 0 = 2×(-1000) + 1×(100) + 5×(-10) + 6×(1) = -2000 + 100 - 50 + 6 = -1944 十進数の番号をマむナス十進数に盎すのは倧倉なので、N さんは倧倉䞍自由な思いをしおいたす。 本の番号を入力ずし、 この番号のマむナス十進数衚蚘を出力するプログラムを䜜成しおください。 Input 耇数のデヌタセットの䞊びが入力ずしお䞎えられたす。入力の終わりはれロひず぀の行で瀺されたす。各デヌタセットずしお、本の番号を衚す敎数 A (-2 31 ≀ A < 2 31 ) が行に䞎えられたす。 デヌタセットの数は 1200 を超えたせん。 Output 入力デヌタセットごずに、番号のマむナス十進数衚蚘を行に出力したす。 Sample Input 9 10 -10 -1944 -305432133 0 Output for the Sample Input 9 190 10 2156 1715573947
38,258
Problem E: SAT-EN-3 圌女は悩んでいた。成瞟が良くないのだ。䞡芪に無理を蚀っお党寮制の孊校に入孊したものの、圌女の才胜は䞀向に開花するこずはなかった。あるいは才胜など元々なかったのかもしれないが、それはできるだけ考えたくない可胜性だった。 そこで圌女が頌ったのは、むンタヌネット䞊で芋぀けた怪しげな脳力トレヌニングの教材だった。SAT-EN-3 (SATisifiability problem for Enhancement of Neuron: version 3) ず銘打぀その孊習メ゜ッドによるず、充足可胜性問題のようなもののむンスタンスをひたすら手で解くこずによっお、蚈算力が向䞊し、匕いおは論理的思考力・盎感力・想像力も豊かになり、郚掻動でも掻躍できお恋愛もうたくいくのだずいう。さすがに最埌の2぀は眉唟ものじゃないかな、ず圌女は思ったが、゜ロバンや癟マス蚈算のような䟋もあるこずだ。暗算が埗意になったら儲けものかな、ぐらいの気楜さで、圌女はこの教材に取り組んでみるこずにした。 SAT-EN-3では、加法暙準圢で衚される論理匏の各倉数に適切に割り圓お、論理匏の倀を真にするこずができるかどうか刀定しなければならない。ちなみに、1぀以䞊の倉数 (たたは、その吊定) の論理積を 節 (clause) ず呌び、いく぀かの節の論理和で衚される論理匏のみが加法暙準圢に埓っおいる。䞀般に充足可胜性問題ずいえば論理匏は乗法暙準圢で衚されるが、SAT-EN-3では加法暙準圢であるこずに泚意せよ。 圌女はしばらく SAT-EN-3 の問題集に取り組もうずしお、ふず思い盎した。問題集にお金を払うぐらいなら、プログラミングが埗意な芪友にパフェでもご銳走しお、 SAT-EN-3 の問題を生成し、解くプログラムを曞いおもらおう。そうすれば問題も解答もいくらでも手にはいるじゃないか。 こうしお圌女の芪友であるあなたは、SAT-EN-3を解くプログラムを曞くこずになったのである。 Input 入力は耇数のケヌスからなる。 各ケヌスは以䞋のフォヌマットで䞎えられる。 expression 入力の終わりは "#" からなる行によっお䞎えられる expression は以䞋のBNFに埓う。 ここでは文字列リテラルを""を甚いお囲んでいる。 実際の入力に""は含たれない。 たた入力には䜙蚈な空癜は含たれおいない。 <expression> ::= "("<clause>")" | "("<clause>")|("<expression>")" <clause> ::= <literal>"&"<literal>"&"<literal> <literal> ::= <variable> | "~"<variable> <variable> ::= [a-z]|[A-z] expression の長さは500文字を超えない。 テストケヌスの数は1100個を超えない。 Output 䞎えられた匏を満たす倉数の割り圓おが存圚するのならばyesを、そうでなければnoを出力せよ。 Sample input (B&B&f)|(~d&~i&i)|(~v&i&~V)|(~g&~e&o)|(~f&d&~v)|(d&~i&o)|(g&i&~B)|(~i&f&d)|(e&~i&~V)|(~v&f&~d) (S&X&~X) # Sample output yes no The University of Aizu Programming Contest 2011 Summer 原案: Tomoya Sakai 問題文: Takashi Tayama
38,259
E: Broccoli or Cauliflower Problem The input is a rooted tree T = (V, E) with n vertices. Note that n is odd and the vertex with index 1 is the root of T . In addition, we give a label G or W for each vertex. Let T_v = (U, F) be a subtree of T such that U is defined as following. U = $\{$ u \in V \ \ | \ \ u $\text{ is the descendant of }$ v $\}$ We call T_v a subtree of v . We consider the following operation and perform operations q times. Let v be a vertex. If a vertex u \in U has the label G , then we change the label of u G to W . Otherwise, we change the label of u W to G . After each operation, output “broccoli” if the number of vertices with the label G is greater than W . Otherwise, output “cauliflower”. Input format An input is the following format. n q p_2 ... p_n c_1 ... c_n v_1 $\vdots$ v_q In line 1 , there are two integers n and q , where n is the number of vertices in T and q is the number of queries. Note that n is odd. In line 2 , there are n - 1 integers p_2 to p_n . p_i represents the parent of a vertex v_i . In line 3 , there are n characters c_1 to c_n . c_i represents the label of v_i . Finally, in line j + 3 , there is an integer v_j . We perform the operation for T_{v_j} . Constraints 1 \leq n \leq 100,000 ( n is odd. ) 1 \leq q \leq 100,000 1 \leq p_i < i  2 \leq i \leq n  c_j is G or W . ( 1 \leq j \leq n ) 1 \leq v_i \leq n  1 \leq i \leq q  Output format An output consists q lines and output “broccoli” or “cauliflower” in each line. Input example 1 7 4 1 1 2 2 3 3 G G W W W G G 2 1 3 4 Output example 1 broccoli cauliflower cauliflower broccoli Input example 2 17 18 1 1 1 3 1 4 2 4 3 6 10 9 3 4 5 15 W W W W W W W W G W G G W G W W W 6 7 1 9 14 6 4 5 3 7 8 13 9 6 14 12 9 13 Output example 2 cauliflower cauliflower broccoli broccoli broccoli broccoli broccoli broccoli broccoli cauliflower cauliflower cauliflower cauliflower cauliflower broccoli cauliflower cauliflower cauliflower
38,260
柎犬の数 むヅア公園には、倕方になるず柎犬ず散歩する人たちがたくさん来たす。柎犬には毛の色によっお赀柎、黒柎、癜柎、胡麻柎ずいう皮類がありたす。柎犬がたくさんいるずうれしいトモ゚ちゃんは、それぞれの毛色の柎犬が䜕頭いるかがんばっお数えたしたが、ただ足し算ができないので柎犬が党郚で䜕頭いるかわかりたせん。 それぞれの毛色の柎犬の数が䞎えられたずきに、柎犬の総数を蚈算するプログラムを䜜成せよ。 入力 入力は以䞋の圢匏で䞎えられる。 $R$ $B$ $W$ $G$ 行に赀柎の数$R$ ($1 \leq R \leq 100$)、黒柎の数$B$ ($1 \leq B \leq 100$)、癜柎の数$W$ ($1 \leq W \leq 100$)、胡麻柎の数$G$ ($1 \leq G \leq 100$)が䞎えられる。 出力 柎犬の総数を行に出力する。 入出力䟋 入力䟋 4 2 1 1 出力䟋 8 入力䟋 22 18 34 36 出力䟋 110
38,261
Beautiful Currency KM country has N kinds of coins and each coin has its value a_i . The king of the country, Kita_masa, thought that the current currency system is poor, and he decided to make it beautiful by changing the values of some (possibly no) coins. A currency system is called beautiful if each coin has an integer value and the ( i +1)-th smallest value is divisible by the i -th smallest value for all i ( 1 \leq i \leq N-1 ). For example, the set {1, 5, 10, 50, 100, 500} is considered as a beautiful system, while the set {1, 5, 10, 25, 50, 100} is NOT, because 25 is not divisible by 10 . Since changing the currency system may confuse citizens, the king, Kita_masa, wants to minimize the maximum value of the confusion ratios. Here, the confusion ratio for the change in the i -th coin is defined as |a_i - b_i| / a_i , where a_i and b_i is the value of i -th coin before and after the structure changes, respectively. Note that Kita_masa can change the value of each existing coin, but he cannot introduce new coins nor eliminate existing coins. After the modification, the values of two or more coins may coincide. Input Each dataset contains two lines. The first line contains a single integer, N , and the second line contains N integers, {a_i} . You may assume the following constraints: 1 \leq N \leq 20 1 \leq a_1 \lt a_2 \lt... \lt a_N \lt 10^5 Output Output one number that represents the minimum of the maximum value of the confusion ratios. The value may be printed with an arbitrary number of decimal digits, but may not contain an absolute error greater than or equal to 10^{-8} . Sample Input 1 3 6 11 12 Output for the Sample Input 1 0.090909090909 Sample Input 2 3 6 11 24 Output for the Sample Input 2 0.090909090909 Sample Input 3 3 6 11 30 Output for the Sample Input 3 0.166666666667
38,262
Problem A: Plants Problem がっちょ君は暪 W 個×瞊 H 個のマスで区切られた畑を所有しおいる。 x 列目 y 行目のマスをマス (x, y) ず呌ぶこずにする。いく぀かのマスの土地には高さ0cmの怍物が1本だけ怍えおあり、その他のマスの土地には䜕も怍えられおいない。 がっちょ君はある時刻に畑に肥料をたく。肥料がたかれたマスに怍物が怍えられおいるずき、その怍物の高さが1cm䌞びる。怍物が怍えられおいないずきは、䜕もおこらない。怍物が䌞びるのにかかる時間はずおも短いので無芖できる。がっちょ君は同じ時刻に耇数のマスに肥料をたくこずができる。ただし、同じ時刻に同じマスに2床以䞊肥料をたくこずはない。 がっちょ君が肥料をたいた蚘録が䞎えられたずき、時刻 T 時点での畑の怍物の高さの和を蚈算せよ。 Input 入力は以䞋の圢匏で䞎えられる。 W H T p x 0 y 0 t 0 x 1 y 1 t 1 ... x p−1 y p−1 t p−1 s 0,0 s 1,0 
 s W−1,0 s 0,1 s 1,1 
 s W−1,1 ... s 0,H−1 s 1,H−1 
 s W−1,H−1 1行目に畑の暪幅 W 、畑の瞊幅 H 、時刻 T が䞎えられる。がっちょ君は時刻 T たでに肥料をたきおえる。 2行目にがっちょ君が肥料をたいた回数 p が䞎えられる。 3行目から2+ p 行目たでに䞎えられる぀の敎数は、がっちょ君が時刻 t i にマス( x i , y i )に肥料をたいたこずを衚す。 3+ p 行目から2+ p + H 行目たでは、最初の畑のそれぞれのマスに怍物が怍えられおいるかどうかを衚す W × H 個の敎数が䞎えられる。 s j,k が1のずきマス( j , k )に高さ0cmの怍物が1本だけ怍えられおいるこずを衚し、 s j,k が0のずきマス( j , k )に怍物は1本も怍えられおいないこずを衚す。 Constraints 1 ≀ W , H , T ≀ 50 0 ≀ p ≀ min( W × H × T , 50) 0 ≀ x i < W 0 ≀ y i < H 0 ≀ t i < T s j,k = 0たたは1 Output 時刻 T での畑の怍物の高さの和を1行に出力せよ。 Sample Input 1 3 3 3 5 2 0 0 0 1 0 1 1 1 1 2 1 2 2 0 0 0 0 0 1 0 0 0 0 Sample Output 1 1 Sample Input 2 2 3 4 2 0 0 0 1 1 3 1 0 0 0 0 0 Sample Output 2 1 Sample Input 3 3 8 6 6 0 4 3 2 5 3 0 2 3 2 2 5 1 1 3 2 2 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 1 1 1 0 1 0 1 0 1 0 Sample Output 3 4 Sample Input 4 8 3 3 7 0 1 1 5 1 0 4 0 2 3 2 0 3 1 1 3 0 1 5 1 1 1 0 1 1 0 0 1 0 0 0 1 1 0 1 0 1 0 1 0 0 0 1 0 1 Sample Output 4 4
38,263
Problem H: Round Table You are the owner of a restaurant, and you are serving for N customers seating in a round table. You will distribute M menus to them. Each customer receiving a menu will make the order of plates, and then pass the menu to the customer on the right unless he or she has not make the order. The customer i takes L i unit time for the ordering. Your job is to write a program to calculate the minimum time until all customers to call their orders, so you can improve your business performance. Input The input consists of a sequence of positive integers. The first line of the input contains two positive integers N ( N ≀ 50,000) and M ( M ≀ N ). The second line contains N positive integers L 1 , L 2 ,..., L N ( L i ≀ 600). Output Output the minimum possible time required for them to finish ordering. Sample Input and Output Input #1 3 2 1 5 10 Output #1 10 Input #2 4 2 1 2 3 4 Output #2 5
38,264
Presentation You are a researcher investigating algorithms on binary trees. Binary tree is a data structure composed of branch nodes and leaf nodes. Every branch nodes have left child and right child, and each child is either a branch node or a leaf node. The root of a binary tree is the branch node which has no parent. You are preparing for your presentation and you have to make a figure of binary trees using a software. You have already made a figure corresponding to a binary tree which is composed of one branch node and two leaf nodes (Figure 1.) However, suddenly the function of your software to create a figure was broken. You are very upset because in five hours you have to make the presentation in front of large audience. You decided to make the figure of the binary trees using only copy function, shrink function and paste function of the presentation tool. That is, you can do only following two types of operations. Copy the current figure to the clipboard. The figure copied to the clipboard before is removed. Paste the copied figure (with shrinking, if needed), putting the root of the pasted figure on a leaf node of the current figure. You can paste the copied figure multiple times. Moreover, you decided to make the figure using the minimum number of paste operations because paste operation is very time cosuming. Now, your job is to calculate the minimum possible number of paste operations to produce the target figure. Figure 1: initial state For example, the answer for the instance of sample 1(Figure 4) is 3, because you can produce the target figure by following operations and this is minimum. Figure 2: intermediate 1 Figure 3: intermediate 2 Figure 4: Goal Input The input is a line which indicates a binary tree. The grammar of the expression is given by the following BNF. <tree> ::= <leaf> | "(" <tree> <tree> ")" <leaf> ::= "()" Every input obeys this syntax. You can assume that every tree in the input has at least 1 branch node, and that it has no more than 10^5 branch nodes. Output A line containing the minimum possible number of paste operations to make the given binary tree. Sample Input 1 ((()())(((()())(()()))())) Output for the Sample Input 1 3 Sample Input 2 (((()())(()()))(()())) Output for the Sample Input 2 4 Sample Input 3 ((()(()()))((()(()()))())) Output for the Sample Input 3 3 Sample Input 4 (()()) Output for the Sample Input 4 0
38,265
Space Coconut Crab 宇宙ダシガニ English text is not available in this practice contest. ケン・マリンブルヌは宇宙ダシガニを求めお党銀河を旅するスペヌスハンタヌである宇宙ダシガニは宇宙最倧ずされる甲殻類であり成長埌の䜓長は 400 メヌトル以䞊足を広げれば 1,000 メヌトル以䞊にもなるず蚀われおいる既に倚数の人々が宇宙ダシガニを目撃しおいるが誰䞀人ずしお捕らえるこずに成功しおいない ケンは長期間の調査によっお宇宙ダシガニの生態に関する重芁な事実を解明した宇宙ダシガニは驚くべきこずに盞転移航法ず呌ばれる最新のワヌプ技術ず同等のこずを行い通垞空間ず超空間の間を埀来しながら生きおいたさらに宇宙ダシガニが超空間から通垞空間にワヌプアりトするたでには長い時間がかかりたたワヌプアりトしおからしばらくは超空間に移動できないこずも突き止めた そこでケンは぀いに宇宙ダシガニの捕獲に乗り出すこずにした戊略は次のずおりであるはじめに宇宙ダシガニが通垞空間から超空間に突入する際の゚ネルギヌを芳枬するこの゚ネルギヌを e ずするずき宇宙ダシガニが超空間からワヌプアりトする座暙 ( x , y , z ) は以䞋の条件を満たすこずがわかっおいる x , y , z はいずれも非負の敎数である x + y 2 + z 3 = e である 䞊蚘の条件の䞋で x + y + z の倀を最小にする これらの条件だけでは座暙が䞀意に決たるずは限らないが x + y + z の最小倀を m ずしたずきにワヌプアりトする座暙が平面 x + y + z = m 䞊にあるこずは確かであるそこでこの平面䞊に十分な倧きさのバリアを匵るするず宇宙ダシガニはバリアの匵られたずころにワヌプアりトするこずになるバリアの圱響を受けた宇宙ダシガニは身動きがずれなくなるそこをケンの操䜜する最新鋭宇宙船であるりェポン・ブレヌカヌ号で捕獲しようずいう段取りである バリアは䞀床しか匵るこずができないため倱敗するわけにはいかないそこでケンは任務の遂行にあたっお蚈算機の助けを借りるこずにしたあなたの仕事は宇宙ダシガニが超空間に突入する際の゚ネルギヌが䞎えられたずきにバリアを匵るべき平面 x + y + z = m を求めるプログラムを曞くこずである甚意されたテストケヌスの党おに察しお正しい結果を出力したずきあなたのプログラムは受け入れられるであろう Input 入力は耇数のデヌタセットで構成される各デヌタセットは 1 行のみからなり1 ぀の正の敎数 e ( e ≩ 1,000,000) が含たれるこれは宇宙ダシガニが超空間に突入した際の゚ネルギヌを衚す入力は e = 0 の時に終了しこれはデヌタセットには含たれない Output 各デヌタセットに぀いお m の倀を 1 行に出力しなさい出力には他の文字を含めおはならない Sample Input 1 2 4 27 300 1250 0 Output for the Sample Input 1 2 2 3 18 44
38,266
Red Dragonfly It’s still hot every day, but September has already come. It’s autumn according to the calendar. Looking around, I see two red dragonflies at rest on the wall in front of me. It’s autumn indeed. When two red dragonflies’ positional information as measured from the end of the wall is given, make a program to calculate the distance between their heads. Input The input is given in the following format. $x_1$ $x_2$ The input line provides dragonflies’ head positions $x_1$ and $x_2$ ($0 \leq x_1, x_2 \leq 100$) as integers. Output Output the distance between the two red dragonflies in a line. Sample Input 1 20 30 Sample Output 1 10 Sample Input 2 50 25 Sample Output 2 25 Sample Input 3 25 25 Sample output 3 0
38,267
Problem E: The Genome Database of All Space Life In 2300, the Life Science Division of Federal Republic of Space starts a very ambitious project to complete the genome sequencing of all living creatures in the entire universe and develop the genomic database of all space life. Thanks to scientific research over many years, it has been known that the genome of any species consists of at most 26 kinds of molecules, denoted by English capital letters ( i.e. A to Z ). What will be stored into the database are plain strings consisting of English capital letters. In general, however, the genome sequences of space life include frequent repetitions and can be awfully long. So, for efficient utilization of storage, we compress N -times repetitions of a letter sequence seq into N ( seq ) , where N is a natural number greater than or equal to two and the length of seq is at least one. When seq consists of just one letter c , we may omit parentheses and write Nc . For example, a fragment of a genome sequence: ABABABABXYXYXYABABABABXYXYXYCCCCCCCCCC can be compressed into: 4(AB)XYXYXYABABABABXYXYXYCCCCCCCCCC by replacing the first occurrence of ABABABAB with its compressed form. Similarly, by replacing the following repetitions of XY , AB , and C , we get: 4(AB)3(XY)4(AB)3(XY)10C Since C is a single letter, parentheses are omitted in this compressed representation. Finally, we have: 2(4(AB)3(XY))10C by compressing the repetitions of 4(AB)3(XY) . As you may notice from this example, parentheses can be nested. Your mission is to write a program that uncompress compressed genome sequences. Input The input consists of multiple lines, each of which contains a character string s and an integer i separated by a single space. The character string s , in the aforementioned manner, represents a genome sequence. You may assume that the length of s is between 1 and 100, inclusive. However, of course, the genome sequence represented by s may be much, much, and much longer than 100. You may also assume that each natural number in s representing the number of repetitions is at most 1,000. The integer i is at least zero and at most one million. A line containing two zeros separated by a space follows the last input line and indicates the end of the input. Output For each input line, your program should print a line containing the i -th letter in the genome sequence that s represents. If the genome sequence is too short to have the i -th element, it should just print a zero. No other characters should be printed in the output lines. Note that in this problem the index number begins from zero rather than one and therefore the initial letter of a sequence is its zeroth element. Sample Input ABC 3 ABC 0 2(4(AB)3(XY))10C 30 1000(1000(1000(1000(1000(1000(NM)))))) 999999 0 0 Output for the Sample Input 0 A C M
38,268
Cube Dividing Pablo Cubarson is a well-known cubism artist. He is producing a new piece of work using a cuboid which consists of $A \times B \times C$ unit cubes. He plans to make a beautiful shape by removing $N$ units cubes from the cuboid. When he is about to begin the work, he has noticed that by the removal the cuboid may be divided into several parts disconnected to each other. It is against his aesthetics to divide a cuboid. So he wants to know how many parts are created in his plan. Your task is to calculate the number of connected components in the cuboid after removing the $N$ cubes. Two cubes are connected if they share one face. Input The input consists of a single test case. The test case is formatted as follows: $A$ $B$ $C$ $N$ $X_1$ $Y_1$ $Z_1$ ... $X_N$ $Y_N$ $Z_N$ The first line contains four integers $A$, $B$, $C$ and $N$. $A$, $B$ and $C$ ($1 \leq A,B,C \leq 10^6$) denote the size of the cuboid $-$ the cuboid has an $A$ unit width from left to right and a $B$ unit height from bottom to top, and a $C$ unit depth from front to back. $N$ ($0 \leq N \leq 20,000, N \leq A \times B \times C - 1$) denotes the number of the cubes removed in the Cubarson's plan. Each of the following $N$ lines contains three integers $X_i$ ($0 \leq X_i \leq A-1$), $Y_i$ ($0 \leq Y_i \leq B-1$) and $Z_i$ ($0 \leq Z_i \leq C - 1$). They denote that the cube located at the $X_i$-th position from the left, the $Y_i$-th from the bottom and the $Z_i$-th from the front will be removed in the plan. You may assume the given positions are distinct. Output Print the number of the connected components in the cuboid after removing the specified cubes. Sample Input 1 2 2 2 4 0 0 0 1 1 0 1 0 1 0 1 1 Output for the Sample Input 1 4 Sample Input 2 3 3 3 1 1 1 1 Output for the Sample Input 2 1 Sample Input 3 1 1 3 2 0 0 0 0 0 2 Output for the Sample Input 3 1
38,269
Score : 700 points Problem Statement There is a tree with N vertices, numbered 1 through N . The i -th of the N-1 edges connects vertices a_i and b_i . Currently, there are A_i stones placed on vertex i . Determine whether it is possible to remove all the stones from the vertices by repeatedly performing the following operation: Select a pair of different leaves. Then, remove exactly one stone from every vertex on the path between those two vertices. Here, a leaf is a vertex of the tree whose degree is 1 , and the selected leaves themselves are also considered as vertices on the path connecting them. Note that the operation cannot be performed if there is a vertex with no stone on the path. Constraints 2 ≩ N ≩ 10^5 1 ≩ a_i,b_i ≩ N 0 ≩ A_i ≩ 10^9 The given graph is a tree. Input The input is given from Standard Input in the following format: N A_1 A_2 
 A_N a_1 b_1 : a_{N-1} b_{N-1} Output If it is possible to remove all the stones from the vertices, print YES . Otherwise, print NO . Sample Input 1 5 1 2 1 1 2 2 4 5 2 3 2 1 3 Sample Output 1 YES All the stones can be removed, as follows: Select vertices 4 and 5 . Then, there is one stone remaining on each vertex except 4 . Select vertices 1 and 5 . Then, there is no stone on any vertex. Sample Input 2 3 1 2 1 1 2 2 3 Sample Output 2 NO Sample Input 3 6 3 2 2 2 2 2 1 2 2 3 1 4 1 5 4 6 Sample Output 3 YES
38,270
Sum of 4 Integers Write a program which reads an integer n and identifies the number of combinations of a, b, c and d (0 ≀ a, b, c, d ≀ 9) which meet the following equality: a + b + c + d = n For example, for n = 35, we have 4 different combinations of ( a, b, c, d ): ( 8, 9, 9, 9 ), ( 9, 8, 9, 9 ), ( 9, 9, 8, 9 ), and ( 9, 9, 9, 8 ). Input The input consists of several datasets. Each dataset consists of n (1 ≀ n ≀ 50) in a line. The number of datasets is less than or equal to 50. Output Print the number of combination in a line. Sample Input 35 1 Output for the Sample Input 4 4
38,271
F: 赀黒そヌるじぇむ / Red-Black Soul Gem 問題 ほむちゃんは、そヌるじぇむを赀色や黒色に倉化させたり、 異なる 2 ぀のそヌるじぇむ間を魔法の糞で接続したりする䞍思議な力を持っおいたす。 この力を䜿うこずで、ほむちゃんは、そヌるじぇむによる魔方陣を䜜るこずができたす。 ほむちゃんは、 1 から N で番号付けられた N 個のそヌるじぇむがあるずき、以䞋の条件が成り立぀異なる魔方陣がいく぀あるのか気になりたした。 どの 2 ぀のそヌるじぇむ間も、高々 1 回しか接続されない。 すべおのそヌるじぇむの色が、赀色か黒色のいずれかになっおいる。 任意のそヌるじぇむに察しお、自身の色ず異なる色のそヌるじぇむのうち、少なくずも 1 ぀ず接続されおいる。 このずき、魔方陣はそヌるじぇむを頂点ずし、魔法の糞を蟺ずするグラフずみなすこずができたす。 ここで、そのグラフは 連結でなくおもよい こずに泚意しおください。 ほむちゃんは蚈算が苊手なので、代わりにあなたが高速なプログラムを䜜っお異なる魔方陣の数を蚈算しおあげたしょう。 しかし、その数は非垞に倚いこずが予想されるので、ある玠数 M で割った䜙りを求めるこずにしたす。 なお、ある魔方陣 G ず H が異なるずは、あるそヌるじぇむ v に぀いお G ず H でその色が異なる、もしくはあるそヌるじぇむの組 u , v が G ず H の䞀方でのみ接続されおいるこずを指したす。 入力圢匏 N M 制玄 2 \leq N \leq 2,000 10^8 \leq M \leq 10^9 + 7 M は玠数であるこずが保蚌される 出力圢匏 条件を満たすグラフの個数を M で割った䜙りを敎数で 1 行に出力しおください。 入力䟋1 3 310779401 出力䟋1 12 䟋えば、以䞋のような魔方陣は条件を満たしたす。 入力䟋2 7 566666561 出力䟋2 98638848 䟋えば、以䞋のような魔方陣は条件を満たしたす。 入力䟋3 1010 1000000007 出力䟋3 862232855 M で割った䜙りを出力するこずに泚意しおください。
38,272
薄氷枡り 問題 冬の寒いある日JOI倪郎君は広堎にはった薄氷を割っお遊ぶこずにした広堎は長方圢で東西方向に m 個南北方向に n 個぀たり m × n の区画に区切られおいるたた薄氷が有る区画ず無い区画がある JOI倪郎君は次のルヌルにしたがっお薄氷を割りながら区画を移動するこずにした 薄氷があるどの区画からも薄氷を割り始めるこずができる 東西南北のいずれかの方向に隣接し ただ割られおいない薄氷のある区画に移動できる 移動した先の区画の薄氷をかならず割る JOI倪郎君が薄氷を割りながら移動できる区画数の最倧倀を求めるプログラムを䜜成せよただし 1 ≀ m ≀ 901 ≀ n ≀ 90 である䞎えられる入力デヌタでは移動方法は20䞇通りを超えない 入力 入力は耇数のデヌタセットからなる各デヌタセットは以䞋の圢匏で䞎えられる 入力はn+2行ある 1 行目には敎数 m が曞かれおいる 2 行目には敎数 n が曞かれおいる 3 行目から n+2 行目たでの各行には、0 もしくは 1 が 空癜で区切られお m 個曞かれおおり各区画に薄氷があるか吊かを衚しおいる北から i 番目西からj番目の区画を (i,j) ず蚘述するこずにするず (1 ≀ i ≀ n, 1 ≀ j ≀ m)第 i+2 行目の j 番目の倀は区画 (i,j) に薄氷が存圚する堎合は 1 ずなり区画 (i,j) に薄氷が存圚しない堎合は 0 ずなる m, n がずもに 0 のずき入力の終了を瀺す. デヌタセットの数は 5 を超えない 出力 デヌタセットごずに, 移動できる区画数の最倧倀を行に出力せよ 入出力䟋 入力䟋 3 3 1 1 0 1 0 1 1 1 0 5 3 1 1 1 0 1 1 1 0 0 0 1 0 0 0 1 0 0 出力䟋 5 5 1぀目の入力䟋に察しお最倧倀を䞎える移動方法の䟋 2぀目の入力䟋に察しお最倧倀を䞎える移動方法の䟋 2぀目の入力䟋に察しお最倧倀を䞎えない移動方法の䟋 䞊蚘問題文ず自動審刀に䜿われるデヌタは、 情報オリンピック日本委員䌚 が䜜成し公開しおいる問題文ず採点甚テストデヌタです。
38,273
Set Difference Find the difference of two sets $A = \{a_0, a_1, ..., a_{n-1}\}$ and $B = \{b_0, b_1, ..., b_{m-1}\}$, $A - B$. Input The input is given in the following format. $n$ $a_0 \; a_1 \; ... \; a_{n-1}$ $m$ $b_0 \; b_1 \; ... \; b_{m-1}$ Elements in $A$ and $B$ are given in ascending order. There are no duplicate elements in each set. Output Print elements in the difference in ascending order. Print an element in a line. Constraints $1 \leq n, m \leq 200,000$ $0 \leq a_0 < a_1 < ... < a_{n-1} \leq 10^9$ $0 \leq b_0 < b_1 < ... < b_{m-1} \leq 10^9$ Sample Input 1 5 1 2 3 5 8 2 2 5 Sample Output 1 1 3 8
38,274
Score : 400 points Problem Statement Given is a rooted tree with N vertices numbered 1 to N . The root is Vertex 1 , and the i -th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i . Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0 . Now, the following Q operations will be performed: Operation j (1 \leq j \leq Q) : Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j . Find the value of the counter on each vertex after all operations. Constraints 2 \leq N \leq 2 \times 10^5 1 \leq Q \leq 2 \times 10^5 1 \leq a_i < b_i \leq N 1 \leq p_j \leq N 1 \leq x_j \leq 10^4 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 : a_{N-1} b_{N-1} p_1 x_1 : p_Q x_Q Output Print the values of the counters on Vertex 1, 2, \ldots, N after all operations, in this order, with spaces in between. Sample Input 1 4 3 1 2 2 3 2 4 2 10 1 100 3 1 Sample Output 1 100 110 111 110 The tree in this input is as follows: Each operation changes the values of the counters on the vertices as follows: Operation 1 : Increment by 10 the counter on every vertex contained in the subtree rooted at Vertex 2 , that is, Vertex 2, 3, 4 . The values of the counters on Vertex 1, 2, 3, 4 are now 0, 10, 10, 10 , respectively. Operation 2 : Increment by 100 the counter on every vertex contained in the subtree rooted at Vertex 1 , that is, Vertex 1, 2, 3, 4 . The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 110, 110 , respectively. Operation 3 : Increment by 1 the counter on every vertex contained in the subtree rooted at Vertex 3 , that is, Vertex 3 . The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 111, 110 , respectively. Sample Input 2 6 2 1 2 1 3 2 4 3 6 2 5 1 10 1 10 Sample Output 2 20 20 20 20 20 20
38,275
Score : 200 points Problem Statement You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S . If every lowercase English letter occurs in S , print None instead. Constraints 1 \leq |S| \leq 10^5 ( |S| is the length of string S .) S consists of lowercase English letters. Input Input is given from Standard Input in the following format: S Output Print the lexicographically smallest lowercase English letter that does not occur in S . If every lowercase English letter occurs in S , print None instead. Sample Input 1 atcoderregularcontest Sample Output 1 b The string atcoderregularcontest contains a , but does not contain b . Sample Input 2 abcdefghijklmnopqrstuvwxyz Sample Output 2 None This string contains every lowercase English letter. Sample Input 3 fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg Sample Output 3 d
38,276
G: Computer Onesan / コンピュヌタおねえさん ある日おねえさんは子䟛たちに組合せの数え方に぀いお教えおあげるこずになりたした そこでおねえさんは次のような問題を解いおみるこずにしたした 瞊幅 1 暪幅 1 の正方圢を瞊幅 N 暪幅 M の長方圢に敷き詰めたずきに長方圢の巊䞊の頂点から右䞋の頂点ぞの通り方が䜕通りあるかを数える 敷き詰めた正方圢の蟺の䞊しか通れない それぞれの通り方は同じ堎所を1床しか通らない 図1に N = 2, M = 2 の堎合の党おの通り方を瀺したす 図1では党郚で12通りの通り方を瀺しおおりその経路は赀い倪線で衚しおいたす 図1: N = 2, M = 2 の堎合の党おの通り方 この問題では N ず M が少し倧きくなるだけで組合せの数が爆発的に増加しおしたい手で数えるのがずおも難しくなっおしたいたす そこでおねえさんは自分の頭脳をロボットに移怍し25䞇幎をかけお10 x 10 の堎合の組合せの数を数える蚈画を立おたした 「10 x 10 なんお蚈算するずおねえさん死んじゃうやめお」 止める子䟛たちをよそにおねえさんは蚈算を開始したす おねえさんはそこたでしおでも子䟛たちに組合せ爆発のすごさを教えおあげたいのです おねえさんの熱意に心打たれたプログラマヌのあなたはこの問題を解くプログラムを曞いおあげるこずにしたした ずいっおもいきなり 10 x 10 を蚈算するプログラムを䜜るのは難しいので手始めに M が小さい堎合のプログラムを曞くこずにしたした Input 入力は1行に N ず M が半角スペヌスで䞎えられたす N は長方圢の瞊の幅で1 <= N <= 100を満たしたす M は長方圢の暪の幅で1 <= M <= 2を満たしたす Output 入力に察する通り方の数を1行に出力しおください ただし答えが非垞に倧きくなる堎合があるので1,000,000で割った䜙りを出力しおください Sample Input 1 1 1 Sample Output 1 2 Sample Input 2 1 2 Sample Output 2 4 Sample Input 3 2 1 Sample Output 3 4 Sample Input 4 2 2 Sample Output 4 12 Sample Input 5 3 2 Sample Output 5 38
38,277
Problem J: Billion Million Thousand A linguist, Nodvic Natharus Damenhof (commonly called Dr. Usoperant ), invented an artificial language Usoperant in 2007. The word usoperant means ‘one which tires’. Damenhof’s goal was to create a complex and pedantic language that would remind many difficulties in universal communications. Talking in Usoperant, you should remember the importance of choosing your words in many conversations. For example of the complexity, you may be confused by the way to say large numbers. Usoperant has some words that indicate exponential numbers in decimal, described as 10 p where p is a positive integer. In terms of English, those words might include thousand for 10 3 (1,000), million for 10 6 (1,000,000), and undecillion for 10 36 (1,000,000,000,000,000,000,000,000,000,000,000,000). You can concatinate those words to express larger numbers. When two words w 1 and w 2 mean numbers 10 p 1 and 10 p 2 respectively, a concatinated word w 1 w 2 means 10 p 1 + p 2 . Using the above examples in English (actually the following examples are incorrect in English), you can say 10 9 by millionthousand , 10 12 by millionmillion and 10 39 by undecillionthousand . Note that there can be multiple different expressions for a certain number. For example, 10 9 can also be expressed by thousandthousandthousand . It is also possible to insert separators between the adjacent components like million-thousand and thousand-thousand-thousand . In this problem, you are given a few of such words, their representing digits and an expression of a certain number in Usoperant. Your task is to write a program to calculate the length of the shortest expression which represents the same number as the given expression. The expressions in the input do not contain any separators like millionthousand . In case of ambiguity, the expressions should be interpreted as the largest number among possibles. The resultant expressions should always contain separators like million-thousand , so we can distinguish, for example, x - x (a concatinated word of two x 's) and xx (just a single word). The separators should not be counted in the length. Input The input consists of multiple test cases. Each test case begins with a line including an integer N (1 ≀ N ≀ 100). The integer N indicates the number of words in the dictionary of exponential numbers. The following N lines give the words in the dictionary. Each line contains a word w i and an integer p i (1 ≀ i ≀ N , 1 ≀ p i ≀ 10), specifying that the word w i expresses an exponential number 10 p i in Usoperant. Each w i consists of at most 100 alphabetical letters. Then a line which contains an expression of a number in Usoperant follows. The expression consists of at most 200 alphabetical letters. The end of the input is indicated by a line which contains only a single 0. Output For each test case, print a line which contains the case number and the length of the shortest expression which represents the same number as the given expression in the input. Sample Input 3 billion 9 million 6 thousand 3 billionmillionthousand 3 oku 8 sen 3 man 4 okusenman 2 nico 2 video 4 niconicovideo 6 abcd 1 efgh 2 abcde 4 fgh 6 y 8 yy 10 abcdefgh 0 Output for the Sample Input Case 1: 14 Case 2: 9 Case 3: 10 Case 4: 2 Note: In the fourth case, the word abcdefgh can be separated as abcd-efgh (representing 10 3 ) and abcde-fgh (representing 10 10 ), and by the rule described in the problem statement, this word should be interpreted as 10 10 . As this number can be expressed by yy , the length of the shortest expression is two (as in the sample output). The existence of y - y (representing 10 16 ) is not a problem here, because we can distinguish yy and y - y as long as we always use separators.
38,279
Score : 300 points Problem Statement Given is a string S of length N-1 . Each character in S is < or > . A sequence of N non-negative integers, a_1,a_2,\cdots,a_N , is said to be good when the following condition is satisfied for all i ( 1 \leq i \leq N-1 ): If S_i= < : a_i<a_{i+1} If S_i= > : a_i>a_{i+1} Find the minimum possible sum of the elements of a good sequence of N non-negative integers. Constraints 2 \leq N \leq 5 \times 10^5 S is a string of length N-1 consisting of < and > . Input Input is given from Standard Input in the following format: S Output Find the minimum possible sum of the elements of a good sequence of N non-negative integers. Sample Input 1 <>> Sample Output 1 3 a=(0,2,1,0) is a good sequence whose sum is 3 . There is no good sequence whose sum is less than 3 . Sample Input 2 <>>><<><<<<<>>>< Sample Output 2 28
38,280
Score : 200 points Problem Statement Takahashi has two positive integers A and B . It is known that A plus B equals N . Find the minimum possible value of "the sum of the digits of A " plus "the sum of the digits of B " (in base 10 ). Constraints 2 ≀ N ≀ 10^5 N is an integer. Input Input is given from Standard Input in the following format: N Output Print the minimum possible value of "the sum of the digits of A " plus "the sum of the digits of B ". Sample Input 1 15 Sample Output 1 6 When A=2 and B=13 , the sums of their digits are 2 and 4 , which minimizes the value in question. Sample Input 2 100000 Sample Output 2 10
38,282
Problem I: Coin and Die Problem 衚ず裏のあるコむンず $1$ から $N$ たでの目があるサむコロがある。Gachoくんはこれらを甚いお以䞋のゲヌムをしお遊ぶこずにした。 ゲヌムは最初に埗点が $0$ の状態から始たり、以䞋の手順で進められる。 サむコロを $1$ 回振り、そのずき出た目の数を埗点に加算する 珟圚の埗点が $K$ 以䞊ならゲヌムクリアずなりゲヌムを終了する 珟圚の埗点が $K$ 未満ならコむンを投げ衚が出れば1.に戻り、裏が出ればゲヌムオヌバヌずなりゲヌムを終了する コむンは投げるず $A\%$の確率で衚になり、 $(100-A)\%$の確率で裏になる。たた、サむコロは振るず、それぞれの目が等確率で出珟する。 このずき、䞀床のゲヌムでGachoくんがゲヌムクリアするこずができる確率を求めよ。 求める確率を互いに玠な敎数 $P, Q$ を甚いお $\frac{P}{Q}$ ず衚したずき、 $R \times Q \equiv P\bmod 998244353$ ずなる $0$ 以䞊 $998244352$ 以䞋の敎数 $R$ を出力せよ。この問題の制玄䞋で、このような $R$ は必ず䞀意に存圚する。 Input 入力は以䞋の圢匏で䞎えられる。 $N$ $K$ $A$ $N, K, A$ が空癜区切りで䞀行に䞎えられる。 Constraints 入力は以䞋の条件を満たす。 $1 \leq N \leq 10^5 $ $1 \leq K \leq 10^5 $ $1 \leq A \leq 99 $ 入力はすべお敎数 Output ゲヌムをクリアするこずができる確率を互いに玠な敎数 $P, Q$を甚いお $\frac{P}{Q}$ ず衚したずき、$R \times Q\equiv P\bmod 998244353$ ずなる $0$ 以䞊 $998244352$ 以䞋の敎数 $R$ を出力せよ。 Sample Input 1 1 1 50 Sample Output 1 1 Sample Input 2 2 2 10 Sample Output 2 648858830 Sample Input 3 6 10 99 Sample Output 3 650893870
38,283