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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.