task
stringlengths 0
154k
| __index_level_0__
int64 0
39.2k
|
|---|---|
Score : 800 points Problem Statement Snuke found a record of a tree with N vertices in ancient ruins. The findings are as follows: The vertices of the tree were numbered 1,2,...,N , and the edges were numbered 1,2,...,N-1 . Edge i connected Vertex a_i and b_i . The length of each edge was an integer between 1 and 10^{18} (inclusive). The sum of the shortest distances from Vertex i to Vertex 1,...,N was s_i . From the information above, restore the length of each edge. The input guarantees that it is possible to determine the lengths of the edges consistently with the record. Furthermore, it can be proved that the length of each edge is uniquely determined in such a case. Constraints 2 \leq N \leq 10^{5} 1 \leq a_i,b_i \leq N 1 \leq s_i \leq 10^{18} The given graph is a tree. All input values are integers. It is possible to consistently restore the lengths of the edges. In the restored graph, the length of each edge is an integer between 1 and 10^{18} (inclusive). Partial Scores In the test set worth 300 points, a_i = i, b_i = i+1 . In the test set worth 200 points, N \geq 3, a_i = 1, b_i = i+1 . Input Input is given from Standard Input in the following format: N a_1 b_1 : a_{N-1} b_{N-1} s_1 s_2 ... s_{N} Output Print N-1 lines. The i -th line must contain the length of Edge i . Sample Input 1 4 1 2 2 3 3 4 8 6 6 8 Sample Output 1 1 2 1 The given record corresponds to the tree shown below: Sample Input 2 5 1 2 1 3 1 4 1 5 10 13 16 19 22 Sample Output 2 1 2 3 4 The given record corresponds to the tree shown below: Sample Input 3 15 9 10 9 15 15 4 4 13 13 2 13 11 2 14 13 6 11 1 1 12 12 3 12 7 2 5 14 8 1154 890 2240 883 2047 2076 1590 1104 1726 1791 1091 1226 841 1000 901 Sample Output 3 5 75 2 6 7 50 10 95 9 8 78 28 89 8
| 39,026
|
Score : 100 points Problem Statement There is a set A = \{ a_1, a_2, \ldots, a_N \} consisting of N positive integers. Taro and Jiro will play the following game against each other. Initially, we have a pile consisting of K stones. The two players perform the following operation alternately, starting from Taro: Choose an element x in A , and remove exactly x stones from the pile. A player loses when he becomes unable to play. Assuming that both players play optimally, determine the winner. Constraints All values in input are integers. 1 \leq N \leq 100 1 \leq K \leq 10^5 1 \leq a_1 < a_2 < \cdots < a_N \leq K Input Input is given from Standard Input in the following format: N K a_1 a_2 \ldots a_N Output If Taro will win, print First ; if Jiro will win, print Second . Sample Input 1 2 4 2 3 Sample Output 1 First If Taro removes three stones, Jiro cannot make a move. Thus, Taro wins. Sample Input 2 2 5 2 3 Sample Output 2 Second Whatever Taro does in his operation, Jiro wins, as follows: If Taro removes two stones, Jiro can remove three stones to make Taro unable to make a move. If Taro removes three stones, Jiro can remove two stones to make Taro unable to make a move. Sample Input 3 2 7 2 3 Sample Output 3 First Taro should remove two stones. Then, whatever Jiro does in his operation, Taro wins, as follows: If Jiro removes two stones, Taro can remove three stones to make Jiro unable to make a move. If Jiro removes three stones, Taro can remove two stones to make Jiro unable to make a move. Sample Input 4 3 20 1 2 3 Sample Output 4 Second Sample Input 5 3 21 1 2 3 Sample Output 5 First Sample Input 6 1 100000 1 Sample Output 6 Second
| 39,027
|
Balls and Boxes 1 Balls Boxes Any way At most one ball At least one ball Distinguishable Distinguishable 1 2 3 Indistinguishable Distinguishable 4 5 6 Distinguishable Indistinguishable 7 8 9 Indistinguishable Indistinguishable 10 11 12 Problem You have $n$ balls and $k$ boxes. You want to put these balls into the boxes. Find the number of ways to put the balls under the following conditions: Each ball is distinguished from the other. Each box is distinguished from the other. Each ball can go into only one box and no one remains outside of the boxes. Each box can contain an arbitrary number of balls (including zero). Note that you must print this count modulo $10^9+7$. Input $n$ $k$ The first line will contain two integers $n$ and $k$. Output Print the number of ways modulo $10^9+7$ in a line. Constraints $1 \le n \le 1000$ $1 \le k \le 1000$ Sample Input 1 2 3 Sample Output 1 9 Sample Input 2 10 5 Sample Output 2 9765625 Sample Input 3 100 100 Sample Output 3 424090053
| 39,028
|
Score : 300 points Problem Statement If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print -1 . The integer has exactly N digits in base ten. (We assume 0 to be a 1 -digit integer. For other integers, leading zeros are not allowed.) The s_i -th digit from the left is c_i . \left(i = 1, 2, \cdots, M\right) Constraints All values in input are integers. 1 \leq N \leq 3 0 \leq M \leq 5 1 \leq s_i \leq N 0 \leq c_i \leq 9 Input Input is given from Standard Input in the following format: N M s_1 c_1 \vdots s_M c_M Output Print the answer. Sample Input 1 3 3 1 7 3 2 1 7 Sample Output 1 702 702 satisfies the conditions - its 1 -st and 3 -rd digits are 7 and 2 , respectively - while no non-negative integer less than 702 satisfies them. Sample Input 2 3 2 2 1 2 3 Sample Output 2 -1 Sample Input 3 3 1 1 0 Sample Output 3 -1
| 39,029
|
ã¢ãªã®å·£ç®±ã®åœ¢ç¶ æ±æåã¯å€äŒã¿ã®èªç±ç ç©¶ãšããŠã¢ãªã®å·£ã®èгå¯ãè¡ãããšã«ããŸããã圌ã®ãããã¡ãããå«ã®ããã«çšæããŠããã芳å¯çšã®éæã±ãŒã¹ã¯ãšãŠããŠããŒã¯ã§ãå³1ã®ãããªåœ¢ãããŠããŸãã å³ïŒ ãã®ã±ãŒã¹ã¯ã2æã®ååãªåžå€è§åœ¢ s1ãs2 ãšäœæãã®é·æ¹åœ¢ã§æ§æãããŠããŸããs1ãs2 以å€ã®ããããã®é·æ¹åœ¢ã®é¢ãåºã«æ¥ããããã«çœ®ããŸãã芳å¯ãå§ããæ±æåã¯ãå
¥ã£ãŠããåã®éãåãã«ãããããããåºé¢ã®éžã³æ¹ã«ãã£ãŠåã®é«ããå€ããããšã«æ°ä»ããŸããïŒå³2ïŒã å³ïŒ æ±æåã¯ãã±ãŒã¹ã®çœ®ãæ¹ã«ãã£ãŠãã©ã®ãããé«ããªããç¥ããããªããŸãããåžå€è§åœ¢ s1 ã®åœ¢ãs1 ãš s2 éã®è·é¢ d ãåã®äœç© V ãå
¥åãšããåã®é«ãã®æå€§å€ãåºåããããã°ã©ã ãäœæããŠãã ãããåã¯ãã±ãŒã¹ã®åºé¢ãåºã«çœ®ããšããã«æ°Žå¹³ã«ãªããã®ãšããŸããéæã±ãŒã¹ã® s1 ã®åœ¢ã¯ãäºæ¬¡å
ã®åº§æšå¹³é¢äžã® n åã®é ç¹ã§äžããããŸãããããã®é ç¹ã¯ãåæèšåãã®é çªã§å
¥åãããŸãã n 㯠3 ä»¥äž 100 以äžã§ã d ãš V ã¯ãããã 1 ä»¥äž 10,000 以äžã®æŽæ°ãšããŸãããŸããå€è§åœ¢ã®é ç¹ã®åº§æš (x, y) ã® x ã y ã¯ãããã -1,000 ä»¥äž 1,000 以äžã®æŽæ°ãšããŸãã V ã¯ã±ãŒã¹ã®äœç©ãè¶
ããŸããã å
¥å è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã¿ã£ã€ã®è¡ã§ç€ºãããŸããåããŒã¿ã»ããã¯ä»¥äžã®ãšããã§ãã 1 è¡ç® n d V ïŒæŽæ° æŽæ° æŽæ°ïŒåè§ç©ºçœåºåãïŒ 2 è¡ç® 第 1 ã®é ç¹ã®åº§æš x y ïŒæŽæ° æŽæ°ïŒåè§ç©ºçœåºåãïŒ 3 è¡ç® 第 2 ã®é ç¹ã®åº§æš : n+1 è¡ç® 第 n ã®é ç¹ã®åº§æš ããŒã¿ã»ããã®æ°ã¯ 20 ãè¶
ããŸããã åºå å
¥åããŒã¿ã»ããããšã«ãåã®é«ãã®æå€§å€ãåºåããŸããçãã«ã¯ 0.00001 ãè¶ãã誀差ããã£ãŠã¯ãããŸããã å
¥åäŸ 4 1 1 0 0 1 0 1 2 0 2 0 0 0 åºåäŸ 1.000000
| 39,031
|
The Number of Inversions For a given sequence $A = \{a_0, a_1, ... a_{n-1}\}$, the number of pairs $(i, j)$ where $a_i > a_j$ and $i < j$, is called the number of inversions. The number of inversions is equal to the number of swaps of Bubble Sort defined in the following program: bubbleSort(A) cnt = 0 // the number of inversions for i = 0 to A.length-1 for j = A.length-1 downto i+1 if A[j] < A[j-1] swap(A[j], A[j-1]) cnt++ return cnt For the given sequence $A$, print the number of inversions of $A$. Note that you should not use the above program, which brings Time Limit Exceeded. Input In the first line, an integer $n$, the number of elements in $A$, is given. In the second line, the elements $a_i$ ($i = 0, 1, .. n-1$) are given separated by space characters. output Print the number of inversions in a line. Constraints $ 1 \leq n \leq 200,000$ $ 0 \leq a_i \leq 10^9$ $a_i$ are all different Sample Input 1 5 3 5 2 1 4 Sample Output 1 6 Sample Input 2 3 3 1 2 Sample Output 2 2
| 39,032
|
Problem E: Kuru-Kuru Robot ããããå·¥åŠã®ç ç©¶è
ã§ããã¢ã·ã¢ãå士ã¯ãæ°ããããããã®éçºã«æåããããã®ããããã¯ãåºã«åŒµãå·¡ãããç¹æ®ãªã¯ã€ã€ãŒã«æ²¿ã£ãŠèªç±ã«åãããšãã§ãããããããã¯åžžã«çŸåšããã¯ã€ã€ãŒã«å¹³è¡ãªæ¹åãåããŠåé²ããã ãã°ãããããšã«ããã®ããããã¯ã¯ã€ã€ãŒäžãç§»åããããã«ãã®è·é¢ã«ããããããšãã«ã®ãŒãæ¶è²»ããªããããããã¯ã€ã€ãŒã®ç«¯ç¹ãã¯ã€ã€ãŒã®äº€ç¹ã§åããå€ããããã«ã¯ãã®ç¹ãäžå¿ã«å転ããå¿
èŠãããããã®å転è§åºŠã ããšãã«ã®ãŒãæ¶è²»ããã ãã®ãããããã¹ã¿ãŒãå°ç¹ãããŽãŒã«å°ç¹ãŸã§åãããããäŸãã°ãäžå³ã«ãããŠããããã start ã«æ±åãïŒäžå³ x è»žã®æ£ã®åãïŒã§é
眮ã goal ãŸã§åãããŠã¿ãããstart ããäº€ç¹ A äº€ç¹ B ãçµç±ã㊠goal ã«ãã©ãçãçµè·¯ãšãäº€ç¹ A äº€ç¹ C ãçµç±ããçµè·¯ãããããåè
ã®æ¹ãç§»åè·é¢ãé·ããã®ã®å転è§åºŠãå°ãªããããšãã«ã®ãŒæ¶è²»éã¯å°ãªãã ããªãã®ä»äºã¯ãåºã«ããã¯ã€ã€ãŒã®äœçœ®ãã¹ã¿ãŒãå°ç¹ããŽãŒã«å°ç¹ãèªã¿èŸŒã¿ãã¹ã¿ãŒãå°ç¹ãããŽãŒã«å°ç¹ãžç§»åããããã«å¿
èŠãªå転è§åºŠã®åèšã®æå°å€ãå ±åããããã°ã©ã ãäœæããããšã§ããã ããããã¯ã¹ã¿ãŒãå°ç¹ã«ãããŠã©ã®ãããªåãã«é
眮ããŠãããããŽãŒã«å°ç¹ã§ã¯ã©ã®æ¹åãåããŠããŠãããã Input å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªããåããŒã¿ã»ããã®åœ¢åŒã¯ä»¥äžã®ãšããïŒ n x 1 1 y 1 1 x 2 1 y 2 1 x 1 2 y 1 2 x 2 2 y 2 2 . . . x 1 n y 1 n x 2 n y 2 n sx sy gx gy n ã¯ã¯ã€ã€ãŒã®æ°ãç€ºãæŽæ°ã§ããã x 1 i y 1 i 㯠i çªç®ã®ã¯ã€ã€ãŒã®äžæ¹ã®ç«¯ç¹ã®åº§æšã x 2 i y 2 i 㯠i çªç®ã®ã¯ã€ã€ãŒã®ããäžæ¹ã®ç«¯ç¹ã®åº§æšã瀺ãã sx sy ã gx gy ã¯ããããã¹ã¿ãŒãå°ç¹ãšãŽãŒã«å°ç¹ã®åº§æšã瀺ãã äžãããã座æšã¯ãã¹ãп޿°å€ã§ããã x 軞 y 軞ã®å€ã¯ -1000 ä»¥äž 1000 以äžã§ããããŸããã¹ã¿ãŒãå°ç¹ãšãŽãŒã«å°ç¹ã¯äžããããã¯ã€ã€ãŒã®ç«¯ç¹äžã«ãããšä»®å®ããŠããã n †50 ã§ãããšä»®å®ããŠããã n ã 0 ã®ãšãå
¥åã®çµäºã瀺ãã Output åããŒã¿ã»ããã«å¯ŸããŠãå転è§åºŠã®åèšã®æå°å€ãïŒè¡ã«åºåãããããããããŽãŒã«å°ç¹ã«ãã©ãçããªãå Žå㯠"-1" ãšåºåãããåºå㯠0.00001 以äžã®èª€å·®ãå«ãã§ãããã Sample Input 8 1 3 11 3 5 3 13 11 10 10 17 10 11 2 11 6 10 5 14 5 13 6 13 2 17 10 17 3 13 3 19 3 1 3 19 3 6 1 3 11 3 5 3 13 11 10 10 17 10 11 2 11 6 10 5 14 5 13 3 19 3 1 3 19 3 2 0 0 7 0 3 0 7 3 0 0 7 3 0 Output for the Sample Input 270.0000 -1 36.86989765
| 39,033
|
Score : 400 points Problem Statement For a positive integer X , let f(X) be the number of positive divisors of X . Given a positive integer N , find \sum_{K=1}^N K\times f(K) . Constraints 1 \leq N \leq 10^7 Input Input is given from Standard Input in the following format: N Output Print the value \sum_{K=1}^N K\times f(K) . Sample Input 1 4 Sample Output 1 23 We have f(1)=1 , f(2)=2 , f(3)=2 , and f(4)=3 , so the answer is 1\times 1 + 2\times 2 + 3\times 2 + 4\times 3 =23 . Sample Input 2 100 Sample Output 2 26879 Sample Input 3 10000000 Sample Output 3 838627288460105 Watch out for overflows.
| 39,034
|
Max Score: $1500$ Points Problem Statement There is a $50 \times 50$ field. The cell at $i$-th row and $j$-th column is denoted $(i, j)$ (0-indexed). One day, square1001 puts $250$ bombs in this field. In each cell, there is 1 or 0 bomb. You want to know where the bombs are by asking some questions. You can ask this question many times. You can ask the number of bombs in the rectangular area in which upper-left cell is $(a, b)$ and lower-right cell is $(c, d)$. Please find all bombs' positions asking as few questions as possible. Note: This problem Input/Output type is special. Please read Input/Output. If you want to use scanf/printf , you have to write fflush(stdout) . Input and output The first line input is following this format: $H \ W \ N \ K$ $H, W$ is field size. In this problem, $H = 50$ and $W = 50$. $N$ is the number of bombs in the field. In this problem, $N = 250$. $K$ is modulo. This integer uses to answer the state of the field. After this input, You can ask some questions, following this output format: $? \ a \ b \ c \ d$ It means that you want to ask the number of bombs in the rectangular area which upper-left cell is $(a, b)$ and lower-right cell is $(c, d)$. You can know the value of the question, from input in this format: $p$ $p$ is the result of your question. Finally, you have to output the answer following this format: $! \ ans$ The value of $ans$ is $\sum_{i=0}^{H-1} \sum_{j=0}^{W-1} r_{i, j} 2^{iW + j}$ mod $K$. Note: $r_{i, j}$ is the number of bombs in cell $(i, j)$. Constraints $H, W = 50$ $N = 250$ $1,000,000,000 \le K \le 1,000,010,000$ ($K$ is random) Score There are 5 testcases in the judge. The $score$ in each testcase is defined by following formula: $Q$ is the number of questions. If $Q > 2500$, $score = 0$ (Wrong Answer). If $930 \le Q \le 2500$, $score = max(\lfloor 125 - 3.2\sqrt{Q - 920} \rfloor, 40)$. If $880 \le Q < 930$, $score = \lfloor 288 - 22\sqrt{Q - 870} \rfloor$. If $Q < 880$, $score = min(2860 - 3Q, 300)$. Sample Inputã»Output In the case of the following arrangement, this input / output is conceivable. This case is $H,W=4$, so this example is not include in testcases. H=4, W=4, N=4 1001 0000 0010 0100 Example of Inputã»Output Input from program Output 4 4 4 1000000007 ? 0 0 0 1 1 ? 0 1 0 2 0 ? 0 3 1 3 1 ? 2 1 3 2 2 ? 2 2 2 2 1 ! 9225 These question is not always meaningful. Writer: E869120
| 39,035
|
Score : 700 points Problem Statement You are given N integers A_1 , A_2 , ..., A_N . Consider the sums of all non-empty subsequences of A . There are 2^N - 1 such sums, an odd number. Let the list of these sums in non-decreasing order be S_1 , S_2 , ..., S_{2^N - 1} . Find the median of this list, S_{2^{N-1}} . Constraints 1 \leq N \leq 2000 1 \leq A_i \leq 2000 All input values are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the median of the sorted list of the sums of all non-empty subsequences of A . Sample Input 1 3 1 2 1 Sample Output 1 2 In this case, S = (1, 1, 2, 2, 3, 3, 4) . Its median is S_4 = 2 . Sample Input 2 1 58 Sample Output 2 58 In this case, S = (58) .
| 39,036
|
Kth Sentence A student, Kita_masa, is taking an English examination. In this examination, he has to write a sentence of length m . Since he completely forgot the English grammar, he decided to consider all sentences of length m constructed by concatenating the words he knows and write the K -th sentence among the candidates sorted in lexicographic order. He believes that it must be the correct sentence because K is today's lucky number for him. Each word may be used multiple times (or it's also fine not to use it at all) and the sentence does not contain any extra character between words. Two sentences are considered different if the order of the words are different even if the concatenation resulted in the same string. Input The first line contains three integers n ( 1 \leq n \leq 100 ), m ( 1 \leq m \leq 2000 ) and K ( 1 \leq K \leq 10^{18} ), separated by a single space. Each of the following n lines contains a word that Kita_masa knows. The length of each word is between 1 and 200, inclusive, and the words contain only lowercase letters. You may assume all the words given are distinct. Output Print the K -th (1-based) sentence of length m in lexicographic order. If there is no such a sentence, print "-". Sample Input 1 2 10 2 hello world Output for the Sample Input 1 helloworld Sample Input 2 3 3 6 a aa b Output for the Sample Input 2 aba Sample Input 3 2 59 1000000000000000000 a b Output for the Sample Input 3 -
| 39,037
|
Score : 100 points Problem Statement Takahashi, who is A years old, is riding a Ferris wheel. It costs B yen ( B is an even number) to ride the Ferris wheel if you are 13 years old or older, but children between 6 and 12 years old (inclusive) can ride it for half the cost, and children who are 5 years old or younger are free of charge. (Yen is the currency of Japan.) Find the cost of the Ferris wheel for Takahashi. Constraints 0 †A †100 2 †B †1000 B is an even number. Input Input is given from Standard Input in the following format: A B Output Print the cost of the Ferris wheel for Takahashi. Sample Input 1 30 100 Sample Output 1 100 Takahashi is 30 years old now, and the cost of the Ferris wheel is 100 yen. Sample Input 2 12 100 Sample Output 2 50 Takahashi is 12 years old, and the cost of the Ferris wheel is the half of 100 yen, that is, 50 yen. Sample Input 3 0 100 Sample Output 3 0 Takahashi is 0 years old, and he can ride the Ferris wheel for free.
| 39,038
|
Problem C: Last One Problem ããªãã¯ãéå奜ããªå人Aãšäžé¢šå€ãã£ãã²ãŒã ãããŠã¿ãäºã«ããã nåã®èŠçŽ ãããªãéè€ãèš±ãããéè² ã®æŽæ°ã®éåSãäžãããããéåSã«å«ãŸããåèŠçŽ ã¯éè² ã® p i 鲿°ã§ãããéåSã«å¯Ÿã㊠以äžã®Step1~3ã1ã€ã®ã¿ãŒã³ãšããŠãããªããšçžæã®äºäººã亀äºã«ã¿ãŒã³ãç¹°ãè¿ããåã¿ãŒã³ã§ã¯ãã®çªå·ã®é ã«æäœãè¡ãã Step 1: éåSã«å«ãŸããå
šãŠã®èŠçŽ ãäžåºŠåãé€ãããã®åãé€ããåèŠçŽ ã2鲿°ã«å€æããŠã0ãæ¶ããŠ1ã1ã€ä»¥äžé£ç¶ããéšåã«åå²ãããã®åå²ãããéšåãå
šãŠéåSã«å ããã Step 2: ãã®ãšãéåSã空ã«ãªã£ãŠãããªãã°ãçŸåšãã®ã¿ãŒã³ããã¬ã€ããŠãããã¬ã€ã€ãŒã¯è² ããã Step 3: éåSã«å«ãŸããèŠçŽ aã1ã€éžã³ããã®aãã 1 †x †a ãæºããä»»æã®æŽæ°xãåŒãã äžã®å³ã¯æ¬¡ã®å
¥åãäžãããããšãã®æåã®1ã¿ãŒã³ã®é²è¡ã®ä»æ¹ã®ãã¡ã®1ã€ã®äŸã§ããã 4 10 3 2 11 16 5 16 AE æåã¯ããªãã®ã¿ãŒã³ã ãäžããããå
¥åã«å¯ŸããŠäž¡è
ãæåãå°œãããšããæãããŠããªãã«åã¡ç®ã¯ããã®ã ãããã Input å
¥åã¯æ¬¡ã®åœ¢åŒã§äžããããã n p 1 m 1 p 2 m 2 ... p i m i ... p n m n éåã®èŠçŽ ã§ãã p i 鲿° m i ã n åäžãããããéåã®èŠçŽ ã®æ° n ã¯10 5 ãè¶
ããªãããŸãã2⊠p i âŠ62ãæºããã p i 鲿° m i ã¯éåžžã®æ°åã§ãã0~9ã«å ããã¢ã«ãã¡ããã52æåã䜿çšããã ãã®é çªã¯012...789ABC...XYZabc...xyzãæé ãšãã i çªç®ãŸã§ã®æåã䜿ããã®ãšããããŸãã p i 鲿° m i ã¯10鲿°ã§2 18 -1ãè¶
ããªã. Output äžããããå
¥åã«å¯ŸãããªããåãŠããªãwinãè² ãããªãloseãåºåããã Sample Input 1 1 10 1 Sample Output 1 win Sample Input 2 2 10 1 10 1 Sample Output 2 lose Sample Input 3 3 25 53AI 43 3BI0 62 pn6 Sample Output 3 win
| 39,039
|
ããã«ãœãŒã(Bubble Sort) ããã«ãœãŒããšã¯ïŒåããœãŒãããã¢ã«ãŽãªãºã ã® 1 ã€ã§ããïŒé·ã N ã®æ°å A ãæé ã«ãœãŒãããããšãããïŒããã«ãœãŒãã¯ïŒé£ãåã 2 ã€ã®æ°ã§å€§å°é¢ä¿ã厩ããŠãããã®ãããã°ïŒãããã®äœçœ®ã亀æããïŒãããïŒæ°åãåããé ã«èµ°æ»ããªããè¡ãïŒããªãã¡ïŒ A i > A i+1 ãšãªã£ãŠããå Žæãããã°ïŒãã® 2 æ°ã亀æãããšããããšãïŒ i = 1, 2, ... , N â 1 ã«å¯ŸããŠãã®é ã§è¡ãã®ã 1 åã®èµ°æ»ã§ããïŒãã®èµ°æ»ã N â 1 åç¹°ãè¿ãããšã§ïŒæ°åãæé ã«ãœãŒãã§ããããšãç¥ãããŠããïŒ æ°å A ã®ããã«ãœãŒãã«ãã亀æåæ°ãšã¯ïŒæ°å A ã«äžèšã®ã¢ã«ãŽãªãºã ãé©çšããæã«ïŒæŽæ°ã®äº€æãè¡ãããåæ°ã§ããïŒïŒããã«ãœãŒããšããŠç¥ãããã¢ã«ãŽãªãºã åã³å®è£
ã«ã¯ïŒã«ãŒãã®é çªãç¯å²ïŒåã³çµäºæ¡ä»¶ãªã©ïŒçްããªå·®ç°ãããå ŽåãããïŒãã ãïŒåãæ°åã«é©çšããéã®æŽæ°ã®äº€æåæ°ã¯ãããã®å·®ç°ã«ããå€åããªãããšãç¥ãããŠããïŒïŒ äŸãã°ïŒä»¥äžã®ããã°ã©ã ã¯é·ã n ã®æŽæ°ã®é
å a ãããã«ãœãŒãã«ãããœãŒããã颿°ã C èšèªã§èšè¿°ãããã®ã§ããïŒ void bubble_sort(int *a, int n) { int i, j; for (i = 0; i < n - 1; ++i) { for (j = 0; j < n - 1; ++j) { if (a[j] > a[j + 1]) { /* 以äž3 è¡ã1 åã®æŽæ°ã®äº€æã«çžåœ*/ int x = a[j]; a[j] = a[j + 1]; a[j + 1] = x; } } } } èª²é¡ é·ã N ã®æ°å A ãäžããããïŒæ°å A ã®ä»»æã®å Žæã® 2 ã€ã®æŽæ°ã 1 åã ã亀æããæ°å A' ãäœããšããïŒæ°å A' ã®ããã«ãœãŒãã«ãã亀æåæ°ã®æå°å€ãæ±ããããã°ã©ã ãäœæããïŒïŒæåã«äº€æãã2ã€ã®æŽæ°ã¯å¿
ãããé£ãåã£ãŠããå¿
èŠã¯ãªãããšã«æ³šæããïŒïŒ å¶é 1 †N †100 000 æ°å A ã®é·ã 1 †A i †1 000 000 000 æ°å A ã«å«ãŸããæ°åã®å€§ãã å
¥å æšæºå
¥åãã以äžã®ããŒã¿ãèªã¿èŸŒãïŒ 1 è¡ç®ã«ã¯ïŒæŽæ° N ãæžãããŠããïŒ N ã¯æ°å A ã®é·ãã衚ãïŒ ç¶ã N è¡ã®ãã¡ã® i è¡ç®(1 †i †N ) ã«ã¯ïŒæŽæ° A i ãæžãããŠããïŒããã¯æ°å A ã® i çªç®ã®æŽæ°ã衚ãïŒ åºå æšæºåºåã«ïŒæ°å A' ã®ããã«ãœãŒãã«ãã亀æåæ°ã®æå°å€ãè¡šãæŽæ°ã 1 è¡ã§åºåããïŒ æ¡ç¹åºæº æ¡ç¹çšããŒã¿ã®ãã¡ïŒé
ç¹ã®10%åã«ã€ããŠã¯ïŒ N †1 000 ãæºããïŒä»»æã® i, j (1 †i < j †N ) ã«ã€ã㊠A i â A j ãæºããïŒ æ¡ç¹çšããŒã¿ã®ãã¡ïŒé
ç¹ã®30%åã«ã€ããŠã¯ïŒ N †5 000 ãæºããïŒä»»æã® i, j (1 †i < j †N ) ã«ã€ã㊠A i â A j ãæºããïŒ æ¡ç¹çšããŒã¿ã®ãã¡ïŒé
ç¹ã®80%åã«ã€ããŠã¯ïŒä»»æã® i, j (1 †i < j †N ) ã«ã€ã㊠A i â A j ãæºããïŒ å
¥åºåäŸ å
¥åäŸ 1 5 10 3 6 8 1 åºåäŸ 1 0 æ°å A ã®æåã® 10 ãšæåŸã® 1 ã亀æããããšã«ãããšïŒæ°å A' ã¯ãœãŒãæžã¿ã®åãšãªãïŒããã«ãœãŒãã®äº€æåæ°ã¯ 0 ãšãªãïŒ å
¥åäŸ 2 5 3 1 7 9 5 åºåäŸ 2 2 æ°å A ã® 3 çªç®ã® 7 ãšæåŸã® 5 ã亀æããããšã§ïŒæ°å A' 㯠3,1,5,9,7 ãšãªãïŒ A' ã®ããã«ãœãŒãã«ãã亀æåæ°ã¯ 2 ã§ããïŒ å
¥åäŸ 3 3 1 2 3 åºåäŸ 3 1 æåããæ°å A ããœãŒããããŠããå Žåã§ãïŒæ°å A' ãäœãéã«äº€æãè¡ããªããã°ãªããªãïŒ å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
| 39,040
|
å®
é
æé ããå®
é
æ¥è
ã®å®
é
æéã¯å€§ãããšééã§äžè¡šã®ããã«æéãèšå®ãããŠããŸãã A ãµã€ãº B ãµã€ãº C ãµã€ãº D ãµã€ãº E ãµã€ãº F ãµã€ãº 倧ãã 60cm以å
80cm以å
100cm以å
120cm以å
140cm以å
160cm以å
éã 2kg以å
5kg以å
10kg以å
15kg以å
20kg以å
25kg以å
æé 600å 800å 1000å 1200å 1400å 1600å 倧ããã¯äžèŸºïŒçžŠã暪ãé«ãïŒã®åã§ããäŸãã°å€§ããã120cmã§ãéãã15kg以å
ã®è·ç©ã¯ïŒ€ãµã€ãºïŒ1,200åïŒãšãªããŸãã倧ããã120cm以å
ã§ããéãã15kgãè¶
ãã20kg以å
ãªãã°ïŒ¥ãµã€ãºãšãªããŸãã 1æ¥ã«æã¡èŸŒãŸããè·ç©ã®æ
å ±ãå
¥åãšããæéã®ç·èšãåºåããããã°ã©ã ãäœæããŠãã ããããªãããµã€ãºãè¶
ããè·ç©ã¯å¯Ÿè±¡å€ãšãæéã®ç·èšã«ã¯å«ã¿ãŸããã Input è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸãã åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã n x 1 y 1 h 1 w 1 x 2 y 2 h 2 w 2 : x n y n h n w n ïŒè¡ç®ã«è·ç©ã®åæ° n (1 †n †10000)ãç¶ã n è¡ã« i çªç®ã®è·ç©ã®çžŠã®é·ã x i ãæšªã®é·ã y i ãé«ã h i ãéã w i (1 †x i , y i , h i , w i †200) ã空çœåºåãã§ïŒè¡ã«äžããããŸãã ããŒã¿ã»ããã®æ°ã¯ 20 ãè¶
ããŸããã Output ããŒã¿ã»ããããšã«è·ç©ã®æéã®ç·èšãïŒè¡ã«åºåããŸãã Sample Input 2 50 25 5 5 80 60 10 30 3 10 15 25 24 5 8 12 5 30 30 30 18 0 Output for the Sample Input 800 3800
| 39,041
|
Problem A: ææ«è©Šéš! ç§ç«æ¡ãäžå¥³åé«çåŠæ ¡ã«éã平沢å¯ããã¯æåŸæ¥ãŸã§ã«é²è·¯åžæãåºããªããã°ãªããªãã®ã ããå°ã£ãããšã«é²è·¯ã«ã€ããŠãŸã äœã決ããŠããªãã£ãã å人ã®åã«çžè«ãããšãããåã®ç¬¬äžå¿æã¯K倧ãšç¥ããèªåãK倧ã«å
¥ãããã©ããé²è·¯æå°ã®å
çã«çžè«ã«ãã£ãã çžè«ãããé²è·¯æå°ã®å
çã§ããããªãã¯å¯ãããK倧ã«å
¥ãããã©ãããäºæ³ããããå¯ããã®ææ«è©Šéšã®æçžŸãåèã«ããããšã«ããã ããããå¯ããã¯è©Šéšã®å±±ãåœãããã©ããã«ãã£ãŠå€§ããæçžŸãå·Šå³ããããããéå»ã®ææ«è©Šéšã®äžã§äžçªè¯ãã£ãæã®ç¹æ°ãšäžçªæªãã£ãæã®ç¹æ°ã調ã¹ãããšã«ããã éå»ã®ææ«è©Šéšã®ããŒã¿ã¯5æç§ã®åç¹æ°ã®ã¿ããæ®ã£ãŠãããã詊éšã®åèšç¹æ°ã¯æ®ã£ãŠããªãã£ãã ãããã£ãŠããªãã®ä»äºã¯å詊éšã®ç¹æ°ããŒã¿ãå
¥åãšããŠãéå»ã®ææ«è©Šéšã®äžã§äžçªè¯ãã£ãæã®ç¹æ°ãšäžçªæªãã£ãæã®ç¹æ°ãåºåããããã°ã©ã ãæžãããšã§ããã Input n s 11 s 12 s 13 s 14 s 15 ... s n1 s n2 s n3 s n4 s n5 n ã¯ä»ãŸã§ã«åãã詊éšã®åæ°ã§ããã詊éšã®åæ°ã¯1以äž100以äžã§ããã ç¶ã n è¡ã«ã¯å詊éšã«ããã5æç§ã®ç¹æ°ãäžãããããç¹æ°ã®ç¯å²ã¯0以äž100以äžã®æŽæ°ã§ããã Output æé«ç¹ æäœç¹ããäžè¡ã«åºåããªãããæé«ç¹ãšæäœç¹ã®éã¯1æåã®ç©ºçœã§åºåããããã以å€ã®æåãå«ãã§ã¯ãªããªãã Notes on Test Cases äžèšå
¥å圢åŒã§è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã«å¯ŸããŠäžèšåºå圢åŒã§åºåãè¡ãããã°ã©ã ãäœæããŠäžããã n ã 0 ã®ãšãå
¥åã®çµããã瀺ããŸãã Sample Input 3 49 50 87 78 41 27 61 100 45 84 28 88 40 95 66 2 100 100 100 100 100 0 0 0 0 0 1 89 90 85 93 82 0 Output for Sample Input 317 305 500 0 439 439
| 39,042
|
Problem J: The Teacherâs Side of Math One of the tasks students routinely carry out in their mathematics classes is to solve a polynomial equation. It is, given a polynomial, say X 2 - 4 X + 1, to find its roots (2 ± â3). If the studentsâ task is to find the roots of a given polynomial, the teacherâs task is then to find a polynomial that has a given root. Ms. Galsone is an enthusiastic mathematics teacher who is bored with finding solutions of quadratic equations that are as simple as a + b â c . She wanted to make higher-degree equations whose solutions are a little more complicated. As usual in problems in mathematics classes, she wants to maintain all coefficients to be integers and keep the degree of the polynomial as small as possible (provided it has the specified root). Please help her by writing a program that carries out the task of the teacherâs side. You are given a number t of the form: t = m â a + n â b where a and b are distinct prime numbers, and m and n are integers greater than 1. In this problem, you are asked to find t's minimal polynomial on integers , which is the polynomial F ( X ) = a d X d + a d -1 X d -1 + ... + a 1 X + a 0 satisfying the following conditions. Coefficients a 0 , ... , a d are integers and a d > 0. F ( t ) = 0. The degree d is minimum among polynomials satisfying the above two conditions. F ( X ) is primitive. That is, coefficients a 0 , ... , a d have no common divisors greater than one. For example, the minimal polynomial of â3+ â2 on integers is F ( X ) = X 4 - 10 X 2 + 1. Verifying F ( t ) = 0 is as simple as the following ( α = 3, β = 2). F ( t ) = ( α + β ) 4 - 10( α + β ) 2 + 1 = ( α 4 + 4 α 3 β + 6 α 2 β 2 + 4 αβ 3 + β 4 ) - 10( α 2 + 2 αβ + β 2 ) + 1 = 9 + 12 αβ + 36 + 8 αβ + 4 - 10(3 + 2 αβ + 2) + 1 = (9 + 36 + 4 - 50 + 1) + (12 + 8 - 20) αβ = 0 Verifying that the degree of F ( t ) is in fact minimum is a bit more difficult. Fortunately, under the condition given in this problem, which is that a and b are distinct prime numbers and m and n greater than one, the degree of the minimal polynomial is always mn . Moreover, it is always monic . That is, the coefficient of its highest-order term ( a d ) is one. Input The input consists of multiple datasets, each in the following format. a m b n This line represents m â a + n â b . The last dataset is followed by a single line consisting of four zeros. Numbers in a single line are separated by a single space. Every dataset satisfies the following conditions. m â a + n â b †4. mn †20. The coefficients of the answer a 0 , ... , a d are between (-2 31 + 1) and (2 31 - 1), inclusive. Output For each dataset, output the coefficients of its minimal polynomial on integers F ( X ) = a d X d + a d -1 X d -1 + ... + a 1 X + a 0 , in the following format. a d a d -1 ... a 1 a 0 Non-negative integers must be printed without a sign (+ or -). Numbers in a single line must be separated by a single space and no other characters or extra spaces may appear in the output. Sample Input 3 2 2 2 3 2 2 3 2 2 3 4 31 4 2 3 3 2 2 7 0 0 0 0 Output for the Sample Input 1 0 -10 0 1 1 0 -9 -4 27 -36 -23 1 0 -8 0 18 0 -104 0 1 1 0 0 -8 -93 0 24 -2976 2883 -32 -3720 -23064 -29775 1 0 -21 0 189 0 -945 -4 2835 -252 -5103 -1260 5103 -756 -2183
| 39,043
|
F : Tree / æš å顿 倧ãã N ã®æ ¹ä»ãæšãããã åé ç¹ã«ã¯ 0 ãã Nâ1 ãŸã§ã®çªå·ãä»ããããæ ¹ã 0 ã§ããã ä»»æã®èŸºã®äž¡ç«¯ã®é ç¹ã«ã€ããŠãå²ãåœãŠãããæŽæ°ã¯æ ¹ã«è¿ãã»ããå°ãããåãã¯å
šãŠã®èŸºã®éã¿ã¯ 0 ã§ããã ãã®æšã«å¯Ÿãã Q åã®ã¯ãšãªãé ã«åŠçãããã¯ãšãªã«ã¯ä»¥äžã® 2 çš®é¡ãããã é ç¹ u , v ã®è·é¢(ãã¹ã«å«ãŸãã蟺ã®éã¿ã®å)ãæ±ããã é ç¹ v ã®åå«(èªèº«ãå«ãŸãªã)ã«æ¥ç¶ãã蟺ã®éã¿ãå
šãŠ x å¢å ãããã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒãããªãã N Q a_0 b_0 ⊠a_{Nâ2} b_{Nâ2} q_0 ⊠q_{Qâ1} a_i,b_i 㯠i çªç®ã®èŸºãçµã¶é ç¹ã§ããã q_i 㯠i çªç®ã®ã¯ãšãªã衚ã 3 ã€ã®æŽæ°ã§ãããæ¬¡ã®ãã¡ããããã§ããã 0 \ u_i \ v_i : é ç¹ u_i, v_i ã®è·é¢ãæ±ããã 1 \ v_i \ x_i : é ç¹ v_i ã®åå«ã«æ¥ç¶ãã蟺ã®éã¿ãå
šãŠ x_i å¢å ãããã å¶çŽ å
¥åã¯ãã¹ãп޿°ã§ãã 2 \†N \†150\,000 1 \†Q \†150\,000 0 \†a_{i},b_{i},u_{i},v_{i} \†Nâ1 a_{i} < b_{i} 0 \†x_{i} \†300 åºå è·é¢ãæ±ããã¯ãšãªã®ãã³ã«ãçµæã1è¡ã§åºåããã æ³šæ ãã®åé¡ã§ã¯å
¥åºåãéåžžã«å€§ãããªãããã®ã§é«éãªé¢æ°ã䜿çšããŠã»ããã ãµã³ãã« ãµã³ãã«å
¥å1 9 6 0 1 0 2 0 3 1 4 1 5 4 6 5 7 5 8 1 0 1 1 1 2 0 6 3 1 5 5 1 8 4 0 4 3 ãµã³ãã«åºå1 8 5 å³ã®ããã«ãªãã ãµã³ãã«å
¥å2 13 7 0 1 1 2 2 3 1 4 3 5 1 6 2 7 0 8 7 9 5 10 8 11 1 12 1 2 143 0 8 7 0 10 6 1 1 42 1 6 37 0 3 6 1 6 38 ãµã³ãã«åºå2 143 429 269
| 39,044
|
Problem E: Magical Island This is a story in the epoch of magic. A clan of magicians lived in an artificial island built by magic power. One day, a crisis erupted on the island. An Empire ACM (Atlas Country of Magic) required unconditional surrender to them, otherwise an imperial force attacked by magical missiles to the island. However, they were so proud that they did not surrender to the ACM, and built a system to generate magical shield to protect the clan from the threat of magical missiles. In this system, a crystal with different elements was put on each corner of the island: the world consisted of four elements, namely Fire, Water, Air and Earth. Each crystal generated magical shield with the element of the crystal by receiving magiciansâ magic power; it shielded the island from magical missiles of the same element: any magical missile consists of one of the four elements. Magic shield covered a circular area; the crystal should be located on the center the circular area. The crystal required R 2 magic power to shield a circular area of radius R . However, there was one restriction. Magicians should send exactly the same amount of magic power to all crystals, otherwise the island was lost because of losing a balance between four elements. They decided to live in an area which is shielded from any magical missile. Your job is to write a program to calculate minimum amount of magic power to secure enough area for them to live in. Input The input consists of multiple datasets. Each dataset is a single line containing three integers W , H and S , separated by a single space. The line containing three zeros separated by a single space indicates the end of the input. W and H are width and depth of the island, respectively. S is the area magicians needed to live in. You may assume that 0 < W , H †100 and 0 < S †W à H . Output For each dataset, output a separate line containing the total minimum necessary magic power. The value may contain an error less than or equal to 0.001. You may print any number of digits after the decimal point. Sample Input 1 1 1 10 15 5 15 10 100 0 0 0 Output for the Sample Input 8.000 409.479 861.420
| 39,045
|
Score : 1900 points Problem Statement Snuke has found two trees A and B , each with N vertices numbered 1 to N . The i -th edge of A connects Vertex a_i and b_i , and the j -th edge of B connects Vertex c_j and d_j . Also, all vertices of A are initially painted white. Snuke would like to perform the following operation on A zero or more times so that A coincides with B : Choose a leaf vertex that is painted white. (Let this vertex be v .) Remove the edge incident to v , and add a new edge that connects v to another vertex. Paint v black. Determine if A can be made to coincide with B , ignoring color. If the answer is yes, find the minimum number of operations required. You are given T cases of this kind. Find the answer for each of them. Constraints 1 \leq T \leq 20 3 \leq N \leq 50 1 \leq a_i,b_i,c_i,d_i \leq N All given graphs are trees. Input Input is given from Standard Input in the following format: T case_1 : case_{T} Each case is given in the following format: N a_1 b_1 : a_{N-1} b_{N-1} c_1 d_1 : c_{N-1} d_{N-1} Output For each case, if A can be made to coincide with B ignoring color, print the minimum number of operations required, and print -1 if it cannot. Sample Input 1 2 3 1 2 2 3 1 3 3 2 6 1 2 2 3 3 4 4 5 5 6 1 2 2 4 4 3 3 5 5 6 Sample Output 1 1 -1 The graph in each case is shown below. In case 1 , A can be made to coincide with B by choosing Vertex 1 , removing the edge connecting 1 and 2 , and adding an edge connecting 1 and 3 . Note that Vertex 2 is not a leaf vertex and thus cannot be chosen. Sample Input 2 3 8 2 7 4 8 8 6 7 1 7 3 5 7 7 8 4 2 5 2 1 2 8 1 3 2 2 6 2 7 4 1 2 2 3 3 4 3 4 2 1 3 2 9 5 3 4 3 9 3 6 8 2 3 1 3 3 8 1 7 4 1 2 8 9 6 3 6 3 5 1 8 9 7 1 6 Sample Output 2 6 0 7 A may coincide with B from the beginning.
| 39,046
|
Problem C: Shopping Your friend will enjoy shopping. She will walk through a mall along a straight street, where $N$ individual shops (numbered from 1 to $N$) are aligned at regular intervals. Each shop has one door and is located at the one side of the street. The distances between the doors of the adjacent shops are the same length, i.e. a unit length. Starting shopping at the entrance of the mall, she visits shops in order to purchase goods. She has to go to the exit of the mall after shopping. She requires some restrictions on visiting order of shops. Each of the restrictions indicates that she shall visit a shop before visiting another shop. For example, when she wants to buy a nice dress before choosing heels, she shall visit a boutique before visiting a shoe store. When the boutique is farther than the shoe store, she must pass the shoe store before visiting the boutique, and go back to the shoe store after visiting the boutique. If only the order of the visiting shops satisfies all the restrictions, she can visit other shops in any order she likes. Write a program to determine the minimum required walking length for her to move from the entrance to the exit. Assume that the position of the door of the shop numbered $k$ is $k$ units far from the entrance, where the position of the exit is $N + 1$ units far from the entrance. Input The input consists of a single test case. $N$ $m$ $c_1$ $d_1$ . . . $c_m$ $d_m$ The first line contains two integers $N$ and $m$, where $N$ ($1 \leq N \leq 1000$) is the number of shops, and $m$ ($0 \leq m \leq 500$) is the number of restrictions. Each of the next $m$ lines contains two integers $c_i$ and $d_i$ ($1 \leq c_i < d_i \leq N$) indicating the $i$-th restriction on the visiting order, where she must visit the shop numbered $c_i$ after she visits the shop numbered $d_i$ ($i = 1, . . . , m$). There are no pair of $j$ and $k$ that satisfy $c_j = c_k$ and $d_j = d_k$. Output Output the minimum required walking length for her to move from the entrance to the exit. You should omit the length of her walk in the insides of shops. Sample Input 1 10 3 3 7 8 9 2 5 Sample Output 1 23 Sample Input 2 10 3 8 9 6 7 2 4 Sample Output 2 19 Sample Input 3 10 0 Sample Output 3 11 Sample Input 4 10 6 6 7 4 5 2 5 6 9 3 5 6 8 Sample Output 4 23 Sample Input 5 1000 8 3 4 6 1000 5 1000 7 1000 8 1000 4 1000 9 1000 1 2 Sample Output 5 2997
| 39,047
|
Problem A: Register Phase ã€ã³ã¿ãŒããããããå®å
šã«æŽ»çšããããã«ãå
ç¢ãªãã¹ã¯ãŒãã䜿ãããšã¯éèŠã§ããããããšåæã«ãåããã¹ã¯ãŒãã䜿ãåããªãããšãéåžžã«éèŠã§ãããã©ããªã«åŒ·ããã¹ã¯ãŒãã䜿ã£ãŠããŠããäžç®æã§å¹³æãæµåºããŠããŸãã°ãç Žãã®ã¯éåžžã«å®¹æã«ãªã£ãŠããŸãããã¡ãããå
šãŠã®ã¢ããªã±ãŒã·ã§ã³ããã¹ã¯ãŒããããã·ã¥åããSALTãé©åã«äœ¿çšããŠããã°æµåºããŠããã®ãããªè¢«å®³ã¯çºçããªãããããŸã ã«ãã¹ã¯ãŒããå¹³æã§ä¿åããŠããã¢ããªã±ãŒã·ã§ã³ã¯ããã®ã§ããã ããŠãããããã³ã³ãã¹ããå§ãŸããããŒã ã®ã¢ã«ãŠã³ããç»é²ããªããŠã¯âŠã åé¡ ãã¹ã¯ãŒãã衚ãæååãäžããããããã®æååã以äžã®æ¡ä»¶ãå
šãŠæºããã調ã¹ãæºããå Žå㯠"VALID" ãšãã²ãšã€ã§ãæºãããªãé
ç®ãããå Žå㯠"INVALID" ãšåºåããã æååé·ã6以äžã§ãã æ°åãäžã€ä»¥äžå«ãã§ãã 倧æåè±åãäžã€ä»¥äžå«ãã§ãã å°æåè±åãäžã€ä»¥äžå«ãã§ãã å
¥å ãã¹ã¯ãŒãã衚ãæååãäžè¡ã«äžããããã åºå ãã¹ã¯ãŒãã衚ãæååãåé¡ã®æ¡ä»¶ãå
šãŠæºãããªã "VALID" ãšãæºãããªãæ¡ä»¶ããããªã "INVALID" ãšãäžè¡ã«åºåããã å¶çŽ ãã¹ã¯ãŒãã衚ãæååã¯1æå以äž20æå以å
ã§ãã ãã¹ã¯ãŒãã衚ãæååã¯è±å€§æåãè±å°æåãæ°åã®ã¿ãå«ã å
¥åºåäŸ å
¥å1 password åºå1 INVALID äžçäžã§åºã䜿ãããŠãããã¹ã¯ãŒãã§ããã å
¥å2 AizuCamp2013 åºå2 VALID çŽ æŽãããã¹ã¯ãŒãã§ããã å
¥å3 1234 åºå3 INVALID æèšŒçªå·ãšããŠåºã䜿ãããŠããã å
¥å4 NaBiO3 åºå4 VALID ãããã6æå以äžã§ããã
| 39,048
|
Score : 100 points Problem Statement We have a sandglass that runs for X seconds. The sand drops from the upper bulb at a rate of 1 gram per second. That is, the upper bulb initially contains X grams of sand. How many grams of sand will the upper bulb contains after t seconds? Constraints 1â€Xâ€10^9 1â€tâ€10^9 X and t are integers. Input The input is given from Standard Input in the following format: X t Output Print the number of sand in the upper bulb after t second. Sample Input 1 100 17 Sample Output 1 83 17 out of the initial 100 grams of sand will be consumed, resulting in 83 grams. Sample Input 2 48 58 Sample Output 2 0 All 48 grams of sand will be gone, resulting in 0 grams. Sample Input 3 1000000000 1000000000 Sample Output 3 0
| 39,049
|
Sorting Tuples Write a program which reads $n$ items and sorts them. Each item has attributes $\{value, weight, type, date, name\}$ and they are represented by $\{$ integer, integer, upper-case letter, integer, string $\}$ respectively. Sort the items based on the following priorities. first by value (ascending) in case of a tie, by weight (ascending) in case of a tie, by type (ascending in lexicographic order) in case of a tie, by date (ascending) in case of a tie, by name (ascending in lexicographic order) Input The input is given in the following format. $n$ $v_0 \; w_0 \; t_0 \; d_0 \; s_0$ $v_1 \; w_1 \; t_1 \; d_1 \; s_1$ : $v_{n-1} \; w_{n-1} \; t_{n-1} \; d_{n-1} \; s_{n-1}$ In the first line, the number of items $n$. In the following $n$ lines, attributes of each item are given. $v_i \; w_i \; t_i \; d_i \; s_i$ represent value, weight, type, date and name of the $i$-th item respectively. Output Print attributes of each item in order. Print an item in a line and adjacency attributes should be separated by a single space. Constraints $1 \leq n \leq 100,000$ $0 \leq v_i \leq 1,000,000,000$ $0 \leq w_i \leq 1,000,000,000$ $t_i$ is a upper-case letter $0 \leq d_i \leq 2,000,000,000,000$ $1 \leq $ size of $s_i \leq 20$ $s_i \ne s_j$ if $(i \ne j)$ Sample Input 1 5 105 24 C 1500000000000 white 100 23 C 1500000000000 blue 105 23 A 1480000000000 pink 110 25 B 1500000000000 black 110 20 A 1300000000000 gree Sample Output 1 100 23 C 1500000000000 blue 105 23 A 1480000000000 pink 105 24 C 1500000000000 white 110 20 A 1300000000000 gree 110 25 B 1500000000000 black
| 39,050
|
åèŠ§äŒ åé¡ JOI åžã§ã¯,ãšããå€§èŠæš¡ãªå芧äŒãéå¬ããããšã«ãªã£ã. ä»åã®å芧äŒã«ã¯ 2 ã€ã®ããŒãããã,JOI åžã«ãã N åã®å±ç€ºæœèšã§ãããã, 2 ã€ã®ããŒãã®ãã¡ã©ã¡ããäžæ¹ã«æ²¿ã£ãå±ç€ºãè¡ãäºå®ã§ãã. æœèšã®äœçœ®ã¯å¹³é¢åº§æš (x, y) ã§è¡šããã.äœçœ® (x, y) ã«ããæœèšãã (xâ² , yâ²) ã«ããæœèšãŸã§ç§»åããããã«ã¯, |x â xâ²| + |y â yâ²| ã ãã®æéãããã (æŽæ° a ã«å¯ŸããŠ, |a| ã§ a ã®çµ¶å¯Ÿå€ã衚ã).åäžããŒãå
ã§ã®çµ±äžæãåºããã,ããã³äžæ¹ã®ããŒãã®ã¿ã«é¢å¿ãæã€äººã«äžäŸ¿ãæããããªãããã«,åäžã®ããŒãã§å±ç€ºãè¡ã£ãŠãã 2 ã€ã®æœèšã®éã®ç§»åæéããªãã¹ãçããªãããã«ããŒããå²ããµããã.ãã¹ãŠã®å±ç€ºæœèšã«åãããŒããå²ããµããªãéã, ã©ã®ããã«ããŒããå²ããµã£ãŠããã. åäžã®ããŒãã§å±ç€ºãè¡ã£ãŠãã 2 ã€ã®æœèšã®éã®ç§»åæéã®æå€§å€ã M ãšãã. N åã®å±ç€ºæœèšã®äœçœ®ãäžãããããšã, M ã®æå°å€ãæ±ããããã°ã©ã ãäœæãã. å
¥å å
¥åã® 1 è¡ç®ã«ã¯, æœèšã®åæ° N(3 †N †100000 = 10 5 ) ãæžãããŠãã.å
¥åã®i + 1 è¡ç® (1 †i †N) ã«ã¯,åæœèšã®åº§æšã衚ã 2 ã€ã®æŽæ° x i , y i (|x i | †100000 = 10 5 , |y i | †100000 = 10 5 ) ã空çœåºåãã§æžãããŠãã.ããã¯,i åç®ã®æœèšã®åº§æšã(x i , y i ) ã§ããããšã衚ã. åäžã®åº§æšã« 2 ã€ä»¥äžã®æœèšãååšããããšã¯ãªã. æ¡ç¹çšããŒã¿ã®ãã¡,é
ç¹ã® 40% åã«ã€ããŠã¯, N †2000 ã§ãã. åºå åºå㯠1 è¡ã®ã¿ãããªã.åäžã®ããŒãã§å±ç€ºãè¡ã£ãŠãã 2 ã€ã®æœèšéã®ç§»åæéã®æå€§å€ M ã®æå°å€ãåºåãã. å
¥åºåäŸ å
¥åäŸ 1 5 0 0 1 0 -1 -2 0 1 -1 1 åºåäŸ 1 3 ãã®å Žå,ããšãã°åº§æš (0, 0), (1, 0), (0, 1) ã«ããæœèšã«äžæ¹ã®ããŒãã,(â1, â2), (â1, 1) ã«ããæœèšã«ããäžæ¹ã®ããŒããå²ããµããš,åäžã®ããŒãã§å±ç€ºãè¡ã 2 ã€ã®æœèšéã®ç§»åæéã¯ãã¹ãŠ 3 以äžã«ãªã.ç§»åæéããã¹ãŠ 2 以äžã«ããããšã¯ã§ããªãã®ã§,3 ãåºåãã. äžèšå顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
| 39,051
|
D: å¿åºŠ (Surmise) ãšããååã¯ãå¶æ°ã奜ãã§ããã $N$ åã®æŽæ° $A_1, A_2, A_3, \dots, A_N$ ã®äžã«å¶æ°ãããã€ãããæ°ããã å
¥å 1 è¡ç®ã«ã¯æŽæ° $N$ ãäžããããã 2 è¡ç®ã«ã¯ $N$ åã®æŽæ° $A_1, A_2, A_3, \dots, A_N$ ã空çœåºåãã§äžããããã åºå å¶æ°ã®åæ°ãåºåããããã ããæåŸã«æ¹è¡ãå
¥ããããšã å¶çŽ $N$ 㯠$1$ ä»¥äž $100$ 以äžã®æŽæ° $A_1, A_2, A_3, \dots, A_N$ 㯠$1$ ä»¥äž $100$ 以äžã®æŽæ° å
¥åäŸ1 5 4 3 5 2 6 åºåäŸ1 3 $A_1 = 4$ã$A_4 = 2$ ãš $A_5 = 6$ ãå¶æ°ã§ãããã£ãŠãå¶æ°ã®åæ°ã¯ $3$ ã€ã§ãã å
¥åäŸ2 3 2 2 2 åºåäŸ2 3 åãæ°ã§ãã$A_1, A_2, A_3, \dots, A_N$ ã®äžã®äœçœ®ãéãã®ã§ããã°ãå¥ã®ãã®ãšããŠã«ãŠã³ãããŸãã
| 39,052
|
Hit and Blow Let's play Hit and Blow game. A imagines four numbers and B guesses the numbers. After B picks out four numbers, A answers: The number of numbers which have the same place with numbers A imagined (Hit) The number of numbers included (but different place) in the numbers A imagined (Blow) For example, if A imagined numbers: 9 1 8 2 and B chose: 4 1 5 9 A should say 1 Hit and 1 Blow. Write a program which reads four numbers A imagined and four numbers B chose and prints the number of Hit and Blow respectively. You may assume that the four numbers are all different and within from 0 to 9. Input The input consists of multiple datasets. Each dataset set consists of: a 1 a 2 a 3 a 4 b 1 b 2 b 3 b 4 , where a i (0 †a i †9) is i -th number A imagined and b i (0 †b i †9) is i -th number B chose. The input ends with EOF. The number of datasets is less than or equal to 50. Output For each dataset, print the number of Hit and Blow in a line. These two numbers should be separated by a space. Sample Input 9 1 8 2 4 1 5 9 4 6 8 2 4 6 3 2 Output for the Sample Input 1 1 3 0
| 39,053
|
Score : 700 points Problem Statement Given is a sequence of N digits a_1a_2\ldots a_N , where each element is 1 , 2 , or 3 . Let x_{i,j} defined as follows: x_{1,j} := a_j \quad ( 1 \leq j \leq N ) x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad ( 2 \leq i \leq N and 1 \leq j \leq N+1-i ) Find x_{N,1} . Constraints 2 \leq N \leq 10^6 a_i = 1,2,3 (1 \leq i \leq N) Input Input is given from Standard Input in the following format: N a_1 a_2 \ldots a_N Output Print x_{N,1} . Sample Input 1 4 1231 Sample Output 1 1 x_{1,1},x_{1,2},x_{1,3},x_{1,4} are respectively 1,2,3,1 . x_{2,1},x_{2,2},x_{2,3} are respectively |1-2| = 1,|2-3| = 1,|3-1| = 2 . x_{3,1},x_{3,2} are respectively |1-1| = 0,|1-2| = 1 . Finally, x_{4,1} = |0-1| = 1 , so the answer is 1 . Sample Input 2 10 2311312312 Sample Output 2 0
| 39,054
|
Score : 1400 points Problem Statement We will recursively define uninity of a tree, as follows: ( Uni is a Japanese word for sea urchins.) A tree consisting of one vertex is a tree of uninity 0 . Suppose there are zero or more trees of uninity k , and a vertex v . If a vertex is selected from each tree of uninity k and connected to v with an edge, the resulting tree is a tree of uninity k+1 . It can be shown that a tree of uninity k is also a tree of uninity k+1,k+2,... , and so forth. You are given a tree consisting of N vertices. The vertices of the tree are numbered 1 through N , and the i -th of the N-1 edges connects vertices a_i and b_i . Find the minimum k such that the given tree is a tree of uninity k . Constraints 2 ⊠N ⊠10^5 1 ⊠a_i, b_i ⊠N(1 ⊠i ⊠N-1) The given graph is a tree. Input The input is given from Standard Input in the following format: N a_1 b_1 : a_{N-1} b_{N-1} Output Print the minimum k such that the given tree is a tree of uninity k . Sample Input 1 7 1 2 2 3 2 4 4 6 6 7 7 5 Sample Output 1 2 A tree of uninity 1 consisting of vertices 1 , 2 , 3 and 4 can be constructed from the following: a tree of uninity 0 consisting of vertex 1 , a tree of uninity 0 consisting of vertex 3 , a tree of uninity 0 consisting of vertex 4 , and vertex 2 . A tree of uninity 1 consisting of vertices 5 and 7 can be constructed from the following: a tree of uninity 1 consisting of vertex 5 , and vertex 7 . A tree of uninity 2 consisting of vertices 1 , 2 , 3 , 4 , 5 , 6 and 7 can be constructed from the following: a tree of uninity 1 consisting of vertex 1 , 2 , 3 and 4 , a tree of uninity 1 consisting of vertex 5 and 7 , and vertex 6 . Sample Input 2 12 1 2 2 3 2 4 4 5 5 6 6 7 7 8 5 9 9 10 10 11 11 12 Sample Output 2 3
| 39,055
|
Problem A: Where is the Boundary An island country JAGAN in a certain planet is very long and narrow, and extends east and west. This long country is said to consist of two major cultural areas | the eastern and the western. Regions in the east tend to have the eastern cultural features and regions in the west tend to have the western cultural features, but, of course, the boundary between the two cultural areas is not clear, which has been an issue. You are given an assignment estimating the boundary using a given data set. More precise specification of the assignment is as follows: JAGAN is divided into $n$ prefectures forming a line in the east-west direction. Each prefecture is numbered 1, 2, ..., $n$ from WEST to EAST . Each data set consists of $m$ features, which has 'E' (east) or 'W' (west) for each prefecture. These data indicate that each prefecture has eastern or western features from $m$ different point of views, for example, food, clothing, and so on. In the estimation, you have to choose a cultural boundary achieving the minimal errors. That is, you have to minimize the sum of 'W's in the eastern side and 'E's in the western side. In the estimation, you can choose a cultural boundary only from the boundaries between two prefectures. Sometimes all prefectures may be estimated to be the eastern or the western cultural area. In these cases, to simplify, you must virtually consider that the boundary is placed between prefecture No. 0 and No. 1 or between prefecture No. $n$ and No. $n+1$. When you get multiple minimums, you must output the most western (least-numbered) result. Write a program to solve the assignment. Input Each input is formatted as follows: $n$ $m$ $d_{11} ... d_{1n}$ : : $d_{m1} ... d_{mn}$ The first line consists of two integers $n$ ($1 \leq n \leq 10,000$), $m$ ($1 \leq m \leq 100$), which indicate the number of prefectures and the number of features in the assignment. The following m lines are the given data set in the assignment. Each line contains exactly $n$ characters. The $j$-th character in the $i$-th line $d_{ij}$ is 'E' (east) or 'W' (west), which indicates $j$-th prefecture has the eastern or the western feature from the $i$-th point of view. Output Print the estimated result in a line. The output consists of two integers sorted in the ascending order which indicate two prefectures touching the boundary. Sample Input 2 1 WE Output for the Sample Input 1 2 Sample Input 3 2 WWE WEE Output for the Sample Input 1 2 Both estimates "1 2" and "2 3" achieve 1 error as the minimum. From the restriction that you must adopt the most western estimate, you must output "1 2". Sample Input 3 1 WWW Output for the Sample Input 3 4 In this case, all the prefectures are western. As described in the problem statement, you must virtually consider that the boundary is placed between third and fourth prefectures. Sample Input 3 1 WEW Output for the Sample Input 1 2 You cannot assume that 'E's and 'W's are separated.
| 39,056
|
Articulation Points Find articulation points of a given undirected graph G(V, E) . A vertex in an undirected graph is an articulation point (or cut vertex) iff removing it disconnects the graph. Input |V| |E| s 0 t 0 s 1 t 1 : s |E|-1 t |E|-1 , where |V| is the number of vertices and |E| is the number of edges in the graph. The graph vertices are named with the numbers 0, 1,..., |V| -1 respectively. s i and t i represent source and target verticess of i -th edge (undirected). Output A list of articulation points of the graph G ordered by name. Constraints 1 †|V| †100,000 0 †|E| †100,000 The graph is connected There are no parallel edges There are no self-loops Sample Input 1 4 4 0 1 0 2 1 2 2 3 Sample Output 1 2 Sample Input 2 5 4 0 1 1 2 2 3 3 4 Sample Output 2 1 2 3
| 39,057
|
Score : 300 points Problem Statement There are N monsters, numbered 1, 2, ..., N . Initially, the health of Monster i is A_i . Below, a monster with at least 1 health is called alive. Until there is only one alive monster, the following is repeated: A random alive monster attacks another random alive monster. As a result, the health of the monster attacked is reduced by the amount equal to the current health of the monster attacking. Find the minimum possible final health of the last monster alive. Constraints All values in input are integers. 2 \leq N \leq 10^5 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the minimum possible final health of the last monster alive. Sample Input 1 4 2 10 8 40 Sample Output 1 2 When only the first monster keeps on attacking, the final health of the last monster will be 2 , which is minimum. Sample Input 2 4 5 13 8 1000000000 Sample Output 2 1 Sample Input 3 3 1000000000 1000000000 1000000000 Sample Output 3 1000000000
| 39,058
|
Score : 100 points Problem Statement Rng is going to a festival. The name of the festival is given to you as a string S , which ends with FESTIVAL , from input. Answer the question: "Rng is going to a festival of what?" Output the answer. Here, assume that the name of "a festival of s " is a string obtained by appending FESTIVAL to the end of s . For example, CODEFESTIVAL is a festival of CODE . Constraints 9 \leq |S| \leq 50 S consists of uppercase English letters. S ends with FESTIVAL . Input Input is given from Standard Input in the following format: S Output Print the answer to the question: "Rng is going to a festival of what?" Sample Input 1 CODEFESTIVAL Sample Output 1 CODE This is the same as the example in the statement. Sample Input 2 CODEFESTIVALFESTIVAL Sample Output 2 CODEFESTIVAL This string is obtained by appending FESTIVAL to the end of CODEFESTIVAL , so it is a festival of CODEFESTIVAL . Sample Input 3 YAKINIKUFESTIVAL Sample Output 3 YAKINIKU
| 39,059
|
Score : 200 points Problem Statement There are N balls in the xy -plane. The coordinates of the i -th of them is (x_i, i) . Thus, we have one ball on each of the N lines y = 1 , y = 2 , ... , y = N . In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B. Then, he placed the i -th type-A robot at coordinates (0, i) , and the i -th type-B robot at coordinates (K, i) . Thus, now we have one type-A robot and one type-B robot on each of the N lines y = 1 , y = 2 , ... , y = N . When activated, each type of robot will operate as follows. When a type-A robot is activated at coordinates (0, a) , it will move to the position of the ball on the line y = a , collect the ball, move back to its original position (0, a) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. When a type-B robot is activated at coordinates (K, b) , it will move to the position of the ball on the line y = b , collect the ball, move back to its original position (K, b) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. Snuke will activate some of the 2N robots to collect all of the balls. Find the minimum possible total distance covered by robots. Constraints 1 \leq N \leq 100 1 \leq K \leq 100 0 < x_i < K All input values are integers. Inputs Input is given from Standard Input in the following format: N K x_1 x_2 ... x_N Outputs Print the minimum possible total distance covered by robots. Sample Input 1 1 10 2 Sample Output 1 4 There are just one ball, one type-A robot and one type-B robot. If the type-A robot is used to collect the ball, the distance from the robot to the ball is 2 , and the distance from the ball to the original position of the robot is also 2 , for a total distance of 4 . Similarly, if the type-B robot is used, the total distance covered will be 16 . Thus, the total distance covered will be minimized when the type-A robot is used. The output should be 4 . Sample Input 2 2 9 3 6 Sample Output 2 12 The total distance covered will be minimized when the first ball is collected by the type-A robot, and the second ball by the type-B robot. Sample Input 3 5 20 11 12 9 17 12 Sample Output 3 74
| 39,060
|
Score : 400 points Problem Statement There are N integers, A_1, A_2, ..., A_N , arranged in a row in this order. You can perform the following operation on this integer sequence any number of times: Operation : Choose an integer i satisfying 1 \leq i \leq N-1 . Multiply both A_i and A_{i+1} by -1 . Let B_1, B_2, ..., B_N be the integer sequence after your operations. Find the maximum possible value of B_1 + B_2 + ... + B_N . Constraints All values in input are integers. 2 \leq N \leq 10^5 -10^9 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the maximum possible value of B_1 + B_2 + ... + B_N . Sample Input 1 3 -10 5 -4 Sample Output 1 19 If we perform the operation as follows: Choose 1 as i , which changes the sequence to 10, -5, -4 . Choose 2 as i , which changes the sequence to 10, 5, 4 . we have B_1 = 10, B_2 = 5, B_3 = 4 . The sum here, B_1 + B_2 + B_3 = 10 + 5 + 4 = 19 , is the maximum possible result. Sample Input 2 5 10 -4 -8 -11 3 Sample Output 2 30 Sample Input 3 11 -1000000000 1000000000 -1000000000 1000000000 -1000000000 0 1000000000 -1000000000 1000000000 -1000000000 1000000000 Sample Output 3 10000000000 The output may not fit into a 32 -bit integer type.
| 39,061
|
Score : 1800 points Problem Statement We have an N \times M grid. The square at the i -th row and j -th column will be denoted as (i,j) . Particularly, the top-left square will be denoted as (1,1) , and the bottom-right square will be denoted as (N,M) . Takahashi painted some of the squares (possibly zero) black, and painted the other squares white. We will define an integer sequence A of length N , and two integer sequences B and C of length M each, as follows: A_i(1\leq i\leq N) is the minimum j such that (i,j) is painted black, or M+1 if it does not exist. B_i(1\leq i\leq M) is the minimum k such that (k,i) is painted black, or N+1 if it does not exist. C_i(1\leq i\leq M) is the maximum k such that (k,i) is painted black, or 0 if it does not exist. How many triples (A,B,C) can occur? Find the count modulo 998244353 . Notice In this problem, the length of your source code must be at most 20000 B. Note that we will invalidate submissions that exceed the maximum length. Constraints 1 \leq N \leq 8000 1 \leq M \leq 200 N and M are integers. Partial Score 1500 points will be awarded for passing the test set satisfying N\leq 300 . Input Input is given from Standard Input in the following format: N M Output Print the number of triples (A,B,C) , modulo 998244353 . Sample Input 1 2 3 Sample Output 1 64 Since N=2 , given B_i and C_i , we can uniquely determine the arrangement of black squares in each column. For each i , there are four possible pairs (B_i,C_i) : (1,1) , (1,2) , (2,2) and (3,0) . Thus, the answer is 4^M=64 . Sample Input 2 4 3 Sample Output 2 2588 Sample Input 3 17 13 Sample Output 3 229876268 Sample Input 4 5000 100 Sample Output 4 57613837
| 39,062
|
Rectangle Write a program which calculates the area and perimeter of a given rectangle. Input The length a and breadth b of the rectangle are given in a line separated by a single space. Output Print the area and perimeter of the rectangle in a line. The two integers should be separated by a single space. Constraints 1 †a , b †100 Sample Input 1 3 5 Sample Output 1 15 16
| 39,063
|
Score : 1300 points Problem Statement You are playing a game and your goal is to maximize your expected gain. At the beginning of the game, a pawn is put, uniformly at random, at a position p\in\{1,2,\dots, N\} . The N positions are arranged on a circle (so that 1 is between N and 2 ). The game consists of turns. At each turn you can either end the game, and get A_p dollars (where p is the current position of the pawn), or pay B_p dollar to keep playing. If you decide to keep playing, the pawn is randomly moved to one of the two adjacent positions p-1 , p+1 (with the identifications 0 = N and N+1=1 ). What is the expected gain of an optimal strategy? Note : The "expected gain of an optimal strategy" shall be defined as the supremum of the expected gain among all strategies such that the game ends in a finite number of turns. Constraints 2 \le N \le 200,000 0 \le A_p \le 10^{12} for any p = 1,\ldots, N 0 \le B_p \le 100 for any p = 1, \ldots, N 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 Print a single real number, the expected gain of an optimal strategy. Your answer will be considered correct if its relative or absolute error does not exceed 10^{-10} . Sample Input 1 5 4 2 6 3 5 1 1 1 1 1 Sample Output 1 4.700000000000 Sample Input 2 4 100 0 100 0 0 100 0 100 Sample Output 2 50.000000000000 Sample Input 3 14 4839 5400 6231 5800 6001 5200 6350 7133 7986 8012 7537 7013 6477 5912 34 54 61 32 52 61 21 43 65 12 45 21 1 4 Sample Output 3 7047.142857142857 Sample Input 4 10 470606482521 533212137322 116718867454 746976621474 457112271419 815899162072 641324977314 88281100571 9231169966 455007126951 26 83 30 59 100 88 84 91 54 61 Sample Output 4 815899161079.400024414062
| 39,064
|
Score : 1200 points Problem Statement One day Mr. Takahashi picked up a dictionary containing all of the N ! permutations of integers 1 through N . The dictionary has N ! pages, and page i ( 1 †i †N! ) contains the i -th permutation in the lexicographical order. Mr. Takahashi wanted to look up a certain permutation of length N in this dictionary, but he forgot some part of it. His memory of the permutation is described by a sequence P_1, P_2, ..., P_N . If P_i = 0 , it means that he forgot the i -th element of the permutation; otherwise, it means that he remembered the i -th element of the permutation and it is P_i . He decided to look up all the possible permutations in the dictionary. Compute the sum of the page numbers of the pages he has to check, modulo 10^9 + 7 . Constraints 1 †N †500000 0 †P_i †N P_i â P_j if i â j ( 1 †i, j †N ), P_i â 0 and P_j â 0 . Partial Score In test cases worth 500 points, 1 †N †3000 . Input The input is given from Standard Input in the following format: N P_1 P_2 ... P_N Output Print the sum of the page numbers of the pages he has to check, as modulo 10^9 + 7 . Sample Input 1 4 0 2 3 0 Sample Output 1 23 The possible permutations are [ 1 , 2 , 3 , 4 ] and [ 4 , 2 , 3 , 1 ]. Since the former is on page 1 and the latter is on page 22 , the answer is 23 . Sample Input 2 3 0 0 0 Sample Output 2 21 Since all permutations of length 3 are possible, the answer is 1 + 2 + 3 + 4 + 5 + 6 = 21 . Sample Input 3 5 1 2 3 5 4 Sample Output 3 2 Mr. Takahashi remembered all the elements of the permutation. Sample Input 4 1 0 Sample Output 4 1 The dictionary consists of one page. Sample Input 5 10 0 3 0 0 1 0 4 0 0 0 Sample Output 5 953330050
| 39,065
|
M: æååéå å顿 以äžã®æ¡ä»¶ãæºããæååéå $S$ ã®ãã¡ãèŠçŽ æ°ãæå€§ãšãªããã®ã $1$ ã€æ§æããŠãã ããã $S$ ã«å«ãŸããæååã®é·ã㯠$1$ ä»¥äž $N$ 以äžã§ããã $S$ ã«å«ãŸããæååã®é·ãã¯ããããç°ãªãã $S$ ã«å«ãŸããæååã¯ãæå 0 , 1 ã®ã¿ãããªãã $S$ ã«å«ãŸããã©ã® $2$ ã€ã®æååã«ã€ããŠããäžæ¹ãããäžæ¹ã®éšåæååãšãªããªãã ãã ããæåå $x$ ã®éšåæååãšã¯ã $x$ ã®å
é ãšæ«å°Ÿãã $0$ æå以äžã®æåãåãé€ãããšã§åŸãããæååã®ããšãèšããŸãã å¶çŽ $1 \leq N \leq 300$ $N$ ã¯æŽæ°ã§ãã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããã $N$ åºå æ¡ä»¶ãæºããæååéå $S$ ã®ãã¡ãèŠçŽ æ°ãæå€§ãšãªããã®ã $1$ ã€åºåããããã®ãã㪠$S$ ã¯è€æ°ååšããå¯èœæ§ãããããã©ããåºåããŠãæ£çãšãªãã å
·äœçã«ã¯ã以äžã®åœ¢åŒã§åºåããã $1$ è¡ç®ã« $S$ ã®èŠçŽ æ° $K$ ãåºåããã $2$ è¡ç®ãã $K+1$ è¡ç®ã« $S$ ã®èŠçŽ ããã¹ãŠåºåãããåè¡ã«ã¯ $S$ ã®èŠçŽ ã $1$ ã€åºåããã $K$ $S_1$ $S_2$ $\vdots$ $S_K$ å
¥åäŸ1 2 åºåäŸ1 2 0 11 æååéå $\{0, 11\}$ ã¯ãæ¡ä»¶ãæºããéåã®äžã§èŠçŽ æ°ãæå€§ãšãªããã®ã§ãã å
¥åäŸ2 1 åºåäŸ2 1 0
| 39,066
|
Score : 800 points Problem Statement Niwango has N cards, numbered 1,2,\ldots,N . He will now arrange these cards in a row. Niwango wants to know if there is a way to arrange the cards while satisfying all the N conditions below. To help him, determine whether such a way exists. If the answer is yes, also find the lexicographically smallest such arrangement. To the immediate right of Card 1 (if any) is NOT Card a_1 . To the immediate right of Card 2 (if any) is NOT Card a_2 . \vdots To the immediate right of Card N (if any) is NOT Card a_N . Constraints 2 \leq N \leq 10^{5} 1 \leq a_i \leq N a_i \neq i Input Input is given from Standard Input in the following format: N a_1 a_2 \ldots a_N Output If no arrangements satisfy the conditions, print -1 . If such arrangements exist, print the lexicographically smallest such arrangement, in the following format: b_1 b_2 \ldots b_N Here, b_i represents the i -th card from the left. Sample Input 1 4 2 3 4 1 Sample Output 1 1 3 2 4 The arrangement (1,2,3,4) is lexicographically smaller than (1,3,2,4) , but is invalid, since it violates the condition "to the immediate right of Card 1 is not Card 2 ." Sample Input 2 2 2 1 Sample Output 2 -1 If no arrangements satisfy the conditions, print -1 . Sample Input 3 13 2 3 4 5 6 7 8 9 10 11 12 13 12 Sample Output 3 1 3 2 4 6 5 7 9 8 10 12 11 13
| 39,067
|
Problem H: Inherit the Spheres In the year 2xxx, an expedition team landing on a planet found strange objects made by an ancient species living on that planet. They are transparent boxes containing opaque solid spheres (Figure 1). There are also many lithographs which seem to contain positions and radiuses of spheres. Figure 1: A strange object Initially their objective was unknown, but Professor Zambendorf found the cross section formed by a horizontal plane plays an important role. For example, the cross section of an object changes as in Figure 2 by sliding the plane from bottom to top. Figure 2: Cross sections at different positions He eventually found that some information is expressed by the transition of the number of connected figures in the cross section, where each connected figure is a union of discs intersecting or touching each other, and each disc is a cross section of the corresponding solid sphere. For instance, in Figure 2, whose geometry is described in the first sample dataset later, the number of connected figures changes as 0, 1, 2, 1, 2, 3, 2, 1, and 0, at z = 0.0000, 162.0000, 167.0000, 173.0004, 185.0000, 191.9996, 198.0000, 203.0000, and 205.0000, respectively. By assigning 1 for increment and 0 for decrement, the transitions of this sequence can be expressed by an 8-bit binary number 11011000. For helping further analysis, write a program to determine the transitions when sliding the horizontal plane from bottom ( z = 0) to top ( z = 36000). Input The input consists of a series of datasets. Each dataset begins with a line containing a positive integer, which indicates the number of spheres N in the dataset. It is followed by N lines describing the centers and radiuses of the spheres. Each of the N lines has four positive integers X i , Y i , Z i , and R i ( i = 1, . . . , N ) describing the center and the radius of the i -th sphere, respectively. You may assume 1 †N †100, 1 †R i †2000, 0 < X i - R i < X i + R i < 4000, 0 < Y i - R i < Y i + R i < 16000, and 0 < Z i - R i < Z i + R i < 36000. Each solid sphere is defined as the set of all points ( x , y , z ) satisfying ( x - X i ) 2 + ( y - Y i ) 2 + ( z - Z i ) 2 †R i 2 . A sphere may contain other spheres. No two spheres are mutually tangent. Every Z i ± R i and minimum/maximum z coordinates of a circle formed by the intersection of any two spheres differ from each other by at least 0.01. The end of the input is indicated by a line with one zero. Output For each dataset, your program should output two lines. The first line should contain an integer M indicating the number of transitions. The second line should contain an M -bit binary number that expresses the transitions of the number of connected figures as specified above. Sample Input 3 95 20 180 18 125 20 185 18 40 27 195 10 1 5 5 5 4 2 5 5 5 4 5 5 5 3 2 5 5 5 4 5 7 5 3 16 2338 3465 29034 710 1571 14389 25019 842 1706 8015 11324 1155 1899 4359 33815 888 2160 10364 20511 1264 2048 8835 23706 1906 2598 13041 23679 618 1613 11112 8003 1125 1777 4754 25986 929 2707 9945 11458 617 1153 10358 4305 755 2462 8450 21838 934 1822 11539 10025 1639 1473 11939 12924 638 1388 8519 18653 834 2239 7384 32729 862 0 Output for the Sample Input 8 11011000 2 10 2 10 2 10 28 1011100100110101101000101100
| 39,068
|
äžéãªã€ã¯ã¿åã¯æã£ãŠãã倧äºãªæåå T ããŠã£ã«ã¹ã«ãã£ãŠç°ãªãæåå T' ã«æžãæããããŠããŸã£ãããã®ãŠã£ã«ã¹ã T ã®ïŒæåãç°ãªãæåã«æžãæããŠããŸã£ãããšãããã£ãŠãããããªãã¡ T ãš T' ã¯ã¡ããã©ïŒæåã®ã¿ç°ãªã£ãŠãããã€ã¯ã¿å㯠T ã埩å
ããããã«ã T ãåºçŸããŠãããšæãããææž S ãçšæããã T ã埩å
ããããã®äžæºåãšã㊠S ã®éšåæååã§ T ãšäžèŽããŠããå¯èœæ§ããããã®ã®åæ°ã調ã¹ããã æåå T' ãšææž S ãäžããããã S = a 1 a 2 a 3 . . . a |S| ã®é·ã |T'| ã®éšåæåå a k a k+1 . . . a k+|T'|â1 (1 †k †|S| â |T'| + 1) ã§ T' ãšæ¯èŒããŠ1æåã ãç°ãªããã®ã®æ°ãæ±ããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã S T' ïŒè¡ç®ã§ S ãäžããããã ïŒè¡ç®ã§ T' ãäžããããã S , T' ã¯ãããã倧æåãå°æåã®ã¢ã«ãã¡ãããã®ã¿ãããªãã Constraints å
¥åäžã®å倿°ã¯ä»¥äžã®å¶çŽãæºããã 1 †|S| †300,000 1 †|T'| †|S| Output æ¡ä»¶ãæºããéšåæååã®æ°ã1è¡ã«åºåããã Sample Input 1 abcbcdbc abc Output for the Sample Input 1 2 S ã®3çªç®ã®æåããå§ãŸãcbc, S ã®6çªç®ã®æåããå§ãŸãdbcãæ¡ä»¶ãæºããã Sample Input 2 aaaaaa aaaaaa Output for the Sample Input 2 0 å®å
šã«äžèŽããæååã¯æ°ããŠã¯ãªããªãã Sample Input 3 baaaaaaaa b Output for the Sample Input 3 8
| 39,069
|
åé¡ A : ããã°ã©ãã³ã°ã³ã³ãã¹ã æã¯ 20XX 幎ïŒäžç㯠Gââgle ç€Ÿã®æ¯é
ã«ãããã£ã¹ããã¢ã§ããïŒ çŸåšïŒäººã
ã®å𝿥œã¯ããã°ã©ãã³ã°ã³ã³ãã¹ãã«éãããŠããïŒ äŸãã°ïŒé±æ«ã«å®¶æã§ TâpCâder ã¢ãªãŒãã蚪ãããšããã®ã¯ãšãŠãããèŠãããå
æ¯ã§ããïŒ ãããïŒããã¯å
ã®äžçã®ããã°ã©ãã³ã°ã³ã³ãã¹ãã®å§¿ã«éããªãïŒ äžæ¹ã§ïŒGââgle ãšåæå¢åãã¶ã€ããåãéã®äžçã§ã¯ïŒ åœããããããã°ã©ãã³ã°ã³ã³ãã¹ããè¡ãããŠããïŒ èªåãä¹
ãã¶ãã«ããã°ã©ãã³ã°ã³ã³ãã¹ãã«åå ããŠã¿ããïŒ è¶³æ
£ããã«ïŒãŸãã¯ïŒããã°ã©ãã³ã°ã³ã³ãã¹ãã®çµæãåŠçããããã°ã©ã ã§ãæžããŠã¿ãããšã«ãããïŒ åé¡ M 人ã®åå è
ãå±
㊠N åã®åé¡ããæãããã°ã©ãã³ã°ã³ã³ãã¹ããèããïŒ ååå è
ã«é¢ããŠïŒååé¡ãè§£ããŠãããè§£ããŠããªãããäžããããã®ã§ïŒ æãå€ãåé¡ãè§£ããŠãã人ãè§£ããå顿°ãåºåããããã°ã©ã ãäœæããïŒ å
¥å å
¥åã®æåã®è¡ã¯ 2 ã€ã®æŽæ° M , N ãå«ãïŒ ããã¯ïŒåå è
æ°ãšå顿°ã衚ãïŒ ç¶ã M è¡ã«ã¯ïŒååå è
ãååé¡ãè§£ããŠãããè§£ããŠããªãããäžããããïŒ ãããã®è¡ã®ãã¡ã® i è¡ç®ã¯ N åã® 0 ã 1 ã®æ°å a i , 1 , a i , 2 , âŠ, a i , N ãæžãããŠããïŒ a i , j ã¯ä»¥äžã®ãããªæå³ãæã€ïŒ a i , j ã 0 ã®æïŒåå è
i ã¯åé¡ j ãè§£ããŠããªãïŒ a i , j ã 1 ã®æïŒåå è
i ã¯åé¡ j ãè§£ããŠããïŒ åºå æãå€ãåé¡ãè§£ããŠãã人ãè§£ããå顿°ãåºåããïŒ å¶çŽ 1 †M †20 1 †N †20 å
¥åºåäŸ å
¥åºåäŸ 1 å
¥åäŸ 1: 3 4 1 0 1 0 1 1 1 0 0 0 0 1 å
¥åäŸ 1 ã«å¯ŸããåºåäŸ: 3 åå è
1 㯠2 åïŒåé¡ 1, 3)ïŒ åå è
2 㯠3 åïŒåé¡ 1, 2, 3ïŒïŒ åå è
3 㯠1 åïŒåé¡ 4ïŒãè§£ããŠããïŒ æãå€ãåé¡ããšããŠããã®ã¯åå è
2 ã§ïŒ ãã®å顿°ã¯ 3 ã§ããïŒ3 ãæ£ããåºåã§ããïŒ å
¥åºåäŸ 2 å
¥åäŸ 2: 3 4 1 1 1 1 1 1 1 1 1 1 1 1 å
¥åäŸ 2 ã«å¯ŸããåºåäŸ: 4 å
šãŠã®åå è
ã 4 åå
šãŠãè§£ããŠããïŒ æãå€ãåé¡ãè§£ããŠããåå è
ãšããã®ã¯ åå è
å
šå¡ã§ããïŒãã®å顿°ã¯ 4 ã§ããïŒ å
¥åºåäŸ 3 å
¥åäŸ 3: 1 1 0 å
¥åäŸ 3 ã«å¯ŸããåºåäŸ: 0
| 39,070
|
å¹³æ¹æ¡äžæ³ å€å
žçãªä¹±æ°çææ¹æ³ã®äžã€ã§ããå¹³æ¹æ¡äžæ³ã®ããã°ã©ã ãäœæããŸããå¹³æ¹æ¡äžæ³ã¯ããã©ã³ãã€ãã³ã«ãã£ãŠ 1940 幎代åã°ã«ææ¡ãããæ¹æ³ã§ãã å¹³æ¹æ¡äžæ³ã¯ãçæããä¹±æ°ã®æ¡æ°ã n ãšãããšããåæå€ s ã®2ä¹ãèšç®ãããã®æ°å€ã 2n æ¡ã®æ°å€ãšã¿ãŠãïŒäžã®äŸã®ããã« 2 ä¹ããæ¡æ°ãè¶³ããªããšãã¯ã0 ãè£ããŸããïŒãã®äžå€®ã«ãã n åã®æ°åãæåã®ä¹±æ°ãšããŸããæ¬¡ã«ãã®ä¹±æ°ã 2 ä¹ããŠãåãæ§ã«ãäžå€®ã«ãã n åã®æ°åããšã£ãŠã次ã®ä¹±æ°ãšããŸããäŸãã°ã123 ãåæå€ãšãããš 123 2 = 00015129 â 0151 151 2 = 00022801 â 0228 228 2 = 00051984 â 0519 519 2 = 00269361 â 2693 2693 2 = 07252249 â 2522 ã®æ§ã«ãªããŸãããã®æ¹æ³ãçšããŠãåæå€ s ïŒ10000æªæºã®æ£ã®æŽæ°ïŒãå
¥åãšãã n = 4 ã®å Žåã®ä¹±æ°ã 10 åçæãåºåããããã°ã©ã ãäœæããŠãã ããã Input è€æ°ã®ããŒã¿ã»ãããäžããããŸããïŒè¡ç®ã«ããŒã¿ã»ããã®æ° d ( d †10) ãäžããããŸããåããŒã¿ã»ãããšããŠãïŒè¡ã«åæå€ s ïŒæŽæ°ã1 †s < 10000ïŒãäžããããŸãã Output åããŒã¿ã»ããã«å¯ŸããŠã Case x : ( x 㯠1 ããå§ãŸãããŒã¿ã»ããçªå·) ïŒåç®ã®çæããä¹±æ°ïŒæŽæ°ïŒ ïŒåç®ã®çæããä¹±æ°ïŒæŽæ°ïŒ ïŒ ïŒ ïŒïŒåç®ã®çæããä¹±æ°ïŒæŽæ°ïŒ ãåºåããŠãã ããã Sample Input 2 123 567 Output for the Sample Input Case 1: 151 228 519 2693 2522 3604 9888 7725 6756 6435 Case 2: 3214 3297 8702 7248 5335 4622 3628 1623 6341 2082
| 39,071
|
æ°Žãããã (Mizuyokan) å顿 æ°Žãããããšã¯ïŒããã«å°è±ãããªã逡ãåã«æµã蟌ãã§å¯å€©ã§åºããããšã«ããäœãããåèåã§ããïŒããŸïŒJOI åã®æå
ã«ã¯ïŒæšªé·ã®çŽæ¹äœã®åœ¢ãããæ°Žãããããã²ãšã€ããïŒJOI åã¯ïŒä»æ¥ã®ããã€ãšããŠãã®æ°Žãããããé£ã¹ãäºå®ã§ããïŒ ãã®æ°Žããããã«ã¯ïŒçžŠæ¹åã®åãç®ãå
šéšã§ N-1 ç®æã«å
¥ã£ãŠããïŒæ°Žããããã®é·ã㯠L_1 + L_2 + ... + L_N ã§ããïŒ i çªç® (1 ⊠i ⊠N-1) ã®åãç®ã¯ïŒå·Šãã L_1 + L_2 + ... + L_i ã®äœçœ®ã«ããïŒ ãã®æ°Žããããã¯äžžããšé£ã¹ãã«ã¯å€§ããããã®ã§ïŒJOI åã¯ïŒæ°Žããããã«å
¥ã£ãŠããåãç®ãã 1 ç®æä»¥äžãéžã³ïŒéžãã åãç®ã«æ²¿ã£ãŠæ°Žãããããåã£ãŠïŒè€æ°ã®ããŒã¹ã«åãåããããšã«ããïŒãã ãïŒããŒã¹ã®å€§ãããäžæãã§ã¯èŠæ ããæªãã®ã§ïŒé·ãæå€§ã®ããŒã¹ãšæå°ã®ããŒã¹ã®é·ãã®å·®ãã§ããã ãå°ãããªãããã«åãããšã«ããïŒ é·ãæå€§ã®ããŒã¹ãšæå°ã®ããŒã¹ã®é·ãã®å·®ã®æå°å€ãæ±ããïŒ å¶çŽ 2 \leq N \leq 50 1 \leq L_i \leq 1000 (1 \leq i \leq N) å
¥åã»åºå å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããïŒ N L_1 L_2 : L_N åºå é·ãæå€§ã®ããŒã¹ãšæå°ã®ããŒã¹ã®é·ãã®å·®ã®æå°å€ã 1 è¡ã§åºåããïŒ å
¥åºåäŸ å
¥åäŸ 1 11 2 3 8 4 7 6 6 5 1 7 5 åºåäŸ 1 2 ãã®äŸã§ã¯ïŒ 4 çªç®ããã³ 7 çªç®ã®åãç®ã«æ²¿ã£ãŠåãåããããšã§ïŒé·ã 17, 19, 18 ã® 3 ã€ã®ããŒã¹ã«åãåããããšãã§ããïŒ ãã®ãšãïŒãã¡ã°ãé·ãããŒã¹ã¯é·ã 19 ã§ïŒãã¡ã°ãçãããŒã¹ã¯é·ã 17 ã§ããã®ã§ïŒé·ãã®å·®ã¯ 2 ãšãªãïŒ ãããæå°å€ãªã®ã§ïŒ 2 ãåºåããïŒ å
¥åäŸ 2 2 1 10 åºåäŸ 2 9 ã©ããªã«å€§ãããäžæãã§ãã£ãŠãïŒå¿
ã 1 ç®æä»¥äžãåãå¿
èŠãããïŒ å
¥åäŸ 3 5 5 5 5 5 5 åºåäŸ 3 0 ãã®äŸã§ã¯æ°Žãããããã¡ããã©åã倧ããã® 5 ã€ã®ããŒã¹ã«åå²ã§ããïŒ æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒäœ ã第 17 åæ¥æ¬æ
å ±ãªãªã³ãã㯠JOI 2017/2018 äºéžç«¶æèª²é¡ã
| 39,072
|
ç¯ç¯ äŒæŽ¥è¥æŸåžã¯ãæŽå²ã®çºããšããŠç¥ãããŠããŸããä»ããçŽ 400 幎åãè²çæ°é·ã«ããåäžçºã®éªšæ ŒãäœãããŸãããããã®åŸã埳å·äžä»£å°è»å®¶å
å
¬ã®ç°æ¯åŒãä¿ç§æ£ä¹ãå
¬ãè©ç¥ãšããäŒæŽ¥è© 23 äžç³ã®äžå¿éœåžãšããŠçºå±ããŸãããä»ã§ãåžå
ã®ããããšããã«å²è·¡ãææ¥ã®é¢åœ±ãæ®ã£ãŠãããããæ¯å¹Žãå
šåœããå€ãã®èгå
客ã蚪ããŠããŸãã ä»å¹Žã¯ã倧河ãã©ãã§ãæ°éžçµïŒããæŸéãããŠãããããæ°éžçµãããã®å°(*1)ãšããŠã倧å¹
ã«èгå
客ãå¢å ããŠããŸããããã§åžã§ã¯ãåžå
ã«ç¹åšããå²è·¡ãçµã¶éãæ²¿ãã« 100 m ééã§ç¯ç¯ãèšçœ®ããŠé£ŸãããŠãããšã«ããŸãããç¯ç¯ã食ã£ãŠããéãã蟿ãã°åžå
ã®å
šãŠã®å²è·¡ã«å°éã§ããããã«èšçœ®ããããšãæ¡ä»¶ã§ãããäžçæžãã§ãã©ããå¿
èŠã¯ãããŸãããããããäºç®ãéãããŠããã®ã§èšçœ®ããç¯ç¯ã®æ°ãæå°éã«ããå¿
èŠããããŸãã å²è·¡ãšå²è·¡ãçµã¶éãã®ããŒã¿ãèªã¿èŸŒãã§ãå¿
èŠæå°éã®ç¯ç¯ã®æ°ãåºåããããã°ã©ã ãäœæããŠäžããããã ããå²è·¡ãšå²è·¡ã®éã®è·é¢ã¯ 200 m 以äžã§ã100 ã®åæ°ã§äžããããŸãããã®ãã®ã®å²è·¡ããäžçªè¿ãç¯ç¯ãŸã§ã®è·é¢ã¯ 100 m ã§ãåžå
ã®å²è·¡ã¯ 100 ç®æä»¥å
ã§ããå²è·¡èªèº«ã«ã¯ç¯ç¯ãèšçœ®ããå¿
èŠã¯ãããŸããã (*1) æ°éžçµã¯äŒæŽ¥è©åŸ¡é ãšãã圢ã§çºè¶³ãçœèéã®æ²åã§ç¥ãããäŒæŽ¥æèŸ°æŠäºã«åæŠãåžå
倩寧寺ã«åæ¹æ³äžãè¿è€åã®å¢ãå»ºç« Input è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã n m a 1 , b 1 , d 1 a 2 , b 2 , d 2 : a m , b m , d m åããŒã¿ã»ããã®æåã® 1 è¡ã«ã¯å²è·¡ã®ç®ææ° n ãäžããããŸããç¶ããŠå²è·¡ãšå²è·¡ãçµã¶éãã®æ° m ãäžããããŸããç¶ã m è¡ã« ã«ã³ãã§åºåãããŠã3 ã€ã®æ°æ° a i , b i , d i ãäžããããŸãã a i , b i ã¯å²è·¡ã®çªå·ã§ããå²è·¡ã®çªå·ã¯ 0 çªãã n - 1 çªãŸã§æ¯ãããŠããŸãã a i b i ã¯ããããçµã¶éããããããšã瀺ãã d i 㯠a i b i éã®éè·¯ã®è·é¢ã衚ããŸãã n ã 0 ã®ãšãå
¥åã®æåŸãšããŸããããŒã¿ã»ããã®æ°ã¯ 20 ãè¶
ããŸããã Output åããŒã¿ã»ããã«å¯ŸããŠãå¿
èŠæå°éã®ç¯ç¯ã®æ°ãïŒè¡ã«åºåããŠäžããã Sample Input 4 4 0,1,1500 0,2,2000 1,2,600 1,3,500 0 Output for the Sample Input 23
| 39,073
|
Extraordinary Girl (I) She is an extraordinary girl. She works for a library. Since she is young and cute, she is forced to do a lot of laborious jobs. The most annoying job for her is to put returned books into shelves, carrying them by a cart. The cart is large enough to carry many books, but too heavy for her. Since she is delicate, she wants to walk as short as possible when doing this job. The library has 4N shelves (1 <= N <= 10000), three main passages, and N + 1 sub passages. Each shelf is numbered between 1 to 4N as shown in Figure 1. Horizontal dashed lines correspond to main passages, while vertical dashed lines correspond to sub passages. She starts to return books from the position with white circle in the figure and ends at the position with black circle. For simplicity, assume she can only stop at either the middle of shelves or the intersection of passages. At the middle of shelves, she put books with the same ID as the shelves. For example, when she stops at the middle of shelf 2 and 3, she can put books with ID 2 and 3. Since she is so lazy that she doesnât want to memorize a complicated route, she only walks main passages in forward direction (see an arrow in Figure 1). The walk from an intersection to its adjacent intersections takes 1 cost. It means the walk from the middle of shelves to its adjacent intersection, and vice versa, takes 0.5 cost. You, as only a programmer amoung her friends, are to help her compute the minimum possible cost she takes to put all books in the shelves. Input The first line of input contains the number of test cases, T . Then T test cases follow. Each test case consists of two lines. The first line contains the number N , and the second line contains 4N characters, either Y or N . Y in n-th position means there are some books with ID n, and N means no book with ID n. Output The output should consists of T lines, each of which contains one integer, the minimum possible cost, for each test case. Sample Input 2 2 YNNNNYYY 4 NYNNYYNNNYNYYNNN Output for the Sample Input 6 9
| 39,074
|
ææã€ãã€ã
ã®è³æº 人é¡ã¯ã€ãã«ç¥ççåœäœã®ååšããææã€ãã€ã
ãçºèŠãããææã€ãã€ã
ã§ã¯ç§åŠã鲿©ããŠããã®ã§ãæ¬¡ç¬¬ã«æã
ãšã®å
±åç ç©¶ãçãã«ãããªãããããã«ãªã£ãã ææã€ãã€ã
ã§ã¯ãã³ãšããè«ãéèŠãªè³æºãšã¿ãªãããŠããããã³ã¯å¹Œè«ãããåããŠæè«ã«ãªãããã³ã®çæ¯åã§ã¯ãã³ã®å¹Œè«ã矀ããŠçæ¯ããŠãã矀çãããã€ãããããã®ãããªçŸ€çãäžåã«äžŠãã§ãããææã€ãã€ã
ã®ãã€ãªãã¯ãããžãŒã䜿ããšã矀çã«å¯ŸããŠä»¥äžã®ãããªæäœãã§ããã æå®ããç¯å²ã®ãã¹ãŠã®çŸ€çã«ãåãæ°ã®å¹Œè«ã远å ããã æå®ããç¯å²ã®ãã¹ãŠã®çŸ€çã§ãæå®ããæ°ã®å¹Œè«ãæè«ã«ãåããããåãã幌è«ã®æ°ã®åèšãæ±ããããã®ãšãããåããã幌è«ã®æ°ãäžã€ã ãæå®ã§ããã ïŒã€ç®ã®æäœã§ã¯ãæå®ããæ°ããã幌è«ã®æ°ãå°ãªã矀çã«ã€ããŠã¯ããã®çŸ€çã«ãããã¹ãŠã®å¹Œè«ããåããããããšãã°ã矀çïŒã«å¹Œè«ãïŒå¹ã矀çïŒã«å¹Œè«ãïŒå¹ããå Žåã矀çïŒããïŒã®ç¯å²ã«å¯ŸããŠãåãããæ°ïŒãæå®ãããšã矀çïŒããã¯ïŒå¹ã矀çïŒããã¯ïŒå¹ãæè«ã«ããããšã«ãªãããã®ãšãã«ãåãã幌è«ã®æ°ã®åèšã¯ïŒå¹ã§ããã ä»åã®å
±åç ç©¶ã§ã¯ãæã
人é¡ããã³ã®å¹Œè«ã«å¯Ÿãããããã®æäœã®ã·ãã¥ã¬ãŒã·ã§ã³ãæ
åœããããšãšãªã£ããããã¯æã
ã®ç§åŠã®åã瀺ããšãã§ããã å矀çã«ååšãã幌è«ã®æ
å ±ãäžãããããšãããããã«å¯Ÿããæäœãã·ãã¥ã¬ãŒã·ã§ã³ããããã°ã©ã ãäœæããã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã $N$ $c_1$ $c_2$ : $c_N$ $M$ $manip_1$ $manip_2$ : $manip_M$ ïŒè¡ç®ã«çŸ€çã®æ°$N$ ($1 \leq N \leq 100,000$)ãäžãããããç¶ã$N$è¡ã«ãå矀çã«ãã幌è«ã®æ°$c_i$ ($0 \leq c_i \leq 100,000$)ãäžããããã ç¶ãïŒè¡ã«ãæäœã®æ°$M$ ($1 \leq M \leq 100,000$)ãäžãããããç¶ã$M$è¡ã«æäœã®å
容ãäžãããããåæäœã®å
å®¹ã¯æ¬¡ã®ããããã§ããã 1 $a$ $b$ $d$ ãŸã㯠2 $a$ $b$ $d$ å
é ã®æ°åã1ã®ãšããæå®ããç¯å²$a$ãã$b$ ($1 \leq a \leq b \leq N$)ã®çŸ€çã«å¯ŸããŠã幌è«ã$d$å¹($1 \leq d \leq 1,000$)远å ãããå
é ã®æ°åã2ã®ãšããæå®ããç¯å²$a$ãã$b$ ($1 \leq a \leq b \leq N$)ã®çŸ€çã«å¯ŸããŠã幌è«ã$d$å¹($1 \leq d \leq 1,000$)ã ãæè«ã«ãåãããæäœã衚ãããã®ãšããå®éã«ãåãã幌è«ã®åèšãåºåããããŸããå
é ã®æ°åã2ã§ããæäœã¯å¿
ãã²ãšã€ä»¥äžäžãããããã®ãšããã åºå 幌è«ããåãããæäœããšã«ãå®éã«ãåãã幌è«ã®åèšãïŒè¡ã«åºåããã å
¥åºåäŸ å
¥åäŸ 3 1 2 3 3 2 1 3 2 1 1 2 5 2 2 3 3 åºåäŸ 5 4
| 39,075
|
Shortest Common Non-Subsequence A subsequence of a sequence $P$ is a sequence that can be derived from the original sequence $P$ by picking up some or no elements of $P$ preserving the order. For example, " ICPC " is a subsequence of " MICROPROCESSOR ". A common subsequence of two sequences is a subsequence of both sequences. The famous longest common subsequence problem is finding the longest of common subsequences of two given sequences. In this problem, conversely, we consider the shortest common non-subsequence problem : Given two sequences consisting of 0 and 1, your task is to find the shortest sequence also consisting of 0 and 1 that is a subsequence of neither of the two sequences. Input The input consists of a single test case with two lines. Both lines are sequences consisting only of 0 and 1. Their lengths are between 1 and 4000, inclusive. Output Output in one line the shortest common non-subsequence of two given sequences. If there are two or more such sequences, you should output the lexicographically smallest one. Here, a sequence $P$ is lexicographically smaller than another sequence $Q$ of the same length if there exists $k$ such that $P_1 = Q_1, ... , P_{k-1} = Q_{k-1}$, and $P_k < Q_k$, where $S_i$ is the $i$-th character of a sequence $S$. Sample Input 1 0101 1100001 Sample Output 1 0010 Sample Input 2 101010101 010101010 Sample Output 2 000000 Sample Input 3 11111111 00000000 Sample Output 3 01
| 39,076
|
H - N and K 1ä»¥äž N 以äžã®æŽæ°ãããªãç矩å調å¢å æ°åã§ïŒæ°åã®èŠçŽ ããã©ã®2ã€ã®ç°ãªãæ°ãåã£ãŠããŠã 仿¹ãäžæ¹ãå²ãåãããšããªããããªãã®ãèããïŒ ãã®ãããªæ°åã®ãã¡ïŒãšãããæå€§ã®é·ãã L ãšããŠïŒãã®ãããªæ°å (a_1,a_2,...,a_L) ãèããïŒ ãã®æ°åã® K çªç®ã®èŠçŽ a_K ãæ±ããïŒãã ãïŒãã®ãããªæ°å (a_1...a_L) ãè€æ°åååšããå Žåã¯ïŒ a_K ã®å€ãšããŠãšãããæå°ã®å€ãåºåããïŒ ãŸãïŒ K > L ã®ãšãã¯-1ãåºåããïŒ å
¥ååœ¢åŒ å
¥åã¯è€æ°ã®å
¥åãããªãïŒå
¥åã®æ°ã¯ C ã»ããããïŒ i çªç®ã®å
¥å㯠N_i, K_i ã§ããïŒ ãã¹ãã±ãŒã¹ã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ C N_1 K_1 ⊠N_C K_C åºååœ¢åŒ åºå㯠C è¡ãããªãïŒ i è¡ç®ã®åºåã¯ïŒ N_i ãš K_i ã«ã€ããŠã®çãã§ããïŒ å¶çŽ 1 \leq C \leq 10^5 1 \leq N_i \leq 10^{18} 1 \leq K_i \leq N_i å
¥åå€ã¯ãã¹ãп޿°ã§ããïŒ ãã®åé¡ã®å€å®ã«ã¯ïŒ50 ç¹åã®ãã¹ãã±ãŒã¹ã®ã°ã«ãŒããèšå®ãããŠããïŒãã®ã°ã«ãŒãã«å«ãŸãããã¹ãã±ãŒã¹ã¯äžèšã®å¶çŽã«å ããŠäžèšã®å¶çŽãæºããïŒ C=1, N_i \leq 50 å
¥åºåäŸ å
¥åäŸ1 5 3 2 5 2 8 3 10 1 18 12 åºåäŸ1 3 3 5 4 -1 N=3 ã®ãšãïŒ2çªç®ã«å°ããèŠçŽ ãæå°ãšãªãçµã¿åããã®äžäŸãšã㊠(2,3) ãæããããïŒ N=5 ã®ãšãïŒ2çªç®ã«å°ããèŠçŽ ãæå°ãšãªãçµã¿åããã®äžäŸãšã㊠(2,3,5) ãæããããïŒ N=8 ã®ãšãïŒ3çªç®ã«å°ããèŠçŽ ãæå°ãšãªãçµã¿åããã®äžäŸãšã㊠(3,4,5,7) ãæããããïŒ N=10 ã®ãšãïŒ1çªç®ã«å°ããèŠçŽ ãæå°ãšãªãçµã¿åããã®äžäŸãšã㊠(4,6,7,9,10) ãæããããïŒ
| 39,077
|
Problem B: Båé¡ R倧åŠã®2D奜ãã®äººãã¡ (2DRespecters)ã¯ãA接倧åŠã§éå¬ãããããã°ã©ãã³ã°ã®ç·Žç¿å宿ã«åå ããã ãã®ç·Žç¿å宿ã§ã¯ãåå è
ãã¡ãèªäœã®ããã°ã©ãã³ã°åé¡ãæã¡å¯ããç·Žç¿ã«çšããã 2DRespectersããããã€ãã®åé¡ãäœæããããšã«ãªã£ãã ããããå宿ã®3æ¥åã«ãªã£ãŠãããŸã ãBåé¡ã宿ããŠããªãã£ãã æåã®Båé¡ã®æ
åœè
ãäœæããåé¡ã¯ãæ
åœè
ãåé¡ã®å¶çŽãé£ãããéããŠããŸã£ããããCåé¡ä»¥éã«ãŸããããŠããŸã£ãã®ã ã ãããŠãç°¡åãããŠããé£ããããŠããããªãã埮åŠãªé£æåºŠã®èª¿æŽãå¿
èŠãšãããBåé¡ã¯ã誰ããæãä»ãããããªãã£ãã ãã以æ¥ãBå顿
åœè
ã®æ€
åã¯ç©ºåžã®ãŸãŸã§ããã å宿3æ¥åã«ãªã£ãŠãéã«ããã®åé¡ã解決ããããã«ã2DRespectersæåŸ
ã®ããŒããç«ã¡äžãã£ãã ã ãã圌ã¯ãBåé¡ãäœæããæ°ããªãã 圌ã¯ãèªåã§Båé¡ãäœæããããªãã®ã§ãBåé¡ã®äœææ
åœãä»è
ã«æŒãä»ããææ³ãèãåºããã®ã ã åœŒã®ææ³ã¯ã衚é¢äžãBåé¡ã®äœææ
åœè
ãå¹³çã«æ±ºå®ããã åœŒã®ææ³ã¯ã以äžã®éãã§ããã åé¡äœæã®ããã«èŠããäœæ¥æéãæãå°ãªã人ãBå顿
åœè
ã«ãªãã äœæ¥æéãæãå°ãªã人ãè€æ°äººå±
ãå Žåã¯ãããåé¡é£æåºŠã®å°ããåé¡ã®æ
åœè
ãBåé¡äœææ
åœè
ã«ãªãã äœæ¥æéãæãå°ãªã人ãè€æ°äººå±
ãŠããã®äžã§ãåé¡é£æåºŠã®æãå°ãã人ãè€æ°äººããå Žåã¯ãããŒãã®åœŒãBåé¡äœææ
åœè
ã«ãªãã åœŒã®ææ³ã¯ãäžèŠãæãä»äºãããŠããªã人ãBåé¡ã®äœæãæ
åœããããã2DRespectersã®ã¡ã³ããŒå
šå¡ã«å¿«ãåãå
¥ããããã ããããåœŒã®ææ³ã«ã¯ã以äžã®ãããªè£ãããã åå人ã®äœæ¥æéã¯ãåå人ãå£é ã§ç³è«ãããããåã®ç³è«ãããããšãå¯èœã§ããã åé¡ã®äœæ¥å¯èœæéãè¶
ããäœæ¥æéãè² ã®äœæ¥æéãç³è«ãããšãåã ãšã°ããã ããåé¡ã®äœæã®ããã®äœæ¥æéã¯ãå¿
ãåé¡é£æåºŠã®æŽæ°åã«ãªãããšãç¥ãããŠãããããããã«åããäœæ¥æéãç³è«ããå Žåããåã ãšã°ããã åã®ç³è«ããã人ã®åãã°ããå Žåããã®äººãå¿
ãBåé¡äœææ
åœè
ã«ãªãã ç³è«ã¯äžäººãã€é çªã«è¡ããåãã°ããå Žåã¯ãç³è«ã®æç¹ã§ã°ããã äžäººã§ãåã®ç³è«ãã°ããæç¹ã§ãBåé¡äœææ
åœè
ãæ±ºãŸãããã以éã®ç³è«ã¯è¡ããªãã ç³è«è
ã¯ãèªåããåã®ç³è«ã®ã¿ãèæ
®ããç³è«ã®æç¹ã§èªåãBåé¡äœææ
åœè
ã«ãªããªããããªæå°ã®äœæ¥æéãç³è«ãããã®ãšããã ç³è«ã®æç¹ã§ãç³è«è
ãBåé¡äœææ
åœè
ã«ãªããªããããªå ±åãã§ããªãå Žåã¯ãåã ãšã°ããªããããªæå€§ã®äœæ¥æéãç³è«ããã ååäººã®æ
åœããåé¡é£æåºŠã®ãªã¹ããç³è«é ã«äžãããããšãã誰ãBåé¡äœææ
åœè
ã«ãªãããæ±ããããã°ã©ã ãäœæããã ããŒãã®åœŒã®ç³è«é çªã¯ãäžçªæåŸã§ããã ãªããæ¬åé¡ã¯ãã£ã¯ã·ã§ã³ã§ãããæ¬åé¡ã®äœæã®çµç·¯ãšã¯äžåã®é¢ä¿ããªãã Input å
¥åã¯ãè€æ°ã®ããŒã¿ã»ãããããªããããŒã¿ã»ããã®çµããã¯ãåè§ã¹ããŒã¹ã§åºåããã0ãäºã€ã ããå«ãè¡ã§è¡šãããã ããŒã¿ã»ããã®ç·æ°ã¯40以äžã§ããã ããŒã¿ã»ããã®1è¡ç®ã§ã¯ãæŽæ° n ( 2 †n †100 1,000 )ãšæŽæ° m ( 1 †m †1,000 )ãåè§ã¹ããŒã¹åºåãã§äžããããã ããŒã¿ã»ããã®2è¡ç®ã§ã¯ãæŽæ° a_1 , a_2 , ..., a_n ( 1 †a_i †1,000 , 1 †i †n )ãåè§ã¹ããŒã¹åºåãã§äžããããã 1è¡ç®ã® n ãš m ã¯ããããããç³è«è
ã®æ°ãšåé¡ã®äœæ¥å¯èœæéã衚ãã 2è¡ç®ã§ã¯ãç³è«é ã«äžŠã¹ãããåé¡é£æåºŠã®ãªã¹ããäžããããŠããã a_i ã¯ãåé¡ã®é£æåºŠã衚ãã Output ããããã®ããŒã¿ã»ããããšã«ãBåé¡äœææ
åœè
ã®ç³è«é çªã1è¡ã§åºåããã Sample Input 3 100 3 7 4 5 24 4 6 12 3 8 5 1 1 1 2 2 3 0 0 Output for Sample Input 2 4 5
| 39,078
|
Problem K: 黿³¢åºå° 20XX幎ïŒé·å¹Žã®ç ç©¶ãå®ãçµã³ïŒ ç¡ç·ã«ãããšãã«ã®ãŒéåä¿¡ã®æè¡ãå®çšåãããïŒ ãã®æè¡ãå©çšããããšã§ïŒ ã³ã¹ããèŠåããä»ãŸã§é»åç·ãåŒãããšãã§ããªãã£ãéçå°ã«ã é»åãäŸçµŠããããšãå¯èœãšãªã£ãïŒ ãã®æè¡ã«ã¯å°ãããããã£ãŠïŒ ã©ããŸã§ãé ãã«ãšãã«ã®ãŒãéãããšãã§ããã®ã ãïŒ ç¹å®ã®äœçœ®ã§ãã黿³¢ã®åä¿¡ãã§ããªããšããå¶çŽãååšããïŒ ã€ãŸãïŒäžçã2次å
å¹³é¢ã§è¡šãïŒ y 軞æ£ã®æ¹åãåïŒ x 軞æ£ã®æ¹åãæ±ãšãããšïŒ x 座æšã» y 座æšããšãã«æŽæ°ã®å°ç¹ã§ãã 黿³¢ãåä¿¡ããããšãã§ããªãïŒäœçžã®åé¡ã§ããïŒïŒ ãŸãïŒåºå°ïŒé»æ³¢ã®éåä¿¡ãå¯èœãªèšåïŒ ããèŠãŠ8æ¹äœïŒæ±ã»è¥¿ã»åã»åã»åæ±ã»å西ã»åæ±ã»åè¥¿ïŒ ã®æ¹åã«ãã黿³¢ãéä¿¡ããããšãã§ããªãïŒ ãã®å¶çŽã®ããã«ïŒç®æšã®å Žæã«é»æ³¢ãçŽæ¥äŸçµŠã§ããªãå ŽåããããïŒ ããã¯äžç¶åºå°ã眮ãããšã§è§£æ±ºå¯èœã§ããïŒ äŸãã°ïŒåº§æš (0, 0) ãã (3, 7) ãžã¯çŽæ¥ãšãã«ã®ãŒãéãããšãã§ããªããïŒ (3, 3) ã«äžç¶åºå°ã眮ãããšã§è§£æ±ºã§ããïŒ ããªãã¯é»åäŒç€Ÿã®ãšã³ãžãã¢ã§ïŒ 顧客ããããå Žæã«åºå°ãçšæããŠã»ãããšèšãããŠããïŒ ãã ãïŒããç®æãæ
éããã ãã§é»åãæ¢ãŸã£ãŠããŸããšããåé¡ãé¿ããããïŒ æ°ãã«åºå°ãæ·èšããéã«ã¯ïŒæ¢ã«å»ºã£ãŠãã2ç®æä»¥äžã®åºå°ãã ãšãã«ã®ãŒãåãåããªããŠã¯ãããªãïŒ ãŸãïŒåºå°ã¯åæã«ã¯1ã€ãã建ãŠãããšãã§ããïŒ åãå Žæã«åºå°ã2ã€çœ®ãããšã¯ã§ããªãïŒ æ¢åã®åºå°ã®äœçœ®ã2ã€äžããããã®ã§ïŒ 顧客ã®èŠæãæºããããã«ã¯æäœã§ãããšäœä»¶ã®åºå°ã建ãŠãå¿
èŠããããã æ±ããŠæ¬²ããïŒ Input å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒ å
¥åã®æåã®è¡ã«ããŒã¿ã»ããæ° N (0 < N †300) ãäžããããïŒ ä»¥éã® N è¡ã«ïŒããããã®ããŒã¿ã»ãããäžããããïŒ 1ã€ã®ããŒã¿ã»ããã¯1è¡ã®æååãããªãïŒ ä»¥äžã®ããã«ã¹ããŒã¹ã§åºåããã6ã€ã®æŽæ°ãäžããããïŒ x 1 y 1 x 2 y 2 X Y ( x 1 , y 1 ) ãš ( x 2 , y 2 ) ã¯æ¢åã®2ã€ã®åºå°ã®åº§æšã§ããïŒ ( X , Y ) ã¯ç®çå°ã®åº§æšã§ããïŒ å
¥åã§äžãããã x , y 座æšå€ã¯ â100000000 †x , y †100000000 ãæºããïŒ æ¢åã®2ã€ã®åºå°ã®åº§æšã¯ç°ãªã£ãŠããããšãä¿èšŒãããŠããïŒ Output ããŒã¿ã»ããããšã«ïŒæ·èšããå¿
èŠã®ããåºå°ã®æ°ã1è¡ã§åºåããïŒ Sample Input 4 0 1 3 2 0 1 1 1 2 2 9 9 0 0 1 4 5 5 0 0 1 4 5 10 Output for the Sample Input 0 1 2 3
| 39,079
|
Score : 800 points Problem Statement In Finite Encyclopedia of Integer Sequences (FEIS), all integer sequences of lengths between 1 and N (inclusive) consisting of integers between 1 and K (inclusive) are listed. Let the total number of sequences listed in FEIS be X . Among those sequences, find the (X/2) -th (rounded up to the nearest integer) lexicographically smallest one. Constraints 1 \leq N,K \leq 3 Ã 10^5 N and K are integers. Input Input is given from Standard Input in the following format: K N Output Print the (X/2) -th (rounded up to the nearest integer) lexicographically smallest sequence listed in FEIS, with spaces in between, where X is the total number of sequences listed in FEIS. Sample Input 1 3 2 Sample Output 1 2 1 There are 12 sequences listed in FEIS: (1),(1,1),(1,2),(1,3),(2),(2,1),(2,2),(2,3),(3),(3,1),(3,2),(3,3) . The (12/2 = 6) -th lexicographically smallest one among them is (2,1) . Sample Input 2 2 4 Sample Output 2 1 2 2 2 Sample Input 3 5 14 Sample Output 3 3 3 3 3 3 3 3 3 3 3 3 3 2 2
| 39,081
|
Score : 400 points Problem Statement Snuke has one biscuit and zero Japanese yen (the currency) in his pocket. He will perform the following operations exactly K times in total, in the order he likes: Hit his pocket, which magically increases the number of biscuits by one. Exchange A biscuits to 1 yen. Exchange 1 yen to B biscuits. Find the maximum possible number of biscuits in Snuke's pocket after K operations. Constraints 1 \leq K,A,B \leq 10^9 K,A and B are integers. Input Input is given from Standard Input in the following format: K A B Output Print the maximum possible number of biscuits in Snuke's pocket after K operations. Sample Input 1 4 2 6 Sample Output 1 7 The number of biscuits in Snuke's pocket after K operations is maximized as follows: Hit his pocket. Now he has 2 biscuits and 0 yen. Exchange 2 biscuits to 1 yen. his pocket. Now he has 0 biscuits and 1 yen. Hit his pocket. Now he has 1 biscuits and 1 yen. Exchange 1 yen to 6 biscuits. his pocket. Now he has 7 biscuits and 0 yen. Sample Input 2 7 3 4 Sample Output 2 8 Sample Input 3 314159265 35897932 384626433 Sample Output 3 48518828981938099
| 39,082
|
Score : 200 points Problem Statement Alice, Bob and Charlie are playing Card Game for Three , as below: At first, each of the three players has a deck consisting of some number of cards. Each card has a letter a , b or c written on it. The orders of the cards in the decks cannot be rearranged. The players take turns. Alice goes first. If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says a , Alice takes the next turn.) If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A , S_B and S_C . The i -th (1âŠiâŠ|S_A|) letter in S_A is the letter on the i -th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game. Constraints 1âŠ|S_A|âŠ100 1âŠ|S_B|âŠ100 1âŠ|S_C|âŠ100 Each letter in S_A , S_B , S_C is a , b or c . Input The input is given from Standard Input in the following format: S_A S_B S_C Output If Alice will win, print A . If Bob will win, print B . If Charlie will win, print C . Sample Input 1 aca accc ca Sample Output 1 A The game will progress as below: Alice discards the top card in her deck, a . Alice takes the next turn. Alice discards the top card in her deck, c . Charlie takes the next turn. Charlie discards the top card in his deck, c . Charlie takes the next turn. Charlie discards the top card in his deck, a . Alice takes the next turn. Alice discards the top card in her deck, a . Alice takes the next turn. Alice's deck is empty. The game ends and Alice wins the game. Sample Input 2 abcb aacb bccc Sample Output 2 C
| 39,083
|
Topological Sort A directed acyclic graph (DAG) can be used to represent the ordering of tasks. Tasks are represented by vertices and constraints where one task can begin before another, are represented by edges. For example, in the above example, you can undertake task B after both task A and task B are finished. You can obtain the proper sequence of all the tasks by a topological sort. Given a DAG $G$, print the order of vertices after the topological sort. Input A directed graph $G$ is given in the following format: $|V|\;|E|$ $s_0 \; t_0$ $s_1 \; t_1$ : $s_{|E|-1} \; t_{|E|-1}$ $|V|$ is the number of vertices and $|E|$ is the number of edges in the graph. The graph vertices are named with the numbers $0, 1,..., |V|-1$ respectively. $s_i$ and $t_i$ represent source and target nodes of $i$-th edge (directed). Output Print the vertices numbers in order. Print a number in a line. If there are multiple possible solutions, print any one of them (the solution is judged by a special validator). Constraints $1 \leq |V| \leq 10,000$ $0 \leq |E| \leq 100,000$ There are no parallel edges in $G$ There are no self loops in $G$ Sample Input 6 6 0 1 1 2 3 1 3 4 4 5 5 2 Sample Output 0 3 1 4 5 2
| 39,084
|
Score : 600 points Problem Statement There are N people, conveniently numbered 1 through N . We want to divide them into some number of groups, under the following two conditions: Every group contains between A and B people, inclusive. Let F_i be the number of the groups containing exactly i people. Then, for all i , either F_i=0 or Câ€F_iâ€D holds. Find the number of these ways to divide the people into groups. Here, two ways to divide them into groups is considered different if and only if there exists two people such that they belong to the same group in exactly one of the two ways. Since the number of these ways can be extremely large, print the count modulo 10^9+7 . Constraints 1â€Nâ€10^3 1â€Aâ€Bâ€N 1â€Câ€Dâ€N Input The input is given from Standard Input in the following format: N A B C D Output Print the number of ways to divide the people into groups under the conditions, modulo 10^9+7 . Sample Input 1 3 1 3 1 2 Sample Output 1 4 There are four ways to divide the people: (1,2),(3) (1,3),(2) (2,3),(1) (1,2,3) The following way to divide the people does not count: (1),(2),(3) . This is because it only satisfies the first condition and not the second. Sample Input 2 7 2 3 1 3 Sample Output 2 105 The only ways to divide the people under the conditions are the ones where there are two groups of two people, and one group of three people. There are 105 such ways. Sample Input 3 1000 1 1000 1 1000 Sample Output 3 465231251 Sample Input 4 10 3 4 2 5 Sample Output 4 0 The answer can be 0 .
| 39,085
|
Score : 400 points Problem Statement A positive integer X is said to be a lunlun number if and only if the following condition is satisfied: In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1 . For example, 1234 , 1 , and 334 are lunlun numbers, while none of 31415 , 119 , or 13579 is. You are given a positive integer K . Find the K -th smallest lunlun number. Constraints 1 \leq K \leq 10^5 All values in input are integers. Input Input is given from Standard Input in the following format: K Output Print the answer. Sample Input 1 15 Sample Output 1 23 We will list the 15 smallest lunlun numbers in ascending order: 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 21 , 22 , 23 . Thus, the answer is 23 . Sample Input 2 1 Sample Output 2 1 Sample Input 3 13 Sample Output 3 21 Sample Input 4 100000 Sample Output 4 3234566667 Note that the answer may not fit into the 32 -bit signed integer type.
| 39,086
|
Longest Common Subsequence For given two sequences $X$ and $Y$, a sequence $Z$ is a common subsequence of $X$ and $Y$ if $Z$ is a subsequence of both $X$ and $Y$. For example, if $X = \{a,b,c,b,d,a,b\}$ and $Y = \{b,d,c,a,b,a\}$, the sequence $\{b,c,a\}$ is a common subsequence of both $X$ and $Y$. On the other hand, the sequence $\{b,c,a\}$ is not a longest common subsequence (LCS) of $X$ and $Y$, since it has length 3 and the sequence $\{b,c,b,a\}$, which is also common to both $X$ and $Y$, has length 4. The sequence $\{b,c,b,a\}$ is an LCS of $X$ and $Y$, since there is no common subsequence of length 5 or greater. Write a program which finds the length of LCS of given two sequences $X$ and $Y$. The sequence consists of alphabetical characters. Input The input consists of multiple datasets. In the first line, an integer $q$ which is the number of datasets is given. In the following $2 \times q$ lines, each dataset which consists of the two sequences $X$ and $Y$ are given. Output For each dataset, print the length of LCS of $X$ and $Y$ in a line. Constraints $1 \leq q \leq 150$ $1 \leq$ length of $X$ and $Y$ $\leq 1,000$ $q \leq 20$ if the dataset includes a sequence whose length is more than 100 Sample Input 1 3 abcbdab bdcaba abc abc abc bc Sample Output 1 4 3 2 Reference Introduction to Algorithms, Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. The MIT Press.
| 39,087
|
ç
é¢ã®éšå±çªå· ãŠã©ãŒã¿ãŒããã³ã«äœã建ç¯å®¶ã®ããã³ããŒããã®ããšã«ãå€ã倧ç
é¢ãæ¹è£
ããä»äºã®äŸé Œãèã蟌ãã§ããŸããã åœã«ãã£ãŠã¯å¿ã¿æ°(ãã¿ãã)ãšããŠå«ãããæ°åãéšå±çªå·ã«çšããããªã人ãããŸã(æ¥æ¬ã§ã¯ 4 ãš 9 ãæåã§ã)ããããããã®ç
é¢ã®éšå±çªå·ã¯å¿ã¿æ°ã«é¢ä¿ãªãã1 ããé çªã«ä»ããããŠããŸããã ãããæ°ã«ãªã£ãããã³ããŒããã¯ãæ©æããããã®å
¥ãæ¿ããå
šãŠçµããåã«ãŠã©ãŒã¿ãŒããã³ã®å¿ã¿æ°ã§ããã4ããšã6ããé€ããæ°åã§éšå±çªå·ãä»ããªãããŠããŸããŸãããããããå
¥ãæ¿ãäœæ¥ã¯æ§éšå±çªå·ã§èšç»ããŠããã®ã§ãæ®ãã®äœæ¥ã確å®ã«è¡ãã«ã¯æ§éšå±çªå·ãæ°éšå±çªå·ã«å€æããå¿
èŠããããŸããèšç®ãèŠæãªããã³ããŒããã¯ãã®ããšã«æ°ã¥ããŠæç¶ãšããŠããŸãã ãããªããã³ããŒããã®ããã«ãæ§éšå±çªå·ãå
¥åãšã察å¿ããæ°éšå±çªå·ãåºåããããã°ã©ã ãäœæããŠãã ããã 15 çªç®ãŸã§ã®éšå±çªå·ã®å¯Ÿå¿è¡šã¯ä»¥äžã®ããã«ãªããŸãã æ§éšå±çªå· 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 æ°éšå±çªå· 1 2 3 5 7 8 9 10 11 12 13 15 17 18 19 Input è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸãã åããŒã¿ã»ãããšããŠãæ§éšå±çªå·ãè¡šãæŽæ° n (1 †n †1,000,000,000) ãïŒè¡ã«äžããããŸãã ããŒã¿ã»ããã®æ°ã¯ 30000 ãè¶
ããŸããã Output å
¥åããŒã¿ã»ããããšã«ãæ°éšå±çªå·ãïŒè¡ã«åºåããŸãã Sample Input 15 100 1000000000 3 0 Output for the Sample Input 19 155 9358757000 3
| 39,088
|
Score : 100 points Problem Statement A professor invented Cookie Breeding Machine for his students who like cookies very much. When one cookie with the taste of x is put into the machine and a non-negative integer y less than or equal to 127 is input on the machine, it consumes the cookie and generates two cookies with the taste of y and ( x XOR y ). Here, XOR represents Bitwise Exclusive OR . At first, there is only one cookie and the taste of it is D . Find the maximum value of the sum of the taste of the exactly N cookies generated after the following operation is conducted N-1 times. Put one of the cookies into the machine. Input a non-negative integer less than or equal to 127 on the machine. Constraints 1 \leq T \leq 1000 1 \leq N_t \leq 1000 (1 \leq t \leq T) 1 \leq D_t \leq 127 (1 \leq t \leq T) Input The input is given from Standard Input in the following format: T N_1 D_1 : N_T D_T The input consists of multiple test cases. An Integer T that represents the number of test cases is given on line 1 . Each test case is given on the next T lines. In the t -th test case ( 1 \leq t \leq T ), N_t that represents the number of cookies generated through the operations and D_t that represents the taste of the initial cookie are given separated by space. Output For each test case, print the maximum value of the sum of the taste of the N cookies generated through the operations on one line. Sample Input 1 3 3 1 4 108 1 10 Sample Output 1 255 400 10 On the 1st test case, if the machine is used as follows, three cookies with the taste of 61 , 95 and 99 are generated. Since the sum of these values is maximum among all possible ways, the answer is 255 . Put the cookie with the taste of 1 and input an integer 60 on the machine, lose the cookie and get two cookies with the taste of 60 and 61 . Put the cookie with the taste of 60 and input an integer 99 on the machine, lose the cookie and get two cookies with the taste of 99 and 95 . On the 3rd test case, the machine may not be used.
| 39,089
|
Score : 600 points Problem Statement Given is an integer sequence of length N+1 : A_0, A_1, A_2, \ldots, A_N . Is there a binary tree of depth N such that, for each d = 0, 1, \ldots, N , there are exactly A_d leaves at depth d ? If such a tree exists, print the maximum possible number of vertices in such a tree; otherwise, print -1 . Notes A binary tree is a rooted tree such that each vertex has at most two direct children. A leaf in a binary tree is a vertex with zero children. The depth of a vertex v in a binary tree is the distance from the tree's root to v . (The root has the depth of 0 .) The depth of a binary tree is the maximum depth of a vertex in the tree. Constraints 0 \leq N \leq 10^5 0 \leq A_i \leq 10^{8} ( 0 \leq i \leq N ) A_N \geq 1 All values in input are integers. Input Input is given from Standard Input in the following format: N A_0 A_1 A_2 \cdots A_N Output Print the answer as an integer. Sample Input 1 3 0 1 1 2 Sample Output 1 7 Below is the tree with the maximum possible number of vertices. It has seven vertices, so we should print 7 . Sample Input 2 4 0 0 1 0 2 Sample Output 2 10 Sample Input 3 2 0 3 1 Sample Output 3 -1 Sample Input 4 1 1 1 Sample Output 4 -1 Sample Input 5 10 0 0 1 1 2 3 5 8 13 21 34 Sample Output 5 264
| 39,090
|
Problem L: The Tower Your task is to write a program that reads some lines of command for the following game and simulates operations until the player reaches the game over. We call following 2-dimensional grid of m by n characters Tower. The objective of this game is to move blocks in the tower to climb to a goal block. In the following grid, the bottom line is the first row and the top one is the n -th row. The leftmost column is the first column and the rightmost one is the m -th column. .................... ( n =13 th row) .....#.....G........ ....##.....##.....## ...####...IIII...### ..####.....##.....## ...####B..####....## ....###....#33##..## .....####...#33#3.## .##CCCC#####2##.#### ..#####..###.#...### ...###....###.....#1 ....####..##.......# S..###..#.####.....# (1st row) Explanation of cell marks: '#' : Normal block Normal block. 'I' : Ice block Block made of the ice. This has different features from the normal one. 'G' : Goal block If the player climbs to this, game is over and clear. 'C' : Fixed block The player can not move this directly. 'B' : Different dimensional block If the player climbs to this, game is over and lose. '.' : Space Empty place. '3' : Fragile block(3) A fragile block of count 3. '2' : Fragile block(2) A fragile block of count 2. '1' : Fragile block(1) A fragile block of count 1. If the count is zero, this block will be broken and become a space. 'S' : Player The player. Explanation of relative positions: 123 4S5 678 In the following description, assume that left up is the position of 1, up(over S) is 2, right up is 3, left is 4, right is 5, left down is 6, down(under S) is 7, right down is 8 for S. Movements of the player The player must not go out of the tower. The outside of the tower is considered as space cells. Move The player can move everywhere in the current row as long as some of the following conditions are satisfied. The player is in the first row and the target cell is a space. There are blocks under the route connecting the current cell and the target cell (horizontal segment) and the target cell is a space. It is OK that some blocks in the horizontal segment. And the case that some of blocks under the segment are different dimensional ones, it is also OK. Climb If the player at the row below the n-th row (from 1st to n-1 th row) and there is a block in the right(left) and both of a cell over the player (up cell) and a right up(left up) cell are space, the player can move to the right up(left up) cell. Get down If the player at the row above the 1st row (from 2nd to n-th row), he can get down to right(left) down. If the direction for getting down is right(left) and if there is no blocks in the right down (left down) cell and the right (left) cell, the player can move to the right down (left down) cell. Push If there is a block or continuous blocks in the right or left of the player, he can push the blocks to the direction one cell. Here, blocks are "continuous" if there are two or more blocks and no space exist between them. However, if there is a fixed block in pushing blocks, the player can not push them. Pushed blocks will not stop the end of the row of the tower (1st and mth column). If the pushed blocks go out of the tower, this will be vanished. In the result of pushing, a block moved over the ice block continues to move to the pushed direction as long as there is a space in the progress direction, there is an ice block under the block and the pushed block is not vanished. If the pushed block is an ice block, this continues to move to the pushed direction as long as there is a block under the ice block, there is a space in the progress direction and the pushed ice block is not vanished. However, for an ice block in the first row, the below the block do not have to be a space. And here, if the player pushes continuous blocks, pushing movements begin from the most distant block to a nearest block. Here, the distance is manhattan distance at the gird. Pull If there is a block in the right(left) of the player and the left(right) cell is space, the player can pull the block. However, if the pulling block is fixed one, he can not pull this. If the player pulls block, the player will move one cell to the direction of pulling. Automated operations after the player operation: Automated operations occur in the following order. This repeats in this order as long as the cells of the tower are changed by this operations. After this operations, the player can do the next operation. Countdown of fragile blocks If the player over a fragile block moved to somewhere else, that fragile block's count will decrease by one. However, this count does not change if the player over the fragile block is moved to somewhere else by the automated operations. Erasing blocks A block over an different dimensional block will be vanished. Falling of the player If there is no block under the player, the player continues to fall as long as satisfying this condition or come to 1st row. Falling of blocks If there is no block under a block and left down and right down of a certain block, the block in the row over the 1st row (from 2nd to n-th row) continues to fall as long as satisfying this condition. Falling of blocks begins from lower blocks of the tower and then lefter blocks. Conditions for game over: After the movement of the player or the automated operations, the game is over when the one of next conditions is satisfied. These conditions are judged in the following order. Note that, the condition (E) should not be judged after the movement of the player. (A) The player is over the goal block. (B) The player is over the different dimensional block. (C) The player and a block is in the same cell. (D) The goal block is moved from its initial position. (E) There is no next commands. Finally, show some examples. Documents of commands will be give in the description of Input. Example table Movement or Automated operation Before After Command Move .#S ### S#. ### MOVETO 1 Climb ... 3S# S.. 3.# CLIMB LEFT Get down S.. 3.# ... 2S# GETDOWN RIGHT Push .#S#####.. ###II.I.I. .#S.####.# ###II.I.I. PUSH RIGHT Push .#SI... ###.### .#S.... ###.### PUSH RIGHT Push .#...S# ###.### .....S. ###.### PUSH RIGHT Pull ..S#####.. ###.#.#.#. .S#.####.. ###.#.#.#. PULL LEFT Falling of the player .#S# .#.# .#.# .#.# .#.# .#.# .#.# .#S# - Falling of blocks .###. #...# #...# #...# .#.# .#.#. #...# #...# #.#.# .#.# - Input Input consists of multiple datasets. A dataset is given in the following format. n m D n,1 D n,2 ... D n,m D n-1,1 D n-1,2 ... D n-1,m ... D 1,1 D 1,2 ... D 1,m T Command 1 Command 2 ... Command T Here, m , n is the width and height of the tower. D i,j (1†i †n and 1†j †m ) is a mark of the cell. The explanation of marks described above. Command k (1†k †T ) is the k -th player operation (movement). This is a string and one of following strings. "MOVETO s" means move to s -th column cell in the same row. "PUSH RIGHT" means push right block(s). "PUSH LEFT" means push left block(s). "PULL RIGHT" means pull the left block to right. "PULL LEFT" means pull the right block to left. "GETDOWN RIGHT" means get down to right down. "GETDOWN LEFT" means get down to left down. "CLIMB RIGHT" means climb to the right block. "CLIMB LEFT" means climb to the left block. Some of commands are invalid. You must ignore these commands. And after game is over, the command input may continue in case. In this case, you must also ignore following commands. m = n =0 shows the end of input. Constraints 3†m â€50 3†n â€50 Characters 'S' and 'G' will appear exactly once in the tower description. Output Each dataset, output a string that represents the result of the game in the following format. Result Here, Result is a string and one of the following strings (quotes for clarity). "Game Over : Cleared" (A) "Game Over : Death by Hole" (B) "Game Over : Death by Block" (C) "Game Over : Death by Walking Goal" (D) "Game Over : Gave Up" (E) Sample Input 8 8 ........ ........ ....###. ...#.#.G S#B...## #ICII.I# #..#.#.# .#..#.#. 7 PUSH RIGHT MOVETO 2 CLIMB RIGHT CLIMB RIGHT GETDOWN RIGHT CLIMB RIGHT GETDOWN RIGHT 8 8 ........ ........ ........ ...G.... S#B..... #ICIIIII #..#.#.# .#..#.#. 4 PUSH RIGHT MOVETO 2 CLIMB RIGHT CLIMB RIGHT 8 8 ........ ....#.#. .....#.G ...#..#. S#B....# #ICIII.# #..#.#.# .#..#.#. 8 PUSH RIGHT MOVETO 2 CLIMB RIGHT CLIMB RIGHT CLIMB RIGHT GETDOWN RIGHT CLIMB RIGHT GETDOWN RIGHT 0 0 Sample Output Game Over : Death by Hole Game Over : Cleared Game Over : Death by Walking Goal
| 39,091
|
On or Off Saving electricity is very important! You are in the office represented as R \times C grid that consists of walls and rooms. It is guaranteed that, for any pair of rooms in the office, there exists exactly one route between the two rooms. It takes 1 unit of time for you to move to the next room (that is, the grid adjacent to the current room). Rooms are so dark that you need to switch on a light when you enter a room. When you leave the room, you can either leave the light on, or of course you can switch off the light. Each room keeps consuming electric power while the light is on. Today you have a lot of tasks across the office. Tasks are given as a list of coordinates, and they need to be done in the specified order. To save electricity, you want to finish all the tasks with the minimal amount of electric power. The problem is not so easy though, because you will consume electricity not only when light is on, but also when you switch on/off the light. Luckily, you know the cost of power consumption per unit time and also the cost to switch on/off the light for all the rooms in the office. Besides, you are so smart that you don't need any time to do the tasks themselves. So please figure out the optimal strategy to minimize the amount of electric power consumed. After you finished all the tasks, please DO NOT leave the light on at any room. It's obviously wasting! Input The first line of the input contains three positive integers R ( 0 \lt R \leq 50 ), C ( 0 \lt C \leq 50 ) and M ( 2 \leq M \leq 1000 ). The following R lines, which contain C characters each, describe the layout of the office. '.' describes a room and '#' describes a wall. This is followed by three matrices with R rows, C columns each. Every elements of the matrices are positive integers. The (r, c) element in the first matrix describes the power consumption per unit of time for the room at the coordinate (r, c) . The (r, c) element in the second matrix and the third matrix describe the cost to turn on the light and the cost to turn off the light, respectively, in the room at the coordinate (r, c) . Each of the last M lines contains two positive integers, which describe the coodinates of the room for you to do the task. Note that you cannot do the i -th task if any of the j -th task ( 0 \leq j \leq i ) is left undone. Output Print one integer that describes the minimal amount of electric power consumed when you finished all the tasks. Sample Input 1 1 3 2 ... 1 1 1 1 2 1 1 1 1 0 0 0 2 Output for the Sample Input 1 7 Sample Input 2 3 3 5 ... .## ..# 1 1 1 1 0 0 1 1 0 3 3 3 3 0 0 3 3 0 5 4 5 4 0 0 5 4 0 1 0 2 1 0 2 2 0 0 0 Output for the Sample Input 2 77 Sample Input 3 5 5 10 #.### #.... ###.# ..#.# #.... 0 12 0 0 0 0 4 3 2 10 0 0 0 99 0 11 13 0 2 0 0 1 1 2 1 0 4 0 0 0 0 13 8 2 4 0 0 0 16 0 1 1 0 2 0 0 2 3 1 99 0 2 0 0 0 0 12 2 12 2 0 0 0 3 0 4 14 0 16 0 0 2 14 2 90 0 1 3 0 4 4 1 4 1 1 4 4 1 1 4 3 3 0 1 4 Output for the Sample Input 3 777
| 39,092
|
Score : 200 points Problem Statement In Japan, people make offerings called hina arare , colorful crackers, on March 3 . We have a bag that contains N hina arare. (From here, we call them arare.) It is known that the bag either contains arare in three colors: pink, white and green, or contains arare in four colors: pink, white, green and yellow. We have taken out the arare in the bag one by one, and the color of the i -th arare was S_i , where colors are represented as follows - pink: P , white: W , green: G , yellow: Y . If the number of colors of the arare in the bag was three, print Three ; if the number of colors was four, print Four . Constraints 1 \leq N \leq 100 S_i is P , W , G or Y . There always exist i , j and k such that S_i= P , S_j= W and S_k= G . Input Input is given from Standard Input in the following format: N S_1 S_2 ... S_N Output If the number of colors of the arare in the bag was three, print Three ; if the number of colors was four, print Four . Sample Input 1 6 G W Y P Y W Sample Output 1 Four The bag contained arare in four colors, so you should print Four . Sample Input 2 9 G W W G P W P G G Sample Output 2 Three The bag contained arare in three colors, so you should print Three . Sample Input 3 8 P Y W G Y W Y Y Sample Output 3 Four
| 39,093
|
Array Update Problem é
æ° N ãåé
a ãå
¬å·® d ã®çå·®æ°å A ãããã以äžã®åœ¢åŒã§æ°åãæŽæ°ããåœä»€æã M åäžããããã®ã§ãäžããããé åºã§æ°å A ã M åæŽæ°ãããšãã® K é
ç®ã®å€ãæ±ããã i çªç®ã®åœä»€æã¯3ã€ã®æŽæ° x i , y i , z i ã§è¡šããã(1 †i †M )ã x i ã0ã ã£ãå Žåã y i é
ç®ã®å€ãš z i é
ç®ã®å€ãå
¥ãæ¿ããã x i ã1ã ã£ãå Žåã y i é
ç®ã®å€ã z i é
ç®ã®å€ã«æžãæããã Input N a d M x 1 y 1 z 1 x 2 y 2 z 2 ... x M y M z M K 1è¡ç®ã«ã1ã€ã®æŽæ° N ãäžããããã 2è¡ç®ã«ã2ã€ã®æŽæ° a ãš d ã空çœåºåãã§äžããããã 3è¡ç®ã«ã1ã€ã®æŽæ° M ãäžããããã 4è¡ç®ããã® M è¡ã®ãã¡ i è¡ç®ã«ã¯ i çªç®ã®åœä»€æã衚ã 3 ã€ã®æŽæ° x i , y i , z i ã空çœåºåãã§äžããããã æåŸã®è¡ã«ã1ã€ã®æŽæ° K ãäžããããã Constraints 1 †N †10 8 1 †a †5 1 †d †5 1 †M †10 0 †x i †1 (1 †i †M ) 1 †y i †N (1 †i †M ) 1 †z i †N (1 †i †M ) y i â z i (1 †i †M ) 1 †K †N Output å
¥åã§äžããããé çªã§æ°å A ã M åæŽæ°ãããšãã® K é
ç®ãåºåããã Sample Input 1 5 2 3 3 0 2 5 0 3 5 1 2 4 2 Sample Output 1 11 { 2 , 5 , 8 , 11 , 14 } â 0 2 5 ⊠2é
ç®ã®å€ãš5é
ç®ã®å€ãå
¥ãæ¿ãã â { 2 , 14 , 8 , 11 , 5 } â 0 3 5 ⊠3é
ç®ã®å€ãš5é
ç®ã®å€ãå
¥ãæ¿ãã â { 2 , 14 , 5 , 11 , 8 } â 1 2 4 ⊠2é
ç®ã®å€ã4é
ç®ã®å€ã«æžãæãã â { 2 , 11 , 5 , 11 , 8 } ãã£ãŠ2é
ç®ã¯11ã§ããã Sample Input 2 6 5 5 4 0 1 2 1 1 2 0 4 1 1 1 6 3 Sample Output 2 15
| 39,094
|
Score : 400 points Problem Statement N people are arranged in a row from left to right. You are given a string S of length N consisting of 0 and 1 , and a positive integer K . The i -th person from the left is standing on feet if the i -th character of S is 0 , and standing on hands if that character is 1 . You will give the following direction at most K times (possibly zero): Direction : Choose integers l and r satisfying 1 \leq l \leq r \leq N , and flip the l -th, (l+1) -th, ... , and r -th persons. That is, for each i = l, l+1, ..., r , the i -th person from the left now stands on hands if he/she was standing on feet, and stands on feet if he/she was standing on hands. Find the maximum possible number of consecutive people standing on hands after at most K directions. Constraints N is an integer satisfying 1 \leq N \leq 10^5 . K is an integer satisfying 1 \leq K \leq 10^5 . The length of the string S is N . Each character of the string S is 0 or 1 . Input Input is given from Standard Input in the following format: N K S Output Print the maximum possible number of consecutive people standing on hands after at most K directions. Sample Input 1 5 1 00010 Sample Output 1 4 We can have four consecutive people standing on hands, which is the maximum result, by giving the following direction: Give the direction with l = 1, r = 3 , which flips the first, second and third persons from the left. Sample Input 2 14 2 11101010110011 Sample Output 2 8 Sample Input 3 1 1 1 Sample Output 3 1 No directions are necessary.
| 39,095
|
çŸè¡å±(Art Exhibition) JOI åœã§çŸè¡å±ãè¡ãããããšã«ãªã£ãïŒçŸè¡å±ã§ã¯ïŒåœäžããéãŸã£ãæ§ã
ãªçŸè¡åãå±ç€ºãããäºå®ã§ããïŒ å±ç€ºãããçŸè¡åã®åè£ãšããŠïŒ N ç¹ã®çŸè¡åãéãŸã£ãïŒãããã®çŸè¡åã«ã¯ 1, 2, ..., N ã®çªå·ãä»ããããŠããïŒããããã®çŸè¡åã«ã¯å€§ãããšäŸ¡å€ãšåŒã°ããå€ãå®ãŸã£ãŠããïŒçŸè¡å i (1 \leq i \leq N) ã®å€§ãã㯠A_i ïŒäŸ¡å€ã¯ B_i ã§ããïŒ çŸè¡å±ã§ã¯ïŒãããã®çŸè¡åã®ãã¡ãã1 ç¹ä»¥äžãéžãã§å±ç€ºããïŒçŸè¡å±ã®äŒå Žã¯ååã«åºãïŒ N ç¹ã®çŸè¡åãã¹ãŠãå±ç€ºããããšãå¯èœã§ããïŒãããïŒJOI åœã®äººã
ã®çŸçæèŠã®ããïŒçŸè¡åã®éã§å€§ããã®å·®ãããŸã倧ãããªããªãããã«å±ç€ºããçŸè¡åãéžã³ããïŒäžæ¹ïŒã§ããã ã䟡å€ã®å€§ããçŸè¡åãå€ãå±ç€ºãããïŒãã®ããïŒæ¬¡ã®æ¡ä»¶ãæºããããã«å±ç€ºããçŸè¡åãéžã¶ããšã«ããïŒ éžãã çŸè¡åã®äžã§ïŒå€§ãããæå€§ã®ãã®ã®å€§ããã A_{max} ïŒæå°ã®ãã®ã®å€§ããã A_{min} ãšããïŒãŸãïŒéžãã çŸè¡åã®äŸ¡å€ã®ç·åã S ãšããïŒ ãã®ãšãïŒ S - (A_{max} - A_{min}) ãæå€§åããïŒ èª²é¡ å±ç€ºãããçŸè¡åã®åè£ã®åæ°ãšïŒããããã®çŸè¡åã®å€§ãããšäŸ¡å€ãäžãããããšãïŒ S - (A_{max} - A_{min}) ã®æå€§å€ãæ±ããïŒ å
¥å æšæºå
¥åãã以äžã®å
¥åãèªã¿èŸŒãïŒ 1 è¡ç®ã«ã¯ïŒæŽæ° N ãæžãããŠããïŒããã¯ïŒå±ç€ºãããçŸè¡åã®åè£ã®åæ°ã衚ãïŒ ç¶ã N è¡ã®ãã¡ã® i è¡ç®( 1 \leq i \leq N ) ã«ã¯ïŒ2 åã®æŽæ° A_i, B_i ã空çœãåºåããšããŠæžãããŠããïŒãããã¯ïŒçŸè¡å i ã®å€§ããã A_i ïŒäŸ¡å€ã B_i ã§ããããšã衚ãïŒ åºå æšæºåºåã«ïŒ S - (A_{max} - A_{min}) ã®æå€§å€ã1 è¡ã§åºåããïŒ å¶é ãã¹ãŠã®å
¥åããŒã¿ã¯ä»¥äžã®æ¡ä»¶ãæºããïŒ 2 \leq N \leq 500 000ïŒ 1 \leq A_i \leq 1 000 000 000 000 000 = 10^{15} (1 \leq i \leq N)ïŒ 1 \leq B_i \leq 1 000 000 000 (1 \leq i \leq N)ïŒ å
¥åºåäŸ å
¥åäŸ1 3 2 3 11 2 4 5 åºåäŸ1 6 ãã®å
¥åäŸã§ã¯ïŒå±ç€ºãããçŸè¡åã®åè£ã3 ç¹ããïŒããããã®çŸè¡åã®å€§ããïŒäŸ¡å€ã¯æ¬¡ã®éãã§ããïŒ çŸè¡å1 ã®å€§ããã¯2ïŒäŸ¡å€ã¯3 ã§ããïŒ çŸè¡å2 ã®å€§ããã¯11ïŒäŸ¡å€ã¯2 ã§ããïŒ çŸè¡å3 ã®å€§ããã¯4ïŒäŸ¡å€ã¯5 ã§ããïŒ ãã®å ŽåïŒçŸè¡å1 ãšçŸè¡å3 ãå±ç€ºããããã«éžã¶ãšïŒæ¬¡ã®ããã«ã㊠S - (A_{max} - A_{min}) = 6 ãšãªãïŒ éžãã äžã§å€§ãããæå€§ã®çŸè¡åã¯ïŒçŸè¡å3 ã§ããïŒãã£ãŠïŒ A_{max} = 4 ã§ããïŒ éžãã äžã§å€§ãããæå°ã®çŸè¡åã¯ïŒçŸè¡å1 ã§ããïŒãã£ãŠïŒ A_{min} = 2 ã§ããïŒ éžãã çŸè¡åã®äŸ¡å€ã®ç·å㯠3 + 5 = 8 ã§ããããïŒ S = 8 ã§ããïŒ S - (A_{max} - A_{min}) ã7 以äžã«ããããšã¯äžå¯èœãªã®ã§ïŒ6 ãåºåããïŒ å
¥åäŸ2 6 4 1 1 5 10 3 9 1 4 2 5 3 åºåäŸ2 7 å
¥åäŸ3 15 1543361732 260774320 2089759661 257198921 1555665663 389548466 4133306295 296394520 2596448427 301103944 1701413087 274491541 2347488426 912791996 2133012079 444074242 2659886224 656957044 1345396764 259870638 2671164286 233246973 2791812672 585862344 2996614635 91065315 971304780 488995617 1523452673 988137562 åºåäŸ3 4232545716 æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒäœ ã第17 åæ¥æ¬æ
å ±ãªãªã³ããã¯(JOI 2017/2018) æ¬éžã
| 39,096
|
7 ããºã« 7 ããºã«ã¯ 8 ã€ã®æ£æ¹åœ¢ã®ã«ãŒããšãããã®ã«ãŒãããŽãããšåãŸãæ ã§æ§æãããŠããŸããããããã®ã«ãŒãã«ã¯ãäºãã«åºå¥ã§ããããã« 0, 1, 2, ..., 7 ãšçªå·ãã€ããããŠããŸããæ ã«ã¯ã瞊㫠2 åãæšªã« 4 åã®ã«ãŒãã䞊ã¹ãããšãã§ããŸãã 7 ããºã«ãå§ãããšãã«ã¯ããŸãæ ã«ãã¹ãŠã®ã«ãŒããå
¥ããŸããæ ã®ãªãã§ 0 ã®ã«ãŒãã ãã¯ãäžäžå·Šå³ã«é£æ¥ããã«ãŒããšäœçœ®ã亀æããããšãã§ããŸããããšãã°ãæ ã®ç¶æ
ãå³(a) ã®ãšãã«ã0 ã®ã«ãŒãã®å³ã«é£æ¥ããã7 ã®ã«ãŒããšäœçœ®ã亀æããã°ãå³(b) ã®ç¶æ
ã«ãªããŸãããããã¯ãå³(a) ã®ç¶æ
ãã 0 ã®ã«ãŒãã®äžã«é£æ¥ãã 2 ã®ã«ãŒããšäœçœ®ã亀æããã°å³(c) ã®ç¶æ
ã«ãªããŸããå³(a) ã®ç¶æ
ã§ 0 ã®ã«ãŒããšäžäžå·Šå³ã«é£æ¥ããã«ãŒã㯠7 ãš 2 ã®ã«ãŒãã ããªã®ã§ããã以å€ã®äœçœ®ã®å
¥ãæ¿ãã¯èš±ãããŸããã ã²ãŒã ã®ç®çã¯ãã«ãŒãããããã«æŽåããŠå³(d) ã®ç¶æ
ã«ããããšã§ããæåã®ç¶æ
ãå
¥åãšããã«ãŒãããããã«æŽåãããŸã§ã«ãå¿
èŠãªæå°ææ°ãåºåããããã°ã©ã ãäœæããŠãã ããããã ããå
¥åãããã«ãŒãã®ç¶æ
ããã¯å³(d) ã®ç¶æ
ã«ç§»ãããšã¯å¯èœã§ãããšããŸãã å
¥åããŒã¿ã¯ã1 è¡ã« 8 ã€ã®æ°åã空çœåºåãã§äžããããŸãããããã¯ãæåã®ç¶æ
ã®ã«ãŒãã®äžŠã³ã衚ããŸããäŸãã°ãå³(a) ã®æ°å衚çŸã¯ 0 7 3 4 2 5 1 6 ã«ãå³(c) 㯠2 7 3 4 0 5 1 6 ãšãªããŸãã å³(a) 0 7 3 4 2 5 1 6 ã®å Žå å³(b) 7 0 3 4 2 5 1 6 ã®å Žå å³(c) 2 7 3 4 0 5 1 6 ã®å Žå å³(d) 0 1 2 3 4 5 6 7 (æçµç¶æ
) Input äžèšåœ¢åŒã§è€æ°ã®ããºã«ãäžããããŸããå
¥åã®æåŸãŸã§åŠçããŠãã ããã äžããããããºã«ã®æ°ã¯ 1,000 以äžã§ãã Output åããºã«ã«ã€ããŠãæçµç¶æ
ãžç§»è¡ããæå°ææ°ãïŒè¡ã«åºåããŠãã ããã Sample Input 0 1 2 3 4 5 6 7 1 0 2 3 4 5 6 7 7 6 5 4 3 2 1 0 Output for the Sample Input 0 1 28
| 39,097
|
Problem B: Step Step Evolution Japanese video game company has developed the music video game called Step Step Evolution. The gameplay of Step Step Evolution is very simple. Players stand on the dance platform, and step on panels on it according to a sequence of arrows shown in the front screen. There are eight types of direction arrows in the Step Step Evolution: UP, UPPER RIGHT, RIGHT, LOWER RIGHT, DOWN, LOWER LEFT, LEFT, and UPPER LEFT. These direction arrows will scroll upward from the bottom of the screen. When the direction arrow overlaps the stationary arrow nearby the top, then the player must step on the corresponding arrow panel on the dance platform. The figure below shows how the dance platform looks like. Figure 1: the dance platform for Step Step Evolution In the game, you have to obey the following rule: Except for the beginning of the play, you must not press the arrow panel which is not correspond to the edit data. The foot must stay upon the panel where it presses last time, and will not be moved until itâs going to press the next arrow panel. The left foot must not step on the panel which locates at right to the panel on which the right foot rests. Conversely, the right foot must not step on the panel which locates at left to the panel on which the left foot rests. As for the third condition, the following figure shows the examples of the valid and invalid footsteps. Figure 2: the examples of valid and invalid footsteps The first one (left foot for LEFT, right foot for DOWN) and the second one (left foot for LOWER LEFT, right foot for UPPER LEFT) are valid footstep. The last one (left foot for RIGHT, right foot for DOWN) is invalid footstep. Note that, at the beginning of the play, the left foot and right foot can be placed anywhere at the arrow panel. Also, you can start first step with left foot or right foot, whichever you want. To play this game in a beautiful way, the play style called â Natural footstep styleâ is commonly known among talented players. âNatural footstep styleâ is the style in which players make steps by the left foot and the right foot in turn. However, when a sequence of arrows is difficult, players are sometimes forced to violate this style. Now, your friend has created an edit data (the original sequence of direction arrows to be pushed) for you. You are interested in how many times you have to violate âNatural footstep styleâ when you optimally played with this edit data. In other words, what is the minimum number of times you have to step on two consecutive arrows using the same foot? Input The input consists of several detasets. Each dataset is specified by one line containing a sequence of direction arrows. Directions are described by numbers from 1 to 9, except for 5. The figure below shows the correspondence between numbers and directions. You may assume that the length of the sequence is between 1 and 100000, inclusive. Also, arrows of the same direction wonât appear consecutively in the line. The end of the input is indicated by a single â # â. Figure 3: the correspondence of the numbers to the direction arrows Output For each dataset, output how many times you have to violate âNatural footstep styleâ when you play optimally in one line. Sample Input 1 12 123 369 6748 4247219123 1232123212321232 # Output for the Sample Input 0 0 1 0 1 2 7
| 39,098
|
Fun Region Dr. Ciel lives in a planar island with a polygonal coastline. She loves strolling on the island along spiral paths. Here, a path is called spiral if both of the following are satisfied. The path is a simple planar polyline with no self-intersections. At all of its vertices, the line segment directions turn clockwise. Four paths are depicted below. Circle markers represent the departure points, and arrow heads represent the destinations of paths. Among the paths, only the leftmost is spiral. Dr. Ciel finds a point fun if, for all of the vertices of the islandâs coastline, there exists a spiral path that starts from the point, ends at the vertex, and does not cross the coastline. Here, the spiral path may touch or overlap the coastline. In the following figure, the outer polygon represents a coastline. The point â
is fun, while the point â is not fun. Dotted polylines starting from â
are valid spiral paths that end at coastline vertices. Figure J.1. Samples 1, 2, and 3. We can prove that the set of all the fun points forms a (possibly empty) connected region, which we call the fun region . Given the coastline, your task is to write a program that computes the area size of the fun region. Figure J.1 visualizes the three samples given below. The outer polygons correspond to the islandâs coastlines. The fun regions are shown as the gray areas. Input The input consists of a single test case of the following format. $n$ $x_1$ $y_1$ . . . $x_n$ $y_n$ $n$ is the number of vertices of the polygon that represents the coastline ($3 \leq n \leq 2000$). Each of the following $n$ lines has two integers $x_i$ and $y_i$ , which give the coordinates ($x_i, y_i$) of the $i$-th vertex of the polygon, in counterclockwise order. $x_i$ and $y_i$ are between $0$ and $10 000$, inclusive. Here, the $x$-axis of the coordinate system directs right and the $y$-axis directs up. The polygon is simple, that is, it does not intersect nor touch itself. Note that the polygon may be non-convex. It is guaranteed that the inner angle of each vertex is not exactly $180$ degrees. Output Output the area of the fun region in one line. Absolute or relative errors less than $10^{â7}$ are permissible. Sample Input 1 4 10 0 20 10 10 30 0 10 Sample Output 1 300.00 Sample Input 2 10 145 269 299 271 343 193 183 139 408 181 356 324 176 327 147 404 334 434 102 424 Sample Output 2 12658.3130191 Sample Input 3 6 144 401 297 322 114 282 372 178 197 271 368 305 Sample Output 3 0.0
| 39,099
|
ãã§ãŠããšããè¡ã¯å€ã寺瀟ä»é£ã§æåãªèгå
å°ã§ããã ã€ã¯ã¿åã¯æ°äººã®å人ãšãã§ãŠã芳å
ã«æ¥ãŠããããå
šå¡ã奜ãåæã«è¡åããçµæãã¿ããªè¿·åã«ãªã£ãŠããŸã£ãã ããã§ã€ã¯ã¿åã¯ããªãã¹ãæ©ãå
šå¡ãšåæµããããã«ã¯éåå Žæãã©ãã«ããã®ããããèããããšã«ããã ãã§ãŠãã®éè·¯ã¯æ±è¥¿ãšååã«è·é¢10ã®ééã§ç¡æ°ã«èµ°ã£ãŠãããç¡éã«åºããæ£æ¹æ Œåãšã¿ãªãããšãã§ããã éè·¯ã¯çŽç·ã§ãããšã¿ãªããå¹
ã¯ç¡ããã®ãšããã ãŸããè¡ã®äžå¿ãåºæºãšããŠæ±ã«è·é¢ x ãåã«è·é¢ y ç§»åããäœçœ®ã (x,y) ãšãã座æšã§è¡šãã è¡ã®äžå¿ã§ãã (0,0) ã§ã¯æ±è¥¿ã®éè·¯ãšååã®éè·¯ã亀差ããŠããã äžå³ã¯ãã§ãŠãã®éè·¯ãšãããã€ãã®ç¹ã®åº§æšãå³ç€ºãããã®ã§ããã N 人ã®èгå
客ã®åº§æš (X i ,Y i ) ãæŽæ°ã§äžããããã®ã§ã N 人ãéè·¯äžãç§»åããŠ1ç¹ã«éåããã®ã«å¿
èŠãªæéã®æå°å€ãçããã 芳å
å®¢ã¯æé1ãããè·é¢1ã®éãã§é£ç¶çã«éè·¯äžãåãããšãã§ãããšããã äžãããã N 人ã®èгå
客ã®åº§æšã¯ããããçžç°ãªãããŸãå
šãŠã®åº§æšã¯éè·¯äžã«ããããšãä¿èšŒãããŠããã ãŸããè€æ°ã®èгå
客ãåæã«1ç¹ã«ååšãããã芳å
客å士ãããéãããã«ç§»åããããšãå¯èœã§ãããšããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã N X 1 Y 1 ... X N Y N 1è¡ç®ã®Nã¯èгå
客ã®äººæ°ã§ããã æ¬¡ã®Nè¡ã®ãã¡iè¡ç®( 1†i †N )ã¯içªç®ã®èгå
客ã®äœçœ® (X i , Y i ) ã衚ããŠããã X i , Y i ã¯ããããæŽæ°ã§äžããããã Constraints å
¥åäžã®å倿°ã¯ä»¥äžã®å¶çŽãæºããã 2 †N †10000 â10 8 †X i , Y i †10 8 i â j ã®ãšã (X i , Y i ) â (X j , Y j ) X i ãš Y i ã®ãã¡å°ãªããšãäžæ¹ã¯10ã®åæ°ã§ãã Output åé¡ã®è§£ã1è¡ã«åºåããã 10 â3 ãŸã§ã®çµ¶å¯Ÿèª€å·®ã蚱容ããã Sample Input 1 3 5 10 -10 0 3 -10 Output for the Sample Input 1 14 (0, 1) ã«éåããã°ããïŒãã®å
¥åäŸã¯å顿äžã®å³ãšå¯Ÿå¿ããŠããïŒ Sample Input 2 2 0 0 0 1 Output for the Sample Input 2 0.5 (0, 0.5) ã«éåããã°ããïŒæŽæ°åº§æšä»¥å€ã«éãŸãå Žåãããããšã«æ³šæããïŒ Sample Input 3 4 100000000 100000000 100000000 -100000000 -100000000 100000000 -100000000 -100000000 Output for the Sample Input 3 200000000
| 39,100
|
Problem D: Weather Forecast You are the God of Wind. By moving a big cloud around, you can decide the weather: it invariably rains under the cloud, and the sun shines everywhere else. But you are a benign God: your goal is to give enough rain to every field in the countryside, and sun to markets and festivals. Small humans, in their poor vocabulary, only describe this as âweather forecastâ. You are in charge of a small country, called Paccimc. This country is constituted of 4 Ã 4 square areas, denoted by their numbers. Your cloud is of size 2 Ã 2, and may not cross the borders of the country. You are given the schedule of markets and festivals in each area for a period of time. On the first day of the period, it is raining in the central areas (6-7-10-11), independently of the schedule. On each of the following days, you may move your cloud by 1 or 2 squares in one of the four cardinal directions (North, West, South, and East), or leave it in the same position. Diagonal moves are not allowed. All moves occur at the beginning of the day. You should not leave an area without rain for a full week (that is, you are allowed at most 6 consecutive days without rain). You donât have to care about rain on days outside the period you were given: i.e. you can assume it rains on the whole country the day before the period, and the day after it finishes. Input The input is a sequence of data sets, followed by a terminating line containing only a zero. A data set gives the number N of days (no more than 365) in the period on a single line, followed by N lines giving the schedule for markets and festivals. The i -th line gives the schedule for the i-th day. It is composed of 16 numbers, either 0 or 1, 0 standing for a normal day, and 1 a market or festival day. The numbers are separated by one or more spaces. Output The answer is a 0 or 1 on a single line for each data set, 1 if you can satisfy everybody, 0 if there is no way to do it. Sample Input 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 1 1 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 7 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 1 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 0 0 Output for the Sample Input 0 1 0 1
| 39,101
|
Score : 800 points Problem Statement 12:17 (UTC): The sample input 1 and 2 were swapped. The error is now fixed. We are very sorry for your inconvenience. There are N children in AtCoder Kindergarten, conveniently numbered 1 through N . Mr. Evi will distribute C indistinguishable candies to the children. If child i is given a candies, the child's happiness will become x_i^a , where x_i is the child's excitement level . The activity level of the kindergarten is the product of the happiness of all the N children. For each possible way to distribute C candies to the children by giving zero or more candies to each child, calculate the activity level of the kindergarten. Then, calculate the sum over all possible way to distribute C candies. This sum can be seen as a function of the children's excitement levels x_1,..,x_N , thus we call it f(x_1,..,x_N) . You are given integers A_i,B_i (1âŠiâŠN) . Find modulo 10^9+7 . Constraints 1âŠNâŠ400 1âŠCâŠ400 1âŠA_iâŠB_iâŠ400 (1âŠiâŠN) Partial Score 400 points will be awarded for passing the test set satisfying A_i=B_i (1âŠiâŠN) . Input The input is given from Standard Input in the following format: N C A_1 A_2 ... A_N B_1 B_2 ... B_N Output Print the value of modulo 10^9+7 . Sample Input 1 2 3 1 1 1 1 Sample Output 1 4 This case is included in the test set for the partial score, since A_i=B_i . We only have to consider the sum of the activity level of the kindergarten where the excitement level of both child 1 and child 2 are 1 ( f(1,1) ). If child 1 is given 0 candy, and child 2 is given 3 candies, the activity level of the kindergarten is 1^0*1^3=1 . If child 1 is given 1 candy, and child 2 is given 2 candies, the activity level of the kindergarten is 1^1*1^2=1 . If child 1 is given 2 candies, and child 2 is given 1 candy, the activity level of the kindergarten is 1^2*1^1=1 . If child 1 is given 3 candies, and child 2 is given 0 candy, the activity level of the kindergarten is 1^3*1^0=1 . Thus, f(1,1)=1+1+1+1=4 , and the sum over all f is also 4 . Sample Input 2 1 2 1 3 Sample Output 2 14 Since there is only one child, child 1 's happiness itself will be the activity level of the kindergarten. Since the only possible way to distribute 2 candies is to give both candies to child 1 , the activity level in this case will become the value of f . When the excitement level of child 1 is 1 , f(1)=1^2=1 . When the excitement level of child 1 is 2 , f(2)=2^2=4 . When the excitement level of child 1 is 3 , f(3)=3^2=9 . Thus, the answer is 1+4+9=14 . Sample Input 3 2 3 1 1 2 2 Sample Output 3 66 Since it can be seen that f(1,1)=4 , f(1,2)=15 , f(2,1)=15 , f(2,2)=32 , the answer is 4+15+15+32=66 . Sample Input 4 4 8 3 1 4 1 3 1 4 1 Sample Output 4 421749 This case is included in the test set for the partial score. Sample Input 5 3 100 7 6 5 9 9 9 Sample Output 5 139123417
| 39,102
|
Score : 1000 points Problem Statement Niwango-kun has \(N\) chickens as his pets. The chickens are identified by numbers \(1\) to \(N\), and the size of the \(i\)-th chicken is a positive integer \(a_i\). \(N\) chickens decided to take each other's hand (wing) and form some cycles. The way to make cycles is represented by a permutation \(p\) of \(1, \ldots , N\). Chicken \(i\) takes chicken \(p_i\)'s left hand by its right hand. Chickens may take their own hand. Let us define the cycle containing chicken \(i\) as the set consisting of chickens \(p_i, p_{p_i}, \ldots, p_{\ddots_i} = i\). It can be proven that after each chicken takes some chicken's hand, the \(N\) chickens can be decomposed into cycles. The beauty \(f(p)\) of a way of forming cycles is defined as the product of the size of the smallest chicken in each cycle. Let \(b_i \ (1 \leq i \leq N)\) be the sum of \(f(p)\) among all possible permutations \(p\) for which \(i\) cycles are formed in the procedure above. Find the greatest common divisor of \(b_1, b_2, \ldots, b_N\) and print it \({\rm mod} \ 998244353\). Constraints \(1 \leq N \leq 10^5\) \(1 \leq a_i \leq 10^9\) All numbers given in input are integers Input Input is given from Standard Input in the following format: \(N\) \(a_1\) \(a_2\) \(\ldots\) \(a_N\) Output Print the answer. Sample Input 1 2 4 3 Sample Output 1 3 In this case, \(N = 2, a = [ 4, 3 ]\). For the permutation \(p = [ 1, 2 ]\), a cycle of an only chicken \(1\) and a cycle of an only chicken \(2\) are made, thus \(f([1, 2]) = a_1 \times a_2 = 12\). For the permutation \(p = [ 2, 1 ]\), a cycle of two chickens \(1\) and \(2\) is made, and the size of the smallest chicken is \(a_2 = 3\), thus \(f([2, 1]) = a_2 = 3\). Now we know \(b_1 = f([2, 1]) = 3, b_2 = f([1, 2]) = 12\), and the greatest common divisor of \(b_1\) and \(b_2\) is \(3\). Sample Input 2 4 2 5 2 5 Sample Output 2 2 There are always \(N!\) permutations because chickens of the same size can be distinguished from each other. The following picture illustrates the cycles formed and their beauties when \(p = (2, 1, 4, 3)\) and \(p = (3, 4, 1, 2)\), respectively.
| 39,103
|
Problem C: ã©ã㌠ããªãã®åéã¯æè¿ UT-Rummy ãšããã«ãŒãã²ãŒã ãæãã€ããïŒ ãã®ã²ãŒã ã§äœ¿ãã«ãŒãã«ã¯èµ€ã»ç·ã»éã®ããããã®è²ãš1ãã9ãŸã§ã®ããããã®çªå·ã ã€ããããŠããïŒ ãã®ã²ãŒã ã®ãã¬ã€ã€ãŒã¯ãããã9æã®ææãæã¡ïŒ èªåã®ã¿ãŒã³ã«ææãã1æéžãã§æšãŠãŠïŒ 代ããã«å±±æãã1æåŒããŠãããšããããšãç¹°ãè¿ãïŒ ãã®ããã«é çªã«ã¿ãŒã³ãé²ããŠããïŒ æåã«ææã¡ã®ã«ãŒãã«3æãã€3ã€ã®ãã»ããããäœã£ããã¬ã€ã€ãŒãåã¡ãšãªãïŒ ã»ãããšã¯ïŒåãè²ã®3æã®ã«ãŒããããªãçµã§ïŒãã¹ãŠåãæ°ãæã£ãŠããã é£çªããªããŠãããã®ã®ããšãèšãïŒ é£çªã«é¢ããŠã¯ïŒçªå·ã®å·¡åã¯èªããããªãïŒ äŸãã°ïŒ7, 8, 9ã¯é£çªã§ããã 9, 1, 2ã¯é£çªã§ã¯ãªãïŒ ããªãã®åéã¯ãã®ã²ãŒã ãã³ã³ãã¥ãŒã¿ã²ãŒã ãšããŠå£²ãåºããšããèšç»ãç«ãŠãŠïŒ ãã®äžç°ãšããŠããªãã«å婿¡ä»¶ã®å€å®éšåãäœæããŠæ¬²ãããšé Œãã§ããïŒ ããªãã®ä»äºã¯ïŒææãå婿¡ä»¶ãæºãããŠãããã©ãããå€å®ãã ããã°ã©ã ãæžãããšã§ããïŒ Input å
¥åã®1è¡ç®ã«ã¯ããŒã¿ã»ããæ°ãè¡šãæ° T (0 < T †50) ãäžããããïŒ ãã®è¡ã«åŒãç¶ã T åã®ããŒã¿ã»ãããäžããããïŒ åããŒã¿ã»ããã¯2è¡ãããªãïŒ 1è¡ç®ã«ã¯ i çªç® ( i = 1, 2, ..., 9) ã®ã«ãŒãã®æ°å n i ãããããã¹ããŒã¹ã§åºåãããŠäžãããïŒ 2è¡ç®ã«ã¯ i çªç®ã®ã«ãŒãã®è²ã衚ãæå c i ãããããã¹ããŒã¹ã§åºåãããŠäžããããïŒ ã«ãŒãã®æ°å n i 㯠1 †n i †9 ãæºããæŽæ°ã§ããïŒ ã«ãŒãã®è² c i ã¯ãããã â R â, â G â, â B â ã®ããããã®æåã§ããïŒ 1ã€ã®ããŒã¿ã»ããå
ã«è²ãšæ°åããšãã«åãã«ãŒãã5æä»¥äžåºçŸããããšã¯ãªãïŒ Output åããŒã¿ã»ããã«ã€ãïŒå婿¡ä»¶ãæºãããŠããã° â 1 âïŒ ããã§ãªããã° â 0 â ãšåºåããïŒ Sample Input 5 1 2 3 3 4 5 7 7 7 R R R R R R G G G 1 2 2 3 4 4 4 4 5 R R R R R R R R R 1 2 3 4 4 4 5 5 5 R R B R R R R R R 1 1 1 3 4 5 6 6 6 R R B G G G R R R 2 2 2 3 3 3 1 1 1 R G B R G B R G B Output for the Sample Input 1 0 0 0 1
| 39,104
|
I - The J-th Number Problem Statement You are given N empty arrays, t_1, ..., t_n . At first, you execute M queries as follows. add a value v to array t_i ( a \leq i \leq b ) Next, you process Q following output queries. output the j -th number of the sequence sorted all values in t_i ( x \leq i \leq y ) Input The dataset is formatted as follows. N M Q a_1 b_1 v_1 ... a_M b_M v_M x_1 y_1 j_1 ... x_Q y_Q j_Q The first line contains three integers N ( 1 \leq N \leq 10^9 ), M ( 1 \leq M \leq 10^5 ) and Q ( 1 \leq Q \leq 10^5 ). Each of the following M lines consists of three integers a_i , b_i and v_i ( 1 \leq a_i \leq b_i \leq N , 1 \leq v_i \leq 10^9 ). Finally the following Q lines give the list of output queries, each of these lines consists of three integers x_i , y_i and j_i ( 1 \leq x_i \leq y_i \leq N, 1 \leq j_i \leq Σ_{x_i \leq k \leq y_i} |t_k| ). Output For each output query, print in a line the j -th number. Sample Input 1 5 4 1 1 5 1 1 1 3 4 5 1 3 4 2 1 3 4 Output for the Sample Input 1 2 After the M -th query is executed, each t_i is as follows: [1,3], [1], [1,2], [1,1,2], [1,1] The sequence sorted values in t_1 , t_2 and t_3 is [1,1,1,2,3]. In the sequence, the 4-th number is 2. Sample Input 2 10 4 4 1 4 11 2 3 22 6 9 33 8 9 44 1 1 1 4 5 1 4 6 2 1 10 12 Output for the Sample Input 2 11 11 33 44
| 39,106
|
Problem K Counting Cycles Given an undirected graph, count the number of simple cycles in the graph. Here, a simple cycle is a connected subgraph all of whose vertices have degree exactly two. Input The input consists of a single test case of the following format. $n$ $m$ $u_1$ $v_1$ ... $u_m$ $v_m$ A test case represents an undirected graph $G$. The first line shows the number of vertices $n$ ($3 \leq n \leq 100 000$) and the number of edges $m$ ($n - 1 \leq m \leq n + 15$). The vertices of the graph are numbered from $1$ to $n$. The edges of the graph are specified in the following $m$ lines. Two integers $u_i$ and $v_i$ in the $i$-th line of these m lines mean that there is an edge between vertices $u_i$ and $v_i$. Here, you can assume that $u_i < v_i$ and thus there are no self loops. For all pairs of $i$ and $j$ ($i \ne j$), either $u_i \ne u_j$ or $v_i \ne v_j$ holds. In other words, there are no parallel edges. You can assume that $G$ is connected. Output The output should be a line containing a single number that is the number of simple cycles in the graph. Sample Input 1 4 5 1 2 1 3 1 4 2 3 3 4 Sample Output 1 3 Sample Input 2 7 9 1 2 1 3 2 4 2 5 3 6 3 7 2 3 4 5 6 7 Sample Output 2 3 Sample Input 3 4 6 1 2 1 3 1 4 2 3 2 4 3 4 Sample Output 3 7
| 39,107
|
æªæåºè
ã¯èª°ã åé¡ JOI倧åŠã®Mææã¯ããã°ã©ãã³ã°ã®ææ¥ãæ
åœããŠããïŒã¯ã©ã¹ã«ã¯30人ã®åè¬çãããŠååè¬çã«ã¯1çªãã30çªãŸã§ã®åºåžçªå·ããµãããŠããïŒãã®ææ¥ã®èª²é¡ã28人ã®åŠçãæåºããïŒæåºãã28人ã®åºåžçªå·ããæåºããŠããªã2人ã®åºåžçªå·ãæ±ããããã°ã©ã ãäœæããïŒ å
¥å å
¥åã¯28è¡ããïŒåè¡ã«ã¯æåºè
ã®åºåžçªå·ïŒ1以äž30以äžïŒã1ã€ãã€æžãããŠããïŒå
¥åãããåºåžçªå·ã«éè€ã¯ãªããïŒã©ã®ãããªé ã«å
¥åããããã¯ããããªãïŒ åºå åºåã¯2è¡ãããªãïŒ 1è¡ç®ã«2äººã®æªæåºè
ã®åºåžçªå·ã®ãã¡å°ããã»ããïŒ 2è¡ç®ã«å€§ããã»ããåºåããïŒ å
¥åºåäŸ å
¥åäŸ 1 3 1 4 5 7 9 6 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 åºåäŸ 1 2 8 å
¥åäŸ 2 9 30 6 12 10 20 21 11 7 5 28 4 18 29 17 19 27 13 16 26 14 23 22 15 3 1 24 25 åºåäŸ 2 2 8 äžèšå顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
| 39,108
|
Official House You manage 4 buildings, each of which has 3 floors, each of which consists of 10 rooms. Write a program which reads a sequence of tenant/leaver notices, and reports the number of tenants for each room. For each notice, you are given four integers b , f , r and v which represent that v persons entered to room r of f th floor at building b . If v is negative, it means that âv persons left. Assume that initially no person lives in the building. Input In the first line, the number of notices n is given. In the following n lines, a set of four integers b , f , r and v which represents i th notice is given in a line. Output For each building, print the information of 1st, 2nd and 3rd floor in this order. For each floor information, print the number of tenants of 1st, 2nd, .. and 10th room in this order. Print a single space character before the number of tenants. Print "####################" (20 '#') between buildings. Constraints No incorrect building, floor and room numbers are given. 0 †the number of tenants during the management †9 Sample Input 3 1 1 3 8 3 2 2 7 4 3 8 1 Sample Output 0 0 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 #################### 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 #################### 0 0 0 0 0 0 0 0 0 0 0 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 #################### 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
| 39,109
|
æèšŒçªå· æ°ããæèšŒçªå·ã¯èŠãã«ãããã®ã§ããã¡ã¢ããã®ã¯ãã¡ãšããããŸããããèŠãããããã«ãããŸãããããã§æç« ã®äžã«æ°å€ãåã蟌ãã§æèšŒçªå·ãã¡ã¢ããããšã«ããŸãããããã§ã¯å
šãŠã®æ°å€ã®åãæèšŒçªå·ã«ãªããŸãã ã¡ã¢ãããæç« ãèªã¿èŸŒãã§ãæèšŒçªå·ãåºåããããã°ã©ã ãäœæããŠãã ããã Input æ£ã®æŽæ°ãåã蟌ãŸããæç« ãè€æ°è¡ã«ãããäžããããŸããåè¡ã¯åè§è±æ°åãèšå·ã空çœãå«ãæååãŸãã¯ç©ºè¡ã§ãã ãã ããå
¥å㯠1 è¡ããã 80 æå以å
ã§ãæèšŒçªå·ã¯ 10,000 以äžã§ããããšãä¿éãããŠããŸãã Output æèšŒçªå·ïŒæç« äžã®æ£ã®æŽæ°ã®åèšïŒãïŒè¡ã«åºåããŸãã Sample Input Thereare100yenonthetable.Iam17yearsold. Ishouldgohomeat6pm. Output for the Sample Input 123
| 39,110
|
H: Revenge of UMG åé¡ 'U', 'M', 'G' ã®äžçš®é¡ã®æåãããªãæåå T ã«å¯Ÿãã 1, 2, ..., |T| æåç®ããããã T_1, T_2, ..., T_{|T|} ãšè¡šãããšã«ãããšãã以äžã®æ¡ä»¶ãæºãã (i, j, k) ã®çµã®åæ°ããæåå T ã® âUMG æ°âãšåŒã¶ããšã«ããŸã: 1 \leq i < j < k \leq |T| j - i = k - j T_i = 'U', T_j = 'M', T_k = 'G' ããŠã'U', 'M', 'G', '?' ã®åçš®é¡ã®æåãããªãæåå S ãäžããããŸãã S ã® '?' ããããã 'U', 'M', 'G' ã®ããããã«çœ®ãæããŠã§ããæååã¯ã'?' ã®åæ°ã N ãšã㊠3^{N} éãèããããŸãããããããã®æååã® UMG æ°ã«ã€ããŠç·åããšã£ããã®ã 998244353 ã§å²ã£ãããŸããæ±ããŠãã ããã å
¥ååœ¢åŒ S å¶çŽ 3 \leq |S| \leq 2 \times 10^{5} S 㯠'U', 'M', 'G', '?' ã®åçš®é¡ã®æåãããªãæååã§ããã åºååœ¢åŒ çããè¡šãæŽæ°ãäžè¡ã«åºåããŠãã ããã 998244353 ã§å²ã£ãããŸããåºåããããšã«æ³šæããŠãã ããã å
¥åäŸ 1 ?MG? åºåäŸ 1 3 æåã® '?' ã 'U' ã§ãªãå Žåã«ã¯ UMG æ°ã¯ 0 ã«ãªããŸããæåã® '?' ã 'U' ãšãããšãã UMGU ã® UMG æ°ã¯ 1 UMGM ã® UMG æ°ã¯ 1 UMGG ã® UMG æ°ã¯ 1 ãšãªããåèšå€ã¯ 3 ã«ãªããŸãã å
¥åäŸ 2 UUMMGGGUMG åºåäŸ 2 4 å
¥åäŸ 3 ?????G????U???M??????G?????M????G???U??????M???G?? åºåäŸ 3 648330088 998244353 ã§å²ã£ãããŸããçããŠãã ããã
| 39,111
|
A: 磯éãããããããïŒ - Sendame - ç©èª äžå³¶ã磯éãïŒããããããïŒã 磯éãããã£ãŠäœã ãïŒäžå³¶ã äžå³¶ãã»ãïŒããã ãïŒããïŒãªããæåã§è¡šããªãããªããªãããïŒèª¬æãã¥ãããªãã 磯éãããïŒå³ãåçãå
¥ããããã¿ããã ãïŒã äžå³¶ãæ¬åœã ïŒã 磯éãã§ïŒäœããããã ïŒã äžå³¶ãã»ãïŒãªãºã ã«ä¹ã£ãŠïŒæã2åå©ããåŸã«ïŒé²åŸ¡ïŒæºãïŒæ»æã®ããŒãºãåããã€ã 磯éããããïŒã€ãã€ãããããªããªâŠã äžå³¶ã2åæãå©ããåŸã«ïŒäŸãã°é²åŸ¡ã ã£ããã äžå³¶ãã§ïŒæºãã ã£ããã äžå³¶ãæ»æã ã£ããã äžå³¶ãã£ãŠãããã€ïŒç¥ã£ãŠãã ãïŒã 磯éãããïŒåçãå
¥ããšåçã«åããããããªããªïŒã äžå³¶ããããææã®é²æ©ã ãªïŒã (ããããæ ä¹
ã®æãçµã£ã) è±æ²¢ãããããã®ããããããããªããããããŸãããããããã äºäººã(ããããâŠããããâŠããããâŠ)ã è±æ²¢ãã¢ã³ã¿ãã¡ïŒãŸããå¯ãªãããããã£ãŠãã®âŠïŒïŒã è±æ²¢ãä»åè² ã€ãããããªãâŠç£¯éããïŒä»ããªãåã£ãããïŒã 磯éãâŠâŠè±æ²¢ããæ¥ãŠããã âŠäžå³¶ããäžåºŠãããâŠzzzã äžå³¶ã(ããã)ã äºäººã(ããããâŠããããâŠ)ã è±æ²¢ãããâŠããã«ïŒããã®åæå€å®ãããã眮ããŠããããâŠã ããããŠè±æ²¢ããã¯å»ã£ãŠè¡ã£ãïŒ ãšããããšããããããããªãã®ã§ïŒããã®åæå€å®ããã°ã©ã ãæžããŠãã ããïŒ åé¡ ããããã¯2人ã§è¡ãã²ãŒã ã§ããïŒãªãºã ã«åãããŠ2人ãåæã«ïŒé²åŸ¡ïŒæºãïŒæ»æã®ããããã®ããŒãºãåãããšãç¹°ãè¿ãïŒããã§ïŒ2人ãããŒãºãåãã¿ã€ãã³ã°ã®ããšããåããšè¡šèšããïŒãã®ã²ãŒã ã§ã¯ïŒããåã§åæãã€ãïŒãã€ïŒãããŸã§ã®åã§åæãã€ããŠããªããšãïŒãã®åæãã²ãŒã ã®åæãšãªãïŒ 2人ã¯ãããããæ»æåããšãããã©ã¡ãŒã¿ãæã¡ïŒã²ãŒã éå§æïŒæ»æå㯠0 ã§ããïŒ æ»æã®ããŒãºãåã£ãå ŽåïŒãã®æç¹ã§ã®æ»æåã«å¿ããŠïŒæ¬¡ã®ããã«ãªãïŒ æ»æåã 0 ã®ãšãã«æ»æã®ããŒãºãåããšïŒååè² ããšãªãïŒãã ãïŒçžæãæ»æåã 0 ã§æ»æã®ããŒãºãããå ŽåïŒãã®åã§ã¯åæãã€ããªãïŒ èªåã®æ»æåã 1 以äžã®ãšãã«æ»æã®ããŒãºããšããšïŒçžæã«æ»æãå ããïŒãŸãïŒãã®åã§çžæãæ»æã®ããŒãºãåã£ãå ŽåïŒæ»æåã®ããé«ããã¬ã€ã€ãŒãåå©ããïŒãã ãïŒäž¡ãã¬ã€ã€ãŒãåãæ»æåã§æ»æã®ããŒãºãåã£ãå Žåã«ã¯ïŒãã®åã§ã¯åæãã€ããªãïŒ ãŸãïŒæ»æã®ããŒãºãåã£ãåã®çµäºæã«ïŒèªåã®æ»æåã 0 ã«ãªãïŒ æºãã®ããŒãºãåããšïŒãã®ãã¬ã€ã€ãŒã®æ»æåã 1 ã ãäžæããïŒãã ãïŒæ»æåã 5 ã§ããå ŽåïŒãã®ãã¬ã€ã€ãŒãæºãã®ããŒãºãåã£ãŠãïŒæ»æå㯠5 ã®ãŸãŸã§ããïŒæºãã®ããŒãºãåã£ãåã§ïŒçžæãæ»æãå ããå ŽåïŒçžæãåå©ããïŒãªãïŒæºãã®ããŒãºãåã£ãåã§ïŒçžæãæ»æä»¥å€ã®ããŒãºããšã£ãå ŽåïŒåæãã€ããªãïŒ é²åŸ¡ã®ããŒãºãåã£ãåã«ïŒçžæãæ»æå 5 ã®æ»æãå ããå ŽåïŒçžæãåå©ããïŒäžæ¹ïŒé²åŸ¡ã®ããŒãºãåã£ãåã«ïŒçžæãæ»æå 4 以äžã®æ»æãå ããå ŽåãïŒæºããŸãã¯é²åŸ¡ã®ããŒãºãåã£ãå ŽåïŒãã®åã§ã¯åæãã€ããªãïŒãªãïŒé²åŸ¡ã®ããŒãºãåã£ãŠãïŒãã®ãã¬ã€ã€ãŒã®æ»æåã«å€åã¯ãªãïŒ äž¡ãã¬ã€ã€ãŒã®ããŒãºãé ã«äžããããã®ã§ïŒåæãåºåããïŒãªãïŒäž¡ãã¬ã€ã€ãŒã¯åæã決å®ããåŸãããŒãºããšãç¶ããããšããããïŒåæã決å®ããåŸã®ããŒãºã¯ç¡èŠãããã®ãšããïŒ å
¥ååœ¢åŒ å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ K I_1 ... I_K N_1 ... N_K å
¥åã®1è¡ç®ã«ã¯ïŒ1åã®æŽæ° K ( 1 †K †100 ) ãäžããããïŒ 2è¡ç®ããã® K è¡ã«ã¯ïŒç£¯éãåã£ãããŒãº I_i ( 1 †i †K ) ãé ã«äžããããïŒ ãã®çŽåŸã® K è¡ã«ã¯ïŒäžå³¶ãåã£ãããŒãº N_i ( 1 †i †K ) ãé ã«äžããããïŒ I_i ããã³ N_i 㯠âmamoruâ, âtameruâ, âkougekidaâ ã®ããããã§ããïŒãããã®æååã¯é ã«ïŒé²åŸ¡ïŒæºãïŒæ»æã®ããŒãºã衚ãïŒ åºååœ¢åŒ ç£¯éãåå©ããå Žåã«ã¯ âIsono-kunâ ïŒäžå³¶ãåå©ããå Žåã«ã¯ âNakajima-kunâ ïŒ K åã§åæãã€ããªãå Žåã«ã¯ïŒ âHikiwake-kunâ ãš1è¡ã§åºåããïŒ å
¥åäŸ1 3 tameru tameru tameru tameru kougekida tameru åºåäŸ1 Nakajima-kun 2 åç®ã§ïŒç£¯éãæºãã®ããŒãºãããŠããã®ã«å¯ŸãïŒäžå³¶ã¯æ»æå 1 ã®æ»æãããŠããã®ã§ïŒäžå³¶ã®åå©ã§ãïŒ å
¥åäŸ2 3 mamoru mamoru mamoru tameru tameru tameru åºåäŸ2 Hikiwake-kun ã©ã¡ããæ»æãããªãã£ãã®ã§ïŒåæãã€ããŸããã§ããïŒ å
¥åäŸ3 5 tameru tameru mamoru mamoru kougekida tameru tameru kougekida tameru kougekida åºåäŸ3 Isono-kun 1 åç®ãã 4 åç®ãŸã§ã§ã¯åæãã€ããŸããïŒ 5 åç®ã§ïŒäž¡ãã¬ã€ã€ãŒãæ»æã®ããŒãºãããŠããŸããïŒç£¯éã®æ»æåã 2 ãªã®ã«å¯ŸãïŒäžå³¶ã®æ»æåã 1 ãªã®ã§ïŒç£¯éã®åå©ã§ãïŒ å
¥åäŸ4 3 kougekida kougekida tameru kougekida mamoru kougekida åºåäŸ4 Nakajima-kun 1 åç®ã§ã¯ïŒäž¡ãã¬ã€ã€ãŒãæ»æå 0 ã§æ»æã®ããŒãºãåã£ãŠããã®ã§ïŒåæãã€ããŸããïŒ 2 åç®ã§ã¯ïŒç£¯éã®ã¿ãæ»æå 0 ã§æ»æã®ããŒãºããšã£ãŠããã®ã§ïŒäžå³¶ã®åå©ã§ãïŒ å
¥åäŸ5 8 tameru mamoru tameru tameru tameru tameru tameru kougekida tameru kougekida mamoru mamoru mamoru mamoru mamoru mamoru åºåäŸ5 Isono-kun 2 åç®ã§ã¯ïŒäžå³¶ãæ»æå 1 ã§æ»æã®ããŒãºãåã£ãŠããŸããïŒç£¯éãé²åŸ¡ã®ããŒãºãåã£ãŠããã®ã§ïŒåæãã€ããŸããïŒ 7 åç®ã§ã¯ïŒç£¯éãæ»æå 5 ã§æºãã®ããŒãºãåã£ãŠããã®ã§ïŒç£¯éã®æ»æå㯠5 ã®ãŸãŸã§ãïŒ 8 åç®ã§ã¯ïŒç£¯éãæ»æå 5 ã§æ»æã®ããŒãºããšãïŒäžå³¶ãé²åŸ¡ã®ããŒãºãåã£ãŠããã®ã§ïŒç£¯éãåå©ããŸãïŒ
| 39,112
|
Score : 100 points Problem Statement We have A balls with the string S written on each of them and B balls with the string T written on each of them. From these balls, Takahashi chooses one with the string U written on it and throws it away. Find the number of balls with the string S and balls with the string T that we have now. Constraints S , T , and U are strings consisting of lowercase English letters. The lengths of S and T are each between 1 and 10 (inclusive). S \not= T S=U or T=U . 1 \leq A,B \leq 10 A and B are integers. Input Input is given from Standard Input in the following format: S T A B U Output Print the answer, with space in between. Sample Input 1 red blue 3 4 red Sample Output 1 2 4 Takahashi chose a ball with red written on it and threw it away. Now we have two balls with the string S and four balls with the string T . Sample Input 2 red blue 5 5 blue Sample Output 2 5 4 Takahashi chose a ball with blue written on it and threw it away. Now we have five balls with the string S and four balls with the string T .
| 39,114
|
Largest Rectangle Given a matrix ( H à W ) which contains only 1 and 0, find the area of the largest rectangle which only contains 0s. Input H W c 1,1 c 1,2 ... c 1,W c 2,1 c 2,2 ... c 2,W : c H,1 c H,2 ... c H,W In the first line, two integers H and W separated by a space character are given. In the following H lines, c i , j , elements of the H à W matrix, are given. Output Print the area (the number of 0s) of the largest rectangle. Constraints 1 †H , W †1,400 Sample Input 4 5 0 0 1 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 Sample Output 6
| 39,115
|
Score : 100 points Problem Statement There is a directed graph G with N vertices and M edges. The vertices are numbered 1, 2, \ldots, N , and for each i ( 1 \leq i \leq M ), the i -th directed edge goes from Vertex x_i to y_i . G does not contain directed cycles . Find the length of the longest directed path in G . Here, the length of a directed path is the number of edges in it. Constraints All values in input are integers. 2 \leq N \leq 10^5 1 \leq M \leq 10^5 1 \leq x_i, y_i \leq N All pairs (x_i, y_i) are distinct. G does not contain directed cycles . Input Input is given from Standard Input in the following format: N M x_1 y_1 x_2 y_2 : x_M y_M Output Print the length of the longest directed path in G . Sample Input 1 4 5 1 2 1 3 3 2 2 4 3 4 Sample Output 1 3 The red directed path in the following figure is the longest: Sample Input 2 6 3 2 3 4 5 5 6 Sample Output 2 2 The red directed path in the following figure is the longest: Sample Input 3 5 8 5 3 2 3 2 4 5 2 5 1 1 4 4 3 1 3 Sample Output 3 3 The red directed path in the following figure is one of the longest:
| 39,116
|
Score : 100 points Problem Statement Given an integer N not less than 3 , find the sum of the interior angles of a regular polygon with N sides. Print the answer in degrees, but do not print units. Constraints 3 \leq N \leq 100 Input Input is given from Standard Input in the following format: N Output Print an integer representing the sum of the interior angles of a regular polygon with N sides. Sample Input 1 3 Sample Output 1 180 The sum of the interior angles of a regular triangle is 180 degrees. Sample Input 2 100 Sample Output 2 17640
| 39,118
|
Score : 1000 points Problem Statement You are given an integer sequence of length N : A_1,A_2,...,A_N . Let us perform Q operations in order. The i -th operation is described by two integers X_i and Y_i . In this operation, we will choose one of the following two actions and perform it: Swap the values of A_{X_i} and A_{Y_i} Do nothing There are 2^Q ways to perform these operations. Find the sum of the inversion numbers of the final sequences for all of these ways to perform operations, modulo 10^9+7 . Here, the inversion number of a sequence P_1,P_2,...,P_M is the number of pairs of integers (i,j) such that 1\leq i < j\leq M and P_i > P_j . Constraints 1 \leq N \leq 3000 0 \leq Q \leq 3000 0 \leq A_i \leq 10^9(1\leq i\leq N) 1 \leq X_i,Y_i \leq N(1\leq i\leq Q) X_i\neq Y_i(1\leq i\leq Q) All values in input are integers. Input Input is given from Standard Input in the following format: N Q A_1 : A_N X_1 Y_1 : X_Q Y_Q Output Print the sum of the inversion numbers of the final sequences, modulo 10^9+7 . Sample Input 1 3 2 1 2 3 1 2 1 3 Sample Output 1 6 There are four ways to perform operations, as follows: Do nothing, both in the first and second operations. The final sequence would be 1,2,3 , with the inversion number of 0 . Do nothing in the first operation, then perform the swap in the second. The final sequence would be 3,2,1 , with the inversion number of 3 . Perform the swap in the first operation, then do nothing in the second. The final sequence would be 2,1,3 , with the inversion number of 1 . Perform the swap, both in the first and second operations. The final sequence would be 3,1,2 , with the inversion number of 2 . The sum of these inversion numbers, 0+3+1+2=6 , should be printed. Sample Input 2 5 3 3 2 3 1 4 1 5 2 3 4 2 Sample Output 2 36 Sample Input 3 9 5 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 Sample Output 3 425
| 39,119
|
Score : 100 points Problem Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30 th, December? Constraints 1â€Mâ€23 M is an integer. Input Input is given from Standard Input in the following format: M Output If we have x hours until New Year at M o'clock on 30 th, December, print x . Sample Input 1 21 Sample Output 1 27 We have 27 hours until New Year at 21 o'clock on 30 th, December. Sample Input 2 12 Sample Output 2 36
| 39,120
|
Score: 600 points Problem Statement How many strings can be obtained by applying the following operation on a string S exactly K times: "choose one lowercase English letter and insert it somewhere"? The answer can be enormous, so print it modulo (10^9+7) . Constraints K is an integer between 1 and 10^6 (inclusive). S is a string of length between 1 and 10^6 (inclusive) consisting of lowercase English letters. Input Input is given from Standard Input in the following format: K S Output Print the number of strings satisfying the condition, modulo (10^9+7) . Sample Input 1 5 oof Sample Output 1 575111451 For example, we can obtain proofend , moonwolf , and onionpuf , while we cannot obtain oofsix , oofelevennn , voxafolt , or fooooooo . Sample Input 2 37564 whydidyoudesertme Sample Output 2 318008117
| 39,122
|
Score : 700 points Problem Statement We have N cards numbered 1, 2, ..., N . Card i ( 1 \leq i \leq N ) has an integer A_i written in red ink on one side and an integer B_i written in blue ink on the other side. Initially, these cards are arranged from left to right in the order from Card 1 to Card N , with the red numbers facing up. Determine whether it is possible to have a non-decreasing sequence facing up from left to right (that is, for each i ( 1 \leq i \leq N - 1 ), the integer facing up on the (i+1) -th card from the left is not less than the integer facing up on the i -th card from the left) by repeating the operation below. If the answer is yes, find the minimum number of operations required to achieve it. Choose an integer i ( 1 \leq i \leq N - 1 ). Swap the i -th and (i+1) -th cards from the left, then flip these two cards. Constraints 1 \leq N \leq 18 1 \leq A_i, B_i \leq 50 ( 1 \leq i \leq N ) 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 If it is impossible to have a non-decreasing sequence, print -1 . If it is possible, print the minimum number of operations required to achieve it. Sample Input 1 3 3 4 3 3 2 3 Sample Output 1 1 By doing the operation once with i = 1 , we have a sequence [2, 3, 3] facing up, which is non-decreasing. Sample Input 2 2 2 1 1 2 Sample Output 2 -1 After any number of operations, we have the sequence [2, 1] facing up, which is not non-decreasing. Sample Input 3 4 1 2 3 4 5 6 7 8 Sample Output 3 0 No operation may be required. Sample Input 4 5 28 15 22 43 31 20 22 43 33 32 Sample Output 4 -1 Sample Input 5 5 4 46 6 38 43 33 15 18 27 37 Sample Output 5 3
| 39,123
|
Shell Sort Shell Sort is a generalization of Insertion Sort to arrange a list of $n$ elements $A$. 1 insertionSort(A, n, g) 2 for i = g to n-1 3 v = A[i] 4 j = i - g 5 while j >= 0 && A[j] > v 6 A[j+g] = A[j] 7 j = j - g 8 cnt++ 9 A[j+g] = v 10 11 shellSort(A, n) 12 cnt = 0 13 m = ? 14 G[] = {?, ?,..., ?} 15 for i = 0 to m-1 16 insertionSort(A, n, G[i]) A function shellSort(A, n) performs a function insertionSort(A, n, g), which considers every $g$-th elements. Beginning with large values of $g$, it repeats the insertion sort with smaller $g$. Your task is to complete the above program by filling ? . Write a program which reads an integer $n$ and a sequence $A$, and prints $m$, $G_i (i = 0, 1, ..., m â 1)$ in the pseudo code and the sequence $A$ in ascending order. The output of your program must meet the following requirements: $1 \leq m \leq 100$ $0 \leq G_i \leq n$ cnt does not exceed $\lceil n^{1.5}\rceil$ Input In the first line, an integer $n$ is given. In the following $n$ lines, $A_i (i=0,1,...,n-1)$ are given for each line. Output In the first line, print an integer $m$. In the second line, print $m$ integers $G_i (i=0,1,...,m-1)$ separated by single space character in a line. In the third line, print cnt in a line. In the following $n$ lines, print $A_i (i=0,1,...,n-1)$ respectively. This problem has multiple solutions and the judge will be performed by a special validator. Constraints $1 \leq n \leq 1,000,000$ $0 \leq A_i \leq 10^9$ Sample Input 1 5 5 1 4 3 2 Sample Output 1 2 4 1 3 1 2 3 4 5 Sample Input 2 3 3 2 1 Sample Output 2 1 1 3 1 2 3
| 39,124
|
B : RUPC å顿 ãã·ã¢é£éŠã§ããã°ã©ãã³ã°ã³ã³ãã¹ããéå¬ããããã³ã³ãã¹ãã«ã¯ N åã®åé¡ãåºé¡ããã M 人ã®åå è
ããããåé¡ i ã«ã¯åŸç¹ a_i ãèšå®ãããŠãããåå è
j ã®å®å㯠b_j ã§ããããšãããã£ãŠãããåé¡ i ãšåå è
j ã«ã€ããŠã a_i †b_j ã®ãšããã€ãã®ãšãéããåå è
j ã¯åé¡ i ãå¿
ãè§£ãããšãã§ããã ã³ã³ãã¹ããéããåå è
ã®åŸç¹ã¯ããã®äººãè§£ãããšãã§ããåé¡ã®åŸç¹ã®ç·åã§ããããŸããåå è
j ã¯ããã®ã³ã³ãã¹ãã§ã®ç®æšç¹æ° c_j ãå®ããŠããã ååå è
ããç®æšç¹æ°ä»¥äžã®åŸç¹ãç²åŸã§ãããå€å®ããã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã N a_{0} a_{1} a_{2} ⊠a_{Nâ1} M b_{0} b_{1} b_{2} ⊠b_{Mâ1} c_{0} c_{1} c_{2} ⊠c_{Mâ1} å¶çŽ å
¥åã¯ãã¹ãп޿°ã§ãã 1 \†N \†300\,000 1 \†M \†300\,000 0 \†a_{i} \†1\,000\,000 0 \†b_{i} \†1\,000\,000 0 \†c_{i} \†âa_k åºå çãã M è¡ã§åºåããã i è¡ç®ã«ã¯ãåå è
iâ1 ãç®æšç¹æ°ä»¥äžã®åŸç¹ãç²åŸã§ãããªã Yes ãã§ããªããªã No ãšåºåããã ãµã³ãã« ãµã³ãã«å
¥å1 6 1 2 1 3 4 5 7 1 3 4 5 3 1 0 2 4 5 3 4 5 3 ãµã³ãã«åºå1 Yes Yes Yes Yes Yes No No ååå è
ã®åŸãããåŸç¹ã¯ä»¥äžã®ããã«ãªãã åå è
0 : 1+1=2 åå è
1 : 1+2+1+3=7 åå è
2 : 1+2+1+3+4=11 åå è
3 : 1+2+1+3+4+5=16 åå è
4 : 1+2+1+3=7 åå è
5 : 1+1=2 åå è
6 : 0 ãµã³ãã«å
¥å2 8 1 1 2 3 3 4 6 100 4 1 3 4 99 1 10 15 120 ãµã³ãã«åºå2 Yes Yes No No
| 39,125
|
Problem B: Repeated Substitution with Sed Do you know "sed," a tool provided with Unix? Its most popular use is to substitute every occurrence of a string contained in the input string (actually each input line) with another string β . More precisely, it proceeds as follows. Within the input string, every non-overlapping (but possibly adjacent) occurrences of α are marked. If there is more than one possibility for non-overlapping matching, the leftmost one is chosen. Each of the marked occurrences is substituted with β to obtain the output string; other parts of the input string remain intact. For example, when α is " aa " and β is " bca ", an input string " aaxaaa " will produce " bcaxbcaa ", but not " aaxbcaa " nor " bcaxabca ". Further application of the same substitution to the string " bcaxbcaa " will result in " bcaxbcbca ", but this is another substitution, which is counted as the second one. In this problem, a set of substitution pairs ( α i , β i ) ( i = 1, 2, ... , n ), an initial string γ , and a final string ÎŽ are given, and you must investigate how to produce ÎŽ from γ with a minimum number of substitutions. A single substitution ( α i , β i ) here means simultaneously substituting all the non-overlapping occurrences of α i , in the sense described above, with β i . You may use a specific substitution ( α i , β i ) multiple times, including zero times. Input The input consists of multiple datasets, each in the following format. n α 1 β 1 α 2 β 2 . . . α n β n γ ÎŽ n is a positive integer indicating the number of pairs. α i and β i are separated by a single space. You may assume that 1 †| α i | < | β i | †10 for any i (| s | means the length of the string s ), α i â α j for any i â j , n †10 and 1 †| γ | < | ÎŽ | †10. All the strings consist solely of lowercase letters. The end of the input is indicated by a line containing a single zero. Output For each dataset, output the minimum number of substitutions to obtain ÎŽ from γ . If ÎŽ cannot be produced from γ with the given set of substitutions, output -1 . Sample Input 2 a bb b aa a bbbbbbbb 1 a aa a aaaaa 3 ab aab abc aadc ad dee abc deeeeeeeec 10 a abc b bai c acf d bed e abh f fag g abe h bag i aaj j bbb a abacfaabe 0 Output for the Sample Input 3 -1 7 4
| 39,126
|
Score : 200 points Problem Statement We have a string S consisting of uppercase English letters. Additionally, an integer N will be given. Shift each character of S by N in alphabetical order (see below), and print the resulting string. We assume that A follows Z . For example, shifting A by 2 results in C ( A \to B \to C ), and shifting Y by 3 results in B ( Y \to Z \to A \to B ). Constraints 0 \leq N \leq 26 1 \leq |S| \leq 10^4 S consists of uppercase English letters. Input Input is given from Standard Input in the following format: N S Output Print the string resulting from shifting each character of S by N in alphabetical order. Sample Input 1 2 ABCXYZ Sample Output 1 CDEZAB Note that A follows Z . Sample Input 2 0 ABCXYZ Sample Output 2 ABCXYZ Sample Input 3 13 ABCDEFGHIJKLMNOPQRSTUVWXYZ Sample Output 3 NOPQRSTUVWXYZABCDEFGHIJKLM
| 39,127
|
Problem E: The Number of the Real Roots of a Cubic Equation Description 3次æ¹çšåŒïŒ ãäžããããã®ã§ïŒãã®æ£ã®å®æ°æ ¹ã®åæ°ïŒè² ã®å®æ°æ ¹ã®åæ°ããããã調ã¹ãŠæ¬²ããïŒ æ ¹ã®åæ°ã¯ïŒéæ ¹ãå«ããŠæ°ãããã®ãšããïŒ Input å
¥åã¯è€æ°ã®ãã¹ãã±ãŒã¹ãããªãïŒ1è¡ç®ã«ã¯ãã®åæ°ãèšãããïŒ 2è¡ç®ä»¥é㯠a b c d ã®åœ¢åŒã§3次æ¹çšåŒã®ä¿æ°ãèšãããïŒ a ã¯0ã§ã¯ãªãïŒãŸãããããã®æ°ã¯-100ãã100ãŸã§ã®æŽæ°å€ã§ããïŒ Output äžãããã3次æ¹çšåŒã«å¯ŸãïŒæ£ã®å®æ°æ ¹ã®åæ°ïŒè² ã®å®æ°æ ¹ã®åæ°ãã¹ããŒã¹ã§åºåã£ãŠåºåããïŒ Sample Input 2 1 3 3 1 -10 0 0 0 Output for Sample Input 0 3 0 0
| 39,128
|
äœè²ïŒ ãŠã§ããã¶ã€ããŒãç®æã倪éåã¯ãã ããŸä¿®è¡äžãäºåæã®å
茩ããããã®ããŒãžã®èæ¯è²ã¯#ffe085ã§ããšããŠã§ããã¶ã€ã³ç¹æã®è²çªå·ã§æç€ºãããã®ã§ããããããã©ããªè²ããããšæãæµ®ãã¹ãããšãã§ããŸããã ãã®è²çªå·ã¯å
ã®äžåè²ã§ããèµ€ãç·ãéããããã®åŒ·ãã衚ãããŠããŸããå
·äœçã«ã¯2 æ¡ã® 16 鲿°ã3 ã€çµã¿åããããã®ã§ãè²çªå·ãâ#RGBâãšãããšããR ã¯èµ€ã®åŒ·ããG ã¯ç·ã®åŒ·ããã¯éã®åŒ·ãã衚ããŸãããããã 00 ãã ff ãŸã§ã®å€ã«ãªããŸãã è²çªå·ã«ãŸã äžæ
£ããªå€ªéåã®ããã«ãè²çªå·ãå
¥åãšããè²ã®è¡šã®äžãããã£ãšãè¿ãè²ã®åå ãåºåããããã°ã©ã ãäœæããŠãã ããã䜿çšããè²ã®è¡šã¯ä»¥äžã®éãã§ãã è²ã®åå èµ€ã®åŒ·ã ç·ã®åŒ·ã éã®åŒ·ã black 00 00 00 blue 00 00 ff lime 00 ff 00 aqua 00 ff ff red ff 00 00 fuchsia ff 00 ff yellow ff ff 00 white ff ff ff ããã£ãšãè¿ãè²ããšã¯ã以äžã®ããã«å®çŸ©ããŸããäžããããè²çªå·ã§ã®èµ€ãç·ãéã®åŒ·ãããããã R ã G ã B ãšãã衚㮠k çªç®ã®è²ã®èµ€ãç·ãéã®åŒ·ãããããã R k ã G k ã B k ãšãããšããæ¬¡ã®åŒã§èšç®ãã d k ã®å€ãæãå°ããè²ããã£ãšãè¿ãè²ãšããŸãã ãªãã d k ã®å€ãåãã«ãªãè²ãè€æ°ååšããå Žåã¯è¡šã®äžã§ããäžã«ããè²ããã£ãšãè¿ãè²ã«ãªã ãŸãã Input è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸããåããŒã¿ã»ãããšããŠãè²çªå·ã衚ãæååãã # RGB 圢åŒã§ïŒè¡ã«äžããããŸãã ããŒã¿ã»ããã®æ°ã¯ 1000 ãè¶
ããŸããã Output ããŒã¿ã»ããæ¯ã«æãè¿ãè²ã®ååãïŒè¡ã«åºåããŸãã Sample Input #ffe085 #787878 #decade #ff55ff 0 Output for the Sample Input white black white fuchsia
| 39,129
|
é»é£Ÿ(Illumination) JOI 髿 ¡ã®æåç¥ã§ã¯æ¯å¹Žå»äžã«é»é£Ÿã食ãããïŒé»é£Ÿã¯ N åã®é»çã§æ§æãããŠããïŒé»çã¯å»äžã®è¥¿åŽããæ±åŽã«äžåã«äžŠãã§ããïŒåé»çã¯æãããã€ããŠãããïŒã€ããŠããªããã®ããããã®ç¶æ
ã§ããïŒ JOI 髿 ¡ã®å庫ã«ã¯é»çãæäœããæ©æ¢°ãç ã£ãŠããïŒãã®æ©æ¢°ã¯é»é£Ÿå
ã§é£ç¶ããé»çãæå®ãããšïŒæå®ãããé»çã®ãã¡ïŒæãããã€ããŠããé»çå
šãŠãæãããã€ããŠããªãç¶æ
ã«ãïŒæãããã€ããŠããªãé»çå
šãŠãæãããã€ããŠããç¶æ
ã«ããïŒãã ãïŒæ©æ¢°ã¯èæœåã®ããïŒ1 åãã䜿çšã§ããªãïŒ JOI 髿 ¡ã®çåŸéã¯æãããã€ããŠããé»çãšã€ããŠããªãé»çã亀äºã«äžŠãã åïŒãã®ãããªé»çã®åã亀äºåãšåŒã¶ïŒã奜ãã§ããïŒããã§ïŒãã®æ©æ¢°ãå¿
èŠãªãã°1 åã ã䜿ã£ãŠïŒã§ããã ãé·ã亀äºåãå«ãé»é£Ÿãäœãããšã«ããïŒ äŸ äŸãã°ïŒé»é£Ÿã®é
眮ã西ããæ±ã«åãã£ãŠ ãšãªã£ãŠãããšããïŒâã¯æãããã€ããŠããé»çãïŒâã¯æãããã€ããŠããªãé»çã衚ãïŒïŒãã®ãšãïŒ4 çªç®ãã7 çªç®ãŸã§ã®4 åã®é»çã«å¯ŸããŠæ©æ¢°ãæäœãããšïŒ ãšãªãïŒ2 çªç®ãã8 çªç®ãŸã§ã®é»çãé·ã7 ã®äº€äºåããªãïŒ ãŸãïŒ8 çªç®ã®é»çã®ã¿ã«å¯ŸããŠæ©æ¢°ãæäœãããšïŒ ãšãªãïŒ4 çªç®ãã10 çªç®ãŸã§ã®é»çãé·ã7 ã®äº€äºåããªãïŒ æ©æ¢°ãæå€§1 å䜿çšããããšã§ïŒé·ãã8 以äžã®äº€äºåãäœãããšã¯ã§ããªãïŒ èª²é¡ é»é£Ÿã®æ
å ±ãäžãããããšãïŒæ©æ¢°ãæå€§1 å䜿çšããããšã§åŸãããé»çã®é
åã«å«ãŸãã亀äºåã®é·ããšããŠèãããããã®ã®æå€§å€ãæ±ããããã°ã©ã ãäœæããïŒ å¶é 2 †N †100 000 é»é£Ÿãæ§æããé»çã®åæ° å
¥å æšæºå
¥åãã以äžã®ããŒã¿ãèªã¿èŸŒãïŒ 1 è¡ç®ã«ã¯æŽæ° N ãæžãããŠããïŒ 2 è¡ç®ã«ã¯ N åã® 0 ãŸã㯠1 ã空çœãåºåããšããŠæžãããŠããïŒåæŽæ°ã¯æ©æ¢°ãæäœããåã«ãããé»çã®æ
å ±ã衚ããŠããïŒå·Šãã i ( 1 †i †N ) çªç®ã®æŽæ°ã¯è¥¿åŽãã i çªç®ã®é»çã®æ
å ±ã衚ããŠããïŒæŽæ°ã 1 ãªãã°é»çã®æãããã€ããŠããŠïŒ0 ãªãã°æãããã€ããŠããªãããšã衚ãïŒ åºå æšæºåºåã«ïŒäœæå¯èœãªé»çã®åã«å«ãŸãã亀äºåã®é·ãã®æå€§å€ãè¡šãæŽæ°ã1 è¡ã§åºåããïŒ å
¥åºåäŸ å
¥åäŸ 1 10 1 1 0 0 1 0 1 1 1 0 åºåäŸ 1 7 ããã¯å顿äžã§èª¬æãããäŸã§ããïŒ å
¥åäŸ 2 10 1 0 0 0 0 1 0 1 0 1 åºåäŸ 2 8 西åŽãã 4 çªç®ã®é»çã®ã¿ãæäœãããšïŒæå€§å€ 8 ãæºãã亀äºåãåŸãããïŒ å
¥åäŸ 3 5 1 1 0 1 1 åºåäŸ 3 5 西åŽããæ°ã㊠2 çªç®ãã 4 çªç®ãŸã§ã®é»çãæäœãããšïŒå
šãŠã®é»çãããªã亀äºåãäœãããšãã§ ããïŒ å
¥åäŸ 4 3 0 1 0 åºåäŸ 4 3 æ©æ¢°ã䜿çšããªããŠãè¯ãå Žåãããããšã«æ³šæããïŒ å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
| 39,130
|
ç å³ã®ããã«äºè¡ã«åãããŠãã容åšããããŸãã1 ãã 10 ãŸã§ã®çªå·ãä»ãããã10 åã®çã容åšã®éå£éš A ããèœãšããå·Šã®ç B ãå³ã®ç C ã«çãå
¥ããŸããæ¿ D ã¯æ¯ç¹ E ãäžå¿ã«å·Šå³ã«å転ã§ããã®ã§ãæ¿ D ãåããããšã§ç B ãšç C ã®ã©ã¡ãã«å
¥ãããæ±ºããããšãã§ããŸãã éå£éš A ããèœãšãçã®äžŠã³ãäžããŸããããããé çªã«ç B åã¯ç Cã«å
¥ããŠãããŸãããã®ãšããç B ãšç C ã®ãã®ãã®ãäž¡æ¹ãšãçªå·ã®å°ããçã®äžã«å€§ããçã䞊ã¹ãããå Žå㯠YESã䞊ã¹ãããªãå Žå㯠NO ãšåºåããããã°ã©ã ãäœæããŠãã ããããã ãã容åšã®äžã§çã®é åºãå
¥ãæ¿ããããšã¯ã§ããªããã®ãšããŸãããŸããç¶ããŠåãçã«å
¥ããããšãã§ãããã®ãšããç B, C ãšãã« 10 åã®çããã¹ãŠå
¥ãã ãã®äœè£ããããã®ãšããŸãã Input è€æ°ã®ããŒã¿ã»ãããäžããããŸããïŒè¡ç®ã«ããŒã¿ã»ããæ° N ãäžããããŸããã€ã¥ããŠã N è¡ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã« 10 åã®çªå·ãå·Šããé çªã«ç©ºçœåºåãã§äžããããŸãã Output åããŒã¿ã»ããã«å¯ŸããŠã YES ãŸã㯠NO ãïŒè¡ã«åºåããŠäžããã Sample Input 2 3 1 4 2 5 6 7 8 9 10 10 9 8 7 6 5 4 3 2 1 Output for the Sample Input YES NO
| 39,131
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.