task stringlengths 0 154k | __index_level_0__ int64 0 39.2k |
|---|---|
Problem F: Tighten Up! We have a flat panel with two holes. Pins are nailed on its surface. From the back of the panel, a string comes out through one of the holes to the surface. The string is then laid on the surface in a form of a polygonal chain, and goes out to the panel's back through the other hole. Initially, the string does not touch any pins. Figures F-1, F-2, and F-3 show three example layouts of holes, pins and strings. In each layout, white squares and circles denote holes and pins, respectively. A polygonal chain of solid segments denotes the string. Figure F-1: An example layout of holes, pins and a string Figure F-2: An example layout of holes, pins and a string Figure F-3: An example layout of holes, pins and a string When we tie a pair of equal weight stones to the both ends of the string, the stones slowly straighten the string until there is no loose part. The string eventually forms a different polygonal chain as it is obstructed by some of the pins. (There are also cases when the string is obstructed by no pins, though.) The string does not hook itself while being straightened. A fully tightened string thus draws a polygonal chain on the surface of the panel, whose vertices are the positions of some pins with the end vertices at the two holes. The layouts in Figures F-1, F-2, and F-3 result in the respective polygonal chains in Figures F-4, F-5, and F-6. Write a program that calculates the length of the tightened polygonal chain. Figure F-4: Tightened polygonal chains from the example in Figure F-1. Figure F-5: Tightened polygonal chains from the example in Figure F-2. Figure F-6: Tightened polygonal chains from the example in Figure F-3. Note that the strings, pins and holes are thin enough so that you can ignore their diameters. Input The input consists of multiple datasets, followed by a line containing two zeros separated by a space. Each dataset gives the initial shape of the string (i.e., the positions of holes and vertices) and the positions of pins in the following format. m n x 1 y 1 ... x l y l The first line has two integers m and n (2 †m †100, 0 †n †100), representing the number of vertices including two holes that give the initial string shape ( m ) and the number of pins ( n ). Each of the following l = m + n lines has two integers x i and y i (0 †x i †1000, 0 †y i †1000), representing a position P i = ( x i , y i ) on the surface of the panel. Positions P 1 , ..., P m give the initial shape of the string; i.e., the two holes are at P 1 and P m , and the string's shape is a polygonal chain whose vertices are P i ( i = 1, ..., m ), in this order. Positions P m +1 , ..., P m + n are the positions of the pins. Note that no two points are at the same position. No three points are exactly on a straight line. Output For each dataset, the length of the part of the tightened string that remains on the surface of the panel should be output in a line. No extra characters should appear in the output. No lengths in the output should have an error greater than 0.001. Sample Input 6 16 5 4 11 988 474 975 459 16 985 12 984 982 242 227 140 266 45 410 92 570 237 644 370 567 406 424 336 290 756 220 634 251 511 404 575 554 726 643 868 571 907 403 845 283 10 4 261 196 943 289 859 925 56 822 112 383 514 0 1000 457 514 1000 0 485 233 224 710 242 850 654 485 915 140 663 26 5 0 953 180 0 299 501 37 301 325 124 162 507 84 140 913 409 635 157 645 555 894 229 598 223 783 514 765 137 599 445 695 126 859 462 599 312 838 167 708 563 565 258 945 283 251 454 125 111 28 469 1000 1000 185 319 717 296 9 315 372 249 203 528 15 15 200 247 859 597 340 134 967 247 421 623 1000 427 751 1000 102 737 448 0 978 510 556 907 0 582 627 201 697 963 616 608 345 819 810 809 437 706 702 695 448 474 605 474 329 355 691 350 816 231 313 216 864 360 772 278 756 747 529 639 513 525 0 0 Output for the Sample Input 2257.0518296609 3609.92159564177 2195.83727086364 3619.77160684813 | 35,600 |
Score : 200 points Problem Statement Given is a string S . Replace every character in S with x and print the result. Constraints S is a string consisting of lowercase English letters. The length of S is between 1 and 100 (inclusive). Input Input is given from Standard Input in the following format: S Output Replace every character in S with x and print the result. Sample Input 1 sardine Sample Output 1 xxxxxxx Replacing every character in S with x results in xxxxxxx . Sample Input 2 xxxx Sample Output 2 xxxx Sample Input 3 gone Sample Output 3 xxxx | 35,601 |
F : åµ / Eggs å顿 1 ãæåã®ããšã§ããïŒ å°åŠçã®è西åã¯å€äŒã¿ã®å®¿é¡ããã£ãŠããªãã£ãïŒ ããã§èªç±ç ç©¶ã¯å®¶ã«ãã£ãåµã®åŒ·åºŠã調ã¹ãããšã«ããïŒ ãã®ç ç©¶ã«ãããŠïŒåµãé«ã H ããèœãšããŠãå²ããïŒ é«ã H+1 ããèœãšããšå²ãããšãïŒ ãã®åµã®åŒ·åºŠã¯ H ã§ãããšå®çŸ©ããïŒ ããã§ H ã¯éè² æŽæ°ã§ããïŒéè² æŽæ°ä»¥å€ã®é«ãããèœãšãããšã¯ç¡ããšããïŒ è西ããã¯åµã 1 ã€èœäžãããå®éšãè¡ãïŒ å®éšã®çµæã¯å²ãããå²ããªããã®ããããã§ããïŒ ãŸãïŒåµã®åŒ·åºŠã¯å
šãŠåãã§ããïŒã€ãŸãïŒã©ã®åµãçšããŠãå®éšã®çµæã¯åãã§ããïŒ è西ããã¯é«ã 1 ãã N ãŸã§ã®æŽæ°ã®é«ãã®æ®µãããªãéæ®µãšïŒ 匷床ãäžæãª E åã®åµãçšæããïŒ é«ã 0 ã§ã¯å²ããïŒé«ã N+1 ã§ã¯å²ãããšããããšã¯æ¢ã«ããã£ãŠããïŒ è西ããã¯å段ãšåãé«ãããå°é¢ã«åãã£ãŠèœãšãïŒãã®åºŠã«åµãå²ãããå²ããªãã£ããã調ã¹ãïŒ ãã®ãšãå²ããåµã¯äºåºŠãšäœ¿ããªããïŒå²ããªãã£ãå Žåã¯åå©çšã§ããïŒ ãã®å®éšãåµãæ®ã£ãŠããéãç¶ããããšãã§ããïŒ äœåºŠãå®éšãç¹°ãè¿ãïŒäžã«å®ãã H ãæ±ãŸã£ããšãïŒåµã®åŒ·åºŠãæ±ãŸã£ããšããïŒ å€äŒã¿çµäºãŸã§åŸæ°æ¥ããç¡ãïŒ æå°ã®åæ°ã§å®éšãçµããããªããšéã«åããªãïŒ ããã§ïŒè西ããã®å
ã§ããããªãã¯ïŒåµã®åŒ·åºŠãç¥ãããã« èœãšãåæ°ãå°ãªããªãããã«æé©ãªæ¹æ³ããšã£ãå Žåã« å¿
èŠãªå®éšåæ°ã®æå€§å€ãæ±ããããã°ã©ã ãæžãããšã«ããïŒ å
¥å T N_1 E_1 ⊠N_T E_T 1 ã€ã®ãã¡ã€ã«ã«è€æ°ã®ãã¹ãã±ãŒã¹ãå«ãŸããïŒ 1 è¡ç®ã«æŽæ° T ãäžããããïŒ 1+i è¡ç®ã« i çªç®ã®ãã¹ãã±ãŒã¹ E_i, N_i ãäžãããã å¶çŽ æŽæ°ã§ãã 1 †T †1000 1 †N_i †10^{18} 1 †E_i †50 åºåã 50 ãè¶
ãããããªå
¥åã¯å«ãŸããªã åºå i çªç®ã®ãã¹ãã±ãŒã¹ã«å¯Ÿããçãã i è¡ç®ã«åºåããïŒ å
šäœã§ T è¡ã«ãããïŒ ãµã³ãã« ãµã³ãã«å
¥å1 3 5 1 5 2 1 2 ãµã³ãã«åºå1 5 3 1 1 ã€ç®ã®å Žå åµã 1 ã€ãããªããã 1 段ç®ããé ã«èœãšããŠãããããªã 2 ã€ç®ã®å Žå ãŸã 2 段ç®ããèœãšã 2 段ç®ããèœãšããŠå²ããå Žå 1 段ç®ããèœãšã 2 段ç®ããèœãšããŠå²ããªãã£ãå Žå 4 段ç®ããèœãšã 1 段ç®ããèœãšããŠå²ããå Žåå®éšçµäº 1 段ç®ããèœãšããŠå²ããªãã£ãå Žåå®éšçµäº 4 段ç®ããèœãšããŠå²ããå Žå 3 段ç®ããèœãšã 4 段ç®ããèœãšããŠå²ããªãã£ãå Žå 5 段ç®ããèœãšã 3 段ç®ããèœãšããŠå²ããå Žåå®éšçµäº 3 段ç®ããèœãšããŠå²ããªãã£ãå Žåå®éšçµäº 5 段ç®ããèœãšããŠå²ããå Žåå®éšçµäº 5 段ç®ããèœãšããŠå²ããªãã£ãå Žåå®éšçµäº 3 ã€ç®ã®å Žå 1 段ç®ããèœãšããŠå®éšçµäº | 35,602 |
Score : 1000 points Problem Statement Consider the following game: The game is played using a row of N squares and many stones. First, a_i stones are put in Square i\ (1 \leq i \leq N) . A player can perform the following operation as many time as desired: "Select an integer i such that Square i contains exactly i stones. Remove all the stones from Square i , and add one stone to each of the i-1 squares from Square 1 to Square i-1 ." The final score of the player is the total number of the stones remaining in the squares. For a sequence a of length N , let f(a) be the minimum score that can be obtained when the game is played on a . Find the sum of f(a) over all sequences a of length N where each element is between 0 and K (inclusive). Since it can be extremely large, find the answer modulo 1000000007 (= 10^9+7) . Constraints 1 \leq N \leq 100 1 \leq K \leq N Input Input is given from Standard Input in the following format: N K Output Print the sum of f(a) modulo 1000000007 (= 10^9+7) . Sample Input 1 2 2 Sample Output 1 10 There are nine sequences of length 2 where each element is between 0 and 2 . For each of them, the value of f(a) and how to achieve it is as follows: f(\{0,0\}) : 0 (Nothing can be done) f(\{0,1\}) : 1 (Nothing can be done) f(\{0,2\}) : 0 (Select Square 2 , then Square 1 ) f(\{1,0\}) : 0 (Select Square 1 ) f(\{1,1\}) : 1 (Select Square 1 ) f(\{1,2\}) : 0 (Select Square 1 , Square 2 , then Square 1 ) f(\{2,0\}) : 2 (Nothing can be done) f(\{2,1\}) : 3 (Nothing can be done) f(\{2,2\}) : 3 (Select Square 2 ) Sample Input 2 20 17 Sample Output 2 983853488 | 35,603 |
AYBABTU There is a tree that has n nodes and n-1 edges. There are military bases on t out of the n nodes. We want to disconnect the bases as much as possible by destroying k edges. The tree will be split into k+1 regions when we destroy k edges. Given the purpose to disconnect the bases, we only consider to split in a way that each of these k+1 regions has at least one base. When we destroy an edge, we must pay destroying cost. Find the minimum destroying cost to split the tree. Input The input consists of multiple data sets. Each data set has the following format. The first line consists of three integers n , t , and k ( 1 \leq n \leq 10,000 , 1 \leq t \leq n , 0 \leq k \leq t-1 ). Each of the next n-1 lines consists of three integers representing an edge. The first two integers represent node numbers connected by the edge. A node number is a positive integer less than or equal to n . The last one integer represents destroying cost. Destroying cost is a non-negative integer less than or equal to 10,000. The next t lines contain a distinct list of integers one in each line, and represent the list of nodes with bases. The input ends with a line containing three zeros, which should not be processed. Output For each test case, print its case number and the minimum destroying cost to split the tree with the case number. Sample Input 2 2 1 1 2 1 1 2 4 3 2 1 2 1 1 3 2 1 4 3 2 3 4 0 0 0 Output for the Sample Input Case 1: 1 Case 2: 3 | 35,604 |
Score : 100 points Problem Statement Snuke has a grid consisting of three squares numbered 1 , 2 and 3 . In each square, either 0 or 1 is written. The number written in Square i is s_i . Snuke will place a marble on each square that says 1 . Find the number of squares on which Snuke will place a marble. Constraints Each of s_1 , s_2 and s_3 is either 1 or 0 . Input Input is given from Standard Input in the following format: s_{1}s_{2}s_{3} Output Print the answer. Sample Input 1 101 Sample Output 1 2 A marble will be placed on Square 1 and 3 . Sample Input 2 000 Sample Output 2 0 No marble will be placed on any square. | 35,605 |
Score : 100 points Problem Statement There are N dishes, numbered 1, 2, \ldots, N . Initially, for each i ( 1 \leq i \leq N ), Dish i has a_i ( 1 \leq a_i \leq 3 ) pieces of sushi on it. Taro will perform the following operation repeatedly until all the pieces of sushi are eaten: Roll a die that shows the numbers 1, 2, \ldots, N with equal probabilities, and let i be the outcome. If there are some pieces of sushi on Dish i , eat one of them; if there is none, do nothing. Find the expected number of times the operation is performed before all the pieces of sushi are eaten. Constraints All values in input are integers. 1 \leq N \leq 300 1 \leq a_i \leq 3 Input Input is given from Standard Input in the following format: N a_1 a_2 \ldots a_N Output Print the expected number of times the operation is performed before all the pieces of sushi are eaten. The output is considered correct when the relative difference is not greater than 10^{-9} . Sample Input 1 3 1 1 1 Sample Output 1 5.5 The expected number of operations before the first piece of sushi is eaten, is 1 . After that, the expected number of operations before the second sushi is eaten, is 1.5 . After that, the expected number of operations before the third sushi is eaten, is 3 . Thus, the expected total number of operations is 1 + 1.5 + 3 = 5.5 . Sample Input 2 1 3 Sample Output 2 3 Outputs such as 3.00 , 3.000000003 and 2.999999997 will also be accepted. Sample Input 3 2 1 2 Sample Output 3 4.5 Sample Input 4 10 1 3 2 3 3 2 3 2 1 3 Sample Output 4 54.48064457488221 | 35,606 |
Problem I: Light The Room You are given plans of rooms of polygonal shapes. The walls of the rooms on the plans are placed parallel to either x -axis or y -axis. In addition, the walls are made of special materials so they reflect light from sources as mirrors do, but only once. In other words, the walls do not reflect light already reflected at another point of the walls. Now we have each room furnished with one lamp. Walls will be illuminated by the lamp directly or indirectly. However, since the walls reflect the light only once, some part of the walls may not be illuminated. You are requested to write a program that calculates the total length of unilluminated part of the walls. Figure 10: The room given as the second case in Sample Input Input The input consists of multiple test cases. The first line of each case contains a single positive even integer N (4 †N †20), which indicates the number of the corners. The following N lines describe the corners counterclockwise. The i-th line contains two integers x i and y i , where ( x i , y i ) indicates the coordinates of the i -th corner. The last line of the case contains x' and y' , where ( x' , y' ) indicates the coordinates of the lamp. To make the problem simple, you may assume that the input meets the following conditions: All coordinate values are integers not greater than 100 in their absolute values. No two walls intersect or touch except for their ends. The walls do not intersect nor touch each other. The walls turn each corner by a right angle. The lamp exists strictly inside the room off the wall. The x-coordinate of the lamp does not coincide with that of any wall; neither does the y-coordinate. The input is terminated by a line containing a single zero. Output For each case, output the length of the unilluminated part in one line. The output value may have an arbitrary number of decimal digits, but may not contain an error greater than 10 -3 . Sample Input 4 0 0 2 0 2 2 0 2 1 1 6 2 2 2 5 0 5 0 0 5 0 5 2 1 4 0 Output for the Sample Input 0.000 3.000 | 35,607 |
Problem E: Psychic Accelerator In the west of Tokyo, there is a city named âAcademy City.â There are many schools and laboratories to develop psychics in Academy City. You are a psychic student of a school in Academy City. Your psychic ability is to give acceleration to a certain object. You can use your psychic ability anytime and anywhere, but there are constraints. If the object remains stationary, you can give acceleration to the object in any direction. If the object is moving, you can give acceleration to the object only in 1) the direction the object is moving to, 2) the direction opposite to it, or 3) the direction perpendicular to it. Todayâs training menu is to move the object along a given course. For simplicity you can regard the course as consisting of line segments and circular arcs in a 2-dimensional space. The course has no branching. All segments and arcs are connected smoothly, i.e. there are no sharp corners. In the beginning, the object is placed at the starting point of the first line segment. You have to move the object to the ending point of the last line segment along the course and stop the object at that point by controlling its acceleration properly. Before the training, a coach ordered you to simulate the minimum time to move the object from the starting point to the ending point. Your task is to write a program which reads the shape of the course and the maximum acceleration a max you can give to the object and calculates the minimum time to move the object from the starting point to the ending point. The object follows basic physical laws. When the object is moving straight in some direction, with acceleration either forward or backward, the following equations hold: v = v 0 + at and s = v 0 t + (1/2) at 2 where v , s , v 0 , a , and t are the velocity, the distance from the starting point, the initial velocity (i.e. the velocity at the starting point), the acceleration, and the time the object has been moving in that direction, respectively. Note that they can be simplified as follows: v 2 â v 0 2 = 2 as When the object is moving along an arc, with acceleration to the centroid, the following equations hold: a = v 2 / r wher v , a , and r are the velocity, the acceleration, and the radius of the arc, respectively. Note that the object cannot change the velocity due to the criteria on your psychic ability. Input The input has the following format: N a max x a ,1 y a ,1 x b ,1 y b ,1 x a ,2 y a ,2 x b ,2 y b ,2 . . . N is the number of line segments; a max is the maximum acceleration you can give to the object; ( x a,i , y a,i ) and ( x b,i , y b,i ) are the starting point and the ending point of the i -th line segment, respectively. The given course may have crosses but you cannot change the direction there. The input meets the following constraints: 0 < N †40000, 1 †a max †100, and -100 †x a i , y a i , x b i , y b i †100. Output Print the minimum time to move the object from the starting point to the ending point with an relative or absolute error of at most 10 -6 . You may output any number of digits after the decimal point. Sample Input 1 2 1 0 0 1 0 1 1 0 1 Output for the Sample Input 1 5.2793638507 Sample Input 2 1 1 0 0 2 0 Output for the Sample Input 2 2.8284271082 Sample Input 3 3 2 0 0 2 0 1 -1 1 2 0 1 2 1 Output for the Sample Input 3 11.1364603512 | 35,608 |
Score: 400 points Problem Statement Kizahashi, who was appointed as the administrator of ABC at National Problem Workshop in the Kingdom of AtCoder, got too excited and took on too many jobs. Let the current time be time 0 . Kizahashi has N jobs numbered 1 to N . It takes A_i units of time for Kizahashi to complete Job i . The deadline for Job i is time B_i , and he must complete the job before or at this time. Kizahashi cannot work on two or more jobs simultaneously, but when he completes a job, he can start working on another immediately. Can Kizahashi complete all the jobs in time? If he can, print Yes ; if he cannot, print No . Constraints All values in input are integers. 1 \leq N \leq 2 \times 10^5 1 \leq A_i, B_i \leq 10^9 (1 \leq i \leq N) Input Input is given from Standard Input in the following format: N A_1 B_1 . . . A_N B_N Output If Kizahashi can complete all the jobs in time, print Yes ; if he cannot, print No . Sample Input 1 5 2 4 1 9 1 8 4 9 3 12 Sample Output 1 Yes He can complete all the jobs in time by, for example, doing them in the following order: Do Job 2 from time 0 to 1 . Do Job 1 from time 1 to 3 . Do Job 4 from time 3 to 7 . Do Job 3 from time 7 to 8 . Do Job 5 from time 8 to 11 . Note that it is fine to complete Job 3 exactly at the deadline, time 8 . Sample Input 2 3 334 1000 334 1000 334 1000 Sample Output 2 No He cannot complete all the jobs in time, no matter what order he does them in. Sample Input 3 30 384 8895 1725 9791 170 1024 4 11105 2 6 578 1815 702 3352 143 5141 1420 6980 24 1602 849 999 76 7586 85 5570 444 4991 719 11090 470 10708 1137 4547 455 9003 110 9901 15 8578 368 3692 104 1286 3 4 366 12143 7 6649 610 2374 152 7324 4 7042 292 11386 334 5720 Sample Output 3 Yes | 35,609 |
Score : 500 points Problem Statement There are N towns on a plane. The i -th town is located at the coordinates (x_i,y_i) . There may be more than one town at the same coordinates. You can build a road between two towns at coordinates (a,b) and (c,d) for a cost of min(|a-c|,|b-d|) yen (the currency of Japan). It is not possible to build other types of roads. Your objective is to build roads so that it will be possible to travel between every pair of towns by traversing roads. At least how much money is necessary to achieve this? Constraints 2 †N †10^5 0 †x_i,y_i †10^9 All input values are integers. Input Input is given from Standard Input in the following format: N x_1 y_1 x_2 y_2 : x_N y_N Output Print the minimum necessary amount of money in order to build roads so that it will be possible to travel between every pair of towns by traversing roads. Sample Input 1 3 1 5 3 9 7 8 Sample Output 1 3 Build a road between Towns 1 and 2 , and another between Towns 2 and 3 . The total cost is 2+1=3 yen. Sample Input 2 6 8 3 4 9 12 19 18 1 13 5 7 6 Sample Output 2 8 | 35,610 |
Problem F: Numoeba A scientist discovered a strange variation of amoeba. The scientist named it numoeba . A numoeba, though it looks like an amoeba, is actually a community of cells, which always forms a tree. The scientist called the cell leader that is at the root position of the tree. For example, in Fig. 1, the leader is A . In a numoeba, its leader may change time to time. For example, if E gets new leadership, the tree in Fig. 1 becomes one in Fig. 2. We will use the terms root, leaf, parent, child and subtree for a numoeba as defined in the graph theory. Numoeba changes its physical structure at every biological clock by cell division and cell death. The leader may change depending on this physical change. The most astonishing fact about the numoeba cell is that it contains an organic unit called numbosome , which represents an odd integer within the range from 1 to 12,345,677. At every biological clock, the value of a numbosome changes from n to a new value as follows: The maximum odd factor of 3 n + 1 is calculated. This value can be obtained from 3 n + 1 by repeating division by 2 while even. If the resulting integer is greater than 12,345,678, then it is subtracted by 12,345,678. For example, if the numbosome value of a cell is 13, 13 à 3 + 1 = 40 is divided by 2 3 = 8 and a new numbosome value 5 is obtained. If the numbosome value of a cell is 11,111,111, it changes to 4,320,989, instead of 16,666,667. If 3 n + 1 is a power of 2, yielding 1 as the result, it signifies the death of the cell as will be described below. At every biological clock, the next numbosome value of every cell is calculated and the fate of the cell and thereby the fate of numoeba is determined according to the following steps. A cell that is a leaf and increases its numbosome value is designated as a candidate leaf. A cell dies if its numbosome value becomes 1. If the dying cell is the leader of the numoeba, the numoeba dies as a whole. Otherwise, all the cells in the subtree from the dying cell (including itself) die. However, there is an exceptional case where the cells in the subtree do not necessarily die; if there is only one child cell of the dying non-leader cell, the child cell will replace the dying cell. Thus, a straight chain simply shrinks if its non-leader constituent dies. For example, consider a numoeba with the leader A below. If the leader A dies in (1), the numoeba dies. If the cell D dies in (1), (1) will be as follows. And, if the cell E dies in (1), (1) will be as follows. Note that this procedure is executed sequentially, top-down from the root of the numoeba to leaves. If the cells E and F will die in (1), the death of F is not detected at the time the procedure examines the cell E . The numoeba, therefore, becomes (3). One should not consider in such a way that the death of F makes G the only child of E , and, therefore, G will replace the dying E . If a candidate leaf survives with the numbosome value of n , it spawns a cell as its child, thereby a new leaf, whose numbosome value is the least odd integer greater than or equal to ( n + 1)/2. We call the child leaf bonus. Finally, a new leader of the numoeba is selected, who has a unique maximum numbosome value among all the constituent cells. The tree structure of the numoeba is changed so that the new leader is its root, like what is shown in Fig. 1 and Fig. 2. Note that the parent-child relationship of some cells may be reversed by this leader change. When a new leader of a unique maximum numbosome value, say m , is selected (it may be the same cell as the previous leader), it spawns a cell as its child with the numbosome whose value is the greatest odd integer less than or equal to ( m + 1)/2. We call the child leader bonus . If there is more than one cell of the same maximum numbosome value, however, the leader does not change for the next period, and there is no leader bonus. The following illustrates the growth and death of a numoeba starting from a single cell seed with the numbosome value 15, which plays both roles of the leader and a leaf at the start. In the figure, a cell is nicknamed with its numbosome value. Note that the order of the children of a parent is irrelevant. The numoeba continues changing its structure, and at clock 104, it looks as follows. Here, two ambitious 2429's could not become the leader. The leader 5 will die without promoting these talented cells at the next clock. This alludes the fragility of a big organization. And, the numoeba dies at clock 105. Your job is to write a program that outputs statistics about the life of numoebae that start from a single cell seed at clock zero. Input A sequence of odd integers, each in a line. Each odd integer k i (3 †k i †9,999) indicates the initial numbosome value of the starting cell. This sequence is terminated by a zero. Output A sequence of pairs of integers:an integer that represents the numoeba's life time and an integer that represents the maximum number of constituent cells in its life. These two integers should be separated by a space character, and each pair should be followed immediately by a newline. Here, the lifetime means the clock when the numoeba dies. You can use the fact that the life time is less than 500, and that the number of cells does not exceed 500 in any time, for any seed value given in the input. You might guess that the program would consume a lot of memory. It is true in general. But, don't mind. Referees will use a test data set consisting of no more than 10 starting values, and, starting from any of the those values, the total numbers of cells spawned during the lifetime will not exceed 5000. Sample Input 3 5 7 15 655 2711 6395 7195 8465 0 Output for the Sample Input 2 3 1 1 9 11 105 65 398 332 415 332 430 332 428 332 190 421 | 35,611 |
åé¡ B : Evacuation Route å顿 æ¥æ¬ã§ã¯é²çœç ç©¶ãçãã«è¡ãããŠããïŒè¿å¹Žãã®éèŠæ§ããŸããŸãå¢ããŠããïŒ é¿é£çµè·¯ã®è©äŸ¡ãéèŠãªç ç©¶ã®ã²ãšã€ã§ããïŒ ä»åã¯çŽç·ç¶ã®éè·¯ã®å®å
šè©äŸ¡ãè¡ãïŒ é路㯠W åã®ãŠãããã«åããããŠããïŒäžæ¹ã®ç«¯ã®ãŠãããããããäžæ¹ã®ç«¯ã®ãŠããããŸã§ 0, 1, 2, ⊠, W-1 ã®çªå·ãã€ããããŠããïŒ éè·¯å
ã®åãŠãããã«ã¯ïŒå
¥å£ã®æïŒåºå£ã®æïŒé²ç«æã®ãããã1ã€ãååšããïŒ å
¥ãå£ã®æïŒåºå£ã®æïŒé²ç«æã¯ããããéè·¯å
ã«è€æ°åååšãããïŒ ãã®åé¡ã§ã¯æå» t=0 ã§ç«çœãçºçãããšæ³å®ããïŒ ããã«ããïŒéè·¯ã®å€éšã«ããŠé¿é£ããããšããŠãã人ã
ãå
¥å£ã®æãéããŠéè·¯ãžå
¥ãïŒããå®å
šãªå Žæãžåºãããã«åºå£ã®æãžè±åºããããšãããã®ãšããïŒ é¿é£äžã®ããããã®äººã¯åäœæå»ããšã« 1 ã€ã®ãŠããããç§»åãããïŒä»ã®ãŠãããã«çãŸãããšãã§ããïŒ ããªãã¡ïŒæå» t ã«ãã人ããŠããã i ã«ãããšãããšãïŒãã®äººã¯æå» t+1 ã§ã¯ãŠããã i-1, i, i+1 ã®3ã€ã®æ°åã®ãã¡ 0 ä»¥äž W-1 以äžã§ãããã®ãéžæãïŒãã®çªå·ã®ãŠããããžç§»åããããšãã§ããïŒ é²ç«æããããŠãããã¯ïŒããäžå®æå»ä»¥éã«ãªããšå®å
šã«é®æãããŠããŸãïŒé¿é£äžã®äººã
ã¯ãã®ãŠãããã«ç«ã¡å
¥ãã§ããªããªãïŒãŸãïŒãã®ãŠãããå
ã«å±
ã人ã
ãããããä»ã®ãŠãããã«ç§»åã§ããªããªã£ãŠããŸãïŒ ãã®åé¡ã«ãããç®çã¯ïŒããããã®æã®æ
å ±ãäžããããã®ã§ïŒé¿é£äžã®äººã
ãæé©ã«è¡åããæã«æå€§ã§äœäººãåºå£ã®æãžãã©ãçãããèšç®ããããšã§ããïŒ éè·¯ã®æ
å ±ã W åã®æŽæ° a_i ã§äžããããïŒ a_i = 0 ã®ãšãïŒ i çªç®ã®ãŠããããåºå£ã®æã§ããããšãããããïŒ a_i < 0 ã®ãšãïŒ i çªç®ã®ãŠããããé²ç«æã«ããæé |a_i| 以éåºå
¥ãã§ããªããªãããšã衚ãïŒ a_i > 0 ã®ãšãïŒæå» t=0, 1, 2, ⊠, a_{i}-1 ã®ããããã«ãããŠïŒã¡ããã©äžäººã®äººã i çªç®ã®ãŠãããã«çŸããïŒæå» t ã«çŸãã人ã¯ïŒæå» t+1 以éããç§»åãéå§ããïŒ ãªãïŒ1ã€ã®ãŠãããã«è€æ°ã®äººã
ãååšããŠãããŸããªãïŒ åºå£ã®æãžãã©ãçããæå€§ã®äººæ°ãæ±ããïŒ å
¥ååœ¢åŒ å
¥åã¯ä»¥äžã®åœ¢åŒã§äžãããã W a_0 a_1 ... a_{W-1} åºååœ¢åŒ æå€§äººæ°ã1è¡ã§åºåããïŒ å¶çŽ 1 †W †10^5 |a_i| †10^4 å
¥åå€ã¯ãã¹ãп޿°ã§ããïŒ å
¥åºåäŸ å
¥åäŸ 1 7 2 0 -2 3 2 -2 0 åºåäŸ 1 4 0, 3, 5 çªç®ã®ãŠãããã«å
¥ãå£ã®æãããïŒ 1, 6 çªç®ã®ãŠãããã«åºå£ã®æãããïŒ 0 çªç®ã®ãŠãããããã¯ïŒ 1 çªç®ã®ãŠããããžïŒäººåºãããšãã§ããïŒ 3 çªç®ã®ãŠãããããã¯ïŒ 1 çªç®ã®ãŠããããžïŒäººåºãããšãã§ããïŒ 5 çªç®ã®ãŠãããããã¯ïŒ 6 çªç®ã®ãŠããããžïŒäººåºãããšãã§ããïŒ ãã£ãŠåãããŠïŒäººãåºå£ãžãšãã©ãçããïŒ å
¥åäŸ 2 4 1 1 1 1 åºåäŸ 2 0 åºå£ããªãã®ã§èª°ãè±åºã§ããªãïŒ å
¥åäŸ 3 9 10 -10 10 -10 10 -10 10 -10 0 åºåäŸ 3 24 | 35,612 |
æå±€(Geologic Fault) é ãæïŒIOI ææãšããé«åºŠãªææãæ ããŠããïŒãããïŒç«å±±ã®åŽç«ã«ããïŒãã®é«åºŠãªææã¯ã€ãã«æ»
ãã§ããŸã£ãïŒIOI ææã¯çŽç·ç¶ã®æ²³å·ã«æ²¿ã£ãŠç¹æ ããŠããïŒIOI ææãæ»
ãã ãšãïŒãã®å°è¡šé¢ã¯å¹³ãã§ãã£ãïŒIOI ææã®è·¡å°ã¯åº§æšå¹³é¢ã®x 軞ãšèŠãªãããšãã§ããïŒy 軞ã¯é«ãæ¹åã衚ãïŒããªãã¡ïŒåº§æšå¹³é¢ã«ãããŠïŒçŽç· $y = 0$ ã¯å°è¡šãïŒé å $y > 0$ ã¯å°äžãïŒé å $y < 0$ ã¯å°äžã衚ãïŒãŸãïŒIOI ææãæ»
ãã ãšãïŒ$a$ 幎å$(a \geq 0)$ ã®å°å±€ã¯ïŒçŽç· $y = -a$ ã®äœçœ®ã«ãã£ãïŒ IOI ææãæ»
ãã åŸïŒIOI ææã®è·¡å°ã§ã¯ $Q$ åã®å°æ®»å€åãèµ·ããïŒ$i$ åç®$(1 \leq i \leq Q)$ ã®å°æ®»å€åã¯ïŒäœçœ® $X_i$ïŒæ¹å $D_i$ïŒå€åã®é $L_i$ ã§è¡šãããïŒ$D_i$ 㯠1 ãŸã㯠2 ã§ããïŒ$i$ åç®ã®å°æ®»å€åã¯ä»¥äžã®ããã«èµ·ããïŒ å°å±€ã®ç§»åãæ¬¡ã®ããã«èµ·ããïŒ $D_i = 1$ ã®ãšãïŒæå±€ãç¹$(X_i, 0)$ ãéãåŸã $1$ ã®çŽç·ã«æ²¿ã£ãŠé ããïŒãã®çŽç·ããäžã®é åã«ããå°å±€ãïŒçŽç·ã«æ²¿ã£ãŠé«ã $L_i$ ã ãç§»åããïŒããªãã¡ïŒãã®çŽç·ããäžã®ç¹ $(x, y)$ ã¯ïŒç¹$(x + L_i, y + L_i)$ ã«ç§»åããïŒ $D_i = 2$ ã®ãšãïŒæå±€ãç¹$(X_i, 0)$ ãéãåŸã $-1$ ã®çŽç·ã«æ²¿ã£ãŠé ããïŒãã®çŽç·ããäžã®é åã«ããå°å±€ãïŒçŽç·ã«æ²¿ã£ãŠé«ã $L_i$ ã ãç§»åããïŒããªãã¡ïŒãã®çŽç·ããäžã®ç¹$(x, y)$ ã¯ïŒç¹$(x - L_i, y + L_i)$ ã«ç§»åããïŒ ãã®ããåŸã«ïŒé å $y > 0$ ã®å°å±€ã颚åã«ãã£ãŠãã¹ãŠæ¶ããïŒ æã¯å€ããçŸä»£ïŒèå€åŠè
ã®JOI å士ã¯IOI ææã®éºè·¡ãçºæããããšã«ããïŒJOI å士ã¯ã©ã®äœçœ®ã®å°è¡šã®å°å±€ãïŒIOI ææãæ»
ã¶äœå¹Žåã®å°å±€ã§ããããç¥ãããïŒã©ã®ãããªå°æ®»å€åãèµ·ãããã¯åãã£ãŠããïŒããªãã®ä»äºã¯ïŒJOI å士ã«ããã£ãŠïŒ$1 \leq i \leq N$ ãæºããåæŽæ° $i$ ã«ã€ããŠïŒç¹$(i-1, 0)$ ãšç¹$(i, 0)$ã®éã®å°è¡šã®å°å±€ãIOI ææãæ»
ã¶äœå¹Žåã®å°å±€ã§ããããæ±ããããšã§ããïŒ èª²é¡ IOI ææã®è·¡å°ã«èµ·ããã®æ
å ±ãäžãããããšãïŒãã¹ãŠã®æŽæ° $i$ $(1 \leq i \leq N)$ ã«å¯ŸãïŒç¹$(i - 1, 0)$ ãšç¹$(i, 0)$ ã®éã®å°è¡šã®å°å±€ãIOI ææãæ»
ã¶äœå¹Žåã®å°å±€ã§ããããåºåããïŒ å
¥å æšæºå
¥åãã以äžã®å
¥åãèªã¿èŸŒãïŒ 1 è¡ç®ã«ã¯ïŒ 2 åã®æŽæ° $N, Q$ ã空çœãåºåããšããŠæžãããŠããïŒããã¯ïŒçããæ±ããå°ç¹ã®æ°ã $N$ïŒå°æ®»å€åã®åæ°ã $Q$ ã§ããããšã衚ãïŒ ç¶ã $Q$ è¡ã®ãã¡ã® $i$ è¡ç®$(1 \leq i \leq Q)$ ã«ã¯ïŒ3 åã®æŽæ° $X_i, D_i, L_i$ ã空çœãåºåããšããŠæžãããŠããïŒããã¯ïŒ$i$ åç®ã®å°æ®»å€åã®äœçœ®ã $X_i$ïŒæ¹åã $D_i$ïŒå€åã®éã $L_i$ ã§ããããšã衚ãïŒ åºå åºå㯠$N$ è¡ãããªãïŒæšæºåºåã® $i$ è¡ç®$(1 \leq i \leq N)$ ã«ã¯ïŒç¹$(i - 1, 0)$ ãšç¹$(i, 0)$ ã®éã®å°è¡šã®å°å±€ãIOIææãæ»
ã¶äœå¹Žåã®å°å±€ã§ããããè¡šãæŽæ°ãåºåããïŒ å¶é ãã¹ãŠã®å
¥åããŒã¿ã¯ä»¥äžã®æ¡ä»¶ãæºããïŒ $1 \leq N \leq 200 000$ $1 \leq Q \leq 200 000$ $ -1 000 000 000 \leq X_i \leq 1 000 000 000$ $(1 \leq i \leq Q)$ $1 \leq D_i \leq 2$ $(1 \leq i \leq Q)$ $1 \leq L_i \leq 1 000 000 000$ $(1 \leq i \leq Q)$ å
¥åºåäŸ å
¥åäŸ1 10 2 12 1 3 2 2 2 åºåäŸ1 3 3 5 5 5 5 5 5 2 2 ãã®å
¥åäŸã¯ïŒä»¥äžã®å³ã«å¯Ÿå¿ããïŒ å
¥åäŸ2 10 6 14 1 1 17 1 1 -6 2 1 3 2 1 4 1 1 0 2 1 åºåäŸ2 5 5 4 5 5 5 5 5 4 4 å
¥åäŸ3 15 10 28 1 7 -24 2 1 1 1 1 8 1 1 6 2 1 20 1 3 12 2 2 -10 1 3 7 2 1 5 1 2 åºåäŸ3 15 14 14 14 14 12 12 12 12 12 12 12 15 15 12 第15å æ¥æ¬æ
å ±ãªãªã³ããã¯æ¬éž èª²é¡ 2016 幎 2 æ 14 æ¥ | 35,613 |
H: Colorful Tree Story Yamiuchi (assassination) is a traditional event that is held annually in JAG summer camp. Every team displays a decorated tree in the dark and all teams' trees are compared from the point of view of their colorfulness. In this competition, it is allowed to cut the other teamsâ tree to reduce its colorfulness. Despite a team would get a penalty if it were discovered that the team cuts the tree of another team, many teams do this obstruction. You decided to compete in Yamiuchi and write a program that maximizes the colorfulness of your teamâs tree. The program has to calculate maximum scores for all subtrees in case the other teams cut your tree. Problem Statement You are given a rooted tree G with N vertices indexed with 1 through N . The root is vertex 1 . There are K kinds of colors indexed with 1 through K . You can paint vertex i with either color c_i or d_i . Note that c_i = d_i may hold, and if so you have to paint vertex i with c_i ( =d_i ). Let the colorfulness of tree T be the number of different colors in T . Your task is to write a program that calculates maximum colorfulness for all rooted subtrees. Note that coloring for each rooted subtree is done independently, so previous coloring does not affect to other coloring. Input N K u_1 v_1 : u_{N-1} v_{N-1} c_1 d_1 : c_N d_N The first line contains two integers N and K in this order. The following N-1 lines provide information about the edges of G . The i -th line of them contains two integers u_i and v_i , meaning these two vertices are connected with an edge. The following N lines provide information about color constraints. The i -th line of them contains two integers c_i and d_i explained above. Constraints 1 \leq N \leq 10^5 1 \leq K \leq 2\times 10^5 1 \leq u_i , v_i \leq N 1 \leq c_i , d_i \leq K The input graph is a tree. All inputs are integers. Output Output N lines. The i -th line of them contains the maximum colorfulness of the rooted subtree of G whose root is i . Sample Input 1 2 10 1 2 1 9 8 7 Output for Sample Input 1 2 1 Sample Input 2 3 2 1 2 1 3 1 2 1 1 1 2 Output for Sample Input 2 2 1 1 Note that two color options of a vertex can be the same. Sample Input 3 5 100000 4 3 3 5 1 3 2 1 3 2 1 3 2 1 4 2 1 4 Output for Sample Input 3 4 1 3 1 1 | 35,614 |
Matrix-like Computation Your task is to develop a tiny little part of spreadsheet software. Write a program which adds up columns and rows of given table as shown in the following figure: Input The input consists of several datasets. Each dataset consists of: n (the size of row and column of the given table) 1st row of the table 2nd row of the table : : n th row of the table The input ends with a line consisting of a single 0. Output For each dataset, print the table with sums of rows and columns. Each item of the table should be aligned to the right with a margin for five digits. Please see the sample output for details. Sample Input 4 52 96 15 20 86 22 35 45 45 78 54 36 16 86 74 55 4 52 96 15 20 86 22 35 45 45 78 54 36 16 86 74 55 0 Output for the Sample Input 52 96 15 20 183 86 22 35 45 188 45 78 54 36 213 16 86 74 55 231 199 282 178 156 815 52 96 15 20 183 86 22 35 45 188 45 78 54 36 213 16 86 74 55 231 199 282 178 156 815 | 35,615 |
ã³ã³ãã¥ãŒã¿ã·ã¹ãã ã®äžå
·å ããªãã¯äžçæé«æ§èœã®ã³ã³ãã¥ãŒã¿ã·ã¹ãã ãé£ç±å€ïŒãªããïŒããèšèšããŠããããããããã®ã·ã¹ãã ã®ãããã¿ã€ãã®å®è£
äžã«ãåœä»€åãããæ¡ä»¶ãæºãããšã·ã¹ãã ã忢ãããšããäžå
·åãèŠã€ãã£ãã ãã®ã·ã¹ãã ã¯ãé·ã$N$ã®åœä»€åãããã°ã©ã ãšããŠäžããããšã§åäœãããåœä»€åã®äžã®$m$çªç®ã®åœä»€ãæ°$X_m$ã§è¡šãããšããäžå
·åãèµ·ããæ¡ä»¶ã¯ãããæŽæ°$i,j$ ($2 \leq iïŒj \leq N$)ã«å¯ŸããŠ$X_i + X_{j-1} = X_j + X_{i-1}$ãšãªãåœä»€ã®ãã¿ãŒã³ãåœä»€åã«ååšããããšã§ãããšå€æããã ããªãã¯ãã®äžå
·åãã©ã®çšåºŠã®åœ±é¿ã«ãªãã®ãã調ã¹ããããããé·ãã§äœãããšãã§ããåœä»€åã®ãã¡ãäœçš®é¡ã®åœä»€åãäžå
·åãèµ·ãããã調ã¹ãããšã«ããã é·ã$N$ã®åœä»€åã®ãã¡ãäžå
·åãèµ·ããåœä»€åãäœéãããããæ±ããããã°ã©ã ãäœæããããã ããåœä»€ã¯$1$以äž$K$以äžã®æŽæ°ã§è¡šããããšãšãããçãã¯äžããããçŽ æ°$M$ã§å²ã£ãäœããšããã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã $N$ $K$ $M$ ïŒè¡ã«ãåœä»€åã®é·ã$N$ ($3 \leq N \leq 100,000$)ãåœä»€ã®çš®é¡ã®æ°$K$ ($1 \leq K \leq 10$)ãçŽ æ°$M$ ($100,000,007 \leq M \leq 1,000,000,007$)ãäžããããã åºå äžå
·åãèµ·ããåœä»€åã®æ°ãMã§å²ã£ãäœããåºåããã å
¥åºåäŸ å
¥åäŸïŒ 3 2 100000007 åºåäŸïŒ 2 åœä»€åã$(X_1,X_2,X_3)$ã®ããã«è¡šããšãèããããåœä»€åã¯$(1,1,1)$ã$(1,1,2)$ã$(1,2,1)$ã$(1,2,2)$ã$(2,1,1)$ã$(2,1,2)$ã$(2,2,1)$ã$(2,2,2)$ã®ïŒéãããã®ãã¡ãäžå
·åãèµ·ããåœä»€åã¯$(1,1,1)$ã$(2,2,2)$ã®ïŒéãã å
¥åäŸïŒ 9 10 100000037 åºåäŸïŒ 66631256 äžå
·åãèµ·ããåœä»€åã¯866631552éããããããã®æ°ãçŽ æ°100000037ã§å²ã£ãäœããåºåãšãªãã | 35,616 |
Score : 500 points Problem Statement We have a two-dimensional grid with H \times W squares. There are M targets to destroy in this grid - the position of the i -th target is \left(h_i, w_i \right) . Takahashi will choose one square in this grid, place a bomb there, and ignite it. The bomb will destroy all targets that are in the row or the column where the bomb is placed. It is possible to place the bomb at a square with a target. Takahashi is trying to maximize the number of targets to destroy. Find the maximum number of targets that can be destroyed. Constraints All values in input are integers. 1 \leq H, W \leq 3 \times 10^5 1 \leq M \leq \min\left(H\times W, 3 \times 10^5\right) 1 \leq h_i \leq H 1 \leq w_i \leq W \left(h_i, w_i\right) \neq \left(h_j, w_j\right) \left(i \neq j\right) Input Input is given from Standard Input in the following format: H W M h_1 w_1 \vdots h_M w_M Output Print the answer. Sample Input 1 2 3 3 2 2 1 1 1 3 Sample Output 1 3 We can destroy all the targets by placing the bomb at \left(1, 2\right) . Sample Input 2 3 3 4 3 3 3 1 1 1 1 2 Sample Output 2 3 Sample Input 3 5 5 10 2 5 4 3 2 3 5 5 2 2 5 4 5 3 5 1 3 5 1 4 Sample Output 3 6 | 35,617 |
ã«ããã²ãŒã 3 ã€ã®ã«ããããµããŠçœ®ãããŠããŸããã«ããã®çœ®ãããŠããå Žæããé ã« A,B,C ãšåŒã¶ããšã«ããŸããæå㯠A ã«çœ®ãããŠããã«ããã®äžã«ããŒã«ãé ãããŠãããšããŸããã«ããã®äœçœ®ãå
¥ãæ¿ãããšãäžã«å
¥ã£ãŠããããŒã«ãäžç·ã«ç§»åããŸãã å
¥ãæ¿ããïŒã€ã®ã«ããã®äœçœ®ãèªã¿èŸŒãã§ãæçµçã«ã©ã®å Žæã®ã«ããã«ããŒã«ãé ãããŠããããåºåããããã°ã©ã ãäœæããŠãã ããã Input å
¥ãæ¿ããïŒã€ã®ã«ããã®äœçœ®ãé çªã«è€æ°è¡ã«ãããäžããããŸããåè¡ã«ãå
¥ãæ¿ããïŒã€ã®ã«ããã®äœçœ®ã衚ãæåïŒA, B, ãŸã㯠CïŒãã«ã³ãåºåãã§äžããããŸãã å
¥ãæ¿ããæäœã¯ 50 åãè¶
ããŸããã Output ããŒã«ãå
¥ã£ãŠããã«ããã®å ŽæïŒA, B, ãŸã㯠CïŒãïŒè¡ã«åºåããŸãã Sample Input B,C A,C C,B A,B C,B Output for the Sample Input A | 35,618 |
Score : 1100 points Problem Statement Alice, Bob and Charlie are playing Card Game for Three , as below: At first, each of the three players has a deck consisting of some number of cards. Alice's deck has N cards, Bob's deck has M cards, and Charlie's deck has K cards. Each card has a letter a , b or c written on it. The orders of the cards in the decks cannot be rearranged. The players take turns. Alice goes first. If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says a , Alice takes the next turn.) If the current player's deck is empty, the game ends and the current player wins the game. There are 3^{N+M+K} possible patters of the three player's initial decks. Among these patterns, how many will lead to Alice's victory? Since the answer can be large, print the count modulo 1\,000\,000\,007 (=10^9+7) . Constraints 1 \leq N \leq 3Ã10^5 1 \leq M \leq 3Ã10^5 1 \leq K \leq 3Ã10^5 Partial Scores 500 points will be awarded for passing the test set satisfying the following: 1 \leq N \leq 1000 , 1 \leq M \leq 1000 , 1 \leq K \leq 1000 . Input The input is given from Standard Input in the following format: N M K Output Print the answer modulo 1\,000\,000\,007 (=10^9+7) . Sample Input 1 1 1 1 Sample Output 1 17 If Alice's card is a , then Alice will win regardless of Bob's and Charlie's card. There are 3Ã3=9 such patterns. If Alice's card is b , Alice will only win when Bob's card is a , or when Bob's card is c and Charlie's card is a . There are 3+1=4 such patterns. If Alice's card is c , Alice will only win when Charlie's card is a , or when Charlie's card is b and Bob's card is a . There are 3+1=4 such patterns. Thus, there are total of 9+4+4=17 patterns that will lead to Alice's victory. Sample Input 2 4 2 2 Sample Output 2 1227 Sample Input 3 1000 1000 1000 Sample Output 3 261790852 | 35,619 |
Problem E: Black Force A dam construction project was designed around an area called Black Force. The area is surrounded by mountains and its rugged terrain is said to be very suitable for constructing a dam. However, the project is now almost pushed into cancellation by a strong protest campaign started by the local residents. Your task is to plan out a compromise proposal. In other words, you must find a way to build a dam with sufficient capacity, without destroying the inhabited area of the residents. The map of Black Force is given as H à W cells (0 < H , W †20). Each cell h i, j is a positive integer representing the height of the place. The dam can be constructed at a connected region surrounded by higher cells, as long as the region contains neither the outermost cells nor the inhabited area of the residents. Here, a region is said to be connected if one can go between any pair of cells in the region by following a sequence of left-, right-, top-, or bottom-adjacent cells without leaving the region. The constructed dam can store water up to the height of the lowest surrounding cell. The capacity of the dam is the maximum volume of water it can store. Water of the depth of 1 poured to a single cell has the volume of 1. The important thing is that, in the case it is difficult to build a sufficient large dam, it is allowed to choose (at most) one cell and do groundwork to increase the height of the cell by 1 unit. Unfortunately, considering the protest campaign, groundwork of larger scale is impossible. Needless to say, you cannot do the groundwork at the inhabited cell. Given the map, the required capacity, and the list of cells inhabited, please determine whether it is possible to construct a dam. Input The input consists of multiple data sets. Each data set is given in the following format: H W C R h 1,1 h 1,2 . . . h 1, W ... h H ,1 h H ,2 . . . h H , W y 1 x 1 ... y R x R H and W is the size of the map. is the required capacity. R (0 < R < H à W ) is the number of cells inhabited. The following H lines represent the map, where each line contains W numbers separated by space. Then, the R lines containing the coordinates of inhabited cells follow. The line â y x â means that the cell h y,x is inhabited. The end of input is indicated by a line â0 0 0 0â. This line should not be processed. Output For each data set, print âYesâ if it is possible to construct a dam with capacity equal to or more than C . Otherwise, print âNoâ. Sample Input 4 4 1 1 2 2 2 2 2 1 1 2 2 1 1 2 2 1 2 2 1 1 4 4 1 1 2 2 2 2 2 1 1 2 2 1 1 2 2 1 2 2 2 2 4 4 1 1 2 2 2 2 2 1 1 2 2 1 1 2 2 1 1 2 1 1 3 6 6 1 1 6 7 1 7 1 5 1 2 8 1 6 1 4 3 1 5 1 1 4 5 6 21 1 1 3 3 3 3 1 3 1 1 1 1 3 3 1 1 3 2 2 3 1 1 1 1 3 1 3 3 3 3 1 3 4 0 0 0 0 Output for the Sample Input Yes No No No Yes | 35,620 |
Score : 700 points Problem Statement You are given sequences A and B consisting of non-negative integers. The lengths of both A and B are N , and the sums of the elements in A and B are equal. The i -th element in A is A_i , and the i -th element in B is B_i . Tozan and Gezan repeats the following sequence of operations: If A and B are equal sequences, terminate the process. Otherwise, first Tozan chooses a positive element in A and decrease it by 1 . Then, Gezan chooses a positive element in B and decrease it by 1 . Then, give one candy to Takahashi, their pet. Tozan wants the number of candies given to Takahashi until the process is terminated to be as large as possible, while Gezan wants it to be as small as possible. Find the number of candies given to Takahashi when both of them perform the operations optimally. Constraints 1 \leq N \leq 2 Ã 10^5 0 \leq A_i,B_i \leq 10^9(1\leq i\leq N) The sums of the elements in A and B are equal. All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 B_1 : A_N B_N Output Print the number of candies given to Takahashi when both Tozan and Gezan perform the operations optimally. Sample Input 1 2 1 2 3 2 Sample Output 1 2 When both Tozan and Gezan perform the operations optimally, the process will proceed as follows: Tozan decreases A_1 by 1 . Gezan decreases B_1 by 1 . One candy is given to Takahashi. Tozan decreases A_2 by 1 . Gezan decreases B_1 by 1 . One candy is given to Takahashi. As A and B are equal, the process is terminated. Sample Input 2 3 8 3 0 1 4 8 Sample Output 2 9 Sample Input 3 1 1 1 Sample Output 3 0 | 35,621 |
Score : 1600 points Problem Statement There is a blackboard on which all integers from -10^{18} through 10^{18} are written, each of them appearing once. Takahashi will repeat the following sequence of operations any number of times he likes, possibly zero: Choose an integer between 1 and N (inclusive) that is written on the blackboard. Let x be the chosen integer, and erase x . If x-2 is not written on the blackboard, write x-2 on the blackboard. If x+K is not written on the blackboard, write x+K on the blackboard. Find the number of possible sets of integers written on the blackboard after some number of operations, modulo M . We consider two sets different when there exists an integer contained in only one of the sets. Constraints 1 \leq K\leq N \leq 150 10^8\leq M\leq 10^9 N , K , and M are integers. Input Input is given from Standard Input in the following format: N K M Output Print the number of possible sets of integers written on the blackboard after some number of operations, modulo M . Sample Input 1 3 1 998244353 Sample Output 1 7 Every set containing all integers less than 1 , all integers greater than 3 , and at least one of the three integers 1 , 2 , and 3 satisfies the condition. There are seven such sets. Sample Input 2 6 3 998244353 Sample Output 2 61 Sample Input 3 9 4 702443618 Sample Output 3 312 Sample Input 4 17 7 208992811 Sample Output 4 128832 Sample Input 5 123 45 678901234 Sample Output 5 256109226 | 35,622 |
Problem J Post Office Investigation In this country, all international mails from abroad are first gathered to the central post office, and then delivered to each destination post office relaying some post offices on the way. The delivery routes between post offices are described by a directed graph $G = (V,E)$, where $V$ is the set of post offices and $E$ is the set of possible mail forwarding steps. Due to the inefficient operations, you cannot expect that the mails are delivered along the shortest route. The set of post offices can be divided into a certain number of groups. Here, a group is defined as a set of post offices where mails can be forwarded from any member of the group to any other member, directly or indirectly. The number of post offices in such a group does not exceed 10. The post offices frequently receive complaints from customers that some mails are not delivered yet. Such a problem is usually due to system trouble in a single post office, but identifying which is not easy. Thus, when such complaints are received, the customer support sends staff to check the system of each candidate post office. Here, the investigation cost to check the system of the post office $u$ is given by $c_u$, which depends on the scale of the post office. Since there are many post offices in the country, and such complaints are frequently received, reducing the investigation cost is an important issue. To reduce the cost, the post service administration determined to use the following scheduling rule: When complaints on undelivered mails are received by the post offices $w_1, ..., w_k$ one day, staff is sent on the next day to investigate a single post office $v$ with the lowest investigation cost among candidates. Here, the post office $v$ is a candidate if all mails from the central post office to the post offices $w_1, ... , w_k$ must go through $v$. If no problem is found in the post office $v$, we have to decide the order of investigating other post offices, but the problem is left to some future days. Your job is to write a program that finds the cost of the lowest-cost candidate when the list of complained post offices in a day, described by $w_1, ... , w_k$, is given as a query. Input The input consists of a single test case, formatted as follows. $n$ $m$ $u_1$ $v_1$ ... $u_m$ $v_m$ $c_1$ ... $c_n$ $q$ $k_1$ $w_{11}$ ... $w_{1k_1}$ ... $k_q$ $w_{q1}$ ... $w_{qk_q}$ $n$ is the number of post offices $(2 \leq n \leq 50,000)$, which are numbered from 1 to $n$. Here, post office 1 corresponds to the central post office. $m$ is the number of forwarding pairs of post offices $(1 \leq m \leq 100,000)$. The pair, $u_i$ and $v_i$, means that some of the mails received at post office $u_i$ are forwarded to post office $v_i$ $(i = 1, ..., m)$. $c_j$ is the investigation cost for the post office $j$ $(j = 1, ..., n, 1 \leq c_j \leq 10^9)$. $q$ $(q \geq 1)$ is the number of queries, and each query is specified by a list of post offices which received undelivered mail complaints. $k_i$ $(k_i \geq 1)$ is the length of the list and $w_{i1}, ..., w_{ik_i}$ are the distinct post offices in the list. $\sum_{i=1}^{q} k_i \leq 50,000$. You can assume that there is at least one delivery route from the central post office to all the post offices. Output For each query, you should output a single integer that is the lowest cost of the candidate of troubled post office. Sample Input 1 8 8 1 2 1 3 2 4 2 5 2 8 3 5 3 6 4 7 1000 100 100 10 10 10 1 1 3 2 8 6 2 4 7 2 7 8 Sample Output 1 1000 10 100 Sample Input 2 10 12 1 2 2 3 3 4 4 2 4 5 5 6 6 7 7 5 7 8 8 9 9 10 10 8 10 9 8 7 6 5 4 3 2 1 3 2 3 4 3 6 7 8 3 9 6 3 Sample Output 2 8 5 8 | 35,623 |
A - æ§ç·åç ç©¶ïŒå·é€š æã¯å¹³æ50幎æ¥äŒã¿ïŒæ
å ±åŠç ç©¶ç§ã«æå±ãã京åããã¯ïŒäº¬éœã«ããæç ç©¶ããŒã¯ããã®ç 究宀ã®åŒè¶ãããã£ãšçµããïŒãããšäžæ¯ã€ããŠããïŒ ä»åã®åŒè¶ãã¯ïŒå€ããªã£ãæ ¡èã®æ¹ä¿®å·¥äºã«ãããã®ã§ïŒæ°å¹ŽåºŠããå·¥äºã«äŒŽãæ ¡èã®ååã倿Žãããããšã«ãªã£ãŠããïŒ ãããšããŠããã®ãã€ãã®éïŒäº¬åããã¯å
çãã倧åŠã®è³æã«èŒã£ãŠããæ ¡èåãæ°ããååã«å€æŽãããä»äºãé ŒãŸããŠããŸã£ãïŒ ãããç·šéããªããã°ãªããªãè³æã«ã¯ïŒä»ãŸã§ã®æ
åœè
ãä»äºãæ ã£ãŠãããããïŒã²ãšã€å€ãååãããã£ãšå€ãååã䜿ãããŠãããã®ããã£ãïŒ ãªããšã京åããã¯ïŒå¹³æã®éã«æ ¡èãæ¹åãè¡ããã幎床ãšãã®ååã®ãªã¹ããèŠã€ããããšãã§ããïŒå¹³æå
å¹ŽåºŠã®æ ¡èå㯠"kogakubu10gokan" ã§ãã£ãïŒ ã ãåŒè¶ãäœæ¥ã«ãšãŠãç²ããã®ã§ïŒãã®è³æãäœããã幎床ã«ãã®æ ¡èãã©ããªååã ã£ãã®ããèªåã®æã§èª¿ã¹ãã®ã«ã¯ææ
¢ãªããªãã£ãïŒ ããã§äº¬åããã¯ïŒããã°ã©ãã³ã°ãåŸæãªããªãã«æäŒã£ãŠãšãé¡ãããããšã«ããïŒ æ¹åã®æŽå²ãšè³æãäœããã幎床ãäžããããã®ã§ãã®å¹ŽåºŠã®æ ¡èã®ååãåºåããããã°ã©ãã³ã°ãæžããŠããããïŒ å
¥ååœ¢åŒ å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ N Q year 1 name 1 year 2 name 2 ⊠year N name N N ã¯å¹³æ2幎床ããå¹³æ50幎床ãŸã§ã«è¡ãããæ¹åãšæ¹åããã幎床ã®çµã®åæ°ã§ããïŒ Q ã¯è³æãäœããã幎床ã衚ãïŒ year i ã¯æ¹åãè¡ããã幎床ã§ããïŒ name i ã¯æ¹åãããååãããããïŒ åºååœ¢åŒ å¹³æ Q å¹ŽåºŠã®æ ¡èã®ååãåºåããïŒ å¶çŽ 1 †N < 50 1 †Q < 50 2 †year 1 < year 2 < ⊠< year n †50 ãã¹ãŠã® i ã«å¯ŸããŠïŒ name i ã¯é·ã1以äž30以äžã§å«ãŸããæåã¯è±æ°å('a'-'z', 'A'-'Z', '0'-'9') ã§ããïŒ å¹³æå
å¹ŽåºŠã®æ ¡èã®ååã¯ïŒ"kogakubu10gokan" ã§ããïŒ å
¥åºåäŸ å
¥åäŸ 1 3 12 5 sogo5gokan 10 sogo10gokan 15 sogo15gokan åºåäŸ 1 sogo10gokan å¹³æ12å¹ŽåºŠã®æ ¡èåãåºåããã°ããïŒ æ ¡èã¯ïŒå¹³æå
幎床㮠kogakubu10gokan ããå§ãŸãïŒå¹³æ5幎床㫠sogo5gokanïŒ å¹³æ10幎床㫠sogo10gokan ããã³å¹³æ15幎床㫠sogo15gokan ã«æ¹åãããŠããïŒ å
¥åäŸ 2 3 10 5 kogakubu11gokan 10 sogo10gokan 15 KyotoUniversityResearchPark åºåäŸ 2 sogo10gokan å¹³æ10å¹ŽåºŠã®æ ¡èåãåºåããã°ããïŒ æ ¡èã¯ïŒå¹³æ10幎床㫠sogo10gokan ã«æ¹åãããŠããïŒ å
¥åäŸ 3 3 3 5 kogakubu11gokan 10 sogo10gokan 15 KyotoUniversityResearchPark åºåäŸ 3 kogakubu10gokan å¹³æ3å¹ŽåºŠã®æ ¡èåãåºåããã°ããïŒ å¹³æå
幎床ããå¹³æ4幎床ãŸã§ã®æ ¡èã®åå㯠"kogakubu10gokan" ã§ããïŒ | 35,624 |
Strange Key Professor Tsukuba invented a mysterious jewelry box that can be opened with a special gold key whose shape is very strange. It is composed of gold bars joined at their ends. Each gold bar has the same length and is placed parallel to one of the three orthogonal axes in a three dimensional space, i.e., x-axis, y-axis and z-axis. The locking mechanism of the jewelry box is truly mysterious, but the shape of the key is known. To identify the key of the jewelry box, he gave a way to describe its shape. The description indicates a list of connected paths that completely defines the shape of the key: the gold bars of the key are arranged along the paths and joined at their ends. Except for the first path, each path must start from an end point of a gold bar on a previously defined path. Each path is represented by a sequence of elements, each of which is one of six symbols (+x, -x, +y, -y, +z and -z) or a positive integer. Each symbol indicates the direction from an end point to the other end point of a gold bar along the path. Since each gold bar is parallel to one of the three orthogonal axes, the 6 symbols are enough to indicate the direction. Note that a description of a path has direction but the gold bars themselves have no direction. An end point of a gold bar can have a label, which is a positive integer. The labeled point may be referred to as the beginnings of other paths. In a key description, the first occurrence of a positive integer defines a label of a point and each subsequent occurrence of the same positive integer indicates the beginning of a new path at the point. An example of a key composed of 13 gold bars is depicted in Figure 1. The following sequence of lines 19 1 +x 1 +y +z 3 +z 3 +y -z +x +y -z -x +z 2 +z 2 +y is a description of the key in Figure 1. Note that newlines have the same role as space characters in the description, so that "19 1 +x 1 +y +z 3 +z 3 +y -z +x +y -z -x +z 2 +z 2 +y" has the same meaning. The meaning of this description is quite simple. The first integer "19" means the number of the following elements in this description. Each element is one of the 6 symbols or a positive integer. The integer "1" at the head of the second line is a label attached to the starting point of the first path. Without loss of generality, it can be assumed that the starting point of the first path is the origin, i.e., (0,0,0), and that the length of each gold bar is 1. The next element "+x" indicates that the first gold bar is parallel to the x-axis, so that the other end point of the gold bar is at (1,0,0). These two elements "1" and "+x" indicates the first path consisting of only one gold bar. The third element of the second line in the description is the positive integer "1", meaning that the point with the label "1", i.e., the origin (0,0,0) is the beginning of a new path. The following elements "+y", "+z", "3", and "+z" indicate the second path consisting of three gold bars. Note that this "3" is its first occurrence so that the point with coordinates (0,1,1) is labeled "3". The head of the third line "3" indicates the beginning of the third path and so on. Consequently, there are four paths by which the shape of the key in Figure 1 is completely defined. Note that there are various descriptions of the same key since there are various sets of paths that cover the shape of the key. For example, the following sequence of lines 19 1 +x 1 +y +z 3 +y -z +x +y -z -x +z 2 +y 3 +z 2 +z is another description of the key in Figure 1, since the gold bars are placed in the same way. Furthermore, the key may be turned 90-degrees around x-axis, y-axis or z-axis several times and may be moved parallelly. Since any combinations of rotations and parallel moves don't change the shape of the key, a description of a rotated and moved key also represent the same shape of the original key. For example, a sequence 17 +y 1 +y -z +x 1 +z +y +x +z +y -x -y 2 -y 2 +z is a description of a key in Figure 2 that represents the same key as in Figure 1. Indeed, they are congruent under a rotation around x-axis and a parallel move. Your job is to write a program to judge whether or not the given two descriptions define the same key. Note that paths may make a cycle. For example, "4 +x +y -x -y" and "6 1 +x 1 +y +x -y" are valid descriptions. However, two or more gold bars must not be placed at the same position. For example, key descriptions "2 +x -x" and "7 1 +x 1 +y +x -y -x" are invalid. Input An input data is a list of pairs of key descriptions followed by a zero that indicates the end of the input. For p pairs of key descriptions, the input is given in the following format. key-description 1-a key-description 1-b key-description 2-a key-description 2-b ... key-description p -a key-description p -b 0 Each key description ( key-description ) has the following format. n e 1 e 2 ... e k ... e n The positive integer n indicates the number of the following elements e 1 , ..., e n . They are separated by one or more space characters and/or newlines. Each element e k is one of the six symbols ( +x , -x , +y , -y , +z and -z ) or a positive integer. You can assume that each label is a positive integer that is less than 51, the number of elements in a single key description is less than 301, and the number of characters in a line is less than 80. You can also assume that the given key descriptions are valid and contain at least one gold bar. Output The number of output lines should be equal to that of pairs of key descriptions given in the input. In each line, you should output one of two words "SAME", when the two key descriptions represent the same key, and "DIFFERENT", when they are different. Note that the letters should be in upper case. Sample Input 19 1 +x 1 +y +z 3 +z 3 +y -z +x +y -z -x +z 2 +z 2 +y 19 1 +x 1 +y +z 3 +y -z +x +y -z -x +z 2 +y 3 +z 2 +z 19 1 +x 1 +y +z 3 +z 3 +y -z +x +y -z -x +z 2 +y 2 +z 18 1 -y 1 +y -z +x 1 +z +y +x +z +y -x -y 2 -y 2 +z 3 +x +y +z 3 +y +z -x 0 Output for the Sample Input SAME SAME DIFFERENT | 35,625 |
察空ã·ãŒã«ã æã¯3xxx幎ïŒå€ªéœç³»å€ã®ææã«é²åºãã人é¡ã¯ïŒå€§éã®éç³ã®é£æ¥ã«ããåºå°ã®è¢«å®³ã§é ãæ©ãŸããŠããïŒåœéå®å®é²è·äŒç€ŸïŒInternational Cosmic Protection CompanyïŒã¯ïŒãã®åé¡ã解決ããããã«æ°ããªå¯Ÿç©ºã·ãŒã«ããéçºããïŒ é²è·å¯Ÿè±¡ã®åºå°ã¯åããµã€ãºã® N åã®ãŠããããäžçŽç·äžã«çééã§äžŠãã 圢ãããŠããïŒ 1 ãã N ãŸã§ã®çªå·ãé ã«ä»ããããŠããïŒICPCã¯ïŒãããã®ãŠãããã«ïŒåèšã§ M åã®ã·ãŒã«ããèšçœ®ããããšã«ããïŒ i çªç®ã®ã·ãŒã«ããèœå a i ãæã¡ïŒãŠããã x i ã«èšçœ®ãããŠãããšããïŒãã®ãšãïŒãããŠããã u ã«ããã匷床ã¯ïŒä»¥äžã®åŒã§è¡šãããïŒ Î£ i=1 M max(a i -(u-x i ) 2 ,0) ã·ãŒã«ãã¯ãŠãããã«ã®ã¿èšçœ®ããããšãã§ãïŒè€æ°ã®ã·ãŒã«ããåããŠãããã«èšçœ®ããããšãã§ããïŒãããŠïŒICPCã«æ¯æãããå ±é
¬ã¯ N åã®ãŠãããã®åŒ·åºŠã®æå°å€ã«æ¯äŸããé¡ãšãªãïŒ ã·ãŒã«ãã®èœåã¯å
šãŠæ¢ã«æ±ºãŸã£ãŠããïŒäœçœ®ãæåŸã® 1 ã€ä»¥å€ã¯æ±ºå®ããŠããïŒæåŸã® 1 ã€ã®ã·ãŒã«ãã®äœçœ®ã決ããã«ããã£ãŠïŒå ±é
¬ããªãã¹ã倧ãããªãããã«ãããïŒãã®ããã«æåŸã®ã·ãŒã«ãã®äœçœ®ã決ãããšãã®åŒ·åºŠã®æå°å€ãæ±ããïŒ Input å
¥åã¯æå€§ã§ 30 åã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯æ¬¡ã®åœ¢åŒã§è¡šãããïŒ N M a 1 x 1 ⊠a M-1 x M-1 a M N ã¯ãŠãããã®åæ°ïŒ M ã¯ã·ãŒã«ãã®åæ°ã衚ãïŒ N ãš M ã¯æŽæ°ã§ããïŒ 1 †N †10 6 ïŒ 1 †M †10 5 ãæºããïŒç¶ã M è¡ã«ã¯åã·ãŒã«ãã®æ
å ±ãäžããããïŒ a i ãš x i ã¯ããããã·ãŒã«ãã®èœåãšäœçœ®ãè¡šãæŽæ°ã§ããïŒ 1 †a i †10 9 ïŒ 1 †x i †N ãæºããïŒ M çªç®ã®ã·ãŒã«ãã®äœçœ®ã¯ãŸã 決å®ããŠããªãããïŒå
¥åã§äžããããªãããšã«æ³šæããïŒ å
¥åã®çµãã㯠2 ã€ã®ãŒããããªãè¡ã§è¡šãããïŒ Output åããŒã¿ã»ããã«ã€ããŠïŒ M çªç®ã®ã·ãŒã«ãã®èšçœ®äœçœ®ãé©åã«æ±ºãããšãã®ïŒåŒ·åºŠã®æå°å€ã 1 è¡ã«åºåããïŒ Sample Input 3 3 2 1 2 2 10 10 4 1 1 1 5 1 9 1 5 7 1000000000 1 1000000000 1 1000000000 3 1000000000 3 1000000000 5 1000000000 5 1 10000 11 10934235 560 3155907 1508 10901182 2457 3471816 3590 10087848 4417 16876957 5583 23145027 6540 15162205 7454 1749653 8481 6216466 9554 7198514 701 14 8181 636 4942 273 1706 282 6758 20 7139 148 6055 629 8765 369 5487 95 6111 77 2302 419 9974 699 108 444 1136 495 2443 0 0 Output for the Sample Input 10 0 5999999960 23574372 985 | 35,626 |
RSQ and RUQ Write a program which manipulates a sequence $A$ = {$a_0, a_1, ..., a_{n-1}$} with the following operations: $update(s, t, x)$: change $a_s, a_{s+1}, ..., a_t$ to $x$. $getSum(s, t)$: print the sum of $a_s, a_{s+1}, ..., a_t$. Note that the initial values of $a_i ( i = 0, 1, ..., n-1 )$ are 0. Input $n$ $q$ $query_1$ $query_2$ : $query_q$ In the first line, $n$ (the number of elements in $A$) and $q$ (the number of queries) are given. Then, $i$-th query $query_i$ is given in the following format: 0 $s$ $t$ $x$ or 1 $s$ $t$ The first digit represents the type of the query. ' 0 ' denotes $update(s, t, x)$ and ' 1 ' denotes $find(s, t)$. Output For each $getSum$ query, print the sum in a line. Constraints $1 †n †100000$ $1 †q †100000$ $0 †s †t < n$ $-1000 †x †1000$ Sample Input 1 6 7 0 1 3 1 0 2 4 -2 1 0 5 1 0 1 0 3 5 3 1 3 4 1 0 5 Sample Output 1 -5 1 6 8 | 35,627 |
Score : 500 points Problem Statement There are N cities numbered 1 to N , connected by M railroads. You are now at City 1 , with 10^{100} gold coins and S silver coins in your pocket. The i -th railroad connects City U_i and City V_i bidirectionally, and a one-way trip costs A_i silver coins and takes B_i minutes. You cannot use gold coins to pay the fare. There is an exchange counter in each city. At the exchange counter in City i , you can get C_i silver coins for 1 gold coin. The transaction takes D_i minutes for each gold coin you give. You can exchange any number of gold coins at each exchange counter. For each t=2, ..., N , find the minimum time needed to travel from City 1 to City t . You can ignore the time spent waiting for trains. Constraints 2 \leq N \leq 50 N-1 \leq M \leq 100 0 \leq S \leq 10^9 1 \leq A_i \leq 50 1 \leq B_i,C_i,D_i \leq 10^9 1 \leq U_i < V_i \leq N There is no pair i, j(i \neq j) such that (U_i,V_i)=(U_j,V_j) . Each city t=2,...,N can be reached from City 1 with some number of railroads. All values in input are integers. Input Input is given from Standard Input in the following format: N M S U_1 V_1 A_1 B_1 : U_M V_M A_M B_M C_1 D_1 : C_N D_N Output For each t=2, ..., N in this order, print a line containing the minimum time needed to travel from City 1 to City t . Sample Input 1 3 2 1 1 2 1 2 1 3 2 4 1 11 1 2 2 5 Sample Output 1 2 14 The railway network in this input is shown in the figure below. In this figure, each city is labeled as follows: The first line: the ID number i of the city ( i for City i ) The second line: C_i / D_i Similarly, each railroad is labeled as follows: The first line: the ID number i of the railroad ( i for the i -th railroad in input) The second line: A_i / B_i You can travel from City 1 to City 2 in 2 minutes, as follows: Use the 1 -st railroad to move from City 1 to City 2 in 2 minutes. You can travel from City 1 to City 3 in 14 minutes, as follows: Use the 1 -st railroad to move from City 1 to City 2 in 2 minutes. At the exchange counter in City 2 , exchange 3 gold coins for 3 silver coins in 6 minutes. Use the 1 -st railroad to move from City 2 to City 1 in 2 minutes. Use the 2 -nd railroad to move from City 1 to City 3 in 4 minutes. Sample Input 2 4 4 1 1 2 1 5 1 3 4 4 2 4 2 2 3 4 1 1 3 1 3 1 5 2 6 4 Sample Output 2 5 5 7 The railway network in this input is shown in the figure below: You can travel from City 1 to City 4 in 7 minutes, as follows: At the exchange counter in City 1 , exchange 2 gold coins for 6 silver coins in 2 minutes. Use the 2 -nd railroad to move from City 1 to City 3 in 4 minutes. Use the 4 -th railroad to move from City 3 to City 4 in 1 minutes. Sample Input 3 6 5 1 1 2 1 1 1 3 2 1 2 4 5 1 3 5 11 1 1 6 50 1 1 10000 1 3000 1 700 1 100 1 1 100 1 Sample Output 3 1 9003 14606 16510 16576 The railway network in this input is shown in the figure below: You can travel from City 1 to City 6 in 16576 minutes, as follows: Use the 1 -st railroad to move from City 1 to City 2 in 1 minute. At the exchange counter in City 2 , exchange 3 gold coins for 3 silver coins in 9000 minutes. Use the 1 -st railroad to move from City 2 to City 1 in 1 minute. Use the 2 -nd railroad to move from City 1 to City 3 in 1 minute. At the exchange counter in City 3 , exchange 8 gold coins for 8 silver coins in 5600 minutes. Use the 2 -nd railroad to move from City 3 to City 1 in 1 minute. Use the 1 -st railroad to move from City 1 to City 2 in 1 minute. Use the 3 -rd railroad to move from City 2 to City 4 in 1 minute. At the exchange counter in City 4 , exchange 19 gold coins for 19 silver coins in 1900 minutes. Use the 3 -rd railroad to move from City 4 to City 2 in 1 minute. Use the 1 -st railroad to move from City 2 to City 1 in 1 minute. Use the 2 -nd railroad to move from City 1 to City 3 in 1 minute. Use the 4 -th railroad to move from City 3 to City 5 in 1 minute. At the exchange counter in City 5 , exchange 63 gold coins for 63 silver coins in 63 minutes. Use the 4 -th railroad to move from City 5 to City 3 in 1 minute. Use the 2 -nd railroad to move from City 3 to City 1 in 1 minute. Use the 5 -th railroad to move from City 1 to City 6 in 1 minute. Sample Input 4 4 6 1000000000 1 2 50 1 1 3 50 5 1 4 50 7 2 3 50 2 2 4 50 4 3 4 50 3 10 2 4 4 5 5 7 7 Sample Output 4 1 3 5 The railway network in this input is shown in the figure below: Sample Input 5 2 1 0 1 2 1 1 1 1000000000 1 1 Sample Output 5 1000000001 The railway network in this input is shown in the figure below: You can travel from City 1 to City 2 in 1000000001 minutes, as follows: At the exchange counter in City 1 , exchange 1 gold coin for 1 silver coin in 1000000000 minutes. Use the 1 -st railroad to move from City 1 to City 2 in 1 minute. | 35,628 |
Score : 1600 points Problem Statement There are N integers written on a blackboard. The i -th integer is A_i . Takahashi and Aoki will arrange these integers in a row, as follows: First, Takahashi will arrange the integers as he wishes. Then, Aoki will repeatedly swap two adjacent integers that are coprime, as many times as he wishes. We will assume that Takahashi acts optimally so that the eventual sequence will be lexicographically as small as possible, and we will also assume that Aoki acts optimally so that the eventual sequence will be lexicographically as large as possible. Find the eventual sequence that will be produced. Constraints 1 ⊠N ⊠2000 1 ⊠A_i ⊠10^8 Input The input is given from Standard Input in the following format: N A_1 A_2 ⊠A_N Output Print the eventual sequence that will be produced, in a line. Sample Input 1 5 1 2 3 4 5 Sample Output 1 5 3 2 4 1 If Takahashi arranges the given integers in the order (1,2,3,4,5) , they will become (5,3,2,4,1) after Aoki optimally manipulates them. Sample Input 2 4 2 3 4 6 Sample Output 2 2 4 6 3 | 35,629 |
Entrance Examination The International Competitive Programming College (ICPC) is famous for its research on competitive programming. Applicants to the college are required to take its entrance examination. The successful applicants of the examination are chosen as follows. The score of any successful applicant is higher than that of any unsuccessful applicant. The number of successful applicants n must be between n min and n max , inclusive. We choose n within the specified range that maximizes the gap. Here, the gap means the difference between the lowest score of successful applicants and the highest score of unsuccessful applicants. When two or more candidates for n make exactly the same gap, use the greatest n among them. Let's see the first couple of examples given in Sample Input below. In the first example, n min and n max are two and four, respectively, and there are five applicants whose scores are 100, 90, 82, 70, and 65. For n of two, three and four, the gaps will be 8, 12, and 5, respectively. We must choose three as n , because it maximizes the gap. In the second example, n min and n max are two and four, respectively, and there are five applicants whose scores are 100, 90, 80, 75, and 65. For n of two, three and four, the gap will be 10, 5, and 10, respectively. Both two and four maximize the gap, and we must choose the greatest number, four. You are requested to write a program that computes the number of successful applicants that satisfies the conditions. Input The input consists of multiple datasets. Each dataset is formatted as follows. m n min n max P 1 P 2 ... P m The first line of a dataset contains three integers separated by single spaces. m represents the number of applicants, n min represents the minimum number of successful applicants, and n max represents the maximum number of successful applicants. Each of the following m lines contains an integer P i , which represents the score of each applicant. The scores are listed in descending order. These numbers satisfy 0 < n min < n max < m †200, 0 †P i †10000 (1 †i †m ) and P n min > P n max +1 . These ensure that there always exists an n satisfying the conditions. The end of the input is represented by a line containing three zeros separated by single spaces. Output For each dataset, output the number of successful applicants in a line. Sample Input 5 2 4 100 90 82 70 65 5 2 4 100 90 80 75 65 3 1 2 5000 4000 3000 4 2 3 10000 10000 8000 8000 4 2 3 10000 10000 10000 8000 5 2 3 100 80 68 60 45 0 0 0 Output for the Sample Input 3 4 2 2 3 2 | 35,630 |
Score : 1900 points Problem Statement Ringo has a tree with N vertices. The i -th of the N-1 edges in this tree connects Vertex A_i and Vertex B_i and has a weight of C_i . Additionally, Vertex i has a weight of X_i . Here, we define f(u,v) as the distance between Vertex u and Vertex v , plus X_u + X_v . We will consider a complete graph G with N vertices. The cost of its edge that connects Vertex u and Vertex v is f(u,v) . Find the minimum spanning tree of G . Constraints 2 \leq N \leq 200,000 1 \leq X_i \leq 10^9 1 \leq A_i,B_i \leq N 1 \leq C_i \leq 10^9 The given graph is a tree. All input values are integers. Input Input is given from Standard Input in the following format: N X_1 X_2 ... X_N A_1 B_1 C_1 A_2 B_2 C_2 : A_{N-1} B_{N-1} C_{N-1} Output Print the cost of the minimum spanning tree of G . Sample Input 1 4 1 3 5 1 1 2 1 2 3 2 3 4 3 Sample Output 1 22 We connect the following pairs: Vertex 1 and 2 , Vertex 1 and 4 , Vertex 3 and 4 . The costs are 5 , 8 and 9 , respectively, for a total of 22 . Sample Input 2 6 44 23 31 29 32 15 1 2 10 1 3 12 1 4 16 4 5 8 4 6 15 Sample Output 2 359 Sample Input 3 2 1000000000 1000000000 2 1 1000000000 Sample Output 3 3000000000 | 35,631 |
Score : 400 points Problem Statement Along a road running in an east-west direction, there are A shrines and B temples. The i -th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i -th temple from the west is located at a distance of t_i meters from the west end of the road. Answer the following Q queries: Query i ( 1 \leq i \leq Q ): If we start from a point at a distance of x_i meters from the west end of the road and freely travel along the road, what is the minimum distance that needs to be traveled in order to visit one shrine and one temple? (It is allowed to pass by more shrines and temples than required.) Constraints 1 \leq A, B \leq 10^5 1 \leq Q \leq 10^5 1 \leq s_1 < s_2 < ... < s_A \leq 10^{10} 1 \leq t_1 < t_2 < ... < t_B \leq 10^{10} 1 \leq x_i \leq 10^{10} s_1, ..., s_A, t_1, ..., t_B, x_1, ..., x_Q are all different. All values in input are integers. Input Input is given from Standard Input in the following format: A B Q s_1 : s_A t_1 : t_B x_1 : x_Q Output Print Q lines. The i -th line should contain the answer to the i -th query. Sample Input 1 2 3 4 100 600 400 900 1000 150 2000 899 799 Sample Output 1 350 1400 301 399 There are two shrines and three temples. The shrines are located at distances of 100, 600 meters from the west end of the road, and the temples are located at distances of 400, 900, 1000 meters from the west end of the road. Query 1 : If we start from a point at a distance of 150 meters from the west end of the road, the optimal move is first to walk 50 meters west to visit a shrine, then to walk 300 meters east to visit a temple. Query 2 : If we start from a point at a distance of 2000 meters from the west end of the road, the optimal move is first to walk 1000 meters west to visit a temple, then to walk 400 meters west to visit a shrine. We will pass by another temple on the way, but it is fine. Query 3 : If we start from a point at a distance of 899 meters from the west end of the road, the optimal move is first to walk 1 meter east to visit a temple, then to walk 300 meters west to visit a shrine. Query 4 : If we start from a point at a distance of 799 meters from the west end of the road, the optimal move is first to walk 199 meters west to visit a shrine, then to walk 200 meters west to visit a temple. Sample Input 2 1 1 3 1 10000000000 2 9999999999 5000000000 Sample Output 2 10000000000 10000000000 14999999998 The road is quite long, and we may need to travel a distance that does not fit into a 32 -bit integer. | 35,632 |
Score : 100 points Problem Statement An elementary school student Takahashi has come to a variety store. He has two coins, A -yen and B -yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it? Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan. Constraints All input values are integers. 1 \leq A, B \leq 500 1 \leq C \leq 1000 Input Input is given from Standard Input in the following format: A B C Output If Takahashi can buy the toy, print Yes ; if he cannot, print No . Sample Input 1 50 100 120 Sample Output 1 Yes He has 50 + 100 = 150 yen, so he can buy the 120 -yen toy. Sample Input 2 500 100 1000 Sample Output 2 No He has 500 + 100 = 600 yen, but he cannot buy the 1000 -yen toy. Sample Input 3 19 123 143 Sample Output 3 No There are 19 -yen and 123 -yen coins in Takahashi Kingdom, which are rather hard to use. Sample Input 4 19 123 142 Sample Output 4 Yes | 35,633 |
Score : 1500 points Problem Statement Consider a circle whose perimeter is divided by N points into N arcs of equal length, and each of the arcs is painted red or blue. Such a circle is said to generate a string S from every point when the following condition is satisfied: We will arbitrarily choose one of the N points on the perimeter and place a piece on it. Then, we will perform the following move M times: move the piece clockwise or counter-clockwise to an adjacent point. Here, whatever point we choose initially, it is always possible to move the piece so that the color of the i -th arc the piece goes along is S_i , by properly deciding the directions of the moves. Assume that, if S_i is R , it represents red; if S_i is B , it represents blue. Note that the directions of the moves can be decided separately for each choice of the initial point. You are given a string S of length M consisting of R and B . Out of the 2^N ways to paint each of the arcs red or blue in a circle whose perimeter is divided into N arcs of equal length, find the number of ways resulting in a circle that generates S from every point, modulo 10^9+7 . Note that the rotations of the same coloring are also distinguished. Constraints 2 \leq N \leq 2 \times 10^5 1 \leq M \leq 2 \times 10^5 |S|=M S_i is R or B . Input Input is given from Standard Input in the following format: N M S Output Print the number of ways to paint each of the arcs that satisfy the condition, modulo 10^9+7 . Sample Input 1 4 7 RBRRBRR Sample Output 1 2 The condition is satisfied only if the arcs are alternately painted red and blue, so the answer here is 2 . Sample Input 2 3 3 BBB Sample Output 2 4 Sample Input 3 12 10 RRRRBRRRRB Sample Output 3 78 | 35,634 |
Problem K: Trading Ship You are on board a trading ship as a crew. The ship is now going to pass through a strait notorious for many pirates often robbing ships. The Maritime Police has attempted to expel those pirates many times, but failed their attempts as the pirates are fairly strong. For this reason, every ship passing through the strait needs to defend themselves from the pirates. The navigator has obtained a sea map on which the location of every hideout of pirates is shown. The strait is considered to be a rectangle of W à H on an xy-plane, where the two opposite corners have the coordinates of (0, 0) and ( W , H ). The ship is going to enter and exit the strait at arbitrary points on y = 0 and y = H respectively. To minimize the risk of attack, the navigator has decided to take a route as distant from the hideouts as possible. As a talented programmer, you are asked by the navigator to write a program that finds the best route, that is, the route with the maximum possible distance to the closest hideouts. For simplicity, your program just needs to report the distance in this problem. Input The input begins with a line containing three integers W , H , and N . Here, N indicates the number of hideouts on the strait. Then N lines follow, each of which contains two integers x i and y i , which denote the coordinates the i -th hideout is located on. The input satisfies the following conditions: 1 †W , H †10 9 , 1 †N †500, 0 †x i †W , 0 †y i †H . Output There should be a line containing the distance from the best route to the closest hideout(s). The distance should be in a decimal fraction and should not contain an absolute error greater than 10 -3 . Sample Input and Output Input #1 10 10 1 3 5 Output #1 7.000 Input #2 10 10 2 2 2 8 8 Output #2 4.243 Input #3 10 10 3 0 1 4 4 8 1 Output #3 2.500 | 35,635 |
E: æ°åã²ãŒã å顿 é·ã $N$ ã®æ£æŽæ°å $a_1, a_2, \ldots, a_N$ ããããŸãã ãã®æ°åãçšããã$2$ 人ã®ãã¬ã€ã€ãŒãå
æãšåŸæã«åãããŠè¡ã以äžã®ã²ãŒã ãèããŸãã å
æãšåŸæã¯äº€äºã«ã以äžã®æäœã®ã©ã¡ãããéžãã§è¡ãã æ°åã®æ£ã®é
ã $1$ ã€éžã³ããã®å€ã $1$ æžããã æ°åã®å
šãŠã®é
ãæ£ã®ãšããå
šãŠã®é
ã®å€ã $1$ ãã€æžããã å
ã«æäœãè¡ããªããªã£ãã»ããè² ãã§ãã $2$ 人ã®ãã¬ã€ã€ãŒãæé©ã«è¡åãããšããå
æãšåŸæã©ã¡ããåã€ããæ±ããŠãã ããã å¶çŽ $1 \leq N \leq 2 \times 10^5$ $1 \leq a_i \leq 10^9$ å
¥åã¯å
šãп޿°ã§ãã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããã $N$ $a_1$ $a_2$ $...$ $a_N$ åºå å
æãåã€ãšã㯠First ããåŸæãåã€ãšã㯠Second ãåºåããã å
¥åäŸ 1 2 1 2 åºåäŸ 1 First å
æãæåã«ç¬¬ $1$ é
ã®å€ã $1$ æžãããšã次ã«åŸæã¯ç¬¬ $2$ é
ã®å€ã $1$ æžãããããããŸããã ãã®ããšã§å
æã第 $2$ é
ã®å€ã $1$ æžãããšãæ°åã®å
šãŠã®é
ã®å€ã¯ $0$ ã«ãªãã åŸæã¯æäœãè¡ãããšãã§ããªããªããŸãã å
¥åäŸ 2 5 3 1 4 1 5 åºåäŸ 2 Second å
¥åäŸ 3 8 2 4 8 16 32 64 128 256 åºåäŸ 3 Second å
¥åäŸ 4 3 999999999 1000000000 1000000000 åºåäŸ 4 First | 35,636 |
Score : 200 points Problem Statement Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A , and he can travel the distance of V per second. The other child is now at coordinate B , and she can travel the distance of W per second. He can catch her when his coordinate is the same as hers. Determine whether he can catch her within T seconds (including exactly T seconds later). We assume that both children move optimally. Constraints -10^9 \leq A,B \leq 10^9 1 \leq V,W \leq 10^9 1 \leq T \leq 10^9 A \neq B All values in input are integers. Input Input is given from Standard Input in the following format: A V B W T Output If "it" can catch the other child, print YES ; otherwise, print NO . Sample Input 1 1 2 3 1 3 Sample Output 1 YES Sample Input 2 1 2 3 2 3 Sample Output 2 NO Sample Input 3 1 2 3 3 3 Sample Output 3 NO | 35,637 |
Score : 1300 points Problem Statement We have a pyramid with N steps, built with blocks. The steps are numbered 1 through N from top to bottom. For each 1â€iâ€N , step i consists of 2i-1 blocks aligned horizontally. The pyramid is built so that the blocks at the centers of the steps are aligned vertically. A pyramid with N=4 steps Snuke wrote a permutation of ( 1 , 2 , ... , 2N-1 ) into the blocks of step N . Then, he wrote integers into all remaining blocks, under the following rule: The integer written into a block b must be equal to the median of the three integers written into the three blocks directly under b , or to the lower left or lower right of b . Writing integers into the blocks Afterwards, he erased all integers written into the blocks. Now, he only remembers that the permutation written into the blocks of step N was ( a_1 , a_2 , ... , a_{2N-1} ). Find the integer written into the block of step 1 . Constraints 2â€Nâ€10^5 ( a_1 , a_2 , ... , a_{2N-1} ) is a permutation of ( 1 , 2 , ... , 2N-1 ). Input The input is given from Standard Input in the following format: N a_1 a_2 ... a_{2N-1} Output Print the integer written into the block of step 1 . Sample Input 1 4 1 6 3 7 4 5 2 Sample Output 1 4 This case corresponds to the figure in the problem statement. Sample Input 2 2 1 2 3 Sample Output 2 2 | 35,638 |
CïŒ AA ã°ã©ã (AA Graph) Problem Given a graph as an ASCII Art (AA), please print the length of shortest paths from the vertex s to the vertex t . The AA of the graph satisfies the following constraints. A vertex is represented by an uppercase alphabet and symbols o in 8 neighbors as follows. ooo oAo ooo Horizontal edges and vertical edges are represented by symbols - and | , respectively. Lengths of all edges are 1, that is, it do not depends on the number of continuous symbols - or | . All edges do not cross each other, and all vertices do not overlap and touch each other. For each vertex, outgoing edges are at most 1 for each directions top, bottom, left, and right. Each edge is connected to a symbol o that is adjacent to an uppercase alphabet in 4 neighbors as follows. ..|.. .ooo. -oAo- .ooo. ..|.. Therefore, for example, following inputs are not given. .......... .ooo..ooo. .oAo..oBo. .ooo--ooo. .......... (Edges do not satisfies the constraint about their position.) oooooo oAooBo oooooo (Two vertices are adjacent each other.) Input Format H W s t a_1 $\vdots$ a_H In line 1, two integers H and W , and two characters s and t are given. H and W is the width and height of the AA, respectively. s and t is the start and end vertices, respectively. They are given in separating by en spaces. In line 1 + i where 1 \leq i \leq H , the string representing line i of the AA is given. Constraints 3 \leq H, W \leq 50 s and t are selected by uppercase alphabets from A to Z , and s \neq t . a_i ( 1 \leq i \leq H ) consists of uppercase alphabets and symbols o , - , | , and . . Each uppercase alphabet occurs at most once in the AA. It is guaranteed that there are two vertices representing s and t . The AA represents a connected graph. Output Format Print the length of the shortest paths from s to t in one line. Example 1 14 16 A L ooo.....ooo..... oAo-----oHo..... ooo.....ooo..ooo .|.......|...oLo ooo..ooo.|...ooo oKo--oYo.|....|. ooo..ooo.|....|. .|....|.ooo...|. .|....|.oGo...|. .|....|.ooo...|. .|....|.......|. ooo..ooo.....ooo oFo--oXo-----oEo ooo..ooo.....ooo Output 1 5 Exapmple 2 21 17 F L ................. .....ooo.....ooo. .....oAo-----oBo. .....ooo.....ooo. ......|.......|.. .ooo..|..ooo..|.. .oCo..|..oDo.ooo. .ooo.ooo.ooo.oEo. ..|..oFo..|..ooo. ..|..ooo..|...|.. ..|...|...|...|.. ..|...|...|...|.. ..|...|...|...|.. .ooo.ooo.ooo..|.. .oGo-oHo-oIo..|.. .ooo.ooo.ooo..|.. ..|...........|.. .ooo...ooo...ooo. .oJo---oKo---oLo. .ooo...ooo...ooo. ................. Output 2 4 | 35,639 |
Transporter In the year 30XX, an expedition team reached a planet and found a warp machine suggesting the existence of a mysterious supercivilization. When you go through one of its entrance gates, you can instantaneously move to the exit irrespective of how far away it is. You can move even to the end of the universe at will with this technology! The scientist team started examining the machine and successfully identified all the planets on which the entrances to the machine were located. Each of these N planets (identified by an index from $1$ to $N$) has an entrance to, and an exit from the warp machine. Each of the entrances and exits has a letter inscribed on it. The mechanism of spatial mobility through the warp machine is as follows: If you go into an entrance gate labeled with c, then you can exit from any gate with label c. If you go into an entrance located on the $i$-th planet, then you can exit from any gate located on the $j$-th planet where $i < j$. Once you have reached an exit of the warp machine on a planet, you can continue your journey by entering into the warp machine on the same planet. In this way, you can reach a faraway planet. Our human race has decided to dispatch an expedition to the star $N$, starting from Star $1$ and using the warp machine until it reaches Star $N$. To evaluate the possibility of successfully reaching the destination. it is highly desirable for us to know how many different routes are available for the expedition team to track. Given information regarding the stars, make a program to enumerate the passages from Star $1$ to Star $N$. Input The input is given in the following format. $N$ $s$ $t$ The first line provides the number of the stars on which the warp machine is located $N$ ($2 \leq N \leq 100,000$). The second line provides a string $s$ of length $N$, each component of which represents the letter inscribed on the entrance of the machine on the star. By the same token, the third line provides a string $t$ of length $N$ consisting of the letters inscribed on the exit of the machine. Two strings $s$ and $t$ consist all of lower-case alphabetical letters, and the $i$-th letter of these strings corresponds respectively to the entrance and exit of Star $i$ machine. Output Divide the number of possible routes from Star $1$ to Star $N$ obtained above by 1,000,000,007, and output the remainder. Sample Input 1 6 abbaba baabab Sample Output 1 5 Sample Input 2 25 neihsokcpuziafoytisrevinu universityofaizupckoshien Sample Output 2 4 | 35,640 |
Problem G: Double or Increment Problem ããæ¥ãmo3tthiåãštubuannåã¯ãéæ³ã®ãã±ãããšãã¹ã±ããã䜿ã£ãŠã²ãŒã ãããããšã«ããŸããã ä»ããã« $K$ åã®ãã±ãããããã$1,2, \ldots ,K$ ã®çªå·ãã€ããŠããŸãã $i$ çªç®ã®ãã±ããã®å®¹é㯠$M_i$ ã§ãæå $N_i$ æã®ãã¹ã±ãããå
¥ã£ãŠããŸãã mo3tthiåãštubuannåã¯ãmo3tthiåããå§ããŠã以äžã®äžé£ã®æäœã亀äºã«è¡ããŸãã ãã±ãããäžã€éžã¶ã 以äžã®ããããäžæ¹ã®æäœãäžåºŠã ãè¡ãããã ããæäœã®çµæéžãã ãã±ããã«å
¥ã£ãŠãããã¹ã±ããã®ææ°ããã±ããã®å®¹éãè¶
ããå Žåãæäœãè¡ãããšã¯ã§ããªãã éžãã ãã±ãããæ«ã§ããéæ³ã®åã«ãã£ãŠéžãã ãã±ããã«å
¥ã£ãŠãããã¹ã±ããã®ææ°ã $1$ å¢ããã éžãã ãã±ãããå©ããéæ³ã®åã«ãã£ãŠéžãã ãã±ããã«å
¥ã£ãŠãããã¹ã±ããã®ææ°ã $2$ åã«ãªãã æäœãè¡ããªããªã£ãæç¹ã§ã²ãŒã ã¯çµäºããæäœãè¡ããªããªã£ã人ãè² ããããã§ãªã人ãåã¡ã«ãªããŸãã mo3tthiåã®å人ã§ããããªãã¯ãmo3tthiåããäºåã«ãã®ã²ãŒã ã«åãŠããã©ãããå€å®ã§ããªããçžè«ãããŸããã mo3tthiåã®ããã«ãmo3tthiåããã®ã²ãŒã ã«å¿
ãåã€ããšãã§ãããã©ãããå€å®ããããã°ã©ã ãäœã£ãŠãã ããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã $K$ $N_1$ $M_1$ $\vdots$ $N_K$ $M_K$ Constraints å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã $1 \leq K \leq 10^5$ $1 \leq N_i \leq M_i \leq 10^{18}$ å
¥åã¯å
šãп޿°ã§ãã Output mo3tthiåãæé©ã«è¡åãããšããå¿
ãåã€ããšãã§ãããªã"mo3tthi"ããããã§ãªããªã"tubuann"ãäžè¡ã«åºåããã Sample Input 1 1 2 4 Sample Output 1 mo3tthi mo3tthiåãäžçªç®ã®ãã±ãããå©ããšãäžçªç®ã®ãã±ããã«å
¥ã£ãŠãããã¹ã±ããã®ææ°ã $4$ ã«ãªããtubuannåã¯æäœãè¡ãããšãã§ããªãã Sample Input 2 2 2 3 3 8 Sample Output 2 tubuann Sample Input 3 10 2 8 5 9 7 20 8 41 23 48 90 112 4 5 7 7 2344 8923 1 29 Sample Output 3 mo3tthi | 35,641 |
ã¹ãã€ããŒäºº æ£çŸ©ã®ããŒããŒãã¹ãã€ããŒäººãã¯ãè
ããããŒããåºããŠãã«ãããã«ãžé£ã³ç§»ãããšãã§ããŸããããããããŒããçãã®ã§èªåããã®è·é¢ã 50 以äžã®ãã«ã«ããç§»åã§ããŸãããããããé ãã®ãã«ã«ç§»åããã«ã¯ãäžæŠå¥ã®ãã«ã«é£ã³ç§»ããªããŠã¯ãªããŸããã ãã«ã®æ° n ã n åã®ãã«ã®æ
å ±ãã¹ãã€ããŒäººã®ç§»åéå§äœçœ®åã³ç®çå°ãå
¥åãšãããã®ç§»åã®æççµè·¯ãåºåããããã°ã©ã ãäœæããŠãã ãããã©ã®ããã«ãã«ãçµç±ããŠãç®æšã®ãã«ã«ç§»åã§ããªãå Žå㯠NA ãšåºåããŠãã ãããåãã«ã¯ç¹ãšããŠæ±ããæçè·é¢ã§ç§»åãããã«ã®çµç±æ¹æ³ãïŒã€ä»¥äžååšããããšã¯ãªããã®ãšããŸãã Input è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸãã åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã n b 1 x 1 y 1 b 2 x 2 y 2 : b n x n y n m s 1 g 1 s 2 g 2 : s m g m ïŒè¡ç®ã«ãã«ã®æ° n (1 †n †100)ãç¶ã n è¡ã« i çªç®ã®ãã«ã®ãã«çªå· b i (1 †b i †n )ããã®ãã«ã®x座æšãšy座æšãè¡šãæŽæ° x i , y i (-1000 †x i , y i †1000) ã空çœåºåãã§äžããããŸãã ç¶ãè¡ã«ç§»åæ
å ±ã®åæ° m (1 †m †100)ãç¶ã m è¡ã« i çªç®ã®ç§»åæ
å ±ãäžããããŸããåç§»åæ
å ±ãšããŠãç§»åãéå§ãããã«ã®çªå· s i ãšç®çå°ãã«ã®çªå· g i ã空çœåºåãã§äžããããŸãã ããŒã¿ã»ããã®æ°ã¯ 10 ãè¶
ããŸããã Output å
¥åããŒã¿ã»ããããšã«æ¬¡ã®åœ¢åŒã§åºåããŸãã i è¡ç®ã« i çªç®ã®ç§»åæ
å ±ã«å¯Ÿããçµè·¯ãŸã㯠NA ãïŒè¡ã«åºåããŸããåçµè·¯ã¯ä»¥äžã®åœ¢åŒã§åºåããŸãã s i br i1 br i2 ... g i br ij 㯠i çªç®ã®ç§»åæ
å ±ã«ãããã j çªç®ã«çµç±ãããã«ã®çªå·ã衚ããŸãã Sample Input 4 1 0 0 2 30 0 3 60 40 4 0 60 2 1 3 1 4 22 1 0 0 2 150 40 3 30 20 4 180 150 5 40 80 6 130 130 7 72 28 8 172 118 9 50 50 10 160 82 11 90 105 12 144 131 13 130 64 14 80 140 15 38 117 16 190 90 17 60 100 18 100 70 19 130 100 20 71 69 21 200 110 22 120 150 1 1 22 0 Output for the Sample Input 1 2 3 NA 1 3 9 20 11 6 22 | 35,642 |
Score : 500 points Problem Statement You have a string S of length N . Initially, all characters in S are 1 s. You will perform queries Q times. In the i -th query, you are given two integers L_i, R_i and a character D_i (which is a digit). Then, you must replace all characters from the L_i -th to the R_i -th (inclusive) with D_i . After each query, read the string S as a decimal integer, and print its value modulo 998,244,353 . Constraints 1 \leq N, Q \leq 200,000 1 \leq L_i \leq R_i \leq N 1 \leq D_i \leq 9 All values in input are integers. Input Input is given from Standard Input in the following format: N Q L_1 R_1 D_1 : L_Q R_Q D_Q Output Print Q lines. In the i -th line print the value of S after the i -th query, modulo 998,244,353 . Sample Input 1 8 5 3 6 2 1 4 7 3 8 3 2 2 2 4 5 1 Sample Output 1 11222211 77772211 77333333 72333333 72311333 Sample Input 2 200000 1 123 456 7 Sample Output 2 641437905 Don't forget to take the modulo. | 35,643 |
åé¡1 äžè§åœ¢ã®åœ¢ã¯èŸºã®é·ãã§æ±ºãŸãïŒ é çªã«ïŒã€ã®æ£æŽæ°ãäžãããããšãïŒ èŸºã®é·ãããããã®å€ãšäžèŽããäžè§åœ¢ãååšãããã©ããã調ã¹ïŒ ååšãããªãéè§äžè§åœ¢ïŒçŽè§äžè§åœ¢ïŒéè§äžè§åœ¢ã®ãããããå€å®ãïŒ æ¬¡ã®å
¥åãžé²ãïŒ äžè§åœ¢ãååšããªããšãïŒ ãããŸã§ã«å
¥åãããïŒäžè§åœ¢ïŒçŽè§äžè§åœ¢ïŒéè§äžè§åœ¢ïŒéè§äžè§åœ¢ã® åæ°ã空çœã§åºåã£ãŠåºåãïŒ ãã以éã®å
¥åã¯ç¡èŠããŠçµäºããïŒ å
¥åã®äžã«ã¯å¿
ãäžè§åœ¢ãååšããªããããªãã®ããã ãšä»®å®ããŠãã. å
¥åã®è¡æ°ã¯å€ããªããåè¡ã«ã¯ïŒã€ã®æ£æŽæ°ã空çœã§åºåã£ãŠæžãããŠããïŒ ãã ãïŒåæŽæ°ã¯100 以äžãšãã. åºåãã¡ã€ã«ã«ãããŠã¯ïŒ åºåã®æåŸã®è¡ã«ãæ¹è¡ã³ãŒããå
¥ããããšïŒ å
¥åºåäŸ å
¥åäŸïŒ 3 4 5 2 1 2 6 3 4 1 1 1 1 2 3 4 1 2 1 å
¥åäŸïŒ 3 4 5 2 1 2 6 3 4 1 2 3 1 1 1 åºåäŸïŒ 3 1 1 1 å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã | 35,644 |
Score: 400 points Problem Statement In Takahashi Kingdom, there is a east-west railroad and N cities along it, numbered 1 , 2 , 3 , ..., N from west to east. A company called AtCoder Express possesses M trains, and the train i runs from City L_i to City R_i (it is possible that L_i = R_i ). Takahashi the king is interested in the following Q matters: The number of the trains that runs strictly within the section from City p_i to City q_i , that is, the number of trains j such that p_i \leq L_j and R_j \leq q_i . Although he is genius, this is too much data to process by himself. Find the answer for each of these Q queries to help him. Constraints N is an integer between 1 and 500 (inclusive). M is an integer between 1 and 200 \ 000 (inclusive). Q is an integer between 1 and 100 \ 000 (inclusive). 1 \leq L_i \leq R_i \leq N (1 \leq i \leq M) 1 \leq p_i \leq q_i \leq N (1 \leq i \leq Q) Input Input is given from Standard Input in the following format: N M Q L_1 R_1 L_2 R_2 : L_M R_M p_1 q_1 p_2 q_2 : p_Q q_Q Output Print Q lines. The i -th line should contain the number of the trains that runs strictly within the section from City p_i to City q_i . Sample Input 1 2 3 1 1 1 1 2 2 2 1 2 Sample Output 1 3 As all the trains runs within the section from City 1 to City 2 , the answer to the only query is 3 . Sample Input 2 10 3 2 1 5 2 8 7 10 1 7 3 10 Sample Output 2 1 1 The first query is on the section from City 1 to 7 . There is only one train that runs strictly within that section: Train 1 . The second query is on the section from City 3 to 10 . There is only one train that runs strictly within that section: Train 3 . Sample Input 3 10 10 10 1 6 2 9 4 5 4 7 4 7 5 8 6 6 6 7 7 9 10 10 1 8 1 9 1 10 2 8 2 9 2 10 3 8 3 9 3 10 1 10 Sample Output 3 7 9 10 6 8 9 6 7 8 10 | 35,645 |
Problem C: Minimal Backgammon Here is a very simple variation of the game backgammon, named âMinimal Backgammonâ. The game is played by only one player, using only one of the dice and only one checker (the token used by the player). The game board is a line of ( N + 1) squares labeled as 0 (the start) to N (the goal). At the beginning, the checker is placed on the start (square 0). The aim of the game is to bring the checker to the goal (square N ). The checker proceeds as many squares as the roll of the dice. The dice generates six integers from 1 to 6 with equal probability. The checker should not go beyond the goal. If the roll of the dice would bring the checker beyond the goal, the checker retreats from the goal as many squares as the excess. For example, if the checker is placed at the square ( N - 3), the roll "5" brings the checker to the square ( N - 2), because the excess beyond the goal is 2. At the next turn, the checker proceeds toward the goal as usual. Each square, except the start and the goal, may be given one of the following two special instructions. Lose one turn (labeled " L " in Figure 2) If the checker stops here, you cannot move the checker in the next turn. Go back to the start (labeled " B " in Figure 2) If the checker stops here, the checker is brought back to the start. Figure 2: An example game Given a game board configuration (the size N , and the placement of the special instructions), you are requested to compute the probability with which the game succeeds within a given number of turns. Input The input consists of multiple datasets, each containing integers in the following format. N T L B Lose 1 ... Lose L Back 1 ... Back B N is the index of the goal, which satisfies 5 †N †100. T is the number of turns. You are requested to compute the probability of success within T turns. T satisfies 1 †T †100. L is the number of squares marked âLose one turnâ, which satisfies 0 †L †N - 1. B is the number of squares marked âGo back to the startâ, which satisfies 0 †B †N - 1. They are separated by a space. Lose i 's are the indexes of the squares marked âLose one turnâ, which satisfy 1 †Lose i †N - 1. All Lose i 's are distinct, and sorted in ascending order. Back i 's are the indexes of the squares marked âGo back to the startâ, which satisfy 1 †Back i †N - 1. All Back i 's are distinct, and sorted in ascending order. No numbers occur both in Lose i 's and Back i 's. The end of the input is indicated by a line containing four zeros separated by a space. Output For each dataset, you should answer the probability with which the game succeeds within the given number of turns. The output should not contain an error greater than 0.00001. Sample Input 6 1 0 0 7 1 0 0 7 2 0 0 6 6 1 1 2 5 7 10 0 6 1 2 3 4 5 6 0 0 0 0 Output for the Sample Input 0.166667 0.000000 0.166667 0.619642 0.000000 | 35,646 |
w æ¬ã®çžŠæ£ãããªãïŒé«ã(暪æ£ã远å ããããšã®ã§ããæ®µæ°) ã h ã®ãã¿ã ãããããïŒ w ã¯å¶æ°ã§ããïŒãã®ãã¿ã ããã®æšªæ£ã远å ããå Žæã®åè£ã®ãã¡äžãã a çªç®ïŒå·Šãã b çªç®ã (a, b) ãšããïŒ( (a, b) ã«æšªæ£ã远å ããå ŽåïŒäžãã a 段ç®ã§å·Šãã b çªç®ãš b+1 çªç®ã®çžŠæ£ãçµã°ããïŒ) ãã®ãããªå Žæã¯åèš h(w â1) ç®æ(1 †a †h , 1 †b †w â 1) ååšããïŒ ãã¬ãåã¯ïŒ a â¡ b (mod 2) ãã¿ããå Žæ (a, b) ã«å
šãŠæšªæ£ã远å ããïŒæ¬¡ã«ïŒãã¬ãåã¯ïŒ (a 1 , b 1 ), . . . , (a n , b n ) ã®å Žæã®æšªæ£ãæ¶ããïŒäžç«¯ã§å·Šãã i çªç®ãéžãã ãšãäžç«¯ã§å·Šããäœçªç®ã«ãªããïŒãšããã®ãå
šãŠæ±ããïŒ Constraints 1 †h, w, n †200000 w ã¯å¶æ° 1 †a i †h 1 †b i †w â 1 a i â¡ b i (mod 2) (a i , b i ) = (a j , b j ) ãšãªããããªçžç°ãªã i, j ã¯ååšããªã Input h w n a 1 b 1 . . . a n b n Output w è¡åºåããïŒ i è¡ç®ã«ã¯ïŒäžç«¯ã§å·Šãã i çªç®ãéžãã ãšãäžç«¯ã§å·Šããäœçªç®ã«ãªãããåºåããïŒ Sample Input 1 4 4 1 3 3 Sample Output 1 2 3 4 1 å³1: ããšãã°ïŒäžç«¯ã§å·Šç«¯ã®çžŠæ£ãéžã¶ãšïŒ(1, 1), (2, 2), (4, 2) ãéã£ãŠäžç«¯ã§å·Šããäºçªç®ã®çžŠæ£ã«ãã©ãçãïŒ Sample Input 2 10 6 10 10 4 4 4 5 1 4 2 7 3 1 3 2 4 8 2 7 5 7 1 Sample Output 2 1 4 3 2 5 6 | 35,647 |
Score : 200 points Problem Statement There is a kangaroo at coordinate 0 on an infinite number line that runs from left to right, at time 0 . During the period between time i-1 and time i , the kangaroo can either stay at his position, or perform a jump of length exactly i to the left or to the right. That is, if his coordinate at time i-1 is x , he can be at coordinate x-i , x or x+i at time i . The kangaroo's nest is at coordinate X , and he wants to travel to coordinate X as fast as possible. Find the earliest possible time to reach coordinate X . Constraints X is an integer. 1â€Xâ€10^9 Input The input is given from Standard Input in the following format: X Output Print the earliest possible time for the kangaroo to reach coordinate X . Sample Input 1 6 Sample Output 1 3 The kangaroo can reach his nest at time 3 by jumping to the right three times, which is the earliest possible time. Sample Input 2 2 Sample Output 2 2 He can reach his nest at time 2 by staying at his position during the first second, and jumping to the right at the next second. Sample Input 3 11 Sample Output 3 5 | 35,648 |
Problem A: Sum of Consecutive Integers ããªãã¯æ°ãæã«æž¡ãåéšæŠäºãåã¡æãïŒæŽããŠICPC倧åŠã«å
¥åŠããããšãã§ããïŒå
¥åŠæç¶ãã®æ¥ïŒå€§åŠã®ãã£ã³ãã¹å
ã§ã¯ç±ççãªãµãŒã¯ã«ã®å§èªæŽ»åãè¡ãããŠããïŒããªãã¯å€§éã®ãã³ãã¬ãããåãåã£ãŠåž°ã£ãŠããïŒéšå±ã«æ»ã£ãŠããããªãã¯åãåã£ããã³ãã¬ããã®äžããæ°ã«ãªãäžæãèŠã€ããïŒãã®ãã³ãã¬ããã¯å€§åŠã®åºå ±éšããæž¡ããããã®ã ã£ãïŒ ãã³ãã¬ããã«ã¯ä»¥äžã®ãããªåé¡ãèšãããŠããïŒ åã N ãšãªããããªïŒé£ç¶ãã2ã€ä»¥äžã®æ£ã®æŽæ°ã®çµã¿åããã¯ïŒäœçµååšããã§ããããïŒäŸãã°ïŒ 9 㯠2+3+4 ãš 4+5 ã® 2éãã®çµã¿åããããããŸãïŒ ãã®åé¡ã®çããæ°ã«ãªã£ãããªãã¯ïŒããã°ã©ã ãæžããŠãã®çãã調ã¹ãããšã«ããïŒãããã£ãŠïŒããªãã®ä»äºã¯ïŒå
¥åãšããŠäžããããæ£ã®æŽæ° N ã«å¯ŸããŠïŒåé¡ã®çããåºåããããã°ã©ã ãæžãããšã§ããïŒ Input å
¥åã¯ããŒã¿ã»ããã®äžŠã³ã§ããïŒåããŒã¿ã»ããã¯ã²ãšã€ã®æŽæ° N ãããªãäžè¡ã§ããïŒããã§ 1 †N †1000 ã§ããïŒ å
¥åã®çµãã¯ïŒã²ãšã€ã®ãŒããããªãäžè¡ã§ç€ºãããïŒ Output åºåã¯ïŒå
¥åã®åããŒã¿ã»ããã®è¡šãæ£ã®æŽæ°ã«å¯Ÿããåé¡ã®çããïŒå
¥åããŒã¿ã»ããã®é åºéãã«äžŠã¹ããã®ã§ããïŒãã以å€ã®æåãåºåã«ãã£ãŠã¯ãªããªãïŒ Sample Input 9 500 0 Output for the Sample Input 2 3 | 35,649 |
Score : 300 points Problem Statement To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation: 1 yen (the currency of Japan) 6 yen, 6^2(=36) yen, 6^3(=216) yen, ... 9 yen, 9^2(=81) yen, 9^3(=729) yen, ... At least how many operations are required to withdraw exactly N yen in total? It is not allowed to re-deposit the money you withdrew. Constraints 1 \leq N \leq 100000 N is an integer. Input Input is given from Standard Input in the following format: N Output If at least x operations are required to withdraw exactly N yen in total, print x . Sample Input 1 127 Sample Output 1 4 By withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw 127 yen in four operations. Sample Input 2 3 Sample Output 2 3 By withdrawing 1 yen three times, we can withdraw 3 yen in three operations. Sample Input 3 44852 Sample Output 3 16 | 35,650 |
Problem J: Cubic Colonies In AD 3456, the earth is too small for hundreds of billions of people to live in peace. Interstellar Colonization Project with Cubes (ICPC) is a project that tries to move people on the earth to space colonies to ameliorate the problem. ICPC obtained funding from governments and manufactured space colonies very quickly and at low cost using prefabricated cubic blocks. The largest colony looks like a Rubik's cube. It consists of 3 à 3 à 3 cubic blocks (Figure J.1A). Smaller colonies miss some of the blocks in the largest colony. When we manufacture a colony with multiple cubic blocks, we begin with a single block. Then we iteratively glue a next block to existing blocks in a way that faces of them match exactly. Every pair of touched faces is glued. Figure J.1: Example of the largest colony and a smaller colony However, just before the first launch, we found a design flaw with the colonies. We need to add a cable to connect two points on the surface of each colony, but we cannot change the inside of the prefabricated blocks in a short time. Therefore we decided to attach a cable on the surface of each colony. If a part of the cable is not on the surface, it would be sheared off during the launch, so we have to put the whole cable on the surface. We would like to minimize the lengths of the cables due to budget constraints. The dashed line in Figure J.1B is such an example. Write a program that, given the shape of a colony and a pair of points on its surface, calculates the length of the shortest possible cable for that colony. Input The input contains a series of datasets. Each dataset describes a single colony and the pair of the points for the colony in the following format. x 1 y 1 z 1 x 2 y 2 z 2 b 0,0,0 b 1,0,0 b 2,0,0 b 0,1,0 b 1,1,0 b 2,1,0 b 0,2,0 b 1,2,0 b 2,2,0 b 0,0,1 b 1,0,1 b 2,0,1 b 0,1,1 b 1,1,1 b 2,1,1 b 0,2,1 b 1,2,1 b 2,2,1 b 0,0,2 b 1,0,2 b 2,0,2 b 0,1,2 b 1,1,2 b 2,1,2 b 0,2,2 b 1,2,2 b 2,2,2 ( x 1 , y 1 , z 1 ) and ( x 2 , y 2 , z 2 ) are the two distinct points on the surface of the colony, where x 1 , x 2 , y 1 , y 2 , z 1 , z 2 are integers that satisfy 0 †x 1 , x 2 , y 1 , y 2 , z 1 , z 2 †3. b i,j,k is ' # ' when there is a cubic block whose two diagonal vertices are ( i , j , k ) and ( i + 1, j + 1, k + 1), and b i,j,k is ' . ' if there is no block. Figure J.1A corresponds to the first dataset in the sample input, whereas Figure J.1B corresponds to the second. A cable can pass through a zero-width gap between two blocks if they are touching only on their vertices or edges. In Figure J.2A, which is the third dataset in the sample input, the shortest cable goes from the point A (0, 0, 2) to the point B (2, 2, 2), passing through (1, 1, 2), which is shared by six blocks. Similarly, in Figure J.2B (the fourth dataset in the sample input), the shortest cable goes through the gap between two blocks not glued directly. When two blocks share only a single vertex, you can put a cable through the vertex (Figure J.2C; the fifth dataset in the sample input). You can assume that there is no colony consisting of all 3 à 3 à 3 cubes but the center cube. Six zeros terminate the input. Figure J.2: Dashed lines are the shortest cables. Some blocks are shown partially transparent for illustration. Output For each dataset, output a line containing the length of the shortest cable that connects the two given points. We accept errors less than 0.0001. You can assume that given two points can be connected by a cable. Sample Input 0 0 0 3 3 3 ### ### ### ### ### ### ### ### ### 3 3 0 0 0 3 #.. ### ### ### ### ### #.# ### ### 0 0 2 2 2 2 ... ... ... .#. #.. ... ##. ##. ... 0 1 2 2 1 1 ... ... ... .#. #.. ... ##. ##. ... 3 2 0 2 3 2 ### ..# ... ..# ... .#. ..# ..# .## 0 0 0 0 0 0 Output for the Sample Input 6.70820393249936941515 6.47870866461907457534 2.82842712474619029095 2.23606797749978980505 2.82842712474619029095 | 35,651 |
åææ° Problem Statement æŽæ° n ã«æãè¿ãåææ°ãæ±ããïŒ ãªãïŒéè² æŽæ° x ãåææ°ã§ãããšã¯ïŒ x ãå鲿³ã§è¡šçŸããæååãšãããå転ãããæååãçããããšãããïŒ äŸãã°0,7,33,10301ãªã©ã¯åææ°ã§ããïŒ32,90,1010ãªã©ã¯åææ°ã§ãªãïŒ Input å
¥åã¯ä»¥äžã®åœ¢åŒã«åŸãïŒäžããããæ°ã¯å
šãп޿°ã§ããïŒ n Constraints 1âŠnâŠ10^4 Output n ã«æãè¿ãåææ°ãåºåããïŒ ãã®ãããªæ°ãè€æ°ããå Žåã¯æãå°ãããã®ãåºåããïŒ Sample Input 1 13 Output for the Sample Input 1 11 13ã«æãè¿ãåææ°ã¯11ã§ããïŒ Sample Input 2 7447 Output for the Sample Input 2 7447 7447ã¯åææ°ãªã®ã§ãã®ãŸãŸåºåããã°ããïŒ Sample Input 3 106 Output for the Sample Input 3 101 106ã«æãè¿ãåææ°ã¯111ãš101ã®ãµãã€ãããïŒãã®ãã¡å°ããæ¹ã®101ãåºåããïŒ | 35,652 |
Problem B: Left Hand Rule The left-hand rule, which is also known as the wall follower, is a well-known strategy that solves a two- dimensional maze. The strategy can be stated as follows: once you have entered the maze, walk around with keeping your left hand in contact with the wall until you reach the goal. In fact, it is proven that this strategy solves some kind of mazes. Your task is to write a program that determines whether the given maze is solvable by using the left-hand rule and (if the maze is solvable) the number of steps to reach the exit. Moving to a cell from the entrance or the adjacent (north, south, east or west) cell is counted as a step. In this problem, the maze is represented by a collection of walls placed on the two-dimensional grid. We use an ordinary Cartesian coordinate system; the positive x -axis points right and the positive y -axis points up. Each wall is represented by a line segment which is parallel to the x -axis or the y -axis, such that both ends of each wall are located on integer coordinates. The size of the maze is given by W and H that indicate the width and the height of the maze, respectively. A rectangle whose vertices are on (0, 0), ( W , 0), ( W , H ) and (0, H ) forms the outside boundary of the maze. The outside of the maze is always surrounded by walls except for the entrance of the maze. The entrance is represented by a line segment whose ends are ( x E , y E ) and ( x E ', y E '). The entrance has a unit length and is located somewhere on one edge of the boundary. The exit is a unit square whose bottom left corner is located on ( x X , y X ). A few examples of mazes are illustrated in the figure below. They correspond to the datasets in the sample input. Figure 1: Example Mazes (shaded squares indicate the exits) Input The input consists of multiple datasets. Each dataset is formatted as follows: W H N x 1 y 1 x 1 ' y 1 ' x 2 y 2 x 2 ' y 2 ' ... x N y N x N ' y N ' x E y E x E ' y E ' x X y X W and H (0 < W , H †100) indicate the size of the maze. N is the number of walls inside the maze. The next N lines give the positions of the walls, where ( x i , y i ) and ( x i ', y i ') denote two ends of each wall (1 †i †N ). The last line gives the positions of the entrance and the exit. You can assume that all the coordinates given in the input are integer coordinates and located inside the boundary of the maze. You can also assume that the wall description is not redundant, i.e. an endpoint of a wall is not shared by any other wall that is parallel to it. The input is terminated by a line with three zeros. Output For each dataset, print a line that contains the number of steps required to reach the exit. If the given maze is unsolvable, print â Impossible â instead of the number of steps. Sample Input 3 3 3 1 0 1 2 1 2 2 2 2 2 2 1 0 0 1 0 1 1 3 3 4 1 0 1 2 1 2 2 2 2 2 2 1 2 1 1 1 0 0 1 0 1 1 3 3 0 0 0 1 0 1 1 0 0 0 Output for the Sample Input 9 Impossible Impossible | 35,653 |
Score : 600 points Problem Statement There is a cave consisting of N rooms and M one-directional passages. The rooms are numbered 1 through N . Takahashi is now in Room 1 , and Room N has the exit. The i -th passage connects Room s_i and Room t_i ( s_i < t_i ) and can only be traversed in the direction from Room s_i to Room t_i . It is known that, for each room except Room N , there is at least one passage going from that room. Takahashi will escape from the cave. Each time he reaches a room (assume that he has reached Room 1 at the beginning), he will choose a passage uniformly at random from the ones going from that room and take that passage. Aoki, a friend of Takahashi's, can block one of the passages (or do nothing) before Takahashi leaves Room 1 . However, it is not allowed to block a passage so that Takahashi is potentially unable to reach Room N . Let E be the expected number of passages Takahashi takes before he reaches Room N . Find the value of E when Aoki makes a choice that minimizes E . Constraints 2 \leq N \leq 600 N-1 \leq M \leq \frac{N(N-1)}{2} s_i < t_i If i != j , (s_i, t_i) \neq (s_j, t_j) . (Added 21:23 JST) For every v = 1, 2, ..., N-1 , there exists i such that v = s_i . Input Input is given from Standard Input in the following format: N M s_1 t_1 : s_M t_M Output Print the value of E when Aoki makes a choice that minimizes E . Your output will be judged as correct when the absolute or relative error from the judge's output is at most 10^{-6} . Sample Input 1 4 6 1 4 2 3 1 3 1 2 3 4 2 4 Sample Output 1 1.5000000000 If Aoki blocks the passage from Room 1 to Room 2 , Takahashi will go along the path 1 â 3 â 4 with probability \frac{1}{2} and 1 â 4 with probability \frac{1}{2} . E = 1.5 here, and this is the minimum possible value of E . Sample Input 2 3 2 1 2 2 3 Sample Output 2 2.0000000000 Blocking any one passage makes Takahashi unable to reach Room N , so Aoki cannot block a passage. Sample Input 3 10 33 3 7 5 10 8 9 1 10 4 6 2 5 1 7 6 10 1 4 1 3 8 10 1 5 2 6 6 9 5 6 5 8 3 6 4 8 2 7 2 9 6 7 1 2 5 9 6 8 9 10 3 9 7 8 4 5 2 10 5 7 3 5 4 7 4 9 Sample Output 3 3.0133333333 | 35,654 |
Score : 200 points Problem Statement Snuke loves working out. He is now exercising N times. Before he starts exercising, his power is 1 . After he exercises for the i -th time, his power gets multiplied by i . Find Snuke's power after he exercises N times. Since the answer can be extremely large, print the answer modulo 10^{9}+7 . Constraints 1 †N †10^{5} Input The input is given from Standard Input in the following format: N Output Print the answer modulo 10^{9}+7 . Sample Input 1 3 Sample Output 1 6 After Snuke exercises for the first time, his power gets multiplied by 1 and becomes 1 . After Snuke exercises for the second time, his power gets multiplied by 2 and becomes 2 . After Snuke exercises for the third time, his power gets multiplied by 3 and becomes 6 . Sample Input 2 10 Sample Output 2 3628800 Sample Input 3 100000 Sample Output 3 457992974 Print the answer modulo 10^{9}+7 . | 35,655 |
Circumscribed Circle of A Triangle. Write a program which prints the central coordinate $(p_x, p_y)$ and the radius $r$ of a circumscribed circle of a triangle which is constructed by three points $(x_1, y_1)$, $(x_2, y_2)$ and $(x_3, y_3)$ on the plane surface. Input Input consists of several datasets. In the first line, the number of datasets $n$ is given. Each dataset consists of: $x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ in a line. All the input are real numbers. Output For each dataset, print $p_x$, $p_y$ and $r$ separated by a space in a line. Print the solution to three places of decimals. Round off the solution to three decimal places. Constraints $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3 \leq 100$ $ n \leq 20$ Sample Input 1 0.0 0.0 2.0 0.0 2.0 2.0 Output for the Sample Input 1.000 1.000 1.414 | 35,656 |
æé·ã®é段 åé¡ 1 ãã n ãŸã§ã®æŽæ°ããããã 1 ã€ãã€æžããã n æã®ã«ãŒããš,1 æã®çœçŽã® ã«ãŒãããã.ããã n + 1 æã®ã«ãŒãã®å
, k æã®ã«ãŒããäžãããã.ãã ã, 1 †k †n ã§ãã.çœçŽã®ã«ãŒãã«ã¯ 1 ãã n ãŸã§ã®æŽæ°ã 1 ã€æžãããšãã§ã ã.äžããããã«ãŒãã ãã§,ã§ããã ãé·ãé£ç¶ããæŽæ°åãäœããã. äžããããã«ãŒããå
¥åããããšãã«, äžããããã«ãŒãããäœãããšãã§ããé£ ç¶ããæŽæ°åã®æå€§é·ãåºåããããã°ã©ã ãäœæãã. äŸ1 n = 7, k = 5 ãšãã.6, 2, 4, 7, 1 ã®ã«ãŒããäžãããããšã,ãã®ã«ãŒãã䜿㣠ãŠäœããé£ç¶ããæŽæ°åã®ãã¡æé·ã®ãã®ã¯ 1, 2 ã§ãã,ãã®é·ã㯠2 ã§ãã. äŸ2 n = 7, k = 5 ãšãã.6, 2, 4, 7 ãšçœçŽã®ã«ãŒããäžãããããšã,ãã®ã«ãŒãã 䜿ã£ãŠäœããé£ç¶ããæŽæ°åã®ãã¡æé·ã®ãã®ã¯,çœçŽã®ã«ãŒãã« 5 ãæžãããšã« ãã£ãŠã§ãã 4, 5, 6, 7 ã§ãã,ãã®é·ã㯠4 ã§ãã. å
¥å å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããïŒå
¥åã¯ãŒãïŒã€ãå«ãè¡ã§çµäºããïŒ 1 è¡ç®ã«ã¯,2 ã€ã®æŽæ° n (1 †n †100000) ãš k (1 †k †n ) ããã®é ã§ 1 ã€ã® 空çœãåºåããšããŠæžãããŠãã.ç¶ã k è¡ã«ã¯æŽæ°ã 1 ã€ãã€æžãããŠãã,äž ãããã k æã®ã«ãŒãã«æžãããŠããæŽæ°ã衚ããŠãã.çœçŽã®ã«ãŒã㯠0 ã§è¡šã ãã. æ¡ç¹çšããŒã¿ã®ãã¡, é
ç¹ã® 40% å㯠1 †n †1000, 1 †k †500 ã, é
ç¹ã® 20% å㯠1 †n †60000, 1 †k †50000 ã. é
ç¹ã® 40% å㯠1 †n †100000, 1 †k †100000 ãæºãã. ããŒã¿ã»ããã®æ°ã¯ 5 ãè¶
ããªãïŒ åºå ããŒã¿ã»ããããšã«æŽæ°ã1è¡ã«åºåããïŒ å
¥åºåäŸ å
¥åäŸ 7 5 6 2 4 7 1 7 5 6 2 0 4 7 0 0 åºåäŸ 2 4 äžèšå顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã | 35,657 |
F: éšåæåååè§£ åé¡ 2 ã€ã®æåå S ãš T ããã³æŽæ° k ãäžããããã T ã®é·ã k 以äžã®é£ç¶ããéšåæååãèãããšãããããã®é£çµã§ S ãæ§æã§ãããå€å®ããã ããã§æåå s = s_1 s_2 ... s_n ã®é£ç¶ããéšåæåå s[l, r] = s_l s_{l+1} ... s_r (1 \leq l \leq r \leq n) ãšã¯ã s ã® l æåç®ãã r æåç®ãŸã§ãåãåºããŠã§ããæååãæãããã®é·ã㯠r - l + 1 ã§ããã å
¥ååœ¢åŒ S T k å¶çŽ S ãš T ã¯å°æåã¢ã«ãã¡ããããããªã 1 \leq |S|, |T| \leq 2\times 10^5 1 \leq k \leq |T| åºååœ¢åŒ S ãæ§æã§ãããšã Yes ããããã§ãªããšã No ãäžè¡ã«åºåããã å
¥åäŸ1 abracadabra cadabra 4 åºåäŸ1 Yes T ã®é·ã 4 以äžã®éšåæååã§ãã abra ãš cadabra ãé£çµãããããšã§ abracadabra ãæ§æã§ãããã㯠S ãšçããæååã§ããã å
¥åäŸ2 abcd zcba 1 åºåäŸ2 No å
¥åäŸ3 abc zcba 1 åºåäŸ3 Yes å
¥åäŸ4 abcdefg abcddefg 4 åºåäŸ4 No | 35,658 |
Score : 100 points Problem Statement There is a right triangle ABC with â ABC=90° . Given the lengths of the three sides, |AB|,|BC| and |CA| , find the area of the right triangle ABC . It is guaranteed that the area of the triangle ABC is an integer. Constraints 1 \leq |AB|,|BC|,|CA| \leq 100 All values in input are integers. The area of the triangle ABC is an integer. Input Input is given from Standard Input in the following format: |AB| |BC| |CA| Output Print the area of the triangle ABC . Sample Input 1 3 4 5 Sample Output 1 6 This triangle has an area of 6 . Sample Input 2 5 12 13 Sample Output 2 30 This triangle has an area of 30 . Sample Input 3 45 28 53 Sample Output 3 630 This triangle has an area of 630 . | 35,659 |
Problem H: Ramen Shop Ron is a master of a ramen shop. Recently, he has noticed some customers wait for a long time. This has been caused by lack of seats during lunch time. Customers loses their satisfaction if they waits for a long time, and even some of them will give up waiting and go away. For this reason, he has decided to increase seats in his shop. To determine how many seats are appropriate, he has asked you, an excellent programmer, to write a simulator of customer behavior. Customers come to his shop in groups, each of which is associated with the following four parameters: T i : when the group comes to the shop P i : number of customers W i : how long the group can wait for their seats E i : how long the group takes for eating The i -th group comes to the shop with P i customers together at the time T i . If P i successive seats are available at that time, the group takes their seats immediately. Otherwise, they waits for such seats being available. When the group fails to take their seats within the time W i (inclusive) from their coming and strictly before the closing time, they give up waiting and go away. In addition, if there are other groups waiting, the new group cannot take their seats until the earlier groups are taking seats or going away. The shop has N counters numbered uniquely from 1 to N . The i -th counter has C i seats. The group prefers âseats with a greater distance to the nearest group.â Precisely, the group takes their seats according to the criteria listed below. Here, S L denotes the number of successive empty seats on the left side of the group after their seating, and S R the number on the right side. S L and S R are considered to be infinity if there are no other customers on the left side and on the right side respectively. Prefers seats maximizing min{ S L , S R }. If there are multiple alternatives meeting the first criterion, prefers seats maximizing max{ S L , S R }. If there are still multiple alternatives, prefers the counter of the smallest number. If there are still multiple alternatives, prefers the leftmost seats. When multiple groups are leaving the shop at the same time and some other group is waiting for available seats, seat assignment for the waiting group should be made after all the finished groups leave the shop. Your task is to calculate the average satisfaction over customers. The satisfaction of a customer in the i -th group is given as follows: If the group goes away without eating, -1. Otherwise, ( W i - t i )/ W i where t i is the actual waiting time for the i -th group (the value ranges between 0 to 1 inclusive). Input The input consists of multiple datasets. Each dataset has the following format: N M T C 1 C 2 ... C N T 1 P 1 W 1 E 1 T 2 P 2 W 2 E 2 ... T M P M W M E M N indicates the number of counters, M indicates the number of groups and T indicates the closing time. The shop always opens at the time 0. All input values are integers. You can assume that 1 †N †100, 1 †M †10000, 1 †T †10 9 , 1 †C i †100, 0 †T 1 < T 2 < ... < T M < T , 1 †P i †max C i , 1 †W i †10 9 and 1 †E i †10 9 . The input is terminated by a line with three zeros. This is not part of any datasets. Output For each dataset, output the average satisfaction over all customers in a line. Each output value may be printed with an arbitrary number of fractional digits, but may not contain an absolute error greater than 10 -9 . Sample Input 1 4 100 7 10 1 50 50 15 2 50 50 25 1 50 50 35 3 50 50 1 2 100 5 30 3 20 50 40 4 40 50 1 2 100 5 49 3 20 50 60 4 50 30 1 2 100 5 50 3 20 50 60 4 50 30 2 3 100 4 2 10 4 20 20 30 2 20 20 40 4 20 20 0 0 0 Output for the Sample Input 0.7428571428571429 0.4285714285714285 0.5542857142857143 -0.1428571428571428 0.8000000000000000 | 35,660 |
Memory Leak Time Limit: 8 sec / Memory Limit: 64 MB D: ã¡ã¢ãªãŒãªãŒã¯ ããªãã®ç 究宀ã®åæã, å®è£
äžã®ãœãããŠã§ã¢ã®ãã°ã«æ©ãŸãããŠãã. 圌ã®ãœãããŠã§ã¢ã¯, ããªãäžäœã®ã¬ã€ã€ã§åäœãããœãããŠã§ã¢ã§ãããã, 髿©èœã®ãããã¬ããã¹ãããŒã«ãªã©ã¯äœ¿çšããããšãã§ããªã. OS ã«ããè£å©ããªãç°å¢ã§ãããã, èšèªäžäœ¿ããã¯ãã®äŸå€åŠçãªã©äœ¿ããªãã, æšæºã©ã€ãã©ãªã§ãã倧åã®ãã®ã䜿çšã§ããªã. ã¬ããŒãžã³ã¬ã¯ã¿ãªããŠå€¢ã®ãŸã倢ã§ãã. ãã®ãã圌ã¯, ãããŸã§ãã©ã€ã¢ã«ã¢ã³ããšã©ãŒã«ãã£ãŠèªåã§æ€èšŒãè¡ã, ä¿®æ£ãè¡ã£ãŠãã. ããã, ä»åã®ãã°ã¯çžåœæ ¹ãæ·±ãããã, 圌ã¯ããäžã¶æè¿ãã«æž¡ãæ€èšŒãç¹°ãè¿ããŠãã. ç· åãŸã§ã«ãã®ãã°ãä¿®æ£ã§ããªãã£ããã, 圌ã¯è«ææåºãèŠéã£ãŠãã. å€äžã®ç 究宀ã«ã¯, æç¶çã«åœŒã®å¥å£°ãèãããŠããå§æ«ã§ãã. èŠå
Œããããªãã¯, 圌ã®ãœãããŠã§ã¢ã®æ€èšŒãæäŒãããšã«ãã. ãããŸã§ã®åœŒã®ããã°ãã«ãã£ãŠ, ããã°ã©ã ã§ã¯ããããã¡ã¢ãªãªãŒã¯ãçºçããŠããå¯èœæ§ãé«ãããã. ã©ãããããã°ã©ã ã®ã©ããã§, 確ä¿ããã¡ã¢ãªãè§£æŸãå¿ããŠããããšãåå ã§, 䜿çšã§ããã¡ã¢ãªã䜿ãæãããŠããŸã£ãŠããããã§ãã. 圌ã®ããã°ã©ã ã¯ãã®ãŸãŸã§ã¯è€éãããã®ã§, 圌ã¯ã¡ã¢ãªã®ç¢ºä¿ãè§£æŸãè¡ãåŠçãç°¡åã«è¡šçŸã, ãã¿ãŒã³åãããã®ãçšæããŠããã. ãã®ãã¿ãŒã³ããšã«ã©ã®çšåºŠã¡ã¢ãªãªãŒã¯ãçºçãããã調ã¹ãŠæ¬²ãããšã®ããšã§ãã. ãŸãåæãšããŠ, 圌ã®ããã°ã©ã ã§ã¯, ã¡ã¢ãªãããŒãžã£ãšããã¢ãžã¥ãŒã«ã«ãã£ãŠ, ã¡ã¢ãªé åã®ç¢ºä¿ãè§£æŸãšãã£ãæ©èœãæäŸãããŠããããã. ã¡ã¢ãªé åã確ä¿ãããšã¯, æ£ç¢ºã«ã¯ã¡ã¢ãªãããŒãžã£ã管çããããŒããšåŒã°ããã¡ã¢ãªé åãã, å¿
èŠãªåãåãåã, ãã®é åãžã®ãåç
§ããåŸãããšã§ãã. ãªã, ããŒãã«ã¯äžéããã, ããã°ã©ã ãããã以äžã®ã¡ã¢ãªã¯å©çšã§ããªã. ã¡ã¢ãªé åã®å€§ããã«ã¯ããã€ãããçšãããã. ãåç
§ããšã¯, ãã®é åãååšããå Žæã瀺ãå€ã§ãã. åç
§ã¯, 倿°ã«ä»£å
¥ããã, çŽæ¥å¥ã®ã¡ã¢ãªé åã®ç¢ºä¿ãè§£æŸã®æ©èœãžæž¡ãåŒæ°ãšããŠå©çšããããšãã§ãã. ã¡ã¢ãªé åãè§£æŸãããšã¯, 䜿ããªããªã£ãã¡ã¢ãªé åãã¡ã¢ãªãããŒãžã£ã«è¿åŽããããšã§ãã. ãããŠ, 圌ã®çšæãããã¿ãŒã³ã¯ä»¥äžã® BNF ã§è¡šçŸã§ãããã®ã§ãã£ã. <line> ::= <expr> | <free> <expr> ::= "(" <expr> ")" | <assign> | "NULL" | <variable> | <malloc> | <clone> <assign> ::= <variable> "=" <expr> <malloc> ::= "malloc(" <number> ")" <free> ::= "free(" <expr> ")" <clone> ::= "clone(" <expr> ")" <variable> ::= "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z" <number> ::= <non_zero_digit> | <number> <digit> <non_zero_digit> ::= "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" <digit> ::= "0" | <non_zero_digit> 倿°(variables)ã¯, åç
§ã®å
¥ãç©ãšãŠæ©èœã, ååãšããŠã¢ã«ãã¡ãããã®å€§æåäžæåã䜿çšã§ãã. 倿°ã¯, ä»ååé¡ãšãªãããŒããšã¯å¥ã®é åã«ç¢ºä¿ããããã, 倿°ãã®ãã®ã䜿çšããã¡ã¢ãªéãæ°ã«ããå¿
èŠã¯ãªã. ãªã, 倿°ã¯æç€ºçã«å€ã代å
¥ãããªãéã, æŽæ°ãããªã. ãŸã, åæå€ã¯ç¹ã«æ±ºãŸã£ãŠããã, ã©ã®ãããªå€ãæã£ãŠãããããããªãããšã«æ³šæããªããã°ãªããªã. ãªã, 倿°ã¯è©äŸ¡çµæãšããŠ, ãã®å€æ°ã®æã€åç
§ãè¿ã. 代å
¥(assign)ã¯, åç
§ã®å€ãã³ããŒãã. å³èŸºã®åŒãè©äŸ¡ããŠåŸãããåç
§ã巊蟺ã®å€æ°ã«ã³ããŒãã. åæåãããŠããªã倿°ã free ããã倿°ã代å
¥ããããšãã§ãã. ããã¯, åç
§ãšã¯é åã®å Žæã瀺ããå€ãã§ãããªããã, å¥ã®å€æ°ã«ä»£å
¥ããŠã, å®éã«æå³ããªãé åãæäœããŠããŸãããšã¯ãªã. ãªã, 代å
¥ãã®ãã®ã¯, 倿°ã«ä»£å
¥ãããåç
§ãè¿ã. malloc, free, clone ã¯, ã¡ã¢ãªãããŒãžã£ã®æ©èœãåŒã³åºãŠããããšã瀺ããŠãã. malloc ã¯, åŒæ°ã§æž¡ããã1以äžã®æŽæ°ãµã€ãºåã®ã¡ã¢ãªé åã確ä¿ã, ãã®é åãžã®åç
§ãè¿ã. free ã¯, åŒæ°ã«ç¢ºä¿æžã¿ã®ã¡ã¢ãªé åãžã®åç
§ãäžããããšã§, ãã®é åãè§£æŸãã. ãªã, è©äŸ¡ããŠãäœãè¿ããªã. clone ã¯, åŒæ°ã«ç¢ºä¿æžã¿ã®ã¡ã¢ãªé åãžã®åç
§ãäžããããšã§, ãã®é åãã³ããŒãã. ä»åã®æ€èšŒã§ã¯åããµã€ãºåã®é åãããäžã€ç¢ºä¿ãããšèããã°ãã. ãªã, malloc ã clone ã®ã¡ã¢ãªç¢ºä¿ã®ã¢ã«ãŽãªãºã èªäœã¯ç²Ÿé¬ãããŠãããã, å²ãåœãŠçšã®ã¡ã¢ãªé åãæçåããããšã¯ãªã. ãŸã, free ããé åã¯å³åº§ã«è§£æŸãã, åå©çšå¯èœã«ãªã. ãã ã, åæåãããŠããªãé åãæ¢ã« free ãããé åã«å¯Ÿã㊠clone ã free ããå Žå, æå³ããªãã¡ã¢ãªé åã«å¯ŸããŠã³ããŒãè§£æŸãè¡ãªãããŠããŸã, äœãèµ·ãããããããªã. ãã®ãããªåäœã¯, å¥ã®ãã°ã®åå ãšãªã£ãŠããå¯èœæ§ããããã, 圌ã«ç¥ãããå¿
èŠããã. äžããããã¡ã¢ãªã®äžéè¶
ã㊠malloc ããããšããå Žåã«ã¯, NULL ãšããç¹æ®ãªåç
§ãè¿ããã. åæ§ã« clone ã§ã³ããŒãããé ååã®ã¡ã¢ãªãæ®ã£ãŠããªãå Žåã«ã, NULL ãè¿ããã. ãã® NULL ã¯ç¹å®ã®ã¡ã¢ãªé åãåç
§ããŠããªãããšã瀺ã. éåžžã®åç
§ãšåæ§ã« NULL ã¯å€æ°ã«ä»£å
¥ã§ã, åç
§ãåŒæ°ã«ãšã clone ã free ã«æž¡ãããšãã§ãã. ãã ã, free ã« NULL ãåŒæ°ã§æž¡ããŠããå Žå, äœãèµ·ãããªãããšãä¿èšŒãããŠãã. ãŸã, clone ã« NULL ãåŒæ°ã§æž¡ããå Žåã§ã, äœãèµ·ããã, NULL ãè¿ããã. è©äŸ¡ãããšåç
§ãè¿ãåŒ(expr)ã¯, "(" ")" ã䜿ãããšã§å
¥ãåã«ããããšãã§ãã. ãã®å Žå, "(" ")"ã®å
éšã®è©äŸ¡çµæããã®å€åŽãžè¿ãããããšã«ãªã. ãªã, free ã¯åç
§ãè¿ããªãã®ã§, å
¥ãåã«ããããšãã§ããªã. ããªãã®ä»äºã¯, ãã¿ãŒã³ãšããŠäžããããå
šãŠã®è¡ãå®è¡ããåŸã«, åç
§ãããŠããªãç¢ºä¿æžã¿ã®ã¡ã¢ãªé åã®ãã€ãæ°ã®åèšãèšç®ããããšã§ãã. ãªã, äžããããå
šãŠã®è¡ãå®è¡ããåŸã«, äžã€ä»¥äžã®å€æ°ãåç
§ãæã£ãŠããé åã«ã€ããŠã¯æ°ã«ããªããŠãã. ãŸã, å¥ã®ãã°ã®åå ãçºèŠããå Žåã«ã¯, 圌ã«ç¥ãããªããã°ãªããªã. ããªãã¯, ãã¿ãŒã³ã®åæãããããã®ããã°ã©ã ãçµãããšãã. ãã®ããã«, 圌ã®ç€ºãããã€ãã®ãã¿ãŒã³ã«ã€ããŠèå¯ãã. å³1 å³1ã¯, ããŒãã 100 ãã€ãååšããç¶æ
ã§, 以äžã®ãããªãã¿ãŒã³ãå®è¡ãããšãã®ç¶æ
ã®é·ç§»ã瀺ããŠãã A=malloc(10) B=clone(A) free(A) ãŸã, 1è¡ç®ã§ã¯, malloc ã«ãã£ãŠ 10 ãã€ãã®é åã確ä¿ã, ãã®é åãžã®åç
§ã倿° A ã«ä»£å
¥ããŠãã. æ®ãã®äœ¿çšå¯èœãªããŒãã¯, 90 ãã€ããšãªã 次ã«, 2è¡ç®ã§ã¯, å
ã»ã©ç¢ºä¿ããé åãžã®åç
§ãæã€å€æ° A ã clone ã«æž¡ããŠãã. ããã«ãã, æ°ãã«10ãã€ãã®é åã確ä¿ãã, æ®ãã®äœ¿çšå¯èœãªããŒãã¯, 80 ãã€ããšãªã. æ°ãã«ç¢ºä¿ããã 10 ãã€ãã®é åãžã®åç
§ã¯, 倿° B ã«ä»£å
¥ããã. ãããŠ, 3è¡ç®ã§ã¯, 1è¡ç®ã§ç¢ºä¿ãããé åãžã®åç
§ãæã€å€æ° A ã free ã«æž¡ããŠãã. ããã«ãã, 10ãã€ãã®é åãè§£æŸãã, æ®ãã®äœ¿çšå¯èœãªããŒãã¯, 90 ãã€ããšãªã. 以äžã§, ãã®ãã¿ãŒã³ã®å®è¡ã¯çµäºã§ãã. ãã®å Žåã§ã¯, åç
§ãããŠããªãç¢ºä¿æžã¿ã®é åã¯ååšããªããã, æ€èšŒã®çµæã¯ 0 ãã€ããšãªã. 2è¡ç®ã§ç¢ºä¿ããã 10 ãã€ãã®é åã¯, 倿° B ãåç
§ãæã£ãŠãããã, ã¡ã¢ãªãªãŒã¯ãšããŠæ±ããªã. ãŸã, 倿° A ã¯3è¡ç®ã§ free ã«æž¡ãããåŸ, 代å
¥ã«ãã£ãп޿°ãããŠããªã. ãã®ãã, ãã®æç¹ã§ãå
ã»ã©è§£æŸãããé åãžã®åç
§ãæã£ããŸãŸã§ãã. ãããã®åŸã«, ãã®é åã free ããã㯠clone ãããããªåœä»€ããã£ãå Žåã¯, æ€èšŒçµæãšã㊠Error ãåºåããå¿
èŠããã. å³2 å³2ã¯, ããŒãã100ååšããç¶æ
ã§, 以äžã®ãããªãã¿ãŒã³ãå®è¡ãããšãã®ç¶æ
ã®é·ç§»ã瀺ããŠãã A=clone(clone(malloc(10))) ãã®å Žåã¯, ãŸã malloc(10) ãå®è¡ãã, 10ãã€ãã®é åã確ä¿ããã. ãã®é åãžã®åç
§ã¯ãã®ãŸãŸ clone ã«æž¡ãã, ããã« 10ãã€ãã®é åã確ä¿ããã. ãã® clone ã«ãã£ãŠç¢ºä¿ãããé åãå€åŽã® clone ã«æž¡ãã, ããã«10ãã€ãã®é åã確ä¿ããã. æåŸã«ç¢ºä¿ãããé åãžã®åç
§ã倿° A ã«ä»£å
¥ããã. æåã® malloc ã§ç¢ºä¿ãããé åãå
åŽã® clone ã§ç¢ºä¿ãããé åã¯, ã©ã®å€æ°ãåç
§ãæã£ãŠããã, è§£æŸããããšãã§ããªããªã£ãŠããŸã. ãã£ãŠ, ãã®ãã¿ãŒã³ã®æ€èšŒçµæã¯ 20 ãã€ããšãªã. Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ M line 1 line 2 line 3 ... line i ... å
¥åã®åœ¢åŒã§çšãããã倿°ã®æå³ã¯æ¬¡ã®éãã§ããïŒ 1è¡ç®ã® M ã¯ããŒãã®äžéã§ãã, 0 <= M <= 5000 ã§ãã. line i ã¯åè¿° BNF ã§ç€ºãããåŒã§ãã, EOF ãŸã§ç¶ãïŒ100è¡ãè¶
ããªãïŒ line i 㯠300 æåãè¶
ããªããšãã malloc ã«åŒæ°ãšããŠäžããããã¡ã¢ãªé åã®å€§ãã size 㯠1 <= size <= 5000 ã§ãã. Output å
¥åã§äžããããå
šãŠã®è¡ãå®è¡ããåŸã«, åç
§ãããŠããªãç¢ºä¿æžã¿ã®ã¡ã¢ãªé åã®ãã€ãæ°ã®åèšãåºåãã. ã¡ã¢ãªãªãŒã¯ä»¥å€ã®ãšã©ãŒãçºçããŠããå Žåã«ã¯, "Error" ãšåºåãã. Sample Input 1 100 A=malloc(10) B=clone(A) free(A) Sample Output 1 0 Sample Input 2 100 A=clone(clone(malloc(10))) Sample Output 2 20 Sample Input 3 30 clone(clone(clone(clone(malloc(10))))) Sample Output 3 30 Sample Input 4 100 free(A) A=malloc(12) NULL N=clone(NULL) Sample Output 4 Error | 35,661 |
Score : 800 points Problem Statement Snuke Festival 2017 will be held in a tree with N vertices numbered 1,2, ...,N . The i -th edge connects Vertex a_i and b_i , and has joyfulness c_i . The staff is Snuke and N-1 black cats. Snuke will set up the headquarters in some vertex, and from there he will deploy a cat to each of the other N-1 vertices. For each vertex, calculate the niceness when the headquarters are set up in that vertex. The niceness when the headquarters are set up in Vertex i is calculated as follows: Let X=0 . For each integer j between 1 and N (inclusive) except i , do the following: Add c to X , where c is the smallest joyfulness of an edge on the path from Vertex i to Vertex j . The niceness is the final value of X . Constraints 1 \leq N \leq 10^{5} 1 \leq a_i,b_i \leq N 1 \leq c_i \leq 10^{9} The given graph is a tree. All input values are integers. Partial Scores In the test set worth 200 points, N \leq 1000 . In the test set worth 200 points, c_i \leq 2 . Input Input is given from Standard Input in the following format: N a_1 b_1 c_1 : a_{N-1} b_{N-1} c_{N-1} Output Print N lines. The i -th line must contain the niceness when the headquarters are set up in Vertex i . Sample Input 1 3 1 2 10 2 3 20 Sample Output 1 20 30 30 The figure below shows the case when headquarters are set up in each of the vertices 1 , 2 and 3 . The number on top of an edge denotes the joyfulness of the edge, and the number below an vertex denotes the smallest joyfulness of an edge on the path from the headquarters to that vertex. Sample Input 2 15 6 3 2 13 3 1 1 13 2 7 1 2 8 1 1 2 8 2 2 12 2 5 2 2 2 11 2 10 2 2 10 9 1 9 14 2 4 14 1 11 15 2 Sample Output 2 16 20 15 14 20 15 16 20 15 20 20 20 16 15 20 Sample Input 3 19 19 14 48 11 19 23 17 14 30 7 11 15 2 19 15 2 18 21 19 10 43 12 11 25 3 11 4 5 19 50 4 11 19 9 12 29 14 13 3 14 6 12 14 15 14 5 1 6 8 18 13 7 16 14 Sample Output 3 103 237 71 263 370 193 231 207 299 358 295 299 54 368 220 220 319 237 370 | 35,662 |
I - 宿¢ã å顿 ãããã¯ãã宿¢ãã®äŸé ŒãåããïŒ ã©ãããïŒãã®è¿ãã®å°äž 2W à 2H ã®ç¯å²å
ã«ãå®ãåãŸã£ãŠãããããïŒ ãããã®åŸæãªããŠãžã³ã°ã䜿ãã°ïŒçŸåšã®äœçœ®ãããå®ãã©ã®æ¹åã«ããã£ãŠããã®ãç¥ãããšãã§ããïŒ ãã ïŒãããã®èœåã¯ãã®æ¥ã®äœèª¿ã«ãã圱é¿ã倧ããïŒä»æ¥ã¯ããŠãžã³ã°ãããæã«æå€§ã§ E 床ãŸã§èª€å·®ãåºãŠããŸãããã ïŒ ãŸãïŒãããã®äœåã«ãéçã¯ããïŒ1æ¥ã«200åãŸã§ããããŠãžã³ã°ãè¡ãããšã¯ã§ããªãïŒ ãããã¯èããããšã¯èŠæã ïŒ ããªãã«ã¯ïŒå®ãèŠã€ããããã«ã©ãã§ããŠãžã³ã°ãããã¹ããã®æç€ºãåºããŠããã ãããïŒ å
¥åºååœ¢åŒ æåã®å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒå
¥åã¯å
šãŠå°æ°12æ¡ãŸã§ã®å®æ°ã§äžããããïŒ W H E ãã®å
¥åã¯ïŒå®ã®åãŸã£ãŠããåº§æš (x,y) ãïŒ -W †x †W -H †y †H ãæºããïŒãŸãããŠãžã³ã°ã®çµæã®èª€å·®ã E 床以äžã§ããããšã衚ãïŒ ä»¥éïŒããªãã¯ããŠãžã³ã°ãè¡ãå Žæãæå®ãçµæãåŸããïŒãããã¯ïŒå®ã®å Žæã確å®ãããšäŒããããšãã§ããïŒ å°ç¹ (x,y) ã§ããŠãžã³ã°ãè¡ãïŒçµæãåŸãã«ã¯ printf("? %.12f %.12f\n", x, y); fflush(stdout); ãšããïŒæ¬¡ã«ïŒ scanf("%lf", °ree); ãšãããšããŠãžã³ã°ã®çµæãåŸãããïŒ çµæã®è§åºŠ degree ã¯ïŒ (x,y) ããå®ã®ããæ¹åã Ξ ãšããæïŒ [Ξ-E,Ξ+E] ã®äžæ§ååžã«ãã£ãŠçæãããïŒ å®ã®ããå°ç¹ã§ããŠãžã³ã°ãè¡ã£ãå ŽåïŒ Îž=0 ãšãªãïŒ è§åºŠã¯xè»žæ£æ¹åã0床ïŒyè»žæ£æ¹åã+90床ãšããïŒ ãã -180 †degree †180 ãæºãããŠãªãå ŽåïŒãã®ç¯å²ã«åãŸãæ§ã« degree ã¯ä¿®æ£ãããïŒ å°ç¹ (x,y) ã«å®ãååšãããšäŒããå Žåã«ã¯ printf("! %.12f %.12f\n", x, y); fflush(stdout); ãšããïŒ ãã®ãšãïŒå®éã®å®ã®äœçœ®ãšã®çµ¶å¯Ÿèª€å·®ã L â ãã«ã ã§ 0.5 以äžã«ãªã£ãŠããªããã°ãªããªãïŒ ãªãïŒããŠãžã³ã°ãå®ã®äœçœ®ã®æå®ä»¥å€ã®åºåãè¡ã£ãå Žåã¯èª€ç( Wrong Answer )ãšå€å®ãããïŒ å¶çŽ 0 †W †10 4 0 †H †10 4 0 †E †120 å
¥åå€ã¯å
šãŠå°æ°12æ¡ãŸã§ã®å®æ°ã§ããïŒ ããŠãžã³ã°ã¯æå€§ã§ 200 åãŸã§è¡ããïŒãããè¶ãããšèª€ç ãšãªãïŒ ãã®åé¡ã®å€å®ã«ã¯ïŒ3 ç¹åã®ãã¹ãã±ãŒã¹ã®ã°ã«ãŒããèšå®ãããŠããïŒãã®ã°ã«ãŒãã«å«ãŸãããã¹ãã±ãŒã¹ã¯äžèšã®å¶çŽã«å ããŠäžèšã®å¶çŽãæºããïŒ E = 0 å
¥åºåäŸ ããã°ã©ã ã®åºå ããã°ã©ã ãžã®å
¥å 100 100 0 ? -97.30147375 -55.03559390 45.8958081317 ? 44.46472896 -54.50272726 110.928234444 ... ... ! 4.50000018 50.00000005 æåã«ããã°ã©ã ã¯å®ã®ããç¯å² W,H ãšããŠãžã³ã°ã®ç²ŸåºŠ E ãåãåãïŒ ãã®åŸïŒããã°ã©ã 㯠(-97.3, -55.0) ã§1åç®ã®ããŠãžã³ã°ãè¡ãïŒå®ã®ããæ¹å㯠45.8 åºŠã®æ¹åã ãšããæ
å ±ãåŸãŠããïŒ æ¬¡ã«ïŒããã°ã©ã 㯠(44.5, -54.5) ã§2åç®ã®ããŠãžã³ã°ãè¡ãïŒå®ã®ããæ¹å㯠110.9 åºŠã®æ¹åã ãšããæ
å ±ãåŸãŠããïŒ ãã®åŸäœåºŠãããŠãžã³ã°ãè¡ãïŒæçµçã«å®ã®ããäœçœ®ã¯ (4.5, 50.0) ã§ãããšåºåããŠããïŒ Writer : æ£®æ§æïŒæ¥ æ¬å
ïŒè±ç°è£äžæ | 35,663 |
Hierarchical Democracy The presidential election in Republic of Democratia is carried out through multiple stages as follows. There are exactly two presidential candidates. At the first stage, eligible voters go to the polls of his/her electoral district. The winner of the district is the candidate who takes a majority of the votes. Voters cast their ballots only at this first stage. A district of the k -th stage ( k > 1) consists of multiple districts of the ( k â 1)-th stage. In contrast, a district of the ( k â 1)-th stage is a sub-district of one and only one district of the k -th stage. The winner of a district of the k -th stage is the candidate who wins in a majority of its sub-districts of the ( k â 1)-th stage. The final stage has just one nation-wide district. The winner of the final stage is chosen as the president. You can assume the following about the presidential election of this country. Every eligible voter casts a vote. The number of the eligible voters of each electoral district of the first stage is odd. The number of the sub-districts of the ( k â 1)-th stage that constitute a district of the k -th stage ( k > 1) is also odd. This means that each district of every stage has its winner (there is no tie). Your mission is to write a program that finds a way to win the presidential election with the minimum number of votes. Suppose, for instance, that the district of the final stage has three sub-districts of the first stage and that the numbers of the eligible voters of the sub-districts are 123, 4567, and 89, respectively. The minimum number of votes required to be the winner is 107, that is, 62 from the first district and 45 from the third. In this case, even if the other candidate were given all the 4567 votes in the second district, s/he would inevitably be the loser. Although you might consider this election system unfair, you should accept it as a reality. Input The entire input looks like: the number of datasets (=n) 1st dataset 2nd dataset ⊠n-th dataset The number of datasets, n , is no more than 100. The number of the eligible voters of each district and the part-whole relations among districts are denoted as follows. An electoral district of the first stage is denoted as [ c ], where c is the number of the eligible voters of the district. A district of the k -th stage ( k > 1) is denoted as [ d 1 d 2 ⊠d m ], where d 1 , d 2 , âŠ, d m denote its sub-districts of the ( k â 1)-th stage in this notation. For instance, an electoral district of the first stage that has 123 eligible voters is denoted as [123]. A district of the second stage consisting of three sub-districts of the first stage that have 123, 4567, and 89 eligible voters, respectively, is denoted as [[123][4567][89]]. Each dataset is a line that contains the character string denoting the district of the final stage in the aforementioned notation. You can assume the following. The character string in each dataset does not include any characters except digits ('0', '1', âŠ, '9') and square brackets ('[', ']'), and its length is between 11 and 10000, inclusive. The number of the eligible voters of each electoral district of the first stage is between 3 and 9999, inclusive. The number of stages is a nation-wide constant. So, for instance, [[[9][9][9]][9][9]] never appears in the input. [[[[9]]]] may not appear either since each district of the second or later stage must have multiple sub-districts of the previous stage. Output For each dataset, print the minimum number of votes required to be the winner of the presidential election in a line. No output line may include any characters except the digits with which the number is written. Sample Input 6 [[123][4567][89]] [[5][3][7][3][9]] [[[99][59][63][85][51]][[1539][7995][467]][[51][57][79][99][3][91][59]]] [[[37][95][31][77][15]][[43][5][5][5][85]][[71][3][51][89][29]][[57][95][5][69][31]][[99][59][65][73][31]]] [[[[9][7][3]][[3][5][7]][[7][9][5]]][[[9][9][3]][[5][9][9]][[7][7][3]]][[[5][9][7]][[3][9][3]][[9][5][5]]]] [[8231][3721][203][3271][8843]] Output for the Sample Input 107 7 175 95 21 3599 | 35,664 |
Score : 200 points Problem Statement Takahashi has many red balls and blue balls. Now, he will place them in a row. Initially, there is no ball placed. Takahashi, who is very patient, will do the following operation 10^{100} times: Place A blue balls at the end of the row of balls already placed. Then, place B red balls at the end of the row. How many blue balls will be there among the first N balls in the row of balls made this way? Constraints 1 \leq N \leq 10^{18} A, B \geq 0 0 < A + B \leq 10^{18} 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 blue balls that will be there among the first N balls in the row of balls. Sample Input 1 8 3 4 Sample Output 1 4 Let b denote a blue ball, and r denote a red ball. The first eight balls in the row will be bbbrrrrb , among which there are four blue balls. Sample Input 2 8 0 4 Sample Output 2 0 He placed only red balls from the beginning. Sample Input 3 6 2 4 Sample Output 3 2 Among bbrrrr , there are two blue balls. | 35,665 |
Score : 300 points Problem Statement There are N people, conveniently numbered 1 through N . They were standing in a row yesterday, but now they are unsure of the order in which they were standing. However, each person remembered the following fact: the absolute difference of the number of the people who were standing to the left of that person, and the number of the people who were standing to the right of that person. According to their reports, the difference above for person i is A_i . Based on these reports, find the number of the possible orders in which they were standing. Since it can be extremely large, print the answer modulo 10^9+7 . Note that the reports may be incorrect and thus there may be no consistent order. In such a case, print 0 . Constraints 1âŠNâŠ10^5 0âŠA_iâŠN-1 Input The input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the number of the possible orders in which they were standing, modulo 10^9+7 . Sample Input 1 5 2 4 4 0 2 Sample Output 1 4 There are four possible orders, as follows: 2,1,4,5,3 2,5,4,1,3 3,1,4,5,2 3,5,4,1,2 Sample Input 2 7 6 4 0 2 4 0 2 Sample Output 2 0 Any order would be inconsistent with the reports, thus the answer is 0 . Sample Input 3 8 7 5 1 1 7 3 5 3 Sample Output 3 16 | 35,666 |
è·¯ç·ãã¹ã®æå»è¡š ãã¹ããã¢ã®å¥æ¬¡éåã¯ãåžå
ã®ãã¹ãããå©çšããŠããŸããããæ¥ãµãšã奿¬¡éåã®å®¶ã®åã®ãã¹åããåºçºãããã¹ãŠã®ãã¹ãåçã«åããããšãæãç«ã¡ãŸããããã®ãã¹åã«ã¯é£¯çå±±è¡ããšé¶Žã±åè¡ãã®ïŒã€ã®ãã¹è·¯ç·ãéããŸããåè·¯ç·ã®æå»è¡šã¯æã«å
¥ããŸããããïŒã€ã®æå»è¡šãšããŠãŸãšããæ¹ããã¹åã§åçãæ®ãããããªããŸãã 奿¬¡éåãå©ããããã«ãïŒã€ã®è·¯ç·ã®æå»è¡šããïŒæïŒåãåºæºãšããŠåºçºæå»ãæ©ãé ã«ïŒã€ã®æå»è¡šãšããŠãŸãšããããã°ã©ã ãäœæããŠãã ããã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã N h 1 m 1 h 2 m 2 ... h N m N M k 1 g 1 k 2 g 2 ... k M g M ïŒè¡ç®ã«ã飯çå±±è¡ãã®ãã¹ã®æ°ãè¡šãæŽæ° N (1 †N †100) ãšãããã«ç¶ããŠé£¯çå±±è¡ãã®ãã¹åºçºæå»ãæ©ãé ã«äžãããããåºçºæå»ã¯æŽæ° h i (0 †h i †23) ãš m i (0 †m i †59) ãããªãã h i æ m i åã« i çªç®ã®ãã¹ãåºçºããããšã衚ããïŒè¡ç®ã«ãé¶Žã±åè¡ãã®ãã¹ã®æ°ãè¡šãæŽæ° M (1 †M †100) ãšãããã«ç¶ããŠé¶Žã±åè¡ãã®ãã¹åºçºæå»ãæ©ãé ã«äžãããããåºçºæå»ã¯æŽæ° k i (0 †k i †23) ãš g i (0 †g i †59) ãããªãã k i æ g i åã« i çªç®ã®ãã¹ãåºçºããããšã衚ããåãè·¯ç·ã«ã¯ãåãæå»ã«åºçºãããã¹ã¯ãªããã®ãšããã åºå ïŒã€ã®è·¯ç·ã®æå»è¡šããïŒæïŒåãåºæºãšããŠåºçºæå»ãæ©ãé ã«ïŒã€ã«ãŸãšããæå»è¡šãïŒè¡ã«åºåããããã ããåãæå»ã«è€æ°ã®ãã¹ãåºçºãããšãã¯ïŒã€ã ããåºåãããåºçºæå»ã®æãšåã : ã§åºåããåãïŒæ¡ã®ãšãã¯å·Šã«ïŒãã²ãšã€å ããŠïŒæ¡ã§åºåãããæå»ãšæå»ã®éã¯ç©ºçœ1 ã€ã§åºåãã å
¥åºåäŸ å
¥åäŸïŒ 2 9 8 15 59 1 8 27 åºåäŸïŒ 8:27 9:08 15:59 å
¥åäŸïŒ 2 0 0 21 0 3 7 30 21 0 23 7 åºåäŸïŒ 0:00 7:30 21:00 23:07 | 35,667 |
ã²ãŒã ã®æ»ç¥ ããªãã¯æå±ããããã°ã©ãã³ã°éšã®éšå®€ããå€ã³ãããŒãã²ãŒã ãçºèŠããŸãããé¢çœãããªã®ã§éãã§ã¿ãããšã«ããŸããã ãã®ã²ãŒã 㯠M åã®ã€ãã³ãããæããæå» t i ã«ã€ãã³ã i ãæ»ç¥ããªããã°ãããŸããããã ãããã®ãšãã«ããªãã®åŒ·ã㯠s i 以äžã§ããå¿
èŠãããã s i 以äžã«ã§ããªãå Žåã¯ã²ãŒã ãªãŒããŒã«ãªããŸããã²ãŒã éå§æïŒæå»ïŒïŒã®ããªãã®åŒ·ãã¯ïŒã§ãããã¢ã€ãã ãè²·ãããšã§åŒ·ããå¢å ãããããšãã§ããŸããã²ãŒã éå§æã®ããªãã®ææéã¯ïŒã§ãããïŒåäœæéãããïŒå¢å ããŸãã ããŒãã«ã¯ããããïŒãã N ã®çªå·ãä»ãããã N åã®ã¢ã€ãã ãé çªã«äžŠã¹ãããŠãããã¢ã€ãã i ã®å€æ®µã¯ v i ã§ãããã賌å
¥ãããšããªãã®åŒ·ãã h i å¢å ããŸããã¢ã€ãã ã¯ææéãååã§ããã°å¥œããªæå»ã«å¥œããªæ°ã ã賌å
¥ããããšãã§ããŸãããæ®ã£ãŠããã¢ã€ãã ã®äžã§çªå·ãå°ãããã®ããé ã«éžã°ãªããã°ãªããŸãããåã¢ã€ãã ã¯ïŒåºŠè³Œå
¥ãããšæ¶æ»
ããŸãã ãŸããåãæå»ã«è€æ°ã®ã¢ã€ãã ãé£ç¶ã§è²·ãããšãã§ãããã®ãšãé£ãåãã¢ã€ãã ã® h i ã®å·®åã®åãããŒãã¹ãšããŠåŸãããšãã§ããŸããäŸãã°ãããæå»ã«ã¢ã€ãã ïŒ,ïŒ,ïŒãåæã«è²·ã£ãå Žåã h 1 + h 2 + h 3 ã«å ããŠ| h 1 - h 2 | + | h 2 - h 3 | ã ãããªãã®åŒ·ããå¢å ããŸãã ããªãã¯ãå
šãŠã®ã€ãã³ããæ»ç¥ããåŸã®ææéãæå€§åããããšèããŠããŸãã ã¢ã€ãã ã®æ
å ±ãšã€ãã³ãã®æ
å ±ãå
¥åãšãããã¹ãŠã®ã€ãã³ããæ»ç¥ããåŸã®ææéã®æå€§å€ãåºåããããã°ã©ã ãäœæããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã N M v 1 h 1 v 2 h 2 : v N h N t 1 s 1 t 2 s 2 : t M s M ïŒè¡ç®ã«ã¢ã€ãã ã®æ° N (1 †N †3000) ãšã€ãã³ãã®æ° M (1 †M †1000) ãäžãããããç¶ã N è¡ã«ã¢ã€ãã i ã®å€æ®µ v i ãšåŒ·ãã®å¢å é h i (1 †v i , h i †100000) ãäžãããããç¶ã M è¡ã«ã€ãã³ã i ã®æå» t i ãšæ¡ä»¶ s i (1 †t i , s i †100000) ãäžããããããã ãã i < j ã®ãšãã t i < t j ãšãããå
¥åã¯ãã¹ãп޿°ã§äžããããã Output ææéã®æå€§å€ãïŒè¡ã«åºåããããã ããæ»ç¥ããããšãã§ããªãå Žåã«ã¯ã-1ããåºåããã Sample Input 1 5 4 3 3 2 1 1 5 4 2 2 6 4 1 8 2 10 4 12 17 Sample Output 1 2 Sample Input 2 5 4 3 3 2 1 1 5 4 2 2 6 4 1 8 2 10 4 12 30 Sample Output 2 -1 | 35,668 |
Segment Intersections: Manhattan Geometry For given $n$ segments which are parallel to X-axis or Y-axis, find the number of intersections of them. Input In the first line, the number of segments $n$ is given. In the following $n$ lines, the $i$-th segment is given by coordinates of its end points in the following format: $x_1 \; y_1 \; x_2 \; y_2$ The coordinates are given in integers. Output Print the number of intersections in a line. Constraints $1 \leq n \leq 100,000$ $ -1,000,000,000 \leq x_1, y_1, x_2, y_2 \leq 1,000,000,000$ Two parallel segments never overlap or touch. The number of intersections $\leq 1,000,000$ Sample Input 1 6 2 2 2 5 1 3 5 3 4 1 4 4 5 2 7 2 6 1 6 3 6 5 6 7 Sample Output 1 3 | 35,669 |
Score : 600 points Problem Statement Given is an integer N . Snuke will choose integers s_1 , s_2 , n_1 , n_2 , u_1 , u_2 , k_1 , k_2 , e_1 , and e_2 so that all of the following six conditions will be satisfied: 0 \leq s_1 < s_2 0 \leq n_1 < n_2 0 \leq u_1 < u_2 0 \leq k_1 < k_2 0 \leq e_1 < e_2 s_1 + s_2 + n_1 + n_2 + u_1 + u_2 + k_1 + k_2 + e_1 + e_2 \leq N For every possible choice (s_1,s_2,n_1,n_2,u_1,u_2,k_1,k_2,e_1,e_2) , compute (s_2 â s_1)(n_2 â n_1)(u_2 â u_1)(k_2 - k_1)(e_2 - e_1) , and find the sum of all computed values, modulo (10^{9} +7) . Solve this problem for each of the T test cases given. Constraints All values in input are integers. 1 \leq T \leq 100 1 \leq N \leq 10^{9} Input Input is given from Standard Input in the following format: T \mathrm{case}_1 \vdots \mathrm{case}_T Each case is given in the following format: N Output Print T lines. The i -th line should contain the answer to the i -th test case. Sample Input 1 4 4 6 10 1000000000 Sample Output 1 0 11 4598 257255556 When N=4 , there is no possible choice (s_1,s_2,n_1,n_2,u_1,u_2,k_1,k_2,e_1,e_2) . Thus, the answer is 0 . When N=6 , there are six possible choices (s_1,s_2,n_1,n_2,u_1,u_2,k_1,k_2,e_1,e_2) as follows: (0,1,0,1,0,1,0,1,0,1) (0,2,0,1,0,1,0,1,0,1) (0,1,0,2,0,1,0,1,0,1) (0,1,0,1,0,2,0,1,0,1) (0,1,0,1,0,1,0,2,0,1) (0,1,0,1,0,1,0,1,0,2) We have one choice where (s_2 â s_1)(n_2 â n_1)(u_2 â u_1)(k_2 - k_1)(e_2 - e_1) is 1 and five choices where (s_2 â s_1)(n_2 â n_1)(u_2 â u_1)(k_2 - k_1)(e_2 - e_1) is 2 , so the answer is 11 . Be sure to find the sum modulo (10^{9} +7) . | 35,670 |
Score : 700 points Problem Statement Takahashi found an undirected connected graph with N vertices and M edges. The vertices are numbered 1 through N . The i -th edge connects vertices a_i and b_i , and has a weight of c_i . He will play Q rounds of a game using this graph. In the i -th round, two vertices S_i and T_i are specified, and he will choose a subset of the edges such that any vertex can be reached from at least one of the vertices S_i or T_i by traversing chosen edges. For each round, find the minimum possible total weight of the edges chosen by Takahashi. Constraints 1 ⊠N ⊠4,000 1 ⊠M ⊠400,000 1 ⊠Q ⊠100,000 1 ⊠a_i,b_i,S_i,T_i ⊠N 1 ⊠c_i ⊠10^{9} a_i \neq b_i S_i \neq T_i The given graph is connected. Partial Scores In the test set worth 200 points, Q = 1 . In the test set worth another 300 points, Q ⊠3000 . Input The input is given from Standard Input in the following format: N M a_1 b_1 c_1 a_2 b_2 c_2 : a_M b_M c_M Q S_1 T_1 S_2 T_2 : S_Q T_Q Output Print Q lines. The i -th line should contain the minimum possible total weight of the edges chosen by Takahashi. Sample Input 1 4 3 1 2 3 2 3 4 3 4 5 2 2 3 1 4 Sample Output 1 8 7 We will examine each round: In the 1 -st round, choosing edges 1 and 3 achieves the minimum total weight of 8 . In the 2 -nd round, choosing edges 1 and 2 achieves the minimum total weight of 7 . Sample Input 2 4 6 1 3 5 4 1 10 2 4 6 3 2 2 3 4 5 2 1 3 1 2 3 Sample Output 2 8 This input satisfies the additional constraints for both partial scores. | 35,671 |
Problem G: BUT We Need a Diagram Consider a data structure called BUT (Binary and/or Unary Tree). A BUT is defined inductively as follows: Let l be a letter of the English alphabet, either lowercase or uppercase (n the sequel, we say simply "a letter"). Then, the object that consists only of l , designating l as its label, is a BUT. In this case, it is called a 0-ary BUT. Let l be a letter and C a BUT. Then, the object that consists of l and C , designating l as its label and C as its component, is a BUT. In this case, it is called a unary BUT. Let l be a letter, L and R BUTs. Then, the object that consists of l , L and R , designating l as its label, L as its left component, and R as its right component, is a BUT. In this case, it is called a binary BUT. A BUT can be represented by a expression in the following way. When a BUT B is 0-ary, its representation is the letter of its label. When a BUT B is unary, its representation is the letter of its label followed by the parenthesized representation of its component. When a BUT B is binary, its representation is the letter of its label, a left parenthesis, the representation of its left component, a comma, the representation of its right component, and a right parenthesis, arranged in this order. Here are examples: a A(b) a(a,B) a(B(c(D),E),f(g(H,i))) Such an expression is concise, but a diagram is much more appealing to our eyes. We prefer a diagram: D H i - --- c E g --- - B f ---- a to the expression a(B(c(D),E),f(g(H,i))) Your mission is to write a program that converts the expression representing a BUT into its diagram. We want to keep a diagram as compact as possible assuming that we display it on a conventional character terminal with a fixed pitch font such as Courier. Let's define the diagram D for BUT B inductively along the structure of B as follows: When B is 0-ary, D consists only of a letter of its label. The letter is called the root of D , and also called the leaf of D When B is unary, D consists of a letter l of its label, a minus symbol S , and the diagram C for its component, satisfying the following constraints: l is just below S The root of C is just above S l is called the root of D , and the leaves of C are called the leaves of D . When B is binary, D consists of a letter l of its label, a sequence of minus symbols S , the diagram L for its left component, and the diagram R for its right component, satisfying the following constraints: S is contiguous, and is in a line. l is just below the central minus symbol of S , where, if the center of S locates on a minus symbol s , s is the central, and if the center of S locates between adjacent minus symbols, the left one of them is the central. The root of L is just above the left most minus symbols of S , and the rot of R is just above the rightmost minus symbol of S In any line of D , L and R do not touch or overlap each other. No minus symbols are just above the leaves of L and R . l is called the root of D , and the leaves of L and R are called the leaves of D Input The input to the program is a sequence of expressions representing BUTs. Each expression except the last one is terminated by a semicolon. The last expression is terminated by a period. White spaces (tabs and blanks) should be ignored. An expression may extend over multiple lines. The number of letter, i.e., the number of characters except parentheses, commas, and white spaces, in an expression is at most 80. You may assume that the input is syntactically correct and need not take care of error cases. Output Each expression is to be identified with a number starting with 1 in the order of occurrence in the input. Output should be produced in the order of the input. For each expression, a line consisting of the identification number of the expression followed by a colon should be produced first, and then, the diagram for the BUT represented by the expression should be produced. For diagram, output should consist of the minimum number of lines, which contain only letters or minus symbols together with minimum number of blanks required to obey the rules shown above. Sample Input a(A,b(B,C)); x( y( y( z(z), v( s, t ) ) ), u ) ; a( b( c, d( e(f), g ) ), h( i( j( k(k,k), l(l) ), m(m) ) ) ); a(B(C),d(e(f(g(h(i(j,k),l),m),n),o),p)) . Output for the Sample Input 1: B C --- A b --- a 2: z s t - --- z v ---- y - y u --- x 3: k k l --- - f k l m - ---- - e g j m --- ----- c d i --- - b h ------- a 4: j k --- i l --- h m --- g n --- f o --- C e p - --- B d ---- a | 35,672 |
D: DAG ããªãª / DAG Trio ãã®åé¡ã¯ G: DAG Trio (Hard) ãšå¶çŽã®ã¿ãç°ãªãåãèšå®ã®åé¡ã§ãã ããããŒã° åŒã¯æè¿ãã ããšããããæ¬²ãããšãããã«åããŠããŸãã å¿é
ã«ãªã£ãå
ã調ã¹ããšãããåŒã®ã¯ã©ã¹ã§ã¯ $k$-DAG (æåã°ã©ãã§ãã£ãŠããã $k$ åã®èŸºãåé€ãããšã蟺ã®åããç¡èŠãããšãã®é£çµæåæ°ã $k$ ã«ã§ãããã€ãããå
šãŠã DAG ã§ãã) ãæµè¡ã£ãŠããã 3-DAG ãç¹ã« DAG ããªãªãšåŒã¶ããšãçªãæ¢ããŸããã åŒã«å°æ¬ããããå
ã¯ãäžããããã°ã©ãã DAG ããªãªãã©ãããå€å¥ããããã°ã©ã ãäœæããããšã«ããŸããã å顿 $N$ é ç¹ $M$ èŸºã®æåã°ã©ããäžããããŸãã åé ç¹ã«ã¯ $1$ ãã $N$ ãŸã§çªå·ãæ¯ãããŠããŸãã åæå蟺ã«ã¯ $1$ ãã $M$ ãŸã§çªå·ãæ¯ãããŠããŸãã æå蟺 $i$ ã¯é ç¹ $a_i$ ãã $b_i$ ã«åãããŸãã ã°ã©ãã¯é£çµãã€åçŽã§ã (蟺ã®åããç¡èŠãããšãä»»æã® 2 ç¹éã«éãããèªå·±ã«ãŒããšå€é蟺ããããŸãã)ã äžããããã°ã©ãã DAG ããªãªãªãã° âYESâãããã§ãªããªã âNOâ ãåºåããŠãã ããã å
¥å $N \ M$ $a_1 \ b_1$ $a_2 \ b_2$ $\vdots$ $a_M \ b_M$ å¶çŽ $3 \le N \le 500$ $\max(3, Nâ1) \le M \le 1000$ $1 \le a_i, b_i \le N$ ã°ã©ãã¯èŸºã®åããç¡èŠãããšãã«é£çµã§ããã å $i$ ã«å¯ŸããŠ$a_i \neq b_i$ ç°ãªã $i, j$ ã«å¯Ÿã㊠$\{a_i, b_i\} \neq \{a_j, b_j\}$ åºå âYESâ ãŸã㯠âNOâ ã $1$ è¡ã§åºåããŠãã ããã ãµã³ãã« ãµã³ãã«å
¥å1 3 3 1 2 2 3 3 1 ãµã³ãã«åºå1 YES ãµã³ãã«å
¥å2 6 7 1 2 2 3 4 3 4 5 5 6 6 4 3 6 ãµã³ãã«åºå2 YES ãµã³ãã«å
¥å3 7 10 4 2 4 7 4 6 2 7 2 5 2 1 5 6 1 3 6 3 4 3 ãµã³ãã«åºå3 NO ãµã³ãã«å
¥å4 4 4 1 2 3 2 4 3 2 4 ãµã³ãã«åºå4 YES ãµã³ãã«å
¥å5 8 9 5 1 3 8 1 2 4 8 4 7 7 5 6 5 3 2 4 2 ãµã³ãã«åºå5 YES | 35,673 |
Minimum Spanning Tree For a given weighted graph $G = (V, E)$, find the minimum spanning tree (MST) of $G$ and print total weight of edges belong to the MST. Input In the first line, an integer $n$ denoting the number of vertices in $G$ is given. In the following $n$ lines, a $n \times n$ adjacency matrix $A$ which represents $G$ is given. $a_{ij}$ denotes the weight of edge connecting vertex $i$ and vertex $j$. If there is no edge between $i$ and $j$, $a_{ij}$ is given by -1. Output Print the total weight of the minimum spanning tree of $G$. Constraints $1 \leq n \leq 100$ $0 \leq a_{ij} \leq 2,000$ (if $a_{ij} \neq -1$) $a_{ij} = a_{ji}$ $G$ is a connected graph Sample Input 1 5 -1 2 3 1 -1 2 -1 -1 4 -1 3 -1 -1 1 1 1 4 1 -1 3 -1 -1 1 3 -1 Sample Output 1 5 Reference Introduction to Algorithms, Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. The MIT Press. | 35,674 |
Score : 200 points Problem Statement A ball will bounce along a number line, making N + 1 bounces. It will make the first bounce at coordinate D_1 = 0 , and the i -th bounce (2 \leq i \leq N+1) at coordinate D_i = D_{i-1} + L_{i-1} . How many times will the ball make a bounce where the coordinate is at most X ? Constraints 1 \leq N \leq 100 1 \leq L_i \leq 100 1 \leq X \leq 10000 All values in input are integers. Input Input is given from Standard Input in the following format: N X L_1 L_2 ... L_{N-1} L_N Output Print the number of times the ball will make a bounce where the coordinate is at most X . Sample Input 1 3 6 3 4 5 Sample Output 1 2 The ball will make a bounce at the coordinates 0 , 3 , 7 and 12 , among which two are less than or equal to 6 . Sample Input 2 4 9 3 3 3 3 Sample Output 2 4 The ball will make a bounce at the coordinates 0 , 3 , 6 , 9 and 12 , among which four are less than or equal to 9 . | 35,675 |
Rakunarok You are deeply disappointed with the real world, so you have decided to live the rest of your life in the world of MMORPG (Massively Multi-Player Online Role Playing Game). You are no more concerned about the time you spend in the game: all you need is efficiency . One day, you have to move from one town to another. In this game, some pairs of towns are connected by roads where players can travel. Various monsters will raid players on roads. However, since you are a high-level player, they are nothing but the source of experience points. Every road is bi-directional. A path is represented by a sequence of towns, where consecutive towns are connected by roads. You are now planning to move to the destination town through the most efficient path. Here, the efficiency of a path is measured by the total experience points you will earn in the path divided by the time needed to travel the path. Since your object is moving, not training, you choose only a straightforward path. A path is said straightforward if, for any two consecutive towns in the path, the latter is closer to the destination than the former. The distance of two towns is measured by the shortest time needed to move from one town to another. Write a program to find a path that gives the highest efficiency. Input The first line contains a single integer c that indicates the number of cases. The first line of each test case contains two integers n and m that represent the numbers of towns and roads respectively. The next line contains two integers s and t that denote the starting and destination towns respectively. Then m lines follow. The i -th line contains four integers u i , v i , e i , and t i , where u i and v i are two towns connected by the i -th road, e i is the experience points to be earned, and t i is the time needed to pass the road. Each town is indicated by the town index number from 0 to ( n - 1). The starting and destination towns never coincide. n , m , e i 's and t i 's are positive and not greater than 1000. Output For each case output in a single line, the highest possible efficiency. Print the answer with four decimal digits. The answer may not contain an error greater than 10 -4 . Sample Input 2 3 3 0 2 0 2 240 80 0 1 130 60 1 2 260 60 3 3 0 2 0 2 180 60 0 1 130 60 1 2 260 60 Output for the Sample Input 3.2500 3.0000 | 35,676 |
Score : 400 points Problem Statement There are N people standing on the x -axis. Let the coordinate of Person i be x_i . For every i , x_i is an integer between 0 and 10^9 (inclusive). It is possible that more than one person is standing at the same coordinate. You will given M pieces of information regarding the positions of these people. The i -th piece of information has the form (L_i, R_i, D_i) . This means that Person R_i is to the right of Person L_i by D_i units of distance, that is, x_{R_i} - x_{L_i} = D_i holds. It turns out that some of these M pieces of information may be incorrect. Determine if there exists a set of values (x_1, x_2, ..., x_N) that is consistent with the given pieces of information. Constraints 1 \leq N \leq 100 000 0 \leq M \leq 200 000 1 \leq L_i, R_i \leq N ( 1 \leq i \leq M ) 0 \leq D_i \leq 10 000 ( 1 \leq i \leq M ) L_i \neq R_i ( 1 \leq i \leq M ) If i \neq j , then (L_i, R_i) \neq (L_j, R_j) and (L_i, R_i) \neq (R_j, L_j) . D_i are integers. Input Input is given from Standard Input in the following format: N M L_1 R_1 D_1 L_2 R_2 D_2 : L_M R_M D_M Output If there exists a set of values (x_1, x_2, ..., x_N) that is consistent with all given pieces of information, print Yes ; if it does not exist, print No . Sample Input 1 3 3 1 2 1 2 3 1 1 3 2 Sample Output 1 Yes Some possible sets of values (x_1, x_2, x_3) are (0, 1, 2) and (101, 102, 103) . Sample Input 2 3 3 1 2 1 2 3 1 1 3 5 Sample Output 2 No If the first two pieces of information are correct, x_3 - x_1 = 2 holds, which is contradictory to the last piece of information. Sample Input 3 4 3 2 1 1 2 3 5 3 4 2 Sample Output 3 Yes Sample Input 4 10 3 8 7 100 7 9 100 9 8 100 Sample Output 4 No Sample Input 5 100 0 Sample Output 5 Yes | 35,677 |
Problem J: Cave Explorer Mike Smith is a man exploring caves all over the world. One day, he faced a scaring creature blocking his way. He got scared, but in short time he took his knife and then slashed it to attempt to kill it. Then they were split into parts, which soon died out but the largest one. He slashed the creature a couple of times more to make it small enough, and finally became able to go forward. Now let us think of his situation in a mathematical way. The creature is considered to be a polygon, convex or concave. Mike slashes this creature straight with his knife in some direction. We suppose here the direction is given for simpler settings, while the position is arbitrary. Then all split parts but the largest one disappears. Your task is to write a program that calculates the area of the remaining part when the creature is slashed in such a way that the area is minimized. Input The input is a sequence of datasets. Each dataset is given in the following format: n v x v y x 1 y 1 ... x n y n The first line contains an integer n , the number of vertices of the polygon that represents the shape of the creature (3 †n †100). The next line contains two integers v x and v y , where ( v x , v y ) denote a vector that represents the direction of the knife (-10000 †v x , v y †10000, v x 2 + v y 2 > 0). Then n lines follow. The i -th line contains two integers x i and y i , where ( x i , y i ) denote the coordinates of the i -th vertex of the polygon (0 †x i , y i †10000). The vertices are given in the counterclockwise order. You may assume the polygon is always simple, that is, the edges do not touch or cross each other except for end points. The input is terminated by a line with a zero. This should not be processed. Output For each dataset, print the minimum possible area in a line. The area may be printed with an arbitrary number of digits after the decimal point, but should not contain an absolute error greater than 10 -2 . Sample Input 5 0 1 0 0 5 0 1 1 5 2 0 2 7 9999 9998 0 0 2 0 3 1 1 1 10000 9999 2 2 0 2 0 Output for the Sample Input 2.00 2.2500000 | 35,678 |
A ãããš B åã¯ïŒ N à M ã®é·æ¹åœ¢ã®ãã¹ç®ç¶ã®å°åã«äœãã§ããïŒåãã¹ç®ã¯éãå£ãå®¶ã®ã©ããã§ããïŒãã®å°åã¯ïŒéãè€éã§å
¥ãçµãã§ããã®ã§çŽæŒ¢è¢«å®³ãããèµ·ããããšã§æåã§ããããïŒãã®å°åãšå€éšãšã®å¢çã¯å
šãŠå£ã§å²ãŸããŠããïŒéé¢ãããŠããïŒ B åã¯ãªããšãªãæ°ãåããã®ã§ïŒA ããã®å®¶ãçºãã«è¡ãããšã«ããïŒãããïŒäžå¹žãªããšã«B åã¯æããã«æªããé¡ãããŠããã®ã§ïŒA ããã®å®¶ã«è¡ãéäžã«å°ãã§ãçŽæŒ¢ã®çãããããããªè¡åãåã£ããããã«æãŸã£ãŠããŸãã ããïŒç¹ã«ïŒå³æãå£ããé¢ããŠæ©ãããšã¯çµ¶å¯Ÿã«ãã£ãŠã¯ãªããªãïŒB åã¯ïŒäžç¬ãããšã峿ãé¢ãããšãªãïŒA ããã®å®¶ã«èŸ¿ãçãããšãåºæ¥ãã ãããïŒ B åã¯ã€ãã«äžäžå·Šå³ããããã®æ¹åãåããŠããŠïŒB åã®å³æãå±ãç¯å²ã¯B åã®åããŠããæ¹åã«å¯ŸããŠæ£é¢ïŒæãå³åïŒå³ïŒæãå³åŸãã®4 ãã¹ã®ã¿ã§ããïŒB åã¯ïŒæ¬¡ã®ããããã®è¡åãç¹°ãè¿ãïŒãã ãïŒããããåæã«è¡ãããšã¯åºæ¥ãªãïŒ åæ¹ã«å£ããªãå ŽåïŒ1 ãã¹é²ãïŒ åããŠããæ¹åã90 床å³ã«å€ããïŒ åããŠããæ¹åã90 床巊ã«å€ããïŒ å³æãæ¥ãããã¹ãå€ããïŒãã ãïŒãã®æã«B åã¯å³æãé¢ãããšãåºæ¥ãªãã®ã§ïŒå€æŽåã®ãã¹ãšå€æŽåŸã®ãã¹ã®éã«ã¯å
±éããç¹ãæã£ãŠããªããŠã¯ãªããªãïŒ Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ N M S 1 S 2 : S N S i (1 †i †N ) ã¯ïŒ M æåã®æååã§åæåã¯æ¬¡ã衚ãïŒ "^"ïŒ"v"ïŒ"<"ïŒ">" 㯠B åã®æåã®äœçœ®ãšæåã«åããŠããæ¹åïŒäžäžå·Šå³ã®åãïŒã衚ãïŒ "." ã¯ïŒäœããªããã¹ã§ããïŒB åã¯ïŒãã®ãã¹ã®äžãç§»åããããšãã§ããïŒ "#" ã¯ïŒå£ã衚ãïŒå£ã®äžãç§»åããããšã¯åºæ¥ãªãïŒ "G" 㯠A ããã®å®¶ã®äœçœ®ã衚ãïŒB åã¯ïŒA ããã®å®¶ã«ãã©ãçããŸã§ç§»åãç¹°ãè¿ãïŒ Constraints 1 †N †50 1 †M †50 å
¥åã«ã¯ïŒæå "^"ïŒ"v"ïŒ"<"ïŒ">" ã®ãã¡ãããããå¿
ãäžã€ã®ã¿çŸããïŒ åæ§ã«ïŒå
¥åã«ã¯ïŒæå "G" ãå¿
ãäžã€ã®ã¿çŸããïŒ åæç¶æ
ã§ã¯ïŒB åãåããŠããæ¹åããå³ã®å£ã«B åã®å³æãæ¥ããŠããïŒ Output äžåºŠã峿ãé¢ããã«A ããã®å®¶ã«èŸ¿ãçãããšãåºæ¥ãå Žåã«ã¯ïŒA ããã®å®¶ã«ãã©ãçããŸã§ã«éã£ãç°ãªããã¹ã®æ°ã®æå°å€ãåºåããïŒA ããã®å®¶ã«èŸ¿ãçãããšãåºæ¥ãªãå Žåã«ã¯ïŒ-1 ãåºåããïŒ Sample Input 1 3 3 G## .#. .<. Output for the Sample Input 1 4 Sample Input 2 3 3 G## .#. .>. Output for the Sample Input 2 6 Sample Input 3 3 3 ... .G. .>. Output for the Sample Input 3 -1 Sample Input 4 4 4 .... .#.G ...# ^#.. Output for the Sample Input 4 8 | 35,679 |
Problem E: Mobile Computing There is a mysterious planet called Yaen, whose space is 2-dimensional. There are many beautiful stones on the planet, and the Yaen people love to collect them. They bring the stones back home and make nice mobile arts of them to decorate their 2-dimensional living rooms. In their 2-dimensional world, a mobile is defined recursively as follows: a stone hung by a string, or a rod of length 1 with two sub-mobiles at both ends; the rod is hung by a string at the center of gravity of sub-mobiles. When the weights of the sub-mobiles are n and m , and their distances from the center of gravity are a and b respectively, the equation n à a = m à b holds. For example, if you got three stones with weights 1, 1, and 2, here are some possible mobiles and their widths: Given the weights of stones and the width of the room, your task is to design the widest possible mobile satisfying both of the following conditions. It uses all the stones. Its width is less than the width of the room. You should ignore the widths of stones. In some cases two sub-mobiles hung from both ends of a rod might overlap (see the figure on the below). Such mobiles are acceptable. The width of the example is (1/3) + 1 + (1/4). Input The first line of the input gives the number of datasets. Then the specified number of datasets follow. A dataset has the following format. r s w 1 . . . w s r is a decimal fraction representing the width of the room, which satisfies 0 < r < 10. s is the number of the stones. You may assume 1 †s †6. w i is the weight of the i -th stone, which is an integer. You may assume 1 †w i †1000. You can assume that no mobiles whose widths are between r - 0.00001 and r + 0.00001 can be made of given stones. Output For each dataset in the input, one line containing a decimal fraction should be output. The decimal fraction should give the width of the widest possible mobile as defined above. An output line should not contain extra characters such as spaces. In case there is no mobile which satisfies the requirement, answer -1 instead. The answer should not have an error greater than 0.00000001. You may output any number of digits after the decimal point, provided that the above accuracy condition is satisfied. Sample Input 5 1.3 3 1 2 1 1.4 3 1 2 1 2.0 3 1 2 1 1.59 4 2 1 1 3 1.7143 4 1 2 3 5 Output for the Sample Input -1 1.3333333333333335 1.6666666666666667 1.5833333333333335 1.7142857142857142 | 35,680 |
Score : 400 points Problem Statement There are N islands lining up from west to east, connected by N-1 bridges. The i -th bridge connects the i -th island from the west and the (i+1) -th island from the west. One day, disputes took place between some islands, and there were M requests from the inhabitants of the islands: Request i : A dispute took place between the a_i -th island from the west and the b_i -th island from the west. Please make traveling between these islands with bridges impossible. You decided to remove some bridges to meet all these M requests. Find the minimum number of bridges that must be removed. Constraints All values in input are integers. 2 \leq N \leq 10^5 1 \leq M \leq 10^5 1 \leq a_i < b_i \leq N All pairs (a_i, b_i) are distinct. Input Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M Output Print the minimum number of bridges that must be removed. Sample Input 1 5 2 1 4 2 5 Sample Output 1 1 The requests can be met by removing the bridge connecting the second and third islands from the west. Sample Input 2 9 5 1 8 2 7 3 5 4 6 7 9 Sample Output 2 2 Sample Input 3 5 10 1 2 1 3 1 4 1 5 2 3 2 4 2 5 3 4 3 5 4 5 Sample Output 3 4 | 35,681 |
åé¡ 4 IOI äžåç£ã§ã¯ãã³ã·ã§ã³ã®è³è²žãè¡ãªã£ãŠããïŒ ãã®äŒç€Ÿãåãæ±ããã³ã·ã§ã³ã®éšå±ã¯ 1LDK ã§ïŒ äžå³ã®ããã«é¢ç©ã 2xy+x+y ã«ãªã£ãŠããïŒ ãã ãïŒ x, y ã¯æ£æŽæ°ã§ããïŒ IOI äžåç£ã®ã«ã¿ãã°ã«ã¯ãã³ã·ã§ã³ã®é¢ç©ãæé ã«ïŒçããã®ããé çªã«ïŒæžãããŠãããïŒãã®äžã«ããã€ãééãïŒããããªãé¢ç©ã®ãã®ïŒãæ··ãã£ãŠããããšãããã£ãïŒ ã«ã¿ãã°ïŒå
¥åãã¡ã€ã«ïŒã¯ N+1 è¡ã§ïŒæåã®è¡ã«éšå±æ°ãæžãããŠããŠïŒ ç¶ã N è¡ã«ïŒïŒè¡ã«ïŒéšå±ãã€é¢ç©ãæé ã«æžãããŠããïŒ ãã ãïŒ éšå±æ°ã¯ 100,000 以äžïŒ é¢ç©ã¯ (2ã®31ä¹)-1 = 2,147,483,647 以äžã§ããïŒ ïŒã€ã®å
¥åããŒã¿ã®ãã¡ïŒã€ãŸã§ã¯ïŒ éšå±æ° 1000 以äžïŒé¢ç© 30000 以äžã§ããïŒ ééã£ãŠããè¡æ°ïŒããããªãéšå±ã®æ°ïŒãåºåããªããïŒ åºåãã¡ã€ã«ã«ãããŠã¯ïŒ åºåã®æåŸã®è¡ã«ãæ¹è¡ã³ãŒããå
¥ããããšïŒ å
¥åºåäŸ å
¥åäŸ 10 4 7 9 10 12 13 16 17 19 20 åºåäŸ 2 å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã | 35,682 |
çœçãšç¹å¥³ ç¹å¥³ã¯å€©åžã®åäŸã§ããããç¶ã®èšãã€ãã§ãããŠããããŠãæ©ãç¹ã£ãŠããŸããã ç¹å¥³ã®ç¹ãé²éŠãšããèŠäºãªåžã§ä»ç«ãŠãæãçãã®ã倩åžã®æ¥œãã¿ã§ãããé²éŠã¯å¯¿åœãçãããã«å£åããŠããŸããŸãããåãè
ã®ç¹å¥³ãæ¯æ¥ç¹ã£ãŠãããã®ã§ãåé¡ã¯ãããŸããã§ãããç¹å¥³ã¯ãç¶ã®èšãã€ããå®ããæ¯æ¥æ¯æ¥é²éŠãç¹ãç¶ããŠããã®ã§ãããŒã€ãã¬ã³ãã¯ããŸããã§ããããããããã«æã£ãç¶ã¯ã倩ã®å·ã®åãã岞ã«äœãçœçãšããåãè
ã玹ä»ããå«å
¥ããããŸããã ãããšãç¹å¥³ã¯ãçµå©ã®æ¥œããã«å€¢äžã«ãªã£ãŠãæ©ç¹ããªã©ãã£ã¡ã®ãã§ãçœçãšéã³åããŠããŸãã倩åžã®ãæ°ã«å
¥ãã®é²éŠã®æãæ°ããä»ç«ãŠãããªãããããããã«ãªã£ãŠããŸããŸããã ããã«ã¯ç¶ãæã£ãŠãç¹å¥³ã宮殿ã«é£ãæ»ããããšæããŸãããããã人éã§ããçœçã®åã«ããããã®æã§å§¿ãçŸãããã«ã¯ãããŸãããéã³åããŠããäºäººã 3 è§åœ¢ã®å£ã§é®æãèªå以å€ã®å
šãŠã®ãã®ãè¡ãæ¥ã§ããªãããããšãèããŸããããããŠãçœçã«èŠã€ãããã«ãç¹å¥³ã«äŒã£ãŠããŸããã«æ©ãç¹ããããããªããã°åŒ·å¶çã«é£ãåž°ããšå®£èšãããšããã®ã§ãã 倩åžã¯ãã®äœæŠãéè¡ããããã« 3 è§åœ¢ã®å£çæè£
眮ãéçºããããšã«ããŸããã3 è§åœ¢ã® 3 é ç¹ã®äœçœ® (xp 1 , yp 1 ) , (xp 2 , yp 2 ) , (xp 3 , yp 3 ) ãçœçã®äœçœ® (xk, yk) ãããã³ç¹å¥³ã®äœçœ® (xs, ys) ããå
¥åãšããäžè§åœ¢ãçœçãšç¹å¥³ã鮿ããŠãããåŠããå€å®ãã鮿ã§ããŠããå Žå㯠OKã鮿ã§ããŠããªãå Žåã«ã¯ NG ãåºåããããã°ã©ã ãäœæããŠãã ããããã ãã鮿ããŠãããšã¯ãçœçãšç¹å¥³ã®ãããããäžè§åœ¢ã®å
åŽã«ããã仿¹ãå€åŽã«ããå ŽåãèšããŸããçœçãšç¹å¥³ã¯äžè§åœ¢ã®é ç¹ãããã¯èŸºã®äžã«ã¯ããªããã®ãšããŸãã ç¹å¥³ãšçœçã¯æã
å»ã
å Žæãå€ãããããããã°ã©ã ã¯æ§ã
ãªäœçœ®æ
å ±ãå
¥åã質åã«çããªããã°ãªããŸããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã n query 1 query 2 : query n ïŒè¡ç®ã«å€å¥ãããæ
å ±ã®åæ° n ( n †10000)ãç¶ã n è¡ã« i çªç®ã®è³ªå query i ãäžããããŸããå質åã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã xp 1 yp 1 xp 2 yp 2 xp 3 yp 3 xk yk xs ys å質åãšããŠã3 è§åœ¢ã® 3 é ç¹ã®äœçœ®ãçœçã®äœçœ®ãããã³ç¹å¥³ã®äœçœ® (-1000 †xp 1 , yp 1 , xp 2 , yp 2 , xp 3 , yp 3 , xk , yk , xs , ys †1000) ãïŒè¡ã«äžããããŸããå
¥åã¯ãã¹ãп޿°ã§ãã Output 質åããšã«ãå€å®çµæ OK ãŸã㯠NG ãïŒè¡ã«åºåããŠãã ããã Sample Input 5 2 5 9 2 8 9 2 11 6 5 2 5 9 2 8 9 2 11 12 6 2 5 9 2 8 9 2 11 11 9 14 1 25 7 17 12 17 9 20 5 14 1 25 7 17 12 22 13 20 5 Output for the Sample Input OK NG NG NG OK | 35,683 |
Range Count Query æ°å a_1,a_2,..,a_N ãäžããããŸãã ã¯ãšãªã§ã¯ãå€ã l ä»¥äž r 以äžã®é
ã®åæ°ãçããŠãã ããã å
¥å N Q a_1 a_2...a_N l_1 r_1 l_2 r_2 : l_q r_q åºå ans_1 ans_2 : ans_q i è¡ç®ã«ã¯ã i çªç®ã®ã¯ãšãªã«å¯Ÿããçããããªãã¡ l_i \leq a_j \leq r_i ãªã j ã®åæ°ãåºåããã å¶çŽ 1 \leq N,Q \leq 10^5 1 \leq a_i \leq 10^9 1 \leq l_i \leq r_i \leq 10^9 å
¥åäŸ 6 3 8 6 9 1 2 1 2 8 1 7 3 5 åºåäŸ 3 4 0 | 35,684 |
ã³ã³ãã¹ã åé¡ å
æ¥ïŒãªã³ã©ã€ã³ã§ã®ããã°ã©ãã³ã°ã³ã³ãã¹ããè¡ãããïŒ W倧åŠãšK倧åŠã®ã³ã³ãã¥ãŒã¿ã¯ã©ãã¯ä»¥åããã©ã€ãã«é¢ä¿ã«ããïŒãã®ã³ã³ãã¹ããå©çšããŠäž¡è
ã®åªå£ã決ããããšããããšã«ãªã£ãïŒ ä»åïŒãã®2ã€ã®å€§åŠããã¯ãšãã«10人ãã€ããã®ã³ã³ãã¹ãã«åå ããïŒé·ãè°è«ã®æ«ïŒåå ãã10人ã®ãã¡ïŒåŸç¹ã®é«ãæ¹ãã3人ã®åŸç¹ãåèšãïŒå€§åŠã®åŸç¹ãšããããšã«ããïŒ W倧åŠããã³K倧åŠã®åå è
ã®åŸç¹ã®ããŒã¿ãäžããããïŒãã®ãšãïŒãã®ãã®ã®å€§åŠã®åŸç¹ãèšç®ããããã°ã©ã ãäœæããïŒ å
¥å å
¥åã¯20è¡ãããªãïŒ 1è¡ç®ãã10è¡ç®ã«ã¯W倧åŠã®ååå è
ã®åŸç¹ãè¡šãæŽæ°ãïŒ 11è¡ç®ãã20è¡ç®ã«ã¯K倧åŠã®ååå è
ã®åŸç¹ãè¡šãæŽæ°ãæžãããŠããïŒãããã®æŽæ°ã¯ã©ãã0以äž100以äžã§ããïŒ åºå W倧åŠã®åŸç¹ãšK倧åŠã®åŸç¹ãïŒãã®é ã«ç©ºçœåºåãã§åºåããïŒ å
¥åºåäŸ å
¥åäŸïŒ 23 23 20 15 15 14 13 9 7 6 25 19 17 17 16 13 12 11 9 5 åºåäŸïŒ 66 61 å
¥åäŸïŒ 17 25 23 25 79 29 1 61 59 100 44 74 94 57 13 54 82 0 42 45 åºåäŸïŒ 240 250 äžèšå顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã | 35,685 |
Reverse Sequence Write a program which reverses a given string str . Input str (the size of str †20) is given in a line. Output Print the reversed str in a line. Sample Input w32nimda Output for the Sample Input admin23w | 35,686 |
Score : 600 points Problem Statement AtCoDeer the deer has N cards with positive integers written on them. The number on the i -th card (1â€iâ€N) is a_i . Because he loves big numbers, he calls a subset of the cards good when the sum of the numbers written on the cards in the subset, is K or greater. Then, for each card i , he judges whether it is unnecessary or not, as follows: If, for any good subset of the cards containing card i , the set that can be obtained by eliminating card i from the subset is also good, card i is unnecessary. Otherwise, card i is NOT unnecessary. Find the number of the unnecessary cards. Here, he judges each card independently, and he does not throw away cards that turn out to be unnecessary. Constraints All input values are integers. 1â€Nâ€5000 1â€Kâ€5000 1â€a_iâ€10^9 (1â€iâ€N) Partial Score 300 points will be awarded for passing the test set satisfying N,Kâ€400 . Input The input is given from Standard Input in the following format: N K a_1 a_2 ... a_N Output Print the number of the unnecessary cards. Sample Input 1 3 6 1 4 3 Sample Output 1 1 There are two good sets: { 2,3 } and { 1,2,3 }. Card 1 is only contained in { 1,2,3 }, and this set without card 1 , { 2,3 }, is also good. Thus, card 1 is unnecessary. For card 2 , a good set { 2,3 } without card 2 , { 3 }, is not good. Thus, card 2 is NOT unnecessary. Neither is card 3 for a similar reason, hence the answer is 1 . Sample Input 2 5 400 3 1 4 1 5 Sample Output 2 5 In this case, there is no good set. Therefore, all the cards are unnecessary. Sample Input 3 6 20 10 4 3 10 25 2 Sample Output 3 3 | 35,687 |
Score : 300 points Problem Statement Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K . She is shopping, and now paying at the cashier. Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change). However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money. Find the amount of money that she will hand to the cashier. Constraints 1 ⊠N < 10000 1 ⊠K < 10 0 ⊠D_1 < D_2 < ⊠< D_KâŠ9 \{D_1,D_2,...,D_K\} â \{1,2,3,4,5,6,7,8,9\} Input The input is given from Standard Input in the following format: N K D_1 D_2 ⊠D_K Output Print the amount of money that Iroha will hand to the cashier. Sample Input 1 1000 8 1 3 4 5 6 7 8 9 Sample Output 1 2000 She dislikes all digits except 0 and 2 . The smallest integer equal to or greater than N=1000 whose decimal notation contains only 0 and 2 , is 2000 . Sample Input 2 9999 1 0 Sample Output 2 9999 | 35,688 |
Score : 500 points Problem Statement Given is a connected undirected graph with N vertices and M edges. The vertices are numbered 1 to N , and the edges are described by a grid of characters S . If S_{i,j} is 1 , there is an edge connecting Vertex i and j ; otherwise, there is no such edge. Determine whether it is possible to divide the vertices into non-empty sets V_1, \dots, V_k such that the following condition is satisfied. If the answer is yes, find the maximum possible number of sets, k , in such a division. Every edge connects two vertices belonging to two "adjacent" sets. More formally, for every edge (i,j) , there exists 1\leq t\leq k-1 such that i\in V_t,j\in V_{t+1} or i\in V_{t+1},j\in V_t holds. Constraints 2 \leq N \leq 200 S_{i,j} is 0 or 1 . S_{i,i} is 0 . S_{i,j}=S_{j,i} The given graph is connected. N is an integer. Input Input is given from Standard Input in the following format: N S_{1,1}...S_{1,N} : S_{N,1}...S_{N,N} Output If it is impossible to divide the vertices into sets so that the condition is satisfied, print -1 . Otherwise, print the maximum possible number of sets, k , in a division that satisfies the condition. Sample Input 1 2 01 10 Sample Output 1 2 We can put Vertex 1 in V_1 and Vertex 2 in V_2 . Sample Input 2 3 011 101 110 Sample Output 2 -1 Sample Input 3 6 010110 101001 010100 101000 100000 010000 Sample Output 3 4 | 35,689 |
Problem G: Japanese Style Pub Youâve just entered a Japanese-style pub, or an izakaya in Japanese, for a drinking party (called nomi-kai ) with your dear friends. Now you are to make orders for glasses of hard and soft drink as requested by the participants. But unfortunately, most staffs in typical izakayas are part-time workers; they are not used to their work so they make mistakes at a certain probability for each order. You are worrying about such mistakes. Today is a happy day for the participants, the dearest friends of yours. Your task is to write a program calculating the probability at which the izakaya staff brings correct drinks for the entire orders. Cases in which the staffâs mistakes result in a correct delivery should be counted into the probability, since those cases are acceptable for you. Input The input consists of multiple test cases. Each test case begins with a line containing an interger N (1 †N †8). The integer N indicates the number of kinds of drinks available in the izakaya . The following N lines specify the probabilities for the drinks in the format shown below. p 11 p 12 . . . p 1 N p 21 p 22 . . . p 2 N ... p N 1 p N 2 . . . p NN Each real number p ij indicates the probability where the staff delivers a glass of the drink j for an order of the drink i . It holds that p ij ⥠0 and p i 1 + p i 2 + . . . + p iN = 1 for 1 †i , j †N . At the end of each test case, a line which contains N comes. The i -th integer n i represents the number of orders for the drink i by the participants (0 †n i †4). The last test case is followed by a line containing a zero. Output For Each test case, print a line containing the test case number (beginning with 1) followed by the natural logarithm of the probability where the staff brings correct drinks for the entire orders. Print the results with eight digits to the right of the decimal point. If the staff cannot bring correct drinks in any case, print â-INFINITYâ instead. Use the format of the sample output. Sample Input 3 0.7 0.1 0.2 0.1 0.8 0.1 0.0 0.0 1.0 4 3 2 8 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 2 2 2 2 2 2 2 2 2 1 0 1 0 2 2 0 Output for the Sample Input Case 1: -1.89723999 Case 2: -8.14438201 Case 3: -INFINITY | 35,690 |
E: Twins Idol / ãã€ã³ãºã¢ã€ãã« ã¢ã€ãã«äºåæ841ãããã¯ã·ã§ã³ã«ã¯ïŒå€ãã®åæ§çãªã¢ã€ãã«éãæå±ããŠããïŒ ååã®ã¢ã€ãã«ã§ããã¢ãïŒããã¯ïŒ841ããã«æå±ããã¢ã€ãã«ã§ããïŒ2人ãšããšãŠãã²ãŒã 奜ãã§ããïŒ ããæ¥2人ã¯ïŒæ¬¡ã®ãããªã²ãŒã ãèªåéã§èªäœããŠæ¥œããããšã«ããïŒ ãã®ã²ãŒã ã¯ïŒ2人ã§ååããã¿ã€ãã®ã²ãŒã ã§ããããïŒååã®æ¯ã®åã£ããã¬ã€ãæåŸ
ãããïŒ ãŸãïŒã²ãŒã ãå§ããåã«ïŒ2人ãå¥ã
ã«èªåã®å¥œããªããã«ãã£ãŒã«ããåºã«æãïŒ ãã£ãŒã«ãã¯ïŒã¢ã«ãã¡ãããã®1æåãæžãããããã€ãã®ããŒããšïŒããŒãéãã€ãªãã«ãŒãã§æ§æãããïŒ åœŒå¥³ãã¯ïŒãã®ã«ãŒãäžã蟿ãããšã§ïŒããŒãéãç§»åã§ããïŒ ãã ãïŒã«ãŒãã«ã¯ç¢å°ãã€ããŠããïŒãã®ç¢å°ã®æ¹åã«åãã£ãŠããç§»åã§ããªãïŒ ã¢ãã®ãã£ãŒã«ããšããã®ãã£ãŒã«ãã®éã«ã«ãŒãã¯ååšããªãããïŒäºãã®ãã£ãŒã«ããè¡ãæ¥ããããšã¯ã§ããªãïŒ ãŸãïŒã¢ããšãããïŒèªåã®ãã£ãŒã«ãå
ã®å¥œããªããŒãã«ç«ã€ãšããããã²ãŒã ãå§ãŸãïŒ ãããŠïŒä»¥äžã®æ±ºãŸãã«åŸã£ãŠïŒ2人ãåæã«è¡åããŠããïŒ 2人ã®ç«ã£ãŠããããŒãã®æåãçããå Žå ã¹ã³ã¢ãšããŠïŒ1ç¹ãåŸãïŒ 2人ã¯çŸåšç«ã£ãŠããããŒããé¢ããŠïŒå¥ã®ããŒãã«ç§»åããªããã°ãªããªãïŒ ãã ãïŒå¥ã®ããŒãã«ç§»åããããšããéïŒ2人ã®å
ã©ã¡ãããç§»åã§ããªãã£ãå ŽåïŒã²ãŒã ãçµäºããïŒ 2人ã®ç«ã£ãŠããããŒãã®æåãç°ãªãå Žå ã¹ã³ã¢ãåŸãããšã¯ã§ããªãïŒ 2人ã¯ããããïŒãçŸåšã®ããŒãã«ãšã©ãŸããããå¥ã®ããŒãã«ç§»åãããããéžæããŠè¡åããïŒ2人ãåãè¡åãåãå¿
èŠã¯ãªãïŒ ãã ãïŒå¥ã®ããŒãã«ç§»åããããšããéïŒç§»åã§ããªãã£ãå ŽåïŒã²ãŒã ãçµäºããïŒ çŸåšä»¥éã®ã¿ãŒã³ã䜿çšããŠïŒçŸåšã®ããŒãããïŒã©ãç§»åããŠãç¹æ°ãå¢ãããªããšã ã²ãŒã ãçµäºããïŒ ã¢ãïŒããã¯ïŒãã®ã²ãŒã ã§ãªãã¹ãé«ãã¹ã³ã¢ãåºããããšèããŠããïŒ 2人ãæå€§ã§ã©ãã ãã®åŸç¹ãååŸã§ãããïŒ841ããã®æ°äººæè
ãããã¥ãŒãµã§ããåãïŒãåŸæã®ããã°ã©ãã³ã°ã«ãã£ãŠè¯éºã«ãã³ããäžããŠããããïŒ Input å
¥åã¯æ¬¡ã®åœ¢åŒã§è¡šãããïŒ AKI_FIELD MAKI_FIELD AKI_FIELD ãš MAKI_FIELD ã¯ïŒããããã¢ããšããã®ãã£ãŒã«ãã衚ãïŒ åãã£ãŒã«ãã®å
¥åã¯ïŒæ¬¡ã®åœ¢åŒã§è¡šãããïŒ N M c 1 c 2, ..., cN a 1 b 1 ... ai bi ... aM bM å
šãŠã®æ°å€ã¯æŽæ°å€ã§ããïŒ N (1 <= N <= 100) ã¯ããŒãã®æ°ã§ããïŒåããŒãã«ã¯ïŒ1, 2, ..., N ã®çªå·ãä»ããŠããïŒ M (0 <= M <= 5000) ã¯ããŒãéã®ã«ãŒãã®æ°ã衚ãïŒ æ¬¡ã®1è¡ã«ã¯ïŒåããŒãã«æžãããŠããæåãïŒããŒã1ããé çªã«ç©ºçœã§åºåãããŠå
¥åãããïŒ åæåã¯ïŒã¢ã«ãã¡ãããã®å°æåã倧æåã®ããããã§ããïŒ å€§æåãšå°æåã¯ïŒå¥ã®æåãšããŠæ±ããªããã°ãªããªãïŒ ç¶ããŠïŒ M è¡ã«ããã£ãŠïŒã«ãŒãæ
å ±ãå
¥åãããïŒ åã«ãŒãã¯ïŒããŒã ai ããããŒã bi ã«åãã£ãŠäŒžã³ãŠãã(1 <= ai , bi <= N )ïŒ ai ãš bi ã¯ç°ãªãå€ã§ããïŒäžåºŠå
¥åãããã«ãŒããïŒåã³å
¥åãããããšã¯ãªãïŒ ãã ãïŒäžåºŠå
¥åãããã«ãŒãã®éæ¹åã®ã«ãŒããå
¥åãããããšã¯ããïŒ Output ã¢ãïŒãããååŸã§ããæå€§ã®åŸç¹ãçããïŒ ãã ãïŒç¡éã«ç¹æ°ãå¢ãããå Žåã¯ïŒ-1ãåºåããïŒ Sample Input 1 5 5 a c b c a 1 2 1 3 2 3 3 4 3 5 4 3 b a c c 1 3 2 3 3 4 Sample Output 1 3 Sample Input 2 2 2 a b 1 2 2 1 4 3 a b a b 1 2 2 3 3 4 Sample Output 2 4 Sample Input 3 3 3 Y Y I 1 2 2 3 3 1 3 3 I O R 1 3 3 2 2 1 Sample Output 3 -1 | 35,691 |
Problem B: Stylish Stylish is a programming language whose syntax comprises names , that are sequences of Latin alphabet letters, three types of grouping symbols , periods ('.'), and newlines. Grouping symbols, namely round brackets ('(' and ')'), curly brackets ('{' and '}'), and square brackets ('[' and ']'), must match and be nested properly. Unlike most other programming languages, Stylish uses periods instead of whitespaces for the purpose of term separation. The following is an example of a Stylish program. 1 ( Welcome .to 2 ......... Stylish ) 3 { Stylish .is 4 .....[.( a. programming . language .fun .to. learn ) 5 .......] 6 ..... Maybe .[ 7 ....... It. will .be.an. official . ICPC . language 8 .......] 9 .....} As you see in the example, a Stylish program is indented by periods. The amount of indentation of a line is the number of leading periods of it. Your mission is to visit Stylish masters, learn their indentation styles, and become the youngest Stylish master. An indentation style for well-indented Stylish programs is defined by a triple of integers, ( R , C , S ), satisfying 1 †R , C , S †20. R , C and S are amounts of indentation introduced by an open round bracket, an open curly bracket, and an open square bracket, respectively. In a well-indented program, the amount of indentation of a line is given by R ( r o â r c ) + C ( c o â c c ) + S ( s o â s c ), where r o , c o , and s o are the numbers of occurrences of open round, curly, and square brackets in all preceding lines, respectively, and r c , c c , and s c are those of close brackets. The first line has no indentation in any well-indented program. The above example is formatted in the indentation style ( R , C , S ) = (9, 5, 2). The only grouping symbol occurring in the first line of the above program is an open round bracket. Therefore the amount of indentation for the second line is 9 · (1 â 0) + 5 · (0 â 0) + 2 ·(0 â 0) = 9. The first four lines contain two open round brackets, one open curly bracket, one open square bracket, two close round brackets, but no close curly nor square bracket. Therefore the amount of indentation for the fifth line is 9 · (2 â 2) + 5 · (1 â 0) + 2 · (1 â 0) = 7. Stylish masters write only well-indented Stylish programs. Every master has his/her own indentation style. Write a program that imitates indentation styles of Stylish masters. Input The input consists of multiple datasets. The first line of a dataset contains two integers p (1 †p †10) and q (1 †q †10). The next p lines form a well-indented program P written by a Stylish master and the following q lines form another program Q . You may assume that every line of both programs has at least one character and at most 80 characters. Also, you may assume that no line of Q starts with a period. The last dataset is followed by a line containing two zeros. Output Apply the indentation style of P to Q and output the appropriate amount of indentation for each line of Q . The amounts must be output in a line in the order of corresponding lines of Q and they must be separated by a single space. The last one should not be followed by trailing spaces. If the appropriate amount of indentation of a line of Q cannot be determined uniquely through analysis of P , then output -1 for that line. Sample Input 5 4 (Follow.my.style .........starting.from.round.brackets) {then.curly.brackets .....[.and.finally .......square.brackets.]} (Thank.you {for.showing.me [all the.secrets]}) 4 2 (This.time.I.will.show.you .........(how.to.use.round.brackets) .........[but.not.about.square.brackets] .........{nor.curly.brackets}) (I.learned how.to.use.round.brackets) 4 2 (This.time.I.will.show.you .........(how.to.use.round.brackets) .........[but.not.about.square.brackets] .........{nor.curly.brackets}) [I.have.not.learned how.to.use.square.brackets] 2 2 (Be.smart.and.let.fear.of ..(closed.brackets).go) (A.pair.of.round.brackets.enclosing [A.line.enclosed.in.square.brackets]) 1 2 Telling.you.nothing.but.you.can.make.it [One.liner.(is).(never.indented)] [One.liner.(is).(never.indented)] 2 4 ([{Learn.from.my.KungFu ...}]) (( {{ [[ ]]}})) 1 2 Do.not.waste.your.time.trying.to.read.from.emptiness ( ) 2 3 ({Quite.interesting.art.of.ambiguity ....}) { ( )} 2 4 ({[ ............................................................]}) ( { [ ]}) 0 0 Output for the Sample Input 0 9 14 16 0 9 0 -1 0 2 0 0 0 2 4 6 0 -1 0 -1 4 0 20 40 60 | 35,692 |
Score : 600 points Problem Statement Given are integers L and R . Find the number, modulo 10^9 + 7 , of pairs of integers (x, y) (L \leq x \leq y \leq R) such that the remainder when y is divided by x is equal to y \mbox{ XOR } x . What is \mbox{ XOR } ? The XOR of integers A and B , A \mbox{ XOR } B , is defined as follows: When A \mbox{ XOR } B is written in base two, the digit in the 2^k 's place ( k \geq 0 ) is 1 if either A or B , but not both, has 1 in the 2^k 's place, and 0 otherwise. For example, 3 \mbox{ XOR } 5 = 6 . (In base two: 011 \mbox{ XOR } 101 = 110 .) Constraints 1 \leq L \leq R \leq 10^{18} Input Input is given from Standard Input in the following format: L R Output Print the number of pairs of integers (x, y) (L \leq x \leq y \leq R) satisfying the condition, modulo 10^9 + 7 . Sample Input 1 2 3 Sample Output 1 3 Three pairs satisfy the condition: (2, 2) , (2, 3) , and (3, 3) . Sample Input 2 10 100 Sample Output 2 604 Sample Input 3 1 1000000000000000000 Sample Output 3 68038601 Be sure to compute the number modulo 10^9 + 7 . | 35,693 |
Intersection of a Circle and a Polygon Find the area of intersection between a circle $c$ and a polygon $g$. The center coordinate of the circle is ($0, 0$). The polygon $g$ is represented by a sequence of points $p_1$, $p_2$,..., $p_n$ where line segments connecting $p_i$ and $p_{i+1}$ ($1 \leq i \leq nâ1$) are sides of the polygon. The line segment connecting $p_n$ and $p_1$ is also a side of the polygon. Note that the polygon is not necessarily convex. Input The input is given in the following format. $n$ $r$ $x_1$ $y_1$ $x_2$ $y_2$ : $x_n$ $y_n$ In the first line, an integer n representing the number of points in the polygon is given. The coordinate of a point $p_i$ is given by two integers $x_i$ and $y_i$. The coordinates of the points are given in the order of counter-clockwise visit of them. All input values are given in integers. Constraints $3 \leq n \leq 100$ $1 \leq r \leq 100$ $-100 \leq x_i, y_i \leq 100$ Output Print the area of intersection in a line. The output values should be in a decimal fraction with an error less than 0.00001. Sample Input 1 3 5 1 1 4 1 5 5 Sample Output 1 4.639858417607 Sample Input 2 4 5 0 0 -3 -6 1 -3 5 -4 Sample Output 2 11.787686807576 | 35,694 |
埮çç©çºé» 飯沌å士ã¯ç£æ¢¯å±±ã®åŽæ°åã§ãµãããªåŸ®çç©ãèŠã€ããŸããããã®åŸ®çç©ã®éãšéïŒäœãã€ãåäœãããšã黿°ãšãã«ã®ãŒãæŸåºããŸãããã®åŸ®çç©ãç ç©¶ããã°ãå°æ¥ã®ãšãã«ã®ãŒå±æ©ããæã
ãæãããããããŸããã 芳å¯ãç¶ãããšã埮çç©ã¯åäœãããšãã ã黿°ãšãã«ã®ãŒãçºçãããããšãšãåäœãã埮çç©ã®ãããªãåäœã¯ãªãããšãããããŸãããããã«èгå¯ãç¶ãããšãåäœã§æŸåºããã黿°ãšãã«ã®ãŒã¯ã埮çç©ãäœå
ã«æã€æªç¥ã®ç²åïŒå士ã¯ãããç£æ¢¯å±±ã«ã¡ãªãã§ïŒ¢ç²åãšåã¥ããŸããïŒã®éã§æ±ºãŸãããšãããããŸãããåäœããéãšéãäœå
ã«æã€ïŒ¢ç²åã®éããããã bm ãš bw ãšãããšãåäœã«ããæŸåºããã黿°ãšãã«ã®ãŒã¯ | bm - bw | à (| bm - bw | - 30) 2 ãšããåŒã§èšç®ã§ããŸãã ãã®çºèŠã«ããã埮çç©ã®éå£ããåŸãããæå€§ã®é»æ°ãšãã«ã®ãŒãèšç®ã§ããããã«ãªããŸãããããã§ã¯ã埮çç©ã®éå£ã«å«ãŸããéãšéã®æ°ãšãååäœãæã€ïŒ¢ç²åã®éãäžãããããšãããã®åŸ®çç©ã®éå£ããåŸãããæå€§ã®é»æ°ãšãã«ã®ãŒãèšç®ããããã°ã©ã ãäœæããŠãã ããã å
¥å å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªããå
¥åã®çµããã¯ãŒã2ã€ã®è¡ã§ç€ºããããå
¥åããŒã¿ã¯ä»¥äžã®åœ¢åŒã§äžããããã M W bm 1 bm 2 ... bm M bw 1 bw 2 ... bw W ïŒè¡ç®ã® M ãš W (1 †M,W †12) ã¯ããããéãšéã®åŸ®çç©ã®æ°ã§ãããïŒè¡ç®ã«ã i çªç®ã®éãäœå
ã«æã€ïŒ¢ç²åã®é bm i (0 †bm i †50) ãäžãããããïŒè¡ç®ã«ã i çªç®ã®éãäœå
ã«æã€ïŒ¢ç²åã®é bw i (0 †bw i †50) ãäžããããã ããŒã¿ã»ããã®æ°ã¯ 20 ãè¶
ããªãã åºå ããŒã¿ã»ããããšã«ã埮çç©ã®éå£ããåŸããã黿°ãšãã«ã®ãŒã®æå€§å€ã1è¡ã«åºåããã å
¥åºåäŸ å
¥åäŸ 3 3 0 20 30 10 20 30 10 10 32 10 15 8 20 10 6 45 50 41 18 0 37 25 45 11 25 21 32 27 7 3 23 14 39 6 47 16 23 19 37 8 0 0 åºåäŸ 12000 53906 11629 | 35,695 |
Score : 900 points Problem Statement Joisino has a formula consisting of N terms: A_1 op_1 A_2 ... op_{N-1} A_N . Here, A_i is an integer, and op_i is an binary operator either + or - . Because Joisino loves large numbers, she wants to maximize the evaluated value of the formula by inserting an arbitrary number of pairs of parentheses (possibly zero) into the formula. Opening parentheses can only be inserted immediately before an integer, and closing parentheses can only be inserted immediately after an integer. It is allowed to insert any number of parentheses at a position. Your task is to write a program to find the maximum possible evaluated value of the formula after inserting an arbitrary number of pairs of parentheses. Constraints 1âŠNâŠ10^5 1âŠA_iâŠ10^9 op_i is either + or - . Input The input is given from Standard Input in the following format: N A_1 op_1 A_2 ... op_{N-1} A_N Output Print the maximum possible evaluated value of the formula after inserting an arbitrary number of pairs of parentheses. Sample Input 1 3 5 - 1 - 3 Sample Output 1 7 The maximum possible value is: 5 - (1 - 3) = 7 . Sample Input 2 5 1 - 2 + 3 - 4 + 5 Sample Output 2 5 The maximum possible value is: 1 - (2 + 3 - 4) + 5 = 5 . Sample Input 3 5 1 - 20 - 13 + 14 - 5 Sample Output 3 13 The maximum possible value is: 1 - (20 - (13 + 14) - 5) = 13 . | 35,696 |
Score : 200 points Problem Statement We have a board with H horizontal rows and W vertical columns of squares. There is a bishop at the top-left square on this board. How many squares can this bishop reach by zero or more movements? Here the bishop can only move diagonally. More formally, the bishop can move from the square at the r_1 -th row (from the top) and the c_1 -th column (from the left) to the square at the r_2 -th row and the c_2 -th column if and only if exactly one of the following holds: r_1 + c_1 = r_2 + c_2 r_1 - c_1 = r_2 - c_2 For example, in the following figure, the bishop can move to any of the red squares in one move: Constraints 1 \leq H, W \leq 10^9 All values in input are integers. Input Input is given from Standard Input in the following format: H \ W Output Print the number of squares the bishop can reach. Sample Input 1 4 5 Sample Output 1 10 The bishop can reach the cyan squares in the following figure: Sample Input 2 7 3 Sample Output 2 11 The bishop can reach the cyan squares in the following figure: Sample Input 3 1000000000 1000000000 Sample Output 3 500000000000000000 | 35,697 |
Score : 300 points Problem Statement Joisino is planning to open a shop in a shopping street. Each of the five weekdays is divided into two periods, the morning and the evening. For each of those ten periods, a shop must be either open during the whole period, or closed during the whole period. Naturally, a shop must be open during at least one of those periods. There are already N stores in the street, numbered 1 through N . You are given information of the business hours of those shops, F_{i,j,k} . If F_{i,j,k}=1 , Shop i is open during Period k on Day j (this notation is explained below); if F_{i,j,k}=0 , Shop i is closed during that period. Here, the days of the week are denoted as follows. Monday: Day 1 , Tuesday: Day 2 , Wednesday: Day 3 , Thursday: Day 4 , Friday: Day 5 . Also, the morning is denoted as Period 1 , and the afternoon is denoted as Period 2 . Let c_i be the number of periods during which both Shop i and Joisino's shop are open. Then, the profit of Joisino's shop will be P_{1,c_1}+P_{2,c_2}+...+P_{N,c_N} . Find the maximum possible profit of Joisino's shop when she decides whether her shop is open during each period, making sure that it is open during at least one period. Constraints 1â€Nâ€100 0â€F_{i,j,k}â€1 For every integer i such that 1â€iâ€N , there exists at least one pair (j,k) such that F_{i,j,k}=1 . -10^7â€P_{i,j}â€10^7 All input values are integers. Input Input is given from Standard Input in the following format: N F_{1,1,1} F_{1,1,2} ... F_{1,5,1} F_{1,5,2} : F_{N,1,1} F_{N,1,2} ... F_{N,5,1} F_{N,5,2} P_{1,0} ... P_{1,10} : P_{N,0} ... P_{N,10} Output Print the maximum possible profit of Joisino's shop. Sample Input 1 1 1 1 0 1 0 0 0 1 0 1 3 4 5 6 7 8 9 -2 -3 4 -2 Sample Output 1 8 If her shop is open only during the periods when Shop 1 is opened, the profit will be 8 , which is the maximum possible profit. Sample Input 2 2 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1 0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1 Sample Output 2 -2 Note that a shop must be open during at least one period, and the profit may be negative. Sample Input 3 3 1 1 1 1 1 1 0 0 1 1 0 1 0 1 1 1 1 0 1 0 1 0 1 1 0 1 0 1 0 1 -8 6 -2 -8 -8 4 8 7 -6 2 2 -9 2 0 1 7 -5 0 -2 -6 5 5 6 -6 7 -9 6 -5 8 0 -9 -7 -7 Sample Output 3 23 | 35,698 |
Problem I: ThreeRooks ããããã§ã¹ã®ç·Žç¿ãããŠãã. ããã¯, $X \times Y$ ã®ãã§ã¹ç€ã®äžã«ã«ãŒã¯ã 3 ã€çœ®ãããšããŠãã. ãã®ãã§ã¹ç€ã® $K$ åã®ãã¹ç®ã«ã¯ãããã座ã£ãŠãã. $i$ å¹ç®ã®ãããã®åº§æšã¯ $(x[i], y[i])$ ã§ãã. ãã ã, ãã§ã¹ç€ã®å·Šäžç«¯ã®ãã¹ç®ã®åº§æšã $(0, 0)$, å³äžç«¯ã®ãã¹ç®ã®åº§æšã $(X-1, Y-1)$ ãšããããããã座ã£ãŠããå Žæã«ã¯ã«ãŒã¯ã眮ãããšãã§ããªã. ãŸã, 1 ã€ã®ãã¹ç®ã«è€æ°åã®ã«ãŒã¯ã眮ãããšã¯ã§ããªã. ã©ã® 2 ã€ã®ã«ãŒã¯ãäºãã«æ»æãåããªãããã«ã«ãŒã¯ã3 ã€çœ®ãæ¹æ³ã¯äœéãããã, mod 1,000,000,007 ã§æ±ãã. 2 ã€ã®ã«ãŒã¯ã¯åãè¡ãŸãã¯åãåã«ãã, éã«ãããã座ã£ãŠããªãå Žåã«äºãã«æ»æããããã®ãšãã. Constraints $X$, $Y$ will be between 1 and 1,000,000,000, inclusive. $K$ will be between 1 and 100,000, inclusive. $x_i$ will be between 0 and $X-1$, inclusive. $y_i$ will be between 0 and $Y-1$, inclusive. No two rabbits sit on the same cell. Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžãããã: $X$ $Y$ $K$ $x_1$ $y_1$ ... $x_K$ $y_K$ Output ã«ãŒã¯ã®é
眮ã®åæ°ã 1,000,000,007 ã§å²ã£ãããŸããè¡šãæŽæ°ã 1 è¡ã«åºåãã. Sample Input 1 3 3 1 0 0 Sample Output 1 4 Sample Input 2 5 8 2 2 2 4 5 Sample Output 2 3424 | 35,699 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.