task
stringlengths 0
154k
| __index_level_0__
int64 0
39.2k
|
|---|---|
J: Horizontal-Vertical Permutation Problem Statement You are given a positive integer N . Your task is to determine if there exists a square matrix A whose dimension is N that satisfies the following conditions and provide an example of such matrices if it exists. A_{i, j} denotes the element of matrix A at the i -th row and j -th column. For all i, j (1 \leq i, j \leq N) , A_{i, j} is an integer that satisfies 1 \leq A_{i, j} \leq 2N - 1 . For all k = 1, 2, ..., N , a set consists of 2N - 1 elements from the k -th row or k -th column is \{1, 2, ..., 2N - 1\} . If there are more than one possible matrices, output any of them. Input N Input consists of one line, which contains the integer N that is the size of a square matrix to construct. Constraint N is an integer that satisfies 1 \leq N \leq 500 . Output Output No in a single line if such a square matrix does not exist. If such a square matrix A exists, output Yes on the first line and A after that. More specifically, follow the following format. Yes A_{1, 1} A_{1, 2} ... A_{1, N} A_{2, 1} A_{2, 2} ... A_{2, N} : A_{N, 1} A_{N, 2} ... A_{N, N} Sample Input 1 4 Output for Sample Input 1 Yes 2 6 3 7 4 5 2 1 1 7 5 6 5 3 4 2 Sample Input 2 3 Output for Sample Input 2 No
| 38,601
|
Sale Result There is data on sales of your company. Your task is to write a program which identifies good workers. The program should read a list of data where each item includes the employee ID i , the amount of sales q and the corresponding unit price p . Then, the program should print IDs of employees whose total sales proceeds (i.e. sum of p à q) is greater than or equal to 1,000,000 in the order of inputting. If there is no such employees, the program should print "NA". You can suppose that n < 4000, and each employee has an unique ID. The unit price p is less than or equal to 1,000,000 and the amount of sales q is less than or equal to 100,000. Input The input consists of several datasets. The input ends with a line including a single 0. Each dataset consists of: n (the number of data in the list) i p q i p q : : i p q Output For each dataset, print a list of employee IDs or a text "NA" Sample Input 4 1001 2000 520 1002 1800 450 1003 1600 625 1001 200 1220 2 1001 100 3 1005 1000 100 2 2013 5000 100 2013 5000 100 0 Output for the Sample Input 1001 1003 NA 2013
| 38,602
|
Problem C: Save your cats Nicholas Y. Alford was a cat lover. He had a garden in a village and kept many cats in his garden. The cats were so cute that people in the village also loved them. One day, an evil witch visited the village. She envied the cats for being loved by everyone. She drove magical piles in his garden and enclosed the cats with magical fences running between the piles. She said âYour cats are shut away in the fences until they become ugly old cats.â like a curse and went away. Nicholas tried to break the fences with a hummer, but the fences are impregnable against his effort. He went to a church and asked a priest help. The priest looked for how to destroy the magical fences in books and found they could be destroyed by holy water. The Required amount of the holy water to destroy a fence was proportional to the length of the fence. The holy water was, however, fairly expensive. So he decided to buy exactly the minimum amount of the holy water required to save all his cats. How much holy water would be required? Input The input has the following format: N M x 1 y 1 . . . x N y N p 1 q 1 . . . p M q M The first line of the input contains two integers N (2 †N †10000) and M (1 †M ). N indicates the number of magical piles and M indicates the number of magical fences. The following N lines describe the coordinates of the piles. Each line contains two integers x i and y i (-10000 †x i , y i †10000). The following M lines describe the both ends of the fences. Each line contains two integers p j and q j (1 †p j , q j †N ). It indicates a fence runs between the p j -th pile and the q j -th pile. You can assume the following: No Piles have the same coordinates. A pile doesnât lie on the middle of fence. No Fences cross each other. There is at least one cat in each enclosed area. It is impossible to destroy a fence partially. A unit of holy water is required to destroy a unit length of magical fence. Output Output a line containing the minimum amount of the holy water required to save all his cats. Your program may output an arbitrary number of digits after the decimal point. However, the absolute error should be 0.001 or less. Sample Input 1 3 3 0 0 3 0 0 4 1 2 2 3 3 1 Output for the Sample Input 1 3.000 Sample Input 2 4 3 0 0 -100 0 100 0 0 100 1 2 1 3 1 4 Output for the Sample Input 2 0.000 Sample Input 3 6 7 2 0 6 0 8 2 6 3 0 5 1 7 1 2 2 3 3 4 4 1 5 1 5 4 5 6 Output for the Sample Input 3 7.236 Sample Input 4 6 6 0 0 0 1 1 0 30 0 0 40 30 40 1 2 2 3 3 1 4 5 5 6 6 4 Output for the Sample Input 4 31.000
| 38,603
|
Score : 1000 points Problem Statement There are M chairs arranged in a line. The coordinate of the i -th chair (1 †i †M) is i . N people of the Takahashi clan played too much games, and they are all suffering from backaches. They need to sit in chairs and rest, but they are particular about which chairs they sit in. Specifically, the i -th person wishes to sit in a chair whose coordinate is not greater than L_i , or not less than R_i . Naturally, only one person can sit in the same chair. It may not be possible for all of them to sit in their favorite chairs, if nothing is done. Aoki, who cares for the health of the people of the Takahashi clan, decides to provide additional chairs so that all of them can sit in chairs at their favorite positions. Additional chairs can be placed at arbitrary real coordinates. Find the minimum required number of additional chairs. Constraints 1 †N,M †2 à 10^5 0 †L_i < R_i †M + 1(1 †i †N) All input values are integers. Input Input is given from Standard Input in the following format: N M L_1 R_1 : L_N R_N Output Print the minimum required number of additional chairs. Sample Input 1 4 4 0 3 2 3 1 3 3 4 Sample Output 1 0 The four people can sit in chairs at the coordinates 3 , 2 , 1 and 4 , respectively, and no more chair is needed. Sample Input 2 7 6 0 7 1 5 3 6 2 7 1 6 2 6 3 7 Sample Output 2 2 If we place additional chairs at the coordinates 0 and 2.5 , the seven people can sit at coordinates 0 , 5 , 3 , 2 , 6 , 1 and 2.5 , respectively. Sample Input 3 3 1 1 2 1 2 1 2 Sample Output 3 2 Sample Input 4 6 6 1 6 1 6 1 5 1 5 2 6 2 6 Sample Output 4 2
| 38,604
|
Score : 200 points Problem Statement You have N apples, called Apple 1 , Apple 2 , Apple 3 , ..., Apple N . The flavor of Apple i is L+i-1 , which can be negative. You can make an apple pie using one or more of the apples. The flavor of the apple pie will be the sum of the flavors of the apples used. You planned to make an apple pie using all of the apples, but being hungry tempts you to eat one of them, which can no longer be used to make the apple pie. You want to make an apple pie that is as similar as possible to the one that you planned to make. Thus, you will choose the apple to eat so that the flavor of the apple pie made of the remaining N-1 apples will have the smallest possible absolute difference from the flavor of the apple pie made of all the N apples. Find the flavor of the apple pie made of the remaining N-1 apples when you choose the apple to eat as above. We can prove that this value is uniquely determined. Constraints 2 \leq N \leq 200 -100 \leq L \leq 100 All values in input are integers. Input Input is given from Standard Input in the following format: N L Output Find the flavor of the apple pie made of the remaining N-1 apples when you optimally choose the apple to eat. Sample Input 1 5 2 Sample Output 1 18 The flavors of Apple 1 , 2 , 3 , 4 , and 5 are 2 , 3 , 4 , 5 , and 6 , respectively. The optimal choice is to eat Apple 1 , so the answer is 3+4+5+6=18 . Sample Input 2 3 -1 Sample Output 2 0 The flavors of Apple 1 , 2 , and 3 are -1 , 0 , and 1 , respectively. The optimal choice is to eat Apple 2 , so the answer is (-1)+1=0 . Sample Input 3 30 -50 Sample Output 3 -1044
| 38,605
|
Problem Statement Let's consider operations on monochrome images that consist of hexagonal pixels, each of which is colored in either black or white. Because of the shape of pixels, each of them has exactly six neighbors (e.g. pixels that share an edge with it.) " Filtering " is an operation to determine the color of a pixel from the colors of itself and its six neighbors. Examples of filterings are shown below. Example 1: Color a pixel in white when all of its neighboring pixels are white. Otherwise the color will not change. Performing this operation on all the pixels simultaneously results in " noise canceling, " which removes isolated black pixels. Example 2: Color a pixel in white when its all neighboring pixels are black. Otherwise the color will not change. Performing this operation on all the pixels simultaneously results in " edge detection, " which leaves only the edges of filled areas. Example 3: Color a pixel with the color of the pixel just below it, ignoring any other neighbors. Performing this operation on all the pixels simultaneously results in " shifting up " the whole image by one pixel. Applying some filter, such as " noise canceling " and " edge detection, " twice to any image yields the exactly same result as if they were applied only once. We call such filters idempotent . The " shifting up " filter is not idempotent since every repeated application shifts the image up by one pixel. Your task is to determine whether the given filter is idempotent or not. Input The input consists of multiple datasets. The number of dataset is less than $100$. Each dataset is a string representing a filter and has the following format (without spaces between digits). $c_0c_1\cdots{}c_{127}$ $c_i$ is either ' 0 ' (represents black) or ' 1 ' (represents white), which indicates the output of the filter for a pixel when the binary representation of the pixel and its neighboring six pixels is $i$. The mapping from the pixels to the bits is as following: and the binary representation $i$ is defined as $i = \sum_{j=0}^6{\mathit{bit}_j \times 2^j}$, where $\mathit{bit}_j$ is $0$ or $1$ if the corresponding pixel is in black or white, respectively. Note that the filter is applied on the center pixel, denoted as bit 3. The input ends with a line that contains only a single " # ". Output For each dataset, print " yes " in a line if the given filter is idempotent, or " no " otherwise (quotes are for clarity). Sample Input 00000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000111111111 10000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000011111111 01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101 # Output for the Sample Input yes yes no
| 38,606
|
Problem A: Starship Hakodate-maru The surveyor starship Hakodate-maru is famous for her two fuel containers with unbounded capacities. They hold the same type of atomic fuel balls. There, however, is an inconvenience. The shapes of the fuel containers # 1 and # 2 are always cubic and regular tetrahedral respectively. Both of the fuel containers should be either empty or filled according to their shapes. Otherwise, the fuel balls become extremely unstable and may explode in the fuel containers. Thus, the number of fuel balls for the container # 1 should be a cubic number ( n 3 for some n = 0, 1, 2, 3,... ) and that for the container # 2 should be a tetrahedral number ( n ( n + 1)( n + 2)/6 for some n = 0, 1, 2, 3,... ). Hakodate-maru is now at the star base Goryokaku preparing for the next mission to create a precise and detailed chart of stars and interstellar matters. Both of the fuel containers are now empty. Commander Parus of Goryokaku will soon send a message to Captain Future of Hakodate-maru on how many fuel balls Goryokaku can supply. Captain Future should quickly answer to Commander Parus on how many fuel balls she requests before her ship leaves Goryokaku. Of course, Captain Future and her omcers want as many fuel balls as possible. For example, consider the case Commander Parus offers 151200 fuel balls. If only the fuel container # 1 were available (i.e. ifthe fuel container # 2 were unavailable), at most 148877 fuel balls could be put into the fuel container since 148877 = 53 Ã 53 Ã 53 < 151200 < 54 Ã 54 Ã 54 . If only the fuel container # 2 were available, at most 147440 fuel balls could be put into the fuel container since 147440 = 95 Ã 96 Ã 97/6 < 151200 < 96 Ã 97 Ã 98/6 . Using both of the fuel containers # 1 and # 2, 151200 fuel balls can be put into the fuel containers since 151200 = 39 Ã 39 Ã 39 + 81 Ã 82 Ã 83/6 . In this case, Captain Future's answer should be "151200". Commander Parus's offer cannot be greater than 151200 because of the capacity of the fuel storages of Goryokaku. Captain Future and her omcers know that well. You are a fuel engineer assigned to Hakodate-maru. Your duty today is to help Captain Future with calculating the number of fuel balls she should request. Input The input is a sequence of at most 1024 positive integers. Each line contains a single integer. The sequence is followed by a zero, which indicates the end of data and should not be treated as input. You may assume that none of the input integers is greater than 151200. Output The output is composed of lines, each containing a single integer. Each output integer should be the greatest integer that is the sum of a nonnegative cubic number and a nonnegative tetrahedral number and that is not greater than the corresponding input number. No other characters should appear in the output. Sample Input 100 64 50 20 151200 0 Output for the Sample Input 99 64 47 20 151200
| 38,607
|
Digit For a positive integer a , let S(a) be the sum of the digits in base l . Also let L(a) be the minimum k such that S^k(a) is less than or equal to l-1 . Find the minimum a such that L(a) = N for a given N , and print a modulo m . Input The input contains several test cases, followed by a line containing "0 0 0". Each test case is given by a line with three integers N , m , l ( 0 \leq N \leq 10^5 , 1 \leq m \leq 10^9 , 2 \leq l \leq 10^9 ). Output For each test case, print its case number and the minimum a modulo m as described above. Sample Input 0 1000 10 1 1000 10 0 0 0 Output for the Sample Input Case 1: 1 Case 2: 10
| 38,608
|
Score : 700 points Problem Statement For strings s and t , we will say that s and t are prefix-free when neither is a prefix of the other. Let L be a positive integer. A set of strings S is a good string set when the following conditions hold true: Each string in S has a length between 1 and L (inclusive) and consists of the characters 0 and 1 . Any two distinct strings in S are prefix-free. We have a good string set S = \{ s_1, s_2, ..., s_N \} . Alice and Bob will play a game against each other. They will alternately perform the following operation, starting from Alice: Add a new string to S . After addition, S must still be a good string set. The first player who becomes unable to perform the operation loses the game. Determine the winner of the game when both players play optimally. Constraints 1 \leq N \leq 10^5 1 \leq L \leq 10^{18} s_1 , s_2 , ..., s_N are all distinct. { s_1 , s_2 , ..., s_N } is a good string set. |s_1| + |s_2| + ... + |s_N| \leq 10^5 Input Input is given from Standard Input in the following format: N L s_1 s_2 : s_N Output If Alice will win, print Alice ; if Bob will win, print Bob . Sample Input 1 2 2 00 01 Sample Output 1 Alice If Alice adds 1 , Bob will be unable to add a new string. Sample Input 2 2 2 00 11 Sample Output 2 Bob There are two strings that Alice can add on the first turn: 01 and 10 . In case she adds 01 , if Bob add 10 , she will be unable to add a new string. Also, in case she adds 10 , if Bob add 01 , she will be unable to add a new string. Sample Input 3 3 3 0 10 110 Sample Output 3 Alice If Alice adds 111 , Bob will be unable to add a new string. Sample Input 4 2 1 0 1 Sample Output 4 Bob Alice is unable to add a new string on the first turn. Sample Input 5 1 2 11 Sample Output 5 Alice Sample Input 6 2 3 101 11 Sample Output 6 Bob
| 38,609
|
Problem B: Hyper Rock-Scissors-Paper Rock-Scissors-Paper is a game played with hands and often used for random choice of a person for some purpose. Today, we have got an extended version, namely, Hyper Rock-Scissors-Paper (or Hyper RSP for short). In a game of Hyper RSP, the players simultaneously presents their hands forming any one of the following 15 gestures: Rock, Fire, Scissors, Snake, Human, Tree, Wolf, Sponge, Paper, Air, Water, Dragon, Devil, Lightning, and Gun. Figure 1: Hyper Rock-Scissors-Paper The arrows in the figure above show the defeating relation. For example, Rock defeats Fire, Scissors, Snake, Human, Tree, Wolf, and Sponge. Fire defeats Scissors, Snake, Human, Tree, Wolf, Sponge, and Paper. Generally speaking, each hand defeats other seven hands located after in anti-clockwise order in the figure. A player is said to win the game if the playerâs hand defeats at least one of the other hands, and is not defeated by any of the other hands. Your task is to determine the winning hand, given multiple hands presented by the players. Input The input consists of a series of data sets. The first line of each data set is the number N of the players ( N < 1000). The next N lines are the hands presented by the players. The end of the input is indicated by a line containing single zero. Output For each data set, output the winning hand in a single line. When there are no winners in the game, output âDrawâ (without quotes). Sample Input 8 Lightning Gun Paper Sponge Water Dragon Devil Air 3 Rock Scissors Paper 0 Output for the Sample Input Sponge Draw
| 38,610
|
ç³ç å€ä»£åœå®¶ã€ã¯ã·ãã®éºè·¡ããç¡æ°ã®ç³çãçºèŠããããç ç©¶è
ã®èª¿æ»ã«ãã£ãŠãåç³çã«ã¯äžã€ã®åèªãå»ãŸããŠããããšãåãã£ããããããé·å¹Žã®é¢šåã«ãã£ãŠã以äžã®çç±ã§è§£èªãå°é£ãªç³çãããããã ã ç³çã«æžãããŠããåèªã®äžã€ã®æåã ãã è(ãã)ã§èŠãããŠããå Žåãããããã®æåãææ¡ããããšãã§ããªãã ç³çã®å·ŠåŽãæ¬ ããŠãããããã«äœãæååãæžãããŠãããããããªãïŒç³çã®å·ŠåŽïŒæå以äžãææ¡ããããšãã§ããªãïŒã ç³çã®å³åŽãæ¬ ããŠãããããã«äœãæååãæžãããŠãããããããªãïŒç³çã®å³åŽïŒæå以äžãææ¡ããããšãã§ããªãïŒã ç³çã«èãçããŠããå Žæã¯å€ããŠãäžãæãããªãããŸããæ¬ ããç³çã«èãçããŠããããšã¯ããããç³çã®äž¡åŽãåæã«æ¬ ããŠããããšã¯ãªãã ç ç©¶è
ã¯ãç³ççºèŠä»¥åã®èª¿æ»ã§ããã£ãŠããåèªããŸãšããèŸæžãæã£ãŠããããããã颚åã®åœ±é¿ã«ããèãšæ¬ ããããç³çããå
ã®åèªãæšæž¬ãããšããèŸæžã®äžã®åèªã«åœãŠã¯ãŸããã®ãããã€ããããããã«ã¯åãããªãã ç³çã®æ
å ±ãäžãããããšããäžããããèŸæžã®äžã«åœãŠã¯ãŸããããªåèªãããã€ããããæ°ããããã°ã©ã ãäœæããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã N M word 1 word 2 : word N slate 1 slate 2 : slate M ïŒè¡ç®ã«èŸæžã«èŒã£ãŠããåèªã®æ° N (1 †N †50000)ãç³çã®æ° M (1 †M †50000) ãäžãããããç¶ã N è¡ã«åèª word i ãäžãããããåèªã¯è±å°æåã®ã¿ãå«ãé·ãã 1 ä»¥äž 200 以äžã®æååã§ããããã ãã N åã®åèªã¯å
šãŠç°ãªããç¶ã M è¡ã«ãåç³çã®æ
å ±ã衚ãæåå slate i ãäžããããã slate i ã¯è±å°æåãã?ããã*ããå«ãé·ãã 1 ä»¥äž 200 以äžã®æååã§ããã? ã¯èã«èŠãããæåã衚ãã? ã¯äžã€ã®æååã«ãå€ããšãäžã€ããçŸããªããæååã®å
é ã * ã®å Žåãç³çã®å·ŠåŽãæ¬ ããŠããããšã瀺ããæååã®æ«å°Ÿã * ã®å Žåãç³çã®å³åŽãæ¬ ããŠããããšã瀺ãã* ã¯ãæååã®å
é ãæ«å°Ÿä»¥å€ã«ã¯çŸãããåæã«äž¡åŽã«çŸããããšã¯ãªãã* ãäžã€ã ãã®æååãäžããããããšã¯ãªãã å
¥åã§äžããããæååã®æåã®ç·æ°ã¯ 3000000 ãè¶
ããªãã Output åç³çã«ã€ããŠãåèªã®æ°ãïŒè¡ã«åºåããã Sample Input 1 5 4 aloe apple apricot cactus cat apple ap* *e ca?* Sample Output 1 1 2 2 2
| 38,611
|
Binary Tree A rooted binary tree is a tree with a root node in which every node has at most two children. Your task is to write a program which reads a rooted binary tree T and prints the following information for each node u of T : node ID of u parent of u sibling of u the number of children of u depth of u height of u node type (root, internal node or leaf) If two nodes have the same parent, they are siblings . Here, if u and v have the same parent, we say u is a sibling of v (vice versa). The height of a node in a tree is the number of edges on the longest simple downward path from the node to a leaf. Here, the given binary tree consists of n nodes and evey node has a unique ID from 0 to n -1. Input The first line of the input includes an integer n , the number of nodes of the tree. In the next n lines, the information of each node is given in the following format: id left right id is the node ID, left is ID of the left child and right is ID of the right child. If the node does not have the left (right) child, the left ( right ) is indicated by -1 . Output Print the information of each node in the following format: node id : parent = p , sibling = s , degree = deg , depth = dep , height = h , type p is ID of its parent. If the node does not have a parent, print -1 . s is ID of its sibling. If the node does not have a sibling, print -1 . deg , dep and h are the number of children, depth and height of the node respectively. type is a type of nodes represented by a string ( root , internal node or leaf . If the root can be considered as a leaf or an internal node, print root . Please follow the format presented in a sample output below. Constraints 1 †n †25 Sample Input 1 9 0 1 4 1 2 3 2 -1 -1 3 -1 -1 4 5 8 5 6 7 6 -1 -1 7 -1 -1 8 -1 -1 Sample Output 1 node 0: parent = -1, sibling = -1, degree = 2, depth = 0, height = 3, root node 1: parent = 0, sibling = 4, degree = 2, depth = 1, height = 1, internal node node 2: parent = 1, sibling = 3, degree = 0, depth = 2, height = 0, leaf node 3: parent = 1, sibling = 2, degree = 0, depth = 2, height = 0, leaf node 4: parent = 0, sibling = 1, degree = 2, depth = 1, height = 2, internal node node 5: parent = 4, sibling = 8, degree = 2, depth = 2, height = 1, internal node node 6: parent = 5, sibling = 7, degree = 0, depth = 3, height = 0, leaf node 7: parent = 5, sibling = 6, degree = 0, depth = 3, height = 0, leaf node 8: parent = 4, sibling = 5, degree = 0, depth = 2, height = 0, leaf Reference Introduction to Algorithms, Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. The MIT Press.
| 38,612
|
D : åžæŸæš¡æ§ / Checkered Pattern å顿 瞊暪ã®é·ãã h, w ã®é·æ¹åœ¢ãããïŒ å
éšã«ã¯äžèŸºã®é·ãã 1 ã®æ£æ¹åœ¢ã®ãã¹ãæ·ãè©°ããããŠããïŒ æãå·Šäžã®ãã¹ã (0,0) ãšãïŒ (0,0) ã® i åäžã§ j åå³ã®ãã¹ã (i,j) ã®ããã«è¡šãããšã«ãããšïŒ (i,j) 㯠i+j ãå¶æ°ãªãèµ€è²ã«ïŒå¥æ°ãªãéè²ã«å¡ãããŠããïŒ ä»ïŒ (0,0) ã®å·Šäžã®é ç¹ãš (h â 1,w â 1) ã®å³äžã®é ç¹ãç·åã§çµãã ïŒ ãã®ç·åãéãèµ€è²ã®éšåã®é·ãã a , éè²ã®éšåã®é·ãã b ãšããããšãïŒ æ¯ a : b ã¯æŽæ°æ¯ãšãªãïŒ a : b ãæãç°¡åã«ããŠ(äºãã«çŽ ãªæŽæ°ã§)衚ãïŒ å
¥å T h_1 \ w_1 ⊠h_T \ w_T 1 ã€ã®ãã¡ã€ã«ã« T åã®å
¥åãå«ãŸããïŒ 1 è¡ç®ã« T ïŒ 1+i è¡ç®ã« T çªç®ã®å
¥åã«ããã瞊暪ã®é·ã h_i , w_i ãå
¥åãããïŒ å¶çŽ æŽæ°ã§ãã 1 †T †1000 1 †h_i, w_i †10 9 åºå åã±ãŒã¹ã«å¯Ÿããçãã 1 ã§ã¹ããŒã¹åºåãã§åºåããïŒ å
šäœã§ T è¡ã«ãããïŒ ãµã³ãã« ãµã³ãã«å
¥å1 3 2 3 3 3 4 3 ãµã³ãã«åºå1 1 1 1 0 1 1
| 38,613
|
Problem B: Amazing Mazes You are requested to solve maze problems. Without passing through these mazes, you might not be able to pass through the domestic contest! A maze here is a rectangular area of a number of squares, lined up both lengthwise and widthwise, The area is surrounded by walls except for its entry and exit. The entry to the maze is at the leftmost part of the upper side of the rectangular area, that is, the upper side of the uppermost leftmost square of the maze is open. The exit is located at the rightmost part of the lower side, likewise. In the maze, you can move from a square to one of the squares adjoining either horizontally or vertically. Adjoining squares, however, may be separated by a wall, and when they are, you cannot go through the wall. Your task is to find the length of the shortest path from the entry to the exit. Note that there may be more than one shortest paths, or there may be none. Input The input consists of one or more datasets, each of which represents a maze. The first line of a dataset contains two integer numbers, the width w and the height h of the rectangular area, in this order. The following 2 Ã h â 1 lines of a dataset describe whether there are walls between squares or not. The first line starts with a space and the rest of the line contains w â 1 integers, 1 or 0, separated by a space. These indicate whether walls separate horizontally adjoining squares in the first row. An integer 1 indicates a wall is placed, and 0 indicates no wall is there. The second line starts without a space and contains w integers, 1 or 0, separated by a space. These indicate whether walls separate vertically adjoining squares in the first and the second rows. An integer 1/0 indicates a wall is placed or not. The following lines indicate placing of walls between horizontally and vertically adjoining squares, alternately, in the same manner. The end of the input is indicated by a line containing two zeros. The number of datasets is no more than 100. Both the widths and the heights of rectangular areas are no less than 2 and no more than 30. Output For each dataset, output a line having an integer indicating the length of the shortest path from the entry to the exit. The length of a path is given by the number of visited squares. If there exists no path to go through the maze, output a line containing a single zero. The line should not contain any character other than this number. Sample Input 2 3 1 0 1 0 1 0 1 9 4 1 0 1 0 0 0 0 0 0 1 1 0 1 1 0 0 0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 0 0 1 1 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 1 0 12 5 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 0 0 1 0 1 0 0 0 0 0 0 1 1 0 1 1 0 1 1 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 Output for the Sample Input 4 0 20
| 38,615
|
ä¹è»åž æ°å¹¹ç·ã«ä¹ãããã«ã¯ããä¹è»åžããç¹æ¥åžãã®2æã®å笊ãå¿
èŠã§ããçµè·¯ã®äžéšã§æ°å¹¹ç·ãå©çšããªãå Žåãããããããããã¯å¥ã
ã®å笊ãšãªã£ãŠããŸãããæ°å¹¹ç·ã®ã¿ãå©çšããçµè·¯ã§ã¯ã1æã§ä¹è»åžãšç¹æ¥åžãå
Œãããä¹è»ã»ç¹æ¥åžããçºè¡ãããããšããããŸãã èªåæ¹ææ©ã§ã¯ããããã®å笊ãèªã¿èŸŒãã§ãæ£ããå笊ãæå
¥ããããšãã ãã²ãŒããéããªããã°ãªããŸããããä¹è»åžããšãç¹æ¥åžãããããïŒæããŸãã¯ããã®äž¡æ¹ããŸãã¯ããä¹è»ã»ç¹æ¥åžããïŒææå
¥ããããã©ãããå€å®ããèªåæ¹ææ©ã®æã®ééã倿ããããã°ã©ã ãäœæããŠäžããã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã b 1 b 2 b 3 å
¥åã¯ïŒè¡ãããªããïŒã€ã®ç©ºçœã§åºåãããïŒã€ã®æŽæ°ãå«ããb 1 ã¯ãä¹è»åžãã®æå
¥ç¶æ
ãb 2 ã¯ãç¹æ¥åžãã®æå
¥ç¶æ
ãb 3 ã¯ãä¹è»ã»ç¹æ¥åžãã®æå
¥ç¶æ
ã瀺ããæå
¥ç¶æ
ã¯0ãŸãã¯1ã§è¡šããã0ã®å Žåã¯æå
¥ãããŠããªãç¶æ
ã1ã®å Žåã¯æå
¥ãããŠããç¶æ
ã衚ãããã ããæ³å®ãããæå
¥ç¶æ
ã®çµã¿åããã¯ä»¥äžã®å Žåã®ã¿ãšããã å
¥å æå
¥ç¶æ
æå
¥ã«å¯Ÿããæã®åäœ 1 0 0 ãä¹è»åžãã®ã¿æå
¥ Close 0 1 0 ãç¹æ¥åžãã®ã¿æå
¥ Close 1 1 0 ãä¹è»åžããšãç¹æ¥åžãæå
¥ Open 0 0 1 ãä¹è»ã»ç¹æ¥åžãæå
¥ Open 0 0 0 æå
¥ãªã Close åºå èªåæ¹ææ©ã®ééã衚ãOpenãŸãã¯CloseãïŒè¡ã«åºåããã å
¥åäŸ1 0 0 1 åºåäŸ1 Open å
¥åäŸ2 0 1 0 åºåäŸ2 Close
| 38,616
|
Score : 100 points Problem Statement We have a grid with H rows and W columns, where all the squares are initially white. You will perform some number of painting operations on the grid. In one operation, you can do one of the following two actions: Choose one row, then paint all the squares in that row black. Choose one column, then paint all the squares in that column black. At least how many operations do you need in order to have N or more black squares in the grid? It is guaranteed that, under the conditions in Constraints, having N or more black squares is always possible by performing some number of operations. Constraints 1 \leq H \leq 100 1 \leq W \leq 100 1 \leq N \leq H \times W All values in input are integers. Input Input is given from Standard Input in the following format: H W N Output Print the minimum number of operations needed. Sample Input 1 3 7 10 Sample Output 1 2 You can have 14 black squares in the grid by performing the "row" operation twice, on different rows. Sample Input 2 14 12 112 Sample Output 2 8 Sample Input 3 2 100 200 Sample Output 3 2
| 38,618
|
F: ã«ãŒãã²ãŒã åé¡ ã«ãŒãã䜿ã£ãã²ãŒã ã $Q$ åè¡ããŸãã ã«ãŒãã«ã¯ $1 \cdots N$ ã®æ°ãæžãããŠãããåæ°ãæžãããã«ãŒãã¯ã²ãŒã ãè¡ãã®ã«ååãªææ°ããããŸãã $i$ åç®ã®ã²ãŒã ã§ã¯ãã¯ããã«ææãšã㊠2 æã®ã«ãŒããé
ãããŸãã ããããã®ã«ãŒãã«æžãããŠããæ°å㯠$x_i$ ãš $y_i$ ã§ãã ã«ãŒãã¯ã«ãŒã«ã«åŸã£ãŠäº€æããããšãã§ããŸãã $j$ çªç® $(1 \le j \le M)$ ã®ã«ãŒã«ã§ã¯ãã«ãŒã $a_j$ ãææ°æ $c_j$ åã§å¥ã®ã«ãŒã $b_j$ ã«äº€æããããšãã§ããŸãã åã«ãŒã«ã¯äœåã§ãçšããããšãã§ããŸãããŸããææ°æãè¶³ããªããŠäº€æã§ããªãå Žåã¯ãããŸããã æåŸã«ãææã®ã«ãŒãã®æ°åã $R$ ã§å²ã£ãããŸããçããæãå ±é
¬ãšã㊠$z_i$ ååãåããŸãã ç°ãªãå Žåå ±é
¬ã¯ $0$ åã§ãã $Q$ åã²ãŒã ãçµããæã«å¢ããããšã®ã§ãããéã®æå€§å€ãæ±ããŠãã ããã å¶çŽ $1 \le N \le 10^5$ $0 \le M \le \min(2 \times 10^5, N\times(N-1))$ $2 \le R \le 10$ $1 \le Q \le 10^5$ $1 \le a_j, b_j \le N$ $a_j \neq b_j$ $0 \le c_j \le 10^5$ $1 \le x_i, y_i \le N$ $0 \le z_i \le 10^5$ å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããŸãã $N \ M \ R \ Q$ $a_1 \ b_1 \ c_1$ $\vdots$ $a_M \ b_M \ c_M$ $x_1 \ y_1 \ z_1$ $\vdots$ $x_Q \ y_Q \ z_Q$ åºå ã²ãŒã ã $Q$ åè¡ã£ããšãã«å¢ããããšã®ã§ãããéã®æå€§å€ã 1 è¡ã§åºåããŠãã ããããŸããæ«å°Ÿã«æ¹è¡ãåºåããŠãã ããã ãµã³ãã« å
¥åäŸ 1 4 4 2 2 1 2 1 2 3 1 3 4 5 4 1 7 1 4 5 2 4 3 åºåäŸ 1 7 1 åç®ã®ã²ãŒã ã§ã¯ã«ãŒã 1 ãææ°æ 1 ã§ã«ãŒã 2 ã«äº€æãããšææã®ã«ãŒãã 2 ã§å²ã£ãæã®ããŸããã©ã¡ãã 0 ãšãªããåŸãããå ±é
¬ã¯ 5 ãšãªããŸãã 2 åç®ã®ã²ãŒã ã§ã¯ãã§ã« 2 ã§å²ã£ããšãã®ããŸããã©ã¡ãã 0 ã§ãããåŸãããå ±é
¬ã¯ 3 ãšãªããŸãã 2 åã®ã²ãŒã ã®çµæãå¢ããããé㯠$5-1+3=7$ ã§ãã å
¥åäŸ 2 4 4 2 1 1 2 1 2 3 1 3 4 5 4 1 7 3 4 2 åºåäŸ 2 0 ã«ãŒãã®äº€æã§ã®ææ°æãå ±é
¬ãããå€ãã®ã§ã亀æãè¡ããªãã®ãæé©ã§ãã
| 38,619
|
Problem H: Fibonacci Sets Fibonacci number f ( i ) appear in a variety of puzzles in nature and math, including packing problems, family trees or Pythagorean triangles. They obey the rule f ( i ) = f ( i - 1) + f ( i - 2), where we set f (0) = 1 = f (-1). Let V and d be two certain positive integers and be N ⡠1001 a constant. Consider a set of V nodes, each node i having a Fibonacci label F [ i ] = ( f ( i ) mod N) assigned for i = 1,..., V †N. If | F ( i ) - F ( j )| < d , then the nodes i and j are connected. Given V and d , how many connected subsets of nodes will you obtain? Figure 1: There are 4 connected subsets for V = 20 and d = 100. Input Each data set is defined as one line with two integers as follows: Line 1 : Number of nodes V and the distance d . Input includes several data sets (i.e., several lines). The number of dat sets is less than or equal to 50. Constraints 1 †V †1000 1 †d †150 Output Output line contains one integer - the number of connected subsets - for each input line. Sample Input 5 5 50 1 13 13 Output for the Sample Input 2 50 8
| 38,620
|
Problem G: Number Sorting Consider sets of natural numbers. Some sets can be sorted in the same order numerically and lexicographically. {2, 27, 3125, 9000} is one example of such sets; {2, 27, 243} is not since lexicographic sorting would yield {2, 243, 27}. Your task is to write a program that, for the set of integers in a given range [ A , B ] (i.e. between A and B inclusive), counts the number of non-empty subsets satisfying the above property. Since the resulting number is expected to be very huge, your program should output the number in modulo P given as the input. Input The input consists of multiple datasets. Each dataset consists of a line with three integers A , B , and P separated by a space. These numbers satisfy the following conditions: 1 †A †1,000,000,000, 0 †B - A < 100,000, 1 †P †1,000,000,000. The end of input is indicated by a line with three zeros. Output For each dataset, output the number of the subsets in modulo P . Sample Input 1 10 1000 1 100000 1000000000 999999999 1000099998 1000000000 0 0 0 Output for the Sample Input 513 899507743 941554688
| 38,621
|
Score : 100 points Problem Statement There is a grid with H horizontal rows and W vertical columns. Let (i, j) denote the square at the i -th row from the top and the j -th column from the left. In the grid, N Squares (r_1, c_1), (r_2, c_2), \ldots, (r_N, c_N) are wall squares, and the others are all empty squares. It is guaranteed that Squares (1, 1) and (H, W) are empty squares. Taro will start from Square (1, 1) and reach (H, W) by repeatedly moving right or down to an adjacent empty square. Find the number of Taro's paths from Square (1, 1) to (H, W) , modulo 10^9 + 7 . Constraints All values in input are integers. 2 \leq H, W \leq 10^5 1 \leq N \leq 3000 1 \leq r_i \leq H 1 \leq c_i \leq W Squares (r_i, c_i) are all distinct. Squares (1, 1) and (H, W) are empty squares. Input Input is given from Standard Input in the following format: H W N r_1 c_1 r_2 c_2 : r_N c_N Output Print the number of Taro's paths from Square (1, 1) to (H, W) , modulo 10^9 + 7 . Sample Input 1 3 4 2 2 2 1 4 Sample Output 1 3 There are three paths as follows: Sample Input 2 5 2 2 2 1 4 2 Sample Output 2 0 There may be no paths. Sample Input 3 5 5 4 3 1 3 5 1 3 5 3 Sample Output 3 24 Sample Input 4 100000 100000 1 50000 50000 Sample Output 4 123445622 Be sure to print the count modulo 10^9 + 7 .
| 38,622
|
Problem H: Cone Cut Problem ãã®åé¡ã§ã¯3次å
空éäžã®ããç¹ X ãšããç¹ Y ãéããããªçŽç·ãçŽç· XY ãšæžãã 3次å
空éäžã«åéãšãã®åéå
éšã®ç¹ P ãäžãããããç¹ P ãéãåéã®åºé¢ã«åçŽãªçŽç·ãšåéã®åºé¢ãšã®äº€ç¹ãç¹ Q ãšããããã®æãåéã®åºé¢ã®äžå¿ã O ãšããçŽç· OQ ãšåéã®åºé¢ã®ååšãšã®äº€ç¹ããç¹ Q ã«è¿ãæ¹ããç¹ A ãç¹ B ãšãã(ãã ããç¹ O ãšç¹ Q ãåäžç¹ã®ãšãã¯ãç¹ O ãéãä»»æã®çŽç·ãšåéã®åºé¢ã®ååšãšã®äº€ç¹ãç¹ A ãç¹ B ãšããã)ããŸããåéã®åºé¢ãå«ããããªå¹³é¢ã«ãããŠãç¹ O ãéããçŽç· AB ãšåçŽã«äº€ããçŽç·ãšåéã®åºé¢ã®ååšãšã®äº€ç¹ãç¹ C ãç¹ D ãšãã(ãã ããç¹ C ãšç¹ D ã¯å
¥ãæ¿ããŠãåé¡ãªã)ã 以äžã®å³ã¯ãåéã®é ç¹æ¹åããèŠãåéã®åºé¢ã®å³ã§ããã çŽç· AP ãšçŽç· BP ã®åéãšã®äº€ç¹ïŒçŽç· AP ã®å Žåãç¹ A ã§ãªãæ¹ã®äº€ç¹ãæããçŽç· BP ãåæ§ãïŒãç¹ A' ãç¹ B' ãšããç¹ A' ãšç¹ B' ãéãçŽç· CD ãšå¹³è¡ãªå¹³é¢ S ã§åéãåæããããã®æãåæåŸã®é ç¹ãå«ãå³åœ¢ã®äœç©ãšããäžæ¹ã®å³åœ¢ã®äœç©ã空çœåºåãã§åºåããã Input åéã®é ç¹ã® x åº§æš y åº§æš z åº§æš åéã®åºé¢ã®äžå¿ã® x åº§æš y åº§æš z åº§æš åéã®åºé¢ã®ååŸ ç¹ P ã® x åº§æš y åº§æš z åº§æš åè¡ã®ããããã®å€ã¯ã¹ããŒã¹åºåãã§äžããããã Constraint å
¥åã®å€ã¯ãã¹ãп޿°ã§ããããã®çµ¶å¯Ÿå€ã¯1000以äžã§ããã åéã®é«ããšãã®åºé¢ã®ååŸã¯1以äžã§ãããç¹ P ãšåéã®è·é¢ã¯10 -5 以äžããã Output åæåŸã®é ç¹ãå«ãå³åœ¢ã®äœç©ãšããäžæ¹ã®å³åœ¢ã®äœç©ã空çœåºåãã§åºåããã ãã ãã10 -5 ãè¶
ãã誀差ãå«ãã§ã¯ãããªãã Sample Input 1 0 0 10 0 0 0 4 0 0 1 Sample Output 1 91.769438 75.782170 Sample Input 2 0 0 10 0 0 0 4 1 1 1 Sample Output 2 84.050413 83.501195 Sample Input 3 0 0 0 8 9 10 5 1 1 1 Sample Output 3 0.071663 409.709196
| 38,623
|
Problem J: Averaging Problem ã¢ã€ã
åœã«ã¯$N$åã®å³¶ãš$N-1$åã®æ©ããããåå³¶ã¯ãããã$1$ãã$N$ãŸã§ã®çªå·ãå²ãæ¯ãããŠããã $i$çªç®ã®æ©ã¯å³¶$u_i$ãšå³¶$v_i$ãåæ¹åã«çµãã§ãããå³¶æ°ã¯æ©ãçšããŠå³¶ãšå³¶ãšãè¡ãæ¥ããããšãã§ããããŸããæ©ä»¥å€ã«å³¶ãšå³¶ãè¡ãæ¥ããæ¹æ³ã¯ãªãã ã©ã®å³¶ããã©ã®å³¶ãžãããã€ãã®æ©ãæž¡ãããšã§å°éããããšãã§ããã çŸåšãå³¶$i$ã«ã¯$X_i$人ã®å³¶æ°ãããã åå³¶ã®ç°å¢ãžã®è² è·ã忣ãããããã«ã¢ã€ã
åœã¯äœäººãã®åœæ°ã«å¥ã®å³¶ãžåŒè¶ããŠãããããšã«ããã å³¶$a$ã«äœãã§ãã人ãå³¶$b$ã«åŒè¶ããããããã«ã¯å³¶$a$ãšå³¶$b$ã®è·é¢ãšåãåã®ã³ã¹ãããããããã ããå³¶$a$ãšå³¶$b$ã®è·é¢ã¯å³¶$a$ããå³¶$b$ãžè¡ãããã«æž¡ãå¿
èŠã®ããæ©ã®æ°ã®æå°å€ã§å®çŸ©ãããã ã©ã®$2$ã€ã®å³¶ãéžãã§ããããã®å³¶æ°ã®äººæ°ã®å·®ã®çµ¶å¯Ÿå€ã$1$以äžã«ãªãããã«åœæ°ã«åŒè¶ããŠãããããã ãã®ãšããå¿
èŠãªã³ã¹ãã®ç·åã®æå°å€ãæ±ããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§ãã¹ãп޿°ã§äžããããã $N$ $X_1$ $X_2$ ... $X_N$ $u_1$ $v_1$ $u_2$ $v_2$ ... $u_{N-1}$ $v_{N-1}$ $1$è¡ç®ã«å³¶ã®æ°$N$ãäžããããã $2$è¡ç®ã«ã¯åå³¶ã®å³¶æ°ã®äººæ°ã衚ã$N$åã®æŽæ°ã空çœåºåãã§äžããããã$i$çªç®ã®æŽæ°$X_i$ã¯å³¶$i$ã®å³¶æ°ã®äººæ°ã衚ãã $3$è¡ç®ããç¶ã$N-1$è¡ã«ã¯åæ©ãã€ãªãå³¶ã®çªå·ã空çœåºåãã§äžããããã$2+i$è¡ç®ã®å
¥åã§ã¯ã$i$çªç®ã®æ©ãå³¶$u_i$ãšå³¶$v_i$ãåæ¹åã«çµãã§ããããšã衚ãã Constraints å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã $2 \le N \le 5000$ $0 \le X_i \le 10^9$ $1 \le u_i, v_i \le N$ ã©ã®å³¶ããã©ã®å³¶ãžãããã€ãã®æ©ãæž¡ãããšã§å°éããããšãã§ãã Output ã³ã¹ãã®ç·åã®æå°å€ã1è¡ã«åºåããã Sample Input 1 5 4 0 4 0 0 1 2 1 3 1 4 2 5 Sample Output 1 7 å³¶$1$ã®äººã$1$人ãå³¶$2$ãžã å³¶$1$ã®äººã$1$人ãå³¶$5$ãžã å³¶$3$ã®äººã$2$人ãå³¶$4$ãžåŒã£è¶ãããšã§ã©ã®$2$ã€ã®å³¶ãéžãã§ããããã®å³¶æ°ã®äººæ°ã®å·®ã®çµ¶å¯Ÿå€ã$1$以äžã«ãªãã ãŸããã®ãšãã®ã³ã¹ãã®ç·åã¯$1+2+2\times2 = 7$ã§ããããããæå°ã§ããã Sample Input 2 7 0 7 2 5 0 3 0 1 2 1 3 1 4 2 5 3 6 3 7 Sample Output 2 10
| 38,624
|
ããŒãº (Cheese) åé¡ ä»å¹Žã JOI çºã®ããŒãºå·¥å ŽãããŒãºã®çç£ãå§ãïŒããã¿ãå·£ããé¡ãåºããïŒJOI çºã¯æ±è¥¿ååã«åºç»æŽçãããŠããŠïŒååºç»ã¯å·£ïŒããŒãºå·¥å ŽïŒé害ç©ïŒç©ºãå°ã®ããããã§ããïŒããã¿ã¯å·£ããåºçºããŠå
šãŠã®ããŒãºå·¥å Žã蚪ãããŒãºã 1 åãã€é£ã¹ãïŒ ãã®çºã«ã¯ïŒN åã®ããŒãºå·¥å ŽãããïŒã©ã®å·¥å ŽãïŒçš®é¡ã®ããŒãºã ããçç£ããŠããïŒããŒãºã®ç¡¬ãã¯å·¥å Žã«ãã£ãŠç°ãªã£ãŠããïŒç¡¬ã 1 ãã N ãŸã§ã®ããŒãºãçç£ããããŒãºå·¥å Žãã¡ããã© 1 ã€ãã€ããïŒ ããã¿ã®æåã®äœå㯠1 ã§ããïŒããŒãºã 1 åé£ã¹ãããšã«äœåã 1 å¢ããïŒãã ãïŒããã¿ã¯èªåã®äœåããã硬ãããŒãºãé£ã¹ãããšã¯ã§ããªãïŒ ããã¿ã¯ïŒæ±è¥¿ååã«é£ãåãåºç»ã« 1 åã§ç§»åããããšãã§ãããïŒé害ç©ã®åºç»ã«ã¯å
¥ãããšãã§ããªãïŒããŒãºå·¥å ŽãããŒãºãé£ã¹ãã«éãéããããšãã§ããïŒãã¹ãŠã®ããŒãºãé£ã¹çµãããŸã§ã«ãããæçæéãæ±ããããã°ã©ã ãæžãïŒãã ãïŒããã¿ãããŒãºãé£ã¹ãã®ã«ãããæéã¯ç¡èŠã§ããïŒ å
¥å å
¥å㯠H+1 è¡ããïŒ1 è¡ç®ã«ã¯ 3 ã€ã®æŽæ° HïŒWïŒN (1 †H †1000ïŒ1 †W †1000ïŒ1 †N †9) ããã®é ã«ç©ºçœã§åºåãããŠæžãããŠããïŒ2 è¡ç®ãã H+1 è¡ç®ãŸã§ã®åè¡ã«ã¯ïŒ'S'ïŒ'1', '2', ..., '9'ïŒ'X'ïŒ'.' ãããªã W æåã®æååãæžãããŠããïŒåã
ãååºç»ã®ç¶æ
ã衚ããŠããïŒåãã i çªç®ïŒè¥¿ãã j çªç®ã®åºç»ã (i,j) ãšèšè¿°ããããšã«ãããš (1 †i †H, 1 †j †W)ïŒç¬¬ i+1 è¡ç®ã® j çªç®ã®æåã¯ïŒåºç» (i,j) ãå·£ã§ããå Žå㯠'S' ãšãªãïŒé害ç©ã§ããå Žå㯠'X' ãšãªãïŒç©ºãå°ã§ããå Žå㯠'.' ãšãªãïŒç¡¬ã 1, 2, ..., 9 ã®ããŒãºãçç£ããå·¥å Žã§ããå Žåã¯ãããã '1', '2', ..., '9' ãšãªãïŒå
¥åã«ã¯å·£ãšç¡¬ã 1, 2, ..., N ã®ããŒãºãçç£ããå·¥å Žããããã 1 ã€ãã€ããïŒä»ã®ãã¹ã¯é害ç©ãŸãã¯ç©ºãå°ã§ããããšãä¿èšŒãããŠããïŒããã¿ã¯å
šãŠã®ããŒãºãé£ã¹ãããããšãä¿èšŒãããŠããïŒ åºå ãã¹ãŠã®ããŒãºãé£ã¹çµãããŸã§ã«ãããæçæéïŒåïŒãè¡šãæŽæ°ã 1 è¡ã§åºåããïŒ å
¥åºåäŸ å
¥åäŸ 1 3 3 1 S.. ... ..1 åºåäŸ 1 4 å
¥åäŸ 2 4 5 2 .X..1 ....X .XX.S .2.X. åºåäŸ 2 12 å
¥åäŸ 3 10 10 9 .X...X.S.X 6..5X..X1X ...XXXX..X X..9X...X. 8.X2X..X3X ...XX.X4.. XX....7X.. X..X..XX.. X...X.XX.. ..X....... åºåäŸ 3 91 å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
| 38,625
|
Score : 100 points Problem Statement You are given a positive integer N . Find the minimum positive integer divisible by both 2 and N . Constraints 1 \leq N \leq 10^9 All values in input are integers. Input Input is given from Standard Input in the following format: N Output Print the minimum positive integer divisible by both 2 and N . Sample Input 1 3 Sample Output 1 6 6 is divisible by both 2 and 3 . Also, there is no positive integer less than 6 that is divisible by both 2 and 3 . Thus, the answer is 6 . Sample Input 2 10 Sample Output 2 10 Sample Input 3 999999999 Sample Output 3 1999999998
| 38,626
|
Max Score: 1450 Points Problem Statement There are N workers in Atcoder company. Each worker is numbered 0 through N - 1 , and the boss for worker i is p_i like a tree structure and the salary is currently a_i . ( p_i < i , especially p_0 = -1 because worker 0 is a president) In atcoder, the boss of boss of boss of ... (repeated k times) worker i called " k -th upper boss", and " k -th lower subordinate" called for vice versa. You have to process Q queries for Atcoder: Query 1: You are given v_i, d_i, x_i . Increase the salary of worker v_i , and all j -th ( 1 †j †d_i ) lower subordinates by x_i . Query 2: You are given v_i, d_i . Calculate the sum of salary of worker v_i and all j -th ( 1 †j †d_i ) lower subordinates. Query 3: You are given pr_i, ar_i . Now Atcoder has a new worker c ! ( c is the current number of workers) The boss is pr_i , and the first salary is ar_i . Process all queries!!! Input Format Let the i -th query query_i , the input format is following: N Q p_0 a_0 p_1 a_1 : : p_{N - 1} a_{N - 1} query_0 query_1 : : query_{Q - 1} THe format of query_i is one of the three format: 1 v_i d_i x_i 2 v_i d_i 3 pr_i ar_i Output Format Print the result in one line for each query 2. Constraints N †400000 Q †50000 p_i < i for all valid i . In each question 1 or 2, worker v_i exists. d_i †400000 0 †a_i, x_i †1000 Scoring Subtask 1 [ 170 points] N, Q †5000 Subtask 2 [ 310 points] p_i + 1 = i for all valid i . Subtask 3 [ 380 points] There are no query 3. Subtask 4 [ 590 points] There are no additional constraints. Sample Input 1 6 7 -1 6 0 5 0 4 2 3 2 2 1 1 2 0 1 1 0 2 1 2 2 1 3 3 3 2 0 3 3 3 4 2 1 1 Sample Output 1 15 12 30 8 Sample Input 2 7 9 -1 1 0 5 0 7 0 8 1 3 4 1 5 1 2 1 1 2 1 2 1 1 2 3 1 4 1 1 2 3 1 2 0 2 3 6 1 3 7 11 2 0 15 Sample Output 2 8 9 8 31 49
| 38,627
|
Problem E: Origami Through-Hole Origami is the traditional Japanese art of paper folding. One day, Professor Egami found the message board decorated with some pieces of origami works pinned on it, and became interested in the pinholes on the origami paper. Your mission is to simulate paper folding and pin punching on the folded sheet, and calculate the number of pinholes on the original sheet when unfolded. A sequence of folding instructions for a flat and square piece of paper and a single pinhole position are specified. As a folding instruction, two points P and Q are given. The paper should be folded so that P touches Q from above (Figure 4). To make a fold, we first divide the sheet into two segments by creasing the sheet along the folding line , i.e., the perpendicular bisector of the line segment PQ , and then turn over the segment containing P onto the other. You can ignore the thickness of the paper. Figure 4: Simple case of paper folding The original flat square piece of paper is folded into a structure consisting of layered paper segments, which are connected by linear hinges. For each instruction, we fold one or more paper segments along the specified folding line, dividing the original segments into new smaller ones. The folding operation turns over some of the paper segments (not only the new smaller segments but also some other segments that have no intersection with the folding line) to the reflective position against the folding line. That is, for a paper segment that intersects with the folding line, one of the two new segments made by dividing the original is turned over; for a paper segment that does not intersect with the folding line, the whole segment is simply turned over. The folding operation is carried out repeatedly applying the following rules, until we have no segment to turn over. Rule 1: The uppermost segment that contains P must be turned over. Rule 2: If a hinge of a segment is moved to the other side of the folding line by the operation, any segment that shares the same hinge must be turned over. Rule 3: If two paper segments overlap and the lower segment is turned over, the upper segment must be turned over too. In the examples shown in Figure 5, (a) and (c) show cases where only Rule 1 is applied. (b) shows a case where Rule 1 and 2 are applied to turn over two paper segments connected by a hinge, and (d) shows a case where Rule 1, 3 and 2 are applied to turn over three paper segments. Figure 5: Different cases of folding After processing all the folding instructions, the pinhole goes through all the layered segments of paper at that position. In the case of Figure 6, there are three pinholes on the unfolded sheet of paper. Figure 6: Number of pinholes on the unfolded sheet Input The input is a sequence of datasets. The end of the input is indicated by a line containing a zero. Each dataset is formatted as follows. k p x 1 p y 1 q x 1 q y 1 . . . p x k p y k q x k q y k h x h y For all datasets, the size of the initial sheet is 100 mm square, and, using mm as the coordinate unit, the corners of the sheet are located at the coordinates (0, 0), (100, 0), (100, 100) and (0, 100). The integer k is the number of folding instructions and 1 †k †10. Each of the following k lines represents a single folding instruction and consists of four integers p x i , p y i , q x i , and q y i , delimited by a space. The positions of point P and Q for the i -th instruction are given by ( p x i , p y i ) and ( q x i , q y i ), respectively. You can assume that P â Q . You must carry out these instructions in the given order. The last line of a dataset contains two integers h x and h y delimited by a space, and ( h x , h y ) represents the position of the pinhole. You can assume the following properties: The points P and Q of the folding instructions are placed on some paper segments at the folding time, and P is at least 0.01 mm distant from any borders of the paper segments. The position of the pinhole also is at least 0.01 mm distant from any borders of the paper segments at the punching time. Every folding line, when infinitely extended to both directions, is at least 0.01 mm distant from any corners of the paper segments before the folding along that folding line. When two paper segments have any overlap, the overlapping area cannot be placed between any two parallel lines with 0.01 mm distance. When two paper segments do not overlap, any points on one segment are at least 0.01 mm distant from any points on the other segment. For example, Figure 5 (a), (b), (c) and (d) correspond to the first four datasets of the sample input. Output For each dataset, output a single line containing the number of the pinholes on the sheet of paper, when unfolded. No extra characters should appear in the output. Sample Input 2 90 90 80 20 80 20 75 50 50 35 2 90 90 80 20 75 50 80 20 55 20 3 5 90 15 70 95 90 85 75 20 67 20 73 20 75 3 5 90 15 70 5 10 15 55 20 67 20 73 75 80 8 1 48 1 50 10 73 10 75 31 87 31 89 91 94 91 96 63 97 62 96 63 80 61 82 39 97 41 95 62 89 62 90 41 93 5 2 1 1 1 -95 1 -96 1 -190 1 -191 1 -283 1 -284 1 -373 1 -374 1 -450 1 2 77 17 89 8 103 13 85 10 53 36 0 Output for the Sample Input 3 4 3 2 32 1 0
| 38,628
|
Score: 500 points Problem Statement N people are standing in a queue, numbered 1, 2, 3, ..., N from front to back. Each person wears a hat, which is red, blue, or green. The person numbered i says: "In front of me, exactly A_i people are wearing hats with the same color as mine." Assuming that all these statements are correct, find the number of possible combinations of colors of the N people's hats. Since the count can be enormous, compute it modulo 1000000007 . Constraints 1 \leq N \leq 100000 0 \leq A_i \leq N-1 All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 A_3 ... A_N Output Print the number of possible combinations of colors of the N people's hats, modulo 1000000007 . Sample Input 1 6 0 1 2 3 4 5 Sample Output 1 3 We have three possible combinations, as follows: Red, Red, Red, Red, Red, Red Blue, Blue, Blue, Blue, Blue, Blue Green, Green, Green, Green, Green, Green Sample Input 2 3 0 0 0 Sample Output 2 6 Sample Input 3 54 0 0 1 0 1 2 1 2 3 2 3 3 4 4 5 4 6 5 7 8 5 6 6 7 7 8 8 9 9 10 10 11 9 12 10 13 14 11 11 12 12 13 13 14 14 15 15 15 16 16 16 17 17 17 Sample Output 3 115295190
| 38,629
|
Problem H: Queen's Case A small country called Maltius was governed by a queen. The queen was known as an oppressive ruler. People in the country suffered from heavy taxes and forced labor. So some young people decided to form a revolutionary army and fight against the queen. Now, they besieged the palace and have just rushed into the entrance. Your task is to write a program to determine whether the queen can escape or will be caught by the army. Here is detailed description. The palace can be considered as grid squares. The queen and the army move alternately. The queen moves first. At each of their turns, they either move to an adjacent cell or stay at the same cell. Each of them must follow the optimal strategy. If the queen and the army are at the same cell, the queen will be caught by the army immediately. If the queen is at any of exit cells alone after the armyâs turn, the queen can escape from the army. There may be cases in which the queen cannot escape but wonât be caught by the army forever, under their optimal strategies. Input The input consists of multiple datasets. Each dataset describes a map of the palace. The first line of the input contains two integers W (1 †W †30) and H (1 †H †30), which indicate the width and height of the palace. The following H lines, each of which contains W characters, denote the map of the palace. " Q " indicates the queen, " A " the army," E " an exit," # " a wall and " . " a floor. The map contains exactly one " Q ", exactly one " A " and at least one " E ". You can assume both the queen and the army can reach all the exits. The last dataset is followed by a line containing two zeros. This line is not a part of any dataset and should not be processed. Output For each dataset, output " Queen can escape. ", " Army can catch Queen. " or " Queen can not escape and Army can not catch Queen. " in a line. Sample Input 2 2 QE EA 3 1 QAE 3 1 AQE 5 5 ..E.. .###. A###Q .###. ..E.. 5 1 A.E.Q 5 5 A.... ####. ..E.. .#### ....Q 0 0 Output for the Sample Input Queen can not escape and Army can not catch Queen. Army can catch Queen. Queen can escape. Queen can not escape and Army can not catch Queen. Army can catch Queen. Army can catch Queen. Hint On the first sample input, the queen can move to exit cells, but either way the queen will be caught at the next armyâs turn. So the optimal strategy for the queen is staying at the same cell. Then the army can move to exit cells as well, but again either way the army will miss the queen from the other exit. So the optimal strategy for the army is also staying at the same cell. Thus the queen cannot escape but wonât be caught.
| 38,630
|
F - Polygon Guards Problem Statement You are an IT system administrator in the Ministry of Defense of Polygon Country. Polygon Country's border forms the polygon with $N$ vertices. Drawn on the 2D-plane, all of its vertices are at the lattice points and all of its edges are parallel with either the $x$-axis or the $y$-axis. In order to prevent enemies from invading the country, it is surrounded by very strong defense walls along its border. However, on the vertices, the junctions of walls have unavoidable structural weaknesses. Therefore, enemies might attack and invade from the vertices. To observe the vertices and find an invasion by enemies as soon as possible, the ministry decided to hire some guards. The ministry plans to locate them on some vertices such that all the vertices are observed by at least one guard. A guard at the vertex $A$ can observe a vertex $B$ if the entire segment connecting $A$ and $B$ is inside or on the edge of Polygon Country. Of course, guards can observe the vertices they are located on. And a guard can observe simultaneously all the vertices he or she can observe. To reduce the defense expense, the ministry wants to minimize the number of guards. Your task is to calculate the minimum number of guards required to observe all the vertices of Polygon Country. Input The input is formatted as follows. $N$ $X_1$ $Y_1$ : : $X_N$ $Y_N$ The first line contains an even integer $N$ ($4 \le N \lt 40$). The following $N$ lines describe the vertices of Polygon Country. Each of the lines contains two integers, $X_i$ and $Y_i$ ($1 \le i \le N$, $\lvert X_i \rvert \le 1{,}000$, $\lvert Y_i \rvert \le 1{,}000$), separated by one space. The position of the $i$-th vertex is $(X_i,Y_i)$. If $i$ is odd, $X_i = X_{i+1}$, $Y_i \ne Y_{i+1}$. Otherwise, $X_i \ne X_{i+1}$, $Y_i = Y_{i+1}$. Here, we regard that $X_{N+1} = X_1$, and $Y_{N+1} = Y_1$. The vertices are given in counterclockwise order under the coordinate system that the $x$-axis goes right, and the $y$-axis goes up. The shape of Polygon Country is simple. That is, each edge doesnât share any points with other edges except that its both end points are shared with its neighbor edges. Output Print the minimum number of guards in one line. Sample Input 1 8 0 2 0 0 2 0 2 1 3 1 3 3 1 3 1 2 Output for the Sample Input 1 1 Sample Input 2 12 0 0 0 -13 3 -13 3 -10 10 -10 10 10 -1 10 -1 13 -4 13 -4 10 -10 10 -10 0 Output for the Sample Input 2 2
| 38,631
|
Problem D: Long Distance Taxi A taxi driver, Nakamura, was so delighted because he got a passenger who wanted to go to a city thousands of kilometers away. However, he had a problem. As you may know, most taxis in Japan run on liquefied petroleum gas (LPG) because it is cheaper than gasoline. There are more than 50,000 gas stations in the country, but less than one percent of them sell LPG. Although the LPG tank of his car was full, the tank capacity is limited and his car runs 10 kilometer per liter, so he may not be able to get to the destination without filling the tank on the way. He knew all the locations of LPG stations. Your task is to write a program that finds the best way from the current location to the destination without running out of gas. Input The input consists of several datasets, and each dataset is in the following format. N M cap src dest c 1,1 c 1,2 d 1 c 2,1 c 2,2 d 2 . . . c N,1 c N,2 d N s 1 s 2 . . . s M The first line of a dataset contains three integers ( N, M, cap ), where N is the number of roads (1 †N †3000), M is the number of LPG stations (1†M †300), and cap is the tank capacity (1 †cap †200) in liter. The next line contains the name of the current city ( src ) and the name of the destination city ( dest ). The destination city is always different from the current city. The following N lines describe roads that connect cities. The road i (1 †i †N) connects two different cities c i,1 and c i,2 with an integer distance d i (0 < d i †2000) in kilometer, and he can go from either city to the other. You can assume that no two different roads connect the same pair of cities. The columns are separated by a single space. The next M lines ( s 1 , s 2 ,..., s M ) indicate the names of the cities with LPG station. You can assume that a city with LPG station has at least one road. The name of a city has no more than 15 characters. Only English alphabet ('A' to 'Z' and 'a' to 'z', case sensitive) is allowed for the name. A line with three zeros terminates the input. Output For each dataset, output a line containing the length (in kilometer) of the shortest possible journey from the current city to the destination city. If Nakamura cannot reach the destination, output "-1" (without quotation marks). You must not output any other characters. The actual tank capacity is usually a little bit larger than that on the specification sheet, so you can assume that he can reach a city even when the remaining amount of the gas becomes exactly zero. In addition, you can always fill the tank at the destination so you do not have to worry about the return trip. Sample Input 6 3 34 Tokyo Kyoto Tokyo Niigata 335 Tokyo Shizuoka 174 Shizuoka Nagoya 176 Nagoya Kyoto 195 Toyama Niigata 215 Toyama Kyoto 296 Nagoya Niigata Toyama 6 3 30 Tokyo Kyoto Tokyo Niigata 335 Tokyo Shizuoka 174 Shizuoka Nagoya 176 Nagoya Kyoto 195 Toyama Niigata 215 Toyama Kyoto 296 Nagoya Niigata Toyama 0 0 0 Output for the Sample Input 846 -1
| 38,632
|
Score : 100 points Problem Statement Cat Snuke is learning to write characters. Today, he practiced writing digits 1 and 9 , but he did it the other way around. You are given a three-digit integer n written by Snuke. Print the integer obtained by replacing each digit 1 with 9 and each digit 9 with 1 in n . Constraints 111 \leq n \leq 999 n is an integer consisting of digits 1 and 9 . Input Input is given from Standard Input in the following format: n Output Print the integer obtained by replacing each occurrence of 1 with 9 and each occurrence of 9 with 1 in n . Sample Input 1 119 Sample Output 1 991 Replace the 9 in the ones place with 1 , the 1 in the tens place with 9 and the 1 in the hundreds place with 9 . The answer is 991 . Sample Input 2 999 Sample Output 2 111
| 38,633
|
Score : 400 points Problem Statement Given are positive integers A and B . Let us choose some number of positive common divisors of A and B . Here, any two of the chosen divisors must be coprime. At most, how many divisors can we choose? Definition of common divisor An integer d is said to be a common divisor of integers x and y when d divides both x and y . Definition of being coprime Integers x and y are said to be coprime when x and y have no positive common divisors other than 1 . Definition of dividing An integer x is said to divide another integer y when there exists an integer \alpha such that y = \alpha x . Constraints All values in input are integers. 1 \leq A, B \leq 10^{12} Input Input is given from Standard Input in the following format: A B Output Print the maximum number of divisors that can be chosen to satisfy the condition. Sample Input 1 12 18 Sample Output 1 3 12 and 18 have the following positive common divisors: 1 , 2 , 3 , and 6 . 1 and 2 are coprime, 2 and 3 are coprime, and 3 and 1 are coprime, so we can choose 1 , 2 , and 3 , which achieve the maximum result. Sample Input 2 420 660 Sample Output 2 4 Sample Input 3 1 2019 Sample Output 3 1 1 and 2019 have no positive common divisors other than 1 .
| 38,635
|
ééäŒç€Ÿ çœèééã¯äŒæŽ¥è¥æŸåžã代衚ããééäŒç€Ÿã§ããæšä»ã®åæ²¹äŸ¡æ Œã®é«éš°ã¯ééäŒç€Ÿã«ãå€å€§ãªãã¡ãŒãžãäžããééäŒç€Ÿå瀟ã§ã¯ãã§ããã ãå°ãªãã¬ãœãªã³ã§è·ç©ãéã¶ããšã課é¡ãšãªã£ãŠããŸãã çœèééã§ã¯ãéãè·ç©ãç©ãã ãã©ãã¯ã¯ããã®èµ°ãã ãã«å€ãã®ãšãã«ã®ãŒãå¿
èŠãšããããšã«çç®ããŸããããã©ãã¯ãå庫ãåºçºããŠããäžåºŠã忢ããããšãªãç®çå°ãŸã§å°éããçµè·¯ã®äžã§æçæéã®çµè·¯ãéãããšã§ãã¬ãœãªã³ã®ç¯çŽãã§ãããšèããŸããã ããªãã®ä»äºã¯ããã®ãããªæççµè·¯ãèšç®ã§ããã«ãŒãããéçºããããšã§ããäœæããã«ãŒããçšããã°ã©ã ã®ä»æ§ã¯ä»¥äžã®ãšããã§ãã åžå
ã¯ãäžå³ã®ããã«ãæ±è¥¿æ¹åã®éè·¯ M æ¬ãååæ¹åã®éè·¯ N æ¬ ãããªãæ Œåã§è¡šããæ Œåã®å亀ç¹ã¯äº€å·®ç¹ã衚ããŸãã 亀差ç¹ã®ããã€ãã«ã¯æ±è¥¿ - ååã®æ¹åã«ä¿¡å·æ©ãèšçœ®ãããŠãããäžå®ã®åšæã§éãèµ€ã®ã·ã°ãã«ãç¹ç¯ããŠããŸãã åžå
ã®äº€å·®ç¹éãçµã¶éè·¯ã«ã¯å·¥äºäžã§ééã§ããªãåæãããã€ããããŸãã ãã©ãã¯ã亀差ç¹ãã亀差ç¹ãžç§»åããã®ã«å¿
èŠãªæéã¯äžå®ã§ãããæžæ»ããŠããéè·¯ã§ã¯ããã«é·ãæéãããããŸãã åžå
ã®éè·¯æ
å ±ããã©ãã¯ã亀差ç¹éãç§»åããã®ã«å¿
èŠãªæéãä¿¡å·æ©ããã亀差ç¹ãšåä¿¡å·æ©ã®åšæãå·¥äºäžã®éè·¯ãæžæ»ããŠããéè·¯ãšæžæ»åºŠãçœèééã®å庫(å§ç¹)ãšç®çå°(çµç¹)ã®äœçœ®ãå
¥åãšããå§ç¹ããçµç¹ãŸã§ã®æçã®æéãåºåããããã°ã©ã ãäœæããŠäžããã å³ã®ããã«ãæ±è¥¿ã®æ¹åã®éè·¯ã¯aãbãcã... ãšè±å°æåã§ååãä»ããã ãååã®æ¹åã®é路㯠1ã2ã3ã... ãšæŽæ°ã§ååãä»ããããŠããŸããåžå
ã®äº€å·®ç¹ã¯ããããã®è±å°æåãšæŽæ°ã®çµã¿åãã H - V ã§æå®ãããŸãã äŸãã°ãåžå
ã®æå西ã®äº€å·®ç¹ã¯ a-1 ã§æå®ãããŸããåä¿¡å·ã¯åšæ k ããã¡ã k åããšã«åãæ¿ãããŸããæ±è¥¿ãéãªãã°ååãèµ€ã§ãååãéãªãã°æ±è¥¿ãèµ€ã§ããé»è²ã®ã·ã°ãã«ã¯ååšããŸããããã©ãã¯ã¯äºã€ã®äº€å·®ç¹ãçµã¶éè·¯ãç§»åããã®ã« D åèŠããŸããããã®éè·¯ãæžæ»ããŠããå Žåã¯ããã« d åã®æéãèŠããŸãããã©ãã¯ã¯éè·¯ãå·¥äºäžã®å Žåã¯ç§»åã§ããŸããã ãŸãã亀差ç¹ã«å°éããæå»ã«ãä¿¡å·ãèµ€ã®å Žåã«ã¯é²å
¥ã§ããŸããããã©ãã¯ã¯äº€å·®ç¹ã§ã®ã¿ãæ±ã西ãåãåã«æ¹åãå€ããããšãã§ããŸãããæ¥ãæ¹åãžã¯ç§»å(Uã¿ãŒã³)ã§ããŸãããéè·¯ã¯2æ¹éè¡ã§ããããã©ãã¯ãè¡ãæ¥ããæéãå·¥äºç¶æ³ãæžæ»åºŠã¯2æ¹åå
±éã§ãã åæç¶æ
ãšããŠããã©ãã¯ã¯æ±ãåããŠããŠããã©ãã¯ãå庫ãåºçºããç¬éãã¹ãŠã®ä¿¡å·æ©ãååã®æ¹åã«éã«åãæ¿ãããã®ãšããŸãããŸãããã©ãã¯ã¯ 100å以å
ã§ç®çå°ã«å°éã§ãããã®ãšããŸãã Input è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒããµãã€ã®è¡ã§ç€ºãããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã M N D ns H 1 - V 1 k 1 H 2 - V 2 k 2 : H ns - V ns k ns nc H 11 - V 11 H 12 - V 12 H 21 - V 21 H 22 - V 22 : H nc1 - V nc1 H nc2 - V nc2 nj H 11 - V 11 H 12 - V 12 d 1 H 21 - V 21 H 22 - V 22 d 2 : H nj1 - V nj1 H nj2 - V nj2 d nj H s - V s H d - V d ïŒè¡ç®ã«éè·¯ã®æ¬æ° M , N (2 †M, N †20) ãäžããããŸããïŒè¡ç®ã«ãäºã€ã®äº€å·®ç¹ãçµã¶éè·¯ãç§»åããã®ã«èŠããæé D (1 †D †D, æŽæ°) ãäžããããŸãã ïŒè¡ç®ã«ä¿¡å·æ©ã®æ° ns ãäžããããŸããç¶ã ns è¡ã«ã i åç®ã®ä¿¡å·æ©ã®äœçœ®ã衚ãè±å°æåãšæŽæ°ã®çµ H i - V i ãšåšæ k (1 †k †100) ãäžããããŸãã ç¶ãè¡ã«ãå·¥äºäžã®éè·¯ã®æ° nc ãäžããããŸããç¶ã nc è¡ã«ã i åç®ã®å·¥äºäžã®éè·¯ã®ïŒã€ã®ç«¯ç¹ïŒäº€å·®ç¹ïŒã衚ãè±å°æåãšæŽæ°ã®çµ H i1 - V i1 H i2 - V i2 ãäžããããŸãã ç¶ãè¡ã«ãæžæ»éè·¯ã®æ° nj ãäžããããŸããç¶ã nj è¡ã«ã i åç®ã®æžæ»éè·¯ã®ïŒã€ã®ç«¯ç¹ïŒäº€å·®ç¹ïŒã衚ãè±å°æåãšæŽæ°ã®çµ H i1 - V i1 H i2 - V i2 ãšæé d i (1 †d i †100) ãäžããããŸãã æåŸã®è¡ã«ãå§ç¹ã®äº€å·®ç¹ H s - V d ãšçµç¹ã®äº€å·®ç¹ H d - V d ãäžããããŸãã ããŒã¿ã»ããã®æ°ã¯ 20 ãè¶
ããŸããã Output ããŒã¿ã»ããæ¯ã«æçæéãïŒè¡ã«åºåããŸãã Sample Input 4 5 1 3 b-2 3 c-3 2 c-4 1 3 a-2 b-2 b-3 c-3 d-3 d-4 2 b-3 b-4 1 c-1 d-1 1 d-1 b-4 4 5 1 3 b-2 3 c-3 2 c-4 1 3 a-2 b-2 b-3 c-3 d-3 d-4 2 b-3 b-4 1 c-1 d-1 1 d-2 b-4 4 5 1 3 b-2 3 c-3 2 c-4 1 3 a-2 b-2 b-3 c-3 d-3 d-4 2 b-3 b-4 1 c-1 d-1 1 d-3 b-4 0 0 Output for the Sample Input 7 4 8
| 38,636
|
Lower Bound For a given sequence $A = \{a_0, a_1, ..., a_{n-1}\}$ which is sorted by ascending order, find the lower bound for a specific value $k$ given as a query. lower bound: the place pointing to the first element greater than or equal to a specific value, or $n$ if there is no such element. Input The input is given in the following format. $n$ $a_0 \; a_1 \; ,..., \; a_{n-1}$ $q$ $k_1$ $k_2$ : $k_q$ The number of elements $n$ and each element $a_i$ are given in the first line and the second line respectively. In the third line, the number of queries $q$ is given and the following $q$ lines, $q$ integers $k_i$ are given as queries. Output For each query, print the position $i$ ($i = 0, 1, ..., n$) of the lower bound in a line. Constraints $1 \leq n \leq 100,000$ $1 \leq q \leq 200,000$ $0 \leq a_0 \leq a_1 \leq ... \leq a_{n-1} \leq 1,000,000,000$ $0 \leq k_i \leq 1,000,000,000$ Sample Input 1 4 1 2 2 4 3 2 3 5 Sample Output 1 1 3 4
| 38,637
|
H: æ¿ åé¡ $R * C$ ã®ãã¹ãäžããããŸãïŒåãã¹ã¯äœããªããã¹ãïŒç©ŽãéããŠãããã¹ã®ã©ã¡ããã§ãïŒ äžãããããã¹ã¯ä»¥äžã®æ¡ä»¶ãæºãããŸãã 穎ã®éãããã¹å士ã¯é£çµã§ããïŒïŒç©Žã®éãããã¹ãååæ¹åã«ã€ãã£ãŠä»»æã®ç©Žã®éãããã¹ã«ç§»åããããšãã§ããïŒ äœããªããã¹å士ã¯é£çµã§ããïŒ ããªãã¯å¹
ã $1$ ã®ä»»æé·ã®é·æ¹åœ¢åã®ã¿ã€ã«ãçæããããšãã§ããŸãïŒ ãã®ã¿ã€ã«ãè€æ°æèšçœ®ããŠå
šãŠã®ç©Žã®ãããã¹ãåãããã§ãïŒã¿ã€ã«ãèšçœ®ãããšãïŒä»¥äžã®å¶çŽãå®ãå¿
èŠããããŸãïŒ ã¿ã€ã«ã¯çžŠåããæšªåãã® $2$ æ¹åã§ã®ã¿èšçœ®ãå¯èœã§ããïŒ äžã€ã®ãã¹ã«äºæä»¥äžã®ã¿ã€ã«ãéãªãããã«èšçœ®ããŠã¯ãããªãïŒ ç©Žã®ãªããã¹ã®äžã«ã¿ã€ã«ããã£ãŠã¯ãããªãïŒ äžèšã®å¶çŽãå®ã£ãŠå
šãŠã®ç©Žã®ãããã¹ãã¿ã€ã«ã§åãããšãã®ïŒã¿ã€ã«ã®æå°ææ°ãçããŠãã ããïŒ å¶çŽ $1 \leq R, C \leq 25$ $|S_i| = C \ \ \ \ |S_i|$ ã¯æååã®é·ãã衚ãã $S_{i,j}$ 㯠'#' ãŸã㯠'.' ã§ããããã穎ã®éãããã¹ãäœããªããã¹ã衚ãã å
¥ååœ¢åŒ å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã $R\ C$ $S_{1,1} \dots S_{1,C}$ $\vdots$ $S_{R,1} \dots S_{R,C}$ åºå æå°åæ°ãåºåããŠãã ãããæ«å°Ÿã«æ¹è¡ãåºåããŠãã ããã ãµã³ãã« ãµã³ãã«å
¥å 1 5 5 ..... .#.#. .###. .#.#. ..... ãµã³ãã«åºå 1 3 $3$ æã®ã¿ã€ã«ã以äžã®ããã«çœ®ãã®ãæé©ã§ã ..... .1.3. .123 .1.3 ..... ãµã³ãã«å
¥å 2 4 10 ########## ....#..... ....#..... .......... ãµã³ãã«åºå 2 2 $2$ æã®ã¿ã€ã«ã以äžã®ããã«çœ®ãã®ãæé©ã§ãïŒã¿ã€ã«ã®é·ãã¯ä»»æé·ã«ã§ãïŒçžŠåãã«ã暪åãã«ã䜿ããããšã«æ³šæããŠãã ããïŒ 1111111111 ....2..... ....2..... ..........
| 38,638
|
Koto Municipal Subway Kotoåžå¶å°äžé Kotoåžã¯ïŒäžå³ã®ããã«ïŒéè·¯ãç¢ç€ã®ç®ç¶ã§ããæåãªè¡ã§ããïŒ ååã«äŒžã³ãéãšæ±è¥¿ã«äŒžã³ãéã¯ïŒãããã1kmã®ééã§äžŠãã§ããïŒ Kotoåžã®æãå西ã®äº€å·®ç¹ã«ããKotoé§
ã (0, 0) ãšããŠïŒããããæ±ã« x kmïŒåã« y km é²ãã äœçœ®ã ( x , y ) ãšèšãããšãšãã (0 †x , y ã§ãã)ïŒ 5幎åŸã«éããããªãªã³ããã¯ã«ãã芳å
客ãå¢å€§ããããšãèŠè¶ããŠïŒåžã¯Kotoé§
ãå§çºé§
ãšããæ°ããå°äžéã®è·¯ç·ã建èšããããšã決ããïŒ çŸåšïŒKotoé§
ã®æ¬¡ã®é§
ãšããŠæ°ãã建èšãããShin-Kotoé§
ãŸã§ã®ã¬ãŒã«ãæ·ãèšç»ãç«ãŠãŠããïŒ ã¬ãŒã«ã¯ïŒKotoé§
ããShin-Kotoé§
ã«åãã£ãŠãŸã£ããæ·ãïŒ åŸã£ãŠïŒShin-Kotoé§
ã®å Žæã ( x , y ) ãšãããšãïŒã¬ãŒã«ã®é·ãã¯ïŒ â( x 2 + y 2 ) ã§ããïŒ ã¬ãŒã«ãæ·ãããã®è²»çšã¯ïŒæ·ããã¬ãŒã«ã®é·ãåã ãå¿
èŠã«ãªãïŒ ã¬ãŒã«ã®é·ãã1.5kmã®ããã«å°æ°ã§ãã£ãŠãïŒè²»çšãåãããã«1.5å¿
èŠãšãªãïŒ Shin-Kotoé§
ã®å Žæ ( x , y ) ã¯ãŸã 決å®ããŠãããïŒä»¥äžã®æ¡ä»¶ãæºããå Žæã«ããäºå®ã§ããïŒ äº€å·®ç¹ã§ããïŒã€ãŸãïŒ x ãš y ãããããæŽæ°ã§ããïŒ Kotoé§
ããéè·¯ã«æ²¿ã£ãŠæ©ããæçè·é¢ãïŒã¡ããã© D ã§ããïŒã€ãŸãïŒ x + y = D ãæºããïŒ äžã®2ã€ã®æ¡ä»¶ãæºããäžã§ïŒåžãå®ããã¬ãŒã«ã®äºç® E ãšã¬ãŒã«ã®è²»çšãšã®ãã | â( x 2 + y 2 ) - E | ãæå°ãšãªãããã«Shin-Kotoé§
ã®å Žæãéžã¶ïŒ ããã§ | A | ã¯ïŒ A ã®çµ¶å¯Ÿå€ã衚ãïŒ ããªãã®ä»äºã¯ïŒäžèšã®ããã«Shin-Kotoé§
ã建èšãããšãã®ïŒã¬ãŒã«ãæ·ãããã®è²»çšãšäºç®ãšã®ãããåºåããããã°ã©ã ãäœæããããšã§ããïŒ Input å
¥åã¯ïŒè€æ°ã®ããŒã¿ã»ããããæ§æããïŒ1ã€ã®å
¥åã«å«ãŸããããŒã¿ã»ããã®æ°ã¯100以äžã§ããïŒ åããŒã¿ã»ããã®åœ¢åŒã¯æ¬¡ã®éãã§ããïŒ D E D (1 †D †100)ã¯ïŒKotoé§
ããShin-Kotoé§
ãŸã§éè·¯ã«æ²¿ã£ãŠæ©ãããšãã®æçè·é¢ãè¡šãæŽæ°ã§ããïŒ E (1 †E †100)ã¯ïŒã¬ãŒã«å»ºèšã®ããã®äºç®ãè¡šãæŽæ°ã§ããïŒ å
¥åã®çµããã¯ïŒç©ºçœã§åºåããã2ã€ã®ãŒããããªãè¡ã«ãã£ãŠç€ºãããïŒ Output åããŒã¿ã»ããã«å¯ŸããŠïŒåé¡ã®æ¡ä»¶ãæºããããã«ã¬ãŒã«ãæ·ãããšãã®è²»çšãšäºç®ãšã®ããã1è¡ã§åºåããïŒ çãã«ã¯ 10 -3 ãè¶ãã絶察誀差ããã£ãŠã¯ãªããªãïŒ åè¡ã®çµããã«æ¹è¡ãåºåããªãã£ãå ŽåãïŒäžå¿
èŠãªæåãåºåããå ŽåïŒèª€çãšå€æãããŠããŸãããïŒæ³šæããããšïŒ Sample Input 2 1 7 5 7 6 7 7 76 5 8 41 0 0 Output for Sample Input 0.4142135624 0 0.0827625303 0 48.7401153702 33 Hint 1ã€ç®ã®ããŒã¿ã»ããã§ã¯ïŒäžå³ã®ããã«ïŒKotoé§
ããéè·¯ã«æ²¿ã£ãŠ2kmé²ãã 亀差ç¹ãShin-Kotoé§
ã建èšããå Žæã®åè£ãšãªãïŒ å亀差ç¹ã«Shin-Kotoé§
ã建èšããå Žåã®ïŒã¬ãŒã«ãæ·ãããã®è²»çšãšäºç®1ãšã®ããã¯æ¬¡ã®ããã«ãªãïŒ (2, 0) ïŒ | â(2 2 + 0 2 ) - 1 | = 1.0 (1, 1) ïŒ | â(1 2 + 1 2 ) - 1 | = 0.4142135623... (0, 2) ïŒ | â(0 2 + 2 2 ) - 1 | = 1.0 ãã£ãŠïŒè²»çšãšäºç®ãšã®ãããæå°ã«ãªãã®ã¯ïŒ (1, 1) ã«å»ºèšããå ŽåãšãªãïŒ
| 38,639
|
Problem A: Hanafuda Shuffle There are a number of ways to shuffle a deck of cards. Hanafuda shuffling for Japanese card game 'Hanafuda' is one such example. The following is how to perform Hanafuda shuffling. There is a deck of n cards. Starting from the p -th card from the top of the deck, c cards are pulled out and put on the top of the deck, as shown in Figure 1. This operation, called a cutting operation, is repeated. Write a program that simulates Hanafuda shuffling and answers which card will be finally placed on the top of the deck. Figure 1: Cutting operation Input The input consists of multiple data sets. Each data set starts with a line containing two positive integers n (1 <= n <= 50) and r (1 <= r <= 50); n and r are the number of cards in the deck and the number of cutting operations, respectively. There are r more lines in the data set, each of which represents a cutting operation. These cutting operations are performed in the listed order. Each line contains two positive integers p and c ( p + c <= n + 1). Starting from the p -th card from the top of the deck, c cards should be pulled out and put on the top. The end of the input is indicated by a line which contains two zeros. Each input line contains exactly two integers separated by a space character. There are no other characters in the line. Output For each data set in the input, your program should write the number of the top card after the shuffle. Assume that at the beginning the cards are numbered from 1 to n , from the bottom to the top. Each number should be written in a separate line without any superfluous characters such as leading or following spaces. Sample Input 5 2 3 1 3 1 10 3 1 10 10 1 8 3 0 0 Output for the Sample Input 4 4
| 38,640
|
é·æ¹åœ¢ ã¢ã€ã
æŸéåäŒã®æè²çªçµ(æè²)ã§ã¯ãåã©ãåãã®å·¥äœçªçµããããã§ã€ããããæŸéããŠããŸãã仿¥ã¯æ£ã§é·æ¹åœ¢ãäœãåã§ãããçšæããïŒæ¬ã®æ£ã䜿ã£ãŠé·æ¹åœ¢ãã§ãããã確ãããããšæããŸãããã ããæ£ã¯åã£ããæã£ããããŠã¯ãããŸããã ïŒæ¬ã®æ£ã®é·ããäžããããã®ã§ãããããã¹ãŠã蟺ãšããé·æ¹åœ¢ãäœãããã©ããå€å®ããããã°ã©ã ãäœæããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã e 1 e 2 e 3 e 4 å
¥åã¯ïŒè¡ãããªãã忣ã®é·ããè¡šãæŽæ° e i (1 †e i †100) ãäžããããã Output é·æ¹åœ¢ãäœæã§ããå Žåã«ã¯ãyesãããäœæã§ããªãå Žåã«ã¯ãnoããåºåããããã ããæ£æ¹åœ¢ã¯é·æ¹åœ¢ã®äžçš®ãªã®ã§ãæ£æ¹åœ¢ã®å Žåã§ããyesããšåºåããã Sample Input 1 1 1 3 4 Sample Output 1 no Sample Input 2 1 1 2 2 Sample Output 2 yes Sample Input 3 2 1 1 2 Sample Output 3 yes Sample Input 4 4 4 4 10 Sample Output 4 no
| 38,641
|
Score : 800 points Problem Statement There is a grid with R rows and C columns. We call the cell in the r -th row and c -th column ( rïŒc ). Mr. Takahashi wrote non-negative integers into N of the cells, that is, he wrote a non-negative integer a_i into ( r_iïŒc_i ) for each i ( 1â€iâ€N ). After that he fell asleep. Mr. Aoki found the grid and tries to surprise Mr. Takahashi by writing integers into all remaining cells. The grid must meet the following conditions to really surprise Mr. Takahashi. Condition 1 : Each cell contains a non-negative integer. Condition 2 : For any 2Ã2 square formed by cells on the grid, the sum of the top left and bottom right integers must always equal to the sum of the top right and bottom left integers. Determine whether it is possible to meet those conditions by properly writing integers into all remaining cells. Constraints 2â€RïŒCâ€10^5 1â€Nâ€10^5 1â€r_iâ€R 1â€c_iâ€C (r_iïŒc_i) â (r_jïŒc_j) ( iâ j ) a_i is an integer. 0â€a_iâ€10^9 Input The input is given from Standard Input in the following format: R C N r_1 c_1 a_1 r_2 c_2 a_2 : r_N c_N a_N Output Print Yes if it is possible to meet the conditions by properly writing integers into all remaining cells. Otherwise, print No . Sample Input 1 2 2 3 1 1 0 1 2 10 2 1 20 Sample Output 1 Yes You can write integers as follows. Sample Input 2 2 3 5 1 1 0 1 2 10 1 3 20 2 1 30 2 3 40 Sample Output 2 No There are two 2Ã2 squares on the grid, formed by the following cells: Cells (1ïŒ1) , (1ïŒ2) , (2ïŒ1) and (2ïŒ2) Cells (1ïŒ2) , (1ïŒ3) , (2ïŒ2) and (2ïŒ3) You have to write 40 into the empty cell to meet the condition on the left square, but then it does not satisfy the condition on the right square. Sample Input 3 2 2 3 1 1 20 1 2 10 2 1 0 Sample Output 3 No You have to write -10 into the empty cell to meet condition 2 , but then it does not satisfy condition 1 . Sample Input 4 3 3 4 1 1 0 1 3 10 3 1 10 3 3 20 Sample Output 4 Yes You can write integers as follows. Sample Input 5 2 2 4 1 1 0 1 2 10 2 1 30 2 2 20 Sample Output 5 No All cells already contain a integer and condition 2 is not satisfied.
| 38,642
|
Score : 100 points Problem Statement AtCoder Inc. holds a contest every Saturday. There are two types of contests called ABC and ARC, and just one of them is held at a time. The company holds these two types of contests alternately: an ARC follows an ABC and vice versa. Given a string S representing the type of the contest held last week, print the string representing the type of the contest held this week. Constraints S is ABC or ARC . Input Input is given from Standard Input in the following format: S Output Print the string representing the type of the contest held this week. Sample Input 1 ABC Sample Output 1 ARC They held an ABC last week, so they will hold an ARC this week.
| 38,643
|
Taro's Shopping Mammy decided to give Taro his first shopping experience. Mammy tells him to choose any two items he wants from those listed in the shopping catalogue, but Taro cannot decide which two, as all the items look attractive. Thus he plans to buy the pair of two items with the highest price sum, not exceeding the amount Mammy allows. As getting two of the same item is boring, he wants two different items. You are asked to help Taro select the two items. The price list for all of the items is given. Among pairs of two items in the list, find the pair with the highest price sum not exceeding the allowed amount, and report the sum. Taro is buying two items, not one, nor three, nor more. Note that, two or more items in the list may be priced equally. Input The input consists of multiple datasets, each in the following format. n m a 1 a 2 ... a n A dataset consists of two lines. In the first line, the number of items n and the maximum payment allowed m are given. n is an integer satisfying 2 †n †1000. m is an integer satisfying 2 †m †2,000,000. In the second line, prices of n items are given. a i (1 †i †n ) is the price of the i -th item. This value is an integer greater than or equal to 1 and less than or equal to 1,000,000. The end of the input is indicated by a line containing two zeros. The sum of n 's of all the datasets does not exceed 50,000. Output For each dataset, find the pair with the highest price sum not exceeding the allowed amount m and output the sum in a line. If the price sum of every pair of items exceeds m , output NONE instead. Sample Input 3 45 10 20 30 6 10 1 2 5 8 9 11 7 100 11 34 83 47 59 29 70 4 100 80 70 60 50 4 20 10 5 10 16 0 0 Output for the Sample Input 40 10 99 NONE 20
| 38,644
|
åé¡å DNA éºäŒåã¯ã A , T , G , C ãããªãæååã§ãã ãã®äžçã®éºäŒåã¯å¥åŠãªããšã«ãããæ§æèŠåã«åŸãããšãç¥ãããŠããŸãã æ§æèŠåã¯ã次ã®ãããªåœ¢ã§äžããããŸãã éçµç«¯èšå·1: èšå·1_1 èšå·1_2 ... èšå·1_n1 éçµç«¯èšå·2: èšå·2_1 èšå·2_2 ... èšå·2_n2 ... éçµç«¯èšå·m: èšå·m_1 èšå·m_2 ... èšå·m_nm èšå·ã¯éçµç«¯èšå·ãŸãã¯çµç«¯èšå·ã®ã©ã¡ããã§ãã éçµç«¯èšå·ã¯å°æåæååã§è¡šãããçµç«¯èšå·ã¯ A , T , G , C ã®ãã¡ã®ããã€ãã®æåãã" [ "ãš" ] "ã«å²ãŸããæååã§è¡šãããŸãã æ§æèŠåã®äŸã¯æ¬¡ã®ããã«ãªããŸãã dna: a a b b a: [AT] b: [GC] " éçµç«¯èšå·i: èšå·i_1 èšå·i_2 ... èšå·i_ni " ãéçµç«¯èšå· i ã®ã«ãŒã«ãšåŒã³ãã«ãŒã«ã¯ãæ§æèŠåã«çŸããåéçµç«¯èšå·ã«å¯ŸããŠãã¡ããã© 1 ã€ã¥ã€ååšããŸãã æåå s ãéçµç«¯èšå· i ã«ã ããããã ããšã¯ã s = s 1 + s 2 + ... + s ni ãšãªããã㪠s ã®éšåæåå {s j } ãååšãã s j ( 1 †j †n i )ãã«ãŒã«å
ã®èšå· j ã«ãããããããšããããŸãã æåå s ãçµç«¯èšå·ã«ã ããããã ããšã¯ãæååã 1 æåãããªãããã®æåãçµç«¯èšå·ã衚ãæååã«å«ãŸããããšããããŸãã æååãæ§æèŠåã«åŸããšã¯ãéçµç«¯èšå· 1 ã«ãã®æååããããããããšããããŸãã ã«ãŒã« i ã¯ãèšå·ã®ãã¡ã«ãéçµç«¯èšå· j ( j †i ) ãå«ã¿ãŸããã æ§æèŠåãšã4ã€ã®æŽæ° Na , Nt , Ng , Nc ãäžããããŸãã æ§æèŠåã«åŸããA ãã¡ããã© Na åãT ãã¡ããã© Nt åãG ãã¡ããã© Ng åãC ãã¡ããã© Nc åå«ããããªéºäŒåã®ç·æ°ã 1,000,000,007 ã§å²ã£ãäœããæ±ããªããã Input Na Nt Ng Nc m éçµç«¯èšå·1: èšå· 1 1 èšå· 1 2 ... èšå· 1 n1 éçµç«¯èšå·2: èšå· 2 1 èšå· 2 2 ... èšå· 2 n2 ... éçµç«¯èšå· m : èšå· m 1 èšå· m 2 ... èšå· m nm 0 †Na, Nt, Ng, Nc †50 1 †m †50 1 †ni †10 1 †èšå·ã衚ãæååã®é·ã †20 (â»èšå·ã«ãããããæååã®é·ãã§ã¯ãªãããšã«æ³šæ) Output ç·æ°ã 1,000,000,007 ã§å²ã£ãäœã Sample Input 1 1 0 1 0 3 dna: a b a: [AT] b: [GC] Output for the Sample Input 1 1 "AG"ã®äžã€ã§ãã Sample Input 2 1 1 1 2 1 k: [ATG] [ATG] [ATG] [C] [C] Output for the Sample Input 2 6 "ATGCC", "AGTCC", "TAGCC", "TGACC", "GATCC", "GTACC"ã®6ã€ã§ãã Sample Input 3 3 1 1 1 3 inv: at b b b at: [ATG] b b: [C] Output for the Sample Input 3 0
| 38,645
|
Score : 700 points Problem Statement There are N stones arranged in a row. The i -th stone from the left is painted in the color C_i . Snuke will perform the following operation zero or more times: Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possible final sequences of colors of the stones, modulo 10^9+7 . Constraints 1 \leq N \leq 2\times 10^5 1 \leq C_i \leq 2\times 10^5(1\leq i\leq N) All values in input are integers. Input Input is given from Standard Input in the following format: N C_1 : C_N Output Print the number of possible final sequences of colors of the stones, modulo 10^9+7 . Sample Input 1 5 1 2 1 2 2 Sample Output 1 3 We can make three sequences of colors of stones, as follows: (1,2,1,2,2) , by doing nothing. (1,1,1,2,2) , by choosing the first and third stones to perform the operation. (1,2,2,2,2) , by choosing the second and fourth stones to perform the operation. Sample Input 2 6 4 2 5 4 2 4 Sample Output 2 5 Sample Input 3 7 1 3 1 2 3 3 2 Sample Output 3 5
| 38,646
|
Problem HïŒ Puzzle and Hexagons Backgorund è¶
倧人æ°ã²ãŒã ãããºã«&ãããµãŽã³ãºããã€ãã«ãªãªãŒã¹ãããããã®ã²ãŒã ã¯è¶
é¢çœãããŠãããããã人ãç¶åºãããŸãã®ç±äžåºŠã«å»åž«ããäžæ¯èªå®ãåããè
ãç¶åºãããäžçååœã®æå¿éã¯ãã®ã²ãŒã ã®äžæ¯è
éãå©ããããã«ãããºã«&ãããµãŽã³ãºãã®ã·ãã¥ã¬ãŒã¿ãäœããå±éºãªå®æ©ã§ã®ãã¬ã€ãé¿ããããä¿ãããšãããããªãã«ã¯ã·ãã¥ã¬ãŒã¿äœãã«ååããŠæ¬²ããã Problem æ£å
è§åœ¢ã®ãã¹ã瞊㫠H åãæšªã« W åæ·ãè©°ããç€é¢ãäžããããã Fig.1㯠H =4, W =7ã®æã®ç€é¢ãšããã«å¯Ÿå¿ãããã¹ã®åº§æš( x , y )ã瀺ãã Fig.1 åæç¶æ
ã§åãã¹ã«ã¯è²ã®ã€ãããããã¯ãååšããã ãããã¯ã®è²ã¯ä»¥äžã®ããã«ã¢ã«ãã¡ãããäžæåã§è¡šçŸãããã 'R' ã»ã»ã»èµ€ 'G' ã»ã»ã»ç· 'B' ã»ã»ã»é 'P' ã»ã»ã»çŽ« 'Y' ã»ã»ã»é» 'E' ã»ã»ã»æ°Ž æ¬¡ã«æäœã®æ° Q ãäžããããã åæäœã§ã¯å転ã®äžå¿åº§æš( x , y )ãäžãããããã®ãã¹ã®åšå²ã«ãã6ã€ã®ãããã¯ãæèšåãã«äžã€å転ãããããšã瀺ãã(Fig.2 åç
§)ã ãã®ãšãããããã¯ãååšããªããã¹ã空ã®ãããã¯ãååšãããšèããŠæèšåãã«äžã€å転ãããã ãã ããæå®ããã座æšãšãã®åšèŸºã®ïŒã€ã®ãã¹ã®å
ããããäžã€ã§ã H à W ã®ç€é¢ã®äžã«ååšããŠããªãå Žåã¯å転ãè¡ããªãã Fig.2 次ã«ä»¥äžã®åŠçãã§ããªããªããŸã§ç¹°ãè¿ãã Fig.3ã«ãããŠããããã¯Aã®äœçœ®ããB, C, Dã®äœçœ®ã®ãããã®ãã¹ã«ããããã¯ãååšããªããšãããããã¯Aã¯Cã®äœçœ®ã«èœäžããããã¹B, Dãååšããªãå Žåã¯ãããã¯ãååšããªããšèãããã¹Cãååšããªãå Žåã¯èœäžã®åŠçãè¡ããªãã 1ã®åŠçãå¯èœãªãããã¯ãååšããå Žåã¯1ã«æ»ãã åãè²ã®ãããã¯ã3ã€ä»¥äžç¹ãã£ãŠããå Žåããã®ãããã¯ã¯å
šãŠæ¶æ»
ããã 2ã€ã®ãããã¯ãç¹ãããšã¯ãã¹ã®äžèŸºãå
±æããããšã§ããã æ³šæïŒãã®äžé£ã®åŠçã¯ãæäœãäžã€ãäžããããŠããªãç¶æ
ïŒåæç¶æ
ïŒã§ãè¡ãããã Fig.3 å
šãŠã®æäœãå®è¡ããåŸã®æçµçãªç€é¢ãåºåããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã H W F 0, Hâ1 F 1, Hâ1 ⊠F Wâ1, Hâ1 F 0, Hâ2 F 1, Hâ2 ⊠F Wâ1, Hâ2 . . . F 0, 0 F 1, 0 ⊠F Wâ1, 0 Q x 0 y 0 x 1 y 1 . . . x Qâ1 y Qâ1 1è¡ç®ã«ãç€é¢ã®çžŠãšæšªã®ãµã€ãºã衚ã2ã€ã®æŽæ° H ãš W ãäžããããã 2è¡ç®ãã H +1è¡ç®ã«ãåæ·»åã«å¯Ÿå¿ããç€é¢ã®è²ã衚ãæååãäžããããã H +2è¡ç®ã«ãæäœã®æ° Q ãäžããããã ç¶ã Q è¡ã«å転ã®äžå¿ã®ãã¹ã®åº§æšã衚ã x ãš y ãäžããããã Constraints 3 †H †50 3 †W †50 0 †x < W 0 †y < H 1 †Q †100 F i, j ( 0 †i < W , 0 †j < H ) ã¯'R','G','B','P','Y','E'ã®ããããã§ããã Output å
šãŠã®æäœãè¡ã£ãåŸã®ç€é¢ã H è¡ã§åºåããã ãã ãããããã¯ãç¡ããã¹ã¯'.'ã§è¡šãããšã Sample Input1 3 3 RGR RBP YEB 1 1 1 Sample Output1 ⊠YBG EBP Fig.4ã¯Sample Input1ã«ãããç¶æ
ã®é·ç§»ã衚ãããã®ã§ããã Fig.4 Sample Input2 4 5 BYYGG RRRRR RRBRR YYGGB 2 3 1 3 1 Sample Output2 ..... ..... ..... B.BGB Sample Input3 4 4 BEEP ERYY BBRP RBYP 1 1 2 Sample Output3 .... .... .... .B.. ç€é¢ã®åæç¶æ
ã§ãã§ã«æ¶ãããããã¯ãããããšæ³šæã 䞡端ã«ãããããã¯ã®èœäžåŠçã«æ³šæã
| 38,648
|
Score : 100 points Problem Statement You are given three integers A, B and C . Determine if there exists an equilateral triangle whose sides have lengths A, B and C . Constraints All values in input are integers. 1 \leq A,B,C \leq 100 Input Input is given from Standard Input in the following format: A B C Output If there exists an equilateral triangle whose sides have lengths A, B and C , print Yes ; otherwise, print No . Sample Input 1 2 2 2 Sample Output 1 Yes There exists an equilateral triangle whose sides have lengths 2, 2 and 2 . Sample Input 2 3 4 5 Sample Output 2 No There is no equilateral triangle whose sides have lengths 3, 4 and 5 .
| 38,649
|
H: Rectangular Stamps ICPC ã§è¯ãæçžŸãåããã«ã¯ä¿®è¡ãæ¬ ãããªãïŒããã㯠ICPC ã§åã¡ããã®ã§ïŒä»æ¥ãä¿®è¡ãããããšã«ããïŒ ä»æ¥ã®ä¿®è¡ã¯ïŒçµµãæãããšã«ãã£ãŠïŒåµé åãé«ããããšãããã®ã§ããïŒåè§ãã¹ã¿ã³ããçšããŠïŒäžæãæš¡æ§ãæããïŒ å€§å°ããŸããŸãªã¹ã¿ã³ãã䜿ãïŒ4 à 4 ã®ãã¹ç®ã®çŽã«æå®ãããèµ€ã»ç·ã»éã®éãã®çµµã宿ããããïŒã¹ã¿ã³ãã¯é·æ¹åœ¢ã§ããïŒãã¹ç®ã«ãŽã£ããåãããŠäœ¿ãïŒã¹ã¿ã³ãã®çžŠãšæšªãå
¥ãæ¿ããããšã¯ã§ããªãïŒ çŽã¯æåè²ãå¡ãããŠããªãç¶æ
ã«ããïŒçŽã«ã¹ã¿ã³ããæŒããšïŒæŒãããéšåãã¹ã¿ã³ãã®è²ã«å€ããïŒäžã«é ããè²ã¯å
šãèŠããªããªãïŒã¹ã¿ã³ãã®è²ã¯ä»ããã€ã³ã¯ã«ããæ±ºå®ãããã®ã§ïŒã©ã®ã¹ã¿ã³ãã§ãïŒå¥œããªè²ãéžã¶ããšãå¯èœã§ããïŒã¹ã¿ã³ãã¯çŽããäžéšãã¯ã¿åºãç¶æ
ã§æŒãããšãå¯èœã§ããïŒã¯ã¿åºãéšåã¯ç¡èŠãããïŒ 1 ã€ã®ã¹ã¿ã³ããè€æ°å䜿ãããšã¯å¯èœã§ããïŒåãã¹ã¿ã³ããå¥ã®è²ã«å¯ŸããŠäœ¿ã£ãŠãããïŒã¹ã¿ã³ããæŒãã®ã¯ããç¥çµã䜿ãäœæ¥ãªã®ã§ïŒåºæ¥ãã ãã¹ã¿ã³ããæŒãåæ°ãå°ãªããããïŒ Input N H 1 W 1 ... H N W N C 1,1 C 1,2 C 1,3 C 1,4 C 2,1 C 2,2 C 2,3 C 2,4 C 3,1 C 3,2 C 3,3 C 3,4 C 4,1 C 4,2 C 4,3 C 4,4 N ã¯ã¹ã¿ã³ãã®åæ°ïŒ H i , W i (1 †i †N ) ã¯ããããïŒ i çªç®ã®ã¹ã¿ã³ãã®çžŠã®é·ãïŒæšªã®é·ããè¡šãæŽæ°ã§ããïŒ C i , j (1 †i †4ïŒ1 †j †4) ã¯ïŒäžãã i è¡ç®ïŒå·Šãã j åç®ã®ãã¹ã«ã€ããŠæå®ãããçµµã®è²ã衚ãæåã§ããïŒèµ€ã¯ R ïŒç·ã¯ G ïŒé㯠B ã§è¡šãããïŒ 1 †N †16ïŒ1 †H i †4ïŒ1 †W i †4 ãæºããïŒ( H i , W i ) ãšããŠåäžã®çµã¯è€æ°åçŸããªãïŒ Output çµµã宿ãããããã«ã¹ã¿ã³ããæŒããªããã°ãªããªãæå°ã®åæ°ã 1 è¡ã«åºåããïŒ Sample Input 1 2 4 4 1 1 RRRR RRGR RBRR RRRR Sample Output 1 3 Sample Input 2 1 2 3 RRGG BRGG BRRR BRRR Sample Output 2 5
| 38,650
|
Score : 900 points Problem Statement Takahashi has an N \times M grid, with N horizontal rows and M vertical columns. Determine if we can place A 1 \times 2 tiles ( 1 vertical, 2 horizontal) and B 2 \times 1 tiles ( 2 vertical, 1 horizontal) satisfying the following conditions, and construct one arrangement of the tiles if it is possible: All the tiles must be placed on the grid. Tiles must not stick out of the grid, and no two different tiles may intersect. Neither the grid nor the tiles may be rotated. Every tile completely covers exactly two squares. Constraints 1 \leq N,M \leq 1000 0 \leq A,B \leq 500000 N , M , A and B are integers. Input Input is given from Standard Input in the following format: N M A B Output If it is impossible to place all the tiles, print NO . Otherwise, print the following: YES c_{11}...c_{1M} : c_{N1}...c_{NM} Here, c_{ij} must be one of the following characters: . , < , > , ^ and v . Represent an arrangement by using each of these characters as follows: When c_{ij} is . , it indicates that the square at the i -th row and j -th column is empty; When c_{ij} is < , it indicates that the square at the i -th row and j -th column is covered by the left half of a 1 \times 2 tile; When c_{ij} is > , it indicates that the square at the i -th row and j -th column is covered by the right half of a 1 \times 2 tile; When c_{ij} is ^ , it indicates that the square at the i -th row and j -th column is covered by the top half of a 2 \times 1 tile; When c_{ij} is v , it indicates that the square at the i -th row and j -th column is covered by the bottom half of a 2 \times 1 tile. Sample Input 1 3 4 4 2 Sample Output 1 YES <><> ^<>^ v<>v This is one example of a way to place four 1 \times 2 tiles and three 2 \times 1 tiles on a 3 \times 4 grid. Sample Input 2 4 5 5 3 Sample Output 2 YES <>..^ ^.<>v v<>.^ <><>v Sample Input 3 7 9 20 20 Sample Output 3 NO
| 38,651
|
Range Write a program which reads three integers a , b and c , and prints "Yes" if a < b < c , otherwise "No". Input Three integers a , b and c separated by a single space are given in a line. Output Print "Yes" or "No" in a line. Constraints 0 †a , b , c †100 Sample Input 1 1 3 8 Sample Output 1 Yes Sample Input 2 3 8 1 Sample Output 2 No
| 38,652
|
Ninja Map Intersections of Crossing Path City are aligned to a grid. There are $N$ east-west streets which are numbered from 1 to $N$, from north to south. There are also $N$ north-south streets which are numbered from 1 to $N$, from west to east. Every pair of east-west and north-south streets has an intersection; therefore there are $N^2$ intersections which are numbered from 1 to $N^2$. Surprisingly, all of the residents in the city are Ninja. To prevent outsiders from knowing their locations, the numbering of intersections is shuffled. You know the connections between the intersections and try to deduce their positions from the information. If there are more than one possible set of positions, you can output any of them. Input The input consists of a single test case formatted as follows. $N$ $a_1$ $b_1$ ... $a_{2N^2â2N}$ $\;$ $b_{2N^2â2N}$ The first line consists of an integer $N$ ($2 \leq N \leq 100$). The following $2N^2 - 2N$ lines represent connections between intersections. The ($i+1$)-th line consists of two integers $a_i$ and $b_i$ ($1 \leq a_i, b_i \leq N^2, a_i \ne b_i$), which represent that the $a_i$-th and $b_i$-th intersections are adjacent. More precisely, let's denote by ($r, c$) the intersection of the $r$-th east-west street and the $c$-th north-south street. If the intersection number of ($r,c$) is $a_i$ for some $r$ and $c$, then the intersection number of either ($r-1, c$), ($r+1, c$), ($r, c-1$) or ($r, c+1$) must be $b_i$. All inputs of adjacencies are different, i.e., ($a_i, b_i$) $\ne$ ($a_j, b_j$) and ($a_i, b_i$) $\ne$ ($b_j, a_j$) for all $1 \leq i < j \leq 2N^2-2N$. This means that you are given information of all adjacencies on the grid. The input is guaranteed to describe a valid map. Output Print a possible set of positions of the intersections. More precisely, the output consists of $N$ lines each of which has space-separated $N$ integers. The $c$-th integer of the $r$-th line should be the intersection number of ($r, c$). If there are more than one possible set of positions, you can output any of them. Sample Input 1 3 1 2 4 7 8 6 2 3 8 9 5 3 4 6 5 6 7 8 1 4 2 6 5 9 Output for Sample Input 1 7 4 1 8 6 2 9 5 3 The following output will also be accepted. 1 2 3 4 6 5 7 8 9 Sample Input 2 4 12 1 3 8 10 7 13 14 8 2 9 12 6 14 11 3 3 13 1 10 11 15 4 15 4 9 14 10 5 7 2 5 6 1 14 5 16 11 15 6 15 13 9 6 16 4 13 2 Output for Sample Input 2 8 2 5 7 3 13 14 10 11 15 6 1 16 4 9 12
| 38,653
|
Score : 1000 points Problem Statement Takahashi and Snuke came up with a game that uses a number sequence, as follows: Prepare a sequence of length M consisting of integers between 0 and 2^N-1 (inclusive): a = a_1, a_2, \ldots, a_M . Snuke first does the operation below as many times as he likes: Choose a positive integer d , and for each i (1 \leq i \leq M) , in binary, set the d -th least significant bit of a_i to 0 . (Here the least significant bit is considered the 1 -st least significant bit.) After Snuke finishes doing operations, Takahashi tries to sort a in ascending order by doing the operation below some number of times. Here a is said to be in ascending order when a_i \leq a_{i + 1} for all i (1 \leq i \leq M - 1) . Choose two adjacent elements of a : a_i and a_{i + 1} . If, in binary, these numbers differ in exactly one bit, swap a_i and a_{i + 1} . There are 2^{NM} different sequences of length M consisting of integers between 0 and 2^N-1 that can be used in the game. How many among them have the following property: if used in the game, there is always a way for Takahashi to sort the sequence in ascending order regardless of Snuke's operations? Find the count modulo (10^9 + 7) . Constraints All values in input are integers. 1 \leq N \leq 5000 2 \leq M \leq 5000 Input Input is given from Standard Input in the following format: N M Output Print the number, modulo (10^9 + 7) , of sequences with the property: if used in the game, there is always a way for Takahashi to sort the sequence in ascending order regardless of Snuke's operations. Sample Input 1 2 5 Sample Output 1 352 Consider the case a = 1, 3, 1, 3, 1 for example. When the least significant bit of each element of a is set to 0 , a = 0, 2, 0, 2, 0 ; When the second least significant bit of each element of a is set to 0 , a = 1, 1, 1, 1, 1 ; When the least two significant bits of each element of a are set to 0 , a = 0, 0, 0, 0, 0 . In all of the cases above and the case when Snuke does no operation to change a , we can sort the sequence by repeatedly swapping adjacent elements that differ in exactly one bit. Thus, this sequence has the property: if used in the game, there is always a way for Takahashi to sort the sequence in ascending order regardless of Snuke's operations. Sample Input 2 2020 530 Sample Output 2 823277409
| 38,654
|
Problem I: FIMO sequence Your task is to simulate the sequence defined in the remaining part of the problem description. This sequence is empty at first. i -th element of this sequence is expressed as a i . The first element of this sequence is a 1 if the sequence is not empty. The operation is given by integer from 0 to 9. The operation is described below. 0: This query is given with some integer x . If this query is given, the integer x is inserted into the sequence. If the sequence is empty, a 1 = x . If the sequence has n elements, a n+1 = x . Same integer will not appear more than once as x . 1: If this query is given, one element in the sequence is deleted. The value in the middle of the sequence is deleted. If the sequence has n elements and n is even, a n/2 will be deleted. If n is odd, a ân/2â will be deleted. This query is not given when the sequence is empty. Assume that the sequence has a 1 =1, a 2 =2, a 3 =3, a 4 =4 and a 5 =5. In this case, a 3 will be deleted. After deletion, the sequence will be a 1 =1, a 2 =2, a 3 =4, a 4 =5. Assume that the sequence has a 1 =1, a 2 =2, a 3 =3 and a 4 =4, In this case, a 2 will be deleted. After deletion, the sequence will be a 1 =1, a 2 =3, a 3 =4. 2: The first half of the sequence is defined by the index from 1 to â n /2â . If this query is given, you should compute the minimum element of the first half of the sequence. This query is not given when the sequence is empty. Let me show an example. Assume that the sequence is {6,2,3,4,5,1,8}. In this case, the minimum element of the first half of the sequence, {6,2,3,4} is 2. 3: The latter half of the sequence is elements that do not belong to the first half of the sequence. If this query is given, you should compute the minimum element of the latter half of the sequence. This query is not given when the sequence is empty. Let me show an example. Assume that the sequence is {6,2,3,4,5,1,8}. In this case the answer for this query is 1 from {5,1,8}. 4: This query is given with an integer i . Assume that deletion is repeated until the sequence is empty. Some elements in the first half of the sequence will become the answer for query 2. You should compute the i -th minimum element from the answers. This query is not given when the sequence is empty. You can assume that i -th minimum element exists when this query is given. Let me show an example. Assume that deletion will be repeated to the sequence {6,2,3,4,5,1,8}. {6,2,3,4,5,1,8} The minimum element in the first half of the sequence is 2. {6,2,3,5,1,8} The minimum element in the first half of the sequence is 2. {6,2,5,1,8} The minimum element in the first half of the sequence is 2. {6,2,1,8} The minimum element in the first half of the sequence is 2. {6,1,8} The minimum element in the first half of the sequence is 1. {6,8} The minimum element in the first half of the sequence is 6. {8} The minimum element in the first half of the sequence is 8. {} The first half of the sequence is empty. For the initial state, {6,2,3,4} is the first half of the sequence. 2 and 6 become the minimum element of the first half of the sequence. In this example, the 1-st minimum element is 2 and the 2-nd is 6. 5: This query is given with an integer i . Assume that deletion is repeated until the sequence is empty. Some elements in the latter half of the sequence will become the answer for query 3. You should compute the i -th minimum element from the answers. This query is not given when the sequence is empty. You can assume that i -th minimum element exists when this query is given. Let me show an example. Assume that deletion will be repeated to the sequence {6,2,3,4,5,1,8}. {6,2,3,4,5,1,8} The minimum elemets in the latter half of the sequence is 1. {6,2,3,5,1,8} The minimum elemets in the latter half of the sequence is 1. {6,2,5,1,8} The minimum elemets in the latter half of the sequence is 1. {6,2,1,8} The minimum elemets in the latter half of the sequence is 1. {6,1,8} The minimum elemets in the latter half of the sequence is 8. {6,8} The minimum elemets in the latter half of the sequence is 8. {8} The latter half of the sequence is empty. {} The latter half of the sequence is empty. For the initial state, {5,1,8} is the latter half of the sequence. 1 and 8 becomes the minimum element of the latter half ot the sequence. In this example, the 1-st minimum element is 1 and the 2-nd is 8. 6: If this query is given, you should compute the maximum element of the first half of the sequence. This query is not given when the sequence is empty. Let me show an example. Assume that the sequence is {1,3,2,5,9,6,7}. In this case, the maximum element of the first half of the sequence,{1,3,2,5}, is 5. 7: If this query is given, you should compute the maximum element of the latter half of the sequence. This query is not given when the sequence is empty. Let me show an example. Assume that the sequence is {1,3,2,5,9,6,7}. In this case, the maximum element of the latter half of the sequence,{9,6,7}, is 9. 8: This query is given with an integer i . Assume that deletion is repeated until the sequence is empty. Some elements in the first half of the sequence will become the answer for query 6. You should compute the i -th maximum element from the answers. This query is not given when the sequence is empty. You can assume that i -th maximum elements exists when this query is given. Let me show an example. Assume that deletion will be repeated to the sequence {1,3,2,5,9,6,7}. {1,3,2,5,9,6,7} The maximum element in the first half of the sequence is 5. {1,3,2,9,6,7} The maximum element in the first half of the sequence is 3. {1,3,9,6,7} The maximum element in the first half of the sequence is 9. {1,3,6,7} The maximum element in the first half of the sequence is 3. {1,6,7} The maximum element in the first half of the sequence is 6. {1,7} The maximum element in the first half of the sequence is 1. {7} The maximum element in the first half of the sequence is 7. {} The first half of the sequence is empty. For the initial state, {1,3,2,5} is the first half of the sequence. 1,3 and 5 becomes the maximum element of the first half of the sequence. In this example, the 1-st maximum element is 5, the 2-nd is 3 and the 3-rd is 1. 9: This query is given with an integer i . Assume that deletion is repeated until the sequence is empty. Some elements in the latter half of the sequence will become the answer for query 7. You should compute the i -th maximum element from the answers. This query is not given when the sequence is empty. You can assume that i -th maximum elements exists when this query is given. Let me show an example. Assume that deletion will be repeated to the sequence {1,3,2,5,9,6,7}. {1,3,2,5,9,6,7} The maximum element in the latter half of the sequence is 9. {1,3,2,9,6,7} The maximum element in the latter half of the sequence is 9. {1,3,9,6,7} The maximum element in the latter half of the sequence is 7. {1,3,6,7} The maximum element in the latter half of the sequence is 7. {1,6,7} The maximum element in the latter half of the sequence is 7. {1,7} The maximum element in the latter half of the sequence is 7. {7} The latter half of the sequence is empty. {} The latter half of the sequence is empty. For the initial state, {9,6,7} is the latter half of the sequence. 7 and 9 becomes the maximum element of the latter half of the sequence. In this example, the 1-st maximum element is 9 and the 2-nd is 7. Input Input consists of multiple test cases. The first line is the number of queries. Following q lines are queries. q query 0 ... query i ... qurey_ q-1 The sum of the number of queries in the input data is less than 200001. If query i = 0, 4, 5, 8, and 9 are consists of pair of integers. Other queries are given with a single integer. You can assume that the length of the sequence doesn't exceed 20000. Output If the query is 0, you don't output any numbers. If the query is 1, you should output the deleted number. For other queries, you should output the computed value. For each case, you should output "end" (without quates) after you process all queries. Sample input 5 0 1 0 2 0 3 0 4 1 6 0 1 0 2 0 3 0 4 0 5 1 31 0 6 0 2 0 3 0 4 0 5 0 1 0 8 4 1 4 2 5 1 5 2 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 1 32 0 1 0 3 0 2 0 5 0 9 0 6 0 7 8 1 8 2 8 3 9 1 9 2 6 7 1 6 7 1 6 7 1 6 7 1 6 7 1 6 7 1 6 1 0 Sample output 2 end 3 end 2 6 1 8 2 1 4 2 1 3 2 1 5 2 1 2 1 8 1 6 8 6 8 8 end 5 3 1 9 7 5 9 5 3 9 2 9 7 9 3 7 3 6 7 6 1 7 1 7 7 end
| 38,655
|
Depth First Search Depth-first search (DFS) follows the strategy to search âdeeperâ in the graph whenever possible. In DFS, edges are recursively explored out of the most recently discovered vertex $v$ that still has unexplored edges leaving it. When all of $v$'s edges have been explored, the search âbacktracksâ to explore edges leaving the vertex from which $v$ was discovered. This process continues until all the vertices that are reachable from the original source vertex have been discovered. If any undiscovered vertices remain, then one of them is selected as a new source and the search is repeated from that source. DFS timestamps each vertex as follows: $d[v]$ records when $v$ is first discovered. $f[v]$ records when the search finishes examining $v$âs adjacency list. Write a program which reads a directed graph $G = (V, E)$ and demonstrates DFS on the graph based on the following rules: $G$ is given in an adjacency-list. Vertices are identified by IDs $1, 2,... n$ respectively. IDs in the adjacency list are arranged in ascending order. The program should report the discover time and the finish time for each vertex. When there are several candidates to visit during DFS, the algorithm should select the vertex with the smallest ID. The timestamp starts with 1. Input In the first line, an integer $n$ denoting the number of vertices of $G$ is given. In the next $n$ lines, adjacency lists of $u$ are given in the following format: $u$ $k$ $v_1$ $v_2$ ... $v_k$ $u$ is ID of the vertex and $k$ denotes its degree. $v_i$ are IDs of vertices adjacent to $u$. Output For each vertex, print $id$, $d$ and $f$ separated by a space character in a line. $id$ is ID of the vertex, $d$ and $f$ is the discover time and the finish time respectively. Print in order of vertex IDs. Constraints $1 \leq n \leq 100$ Sample Input 1 4 1 1 2 2 1 4 3 0 4 1 3 Sample Output 1 1 1 8 2 2 7 3 4 5 4 3 6 Sample Input 2 6 1 2 2 3 2 2 3 4 3 1 5 4 1 6 5 1 6 6 0 Sample Output 2 1 1 12 2 2 11 3 3 8 4 9 10 5 4 7 6 5 6 This is example for Sample Input 2 (discover/finish) Reference Introduction to Algorithms, Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. The MIT Press.
| 38,656
|
ããããã 仲è¯ã 5 人çµã§ããããããããããšã«ãªããŸãããããããããšã¯ãã°ãŒããã§ããããŒãšãã 3ã€ã®æããããã°ãŒãšãã§ãã®åè² ãªãã°ãŒããåã¡ãã»ãã§ãããè² ããããã§ããšããŒãªãããã§ãããåã¡ãã»ããŒããè² ãããããŒãšã°ãŒãªãããŒããåã¡ãã»ã°ãŒããè² ãããšããã«ãŒã«ã§ããå
šå¡ãåãæããŸãã¯ã°ãŒããã§ããããŒå
šãŠãåºãå Žåã¯ããããããšãªããŸãã 5 人ã®ãããããã®æãå
¥åãšããããããã®äººã®åæãåºåããããã°ã©ã ãäœæããŠãã ããããããããã®æã¯ãã°ãŒã¯ 1ããã§ã㯠2ãããŒã¯ 3 ã®æ°åã§è¡šããŸããåæã¯ãåã¡ãã 1ããè² ããã 2ããããããã 3 ã®æ°åã§è¡šããå
¥åé ã«åŸã£ãŠåºåããŸãã Input è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸãã åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã h 1 h 2 h 3 h 4 h 5 i è¡ç®ã« i 人ç®ã®æ h i (1, 2 ãŸã㯠3) ãäžããããŸãã ããŒã¿ã»ããã®æ°ã¯ 200 ãè¶
ããŸããã Output å
¥åããŒã¿ã»ããããšã«ã5 人ã®åæãåºåããŸãã i è¡ç®ã« i 人ç®ã®åæ(1, 2 ãŸã㯠3) ãåºåããŠãã ããã Sample Input 1 2 3 2 1 1 2 2 2 1 0 Output for the Sample Input 3 3 3 3 3 1 2 2 2 1
| 38,657
|
Score : 200 points Problem Statement We have a string S of length N consisting of uppercase English letters. How many times does ABC occur in S as contiguous subsequences (see Sample Inputs and Outputs)? Constraints 3 \leq N \leq 50 S consists of uppercase English letters. Input Input is given from Standard Input in the following format: N S Output Print number of occurrences of ABC in S as contiguous subsequences. Sample Input 1 10 ZABCDBABCQ Sample Output 1 2 Two contiguous subsequences of S are equal to ABC : the 2 -nd through 4 -th characters, and the 7 -th through 9 -th characters. Sample Input 2 19 THREEONEFOURONEFIVE Sample Output 2 0 No contiguous subsequences of S are equal to ABC . Sample Input 3 33 ABCCABCBABCCABACBCBBABCBCBCBCABCB Sample Output 3 5
| 38,659
|
äžæ¥ä¹è»åž æåœã«äœã倧åŠçDæ°ã¯ïŒåœæ°çã®ã¿ãªã¹ãAæ°ã®å€§ãã¡ã³ã§ïŒãã®å€éœå¿ã§è¡ãããã©ã€ãã«è¡ãããšèããŠããïŒ ãããïŒDæ°ã¯èŸºå¢ã®å°ã«äœãã§ããããïŒäº€éè²»ããããããšããšãŠãäžå®ã ã£ãïŒ ãããªãšã圌ã¯ïŒJAGãšããçµç¹ããå®äŸ¡ã§è²©å£²ãããŠããã1Dayãã¹ããŒããã®ååšãç¥ã£ãïŒ JAG (Journey Administrative Group) ã¯ïŒDæ°ãäœãåœã«ååšããããã€ãã®ééäŒç€Ÿãçµ±æ¬ããçµç¹ã§ããïŒ JAGã¯ïŒå
šåœã«è€æ°ã®é§
ãæã¡ïŒãããã®éãçµã¶è·¯ç·ãæŽåããŠããïŒ åè·¯ç·ã¯ïŒJAGã«æå±ããäŒç€Ÿã®å
ãããã1瀟ã«ãã管çãããŠããïŒ2é§
éãéäžé§
ç¡ãã§åæ¹åã«çµãã§ããïŒ ãŸãåè·¯ç·ã«ã¯ïŒå©çšããéã®éè³ãšæèŠæéãå®ãŸã£ãŠãã (ãããã¯ã©ã¡ãåãã«ç§»åããå Žåã§ãçãã)ïŒ JAGã®ãã€ã€ã¯ã·ã³ãã«ã«äœãããŠããïŒåè»ã¯æ¯æ0åã«é§
ã«çºçããïŒ ãŸãJAGã®åé§
ã¯ïŒæ¥µããŠè³¢ããã¶ã€ã³ãããŠããïŒè·¯ç·ã®ä¹ãæãã«ãããæéã¯ç¡èŠããããšãã§ããïŒ ç§»åã«å¿
èŠãªäº€éè²»ã¯éè³ã®åçŽãªåèšãšãªã. 1Dayãã¹ããŒãã¯ïŒJAGãæšä»ã®çµå¶é£ãè±ããããã«è²©å£²ãå§ããïŒä¹ãæŸé¡ãã¹ããŒãã§ããïŒ JAGã¯ïŒäœçš®é¡ãã®1Dayãã¹ããŒãã販売ããŠããïŒ åãã¹ããŒãã¯ïŒJAGãæå®ããè²©å£²äŸ¡æ Œã§è³Œå
¥ããããšãã§ããïŒ ãŸããã¹ããŒãã«ã¯ïŒJAGã«æå±ããäŒç€Ÿåãããã€ãæžãããŠããïŒãããã®äŒç€Ÿã管çããå
šãŠã®è·¯ç·ã1æ¥é (è¿œå æéç¡ãã§) ä¹ãæŸé¡ã«ãªãïŒ ãã¹ããŒãã¯ïŒããã€ã§ã賌å
¥ããããšãã§ãïŒè€æ°ã®ãã¹ããŒãã䜵çšããããšãã§ããïŒ ãã ãïŒãã¹ããŒãã«æžãããŠããªãäŒç€Ÿã®ç®¡çè·¯ç·ãéãå ŽåïŒãã®è·¯ç·ã®éè³ã¯éåžžéãå¿
èŠãšãªãïŒ Dæ°ã¯ïŒ1Dayãã¹ããŒããããŸã䜿ãïŒãªãã¹ããéããããã©ã€ãäŒå ŽãŸã§è¡ããããšèããŠããïŒ ãŸãïŒåœŒã¯å®¿æ³ã§äœèšã«ãéããããã®ãå«ãªã®ã§ïŒãã®åœã®1æ¥ã§ãã$H$æé以äžã§ã©ã€ãäŒå ŽãŸã§èŸ¿ãçããããšèããŠããïŒ ãããïŒåœŒã¯èšç®ãåŸæã§ã¯ãªãããïŒåã倧åŠã®å人ã§ããã°ã©ãã³ã°ãåŸæãªããªãã«å©ããæ±ããŠæ¥ãïŒ å°ã£ãŠããDæ°ã®ããã«ïŒæ¬¡ã®ãããªããã°ã©ã ãæžããŠããããïŒ JAGã®è·¯ç·æ
å ±ãš1Dayãã¹ããŒãã®æ
å ±ãäžãããããšãïŒDæ°ã®æå¯ãé§
ããã©ã€ãäŒå Žã®æå¯ãé§
ãžïŒ$H$æé以äžã§ç§»åããããã®æå°è²»çš (ãã¹ããŒã代ãšéè³ã®åèšã®æå°) ãæ±ããããã°ã©ã ãäœæããïŒ $H$æé以äžã§å°éã§ããªãå ŽåãïŒã©ã€ãäŒå Žãžå°éããçµè·¯ããªãå Žåã¯ïŒ-1ãåºåããïŒ Input å
¥åã¯ïŒè€æ°ã®ããŒã¿ã»ããããæ§æããïŒ1ã€ã®å
¥åã«å«ãŸããããŒã¿ã»ããã®æ°ã¯150以äžã§ããïŒ åããŒã¿ã»ããã®åœ¢åŒã¯æ¬¡ã®éãã§ããïŒ $N$ $M$ $H$ $K$ $a_1$ $b_1$ $c_1$ $h_1$ $r_1$ ... $a_M$ $b_M$ $c_M$ $h_M$ $r_M$ $S$ $T$ $P$ $l_1$ $d_1$ $k_{1,1}$ ... $k_{1,l_1}$ ... $l_P$ $d_P$ $k_{P,1}$ ... $k_{P,l_P}$ å
¥åã¯å
šãп޿°å€ã§äžããããïŒ ãŸãïŒJAGã®è·¯ç·æ
å ±ãäžããããïŒ $N$ ($2 \le N \le 100$) ã¯é§
ã®æ°ïŒ$M$ ($1 \le M \le 500$) ã¯è·¯ç·ã®æ°ïŒ$H$ ($1 \le H \le 24$) ã¯1æ¥ã®æéïŒ$K$ ($1 \le K \le 8$) ã¯JAGã«æå±ããäŒç€Ÿæ°ã衚ãïŒ åé§
ã«ã¯ïŒ$1, 2, \ldots, N$ ãšçªå·ãã€ããŠããïŒ ãŸãïŒåäŒç€Ÿã«ã¯ïŒ$1, 2, \ldots, K$ ãšçªå·ãã€ããŠããïŒ ç¶ã㊠$M$ è¡ã«ããã£ãŠè·¯ç·æ
å ±ãå
¥åãããïŒ $a_i$ ãš $b_i$ ($1 \le a_i \lt b_i \le N$) ã $i$ çªç®ã®è·¯ç·ãã€ãªãã§ãã2ã€ã®é§
ã衚ãïŒ $c_i$ ($1 \le c_i \le 10{,}000$) 㯠$i$ çªç®ã®è·¯ç·ã®éè³ïŒ$h_i$ ($1 \le h_i \le H$) ã¯è·¯ç·ã®æèŠæéïŒ$r_i$ ($1 \le r_i \le K$) ã¯è·¯ç·ã管çããŠããäŒç€Ÿã衚ãïŒ ãã2ã€ã®é§
ãçµã¶è·¯ç·ã2æ¬ä»¥äžååšããããšã¯ãªãïŒ æ¬¡ã®è¡ã§ïŒDæ°ã®æå¯ãé§
$S$ ãšïŒAæ°ã®ã©ã€ãäŒå Žã®æå¯ãé§
$T$ ãäžãããã ($1 \le S, T \le N$)ïŒ $S$ ãš $T$ ã¯ç°ãªãå€ã§ããïŒ æ¬¡ã«ïŒ1Dayãã¹ããŒãã®æ
å ±ãäžããããïŒ $P$ ($0 \le P \le 2^K - 1$) ã¯ïŒ1Dayãã¹ããŒãã®çš®é¡æ°ã衚ããŠããïŒ ç¶ã㊠$P$ è¡ã«ããã£ãŠïŒ1Dayãã¹ããŒãã®æ
å ±ãå
¥åãããïŒ $l_j$ ($1 \le l_j \le K$) ãš $d_j$ ($1 \le d_j \le 10{,}000$) ã¯ïŒãããã $j$ çªç®ã®1Dayãã¹ããŒãã«æžãããŠããäŒç€Ÿæ°ãšãã¹ããŒãã®æéã衚ãïŒ åãè¡ã«ïŒ$j$ çªç®ã®ãã¹ããŒãã«æžããã $l_j$ åã®äŒç€Ÿçªå· $k_{j, 1}, k_{j, 2}, \ldots, k_{j, l_j}$ ($1 \le k_{j, 1} \lt k_{j, 2} \lt \cdots \lt k_{j, l_j} \le K$) ãäžããããïŒ åãäŒç€Ÿã®çµã¿åãããããªã1Dayãã¹ããŒããè€æ°å
¥åãããããšã¯ãªãïŒ å
¥åã®çµããã¯ïŒ$N=M=H=K=0$ ã®è¡ã«ãã£ãŠè¡šãããïŒ ãã®ããŒã¿ã¯åŠçãè¡ã£ãŠã¯ãªããªãïŒ Output åããŒã¿ã»ããã«å¯ŸããŠïŒèšç®çµæã1è¡ã§åºåããïŒ ããªãã¡ïŒDæ°ã®æå¯ãé§
ããã©ã€ãäŒå Žã®æå¯ãé§
ãžã®çµè·¯ãååšã $H$ æé以å
ã«å°éã§ããã®ã§ããã°ïŒãã®ããã®æå°ã®æéãïŒèŸ¿ãçããªãã®ã§ããã°-1ãåºåããïŒ Sample Input 3 3 3 2 1 2 3 1 1 1 3 8 1 1 2 3 3 2 2 1 3 0 3 3 2 2 1 2 3 1 1 1 3 8 1 1 2 3 3 2 2 1 3 0 6 4 3 2 1 2 3 1 1 1 3 8 1 1 4 6 3 2 2 5 6 7 2 2 1 6 0 3 3 3 2 1 2 3 1 1 1 3 8 1 1 2 3 3 2 2 1 3 2 2 6 1 2 1 2 2 3 3 2 2 1 2 3 1 1 1 3 8 1 1 2 3 3 2 2 1 3 2 2 6 1 2 1 2 2 3 2 2 2 1 2 3 1 1 2 3 3 2 2 1 3 2 2 6 1 2 1 2 2 5 4 20 4 2 4 100 5 1 1 4 100 5 3 1 5 100 5 4 3 5 100 5 2 3 2 3 2 80 1 2 2 60 1 3 2 40 2 3 0 0 0 0 Output for Sample Input 6 8 -1 5 6 -1 200
| 38,660
|
Ambiguous Encoding A friend of yours is designing an encoding scheme of a set of characters into a set of variable length bit sequences. You are asked to check whether the encoding is ambiguous or not. In an encoding scheme, characters are given distinct bit sequences of possibly different lengths as their codes. A character sequence is encoded into a bit sequence which is the concatenation of the codes of the characters in the string in the order of their appearances. An encoding scheme is said to be ambiguous if there exist two different character sequences encoded into exactly the same bit sequence. Such a bit sequence is called an âambiguous binary sequenceâ. For example, encoding characters â A â, â B â, and â C â to 0 , 01 and 10 , respectively, is ambiguous. This scheme encodes two different character strings â AC â and â BA â into the same bit sequence 010 . Input The input consists of a single test case of the following format. $n$ $w_1$ . . . $w_n$ Here, $n$ is the size of the set of characters to encode ($1 \leq n \leq 1000$). The $i$-th line of the following $n$ lines, $w_i$, gives the bit sequence for the $i$-th character as a non-empty sequence of at most 16 binary digits, 0 or 1. Note that different characters are given different codes, that is, $w_i \ne w_j$ for $i \ne j$. Output If the given encoding is ambiguous, print in a line the number of bits in the shortest ambiguous binary sequence. Output zero, otherwise. Sample Input 1 3 0 01 10 Sample Output 1 3 Sample Input 2 3 00 01 1 Sample Output 2 0 Sample Input 3 3 00 10 1 Sample Output 3 0 Sample Input 4 10 1001 1011 01000 00011 01011 1010 00100 10011 11110 0110 Sample Output 4 13 Sample Input 5 3 1101 1 10 Sample Output 5 4
| 38,661
|
Score : 2300 points Problem Statement You are given a set S of strings consisting of 0 and 1 , and an integer K . Find the longest string that is a subsequence of K or more different strings in S . If there are multiple strings that satisfy this condition, find the lexicographically smallest such string. Here, S is given in the format below: The data directly given to you is an integer N , and N+1 strings X_0,X_1,...,X_N . For every i (0\leq i\leq N) , the length of X_i is 2^i . For every pair of two integers (i,j) (0\leq i\leq N,0\leq j\leq 2^i-1) , the j -th character of X_i is 1 if and only if the binary representation of j with i digits (possibly with leading zeros) belongs to S . Here, the first and last characters in X_i are called the 0 -th and (2^i-1) -th characters, respectively. S does not contain a string with length N+1 or more. Here, a string A is a subsequence of another string B when there exists a sequence of integers t_1 < ... < t_{|A|} such that, for every i (1\leq i\leq |A|) , the i -th character of A and the t_i -th character of B is equal. Constraints 0 \leq N \leq 20 X_i(0\leq i\leq N) is a string of length 2^i consisting of 0 and 1 . 1 \leq K \leq |S| K is an integer. Input Input is given from Standard Input in the following format: N K X_0 : X_N Output Print the lexicographically smallest string among the longest strings that are subsequences of K or more different strings in S . Sample Input 1 3 4 1 01 1011 01001110 Sample Output 1 10 The following strings belong to S : the empty string, 1 , 00 , 10 , 11 , 001 , 100 , 101 and 110 . The lexicographically smallest string among the longest strings that are subsequences of four or more of them is 10 . Sample Input 2 4 6 1 01 1011 10111010 1101110011111101 Sample Output 2 100 Sample Input 3 2 5 0 11 1111 Sample Output 3 The answer is the empty string.
| 38,662
|
Problem A: Clock Problem ãã£ã¡ãåã¯ãæ°ã«å
¥ãã®æèšãæã£ãŠãããããæ¥æèšã®é·éãåããŠããŸããã©ãããžãªãããŠããŸã£ãããããããã£ã¡ãåã¯ãã®æèšã䜿ãç¶ãããããçéã ãã§æå»ãèªã¿åããããšèããŠããã çéã®æ
å ± Ξ ã«å¯Ÿããæå»(æ h ãå m )ãåºåãããæèšã¯ããããã¢ããã°æèšã§ã1ãã12ã®æ°ãçééã«æèšåãã«æé ã«äžŠãã§ãããã®ã§ããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã Ξ 1è¡ã«çéã®è§åºŠ Ξ ãè¡šãæŽæ°ãåºŠæ°æ³(degree)ã§äžããããã çéãæãæ¹åã¯ã12æãæãæ¹åã0床ãšãããšããæèšåã㫠Ξ 床å転ããæ¹åã§ããã Constraints 0 †Ξ †359 Output çéãäžããããè§åºŠããšãæã®æå»ã h m ã®åœ¢ã§1è¡ã«åºåããã æå»ã«ååååŸã®åºå¥ã¯ãªããã0 †h †11ãšããã Sample Input 1 0 Sample Output 1 0 0 Sample Input 2 45 Sample Output 2 1 30 Sample Input 3 100 Sample Output 3 3 20
| 38,663
|
ããããŒã« æä¹
ïŒïŒ1862ïŒå¹ŽãäŒæŽ¥ã®æ®¿æ§ã京éœå®è·è·ãåœããããŸããã京éœå®è·è·ãšã¯æ²»å®ã®æªåãã广«ã®äº¬éœãå®ã倧åãªåœ¹ç®ã§ããå¹åºãä»ã®è©ãšåæ
ããŠåžäžãããããŒã«ããªããã°ãªããŸããããšãããããåæ
ã«ãŒããæ±ºããæ®µã«ãªã£ãŠãå®¶è£ã®äžã§ãæåãªé åºè
ã®å€èãã以äžã®ãããªæ³šæãã€ããŸããã 倧å€ãªããšã«ãªããŸãããæ®¿æ§ãšããã©ããã®å®¶è£ã®èšãåãç¡èŠããããã«ã¯ãããŸãããåæ
ã«ãŒãã®éžæã«ãã£ãŠã¯ããæŠå£«ã®é¢ç®ãç«ããªãããšããããšã«ãªã£ãŠããŸããŸãã ãšããããšã§ãã¹ã¿ãŒãå°ç¹ããŽãŒã«å°ç¹ã亀差ç¹ã®æ
å ±ãå
¥åãšããŠãäžã®äžã€ã®æ¡ä»¶ãæºãããã©ãããå€å®ããããã°ã©ã ãäœã£ãŠã殿æ§ã«ç®äžããŠãã ããã ã¹ã¿ãŒãå°ç¹ã 1ããŽãŒã«å°ç¹ã2ããã®ä»ã®äº€å·®ç¹ã 3 以äžã®æŽæ°ã§è¡šããŸãã1ã€ã®éè·¯ã¯ããã®éãçµã¶1çµã®äº€å·®ç¹çªå·ã§è¡šããŸãããªãã亀差ç¹ã®æ°ã¯ 100 以äžãšããå
šãŠã®äº€å·®ç¹ããã¹ã¿ãŒãå°ç¹ããã³ãŽãŒã«å°ç¹ãžã®çµè·¯ãããããäžã€ä»¥äžãããã®ãšããŸãã å
¥å è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã a 1 b 1 a 2 b 2 ïŒ ïŒ 0 0 åè¡ã®ïŒã€ã®æŽæ°ã¯ãäº€å·®ç¹ a i ãšäº€å·®ç¹ b i ãšãã€ãªãéè·¯ãååšããããšã瀺ããŸãã a i ãš b i ããšãã« 0 ã®ãšãäº€å·®ç¹æ
å ±ã®å
¥åã®çµããã瀺ããŸãã ããŒã¿ã»ããã®æ°ã¯50ãè¶
ããŸããã åºå åããŒã¿ã»ããã«å¯ŸããŠãæŠå£«ã®é¢ç®ãç«ã€å ŽåïŒäžã€ã®æ¡ä»¶ãæºããå ŽåïŒOKããã以å€ã®å ŽåïŒäžã€ã®æ¡ä»¶ãæºãããªãå ŽåïŒNG ãšïŒè¡ã«åºåããŠãã ããã Sample Input 1 3 3 4 3 5 3 6 4 6 4 7 4 7 5 6 6 7 5 8 5 8 6 8 6 9 7 9 8 9 9 2 0 0 1 3 3 4 3 4 4 2 0 0 Output for the Sample Input OK NG
| 38,664
|
Score : 600 points Problem Statement Given is an integer N . Find the minimum possible positive integer k such that (1+2+\cdots+k) is a multiple of N . It can be proved that such a positive integer k always exists. Constraints 1 \leq N \leq 10^{15} All values in input are integers. Input Input is given from Standard Input in the following format: N Output Print the answer in a line. Sample Input 1 11 Sample Output 1 10 1+2+\cdots+10=55 holds and 55 is indeed a multple of N=11 . There are no positive integers k \leq 9 that satisfy the condition, so the answer is k = 10 . Sample Input 2 20200920 Sample Output 2 1100144
| 38,665
|
ãã¿ã ãã II 瞊ç·ã n æ¬ã®ãã¿ã ããããããŸãããã®ãã¿ã ããã¯ä»¥äžã®æ¡ä»¶ãæºãããŠããŸãã æšªç·ã¯ç暪ã«åŒããŸããæãã«åŒãããšã¯ãããŸããã æšªç·ã¯å¿
ãé£ãåã£ã瞊ç·å士ãã€ãªããŸããã€ãŸããæšªç·ã瞊ç·ããŸããããšã¯ãããŸããã ã©ã®çžŠç·ã«ã€ããŠãåãç¹ããå·Šå³åæã«æšªç·ãåºãããšã¯ãããŸãããã€ãŸããæšªç·ã瞊ç·ã暪åãããšã¯ãããŸããã åœãã¯ã²ãšã€ã ãã§ãã äžå³ ã« n = 5 ã®ãšãã®ããã¿ã ããã®äŸã瀺ããŸããäžåŽã®æ°åã¯çžŠç·ã®çªå·(å·Šãã1, 2, 3, 4, 5 ) ã衚ããŸããâãåœããã§ãã 瞊ç·ã®æ¬æ° n ãéžãã 瞊ç·ã®çªå· m ããã¿ã ããã®åœãã®å Žæãåæ®µã«ãããæšªç·ã®æç¡ãèªã¿èŸŒãã§ãåœãã«ãã©ãçãããã©ããã®å€å®ãåºåããããã°ã©ã ãäœæããŠãã ããããã ããäžãããããã¿ã ããã®ä»»æã®äœçœ®ã«1 æ¬ã ãæšªç·ãä»ãå ããããšãã§ãããã®ãšããŸãïŒä»ãå ããªããŠãããŸããŸããïŒã暪ç·ã1 æ¬ä»ãå ããåŸã®ãã¿ã ãããåè¿°ã®æ¡ä»¶ãæºãããŠããªããã°ãªããŸããã Input è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã¯ä»¥äžã®ãšããã§ãïŒ ïŒè¡ç®ã«ã瞊ç·ã®æ¬æ° n (1 < n †10) ãæžãããŠããŸãã ïŒè¡ç®ã«ã¯ãéžãã 瞊ç·ã®çªå· m (1 †m †n ) ãæžãããŠããŸãã ïŒè¡ç®ã«ã¯ãåœãã®å ŽæïŒå³ã§ããâïŒãå·Šããæ°ããŠäœçªç®ããæžãããŠããŸãã ïŒè¡ç®ã«ã¯ããã¿ã ããã®æ®µæ° d (1 †d †30) ãæžãããŠããŸãã ïŒè¡ç®ä»¥éã¯ãå³ã«å¯Ÿå¿ããæ°åã®äžŠã³ã®ããã«ããã¿ã ããã®äžããé ã«ãå瞊ç·ã®éã«æšªç·ããããšãã 1ããªããšãã 0 ãšããŠã n - 1 ã€ã®æ°åã䞊ãã§ããŸãã å
¥åã¯ïŒã€ã® 0 ãæžãããè¡ã§çµãããŸãã Output åããŒã¿ã»ããã«ã€ããŠãéžãã 瞊ç·ã®çªå· m ããåœãã«ãã©ãçãããã©ããã«å¿ããŠä»¥äžã®å€ãåºåããŠãã ããã æšªç·ãåŒããªããŠãåœãã«ãã©ãçãããšã㯠0 ãåºåããŠãã ããã æšªç·ã1 æ¬åŒãã°åœãã«ãã©ãçãããšãã¯ããã®äžã§æãåºçºåŽïŒå³ã§ã¿ãŠäžïŒã«è¿ã暪ç·ã®äœçœ®ãåºåããŠãã ãããåºçºåŽããæ°ããŠäœæ®µç®ïŒå³ ãåèã«ããŠãã ããïŒã«ãå·Šããæ°ããŠäœçªç®ã®çžŠç·ããå³ã«åãã£ãŠæšªç·ãåŒãããåè§ã®ç©ºçœã§åºåã£ãŠåºåããŠãã ããã æšªç·ã1 æ¬åŒããŠãåœãã«ãã©ãçããªããšãã«ã¯ 1 ãåºåããŠãã ããã Sample Input 5 2 3 9 1010 1001 0100 1001 0010 1000 0100 0101 1010 0 Output for the Sample Input 6 4
| 38,666
|
C: äž²åºã (Skewering) åé¡ ããæ¥ãã»ããã¡ãããç©ã¿æšã§éãã§ãããšãŠãã·ãåããã£ãŠããŸããã ã»ããã¡ããã¯ããŠãã·ãåãšäžç·ã«ç©ã¿æšã§éã¶ããšã«ããŸããã äžèŸºã®é·ãã 1 ã®ç«æ¹äœã®ç©ã¿æšã®ãããã¯ã A \times B \times C åééãªãç©ã¿éããŠã§ããã A \times B \times C ã®çŽæ¹äœããããŸããå
šãŠã®ç«æ¹äœãšçŽæ¹äœã®å蟺㯠x 軞ã y 軞ã z 軞ã®ãããããšå¹³è¡ã§ãã ã»ããã¡ãããšãŠãã·ãåã¯äº€äºã«ä»¥äžã®æäœãç¹°ãè¿ããŸãã çŽæ¹äœãã瞊æ¹åãæšªæ¹åã奥è¡ãæ¹åã®ããããã®æ¹åã«äžåã«äžŠãã ç©ã¿æšã®ãããã¯ã®åãéžãã§ãåã«å«ãŸãããããã¯å
šãŠãèµ€ãå¡ãããã ãããã§ã«èµ€ãå¡ãããŠãããããã¯ãå«ãåã¯éžã¶ããšãã§ããªãã ããæ£ç¢ºã«ã¯ã çŽæ¹äœã«å«ãŸãããããã¯ã®ãã¡äžã€ãšã x,y,z ã®äžã€ã®æ¹åããäžã€ãéžã¶ã éžãã ãããã¯ãéžãã æ¹åã«æŽæ°ã®è·é¢ã ãåããããšããå®å
šã«éãªããããªãããã¯å
šãŠãèµ€ãå¡ãïŒ 0 ãè² ã®æŽæ°ã®è·é¢ãåããããšãèããïŒããã ããæ¡ä»¶ãæºãããããã¯ã§ãã£ãŠãã§ã«å¡ããããã®ãã²ãšã€ã§ãååšããå Žåããã®æäœã¯è¡ãããšãã§ããªãã ã»ããã¡ãããå
æã§ãå
ã«æäœãè¡ããªããªã£ãæ¹ã®è² ãã§ãã ãŸããæåå
šãŠã®ç«æ¹äœã«è²ã¯å¡ãããŠããŸããã äºäººãæé©ã«è¡åãããšããã©ã¡ããåã€ãå€å®ããŠãã ããã å
¥ååœ¢åŒ A B C å¶çŽ 1 \leq A, B, C \leq 100 å
¥åã¯ãã¹ãп޿°ã§ããã åºååœ¢åŒ äºäººãæé©ã«è¡åãããšããã»ããã¡ãããåã€ãªãã° Hom ãããŠãã·ãåãåã€ãªãã° Tem ãäžè¡ã«åºåããã å
¥åäŸ 1 1 1 10 åºåäŸ 1 Hom äžåç®ã§ã»ããã¡ããã¯å
šãŠã®ãããã¯ãèµ€ãå¡ãããšãã§ããŸãã å
¥åäŸ 2 4 3 5 åºåäŸ 2 Hom å
¥åäŸ 3 6 4 10 åºåäŸ 3 Tem
| 38,667
|
JPEG Compression The fundamental idea in the JPEG compression algorithm is to sort coeffi- cient of given image by zigzag path and encode it. In this problem, we donât discuss about details of the algorithm, but you are asked to make simple pro- gram. You are given single integer N , and you must output zigzag path on a matrix where size is N by N . The zigzag scanning is start at the upper-left corner (0, 0) and end up at the bottom-right corner. See the following Figure and sample output to make sure rule of the zigzag scanning. For example, if you are given N = 8, corresponding output should be a matrix shown in right-side of the Figure. This matrix consists of visited time for each element. Input Several test cases are given. Each test case consists of one integer N (0 < N < 10) in a line. The input will end at a line contains single zero. Output For each input, you must output a matrix where each element is the visited time. All numbers in the matrix must be right justified in a field of width 3. Each matrix should be prefixed by a header âCase x:â where x equals test case number. Sample Input 3 4 0 Output for the Sample Input Case 1: 1 2 6 3 5 7 4 8 9 Case 2: 1 2 6 7 3 5 8 13 4 9 12 14 10 11 15 16
| 38,668
|
æå€§ã®å åé¡ n åã®æŽæ°ãããªãæ°å a 1 , a 2 , ..., a n ãšæ£æŽæ° k (1 †k †n ) ãäžãããã.ãã®ãšã, é£ç¶ããŠäžŠã¶ k åã®æŽæ°ã®å S i = a i + a i+1 + ... + a i + k -1 (1 †i †n - k + 1) ã®æå€§å€ãåºåããããã°ã©ã ãäœããªãã. å
¥å å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããïŒå
¥åã¯ïŒã€ã®ãŒããå«ãè¡ã§çµäºããïŒ 1 è¡ç®ã«ã¯æ£æŽæ° n (1 †n †100000) ãšæ£æŽæ° k (1 †k †n ) ããã®é ã«ç©ºçœã§ åºåãããŠæžãããŠãã.2 è¡ç®ä»¥éã®ç¬¬ 1 + i è¡ç® (1 †i †n ) ã«ã¯, æ°åã® i çªç®ã®é
a i (-10000 †a i †10000) ãæžãããŠãã. æ¡ç¹çšããŒã¿ã®ãã¡, é
ç¹ã® 60% å㯠n †5000, k †1000 ãæºãã. ããŒã¿ã»ããã®æ°ã¯ 5 ãè¶
ããªãïŒ åºå ããŒã¿ã»ããããšã« S i ã®æå€§å€ãïŒè¡ã«åºåããïŒ å
¥åºåäŸ å
¥åäŸ 5 3 2 5 -4 10 3 0 0 åºåäŸ 11 äžèšå顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
| 38,669
|
Print a Frame Draw a frame which has a height of H cm and a width of W cm. For example, the following figure shows a frame which has a height of 6 cm and a width of 10 cm. ########## #........# #........# #........# #........# ########## Input The input consists of multiple datasets. Each dataset consists of two integers H and W separated by a single space. The input ends with two 0 (when both H and W are zero). Output For each dataset, print the frame made of '#' and '.'. Print a blank line after each dataset. Constraints 3 †H †300 3 †W †300 Sample Input 3 4 5 6 3 3 0 0 Sample Output #### #..# #### ###### #....# #....# #....# ###### ### #.# ###
| 38,670
|
Problem Statement The Animal School is a primary school for animal children. You are a fox attending this school. One day, you are given a problem called "Arithmetical Restorations" from the rabbit teacher, Hanako. Arithmetical Restorations are the problems like the following: You are given three positive integers, $A$, $B$ and $C$. Several digits in these numbers have been erased. You should assign a digit in each blank position so that the numbers satisfy the formula $A+B=C$. The first digit of each number must not be zero. It is also the same for single-digit numbers. You are clever in mathematics, so you immediately solved this problem. Furthermore, you decided to think of a more difficult problem, to calculate the number of possible assignments to the given Arithmetical Restorations problem. If you can solve this difficult problem, you will get a good grade. Shortly after beginning the new task, you noticed that there may be too many possible assignments to enumerate by hand. So, being the best programmer in the school as well, you are now trying to write a program to count the number of possible assignments to Arithmetical Restoration problems. Input The input is a sequence of datasets. The number of datasets is less than 100. Each dataset is formatted as follows. $A$ $B$ $C$ Each dataset consists of three strings, $A$, $B$ and $C$. They indicate that the sum of $A$ and $B$ should be $C$. Each string consists of digits ( 0 - 9 ) and/or question mark ( ? ). A question mark ( ? ) indicates an erased digit. You may assume that the first character of each string is not 0 and each dataset has at least one ? . It is guaranteed that each string contains between 1 and 50 characters, inclusive. You can also assume that the lengths of three strings are equal. The end of input is indicated by a line with a single zero. Output For each dataset, output the number of possible assignments to the given problem modulo 1,000,000,007. Note that there may be no way to solve the given problems because Ms. Hanako is a careless rabbit. Sample Input 3?4 12? 5?6 ?2?4 5?7? ?9?2 ????? ????? ????? 0 Output for the Sample Input 2 40 200039979 Note The answer of the first dataset is 2. They are shown below. 384 + 122 = 506 394 + 122 = 516
| 38,672
|
Score: 100 points Problem Statement We have two distinct integers A and B . Print the integer K such that |A - K| = |B - K| . If such an integer does not exist, print IMPOSSIBLE instead. Constraints All values in input are integers. 0 \leq A,\ B \leq 10^9 A and B are distinct. Input Input is given from Standard Input in the following format: A B Output Print the integer K satisfying the condition. If such an integer does not exist, print IMPOSSIBLE instead. Sample Input 1 2 16 Sample Output 1 9 |2 - 9| = 7 and |16 - 9| = 7 , so 9 satisfies the condition. Sample Input 2 0 3 Sample Output 2 IMPOSSIBLE No integer satisfies the condition. Sample Input 3 998244353 99824435 Sample Output 3 549034394
| 38,673
|
åé¡ G : ããã°ã©ãã³ã°ã³ã³ãã¹ããã£ã¬ã³ãžãã㯠ä»ïŒGââgle Code Jam ã®å°åºå€§äŒãå§ãŸãããšããŠããïŒ åã®åžã«åº§ã£ãŠããç·ã® ID 㯠omeometo ãšèšããããïŒ åŸãã®åžã«åº§ã£ãŠããç·ã® ID 㯠jellies ãšèšããããïŒ æ±äº¬å€§åп代ã®èšæ¶ã«ïŒäŒŒããã㪠ID ã®ä»²éãå±
ãèŠãããããïŒåã®ä»²éã¯äžäººæ®ããçŸå°å¥³ã ã£ãã¯ãã ïŒ åœŒãã¯ïŒæºã®äžã«è»ã®ã€ã©ã¹ããæãããæ¬ãæã£ãŠããïŒ ããã¯ãããâŠããã°ã©ãã³ã°ã³ã³ãã¹ãã®ã¢ã«ãŽãªãºã ãæåã«ç¶²çŸ
ãïŒä»ã§ã¯çºå£²çŠæ¢ãšãªã£ãäŒèª¬ã®æ¬ïŒ ãããã°ã©ãã³ã°ã³ã³ãã¹ããã£ã¬ã³ãžããã¯ãã§ã¯ãªããïŒ åã¯ïŒomeometo ããã€ã¬ã«è¡ã£ãã®ãèŠèšããïŒå°ãæåããŠïŒèªãã§ã¿ãããšã«ããïŒ ããã°ã©ãã³ã°ã³ã³ãã¹ããã£ã¬ã³ãžãã㯠âŠãããïŒåã¯äžç¬ã§æ¬ãèªã¿çµããŠããŸã£ãïŒ æåæãã ïŒç°¡åãããïŒ å°ãå€ãæ¬ã ãããšãã£ãŠïŒãããªå
容ã§ããå£²ãæ°ã«ãªã£ããã®ã ïŒ äŸãã°ïŒæåã®äžè§åœ¢ã®åé¡ïŒããã¯ïŒç°¡åãããŠã話ã«ãªããªãïŒèªåã ã£ããïŒããããïŒ åé¡ N æ¬ã®çŽç·ç¶ã®æ£ãããïŒæ£ i ã®é·ã㯠a i ã§ããïŒ ããªãã¯ïŒãããã®æ£ãã 6 æ¬ãéžã³ïŒ ãããã® 3 æ¬ãã€ã§ïŒ2 åã®äžè§åœ¢ãäœãããšèããŠããïŒ 3 æ¬ã®æ£ã¯ããããäžè§åœ¢ã®èŸºãšããŠçšãïŒ2 ã€ã®æ£ãè§Šããäœçœ®ã¯æ£ã®ç«¯ç¹ã®ã¿ãšããïŒ ã€ãŸãïŒæ£ã®äžéšãäžè§åœ¢ã®èŸºãšããŠäœ¿ãããšã¯èš±ãããïŒå¿
ãæ£å
šäœã蟺ãšããªããã°ãªããªãïŒ ãŸãïŒæ£ã®å€ªãã¯èããïŒäžè§åœ¢ã¯æ£ã®é¢ç©ãæããªããã°ãªããªããã®ãšããïŒ 2 åã®äžè§åœ¢ã®åšé·ã®åã®æå€§å€ãæ±ããïŒ ãã ãïŒ2 åã®äžè§åœ¢ãäœãããšãã§ããªãéã«ã¯ 0 ãçããšããïŒ å
¥å å
¥åã®æåã®è¡ã«ã¯æŽæ° N ãæžãããŠããïŒ ç¶ã N è¡ã® i è¡ç®ã«ã¯ 1 ã€ã®æŽæ° a i ãæžãããŠããïŒ åºå çãã®æŽæ°ãåºåããïŒ å¶çŽ 1 †N †10 5 1 †a i †10 15 éšåç¹ ãã®åé¡ã®å€å®ã«ã¯ïŒ20 ç¹åã®ãã¹ãã±ãŒã¹ã®ã°ã«ãŒããèšå®ãããŠããïŒ ãã®ã°ã«ãŒãã«å«ãŸãããã¹ãã±ãŒã¹ã®å
¥åã¯ä»¥äžãæºããïŒ 1 †N †100 å
¥åºåäŸ å
¥åäŸ: 6 1 1 1 1 1 1 å
¥åäŸã«å¯Ÿããåºå: 6
| 38,674
|
Score : 400 points Problem Statement One day, Niwango-kun, an employee of Dwango Co., Ltd., found an integer sequence (a_1, ..., a_N) of length N . He is interested in properties of the sequence a . For a nonempty contiguous subsequence a_l, ..., a_r (1 \leq l \leq r \leq N) of the sequence a , its beauty is defined as a_l + ... + a_r . Niwango-kun wants to know the maximum possible value of the bitwise AND of the beauties of K nonempty contiguous subsequences among all N(N+1)/2 nonempty contiguous subsequences. (Subsequences may share elements.) Find the maximum possible value for him. Constraints 2 \leq N \leq 1000 1 \leq a_i \leq 10^9 1 \leq K \leq N(N+1)/2 All numbers given in input are integers Input Input is given from Standard Input in the following format: N K a_1 a_2 ... a_N Output Print the answer. Sample Input 1 4 2 2 5 2 5 Sample Output 1 12 There are 10 nonempty contiguous subsequences of a . Let us enumerate them: contiguous subsequences starting from the first element: \{2\}, \{2, 5\}, \{2, 5, 2\}, \{2, 5, 2, 5\} contiguous subsequences starting from the second element: \{5\}, \{5, 2\}, \{5, 2, 5\} contiguous subsequences starting from the third element: \{2\}, \{2, 5\} contiguous subsequences starting from the fourth element: \{5\} (Note that even if the elements of subsequences are equal, subsequences that have different starting indices are considered to be different.) The maximum possible bitwise AND of the beauties of two different contiguous subsequences is 12 . This can be achieved by choosing \{5, 2, 5\} (with beauty 12 ) and \{2, 5, 2, 5\} (with beauty 14 ). Sample Input 2 8 4 9 1 8 2 7 5 6 4 Sample Output 2 32
| 38,675
|
Problem F: Problem F: ãªãºã ãã·ãŒã³ Advanced Computer Music瀟ïŒACM瀟ïŒã¯ïŒ ãããããããã°ã©ã ããããªãºã éãã«é³æ¥œãæŒå¥ãã ãªãºã ãã·ãŒã³ã販売ããŠããïŒ ããæïŒACMç€Ÿã¯æ°ãããªãºã ãã·ãŒã³ãéçºããŠå£²ãåºãããšããŠããïŒ ACMç€Ÿã®æ§è£œåã¯åæã«1ã€ã®é³ãã鳎ããããšãã§ããªãã£ãã®ã«å¯ŸãïŒ æ°è£œåã§ã¯æå€§ã§8ã€ã®é³ãåæã«é³Žãããããã«ãªããšããã®ã äžçªã®ç®çæ©èœã§ãã£ãïŒ ä»ãŸã§è€æ°ã®æ§è£œåãå©çšããŠæŒå¥ããå¿
èŠã®ãã£ãæ²ã æ°è£œå1å°ã§æžãããã«ãªãã®ã§ïŒ ACMç€Ÿã¯æ°è£œåãžã®ç§»è¡ãæšé²ãããããã«ïŒ è€æ°ã®æ§è£œååãã®ãªãºã ãã¿ãŒã³ã1ã€ã®æ°è£œååãã®ãªãºã ãã¿ãŒã³ã« 倿ããããã°ã©ã ãäœãããšã«ããïŒ ACM瀟ã®ãªãºã ãã·ãŒã³ã§ã¯ïŒåæã«ã©ã®é³ã鳎ãããã2æ¡ã®16鲿°ã§è¡šçŸããïŒ ACM瀟ã®ãªãºã ãã·ãŒã³ã¯8ã€ã®ç°ãªãé³ã鳎ããããšãå¯èœã§ïŒ ããããã®é³ã«ã¯0ãã7ã®çªå·ãå²ãåœãŠãããŠããïŒ ããã¿ã€ãã³ã°ã«ãããŠïŒé³ i (0 †i < 8) ã鳎ããå Žåã s i = 1ïŒ é³Žãããªãå Žåã s i = 0 ãšããïŒ ãã®ãšãïŒããããã®é³ãåæã«é³Žããããããªåé³ã ãšããå€ã§è¡šãïŒ ãã®å€ã2æ¡ã®16鲿°è¡šèšã§è¡šãããåé³è¡šçŸã ããªãºã ãã¿ãŒã³ã®äžã§çšããããïŒ16鲿°ã®è±åã¯å€§æåãçšããïŒïŒ äŸãã°ïŒé³0, 6, 7 ãåæã«é³Žãããããªåé³ã¯ S = 2 0 + 2 6 + 2 7 = C1 (16) ãšãªããã â C1 â ãšè¡šçŸããïŒ ãŸãäœã鳎ãããªããããªãåé³ã㯠â 00 â ãšè¡šçŸãããïŒ ãªãºã ãã¿ãŒã³ã¯ïŒäžèšã®ãããªåé³è¡šçŸã1ã€ä»¥äžäžŠã¹ããã®ãšããŠäžããããïŒ ãããªãºã ãã¿ãŒã³æååã¯ïŒ1å°ç¯å
ã®æŒå¥ãã¿ãŒã³ã瀺ããŠããïŒ ããããã®åé³ã鳎ããã¿ã€ãã³ã°ãå°ç¯å
ã®çžå¯Ÿäœçœ® t (0 †t < 1) ã§è¡šçŸããããšã«ããïŒ k åã®åé³è¡šçŸãããªããªãºã ãã¿ãŒã³æååã¯ïŒ å°ç¯ã k çåãããããã®åé³ãé ã« t = 0/ k , 1/ k , ..., ( k â1)/ k ã®ã¿ã€ãã³ã°ã§æŒå¥ãããã㪠ãªãºã ãã¿ãŒã³ã衚ããŠããïŒ äŸãã°ïŒãªãºã ãã¿ãŒã³ â 01000003 â ã¯ïŒ t = 0/4 ã®ã¿ã€ãã³ã°ã§é³0ãæŒå¥ãïŒ t = 3/4 ã®ã¿ã€ãã³ã°ã§é³0, 1ãæŒå¥ããããšã衚ãïŒ ãŸãïŒãªãºã ãã¿ãŒã³ â 00 â ã¯å°ç¯å
ã§äœãé³ã鳎ãããªãããšã衚ã ïŒãªãºã ãã¿ãŒã³ã«ã¯åé³è¡šçŸã1ã€ä»¥äžå¿
èŠã§ããããšã«æ³šæããïŒïŒ æ§è£œåã¯åæã«1ã€ã®é³ãã鳎ãããªãããïŒ æ§è£œååãã®ãªãºã ãã¿ãŒã³æååå
ã«ã¯ â 00 â, â 01 â, â 02 â, â 04 â, â 08 â, â 10 â, â 20 â, â 40 â, â 80 â ã®ããããã®åé³è¡šçŸããçŸããªãïŒ æ§è£œååãã®ãªãºã ãã¿ãŒã³ã N å (1 †N †8) åãåãïŒ ãããã®ãªãºã ãã¿ãŒã³ãåæã«æŒå¥ãããã㪠æ°è£œååãã®ãªãºã ãã¿ãŒã³ãåºåããããã°ã©ã ãæžããŠæ¬²ããïŒ äžãããã N åã®ãªãºã ãã¿ãŒã³ã«ãããŠïŒ ãŸã£ããåãã¿ã€ãã³ã°ã§åãé³ãæŒå¥ãããããšã¯ãªããšä»®å®ããŠããïŒ Input æåã®è¡ã«ããŒã¿ã»ããã®æ°ãäžããããïŒ æ¬¡ã®è¡ä»¥éã«ã¯ïŒããããã®ããŒã¿ã»ãããé ã«èšè¿°ãããŠããïŒ ããŒã¿ã»ããã®æ°ã¯ 120 ãè¶ããªããšä»®å®ããŠããïŒ ããããã®ããŒã¿ã»ããã¯ä»¥äžã®ãããªåœ¢åŒã§äžããããïŒ N R 1 R 2 ... R N R i (1 †i †N ) ã¯ããããæ§è£œååãã®ãªãºã ãã¿ãŒã³ã§ããïŒ åãªãºã ãã¿ãŒã³ã¯æå€§ã§2048æåïŒ1024åé³è¡šçŸïŒã§ããïŒ äžãããããªãºã ãã¿ãŒã³ã¯å¿
ãããæçã®è¡šçŸã«ãªã£ãŠããªãããšã«æ³šæããïŒ Output åããŒã¿ã»ããã«ã€ããŠïŒäžãããã N åã®ãªãºã ãã¿ãŒã³ã ãã¹ãŠåæã«æŒå¥ãããããªæçã®ãªãºã ãã¿ãŒã³ãçæãïŒ 1è¡ã§åºåããïŒ ãã®ãããªãªãºã ãã¿ãŒã³ã2048æåãè¶ããå ŽåïŒ ãªãºã ãã¿ãŒã³ã®ä»£ããã« â Too complex. â ãšããæååãåºåããïŒ Sample Input 5 2 01000100 00020202 2 0102 00000810 1 0200020008000200 5 0001 000001 0000000001 00000000000001 0000000000000000000001 1 000000 Output for the Sample Input 01020302 01000A10 02020802 Too complex. 00
| 38,676
|
Score : 200 points Problem Statement There are N people numbered 1 to N . Each person wears a red hat or a blue hat. You are given a string s representing the colors of the people. Person i wears a red hat if s_i is R , and a blue hat if s_i is B . Determine if there are more people wearing a red hat than people wearing a blue hat. Constraints 1 \leq N \leq 100 |s| = N s_i is R or B . Input Input is given from Standard Input in the following format: N s Output If there are more people wearing a red hat than there are people wearing a blue hat, print Yes ; otherwise, print No . Sample Input 1 4 RRBR Sample Output 1 Yes There are three people wearing a red hat, and one person wearing a blue hat. Since there are more people wearing a red hat than people wearing a blue hat, the answer is Yes . Sample Input 2 4 BRBR Sample Output 2 No There are two people wearing a red hat, and two people wearing a blue hat. Since there are as many people wearing a red hat as people wearing a blue hat, the answer is No .
| 38,677
|
æçµé²è¡ç· ãã³ãã³æªç¢ºèªçç©ã«äŸµç¥ãããããã«ãªã£ãæåœã§ã¯éèŠæœèšãæ°åé²è¡å
µåšã§ä¿è·ããããšã«ããã ãã®å
µåšã¯å€è§åœ¢ã®é åã«ç¹æ®ãªã¬ã¹ãå
æºãããããšã§æªç¢ºèªçç©ã«ãã¡ãŒãžãäžããããšãã§ãããæªç¢ºèªçç©ã䟵æ»ããéäžã§ã¬ã¹ã®æ¿åºŠãå€ãããšãæ¿åºŠã®å·®ã®çµ¶å¯Ÿå€ã®ãã¡ãŒãžãäžãããã¬ã¹ã®æ¿åºŠãåãé åãåããŠãããšãã¯ãã¡ãŒãžã¯äžåçºçããªãã çŸåšã®æè¡ã§ã¯ã¬ã¹ã®æ¿åºŠã¯äžå®ã«ããã§ããªãã®ã§ãæåœã¯æ°åé²è¡å
µåšãè€æ°æå
¥ããããšã«ãããå
šãŠã®å
µåšã§ã¬ã¹ã®æ¿åºŠã¯åãã§ãããè€æ°ã®å
µåšã®é åã«å«ãŸããéšåã¯æ¿åºŠãè¶³ãåããããã æªç¢ºèªçç©ã®åºçŸå°ç¹ãšéèŠæœèšã®äœçœ®ãå
ã«ãæªç¢ºèªçç©ãéèŠæœèšãŸã§äŸµæ»ããæã«åãããã¡ãŒãžã®æå°å€ãæ±ããŠæ¬²ããã ãã ããæªç¢ºèªçç©ã®äŸµæ»ã«ãŒãã«å€è§åœ¢ã®é ç¹ãä»ã®å€è§åœ¢ãšã®äº€ç¹ã¯å«ãŸããªããã®ãšããããŸããå€è§åœ¢ã®èŸºäžã蟺ã«ãã£ãŠäŸµæ»ããããšã¯ãªãã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã å€è§åœ¢ã®æ° å€è§åœ¢ã®é ç¹æ° xåº§æš yåº§æš xåº§æš yåº§æš ... å€è§åœ¢ã®é ç¹æ° xåº§æš yåº§æš xåº§æš yåº§æš ... åºçŸå°ç¹ãšéèŠæœèšã®ããŒã¿ã®æ° åºçŸäœçœ®ã®xåº§æš åºçŸäœçœ®ã®yåº§æš éèŠæœèšã®xåº§æš éèŠæœèšã®yåº§æš åºçŸäœçœ®ã®xåº§æš åºçŸäœçœ®ã®yåº§æš éèŠæœèšã®xåº§æš éèŠæœèšã®yåº§æš ... Constraints å
¥åã«å«ãŸãã座æšã¯çµ¶å¯Ÿå€ã1,000以äžã®æŽæ° å€è§åœ¢ã®æ°ã¯1以äž5ä»¥äž å€è§åœ¢ã®é ç¹æ°ã¯3以äž5ä»¥äž åºçŸå°ç¹ãšéèŠæœèšã®ããŒã¿ã®æ°ã¯1以äž100ä»¥äž å€è§åœ¢ã¯äžããããé ç¹ãé ã«ã€ãªãã§ã§ããå€è§åœ¢ãæããèªå·±äº€å·®ã¯ãªã åºçŸå°ç¹ãšéèŠæœèšã¯å€è§åœ¢ã®é ç¹åã³èŸºäžã«ããããšã¯ãªã Output åºçŸå°ç¹ãšéèŠæœèšã®çµããšã«æªç¢ºèªçç©ãéèŠæœèšãŸã§äŸµæ»ããéã«åãããã¡ãŒãžã®æå°å€ã1è¡ãã€åºåããã Sample Input 1 2 4 0 4 1 1 3 1 4 4 3 6 0 10 0 8 7 1 2 3 9 1 Output for the Sample Input 1 2 1ã€ç®ã®å€è§åœ¢ãåºãæã«1ãã¡ãŒãžãäžãã2ã€ç®ã®å€è§åœ¢ã«å
¥ãæã«1ãã¡ãŒãžãäžããã Sample Input 2 1 4 0 0 10 0 10 10 0 10 2 15 5 5 5 5 5 15 5 Output for the Sample Input 2 1 1 1ã€ç®ã®ããŒã¿ã§ã¯æªç¢ºèªçç©ãå€è§åœ¢ã«å
¥ãæã«ãã¡ãŒãžãçºçããã 2ã€ç®ã®ããŒã¿ã§ã¯æªç¢ºèªçç©ãå€è§åœ¢ããåºãæã«ãã¡ãŒãžãçºçããã Sample Input 3 2 4 0 0 10 0 10 10 0 10 4 10 0 20 0 20 10 10 10 1 5 5 15 5 Output for the Sample Input 3 0 æªç¢ºèªçç©ã1ã€ç®ã®å€è§åœ¢ãã2ã€ç®ã®å€è§åœ¢ã«åãã«ãŒããåããšæ¿åºŠãå€ããããšããªãã®ã§ãã¡ãŒãžãäžããããšãã§ããªãã Sample Input 4 2 3 0 0 10 0 5 10 3 5 0 15 0 10 10 1 5 5 10 5 Output for the Sample Input 4 2 åºçŸå°ç¹ã®é åãšéèŠæœèšã®é åã¯ç¹ã§æ¥ããŠããããã®ç¹ãéã£ãŠäŸµæ»ããããšã¯ãªãã Sample Input 5 2 4 0 0 10 0 10 10 0 10 4 0 0 10 0 10 10 0 10 2 15 5 5 5 5 5 15 5 Output for the Sample Input 5 2 2
| 38,678
|
Scores of Final Examination I am a junior high school teacher. The final examination has just finished, and I have all the students' scores of all the subjects. I want to know the highest total score among the students, but it is not an easy task as the student scores are listed separately for each subject. I would like to ask you, an excellent programmer, to help me by writing a program that finds the total score of a student with the highest total score. Input The input consists of multiple datasets, each in the following format. n m p 1,1 p 1,2 ⊠p 1, n p 2,1 p 2,2 ⊠p 2, n ⊠p m ,1 p m ,2 ⊠p m,n The first line of a dataset has two integers n and m . n is the number of students (1 †n †1000). m is the number of subjects (1 †m †50). Each of the following m lines gives n students' scores of a subject. p j,k is an integer representing the k -th student's score of the subject j (1 †j †m and 1 †k †n ). It satisfies 0 †p j,k †1000. The end of the input is indicated by a line containing two zeros. The number of datasets does not exceed 100. Output For each dataset, output the total score of a student with the highest total score. The total score s k of the student k is defined by s k = p 1, k + ⊠+ p m,k . Sample Input 5 2 10 20 30 40 50 15 25 35 45 55 6 3 10 20 30 15 25 35 21 34 11 52 20 18 31 15 42 10 21 19 4 2 0 0 0 0 0 0 0 0 0 0 Output for the Sample Input 105 83 0
| 38,679
|
Score: 500 points Problem Statement You are the top spy of AtCoder Kingdom. To prevent the stolen secret from being handed to AlDebaran Kingdom, you have sneaked into the party where the transaction happens. There are N attendees in the party, and they are given attendee numbers from 1 through N . The height of Attendee i is A_i . According to an examination beforehand, you know that a pair of attendees satisfying the condition below will make the transaction. The absolute difference of their attendee numbers is equal to the sum of their heights. There are \frac{N(N-1)}{2} ways to choose two from the N attendees and make a pair. Among them, how many satisfy the condition above? P.S.: We cannot let you know the secret. Constraints All values in input are integers. 2 \leq N \leq 2 \times 10^5 1 \leq A_i \leq 10^9\ (1 \leq i \leq N) Input Input is given from Standard Input in the following format: N A_1 A_2 \dots A_N Output Print the number of pairs satisfying the condition. Sample Input 1 6 2 3 3 1 3 1 Sample Output 1 3 A_1 + A_4 = 3 , so the pair of Attendee 1 and 4 satisfy the condition. A_2 + A_6 = 4 , so the pair of Attendee 2 and 6 satisfy the condition. A_4 + A_6 = 2 , so the pair of Attendee 4 and 6 satisfy the condition. No other pair satisfies the condition, so you should print 3 . Sample Input 2 6 5 2 4 2 8 8 Sample Output 2 0 No pair satisfies the condition, so you should print 0 . Sample Input 3 32 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 Sample Output 3 22
| 38,680
|
Score : 300 points Problem Statement Eli- 1 started a part-time job handing out leaflets for N seconds. Eli- 1 wants to hand out as many leaflets as possible with her special ability, Cloning. Eli- gen can perform two kinds of actions below. Clone herself and generate Eli- (gen + 1) . (one Eli- gen (cloning) and one Eli- (gen + 1) (cloned) exist as a result of Eli- gen 's cloning.) This action takes gen \times C ( C is a coefficient related to cloning. ) seconds. Hand out one leaflet. This action takes one second regardress of the generation ( =gen ). They can not hand out leaflets while cloning. Given N and C , find the maximum number of leaflets Eli- 1 and her clones can hand out in total modulo 1000000007 ( = 10^9 + 7 ). Constraints 1 \leq Q \leq 100000 = 10^5 1 \leq N_q \leq 100000 = 10^5 1 \leq C_q \leq 20000 = 2 \times 10^4 Input The input is given from Standard Input in the following format: Q N_1 C_1 : N_Q C_Q The input consists of multiple test cases. On line 1 , Q that represents the number of test cases is given. Each test case is given on the next Q lines. For the test case q ( 1 \leq q \leq Q ) , N_q and C_q are given separated by a single space. N_q and C_q represent the working time and the coefficient related to cloning for test case q respectively. Output For each test case, Print the maximum number of leaflets Eli- 1 and her clones can hand out modulo 1000000007 ( = 10^9 + 7 ). Partial Scores 30 points will be awarded for passing the test set satisfying the condition: Q = 1 . Another 270 points will be awarded for passing the test set without addtional constraints and you can get 300 points in total. Sample Input 1 2 20 8 20 12 Sample Output 1 24 20 For the first test case, while only 20 leaflets can be handed out without cloning, 24 leaflets can be handed out by cloning first and two people handing out 12 leaflets each. For the second test case, since two people can only hand out 8 leaflets each if Eli- 1 clones, she should hand out 20 leaflets without cloning. Sample Input 2 1 20 3 Sample Output 2 67 One way of handing out 67 leaflets is like the following image. Each black line means cloning, and each red line means handing out. This case satisfies the constraint of the partial score. Sample Input 3 1 200 1 Sample Output 3 148322100 Note that the value modulo 1000000007 ( 10^9 + 7 ) must be printed. This case satisfies the constraint of the partial score.
| 38,681
|
Wire I am a craftsman specialized in interior works. A customer asked me to perform wiring work on a wall whose entire rectangular surface is tightly pasted with pieces of panels. The panels are all of the same size (2 m in width, 1 m in height) and the wall is filled with an x (horizontal) by y (vertical) array of the panels. The customer asked me to stretch a wire from the left top corner of the wall to the right bottom corner whereby the wire is tied up at the crossing points with the panel boundaries (edges and vertexes) as shown in the figure. There are nine tied-up points in the illustrative figure shown below. Fig: The wire is tied up at the edges and vertexes of the panels (X: 4 panels, Y: 6 panels) Write a program to provide the number of points where the wire intersects with the panel boundaries. Assume that the wire and boundary lines have no thickness. Input The input is given in the following format. x y A line of data is given that contains the integer number of panels in the horizontal direction x (1 †x †1000) and those in the vertical direction y (1 †y †1000). Output Output the number of points where the wire intersects with the panel boundaries. Sample Input 1 4 4 Sample Output 1 5 Sample Input 2 4 6 Sample Output 2 9
| 38,682
|
Get Many Persimmon Trees Seiji Hayashi had been a professor of the Nisshinkan Samurai School in the domain of Aizu for a long time in the 18th century. In order to reward him for his meritorious career in education, Katanobu Matsudaira, the lord of the domain of Aizu, had decided to grant him a rectangular estate within a large field in the Aizu Basin. Although the size (width and height) of the estate was strictly specified by the lord, he was allowed to choose any location for the estate in the field. Inside the field which had also a rectangular shape, many Japanese persimmon trees, whose fruit was one of the famous products of the Aizu region known as 'Mishirazu Persimmon', were planted. Since persimmon was Hayashi's favorite fruit, he wanted to have as many persimmon trees as possible in the estate given by the lord. For example, in Figure 1, the entire field is a rectangular grid whose width and height are 10 and 8 respectively. Each asterisk (*) represents a place of a persimmon tree. If the specified width and height of the estate are 4 and 3 respectively, the area surrounded by the solid line contains the most persimmon trees. Similarly, if the estate's width is 6 and its height is 4, the area surrounded by the dashed line has the most, and if the estate's width and height are 3 and 4 respectively, the area surrounded by the dotted line contains the most persimmon trees. Note that the width and height cannot be swapped; the sizes 4 by 3 and 3 by 4 are different, as shown in Figure 1. Figure 1: Examples of Rectangular Estates Your task is to find the estate of a given size (width and height) that contains the largest number of persimmon trees. Input The input consists of multiple data sets. Each data set is given in the following format. N W H x 1 y 1 x 2 y 2 ... x N y N S T N is the number of persimmon trees, which is a positive integer less than 500. W and H are the width and the height of the entire field respectively. You can assume that both W and H are positive integers whose values are less than 100. For each i (1 <= i <= N ), x i and y i are coordinates of the i -th persimmon tree in the grid. Note that the origin of each coordinate is 1. You can assume that 1 <= x i <= W and 1 <= y i <= H , and no two trees have the same positions. But you should not assume that the persimmon trees are sorted in some order according to their positions. Lastly, S and T are positive integers of the width and height respectively of the estate given by the lord. You can also assume that 1 <= S <= W and 1 <= T <= H . The end of the input is indicated by a line that solely contains a zero. Output For each data set, you are requested to print one line containing the maximum possible number of persimmon trees that can be included in an estate of the given size. Sample Input 16 10 8 2 2 2 5 2 7 3 3 3 8 4 2 4 5 4 8 6 4 6 7 7 5 7 8 8 1 8 4 9 6 10 3 4 3 8 6 4 1 2 2 1 2 4 3 4 4 2 5 3 6 1 6 2 3 2 0 Output for the Sample Input 4 3
| 38,683
|
ã»ãŒåšææåå æåå S ãäžããããããã®æåå S ã«å¯Ÿãã Q åã®ã¯ãšãªã«çããã i çªç®ã®ã¯ãšãªã§ã¯ã S[l_i,\ r_i] ãã1æåãŸã§å€ããŠãããšãã S[l_i,\ r_i] ãåšæ t_i ã®æååã«ã§ãããã©ãããå€å®ããã S[l,\ r] ã¯æåå S ã® l æåç®ãã r æåç®ãŸã§ã®éšåæååã衚ãã æåå W ãåšæ t ã®æååã§ãããšã¯ã i\ =\ 1,\2,\... ,\ |W| â t ã«å¯Ÿãã W_{i} = W_{i+t} ãšãªãããšãšããã Constraints 1 †|S| †10^5 1 †Q †10^5 1 †l_i †r_i †|S| 1 †t_i †r_i â l_i+1 S ã¯ã¢ã«ãã¡ãããã®å°æåã®ã¿ãããªã Input Format å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããã S Q l_1 r_1 t_1 ... l_Q r_Q t_Q Output Format Q è¡ã«ããã£ãŠåºåããã i è¡ç®ã«ã¯ã i çªç®ã®ã¯ãšãªã®çãã Yes ãŸã㯠No ã§åºåããã Sample Input 1 abcabcaxcabc 4 1 9 3 8 12 3 1 4 2 2 3 2 Sample Output 1 Yes Yes No Yes Sample Input 2 isuruu 4 3 6 1 3 6 2 3 6 3 2 4 1 Sample Output 2 Yes Yes Yes No
| 38,685
|
>åå°åå² ããŠãžã³ã°ã¡ãŒã«ãŒã®å±±ç°ããŠã¹ã¯ãæ°ããªç®çååãšããŠãåŠæ ¡ãç
é¢ãªã©ç°å¢ãå
å®ããŠããç·ããŒã ã¿ãŠã³ã®åè²å°ã売ãåºããŸããããã®åè²å°ã¯è€æ°ã®åºç»ã«åå²ãããŠããã奜ããªã ã賌å
¥ã§ããŸããã賌å
¥ããåºç»ãåãããåå°ã®åœ¢ç¶ã¯é·æ¹åœ¢(æ£æ¹åœ¢ãå«ã)ã§ãªããã°ãªããŸããã å±±ç°ããŠã¹ã¯ãå
šåºç»ãå®å£²ããåè²å°ã管çãããã賌å
¥è
ããšã«å¢çç·ãåŒãããã®åºç»ã® 1ã€ã«è³Œå
¥è
çªå·ãæžããçæ¿ãèšçœ®ããŠãããŸãããå¢çç·ã¯å°é¢ã«æšã®æã§ç·ãåŒããã ãã®ãã®ã§ãã£ããããæ°æ¥åŸã®è±ªéšã«ããæ¶ããŠããŸãçæ¿ã ããæ®ããŸãããå³ 1 ã¯çæ¿ã®ãã£ãåºç»ã«ããã®åºç»ãè²·ã£ã賌å
¥è
çªå·ãèšãããã®ã§ããããã§ã¯åè²å°ãã©ã®ããã«è²·ããããåãããŸãããæãã¯äºåæã®åŒãåºãã«ãã£ã賌å
¥è
çªå· b ãšè³Œå
¥åºç»æ° k ã®ã¡ã¢(å³ 2)ãèŠã€ãã£ãããšã§ãã å³ïŒïŒå·ŠïŒïŒçæ¿ã®é
眮ãå³2ïŒå³ïŒïŒã¡ã¢ ããã°ã©ããŒã§ããããªãã¯ãããã°ã©ã ãæžããŠå±±ç°ããŠã¹ãå©ããããšã«ãªããŸãããåè²å°ã®å€§ãã X à Y ã賌å
¥è
æ° n ãã¡ã¢ã®æ
å ± b ã k ãåã³çæ¿ã®äœçœ®æ
å ± s ãå
¥åãšããå³ 3 ã«ç€ºãããã«ååºç»ã®è³Œå
¥è
ãåºåããããã°ã©ã ãäœæããŠãã ããã å³3ïŒååºç»ã®è³Œå
¥è
äžããããæ
å ±ã«ã€ããŠã以äžã®å Žå㯠NA ãšåºåããŸãã åºç»ãåºå¥ããæ¹æ³ãååšããªãå Žå åºç»ãåºå¥ããæ¹æ³ãè€æ°ååšããå Žå Input è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒããïŒã€ã®è¡ã§ç€ºãããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã X Y n b 1 k 1 b 2 k 2 : b n k n s 11 s 21 ... s X1 s 12 s 22 ... s X2 : s 1Y s 2Y ... s XY 1 è¡ç®ã« X, Y, n (1 †X, Y †10, 1 †n †15) ãäžããããŸããç¶ã n è¡ã«ã¡ã¢ã® i è¡ç®ã«æžãããæ
å ± b i (1 †b i †n ), k i (1 †k i †100) ãäžããããŸãã ç¶ã Y è¡ã«åºç»æ
å ±ã® i è¡ç®ã®æ
å ± s ij ãäžããããŸãã s ij 㯠i è¡ç®ã®å·Šãã j çªç®ã®åºç»ã®çæ¿æ
å ±ã衚ããŸããçæ¿ã®æ
å ± s ij ãšããŠããã®åºç»ã«çæ¿ãç¡ãå Žå㯠0 ãçæ¿ãããå Žåã¯ãã®åºç»ã®è³Œå
¥è
çªå·ãäžããããŸãã ããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã Output å
¥åããŒã¿ã»ããããšã«ã賌å
¥è
æ
å ±ãŸãã¯NA ãåºåããŸãã Sample Input 5 4 6 1 6 2 4 3 3 4 4 5 1 6 2 0 0 1 0 0 0 0 0 2 0 0 0 0 3 0 0 4 5 0 6 3 3 1 1 9 0 0 1 0 0 0 0 0 0 4 4 4 1 6 2 2 3 4 4 4 0 1 0 0 0 0 0 2 0 0 3 0 0 4 0 0 0 0 0 Output for the Sample Input 1 1 1 2 2 1 1 1 2 2 4 4 3 3 3 4 4 5 6 6 1 1 1 1 1 1 1 1 1 NA
| 38,686
|
Problem G: Rolling Dice The north country is conquered by the great shogun-sama (which means king). Recently many beautiful dice which were made by order of the great shogun-sama were given to all citizens of the country. All citizens received the beautiful dice with a tear of delight. Now they are enthusiastically playing a game with the dice. The game is played on grid of h * w cells that each of which has a number, which is designed by the great shogun-sama's noble philosophy. A player put his die on a starting cell and move it to a destination cell with rolling the die. After rolling the die once, he takes a penalty which is multiple of the number written on current cell and the number printed on a bottom face of the die, because of malicious conspiracy of an enemy country. Since the great shogun-sama strongly wishes, it is decided that the beautiful dice are initially put so that 1 faces top, 2 faces south, and 3 faces east. You will find that the number initially faces north is 5, as sum of numbers on opposite faces of a die is always 7. Needless to say, idiots those who move his die outside the grid are punished immediately. The great shogun-sama is pleased if some citizens can move the beautiful dice with the least penalty when a grid and a starting cell and a destination cell is given. Other citizens should be sent to coal mine (which may imply labor as slaves). Write a program so that citizens can deal with the great shogun-sama's expectations. Input The first line of each data set has two numbers h and w , which stands for the number of rows and columns of the grid. Next h line has w integers, which stands for the number printed on the grid. Top-left corner corresponds to northwest corner. Row number and column number of the starting cell are given in the following line, and those of the destination cell are given in the next line. Rows and columns are numbered 0 to h -1, 0 to w -1, respectively. Input terminates when h = w = 0. Output For each dataset, output the least penalty. Constraints 1 †h , w †10 0 †number assinged to a cell †9 the start point and the goal point are different. Sample Input 1 2 8 8 0 0 0 1 3 3 1 2 5 2 8 3 0 1 2 0 0 2 2 3 3 1 2 5 2 8 3 0 1 2 0 0 1 2 2 2 1 2 3 4 0 0 0 1 2 3 1 2 3 4 5 6 0 0 1 2 0 0 Output for the Sample Input 24 19 17 6 21
| 38,687
|
Low Range-Sum Matrix You received a card at a banquet. On the card, a matrix of $N$ rows and $M$ columns and two integers $K$ and $S$ are written. All the elements in the matrix are integers, and an integer at the $i$-th row from the top and the $j$-th column from the left is denoted by $A_{i,j}$. You can select up to $K$ elements from the matrix and invert the sign of the elements. If you can make a matrix such that there is no vertical or horizontal contiguous subsequence whose sum is greater than $S$, you can exchange your card for a prize. Your task is to determine if you can exchange a given card for a prize. Input The input consists of a single test case of the following form. $N$ $M$ $K$ $S$ $A_{1,1}$ $A_{1,2}$ ... $A_{1,M}$ : $A_{N,1}$ $A_{N,2}$ ... $A_{N,M}$ The first line consists of four integers $N, M, K$ and $S$ ($1 \leq N, M \leq 10, 1 \leq K \leq 5, 1 \leq S \leq 10^6$). The following $N$ lines represent the matrix in your card. The ($i+1$)-th line consists of $M$ integers $A_{i,1}, A_{i,2}, ..., A_{i, M}$ ($-10^5 \leq A_{i,j} \leq 10^5$). Output If you can exchange your card for a prize, print ' Yes '. Otherwise, print ' No '. Sample Input 1 3 3 2 10 5 3 7 2 6 1 3 4 1 Output for Sample Input 1 Yes The sum of a horizontal contiguous subsequence from $A_{1,1}$ to $A_{1,3}$ is $15$. The sum of a vertical contiguous subsequence from $A_{1,2}$ to $A_{3,2}$ is $13$. If you flip the sign of $A_{1,2}$, there is no vertical or horizontal contiguous subsequence whose sum is greater than $S$. Sample Input 2 2 3 1 5 4 8 -2 -2 -5 -3 Output for Sample Input 2 Yes Sample Input 3 2 3 1 5 9 8 -2 -2 -5 -3 Output for Sample Input 3 No Sample Input 4 2 2 3 100 0 0 0 0 Output for Sample Input 4 Yes
| 38,688
|
Dice II Construct a dice from a given sequence of integers in the same way as Dice I . You are given integers on the top face and the front face after the dice was rolled in the same way as Dice I . Write a program to print an integer on the right side face. Input In the first line, six integers assigned to faces are given in ascending order of their corresponding labels. In the second line, the number of questions $q$ is given. In the following $q$ lines, $q$ questions are given. Each question consists of two integers on the top face and the front face respectively. Output For each question, print the integer on the right side face. Constraints $0 \leq $ the integer assigned to a face $ \leq 100$ The integers are all different $1 \leq q \leq 24$ Sample Input 1 2 3 4 5 6 3 6 5 1 3 3 2 Sample Output 3 5 6
| 38,689
|
Problem E: ã¢ããã çæãç¶ãããé·ãã£ãããã§çãã£ããããªå€ãããããçµããããšããŠããã ãããª8æäžæ¬ã®ããæ¥ããšãã2D奜ããªäººç©ãšãã®å
茩ã®slipã¯ãã¢ããããµããŒã©ã€ããéç§°ã¢ããããšåŒã°ããã€ãã³ãã«åå ããŠããã ã¢ããããšã¯ãããŸããŸãªã¢ãã¡ãœã³ã°ã¢ãŒãã£ã¹ããã¡ãéçµãããæ¥æ¬åœå
æå€§ã®ã¢ãã¡ãœã³ã°ã©ã€ãã€ãã³ãã§ããã ä»å¹Žã®ã¢ãããã¯ãå
¬åŒã§å
¬è¡šãããŠããã¢ãŒãã£ã¹ãã®ä»ã«ãã·ãŒã¯ã¬ããã§è¶
è±ªè¯ææãåºæŒããå€§çæ³ã®å
ã«å¹ãéããã ã¢ãããã«ã¯ååæŠã ã£ã2D奜ããªåœŒã¯ãã©ã€ãåŸã®äœé»ã«ã²ããã€ã€ããã²ãšã€ã®çåãæ±ããŠããã ãã¢ãããã«åºæŒããã¢ãŒãã£ã¹ãã¯ã©ã®ããã«æ±ºããŠããã®ã ãããïŒã 圌ã¯ãæ°ããã¢ãŒãã£ã¹ãã®äžãããåºæŒã¢ãŒãã£ã¹ãã®éžåºãããã®ã«ã次ã®ãããªæ¹æ³ãããã®ã§ã¯ãªãããšãéžåºæ³ãèããŠã¿ãã ãŸããã¢ãããã®ã¢ãŒãã£ã¹ãã«ã¯ãã·ãŒã¯ã¬ããã¢ãŒãã£ã¹ããšã¹ã¿ã³ããŒãã¢ãŒãã£ã¹ãã®2çš®é¡ã®åé¡ããããã®ãšããã ã·ãŒã¯ã¬ããã¢ãŒãã£ã¹ããšã¯ãã©ã€ãã«åºæŒããããšãäºåå
¬è¡šãããã©ã€ãæ¬çªã«ãªã£ãŠçªç¶çŸããã¢ãŒãã£ã¹ãã®ããšãæãã ã¹ã¿ã³ããŒãã¢ãŒãã£ã¹ããšã¯ãã©ã€ãã«åºæŒããããšãäºåã«å
¬è¡šããŠããã¢ãŒãã£ã¹ãã®ããšãæãã å
šãŠã®ã¢ãŒãã£ã¹ãã¯ã次ã®ã¹ããŒã¿ã¹ãæã€ã ã¢ãŒãã£ã¹ãåïŒæåå ã¢ãŒãã£ã¹ããéãããã®éé¡ïŒä»¥äžãéçšéãšåŒã¶ïŒïŒèªç¶æ° ãã®ã¢ãŒãã£ã¹ããåºæŒããããšã§ãã客ãã©ãã»ã©æºè¶³ããããããïŒä»¥äžãæºè¶³åºŠãšåŒã¶ïŒïŒèªç¶æ° ä»åãã©ã€ãã«åºæŒããã¢ãŒãã£ã¹ããéžã¶ããã«ãã·ãŒã¯ã¬ããã¢ãŒãã£ã¹ãåè£ N 人ãã¹ã¿ã³ããŒãã¢ãŒãã£ã¹ãåè£ M 人ãããã§ã«çšæãããŠãããã®ãšãããããã«ãã©ã€ãã®äž»å¬è
ã¯ãã¢ãŒãã£ã¹ããéçšããããã«äœ¿çšã§ããè³é LIMIT ãæã£ãŠãããã®ãšããã äž»å¬è
ã¯ãæ¬¡ã®æ¡ä»¶ãæºããããã«ãã¢ãŒãã£ã¹ããéžåºããªããã°ãªããªãã N 人ã®ã·ãŒã¯ã¬ããã¢ãŒãã£ã¹ãæ ããã1人以äžã2人以äžãéžåºãã(1人or2人ãªã®ã¯ãã·ãŒã¯ã¬ãããããªãã£ããå€ãã£ããããããšãé¿ããããã§ãã) M 人ã®ã¹ã¿ã³ããŒãã¢ãŒãã£ã¹ãæ ããã X 人以äžã®ã¢ãŒãã£ã¹ããéžåºãã ã¢ãŒãã£ã¹ããå
šãŠéžåºãçµãããšããéçšéã®åèšãã LIMIT 以äžã«ãã éžåºããã¢ãŒãã£ã¹ãå
šå¡ã§åŸãããæºè¶³åºŠã®åèšãæå€§åãã ããŠããããŸã§éžåºæ³ãèãã2D奜ããªåœŒã¯ããã®æ¹æ³ã§ããã°ã©ã ãæžããŠã¿ãããšæã£ãããããã圌ã¯éžåºæ³ãèããã®ã«æ°åã䜿ã£ãŠããŸããããã°ã©ã ãæžãæ°åããªããªã£ãŠããŸã£ããããªã®ã§ã圌ã®ä»£ããã«ããã°ã©ã ãæžããŠãããŠã»ããã ããªãã®ä»äºã¯ãäžèšã®éžåºæ³ã«åŸããã¢ãŒãã£ã¹ããéžåºãããšãã®ãå®¢ã®æå€§æºè¶³åºŠãåºåããããã°ã©ã ãäœæããããšã§ããã Input å
¥åã¯ãè€æ°ã®ããŒã¿ã»ãããããªããããŒã¿ã»ããã®ç·æ°ã¯20以äžã§ããã åããŒã¿ã»ããã¯ã次ã®åœ¢ãããŠããã LIMIT N M X SEC_NAME 1 SEC_E 1 SEC_S 1 ... SEC_NAME i SEC_E i SEC_S i ... SEC_NAME N SEC_E N SEC_S N NAME 1 E 1 S 1 ... NAME i E i S i ... NAME M E M S M æŽæ° LIMIT ( 4 †LIMIT †1000 )ã N ( 2 †N †100 )ã M ( 2 †M †100 )ã X ( 2 †X †M )ã¯ã ããããã¢ãŒãã£ã¹ããéçšããã®ã«äœ¿çšã§ããè³éãã·ãŒã¯ã¬ããã¢ãŒãã£ã¹ãåè£ã®æ°ãã¹ã¿ã³ããŒãã¢ãŒãã£ã¹ãåè£ã®æ°ãã¹ã¿ã³ããŒãã¢ãŒãã£ã¹ãããéžåºããªããã°ãªããªãæäœäººæ°ã衚ãã SEC_NAME i ã NAME i ãã¯ããããã·ãŒã¯ã¬ããã¢ãŒãã£ã¹ãåè£ãã¹ã¿ã³ããŒãã¢ãŒãã£ã¹ãåè£ã®ååãæã30æå以äžã®æååã§ããã æååã«ã¯ãã¢ã«ãã¡ããã('A'-'Z', 'a'-'z')ã®ã¿ã䜿çšãããã åãã¢ãŒãã£ã¹ãåã2å以äžåºçŸããããšã¯ãªãã æŽæ° SEC_E i ã E i ( 1 †SEC_E i , E i †10 )ã SEC_S i ã S i ( 1 †SEC_S i , S i †10 ) ã¯ãããããã·ãŒã¯ã¬ããã¢ãŒãã£ã¹ãåè£ã®éçšéãã¹ã¿ã³ããŒãã¢ãŒãã£ã¹ãåè£ã®éçšéãã·ãŒã¯ã¬ããã¢ãŒãã£ã¹ãåè£ãåºæŒãããšãã«åŸãããæºè¶³åºŠãã¹ã¿ã³ããŒãã¢ãŒãã£ã¹ãåè£ãåºæŒãããšãã«åŸãããæºè¶³åºŠã衚ãã å
¥åã®çµäºã¯ã0ã4ã€ã®è¡ã§ç€ºãããããã®ããŒã¿ã«ã€ããŠã¯åŠçããå¿
èŠã¯ãªãã Output éžåºæ³ãé©çšããŠã¢ãŒãã£ã¹ããéžåºãããšãããå®¢ã®æºè¶³åºŠã®æå€§å€ãåºåããã ã¢ãŒãã£ã¹ãã®éžåºã®ä»æ¹ã¯ãå¿
ããããšä»®å®ããŠããã Sample Input 100 2 2 2 A 5 6 B 7 8 C 1 2 D 3 4 27 2 3 3 A 8 10 B 8 10 C 6 7 D 5 4 E 8 9 27 2 3 2 A 8 10 B 8 10 C 6 7 D 5 4 E 8 9 44 3 6 5 YamatoNoHito 9 10 ZettoNoHito 9 10 TMR 10 10 SkillNoGroup 8 10 NanaSama 6 9 FRPSD 6 8 Magi3rdDeshi 5 7 Magi13thDeshi 2 2 MagicalItoh 4 6 0 0 0 0 Output for Sample Input 20 30 31 55
| 38,690
|
Movie Problem 倪éåã¯å€äŒã¿ã®éãæ¯æ¥ïŒã€ã®æ ç»ãè¿æã®æ ç»é€šã§èŠãããšã«ããŸããã ïŒå€ªéåã®å€äŒã¿ã¯8æ1æ¥ãã8æ31æ¥ãŸã§ã®31æ¥éãããŸããïŒ ãã®æ ç»é€šã§ã¯ãå€äŒã¿ã®éã« n ã€ã®æ ç»ãäžæ ãããããšã«ãªã£ãŠããŸãã ããããã®æ ç»ã«ã¯ 1 ãã n ãŸã§ã®çªå·ãå²ãåœãŠãããŠããã i çªç®ã®æ ç»ã¯8æ a i æ¥ãã8æ b i æ¥ã®éã ãäžæ ãããŸãã 倪éåã¯æ ç»ãèŠãæããããåããŠèŠãæ ç»ã ã£ãå Žå㯠100 ã®å¹žçŠåºŠãåŸãããšãã§ããŸãã ããããéå»ã« 1 床ã§ãèŠãããšã®ããæ ç»ã ã£ãå Žå㯠50 ã®å¹žçŠåºŠãåŸãŸãã 倪éåã¯äžæ ãããæ ç»ã®äºå®è¡šãããšã«ãå€äŒã¿ã®èšç»ãç«ãŠãããšã«ããŸããã 倪éåãåŸããã幞çŠåºŠã®åèšå€ãæå€§ã«ãªãããã«æ ç»ãèŠããšãã®åèšå€ãæ±ããŠãã ããã ã©ã®æ¥ãå¿
ã1ã€ä»¥äžã®æ ç»ãäžæ ãããŠããããšãä¿èšŒãããŸãã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã n a 1 b 1 a 2 b 2 ... a n b n 1è¡ç®ã«ã1ã€ã®æŽæ° n ãäžããããã 2è¡ç®ããã® n è¡ã®ãã¡ i è¡ç®ã«ã¯ 2 ã€ã®æŽæ° a i , b i ã空çœåºåãã§äžããããã Constraints 1 †n †100 1 †a i †b i †31 (1 †i †n ) Output 倪éåã®åŸããã幞çŠåºŠã®åèšå€ã®æå€§å€ãåºåããã Sample Input 1 4 1 31 2 2 2 3 3 3 Sample Output 1 1700 Sample Input 2 5 1 10 10 20 20 21 22 31 4 20 Sample Output 2 1800
| 38,691
|
Score : 1600 points Problem Statement Ringo got interested in modern art. He decided to draw a big picture on the board with N+2 rows and M+2 columns of squares constructed in the venue of CODE FESTIVAL 2017, using some people. The square at the (i+1) -th row and (j+1) -th column in the board is represented by the pair of integers (i,j) . That is, the top-left square is (0,0) , and the bottom-right square is (N+1,M+1) . Initially, the squares (x,y) satisfying 1 \leq x \leq N and 1 \leq y \leq M are painted white, and the other (outermost) squares are painted black. Ringo arranged people at some of the outermost squares, facing inward. More specifically, the arrangement of people is represented by four strings A , B , C and D , as follows: For each row except the top and bottom, if the i -th character (1 \leq i \leq N) in A is 1 , place a person facing right at the square (i,0) ; otherwise, do nothing. For each row except the top and bottom, if the i -th character (1 \leq i \leq N) in B is 1 , place a person facing left at the square (i,M+1) ; otherwise, do nothing. For each column except the leftmost and rightmost, if the i -th character (1 \leq i \leq M) in C is 1 , place a person facing down at the square (0,i) ; otherwise, do nothing. For each column except the leftmost and rightmost, if the i -th character (1 \leq i \leq M) in D is 1 , place a person facing up at the square (N+1,i) ; otherwise, do nothing. Each person has a sufficient amount of non-white paint. No two people have paint of the same color. An example of an arrangement of people (For convenience, black squares are displayed in gray) Ringo repeats the following sequence of operations until all people are dismissed from the venue. Select a person who is still in the venue. The selected person repeats the following action while the square in front of him/her is white: move one square forward, and paint the square he/she enters with his/her paint. When the square in front of him/her is not white, he/she stops doing the action. The person is now dismissed from the venue. An example of a way the board is painted How many different states of the board can Ringo obtain at the end of the process? Find the count modulo 998244353 . Two states of the board are considered different when there is a square painted in different colors. Constraints 1 \leq N,M \leq 10^5 |A|=|B|=N |C|=|D|=M A , B , C and D consist of 0 and 1 . Input Input is given from Standard Input in the following format: N M A B C D Output Print the number of the different states of the board Ringo can obtain at the end of the process, modulo 998244353 . Sample Input 1 2 2 10 01 10 01 Sample Output 1 6 There are six possible states as shown below. Sample Input 2 2 2 11 11 11 11 Sample Output 2 32 Sample Input 3 3 4 111 111 1111 1111 Sample Output 3 1276 Sample Input 4 17 21 11001010101011101 11001010011010111 111010101110101111100 011010110110101000111 Sample Output 4 548356548 Be sure to find the count modulo 998244353 . Sample Input 5 3 4 000 101 1111 0010 Sample Output 5 21 Sample Input 6 9 13 111100001 010101011 0000000000000 1010111111101 Sample Output 6 177856 Sample Input 7 23 30 01010010101010010001110 11010100100100101010101 000101001001010010101010101101 101001000100101001010010101000 Sample Output 7 734524988
| 38,692
|
Score : 600 points Problem Statement Given are two sequences A and B , both of length N . A and B are each sorted in the ascending order. Check if it is possible to reorder the terms of B so that for each i ( 1 \leq i \leq N ) A_i \neq B_i holds, and if it is possible, output any of the reorderings that achieve it. Constraints 1\leq N \leq 2 \times 10^5 1\leq A_i,B_i \leq N A and B are each sorted in the ascending order. All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 \cdots A_N B_1 B_2 \cdots B_N Output If there exist no reorderings that satisfy the condition, print No . If there exists a reordering that satisfies the condition, print Yes on the first line. After that, print a reordering of B on the second line, separating terms with a whitespace. If there are multiple reorderings that satisfy the condition, you can print any of them. Sample Input 1 6 1 1 1 2 2 3 1 1 1 2 2 3 Sample Output 1 Yes 2 2 3 1 1 1 Sample Input 2 3 1 1 2 1 1 3 Sample Output 2 No Sample Input 3 4 1 1 2 3 1 2 3 3 Sample Output 3 Yes 3 3 1 2
| 38,693
|
ã·ãŒã«ã®éãªã 1 蟺ã®é·ãã 10 ã®æ£æ¹åœ¢ã®æãçŽã«ååŸ 1 ã®å圢ã®ã·ãŒã«ã n æè²ŒããŸããã·ãŒã«ã¯éããŠè²Œãããšãã§ããŸããã·ãŒã«ã貌ãäœçœ®ã®åº§æšãèªã¿èŸŒãã§ãæãçŽäžã§ãã£ãšãå€ãã·ãŒã«ãéãªã£ãŠããå Žæ(ã·ãŒã«ãïŒæã ãã§ã"éãªã£ãŠãã"ãšãã)ã§ã®ã·ãŒã«ã®ææ°ãåºåããããã°ã©ã ãäœæããŠãã ããã æãçŽã®å·Šäžãåç¹ãšãã x, y 座æšãäžããŸãããã® x, y ãåã®äžå¿ãšããŠã·ãŒã«ã貌ãããšãšããŸããåã®äžå¿ãæãçŽã®å€ã«åºãããšã¯ãããŸããããŸããåäžåº§æšã«è€æ°ã®ã·ãŒã«ã貌ãããããšã¯ãããŸããã Input è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã¯ä»¥äžã®ãããªåœ¢åŒã§äžããããŸãã n x 1 , y 1 x 2 , y 2 : x n , y n ïŒè¡ç®ã«ã·ãŒã«ã®ææ° n (0 †100) ãäžããããŸããç¶ã n è¡ã«ãåã·ãŒã«ã®äžå¿åº§æšãäžããããŸãã x i , y i 㯠i æç®ã®ã·ãŒã«ã®äžå¿ã® x 座æšãš y 座æšã衚ããŸããåå€ã¯å°æ°ç¹ä»¥äžæå€§ 6 æ¡ãŸã§ã®æ°åãå«ã宿°ã§äžããããŸãã n ã 0 ã®ãšããå
¥åã®æåŸãšããŸããããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã Output åããŒã¿ã»ããã«å¯ŸããæãçŽäžã§æãå€ãã·ãŒã«ãéãªã£ãŠããå Žæã§ã®ã·ãŒã«ã®ææ°ïŒæŽæ°ïŒãåºåããŠäžããã Sample Input 15 3.14979,8.51743 2.39506,3.84915 2.68432,5.39095 5.61904,9.16332 7.85653,4.75593 2.84021,5.41511 1.79500,8.59211 7.55389,8.17604 4.70665,4.66125 1.63470,4.42538 7.34959,4.61981 5.09003,8.11122 5.24373,1.30066 0.13517,1.83659 7.57313,1.58150 0 Output for the Sample Input 4 Hint å
¥åäŸã®ããã«ã·ãŒã«ã貌ã£ãå³ã§ããåã¯ã·ãŒã«ãæ°åã¯å
¥åäŸã®è¡æ°ã衚ããŠããŸãã ç¹(2.3,4.6)ã§ã¯ãå
¥åäŸã® 2 è¡ç®ã3 è¡ç®ã6 è¡ç®ã10 è¡ç®ã® 4 æã®ã·ãŒã«ãéãªã£ãŠããŸãã 6 ãš 9 ã®ãã®ãã®ã®äžå¿ã®è·é¢ã¯ 2.01293 ãªã®ã§ãã·ãŒã«ã¯éãªã£ãŠããŸããã1 ãš 12 ã®ãã®ãã®ã®äžå¿ã®è·é¢ã¯ 1.98231 ãªã®ã§ãã·ãŒã«ã¯éãªã£ãŠããŸãã ïŒã€ã®åãæ¥ããŠãããšãïŒãã®ãã®ã®äžå¿ã®è·é¢ã 2 ã®ãšãïŒã¯ãéãªã£ãŠãããã®ãšããŸãã
| 38,694
|
Problem J: Demon's Plan BackGround ããŒã¢ã³ãºãã©ã³ã§ã¯æ
Ÿãåžã108äœã®æªéãæ¥å€ããã°ã©ãã³ã°ã³ã³ãã¹ãã§ãã®ããåã£ãŠãããäž»å¬ã§ããããããŒã³ã¯ãå
šãŠã®æ
Ÿãéãå Žæâãªã¯ã¹ïŒãã°ãâã«æªéãã¡ãæåŸ
ããããšããŠããã ããããŒã³ã¯ãŸã æåŸ
ãéã£ãŠããªãæªéã«æåŸ
ãéãããããæªéã¯äžçåå°ã«ãããèªåã§è¡ãã®ã¯é¢åãããã®ã§èªèº«ã®äœ¿ãééã«ããããããšã«ããã ããããŒã³ã¯æ°ãå©ãã®ã§äœ¿ãéå士ãããå¹³çã«åãããã«ã©ã®äœ¿ãéãã©ã®æªéãæ
åœããããå²ãæ¯ãããšããŠããã Problem N äœã®äœ¿ãéãš M äœã®æªéãããã 䜿ãé i ãš æªé j ã®è·é¢ã¯ H i j ã§ããã åæªéã«å¿
ã1人ã®äœ¿ãéãåããããããã©ã®äœ¿ãéãã©ã®æªéã蚪åãããã¯ä»¥äžã®æ¡ä»¶ã«åŸã£ãŠå²ãæ¯ãããšã«ããã 䜿ãé1äœãããã®èšªåããæªéã®æ°ã®å·®ã®æå€§ãæå°åããã 1ãæºãããäžã§èšªåããæªéãšæ
åœãã䜿ãéã®è·é¢ã®æå€§ãæå°åããã 1è¡ç®ã«äœ¿ãé1äœãããã®èšªåããæªéã®æ°ã®å·®ã®æå€§ãã2è¡ç®ã«æªéãšæ
åœãã䜿ãéã®è·é¢ã®æå€§ãåºåããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã N M H 0 0 H 0 1 ⊠H 0 Mâ1 H 1 0 H 1 1 ⊠H 1 Mâ1 . . H Nâ1 0 H Nâ1 1 ⊠H Nâ1 Mâ1 1è¡ç®ã«äœ¿ãéã®æ° N ãšæªéã®æ° M ãæŽæ°ã§ç©ºçœåºåãã§äžããããã ç¶ã N è¡ã«äœ¿ãéãšæªéã®è·é¢ãæŽæ°ã§äžããããã H ij ã¯äœ¿ãé i ãšæªé j ã®è·é¢ã衚ãã Constraints 1 †N †108 1 †M †108 1 †H i j †10 9 ( 0 †i < N , 0 †j < M ) ( 䜿ãé i ããæªé j ãŸã§ã®è·é¢ ) Output åé¡æã®æ¡ä»¶ã«åŸãã1è¡ç®ã«äœ¿ãé1äœãããã®èšªåããæªéã®æ°ã®å·®ã®æå€§ãã2è¡ç®ã«æªéãšæ
åœãã䜿ãéã®è·é¢ã®æå€§ãåºåããã Sample Input 1 3 3 1 2 3 2 1 2 3 2 1 Sample Output 1 0 1 䜿ãé 0 - æªé 0 䜿ãé 1 - æªé 1 䜿ãé 2 - æªé 2 ãšå²ãæ¯ãããšã§èšªåããæªéã®æ°ã®å·®ã0ã«ãªããæ
åœäœ¿ãéãšæªéã®è·é¢ã®æå€§ã1ã«ãªãæé©ãªçµã¿åããã«ãªãã Sample Input 2 3 5 1 2 3 4 5 5 4 3 2 1 4 3 2 1 5 Sample Output 2 1 2 䜿ãé 0 - æªé 0 䜿ãé 0 - æªé 1 䜿ãé 1 - æªé 4 䜿ãé 2 - æªé 3 䜿ãé 2 - æªé 2 ãšå²ãæ¯ãããšã§èšªåããæªéã®å·®ã1ã«ãªããæ
åœäœ¿ãéãšæªéã®è·é¢ã®æå€§ã2ã«ãªãæé©ãªçµã¿åããã«ãªãã
| 38,695
|
Score : 500 points Problem Statement You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N . You would like to sort this sequence in ascending order by repeating the following operation: Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of operations required. It can be proved that it is actually possible to sort the sequence using this operation. Constraints 1 \leq N \leq 2\times 10^5 (P_1,P_2,...,P_N) is a permutation of (1,2,...,N) . All values in input are integers. Input Input is given from Standard Input in the following format: N P_1 : P_N Output Print the minimum number of operations required. Sample Input 1 4 1 3 2 4 Sample Output 1 2 For example, the sequence can be sorted in ascending order as follows: Move 2 to the beginning. The sequence is now (2,1,3,4) . Move 1 to the beginning. The sequence is now (1,2,3,4) . Sample Input 2 6 3 2 5 1 4 6 Sample Output 2 4 Sample Input 3 8 6 3 1 2 7 4 8 5 Sample Output 3 5
| 38,696
|
Problem D : Numbers n ãäžããããã®ã§ã n åã®é£ç¶ããæ£ã®æŽæ°ãæ±ããã ãã ããã¹ãŠã®æ°ããïŒãšãã®æ°èªèº«ä»¥å€ã®çŽæ°ããããªããŠã¯ãªããªãã Input å
¥åã¯ä»¥äžã®ãã©ãŒãããã§äžããããã n å
¥åã¯ä»¥äžã®å¶çŽãæºããã 1 †n †1,500 Output æåã®è¡ã«ãããªããéžãã é£ç¶ãã n åã®æ£ã®æŽæ°ã®äžã§äžçªå°ãããã®ãåºåããã 2è¡ç®ãã n+1 è¡ç®ã«ãããããã®å€ã«å¯ŸããçŽæ°ãåºåããã çŽæ°ã¯1ããã®æ°èªèº«ã§ãªããã°ã©ã®å€ãåºåããŠãè¯ãã 1è¡ç®ã«åºåããæ°ã x ãšããŠãiè¡ç®ã«ã¯ x+i-2 ã®çŽæ°ãåºåããã åºåããå€ã¯5,000æ¡ãè¶
ããŠã¯ãããªãã Sample Input 1 2 Sample Output 1 8 2 3 Sample Input 2 3 Sample Output 2 8 2 3 5 Hint Sample Output 2ã§ã¯ã8,9,10ã3åã®é£ç¶ããæŽæ°ãšããŠéžãã§ããã 2è¡ç®ã«ã8ã®çŽæ°ãšããŠ2,3è¡ç®ã¯9ã®çŽæ°ãšããŠ3,ïŒè¡ç®ã«ã¯10ã®çŽæ°ãšããŠ5,ãåºåããŠããã
| 38,697
|
Problem Statement Fox Ciel is practicing miniature golf, a golf game played with a putter club only. For improving golf skills, she believes it is important how well she bounces the ball against walls. The field of miniature golf is in a two-dimensional plane and surrounded by $N$ walls forming a convex polygon. At first, the ball is placed at $(s_x, s_y)$ inside the field. The ball is small enough to be regarded as a point. Ciel can shoot the ball to any direction and stop the ball whenever she wants. The ball will move in a straight line. When the ball hits the wall, it rebounds like mirror reflection (i.e. incidence angle equals reflection angle). For practice, Ciel decided to make a single shot under the following conditions: The ball hits each wall of the field exactly once. The ball does NOT hit the corner of the field. Count the number of possible orders in which the ball hits the walls. Input The input contains several datasets. The number of datasets does not exceed $100$. Each dataset is in the following format. $N$ $s_x$ $s_y$ $x_1$ $y_1$ : : $x_N$ $y_N$ The first line contains an integer $N$ ($3 \leq N \leq 8$). The next line contains two integers $s_x$ and $s_y$ ($-50 \leq s_x, s_y \leq 50$), which describe the coordinates of the initial position of the ball. Each of the following $N$ lines contains two integers $x_i$ and $y_i$ ($-50 \leq x_i, y_i \leq 50$), which describe the coordinates of each corner of the field. The corners are given in counterclockwise order. You may assume given initial position $(s_x, s_y)$ is inside the field and the field is convex. It is guaranteed that there exists a shoot direction for each valid order of the walls that satisfies the following condition: distance between the ball and the corners of the field $(x_i, y_i)$ is always greater than $10^{-6}$ until the ball hits the last wall. The last dataset is followed by a line containing a single zero. Output For each dataset in the input, print the number of valid orders of the walls in a line. Sample Input 4 0 0 -10 -10 10 -10 10 10 -10 10 0 Output for the Sample Input 8
| 38,698
|
Score : 500 points Problem Statement For a finite set of integers X , let f(X)=\max X - \min X . Given are N integers A_1,...,A_N . We will choose K of them and let S be the set of the integers chosen. If we distinguish elements with different indices even when their values are the same, there are {}_N C_K ways to make this choice. Find the sum of f(S) over all those ways. Since the answer can be enormous, print it \bmod (10^9+7) . Constraints 1 \leq N \leq 10^5 1 \leq K \leq N |A_i| \leq 10^9 Input Input is given from Standard Input in the following format: N K A_1 ... A_N Output Print the answer \bmod (10^9+7) . Sample Input 1 4 2 1 1 3 4 Sample Output 1 11 There are six ways to choose S : \{1,1\},\{1,3\},\{1,4\},\{1,3\},\{1,4\}, \{3,4\} (we distinguish the two 1 s). The value of f(S) for these choices are 0,2,3,2,3,1 , respectively, for the total of 11 . Sample Input 2 6 3 10 10 10 -10 -10 -10 Sample Output 2 360 There are 20 ways to choose S . In 18 of them, f(S)=20 , and in 2 of them, f(S)=0 . Sample Input 3 3 1 1 1 1 Sample Output 3 0 Sample Input 4 10 6 1000000000 1000000000 1000000000 1000000000 1000000000 0 0 0 0 0 Sample Output 4 999998537 Print the sum \bmod (10^9+7) .
| 38,699
|
Problem D: Organize Your Train In the good old Hachioji railroad station located in the west of Tokyo, there are several parking lines, and lots of freight trains come and go every day. All freight trains travel at night, so these trains containing various types of cars are settled in your parking lines early in the morning. Then, during the daytime, you must reorganize cars in these trains according to the request of the railroad clients, so that every line contains the ârightâ train, i.e. the right number of cars of the right types, in the right order. As shown in Figure 7, all parking lines run in the East-West direction. There are exchange lines connecting them through which you can move cars. An exchange line connects two ends of different parking lines. Note that an end of a parking line can be connected to many ends of other lines. Also note that an exchange line may connect the East-end of a parking line and the West-end of another. Cars of the same type are not discriminated between each other. The cars are symmetric, so directions of cars donât matter either. You can divide a train at an arbitrary position to make two sub-trains and move one of them through an exchange line connected to the end of its side. Alternatively, you may move a whole train as is without dividing it. Anyway, when a (sub-) train arrives at the destination parking line and the line already has another train in it, they are coupled to form a longer train. Your superautomatic train organization system can do these without any help of locomotive engines. Due to the limitation of the system, trains cannot stay on exchange lines; when you start moving a (sub-) train, it must arrive at the destination parking line before moving another train. In what follows, a letter represents a car type and a train is expressed as a sequence of letters. For example in Figure 8, from an initial state having a train " aabbccdee " on line 0 and no trains on other lines, you can make " bbaadeecc " on line 2 with the four moves shown in the figure. To cut the cost out, your boss wants to minimize the number of (sub-) train movements. For example, in the case of Figure 8, the number of movements is 4 and this is the minimum. Given the configurations of the train cars in the morning (arrival state) and evening (departure state), your job is to write a program to find the optimal train reconfiguration plan. Input The input consists of one or more datasets. A dataset has the following format: x y p 1 P 1 q 1 Q 1 p 2 P 2 q 2 Q 2 . . . p y P y q y Q y s 0 s 1 . . . s x -1 t 0 t 1 . . . t x -1 x is the number of parking lines, which are numbered from 0 to x -1. y is the number of exchange lines. Then y lines of the exchange line data follow, each describing two ends connected by the exchange line; p i and q i are integers between 0 and x - 1 which indicate parking line numbers, and P i and Q i are either " E " (East) or " W " (West) which indicate the ends of the parking lines. Then x lines of the arrival (initial) configuration data, s 0 , ... , s x -1 , and x lines of the departure (target) configuration data, t 0 , ... t x -1 , follow. Each of these lines contains one or more lowercase letters " a ", " b ", ..., " z ", which indicate types of cars of the train in the corresponding parking line, in west to east order, or alternatively, a single " - " when the parking line is empty. You may assume that x does not exceed 4, the total number of cars contained in all the trains does not exceed 10, and every parking line has sufficient length to park all the cars. You may also assume that each dataset has at least one solution and that the minimum number of moves is between one and six, inclusive. Two zeros in a line indicate the end of the input. Output For each dataset, output the number of moves for an optimal reconfiguration plan, in a separate line. Sample Input 3 5 0W 1W 0W 2W 0W 2E 0E 1E 1E 2E aabbccdee - - - - bbaadeecc 3 3 0E 1W 1E 2W 2E 0W aabb bbcc aa bbbb cc aaaa 3 4 0E 1W 0E 2E 1E 2W 2E 0W ababab - - aaabbb - - 0 0 Output for the Sample Input 4 2 5
| 38,700
|
Score : 800 points Problem Statement Takahashi and Aoki will play a game using a grid with H rows and W columns of square cells. There are N obstacles on this grid; the i -th obstacle is at (X_i,Y_i) . Here, we represent the cell at the i -th row and j -th column (1 \leq i \leq H, 1 \leq j \leq W) by (i,j) . There is no obstacle at (1,1) , and there is a piece placed there at (1,1) . Starting from Takahashi, he and Aoki alternately perform one of the following actions: Move the piece to an adjacent cell. Here, let the position of the piece be (x,y) . Then Takahashi can only move the piece to (x+1,y) , and Aoki can only move the piece to (x,y+1) . If the destination cell does not exist or it is occupied by an obstacle, this action cannot be taken. Do not move the piece, and end his turn without affecting the grid. The game ends when the piece does not move twice in a row. Takahashi would like to perform as many actions (including not moving the piece) as possible before the game ends, while Aoki would like to perform as few actions as possible before the game ends. How many actions will Takahashi end up performing? Constraints 1 \leq H,W \leq 2\times 10^5 0 \leq N \leq 2\times 10^5 1 \leq X_i \leq H 1 \leq Y_i \leq W If i \neq j , (X_i,Y_i) \neq (X_j,Y_j) (X_i,Y_i) \neq (1,1) X_i and Y_i are integers. Input Input is given from Standard Input in the following format: H W N X_1 Y_1 : X_N Y_N Output Print the number of actions Takahashi will end up performing. Sample Input 1 3 3 1 3 2 Sample Output 1 2 For example, the game proceeds as follows: Takahashi moves the piece to (2,1). Aoki does not move the piece. Takahashi moves the piece to (3,1). Aoki does not move the piece. Takahashi does not move the piece. Takahashi performs three actions in this case, but if both players play optimally, Takahashi will perform only two actions before the game ends. Sample Input 2 10 10 14 4 3 2 2 7 3 9 10 7 7 8 1 10 10 5 4 3 4 2 8 6 4 4 4 5 8 9 2 Sample Output 2 6 Sample Input 3 100000 100000 0 Sample Output 3 100000
| 38,702
|
åé¡ G XOR åè·¯ å顿 èšç®æ©ç§åŠå®éšåæŒç¿ 3 㯠CAD ãçšã㊠CPU ãèšèšããææ¥ã§ããïŒCPU ã¯å€ãã®åè·¯ãçµã¿åãããªããã°åããïŒãã®äžã® 1 ã€ã« n ãããå
¥åã® XOR åè·¯ãããïŒããã§ XOR åè·¯ãšã¯ïŒå
¥åãããå x 1 x 2 ...x n ã«å¯ŸããŠïŒ x 1 + x 2 + ... + x n \ (mod 2) ãåºåããåè·¯ã®ããšãèšãïŒãããå®ç§ã«åäœãã XOR åè·¯ãèšèšããã®ã¯æéããããã®ã§ïŒãšãããã n ãããã®ãã¡ k ãããã ã䜿ã XOR åè·¯ A ãäœãããšã«ããïŒã€ãŸãïŒãã i 1 , ... , i k ãååšãïŒåè·¯ A 㯠x i 1 + x i 2 + ... + x i k \ (mod 2) ãåºåããïŒ æ«ãåŸã«ä»åºŠã¯ k ãããå
¥åã® XOR åè·¯ãæ¬²ãããªã£ãïŒäœã ç°¡åã§ã¯ãªããïŒå
ã»ã©ã®åè·¯ A ã䜿ãã°ããïŒãã æ®å¿µãªããšã«ïŒåè·¯ A ãã©ã® k ãããã䜿ã£ãŠããã®ãå¿ããŠããŸã£ãäžã«ïŒåè·¯ A ã®èšèšå³ãééã£ãŠåé€ããŠããŸã£ãïŒãããã³ã³ãã€ã«æžã¿ã®åè·¯ A ã¯æ®ã£ãŠããïŒãªã®ã§ïŒå
¥å x 1 x 2 ...x n ãå
¥ããŠåè·¯ A ãå®è¡ããããšã§ïŒãã®åºå x i 1 + x i 2 + ... + x i k \ (mod 2) ãèŠãããšã¯åºæ¥ãïŒ åºæ¥ãã ãäœæ¥ã®æéãçããããã®ã§ïŒåè·¯ A ã®å®è¡åæ°ã«ã¯äžéãèšå®ããããšã«ãããïŒã©ãããã°åè·¯AãäŸåããŠããããã i 1 , ... , i k ãèŠã€ããããã ãããïŒ å
¥åºå æåã« n ãš k ãã¹ããŒã¹åºåãã§äžããããïŒä»¥éïŒããã°ã©ã ã¯åè·¯ A ã«å
¥åãäžãïŒãã®åºåãèªãããšãåºæ¥ãïŒäŸãã° C/C++ ã§åè·¯ A ã«ãããå x 1 x 2 ...x n ãäžããã«ã¯ printf("? x 1 x 2 ...x n \n"); fflush(stdout); ãšããïŒããã§å x i ã®éã«ã¹ããŒã¹ããããŠã¯ãªããªãïŒ æ¬¡ã«ïŒ scanf("%d", &v); ãšãããš v ã«å¯Ÿå¿ããåºå x i 1 + x i 2 + ... + x i k \ (mod 2) ãå
¥ãïŒ æçµçã«åè·¯ A ãäŸåããããã i 1 ,...,i k ãåºåããã«ã¯ printf("! i 1 i 2 ...i k \n"); fflush(stdout); ãšããïŒããã§å i j ã®éã¯ã¹ããŒã¹ãäžåºŠ 1 ã€ãã€ãããïŒ å¶çŽ 1 †n †10,000 1 †k †min(10, n) åããŒã¿ã»ããããšã«ïŒåè·¯ A ã®å®è¡åæ°ã®äžé㯠200 åã§ããïŒãããè¶
ãããšèª€ç ( Query Limit Exceeded ) ãšå€å®ãããïŒ å
¥åºåäŸ å
¥åäŸ 1 以äžã®äŸã¯ããã°ã©ã ã®å
¥åºåã®äŸã§ããïŒå·Šã®åã¯ããã°ã©ã ã®åºåïŒå³ã®åã¯ããã°ã©ã ãžã®å
¥åãæç³»åé ã«ç€ºããŠããïŒæåã« n k ãå
¥åãšããŠäžããããïŒããã§ã¯ n = 2, k = 1 ã§ããïŒæ¬¡ã«åè·¯ A ã« 00 ãšããå
¥åãããããšïŒåè·¯ A 㯠0 ãè¿ããïŒæ¬¡ã«åè·¯ A ã« 01 ãšããå
¥åãããããšïŒåè·¯ A ã¯åã³ 0 ãè¿ããïŒãã®ããšããåè·¯ A 㯠1 ãããç®ã®ã¿å©çšããŠããããšãåããïŒããã°ã©ã 㯠1 ãè§£çãšããŠåºåããïŒ ããã°ã©ã ã®åºå ããã°ã©ã ãžã®å
¥å 2 1 ?00 0 ?01 0 !1 å
¥åäŸ 2 以äžã®äŸã§ã¯ïŒ n = 2, k = 2 ã§ããïŒçŽã¡ã«åè·¯ A ã 1 ãããç®ãš 2 ãããç®ã®äž¡æ¹ãå©çšããŠããããšãåããïŒãã£ãŠããã°ã©ã 㯠1 ãš 2 ãè§£çãšããŠåºåããïŒ ããã°ã©ã ã®åºå ããã°ã©ã ãžã®å
¥å 2 2 !1 2
| 38,703
|
Score : 800 points Problem Statement There are N positive integers arranged in a circle. Now, the i -th number is A_i . Takahashi wants the i -th number to be B_i . For this objective, he will repeatedly perform the following operation: Choose an integer i such that 1 \leq i \leq N . Let a, b, c be the (i-1) -th, i -th, and (i+1) -th numbers, respectively. Replace the i -th number with a+b+c . Here the 0 -th number is the N -th number, and the (N+1) -th number is the 1 -st number. Determine if Takahashi can achieve his objective. If the answer is yes, find the minimum number of operations required. Constraints 3 \leq N \leq 2 \times 10^5 1 \leq A_i, B_i \leq 10^9 All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N B_1 B_2 ... B_N Output Print the minimum number of operations required, or -1 if the objective cannot be achieved. Sample Input 1 3 1 1 1 13 5 7 Sample Output 1 4 Takahashi can achieve his objective by, for example, performing the following operations: Replace the second number with 3 . Replace the second number with 5 . Replace the third number with 7 . Replace the first number with 13 . Sample Input 2 4 1 2 3 4 2 3 4 5 Sample Output 2 -1 Sample Input 3 5 5 6 5 2 1 9817 1108 6890 4343 8704 Sample Output 3 25
| 38,704
|
Score : 800 points Problem Statement There are X+Y+Z people, conveniently numbered 1 through X+Y+Z . Person i has A_i gold coins, B_i silver coins and C_i bronze coins. Snuke is thinking of getting gold coins from X of those people, silver coins from Y of the people and bronze coins from Z of the people. It is not possible to get two or more different colors of coins from a single person. On the other hand, a person will give all of his/her coins of the color specified by Snuke. Snuke would like to maximize the total number of coins of all colors he gets. Find the maximum possible number of coins. Constraints 1 \leq X 1 \leq Y 1 \leq Z X+Y+Z \leq 10^5 1 \leq A_i \leq 10^9 1 \leq B_i \leq 10^9 1 \leq C_i \leq 10^9 Input Input is given from Standard Input in the following format: X Y Z A_1 B_1 C_1 A_2 B_2 C_2 : A_{X+Y+Z} B_{X+Y+Z} C_{X+Y+Z} Output Print the maximum possible total number of coins of all colors he gets. Sample Input 1 1 2 1 2 4 4 3 2 1 7 6 7 5 2 3 Sample Output 1 18 Get silver coins from Person 1 , silver coins from Person 2 , bronze coins from Person 3 and gold coins from Person 4 . In this case, the total number of coins will be 4+2+7+5=18 . It is not possible to get 19 or more coins, and the answer is therefore 18 . Sample Input 2 3 3 2 16 17 1 2 7 5 2 16 12 17 7 7 13 2 10 12 18 3 16 15 19 5 6 2 Sample Output 2 110 Sample Input 3 6 2 4 33189 87907 277349742 71616 46764 575306520 8801 53151 327161251 58589 4337 796697686 66854 17565 289910583 50598 35195 478112689 13919 88414 103962455 7953 69657 699253752 44255 98144 468443709 2332 42580 752437097 39752 19060 845062869 60126 74101 382963164 Sample Output 3 3093929975
| 38,705
|
How many ways? Write a program which identifies the number of combinations of three integers which satisfy the following conditions: You should select three distinct integers from 1 to n . A total sum of the three integers is x . For example, there are two combinations for n = 5 and x = 9. 1 + 3 + 5 = 9 2 + 3 + 4 = 9 Input The input consists of multiple datasets. For each dataset, two integers n and x are given in a line. The input ends with two zeros for n and x respectively. Your program should not process for these terminal symbols. Constraints 3 †n †100 0 †x †300 Output For each dataset, print the number of combinations in a line. Sample Input 5 9 0 0 Sample Output 2 Note 解説
| 38,706
|
çããéœåž(Unique Cities) JOI åœã«ã¯$N$ åã®éœåžãããïŒ1 ãã$N$ ãŸã§ã®çªå·ãã€ããŠããïŒãããã®éœåžã¯$N - 1$ æ¬ã®éè·¯ã§çµã°ããŠããïŒ$i$ çªç®($1 \leq i \leq N - 1$) ã®éè·¯ã¯éœåž$A_i$ ãšéœåž$B_i$ ãçµãã§ããïŒåæ¹åã«éè¡å¯èœã§ããïŒã©ã®éœåžããã©ã®éœåžãžãäœæ¬ãã®éè·¯ãéè¡ããããšã§ç§»åã§ããïŒ JOI åœã«ã¯ããã€ãã®ç¹ç£åãååšããïŒç¹ç£åã«ã¯ïŒçš®é¡ã衚ã1 以äž$M$ 以äžã®çªå·ãä»ããããŠãã(JOI åœã§çç£ãããŠããç¹ç£åã«å¯Ÿå¿ããŠããªãçªå·ããããããããªã)ïŒåéœåžã¯1 ã€ã®ç¹ç£åãçç£ããŠããïŒéœåž$j$ ($1 \leq j \leq N$) ã§ã¯ç¹ç£å$C_j$ ãçç£ããŠããïŒè€æ°ã®éœåžãåãçš®é¡ã®ç¹ç£åãçç£ããããšããããããããªãïŒ 2 ã€ã®éœåžã®éã®è·é¢ã¯ïŒãã®éãç§»åããããã«éãéè·¯ã®æ¬æ°ã®æå°å€ã§ããïŒéœåž$x$ ($1 \leq x \leq N$)ããèŠãŠéœåž$y$ ($1 \leq y \leq N, y \ne x$) ãçããéœåžã§ãããšã¯ïŒãã¹ãŠã®éœåž$z$ ($1 \leq z \leq N, z \ne x, z \ne y) ã«ã€ããŠïŒéœåž$x, y$ éã®è·é¢ãšéœåž$x, z$ éã®è·é¢ãç°ãªãããšãæå³ããïŒ JOI åœã®å€§è£ã§ããK çäºé·ã¯ïŒãã¹ãŠã®$j$ ($1 \leq j \leq N$) ã«ã€ããŠïŒéœåž$j$ ããèŠãŠçããéœåžã§çç£ãããŠããç¹ç£åãäœçš®é¡ããããç¥ãããïŒ JOI åœã®éè·¯ã®æ
å ±ãšïŒåéœåžã§çç£ãããŠããç¹ç£åã®çªå·ãäžãããããšãïŒåéœåžããšã«ïŒãã®éœåžããèŠãŠçããéœåžã§çç£ãããŠããç¹ç£åãäœçš®é¡ããããæ±ããããã°ã©ã ãäœæããïŒ å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããïŒ $N$ $M$ $A_1$ $B_1$ : $A_{N-1}$ $B_{N-1}$ $C_1$ ... $C_N$ åºå æšæºåºåã«$N$ è¡ã§åºåããïŒ $j$ è¡ç®($1 \leq j \leq N$) ã«ã¯ïŒéœåž$j$ ããèŠãŠçããéœåžã§çç£ãããŠããç¹ç£åãäœçš®é¡ããããåºåããïŒ å¶çŽ $ 2 \leq N \leq 200 000$ïŒ $ 1 \leq M \leq N$ïŒ $ 1 \leq A_i \leq N (1 \leq i \leq N - 1)ïŒ1 \leq B_i \leq N (1 \leq i \leq N - 1)$ïŒ $ A_i \ne B_i (1 \leq i \leq N - 1)$ïŒ ã©ã®éœåžããã©ã®éœåžãžãäœæ¬ãã®éè·¯ãéè¡ããããšã§ç§»åã§ããïŒ $ 1 \leq C_j \leq M (1 \leq j \leq N)$ïŒ å
¥åºåäŸ å
¥åäŸ1 5 4 1 2 2 3 3 4 3 5 1 2 1 2 4 åºåäŸ1 2 0 1 1 1 éœåž1 ããèŠãŠçããéœåžã¯éœåž2; 3 ã§ããïŒããã§çç£ãããç¹ç£åã¯ç¹ç£å2; 1 ãªã®ã§ïŒçãã¯2çš®é¡ã§ããïŒ éœåž2 ããèŠãŠçããéœåžã¯ååšããªãã®ã§ïŒçãã¯0 çš®é¡ã§ããïŒ éœåž3 ããèŠãŠçããéœåžã¯éœåž1 ã§ããïŒããã§çç£ãããç¹ç£åã¯ç¹ç£å1 ãªã®ã§ïŒçãã¯1 çš®é¡ã§ããïŒ éœåž4 ããèŠãŠçããéœåžã¯éœåž1; 3 ã§ããïŒã©ã¡ãã®éœåžã«ãããŠãçç£ãããç¹ç£åã¯ç¹ç£å1 ãªã®ã§ïŒçãã¯1 çš®é¡ã§ããïŒ éœåž5 ããèŠãŠçããéœåžã¯éœåž1; 3 ã§ããïŒã©ã¡ãã®éœåžã«ãããŠãçç£ãããç¹ç£åã¯ç¹ç£å1 ãªã®ã§ïŒçãã¯1 çš®é¡ã§ããïŒ çªå·3 ã®ç¹ç£åã¯ååšããªãããšã«æ³šæããïŒ å
¥åäŸ2 7 1 1 2 2 3 3 4 4 5 5 6 6 7 1 1 1 1 1 1 1 åºåäŸ2 1 1 1 0 1 1 1 å
¥åäŸ3 10 10 2 6 5 8 10 8 1 4 10 6 4 5 10 7 6 9 3 7 1 2 3 4 5 6 7 8 9 10 åºåäŸ3 4 3 4 2 0 2 2 0 3 2 å
¥åäŸ4 22 12 9 6 12 13 4 20 21 22 3 19 2 9 6 18 18 11 18 3 16 2 6 4 3 17 16 10 8 16 22 1 16 14 15 8 9 21 2 12 21 5 12 7 1 1 4 8 4 11 7 6 7 11 6 11 10 4 7 5 3 12 9 6 12 2 åºåäŸ4 2 0 1 1 1 1 1 0 0 1 2 0 1 1 2 0 2 1 2 3 0 0 æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒäœ ã第18 åæ¥æ¬æ
å ±ãªãªã³ããã¯(JOI 2018/2019) æ¬éžã
| 38,707
|
F: Absum åé¡ é·ã $N$ ã®æ°å $A$ ãäžããããïŒããªãã¯é«ã
$M$ åãŸã§ïŒæ°åã® $i$ çªç®ãš $j$ çªç®ïŒ$0 \leq i, j \leq N-1$ïŒã®èŠçŽ ãå
¥ãæ¿ããæäœãè¡ãããšãã§ããïŒ æäœãè¡ãªã£ãŠã§ããæ°åã® $\sum_{i = 0}^{N - 1} abs(A_i - i)$ ã®æå€§å€ãæ±ããïŒ å¶çŽ $2 \leq N \leq 10^5$ $0 \leq M \leq N$ $0 \leq A_i \leq 10^5$ å
¥ååœ¢åŒ å
¥åã¯ä»¥äžã®åœ¢åŒã§äžãããã. $N\ M$ïŒ15:15ä¿®æ£ïŒ $A_0\ A_1\ A_2\ \dots\ A_{N - 1}$ åºå æäœãè¡ãªã£ãŠã§ããæ°åã® $\sum_{i = 0}^{N - 1} abs(A_i - i)$ ã®æå€§å€ãæ±ãã.ãŸã, æ«å°Ÿã«æ¹è¡ãåºåãã. ãµã³ãã« ãµã³ãã«å
¥å 1 5 2 0 3 2 1 4 ãµã³ãã«åºå 1 12 $0$ çªç®ã®èŠçŽ ãš $4$ çªç®ã®èŠçŽ ã«æäœãè¡ããšïŒæäœåŸã®æ°å㯠$(4, 3, 2, 1, 0)$ ãšãªãïŒ $|4 - 0| + |3 - 1| + |2 - 2| + |1 - 3| + |0 - 4| = 12$ ã§æå€§ãšãªãïŒå¿
ãããæäœã $M$ åè¡ãå¿
èŠããªã ããšã«æ³šæããïŒ ãµã³ãã«å
¥å 2 3 2 0 0 0 ãµã³ãã«åºå 2 3 æäœãè¡ãããšãªãæå€§å€ãšãªãïŒ ãµã³ãã«å
¥å 3 6 2 1 0 3 6 5 4 ãµã³ãã«åºå 3 20
| 38,708
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.