task stringlengths 0 154k | __index_level_0__ int64 0 39.2k |
|---|---|
Binary Search Tree I Search trees are data structures that support dynamic set operations including insert, search, delete and so on. Thus a search tree can be used both as a dictionary and as a priority queue. Binary search tree is one of fundamental search trees. The keys in a binary search tree are always stored in such a way as to satisfy the following binary search tree property: Let $x$ be a node in a binary search tree. If $y$ is a node in the left subtree of $x$, then $y.key \leq x.key$. If $y$ is a node in the right subtree of $x$, then $x.key \leq y.key$. The following figure shows an example of the binary search tree. For example, keys of nodes which belong to the left sub-tree of the node containing 80 are less than or equal to 80, and keys of nodes which belong to the right sub-tree are more than or equal to 80. The binary search tree property allows us to print out all the keys in the tree in sorted order by an inorder tree walk. A binary search tree should be implemented in such a way that the binary search tree property continues to hold after modifications by insertions and deletions. A binary search tree can be represented by a linked data structure in which each node is an object. In addition to a key field and satellite data, each node contains fields left , right , and p that point to the nodes corresponding to its left child, its right child, and its parent, respectively. To insert a new value $v$ into a binary search tree $T$, we can use the procedure insert as shown in the following pseudo code. The insert procedure is passed a node $z$ for which $z.key = v$, $z.left = NIL$, and $z.right = NIL$. The procedure modifies $T$ and some of the fields of $z$ in such a way that $z$ is inserted into an appropriate position in the tree. 1 insert(T, z) 2 y = NIL // parent of x 3 x = 'the root of T' 4 while x â NIL 5 y = x // set the parent 6 if z.key < x.key 7 x = x.left // move to the left child 8 else 9 x = x.right // move to the right child 10 z.p = y 11 12 if y == NIL // T is empty 13 'the root of T' = z 14 else if z.key < y.key 15 y.left = z // z is the left child of y 16 else 17 y.right = z // z is the right child of y Write a program which performs the following operations to a binary search tree $T$. insert $k$: Insert a node containing $k$ as key into $T$. print : Print the keys of the binary search tree by inorder tree walk and preorder tree walk respectively. You should use the above pseudo code to implement the insert operation. $T$ is empty at the initial state. Input In the first line, the number of operations $m$ is given. In the following $m$ lines, operations represented by insert $k$ or print are given. Output For each print operation, print a list of keys obtained by inorder tree walk and preorder tree walk in a line respectively. Put a space character before each key . Constraints The number of operations $\leq 500,000$ The number of print operations $\leq 10$. $-2,000,000,000 \leq key \leq 2,000,000,000$ The height of the binary tree does not exceed 100 if you employ the above pseudo code. The keys in the binary search tree are all different. Sample Input 1 8 insert 30 insert 88 insert 12 insert 1 insert 20 insert 17 insert 25 print Sample Output 1 1 12 17 20 25 30 88 30 12 1 20 17 25 88 Reference Introduction to Algorithms, Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. The MIT Press. | 35,901 |
Score : 300 points Problem Statement Given is a sequence of integers A_1, A_2, ..., A_N . If its elements are pairwise distinct, print YES ; otherwise, print NO . Constraints 2 †N †200000 1 †A_i †10^9 All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 ... A_N Output If the elements of the sequence are pairwise distinct, print YES ; otherwise, print NO . Sample Input 1 5 2 6 1 4 5 Sample Output 1 YES The elements are pairwise distinct. Sample Input 2 6 4 1 3 1 6 2 Sample Output 2 NO The second and fourth elements are identical. Sample Input 3 2 10000000 10000000 Sample Output 3 NO | 35,902 |
Problem E: Cards There are many blue cards and red cards on the table. For each card, an integer number greater than 1 is printed on its face. The same number may be printed on several cards. A blue card and a red card can be paired when both of the numbers printed on them have a common divisor greater than 1. There may be more than one red card that can be paired with one blue card. Also, there may be more than one blue card that can be paired with one red card. When a blue card and a red card are chosen and paired, these two cards are removed from the whole cards on the table. Figure E-1: Four blue cards and three red cards For example, in Figure E-1, there are four blue cards and three red cards. Numbers 2, 6, 6 and 15 are printed on the faces of the four blue cards, and 2, 3 and 35 are printed on those of the three red cards. Here, you can make pairs of blue cards and red cards as follows. First, the blue card with number 2 on it and the red card with 2 are paired and removed. Second, one of the two blue cards with 6 and the red card with 3 are paired and removed. Finally, the blue card with 15 and the red card with 35 are paired and removed. Thus the number of removed pairs is three. Note that the total number of the pairs depends on the way of choosing cards to be paired. The blue card with 15 and the red card with 3 might be paired and removed at the beginning. In this case, there are only one more pair that can be removed and the total number of the removed pairs is two. Your job is to find the largest number of pairs that can be removed from the given set of cards on the table. Input The input is a sequence of datasets. The number of the datasets is less than or equal to 100. Each dataset is formatted as follows. m n b 1 ... b k ... b m r 1 ... r k ... r n The integers m and n are the number of blue cards and that of red cards, respectively. You may assume 1 †m †500 and 1†n †500. b k (1 †k †m ) and r k (1 †k †n ) are numbers printed on the blue cards and the red cards respectively, that are integers greater than or equal to 2 and less than 10000000 (=10 7 ). The input integers are separated by a space or a newline. Each of b m and r n is followed by a newline. There are no other characters in the dataset. The end of the input is indicated by a line containing two zeros separated by a space. Output For each dataset, output a line containing an integer that indicates the maximum of the number of the pairs. Sample Input 4 3 2 6 6 15 2 3 5 2 3 4 9 8 16 32 4 2 4 9 11 13 5 7 5 5 2 3 5 1001 1001 7 11 13 30 30 10 10 2 3 5 7 9 11 13 15 17 29 4 6 10 14 18 22 26 30 34 38 20 20 195 144 903 63 137 513 44 626 75 473 876 421 568 519 755 840 374 368 570 872 363 650 155 265 64 26 426 391 15 421 373 984 564 54 823 477 565 866 879 638 100 100 195 144 903 63 137 513 44 626 75 473 876 421 568 519 755 840 374 368 570 872 363 650 155 265 64 26 426 391 15 421 373 984 564 54 823 477 565 866 879 638 117 755 835 683 52 369 302 424 513 870 75 874 299 228 140 361 30 342 750 819 761 123 804 325 952 405 578 517 49 457 932 941 988 767 624 41 912 702 241 426 351 92 300 648 318 216 785 347 556 535 166 318 434 746 419 386 928 996 680 975 231 390 916 220 933 319 37 846 797 54 272 924 145 348 350 239 563 135 362 119 446 305 213 879 51 631 43 755 405 499 509 412 887 203 408 821 298 443 445 96 274 715 796 417 839 147 654 402 280 17 298 725 98 287 382 923 694 201 679 99 699 188 288 364 389 694 185 464 138 406 558 188 897 354 603 737 277 35 139 556 826 213 59 922 499 217 846 193 416 525 69 115 489 355 256 654 49 439 118 961 0 0 Output for the Sample Input 3 1 0 4 9 18 85 | 35,903 |
E : å°é¢š / Typhoon å顿 ååæ¹åã« H ïŒæ±è¥¿æ¹åã« W ã®å€§ããã®çºãããïŒ çºã«ã¯äžèŸºã®é·ãã 1 ã®æ£æ¹åœ¢ã®åºç»ã«ééãªãæŽåãããŠããïŒå
šãŠã®åºç»ã« 1 è»ãã€å®¶ã建ã£ãŠããïŒ ãã®çºã®ããåºç»ã®äžç©ºã§å°é¢šãçºçãïŒè¢«å®³ãäžããåŸïŒããåºç»ã®äžç©ºã§æž©åž¯äœæ°å§ã«å€åããïŒ å€åããåŸã¯è¢«å®³ãäžããªãïŒ äžå³ã®ããã«ïŒå°é¢šã¯é«ã 3 , å¹
3 ã®æ£æ¹åœ¢ã§ããïŒ â
ã®ã€ãããã¹ãäžå¿ãšåŒã¶ããšã«ããïŒå°é¢šã¯ 8 è¿åã«åºç»åäœã§ç§»åããïŒ ã€ãŸãïŒå°é¢šã®äžå¿ã¯èŸºãŸãã¯é ç¹ãå
±æããåºç»(çŸåšã®åºç»ãå«ã)ã«ç§»ãããã«ïŒå
šäœã䌎ã£ãŠç§»åããïŒ ãã ãïŒçºã®å€ã«å°é¢šãã¯ã¿åºãããšã¯ãªãïŒ å°é¢šã®äžå¿ã¯ïŒäžã®å³ã®ç¶²æãã®ããã«ïŒåãã 0 çªç®ãš H â 1 çªç®ïŒè¥¿ãã 0 çªç®ãš W â 1 çªç®ã®åºéã¯éããªãããã«ç§»åããïŒ å®¶ã¯å°é¢šãäžåºŠäžç©ºã«æ¥ããšïŒä»¥äžã®ããã«è¢«å®³ã®çšåºŠãå€åããïŒ æå£ãã· â äžéšæå£ â åå£ â å
šå£ â 跡圢ãã· ã ãïŒå¹žã跡圢ãã·ãšãªã£ãå®¶ã¯ç¡ãã£ãããã ïŒ åå®¶ã®è¢«å®³ã®ç¶æ³ãäžããããã®ã§ïŒå°é¢šãçºçããå°ç¹ãšïŒæž©åž¯äœæ°å§ã«å€åããå°ç¹ãæ±ããïŒ ãã ãïŒçºçããåºç»ãåãã s_i çªç®ïŒè¥¿ãã s_j çªç®ïŒ æž©åž¯äœæ°å§ã«å€åããåºç»ãåãã t_i çªç®ïŒè¥¿ãã t_j çªç®ãšãããšïŒ 2 ã€ã®å°ç¹ã¯ 10000 t_i + t_j †10000 s_i + s_j ãæºããããã«å®ãŸãïŒ å
¥å H \ W D_{11} \ ⊠\ D_{1W} D_{21} \ ⊠\ D_{2W} ⊠D_{H1} \ ⊠\ D_{HW} D_{ij} ã¯åãã i çªç®ïŒ 西ãã j çªç®ã®å®¶ã®è¢«å®³ã®çšåºŠã以äžã®ããã«è¡šãæŽæ°ã§ããïŒ 0 : æå£ãã· 1 : äžéšæå£ 2 : åå£ 3 : å
šå£ å¶çŽ æŽæ°ã§ãã å
¥åã¯çããäžæã«å®ãŸããããªãã®ã®ã¿äžãããã 3 †H,W †500 0 †D_{ij} †3 åºå çãã以äžã®ããã« 1 è¡ã§åºåããïŒ s_i \ s_j \ t_i \ t_j ãµã³ãã« ãµã³ãã«å
¥å1 7 5 0 0 0 0 0 0 1 1 1 0 0 2 2 2 0 0 3 3 3 0 0 2 2 2 0 0 1 1 1 0 0 0 0 0 0 ãµã³ãã«åºå1 4 2 2 2 ãµã³ãã«å
¥å2 6 6 0 0 0 1 1 1 0 0 0 2 2 2 0 0 1 3 3 2 1 2 3 3 2 1 1 2 3 2 1 0 1 2 2 1 0 0 ãµã³ãã«åºå2 4 1 1 4 ãµã³ãã«å
¥å3 4 4 2 2 2 0 2 2 2 0 2 2 2 0 0 0 0 0 ãµã³ãã«åºå3 1 1 1 1 | 35,904 |
Billiards Sorting Rotation is one of several popular pocket billiards games. It uses 15 balls numbered from 1 to 15, and set them up as illustrated in the following figure at the beginning of a game. (Note: the ball order is modified from real-world Rotation rules for simplicity of the problem.) [ 1] [ 2][ 3] [ 4][ 5][ 6] [ 7][ 8][ 9][10] [11][12][13][14][15] You are an engineer developing an automatic billiards machine. For the first step you had to build a machine that sets up the initial condition. This project went well, and finally made up a machine that could arrange the balls in the triangular shape. However, unfortunately, it could not place the balls in the correct order. So now you are trying to build another machine that fixes the order of balls by swapping them. To cut off the cost, it is only allowed to swap the ball #1 with its neighboring balls that are not in the same row. For example, in the case below, only the following pairs can be swapped: (1,2), (1,3), (1,8), and (1,9). [ 5] [ 2][ 3] [ 4][ 1][ 6] [ 7][ 8][ 9][10] [11][12][13][14][15] Write a program that calculates the minimum number of swaps required. Input The first line of each test case has an integer N ( 1 \leq N \leq 5 ), which is the number of the rows. The following N lines describe how the balls are arranged by the first machine; the i -th of them consists of exactly i integers, which are the ball numbers. The input terminates when N = 0. Your program must not output for this case. Output For each test case, print its case number and the minimum number of swaps. You can assume that any arrangement can be fixed by not more than 45 swaps. Sample Input 2 3 2 1 4 9 2 4 8 5 3 7 1 6 10 0 Output for the Sample Input Case 1: 1 Case 2: 13 | 35,905 |
Score : 1000 points Problem Statement Select any integer N between 1000 and 2000 (inclusive), and any integer K not less than 1 , then solve the problem below. Problem We have N sheets of paper. Write K integers on each of them to satisfy the following conditions: Each integer written must be between 1 and N (inclusive). The K integers written on the same sheet must be all different. Each of the integers between 1 and N must be written on exactly K sheets. For any two sheet, there is exactly one integer that appears on both. Input There is no input in this problem. Output In the first line, print N and K separated by a space. In the subsequent N lines, print your solution. The i -th of these lines must contain the K integers written on the i -th sheet, with spaces in between. Sample Output 3 2 1 2 2 3 3 1 This is an example of a solution for N = 3 and K = 2 . Note that this output will be judged as incorrect, since the constraint on N is not satisfied. | 35,906 |
Score : 800 points Problem Statement There is a tree with N vertices. The vertices are numbered 1 through N . The i -th edge ( 1 \leq i \leq N - 1 ) connects Vertex x_i and y_i . For vertices v and w ( 1 \leq v, w \leq N ), we will define the distance between v and w d(v, w) as "the number of edges contained in the path v - w ". A squirrel lives in each vertex of the tree. They are planning to move, as follows. First, they will freely choose a permutation of (1, 2, ..., N) , p = (p_1, p_2, ..., p_N) . Then, for each 1 \leq i \leq N , the squirrel that lived in Vertex i will move to Vertex p_i . Since they like long travels, they have decided to maximize the total distance they traveled during the process. That is, they will choose p so that d(1, p_1) + d(2, p_2) + ... + d(N, p_N) will be maximized. How many such ways are there to choose p , modulo 10^9 + 7 ? Constraints 2 \leq N \leq 5,000 1 \leq x_i, y_i \leq N The input graph is a tree. Input Input is given from Standard Input in the following format: N x_1 y_1 x_2 y_2 : x_{N - 1} y_{N - 1} Output Print the number of the ways to choose p so that the condition is satisfied, modulo 10^9 + 7 . Sample Input 1 3 1 2 2 3 Sample Output 1 3 The maximum possible distance traveled by squirrels is 4 . There are three choices of p that achieve it, as follows: (2, 3, 1) (3, 1, 2) (3, 2, 1) Sample Input 2 4 1 2 1 3 1 4 Sample Output 2 11 The maximum possible distance traveled by squirrels is 6 . For example, p = (2, 1, 4, 3) achieves it. Sample Input 3 6 1 2 1 3 1 4 2 5 2 6 Sample Output 3 36 Sample Input 4 7 1 2 6 3 4 5 1 7 1 5 2 3 Sample Output 4 396 | 35,907 |
Problem A: Ruins In 1936, a dictator Hiedler who aimed at world domination had a deep obsession with the Lost Ark . A person with this ark would gain mystic power according to legend. To break the ambition of the dictator, ACM (the Alliance of Crusaders against Mazis) entrusted a secret task to an archeologist Indiana Johns. Indiana stepped into a vast and harsh desert to find the ark. Indiana finally found an underground treasure house at a ruin in the desert. The treasure house seems storing the ark. However, the door to the treasure house has a special lock, and it is not easy to open the door. To open the door, he should solve a problem raised by two positive integers a and b inscribed on the door. The problem requires him to find the minimum sum of squares of differences for all pairs of two integers adjacent in a sorted sequence that contains four positive integers a 1 , a 2 , b 1 and b 2 such that a = a 1 a 2 and b = b 1 b 2 . Note that these four integers does not need to be different. For instance, suppose 33 and 40 are inscribed on the door, he would have a sequence 3, 5, 8, 11 as 33 and 40 can be decomposed into 3 Ã 11 and 5 Ã 8 respectively. This sequence gives the sum (5 - 3) 2 + (8 - 5) 2 + (11 - 8) 2 = 22, which is the smallest sum among all possible sorted sequences. This example is included as the first data set in the sample input. Once Indiana fails to give the correct solution, he will suffer a calamity by a curse. On the other hand, he needs to solve the problem as soon as possible, since many pawns under Hiedler are also searching for the ark, and they might find the same treasure house. He will be immediately killed if this situation happens. So he decided to solve the problem by your computer program. Your task is to write a program to solve the problem presented above. Input The input consists of a series of data sets. Each data set is given by a line that contains two positive integers not greater than 10,000. The end of the input is represented by a pair of zeros, which should not be processed. Output For each data set, print a single integer that represents the minimum square sum in a line. No extra space or text should appear. Sample Input 33 40 57 144 0 0 Output for the Sample Input 22 94 | 35,908 |
Score : 100 points Problem Statement Let N be a positive odd number. There are N coins, numbered 1, 2, \ldots, N . For each i ( 1 \leq i \leq N ), when Coin i is tossed, it comes up heads with probability p_i and tails with probability 1 - p_i . Taro has tossed all the N coins. Find the probability of having more heads than tails. Constraints N is an odd number. 1 \leq N \leq 2999 p_i is a real number and has two decimal places. 0 < p_i < 1 Input Input is given from Standard Input in the following format: N p_1 p_2 \ldots p_N Output Print the probability of having more heads than tails. The output is considered correct when the absolute error is not greater than 10^{-9} . Sample Input 1 3 0.30 0.60 0.80 Sample Output 1 0.612 The probability of each case where we have more heads than tails is as follows: The probability of having (Coin 1, Coin 2, Coin 3) = (Head, Head, Head) is 0.3 Ã 0.6 Ã 0.8 = 0.144 ; The probability of having (Coin 1, Coin 2, Coin 3) = (Tail, Head, Head) is 0.7 Ã 0.6 Ã 0.8 = 0.336 ; The probability of having (Coin 1, Coin 2, Coin 3) = (Head, Tail, Head) is 0.3 Ã 0.4 Ã 0.8 = 0.096 ; The probability of having (Coin 1, Coin 2, Coin 3) = (Head, Head, Tail) is 0.3 Ã 0.6 Ã 0.2 = 0.036 . Thus, the probability of having more heads than tails is 0.144 + 0.336 + 0.096 + 0.036 = 0.612 . Sample Input 2 1 0.50 Sample Output 2 0.5 Outputs such as 0.500 , 0.500000001 and 0.499999999 are also considered correct. Sample Input 3 5 0.42 0.01 0.42 0.99 0.42 Sample Output 3 0.3821815872 | 35,909 |
æå€§å
¬çŽæ°-ãŠãŒã¯ãªããã®äºé€æ³ æå€§å
¬çŽæ°ã¯ãã³ã³ãã¥ãŒã¿äžã§æ±ãæ°åŠã«ã¯æ¬ ãããªãèŠçŽ ã§ããæå€§å
¬çŽ æ°ã䜿ãããšã§ãèšç®ã®å¹çã倧ããå€åããããšããããŸããæå€§å
¬çŽæ°ãæ±ããã¢ã«ãŽãªãºã ã®ã²ãšã€ãããŠãŒã¯ãªããã®äºé€æ³ãã§ãããã®åŠç ã®æµãã以äžã«ç€ºããŸãã äŸãã° 1071 ãš 1029 ã®å Žåã1071 ã X ã1029 ã Y ã«ä»£å
¥ããŠã 1071 ÷ 1029 ã®äœã㯠42 ã X ã« 42 ã代å
¥ã㊠X ãš Y ãå
¥ãæ¿ããã (1 ã¹ããã) 1029 ÷ 42 ã®äœã㯠21 ã X ã« 21 ã代å
¥ã㊠X ãš Y ãå
¥ãæ¿ããã (2 ã¹ããã) 42 ÷ 21 ã®äœã㯠0 ã X ã« 0 ã代å
¥ã㊠X ãš Y ãå
¥ãæ¿ããã (3 ã¹ããã) Y ã 0 ã«ãªã£ãã®ã§ããã®æã® X ãæå€§å
¬çŽæ°ãšãªãããã£ãп倧å
¬çŽæ°ã¯ 21 ã ãã®ããã«ããã£ãã® 3 ã¹ãããã§ 1071 ãš 1029 ã®æå€§å
¬çŽæ°ãæ±ããããšãåºæ¥ãŸããããŠãŒã¯ãªããã®äºé€æ³ã¯çŽæ°ãåºããŠæ¯èŒããŠããæ¹æ³ã«æ¯ã¹ãå§åçã«æ©ãçµæãåºããŠãããŸãã ïŒã€ã®æŽæ°ãå
¥åãšãããŠãŒã¯ãªããã®äºé€æ³ãçšããŠæå€§å
¬çŽæ°ãæ±ãããã®æå€§å
¬çŽæ°ãšèšç®ã«ããã£ãã¹ãããæ°ãåºåããããã°ã©ã ãäœæããŠãã ããã Input è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒããµãã€ã®è¡ã§ç€ºãããŸãã åããŒã¿ã»ãããšããŠïŒã€ã®æŽæ° a, b (2 †a, b †2 31 -1) ãïŒè¡ã«äžããããŸãã ããŒã¿ã»ããã®æ°ã¯ 1000 ãè¶
ããŸããã Output ããŒã¿ã»ããããšã«ãå
¥åãããïŒã€ã®æŽæ°ã®æå€§å
¬çŽæ°ãšãèšç®ã«ããã£ããŠãŒã¯ãªããã®äºé€æ³ã®ã¹ãããæ°ã空çœåºåãã§ïŒè¡ã«åºåããŸãã Sample Input 1071 1029 5 5 0 0 Output for the Sample Input 21 3 5 1 | 35,910 |
Permutation Enumeration For given an integer $n$, print all permutations of $\{1, 2, ..., n\}$ in lexicographic order. Input An integer $n$ is given in a line. Output Print each permutation in a line in order. Separate adjacency elements by a space character. Constraints $1 \leq n \leq 9$ Sample Input 1 2 Sample Output 1 1 2 2 1 Sample Input 2 3 Sample Output 2 1 2 3 1 3 2 2 1 3 2 3 1 3 1 2 3 2 1 | 35,911 |
E: åžå¹æ°å åé¡ é·ã $N$ ã®æ°å $A$ ãäžããããã$A$ ã® $i$ é
ç® ã¯ $A_i$ ã§ããã ããªãã¯ããã®æ°åã«å¯ŸããŠä»¥äžã®æäœãè¡ãããšãã§ããã $1 \leq i \leq N - 1$ ãªãæŽæ° i ãéžã¶ã $A_i$ ã®å€ãš $A_{i + 1}$ ã®å€ãå
¥ãæ¿ããã $A$ ãåžå¹æ°åã«ããããã«å¿
èŠãªæäœã®æå°åæ°ãæ±ããã 以äžã®æ¡ä»¶ãæºããé·ã $N$ ã®æ°åãåžå¹æ°åãšå®çŸ©ããã $1 < i < N$ ãæºããä»»æã® $i$ ã«ã€ããŠã $A_{i + 1}, A_{i - 1} > A_i$ ãŸã㯠$A_{i + 1}, A_{i - 1} < A_i$ ãæºããã çŽæçã«èšãã°ã $1,\ 10,\ 2,\ 30,\ \dots (10,\ 1,\ 30,\ 2,\ \dots )$ ã®ãããªãå¢å ãæžå°ãå¢å âŠïŒæžå°ãå¢å ãæžå°âŠïŒãç¹°ãè¿ãæ°åã§ããã å¶çŽ å
¥åå€ã¯å
šãп޿°ã§ããã $3 \leq N \leq 10^5$ $i \neq j$ ãªãã° $A_i \neq A_j$ $-10^9 \leq A_i \leq 10^9$ å
¥ååœ¢åŒ å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã $N$ $A_1 \dots A_N$ åºå åžå¹æ°åã«ããããã«å¿
èŠãªæäœã®æå°åæ°ãåºåããããŸããæ«å°Ÿã«æ¹è¡ãåºåããã ãµã³ãã« ãµã³ãã«å
¥å 1 5 1 2 3 4 5 ãµã³ãã«åºå 1 2 $2$ ãš $3$ ã $4$ ãš $5$ ã«æäœãè¡ãã°ã $1\ 3\ 2\ 5\ 4$ ãšããåžå¹æ°åã«ãªãã ãµã³ãã«å
¥å 2 3 1 2 3 ãµã³ãã«åºå 2 1 $1$ ãš $2$ ã«æäœãè¡ããããã㯠$2$ ãš $3$ ã«æäœãè¡ãããšã§ãåžå¹æ°åã«ãªãã ãµã³ãã«å
¥å 3 12 5 9 1 38 100 -23 4 16 -2 -10 -17 8 ãµã³ãã«åºå 3 2 | 35,912 |
Problem A: Gift from the Goddess of Programming The goddess of programming is reviewing a thick logbook, which is a yearly record of visitors to her holy altar of programming. The logbook also records her visits at the altar. The altar attracts programmers from all over the world because one visitor is chosen every year and endowed with a gift of miracle programming power by the goddess. The endowed programmer is chosen from those programmers who spent the longest time at the altar during the goddess's presence. There have been enthusiastic visitors who spent very long time at the altar but failed to receive the gift because the goddess was absent during their visits. Now, your mission is to write a program that finds how long the programmer to be endowed stayed at the altar during the goddess's presence. Input The input is a sequence of datasets. The number of datasets is less than 100. Each dataset is formatted as follows. n M 1 /D 1 h 1 : m 1 e 1 p 1 M 2 /D 2 h 2 : m 2 e 2 p 2 . . . M n /D n h n : m n e n p n The first line of a dataset contains a positive even integer, n †1000, which denotes the number of lines of the logbook. This line is followed by n lines of space-separated data, where M i /D i identifies the month and the day of the visit, h i : m i represents the time of either the entrance to or exit from the altar, e i is either I for entrance, or O for exit, and p i identifies the visitor. All the lines in the logbook are formatted in a fixed-column format. Both the month and the day in the month are represented by two digits. Therefore April 1 is represented by 04/01 and not by 4/1. The time is described in the 24-hour system, taking two digits for the hour, followed by a colon and two digits for minutes, 09:13 for instance and not like 9:13. A programmer is identified by an ID, a unique number using three digits. The same format is used to indicate entrance and exit of the goddess, whose ID is 000. All the lines in the logbook are sorted in ascending order with respect to date and time. Because the altar is closed at midnight, the altar is emptied at 00:00. You may assume that each time in the input is between 00:01 and 23:59, inclusive. A programmer may leave the altar just after entering it. In this case, the entrance and exit time are the same and the length of such a visit is considered 0 minute. You may assume for such entrance and exit records, the line that corresponds to the entrance appears earlier in the input than the line that corresponds to the exit. You may assume that at least one programmer appears in the logbook. The end of the input is indicated by a line containing a single zero. Output For each dataset, output the total sum of the blessed time of the endowed programmer. The blessed time of a programmer is the length of his/her stay at the altar during the presence of the goddess. The endowed programmer is the one whose total blessed time is the longest among all the programmers. The output should be represented in minutes. Note that the goddess of programming is not a programmer. Sample Input 14 04/21 09:00 I 000 04/21 09:00 I 001 04/21 09:15 I 002 04/21 09:30 O 001 04/21 09:45 O 000 04/21 10:00 O 002 04/28 09:00 I 003 04/28 09:15 I 000 04/28 09:30 I 004 04/28 09:45 O 004 04/28 10:00 O 000 04/28 10:15 O 003 04/29 20:00 I 002 04/29 21:30 O 002 20 06/01 09:00 I 001 06/01 09:15 I 002 06/01 09:15 I 003 06/01 09:30 O 002 06/01 10:00 I 000 06/01 10:15 O 001 06/01 10:30 I 002 06/01 10:45 O 002 06/01 11:00 I 001 06/01 11:15 O 000 06/01 11:30 I 002 06/01 11:45 O 001 06/01 12:00 O 002 06/01 12:15 I 000 06/01 12:30 I 002 06/01 12:45 O 000 06/01 13:00 I 000 06/01 13:15 O 000 06/01 13:30 O 002 06/01 13:45 O 003 0 Output for the Sample Input 45 120 | 35,913 |
G - Proportional Representation Problem Statement An election selecting the members of the parliament in JAG Kingdom was held. The only system adopted in this country is the party-list proportional representation. In this system, each citizen votes for a political party, and the number of seats a party wins will be proportional to the number of votes it receives. Since the total number of seats in the parliament is an integer, of course, it is often impossible to allocate seats exactly proportionaly. In JAG Kingdom, the following method, known as the D'Hondt method, is used to determine the number of seats for each party. Assume that every party has an unlimited supply of candidates and the candidates of each party are ordered in some way. To the $y$-th candidate of a party which received $x$ votes, assign the value $\dfrac{x}{y}$. Then all the candidates are sorted in the decreasing order of their assigned values. The first $T$ candidates are considered to win, where $T$ is the total number of seats, and the number of seats a party win is the number of its winning candidates. The table below shows an example with three parties. The first party received $40$ votes, the second $60$ votes, and the third $30$ votes. If the total number of seats is $T = 9$, the first party will win $3$ seats, the second $4$ seats, and the third $2$ seats. When selecting winning candidates, ties are broken by lottery; any tied candidates will have a chance to win. For instance, in the example above, if $T = 5$ then two candidates tie for the value $20$ and there are two possible outcomes: The first party wins $2$ seats, the second $2$ seats, and the third $1$ seat. The first party wins $1$ seat, the second $3$ seats, and the third $1$ seat. You have just heard the results of the election on TV. Knowing the total number of valid votes and the number of seats each party won, you wonder how many votes each party received. Given $N$, $M$, and $S_i$ ($1 \le i \le M$), denoting the total number of valid votes, the number of parties, and the number of seats the $i$-th party won, respectively, your task is to determine for each party the minimum and the maximum possible number of votes it received. Note that for some cases there might be no such situation with the given $N$, $M$, and $S_i$. Input The first line of the input contains two integers $N$ ($1 \le N \le 10^9$) and $M$ ($1 \le M \le 30{,}000$), where $N$ is the total number of valid votes and $M$ is the number of parties. $M$ lines follow, the $i$-th of which contains a single integer $S_i$ ($0 \le S_i \le 30{,}000$), representing the number of seats the $i$-th party won. You can assume that there exists $i$ with $S_i \ne 0$. Output If there is no situation with the given $N$, $M$, and $S_i$, display the word "impossible". Otherwise, output $M$ lines, each containing two integers. The first integer and the second integer in the $i$-th line should be the minimum and the maximum possible number of votes the $i$-th party received, respectively. Sample Input 1 10 2 2 1 Output for the Sample Input 1 5 7 3 5 Sample Input 2 5 6 0 2 0 2 6 0 Output for the Sample Input 2 0 0 1 1 0 0 1 1 3 3 0 0 Sample Input 3 2000 5 200 201 202 203 204 Output for the Sample Input 3 396 397 397 399 399 401 401 403 403 404 Sample Input 4 15 10 1 1 1 1 1 1 1 1 1 13 Output for the Sample Input 4 impossible Sample Input 5 1000000000 9 12507 16653 26746 21516 29090 10215 28375 21379 18494 Output for the Sample Input 5 67611619 67619582 90024490 90033301 144586260 144597136 116313392 116323198 157257695 157269050 55221291 55228786 153392475 153403684 115572783 115582561 99976756 99985943 | 35,914 |
Score : 400 points Problem Statement You are given integers N and M . Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M . Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N . Constraints All values in input are integers. 1 \leq N \leq 10^5 N \leq M \leq 10^9 Input Input is given from Standard Input in the following format: N M Output Print the maximum possible value of the greatest common divisor of a sequence a_1, a_2, ..., a_N that satisfies the condition. Sample Input 1 3 14 Sample Output 1 2 Consider the sequence (a_1, a_2, a_3) = (2, 4, 8) . Their greatest common divisor is 2 , and this is the maximum value. Sample Input 2 10 123 Sample Output 2 3 Sample Input 3 100000 1000000000 Sample Output 3 10000 | 35,915 |
Score : 300 points Problem Statement We have a square grid with H rows and W columns. Snuke wants to write 0 or 1 in each of the squares. Here, all of the following conditions have to be satisfied: For every row, the smaller of the following is A : the number of 0 s contained in the row, and the number of 1 s contained in the row. (If these two numbers are equal, âthe smallerâ should be read as âeitherâ.) For every column, the smaller of the following is B : the number of 0 s contained in the column, and the number of 1 s contained in the column. Determine if these conditions can be satisfied by writing 0 or 1 in each of the squares. If the answer is yes, show one way to fill the squares so that the conditions are satisfied. Constraints 1 \leq H,W \leq 1000 0 \leq A 2 \times A \leq W 0 \leq B 2 \times B \leq H All values in input are integers. Input Input is given from Standard Input in the following format: H W A B Output If the conditions cannot be satisfied by writing 0 or 1 in each of the squares, print -1 . If the conditions can be satisfied, print one way to fill the squares so that the conditions are satisfied, in the following format: s_{11}s_{12}\cdots s_{1W} s_{21}s_{22}\cdots s_{2W} \vdots s_{H1}s_{H2}\cdots s_{HW} Here s_{ij} is the digit written in the square at the i -th row from the top and the j -th column from the left in the grid. If multiple solutions exist, printing any of them will be accepted. Sample Input 1 3 3 1 1 Sample Output 1 100 010 001 Every row contains two 0 s and one 1 , so the first condition is satisfied. Also, every column contains two 0 s and one 1 , so the second condition is satisfied. Sample Input 2 1 5 2 0 Sample Output 2 01010 | 35,916 |
Score : 300 points Problem Statement You are given an integer sequence of length N , a_1,a_2,...,a_N . For each 1â€iâ€N , you have three choices: add 1 to a_i , subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X . Maximize this count by making optimal choices. Constraints 1â€Nâ€10^5 0â€a_i<10^5 (1â€iâ€N) a_i is an integer. Input The input is given from Standard Input in the following format: N a_1 a_2 .. a_N Output Print the maximum possible number of i such that a_i=X . Sample Input 1 7 3 1 4 1 5 9 2 Sample Output 1 4 For example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4 , the maximum possible count. Sample Input 2 10 0 1 2 3 4 5 6 7 8 9 Sample Output 2 3 Sample Input 3 1 99999 Sample Output 3 1 | 35,917 |
Score : 300 points Problem Statement Let us define the beauty of a sequence (a_1,... ,a_n) as the number of pairs of two adjacent elements in it whose absolute differences are d . For example, when d=1 , the beauty of the sequence (3, 2, 3, 10, 9) is 3 . There are a total of n^m sequences of length m where each element is an integer between 1 and n (inclusive). Find the beauty of each of these n^m sequences, and print the average of those values. Constraints 0 \leq d < n \leq 10^9 2 \leq m \leq 10^9 All values in input are integers. Input Input is given from Standard Input in the following format: n m d Output Print the average of the beauties of the sequences of length m where each element is an integer between 1 and n . The output will be judged correct if the absolute or relative error is at most 10^{-6} . Sample Input 1 2 3 1 Sample Output 1 1.0000000000 The beauty of (1,1,1) is 0 . The beauty of (1,1,2) is 1 . The beauty of (1,2,1) is 2 . The beauty of (1,2,2) is 1 . The beauty of (2,1,1) is 1 . The beauty of (2,1,2) is 2 . The beauty of (2,2,1) is 1 . The beauty of (2,2,2) is 0 . The answer is the average of these values: (0+1+2+1+1+2+1+0)/8=1 . Sample Input 2 1000000000 180707 0 Sample Output 2 0.0001807060 | 35,918 |
Problem A: Alien's Counting Natsuki and her friends were taken to the space by an alien and made friends with a lot of aliens. During the space travel, she discovered that aliensâ hands were often very different from humansâ. Generally speaking, in a kind of aliens, there are N fingers and M bend rules on a hand. Each bend rule describes that a finger A always bends when a finger B bends. However, this rule does not always imply that the finger B bends when the finger A bends. When she were counting numbers with the fingers, she was anxious how many numbers her alien friends can count with the fingers. However, because some friends had too complicated rule sets, she could not calculate those. Would you write a program for her? Input N M S 1 D 1 S 2 D 2 . . . S M D M The first line contains two integers N and M (1 †N †1000, 0 †M †1000) in this order. The following M lines mean bend rules. Each line contains two integers S i and D i in this order, which mean that the finger D i always bends when the finger S i bends. Any finger appears at most once in S . Output Calculate how many numbers her alien friends can count with the fingers. Print the answer modulo 1000000007 in a line. Sample Input 1 5 4 2 3 3 4 4 3 5 4 Output for the Sample Input 1 10 Sample Input 2 5 5 1 2 2 3 3 4 4 5 5 1 Output for the Sample Input 2 2 Sample Input 3 5 0 Output for the Sample Input 3 32 | 35,919 |
Score: 600 points Problem Statement Takahashi and Aoki are training for long-distance races in an infinitely long straight course running from west to east. They start simultaneously at the same point and moves as follows towards the east : Takahashi runs A_1 meters per minute for the first T_1 minutes, then runs at A_2 meters per minute for the subsequent T_2 minutes, and alternates between these two modes forever. Aoki runs B_1 meters per minute for the first T_1 minutes, then runs at B_2 meters per minute for the subsequent T_2 minutes, and alternates between these two modes forever. How many times will Takahashi and Aoki meet each other, that is, come to the same point? We do not count the start of the run. If they meet infinitely many times, report that fact. Constraints 1 \leq T_i \leq 100000 1 \leq A_i \leq 10^{10} 1 \leq B_i \leq 10^{10} A_1 \neq B_1 A_2 \neq B_2 All values in input are integers. Input Input is given from Standard Input in the following format: T_1 T_2 A_1 A_2 B_1 B_2 Output Print the number of times Takahashi and Aoki will meet each other. If they meet infinitely many times, print infinity instead. Sample Input 1 1 2 10 10 12 4 Sample Output 1 1 They will meet just once, \frac{4}{3} minutes after they start, at \frac{40}{3} meters from where they start. Sample Input 2 100 1 101 101 102 1 Sample Output 2 infinity They will meet 101, 202, 303, 404, 505, 606, ... minutes after they start, that is, they will meet infinitely many times. Sample Input 3 12000 15700 3390000000 3810000000 5550000000 2130000000 Sample Output 3 113 The values in input may not fit into a 32 -bit integer type. | 35,920 |
Max Score: $800$ Points Problem Statement There is an undirected connected graph with $N$ vertices and $N-1$ edges. The i -th edge connects u_i and v_i . E869120 the coder moves in the graph as follows: He move to adjacent vertex, but he can't a visit vertex two or more times. He ends move when there is no way to move. Otherwise, he moves randomly. (equal probability) If he has $p$ way to move this turn, he choose each vertex with $1/p$ probability. Calculate the expected value of the number of turns, when E869120 starts from vertex i , for all i (1 †i †N) . Input The input is given from standard input in the following format. N u_1 v_1 u_2 v_2 : u_{N-1} v_{N-1} Output In i -th (1 †i †N) line, print the expected vaule of the number of turns E869120 moves. The relative error or absolute error of output should be within 10^{-6} . Constraints $1 \le N \le 150,000$ The graph is connected. Subtasks Subtask 1 [ $190$ points ] There is no vertex which degree is more than 2. This means the graph looks like a list. Subtask 2 [ $220$ points ] 1 †N †1000 . Subtask 3 [ $390$ points ] There are no additional constraints. Sample Input 1 4 1 2 2 3 2 4 Sample Output 1 2.0 1.0 2.0 2.0 Sample Input 2 4 1 2 2 4 4 3 | 35,921 |
D : Hopping Hearts / ããããŽãããŽãã å顿 N 矜ã®ããããé·ã Lâ1 ã®å¹³åå°ã®äžã«ããã i çªç®ã®ãããã®åæäœçœ®ã¯æŽæ° x_i ã§ããã 0 †x_{i} \lt x_{i+1} †Lâ1 ãæºããã座æšã¯å³ã«é²ãã»ã©å€§ãããªããä»»æã® i çªç®ã®ãããã¯ãä»»æã®åæ°ã ããã¡ããã©è·é¢ a_i ã ã峿¹åã«ãžã£ã³ã(ããªãã¡ã x_i ãã x_i+a_i ãžç§»å)ããããšãã§ããããã ãå¥ã®ããããé£ã³è¶ããããšã â1 以äžãŸã㯠L 以äžã®äœçœ®ã«å
¥ãããšã¯ã§ããªãããŸããåæã«ãžã£ã³ãããŠããããã®ã¯é«ã
1 矜ã§ããããã座æšã«ååšã§ãããããã®æ°ãé«ã
1 矜ã§ããã åæç¶æ
ããå§ããŠãžã£ã³ããä»»æã®åæ°ç¹°ãè¿ããããšã® x_{0}, âŠ, x_{Nâ1} ã®ç¶æ
ãšããŠãããåŸããã®ã¯äœéããããã 1\,000\,000\,007 ã§å²ã£ãäœãã§æ±ããã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã N L x_{0} ⊠x_{Nâ1} a_{0} ⊠a_{Nâ1} å¶çŽ å
¥åã¯ãã¹ãп޿°ã§ãã 1 \†N \†5\,000 N \†L \†5\,000 0 \†x_{i} \lt x_{i+1} \†Lâ1 0 \†a_{i} \†Lâ1 åºå çãã1è¡ã§åºåããã ãµã³ãã« ãµã³ãã«å
¥å1 1 3 0 1 ãµã³ãã«åºå1 3 1/0ã§ãããããã/ããªãã衚çŸããã°ã100, 010, 001 ã® 3 éãã§ããã ãµã³ãã«å
¥å2 2 4 0 1 1 2 ãµã³ãã«åºå2 4 1100, 1001, 0101, 0011 ã® 4 éãã§ããã ãµã³ãã«å
¥å3 10 50 0 1 2 3 4 5 6 7 8 9 1 1 1 1 1 1 1 1 1 1 ãµã³ãã«åºå3 272278100 äºé
ä¿æ° C(50,10) = 10\,272\,278\,170 ã§ãããããã 1\,000\,000\,007 ã§å²ã£ãããŸã㯠272\,278\,100 ã§ããã | 35,922 |
Problem A: Whist Whist is a game played by four players with a standard deck of playing cards. The players seat around a table, namely, in north, east, south, and west. This game is played in a team-play basis: the players seating opposite to each other become a team. In other words, they make two teams we could call the north-south team and the east-west team. Remember that the standard deck consists of 52 cards each of which has a rank and a suit. The rank indicates the strength of the card and is one of the following: 2, 3, 4, 5, 6, 7, 8, 9, 10, jack, queen, king, and ace (from the lowest to the highest). The suit refers to the type of symbols printed on the card, namely, spades, hearts, diamonds, and clubs. The deck contains exactly one card for every possible pair of a rank and a suit, thus 52 cards. One of the four players (called a dealer) shuffles the deck and deals out all the cards face down, one by one, clockwise from the player left to him or her. Each player should have thirteen cards. Then the last dealt card, which belongs to the dealer, is turned face up. The suit of this card is called trumps and has a special meaning as mentioned below. A deal of this game consists of thirteen tricks. The objective for each team is winning more tricks than another team. The player left to the dealer leads the first trick by playing one of the cards in his or her hand. Then the other players make their plays in the clockwise order. They have to play a card of the suit led if they have one; they can play any card otherwise. The trick is won by the player with the highest card of the suit led if no one plays a trump, or with the highest trump otherwise. The winner of this trick leads the next trick, and the remaining part of the deal is played similarly. After the thirteen tricks have been played, the team winning more tricks gains a score, one point per trick in excess of six. Your task is to write a program that determines the winning team and their score for given plays of a deal. Input The input is a sequence of datasets. Each dataset corresponds to a single deal and has the following format: Trump Card N,1 Card N,2 ... Card N,13 Card E,1 Card E,2 ... Card E,13 Card S,1 Card S,2 ... Card S,13 Card W,1 Card W,2 ... Card W,13 Trump indicates the trump suit. Card N, i , Card E, i , Card S, i , and Card W, i denote the card played in the i -th trick by the north, east, south, and west players respectively. Each card is represented by two characters; the first and second character indicates the rank and the suit respectively. The rank is represented by one of the following characters: â 2 â, â 3 â, â 4 â, â 5 â, â 6 â, â 7 â, â 8 â, â 9 â, â T â (10), â J â (jack), â Q â (queen), â K â (king), and â A â (ace). The suit is represented by one of the following characters: â S â (spades), â H â (hearts), â D â (diamonds), and â C â (clubs). You should assume the cards have been dealt out by the west player. Thus the first trick is led by the north player. Also, the input does not contain any illegal plays. The input is terminated by a line with â # â. This is not part of any dataset and thus should not be processed. Output For each dataset, print the winner and their score of the deal in a line, with a single space between them as a separator. The winner should be either â NS â (the north-south team) or â EW â (the east-west team). No extra character or whitespace should appear in the output. Sample Input H 4C 8H QS 5D JD KS 8S AH 6H 7H 3S 7S 6D TC JC JS KD AC QC QD 2H QH 3H 3C 7C 4D 6C 9C AS TD 5H 6S 5S KH TH AD 9S 8D 2D 8C 5C 2S 7D KC 4S TS JH 4H 9H 2C 9D 3D D 8D 9D 9S QS 4H 5H JD JS 9H 6S TH 6H QH QD 9C 5S 7S 7H AC 2D KD 6C 3D 8C TC 7C 5D QC 3S 4S 3H 3C 6D KS JC AS 5C 8H TS 4D 4C 8S 2S 2H KC TD JH 2C AH 7D AD KH # Output for the Sample Input EW 1 EW 2 The winners of the tricks in the first dataset are as follows (in the order of tricks): east, north, south, east, south, north, west, north, east, west, east, east, north. | 35,923 |
çŸä»£çãªå±æ·(Modern Mansion) ããªãã¯ïŒãã倧ããªå±æ·ã«è¿·ã蟌ãã§ããŸã£ãïŒãã®å±æ·ã¯æ£æ¹åœ¢ã®éšå±ãæ±è¥¿ååã«æ Œåç¶ã«ïŒæ±è¥¿æ¹åã« M åïŒååæ¹åã« N è¡ã®åèš M à N å䞊ãã æ§é ãããŠããïŒè¥¿ãã x åç®(1 †x †M )ïŒåãã y è¡ç®(1 †y †N ) ã«ããéšå±ã( x , y ) ã§è¡šãïŒ æ±è¥¿ååã«é£ãåã 2 éšå±ã®éã¯ïŒå£ã®äžå€®ã«ããæã«ããçµã°ããŠããïŒããããã®æã¯ïŒéããŠããŠéè¡äžå¯èœãªç¶æ
ãïŒéããŠããŠéè¡å¯èœãªç¶æ
ã®ããããã«ããïŒæãéããŠãããšãïŒãããã®éšå±ã®äžå€®éãç§»åããã®ã« 1 åéãããïŒãŸãïŒããã€ãã®éšå±ã®äžå€®ã«ã¯ã¹ã€ãããããïŒã¹ã€ããã 1 åéæŒãç¶ãããšïŒå±æ·å
ã®ãã¹ãŠã®æã®ééã®ç¶æ
ãåãæ¿ããïŒ ä»ïŒæ±è¥¿ã«é£ãåã 2 éšå±ãçµã¶ãã¹ãŠã®æã¯éããŠããŠïŒååã«é£ãåã 2 éšå±ãçµã¶ãã¹ãŠã®æã¯éããŠããïŒããªãã¯ä»éšå± (1, 1) ã®äžå€®ã«ããŠïŒéšå± ( M , N ) ã®äžå€®ãŸã§æçæéã§ç§»åãããïŒ èª²é¡ å±æ·ã®å€§ãã M , N ããã³ïŒã¹ã€ããã®ãã K åã®éšå±ã®äœçœ® ( X 1 , Y 1 ), ( X 2 , Y 2 ),..., ( X K , Y K ) ãäžããããïŒæ±è¥¿ã«é£ãåã 2 éšå±ãçµã¶ãã¹ãŠã®æã¯éããŠããŠïŒååã«é£ãåã 2 éšå±ãçµã¶ãã¹ãŠã®æã¯éããŠããç¶æ
ããå§ããŠïŒéšå± (1, 1) ã®äžå€®ããéšå± ( M , N ) ã®äžå€®ãŸã§ç§»åããã®ã«æçã§äœåãããããæ±ããããã°ã©ã ãäœæããïŒãã ãïŒéšå± ( M , N ) ã«èŸ¿ãçãããšãã§ããªããšãã¯ãããææããïŒ å¶é 2 †M †100 000 屿·ã®æ±è¥¿æ¹åã®éšå±ã®åæ° 2 †N †100 000 屿·ã®ååæ¹åã®éšå±ã®åæ° 1 †K †200 000 ã¹ã€ããã®ããéšå±ã®åæ° 1 †X i †M ã¹ã€ããã®ããéšå±ã®æ±è¥¿æ¹åã®äœçœ® 1 †Y i †N ã¹ã€ããã®ããéšå±ã®ååæ¹åã®äœçœ® å
¥å æšæºå
¥åãã以äžã®ããŒã¿ãèªã¿èŸŒãïŒ 1 è¡ç®ã«ã¯ïŒæŽæ° M, N, K ã空çœãåºåããšããŠæžãããŠããïŒ M ã¯å±æ·ã®æ±è¥¿æ¹åã®éšå±ã®åæ°ïŒ N ã¯å±æ·ã®ååæ¹åã®éšå±ã®åæ°ïŒ K ã¯ã¹ã€ããã®ããéšå±ã®åæ°ã衚ãïŒ ç¶ã K è¡ã®ãã¡ã® i è¡ç®(1 †i †K ) ã«ã¯ïŒæŽæ° X i , Y i ã空çœãåºåããšããŠæžãããŠããïŒããã¯ïŒéšå±( X i , Y i ) ã®äžå€®ã«ã¹ã€ãããããããšã衚ãïŒ K åã®çµ( X 1 , Y 1 ), ( X 2 , Y 2 ),..., ( X K , Y K ) ã¯äºãã«ç°ãªãïŒ åºå æšæºåºåã«ïŒç§»åã«æçã§äœåãããããè¡šãæŽæ°ã 1 è¡ã§åºåããïŒãã ãïŒéšå±( M , N ) ã«èŸ¿ãçãããšãã§ããªããšãã¯ä»£ããã«æŽæ° -1 ãåºåããïŒ æ¡ç¹åºæº æ¡ç¹çšããŒã¿ã®ãã¡ïŒé
ç¹ã®20%åã«ã€ããŠã¯ïŒ M †1 000, N †1 000 ãæºããïŒ æ¡ç¹çšããŒã¿ã®ãã¡ïŒé
ç¹ã®30%åã«ã€ããŠã¯ïŒ K †2 000 ãæºããïŒ æ¡ç¹çšããŒã¿ã®ãã¡ïŒé
ç¹ã®50%åã«ã€ããŠã¯ïŒããã 2 ã€ã®æ¡ä»¶ã®å°ãªããšãäžæ¹ãæºããïŒãŸãïŒããã 2 ã€ã®æ¡ä»¶ã®äž¡æ¹ãæºãããããªæ¡ç¹çšããŒã¿ã¯ãªãïŒ å
¥åºåäŸ å
¥åäŸ 1 3 2 1 1 2 åºåäŸ 1 4 ãã®äŸã§ã¯ïŒä»¥äžã®è¡åã«ãã£ãŠ 4 åéã§éšå±(1, 1) ã®äžå€®ããéšå±(3, 2) ã®äžå€®ãžç§»åããããšãã§ãïŒãããæçã§ããïŒ éšå±(1, 2) ã®äžå€®ãžç§»åããïŒ éšå±(1, 2) ã®äžå€®ã®ã¹ã€ãããæŒãïŒ éšå±(2, 2) ã®äžå€®ãžç§»åããïŒ éšå±(3, 2) ã®äžå€®ãžç§»åããïŒ ãã®ãšãã®å±æ·ã®æ§åã以äžã®å³ã«è¡šãããŠããïŒå³ã§ã¯å³æ¹åãæ±ïŒäžæ¹åãåã§ããïŒÃå°ã¯ããªãã®äœçœ®ïŒâå°ã¯ã¹ã€ããã衚ãïŒ å
¥åäŸ 2 3 2 1 2 1 åºåäŸ 2 -1 ãã®äŸã§ã¯ïŒããªãã¯éšå±(3, 2) ã«èŸ¿ãçãããšãã§ããªãïŒ å
¥åäŸ 3 8 9 15 3 1 3 2 3 7 3 8 1 1 4 5 4 3 5 6 5 8 6 3 6 2 7 5 8 9 8 6 8 5 åºåäŸ 3 25 ãã®äŸã§ã¯ïŒæåã®å±æ·ã®æ§åã¯ä»¥äžã®å³ã®ããã«ãªã£ãŠããïŒéšå±(1, 1) ãéšå±( M , N ) ã®äžå€®ã«ã¹ã€ãããããå¯èœæ§ãããããšã«æ³šæããïŒ å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã | 35,924 |
ãããªã¹ ãããªã¹ã¯ãèœã¡ãŠãããããã¯ãç€é¢äžã«äžŠã¹ãŠæ¶ãã²ãŒã ã§ããããã§ã¯ããããå°ãã¢ã¬ã³ãžããã²ãŒã ãèããŸãããã ãã®ã²ãŒã ã®ç€é¢ã®å€§ããã¯æšª 5 ã³ãã§ãåºçŸãããããã¯ããã¹ãŠå
¥ãã ãã®é«ãããããŸããèœã¡ãŠãããããã¯ã¯çŽç·ç¶ã§ã暪åãã瞊åãã® 2 çš®é¡ããããé·ã㯠1 ãã 5 ãŸã§ã® 5 çš®é¡ã§ãã 以äžã«äŸã瀺ããŸããStep(ã€) ããStep(ã)ãŸã§ã®å³ã¯ãããã¯ãèœã¡ãŠæ¶ããŠããæ§åã衚ãããã®ã§ãã Step(ã€)ããé ã«Step(ã)ãStep(ã)ãšé ã«é²ãã§ãããŸãã ãããã¯ãèœãšããšãã«ãStep(ã€)ã®ããã«ãããã¯ã®ã©ãããäžã«ç©ãã§ãããããã¯ã«åŒã£ããã£ããšãã«ã¯ãStep(ã)ã®ããã«èœã¡ããããã¯ã¯ãã®å Žæã§æ¢ãŸããŸãããŸãããããã¯ãèœãšããçµæãç€é¢ã®æšªäžè¡ã®å
šãŠã®ã³ãã«ãããã¯ãè©°ãŸã£ãå Žåã«ã¯ãStep(ã)ã§ç€ºãããããã«ããã®è¡ã®ãããã¯ãæ¶ããŸãããã®åŸãæ¶ããè¡ã®äžã«ãããããã¯ãããã®ãŸãŸã®åœ¢ã§1è¡äžã«ããã¿ãŸã(Step(ã))ã 1 ã²ãŒã 㯠1000 å以å
ã®ãããã¯ãé ã«èœã¡ãŠããããšãšããŸããäŸãã°ãèœã¡ããããã¯ã®é·ããé çªã«æšªåã 4 ã³ã, 暪åã 3 ã³ã, 瞊åã 2 ã³ã, 瞊åã 3 ã³ãã§ãèœã¡ãå Žæã巊端ãã 1 ã³ãç®ã1 ã³ãç®ã4 ã³ãç®ã5 ã³ãç®ã§ãã£ãå Žåã«ã¯ãäžå³ã®Step(ã€)~(ã)ã®ããã«èœã¡ãæåŸã«æ®ããããã¯ã¯ 2 ã³ãã«ãªããŸãã é çªã«èœã¡ãŠãããããã¯ã®æ
å ±ãå
¥åãšããå
šãŠã®ãããã¯ãèœã¡ãæã«æ®ãã³ãæ°ãåºåããããã°ã©ã ãäœæããŠãã ããã Input è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã n d 1 p 1 q 1 d 2 p 2 q 2 : d n p n q n ïŒè¡ç®ã«ãããã¯ã®æ° n (1 †n †1000) ãäžããããŸããç¶ã n è¡ã« i åç®ã®ãããã¯ã®åã d i (1 ãŸãã¯2)ããããã¯ã®é·ã p i (1 †p i †5)ããããã¯ã®äœçœ® q i ãäžããããŸãããããã¯ã®åã d i 㯠1 ãæšªåããã2 ã瞊åãã衚ããŸãããããã¯ã®äœçœ® q i ã¯ç€é¢äžã®å·Šç«¯ãã1 ~ 5 ãŸã§ã®æŽæ°ãšããæšªåãã®ãããã¯ã®å Žåã¯å·Šç«¯ã®ã³ãã®èœã¡ãäœçœ®ãšããŸãã ããŒã¿ã»ããã®æ°ã¯ 20 ãè¶
ããŸããã Output ããŒã¿ã»ããæ¯ã«æåŸã«æ®ããããã¯ã®å ããã³ãæ°ãïŒè¡ã«åºåããŸãã Sample Input 4 1 4 1 1 3 1 2 2 4 2 3 5 1 1 5 1 7 2 2 2 1 4 1 2 1 3 1 4 1 1 1 1 2 5 5 1 4 2 0 Output for the Sample Input 2 0 6 | 35,925 |
Problem I: Shiritori Problem ããã«æååã®ãªã¹ãããããæ¯æãã«ããããšããããŠéã¶ããšã«ãããããããšãã¯ã以äžã®ã«ãŒã«ã§è¡ãããã ãŸãæåã«ããªã¹ãã®äžãã奜ããªæååãäžã€éžã³ããã®æååããªã¹ãããé€å€ããã ç¶ããŠãäžã€åã«éžãã æååã®æåŸã®äžæåããæåã®äžæåã§ããæååããªã¹ãããäžã€éžã¶ã éžãã æååããªã¹ãããé€å€ããã ãã®åŸã2., 3.ã亀äºã«ç¹°ãè¿ãããšã«ãªãã ããŠããã®ãããšãã2.ã§ãªã¹ãããéžã¹ãæååããªããªããŸã§ç¶ãããšãããã ãã®ãšãã«ãæåŸã«éžãã æååã®ãæåŸã®äžæåããšããŠããåŸãæåããã¹ãŠåæãããã Input $N$ $s_1$ $s_2$ $s_3$ : $s_N$ äžè¡ç®ã«ãæååã®æ°$N$ãäžããããã ç¶ã$N$è¡ã«ãæååã®ãªã¹ããäžããããã Constraints å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã $1 \le N \lt 10^4$ $1 \le |s_i| \lt 100$ $s_i \neq s_j (i \neq j)$ æååã«ã¯ãè±å°æåã®ã¿å«ãŸãã Output æåŸã«éžãã æååã®ãæåŸã®äžæåããšããŠããåŸãæåãaããzã®é ã§èŸæžé ã§æé ã«åºåããã Sample Input 1 5 you ate my hum toast Sample Output 1 e t u ãã®æã以äžã®ãããªå Žåãã¢ãŠããããäŸãšãªãã ate(1ã€ã®æååã®ã¿) toast hum - my - you ãŸããm,yã§çµãããã¿ãŒã³ã¯ååšããªãã Sample Input 2 7 she sells sea shells by the seashore Sample Output 2 a e y | 35,926 |
JOI æ (JOI Flag) åé¡ æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒã§ã¯ïŒä»å¹Žã®æ¥æ¬æ
å ±ãªãªã³ãã㯠(JOI) ã宣äŒããããã«ïŒ JOI ã®ããŽãã¢ããŒãã«ããæãäœãããšã«ãªã£ãïŒæã¯ãè¯ãæãã§ãªããã°ãªããªãïŒãè¯ãæããšã¯ïŒã¢ã«ãã¡ãããã® J, O, I ã®ããããã®æåãïŒçžŠ M è¡ïŒæšª N åã®é·æ¹åœ¢ç¶ã«äžŠã¹ããã®ã§ïŒ J, O, I ã以äžã®å³ã®ããã« (ããªãã¡ïŒJ ã®å³é£ã« O ãïŒãã® J ã®äžé£ã« I ã) 䞊ãã§ããç®æãæã®å°ãªããšã 1 ãæã«ãããã®ã§ããïŒ ä»¥äžã®å³ã«ïŒãè¯ãæãã®äŸã 2 ã€ç€ºãïŒ ä»¥äžã®å³ã«ïŒãè¯ãæãã§ã¯ãªãäŸã 2 ã€ç€ºãïŒ ã㟠M, N ã®å€ïŒããã³æã®äžéšã®å Žæã«ã€ã㊠J, O, I ã®ã©ã®æåã«ããããæ±ºãŸã£ãŠããïŒå
¥åãšããŠãã®æ
å ±ãäžããããïŒèãããããè¯ãæãã¯äœéãããããèšç®ãïŒãã®æ°ã 100000 (=10 5 ) ã§å²ã£ãäœããåºåããããã°ã©ã ãäœæããïŒ å
¥å å
¥å㯠1 + M è¡ãããªãïŒ 1 è¡ç®ã«ã¯æã®å€§ããã衚ã 2 ã€ã®æŽæ° M, N (2 †M †20, 2 †N †20) ã空çœã§åºåãããŠæžãããŠããïŒ 1 + i è¡ç® (1 †i †M) ã«ã¯ïŒN æåãããªãæååãæžãããŠããïŒåæå㯠J, O, I, ? ã®ããããã§ããïŒ j æåç® (1 †j †N) ã J, O, I ã®ããããã§ããå Žå㯠i è¡ j åã®å Žæã®æåããããã J, O, I ã«æ±ºãŸã£ãŠããããšïŒ ? ã§ããå Žåã¯ãŸã 決ãŸã£ãŠããªãããšã衚ãïŒ åºå èãããããè¯ãæãã®åæ°ã 100000 (=10 5 ) ã§å²ã£ãäœãã 1 è¡ã§åºåããïŒ å
¥åºåäŸ å
¥åäŸ 1 2 3 ??O IIJ åºåäŸ 1 4 å
¥åäŸ 1 ã«ãããŠã¯ïŒä»¥äžã®å³ã® 4 éãã®ãè¯ãæããèããããïŒ å
¥åäŸ 2 2 2 ?? ?? åºåäŸ 2 3 å
¥åäŸ 3 3 3 ??I ??? O?J åºåäŸ 3 53 å
¥åäŸ 4 5 4 JOI? ???? ???? ???? ?JOI åºåäŸ 4 28218 å
¥åäŸ 4 ã«ãããŠã¯ïŒãè¯ãæã㯠2428218 éãèããããã®ã§ïŒããã 100000 (=10 5 ) ã§å²ã£ãäœãã§ãã 28218 ãåºåããïŒ å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã | 35,927 |
Small, Large, or Equal Write a program which prints small/large/equal relation of given two integers a and b . Input Two integers a and b separated by a single space are given in a line. Output For given two integers a and b , print a < b if a is less than b , a > b if a is greater than b , and a == b if a equals to b . Constraints -1000 †a , b †1000 Sample Input 1 1 2 Sample Output 1 a < b Sample Input 2 4 3 Sample Output 2 a > b Sample Input 3 5 5 Sample Output 3 a == b | 35,928 |
Problem J: BD Shelf Remember the boy called Jack. He likes anime, especially programs broadcasting in midnight or early morning. In his room, there is a big shelf and it is kept organized well. And there are anime BD/DVDs which he watched or gave up because of overlapping of broadcasting time with other animes. His money is tight, but he succeeded to get W hundreds dollars because of an unexpected event. And he came up with enhancing the content of his BD shelf. He is troubled about the usage of the unexpected income. He has a good judge for anime to choose the anime he can enjoy because he is a great anime lover. Therefore, first of all, he listed up expectable animes and assigned each anime a value that represents "a magnitude of expectation". Moreover Jack tagged a mysterious string M for each anime. However Jack did not tell you the meaning of the string M. Your task is to write a program that reads a string X and that maximizes the sum of magnitudes of expectation when Jack bought BD/DVD boxes of anime with the budget of W hundreds dollars. Here, Jack must buy anime's BD/DVD box that have a string X as a sub-string of the string M assigned the anime. If he can not buy any boxes, output -1. A sequence of string X is given in order in the input as query. Assume two strings X 1 and X 2 are given as string X , and X 1 is the prefix of X 2 . If X 1 is given in the input preceding X 2 , you must not buy an anime which has the minimum magnitude of expectation among animes extracted by X 1 in the calculation for X 2 . And vice versa ( X 1 is the prefix of X 2 and if X 2 is given in the input preceding X 1 , ...) . For example, If three strings "a", "abc" and "ab" are given in this order in the input, In the processing for string "abc", you must not extract an anime which has the minimum magnitude of expectation among animes extracted by the processing of the string "a". In the processing for string "ab", you must not extract an anime has minimum magnitude of expectation among animes extracted by the processing of the string "abc" and "a". Input Input consists of multiple datasets. A dataset is given in the following format. N W string 1 expectation 1 price 1 string 2 expectation 2 price 2 ... string N expectation N price N Q query 1 query 2 ... query Q N is an integer that represents the number of anime. Following N lines contains the information of each anime. string i (1†i †N ) is a string consists of lowercase letters that represents string M assigned i -th anime by Jack. No two characters in this string are same. expectation i (1†i †N ) is a natural number that represents a magnitude of expectation of the i -th anime. price i (1†i †N ) is a natural number that represents a price(cost) in hundreds to buy the i -th anime. Q is an integer that represents the number of queries. query i (1†i †Q ) is a string consists of lowercase letters. This is a string X described in the problem statement. N = W =0 shows the end of the input. Constraints There are 4 test cases. This is given by the following order. In the first testcase, 4 datasets satisfy N â€10 and Q â€10, 6 datasets satisfy N â€5000 and Q â€5000. In the 2nd, 3rd and 4th testcase, each satisfies N â€20000 and Q â€20000. The time limit for this problem is the limit for each testcase. 1†N â€20000 1†W â€20 1â€(the length of string i (1†i †N ))â€10 1†price i (1†i †N )â€20 1†expectation i (1†i †N )â€7000000 1†Q â€20000 1â€(the length of query i (1†i †Q ))â€5 It is assured that all values for expectation are different. Output For each query, output an integer S on a line that represents the maximum sum of magnitudes of expectation in the following format. S Sample Input 3 4 abc 1 1 abc 10 1 abc 100 1 3 a abc ab 3 4 ab 1 1 ab 10 1 abc 100 1 3 abc ab a 3 4 abc 1 1 abc 10 1 abc 100 1 3 ab ab ab 8 20 abcdef 100 2 bcdef 200 1 cfghj 300 3 ksjirto 400 6 ksitoew 500 2 qwertyl 600 2 kjhbvc 700 2 edfghucb 800 1 10 ks cd hj e a g h j i a 0 0 Output for the Sample Input 111 110 100 100 11 10 111 110 100 900 300 300 2200 100 1100 1500 1400 900 -1 | 35,929 |
GïŒ ã»ãŒç¡éã°ãªã³ - Almost Infinite Glico åé¡ N åã®ãã¹ãåç°ç¶ã«äžŠãã§ãããã£ãŒã«ãããããŸãã i çªç® (1 \leq i \leq N-1) ã®ãã¹ã® 1 ã€å
ã¯ã i+1 çªç®ã®ãã¹ã«ãªããŸãããã ãã i = N ã®å Žåããã® 1 ã€å
㯠1 çªç®ã®ãã¹ã«ãªããŸãã ããªããæåã«ãããã¹ã¯ 1 çªç®ã®ãã¹ã§ãããããã以äžã®ã«ãŒã«ã«åŸã£ãŠããããããã K åç¶ããŠè¡ããŸãããã®ãšããããªããšçžæã¯ç¹æ®ãªããããããäŒåŸããŠããã®ã§ããããããã®åã¡æ¹ã M éããããŸãã çžæãšããããããè¡ããããªããçžæã«åã£ããšããä»åºããæãããªãã¡åã¡æ¹ i ã«å¿ãããã¹æ° p_i ã ãé²ã¿ãŸããè² ãããšãã¯ãã®å Žã«çãŸããŸãã K åã®ããããããçµããããšã«ãããªãã i çªç®ã®ãã¹ã«ããå Žåã®æ°ã 1,000,000,007 ã§å²ã£ãäœãããããããã®ãã¹ã«ã€ããŠæ±ããŠãã ãããããã§ 2 ã€ã®å Žåãç°ãªããšã¯ã K åã®ãããããã®ååã®ãã¡è² ããåãäžåºŠã§ãç°ãªãããŸãã¯åã¡æ¹ãç°ãªãåãäžåºŠã§ãååšããããšãèšããŸããåã¡æ¹ãåºå¥ããããšã«æ³šæããŠãã ããããŸããããããã®åã¡æ¹ã«ã€ããŠãçºçããå¯èœæ§ãå
šããªããã®ã¯ååšããªãããšãšããŸãã å
¥ååœ¢åŒ å
¥å㯠1 + M è¡äžããããã N M K p_1 ... p_M 1 è¡ç®ã§ã¯ããã¹ã®æ° N ã ãããããã®åã¡æ¹ã®æ° M ã ããããããè¡ãåæ° K ãäžããããã ç¶ã㊠M è¡äžããããã i+1 è¡ç®ã§ã¯ã i çªç®ã®åã¡æ¹ãããæã«é²ãããã¹ã®æ° p_i ãäžããããã å¶çŽ 1 \leq N \leq 8 \times 10^2 1 \leq M \leq 10^4 1 \leq K \leq 10^9 1 \leq p_i \leq 10^9 åºååœ¢åŒ åºå㯠N è¡ãããªãã i è¡ç®ã§ã¯ã K åã®ããããããçµããããšã«ããªãã i çªç®ã®ãã¹ã«ããå Žåã®æ°ãåºåããã å
¥åäŸ1 10 3 2 3 6 6 åºåäŸ1 1 0 4 2 0 0 5 0 0 4 äžè¬çãªã°ãªã³ã§ãããã®å
¥åã«ãããŠãããããã㯠2 åè¡ãããŸãã äŸãã°ã 2 åããããããããåŸã« 1 çªç®ã®ãã¹ã«ããããã«ã¯ãå
šãŠã®ãããããã§è² ããªããã°ãããŸããããã以å€ã« 1 çªç®ã®ãã¹ã§çµããçµã¿åããã¯ååšããªãããã 1 éãã§ãã 2 åããããããããåŸã« 4 çªç®ã®ãã¹ã«ããããã«ã¯ã 1 åç®ã®ãããããã§ 1 çªç®ã®åã¡æ¹ã§å〠â 2 åç®ã®ãããããã§è² ãã 1 åç®ã®ãããããã§è² ãã â 2 åç®ã®ãããããã§ 1 çªç®ã®åã¡æ¹ã§å〠㮠2 éãããããŸããé çªãç°ãªããªãã°ãç°ãªãå ŽåãšããŠæ±ãããããšã«æ³šæããŠãã ããã å
¥åäŸ2 5 1 103 4 åºåäŸ2 355272559 885073297 355272559 607675915 607675915 1,000,000,007 ã§å²ã£ãäœããåºåããããšã«æ³šæããŠãã ããã | 35,930 |
Score : 150 points Problem Statement There are some goats on a grid with H rows and W columns. Alice wants to put some fences at some cells where goats do not exist so that no goat can get outside the grid. Goats can move in the four directions, that is, up, down, right and left. Goats can not move onto the cells where fences are placed. If a goat exists at one of the outermost cells in the grid, it can move outside. Goats do not move until all fences are placed. Find the minimum number of fences to be placed. Constraints 1 \leq H \leq 100 1 \leq W \leq 100 There is at least one goat on the given grid. Input The input is given from the Standart Input in the following format: H W S_1 : S_H The j -th (1 \leq j \leq W) character in S_i (1 \leq i \leq H) represents whether a goat exists at the cell located at row i and column j . Character . represents there is no goat, and X represents there is one goat at the cell. | 35,931 |
æ
è¡ã¯ãã€? ããªãã¯åäººãšæ
è¡ã«è¡ããããšèããŠããŸãããšããããæµªè²»çã®ããå人ã¯ãªããªãæ
è¡è²»çšã貯ããããšãã§ããŸãããå人ãä»ã®ç掻ãç¶ããŠãããšãæ
è¡ã«è¡ãã®ã¯ãã€ã«ãªã£ãŠããŸããåãããŸãããããã§ãæ©ãæ
è¡ã«è¡ãããããªãã¯ãå人ãèšç»çã«è²¯èããããšãå©ããããã°ã©ã ãäœæããããšã«ããŸããã å人ã®ããæã®ãå°é£ãã M åããã®æã«äœ¿ããéã N åãšãããšããã®æã¯ ( M - N ) å貯èãããŸããæ¯æã®åæ¯æ
å ± M ã N ãå
¥åãšãã貯èé¡ãæ
è¡è²»çš L ã«éããã®ã«ãããææ°ãåºåããããã°ã©ã ãäœæããŠãã ããããã ãã12 ã¶æãéããŠã貯èé¡ãæ
è¡è²»çšã«éããªãã£ãå Žåã¯NA ãšåºåããŠãã ããã Input è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸãã å
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸãã åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã L M 1 N 1 M 2 N 2 : M 12 N 12 1 è¡ç®ã«æ
è¡è²»çš L (1 †L †1000000, æŽæ°) ãäžããããŸããç¶ã 12 è¡ã«ã i æç®ã®åæ¯æ
å ± M i , N i (0 †M i , N i †100000, N i †M i , æŽæ°) ãäžããããŸãã ããŒã¿ã»ããã®æ°ã¯ 1000 ãè¶
ããŸããã Output å
¥åããŒã¿ã»ããããšã«ã貯èé¡ãæ
è¡è²»çšã«éããã®ã«ãããææ°ãïŒè¡ã«åºåããŸãã Sample Input 10000 5000 3150 5000 5000 0 0 5000 1050 5000 3980 5000 210 5000 5000 5000 5000 0 0 5000 2100 5000 2100 5000 2100 29170 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 70831 0 Output for the Sample Input 6 NA | 35,932 |
Score : 700 points Problem Statement N cells are arranged in a row. Some of them may contain tokens. You are given a string s that consists of 0 s and 1 s. If the i -th character of s is 1 , the i -th cell (from left) contains a token. Otherwise, it doesn't contain a token. Snuke wants to perform the following operation as many times as possible. In each operation, he chooses three consecutive cells. Let's call the cells X, Y, Z from left to right. In order for the operation to be valid, both X and Z must contain tokens and Y must not contain a token. Then, he removes these two tokens and puts a new token on Y . How many operations can he perform if he performs operations in the optimal way? Constraints 1 \leq N \leq 500,000 |s| = N Each character in s is either 0 or 1 . Input Input is given from Standard Input in the following format: N s Output Print the answer. Sample Input 1 7 1010101 Sample Output 1 2 For example, he can perform two operations in the following way: Perform an operation on the last three cells. Now the string that represents tokens becomes 1010010 . Perform an operation on the first three cells. Now the string that represents tokens becomes 0100010 . Note that the choice of operations matters. For example, if he chooses three cells in the middle first, he can perform no more operations. Sample Input 2 50 10101000010011011110001001111110000101010111100110 Sample Output 2 10 | 35,933 |
Problem K: Manhattan Warp Machine 2 Problem ãšããå®å®ã§ã¯ã3次å
ã®æ Œåç¹äžã«æãååšããå®å®äººéã¯ãã³ããã¿ã³ã¯ãŒãè£
眮ãšããè£
眮ã䜿ããæéãç§»åããŠããã ãã®ã¯ãŒãè£
眮ã«ã¯ã N åã®ãã¿ã³ãä»ããŠããããã¿ã³ i ãæŒããšãçŸåšããæããã®ãã³ããã¿ã³è·é¢ã d i ã§ããä»»æã®æã«ã¯ãŒãããããšãã§ããã ã¯ãŒãè£
çœ®ã¯æ¹è¯ãããã³ã¹ããããããã«ç§»ååºæ¥ãã ä»ã(0, 0, 0)ã®æã«ããããå®å®äººããã M åã®æã蚪ããããšèããŠããã M åã®æãå
šãŠèšªããã®ã«æçã§äœåã¯ãŒããããå¿
èŠããããçããã ããã1ã€ã§ã蚪ããããšãäžå¯èœãªæãããå Žåã¯-1ãåºåããã M åã®æã¯å¥œããªé çªã«èšªããããšãåºæ¥ãå
šãŠèšªããåŸã«(0, 0, 0)ã«æ»ã£ãŠæ¥ãå¿
èŠã¯ç¡ãã 3次å
äžã®å
šãŠã®æ Œåç¹ã«ã¯å¿
ãæãååšããã ç¹( x 1 , y 1 , z 1 )ãšç¹( x 2 , y 2 , z 2 )éã®ãã³ããã¿ã³è·é¢ã¯| x 1 - x 2 | + | y 1 - y 2 | + | z 1 - z 2 |ã§è¡šãããã Input N M d 1 ... d N x 1 y 1 z 1 ... x M y M z M å
¥åã¯å
šãп޿°ã§äžããããã 1è¡ç®ã« N , M ãäžããããã 2è¡ç®ã«ç§»åå¯èœãªãã³ããã¿ã³è·é¢ d i ã空çœåºåãã§äžããããã 3è¡ç®ä»¥éã® M è¡ã«ã M åã®èšªãããæã®æ Œåç¹ã®åº§æš( x i , y i , z i )ã1è¡ãã€ç©ºçœåºåãã§äžããããã Constraints å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã 1 †N †15 1 †M †15 1 †d i †3Ã10 5 -10 5 †x i , y i , z i †10 5 äžãããããã³ããã¿ã³è·é¢ d i ã¯å
šãŠç°ãªãã äžããããæ Œåç¹ã®åº§æšã¯å
šãŠç°ãªãã Output M åã®æå
šãŠã蚪ããã®ã«ãããæçã¯ãŒãåæ°ã1è¡ã«åºåããã 蚪ããããšãäžå¯èœãªæãããå Žåã¯-1ãåºåããã Sample Input 1 2 1 1 2 5 0 0 Sample Output 1 3 Sample Input 2 2 2 9 3 3 0 0 3 9 0 Sample Output 2 2 Sample Input 3 1 1 4 3 0 0 Sample Output 3 -1 | 35,934 |
Calender Colors Taro is a member of a programming contest circle. In this circle, the members manage their schedules in the system called Great Web Calender . Taro has just added some of his friends to his calendar so that he can browse their schedule on his calendar. Then he noticed that the system currently displays all the schedules in only one color, mixing the schedules for all his friends. This is difficult to manage because it's hard to tell whose schedule each entry is. But actually this calender system has the feature to change the color of schedule entries, based on the person who has the entries. So Taro wants to use that feature to distinguish their plans by color. Given the colors Taro can use and the number of members, your task is to calculate the subset of colors to color all schedule entries. The colors are given by "Lab color space". In Lab color space, the distance between two colors is defined by the square sum of the difference of each element. Taro has to pick up the subset of colors that maximizes the sum of distances of all color pairs in the set. Input The input is like the following style. N M L_{0} a_{0} b_{0} L_{1} a_{1} b_{1} ... L_{N-1} a_{N-1} b_{N-1} The first line contains two integers N and M ( 0 \leq M \leq N \leq 20 ), where N is the number of colors in the input, and M is the number of friends Taro wants to select the colors for. Each of the following N lines contains three decimal integers L ( 0.0 \leq L \leq 100.0 ), a ( -134.0 \leq a \leq 220.0 ) and b ( -140.0 \leq b \leq 122.0 ) which represents a single color in Lab color space. Output Output the maximal of the total distance. The output should not contain an error greater than 10^{-5} . Sample Input 1 3 2 0 0 0 10 10 10 100 100 100 Output for the Sample Input 1 30000.00000000000000000000 Sample Input 2 5 3 12.0 15.0 9.0 10.0 -3.0 2.2 3.5 6.8 9.0 2.1 4.4 5.9 1.2 4.0 -5.4 Output for the Sample Input 2 1003.44000000000005456968 Sample Input 3 2 1 1.0 1.0 1.0 0.0 0.0 0.0 Output for the Sample Input 3 0.00000000000000000000 | 35,935 |
Almost Identical Programs The programming contest named Concours de Programmation Comtemporaine Interuniversitaire (CPCI) has a judging system similar to that of ICPC; contestants have to submit correct outputs for two different inputs to be accepted as a correct solution. Each of the submissions should include the program that generated the output. A pair of submissions is judged to be a correct solution when, in addition to the correctness of the outputs, they include an identical program. Many contestants, however, do not stop including a different version of their programs in their second submissions, after modifying a single string literal in their programs representing the input file name, attempting to process different input. The organizers of CPCI are exploring the possibility of showing a special error message for such close submissions, indicating contestants what's wrong with such submissions. Your task is to detect such close submissions. Input The input consists of at most 100 datasets, each in the following format. s 1 s 2 Each of s 1 and s 2 is a string written in a line, with the length between 1 and 200, inclusive. They are the first and the second submitted programs respectively. A program consists of lowercase letters ( a , b , ..., z ), uppercase letters ( A , B , ..., Z ), digits ( 0 , 1 , ..., 9 ), double quotes ( " ), and semicolons ( ; ). When double quotes occur in a program, there are always even number of them. The end of the input is indicated by a line containing one ' . ' (period). Output For each dataset, print the judge result in a line. If the given two programs are identical, print IDENTICAL . If two programs differ with only one corresponding string literal, print CLOSE . Otherwise, print DIFFERENT . A string literal is a possibly empty sequence of characters between an odd-numbered occurrence of a double quote and the next occurrence of a double quote. Sample Input print"hello";print123 print"hello";print123 read"B1input";solve;output; read"B2";solve;output; read"C1";solve;output"C1ans"; read"C2";solve;output"C2ans"; """""""" """42""""" slow"program" fast"code" "super"fast"program" "super"faster"program" X"" X I"S""CREAM" I"CE""CREAM" 11"22"11 1"33"111 . Output for the Sample Input IDENTICAL CLOSE DIFFERENT CLOSE DIFFERENT DIFFERENT DIFFERENT CLOSE DIFFERENT | 35,936 |
åé¡å YAML YAML (YAML Ain't Markup Language)ãšã¯ããªããžã§ã¯ããæååã§è¡šçŸãã圢åŒã®äžã€ã§ãã YAMLã®ãµãã»ããã§è¡šããããªããžã§ã¯ããšãããããã£ãæå®ããã¯ãšãªãäžããããã®ã§ãæå®ãããããããã£ã®å€ãçããŠãã ããã YAMLã®ãµãã»ãã YAML ã®ãµãã»ããã¯ã次ã®ãããªæ¡åŒµ BNF èšæ³ã§è¡šãããæ§æèŠåã«åŸããŸãã yaml: mapping(0) mapping(n): mapping-item(n) | mapping-item(n) mapping(n) mapping-item(n): indent(n) key ':' ' ' string '\n' | indent(n) key ':' '\n' mapping(m) (ãã ãm>n) key: [a-z0-9]+ (â»è±åå°æåãŸãã¯æ°åãããªã1æå以äžã®æåå) string: [a-z0-9 ]+ (â»è±åå°æåãŸãã¯æ°åãŸãã¯ã¹ããŒã¹ãããªã1æå以äžã®æåå) indent(0): "" (â»ç©ºæåå) indent(n+1): ' ' indent(n) (â»ã¹ããŒã¹ãn+1å䞊ã¹ãæåå) '\n'ã¯æ¹è¡æåã衚ããŸãã mapping(n) ã¯ãªããžã§ã¯ãã衚ãã mapping(n) ã«å«ãŸãã mapping-item(n) ã¯ããªããžã§ã¯ãã«å«ãŸããããããã£ã衚ããŸãã mapping-item(n): indent(n) key ':' ' ' string '\n' ã¯ã key ã§è¡šãããããããã£ã®å€ãstringã§è¡šãããæååã§ããããšã瀺ããŸãã mapping-item(n): indent(n) key ':' '\n' mapping(m) ã¯ã key ã§è¡šãããããããã£ã®å€ãmapping(m)ã§è¡šããããªããžã§ã¯ãã§ããããšã瀺ããŸãã 1ã€ã®ãªããžã§ã¯ãã«ã2ã€ä»¥äžãåã key ãæã€ããããã£ãå«ãŸããããšã¯ãããŸããã ããããã£ãæå®ããã¯ãšãªã®åœ¢åŒ ããããã£ãæå®ããã¯ãšãªã¯ã .key_1.key_2(..çç¥..).key_n ã®ããã«ã' . 'ãš key ã亀äºã«çŸãã圢ã§äžããããããã¯ã yaml ã§äžãããããªããžã§ã¯ãã®ã key 1 ãšãã key ãæã€ããããã£ã®å€ã§ãããªããžã§ã¯ãã®ã key 2 ãšãã key ãæã€ããããã£ã®å€ã§ãããªããžã§ã¯ãã®ã(..çç¥..) key n ãšãã key ãæã€ããããã£ãã衚ããŸãã ãªããããi( 1 †i †n - 1 )ã«ã€ããŠã.key_1.key_2.(..çç¥..).key_iãŸã§ã§è¡šãããããããã£ã®å€ããªããžã§ã¯ãã§ãªãããŸãã¯ãªããžã§ã¯ãã§ãããkey_i+1ãšããããããã£ãå«ãã§ããªãå Žåã.key_1.key_2(..çç¥..).key_n ã§è¡šããããããªããããã£ã¯ååšããªããšã¿ãªããŸãã Input .key_1.key_2(...).key_n yaml 1 †n †20 å
¥åå
šäœã«å«ãŸããæåæ° â€ 50,000 Output ããããã£ã®å€ã 1 è¡ã§åºåããŠãã ããã æå®ãããããããã£ãååšããªãå Žå㯠no such property , ããããã£ã®å€ããªããžã§ã¯ãã®å Žå㯠object , ããããã£ã®å€ãæååã®å Žå㯠string "<æååã®å
容>" ãšåºåããŠãã ããã Sample Input 1 .tweets.1 name: shimeji id: shimejitan tweets: 1: shimejilove 2: azupero Output for the Sample Input 1 string "shimejilove" Sample Input 2 .a a: sample case Output for the Sample Input 2 string "sample case" Sample Input 3 .my.obj my: str: string value obj: a: a b: b c: c Output for the Sample Input 3 object Sample Input 4 .str.inner str: inner Output for the Sample Input 4 no such property Sample Input 5 .no.such.property object: prop1: str prop2: str Output for the Sample Input 5 no such property | 35,937 |
Score : 200 points Problem Statement You are given a string S of length N . Among its subsequences, count the ones such that all characters are different, modulo 10^9+7 . Two subsequences are considered different if their characters come from different positions in the string, even if they are the same as strings. Here, a subsequence of a string is a concatenation of one or more characters from the string without changing the order. Constraints 1 \leq N \leq 100000 S consists of lowercase English letters. |S|=N Input Input is given from Standard Input in the following format: N S Output Print the number of the subsequences such that all characters are different, modulo 10^9+7 . Sample Input 1 4 abcd Sample Output 1 15 Since all characters in S itself are different, all its subsequences satisfy the condition. Sample Input 2 3 baa Sample Output 2 5 The answer is five: b , two occurrences of a , two occurrences of ba . Note that we do not count baa , since it contains two a s. Sample Input 3 5 abcab Sample Output 3 17 | 35,938 |
Problem D: Circle and Points You are given N points in the xy -plane. You have a circle of radius one and move it on the xy -plane, so as to enclose as many of the points as possible. Find how many points can be simultaneously enclosed at the maximum. A point is considered enclosed by a circle when it is inside or on the circle. Fig 1. Circle and Points Input The input consists of a series of data sets, followed by a single line only containing a single character '0', which indicates the end of the input. Each data set begins with a line containing an integer N , which indicates the number of points in the data set. It is followed by N lines describing the coordinates of the points. Each of the N lines has two decimal fractions X and Y , describing the x - and y -coordinates of a point, respectively. They are given with five digits after the decimal point. You may assume 1 <= N <= 300, 0.0 <= X <= 10.0, and 0.0 <= Y <= 10.0. No two points are closer than 0.0001. No two points in a data set are approximately at a distance of 2.0. More precisely, for any two points in a data set, the distance d between the two never satisfies 1.9999 <= d <= 2.0001. Finally, no three points in a data set are simultaneously very close to a single circle of radius one. More precisely, let P 1 , P 2 , and P 3 be any three points in a data set, and d 1 , d 2 , and d 3 the distances from an arbitrarily selected point in the xy -plane to each of them respectively. Then it never simultaneously holds that 0.9999 <= d i <= 1.0001 ( i = 1, 2, 3). Output For each data set, print a single line containing the maximum number of points in the data set that can be simultaneously enclosed by a circle of radius one. No other characters including leading and trailing spaces should be printed. Sample Input 3 6.47634 7.69628 5.16828 4.79915 6.69533 6.20378 6 7.15296 4.08328 6.50827 2.69466 5.91219 3.86661 5.29853 4.16097 6.10838 3.46039 6.34060 2.41599 8 7.90650 4.01746 4.10998 4.18354 4.67289 4.01887 6.33885 4.28388 4.98106 3.82728 5.12379 5.16473 7.84664 4.67693 4.02776 3.87990 20 6.65128 5.47490 6.42743 6.26189 6.35864 4.61611 6.59020 4.54228 4.43967 5.70059 4.38226 5.70536 5.50755 6.18163 7.41971 6.13668 6.71936 3.04496 5.61832 4.23857 5.99424 4.29328 5.60961 4.32998 6.82242 5.79683 5.44693 3.82724 6.70906 3.65736 7.89087 5.68000 6.23300 4.59530 5.92401 4.92329 6.24168 3.81389 6.22671 3.62210 0 Output for the Sample Input 2 5 5 11 | 35,939 |
Problem L Wall Making Game The game Wall Making Game , a two-player board game, is all the rage. This game is played on an $H \times W$ board. Each cell of the board is one of empty , marked , or wall . At the beginning of the game, there is no wall on the board. In this game, two players alternately move as follows: A player chooses one of the empty cells (not marked and not wall). If the player can't choose a cell, he loses. Towards each of the four directions (upper, lower, left, and right) from the chosen cell, the player changes cells (including the chosen cell) to walls until the player first reaches a wall or the outside of the board. Note that marked cells cannot be chosen in step 1, but they can be changed to walls in step 2. Fig.1 shows an example of a move in which a player chooses the cell at the third row and the fourth column. Fig.1: An example of a move in Wall Making Game. Your task is to write a program that determines which player wins the game if the two players play optimally from a given initial board. Input The first line of the input consists of two integers $H$ and $W$ $(1 \leq H, W \leq 20)$, where $H$ and $W$ are the height and the width of the board respectively. The following $H$ lines represent the initial board. Each of the $H$ lines consists of $W$ characters. The $j$-th character of the $i$-th line is ' . ' if the cell at the $j$-th column of the $i$-th row is empty, or ' X ' if the cell is marked. Output Print " First " (without the quotes) in a line if the first player wins the given game. Otherwise, print " Second " (also without the quotes) in a line. Sample Input 1 2 2 .. .. Output for the Sample Input 1 Second Sample Input 2 2 2 X. .. Output for the Sample Input 2 First Sample Input 3 4 5 X.... ...X. ..... ..... Output for the Sample Input 3 First | 35,940 |
å¿
åïŒäžŠã¹ ãã©ã³ãã䜿ã£ãã²ãŒã ã«ãïŒäžŠã¹ãããããŸããããã§ã¯ãããç°¡åã«ããã²ãŒã ãèããŸããïŒããïŒïŒã®çªå·ãããããæžãããïŒïŒæã®ã«ãŒãã䜿ã£ãŠïŒäžŠã¹ãããŸãã察æŠã¯ãïŒè
ã ãã§æ¬¡ã®ããã«ã²ãŒã ãé²ããŸãã ãå Žãã«ïŒã®ã«ãŒãã眮ããŸãã ïŒè
ã«ã¯ãæ®ãã®ã«ãŒããã©ã³ãã ã«ïŒæãã€é
åžãããŸãã å
æã®ææã¡ã®ã«ãŒãã®ãã¡ãå Žã«ããã«ãŒãã®çªå·ãšé£ç¶ããçªå·ã®ã«ãŒããããã°ããã®ãã¡ã®ïŒæãå Žã«çœ®ããŸãããã¬ã€ã€ãŒã¯ã«ãŒãã眮ããå Žåã«ã¯å¿
ã眮ããªããã°ãããŸãããç¡ããšãã«éããã«ãŒããåºããã«çžæã®çªã«ãªããŸãã åŸæãåãèŠé ã§ãææã¡ã®ã«ãŒããå Žã«çœ®ããŸãã æé ïŒãšïŒãç¹°ãè¿ããŠãäžæ¹ã®ææã¡ã®ã«ãŒãããªããªããŸã§ç¶ããŸããå
ã«ææã¡ã®ã«ãŒãããã¹ãŠå Žã«çœ®ããæ¹ãåè
ãšãªããŸãã å
æã®ã«ãŒãã®çªå·ãäžãããããšããåŸæãã©ã®ããã«ã«ãŒããåºããŠããŠããå
æãåã€æé ãå°ãªããšãäžã€ããããå€å®ããŠåºåããããã°ã©ã ãäœæããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã N game 1 game 2 : game N ïŒè¡ç®ã«ã¯ãã²ãŒã ãè¡ãåæ° N (1 †N †100) ãäžãããããç¶ã N è¡ã«ã i åç®ã®ã²ãŒã ã®æ
å ± game i ãäžãããããå game i ã¯ã以äžã®åœ¢åŒã§äžããããã f 1 f 2 f 3 f 4 f 5 f 6 f j (1 †f j †13, f j â 7) ã¯å
æã«é
ãããã«ãŒãã®çªå·ã§ããããã ããåãè¡ã«çªå·ãéè€ããŠçŸããããšã¯ãªãïŒ j â k ã«ã€ã㊠f j â f k )ã Output åã²ãŒã ã«ã€ããŠãåŸæãã©ã®ããã«ã«ãŒããåºããŠããŠããå
æãåã€æé ãå°ãªããšãäžã€ããå Žåãyesããããã§ãªãå ŽåãnoããšïŒè¡ã«åºåããã Sample Input 1 5 1 2 3 4 5 6 1 3 5 6 8 4 1 2 3 4 5 8 1 2 4 5 10 11 1 2 3 6 9 11 Sample Output 1 yes yes no yes no | 35,941 |
Score: 400 points Problem Statement The Kingdom of Takahashi has N towns, numbered 1 through N . There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i . Takahashi, the king, loves the positive integer K . The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Help the king by writing a program that answers this question. Constraints 2 \leq N \leq 2 \times 10^5 1 \leq A_i \leq N 1 \leq K \leq 10^{18} Input Input is given from Standard Input in the following format: N K A_1 A_2 \dots A_N Output Print the integer representing the town the king will be in if he starts at Town 1 and uses a teleporter exactly K times from there. Sample Input 1 4 5 3 2 4 1 Sample Output 1 4 If we start at Town 1 and use the teleporter 5 times, our travel will be as follows: 1 \to 3 \to 4 \to 1 \to 3 \to 4 . Sample Input 2 6 727202214173249351 6 5 2 5 3 2 Sample Output 2 2 | 35,942 |
Score : 1200 points Problem Statement There are N arrays. The length of each array is M and initially each array contains integers (1ïŒ2ïŒ...ïŒM) in this order. Mr. Takahashi has decided to perform Q operations on those N arrays. For the i -th ( 1â€iâ€Q ) time, he performs the following operation. Choose an arbitrary array from the N arrays and move the integer a_i ( 1â€a_iâ€M ) to the front of that array. For example, after performing the operation on a_i=2 and the array (5ïŒ4ïŒ3ïŒ2ïŒ1) , this array becomes (2ïŒ5ïŒ4ïŒ3ïŒ1) . Mr. Takahashi wants to make N arrays exactly the same after performing the Q operations. Determine if it is possible or not. Constraints 2â€Nâ€10^5 2â€Mâ€10^5 1â€Qâ€10^5 1â€a_iâ€M Input The input is given from Standard Input in the following format: N M Q a_1 a_2 ... a_Q Output Print Yes if it is possible to make N arrays exactly the same after performing the Q operations. Otherwise, print No . Sample Input 1 2 2 3 2 1 2 Sample Output 1 Yes You can perform the operations as follows. Sample Input 2 3 2 3 2 1 2 Sample Output 2 No Sample Input 3 2 3 3 3 2 1 Sample Output 3 Yes You can perform the operations as follows. Sample Input 4 3 3 6 1 2 2 3 3 3 Sample Output 4 No | 35,943 |
Arithmetic Progressions An arithmetic progression is a sequence of numbers $a_1, a_2, ..., a_k$ where the difference of consecutive members $a_{i+1} - a_i$ is a constant ($1 \leq i \leq k-1$). For example, the sequence 5, 8, 11, 14, 17 is an arithmetic progression of length 5 with the common difference 3. In this problem, you are requested to find the longest arithmetic progression which can be formed selecting some numbers from a given set of numbers. For example, if the given set of numbers is {0, 1, 3, 5, 6, 9}, you can form arithmetic progressions such as 0, 3, 6, 9 with the common difference 3, or 9, 5, 1 with the common difference -4. In this case, the progressions 0, 3, 6, 9 and 9, 6, 3, 0 are the longest. Input The input consists of a single test case of the following format. $n$ $v_1$ $v_2$ ... $v_n$ $n$ is the number of elements of the set, which is an integer satisfying $2 \leq n \leq 5000$. Each $v_i$ ($1 \leq i \leq n$) is an element of the set, which is an integer satisfying $0 \leq v_i \leq 10^9$. $v_i$'s are all different, i.e., $v_i \ne v_j$ if $i \ne j$. Output Output the length of the longest arithmetic progressions which can be formed selecting some numbers from the given set of numbers. Sample Input 1 6 0 1 3 5 6 9 Sample Output 1 4 Sample Input 2 7 1 4 7 3 2 6 5 Sample Output 2 7 Sample Input 3 5 1 2 4 8 16 Sample Output 3 2 | 35,944 |
Score : 400 points Problem Statement Given is a string S consisting of L and R . Let N be the length of S . There are N squares arranged from left to right, and the i -th character of S from the left is written on the i -th square from the left. The character written on the leftmost square is always R , and the character written on the rightmost square is always L . Initially, one child is standing on each square. Each child will perform the move below 10^{100} times: Move one square in the direction specified by the character written in the square on which the child is standing. L denotes left, and R denotes right. Find the number of children standing on each square after the children performed the moves. Constraints S is a string of length between 2 and 10^5 (inclusive). Each character of S is L or R . The first and last characters of S are R and L , respectively. Input Input is given from Standard Input in the following format: S Output Print the number of children standing on each square after the children performed the moves, in order from left to right. Sample Input 1 RRLRL Sample Output 1 0 1 2 1 1 After each child performed one move, the number of children standing on each square is 0, 2, 1, 1, 1 from left to right. After each child performed two moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right. After each child performed 10^{100} moves, the number of children standing on each square is 0, 1, 2, 1, 1 from left to right. Sample Input 2 RRLLLLRLRRLL Sample Output 2 0 3 3 0 0 0 1 1 0 2 2 0 Sample Input 3 RRRLLRLLRRRLLLLL Sample Output 3 0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0 | 35,945 |
Score : 600 points Problem Statement We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N-1 or smaller. Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N , and increase each of the other elements by 1 . It can be proved that the largest element in the sequence becomes N-1 or smaller after a finite number of operations. You are given an integer K . Find an integer sequence a_i such that the number of times we will perform the above operation is exactly K . It can be shown that there is always such a sequence under the constraints on input and output in this problem. Constraints 0 †K †50 \times 10^{16} Input Input is given from Standard Input in the following format: K Output Print a solution in the following format: N a_1 a_2 ... a_N Here, 2 †N †50 and 0 †a_i †10^{16} + 1000 must hold. Sample Input 1 0 Sample Output 1 4 3 3 3 3 Sample Input 2 1 Sample Output 2 3 1 0 3 Sample Input 3 2 Sample Output 3 2 2 2 The operation will be performed twice: [2, 2] -> [0, 3] -> [1, 1]. Sample Input 4 3 Sample Output 4 7 27 0 0 0 0 0 0 Sample Input 5 1234567894848 Sample Output 5 10 1000 193 256 777 0 1 1192 1234567891011 48 425 | 35,946 |
åé¡ F : å
šåæš ä»ïŒGââgle Code Jam ã®å°åºå€§äŒãå§ãŸãããšããŠããïŒ å·Šã®åžã«åº§ã£ãŠããç·ã® ID 㯠wata ãšèšããããïŒ æ±äº¬å€§åп代ã®èšæ¶ã«ïŒäŒŒããã㪠ID ã®ä»²éãå±
ãèŠããããïŒ ãããïŒåã®ä»²éã¯äžäººæ®ããçŸå°å¥³ã ã£ãã¯ãã ïŒ åã®èšæ¶ã®äžã® wata ã¯ïŒãããã€ãã奜ãã ã£ãïŒ ç¹ã«ïŒãããã€ã亀差ã倧奜ãã§ïŒ æ§ã
ãªãããã€ãéã亀差ãããããšã«äžçš®ã®è奮ããèŠãããšèšãå°ãå€ãã£ã奎ã ã£ãïŒ ãããã€ãã®çè«ã®åã䜿ãã°ïŒ äžããããã°ã©ãäžã§èŸºãå
±æããªãè€æ°ã®å
šåæšãæ±ããããšã¯ãšãŠãç°¡åãªåé¡ã ãšèšã£ãŠããæ°ãããïŒ ãããïŒç¹å¥ãªã°ã©ãã«é¢ããŠã¯ïŒ ãããã€ãã®ã¢ã«ãŽãªãºã ãçŽæ¥ã«é©çšãããããé«éãªã¢ã«ãŽãªãºã ãããã®ã§ã¯ãªããïŒ åé¡ N åã®é ç¹ãããªãå®å
šã°ã©ãã«ãããŠïŒ 蟺ãå
±æããªãå
šåæšã K åäœæããïŒ å®å
šã°ã©ããšã¯ïŒå
šãŠã®çžç°ãªã 2 é ç¹éã« 1 æ¬ã®èŸºãæã€ã°ã©ãã§ããïŒ äžå³ã¯ïŒ4 é ç¹ã®å®å
šã°ã©ãã®äŸã§ããïŒ 4 é ç¹ã®å®å
šã°ã©ãïŒ å
šåæšãšã¯ïŒå
ã®ã°ã©ãã®å
šãŠã®é ç¹ãšäžéšã®èŸºãããªãæšã®ããšã§ããïŒ æšãšã¯ïŒé£çµãã€éè·¯ãæããªãã°ã©ãã®ããšã§ããïŒ äžå³ã¯ïŒ4 é ç¹ã®å®å
šã°ã©ãã«ãããïŒèŸºãå
±æããªã 2 ã€ã®å
šåæšã§ããïŒ 4 é ç¹ã®å®å
šã°ã©ãã®å
šåæšã®äŸïŒ 4 é ç¹ã®å®å
šã°ã©ãã®å
šåæšã§ããïŒåã®äŸãšèŸºãå
±æããªããã®ïŒ å
¥å å
¥å㯠1 è¡ãããªãïŒ 2 ã€ã®æŽæ° N , K ãæžãããŠããïŒ åºå æ¡ä»¶ãæºãã K åã®å
šåæšãäœãããšãã§ããªãæïŒ-1 ãšã ãåºåããïŒ æ¡ä»¶ãæºãã K åã®å
šåæšãäœãããšãã§ããæïŒ K åã®å
šåæšãæ¹è¡ã§åºåãåºåããïŒ 1 ã€ã®å
šåæšã¯ N - 1 è¡ã§è¡šãããïŒ ãã® i è¡ç®ã«ã¯ïŒãã®å
šåæšã®èŸº i ãçµã¶ 2 ã€ã®é ç¹ã衚ã 2 ã€ã®æŽæ°ãã¹ããŒã¹ã§åºåãåºåããïŒ ããã§ïŒé ç¹ã¯ 1 ãã N ãŸã§ã®æŽæ°ã§è¡šããã®ãšããïŒ å¶çŽ 2 †N †10000 1 †K †100 éšåç¹ ãã®åé¡ã®å€å®ã«ã¯ïŒ20 ç¹åã®ãã¹ãã±ãŒã¹ã®ã°ã«ãŒããèšå®ãããŠããïŒ ãã®ã°ã«ãŒãã«å«ãŸãããã¹ãã±ãŒã¹ã®å
¥åã¯ä»¥äžãæºããïŒ 1 †N †8 å
¥åºåäŸ å
¥åºåäŸ 1 å
¥åäŸ 1: 4 2 å
¥åäŸ 1 ã«å¯Ÿããåºåã®äŸ: 1 2 1 4 2 3 1 3 2 4 3 4 ãã®å
¥åºåäŸã¯å顿äžã®å³ãšå¯Ÿå¿ããŠããïŒ å
¥åºåäŸ 2 å
¥åäŸ 2: 4 3 å
¥åäŸ 2 ã«å¯Ÿããåºåã®äŸ: -1 | 35,947 |
Score : 600 points Problem Statement In Dwango Co., Ltd., there is a content distribution system named 'Dwango Media Cluster', and it is called 'DMC' for short. The name 'DMC' sounds cool for Niwango-kun, so he starts to define DMC-ness of a string. Given a string S of length N and an integer k (k \geq 3) , he defines the k -DMC number of S as the number of triples (a, b, c) of integers that satisfy the following conditions: 0 \leq a < b < c \leq N - 1 S[a] = D S[b] = M S[c] = C c-a < k Here S[a] is the a -th character of the string S . Indexing is zero-based, that is, 0 \leq a \leq N - 1 holds. For a string S and Q integers k_0, k_1, ..., k_{Q-1} , calculate the k_i -DMC number of S for each i (0 \leq i \leq Q-1) . Constraints 3 \leq N \leq 10^6 S consists of uppercase English letters 1 \leq Q \leq 75 3 \leq k_i \leq N All numbers given in input are integers Input Input is given from Standard Input in the following format: N S Q k_{0} k_{1} ... k_{Q-1} Output Print Q lines. The i -th line should contain the k_i -DMC number of the string S . Sample Input 1 18 DWANGOMEDIACLUSTER 1 18 Sample Output 1 1 (a,b,c) = (0, 6, 11) satisfies the conditions. Strangely, Dwango Media Cluster does not have so much DMC-ness by his definition. Sample Input 2 18 DDDDDDMMMMMCCCCCCC 1 18 Sample Output 2 210 The number of triples can be calculated as 6\times 5\times 7 . Sample Input 3 54 DIALUPWIDEAREANETWORKGAMINGOPERATIONCORPORATIONLIMITED 3 20 30 40 Sample Output 3 0 1 2 (a, b, c) = (0, 23, 36), (8, 23, 36) satisfy the conditions except the last one, namely, c-a < k_i . By the way, DWANGO is an acronym for "Dial-up Wide Area Network Gaming Operation". Sample Output 4 30 DMCDMCDMCDMCDMCDMCDMCDMCDMCDMC 4 5 10 15 20 Sample Output 4 10 52 110 140 | 35,948 |
Score : 100 points Problem Statement There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N -th child. How many candies will be necessary in total? Constraints 1âŠNâŠ100 Input The input is given from Standard Input in the following format: N Output Print the necessary number of candies in total. Sample Input 1 3 Sample Output 1 6 The answer is 1+2+3=6 . Sample Input 2 10 Sample Output 2 55 The sum of the integers from 1 to 10 is 55 . Sample Input 3 1 Sample Output 3 1 Only one child. The answer is 1 in this case. | 35,949 |
F: MOD Rush åé¡ é·ã N ã®æ£ã®æŽæ°å A ãšãé·ã M ã®æ£ã®æŽæ°å B ãäžããããŸãã ãã¹ãŠã® (i, j) (1 \leq i \leq N, 1 \leq j \leq M) ã«ã€ããŠã A_i ã B_j ã§å²ã£ãããŸããæ±ãããããã®åãåºåããŠãã ããã å
¥ååœ¢åŒ N M A_1 A_2 ... A_N B_1 B_2 ... B_M å¶çŽ 1 \leq N, M \leq 2 \times 10^5 1 \leq A_i, B_i \leq 2 \times 10^5 å
¥åã¯ãã¹ãп޿°ã§äžãããã åºååœ¢åŒ çãã 1 è¡ã«åºåããŠãã ãããæåŸã«æ¹è¡ããŠãã ããã å
¥åäŸ 1 3 3 5 1 6 2 3 4 åºåäŸ 1 9 æ°å A ã® 1 çªç®ã®èŠçŽ ããæ°å B ã®åèŠçŽ ã§å²ã£ãããŸããèããŸãã 5 ã 2 ã§å²ããšããŸã㯠1 ã 3 ã§å²ããšããŸã㯠2 ã 4 ã§å²ããšããŸã㯠1 ã§ãã åæ§ã« 2 çªç®ã®èŠçŽ ã«ã€ããŠãèãããšãããŸãã¯ãããã 1, 1, 1 ã§ãã 3 çªç®ã®èŠçŽ ã«ã€ããŠãèãããšãããŸãã¯ãããã 0, 0, 2 ã§ãã ããŸããåèšãããš 1 + 2 + 1 + 1 + 1 + 1 + 0 + 0 + 2 = 9 ãšãªãã®ã§ã 9 ãåºåããŸãã å
¥åäŸ 2 2 4 2 7 3 3 4 4 åºåäŸ 2 16 æ°åå
ã«ã¯åãå€ãè€æ°å«ãŸããŠããããšããããŸãããããããã®èŠçŽ ã«å¯ŸããŠããŸããèšç®ããŠåãæ±ããŸãã å
¥åäŸ 3 3 1 12 15 21 3 åºåäŸ 3 0 | 35,950 |
Pair of Primes We arrange the numbers between 1 and N (1 <= N <= 10000) in increasing order and decreasing order like this: 1 2 3 4 5 6 7 8 9 . . . N N . . . 9 8 7 6 5 4 3 2 1 Two numbers faced each other form a pair. Your task is to compute the number of pairs P such that both numbers in the pairs are prime. Input Input contains several test cases. Each test case consists of an integer N in one line. Output For each line of input, output P . Sample Input 1 4 7 51 Output for the Sample Input 0 2 2 6 | 35,951 |
Reversing Numbers Write a program which reads a sequence and prints it in the reverse order. Input The input is given in the following format: n a 1 a 2 . . . a n n is the size of the sequence and a i is the i th element of the sequence. Output Print the reversed sequence in a line. Print a single space character between adjacent elements (Note that your program should not put a space character after the last element). Constraints n †100 0 †a i < 1000 Sample Input 1 5 1 2 3 4 5 Sample Output 1 5 4 3 2 1 Sample Input 2 8 3 3 4 4 5 8 7 9 Sample Output 2 9 7 8 5 4 4 3 3 Note 解説 | 35,952 |
Problem B: Hating Crowd Problem ããŒãåã¯1幎12ã¶ææ¯æ30æ¥ãŸã§èš360æ¥ã®äžçç·ã§æ®ãããŠããŸãããã®äžçã§ã¯æ¯å¹Žåãæ¥çšã® N åã®é£äŒãäžçäžã®äººã«é©çšãããŠããŸãããé£äŒ i 㯠M i æ D i æ¥ããå§ãŸãé£ç¶ãã V i æ¥éã§ãã ããŒãåã¯NEETãªã®ã§é£äŒã«é¢ä¿ãªãæ¯æ¥äŒã¿ã§ããããæ¥ããŒãåã¯çããåºãããããšæããŸãããã人混ã¿ãå«ããªã®ã§ãé£äŒã®åœ±é¿ã§æ··éããæ¥ã¯ãªãã¹ãå€ã«åºãããããŸãããããã§ãããŒãåã¯ä»¥äžã®æ¹æ³ã§åæ¥ã®æ··é床ãèšç®ããæ··é床ãäžçªå°ããæ¥ãæ¢ãããšããŠããŸãã ããæ¥ä» x ããé£äŒ i ã«ãã£ãŠåãã圱é¿ã®åºŠåãè¡šãæ°å€ã¯ãæ¥ä» x ãé£äŒ i ã®äžã«å«ãŸããŠããã° S i ã§ãããããã§ãªããã°ã max ( 0, S i â min ( x ããé£äŒ i ã®åæ¥ãŸã§ã®æ¥æ° , é£äŒ i ã®æçµæ¥ãã x ãŸã§ã®æ¥æ° ) )ã§ãã ããæ¥ä» x ã®æ··é床ã¯ã N åã®é£äŒããåãã圱é¿ã®åºŠåã®äžã§ãæã倧ããåãã圱é¿ã®åºŠåãšãªã 1幎ã®äžã§äžçªå°ããæ··é床ãåºåããŠãã ããã ãã ããé£äŒ i ã¯å¹Žãè·šãäºããããŸãããŸããé£äŒã®æ¥çšã¯éè€ããäºããããŸãã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã N M 1 D 1 V 1 S 1 M 2 D 2 V 2 S 2 ... M N D N V N S N 1è¡ç®ã«æŽæ° N ãäžããããã 2è¡ç®ãã N +1è¡ç®ã«æŽæ° M i , D i , V i , S i ã空çœåºåãã§äžãããããïŒ1 †i †N ïŒ Constraints å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã 1 †N †100 1 †M i †12 1 †D i †30 1 †V i , S i †360 Output äžçªå°ããæ··é床ã1è¡ã«åºåããã Sample Input 1 1 1 1 359 1 Sample Output 1 0 Sample Input 2 2 2 4 25 306 1 9 7 321 Sample Output 2 158 Sample Input 3 8 2 9 297 297 8 6 359 211 8 16 28 288 7 9 113 143 3 18 315 190 10 18 277 300 9 5 276 88 3 5 322 40 Sample Output 3 297 | 35,953 |
ãšã»ãã®ãã€ã¢ æããšã»ãã®ãã€ã¢ãšããã²ãŒã ããããŸããã n 人ãåå ããŠãããšããŸããããåå è
ã¯äžå¿ãåããŠåé£ãçµã¿ã1 ããé çªã«çªå·ãæ¯ãããŸããã¢ãã¢ãã®ãã€ã¢ãã²ãšã€ãåå è
n (å·Šã®å³å
åŽã®å€§ããæ°åã® 30 )ã«æž¡ãããŸãããã€ã¢ãæž¡ãããåå è
ã¯å³é£ã®åå è
ã«ãã®ãã€ã¢ãæž¡ããŸãã m åç®ã«æž¡ããã人ã¯å³é£ã®äººã«æž¡ããŠåé£ããæããŸã(å·Šã®å³ã§ã¯ m = 9 ã®å Žåã衚ããŠããŸã) ã åæž¡ãæ¯ã«äžäººãã€ã¬ããæåŸã«æ®ã£ã人ãåè
ãšãªãããã€ã¢ãããã ããŸãã n , m ãæ±ºãŸã£ãŠãããå®éã«ãã€ã¢ãæž¡ãå§ããåã«ã©ãã«ãããåãŠããããããšããã§ããããäžã®å³ã¯ 30 人ã®åå è
ã§ 9 人ããšã«æãããšããã«ãŒã«ã§ãã®ã²ãŒã ãããå Žåãæžã衚ããŠããŸããå
åŽã®å€§ããæ°åãåå è
ã«æ¯ãããçªå·ãå€åŽã®å°ããæ°åãæããé çªã§ããããã«ãããšã9,18,27,6,16,26 ãšããé çªã§åé£ããæãåºããæåŸã«ã¯ 21 ãæ®ãããšã«ãªããŸããããªãã¡ 21 ãåè
ãšãªããŸã(å°ããæ°åã 30 ã«ãªã£ãŠããŸã)ã ã²ãŒã åå è
æ° n ãšåé£ããæãåºãåå è
ã®éé m ãå
¥åããåè
ã®çªå·ãåºåããããã°ã©ã ãäœæããŠãã ããããã ãã m , n < 1000 ãšããŸãã å
¥å è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã n m ã²ãŒã åå è
æ° n ïŒæŽæ°ïŒãšåé£ããæãåºãåå è
ã®éé m ïŒæŽæ°ïŒã空çœåºåãã§ïŒè¡ã«äžããããŸãã å
¥åã¯ïŒã€ã® 0 ã§çµãããŸããããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã åºå åããŒã¿ã»ããã«å¯ŸããŠãåè
ãšãªããã€ã¢ãããã ã人ã®çªå·ïŒæŽæ°ïŒãïŒè¡ã«åºåããŠãã ããã Sample Input 41 3 30 9 0 0 Output for the Sample Input 31 21 | 35,954 |
Score : 600 points Problem Statement There is a board with N rows and M columns. The information of this board is represented by N strings S_1,S_2,\ldots,S_N . Specifically, the state of the square at the i -th row from the top and the j -th column from the left is represented as follows: S_{i,j}= . : the square is empty. S_{i,j}= # : an obstacle is placed on the square. S_{i,j}= o : a piece is placed on the square. Yosupo repeats the following operation: Choose a piece and move it to its right adjecent square or its down adjacent square. Moving a piece to squares with another piece or an obstacle is prohibited. Moving a piece out of the board is also prohibited. Yosupo wants to perform the operation as many times as possible. Find the maximum possible number of operations. Constraints 1 \leq N \leq 50 1 \leq M \leq 50 S_i is a string of length M consisting of . , # and o . 1 \leq ( the number of pieces )\leq 100 . In other words, the number of pairs (i, j) that satisfy S_{i,j}= o is between 1 and 100 , both inclusive. Input Input is given from Standard Input in the following format: N M S_1 S_2 \vdots S_N Output Print the maximum possible number of operations in a line. Sample Input 1 3 3 o.. ... o.# Sample Output 1 4 Yosupo can perform operations 4 times as follows: o.. .o. ..o ... ... ... -> ... -> ... -> ..o -> ..o o.# o.# o.# o.# .o# Sample Input 2 9 10 .#....o#.. .#..#..##o .....#o.## .###.#o..o #.#...##.# ..#..#.### #o.....#.. ....###..o o.......o# Sample Output 2 24 | 35,955 |
Score : 100 points Problem Statement Takahashi has K 500 -yen coins. (Yen is the currency of Japan.) If these coins add up to X yen or more, print Yes ; otherwise, print No . Constraints 1 \leq K \leq 100 1 \leq X \leq 10^5 Input Input is given from Standard Input in the following format: K X Output If the coins add up to X yen or more, print Yes ; otherwise, print No . Sample Input 1 2 900 Sample Output 1 Yes Two 500 -yen coins add up to 1000 yen, which is not less than X = 900 yen. Sample Input 2 1 501 Sample Output 2 No One 500 -yen coin is worth 500 yen, which is less than X = 501 yen. Sample Input 3 4 2000 Sample Output 3 Yes Four 500 -yen coins add up to 2000 yen, which is not less than X = 2000 yen. | 35,956 |
Score : 600 points Problem Statement You are given an integer sequence of length N , a = { a_1, a_2, âŠ, a_N }, and an integer K . a has N(N+1)/2 non-empty contiguous subsequences, { a_l, a_{l+1}, âŠ, a_r } (1 †l †r †N) . Among them, how many have an arithmetic mean that is greater than or equal to K ? Constraints All input values are integers. 1 †N †2 \times 10^5 1 †K †10^9 1 †a_i †10^9 Input Input is given from Standard Input in the following format: N K a_1 a_2 : a_N Output Print the number of the non-empty contiguous subsequences with an arithmetic mean that is greater than or equal to K . Sample Input 1 3 6 7 5 7 Sample Output 1 5 All the non-empty contiguous subsequences of a are listed below: { a_1 } = { 7 } { a_1, a_2 } = { 7, 5 } { a_1, a_2, a_3 } = { 7, 5, 7 } { a_2 } = { 5 } { a_2, a_3 } = { 5, 7 } { a_3 } = { 7 } Their means are 7 , 6 , 19/3 , 5 , 6 and 7 , respectively, and five among them are 6 or greater. Note that { a_1 } and { a_3 } are indistinguishable by the values of their elements, but we count them individually. Sample Input 2 1 2 1 Sample Output 2 0 Sample Input 3 7 26 10 20 30 40 30 20 10 Sample Output 3 13 | 35,957 |
Parentheses Editor You are working with a strange text editor for texts consisting only of open and close parentheses. The editor accepts the following three keys as editing commands to modify the text kept in it. â ( â appends an open parenthesis (â ( â) to the end of the text. â ) â appends a close parenthesis (â ) â) to the end of the text. â - â removes the last character of the text. A balanced string is one of the following. â () â â ( $X$ ) â where $X$ is a balanced string â$XY$â where both $X$ and $Y$ are balanced strings Initially, the editor keeps an empty text. You are interested in the number of balanced substrings in the text kept in the editor after each of your key command inputs. Note that, for the same balanced substring occurring twice or more, their occurrences should be counted separately. Also note that, when some balanced substrings are inside a balanced substring, both the inner and outer balanced substrings should be counted. Input The input consists of a single test case given in a line containing a number of characters, each of which is a command key to the editor, that is, either â ( â, â ) â, or â - â. The number of characters does not exceed 200 000. They represent a key input sequence to the editor. It is guaranteed that no â - â command comes when the text is empty. Output Print the numbers of balanced substrings in the text kept in the editor after each of the key command inputs are applied, each in one line. Thus, the number of output lines should be the same as the number of characters in the input line. Sample Input 1 (()())---) Sample Output 1 0 0 1 1 3 4 3 1 1 2 Sample Input 2 ()--()()----)(()())) Sample Output 2 0 1 0 0 0 1 1 3 1 1 0 0 0 0 0 1 1 3 4 4 | 35,958 |
èžã¿å°æé JAG倧åŠã«éãäžæš¹åïŒéç§°ã«ãŒåã¯ïŒãã®å€åéã§ããããªãã«èªãããŠïŒICPC (International Collegiate Potchari Contest) ã«åºå Žããããšã«ãªã£ãïŒ ICPCã¯ïŒã¹ããŒãç³»ã®ã³ã³ãã¹ãã§ããïŒé«åºŠãªéåèœåãå¿
èŠãšãããïŒ ãããïŒã«ãŒåã¯ãã€ãããœã³ã³ã®åã«ããŠã°ããã§ïŒå°ãåãã ãã§ãç²ããŠããŸãã»ã©ã«éåäžè¶³ã ã£ãïŒ ããã§ã«ãŒåã¯ïŒICPCã§ããæçžŸãæ®ãããã®ç¬¬1ã¹ããããšããŠïŒæè»œã«å§ããããéåïŒãèžã¿å°æéããå§ããããšã«ããïŒ èžã¿å°æéãšã¯ïŒãã®åã®éãïŒèžã¿å°ãšåºãšã®äžãäžãããã ã²ãããç¹°ãè¿ãã ãã®åçŽãªéåã§ããïŒ ãã ãïŒèžã¿å°æéã§ã¯ïŒæ£ããè¶³ã®æéãè¡ããªããã°ïŒãã®å¹æãåŸãããšã¯ã§ããªãïŒ æ£ããæéãšã¯ïŒä»¥äžã®2çš®é¡ã®å
ãããããæºããè¶³ã®åãã§ããïŒ äž¡è¶³ãåºã«ã€ããç¶æ
ããïŒå·Šè¶³ãšå³è¶³ãèžã¿å°ã®äžã«äžããŠïŒèžã¿å°ã®äžã«äž¡è¶³ãšãã€ããç¶æ
ã«ãªãïŒå·Šè¶³ãšå³è¶³ã©ã¡ããå
ã«äžããŠãããïŒ èžã¿å°ã®äžã«äž¡è¶³ãšãã€ããç¶æ
ããïŒå·Šè¶³ãšå³è¶³ãåºã«äžããŠïŒäž¡è¶³ãåºã«ã€ããç¶æ
ã«ãªãïŒå·Šè¶³ãšå³è¶³ã©ã¡ããå
ã«äžããŠãããïŒ ä»¥äžãããããããã«ïŒåºãŸãã¯èžã¿å°ã®äžã«ããç¶æ
ããé£ç¶ã§çè¶³ã ããäžãäžãããŠãïŒæ£ããæéãšã¯ãªããªãïŒ èžã¿å°æééåã§ã¯ïŒäžèšã®æ£ããæéã®åãã®ãããããæºãããšãïŒ1åãšã«ãŠã³ããïŒãã®ã«ãŠã³ãæ°ã倧ãããã°å€§ããã»ã©ïŒå¹æãåŸãããšãã§ããïŒ åºãšèžã¿å°ãåŸåŸ©ããªããŠãïŒçéã ãã§1åãšã«ãŠã³ãããããšã«æ³šæããŠã»ããïŒ ããªãã¯ïŒããŒã ã¡ã€ãã§ããã«ãŒåã«å°ãã§ã匷ããªã£ãŠã»ãããšèããŠããïŒ ããã§ããªãã¯ïŒã«ãŒåãèžã¿å°æéãããŒã£ãŠããªããïŒããã°ã©ã ãæžããŠãã§ãã¯ããŠãããããšã«ããïŒ ã«ãŒåãèžã¿å°æéã§åãããè¶³ã®æ
å ±ãäžããããã®ã§ïŒæ£ããæéãè¡ã£ãåæ°ãæ±ããïŒ ãã ãïŒ äž¡è¶³ãšãåºã«ã€ããŠããç¶æ
ããèžã¿å°æéãå§ãã ãã®ãšããïŒ Input å
¥åã¯ïŒè€æ°ã®ããŒã¿ã»ããããæ§æããïŒ1ã€ã®å
¥åã«å«ãŸããããŒã¿ã»ããã®æ°ã¯150以äžã§ããïŒ åããŒã¿ã»ããã®åœ¢åŒã¯æ¬¡ã®éãã§ããïŒ $n$ $f_1$ $f_2$ ... $f_n$ 1è¡ç®ã§ïŒè¶³ãåãããåæ°ãè¡šãæŽæ° $n$ ($1 \le n \le 100$) ãäžããããïŒ 2è¡ç®ã§ïŒè¶³ã®åäœã衚ãæååã§ãã $f_i$ ãæç³»åé ã« $n$ åïŒã¹ããŒã¹åºåãã§äžããããïŒ $f_i$ ã¯ïŒä»¥äžã®4çš®é¡ã®æååã®å
ããããã§ããïŒ " lu " : å·Šè¶³ãèžã¿å°ãžäžããïŒ " ru " : å³è¶³ãèžã¿å°ãžäžããïŒ " ld " : å·Šè¶³ãåºãžäžããïŒ " rd " : å³è¶³ãåºãžäžããïŒ åºã«ã€ããŠããè¶³ãããã«äžãããããªåäœãïŒèžã¿å°ã«ã€ããŠããè¶³ãããã«äžãããããªåäœã¯å
¥åãããªããšä»®å®ããŠããïŒ $n$ ã0ã®è¡ã¯å
¥åã®çµããã衚ãïŒãã®ããŒã¿ã«ã€ããŠã¯åŠçãè¡ã£ãŠã¯ãªããªãïŒ Output åããŒã¿ã»ããã«å¯ŸããŠïŒ1è¡ã§æ£ããèžã¿å°æéãè¡ã£ãåæ°ãåºåããïŒ åè¡ã®çµããã«æ¹è¡ãåºåããªãå ŽåãïŒäžå¿
èŠãªæåãåºåããå ŽåïŒèª€çãšå€æãããŠããŸãããæ³šæããããšïŒ Sample Input 4 lu ru ld rd 4 lu ld lu ru 1 lu 10 ru lu ld rd ru rd ru lu rd ld 0 Output for Sample Input 2 1 0 4 | 35,959 |
Score : 300 points Problem Statement You are given a string s . Among the different substrings of s , print the K -th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s . For example, if s = ababc , a , bab and ababc are substrings of s , while ac , z and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j} . Constraints 1 †|s| †5000 s consists of lowercase English letters. 1 †K †5 s has at least K different substrings. Partial Score 200 points will be awarded as a partial score for passing the test set satisfying |s| †50 . Input Input is given from Standard Input in the following format: s K Output Print the K -th lexicographically smallest substring of K . Sample Input 1 aba 4 Sample Output 1 b s has five substrings: a , b , ab , ba and aba . Among them, we should print the fourth smallest one, b . Note that we do not count a twice. Sample Input 2 atcoderandatcodeer 5 Sample Output 2 andat Sample Input 3 z 1 Sample Output 3 z | 35,960 |
Problem D: äŒèª¬ã®å£ â» ãã®åé¡ã«ã¯åšäºæåãå€ãå«ãŸããŸããèžçŒãã«ã泚æãã ããã ã€ãã«åŸ©æŽ»ãéããéçã¯ãåã³äžçãéã«å
ãããã«äººéçã«æ»ãå
¥ãããšããŠããã éçã¯ãæ¬æ ŒçãªäŸµæ»ãå§ããåã«ããŸãäŒèª¬ã®å£ãç Žå£ããããšã«ããã ååã®æŠäºã«ãããŠãéçã¯äŒèª¬ã®å£ãæã€åè
ã«ãã£ãŠåãããã éçã®äœã¯éã®è¡£ã«ãã£ãŠå®ãããŠãããããçåå¯ãªæ»æã§ã¯éçãå·ã€ããããšã¯ã§ããªãã ããããäŒèª¬ã®å£ã¯ãç¥ã
ã®å è·ã«ãããéçã®éã®è¡£ãã容æã«è²«ããŠããŸãã ãã®ãããä»åã®æŠäºã«åå©ããããã«ã¯ããªããšããŠããã®äŒèª¬ã®å£ãæã«å
¥ããŠç Žå£ããå¿
èŠãããã 調æ»ã®æ«ãäŒèª¬ã®å£ã¯ãšããéºè·¡ã®æå¥¥ã«å®çœ®ãããæ¬¡ä»£ã®åè
ãçŸãããã®ãåŸ
ã£ãŠããããšãããã£ãã äŒèª¬ã®å£ã¯ãéªæªãªè
ãçè³ã«ãã£ãŠå¥ªãããã®ãé²ãããã«ãåšå²ã«ç¹åšããç¡æ°ã®å®ç ã«ãã£ãŠå°å°ãããŠããã éçã¯ã匷åãªéåãæã£ãŠãããããè§Šããã ãã§å®ç ãç Žå£ããããšãã§ããã ãã ããå®ç ã«ããå°å°ã¯å€éæ§é ã«ãªã£ãŠããã衚局ããé ã«ç Žå£ããŠããå¿
èŠãããã äŸãã°ã第1ã®å°å°ã®å®ç ãç Žå£ããåã«ç¬¬2以éã®å°å°ã®å®ç ã«è§ŠãããšããŠããç Žå£ããããšã¯ã§ããªãã ãŸããè€æ°ã®å®ç ãåãå°å°ãæ§æããŠããããšãããããéçã¯ãã®ãã¡ã®äžã€ã«è§Šããã ãã§ãåæã«ãã®å°å°ãç Žå£ããããšãã§ããã éºè·¡ã«ã¯ç¥èãªåãæºã¡ãŠããã䞊ã®éç©ã§ã¯å
¥ãããšãããŸãŸãªããªãã ããã§ãéçèªã赎ãäŒèª¬ã®å£ãååããŠããããšã«ãªã£ãã ããã«éçãšããã©ãé·æéãã®åãåãç¶ããã°ãã ã§ã¯ããŸãªãã éçã®å³è
ã§ããããªãã®ä»äºã¯ã念ã®ããéçãå
šãŠã®å°å°ãç Žå£ããäŒèª¬ã®å£ã®äžã«èŸ¿ãã€ããŸã§ã®æéãæ±ããããšã§ããã Input å
¥åã¯ãè€æ°ã®ããŒã¿ã»ãããããªããå
¥åã®çµããã¯ã¹ããŒã¹ã§åºåããããŒãäºã€ãããªãè¡ã§ããã ããŒã¿ã»ããã®ç·æ°ã¯50以äžã§ããã åããŒã¿ã»ããã¯ã次ã®åœ¢åŒãããŠããã w h s(1,1) ... s(1,w) s(2,1) ... s(2,w) ... s(h,1) ... s(h,w) w ãš h ã¯ãããããéºè·¡ã®ããã¢ã衚çŸããè¡åããŒã¿ã®å¹
ãšé«ããç€ºãæŽæ°ã§ããããããã 1 †w, h †100 ã§ããã 2 †w + h †100 ãšä»®å®ããŠè¯ãã ç¶ã h è¡ã¯ãããããã¹ããŒã¹ã§åºåããã w åã®æåããæ§æãããŠãããæå s(y,x) ã¯ãåº§æš (y,x) ã®å°ç¹ã®ç¶æ
ã瀺ãã ãã®æå³ã¯ã以äžã®éãã§ããã SïŒéçãæåã«ããå°ç¹ãããã¢ã«å¿
ã1ã€ã ãååšããã GïŒäŒèª¬ã®å£ã®å°ç¹ãå¿
ã1ã€ã ãååšããã .ïŒãªã«ããªãã æ°åïŒå®ç ãããå°ç¹ãæ°åã¯æ§æããå°å°ã®çªå·ã瀺ããæ°åã¯1以äžã®æŽæ°ã§ãããéã®æ°åã«æãã¯ãªããšããŠããã ãŸããéçã¯ãéºè·¡ã®ããã¢å
ã®äžäžå·Šå³ã®é£æ¥ãã座æšã«ç§»åããããšãã§ãããã®ç§»åã«ãããæéã1ãšããã ç Žå£ã§ããå®ç ã¯è§Šããã ãã§ç Žå£ã§ãããããå®ç ã®ç Žå£ã«ã¯æéã¯ããããªãã Output åããŒã¿ã»ããã«å¯ŸããŠãéçãå
šãŠã®å°å°ãç Žå£ããäŒèª¬ã«å£ã«èŸ¿ãã€ãããã«å¿
èŠãªæçæéãåºåããã Sample Input 10 10 S . . . . . . . . . . . . . . . . . . . . . . . 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 . . . . . . . . . . . . . . . . . 4 . . . . . . . . . . . . . . 2 . . . . . . . . G 10 10 S . . . . . 3 . . . . . 3 . . . . . . . . . . . 1 . . . . . . . . . . . 4 . . . . . 3 . . . 1 . . . . . . . . . . 3 . . . . . . . . . . . . . . . . . 4 . . . . . . . . . 5 . . . . 2 . . . . . . . . G 10 10 S . . . . . . . . 1 . . . . . 5 . . . . . 4 . . . . . . . . . . . . 8 . 9 . . . . . . . 10 . . . . . . . 7 . G . . . . . . . . 11 . . . . . . 3 . . . . . . . . 6 . . . . . . . 2 . . . . . . . . . . . . 0 0 Output for Sample Input 38 36 71 | 35,961 |
Squid Ink Problem è¿å¹Žãã€ã«ãã¡ã®éã§ã¯çžåŒµãäºããé »ç¹ã«èµ·ããŠãããè€æ°ã®ã€ã«ãã¡ãããŒã ãçµã¿ãèªãã®ã€ã«ã¹ããæŠåšã«æŠãã®ãè¿å¹Žã®ã€ã«ã®æŠéã¹ã¿ã€ã«ã§ããã çŸåšãçžåŒµãäºããèµ·ãã£ãŠããããã®æŠå Žã¯ R à C ã®ã°ãªããã§è¡šããããçžåŒµãäºãã«åå ããŠããã€ã«ã®ã²ãœå€ªã¯ãã®ã°ãªããäžã®ããå Žæã«ããããã®äºãã§ã¯ãéèŠãªå Žæãæµãããæ©ãå æ ããããšã§æŠæ³ãæå©ã«ããããšãã§ããããã®ãããã²ãœå€ªã¯éèŠãããªå Žæã1ã€æ±ºããããã«ãªãã¹ãæ©ãç§»åããããšèããŠããã ã²ãœå€ªã¯é£æ¥ããäžäžå·Šå³ã®ãã¹ã«ç§»åããããšãã§ãããã°ãªããã®åãã¹ã«ã¯å³æ¹ããŸãã¯æµã®ã€ã«ã¹ããå¡ãããŠããå Žåãããããªã«ãå¡ãããŠããªããã¹ã«ç§»åããå Žåã2ç§ããããã峿¹ã®ã€ã«ã¹ããå¡ãããŠãããã¹ã«ç§»åããå Žåããã®ååã®æé(1ç§)ã§æžããæµã®ã€ã«ã¹ããå¡ãããŠãããã¹ã«ã¯ç§»åããããšãã§ããªããå£ããããã¹ãæŠå Žã®å€ãžã¯åœç¶ç§»åããããšãã§ããªãã ãŸããã²ãœå€ªã¯äžäžå·Šå³ã®ããããã®æ¹åãåããã€ã«ã¹ããåãããšãã§ããããããšãåæ¹ã®3ãã¹ã峿¹ã®ã€ã«ã¹ãã§äžæžããããããã ãéäžã«å£ãããå Žåã¯ãã®æåãŸã§ããã€ã«ã¹ãã¯å±ããªãããã®åäœã«ã¯2ç§ãããã æŠå Žã®æ
å ±ãšã²ãœå€ªã®äœçœ®ãšç®çã®äœçœ®ãäžããããã®ã§ãæçã§äœç§ã§ç§»åã§ãããæ±ããŠã»ããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã R C a 1,1 a 1,2 ... a 1,C a 2,1 a 2,2 ... a 2,C : a R,1 a R,2 ... a R,C 1è¡ç®ã«2ã€ã®æŽæ° R , C ã空çœåºåãã§äžãããããç¶ã R è¡ã«æŠå Žã®æ
å ±ãšã㊠C åã®ãã¹ã®æ
å ±ãäžããããã a i,j ã¯æŠå Žã®äœçœ®( i , j )ã®ãã¹ã®æ
å ±ã衚ãã以äžã®ããããã®æåã§ããã '.': ãªã«ãå¡ãããŠããªããã¹ '#': å£ 'o': 峿¹ã®ã€ã«ã¹ããå¡ãããŠãããã¹ 'x': æµã®ã€ã«ã¹ããå¡ãããŠãããã¹ 'S': ã²ãœå€ªã®äœçœ®(å
¥åäžã«1ã€ã ãååšãããã¹ã¯ãªã«ãå¡ãããŠããªã) 'G': ç®çã®äœçœ®(å
¥åäžã«1ã€ã ãååšãããã¹ã¯ãªã«ãå¡ãããŠããªã) äžããããå
¥åã¯ãç®çã®äœçœ®ãŸã§ç§»åããããšãå¯èœã§ããããšãä¿èšŒãããã Constraints 2 †R , C †30 Output ã²ãœå€ªãç®çã®äœçœ®ãŸã§ç§»åããã®ã«ãããæçã®ç§æ°ã1è¡ã«åºåããã Sample Input 1 5 5 S.... ..... ..... ..... ....G Sample Output 1 14 Sample Input 2 5 5 Sxxxx xxxxx xxxxx xxxxx xxxxG Sample Output 2 15 Sample Input 3 4 5 S#... .#.#. .#.#. ...#G Sample Output 3 23 Sample Input 4 4 5 S#ooo o#o#o o#o#o ooo#G Sample Output 4 14 Sample Input 5 4 5 G#### ooxoo ##x#o Soooo Sample Output 5 10 | 35,962 |
Score : 1600 points Problem Statement There are A slimes lining up in a row. Initially, the sizes of the slimes are all 1 . Snuke can repeatedly perform the following operation. Choose a positive even number M . Then, select M consecutive slimes and form M / 2 pairs from those slimes as follows: pair the 1 -st and 2 -nd of them from the left, the 3 -rd and 4 -th of them, ... , the (M-1) -th and M -th of them. Combine each pair of slimes into one larger slime. Here, the size of a combined slime is the sum of the individual slimes before combination. The order of the M / 2 combined slimes remain the same as the M / 2 pairs of slimes before combination. Snuke wants to get to the situation where there are exactly N slimes, and the size of the i -th ( 1 †i †N ) slime from the left is a_i . Find the minimum number of operations required to achieve his goal. Note that A is not directly given as input. Assume A = a_1 + a_2 + ... + a_N . Constraints 1 †N †10^5 a_i is an integer. 1 †a_i †10^9 Input Input is given from Standard Input in the following format: N a_1 a_2 ... a_N Output Print the minimum number of operations required to achieve Snuke's goal. Sample Input 1 2 3 3 Sample Output 1 2 One way to achieve Snuke's goal is as follows. Here, the selected slimes are marked in bold. (1, 1 , 1 , 1 , 1 , 1) â (1, 2 , 2 , 1) ( 1 , 2 , 2 , 1 ) â ( 3 , 3 ) Sample Input 2 4 2 1 2 2 Sample Output 2 2 One way to achieve Snuke's goal is as follows. ( 1 , 1 , 1, 1, 1, 1, 1) â ( 2 , 1, 1, 1, 1, 1) (2, 1, 1 , 1 , 1 , 1 ) â (2, 1, 2 , 2 ) Sample Input 3 1 1 Sample Output 3 0 Sample Input 4 10 3 1 4 1 5 9 2 6 5 3 Sample Output 4 10 | 35,963 |
ã¶ã»ã¹ã¯ãšã¢ãŒãº ãã®åºŠãæåãªããŒãããŒã¯ã«ã巚倧迷路ã¶ã»ã¹ã¯ãšã¢ãŒãºãæ°ãã宿ããŸããã æ¶é²çœ²ã®æå°ã«ããé¿é£èšç·Žãããªããã°ãªããŸãããã巚倧迷路ãªã ãã«èšç·Žã«ãããæéãäºæž¬ããããšãã§ããŸãããããã§ãããªãã¯ä»¥äžã®ä»æ§ãããšã«é¿é£èšç·Žã·ãã¥ã¬ãŒã¿ãéçºããããšã«ãªããŸããã 巚倧迷路ã¯å³ 1 ã«ç€ºãããã«ã暪 W ã瞊 H ã® W à H åã®ãã¹ç®ã§è¡šããããŸããåãã¹ç®ã¯ãéè·¯(çœããã¹ç®)ãå£(è¶è²ããã¹ç®) ãéåžžå£(ç·ã®ãã¹ç®)ã®ããããã§ããå³äžã®âã¯äººã衚ãããã®äžã®è±å°æå(EãWãSãN)ã¯ãã®äººãåããŠããæ¹è§(æ±è¥¿åå)ã衚ããŠããŸããå³ã¯äžæ¹åãåã«ãªãããã«æãããŠããŸãã å³1 巚倧迷路å
ã«ããäººã¯æåãæ±è¥¿ååã®ããããã®æ¹åãåããŠç«ã£ãŠããŸããå人㯠1 ç§åäœã§åæã«æ¬¡ã«ç€ºãæé ã§ç§»åã詊ã¿ãŸãã çŸåšåããŠããæ¹åã®ãå³ãåãå·ŠãåŸã®ãã¹ç®ãé çªã«èª¿ã¹ãæåã«èŠã€ããã空ããŠããéè·¯ãŸãã¯éåžžå£ã®æ¹åã«åããå€ããŸãããã®ãããªãã¹ç®ãç¡ãå Žåã¯åããå€ããŸããã ç®ã®åã®ãã¹ç®ã空ããŠããŠãä»ã®äººã®ç®ã®åã®ãã¹ç®ã«ãªã£ãŠããªãå Žåã¯ç§»åããŸããåããã¹ç®ãç®ã®åã®ãã¹ãšãã人ãè€æ°ããå Žåã¯ããã®ãã¹ç®ã®ãæ±ãåã西ãåã®ãã¹ç®ã«ãã人ã®é ã§éžæããã 1 人ãç§»åããŸãã ç§»ååŸã«éåžžå£ã«å°çãã人ã¯ãç¡äºé¿é£ãè¿·è·¯å
ããæ¶ããŸãã äžãããã巚倧迷路ãšäººã®äœçœ®æ
å ±ãå
¥åãšããå
šãŠã®äººãé¿é£ãçµããæéãåºåããããã°ã©ã ãäœæããŠãã ããã è±åºã« 180 ç§ããé·ãæéãèŠããå Žå㯠NA ãšåºåããŠäžããã è¿·è·¯ãšäººã®äœçœ®æ
å ±ã¯ã H è¡ W åã®æåã«ãã£ãŠäžããããŸããåæåã®æå³ã¯ä»¥äžã®ãšããã§ãã # : å£ . : åº X : éåžžå£ E : æ±ãåããŠãã人 N : åãåããŠãã人 W : 西ãåããŠãã人 S : åãåããŠãã人 ãªããè¿·è·¯ãšå€éšãšã®å¢çã¯å£ # ãŸãã¯éåžžå£ X ã®ããããã§ãããŸãã巚倧迷路ã®äžã«ã¯ã人ãå¿
ãïŒäººä»¥äžããŸãã Input è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸãã å
¥åã®çµããã¯ãŒããµãã€ã®è¡ã§ç€ºãããŸãã åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã W H str 1 str 2 : str H 1 è¡ç®ã«è¿·è·¯ã®æšªæ¹åã®å€§ãã W ã瞊æ¹åã®å€§ãã H (1 †W, H †30) ãäžããããŸããç¶ã H è¡ã«è¿·è·¯ã® i è¡ç®ã衚ãæåå str i (é·ã W ) ãäžããããŸãã ããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã Output å
¥åããŒã¿ã»ããããšã«ãå
šãŠã®äººãé¿é£ãçµããæéãïŒè¡ã«åºåããŸãã Sample Input 10 3 ########## #E.......X ########## 4 4 #### #N.# #..X #### 5 5 ##### #N..# ###.X #S..# ##### 6 6 ###### #..#X# #.EE.# ####N# #....# ###### 8 8 ##X##### #....E.# #####.## #.#...## #.W.#..# #.#.N#.X #X##.#.# ######## 0 0 Output for the Sample Input 8 NA 9 16 10 | 35,964 |
Tiny Room You are an employee of Automatic Cleaning Machine (ACM) and a member of the development team of Intelligent Circular Perfect Cleaner (ICPC). ICPC is a robot that cleans up the dust of the place which it passed through. Your task is an inspection of ICPC. This inspection is performed by checking whether the center of ICPC reaches all the $N$ given points. However, since the laboratory is small, it may be impossible to place all the points in the laboratory so that the entire body of ICPC is contained in the laboratory during the inspection. The laboratory is a rectangle of $H \times W$ and ICPC is a circle of radius $R$. You decided to write a program to check whether you can place all the points in the laboratory by rotating and/or translating them while maintaining the distance between arbitrary two points. Input The input consists of a single test case of the following format. $N$ $H$ $W$ $R$ $x_1$ $y_1$ : $x_N$ $y_N$ The first line consists of four integers $N, H, W$ and $R$ ($1 \leq N \leq 100$, $1 \leq H, W \leq 10^9$, $1 \leq R \leq 10^6$). The following $N$ lines represent the coordinates of the points which the center of ICPC must reach. The ($i+1$)-th line consists of two integers $x_i$ and $y_i$ ($0 \leq x_i, y_i \leq 10^9$). $x_i$ and $y_i$ represent the $x$ and $y$ coordinates of the $i$-th point, respectively. It is guaranteed that the answer will not change even if $R$ changes by $1$. Output If all the points can be placed in the laboratory, print ' Yes '. Otherwise, print ' No '. Sample Input 1 4 20 20 1 10 0 20 10 10 20 0 10 Output for Sample Input 1 Yes All the points can be placed in the laboratory by rotating them through $45$ degrees. Sample Input 2 2 5 55 1 0 0 30 40 Output for Sample Input 2 Yes Sample Input 3 2 5 49 1 0 0 30 40 Output for Sample Input 3 No Sample Input 4 1 3 3 1 114 514 Output for Sample Input 4 Yes | 35,965 |
Problem D: Distorted Love Saying that it is not surprising that people want to know about their love, she has checked up his address, name, age, phone number, hometown, medical history, political party and even his sleeping position, every piece of his personal information. The word "privacy" is not in her dictionary. A person like her is called "stoker" or " yandere ", but it doesn't mean much to her. To know about him, she set up spyware to his PC. This spyware can record his mouse operations while he is browsing websites. After a while, she could successfully obtain the record from the spyware in absolute secrecy. Well, we want you to write a program which extracts web pages he visited from the records. All pages have the same size H à W where upper-left corner is (0, 0) and lower right corner is ( W , H ). A page includes several (or many) rectangular buttons (parallel to the page). Each button has a link to another page, and when a button is clicked the browser leads you to the corresponding page. His browser manages history and the current page in the following way: The browser has a buffer of 1-dimensional array with enough capacity to store pages, and a pointer to indicate a page in the buffer. A page indicated by the pointer is shown on the browser. At first, a predetermined page is stored and the pointer indicates that page. When the link button is clicked, all pages recorded in the right side from the pointer are removed from the buffer. Then, the page indicated by the link button is stored into the right-most position of the buffer, and the pointer moves to right. As a result, the user browse the page indicated by the button. The browser also has special buttons 'back to the previous page' (back button) and 'forward to the next page' (forward button). When the user clicks the back button, the pointer moves to left, and the user clicks the forward button, the pointer moves to right. But in both cases, if there are no such pages in the buffer, nothing happen. The record consists of the following operations: click x y It means to click ( x , y ). If there is a button on the point ( x , y ), he moved to the corresponding page. If there is nothing in the point, nothing happen. The button is clicked if x 1 †x †x 2 and y 1 †y †y 2 where x 1, x 2 means the leftmost and rightmost coordinate and y 1, y 2 means the topmost and bottommost coordinate of the corresponding button respectively. back It means to click the Back button. forward It means to click the Forward button. In addition, there is a special operation show . Your program should print the name of current page for each show operation. By the way, setting spyware into computers of others may conflict with the law. Do not attempt, or you will be reprimanded by great men. Input Input consists of several datasets. Each dataset starts with an integer n which represents the number of pages in the dataset. Next line contains two integers W and H . Next, information of each page are given. Each page starts with a string of characters and b [ i ], the number of buttons the page has. Following b [ i ] lines give information of buttons. Each button consists of four integers representing the coordinate ( x 1, y 1) of upper left corner and the coordinate ( x 2, y 2) of lower right corner of the button and a string of characters, which represents the name of page that the link of the button represents. Next, the number of operation m is given. Following m lines represent the record of operations. Please see the above description for the operation. The first page is stored in the buffer at first. Input ends when n = 0. Output For each dataset, output the name of current page for each show operation. Constraints 1 †n †100 b [ i ] †100 1 †the number of characters in the name †20 Buttons are not touch, overlapped nor run over from the browser. Sample Input 3 800 600 index 1 500 100 700 200 profile profile 2 100 100 400 200 index 100 400 400 500 link link 1 100 100 300 200 index 9 click 600 150 show click 200 450 show back back show forward show 0 Output for the Sample Input profile link index profile | 35,966 |
Hello World Welcome to Online Judge! Write a program which prints "Hello World" to standard output. Input There is no input for this problem. Output Print "Hello World" in a line. Sample Input 1 No input Sample Output 1 Hello World | 35,967 |
Score : 150 points Problem Statement Gorillas in Kyoto University are good at math. They are currently trying to solve problems to find the value of an expression that contains two functions, _ , ^ . Each of these functions takes two input values. _ function returns the smaller of the two input values and ^ function returns the larger. Gorillas know that integers in the expression are non-negative and less than or equal to 99 , but can not find out the length of the expression until they read a terminal symbol ? that represents the end of the expression. The number of characters included in each expression is less than or equal to 1000, but they do not even know this fact. Ai, a smart gorilla, noticed that she may be able to know the value of the expression even if they don't read the whole expression. For example, Assume you read the following sentence from the left. ^(41,3)? When you read the sixth character, that is, when you read the following expression, ^(41,3 you can tell the second input value of the funcion is whether 3 or an integer between 30 and 39 , and the value turns out 41 . Since Ai wants to solve problems earlier than other gorillas, she decided to solve the problems such that she reads as fewer characters as possible from the left. For each expression, Find the value of the expression and the minimum number of characters Ai needs to read to know the value. Constraints 1 \leq Q \leq 200 The number of characters each expression contains is less than or equal to 1000 . Input The input consists of multiple test cases and is given from Standard Input in the following format: Q statement_1 ... statement_Q Each statement_i (1 \leq i \leq Q) is given in the following BNF format. <statement> ::= <expression> ? <expression> ::= ( ^ | _ ) ( <expression> , <expression> ) | <number> <number> :: = 0 | 1 | 2 | ... | 98 | 99 Output Output consists of Q lines. On line i (1 \leq i \leq Q) , print the value of the expression and the number of character Ai needs to read for the test case i separated by space. Sample Input 1 4 _(4,51)? ^(99,_(3,67))? _(0,87)? 3? Sample Output 1 4 5 99 4 0 3 3 2 For the first test case, when you read the fifth character, that is, when you read _(4,5 , you will know the value is 4 . For the second test case, when you read the fourth character, that is, when you read ^(99 , you will know the value is 99 . For the third test case, when you read the third character, that is, when you read _(0 , you will know the value is 0 . For the fourth test case, you will not know the value is 3 untill you read the terminal symbol. Sample Input 2 7 _(23,^(_(22,40),4))? _(0,99)? ^(99,_(^(19,2),5))? _(^(43,20),^(30,29))? ^(_(20,3),_(50,41))? ^(_(20,3),_(3,41))? ^(_(20,3),_(4,41))? Sample Output 2 22 18 0 3 99 4 30 17 41 17 3 14 4 15 | 35,968 |
Score : 600 points Problem Statement There is a game that involves three variables, denoted A , B , and C . As the game progresses, there will be N events where you are asked to make a choice. Each of these choices is represented by a string s_i . If s_i is AB , you must add 1 to A or B then subtract 1 from the other; if s_i is AC , you must add 1 to A or C then subtract 1 from the other; if s_i is BC , you must add 1 to B or C then subtract 1 from the other. After each choice, none of A , B , and C should be negative. Determine whether it is possible to make N choices under this condition. If it is possible, also give one such way to make the choices. Constraints 1 \leq N \leq 10^5 0 \leq A,B,C \leq 10^9 N, A, B, C are integers. s_i is AB , AC , or BC . Input Input is given from Standard Input in the following format: N A B C s_1 s_2 : s_N Output If it is possible to make N choices under the condition, print Yes ; otherwise, print No . Also, in the former case, show one such way to make the choices in the subsequent N lines. The (i+1) -th line should contain the name of the variable ( A , B , or C ) to which you add 1 in the i -th choice. Sample Input 1 2 1 3 0 AB AC Sample Output 1 Yes A C You can successfully make two choices, as follows: In the first choice, add 1 to A and subtract 1 from B . A becomes 2 , and B becomes 2 . In the second choice, add 1 to C and subtract 1 from A . C becomes 1 , and A becomes 1 . Sample Input 2 3 1 0 0 AB BC AB Sample Output 2 No Sample Input 3 1 0 9 0 AC Sample Output 3 No Sample Input 4 8 6 9 1 AC BC AB BC AC BC AB AB Sample Output 4 Yes C B B C C B A A | 35,969 |
Reservation System The supercomputer system L in the PCK Research Institute performs a variety of calculations upon request from external institutes, companies, universities and other entities. To use the L system, you have to reserve operation time by specifying the start and end time. No two reservation periods are allowed to overlap each other. Write a program to report if a new reservation overlaps with any of the existing reservations. Note that the coincidence of start and end times is not considered to constitute an overlap. All the temporal data is given as the elapsed time from the moment at which the L system starts operation. Input The input is given in the following format. a b N s_1 f_1 s_2 f_2 : s_N f_N The first line provides new reservation information, i.e., the start time a and end time b (0 †a < b †1000) in integers. The second line specifies the number of existing reservations N (0 †N †100). Subsequent N lines provide temporal information for the i -th reservation: start time s_i and end time f_i (0 †s_i < f_i †1000) in integers. No two existing reservations overlap. Output Output "1" if the new reservation temporally overlaps with any of the existing ones, or "0" otherwise. Sample Input 1 5 7 3 1 4 4 5 7 10 Sample Output 1 0 Sample Input 2 3 7 3 7 10 1 4 4 5 Sample Output 2 1 | 35,970 |
Strongly Connected Components A direced graph is strongly connected if every two nodes are reachable from each other. In a strongly connected component of a directed graph, every two nodes of the component are mutually reachable. Input A directed graph G(V, E) and a sequence of queries where each query contains a pair of nodes u and v . |V| |E| s 0 t 0 s 1 t 1 : s |E|-1 t |E|-1 Q u 0 v 0 u 1 v 1 : u Q-1 v Q-1 |V| is the number of nodes and |E| is the number of edges in the graph. The graph nodes are named with the numbers 0, 1,..., |V| -1 respectively. s i and t i represent source and target nodes of i -th edge (directed). u i and v i represent a pair of nodes given as the i -th query. Output For each query, pinrt "1" if the given nodes belong to the same strongly connected component, "0" otherwise. Constraints 1 †|V| †10,000 0 †|E| †30,000 1 †Q †100,000 Sample Input 1 5 6 0 1 1 0 1 2 2 4 4 3 3 2 4 0 1 0 3 2 3 3 4 Sample Output 1 1 0 1 1 | 35,971 |
I - ãã€ã³ãªããŒã¹ èŠçŽ æ° N ã®é
å A ãäžããããããã ãã A 㯠(1, 2, ... , N) ã®é åã§ããã æ¬¡ã®æäœã 0 åä»¥äž 10,000 å以äžã®ä»»æã®åæ°è¡ãã A ã (1, 2, ... , N) ãžãœãŒããããã æŽæ° i ( 1 †i †N ) ã 1 ã€éžã³ãåºé A[1,\ i-1] ã®èŠçŽ ãéé ã«ããåºé A[i+1,\ N] ã®èŠçŽ ãéé ã«ããã ãã ããåºé A[l,\ r] ãšã¯ A ã® l, l+1, ... , r çªç®ã®äœçœ®ã®ããšã§ããã A ã (1, 2, ... , N) ãžãœãŒãã§ãããå€å®ããããœãŒãã§ãããªãã°ãæäœã®äŸãäžã€åºåããã Constraints 1 †N †3,000 A 㯠(1, 2, ... , N) ã®é åã§ããã Input Format å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããã N A_1 A_2 ... A_N Output Format A ã (1, 2, ... , N) ãžãœãŒãã§ããªããªãã°ã -1 ãšã ãäžè¡ã«åºåããã ãœãŒãã§ãããªãã°ãæäœã®äŸãäžã€æ¬¡ã®ããã«åºåããã 1 è¡ç®ã«ã¯ãæäœã®åæ°ãè¡šãæŽæ° M ( 0 †M †10,000 ) ãåºåããã 2 è¡ç®ããã® M è¡ã®ãã¡ k è¡ç®ã«ã¯ã k åç®ã®æäœã§éžã¶æŽæ° i ( 1 †i †N ) ãåºåããã Sample Input 1 5 5 1 4 2 3 Sample Output 1 2 3 1 äŸãã°ã次ã®ããã« 2 åã®æäœãè¡ãã°ããã i=3 ãéžã¶ãš (5,\ 1,\ 4,\ 2,\ 3) â (1,\ 5,\ 4,\ 3,\ 2) i=1 ãéžã¶ãš (1,\ 5,\ 4,\ 3,\ 2) â (1,\ 2,\ 3,\ 4,\ 5) Sample Input 2 2 2 1 Sample Output 2 -1 Sample Input 3 3 1 2 3 Sample Output 3 0 | 35,972 |
When Can We Meet? The ICPC committee would like to have its meeting as soon as possible to address every little issue of the next contest. However, members of the committee are so busy maniacally developing (possibly useless) programs that it is very difficult to arrange their schedules for the meeting. So, in order to settle the meeting date, the chairperson requested every member to send back a list of convenient dates by E-mail. Your mission is to help the chairperson, who is now dedicated to other issues of the contest, by writing a program that chooses the best date from the submitted lists. Your program should find the date convenient for the most members. If there is more than one such day, the earliest is the best. Input The input has multiple data sets, each starting with a line containing the number of committee members and the quorum of the meeting. N Q Here, N , meaning the size of the committee, and Q meaning the quorum, are positive integers. N is less than 50, and, of course, Q is less than or equal to N. N lines follow, each describing convenient dates for a committee member in the following format. M Date 1 Date 2 ... Date M Here, M means the number of convenient dates for the member, which is an integer greater than or equal to zero. The remaining items in the line are his/her dates of convenience, which are positive integers less than 100, that is, 1 means tomorrow, 2 means the day after tomorrow, and so on. They are in ascending order without any repetition and separated by a space character. Lines have neither leading nor trailing spaces. A line containing two zeros indicates the end of the input. Output For each data set, print a single line containing the date number convenient for the largest number of committee members. If there is more than one such date, print the earliest. However, if no dates are convenient for more than or equal to the quorum number of members, print 0 instead. Sample Input 3 2 2 1 4 0 3 3 4 8 3 2 4 1 5 8 9 3 2 5 9 5 2 4 5 7 9 3 3 2 1 4 3 2 5 9 2 2 4 3 3 2 1 2 3 1 2 9 2 2 4 0 0 Output for the Sample Input 4 5 0 2 | 35,973 |
Score : 1200 points Problem Statement Given is a positive integer N . Find the number of permutations (P_1,P_2,\cdots,P_{3N}) of (1,2,\cdots,3N) that can be generated through the procedure below. This number can be enormous, so print it modulo a prime number M . Make N sequences A_1,A_2,\cdots,A_N of length 3 each, using each of the integers 1 through 3N exactly once. Let P be an empty sequence, and do the following operation 3N times. Among the elements that are at the beginning of one of the sequences A_i that is non-empty, let the smallest be x . Remove x from the sequence, and add x at the end of P . Constraints 1 \leq N \leq 2000 10^8 \leq M \leq 10^9+7 M is a prime number. All values in input are integers. Input Input is given from Standard Input in the following format: N M Output Print the number of permutations modulo M . Sample Input 1 1 998244353 Sample Output 1 6 All permutations of length 3 count. Sample Input 2 2 998244353 Sample Output 2 261 Sample Input 3 314 1000000007 Sample Output 3 182908545 | 35,974 |
Score : 700 points Problem Statement Today, Snuke will eat B pieces of black chocolate and W pieces of white chocolate for an afternoon snack. He will repeat the following procedure until there is no piece left: Choose black or white with equal probability, and eat a piece of that color if it exists. For each integer i from 1 to B+W (inclusive), find the probability that the color of the i -th piece to be eaten is black. It can be shown that these probabilities are rational, and we ask you to print them modulo 10^9 + 7 , as described in Notes. Notes When you print a rational number, first write it as a fraction \frac{y}{x} , where x, y are integers and x is not divisible by 10^9 + 7 (under the constraints of the problem, such representation is always possible). Then, you need to print the only integer z between 0 and 10^9 + 6 , inclusive, that satisfies xz \equiv y \pmod{10^9 + 7} . Constraints All values in input are integers. 1 \leq B,W \leq 10^{5} Input Input is given from Standard Input in the following format: B W Output Print the answers in B+W lines. In the i -th line, print the probability that the color of the i -th piece to be eaten is black, modulo 10^{9}+7 . Sample Input 1 2 1 Sample Output 1 500000004 750000006 750000006 There are three possible orders in which Snuke eats the pieces: white, black, black black, white, black black, black, white with probabilities \frac{1}{2}, \frac{1}{4}, \frac{1}{4} , respectively. Thus, the probabilities of eating a black piece first, second and third are \frac{1}{2},\frac{3}{4} and \frac{3}{4} , respectively. Sample Input 2 3 2 Sample Output 2 500000004 500000004 625000005 187500002 187500002 They are \frac{1}{2},\frac{1}{2},\frac{5}{8},\frac{11}{16} and \frac{11}{16} , respectively. Sample Input 3 6 9 Sample Output 3 500000004 500000004 500000004 500000004 500000004 500000004 929687507 218750002 224609377 303710940 633300786 694091802 172485353 411682132 411682132 | 35,975 |
Score : 500 points Problem Statement Rng has a connected undirected graph with N vertices. Currently, there are M edges in the graph, and the i -th edge connects Vertices A_i and B_i . Rng will add new edges to the graph by repeating the following operation: Operation: Choose u and v (u \neq v) such that Vertex v can be reached by traversing exactly three edges from Vertex u , and add an edge connecting Vertices u and v . It is not allowed to add an edge if there is already an edge connecting Vertices u and v . Find the maximum possible number of edges that can be added. Constraints 2 \leq N \leq 10^5 1 \leq M \leq 10^5 1 \leq A_i,B_i \leq N The graph has no self-loops or multiple edges. The graph is connected. 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 Find the maximum possible number of edges that can be added. Sample Input 1 6 5 1 2 2 3 3 4 4 5 5 6 Sample Output 1 4 If we add edges as shown below, four edges can be added, and no more. Sample Input 2 5 5 1 2 2 3 3 1 5 4 5 1 Sample Output 2 5 Five edges can be added, for example, as follows: Add an edge connecting Vertex 5 and Vertex 3 . Add an edge connecting Vertex 5 and Vertex 2 . Add an edge connecting Vertex 4 and Vertex 1 . Add an edge connecting Vertex 4 and Vertex 2 . Add an edge connecting Vertex 4 and Vertex 3 . | 35,976 |
æé·å¢å ååé¡ æã¯éããŠå€ªéåã¯é«æ ¡çã«ãªããŸããã 倧åŠçã ã£ããå
ããã®åœ±é¿ãåããã³ã³ãã¥ãŒã¿ãŒãµã€ãšã³ã¹ã«èå³ãæã¡å§ããŸããã 倪éåã¯ã³ã³ãã¥ãŒã¿ãŒãµã€ãšã³ã¹ã®æç§æžãèªã¿é²ãããæé·å¢å éšåååé¡ããšããæååé¡ãããããšãç¥ããŸããã倪éåã¯ãã®åé¡ã®ããšãçè§£ããŸããããèªåã§ãé¡äŒŒåé¡ãäœããªããã®ããšæ°ã«ãªããŸããã ããã§å€ªéåã¯è©Šè¡é¯èª€ã®çµæã«æ¬¡ã®ãããªåé¡ãäœããŸããã n åã®æŽæ°ã§æ§æãããæ°åAããã m-1 åã®åºåããå
¥ããŠãæ°åAã m åã®æ°åã«åè§£ããããªããåè§£åŸã®ããããã®æ°åã¯1ã€ä»¥äžã®æ°ãå¿
ãå«ãŸãªããã°ãªããªãã ãã® m åããããã®æ°åå
ã®æŽæ°ããã¹ãŠè¶³ãåãããçµæåºæ¥äžãã m åã®æ°ããå
ã®æ°åã®é ã«é
眮ãããšå³å¯ãªå¢å åã«ãªã£ãŠãã(ã€ãŸããåºæ¥äžããæ°å㯠B i < B i+1 ãã¿ãã)ããã«ãããã ç®æšã¯æçµçã«ã§ããæ°å B ã®é·ã m ãæå€§åããããšã§ããã äŸãã°ãæ°å A ã{5,-4,10,-3,8}ã®å ŽåãèããŠã¿ãã åºåãã®äœçœ®ãè¡šãæ°å C ãçšæãã C={2,4} ãšããã ãã®ãšããæ°å A ã¯(5,-4),(10,-3),(8)ã®éšåã«åããããããã®å
éšãè¶³ãåããããšãããã1,7,8ãšãªããåºæ¥äžããæ°å B ã¯{1,7,8}ãšãªãã 倪éåã¯ãã®åé¡ã«ã€ããŠ"æé·å¢å ååé¡"ãšåä»ãããããè§£ãã¢ã«ãŽãªãºã ãèããŸããã ãããŠç€ŸäŒäººã«ãªã£ãããªãã«ãã§ãã¯ãããŠã»ãããšé£çµ¡ãããŸããã ããªãã®ä»äºã¯ãæé·ãã倪éåã®äœã£ãåé¡ãè§£ãããã°ã©ã ãäœãããšã§ãã ãã§ãã¯ããã®ãä»äºãªã®ã§ã m-1 åã®åºåãã®äœçœ®ãåºåããŸãã ãªããæé©ãª m ã«å¯ŸããŠãã®ãããªåºåãæ¹ãè€æ°èããããå ŽåããããŸããããã® m ãæ£ããåºåãããŠããã°ãèãããããã®ã®ãã¡äžã€ãåºåããã°ããã§ãã Input æ¹è¡åºåãã§ n+1 åã®æŽæ°ãäžããããã n A 1 A 2 ... A n n ã¯äžããããæ°å A ã®é·ãã衚ã A i ã¯æ°å A ã®içªç®ã®èŠçŽ ã衚ãã Constraints 1â€nâ€4000 |Ai|†10 8 æŽæ° k ã«å¯Ÿã㊠|k| 㯠k ã®çµ¶å¯Ÿå€ã衚ã Output m C 1 C 2 .. C m-1 1è¡ç®ã¯äžã€ã®æŽæ° m ãåºåããã m ã¯æçµçã«ã§ããæ°å B ã®é·ãã衚ãã 2è¡ç®ã¯ m-1 åã®æŽæ° C i ã空çœåºåãã§åºåããã C i ã¯ãæ°å A ã m åã®éšåã«é©åã«åºåã£ãæã® i çªç®ã®åºåãå Žæã衚ãã åºåãå Žæã®å®çŸ©ã¯å³ãåç
§ããããªãã 1â€C i <n ãæºããã 2è¡ç®ã® m-1 åã®æŽæ°åCã¯æé ã«äžŠãã§ããªããã°ãªããªããããã£ãŠã i < j ãªãã° C i < C j ãæç«ããã m=1 ã®å Žå2è¡ç®ã¯ç©ºè¡ã«ãªãã æ°å C ã«åŸã£ãŠæ°å A ããæ°å B ãçæãããšããæ°å B ãå¢å åã«ãªã£ãŠããªããšã(ããªãã¡ B i â¥B i+1 ãšãªã i(1â€i<m) ãååšãããšã)ãWrongAnswerãšãªã Sample Input 1 3 1 2 4 Output for the Sample Input 1 3 1 2 ããšããšå¢å åãªã®ã§ããã¹ãŠã®å Žæã«åºåããå
¥ããã°ãã Sample Input 2 3 2 2 2 Output for the Sample Input 2 2 1 2 2 2ã¯å¢å åã§ãªãã®ã§ã3ã€ã«åå²ããããšã¯ã§ããªã Sample Input 3 3 4 2 1 Output for the Sample Input 3 1 (空è¡) ã©ãåå²ããŠãå¢å åã«ã¯ãªããªããããåå²ãããªã | 35,977 |
Score : 100 points Problem Statement Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1 . Constraints 1\leq N,K\leq 100 N and K are integers. Input Input is given from Standard Input in the following format: N K Output If we can choose K integers as above, print YES ; otherwise, print NO . Sample Input 1 3 2 Sample Output 1 YES We can choose 1 and 3 . Sample Input 2 5 5 Sample Output 2 NO Sample Input 3 31 10 Sample Output 3 YES Sample Input 4 10 90 Sample Output 4 NO | 35,978 |
Equilateral Triangular Fence Ms. Misumi owns an orchard along a straight road. Recently, wild boars have been witnessed strolling around the orchard aiming at pears, and she plans to construct a fence around many of the pear trees. The orchard contains n pear trees, whose locations are given by the two-dimensional Euclidean coordinates ( x 1 , y 1 ),..., ( x n , y n ). For simplicity, we neglect the thickness of pear trees. Ms. Misumi's aesthetic tells that the fence has to form a equilateral triangle with one of its edges parallel to the road. Its opposite apex, of course, should be apart from the road. The coordinate system for the positions of the pear trees is chosen so that the road is expressed as y = 0, and the pear trees are located at y ⥠1. Due to budget constraints, Ms. Misumi decided to allow at most k trees to be left outside of the fence. You are to find the shortest possible perimeter of the fence on this condition. The following figure shows the first dataset of the Sample Input. There are four pear trees at (â1,2), (0,1), (1,2), and (2,1). By excluding (â1,2) from the fence, we obtain the equilateral triangle with perimeter 6. Input The input consists of multiple datasets, each in the following format. n k x 1 y 1 ... x n y n Each of the datasets consists of n +2 lines. n in the first line is the integer representing the number of pear trees; it satisfies 3 †n †10 000. k in the second line is the integer representing the number of pear trees that may be left outside of the fence; it satisfies 1 †k †min( n â2, 5 000). The following n lines have two integers each representing the x- and y- coordinates, in this order, of the locations of pear trees; it satisfies â10 000 †x i †10 000, 1 †y i †10 000. No two pear trees are at the same location, i.e., ( x i , y i )=( x j , y j ) only if i = j . The end of the input is indicated by a line containing a zero. The number of datasets is at most 100. Output For each dataset, output a single number that represents the shortest possible perimeter of the fence. The output must not contain an error greater than 10 â6 . Sample Input 4 1 0 1 1 2 -1 2 2 1 4 1 1 1 2 2 1 3 1 4 4 1 1 1 2 2 3 1 4 1 4 1 1 2 2 1 3 2 4 2 5 2 0 1 0 2 0 3 0 4 0 5 6 3 0 2 2 2 1 1 0 3 2 3 1 4 0 Output for the Sample Input 6.000000000000 6.928203230276 6.000000000000 7.732050807569 6.928203230276 6.000000000000 | 35,979 |
Grading Write a program which reads a list of student test scores and evaluates the performance for each student. The test scores for a student include scores of the midterm examination m (out of 50), the final examination f (out of 50) and the makeup examination r (out of 100). If the student does not take the examination, the score is indicated by -1. The final performance of a student is evaluated by the following procedure: If the student does not take the midterm or final examination, the student's grade shall be F. If the total score of the midterm and final examination is greater than or equal to 80, the student's grade shall be A. If the total score of the midterm and final examination is greater than or equal to 65 and less than 80, the student's grade shall be B. If the total score of the midterm and final examination is greater than or equal to 50 and less than 65, the student's grade shall be C. If the total score of the midterm and final examination is greater than or equal to 30 and less than 50, the student's grade shall be D. However, if the score of the makeup examination is greater than or equal to 50, the grade shall be C. If the total score of the midterm and final examination is less than 30, the student's grade shall be F. Input The input consists of multiple datasets. For each dataset, three integers m , f and r are given in a line. The input ends with three -1 for m , f and r respectively. Your program should not process for the terminal symbols. The number of datasets (the number of students) does not exceed 50. Output For each dataset, print the grade ( A , B , C , D or F ) in a line. Sample Input 40 42 -1 20 30 -1 0 2 -1 -1 -1 -1 Sample Output A C F | 35,980 |
A + B Problem Compute A + B. Input The input will consist of a series of pairs of integers A and B separated by a space, one pair of integers per line. The input will be terminated by EOF. Output For each pair of input integers A and B, you must output the sum of A and B in one line. Constraints -1000 †A, B †1000 Sample Input 1 2 10 5 100 20 Output for the Sample Input 3 15 120 Sample Program #include<stdio.h> int main(){ int a, b; while( scanf("%d %d", &a, &b) != EOF ){ printf("%d\n", a + b); } return 0; } | 35,981 |
E: LISum åé¡ é·ã $N$ ã®æ°å $A$ ãäžããããã æ°å $A$ ã®æé·å¢å éšååã®ã²ãšã€ã $B$ ãšãããšãã$\sum B_i$ ã®æå€§å€ãæ±ããã æ°å $A$ ã®æé·å¢å éšååãšã¯ããã¹ãŠã® $i < j$ ã§ $A_i < A_j$ ãæºããéšååã®ãã¡ãæé·ãªãã®ã瀺ãã å¶çŽ å
¥åå€ã¯å
šãп޿°ã§ããã $1 \leq N \leq 10^5$ $0 \leq A_i \leq 10^5$ å
¥ååœ¢åŒ å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã $N$ $A_1 \dots A_N$ åºå æ°å $A$ ã®æé·å¢å éšååã®ã²ãšã€ã $B$ ãšãããšãã$\sum B_i$ ã®æå€§å€ãåºåããããŸããæ«å°Ÿã«æ¹è¡ãåºåããã ãµã³ãã« ãµã³ãã«å
¥å 1 4 6 4 7 8 ãµã³ãã«åºå 1 21 æé·å¢å éšåå㯠$ (6, 7, 8)$ ãš $(4, 7, 8)$ ã§ããããã£ãп倧å€ã¯ $21$ ã§ããã ãµã³ãã«å
¥å 2 3 1000 2 3 ãµã³ãã«åºå 2 5 æé·å¢å éšåå㯠$(2,3)$ ã®ã¿ã§ããã ãµã³ãã«å
¥å 3 7 17 17 13 4 20 12 15 ãµã³ãã«åºå 3 31 ãµã³ãã«å
¥å 4 7 19 16 14 9 4 20 2 ãµã³ãã«åºå 4 39 | 35,982 |
Score : 300 points Problem Statement There are N Reversi pieces arranged in a row. (A Reversi piece is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N . If S_i= B , the i -th piece from the left is showing black; If S_i= W , the i -th piece from the left is showing white. Consider performing the following operation: Choose i ( 1 \leq i < N ) such that the i -th piece from the left is showing black and the (i+1) -th piece from the left is showing white, then flip both of those pieces. That is, the i -th piece from the left is now showing white and the (i+1) -th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed. Constraints 1 \leq |S| \leq 2\times 10^5 S_i= B or W Input Input is given from Standard Input in the following format: S Output Print the maximum possible number of times the operation can be performed. Sample Input 1 BBW Sample Output 1 2 The operation can be performed twice, as follows: Flip the second and third pieces from the left. Flip the first and second pieces from the left. Sample Input 2 BWBWBW Sample Output 2 6 | 35,983 |
åé¡ J Mod 3 Knights Out å顿 ããæ¥ã®å€æ¹ïŒã³ã³ãã¹ãã®åé¡ãè§£ãçµããäºäººã¯ä»æ¥ã®åé¡ã«ã€ããŠè©±ãåã£ãŠããïŒ AããããŒïŒãã®ã©ã€ãã¢ãŠãã®åé¡ïŒmod 2 ãããªã㊠mod 3 ãšã mod 7 ãšãã ã£ããè§£æ³åãã£ãã®ã«ãŒïŒã BããããïŒmod 3 ã§å¥ã®æ¹æ³ã§è§£ãåé¡ãäœãã°ãããã§ããïŒåãããŸããïŒã ããããŠæ¬¡ã®ãããªåé¡ãèªçããïŒ H à W ã®ãã§ã¹ç€ãããïŒãã§ã¹ç€ã®åãã¹ã«ã¯ 0 ãã 2 ã®æŽæ°ãæžãããŠããïŒãã®ãã§ã¹ç€ã«ãã€ãã眮ããŠããïŒãã ãïŒåãã¹ã«ã¯å€ããŠã 1 äœã®ãã€ããã眮ããªãïŒåãã¹ã«ã€ããŠïŒ (ãã¹ã®æ°å€+ãããæ»æãããã¹ã«ãããã€ãã®æ°)=0 mod 3 ãæãç«ã€ãããªãã€ãã®é
眮ã è¯ã é
眮ãšåŒã¶ïŒæ»æãããã¹ãšã¯ãã®ãã¹ãã瞊æ¹å㫠±2 ãã¹ãã€æšªæ¹å㫠±1 ãã¹ïŒãããã¯çžŠæ¹å㫠±1 ãã¹ãã€æšªæ¹å㫠±2 ãã¹ããããã¹ã®ããšã§ããïŒ è¯ããã€ãã®é
çœ®ã®æ°ãæ±ããïŒçãã¯å€§ãããªãå¯èœæ§ãããã®ã§ 1,000,000,007 ã§å²ã£ãäœããçããïŒ å
¥ååœ¢åŒ æåã®è¡ã« H ãš W ãã¹ããŒã¹åºåãã§äžããããïŒ æ¬¡ã® H è¡ã«ã¯ããã§ã¹ç€ã®ãã¹ç®ã«æžãããŠããæ°å€ãšã㊠W åã® 0 ïŒ 1 ïŒ 2 ã®ããããã®æŽæ°ãã¹ããŒã¹åºåãã§äžããããïŒ åºååœ¢åŒ è¯ããã€ãã®é
çœ®ã®æ°ã 1,000,000,007 ã§å²ã£ãäœããåºåããïŒ å¶çŽ 1 †H †50 1 †W †16 å
¥åºåäŸ å
¥åäŸ 1 5 5 0 2 0 2 0 2 0 0 0 2 0 0 0 0 0 2 0 0 0 2 0 2 0 2 0 åºåäŸ 1 5 å
¥åäŸ 2 3 3 2 2 2 2 0 2 2 2 2 åºåäŸ 2 8 å
¥åäŸ 3 7 7 2 2 2 2 2 2 2 2 1 1 2 1 1 2 2 0 1 0 1 0 2 2 2 0 2 0 2 2 2 0 1 0 1 0 2 2 1 1 2 1 1 2 2 2 2 2 2 2 2 åºåäŸ 3 96 å
¥åäŸ 4 7 3 2 2 2 1 0 1 0 1 0 1 1 1 0 1 0 1 0 1 2 2 2 åºåäŸ 4 8 å
¥åäŸ 5 6 6 0 2 0 1 0 2 2 0 1 2 2 2 0 2 2 0 0 0 2 0 2 0 2 0 0 2 2 1 0 2 0 0 0 2 0 2 åºåäŸ 5 1 å
¥åäŸ 6 16 16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 åºåäŸ 6 1 è¬èŸ ãã®åé¡ã¯ Tester ãš Writer ã ã¢ãžã¢å°åºäºéžã®åé¡ ã«é¢ããŠè©±ãåã£ãã®ããã£ãããšããŠäœãããã | 35,984 |
Score : 800 points Problem Statement There is a directed graph with N vertices and N edges. The vertices are numbered 1, 2, ..., N . The graph has the following N edges: (p_1, 1), (p_2, 2), ..., (p_N, N) , and the graph is weakly connected. Here, an edge from Vertex u to Vertex v is denoted by (u, v) , and a weakly connected graph is a graph which would be connected if each edge was bidirectional. We would like to assign a value to each of the vertices in this graph so that the following conditions are satisfied. Here, a_i is the value assigned to Vertex i . Each a_i is a non-negative integer. For each edge (i, j) , a_i \neq a_j holds. For each i and each integer x(0 †x < a_i) , there exists a vertex j such that the edge (i, j) exists and x = a_j holds. Determine whether there exists such an assignment. Constraints 2 †N †200 000 1 †p_i †N p_i \neq i The graph is weakly connected. Input Input is given from Standard Input in the following format: N p_1 p_2 ... p_N Output If the assignment is possible, print POSSIBLE ; otherwise, print IMPOSSIBLE . Sample Input 1 4 2 3 4 1 Sample Output 1 POSSIBLE The assignment is possible: { a_i } = { 0, 1, 0, 1 } or { a_i } = { 1, 0, 1, 0 }. Sample Input 2 3 2 3 1 Sample Output 2 IMPOSSIBLE Sample Input 3 4 2 3 1 1 Sample Output 3 POSSIBLE The assignment is possible: { a_i } = { 2, 0, 1, 0 }. Sample Input 4 6 4 5 6 5 6 4 Sample Output 4 IMPOSSIBLE | 35,985 |
Score : 1100 points Problem Statement We have a grid with N rows and M columns of squares. Each integer from 1 to NM is written in this grid once. The number written in the square at the i -th row from the top and the j -th column from the left is A_{ij} . You need to rearrange these numbers as follows: First, for each of the N rows, rearrange the numbers written in it as you like. Second, for each of the M columns, rearrange the numbers written in it as you like. Finally, for each of the N rows, rearrange the numbers written in it as you like. After rearranging the numbers, you want the number written in the square at the i -th row from the top and the j -th column from the left to be M\times (i-1)+j . Construct one such way to rearrange the numbers. The constraints guarantee that it is always possible to achieve the objective. Constraints 1 \leq N,M \leq 100 1 \leq A_{ij} \leq NM A_{ij} are distinct. Input Input is given from Standard Input in the following format: N M A_{11} A_{12} ... A_{1M} : A_{N1} A_{N2} ... A_{NM} Output Print one way to rearrange the numbers in the following format: B_{11} B_{12} ... B_{1M} : B_{N1} B_{N2} ... B_{NM} C_{11} C_{12} ... C_{1M} : C_{N1} C_{N2} ... C_{NM} Here B_{ij} is the number written in the square at the i -th row from the top and the j -th column from the left after Step 1 , and C_{ij} is the number written in that square after Step 2 . Sample Input 1 3 2 2 6 4 3 1 5 Sample Output 1 2 6 4 3 5 1 2 1 4 3 5 6 Sample Input 2 3 4 1 4 7 10 2 5 8 11 3 6 9 12 Sample Output 2 1 4 7 10 5 8 11 2 9 12 3 6 1 4 3 2 5 8 7 6 9 12 11 10 | 35,986 |
åé¡ C : [[iwi]] ããã ïŒåã®ãã³ãã«ããŒã 㯠(iwi) ã ïŒ åã¯ç¢ºãã«æã«ããã°ã©ãã³ã°ã³ã³ãã¹ãã«åå ããŠããïŒ ãããŠïŒå€ãã®ä»²éãšæ¥œããæéãéãããïŒ ç¢ºãïŒä»²éãã¡ã¯å
šå¡ïŒçŸå°å¥³ã ã£ããããªæ°ãããïŒ ããã°ã©ãã³ã°ã³ã³ãã¹ãã®äžçã¯ïŒåã®ããŒã¬ã ã ã£ããããªæ°ãããïŒ Gââgle ã¯ïŒåã®ããŒã¬ã ã奪ã£ãã®ã ïŒããã«éããªãïŒ æã®ä»²éã®æããããã€ããããã«ãïŒãã¯ãããã°ã©ãã³ã°ã³ã³ãã¹ãã«åºãªããã°ãªããªãïŒ Gââgle Code Jam ã«åå ç»é²ããããšã«ãããïŒ ä»åºŠã® ID ã«ã¯ïŒäžžæ¬åŒ§ä»¥å€ã®æ¬åŒ§ãæ€èšã«å
¥ããŠã¿ããïŒ åé¡ 'i', 'w', '(', ')', '{', '}', '[', ']' ãããªãæååãäžããããæïŒ ãã®éšååããšã£ãŠïŒç·å¯Ÿç§°ãªæååãäœãããïŒ æå€§ã§äœæåã®æååãäœãããšãã§ããããèšç®ããããã°ã©ã ãäœæããïŒ äžããããæååã¯ïŒ "iwi" ãšããæååãäžåºŠå«ã¿ïŒãã以å€ã®éšåã«ã¯ 'i' ãš 'w' ãå«ãŸãªãïŒ ãã圢åŒçã«ã¯ïŒäžããããæåå㯠s "iwi" t ïŒ s ãš "iwi" ãš t ãé£çµãããã®ïŒãšãã圢ã§è¡šãããšãã§ãïŒ s ãš t 㯠'(', ')', '{', '}', '[', ']' ãããªãæååã§ããïŒ s ã t ã 0 æåã§ããå¯èœæ§ãããïŒ äœãæååã¯ïŒäžããããæååã®éšååããšã£ãŠäœãïŒ éšååãšã¯ïŒå
ã®æååããããã€ãã®æåãåãåºãïŒããããïŒ å
ã®æååã«å«ãŸããé çªã§ç¹ãããã®ã§ããïŒ åãåºãæåãã¡ã¯å¿
ãããå
ã®æååã§é£ç¶ããŠããªããŠãè¯ãïŒ ãŸãïŒäœãæååãïŒäžããããæååãšåæ§ã«ïŒ"iwi" ãšããæååãäžåºŠå«ã¿ïŒ ãã以å€ã®éšåã«ã¯ 'i' ãš 'w' ã¯å«ãŸãªãããã«ãããïŒ ããã§çšããå·Šå³ã«ç·å¯Ÿç§°ã®å®çŸ©ã¯ïŒä»¥äžãšããïŒ ä»¥äžã®æååã¯å·Šå³ã«ç·å¯Ÿç§°ïŒ 空æåå "i" "w" æåå x ãå·Šå³ã«ç·å¯Ÿç§°ã®ãšãïŒä»¥äžã®æååãå·Šå³ã«ç·å¯Ÿç§°ïŒ "i" x "i" "w" x "w" "(" x ")" ")" x "(" "{" x "}" "}" x "{" "[" x "]" "]" x "[" 以äžã®ãã®ã®ã¿ãå·Šå³ã«ç·å¯Ÿç§°ïŒ å
¥å å
¥å㯠'i', 'w', '(', ')', '{', '}', '[', ']' ãããªãäžèšã®æ¡ä»¶ãæºããæååã§ããïŒ åºå äžèšã®æ¡ä»¶ãæºããäœãããšã®ã§ããæååã®é·ãã®æå€§å€ãåºåããïŒ å¶çŽ å
¥åã®æååã®é·ã㯠15 以äžã§ããïŒ å
¥åºåäŸ å
¥åºåäŸ 1 å
¥åäŸ 1: [[[iwi[[[ å
¥åäŸ 1 ã«å¯ŸããåºåäŸ: 3 "iwi" ãšããæååããäœãããšãã§ããªãïŒ å
¥åºåäŸ 2 å
¥åäŸ 2: [{)iwi(]} å
¥åäŸ 2 ã«å¯ŸããåºåäŸ: 7 "[)iwi(]" ã "{)iwi(}" ãªã© 7 æåã®æååãäœãããšãã§ããïŒ | 35,987 |
Score : 300 points Problem Statement Takahashi, Nakahashi and Hikuhashi have integers A , B and C , respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18} , print Unfair instead. Constraints 1 \leq A,B,C \leq 10^9 0 \leq K \leq 10^{18} All values in input are integers. Input Input is given from Standard Input in the following format: A B C K Output Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times. If the absolute value of the answer exceeds 10^{18} , print Unfair instead. Sample Input 1 1 2 3 1 Sample Output 1 1 After one operation, Takahashi, Nakahashi and Hikuhashi have 5 , 4 and 3 , respectively. We should print 5-4=1 . Sample Input 2 2 3 2 0 Sample Output 2 -1 Sample Input 3 1000000000 1000000000 1000000000 1000000000000000000 Sample Output 3 0 | 35,988 |
Problem Statement Dr. Suposupo developed a programming language called Shipura. Shipura supports only one binary operator ${\tt >>}$ and only one unary function ${\tt S<\ >}$. $x {\tt >>} y$ is evaluated to $\lfloor x / 2^y \rfloor$ (that is, the greatest integer not exceeding $x / 2^y$), and ${\tt S<} x {\tt >}$ is evaluated to $x^2 \bmod 1{,}000{,}000{,}007$ (that is, the remainder when $x^2$ is divided by $1{,}000{,}000{,}007$). The operator ${\tt >>}$ is left-associative. For example, the expression $x {\tt >>} y {\tt >>} z$ is interpreted as $(x {\tt >>} y) {\tt >>} z$, not as $x {\tt >>} (y {\tt >>} z)$. Note that these parentheses do not appear in actual Shipura expressions. The syntax of Shipura is given (in BNF; Backus-Naur Form) as follows: expr ::= term | expr sp ">>" sp term term ::= number | "S" sp "<" sp expr sp ">" sp ::= "" | sp " " number ::= digit | number digit digit ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" The start symbol of this syntax is $\tt expr$ that represents an expression in Shipura. In addition, $\tt number$ is an integer between $0$ and $1{,}000{,}000{,}000$ inclusive, written without extra leading zeros. Write a program to evaluate Shipura expressions. Input The input is a sequence of datasets. Each dataset is represented by a line which contains a valid expression in Shipura. A line containing a single ${\tt \#}$ indicates the end of the input. You can assume the number of datasets is at most $100$ and the total size of the input file does not exceed $2{,}000{,}000$ bytes. Output For each dataset, output a line containing the evaluated value of the expression. Sample Input S< S< 12 >> 2 > > 123 >> 1 >> 1 1000000000 >>129 S<S<S<S<S<2>>>>> S <S< S<2013 >>> 11 >>> 10 > # Output for the Sample Input 81 30 0 294967268 14592400 | 35,989 |
Problem A : ID A倧åŠã§ã¯IDã®å
¥åãã¹ãå€çºããŠããã ããã§ãA倧åŠã¯å
¥åãã¹é²æ¢ã®ããæ°ããIDãçºè¡ããããšã«ããã æ°ããIDã«ã¯å
¥åãã¹é²æ¢ã®ããã«IDãæ£ãããã©ãããã§ãã¯ããæ¹æ³ãããã ã»å
šãŠã®æ¡ã®æ°åã®ç·åãæ±ããã ã»ãã ããå³ç«¯ã®æ¡ãïŒçªç®ãšããŠãå¶æ°çªç®ã®æ¡ã®æ°åãïŒåã«ããã ã»ïŒåããããšã«ãã£ãŠæ°åãïŒïŒä»¥äžã«ãªã£ãæãïŒã®äœã®æ°åãšïŒïŒã®äœã®æ°åãå ç®ããæ°åããã®æ¡ã®æ°åãšããã ã»ç·åãïŒïŒã§å²ãåããã°æ£ããIDãããã§ãªããã°ééããšããã äŸãšããŠã53579ãšããIDããã§ãã¯ããã å
šãŠã®æ¡ã®æ°åã®ç·åãæ±ããã®ã§ã 5 + 3 + 5 + 7 + 9 ãã ããå¶æ°çªç®ã®æ¡ã®æ°åãïŒåã«ããã®ã§ã 5 + 6 + 5 + 14 + 9 ïŒåããããšã«ãã£ãŠæ°åãïŒïŒä»¥äžã«ãªã£ãæãïŒã®äœã®æ°åãšïŒïŒã®äœã®æ°åãå ç®ããæ°åããã®æ¡ã®æ°åãšããã®ã§ã 5 + 6 + 5 + (1 + 4) + 9 以äžãããç·åã¯30ãšãªãã30ã¯10ã§å²ãåããã®ã§ã53579ã¯æ£ããIDã§ããã Båã¯A倧åŠã®å€§åŠçã§ãããæ°ããIDãçºè¡ããŠããã£ãããIDã®äžéšã®æ¡ãå¿ããŠããŸã£ãã ããããå¿ããŠããŸã£ãéšåã«ã©ããªæ°åãå
¥ãããããã€ãåè£ãçµãããšã«æåããã ããªãã®ä»äºã¯ãBåã®IDã®æ£ããçµã¿åãããäœéãããããæ±ããããšã§ããã Input å
¥åã¯ä»¥äžã®ãã©ãŒãããã§äžããããã n ID m a 0 a 1 ... a m-1 n 㯠ID ã®æ¡ã®æ°ã§ããã ID ã®åæ¡ã«ã¯0~9ã®æ°åãŸãã¯å¿ããæ¡ã§ãããšããããšã瀺ã'*'ãšããæåãå
¥ãã m ã¯'*'ã«å
¥ãæ°åã®åè£ã®æ°ã§ããã a i ã¯'*'ã«å
¥ãæ°åã®åè£ã§ããã å
¥åã¯ä»¥äžã®å¶çŽãæºãã 1 †n †100,000 1 †m †10 0 †a i †9 1 †'*'ã®æ° †7 Output çãã®å€ãïŒè¡ã«åºåãã Sample Input 1 5 5*57* 2 3 9 Sample Output 1 1 Sample Input 2 15 2***9*2*6*1199* 9 0 1 2 3 4 6 7 8 9 Sample Output 2 478297 | 35,990 |
ããªãªã³ã¯äºæ¬¡å
å¹³é¢äžã«ãããé·ã 2L ã®ç·åã®åœ¢ç¶ãããŠããã ããªãªã³ã®ãŸããã«ã¯ãç·åã®åœ¢ç¶ãããããã€ãã®é害ç©ãååšããŠããã ããªãªã³ã¯é害ç©ã«æ¥ãããšäœåãåãããŠããŸãã å®ç§äž»çŸ©ã®ããªãªã³ã¯ç¡å·ã§ãŽãŒã«ããããšã«ããã ããªãªã³ã¯ä»¥äžã®è¡åãã§ããã å¹³è¡ç§»å ããªãªã³ã衚ãç·åã®äžç¹ãäžå¿ãšããŠãåæèšåšãã«ã¡ããã© 180 / r 床ã ãå転ãã ãã ããäºæ¬¡å
å¹³é¢ã¯äžæ¹åã« y 軞ããšãã ããªãªã³ã®ãŸããã«ã2 ç¹ S, G ãããã å§ãã¯ããªãªã³ã®äžå¿ã¯ç¹ S ã«ãã£ãŠã x 軞ã«å¹³è¡ãªç¶æ
ã«ãªã£ãŠããã ããªãªã³ã¯ãå¹³è¡ç§»åããã®ã¯åŸæã ããå転ããã®ã¯äžåŸæã§ããã ããªãã®ä»äºã¯ãããªãªã³ãäžå¿ãç¹ S ããç¹ G ãŸã§ç§»åããããŸã§ã«å¿
èŠãªãæå°ã®å転è¡åã®åæ°ãæ±ããããšã§ããã ç§»åãããããšãã§ããªãå Žåã¯ããã®ããšãæ€åºããã ãã ãã以äžã®ããšã«æ³šæããã ããªãªã³ã¯ç§»åããªããå転ããããšã¯ã§ããªãã ããªãªã³ãå転ããéäžã§é害ç©ã«ã¶ã€ããããå Žåã¯ãå転ããããšã¯ã§ããªãã é害ç©ãäºãã«äº€å·®ããŠããããšã¯ããåŸãã ç·åã¯ååå°ããæéã®å€ªããæã€ãã®ãšããŠæ±ããæåŸã®ãµã³ãã«ãèŠãã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã L r s x s y g x g y n x 11 y 11 x 12 y 12 ... x n1 y n1 x n2 y n2 L ã¯ããªãªã³ã®ååã®é·ãã衚ãã r ã¯å転è§åºŠãå®ãããã®ã§ããã (s x , s y ) ã¯ç¹ Sã (g x , g y ) ã¯ç¹ G ã®åº§æšã§ããã n ã¯é害ç©ã®æ°ã衚ãã (x i1 , y i1 ) ãš (x i2 , y i2 ) 㯠i çªç®ã®é害ç©ã衚ãç·åã®ç«¯ç¹ã§ããã Constraints å
¥åã¯ä»¥äžã®å¶çŽãæºããã 1 †n †30 2†r †11 1 †L †10 5 å
¥åã«å«ãŸãã座æšã®åæåã¯çµ¶å¯Ÿå€ã 10 5 ä»¥äž å
¥åã«å«ãŸããæ°å€ã¯ãã¹ãп޿° i = 1, . . . , n ã«ã€ã㊠(x i1 , y i1 ) â (x i2 , y i2 ) ããªãªã³ãã¹ã¿ãŒãå°ç¹ã«xè»žã«æ°Žå¹³ãªç¶æ
ã§é
眮ãããšããé害ç©ãšã®ïŒç·åãšç·åãšã®ïŒè·é¢ã¯ 10 â3 ãã倧ãã é害ç©ã衚ãç·åã®ç«¯ç¹ããäž¡æ¹åã« 10 â3 ã ãå»¶ã°ããŠãçž®ããŠãè§£ã¯å€ãããªã L ã 10 â3 ã ã墿žãããŠãè§£ã¯å€ãããªã é害ç©ã®ç·åã l i ãšæžãããšã«ãããšã 1 †i †j †n ã§ãã£ãŠã l i ãš l j ã®è·é¢ã 2L 以äžã§ãããããªçµ (i, j) ã¯é«ã
100å ãŽãŒã«å°ç¹ã¯é害ç©ã«ä¹ã£ãŠããããšã¯ãªã Output ã¹ã¿ãŒãå°ç¹ãããŽãŒã«å°ç¹ãŸã§ç§»åããããã«å¿
èŠãªæå°ã®å転è¡åã®åæ°ã1è¡ã«åºåããã ç§»åãããããšãã§ããªãå Žåã¯ã-1ã1è¡ã«åºåããã Sample Input 1 1 2 3 3 2 -1 4 1 0 1 5 0 1 4 1 0 4 6 4 5 0 5 5 Output for the Sample Input 1 1 ããªãªã³ã90床å転ãããããšã§ãééãæããããšãã§ããã Sample Input 2 1 2 3 3 2 -1 4 1 0 1 5 0 1 6 1 0 4 6 4 5 0 5 5 Output for the Sample Input 2 -1 ããªãªã³ã¯å®å
šã«å²ãŸããŠããã®ã§ããŽãŒã«ãŸã§ç§»åããããšãã§ããªãã Sample Input 3 1 4 3 3 7 0 5 1 0 1 5 0 1 6 1 0 4 6 4 8 0 2 5 6 0 4 2 Output for the Sample Input 3 3 æãã®çµè·¯ãéãããã«ã¯ã3ååæèšåšãã«å転ããªããã°ãªããªãã Sample Input 4 2 2 4 2 4 5 5 1 5 2 0 0 4 3 4 0 1 8 1 7 0 7 5 8 4 5 4 Output for the Sample Input 4 -1 ããªãªã³ã¯é害ç©ã«ãŽã£ããæ¥ããããšãã§ããªãã®ã§ãééã®ãšããã§å転ããŠãŽãŒã«ãŸã§ç§»åããããšã¯ã§ããªãã | 35,991 |
Score : 400 points Problem Statement There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle. Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying to minimize S_{max} - S_{min} , where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece. Find the minimum possible value of S_{max} - S_{min} . Constraints 2 †H, W †10^5 Input Input is given from Standard Input in the following format: H W Output Print the minimum possible value of S_{max} - S_{min} . Sample Input 1 3 5 Sample Output 1 0 In the division below, S_{max} - S_{min} = 5 - 5 = 0 . Sample Input 2 4 5 Sample Output 2 2 In the division below, S_{max} - S_{min} = 8 - 6 = 2 . Sample Input 3 5 5 Sample Output 3 4 In the division below, S_{max} - S_{min} = 10 - 6 = 4 . Sample Input 4 100000 2 Sample Output 4 1 Sample Input 5 100000 100000 Sample Output 5 50000 | 35,992 |
Score : 600 points Problem Statement There are N slimes standing on a number line. The i -th slime from the left is at position x_i . It is guaruanteed that 1 \leq x_1 < x_2 < \ldots < x_N \leq 10^{9} . Niwango will perform N-1 operations. The i -th operation consists of the following procedures: Choose an integer k between 1 and N-i (inclusive) with equal probability. Move the k -th slime from the left, to the position of the neighboring slime to the right. Fuse the two slimes at the same position into one slime. Find the total distance traveled by the slimes multiplied by (N-1)! (we can show that this value is an integer), modulo (10^{9}+7) . If a slime is born by a fuse and that slime moves, we count it as just one slime. Constraints 2 \leq N \leq 10^{5} 1 \leq x_1 < x_2 < \ldots < x_N \leq 10^{9} x_i is an integer. Subtasks 400 points will be awarded for passing the test cases satisfying N \leq 2000 . Input Input is given from Standard Input in the following format: N x_1 x_2 \ldots x_N Output Print the answer. Sample Input 1 3 1 2 3 Sample Output 1 5 With probability \frac{1}{2} , the leftmost slime is chosen in the first operation, in which case the total distance traveled is 2 . With probability \frac{1}{2} , the middle slime is chosen in the first operation, in which case the total distance traveled is 3 . The answer is the expected total distance traveled, 2.5 , multiplied by 2! , which is 5 . Sample Input 2 12 161735902 211047202 430302156 450968417 628894325 707723857 731963982 822804784 880895728 923078537 971407775 982631932 Sample Output 2 750927044 Find the expected value multiplied by (N-1)! , modulo (10^9+7) . | 35,993 |
Score : 300 points Problem Statement How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions? 0 \leq A_i \leq 9 There exists some i such that A_i=0 holds. There exists some i such that A_i=9 holds. The answer can be very large, so output it modulo 10^9 + 7 . Constraints 1 \leq N \leq 10^6 N is an integer. Input Input is given from Standard Input in the following format: N Output Print the answer modulo 10^9 + 7 . Sample Input 1 2 Sample Output 1 2 Two sequences \{0,9\} and \{9,0\} satisfy all conditions. Sample Input 2 1 Sample Output 2 0 Sample Input 3 869121 Sample Output 3 2511445 | 35,994 |
Lçªç®ã®Kçªç®ã®æ° (LthKthNumber) å顿 暪äžåã«äžŠã¹ããã N æã®ã«ãŒããããïŒå·Šãã i æç®( 1 ⊠i ⊠N )ã®ã«ãŒãã«ã¯ïŒæŽæ° a_i ãæžãããŠããïŒ JOI åã¯ïŒãããã®ã«ãŒããçšããŠæ¬¡ã®ãããªã²ãŒã ãè¡ãïŒé£ç¶ãã K æä»¥äžã®ã«ãŒãã®åãéžã³ïŒæ¬¡ã®æäœãè¡ãïŒ éžãã ã«ãŒããïŒæžãããŠããæŽæ°ãå°ããé ã«å·Šãã䞊ã¹ãïŒ äžŠã¹ãã«ãŒãã®ãã¡ïŒå·Šãã K çªç®ã®ã«ãŒãã«æžãããæŽæ°ãçŽã«æžãåºãïŒ éžãã ã«ãŒããïŒãã¹ãŠå
ã®äœçœ®ã«æ»ãïŒ ãã®æäœãïŒé£ç¶ãã K æä»¥äžã®ã«ãŒãã®åãã¹ãŠã«å¯ŸããŠè¡ãïŒããªãã¡ïŒ 1 ⊠l ⊠r ⊠N ã〠K ⊠r - l + 1 ãæºãããã¹ãŠã® (l,r) ã«ã€ããŠïŒ a_l, a_{l+1}, ..., a_r ã®ãã¡ K çªç®ã«å°ããªæŽæ°ãæžãåºãïŒ ããããŠæžãåºãããæŽæ°ãïŒå·Šããå°ããé ã«äžŠã¹ãïŒäžŠã¹ãæŽæ°ã®ãã¡ïŒå·Šãã L çªç®ã®ãã®ããã®ã²ãŒã ã«ããã JOI åã®åŸç¹ã§ããïŒJOI åã®åŸç¹ãæ±ããïŒ å¶çŽ 1 \leq N \leq 200000 1 \leq K \leq N 1 \leq a_i \leq N 1 \leq L JOI åãæžãåºãæŽæ°ã¯ L å以äžã§ããïŒ å
¥åã»åºå å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããïŒ N K L a_1 a_2 ... a_N åºå JOI åã®åŸç¹ã 1 è¡ã§åºåããïŒ å
¥åºåäŸ å
¥åäŸ 1 4 3 2 4 3 1 2 åºåäŸ 1 3 1 \leq l \leq r \leq N (= 4) ã〠K (= 3) \leq r - l + 1 ãæºãã (l,r) ã¯ïŒ (1,3), (1,4), (2,4) ã® 3 éãããïŒ ãããã® (l,r) ã«å¯ŸãïŒ a_l, a_{l+1}, ..., a_r ã§ 3 çªç®ã«å°ããªæŽæ°ã¯ïŒãããã 4, 3, 3 ã§ããïŒ ãã®ãã¡ L (= 2) çªç®ã«å°ããæŽæ°ã¯ 3 ãªã®ã§ïŒJOI åã®åŸç¹ã¯ 3 ã§ããïŒåãæŽæ°ãè€æ°ãããšããïŒéè€ããŠæ°ããããšã«æ³šæããïŒ å
¥åäŸ 2 5 3 3 1 5 2 2 4 åºåäŸ 2 4 JOI åãæžãåºãæŽæ°ã¯ïŒ (l,r) = (1,3) ã«å¯Ÿã 5 (l,r) = (1,4) ã«å¯Ÿã 2 (l,r) = (1,5) ã«å¯Ÿã 2 (l,r) = (2,4) ã«å¯Ÿã 5 (l,r) = (2,5) ã«å¯Ÿã 4 (l,r) = (3,5) ã«å¯Ÿã 4 ã§ããïŒãã®ãã¡ L (= 3) çªç®ã«å°ããæŽæ°ã¯ 4 ã§ããïŒ å
¥åäŸ 3 6 2 9 1 5 3 4 2 4 åºåäŸ 3 4 å
¥åäŸ 4 6 2 8 1 5 3 4 2 4 åºåäŸ 4 3 | 35,995 |
ããã幎 è¥¿æŠ a 幎ãã b 幎ãŸã§ã®éã«ãããã¹ãŠã®ããã幎ãåºåããããã°ã©ã ãäœæããŠãã ããã ãããå¹Žã®æ¡ä»¶ã¯ã次ã®ãšãããšããŸãããã ãã0 < a †b < 3,000 ãšããŸããäžããããæéã«ããã幎ããªãå Žåã«ã¯ "NA"ãšåºåããŠãã ããã 西æŠå¹Žã 4 ã§å²ãåãã幎ã§ããããšã ãã ãã100 ã§å²ãåãã幎ã¯ããã幎ãšããªãã ãããã400 ã§å²ãåãã幎ã¯ããã幎ã§ããã Input è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã®åœ¢åŒã¯ä»¥äžã®ãšããã§ãïŒ a b a , b ããšãã« 0 ã®ãšãå
¥åã®çµäºãšããŸããããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã Output ããŒã¿ã»ããããšã«ã西æŠãŸã㯠NA ãåºåããŠãã ããã ããŒã¿ã»ããã®éã«ïŒã€ã®ç©ºè¡ãå
¥ããŠãã ããã Sample Input 2001 2010 2005 2005 2001 2010 0 0 Output for the Sample Input 2004 2008 NA 2004 2008 | 35,996 |
Problem G: Chairs Problem 1ãã N ã®çªå·ãå²ãåœãŠããã N èã®æ€
åã«ã1ãã N ã®IDãå²ãåœãŠããã N 人ã®äººã座ãããšããŠãããIDã i ã®äººã¯æ€
å p i ã«åº§ããããšæã£ãŠããã N 人ã®äººã¯IDãå°ããé ã«1åã«äžŠã³ãåã®å
é ã®äººã以äžã®è¡åããšãã æ€
å p i ã«èª°ã座ã£ãŠããªããã°ããã®æ€
åã«åº§ãã ããã§ãªããã°ã p i ã«1ãå ç®ããåã®æåŸå°Ÿã«äžŠã³çŽãããã ãã p i ã N ãè¶
ããå Žå㯠p i ã1ã«ããã å
šãŠã®äººãæ€
åã«åº§ããŸã§ãã®è¡åãç¹°ãè¿ããããšããæçµçã«åæ€
åã«åº§ã£ãŠãã人ã®IDãåºåããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã N p 1 p 2 ... p N 1è¡ç®ã«æŽæ° N ãäžããããã 2è¡ç®ã« N åã®æŽæ° p 1 , p 2 , ..., p N ã空çœåºåãã§äžããããã Constraints å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã 1 †N †10 5 1 †p i †N Output N è¡ã«æçµçãªç¶æ
ãåºåããã i è¡ç®ã«æ€
å i ã«åº§ã£ãŠãã人ã®IDãåºåããã Sample Input 1 5 1 2 3 4 5 Sample Output 1 1 2 3 4 5 Sample Input 2 5 3 3 4 4 5 Sample Output 2 4 2 1 3 5 | 35,997 |
ãã ããäžçã«ã¯ïŒæåã ãã§ã§ããäžæè°ãªãããäœãã§ããŸãããã®ããã«ã¯çŸåšAçš®ãšBçš®ã®2çš®é¡ã確èªãããŠããŸããããã以å€ã®çš®é¡ãããå¯èœæ§ããããŸãã Açš®ã¯ïŒ">'"ã®åŸã«"="ã1å以äžäžŠãã åŸã"#"ãæ¥ãŠãããã«åãšåãåæ°ã®"="ãæ¥ãåŸã"~"ïŒåè§ãã«ãïŒã§çµãããŸãã Bçš®ã¯ïŒ">^"ã®åŸã« "Q="ã1å以äžäžŠãã åŸã"~~"ã§çµãããŸãã Açš®ã®äŸïŒ >'====#====~ >'==#==~ Bçš®ã®äŸïŒ >^Q=Q=Q=Q=~~ >^Q=Q=~~ ãããæååããŒã¿ãšããŠåãåãããããã©ããªçš®é¡ã§ããããå€å¥ããŠãAçš®ã®å Žåã¯ãAããBçš®ã®å Žåã¯ãBãããã以å€ã®çš®é¡ã®å Žåã¯ãNAããåºåããããã°ã©ã ãäœæããŠãã ããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã n S 1 S 2 : S n 1 è¡ç®ã«å€å¥ãããããã®æ° n ïŒ1 †n †10000ïŒãç¶ã n è¡ã« i å¹ç®ã®ããã衚ãæåå S i (200æå以äžã®ã空çœãå«ãŸãªãæåå) ãããããïŒè¡ã«äžããããŸãã Output i è¡ç®ã« i å¹ç®ã®ããã®çš®é¡ AãB ãŸã㯠NA ãåºåããŠãã ããã Sample Input 3 >'======#======~ >^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~ >'===#====~ Output for the Sample Input A B NA | 35,998 |
Score : 400 points Problem Statement You are given a permutation p of the set { 1, 2, ..., N }. Please construct two sequences of positive integers a_1 , a_2 , ..., a_N and b_1 , b_2 , ..., b_N satisfying the following conditions: 1 \leq a_i, b_i \leq 10^9 for all i a_1 < a_2 < ... < a_N b_1 > b_2 > ... > b_N a_{p_1}+b_{p_1} < a_{p_2}+b_{p_2} < ... < a_{p_N}+b_{p_N} Constraints 2 \leq N \leq 20,000 p is a permutation of the set { 1, 2, ..., N } Input The input is given from Standard Input in the following format: N p_1 p_2 ... p_N Output The output consists of two lines. The first line contains a_1 , a_2 , ..., a_N seperated by a space. The second line contains b_1 , b_2 , ..., b_N seperated by a space. It can be shown that there always exists a solution for any input satisfying the constraints. Sample Input 1 2 1 2 Sample Output 1 1 4 5 4 a_1 + b_1 = 6 and a_2 + b_2 = 8 . So this output satisfies all conditions. Sample Input 2 3 3 2 1 Sample Output 2 1 2 3 5 3 1 Sample Input 3 3 2 3 1 Sample Output 3 5 10 100 100 10 1 | 35,999 |
A: ããŒãã¡ã³ã åé¡ AOR ã€ã«ã¡ãããšããªãã¯ãããŒãã¡ã³ã圢åŒã®åç倧äŒã·ã³ã°ã«ã¹ã®éšã«åµå¯ã«æ¥ãã å
šãŠã®è©Šåãé²ç»ããã AOR ã€ã«ã¡ããã®ããã«ãããªãã¯ãã®å€§äŒã§è¡ãããè©Šåæ°ãæ±ããŠãããããšã«ããã ãã®å€§äŒã«ã¯ $N$ 人ã®éžæãåå ããŠããããããã $0, \dots , N - 1$ ã®èçªå·ãæã£ãŠããã ãã®ãã¡ã $M$ 人ã®éžæãæ£æš©ãã詊åã«ã¯åºå Žããªãã£ãã ãã®å€§äŒã®è©Šåæ°ã¯ã以äžã®ã«ãŒã«ã«åºããŠæ±ºå®ãããã ã·ãŒãéžæã¯ååšãããä»»æã®åºå Žè
ãåªåããããã«å¿
èŠãªåå©åæ°ã¯äžå®ã§ããã 察æŠçžæãäžåšã®å Žåã¯è©Šåãè¡ãããåºå Žããéžæãåå©ãããè©Šåæ°ã«ã¯ã«ãŠã³ããããªãã åªåè
ãæ±ºãŸã£ã段éã§å€§äŒã¯çµäºããã äžåºŠè©Šåã«è² ãã人ãåã³è©Šåãããããšã¯ãªããã€ãŸãæè
埩掻æŠã 3 äœæ±ºå®æŠãªã©ã¯è¡ããªãã ãªããåçå°ã 1 å°ããç¡ãããç°ãªã詊åãåæã«è¡ãããããšã¯ãªãããŸãå詊åã§ã¯å¿
ãåè
ãæ±ºãŸã (åŒãåããšãªãããšã¯ãªã)ã ãªããããŒãã¡ã³ãã®å®çŸ©ã¯æ¬¡ã®ãšããã§ããã ããŒãã¡ã³ãã¯é«ã $L = \log_2 N$ ã®å®å
šäºåæšã§è¡šãããèã«ãããåé ç¹ã«ã¯åå è
ã®èçªå·ãæžã蟌ãŸããŠããã æ ¹ã®æ·±ãã 0 ãšãããšã $i$ åæŠ ($1 \le i \le L$) ã§ã¯ã æ·±ã $L - i$ ã®åé ç¹ã®åã«æžãããçªå·ã®éžæå士ã詊åãè¡ãããã®åè
ã®èçªå·ããã®é ç¹ã«æžã蟌ãã å¶çŽ $2 \le N \le 2^8$ $0 \le M \le N - 1$ $0 \le a_i \le N - 1 \ (0 \le i \le M - 1)$ $N$ 㯠2 ã®çޝä¹ã§ããã $a_i \ (0 \le i \le M - 1)$ ã¯çžç°ãªã å
¥ååœ¢åŒ å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã $N \ M$ $a_1$ $\vdots$ $a_M$ 1 è¡ç®ã«ã¯ãåå è
ãè¡šãæŽæ° $N$ ãåå è
ã®ãã¡æ£æš©ããè
ã®äººæ°ãè¡šãæŽæ° $M$ ãäžããããã ç¶ã $M$ è¡ã«ã¯ãæ£æš©ããŠåºå Žããªãã£ãéžæã®çªå·ãè¡šãæŽæ° $a_i$ ãäžããããã åºå ãã®å€§äŒãçµäºãããŸã§ã«è¡ãããè©Šåæ°ã 1 è¡ã§åºåããããŸããæ«å°Ÿã«æ¹è¡ãåºåããã ãµã³ãã« ãµã³ãã«å
¥å 1 2 0 ãµã³ãã«åºå 1 1 æåã®è©Šåã§åªåè
ãæ±ºãŸãã ãµã³ãã«å
¥å 2 4 2 2 3 ãµã³ãã«åºå 2 1 | 36,000 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.