task
stringlengths 0
154k
| __index_level_0__
int64 0
39.2k
|
|---|---|
Score : 300 points Problem Statement We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N) ). There are N! possible permutations of size N . Among them, let P and Q be the a -th and b -th lexicographically smallest permutations, respectively. Find |a - b| . Notes For two sequences X and Y , X is said to be lexicographically smaller than Y if and only if there exists an integer k such that X_i = Y_i~(1 \leq i < k) and X_k < Y_k . Constraints 2 \leq N \leq 8 P and Q are permutations of size N . Input Input is given from Standard Input in the following format: N P_1 P_2 ... P_N Q_1 Q_2 ... Q_N Output Print |a - b| . Sample Input 1 3 1 3 2 3 1 2 Sample Output 1 3 There are 6 permutations of size 3 : (1,~2,~3) , (1,~3,~2) , (2,~1,~3) , (2,~3,~1) , (3,~1,~2) , and (3,~2,~1) . Among them, (1,~3,~2) and (3,~1,~2) come 2 -nd and 5 -th in lexicographical order, so the answer is |2 - 5| = 3 . Sample Input 2 8 7 3 5 4 2 1 6 8 3 8 2 5 4 6 7 1 Sample Output 2 17517 Sample Input 3 3 1 2 3 1 2 3 Sample Output 3 0
| 38,816
|
å£ããæå·çæåš JAG (Japanese Alumni Group) ã¯å€ãã®ããã°ã©ãã§æ§æãããè¬ã®çµç¹ã§ããïŒãã®çµç¹ã®æ¬éšããã建ç©ã«å
¥ãããã«ã¯æ¯åããæ©æ¢°ã«ãã£ãŠçæãããæå·æãè§£ããªããŠã¯ãªããªãïŒ ãã®æå·æã¯ïŒ' + 'ïŒ' - 'ïŒ' [ 'ïŒ' ] ' ã®èšå·ãšå€§æåã®ã¢ã«ãã¡ããããããªã£ãŠããïŒä»¥äžã® BNF ã§å®çŸ©ããã <Cipher> ã«ãã£ãŠè¡šãããïŒ <Cipher> ::= <String> | <Cipher><String> <String> ::= <Letter> | '['<Cipher>']' <Letter> ::= '+'<Letter> | '-'<Letter> | 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z' ããã§ããããã®èšå·ã¯ä»¥äžã®ãããªæå³ã衚ãïŒ +(æå) : ãã®æåã®æ¬¡ã®ã¢ã«ãã¡ãããã衚ã (ãã ã ' Z ' ã®æ¬¡ã®ã¢ã«ãã¡ããã㯠' A ' ã§ãããšãã) -(æå) : ãã®æåã®åã®ã¢ã«ãã¡ãããã衚ã (ãã ã ' A ' ã®åã®ã¢ã«ãã¡ããã㯠' Z ' ã§ãããšãã) [(æåå)] : ãã®æååãå·Šå³å転ããæååã衚ã ããããã®æå·æãçæããæ©æ¢°ã«ã¯çŸåšæ
éãçºçããŠããïŒæå·æã®ãã¡ã¢ã«ãã¡ãããã®ç®æãæ°æåå£ããŠèªããªããªã£ãŠããå ŽåãããïŒèªããªãæåã¯ä»®ã« ' ? ' ãšè¡šãããŠããïŒ èª¿æ»ã®çµæïŒå£ããæåã®åãæ¹ã¯ïŒåŸ©å·åŸã®æååãïŒåŸ©å·åŸã®æååãšããŠããããæååã®äžã§èŸæžé æå°ã«ãªããããªãã®ã§ããããšãããã£ãïŒ ããªãã®ä»äºã¯ãã®æå·æãæ£ãã埩å·ããããšã§ããïŒ Input å
¥åã¯è€æ°ã®ããŒã¿ã»ããããæ§æãããïŒ åããŒã¿ã»ããã¯ïŒäžèšã® BNF ã§å®çŸ©ãããæå·æã«ãããŠïŒäžéšã®å€§æåã®ã¢ã«ãã¡ãããã â?â ã«çœ®ãæããããæååãå«ã 1 è¡ãããªãïŒ åæååã®é·ã㯠$80$ 以äžã§ãããšä»®å®ããŠããïŒ ãŸãåããŒã¿ã»ããã«å«ãŸãã ' ? ' ã®æ°ã¯ $0$ ä»¥äž $3$ 以äžã§ãããšä»®å®ããŠããïŒ å
¥åã®çµäºã¯ ' . ' ã®1æåã ããå«ãè¡ã§è¡šãããïŒ Output åããŒã¿ã»ããã«å¯ŸããŠïŒåŸ©å·åŸã®æååãèŸæžé æå°ã«ãªãããã«æå·æã埩å·ãããšãã®ïŒåŸ©å·åŸã®æååãåºåããïŒ Sample Input A+A++A Z-Z--Z+-Z [ESREVER] J---?---J ++++++++A+++Z-----------A+++Z [[++-+--?[--++-?++-+++L]][-+-----+-O]]++++---+L . Output for Sample Input ABC ZYXZ REVERSE JAG ICPC JAPAN
| 38,817
|
Halting Problem A unique law is enforced in the Republic of Finite Loop. Under the law, programs that never halt are regarded as viruses. Releasing such a program is a cybercrime. So, you want to make sure that your software products always halt under their normal use. It is widely known that there exists no algorithm that can determine whether an arbitrary given program halts or not for a given arbitrary input. Fortunately, your products are based on a simple computation model given below. So, you can write a program that can tell whether a given program based on the model will eventually halt for a given input. The computation model for the products has only one variable $x$ and $N + 1$ states, numbered $1$ through $N + 1$. The variable $x$ can store any integer value. The state $N + 1$ means that the program has terminated. For each integer $i$ ($1 \leq i \leq N$), the behavior of the program in the state $i$ is described by five integers $a_i$, $b_i$, $c_i$, $d_i$ and $e_i$ ($c_i$ and $e_i$ are indices of states). On start of a program, its state is initialized to $1$, and the value of $x$ is initialized by $x_0$, the input to the program. When the program is in the state $i$ ($1 \leq i \leq N$), either of the following takes place in one execution step: if $x$ is equal to $a_i$, the value of $x$ changes to $x + b_i$ and the program state becomes $c_i$; otherwise, the value of $x$ changes to $x + d_i$ and the program state becomes $e_i$. The program terminates when the program state becomes $N + 1$. Your task is to write a program to determine whether a given program eventually halts or not for a given input, and, if it halts, to compute how many steps are executed. The initialization is not counted as a step. Input The input consists of a single test case of the following format. $N$ $x_0$ $a_1$ $b_1$ $c_1$ $d_1$ $e_1$ . . . $a_N$ $b_N$ $c_N$ $d_N$ $e_N$ The first line contains two integers $N$ ($1 \leq N \leq 10^5$) and $x_0$ ($â10^{13} \leq x_0 \leq 10^{13}$). The number of the states of the program is $N + 1$. $x_0$ is the initial value of the variable $x$. Each of the next $N$ lines contains five integers $a_i$, $b_i$, $c_i$, $d_i$ and $e_i$ that determine the behavior of the program when it is in the state $i$. $a_i$, $b_i$ and $d_i$ are integers between $â10^{13}$ and $10^{13}$, inclusive. $c_i$ and $e_i$ are integers between $1$ and $N + 1$, inclusive. Output If the given program eventually halts with the given input, output a single integer in a line which is the number of steps executed until the program terminates. Since the number may be very large, output the number modulo $10^9 + 7$. Output $-1$ if the program will never halt. Sample Input 1 2 0 5 1 2 1 1 10 1 3 2 2 Sample Output 1 9 Sample Input 2 3 1 0 1 4 2 3 1 0 1 1 3 3 -2 2 1 4 Sample Output 2 -1 Sample Input 3 3 3 1 -1 2 2 2 1 1 1 -1 3 1 1 4 -2 1 Sample Output 3 -1
| 38,818
|
Score : 100 points Problem Statement Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a , b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either directly or indirectly. Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate. Constraints 1 †a,b,c †100 1 †d †100 All values in input are integers. Input Input is given from Standard Input in the following format: a b c d Output If A and C can communicate, print Yes ; if they cannot, print No . Sample Input 1 4 7 9 3 Sample Output 1 Yes A and B can directly communicate, and also B and C can directly communicate, so we should print Yes . Sample Input 2 100 10 1 2 Sample Output 2 No They cannot communicate in this case. Sample Input 3 10 10 10 1 Sample Output 3 Yes There can be multiple people at the same position. Sample Input 4 1 100 2 10 Sample Output 4 Yes
| 38,819
|
Problem M: Settler Problem äºæ¬¡å
å¹³é¢äžã« N åã®ç©ºãå°ãããã空ãå°ã«ã¯ãããã1ãã N ãŸã§ã®çªå·ãå²ãæ¯ãããŠãããã©ã®ç©ºãå°ããšãŠãå°ããã®ã§ãç¹ãšã¿ãªãããšãã§ããã i çªç®ã®ç©ºãå°ã¯( x i , y i )ã«ååšããŠããã 倪éåã¯ãã® N åã®ç©ºãå°ã®äžããã¡ããã© K åãéžã³ããããã®ç©ºãå°ã«å»ºç©ã建ãŠãããšã«ããã ããããããŸãã«ãè¿ãå Žæã«è€æ°ã®å»ºç©ã建ãŠãŠãé¢çœããªããšæã£ãã®ã§ã倪éåã¯ããããã®ç©ºãå°ã©ããã®ãŠãŒã¯ãªããè·é¢ãå¿
ã2以äžãšãªãããã«ç©ºãå°ãéžã¶ããšã«ããã 倪éåãéžã¶ç©ºãå°ã®çµã¿åãããšããŠèãããããã®ãåºåããããã°ã©ã ãäœæããã çµã¿åãããè€æ°ååšããå Žåã¯ãèŸæžé ã§æå°ã®ãã®ãåºåããã ãã ããã©ã®ããã« K åã®ç©ºãå°ãéžãã ãšããŠãããããã2ã€ã®ç©ºãå°ã®ãŠãŒã¯ãªããè·é¢ã2ããå°ãããªã£ãŠããŸãå Žåã¯ããããã«-1ãåºåããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã N K x 1 y 1 x 2 y 2 ... x N y N Constraints å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã å
¥åã¯å
šãп޿°ã§ããã 2 †K †N †6,000 1 †x i , y i †1,000,000 ( 1 †i †N ) x i mod 2 = floor ( y i ÷ 2 ) mod 2 ( 1 †i †N ) (ããã§ floor ( y i ÷ 2 ) ãšã¯ y i ã2ã§å²ãå°æ°ç¹ä»¥äžãåãæšãŠãå€ã§ãã) åã座æšã«è€æ°ã®ç©ºãå°ãååšããããšã¯ãªãã Output 倪éåãéžã¶ç©ºãå°ã®çªå·ãæé ã«1è¡ãã€åºåããã Sample Input 1 3 2 2 1 1 2 1 3 Sample Output 1 1 3 Sample Input 2 4 3 2 1 1 2 1 3 2 4 Sample Output 2 -1 Sample Input 3 5 3 5 7 5 6 6 8 20 20 4 8 Sample Output 3 2 3 4
| 38,820
|
æªçè
ã®æ°åŒ å士 : ããŒã¿ãŒåãã€ãã«ãã£ããã ããŒã¿ãŒ : ãŸãã§ãããä»åºŠã¯ã©ããªãã ããªãçºæã§ããã å士 : ã€ãã«æ°åŒãèšç®æ©ã§åŠçããç»æçãªæ¹æ³ãæãã€ãããã ããã®è¡šãã¿ãŠãããã éåžžã®èšæ³ å士ã®ãç»æçãªãèšæ³ 1 + 2 1 2 + 3 * 4 + 7 3 4 * 7 + 10 / ( 2 - 12 ) 10 2 12 - / ( 3 - 4 ) * ( 7 + 2 * 3 ) 3 4 - 7 2 3 * + * ããŒã¿ãŒ : ã¯ãã å士 : ãµã£ãµã£ãµãããã ãã§ã¯ãæªçè
ã®åã«ã¯äœã®ããšã ãããããªãã ããããããããããèå¿ãªãããã ããŒã¿ãŒ : ã£ãŠãããã»ã»ã»ã å士 : èšç®æ©ã«ã¯ã¹ã¿ãã¯ãšããããŒã¿æ§é ãããããšã¯åãç¥ã£ãŠããããã»ãããå
å
¥ãåŸåºããã®ãããããã ããŒã¿ãŒ : ã¯ããç¥ã£ãŠãŸããããã®ã»ã»ã»ã å士 : ãã®ç»æçãªèšæ³ã¯ãã®ã¹ã¿ãã¯ã䜿ãããããäŸãã°ãã® 10 2 12 - / ã ããæ¬¡ã®ããã«åŠçããã åŠç察象 10 2 12 - / â â â â2-12 â10/-10 ã¹ã¿ã㯠. . 10 . 2 10 12 2 10 . -10 10 . . -1 å士 : ã©ããããªãæ¬åŒ§ãæŒç®åã®åªå
é äœãæ°ã«ããå¿
èŠããªãããããïŒèªé ãã10 ã 2 ãã 12 ãåŒãããã®ã§å²ããããšãªããäœãšãªãåœŒã®æ¥µæ±ã®å³¶åœã®èšèãæ¥æ¬èªãšäŒŒãŠãããããããŠã ãã®ç»æçãªçºæããããã°ãæãç 究宀ã¯å®æ³°ãããŠããã¡ãã¡ãã¡ã ããŒã¿ãŒ : ã£ãŠãããå士ãããã£ãŠæ¥æ¬ã«ãããšãäŒæŽ¥å€§åŠã®åºç€ã³ãŒã¹ã§ç¿ããŸãããããéããŒã©ã³ãèšæ³ããšããã£ãŠãã¿ããªç°¡åã«ããã°ã©ã ããŠãŸããã å士 : ã»ã»ã»ã ãšããããšã§ãããŒã¿ãŒåã«å€ãã£ãŠå士ã«ããã®ããã°ã©ã ãæããäºã«ãªããŸããããéããŒã©ã³ãèšæ³ãã§æžãããæ°åŒãå
¥åãšããèšç®çµæãåºåããããã°ã©ã ãäœæããŠãã ããã å
¥å è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã§ã¯ãéããŒã©ã³ãèšæ³ã«ããæ°åŒïŒæŽæ°ãšæŒç®èšå·ãç©ºçœæåïŒæåïŒåè§ïŒã§åºåããã80æå以å
ã®æååïŒã ïŒ è¡ã«äžããããŸãã ããå€ã 0 ã 0 ã«éããªãè¿ãå€ã§å²ããããªæ°åŒã¯äžããããŸããã ããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã åºå åããŒã¿ã»ããããšã«ãèšç®çµæïŒå®æ°ïŒãïŒè¡ã«åºåããŠãã ããããªããèšç®çµæã¯ 0.00001 以äžã®èª€å·®ãå«ãã§ãããã Sample Input 10 2 12 - / 3 4 - 7 2 3 * + * -1 -2 3 + + Output for the Sample Input -1.000000 -13.000000 0.000000
| 38,821
|
Score : 300 points Problem Statement There are N cities on a 2D plane. The coordinate of the i -th city is (x_i, y_i) . Here (x_1, x_2, \dots, x_N) and (y_1, y_2, \dots, y_N) are both permuations of (1, 2, \dots, N) . For each k = 1,2,\dots,N , find the answer to the following question: Rng is in City k . Rng can perform the following move arbitrarily many times: move to another city that has a smaller x -coordinate and a smaller y -coordinate, or a larger x -coordinate and a larger y -coordinate, than the city he is currently in. How many cities (including City k ) are reachable from City k ? Constraints 1 \leq N \leq 200,000 (x_1, x_2, \dots, x_N) is a permutation of (1, 2, \dots, N) . (y_1, y_2, \dots, y_N) is a permutation of (1, 2, \dots, N) . All values in input are integers. Input Input is given from Standard Input in the following format: N x_1 y_1 x_2 y_2 : x_N y_N Output Print N lines. In i -th line print the answer to the question when k = i . Sample Input 1 4 1 4 2 3 3 1 4 2 Sample Output 1 1 1 2 2 Rng can reach City 4 from City 3 , or conversely City 3 from City 4 . Sample Input 2 7 6 4 4 3 3 5 7 1 2 7 5 2 1 6 Sample Output 2 3 3 1 1 2 3 2
| 38,822
|
D: Two Colors Sort åé¡ umg åã¯æ£æ©äžã« 1,2, ... ,N ã䞊ã³å€ããŠã§ããé·ã N ã®æ°å P_1, P_2, ..., P_N ãèŠã€ããŸããã umg åã¯äžæè°ãªåã䜿ãããšã§ãåãè²ã«å¡ãããç°ãªãæ°ãäºã€éžãã§å Žæã亀æããããšãã§ããŸãã umg åã¯ãæ°åã«å«ãŸããæ°ã®ãã¡ R åãèµ€ã«ãæ®ãã® N-R åãéã«å¡ãããšã§æ°åãæé ã«äžŠã³æ¿ããããããã«ããããšèããŸããã umg åãç®æšãéæã§ãããã©ããå€å®ããŠãã ããã ãã ããæ°åã¯ãšãŠãéãã®ã§äžæè°ãªåã䜿ããã«åããããšã¯ã§ããŸããããŸããumg åã¯å€©æãªã®ã§äžæè°ãªåãä»»æã®åæ°äœ¿ãããšãã§ããŸãã å
¥ååœ¢åŒ N R P_1 P_2 ... P_N å¶çŽ 1 \leq N \leq 3 \times 10^5 1 \leq R \leq N 1\leq P_i \leq N P_i \neq P_j ( 1 \leq i < j \leq N ) å
¥åã¯å
šãп޿°ã§ããã åºååœ¢åŒ umg åãç®çãéæã§ãããªã Yes ãããã§ãªããã° No ãäžè¡ã«åºåããã å
¥åäŸ 1 3 2 1 3 2 åºåäŸ 1 Yes 1 ãéã«ã 2,3 ãèµ€ã«å¡ãããšã§ç®æšãéæã§ããŸãã å
¥åäŸ 2 5 2 1 2 3 4 5 åºåäŸ 2 Yes åãããæé ã«äžŠãã§ããŸãã å
¥åäŸ 3 10 7 3 4 8 5 7 6 2 10 1 9 åºåäŸ 3 No
| 38,823
|
茪ãŽã n æ¬ã®éãå¹³æ¿äžã®åº§æš P 1 ( x 1 , y 1 ), P 2 ( x 2 , y 2 ), P 3 ( x 3 , y 3 ),..., P n ( x n , y n ) ã«ïŒæ¬ãã€æã¡ã茪ãŽã ã®èŒªã®äžã«å
šãŠã®éãå
¥ãããã« 1 æ¬ã®èŒªãŽã ã§å²ã¿ãŸãããã®ãšãã茪ãŽã ã亀差ããŠã¯ãããŸããã éã®åº§æšãèªã¿èŸŒãã§ãäžèšã®ããã«éã茪ãŽã ã§å²ãã ãšãã«èŒªãŽã ã«æ¥ããŠããªãéã®æ¬æ°ãåºåããããã°ã©ã ãäœæããŠãã ããã茪ãŽã ã¯å
åã«äŒžã³çž®ã¿ãããã®ãšããŸããåã座æšã« 2 æ¬ä»¥äžã®éãæã€ããšã¯ãªããã®ãšããŸãããŸãã茪ãŽã ãããã£ãéãšéã®éã¯çŽç·ã§çµã°ãããã®ãšãããã®çŽç·äžã« 3 æ¬ä»¥äžã®éã䞊ã¶ããšã¯ãªããã®ãšããŸããäŸãã°ãå³ 1 ã«ç€ºããããªå
¥åã¯ããããŸãããå³ 2 ã«ç€ºãããã«èŒªãŽã ãããã£ãŠããªãéã 1 çŽç·äžã«äžŠã¶ããšã¯ããããŸãã å³ïŒ å³ïŒ ãã ããããããã®åº§æšå€ã¯ -1000.0 以äž1000.0 以äžã®å®æ°ã§ãããŸãã n 㯠3 ä»¥äž 100 以äžã®æŽæ°ã§ãã Input è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã¯ä»¥äžã®ãããªåœ¢åŒã§ãäžããããŸãã n x 1 , y 1 x 2 , y 2 ... ... x n , y n n ã 0 ã®æãå
¥åã®æåŸã瀺ããŸããããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã Output ããŒã¿ã»ããããšã«ããŽã ãšæ¥ããŠããªãéã®æ¬æ°ãåºåããŠãã ããã äŸãã°ãå³ 3 ã«ç€ºãïŒã€ã®éã衚ãå
¥åããã£ãå Žåãå³ 4 ã®ããã«å²ãŸããã®ã§ã茪ãŽã ã«æ¥ããŠããªãéã®æ¬æ°ã¯ 1 æ¬ã§ãã å³ïŒ å³ïŒ Sample Input 4 1.0,0.0 0.0,1.0 2.0,1.0 1.0,2.0 9 -509.94,892.63 567.62,639.99 -859.32,-64.84 -445.99,383.69 667.54,430.49 551.12,828.21 -940.2,-877.2 -361.62,-970 -125.42,-178.48 0 Output for the Sample Input 0 3 Hint 以äžã¯ïŒã€ãã®ãµã³ãã«å
¥åã«å¯Ÿããå³ã§ãã
| 38,824
|
Boring Commercial Now it is spring holidays. A lazy student has finally passed all final examination, and he decided to just kick back and just watch TV all day. Oh, his only source of entertainment is watching TV. And TV commercial, as usual, are a big nuisance for him. He can watch any thing on television, but cannot bear even a single second of commercial. So to prevent himself from the boredom of seeing the boring commercial, he keeps shuffling through the TV channels, so that he can watch programs on different channels without seeing even a single commercial. Given the number of channels, and the duration at which the TV commercials are showed on each of the channels, you have to write a program which will print the longest interval for which the lazy student can watch the television by shuffling between the different channels without ever seeing an TV commercial. For example, consider the simplified situation where there are only three television channels, and suppose that he is watching TV from 2100 hrs to 2400 hrs. Suppose that the commercials are displayed at following time on each of the channels. Channel 1: 2100 to 2130, 2200 to 2230 and 2300 to 2330 Channel 2: 2130 to 2200, 2330 to 2400 Channel 3: 2100 to 2130, 2330 to 2400 Then in this case, he can watch TV without getting interrupted by commercials for full 3 hours by watching Channel 2 from 2100 to 2130, then Channel 3 from 2130 to 2330, and then Channel 1 from 2330 to 2400. Input The input will consist of several cases. In each case, the first line of the input will be n, the number of channels, which will then be followed by p and q, the time interval between which he will be watching the TV. It will be followed by 2n lines, giving the time slots for each of the channels. For each channel, the first line will be k, the number of commercial slots, and it will then be followed by 2k numbers giving the commercial slots in order. The input will be terminated by values 0 for each of n, p, q. This case should not be processed. Output For each case, you have to output the maximum duration (in minutes) for which he can watch television without seeing any commercial. Sample Input 1 2100 2400 1 2130 2200 3 2100 2400 3 2100 2130 2200 2230 2300 2330 2 2130 2200 2330 2400 2 2100 2130 2330 2400 0 0 0 Output for the Sample Input 120 180
| 38,825
|
Print a Chessboard Draw a chessboard which has a height of H cm and a width of W cm. For example, the following figure shows a chessboard which has a height of 6 cm and a width of 10 cm. #.#.#.#.#. .#.#.#.#.# #.#.#.#.#. .#.#.#.#.# #.#.#.#.#. .#.#.#.#.# Note that the top left corner should be drawn by '#'. Input The input consists of multiple datasets. Each dataset consists of two integers H and W separated by a single space. The input ends with two 0 (when both H and W are zero). Output For each dataset, print the chessboard made of '#' and '.'. Print a blank line after each dataset. Constraints 1 †H †300 1 †W †300 Sample Input 3 4 5 6 3 3 2 2 1 1 0 0 Sample Output #.#. .#.# #.#. #.#.#. .#.#.# #.#.#. .#.#.# #.#.#. #.# .#. #.# #. .# #
| 38,826
|
éåŠçµè·¯ åé¡ å€ªéåã®äœãã§ããJOIåžã¯ïŒååæ¹åã«ãŸã£ããã«äŒžã³ã a æ¬ã®éè·¯ãšïŒæ±è¥¿æ¹åã«ãŸã£ããã«äŒžã³ã b æ¬ã®éè·¯ã«ããïŒç¢ç€ã®ç®ã®åœ¢ã«åºåããããŠããïŒ ååæ¹åã® a æ¬ã®éè·¯ã«ã¯ïŒè¥¿ããé ã« 1, 2, ... , a ã®çªå·ãä»ããããŠããïŒãŸãïŒæ±è¥¿æ¹åã® b æ¬ã®éè·¯ã«ã¯ïŒåããé ã« 1, 2, ... , b ã®çªå·ãä»ããããŠããïŒè¥¿ãã i çªç®ã®ååæ¹åã®éè·¯ãšïŒåãã j çªç®ã®æ±è¥¿æ¹åã®éè·¯ã亀ãã亀差ç¹ã (i, j) ã§è¡šãïŒ å€ªéåã¯ïŒäº€å·®ç¹ (1, 1) ã®è¿ãã«äœãã§ããïŒäº€å·®ç¹ (a, b) ã®è¿ãã®JOI髿 ¡ã«èªè»¢è»ã§éã£ãŠããïŒèªè»¢è»ã¯éè·¯ã«æ²¿ã£ãŠã®ã¿ç§»åããããšãã§ããïŒå€ªéåã¯ïŒéåŠæéãçãããããïŒæ±ãŸãã¯åã«ã®ã¿åãã£ãŠç§»åããŠéåŠããŠããïŒ çŸåšïŒ JOIåžã§ã¯ïŒ n åã®äº€å·®ç¹ (x 1 , y 1 ), (x 2 , y 2 ), ... , (x n , y n ) ã§å·¥äºãè¡ã£ãŠããïŒå€ªéåã¯å·¥äºäžã®äº€å·®ç¹ãéãããšãã§ããªãïŒ å€ªéåãäº€å·®ç¹ (1, 1) ããäº€å·®ç¹ (a, b) ãŸã§ïŒå·¥äºäžã®äº€å·®ç¹ãé¿ããªããïŒæ±ãŸãã¯åã«ã®ã¿åãã£ãŠç§»åããŠéåŠããæ¹æ³ã¯äœéãããã ãããïŒå€ªéåã®éåŠçµè·¯ã®åæ° m ãæ±ããããã°ã©ã ãäœæããïŒ å
¥å å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããïŒå
¥åã¯ãŒããïŒã€å«ãè¡ã§çµäºããïŒ 1è¡ç®ã«ã¯ïŒç©ºçœãåºåããšããŠ2åã®æŽæ° a, b ãæžãããŠããïŒããã¯ïŒååæ¹åã®éè·¯ã®æ¬æ°ãšïŒæ±è¥¿æ¹åã®éè·¯ã®æ¬æ°ã衚ãïŒ a, b 㯠1 †a, b †16 ãã¿ããïŒ 2è¡ç®ã«ã¯, å·¥äºäžã®äº€å·®ç¹ã®åæ°ãè¡šãæŽæ° n ãæžãããŠããïŒ n 㯠1 †n †40 ãã¿ããïŒ ç¶ã n è¡ (3è¡ç®ãã n+2 è¡ç®) ã«ã¯ïŒå·¥äºäžã®äº€å·®ç¹ã®äœçœ®ãæžãããŠããïŒ i+2 è¡ç®ã«ã¯ç©ºçœã§åºåãããæŽæ° x i , y i ãæžãããŠããïŒäº€å·®ç¹ (x i , y i ) ãå·¥äºäžã§ããããšã衚ãïŒ x i , y i 㯠1 †x i , y i †16 ãã¿ããïŒ ããŒã¿ã»ããã®æ°ã¯ 5 ãè¶
ããªãïŒ åºå ããŒã¿ã»ããããšã«, 倪éåã®éåŠçµè·¯ã®åæ° m ã1è¡ã«åºåããïŒ å
¥åºåäŸ å
¥åäŸ 5 4 3 2 2 2 3 4 2 5 4 3 2 2 2 3 4 2 0 0 åºåäŸ 5 5 äžå³ã¯ a=5, b=4, n=3 ã§ïŒå·¥äºäžã®äº€å·®ç¹ã (2,2), (2,3), (4,2) ã®å Žåã衚ããŠããïŒ ãã®å ŽåïŒéåŠçµè·¯ã¯ m=5 éãããïŒ 5éãã®éåŠçµè·¯ãå
šãŠå³ç€ºãããšïŒä»¥äžã®éãïŒ äžèšå顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
| 38,827
|
Problem Statement You are now participating in the Summer Training Camp for Programming Contests with your friend Jiro, who is an enthusiast of the ramen chain SIRO. Since every SIRO restaurant has its own tasteful ramen, he wants to try them at as many different restaurants as possible in the night. He doesn't have plenty of time tonight, however, because he has to get up early in the morning tomorrow to join a training session. So he asked you to find the maximum number of different restaurants to which he would be able to go to eat ramen in the limited time. There are $n$ railway stations in the city, which are numbered $1$ through $n$. The station $s$ is the nearest to the camp venue. $m$ pairs of stations are directly connected by the railway: you can move between the stations $a_i$ and $b_i$ in $c_i$ minutes in the both directions. Among the stations, there are $l$ stations where a SIRO restaurant is located nearby. There is at most one SIRO restaurant around each of the stations, and there are no restaurants near the station $s$. It takes $e_i$ minutes for Jiro to eat ramen at the restaurant near the station $j_i$. It takes only a negligibly short time to go back and forth between a station and its nearby SIRO restaurant. You can also assume that Jiro doesn't have to wait for the ramen to be served in the restaurants. Jiro is now at the station $s$ and have to come back to the station in $t$ minutes. How many different SIRO's can he taste? Input The input is a sequence of datasets. The number of the datasets does not exceed $100$. Each dataset is formatted as follows: $n$ $m$ $l$ $s$ $t$ $a_1$ $b_1$ $c_1$ : : $a_m$ $b_m$ $c_m$ $j_1$ $e_1$ : : $j_l$ $e_l$ The first line of each dataset contains five integers: $n$ for the number of stations, $m$ for the number of directly connected pairs of stations, $l$ for the number of SIRO restaurants, $s$ for the starting-point station, and $t$ for the time limit for Jiro. Each of the following $m$ lines contains three integers: $a_i$ and $b_i$ for the connected stations, and $c_i$ for the time it takes to move between the two stations. Each of the following $l$ lines contains two integers: $j_i$ for the station where a SIRO restaurant is located, and $e_i$ for the time it takes for Jiro to eat at the restaurant. The end of the input is indicated by a line with five zeros, which is not included in the datasets. The datasets satisfy the following constraints: $2 \le n \le 300$ $1 \le m \le 5{,}000$ $1 \le l \le 16$ $1 \le s \le n$ $1 \le t \le 100{,}000$ $1 \le a_i, b_i \le n$ $1 \le c_i \le 1{,}000$ $1 \le j_i \le n$ $1 \le e_i \le 15$ $s \ne j_i$ $j_i$'s are distinct. $a_i \ne b_i$ $(a_i, b_i) \ne (a_j, b_j)$ and $(a_i, b_i) \ne (b_j, a_j)$ for any $i \ne j$ Note that there may be some stations not reachable from the starting point $s$. Output For each data set, output the maximum number of different restaurants where Jiro can go within the time limit. Sample Input 2 1 1 1 10 1 2 3 2 4 2 1 1 1 9 1 2 3 2 4 4 2 2 4 50 1 2 5 3 4 5 2 15 3 15 4 6 3 1 29 1 2 20 3 2 10 4 1 5 3 1 5 2 4 3 3 4 4 2 1 4 5 3 3 0 0 0 0 0 Output for the Sample Input 1 0 1 3
| 38,828
|
Score : 200 points Problem Statement Takahashi loves numbers divisible by 2 . You are given a positive integer N . Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2 , is how many times the integer can be divided by 2 without remainder. For example, 6 can be divided by 2 once: 6 -> 3 . 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1 . 3 can be divided by 2 zero times. Constraints 1 †N †100 Input Input is given from Standard Input in the following format: N Output Print the answer. Sample Input 1 7 Sample Output 1 4 4 can be divided by 2 twice, which is the most number of times among 1 , 2 , ..., 7 . Sample Input 2 32 Sample Output 2 32 Sample Input 3 1 Sample Output 3 1 Sample Input 4 100 Sample Output 4 64
| 38,829
|
Score : 600 points Problem Statement We have a set S of N points in a two-dimensional plane. The coordinates of the i -th point are (x_i, y_i) . The N points have distinct x -coordinates and distinct y -coordinates. For a non-empty subset T of S , let f(T) be the number of points contained in the smallest rectangle, whose sides are parallel to the coordinate axes, that contains all the points in T . More formally, we define f(T) as follows: f(T) := (the number of integers i (1 \leq i \leq N) such that a \leq x_i \leq b and c \leq y_i \leq d , where a , b , c , and d are the minimum x -coordinate, the maximum x -coordinate, the minimum y -coordinate, and the maximum y -coordinate of the points in T ) Find the sum of f(T) over all non-empty subset T of S . Since it can be enormous, print the sum modulo 998244353 . Constraints 1 \leq N \leq 2 \times 10^5 -10^9 \leq x_i, y_i \leq 10^9 x_i \neq x_j (i \neq j) y_i \neq y_j (i \neq j) All values in input are integers. Input Input is given from Standard Input in the following format: N x_1 y_1 : x_N y_N Output Print the sum of f(T) over all non-empty subset T of S , modulo 998244353 . Sample Input 1 3 -1 3 2 1 3 -2 Sample Output 1 13 Let the first, second, and third points be P_1 , P_2 , and P_3 , respectively. S = \{P_1, P_2, P_3\} has seven non-empty subsets, and f has the following values for each of them: f(\{P_1\}) = 1 f(\{P_2\}) = 1 f(\{P_3\}) = 1 f(\{P_1, P_2\}) = 2 f(\{P_2, P_3\}) = 2 f(\{P_3, P_1\}) = 3 f(\{P_1, P_2, P_3\}) = 3 The sum of these is 13 . Sample Input 2 4 1 4 2 1 3 3 4 2 Sample Output 2 34 Sample Input 3 10 19 -11 -3 -12 5 3 3 -15 8 -14 -9 -20 10 -9 0 2 -7 17 6 -6 Sample Output 3 7222 Be sure to print the sum modulo 998244353 .
| 38,830
|
åé¡ H : ãã£ãã·ã¥æŠç¥ ä»ïŒGââgle Code Jam ã®å°åºå€§äŒãå§ãŸãããšããŠããïŒ æãå³åã®åžã«åº§ã£ãŠããç·ã® ID 㯠lyrically ãšèšããããïŒ æ±äº¬å€§åп代ã®èšæ¶ã«ïŒäŒŒããã㪠ID ã®ä»²éãå±
ãèŠãããããïŒåã®ä»²éã¯äžäººæ®ããçŸå°å¥³ã ã£ãã¯ãã ïŒ åã®èšæ¶ã®äžã® lyrically ã¯ïŒã¢ã«ãŽãªãºã ã®åãå®è£
ã®åãããªããïŒ æ°åã§åé¡ã«æ£è§£ããããšã«ãå®è©ããã£ãïŒ äŸãã°ïŒèšç®éãå€å°æªãããã°ã©ã ã§ãïŒäžæãªå®è£
ãããããšã§é«éã«ãïŒ æ£è§£ãšãããããªããšãåŸæãšããŠããïŒ ããã°ã©ã ãé«éã«ããäžã§ïŒéåžžã«å€§åã«ãªã£ãŠããã®ãïŒ ãã£ãã·ã¥ã¡ã¢ãªãšã®èŠªåæ§ã§ããïŒ åé¡ ãããã¯æ¯ã«èªã¿èŸŒã¿ã®ã³ã¹ããç°ãªãã¡ã¢ãªãèããïŒ èµ·ããå
šãŠã®ã¡ã¢ãªã¢ã¯ã»ã¹ããããããåãã£ãç¶æ
ã§ã®ïŒ ãã«ã¢ãœã·ã¢ãã£ãã®ãã£ãã·ã¥ã¡ã¢ãªã§ã®æåãªãã£ãã·ã¥æŠç¥ãæ±ãããïŒ ä»¥äžïŒå¹³æãªèšèã§èª¬æããïŒ M åã®ç®±ãšïŒ N åã®ããŒã«ãããïŒ ããŒã«ã«ã¯ 1 ãã N ãŸã§ã®çªå·ãä»ããŠããïŒ åããŒã« i ã«ã¯éã w i ãæ±ºãŸã£ãŠããïŒ ãŸãïŒé·ã K ã®æ°å a 1 , a 2 , âŠ, a K ãäžããããïŒ å a j 㯠1 †a j †N ãæºããæŽæ°ã§ããïŒ ã¯ããã¯å
šãŠã®ç®±ã¯ç©ºã§ããïŒ j = 1, 2, âŠ, K ã®é ã«ïŒä»¥äžãè¡ãããïŒ ããŒã« a j ãå
¥ã£ãŠããç®±ãããã°ïŒäœãããªãïŒ ãã®æäœã«ãããã³ã¹ã㯠0 ã§ããïŒ ããŒã« a j ãå
¥ã£ãŠããç®±ããªããã°ïŒããããã®ç®±ã«ããŒã« a j ãå
¥ããïŒ ããŒã«ãç®±ã«å
¥ããéïŒããæ¢ã«ãã®ç®±ã«å
¥ã£ãŠããããŒã«ãããã°ïŒãã®ããŒã«ã¯å€ã«åºãïŒ ãã®æäœã«ãããã³ã¹ã㯠w a j ã§ããïŒïŒã³ã¹ãã¯ïŒå
¥ããç®±ãåãåºãããŒã«çã«ã¯ãããªãïŒïŒ ã³ã¹ãã®åã®æå°å€ãèšç®ããããã°ã©ã ãäœæããïŒ å
¥å å
¥åã®æåã®è¡ã¯ 3 ã€ã®æŽæ° M , N , K ãå«ãïŒ ç¶ã N è¡ã® i è¡ç®ã«ã¯æŽæ° w i ãæžãããŠããïŒ ç¶ã K è¡ã® j è¡ç®ã«ã¯æŽæ° a j ãæžãããŠããïŒ åºå ã³ã¹ãã®åã®æå°å€ãåºåããïŒ å¶çŽ 1 †M †10 1 †N †10 4 1 †K †10 4 1 †w i †10 4 1 †a j †N éšåç¹ ãã®åé¡ã®å€å®ã«ã¯ïŒ20 ç¹åã®ãã¹ãã±ãŒã¹ã®ã°ã«ãŒããèšå®ãããŠããïŒ ãã®ã°ã«ãŒãã«å«ãŸãããã¹ãã±ãŒã¹ã®å
¥åã¯ä»¥äžãæºããïŒ 1 †M †3 1 †N †10 1 †K †10 3 å
¥åºåäŸ å
¥åäŸ 1 å
¥åäŸ 1: 3 3 6 10 20 30 1 2 3 1 2 3 å
¥åäŸ 1 ã«å¯ŸããåºåäŸ: 60 å
¥åäŸ 2 å
¥åäŸ 2: 2 3 6 10 20 30 1 2 3 1 2 3 å
¥åäŸ 2 ã«å¯ŸããåºåäŸ: 80
| 38,831
|
Problem G: ãšããžãŒã»ãã©ã³ã¹ããŒã¿ãŒ ãšããç ç©¶æã§ïŒ ãšãã«ã®ãŒäŒéçšã®åªäœã®éçºãããŠããïŒ ãã®åªäœã¯å³3ã«ç€ºããããªç¹æ®ãªç©è³ªãããªã ããªããŒæ§é ããªããŠããïŒ (-α-Ea-β-) n å³3: ãšãã«ã®ãŒäŒéçšåªäœã®æ§é ïŒ å³ã® Ea ã§ç€ºããéšåããã®åªäœã®ãã£ãšãç¹åŸŽçãªéšäœã® ãšããžãŒã¢ãã¥ã ã¬ãŒã¿ (Energy Accumulator) ã§ããïŒ ãã®Eaåºã¯ 1 kJ å¹
ã§é¢æ£åããã倿§ãªãšãã«ã®ãŒç¶æ
ãåãããšãã§ããïŒ ããEaåºãå±èµ·ããããšïŒ ãã®Eaåºã®Î±åŽã«çµåããŠãã飿¥ããEaåºã«èç©ãããŠããå
šãšãã«ã®ãŒã βåŽã«çµåããŠãã飿¥ããEaåºã«ç§»åããããããªå¹æãæã€ çºç±åå¿ãåŒãèµ·ããããïŒå³4ïŒïŒ ãã®åå¿ã®éïŒå±èµ·ãããEaåºã®ãšãã«ã®ãŒã 1 kJ æ¶è²»ãããïŒ ãªãïŒããªããŒã®äž¡ç«¯ã«äœçœ®ããEaåºããšãã«ã®ãŒç¶æ
ã 0 kJ ã«ãªã£ãŠãã Eaåºã«å¯ŸããŠã¯å±èµ·åå¿ã¯çºçããªãããšïŒ ããã³Eaåºã¯ååã«å€§ããªãšãã«ã®ãŒãèããããšãå¯èœã§ããããšãç¥ãããŠããïŒ å³4: äžå€®ã®Eaåºãå±èµ·ããããšãã®åå¿ïŒ ãã®æ§è³ªãå©çšããããšã§ãšãã«ã®ãŒã®äŒéãå¯èœã«ããããšèããŠããã®ã ãïŒ ãšãã«ã®ãŒãå¹çããäŒéããã«ã¯åEaåºãå±èµ·ãããé çªãéèŠã§ããããšã« ç ç©¶è
ãã¡ã¯æ°ãã€ããã®ã§ããïŒ å¹žãïŒå±èµ·ãããé çªãåæ°ã¯ä»»æã«å¶åŸ¡ã§ããã®ã ãïŒ åœŒãã«ã¯æé©ãªå±èµ·æé ãããããªãïŒ ããã§åœŒãã®çºæ³ã®è¶³ããããšããŠïŒ åæç¶æ
ã®ãšãã«ã®ãŒååžã«å¯Ÿã㊠æå³EaåºïŒÎ²æ«ç«¯ãããã£ãšãè¿ãEaåºïŒ ã«èãããããæå€§ã®ãšãã«ã®ãŒéãèšç®ããŠãããããïŒ Input å
¥åã¯è€æ°ã®ããŒã¿ã»ããããæ§æããïŒ ä»¥äžã®ãããªåœ¢åŒã§äžããããïŒ N C 1 C 2 ... C N å
¥åã®å
é ã®æŽæ° N (0 < N †60) ãåãæ±ãåé¡ã®ããŒã¿ã»ããæ°ã§ããïŒ ãã®åŸã 2 N è¡ã«æž¡ã£ãŠïŒ ããããã®ããŒã¿ã»ããããšã®æ
å ± C k ãäžããããïŒ ããããã®ããŒã¿ã»ãã C k ã¯ä»¥äžã®ãããªåœ¢åŒã§ 2è¡ã«æž¡ãäžããããïŒ L E 1 E 2 ... E L L ã¯ããããã®ããŒã¿ã»ããã§åãæ±ãåªäœã®Eaéã®é·ãã§ããïŒ ããã§äžããããæ°ã ãEaåºãçŽåã«çµåããŠããããšãæå³ããŠããïŒ ãã®æ¬¡ã®è¡ã® L åã®æŽæ° E k ã¯ïŒ é·ã L ã®Eaéã®ãã¡Î±æ«ç«¯ãå·Šç«¯ã«æ®ãããšãã« å·Šããæ°ã㊠k çªç®ã®Eaéã«ã¯ããã«èç©ãããŠãããšãã«ã®ãŒéã kJåäœã§ç€ºãããã®ã§ããïŒ ããã§ïŒ 0 †E k †4, 1 †L †80 ã§ããããšãä¿èšŒãããŠããïŒ Output åºåã¯åããŒã¿ã»ããããšã«ïŒäžããããç¶æ³äžã§ã®å³ç«¯Eaéã«å°éå¯èœãª æå€§ãšãã«ã®ãŒãkJåäœã§ïŒæŽæ°å€ã®ã¿ã1è¡ã§èšè¿°ããããšïŒ Sample Input 7 1 2 2 1 2 3 4 1 4 3 4 0 4 5 4 1 4 0 4 5 4 1 4 1 4 5 4 2 4 0 4 Output for the Sample Input 2 2 8 4 7 12 11
| 38,832
|
Score : 200 points Problem Statement Niwango-kun is an employee of Dwango Co., Ltd. One day, he is asked to generate a thumbnail from a video a user submitted. To generate a thumbnail, he needs to select a frame of the video according to the following procedure: Get an integer N and N integers a_0, a_1, ..., a_{N-1} as inputs. N denotes the number of the frames of the video, and each a_i denotes the representation of the i -th frame of the video. Select t -th frame whose representation a_t is nearest to the average of all frame representations. If there are multiple such frames, select the frame with the smallest index. Find the index t of the frame he should select to generate a thumbnail. Constraints 1 \leq N \leq 100 1 \leq a_i \leq 100 All numbers given in input are integers Input Input is given from Standard Input in the following format: N a_{0} a_{1} ... a_{N-1} Output Print the answer. Sample Input 1 3 1 2 3 Sample Output 1 1 Since the average of frame representations is 2 , Niwango-kun needs to select the index 1 , whose representation is 2 , that is, the nearest value to the average. Sample Input 2 4 2 5 2 5 Sample Output 2 0 The average of frame representations is 3.5 . In this case, every frame has the same distance from its representation to the average. Therefore, Niwango-kun should select index 0 , the smallest index among them.
| 38,833
|
Airport Codes 空枯ã³ãŒã JAGçåœã§ã¯åœå
ã®ç©ºæž¯ã«ãããã空枯ã³ãŒããå²ãåœãŠãŠèå¥ãããŠããïŒ ç©ºæž¯ã³ãŒãã¯ïŒå°æåã®è±èªã¢ã«ãã¡ãããã§è¡šèšãã空枯ã®ååãããšã«ä»¥äžã®èŠåã§å²ãåœãŠããã: ååã®æåã®æåãšïŒæ¯é³ (a,i,u,e,o) ã®çŽåŸã®æåãé ã«åãåºãïŒ åãåºããæååã k æåæªæºãªãããã空枯ã³ãŒããšãïŒ k æå以äžãªãïŒãã®åãåºããæååã®å
é k æåã空枯ã³ãŒããšããŠäœ¿ãïŒ äŸãã° k = 3 ã®ãšãïŒhaneda ã«ã¯ hnd ïŒ oookayama ã«ã¯ ooo ïŒ tsu ã«ã¯ t ãšããã³ãŒããå²ãåœãŠãããïŒ ããããã®ã³ãŒãã®å²ãåœãŠæ¹ã§ã¯ïŒéãååã®ç©ºæž¯ã§ãåãã³ãŒããå²ãåœãŠãããããšãããïŒæ··ä¹±ãæããŠããŸãïŒ ç©ºæž¯ã®ååã®äžèЧãäžããããã®ã§ïŒãã¹ãŠã®ç©ºæž¯ã®ã³ãŒããç°ãªãããã«ã§ãããå€å®ããŠïŒå¯èœãªå Žåã¯ãã¹ãŠã®ç©ºæž¯ã³ãŒããç°ãªãããã«ã§ããæå°ã® k ãæ±ãïŒäžå¯èœãªå Žåã¯ãã®æšãäŒããããã°ã©ã ãäœæããïŒ Input å
¥åã¯100å以äžã®ããŒã¿ã»ãããããªãïŒ ããããã®ããŒã¿ã»ããã¯æ¬¡ã®åœ¢åŒã§äžããããïŒ n s 1 ... s n 1è¡ç®ã«ç©ºæž¯ã®æ° n (2 †n †50) ãæŽæ°ã§äžãããïŒç¶ã n è¡ã«ã¯ãããã空枯ã®åå s i ãæååã§äžããããïŒ ç©ºæž¯ã®ååã¯' a 'ãã' z 'ã®å°æåã®è±èªã¢ã«ãã¡ãããã®ã¿ã§æ§æããïŒããããæåæ°ã¯1以äž50以äžã§ããïŒ ãŸãïŒäžãããã空枯ã®ååã¯ãã¹ãŠç°ãªãïŒããªãã¡ïŒ1 †i < j †n ã®ãšã s i â s j ãæºããïŒ å
¥åã®çµããã¯1ã€ã®ãŒãã ããããªãè¡ã§ç€ºãããïŒ Output ããããã®ããŒã¿ã»ããã«ã€ããŠïŒãã¹ãŠã®ç©ºæž¯ã«çžç°ãªã空枯ã³ãŒããå²ãåœãŠããããšãã¯ïŒãã®ãããªæå°ã® k ã1è¡ã«åºåããïŒ äžå¯èœãªå Žåã¯ïŒ-1ã1è¡ã«åºåããïŒ Sample Input 3 haneda oookayama tsu 2 azusa azishirabe 2 snuke snake 4 haneda honda hanamaki hawaii 0 Output for Sample Input 1 4 -1 3
| 38,834
|
Problem B: Red and Black There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can't move on red tiles, he can move only on black tiles. Write a program to count the number of black tiles which he can reach by repeating the moves described above. Input The input consists of multiple data sets. A data set starts with a line containing two positive integers W and H ; W and H are the numbers of tiles in the x - and y - directions, respectively. W and H are not more than 20. There are H more lines in the data set, each of which includes W characters. Each character represents the color of a tile as follows. '.' - a black tile '#' - a red tile '@' - a man on a black tile(appears exactly once in a data set) The end of the input is indicated by a line consisting of two zeros. Output For each data set, your program should output a line which contains the number of tiles he can reach from the initial tile (including itself). Sample Input 6 9 ....#. .....# ...... ...... ...... ...... ...... #@...# .#..#. 11 9 .#......... .#.#######. .#.#.....#. .#.#.###.#. .#.#..@#.#. .#.#####.#. .#.......#. .#########. ........... 11 6 ..#..#..#.. ..#..#..#.. ..#..#..### ..#..#..#@. ..#..#..#.. ..#..#..#.. 7 7 ..#.#.. ..#.#.. ###.### ...@... ###.### ..#.#.. ..#.#.. 0 0 Output for the Sample Input 45 59 6 13
| 38,835
|
æ£ã§äœãçŽæ¹äœ ã¢ã€ã
æŸéåäŒã®æè²çªçµ(æè²)ã§ã¯ãåã©ãåãã®å·¥äœçªçµããããã§ã€ããããæŸéããŠããŸããä»åã¯æ£ã§ç®±ãäœãåã§ãããçšæããïŒïŒæ¬ã®æ£ã䜿ã£ãŠçŽæ¹äœãã§ãããã確ãããããšæããŸãããã ããæ£ã¯åã£ããæã£ããããŠã¯ãããŸããã ïŒïŒæ¬ã®æ£ã®é·ããäžããããã®ã§ãããããã¹ãŠã蟺ãšããçŽæ¹äœãäœãããã©ããå€å®ããããã°ã©ã ãäœæããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã e 1 e 2 ... e 12 å
¥åã¯ïŒè¡ãããªãã忣ã®é·ããè¡šãæŽæ° e i (1 †e i †100) ãäžããããã Output çŽæ¹äœãäœæã§ããå Žåã«ã¯ãyesãããäœæã§ããªãå Žåã«ã¯ãnoããåºåããããã ããç«æ¹äœã¯çŽæ¹äœã®äžçš®ãªã®ã§ãç«æ¹äœã®å Žåã§ããyesããšåºåããã Sample Input 1 1 1 3 4 8 9 7 3 4 5 5 5 Sample Output 1 no Sample Input 2 1 1 2 2 3 1 2 3 3 3 1 2 Sample Output 2 yes
| 38,836
|
Score : 400 points Problem Statement Mr. Takahashi has a string s consisting of lowercase English letters. He repeats the following operation on s exactly K times. Choose an arbitrary letter on s and change that letter to the next alphabet. Note that the next letter of z is a . For example, if you perform an operation for the second letter on aaz , aaz becomes abz . If you then perform an operation for the third letter on abz , abz becomes aba . Mr. Takahashi wants to have the lexicographically smallest string after performing exactly K operations on s . Find the such string. Constraints 1â€|s|â€10^5 All letters in s are lowercase English letters. 1â€Kâ€10^9 Input The input is given from Standard Input in the following format: s K Output Print the lexicographically smallest string after performing exactly K operations on s . Sample Input 1 xyz 4 Sample Output 1 aya For example, you can perform the following operations: xyz , yyz , zyz , ayz , aya . Sample Input 2 a 25 Sample Output 2 z You have to perform exactly K operations. Sample Input 3 codefestival 100 Sample Output 3 aaaafeaaivap
| 38,837
|
Score : 600 points Problem Statement A bracket sequence is a string that is one of the following: An empty string; The concatenation of ( , A , and ) in this order, for some bracket sequence A ; The concatenation of A and B in this order, for some non-empty bracket sequences A and B / Given are N strings S_i . Can a bracket sequence be formed by concatenating all the N strings in some order? Constraints 1 \leq N \leq 10^6 The total length of the strings S_i is at most 10^6 . S_i is a non-empty string consisting of ( and ) . Input Input is given from Standard Input in the following format: N S_1 : S_N Output If a bracket sequence can be formed by concatenating all the N strings in some order, print Yes ; otherwise, print No . Sample Input 1 2 ) (() Sample Output 1 Yes Concatenating (() and ) in this order forms a bracket sequence. Sample Input 2 2 )( () Sample Output 2 No Sample Input 3 4 ((())) (((((( )))))) ()()() Sample Output 3 Yes Sample Input 4 3 ((( ) ) Sample Output 4 No
| 38,838
|
Gift Exchange Party A gift exchange party will be held at a school in TKB City. For every pair of students who are close friends, one gift must be given from one to the other at this party, but not the other way around. It is decided in advance the gift directions, that is, which student of each pair receives a gift. No other gift exchanges are made. If each pair randomly decided the gift direction, some might receive countless gifts, while some might receive only few or even none. You'd like to decide the gift directions for all the friend pairs that minimize the difference between the smallest and the largest numbers of gifts received by a student. Find the smallest and the largest numbers of gifts received when the difference between them is minimized. When there is more than one way to realize that, find the way that maximizes the smallest number of received gifts. Input The input consists of at most 10 datasets, each in the following format. n m u 1 v 1 ... u m v m n is the number of students, and m is the number of friendship relations (2 †n †100, 1 †m †n ( n -1)/2). Students are denoted by integers between 1 and n , inclusive. The following m lines describe the friendship relations: for each i , student u i and v i are close friends ( u i < v i ). The same friendship relations do not appear more than once. The end of the input is indicated by a line containing two zeros. Output For each dataset, output a single line containing two integers l and h separated by a single space. Here, l and h are the smallest and the largest numbers, respectively, of gifts received by a student. Sample Input 3 3 1 2 2 3 1 3 4 3 1 2 1 3 1 4 4 6 1 2 1 3 1 4 2 3 3 4 2 4 0 0 Output for the Sample Input 1 1 0 1 1 2
| 38,839
|
åé¡å ä» n æã®æ°åãæžãããã«ãŒãããããŸãããããã®äžéšãŸãã¯å
šéšãé©åœã«äžŠã¹ãŠæ°åãäœãããšãèããŸãããã®æäœãããæ°åãå
šãŠè¶³ããæ°ãæ±ããŠäžããã äŸãã°ã 1 ãš 2 ããã£ãããäœãããæ°å㯠1, 2, 12, 21 ã® 4 ã€ãªã®ã§ãå
šãŠè¶³ããæ°ã¯ 36 ã«ãªããŸãã䞊ã¹ãçµæåãæ°åãåºæ¥ãŠãéãäžŠã¹æ¹ã ãšãããå¥ã
ã«è¶³ããŸããããšãã°ã 1 ãšããã«ãŒããš 11 ãšããã«ãŒãããã£ãã䞊ã¹ãŠ 111 ã«ãªãäžŠã¹æ¹ã2éããããŸããããããå¥ã®ãã®ãšããŠè¶³ãåãããŸããã«ãŒãã®äžã«ãªãŒãã£ã³ã°ãŒãã®ã«ãŒãã¯ãããŸãããããªãŒãã£ã³ã°ãŒãã«ãªãæ°åã¯èªããŸãããçãã1,000,000,007 ã§å²ã£ããã®ãåºåããŠãã ããã Input å
¥åã¯ã以äžã®åœ¢ã§äžããããŸãã n a 1 a 2 ... a n æåã® 1 è¡ã«ã¯ã«ãŒãã®ææ°ã衚ã n ïŒ 1 †n †200 ïŒã次㮠n è¡ã«ã¯ããããã®ã«ãŒãã«æžãããŠããæ°å a i ( 0 †a i < 10000 ) ãæžãããŠããŸãããŸãè€æ°ã®ã«ãŒãã«åãæ°åãæžãããŠããããšã¯ãããŸããã Output äœãããšã®åºæ¥ãå
šãŠã®æ°åã®åèšã 1,000,000,007 ã§å²ã£ããã®ã 1 è¡ã«åºåããªããã Sample Input 1 2 1 2 Output for the Sample Input 1 36 ãµã³ãã«ã«ãã£ãäŸã§ãã Sample Input 2 2 1 11 Output for the Sample Input 2 234 äœãããæ°å㯠1 ãš 11 ãšã 111 ã 2 éãäœãããã®ã§å
šãŠè¶³ã㊠234 ãšãªããŸãã Sample Input 3 4 0 4 7 8 Output for the Sample Input 3 135299 04 ã 078 ãšãã£ãäžŠã¹æ¹ã¯èªããããªãããšã«æ³šæããŠãã ããã
| 38,840
|
Score : 800 points Problem Statement You are given integers N,\ A and B . Determine if there exists a permutation (P_0,\ P_1,\ ...\ P_{2^N-1}) of (0,\ 1,\ ...\ 2^N-1) that satisfies all of the following conditions, and create one such permutation if it exists. P_0=A P_{2^N-1}=B For all 0 \leq i < 2^N-1 , the binary representations of P_i and P_{i+1} differ by exactly one bit. Constraints 1 \leq N \leq 17 0 \leq A \leq 2^N-1 0 \leq B \leq 2^N-1 A \neq B All values in input are integers. Input Input is given from Standard Input in the following format: N A B Output If there is no permutation that satisfies the conditions, print NO . If there is such a permutation, print YES in the first line. Then, print (P_0,\ P_1,\ ...\ P_{2^N-1}) in the second line, with spaces in between. If there are multiple solutions, any of them is accepted. Sample Input 1 2 1 3 Sample Output 1 YES 1 0 2 3 The binary representation of P=(1,0,2,3) is (01,00,10,11) , where any two adjacent elements differ by exactly one bit. Sample Input 2 3 2 1 Sample Output 2 NO
| 38,841
|
Score : 1600 points Problem Statement For a string S , let f(S) be the lexicographically smallest cyclic shift of S . For example, if S = babca , f(S) = ababc because this is the smallest among all cyclic shifts ( babca , abcab , bcaba , cabab , ababc ). You are given three integers X, Y , and Z . You want to construct a string T that consists of exactly X a s, exactly Y b s, and exactly Z c s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T) . Constraints 1 \leq X + Y + Z \leq 50 X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Sample Input 1 2 2 0 Sample Output 1 abab T must consist of two a s and two b s. If T = aabb , f(T) = aabb . If T = abab , f(T) = abab . If T = abba , f(T) = aabb . If T = baab , f(T) = aabb . If T = baba , f(T) = abab . If T = bbaa , f(T) = aabb . Thus, the largest possible f(T) is abab . Sample Input 2 1 1 1 Sample Output 2 acb
| 38,842
|
Score: 400 points Problem Statement The Patisserie AtCoder sells cakes with number-shaped candles. There are X , Y and Z kinds of cakes with 1 -shaped, 2 -shaped and 3 -shaped candles, respectively. Each cake has an integer value called deliciousness , as follows: The deliciousness of the cakes with 1 -shaped candles are A_1, A_2, ..., A_X . The deliciousness of the cakes with 2 -shaped candles are B_1, B_2, ..., B_Y . The deliciousness of the cakes with 3 -shaped candles are C_1, C_2, ..., C_Z . Takahashi decides to buy three cakes, one for each of the three shapes of the candles, to celebrate ABC 123. There are X \times Y \times Z such ways to choose three cakes. We will arrange these X \times Y \times Z ways in descending order of the sum of the deliciousness of the cakes. Print the sums of the deliciousness of the cakes for the first, second, ... , K -th ways in this list. Constraints 1 \leq X \leq 1 \ 000 1 \leq Y \leq 1 \ 000 1 \leq Z \leq 1 \ 000 1 \leq K \leq \min(3 \ 000, X \times Y \times Z) 1 \leq A_i \leq 10 \ 000 \ 000 \ 000 1 \leq B_i \leq 10 \ 000 \ 000 \ 000 1 \leq C_i \leq 10 \ 000 \ 000 \ 000 All values in input are integers. Input Input is given from Standard Input in the following format: X Y Z K A_1 \ A_2 \ A_3 \ ... \ A_X B_1 \ B_2 \ B_3 \ ... \ B_Y C_1 \ C_2 \ C_3 \ ... \ C_Z Output Print K lines. The i -th line should contain the i -th value stated in the problem statement. Sample Input 1 2 2 2 8 4 6 1 5 3 8 Sample Output 1 19 17 15 14 13 12 10 8 There are 2 \times 2 \times 2 = 8 ways to choose three cakes, as shown below in descending order of the sum of the deliciousness of the cakes: (A_2, B_2, C_2) : 6 + 5 + 8 = 19 (A_1, B_2, C_2) : 4 + 5 + 8 = 17 (A_2, B_1, C_2) : 6 + 1 + 8 = 15 (A_2, B_2, C_1) : 6 + 5 + 3 = 14 (A_1, B_1, C_2) : 4 + 1 + 8 = 13 (A_1, B_2, C_1) : 4 + 5 + 3 = 12 (A_2, B_1, C_1) : 6 + 1 + 3 = 10 (A_1, B_1, C_1) : 4 + 1 + 3 = 8 Sample Input 2 3 3 3 5 1 10 100 2 20 200 1 10 100 Sample Output 2 400 310 310 301 301 There may be multiple combinations of cakes with the same sum of the deliciousness. For example, in this test case, the sum of A_1, B_3, C_3 and the sum of A_3, B_3, C_1 are both 301 . However, they are different ways of choosing cakes, so 301 occurs twice in the output. Sample Input 3 10 10 10 20 7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488 1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338 4975681328 8974383988 2882263257 7690203955 514305523 6679823484 4263279310 585966808 3752282379 620585736 Sample Output 3 23379871545 22444657051 22302177772 22095691512 21667941469 21366963278 21287912315 21279176669 21160477018 21085311041 21059876163 21017997739 20703329561 20702387965 20590247696 20383761436 20343962175 20254073196 20210218542 20150096547 Note that the input or output may not fit into a 32 -bit integer type.
| 38,843
|
Problem I: Hopping Mind Problem ããšããšã«ã«ãªã¯åãå«è¶åºã§åãå§åйã§ããã2人ã¯ãšãŠã仲ãè¯ããããæ¥ããšããããŒãã«ã²ãŒã ã§éã¶ããšã«ãªã£ãã ã²ãŒã 㯠R ãã¹Ã C ãã¹ã®ç€é¢ãšãé§ãšããŠãããã®TPãçšãããç€é¢ã®åãã¹ã¯çœãé»ã®è²ãå¡ãããŠãããæåã«TPãç€é¢ã®å³äž( R , C )ã«ããã2äººã§æ¬¡ã®è¡åã亀äºã«è¡ããTPã®çŸåšã®äœçœ®ã( a , b )ãšãããšããããããžã£ã³ãå¯èœãªäœçœ®( i , j )ã1ã€éžã³ãTPãããã«ãžã£ã³ãããããTPããžã£ã³ãå¯èœãªäœçœ®( i , j )ã¯ä»¥äžããã¹ãŠæºããã 1 †i †R ã〠1 †j †C ã〠i †a ã〠j †b ã〠1 †( a - i ) + ( b - j ) †K ( i , j )ã¯çœããã¹ã§ãã èªåã®ã¿ãŒã³ã«TPããžã£ã³ããããããšãã§ããªããªã£ãå Žåãè² ããšãªãã ããšããå
æãã«ã«ãªãåŸæã§ãã®ã²ãŒã ãè¡ããã«ã«ãªã¯é ã®äžã§ã²ãŒã ãæåŸãŸã§å
èªã¿ããããšãã§ããåžžã«æé©ãªè¡åããšãããã®æãããšããåã€æ¹æ³ãååšãããã©ãããå€å®ããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã R C K G 1,1 G 1,2 ... G 1,C G 2,1 G 2,2 ... G 2,C : G R,1 G R,2 ... G R,C 1è¡ç®ã«3ã€ã®æŽæ° R , C , K ã空çœåºåãã§äžãããããæ¬¡ã® R è¡ã«ç€é¢ã®æ
å ±ãšã㊠C åã®".âãŸãã¯"#âãäžããããã G i,j ã¯ç€é¢ã®äœçœ®( i , j )ã®è²ã衚ããâ.âãçœã"#âãé»ã衚ãã Constraints 1 †R , C †1000 1 †K †2000 G R,C ã¯â.âã§ãã Output ããšããåã€æ¹æ³ãååšããå Žåã¯âChienoâããååšããªãå Žåã¯âCacaoâã1è¡ã«åºåããã Sample Input1 3 3 2 ... ... ... Sample Output1 Chieno Sample Input2 3 3 2 #.# .#. #.. Sample Output2 Cacao
| 38,844
|
Score : 600 points Problem Statement There are N holes in a two-dimensional plane. The coordinates of the i -th hole are (x_i,y_i) . Let R=10^{10^{10^{10}}} . Ringo performs the following operation: Randomly choose a point from the interior of a circle of radius R centered at the origin, and put Snuke there. Snuke will move to the hole with the smallest Euclidean distance from the point, and fall into that hole. If there are multiple such holes, the hole with the smallest index will be chosen. For every i (1 \leq i \leq N) , find the probability that Snuke falls into the i -th hole. Here, the operation of randomly choosing a point from the interior of a circle of radius R is defined as follows: Pick two real numbers x and y independently according to uniform distribution on [-R,R] . If x^2+y^2\leq R^2 , the point (x,y) is chosen. Otherwise, repeat picking the real numbers x,y until the condition is met. Constraints 2 \leq N \leq 100 |x_i|,|y_i| \leq 10^6(1\leq i\leq N) All given points are pairwise distinct. All input values are integers. Input Input is given from Standard Input in the following format: N x_1 y_1 : x_N y_N Output Print N real numbers. The i -th real number must represent the probability that Snuke falls into the i -th hole. The output will be judged correct when, for all output values, the absolute or relative error is at most 10^{-5} . Sample Input 1 2 0 0 1 1 Sample Output 1 0.5 0.5 If Ringo put Snuke in the region x+y\leq 1 , Snuke will fall into the first hole. The probability of this happening is very close to 0.5 . Otherwise, Snuke will fall into the second hole, the probability of which happening is also very close to 0.5 . Sample Input 2 5 0 0 2 8 4 5 2 6 3 10 Sample Output 2 0.43160120892732328768 0.03480224363653196956 0.13880483535586193855 0.00000000000000000000 0.39479171208028279727
| 38,845
|
I: Starting Line ICPC ã§è¯ãæçžŸãåããã«ã¯ä¿®è¡ãæ¬ ãããªãïŒããã㯠ICPC ã§åã¡ããã®ã§ïŒä»æ¥ãä¿®è¡ãããããšã«ããïŒ ä»æ¥ã®ä¿®è¡ã¯ïŒäžçŽç·äžã®éãèµ°ã£ãŠïŒäœåãšå€æåãé€ãããšãããã®ã§ããïŒãããã¯ä»ïŒã¹ã¿ãŒãã©ã€ã³ã«ç«ã£ãŠé·ãé·ãéãèŠæž¡ããŠããïŒ éã®éäžã«ã¯ããã€ããã³ãžã³ã眮ãããŠããïŒãããã¯ãã³ãžã³ãé£ã¹ããšå éããããšãã§ããïŒå éããŠããªããšãã®ãããã®èµ°ãéãã¯æ¯ç§ U ã¡ãŒãã«ã§ãããïŒãã³ãžã³ãé£ã¹ãããšã§ïŒæåŸã®ãã³ãžã³ãé£ã¹ãŠãã T ç§åŸãŸã§ã¯éããæ¯ç§ V ã¡ãŒãã«ãšãªãïŒãŸãïŒãããã¯ãã³ãžã³ã K åãŸã§é£ã¹ãã«æã£ãŠããããšãã§ããïŒãã³ãžã³ãæã£ãŠããŠãèµ°ãéãã¯å€ãããªãïŒ ãã³ãžã³ãæã£ããé£ã¹ããããã®ã«æéã¯ããããªããšããŠïŒãŽãŒã«ãŸã§ã®æçæèŠæéãæ±ãããïŒ Input N K T U V L D 1 ... D N N ã¯ãã³ãžã³ã®åæ°ïŒ L ã¯ã¹ã¿ãŒããããŽãŒã«ãŸã§ã®è·é¢ (ã¡ãŒãã«)ïŒ D i (1 †i †N ) 㯠i çªç®ã®ãã³ãžã³ã眮ãããŠããå Žæã®ã¹ã¿ãŒãããã®è·é¢ (ã¡ãŒãã«) ã§ããïŒ 1 †N †200ïŒ1 †K †N ïŒ1 †T †10,000ïŒ1 †U < V †10,000ïŒ2 †L †10,000ïŒ0 < D 1 < D 2 < ... < D N < L ãæºããïŒå
¥åã®å€ã¯ãã¹ãп޿°ã§ããïŒ Output æçæèŠæé (ç§) ã 1 è¡ã«åºåããïŒ10 -6 以äžã®çµ¶å¯Ÿèª€å·®ã蚱容ãããïŒ Sample Input 1 1 1 1 2 3 100 50 Sample Output 1 49.500000000 Sample Input 2 3 1 1 2 3 100 49 50 51 Sample Output 2 48.666666667
| 38,846
|
Sorting Three Numbers Write a program which reads three integers, and prints them in ascending order. Input Three integers separated by a single space are given in a line. Output Print the given integers in ascending order in a line. Put a single space between two integers. Constraints 1 †the three integers †10000 Sample Input 1 3 8 1 Sample Output 1 1 3 8
| 38,847
|
Slimming Plan Chokudai loves eating so much. However, his doctor Akensho told him that he was overweight, so he finally decided to lose his weight. Chokudai made a slimming plan of a $D$-day cycle. It is represented by $D$ integers $w_0, ..., w_{D-1}$. His weight is $S$ on the 0-th day of the plan and he aims to reduce it to $T$ ($S > T$). If his weight on the $i$-th day of the plan is $x$, it will be $x + w_{i\%D}$ on the $(i+1)$-th day. Note that $i\%D$ is the remainder obtained by dividing $i$ by $D$. If his weight successfully gets less than or equal to $T$, he will stop slimming immediately. If his slimming plan takes too many days or even does not end forever, he should reconsider it. Determine whether it ends or not, and report how many days it takes if it ends. Input The input consists of a single test case formatted as follows. $S$ $T$ $D$ $w_0 ... w_{D-1}$ The first line consists of three integers $S$, $T$, $D$ ($1 \leq S, T, D \leq 100,000, S > T$). The second line consists of $D$ integers $w_0, ..., w_{D-1}$ ($-100,000 \leq w_i \leq 100,000$ for each $i$). Output If Chokudai's slimming plan ends on the $d$-th day, print $d$ in one line. If it never ends, print $-1$. Sample Input 1 65 60 3 -2 3 -4 Output for Sample Input 1 4 Chokudai's weight will change as follows: $65 \rightarrow 63 \rightarrow 66 \rightarrow 62 \rightarrow 60$. Sample Input 2 65 60 3 -2 10 -3 Output for Sample Input 2 -1 Chokudai's weight will change as follows: $65 \rightarrow 63 \rightarrow 73 \rightarrow 70 \rightarrow 68 \rightarrow 78 \rightarrow 75 \rightarrow ...$. Sample Input 3 100000 1 1 -1 Output for Sample Input 3 99999 Sample Input 4 60 59 1 -123 Output for Sample Input 4 1
| 38,848
|
Problem H: Squid Multiplication Squid Eiko loves mathematics. Especially she loves to think about integer. One day, Eiko found a math problem from a website. "A sequence b ={ a i + a j | i < j } is generated from a sequence a ={ a 0 , ... , a n | a i is even if i is 0, otherwise a i is odd}. Given the sequence b , find the sequence a ." This problem is easy for Eiko and she feels boring. So, she made a new problem by modifying this problem . "A sequence b ={ a i * a j | i < j } is generated from a sequence a ={ a 0 , ... , a n | a i is even if i is 0, otherwise a i is odd}. Given the sequence b , find the sequence a ." Your task is to solve the problem made by Eiko. Input Input consists of multiple datasets. Each dataset is given by following formats. n b 0 b 1 ... b n*(n+1)/2-1 n is the number of odd integers in the sequence a . The range of n is 2 †n †250. b i is separated by a space. Each b i is 1 †b i †2 63 -1. The end of the input consists of a single 0. Output For each dataset, you should output two lines. First line contains a 0 , an even number in the sequence a . The second line contains n odd elements separated by a space. The odd elements are sorted by increasing order. You can assume that the result is greater than or equal to 1 and less than or equal to 2 31 -1. Sample input 3 6 10 14 15 21 35 2 30 42 35 0 Sample output 2 3 5 7 6 5 7
| 38,849
|
Score : 400 points Problem Statement You start with the number 0 and you want to reach the number N . You can change the number, paying a certain amount of coins, with the following operations: Multiply the number by 2 , paying A coins. Multiply the number by 3 , paying B coins. Multiply the number by 5 , paying C coins. Increase or decrease the number by 1 , paying D coins. You can perform these operations in arbitrary order and an arbitrary number of times. What is the minimum number of coins you need to reach N ? You have to solve T testcases. Constraints 1 \le T \le 10 1 \le N \le 10^{18} 1 \le A, B, C, D \le 10^9 All numbers N, A, B, C, D are integers. Input The input is given from Standard Input. The first line of the input is T Then, T lines follow describing the T testcases. Each of the T lines has the format N A B C D Output For each testcase, print the answer on Standard Output followed by a newline. Sample Input 1 5 11 1 2 4 8 11 1 2 2 8 32 10 8 5 4 29384293847243 454353412 332423423 934923490 1 900000000000000000 332423423 454353412 934923490 987654321 Sample Output 1 20 19 26 3821859835 23441258666 For the first testcase, a sequence of moves that achieves the minimum cost of 20 is: Initially x = 0 . Pay 8 to increase by 1 ( x = 1 ). Pay 1 to multiply by 2 ( x = 2 ). Pay 1 to multiply by 2 ( x = 4 ). Pay 2 to multiply by 3 ( x = 12 ). Pay 8 to decrease by 1 ( x = 11 ). For the second testcase, a sequence of moves that achieves the minimum cost of 19 is: Initially x = 0 . Pay 8 to increase by 1 ( x = 1 ). Pay 1 to multiply by 2 ( x = 2 ). Pay 2 to multiply by 5 ( x = 10 ). Pay 8 to increase by 1 ( x = 11 ).
| 38,850
|
UFO æå¢äœæŠ 40XX 幎ãå°çã¯å®å®äººã®äŸµæ»ãåããŠãã!ãã§ã«å°çã®ã»ãšãã©ã¯å®å®äººã«ããå¶å§ãããŠãããæ®ãé²è¡æ ç¹ã¯é¶Žã¶åèŠå¡ã®ã¿ã«ãªã£ãŠããŸã£ãããã®é¶Žã¶åèŠå¡ã«ããå¶å§éšéãæ¬¡ã
ã«è¿«ã£ãŠããŠããã ããããåžæã¯æ®ãããŠãããé²è¡è»ã®æçµå
µåšãè¶
é·è·é¢è²«éã¬ãŒã¶ãŒç ²ã宿ããã®ã ãæ¬ ç¹ãšããã°ã åšåãåºããŸã§ã«äžå®ã®è·é¢ãå¿
èŠã§ã è¿ãããæµã¯ãã éãã¬ããŠããŸããšããããšã ã åšåãåºãªãç¯å²ã«äŸµå
¥ããæµã¯ãä»ã®æŠåã§ã©ãã«ããããããªããé²è¡è»ã®åè¬ã¯ã䟵å
¥ããŠæ¥ã UFO ã«å¯ŸåŠããããã«ããã®æ°ãç¥ããªããã°ãªããªãã®ã ããããŸãã«ãæµãå€ãããã§ããŸãæ°ãããããã«ãªããããã§åè¬ã¯ããªãã«ãã¬ãŒã¶ãŒã«æå¢ãããªãã£ã UFO ã®æ°ãåºåããããã°ã©ã ãçšæããããã«åœä»€ãããæŠééå§ãŸã§ã«ããã°ã©ã ãäœæããé¶Žã¶åèŠå¡ãå®ãåãšãªããã æµã® UFO ã¯ãã ãŸã£ããã«ã¬ãŒã¶ãŒç ²ã®ããæ ç¹ãç®æããŠçªæããŠãã(UFO ã«ã¯äºãã«ããæããåŠçãæœãããŠãããè¡çªããŠããŸãããšã¯ãªã) ãã¬ãŒã¶ãŒç ²ã¯ãåæç¶æ
ãã 1 ååŸã«æãè¿ã UFO ã®äžå¿ãçã£ãŠã¬ãŒã¶ãŒãçºå°ãå§ãããããã 1 åããšã«åãæ¡ä»¶ã§ã¬ãŒã¶ãŒãçºå°ãç¶ãããã¬ãŒã¶ãŒã¯è²«éãããã®å
ã«ãã UFO ãã¬ãŒã¶ãŒãããã£ãã ãã§æå¢ããããšãã§ããããããããã®ã¬ãŒã¶ãŒã«ã¯åšåã®åºãªãç¯å²ãããããã®ç¯å²ã«å
¥ã£ãŠããŸã£ãUFO ã¯çã£ãŠãæå³ããªããããçããªãããã«èšèšãããŠãããæå¢ã§ããã ãæå¢ãããšããã¬ãŒã¶ãŒã®åšåãåºãªãç¯å²ã«ã¯äœæ©ã® UFO ã䟵å
¥ããã ãããã ã¬ãŒã¶ãŒã®åšåãåºãªãç¯å²ã®ååŸ R ãšã襲æ¥ãã UFO ã®æ
å ±ãå
¥åãšããæå¢ããã䟵å
¥ããŠãã UFO ãäœæ©ããããåºåããããã°ã©ã ãäœæããŠãã ããã 襲æ¥ãã UFO ã®æ
å ±ã¯ãUFO ã®æ° N ãå UFO ã®åæåº§æš ( x0, y0 )ãå UFO ã®ååŸ r ãå UFO ã®åé v ã§æ§æãããŸãã 座æšã®åç¹ (0 , 0) ãã¬ãŒã¶ãŒç ²ã®äœçœ®ãšããŸããã¬ãŒã¶ãŒç ²ãš UFO ã®è·é¢ã¯åç¹ãã UFO ã®äžå¿ãŸã§ã®è·é¢ã§äžãããããã®è·é¢ã R 以äžã® UFO ã¯ã¬ãŒã¶ãŒã®åšåãåºãªãç¯å²ã«å
¥ã£ããšããŸããçãã¹ã察象ãåæã«è€æ°ååšããå Žåã¯ãªããã®ãšããŠèããŸããèšç®ã¯å
šãŠå¹³é¢äžã§èããå
¥åã¯ãã¹ãп޿°ã§äžããããŸãã Input è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸãã å
¥åã®çµããã¯ãŒããµãã€ã®è¡ã§ç€ºãããŸãã åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã R N x0 1 y0 1 r 1 v 1 x0 2 y0 2 r 2 v 2 : x0 N y0 N r N v N 1 è¡ç®ã«ã¬ãŒã¶ãŒã®åšåãåºãªãç¯å²ã®ååŸ R (1 †R †500) ãšUFO ã®æ° N (1 †N †100) ãäžããããŸããç¶ã N è¡ã« i æ©ç®ã® UFO ã®æ
å ± x0 i , y0 i (-100 †x0 i , y0 i †1000), r i , v i (1 †r i , v i †500) ãäžããããŸãã ããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã Output å
¥åããŒã¿ã»ããããšã«ãã¬ãŒã¶ãŒã®åšåãåºãªãç¯å²ã«äŸµå
¥ãã UFO ã®æ°ã1è¡ã«åºåããŸãã Sample Input 100 5 101 101 5 5 110 110 2 3 -112 -100 9 11 -208 160 82 90 -110 108 10 2 10 11 15 0 5 1 25 0 5 1 35 0 5 1 45 0 5 1 55 0 5 1 65 0 5 1 75 0 5 1 85 0 5 1 95 0 5 1 -20 0 5 20 -30 0 500 5 0 0 Output for the Sample Input 1 1
| 38,851
|
Breadth First Search Write a program which reads an directed graph $G = (V, E)$, and finds the shortest distance from vertex $1$ to each vertex (the number of edges in the shortest path). Vertices are identified by IDs $1, 2, ... n$. Input In the first line, an integer $n$ denoting the number of vertices, is given. In the next $n$ lines, adjacent lists of vertex $u$ are given in the following format: $u$ $k$ $v_1$ $v_2$ ... $v_k$ $u$ is ID of the vertex and $k$ denotes its degree.$v_i$ are IDs of vertices adjacent to $u$. Constraints $1 \leq n \leq 100$ Output For each vertex $u$, print $id$ and $d$ in a line. $id$ is ID of vertex $u$ and $d$ is the distance from vertex $1$ to vertex $u$. If there are no path from vertex $1$ to vertex $u$, print -1 as the shortest distance. Print in order of IDs. Sample Input 1 4 1 2 2 4 2 1 4 3 0 4 1 3 Sample Output 1 1 0 2 1 3 2 4 1 Reference Introduction to Algorithms, Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. The MIT Press.
| 38,852
|
Problem K: A Polygon And Circles Problem $N$åã®é ç¹ãããªãåžå€è§åœ¢ãš$M$åã®åã®äžå¿åº§æšãäžããããããã¹ãŠã®åã®ååŸã¯$r$ã§ããã 以äžã®æ¡ä»¶ãæºããæå°ã®å®æ°$r$ãæ±ãããã æ¡ä»¶: åžå€è§åœ¢ã®å
éšã®ã©ã®ç¹ããå°ãªããšãäžã€ä»¥äžã®åã«å
å
ãããŠããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§ãã¹ãп޿°ã§äžããããã $N$ $px_1$ $py_1$ $px_2$ $py_2$ : $px_N$ $py_N$ $M$ $cx_1$ $cy_1$ $cx_2$ $cy_2$ : $cx_M$ $cy_M$ $1$è¡ç®ã«ã¯åžå€è§åœ¢ã®é ç¹æ°ãè¡šãæŽæ°$N$ãäžããããã $2$è¡ç®ãã$2+N-1$è¡ç®ã«ã¯åžå€è§åœ¢ã®åé ç¹ã®æ
å ±ãåæèšåšãã®é ã§äžããããã$1+i$è¡ç®ã«ã¯$i$çªç®ã®é ç¹ã®åº§æšã衚ã$px_i$ $py_i$ã空çœåºåãã§äžããããã $2+N$è¡ç®ã«ã¯åã®æ°ãè¡šãæŽæ°$M$ãäžããããã $2+N+1$è¡ç®ãã$2+N+M$è¡ã«ã¯åã®äžå¿åº§æšã®æ
å ±ãäžããããã$2+N+i$è¡ç®ã«ã¯$i$çªç®ã®åã®äžå¿åº§æšã衚ã$cx_i$ $cy_i$ã空çœåºåãã§äžããããã Constraints å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã $3 \le N \le 100$ $1 \le M \le 100$ $-10^5 \le px_i, py_i \le 10^5$ $-10^5 \le cx_i, cy_i \le 10^5$ åžå€è§åœ¢ã®é ç¹ã®ãã¡ã©ã®3ç¹ãéžãã§ããåäžçŽç·äžã«ã¯ååšããªã Output æ¡ä»¶ãæºããæå°ã®åã®ååŸ $r$ ãåºåããã ãã ãã$10^{-5}$ ãŸã§ã®çµ¶å¯Ÿèª€å·®ãŸãã¯çžå¯Ÿèª€å·®ã¯èš±å®¹ãããã Sample Input 1 4 2 3 1 2 2 1 3 2 4 1 3 1 1 3 3 3 1 Sample Output 1 1.414213562373 Sample Input 2 7 -96469 25422 -55204 -45592 -29140 -72981 98837 -86795 92303 63297 19059 96012 -67980 70342 17 -4265 -14331 33561 72343 52055 98952 -71189 60872 10459 -7512 -11981 57756 -78228 -28044 37397 -69980 -27527 -51966 22661 -16694 13759 -59976 86539 -47703 17098 31709 -62497 -70998 -57608 59799 -1904 -35574 -73860 121 Sample Output 2 75307.220122044484
| 38,853
|
1幎ç (A First Grader) åé¡ JOIåã¯å°åŠ 1 幎çã§ããïŒJOIåã¯æãã£ãã°ããã®è¶³ãç®ïŒåŒãç®ããšãŠã奜ãã§ïŒæ°åã䞊ãã§ããã®ãèŠããšæåŸã® 2 ã€ã®æ°åã®éã«ã=ããå
¥ãïŒæ®ãã®æ°åã®éã«å¿
ãã+ããŸãã¯ã-ããå
¥ããŠçåŒãäœã£ãŠéãã§ããïŒäŸãã°ã8 3 2 4 8 7 2 4 0 8 8ãããïŒçåŒã8+3-2-4+8-7-2-4-0+8=8ããäœãããšãã§ããïŒ JOI åã¯çåŒãäœã£ãåŸïŒãããæ£ããçåŒã«ãªã£ãŠããããèšç®ããŠç¢ºãããïŒãã ãïŒJOIåã¯ãŸã è² ã®æ°ã¯ç¥ããªããïŒ20 ãè¶
ããæ°ã®èšç®ã¯ã§ããªãïŒãããã£ãŠïŒæ£ããçåŒã®ãã¡å·ŠèŸºãå·Šããèšç®ãããšãèšç®ã®éäžã§çŸããæ°ãå
šãŠ 0 ä»¥äž 20 以äžã®çåŒã ããJOIåã確ãããããæ£ããçåŒã§ããïŒäŸãã°ïŒã8+3-2-4-8-7+2+4+0+8=8ã㯠æ£ããçåŒã ãïŒéäžã«çŸãã 8+3-2-4-8 ãè² ã®æ°ãªã®ã§JOIåã¯ãã®çåŒãæ£ãããã©ãã確ãããããšãã§ããªãïŒ å
¥åãšããŠæ°åã®åãäžãããããšãïŒJOIåãäœãïŒç¢ºãããããšãã§ããæ£ããçåŒã®åæ°ãæ±ããããã°ã©ã ãäœæããïŒ å
¥å å
¥åãã¡ã€ã«ã¯ 2 è¡ãããªãïŒ1 è¡ç®ã«ã¯äžŠãã§ããæ°åã®åæ°ãè¡šãæŽæ° N ïŒ3 †N †100ïŒãæžãããŠããïŒ2 è¡ç®ã«ã¯ 0 ä»¥äž 9 以äžã®æŽæ°ã N åïŒç©ºçœãåºåããšããŠæžãããŠããïŒ äžããããå
¥åããŒã¿ã® 60% ã§ã¯ïŒJOIåãäœãïŒç¢ºãããããšãã§ããæ£ããçåŒã®åæ°ã¯ 2 31 -1 ãè¶
ããªãïŒãŸãïŒäžããããå
¥åããŒã¿ã®å
šãŠã«ãããŠïŒJOIåãäœãïŒç¢ºãããããšãã§ããæ£ããçåŒã®åæ°ã¯ 2 63 -1 ãè¶
ããªãïŒ åºå JOIåãäœãïŒç¢ºãããããšãã§ããæ£ããçåŒã®åæ°ãè¡šãæŽæ°ã 1 è¡ã§åºåããïŒ å
¥åºåäŸ å
¥åäŸ 1 11 8 3 2 4 8 7 2 4 0 8 8 åºåäŸ 1 10 å
¥åäŸ 1 ã«ãããŠïŒJOIå㯠10 åã®æ£ããçåŒ 8+3-2-4+8-7-2-4-0+8=8 8+3-2-4+8-7-2-4+0+8=8 8+3+2+4-8-7+2-4-0+8=8 8+3+2+4-8-7+2-4+0+8=8 8+3-2-4+8-7+2+4-0-8=8 8+3-2-4+8-7+2+4+0-8=8 8-3+2+4-8+7+2+4-0-8=8 8-3+2+4-8+7+2+4+0-8=8 8-3+2-4+8+7+2-4-0-8=8 8-3+2-4+8+7+2-4+0-8=8 ãäœãïŒç¢ºãããããšãã§ããã®ã§ 10 ãåºåããïŒ å
¥åäŸ 2 40 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 åºåäŸ 2 7069052760 å
¥åäŸ 2 ã«ãããŠïŒçãã 32 bit笊å·ä»ãæŽæ°ã®ç¯å²ã«åãŸããªãããšã«æ³šæããïŒ å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
| 38,854
|
Score : 600 points Problem Statement Kenkoooo found a simple connected graph. The vertices are numbered 1 through n . The i -th edge connects Vertex u_i and v_i , and has a fixed integer s_i . Kenkoooo is trying to write a positive integer in each vertex so that the following condition is satisfied: For every edge i , the sum of the positive integers written in Vertex u_i and v_i is equal to s_i . Find the number of such ways to write positive integers in the vertices. Constraints 2 \leq n \leq 10^5 1 \leq m \leq 10^5 1 \leq u_i < v_i \leq n 2 \leq s_i \leq 10^9 If i\neq j , then u_i \neq u_j or v_i \neq v_j . The graph is connected. All values in input are integers. Input Input is given from Standard Input in the following format: n m u_1 v_1 s_1 : u_m v_m s_m Output Print the number of ways to write positive integers in the vertices so that the condition is satisfied. Sample Input 1 3 3 1 2 3 2 3 5 1 3 4 Sample Output 1 1 The condition will be satisfied if we write 1,2 and 3 in vertices 1,2 and 3 , respectively. There is no other way to satisfy the condition, so the answer is 1 . Sample Input 2 4 3 1 2 6 2 3 7 3 4 5 Sample Output 2 3 Let a,b,c and d be the numbers to write in vertices 1,2,3 and 4 , respectively. There are three quadruples (a,b,c,d) that satisfy the condition: (a,b,c,d)=(1,5,2,3) (a,b,c,d)=(2,4,3,2) (a,b,c,d)=(3,3,4,1) Sample Input 3 8 7 1 2 1000000000 2 3 2 3 4 1000000000 4 5 2 5 6 1000000000 6 7 2 7 8 1000000000 Sample Output 3 0
| 38,855
|
Max Score: 1150 Points Task statement was updated. Problem Statement There is a grid which size is $H \times W$. the upper-left cell is $(1,1)$ and the lower-right cell is $(H,W)$. There is $N$ arrows. Arrow which start point is $(a_i,b_i)$ of direction is $c_i$, and size is $d_i$. ($d_i$ may be negative) It is guaranteed that there are no two arrow which start point is same. Sothe want to move from cell $(sx,sy)$ to cell $(gx,gy)$ with arrows. But it may not possible to move to goal in initial grid. So, Snuke decided to change some arrows. Sothe can change each arrow as follows: He can't change the start point of this arrow. It costs $e_i$ if he change the direction of this arrow. It costs $f \times |d_i-G|$ if he change d_i to $G$. He can't add or erase arrows. Please calculate the minimum cost that he can move to $(gx,gy)$. If he can't move to goal, please output '-1'. Note: Arrows are directed, and he can't turn in the middle of the arrow. Input The input is given from standard input in the following format. H W N f sx sy gx gy a_1 b_1 c_1 d_1 e_1 a_2 b_2 c_2 d_2 e_2 : : : a_N b_N c_N d_N e_N Output Please output a single integer: The minimum cost to clear this puzzle. If you can't achieve the objective, print -1 . Print \n (line break) in the end. Constraints $1 \le H,W \le 100000$ $1 \le N \le 70000$ $1 \le f,e_i \le 1000000$ $1 \le d_i \le 100000$ $1 \le a_i,sx,tx \le H$ $1 \le b_i,sy,ty \le W$ $c_i$ is N , E , S , or W , which means North, East, South, West. Subtasks Subtask 1 [ 190 points ] $H=1$ $W \le 600$ Subtask 2 [ 170 points ] $H,W \le 80$ Subtask 3 [ 360 points ] $H,W \le 600$ Subtask 4 [ 430 points ] There is no additional constraints. Sample Input 1 4 4 2 2 1 1 2 2 1 1 E 1 1 1 2 E 2 2 Sample Output 1 4 Sample Input 2 1 4 2 10 1 1 1 4 1 1 E 1 4 1 3 W 1 4 Sample Output 2 14 Sample Input 3 1 8 4 9 1 3 1 6 1 1 E 7 2 1 8 W 7 5 1 3 W 2 5 1 6 E 2 8 Sample Output 3 14 Sample Input 4 5 5 7 10 1 2 4 5 1 2 E 2 6 2 3 S 2 7 3 1 N 1 8 3 2 W 1 10 4 1 E 4 12 5 5 N 3 13 5 1 E 2 14
| 38,856
|
Score: 400 points Problem Statement AtCoder Inc. has decided to lock the door of its office with a 3 -digit PIN code. The company has an N -digit lucky number, S . Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code. How many different PIN codes can he set this way? Both the lucky number and the PIN code may begin with a 0 . Constraints 4 \leq N \leq 30000 S is a string of length N consisting of digits. Input Input is given from Standard Input in the following format: N S Output Print the number of different PIN codes Takahashi can set. Sample Input 1 4 0224 Sample Output 1 3 Takahashi has the following options: Erase the first digit of S and set 224 . Erase the second digit of S and set 024 . Erase the third digit of S and set 024 . Erase the fourth digit of S and set 022 . Thus, he can set three different PIN codes: 022 , 024 , and 224 . Sample Input 2 6 123123 Sample Output 2 17 Sample Input 3 19 3141592653589793238 Sample Output 3 329
| 38,857
|
Problem F: Chemist's Math You have probably learnt chemical equations (chemical reaction formulae) in your high-school days. The following are some well-known equations. 2H 2 + O 2 â 2H 2 O (1) C a (OH) 2 + CO 2 â C a CO 3 + H 2 O (2) N 2 + 3H 2 â 2NH 3 (3) While Equations (1)â(3) all have balanced left-hand sides and right-hand sides, the following ones do not. Al + O 2 â Al 2 O 3 ( wrong ) (4) C 3 H 8 + O 2 â CO 2 + H 2 O ( wrong ) (5) The equations must follow the law of conservation of mass ; the quantity of each chemical element (such as H, O, Ca, Al) should not change with chemical reactions. So we should "adjust" the numbers of molecules on the left-hand side and right-hand side: 4Al + 3O 2 â 2Al 2 O 3 ( correct ) (6) C 3 H 8 + 5O 2 â 3CO 2 + 4H 2 O (correct) (7) The coefficients of Equation (6) are (4, 3, 2) from left to right, and those of Equation (7) are (1, 5, 3, 4) from left to right. Note that the coefficient 1 may be omitted from chemical equations. The coefficients of a correct equation must satisfy the following conditions. The coefficients are all positive integers. The coefficients are relatively prime, that is, their greatest common divisor (g.c.d.) is 1. The quantities of each chemical element on the left-hand side and the right-hand side are equal. Conversely, if a chemical equation satisfies the above three conditions, we regard it as a correct equation, no matter whether the reaction or its constituent molecules can be chemically realized in the real world, and no matter whether it can be called a reaction (e.g., H 2 â H 2 is considered correct). A chemical equation satisfying Conditions 1 and 3 (but not necessarily Condition 2) is called a balanced equation. Your goal is to read in chemical equations with missing coefficients like Equation (4) and (5), line by line, and output the sequences of coefficients that make the equations correct. Note that the above three conditions do not guarantee that a correct equation is uniquely determined. For example, if we "mix" the reactions generating H 2 O and NH 3 , we would get x H 2 + y O 2 + z N 2 + u H 2 â v H 2 O + w NH 3 (8) but ( x , y , z , u , v , w ) = (2, 1, 1, 3, 2, 2) does not represent a unique correct equation; for instance, (4, 2, 1, 3, 4, 2) and (4, 2, 3, 9, 4, 6) are also "correct" according to the above definition! However, we guarantee that every chemical equation we give you will lead to a unique correct equation by adjusting their coefficients. In other words, we guarantee that (i) every chemical equation can be balanced with positive coefficients, and that (ii) all balanced equations of the original equation can be obtained by multiplying the coefficients of a unique correct equation by a positive integer. Input The input is a sequence of chemical equations (without coefficients) of the following syntax in the Backus-Naur Form: <chemical_equation> ::= <molecule_sequence> "->" <molecule_sequence> <molecule_sequence> ::= <molecule> | <molecule> "+" <molecule_sequence> <molecule> ::= <group> | <group> <molecule> <group> ::= <unit_group> | <unit_group> <number> <unit_group> ::= <chemical_element> | "(" <molecule> ")" <chemical_element> ::= <uppercase_letter> | <uppercase_letter> <lowercase_letter> <uppercase_letter> ::= "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z" <lowercase_letter> ::= "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z" <number> ::= <non_zero_digit> | <non_zero_digit> <digit> <non_zero_digit> ::= "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | <digit> ::= "0" | <non_zero_digit> Each chemical equation is followed by a period and a newline. No other characters such as spaces do not appear in the input. For instance, the equation C a (OH) 2 + CO 2 â C a CO 3 + H 2 O is represented as Ca(OH)2+CO2->CaCO3+H2O. Each chemical equation is no more than 80 characters long, and as the above syntax implies, the <number>'s are less than 100. Parentheses may be used but will not be nested (maybe a good news to some of you!). Each side of a chemical equation consists of no more than 10 top-level molecules. The coefficients that make the equations correct will not exceed 40000. The chemical equations in the input have been chosen so that 32-bit integer arithmetic would suffice with appropriate precautions against possible arithmetic overflow. You are free to use 64-bit arithmetic, however. The end of the input is indicated by a line consisting of a single period. Note that our definition of <chemical_element> above allows chemical elements that do not exist or unknown as of now, and excludes known chemical elements with three-letter names (e.g., ununbium (Uub), with the atomic number 112). Output For each chemical equation, output a line containing the sequence of positive integer coefficients that make the chemical equation correct . Numbers in a line must be separated by a single space. No extra characters should appear in the output. Sample Input N2+H2->NH3. Na+Cl2->NaCl. Ca(OH)2+CO2->CaCO3+H2O. CaCl2+AgNO3->Ca(NO3)2+AgCl. C2H5OH+O2->CO2+H2O. C4H10+O2->CO2+H2O. A12B23+C34D45+ABCD->A6D7+B8C9. A98B+B98C+C98->A98B99C99. A2+B3+C5+D7+E11+F13->ABCDEF. . Output for the Sample Input 1 3 2 2 1 2 1 1 1 1 1 2 1 2 1 3 2 3 2 13 8 10 2 123 33042 5511 4136 1 1 1 1 15015 10010 6006 4290 2730 2310 30030
| 38,858
|
Problem I: Wind Passages Wind Corridor is a covered passageway where strong wind is always blowing. It is a long corridor of width W, and there are several pillars in it. Each pillar is a right prism and its face is a polygon (not necessarily convex). In this problem, we consider two-dimensional space where the positive x -axis points the east and the positive y -axis points the north. The passageway spans from the south to the north, and its length is infinity. Specifically, it covers the area 0 †x †W . The outside of the passageway is filled with walls. Each pillar is expressed as a polygon, and all the pillars are located within the corridor without conflicting or touching each other. Wind blows from the south side of the corridor to the north. For each second, w unit volume of air can be flowed at most if the minimum width of the path of the wind is w . Note that the path may fork and merge, but never overlaps with pillars and walls. Your task in this problem is to write a program that calculates the maximum amount of air that can be flowed through the corridor per second. Input The input consists of multiple datasets. Each dataset has the following format: The first line of the input contains two integers W and N . W is the width of the corridor, and N is the number of pillars. W and N satisfy the following condition: 1 †W †10 4 and 0 †N †200. Then, N specifications of each pillar follow. Each specification starts with a line that contains a single integer M , which is the number of the vertices of a polygon (3 †M †40). The following M lines describe the shape of the polygon. The i -th line (1 †i †M ) contains two integers x i and y i that denote the coordinate of the i -th vertex (0 < x i < W , 0 < y i < 10 4 ). The last dataset is followed by a line containing two zeros. This line is not a part of any dataset and should not be processed. Output For each dataset, your program should print a line that contains the maximum amount of air flow per second, in unit volume. The output may contain arbitrary number of digits after the decimal point, but the absolute error must not exceed 10 -6 . Sample Input 5 2 4 1 1 1 2 2 2 2 1 4 3 3 3 4 4 4 4 3 0 0 Output for the Sample Input 3.41421356
| 38,859
|
E - Parentheses Problem Statement You are given $n$ strings $\mathit{str}_1, \mathit{str}_2, \ldots, \mathit{str}_n$, each consisting of ( and ) . The objective is to determine whether it is possible to permute the $n$ strings so that the concatenation of the strings represents a valid string. Validity of strings are defined as follows: The empty string is valid. If $A$ and $B$ are valid, then the concatenation of $A$ and $B$ is valid. If $A$ is valid, then the string obtained by putting $A$ in a pair of matching parentheses is valid. Any other string is not valid. For example, "()()" and "(())" are valid, while "())" and "((()" are not valid. Input The first line of the input contains an integer $n$ ($1 \leq n \leq 100$), representing the number of strings. Then $n$ lines follow, each of which contains $\mathit{str}_i$ ($1 \leq \lvert \mathit{str}_i \rvert \leq 100$). All characters in $\mathit{str}_i$ are ( or ) . Output Output a line with "Yes" (without quotes) if you can make a valid string, or "No" otherwise. Sample Input 1 3 ()(()(( ))()()(() )())(()) Output for the Sample Input 1 Yes Sample Input 2 2 ))()(( ))((())( Output for the Sample Input 2 No
| 38,860
|
Problem C: Weaker than Planned The committee members of the Kitoshima programming contest had decided to use crypto-graphic software for their secret communication. They had asked a company, Kodai Software, to develop cryptographic software that employed a cipher based on highly sophisticated mathematics. According to reports on IT projects, many projects are not delivered on time, on budget, with required features and functions. This applied to this case. Kodai Software failed to implement the cipher by the appointed date of delivery, and asked to use a simpler version that employed a type of substitution cipher for the moment. The committee members got angry and strongly requested to deliver the full specification product, but they unwillingly decided to use this inferior product for the moment. In what follows, we call the text before encryption, plaintext, and the text after encryption, ciphertext . This simple cipher substitutes letters in the plaintext, and its substitution rule is specified with a set of pairs. A pair consists of two letters and is unordered, that is, the order of the letters in the pair does not matter. A pair (A, B) and a pair (B, A) have the same meaning. In one substitution rule, one letter can appear in at most one single pair. When a letter in a pair appears in the plaintext, the letter is replaced with the other letter in the pair. Letters not specified in any pairs are left as they are. For example, by substituting the plaintext ABCDEFGHIJKLMNOPQRSTUVWXYZ with the substitution rule {(A, Z), (B, Y)} results in the following ciphertext. ZYCDEFGHIJKLMNOPQRSTUVWXBA This may be a big chance for us, because the substitution rule seems weak against cracking. We may be able to know communications between committee members. The mission here is to develop a deciphering program that finds the plaintext messages from given ciphertext messages. A ciphertext message is composed of one or more ciphertext words. A ciphertext word is generated from a plaintext word with a substitution rule. You have a list of candidate words containing the words that can appear in the plaintext; no other words may appear. Some words in the list may not actually be used in the plaintext. There always exists at least one sequence of candidate words from which the given ciphertext is obtained by some substitution rule. There may be cases where it is impossible to uniquely identify the plaintext from a given ciphertext and the list of candidate words. Input The input consists of multiple datasets, each of which contains a ciphertext message and a list of candidate words in the following format. n word 1 . . . word n sequence n in the first line is a positive integer, representing the number of candidate words. Each of the next n lines represents one of the candidate words. The last line, sequence, is a sequence of one or more ciphertext words separated by a single space and terminated with a period. You may assume the number of characters in each sequence is more than 1 and less than or equal to 80 including spaces and the period. The number of candidate words in the list, n , does not exceed 20. Only 26 uppercase letters, A to Z, are used in the words and the length of each word is from 1 to 20, inclusive. A line of a single zero indicates the end of the input. Output For each dataset, your program should print the deciphered message in a line. Two adjacent words in an output line should be separated by a single space and the last word should be followed by a single period. When it is impossible to uniquely identify the plaintext, the output line should be a single hyphen followed by a single period. Sample Input 4 A AND CAT DOG Z XUW ZVX Z YZT. 2 AZ AY ZA. 2 AA BB CC. 16 A B C D E F G H I J K L M N O ABCDEFGHIJKLMNO A B C D E F G H I J K L M N O ABCDEFGHIJKLMNO. 0 Output for the Sample Input A DOG AND A CAT. AZ. -. A B C D E F G H I J K L M N O ABCDEFGHIJKLMNO.
| 38,861
|
Score : 200 points Problem Statement Kurohashi has never participated in AtCoder Beginner Contest (ABC). The next ABC to be held is ABC N (the N -th ABC ever held). Kurohashi wants to make his debut in some ABC x such that all the digits of x in base ten are the same. What is the earliest ABC where Kurohashi can make his debut? Constraints 100 \leq N \leq 999 N is an integer. Input Input is given from Standard Input in the following format: N Output If the earliest ABC where Kurohashi can make his debut is ABC n , print n . Sample Input 1 111 Sample Output 1 111 The next ABC to be held is ABC 111 , where Kurohashi can make his debut. Sample Input 2 112 Sample Output 2 222 The next ABC to be held is ABC 112 , which means Kurohashi can no longer participate in ABC 111 . Among the ABCs where Kurohashi can make his debut, the earliest one is ABC 222 . Sample Input 3 750 Sample Output 3 777
| 38,862
|
Score : 500 points Problem Statement We have N locked treasure boxes, numbered 1 to N . A shop sells M keys. The i -th key is sold for a_i yen (the currency of Japan), and it can unlock b_i of the boxes: Box c_{i1} , c_{i2} , ... , c_{i{b_i}} . Each key purchased can be used any number of times. Find the minimum cost required to unlock all the treasure boxes. If it is impossible to unlock all of them, print -1 . Constraints All values in input are integers. 1 \leq N \leq 12 1 \leq M \leq 10^3 1 \leq a_i \leq 10^5 1 \leq b_i \leq N 1 \leq c_{i1} < c_{i2} < ... < c_{i{b_i}} \leq N Input Input is given from Standard Input in the following format: N M a_1 b_1 c_{11} c_{12} ... c_{1{b_1}} : a_M b_M c_{M1} c_{M2} ... c_{M{b_M}} Output Print the minimum cost required to unlock all the treasure boxes. If it is impossible to unlock all of them, print -1 . Sample Input 1 2 3 10 1 1 15 1 2 30 2 1 2 Sample Output 1 25 We can unlock all the boxes by purchasing the first and second keys, at the cost of 25 yen, which is the minimum cost required. Sample Input 2 12 1 100000 1 2 Sample Output 2 -1 We cannot unlock all the boxes. Sample Input 3 4 6 67786 3 1 3 4 3497 1 2 44908 3 2 3 4 2156 3 2 3 4 26230 1 2 86918 1 3 Sample Output 3 69942
| 38,864
|
人æ°ã®åºåºã¯? äŒæŽ¥è¥æŸåžã§ã¯ãæ¯å¹Ž1æ10æ¥ã«ã忥åžããšããååžããããŸãããã®åæ¥åžã¯ãçŽ600å¹Žã®æŽå²ãããäŒæŽ¥å°æ¹æå€§ã®ååžã§ããäŒæŽ¥å°æ¹ã§ã¯ã銎æã¿ã®çžèµ·ç©ã§ãããèµ·ãäžããå°æ³åž«(ãããããããŒã)ã売ãããŠããããšã§ãããç¥ãããŠããŸããèµ·ãäžããå°æ³åž«ã¯ã倧ãã3cm çšåºŠã®éå¿ãåºã«ãã匵ãåã§ã転ãããŠãããã«èµ·ããããããšãããã®ååãä»ããŸãããåå®¶åºã§ã¯ãå¿
ãå®¶æããäžåå€ãè²·ã£ãŠç¥æ£ã«äŸããŸãããã®äžåã¯ã ãå®¶æãå¢ããããã«ãããåãèè² ã£ãŠãããããšã®æå³ããããŸãã 忥åžå®è¡å§å¡äŒã§ã¯ã次åã®åæ¥åžã«åããŠãèµ·ãäžããå°æ³åž«ã®è²©å£²åæ°ãäžçªå€ãåºåºã調ã¹ãããšã«ãªããŸãããä»å¹Žã®åºåºã®æ°ã¯5åº(AãBãCãDãE:åè§è±å)ã§ãè²©å£²åæ°ã¯ãååãšååŸã«åããŠåæ¥åžå®è¡å§å¡äŒã«å ±åãããŠããŸãã ååºåºã®æ
å ±ãå
¥åãšããäžæ¥ã®è²©å£²åæ°ãäžçªå€ãåºåºã®ååãšãã®åæ°ãåºåããããã°ã©ã ãäœæããŠãã ããã Input è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒããµãã€ã®è¡ã§ç€ºãããŸãã åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã s1 A s2 A s1 B s2 B s1 C s2 C s1 D s2 D s1 E s2 E i è¡ç®ã«ãããããA, B, C, D, E ã®ååã®è²©å£²åæ° s1 i ãšååŸã®è²©å£²åæ° s2 i (1 †s1 i , s2 i †10000) ãäžããããŸãããã ããäžæ¥ã®è²©å£²åæ°ãåãåºåºã¯ç¡ããã®ãšããŸãã ããŒã¿ã»ããã®æ°ã¯ 100 ãè¶
ããŸããã Output ããŒã¿ã»ããããšã«ãäžæ¥ã®è²©å£²åæ°ã®äžçªå€ãåºåºã®ååãšãã®åæ°ãïŒè¡ã«åºåããŸãã Sample Input 1593 4311 4321 2155 1256 6421 5310 1455 2152 5421 1549 3386 4528 3719 1234 4321 3330 3109 2739 2199 0 0 Output for the Sample Input C 7677 B 8247
| 38,865
|
Includes For given two sequneces $A = \{a_0, a_1, ..., a_{n-1}\}$ and $B = \{b_0, b_1, ..., b_{m-1}\}$, determine whether all elements of $B$ are included in $A$. Note that, elements of $A$ and $B$ are sorted by ascending order respectively. Input The input is given in the following format. $n$ $a_0 \; a_1 \; ,..., \; a_{n-1}$ $m$ $b_0 \; b_1 \; ,..., \; b_{m-1}$ The number of elements in $A$ and its elements $a_i$ are given in the first and second lines respectively. The number of elements in $B$ and its elements $b_i$ are given in the third and fourth lines respectively. Output Print 1 , if $A$ contains all elements of $B$, otherwise 0 . Constraints $1 \leq n, m \leq 200,000$ $-1,000,000,000 \leq a_0 < a_1 < ... < a_{n-1} \leq 1,000,000,000$ $-1,000,000,000 \leq b_0 < b_1 < ... < b_{m-1} \leq 1,000,000,000$ Sample Input 1 4 1 2 3 4 2 2 4 Sample Output 1 1 Sample Input 2 4 1 2 3 4 3 1 2 5 Sample Output 2 0
| 38,866
|
G: åŒã®åãåã åé¡ é·ã $N$ ã®æ°åŒ $S$ ãäžããããã æ°åŒã¯ã以äžã® BNF ã§ç€ºããã圢åŒã«ãªã£ãŠããã <expr> ::= <number> | <expr> <op> <expr> <op> ::= â^â | â&â | â|â <number> ã¯ã $0$ ä»¥äž $2^{31}-1$ 以äžã®æŽæ°ã衚ãã æŒç®åãâ^â â&â â|â ã¯ãããããæä»çè«çåãè«çç©ãè«çåã衚ãã æŒç®åã®åªå
é äœã¯ä»¥äžã®éãã§ããã é« â^â > â&â > â|â äœ åºé $[i, j]$ ã $Q$ åäžããããã $S_i, \dots , S_j$ ã®èšç®çµæãåºåããã ãªããæ°åŒ $S_i, \dots , S_j$ ãäžèšã®BNFã§ç€ºããã圢åŒã§ããããšã¯ä¿èšŒãããããŸããæ°åŒã«ãŒãè©°ããããå€ãå«ãŸããããšã¯ãªãã å¶çŽ $1 \leq N, Q \leq 10^5$ $N = |S| \ \ \ \ \ |S|$ ã¯æååã®é·ãã衚ãã $0 \leq i \leq j < N$ å
¥ååœ¢åŒ å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã $N$ $S$ $Q$ $i_1\ j_1$ $\vdots$ $i_Q\ j_Q$ åºå $S_i, \dots , S_j$ ã®èšç®çµæãåºåããã ãŸããæ«å°Ÿã«æ¹è¡ãåºåããã ãµã³ãã« ãµã³ãã«å
¥å 1 7 9^2&1|2 4 0 6 0 2 2 6 4 4 ãµã³ãã«åºå 1 3 11 2 1 ãµã³ãã«å
¥å 2 13 3423&423^1234 3 2 12 5 9 9 12 ãµã³ãã«åºå 2 21 422 1234 ãµã³ãã«å
¥å 3 7 1234567 3 0 0 0 1 4 6 ãµã³ãã«åºå 3 1 12 567
| 38,867
|
Dungeon Creation The king demon is waiting in his dungeon to defeat a brave man. His dungeon consists of H \times W grids. Each cell is connected to four (i.e. north, south, east and west) neighboring cells and some cells are occupied by obstacles. To attack the brave man, the king demon created and sent a servant that walks around in the dungeon. However, soon the king demon found that the servant does not work as he wants. The servant is too dumb. If the dungeon had cyclic path, it might keep walking along the cycle forever. In order to make sure that the servant eventually find the brave man, the king demon decided to eliminate all cycles by building walls between cells. At the same time, he must be careful so that there is at least one path between any two cells not occupied by obstacles. Your task is to write a program that computes in how many ways the kind demon can build walls. Input The first line of each test case has two integers H and W ( 1 \leq H \leq 500 , 1 \leq W \leq 15 ), which are the height and the width of the dungeon. Following H lines consist of exactly W letters each of which is '.' (there is no obstacle on the cell) or '#' (there is an obstacle). You may assume that there is at least one cell that does not have an obstacle. The input terminates when H = 0 and W = 0 . Your program must not output for this case. Output For each test case, print its case number and the number of ways that walls can be built in one line. Since the answer can be very big, output in modulo 1,000,000,007. Sample Input 2 2 .. .. 3 3 ... ... ..# 0 0 Output for the Sample Input Case 1: 4 Case 2: 56
| 38,868
|
Problem C: Online Quizu System ICPC (Internet Contents Providing Company) is working on a killer game named Quiz Millionaire Attack. It is a quiz system played over the Internet. You are joining ICPC as an engineer, and you are responsible for designing a protocol between clients and the game server for this system. As bandwidth assigned for the server is quite limited, data size exchanged between clients and the server should be reduced as much as possible. In addition, all clients should be well synchronized during the quiz session for a simultaneous play. In particular, much attention should be paid to the delay on receiving packets. To verify that your protocol meets the above demands, you have decided to simulate the communication between clients and the server and calculate the data size exchanged during one game. A game has the following process. First, players participating and problems to be used are fixed. All players are using the same client program and already have the problem statements downloaded, so you donât need to simulate this part. Then the game begins. The first problem is presented to the players, and the players answer it within a fixed amount of time. After that, the second problem is presented, and so forth. When all problems have been completed, the game ends. During each problem phase, the players are notified of what other players have done. Before you submit your answer, you can know who have already submitted their answers. After you have submitted your answer, you can know what answers are submitted by other players. When each problem phase starts, the server sends a synchronization packet for problem-start to all the players, and begins a polling process. Every 1,000 milliseconds after the beginning of polling, the server checks whether it received new answers from the players strictly before that moment, and if there are any, sends a notification to all the players: If a player hasnât submitted an answer yet, the server sends it a notification packet type A describing othersâ answers about the newly received answers. If a player is one of those who submitted the newly received answers, the server sends it a notification packet type B describing othersâ answers about all the answers submitted by other players (i.e. excluding the player him/herselfâs answer) strictly before that moment. If a player has already submitted an answer, the server sends it a notification packet type B describing othersâ answers about the newly received answers. Note that, in all above cases, notification packets (both types A and B) must contain information about at least one player, and otherwise a notification packet will not be sent. When 20,000 milliseconds have passed after sending the synchronization packet for problem-start , the server sends notification packets of type A or B if needed, and then sends a synchronization packet for problem-end to all the players, to terminate the problem. On the other hand, players will be able to answer the problem after receiving the synchronization packet for problem-start and before receiving the synchronization packet for problem-end . Answers will be sent using an answer packet . The packets referred above have the formats shown by the following tables. Input The input consists of multiple test cases. Each test case begins with a line consisting of two integers M and N (1 †M , N †100), denoting the number of players and problems, respectively. The next line contains M non-negative integers D 0 , D 1 , . . . , D M - 1 , denoting the communication delay between each players and the server (players are assigned IDâs ranging from 0 to M - 1, inclusive). Then follow N blocks describing the submissions for each problem. Each block begins with a line containing an integer L , denoting the number of players that submitted an answer for that problem. Each of the following L lines gives the answer from one player, described by three fields P , T , and A separated by a whitespace. Here P is an integer denoting the player ID, T is an integer denoting the time elapsed from the reception of synchronization packet for problem-start and the submission on the playerâs side, and A is an alphanumeric string denoting the playerâs answer, whose length is between 1 and 9, inclusive. Those L lines may be given in an arbitrary order. You may assume that all answer packets will be received by the server within 19,999 milliseconds (inclusive) after sending synchronization packet for problem-start . The input is terminated by a line containing two zeros. Output For each test case, you are to print M + 1 lines. In the first line, print the data size sent and received by the server, separated by a whitespace. In the next M lines, print the data size sent and received by each player, separated by a whitespace, in ascending order of player ID. Print a blank line between two consecutive test cases. Sample Input 3 2 1 2 10 3 0 3420 o 1 4589 o 2 4638 x 3 1 6577 SUZUMIYA 2 7644 SUZUMIYA 0 19979 YASUZUMI 4 2 150 150 150 150 4 0 1344 HOGEHOGE 1 1466 HOGEHOGE 2 1789 HOGEHOGE 3 19100 GEHO 2 2 1200 SETTEN 3 700 SETTEN 0 0 Output for the Sample Input 177 57 19 58 19 57 19 62 253 70 13 58 13 58 24 66 20 71
| 38,870
|
éšæŽ»åèª¿æ» A 髿 ¡ã®çåŸäŒé·ã§ããæã¯ãA 髿 ¡ã®çåŸãã©ã®éšæŽ»åã«æå±ããŠãããã調æ»ããããšã«ãããA髿 ¡ã«ã¯ 1 ãã N ã®çªå·ãä»ãããã N 人ã®çåŸãšã1 ãã M ã®çªå·ãä»ãããã M çš®é¡ã®éšæŽ»åããããåéšæŽ»åã«äººæ°å¶éã¯ãªãã0 人ã®éšæŽ»åãããããããã ããA 髿 ¡ã®æ ¡åã§ã¯çåŸã¯ã²ãšã€ã®éšæŽ»åãŸã§ããæå±ã§ããªããçåŸã¯å
šå¡ãã®æ ¡åãå®ã£ãŠããã æã¯çåŸäŒå¡ã«èª¿æ»ãäŸé Œããåè¡ã次ã®ããããã§ãããã㪠K è¡ã®èšé²ãå
¥æããã çåŸ a ãšçåŸ b ã¯åãéšæŽ»åã«æå±ããŠããã çåŸ c ã¯éšæŽ»å x ã«æå±ããŠããã ãããããã®èšé²ã«ã¯èª°ããæ ¡åéåã«ãªã£ãŠããŸããããªççŸããããããããªããæã¯ïŒè¡ç®ããé ã«èŠãŠãããççŸããããšå€æã§ããæåã®è¡ãæ¢ãããšã«ããã K è¡ã®èšé²ãäžãããããšããççŸããããšå€æã§ããæåã®è¡ã®çªå·ãæ±ããããã°ã©ã ãäœæããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã N M K record 1 record 2 : record K ïŒè¡ç®ã«çåŸã®äººæ° N (1 †N †100000)ãéšæŽ»åã®çš®é¡ã®æ° M (1 †M †100000)ãèšé²ã®è¡æ° K (1 †K †200000) ãäžãããããç¶ã K è¡ã«èšé²ã®åè¡ record i ãã以äžã®ããããã®åœ¢åŒã§äžããããã 1 a b ãŸã㯠2 c x å
é ã®æ°åãã1ãã®ãšããçåŸ a (1 †a †N ) ãšçåŸ b (1 †b †N ) ãåãéšæŽ»åã«æå±ããŠããããšã瀺ãããã ãã a â b ã§ããã å
é ã®æ°åãã2ãã®ãšããçåŸ c (1 †c †N ) ãéšæŽ»å x (1 †x †M ) ã«æå±ããŠããããšã瀺ãã Output ççŸããããšå€æã§ããæåã®è¡ã®çªå·ãïŒè¡ã«åºåãããèŠã€ãããªãå Žå㯠0 ãïŒè¡ã«åºåããã Sample Input 1 3 2 5 1 1 2 1 2 3 2 1 1 2 3 2 2 2 1 Sample Output 1 4 Sample Input 2 3 2 4 1 1 2 2 1 1 2 3 2 2 2 1 Sample Output 2 0 Sample Input 3 3 2 2 1 1 2 2 1 1 Sample Output 3 0
| 38,871
|
Tree Walk Binary trees are defined recursively. A binary tree T is a structure defined on a finite set of nodes that either contains no nodes, or is composed of three disjoint sets of nodes: - a root node. - a binary tree called its left subtree. - a binary tree called its right subtree. Your task is to write a program which perform tree walks (systematically traverse all nodes in a tree) based on the following algorithms: Print the root, the left subtree and right subtree (preorder). Print the left subtree, the root and right subtree (inorder). Print the left subtree, right subtree and the root (postorder). Here, the given binary tree consists of n nodes and evey node has a unique ID from 0 to n -1. Input The first line of the input includes an integer n , the number of nodes of the tree. In the next n linen, the information of each node is given in the following format: id left right id is the node ID, left is ID of the left child and right is ID of the right child. If the node does not have the left (right) child, the left ( right ) is indicated by -1 Output In the 1st line, print " Preorder ", and in the 2nd line print a list of node IDs obtained by the preorder tree walk. In the 3rd line, print " Inorder ", and in the 4th line print a list of node IDs obtained by the inorder tree walk. In the 5th line, print " Postorder ", and in the 6th line print a list of node IDs obtained by the postorder tree walk. Print a space character before each node ID. Constraints 1 †n †25 Sample Input 1 9 0 1 4 1 2 3 2 -1 -1 3 -1 -1 4 5 8 5 6 7 6 -1 -1 7 -1 -1 8 -1 -1 Sample Output 1 Preorder 0 1 2 3 4 5 6 7 8 Inorder 2 1 3 0 6 5 7 4 8 Postorder 2 3 1 6 7 5 8 4 0 Reference Introduction to Algorithms, Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. The MIT Press.
| 38,872
|
C : 壺 / Pots å顿 ããã« N åã®äžæè°ãªåœ¢ã®å£ºãããïŒ i çªç®ã®å£ºã¯ K_i åã®çŽåæ±ãäžããé ã«éçŽã«ç¹ãã圢ç¶ã§ããïŒ ç¹ãã£ãŠããé çªã¯å€ããããšãã§ããªãïŒ A æ°ã¯äœç© M ã®æ°Žãæã£ãŠããïŒ ãã®æ°Žãããããã®å£ºã«å¥œããªéãã€ã«åããŠæ³šãïŒ æ°Žãå
šãå
¥ã£ãŠããªã壺ãååšããŠãæ§ããªãïŒ ãŸãïŒå
šãŠã®å£ºãæ°Žã§æºãããããšãïŒããä»¥äžæ°Žã泚ãäºã¯ã§ããªãïŒããããã®å£ºã®æ°Žé¢ã®é«ãã®ç·åã®æå€§å€ãæ±ããïŒ å
¥å N \ M K_1 \ S_{11} \ H_{11} \ ⊠\ S_{1 K_1} \ H_{1 K_1} K_2 \ S_{21} \ H_{21} \ ⊠\ S_{2 K_2} \ H_{2 K_2} ⊠K_N \ S_{N1} \ H_{N1} \ ⊠\ S_{N K_N} \ H_{N K_N} 1 è¡ç®ã« N, M ãïŒ 1+i è¡ç®ã«ã¯ i çªç®ã®å£ºã®æ
å ±ãå
¥åãããïŒ K_i ã¯çŽåæ±ã®æ°ã§ããïŒ S_{ij}, H_{ij} ã¯ããããå£ºãæ§æããäžãã j çªç®ã®çŽåæ±ã®åºé¢ç©ãšé«ãã§ããïŒ å¶çŽ æŽæ°ã§ãã 1 †N †200 1 †M †200 1 †K_i †20 1 †S_{ij} †20 1 †H_{ij} †20 åºå çãã 1 è¡ã§åºåããïŒ 0.00001 以äžã®çµ¶å¯Ÿèª€å·®ãå«ãã§ãè¯ãïŒ ãµã³ãã« ãµã³ãã«å
¥å1 2 15 2 3 3 7 2 2 7 1 1 4 ãµã³ãã«åºå1 6.33333333 ãµã³ãã«å
¥å2 2 14 1 2 4 2 5 2 1 4 ãµã³ãã«åºå2 6 ãµã³ãã« 1, 2 ã®å
¥åºåãå³ç€ºãããšæ¬¡ã®ããã«ãªãïŒ ãµã³ãã«å
¥å3 2 25 4 8 9 1 9 6 5 2 8 4 1 7 4 4 1 6 4 3 ãµã³ãã«åºå3 13
| 38,874
|
Problem A: Pablo Squarson's Headache Pablo Squarson is a well-known cubism artist. This year's theme for Pablo Squarson is "Squares". Today we are visiting his studio to see how his masterpieces are given birth. At the center of his studio, there is a huuuuuge table and beside it are many, many squares of the same size. Pablo Squarson puts one of the squares on the table. Then he places some other squares on the table in sequence. It seems his methodical nature forces him to place each square side by side to the one that he already placed on, with machine-like precision. Oh! The first piece of artwork is done. Pablo Squarson seems satisfied with it. Look at his happy face. Oh, what's wrong with Pablo? He is tearing his hair! Oh, I see. He wants to find a box that fits the new piece of work but he has trouble figuring out its size. Let's help him! Your mission is to write a program that takes instructions that record how Pablo made a piece of his artwork and computes its width and height. It is known that the size of each square is 1. You may assume that Pablo does not put a square on another. I hear someone murmured "A smaller box will do". No, poor Pablo, shaking his head, is grumbling "My square style does not seem to be understood by illiterates". Input The input consists of a number of datasets. Each dataset represents the way Pablo made a piece of his artwork. The format of a dataset is as follows. N n 1 d 1 n 2 d 2 ... n N -1 d N -1 The first line contains the number of squares (= N ) used to make the piece of artwork. The number is a positive integer and is smaller than 200. The remaining ( N -1) lines in the dataset are square placement instructions. The line â n i d i â indicates placement of the square numbered i (†N -1). The rules of numbering squares are as follows. The first square is numbered "zero". Subsequently placed squares are numbered 1, 2, ..., ( N -1). Note that the input does not give any placement instruction to the first square, which is numbered zero. A square placement instruction for the square numbered i , namely â n i d i â, directs it to be placed next to the one that is numbered n i , towards the direction given by d i , which denotes leftward (= 0), downward (= 1), rightward (= 2), and upward (= 3). For example, pieces of artwork corresponding to the four datasets shown in Sample Input are depicted below. Squares are labeled by their numbers. The end of the input is indicated by a line that contains a single zero. Output For each dataset, output a line that contains the width and the height of the piece of artwork as decimal numbers, separated by a space. Each line should not contain any other characters. Sample Input 1 5 0 0 0 1 0 2 0 3 12 0 0 1 0 2 0 3 1 4 1 5 1 6 2 7 2 8 2 9 3 10 3 10 0 2 1 2 2 2 3 2 2 1 5 1 6 1 7 1 8 1 0 Output for the Sample Input 1 1 3 3 4 4 5 6
| 38,875
|
å®¶åºèåã«éèãæ€ããããšã«ããŸãããn ç²ã®çš®ããã£ãã®ã§1æ¥ã«1ç²ãã€ãn æ¥ãã㊠n ç²ã®çš®ããŸããŸãããã©ã®çš®ãããèœãåºãŠããããããšè²ã£ãŠããŸããåç©«ã®ææãåŸ
ã¡é ãããã®ã§ãã ããæ¥ããã€ãã®ããã«èã«æ°ŽãããããŠãããšãããããªããšã«æ°ã¥ããŸãããn æ¬ã®éèã®èãããã¯ããªã®ã«ã1æ¬å€ãã®ã§ããéèãçããŠããŠããŸããŸãããçŽã¡ã«åŒã£ãæãããã®ã§ãããå°ã£ãããšã«ã©ã®èããã䌌ãŠããŠãéèãšéèã®èŠåããã€ããŸããã æãããã«ãªãã®ã¯ãéèã®æé·é床ã§ãããã®éèã¯ãçš®ããŸããŠãããã£ãšã1æ¥ã«æ±ºãŸã£ãé·ãã ã䌞ã³ç¶ããã®ã§ãããããããã®ã決ãŸã£ãé·ãããšããã®ãäœã»ã³ãã¡ãŒãã«ãªã®ãã¯ããããŸããããŸããæåã®çš®ãäœæ¥åã«ãŸããã®ããå¿ããŠããŸããŸãããèã¯äžåã«äžŠãã§ããŸãããå¯äžèŠããŠããã®ã¯ãçš®ããŸããšãæ¯æ¥äžç²ãã€å³ããé ã«ãŸããŠãã£ãããšã ãã§ãã nïŒïŒæ¬ã®èã®é·ããå
¥åããéèã®é·ããåºåããããã°ã©ã ãäœæããŠäžããã å
¥å å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªããå
¥åã®çµããã¯ãŒãïŒã€è¡ã§ç€ºããããå
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã n h 1 h 2 h 3 ... h n+1 ïŒè¡ç®ã® n (4 †n †100) ã¯éèã®èã®æ°ãè¡šãæŽæ°ã§ãããïŒè¡ç®ã¯ïŒã€ã®ç©ºçœã§åºåããã n+1 åã®æŽæ°ãå«ã¿ã h i (1 †h i †10 9 )ã¯å·Šããiçªç®ã®èã®é·ãã瀺ãã h 1 h 2 ... h n+1 ãçå·®æ°åã«ãªã£ãŠãããããªå
¥åã¯äžããããªãã ããŒã¿ã»ããã®æ°ã¯ 500 ãè¶
ããªãã åºå åããŒã¿ã»ããããšã«éèã®é·ããåºåãã ã å
¥åäŸ 5 1 2 3 6 4 5 6 1 3 6 9 12 15 18 4 5 7 9 11 12 0 åºåäŸ 6 1 12
| 38,876
|
Score : 600 points Problem Statement We have a tree with N vertices numbered 1 to N . The i -th edge in this tree connects Vertex a_i and Vertex b_i . Consider painting each of these edges white or black. There are 2^{N-1} such ways to paint the edges. Among them, how many satisfy all of the following M restrictions? The i -th (1 \leq i \leq M) restriction is represented by two integers u_i and v_i , which mean that the path connecting Vertex u_i and Vertex v_i must contain at least one edge painted black. Constraints 2 \leq N \leq 50 1 \leq a_i,b_i \leq N The graph given in input is a tree. 1 \leq M \leq \min(20,\frac{N(N-1)}{2}) 1 \leq u_i < v_i \leq N If i \not= j , either u_i \not=u_j or v_i\not=v_j All values in input are integers. Input Input is given from Standard Input in the following format: N a_1 b_1 : a_{N-1} b_{N-1} M u_1 v_1 : u_M v_M Output Print the number of ways to paint the edges that satisfy all of the M conditions. Sample Input 1 3 1 2 2 3 1 1 3 Sample Output 1 3 The tree in this input is shown below: All of the M restrictions will be satisfied if Edge 1 and 2 are respectively painted (white, black), (black, white), or (black, black), so the answer is 3 . Sample Input 2 2 1 2 1 1 2 Sample Output 2 1 The tree in this input is shown below: All of the M restrictions will be satisfied only if Edge 1 is painted black, so the answer is 1 . Sample Input 3 5 1 2 3 2 3 4 5 3 3 1 3 2 4 2 5 Sample Output 3 9 The tree in this input is shown below: Sample Input 4 8 1 2 2 3 4 3 2 5 6 3 6 7 8 6 5 2 7 3 5 1 6 2 8 7 8 Sample Output 4 62 The tree in this input is shown below:
| 38,878
|
G: éšéããã¹ä¹ãæã èæ¯ 仿¥ã¯ AOR ã€ã«ã¡ããã«ãšã£ãŠåãšãªãããŒãã®æ¥ã ã AOR ã€ã«ã¡ããã¯é§
ãããã¹ãä¹ãç¶ããåŸ
ã¡åããå Žæã®ãã¹åã«åããäºå®ã§ããã AOR ã€ã«ã¡ãããé§
ã«çããæãäžå¹žã«ãéšãéã£ãŠãããåœåäºå®ããŠããçµè·¯ã§ã¯ãã¹ã®åŸ
ã¡æéã§æ¿¡ããŠããŸãããã£ããæŽãã身ã ããªã¿ãå°ç¡ãã«ãªã£ãŠããŸãå¯èœæ§ãããã ããã§ããã¹ã®åŸ
ã¡æéãæãå°ãªããªããããªçµè·¯ã§ãã¹åãŸã§åããããšã«ããã AOR ã€ã«ã¡ããã¯ãåŸ
ã¡åããå Žæã®ãã¹åã«çããŸã§ã«ã©ã®çšåºŠæ¿¡ããã®ãå¿é
ããŠããã åé¡ AOR ã€ã«ã¡ããã¯æå» $0$ ã« $S$ çªç®ã®ãã¹åã«ããããããã $G$ çªç®ã®ãã¹åãŸã§è¡ããããšèããŠããã ãã¹åã®åæ° $N$ ãšãç°ãªããã¹åå士ãç¹ã $M$ åã®çµè·¯ (â») ãäžããããã ãã¹åã«ã¯ããããã $1, \dots, N$ ã®çªå·ããµãããŠããã åçµè·¯ã¯ãåºçºå° $u$ ãç®çå° $v$ ãåºçºæå» $t$ ãæèŠæé $c$ ã® $4$ ã€ã®å€ãããªãã æå» $t$ ã«åºçºå° $u$ ã«ããã°ãã¹ã«ä¹ãããšãã§ããæå» $t + c$ ã«ç®çå° $v$ ãžå°çããã ãã¹ã«ä¹ã£ãŠããªãéã AOR ã€ã«ã¡ããã¯éšã«æ¿¡ããŠããŸãã éšã«ã¬ããæéãæå°ãšãªãçµè·¯ãéã $G$ çªç®ã®ãã¹åãžåããæãæå» $0$ ãã $G$ çªç®ã®ãã¹åã«çããŸã§ã®éã«éšã«æ¿¡ããæéã®åèšãåºåããã (â») ã°ã©ãçè«ã®çšèªã«ãããçµè·¯ãšã¯é ç¹ãšèŸºã®åã§ãããïŒããã§ã¯èŸºã®æå³ã§äœ¿ãããŠããããšã«æ³šæããŠã»ããã å¶çŽ $2 \le N \le 10^5$ $1 \le M \le 2 \times 10^5$ $1 \le S , G \le N$ $1 \le u_i , v_i \le N$ $0 \le t_i \le 10^5$ $1 \le c_i \le 10^5$ $S \neq G$ $u_i \neq v_i$ åºçºå° $u$ ãšç®çå° $v$ ãåãã§ãããããªçµè·¯ã¯ååšããªãã åºçºå° $u$ ãšç®çå° $v$ ãçµã¶çµè·¯ã¯è€æ°ååšããå Žåãããã ãã¹ã®ä¹ãéããä¹ãæãã«æéã¯ããããªããã®ãšããã $G$ çªç®ã®ãã¹åãžå°çããæéã¯åããªãã $S$ çªç®ã®ãã¹åãã $G$ çªç®ã®ãã¹åãžå°çã§ããããšã¯ä¿èšŒãããŠããã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããã $N \ M \ S \ G$ $u_1 \ v_1 \ t_1 \ c_1$ $\vdots$ $u_M \ v_M \ t_M \ c_M$ åºå éšã«æ¿¡ããæå°ã®æéã 1 è¡ã§åºåããããŸããæ«å°Ÿã«æ¹è¡ãåºåããã ãµã³ãã« å
¥åäŸ 1 2 2 1 2 1 2 10 100 1 2 5 500 åºåäŸ 1 5 å°çæéãé
ããŠããã§ããã ãéšã«æ¿¡ããªãçµè·¯ãéžã¶ã å
¥åäŸ 2 3 2 1 3 1 2 0 123 2 3 123 500 åºåäŸ 2 0 ä¹ãæãã«æéã¯ããããªãã
| 38,879
|
Problem I: Riffle Shuffle There are a number of ways to shuffle a deck of cards. Riffle shuffle is one such example. The following is how to perform riffle shuffle. There is a deck of n cards. First, we divide it into two decks; deck A which consists of the top half of it and deck B of the bottom half. Deck A will have one more card when n is odd. Next, c cards are pulled from bottom of deck A and are stacked on deck C, which is empty initially. Then c cards are pulled from bottom of deck B and stacked on deck C, likewise. This operation is repeated until deck A and B become empty. When the number of cards of deck A(B) is less than c , all cards are pulled. Finally we obtain shuffled deck C. See an example below: - A single riffle operation where n = 9, c = 3 for given deck [0 1 2 3 4 5 6 7 8] (right is top) - Step 0 deck A [4 5 6 7 8] deck B [0 1 2 3] deck C [] - Step 1 deck A [7 8] deck B [0 1 2 3] deck C [4 5 6] - Step 2 deck A [7 8] deck B [3] deck C [4 5 6 0 1 2] - Step 3 deck A [] deck B [3] deck C [4 5 6 0 1 2 7 8] - Step 4 deck A [] deck B [] deck C [4 5 6 0 1 2 7 8 3] shuffled deck [4 5 6 0 1 2 7 8 3] This operation, called riffle operation, is repeated several times. Write a program that simulates Riffle shuffle and answer which card will be finally placed on the top of the deck. Input The input consists of multiple data sets. Each data set starts with a line containing two positive integers n (1 †n †50) and r (1 †r †50); n and r are the number of cards in the deck and the number of riffle operations, respectively. r more positive integers follow, each of which represents a riffle operation. These riffle operations are performed in the listed order. Each integer represents c , which is explained above. The end of the input is indicated by EOF. The number of data sets is less than 100. Output For each data set in the input, your program should print the number of the top card after the shuffle. Assume that at the beginning the cards are numbered from 0 to n -1, from the bottom to the top. Each number should be written in a sparate line without any superfluous characters such as leading or following spaces. Sample Input 9 1 3 9 4 1 2 3 4 Output for the Sample Input 3 0
| 38,880
|
Problem F: Mysterious Maze A robot in a two-dimensional maze again. The maze has an entrance and an exit this time, though. Just as in the previous problem, the maze is made up of H à W grid cells, its upper side faces north, and each cell is either empty or wall. Unlike the previous, on the other hand, one of the empty cells is connected to the entrance and another to the exit. The robot is rather complex - there is some control, but not full. It is associated with a controller that has two buttons, namely forward and turn . The forward button moves the robot forward to the next cell, if possible. The robot can not move into a wall nor outside the maze. The turn button turns the robot as programmed . Here the program is a finite sequence of N commands, each of which is either 'L' (indicating a left turn) or 'R' (a right turn). The first turn follows the first command; the second turn follows the second command; similar for the following turns. The turn button stops working once the commands are exhausted; the forward button still works in such a case though. The robot always turns by 90 degrees at once. The robot is initially put on the entrance cell, directed to the north. Your mission is to determine whether it can reach the exit cell if controlled properly. Input The input is a sequence of datasets. Each dataset is formatted as follows. H W N s 1 ... s N c 1,1 c 1,2 ... c 1, W ... c H ,1 c H ,2 ... c H , W The first line of a dataset contains three integers H , W and N (1 †H , W †1,000, 1 †N †1,000,000). The second line contains a program of N commands. Each of the following H lines contains exactly W characters. Each of these characters represents a cell of the maze. " . " indicates empty, " # " indicates a wall, " S " indicates an entrance, and " G " indicates an exit. There is exactly one entrance cell and one exit cell. The end of input is indicated by a line with three zeros. Output For each dataset, output whether the robot can reach the exit in a line: " Yes " if it can or " No " otherwise (without quotes). Sample Input 2 2 1 L G. #S 2 2 2 RR G. .S 3 3 6 LLLLLL G#. ... .#S 0 0 0 Output for the Sample Input Yes No Yes
| 38,881
|
Score : 100 points Problem Statement There are N stones, numbered 1, 2, \ldots, N . For each i ( 1 \leq i \leq N ), the height of Stone i is h_i . Here, h_1 < h_2 < \cdots < h_N holds. There is a frog who is initially on Stone 1 . He will repeat the following action some number of times to reach Stone N : If the frog is currently on Stone i , jump to one of the following: Stone i + 1, i + 2, \ldots, N . Here, a cost of (h_j - h_i)^2 + C is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N . Constraints All values in input are integers. 2 \leq N \leq 2 \times 10^5 1 \leq C \leq 10^{12} 1 \leq h_1 < h_2 < \cdots < h_N \leq 10^6 Input Input is given from Standard Input in the following format: N C h_1 h_2 \ldots h_N Output Print the minimum possible total cost incurred. Sample Input 1 5 6 1 2 3 4 5 Sample Output 1 20 If we follow the path 1 â 3 â 5 , the total cost incurred would be ((3 - 1)^2 + 6) + ((5 - 3)^2 + 6) = 20 . Sample Input 2 2 1000000000000 500000 1000000 Sample Output 2 1250000000000 The answer may not fit into a 32-bit integer type. Sample Input 3 8 5 1 3 4 5 10 11 12 13 Sample Output 3 62 If we follow the path 1 â 2 â 4 â 5 â 8 , the total cost incurred would be ((3 - 1)^2 + 5) + ((5 - 3)^2 + 5) + ((10 - 5)^2 + 5) + ((13 - 10)^2 + 5) = 62 .
| 38,882
|
Planarian Regeneration Problem çãããããã©ããªã¢ãã£ãŠç¥ã£ãŠããŸããïŒ ãã©ããªã¢ãšã¯ãæ¥æ¬ã§ã¯å·ã®äžæµã®ç³ãæ¯èãªã©ã®è£ã«åŒµãä»ããŠçæ¯ããŠããæ°Žççç©ã§ãã ãã©ããªã¢ã®æãåªããèœåã¯ãã®ãåçèœåãã§ãããã©ããªã¢ã®åçèœåã¯èãããäŸãã°ãäžçåãããšãããããåçããæ°é±éåŸã«ã¯å
ã®å®å
šãªç¶æ
ã®ãã©ããªã¢ã3å¹ã§ãããããŸãã ãã®åºŠãäŒæŽ¥ã®å±±å¥¥ã®äžæµã«ãŠçºèŠãããæ°çš®ã®ãã©ããªã¢ã®å§¿ã¯é·æ¹åœ¢ãããŠããŠããã©ããªã¢ã¯ããæ³åã«ããåçããŸãã ãã®ãšãããã©ããªã¢ã¯äžã®å³ã®ããã«é
眮ããïŒã€ã®ææ®µã§ãã©ããªã¢ã®åæå®éšãè¡ããŸãã ãŸãïŒã€ç®ã®ææ®µãšããŠãåçŽæ¹åã«åãããšãèããŸããäžåºŠã®åæã§ã¯ããã¹ãŠã®æçãæ°Žå¹³æ¹åã®é·ãã(æçã®é ã«è¿ãéšå):(æçã®é ã«é ãéšå)= m : n ã«ãªãããã«åæããŸãããã®åäœã x åç¹°ãè¿ããŸãã æ¬¡ã«ïŒã€ç®ã®ææ®µãšããŠãæ°Žå¹³æ¹åã«åãããšãèããŸããäžåºŠã®åæã§ã¯ããã¹ãŠã®æçãåçŽæ¹åã®é·ãã(æçã®å³ç«¯ã«è¿ãéšå):(æçã®å·Šç«¯ã«è¿ãéšå)= k : l ã«åæããŸãããã®åäœã y åç¹°ãè¿ããŸãããããã®åæã«ãã£ãŠæçãç§»åããããšã¯ãããŸããã æ°é±éåŸã«ãåæçãå
ã®å®å
šãªãã©ããªã¢ã®ç¶æ
ã«åçããŠãã確çã¯ä»¥äžã®åŒã«ããæ±ãŸããŸãã äžã®å³ã¯ãåçŽæ¹åã«1:2ã§2åãæ°Žå¹³æ¹åã«1:1ã§1ååæããç¶æ
ã§ãã 以äžã®æäœã§åæããæã®ãæ°é±éåŸã«å
ã®å§¿ã«åçããŠãããã©ããªã¢ã®æ°ã®æåŸ
å€ãæ±ããŠãã ãããå
ã®ãã©ããªã¢ã®åçŽæ¹åã®é·ããšæ°Žå¹³æ¹åã®é·ãã¯ãšãã«1ãšããŸãã Input m n x k l y å
¥åã§ã¯ã6ã€ã®æŽæ° m , n , x , k , l , y ãäžèšã®å
¥åãã©ãŒãããã§äžããããŸãã ããã6ã€ã®æŽæ°ã¯å顿äžã®ãã®ãšå¯Ÿå¿ããŠãããæ°Žå¹³æ¹åã« m : n ã§åæããåäœã x åãåçŽæ¹åã« k : l ã§åæããåäœã y åç¹°ãè¿ããŸãã 1 †m , n , k , l †100ã 0 †x , y †40 ã§ããã m , n ãš l , k ã¯ããããäºãã«çŽ ã§ãã Output äžè¡ã«æ°é±éåŸã«å
ã®å§¿ã«åçããŠãããã©ããªã¢ã®æ°ã®æåŸ
å€ãåºåããŠãã ããã åºå㯠10 -6 以äžã®èª€å·®ãªãã°èš±å®¹ãããŸãã Sample Input 1 1 1 1 1 1 1 Sample Output 1 0.562500 Sample Input 2 1 2 2 1 1 1 Sample Output 2 0.490741 Sample Input 3 1 2 0 3 4 0 Sample Output 3 1.000000 Notes ãã®åé¡ã§ã¯ãdoubleããã粟床ã®é«ãæµ®åå°æ°ã䜿çšããããšãæšå¥šããŸãã
| 38,883
|
Score : 700 points Problem Statement Snuke and Ciel went to a strange stationery store. Each of them got a transparent graph paper with H rows and W columns. Snuke painted some of the cells red in his paper. Here, the cells painted red were 4-connected , that is, it was possible to traverse from any red cell to any other red cell, by moving to vertically or horizontally adjacent red cells only. Ciel painted some of the cells blue in her paper. Here, the cells painted blue were 4-connected. Afterwards, they precisely overlaid the two sheets in the same direction. Then, the intersection of the red cells and the blue cells appeared purple. You are given a matrix of letters a_{ij} ( 1â€iâ€H , 1â€jâ€W ) that describes the positions of the purple cells. If the cell at the i -th row and j -th column is purple, then a_{ij} is # , otherwise a_{ij} is . . Here, it is guaranteed that no outermost cell is purple . That is, if i=1, H or j = 1, W , then a_{ij} is . . Find a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation described. It can be shown that a solution always exists. Constraints 3â€H,Wâ€500 a_{ij} is # or . . If i=1,H or j=1,W , then a_{ij} is . . At least one of a_{ij} is # . Input The input is given from Standard Input in the following format: H W a_{11} ... a_{1W} : a_{H1} ... a_{HW} Output Print a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation, as follows: The first H lines should describe the positions of the red cells. The following 1 line should be empty. The following H lines should describe the positions of the blue cells. The description of the positions of the red or blue cells should follow the format of the description of the positions of the purple cells. Sample Input 1 5 5 ..... .#.#. ..... .#.#. ..... Sample Output 1 ..... ##### #.... ##### ..... .###. .#.#. .#.#. .#.#. ..... One possible pair of the set of the positions of the red cells and the blue cells is as follows: Sample Input 2 7 13 ............. .###.###.###. .#.#.#...#... .###.#...#... .#.#.#.#.#... .#.#.###.###. ............. Sample Output 2 ............. .###########. .###.###.###. .###.###.###. .###.###.###. .###.###.###. ............. ............. .###.###.###. .#.#.#...#... .###.#...#... .#.#.#.#.#... .#.#########. ............. One possible pair of the set of the positions of the red cells and the blue cells is as follows:
| 38,884
|
Problem D: Goofy Converter Nathan O. Davis is a student at the department of integrated systems. He is now taking a class in in- tegrated curcuits. He is an idiot. One day, he got an assignment as follows: design a logic circuit that takes a sequence of positive integers as input, and that outputs a sequence of 1-bit integers from which the original input sequence can be restored uniquely. Nathan has no idea. So he searched for hints on the Internet, and found several pages that describe the 1-bit DAC. This is a type of digital-analog converter which takes a sequence of positive integers as input, and outputs a sequence of 1-bit integers. Seeing how 1-bit DAC works on these pages, Nathan came up with a new idea for the desired converter. His converter takes a sequence L of positive integers, and a positive integer M aside from the sequence, and outputs a sequence K of 1-bit integers such that: He is not so smart, however. It is clear that his converter does not work for some sequences. Your task is to write a program in order to show the new converter cannot satisfy the requirements of his assignment, even though it would make Nathan in despair. Input The input consists of a series of data sets. Each data set is given in the following format: N M L 0 L 1 . . . L N -1 N is the length of the sequence L . M and L are the input to Nathanâs converter as described above. You may assume the followings: 1 †N †1000, 1 †M †12, and 0 †L j †M for j = 0, . . . , N - 1. The input is terminated by N = M = 0. Output For each data set, output a binary sequence K of the length ( N + M - 1) if there exists a sequence which holds the equation mentioned above, or âGoofyâ (without quotes) otherwise. If more than one sequence is possible, output any one of them. Sample Input 4 4 4 3 2 2 4 4 4 3 2 3 0 0 Output for the Sample Input 1111001 Goofy
| 38,885
|
Score: 100 points Problem Statement In 2020 , AtCoder Inc. with an annual sales of more than one billion yen (the currency of Japan) has started a business in programming education. One day, there was an exam where a one-year-old child must write a program that prints Hello World , and a two-year-old child must write a program that receives integers A, B and prints A+B . Takahashi, who is taking this exam, suddenly forgets his age. He decides to write a program that first receives his age N ( 1 or 2 ) as input, then prints Hello World if N=1 , and additionally receives integers A, B and prints A+B if N=2 . Write this program for him. Constraints N is 1 or 2 . A is an integer between 1 and 9 (inclusive). B is an integer between 1 and 9 (inclusive). Input Input is given from Standard Input in one of the following formats: 1 2 A B Output If N=1 , print Hello World ; if N=2 , print A+B . Sample Input 1 1 Sample Output 1 Hello World As N=1 , Takahashi is one year old. Thus, we should print Hello World . Sample Input 2 2 3 5 Sample Output 2 8 As N=2 , Takahashi is two years old. Thus, we should print A+B , which is 8 since A=3 and B=5 .
| 38,886
|
Score : 700 points Problem Statement You are given a string S consisting of a , b and c . Find the number of strings that can be possibly obtained by repeatedly performing the following operation zero or more times, modulo 998244353 : Choose an integer i such that 1\leq i\leq |S|-1 and the i -th and (i+1) -th characters in S are different. Replace each of the i -th and (i+1) -th characters in S with the character that differs from both of them (among a , b and c ). Constraints 2 \leq |S| \leq 2 Ã 10^5 S consists of a , b and c . Input Input is given from Standard Input in the following format: S Output Print the number of strings that can be possibly obtained by repeatedly performing the operation, modulo 998244353 . Sample Input 1 abc Sample Output 1 3 abc , aaa and ccc can be obtained. Sample Input 2 abbac Sample Output 2 65 Sample Input 3 babacabac Sample Output 3 6310 Sample Input 4 ababacbcacbacacbcbbcbbacbaccacbacbacba Sample Output 4 148010497
| 38,887
|
Problem Statement You bought 3 ancient scrolls from a magician. These scrolls have a long string, and the lengths of the strings are the same. He said that these scrolls are copies of the key string to enter a dungeon with a secret treasure. However, he also said, they were copied so many times by hand, so the string will contain some errors, though the length seems correct. Your job is to recover the original string from these strings. When finding the original string, you decided to use the following assumption. The copied string will contain at most d errors. In other words, the Hamming distance of the original string and the copied string is at most d . If there exist many candidates, the lexicographically minimum string is the original string. Can you find the orignal string? Input The input contains a series of datasets. Each dataset has the following format: l d str_1 str_2 str_3 The first line contains two integers l ( 1 \leq l \leq 100,000 ) and d ( 0 \leq d \leq 5,000 .) l describes the length of 3 given strings and d describes acceptable maximal Hamming distance. The following 3 lines have given strings, whose lengths are l . These 3 strings consist of only lower and upper case alphabets. The input ends with a line containing two zeros, which should not be processed. Output Print the lexicographically minimum satisfying the condition in a line. If there do not exist such strings, print -1 . Sample Input 3 1 ACM IBM ICM 5 2 iwzwz iziwi zwizi 1 0 A B C 10 5 jLRNlNyGWx yyLnlyyGDA yLRnvyyGDA 0 0 Output for the Sample Input ICM iwiwi -1 AARAlNyGDA
| 38,888
|
Score : 1100 points Problem Statement There is a tree with N vertices numbered 1, 2, ..., N . The edges of the tree are denoted by (x_i, y_i) . On this tree, Alice and Bob play a game against each other. Starting from Alice, they alternately perform the following operation: Select an existing edge and remove it from the tree, disconnecting it into two separate connected components. Then, remove the component that does not contain Vertex 1 . A player loses the game when he/she is unable to perform the operation. Determine the winner of the game assuming that both players play optimally. Constraints 2 \leq N \leq 100000 1 \leq x_i, y_i \leq N The given graph is a tree. Input Input is given from Standard Input in the following format: N x_1 y_1 x_2 y_2 : x_{N-1} y_{N-1} Output Print Alice if Alice wins; print Bob if Bob wins. Sample Input 1 5 1 2 2 3 2 4 4 5 Sample Output 1 Alice If Alice first removes the edge connecting Vertices 1 and 2 , the tree becomes a single vertex tree containing only Vertex 1 . Since there is no edge anymore, Bob cannot perform the operation and Alice wins. Sample Input 2 5 1 2 2 3 1 4 4 5 Sample Output 2 Bob Sample Input 3 6 1 2 2 4 5 1 6 3 3 2 Sample Output 3 Alice Sample Input 4 7 1 2 3 7 4 6 2 3 2 4 1 5 Sample Output 4 Bob
| 38,889
|
Problem B Quality of Check Digits The small city where you live plans to introduce a new social security number (SSN) system. Each citizen will be identified by a five-digit SSN. Its first four digits indicate the basic ID number (0000 - 9999) and the last one digit is a check digit for detecting errors. For computing check digits, the city has decided to use an operation table. An operation table is a 10 $\times$ 10 table of decimal digits whose diagonal elements are all 0. Below are two example operation tables. Operation Table 1 Operation Table 2 Using an operation table, the check digit $e$ for a four-digit basic ID number $abcd$ is computed by using the following formula. Here, $i \otimes j$ denotes the table element at row $i$ and column $j$. $e = (((0 \otimes a) \otimes b) \otimes c) \otimes d$ For example, by using Operation Table 1 the check digit $e$ for a basic ID number $abcd = $ 2016 is computed in the following way. $e = (((0 \otimes 2) \otimes 0) \otimes 1) \otimes 6$ $\;\;\; = (( \;\;\;\;\;\;\;\;\; 1 \otimes 0) \otimes 1) \otimes 6$ $\;\;\; = ( \;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\; 7 \otimes 1) \otimes 6$ $\;\;\; = \;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\; 9 \otimes 6$ $\;\;\; = \;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\; 6$ Thus, the SSN is 20166. Note that the check digit depends on the operation table used. With Operation Table 2, we have $e = $ 3 for the same basic ID number 2016, and the whole SSN will be 20163. Figure B.1. Two kinds of common human errors The purpose of adding the check digit is to detect human errors in writing/typing SSNs. The following check function can detect certain human errors. For a five-digit number $abcde$, the check function is defined as follows. check ($abcde$) $ = ((((0 \otimes a) \otimes b) \otimes c) \otimes d) \otimes e$ This function returns 0 for a correct SSN. This is because every diagonal element in an operation table is 0 and for a correct SSN we have $e = (((0 \otimes a) \otimes b) \otimes c) \otimes d$: check ($abcde$) $ = ((((0 \otimes a) \otimes b) \otimes c) \otimes d) \otimes e = e \otimes e = 0$ On the other hand, a non-zero value returned by check indicates that the given number cannot be a correct SSN. Note that, depending on the operation table used, check function may return 0 for an incorrect SSN. Kinds of errors detected depends on the operation table used; the table decides the quality of error detection. The city authority wants to detect two kinds of common human errors on digit sequences: altering one single digit and transposing two adjacent digits, as shown in Figure B.1. An operation table is good if it can detect all the common errors of the two kinds on all SSNs made from four-digit basic ID numbers 0000{9999. Note that errors with the check digit, as well as with four basic ID digits, should be detected. For example, Operation Table 1 is good. Operation Table 2 is not good because, for 20613, which is a number obtained by transposing the 3rd and the 4th digits of a correct SSN 20163, check (20613) is 0. Actually, among 10000 basic ID numbers, Operation Table 2 cannot detect one or more common errors for as many as 3439 basic ID numbers. Given an operation table, decide how good it is by counting the number of basic ID numbers for which the given table cannot detect one or more common errors. Input The input consists of a single test case of the following format. $x_{00}$ $x_{01}$ ... $x_{09}$ ... $x_{90}$ $x_{91}$ ... $x_{99}$ The input describes an operation table with $x_{ij}$ being the decimal digit at row $i$ and column $j$. Each line corresponds to a row of the table, in which elements are separated by a single space. The diagonal elements $x_{ii}$ ($i = 0, ... , 9$) are always 0. Output Output the number of basic ID numbers for which the given table cannot detect one or more common human errors. Sample Input 1 0 3 1 7 5 9 8 6 4 2 7 0 9 2 1 5 4 8 6 3 4 2 0 6 8 7 1 3 5 9 1 7 5 0 9 8 3 4 2 6 6 1 2 3 0 4 5 9 7 8 3 6 7 4 2 0 9 5 8 1 5 8 6 9 7 2 0 1 3 4 8 9 4 5 3 6 2 0 1 7 9 4 3 8 6 1 7 2 0 5 2 5 8 1 4 3 6 7 9 0 Sample Output 1 0 Sample Input 2 0 1 2 3 4 5 6 7 8 9 9 0 1 2 3 4 5 6 7 8 8 9 0 1 2 3 4 5 6 7 7 8 9 0 1 2 3 4 5 6 6 7 8 9 0 1 2 3 4 5 5 6 7 8 9 0 1 2 3 4 4 5 6 7 8 9 0 1 2 3 3 4 5 6 7 8 9 0 1 2 2 3 4 5 6 7 8 9 0 1 1 2 3 4 5 6 7 8 9 0 Sample Output 2 3439 Sample Input 3 0 9 8 7 6 5 4 3 2 1 1 0 9 8 7 6 5 4 3 2 2 1 0 9 8 7 6 5 4 3 3 2 1 0 9 8 7 6 5 4 4 3 2 1 0 9 8 7 6 5 5 4 3 2 1 0 9 8 7 6 6 5 4 3 2 1 0 9 8 7 7 6 5 4 3 2 1 0 9 8 8 7 6 5 4 3 2 1 0 9 9 8 7 6 5 4 3 2 1 0 Sample Output 3 9995 Sample Input 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Sample Output 4 10000
| 38,890
|
Enumeration of Subsets III You are given a set $T$, which is a subset of $S$. The set $S$ consists of $0, 1, ... n-1$. Print all subsets of $T$. Note that we represent $0, 1, ... n-1$ as 00...0001, 00...0010, 00...0100, ..., 10...0000 in binary respectively and the integer representation of a subset is calculated by bitwise OR of existing elements. Input The input is given in the following format. $n$ $k \; b_0 \; b_1 \; ... \; b_{k-1}$ $k$ is the number of elements in $T$, and $b_i$ represents elements in $T$. Output Print the subsets ordered by their decimal integers. Print a subset in the following format. $d$: $e_0$ $e_1$ ... Print ' : ' after the integer value $d$, then print elements $e_i$ in the subset in ascending order. Separate two adjacency elements by a space character. Constraints $1 \leq n \leq 28$ $0 \leq k \leq 18$ $k \leq n$ $0 \leq b_i < n$ Sample Input 1 4 2 0 2 Sample Output 1 0: 1: 0 4: 2 5: 0 2
| 38,891
|
ãžã³ã®è±ç® ã»ã¢ããªé«åã§çºèŠãããæ°çš®ã®ãžã³ã¯ãé ããå°Ÿã«ãããŠïŒåã«äžŠãã ãã«ïŒoïŒãšããïŒxïŒãããªãæš¡æ§ãç¹åŸŽã§ããäžå³ã«äŸã瀺ããŸããããžã³ã®æš¡æ§ã¯åäœã«ããæ§ã
ã§ãã xxoooxxxoox ãã®ãžã³ã¯è±ç®ã®ãšãã«ãïŒã€ã®ãã«ã䞊ãã éšåã®éãã¹ãŠã䌞ã³ãããšã§æé·ããŸããæ°ãã«å ãã£ãç®æã«ã¯ãã«ãããããã«ã䞊ãã æš¡æ§ãä»ããŸãã ããšãã°ãé·ãïŒã®ãžã³ ooo ãïŒåè±ç®ãããšãå·Šãã1çªç®ãšïŒçªç®ãïŒçªç®ãšïŒçªç®ã®ãã«ã®éã«ãã«ãããããã«ã䞊ãã æš¡æ§ãå ããã®ã§ãè±ç®åŸã®ãžã³ã¯ ooxoooxoo ãšãªããŸãïŒäžç·éšãæ°ãã«å ãã£ãç®æã§ãïŒãããäžåè±ç®ãããš ooxooxooxoooxooxooxoo ãšãªãããžã³ã®é·ãã¯ïŒïŒã«ãªããŸãã ãã®ãžã³ã®çæ
ãç ç©¶ããŠããããªãã¯ããã®ãžã³ãè±ç®ãç¹°ãè¿ãããããšãŠã€ããªãé·ãã«ãªã£ãŠããŸããããããªããšå±æ§ããŠããŸãã ãžã³ã®æš¡æ§ãšè±ç®ã®åæ°ãäžãããããšãããã®åæ°ã ãè±ç®ããåŸã®ãžã³ã®é·ããæ±ããããã°ã©ã ãäœæããã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã $L$ $N$ $snake$ ïŒè¡ç®ã«è±ç®ããåã®èã®é·ã$L$($1\leq L \leq 100$)ãšè±ç®ã®åæ°$N$ ($1 \leq N \leq 50$)ãäžãããããç¶ãïŒè¡ã«è±ç®ããåã®ãžã³ã®æš¡æ§ã衚ãé·ã$L$ã®æåå$snake$ãäžããããããã ã$snake$ã¯è±å°æå x ãš o ãããªãã åºå ãžã³ã®é·ããïŒè¡ã«åºåããã å
¥åºåäŸ å
¥åäŸïŒ 3 2 ooo åºåäŸïŒ 21 å
¥åäŸïŒ 3 4 xoo åºåäŸïŒ 48 å
¥åäŸïŒ 13 30 xooxoooxxxoox åºåäŸïŒ 12884901889
| 38,892
|
Score : 200 points Problem Statement We have sticks numbered 1, \cdots, N . The length of Stick i (1 \leq i \leq N) is L_i . In how many ways can we choose three of the sticks with different lengths that can form a triangle? That is, find the number of triples of integers (i, j, k) (1 \leq i < j < k \leq N) that satisfy both of the following conditions: L_i , L_j , and L_k are all different. There exists a triangle whose sides have lengths L_i , L_j , and L_k . Constraints 1 \leq N \leq 100 1 \leq L_i \leq 10^9 All values in input are integers. Input Input is given from Standard Input in the following format: N L_1 L_2 \cdots L_N Output Print the number of ways to choose three of the sticks with different lengths that can form a triangle. Sample Input 1 5 4 4 9 7 5 Sample Output 1 5 The following five triples (i, j, k) satisfy the conditions: (1, 3, 4) , (1, 4, 5) , (2, 3, 4) , (2, 4, 5) , and (3, 4, 5) . Sample Input 2 6 4 5 4 3 3 5 Sample Output 2 8 We have two sticks for each of the lengths 3 , 4 , and 5 . To satisfy the first condition, we have to choose one from each length. There is a triangle whose sides have lengths 3 , 4 , and 5 , so we have 2 ^ 3 = 8 triples (i, j, k) that satisfy the conditions. Sample Input 3 10 9 4 6 1 9 6 10 6 6 8 Sample Output 3 39 Sample Input 4 2 1 1 Sample Output 4 0 No triple (i, j, k) satisfies 1 \leq i < j < k \leq N , so we should print 0 .
| 38,893
|
B: Spent Fuel Disposal å顿 $N$ åã®äžæ°ŽåŠçæœèšã $M$ æ¬ã®ãã€ãã§ç¹ãã£ãŠããã$i$ çªç®ã®ãã€ã㯠$u_i$ çªç®ãš $v_i$ çªç®ã®æœèšãç¹ãã§ããŸãã ãã€ãã¯å
šãŠãæ¯ç§æå€§ $1$ ãªããã«ã®æ¶²äœãæµãããšãã§ããŸãã ä»ã$S$ çªç®ã®æœèšãã $T$ çªç®ã®æœèšãžå·¥æ¥å»æ°Žãã $U$ çªç®ã®æœèšãã $V$ çªç®ã®æœèšãžçŽæ°Žãæµãããã§ãã$S$ çªç®ããã³ $U$ çªç®ã®æœèšã¯ãããããå·¥æ¥å»æ°Žããã³çŽæ°ŽãååãªéæããŠããããã€ãã§ç¹ãã£ãŠããå¥ã®æœèšãžãããã®æ¶²äœã奜ãã«éãããšãã§ããŸãã ãŸããåæœèšã§ã¯ãéãããŠããæ¶²äœããã€ãã§ç¹ãã£ãŠããå¥ã®åŠçæœèšãžæµãããšãã§ããŸãã ãã€ãã¯ãã€ãã¯ãªã®ã§ã$2$ çš®é¡ã®æ¶²äœãåæã«å¥œããªæ¹åãžæµãããšãã§ããŸãã äŸãã°ã$i$ çªç®ã®ãã€ãã¯ã$u_i$ ãã $v_i$ ãžå·¥æ¥å»æ°Žãã$v_i$ ãã $u_i$ ãžçŽæ°Žãæµãããšãã§ããŸãã å察㫠$v_i$ ãã $u_i$ ãžå·¥æ¥å»æ°Žãã$u_i$ ãã $v_i$ ãžçŽæ°Žãæµãããšãå¯èœã§ãã ãã¡ããã$2$ çš®é¡ã®æ¶²äœãåãæ¹åãžæµãããšãã§ããŸãã ãã ããã©ã®å Žåã«ãããŠãã$1$ ã€ã®ãã€ãã«æµãæ¶²äœã®ç·éã¯æ¯ç§ $1$ ãªããã«ãè¶
ããããšã¯ã§ããŸããã $S$ ãã $T$ ãžæµãå·¥æ¥å»æ°Žã®ç·éãš $U$ ãã $V$ ãžæµãçŽæ°Žã®ç·éã®åèšã¯ãæå€§ã§æ¯ç§äœãªããã«ã«ã§ããŸããã çãã¯æŽæ°ã«ãªãããšã蚌æã§ãããããæŽæ°ã§åºåããŠãã ããã å¶çŽ å
¥åã¯å
šãп޿° $1 \leq N, M \leq 10^5$ $1 \leq S, T, U, V \leq N$ $S \neq T$ $U \neq V$ $1 \leq u_i, v_i \leq N$ $u_i < v_i$ ($i = 1, \ldots, M$) $i \neq j \rightarrow (u_i, v_i) \neq (u_j, v_j)$ å
šãŠã®æœèšã¯ãã€ããéããŠé£çµã§ãã å
¥å å
¥åã¯æšæºå
¥åãã以äžã®åœ¢åŒã§äžããããŸãã $N$ $M$ $S$ $T$ $U$ $V$ $u_1$ $v_1$ $\vdots$ $u_M$ $v_M$ åºå çãã1è¡ã«åºåããŠãã ããã å
¥åºåäŸ å
¥åäŸ1 5 6 1 4 2 3 1 2 2 3 3 4 4 5 3 5 1 5 åºåäŸ1 2 äŸãã°ã$1$ ãã $5$ã$5$ ãã $4$ ãžå·¥æ¥ææ°Žãæ¯ç§ $1$ ãªããã«ã$2$ ãã $3$ ãžçŽæ°Žãæ¯ç§ $1$ ãªããã«æµãã°è¯ãã§ãã å
¥åäŸ2 3 3 1 2 1 3 1 2 1 3 2 3 åºåäŸ2 2 $T$ ãš $V$ ãåäžã®æœèšã§ããã±ãŒã¹ãªã©ã«æ³šæããŠãã ããã
| 38,894
|
çŽ æ° II çŽ æ°ãšããã®ã¯ã1 ããã倧ããããèªèº«ã 1 ã§ããå²ããããªãæŽæ°ããããŸããäŸãã°ã2 ã¯ã2 ãš 1 ã§ããå²ãåããªãã®ã§çŽ æ°ã§ããã12 ã¯ã12 ãš 1 ã®ã»ãã«ã2, 3, 4, 6 ã§å²ããããæ°ãªã®ã§çŽ æ°ã§ã¯ãããŸããã æŽæ° n ãå
¥åãããšãã n ããå°ããçŽ æ°ã®ãã¡æã倧ãããã®ãšã n ãã倧ããçŽ æ°ã®ãã¡æãå°ãããã®ãåºåããããã°ã©ã ãäœæããŠãã ããã Input è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã« n (3 †n †50,000) ãïŒè¡ã«äžããããŸãã ããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã Output åããŒã¿ã»ããã«å¯ŸããŠã n ããå°ããçŽ æ°ã®ãã¡æå€§ã®ãã®ãšã n ãã倧ããçŽ æ°ã®ãã¡æå°ã®ãã®ãïŒã€ã®ã¹ããŒã¹ã§åºåã£ãŠïŒè¡ã«åºåããŠäžããã Sample Input 19 3517 Output for the Sample Input 17 23 3511 3527
| 38,895
|
çžåŒµã(Territory) ããªãã¯ååæ¹åã«ãšãŠãé·ã䌞ã³ãããããã®éè·¯ãšïŒæ±è¥¿æ¹åã«ãšãŠãé·ã䌞ã³ãããããã®éè·¯ã亀ãã£ã圢ãããè¡ã«äœãã§ããïŒé£ãåã2 ã€ã®ååæ¹åã®éè·¯ã®éé㯠1 km ã§ããïŒãŸãïŒé£ãåã 2 ã€ã®æ±è¥¿æ¹åã®éè·¯ã®ééã 1 km ã§ããïŒ ãã®è¡ã«ã¯åžåœ¹æã 1 ã€ããïŒåžåœ¹æã®ãã亀差ç¹ã $(0,0)$ ãšè¡šãïŒãã®è¡ã®äº€å·®ç¹ã¯ 2 ã€ã®æŽæ° $i, j$ ãçšããŠäº€å·®ç¹ $(i, j)$ ãšè¡šãããïŒããªãã¡ïŒäº€å·®ç¹ $(i, j)$ ãšã¯ïŒäº€å·®ç¹ $(0,0)$ ããæ±ã« $i$ km ($i < 0$ ã®ãšãã¯è¥¿ã« $-i$ km)ïŒåã« $j$ km ( $j < 0$ ã®ãšãã¯åã« $-j$ km) é²ãã äœçœ®ã®äº€å·®ç¹ã衚ãïŒ åžåœ¹æã§ã¯ãžã§ã€åãšããåã® 1 å¹ã®ç¬ã飌ã£ãŠããïŒãžã§ã€å㯠$K$ æ¥éã®æ£æ©ã®èšç»ãç«ãŠãïŒæ£æ©ã®èšç»ã¯ä»¥äžã®éãã§ããïŒ $K$ æ¥ã®ãã¡æåã®æ¥ã®æã«ã¯ãžã§ã€åã¯äº€å·®ç¹ $(0,0)$ ã«ããïŒãžã§ã€åã¯äº€å·®ç¹ $(0,0)$ ã«å°ãä»ããïŒ$(0,0)$ 以å€ã«ã¯ãžã§ã€åãå°ãä»ãã亀差ç¹ã¯ãªãïŒ $K$ æ¥ã®ããããã®æ¥ã®æŒã«æ£æ©ãè¡ãïŒ1 æ¥ã®æ£æ©ã¯ $N$ åã®ã¹ããããããªãïŒåã¹ãããã§ã¯äº€å·®ç¹ããé£ã®äº€å·®ç¹ãžãšç§»åãïŒç§»åå
ã«å°ãä»ããïŒãžã§ã€åãããããã®æ¥ã®æŒã«ã©ãç§»åãããã¯æ¥ã«ãããäžå®ã§ããïŒ æŒã®ç§»åãçµãã£ãåŸã¯ïŒçŸåšãã亀差ç¹ã§æ¬¡ã®æ¥ã®æãŸã§å¯ãïŒ åžåœ¹æã§ã¯ $K$ æ¥éã®æ£æ©ã«ãã£ãŠã§ãããžã§ã€åã®çžåŒµãã«ã€ããŠè©±é¡ã«ãªã£ãŠããïŒ4 ã€ã®äº€å·®ç¹ $(a,b),(a + 1,b),(a + 1,b + 1),(a,b + 1)$ ã®ãããã«ããžã§ã€åã 1 å以äžå°ãä»ããŠãããšãïŒ4 ã€ã®äº€å·®ç¹ã§å²ãŸããåºç»ã¯ãžã§ã€åã®çžåŒµãã«å±ããïŒ ããªãã¯ïŒãžã§ã€åã®æ£æ©èšç»ããïŒãžã§ã€åã®çžåŒµãã«å±ããåºç»ã®åæ°ãèšç®ããããã°ã©ã ãäœæããããšãšãªã£ãïŒ ãã®è¡ã®éè·¯ã¯ãšãŠãé·ãïŒãŸãïŒååæ¹åã«ãæ±è¥¿æ¹åã«ãååããããã®éè·¯ãããããïŒæ£æ©ã®éäžã§ãžã§ã€åãéè·¯ã®ç«¯ãè¡ã®ç«¯ã«å°éããããšã¯ãªãïŒ èª²é¡ ãžã§ã€åã®æ£æ©èšç»ãäžãããããšïŒãžã§ã€åã®çžåŒµãã«å±ããåºç»ã®åæ°ãæ±ããããã°ã©ã ãäœæããïŒ å
¥å æšæºå
¥åãã以äžã®å
¥åãèªã¿èŸŒãïŒ 1 è¡ç®ã«ã¯ 2 åã®æŽæ° $N, K$ ã空çœãåºåããšããŠæžãããŠããïŒããã¯ããããã®æ¥ã®æ£æ©ã $N$ åã®ã¹ããããããªãïŒæ£æ©èšç»ã $K$ æ¥éã«æž¡ãããšã衚ããŠããïŒ 2 è¡ç®ã«ã¯é·ã $N$ ã®æåå $S$ ãæžãããŠããïŒæåå $S$ ã®ãã¡å·Šãã $p$ æåç® $(1 \leq p \leq N)$ ã®æå $C_p$ 㯠EïŒNïŒWïŒS ã®ããããã§ããïŒãããã®æåã¯ä»¥äžã®ããšã衚ãïŒ æå $C_p$ ã E ã§ãããªãã°ïŒ$p$ çªç®ã®ã¹ãããã§æ±é£ã®äº€å·®ç¹ã«ç§»åããããšã衚ãïŒ æå $C_p$ ã N ã§ãããªãã°ïŒ$p$ çªç®ã®ã¹ãããã§åé£ã®äº€å·®ç¹ã«ç§»åããããšã衚ãïŒ æå $C_p$ ã W ã§ãããªãã°ïŒ$p$ çªç®ã®ã¹ãããã§è¥¿é£ã®äº€å·®ç¹ã«ç§»åããããšã衚ãïŒ æå $C_p$ ã S ã§ãããªãã°ïŒ$p$ çªç®ã®ã¹ãããã§åé£ã®äº€å·®ç¹ã«ç§»åããããšã衚ãïŒ ããã§ïŒäº€å·®ç¹$(i, j)$ ã«å¯ŸããŠæ±é£ïŒåé£ïŒè¥¿é£ïŒåé£ã®äº€å·®ç¹ã¯ããããïŒäº€å·®ç¹ $(i + 1, j)$ïŒäº€å·®ç¹$(i, j + 1)$ïŒäº€å·®ç¹$(i - 1, j)$ïŒäº€å·®ç¹$(i, j - 1)$ ã§ããïŒ åºå æšæºåºåã«ïŒãžã§ã€åã®çžåŒµãã«å±ããåºç»ã®åæ°ã 1 è¡ã§åºåããïŒ å¶é ãã¹ãŠã®å
¥åããŒã¿ã¯ä»¥äžã®æ¡ä»¶ãæºããïŒ $1 \leq N \leq 100 000$ $1 \leq K \leq 1 000 000 000$ å
¥åºåäŸ å
¥åäŸ1 12 1 EENWSEEESWWS åºåäŸ1 3 ãã®å
¥åäŸã§ã¯ïŒæ£æ©ã¯ 1 æ¥éã§è¡ãããïŒ1 æ¥ç®ã«ãžã§ã€åã¯åžåœ¹æããåºçºããŠäžå³ã®ããã«ç§»åããïŒé»äžžã¯ãžã§ã€åãå°ãä»ãã亀差ç¹ïŒçœäžžã¯ãžã§ã€åãå°ãä»ããŠããªã亀差ç¹ïŒäºéäžžã¯åžåœ¹æã®ãã亀差ç¹ïŒæ°åã¯åã¹ãããã衚ãïŒ ãžã§ã€åã®ç§»åçµè·¯ å
¥åäŸ 1 ã«ãããŠïŒäžå³ã®æç·éšåã§ç€ºããã 3 åã®åºç»ããžã§ã€åã®çžåŒµãã«å±ããïŒ å
¥åäŸ1 ã«ããããžã§ã€åã®çžåŒµã å
¥åäŸ2 12 2 EENWSEEESWWS åºåäŸ2 7 å
¥åäŸ 2 ã§ã¯ïŒæ£æ©ã 2 æ¥éã«æž¡ãè¡ãããïŒããããã®æ¥ã®ç§»åçµè·¯ã¯å
¥åäŸ 1 ãšåäžã§ããïŒæ£æ©ãå®äºãããšãïŒäžå³ã®æç·éšåã§ç€ºããã 7 åã®åºç»ããžã§ã€åã®çžåŒµãã«å±ããïŒ å
¥åäŸ2 ã«ããããžã§ã€åã®çžåŒµã å
¥åäŸ3 7 1 ENNWNNE åºåäŸ3 0 å
¥åäŸ 3 ã§ã¯ïŒãžã§ã€åã®çžåŒµãã«å±ããåºç»ã¯ååšããªãïŒ å
¥åäŸ4 16 5 WSESSSWWWEEENNNW åºåäŸ4 21 第15å æ¥æ¬æ
å ±ãªãªã³ããã¯æ¬éž èª²é¡ 2016 幎 2 æ 14 æ¥
| 38,896
|
I: Add Problem Statement Mr. T has had an integer sequence of N elements a_1, a_2, ... , a_N and an integer K . Mr. T has created N integer sequences B_1, B_2, ... , B_N such that B_i has i elements. B_{N,j} = a_j ( 1 \leq j \leq N ) B_{i,j} = K \times B_{i+1,j} + B_{i+1,j+1} ( 1\leq i \leq N-1, 1 \leq j \leq i ) Mr. T was so careless that he lost almost all elements of these sequences a and B_i . Fortunately, B_{1,1}, B_{2,1}, ... , B_{N,1} and K are not lost. Your task is to write a program that restores the elements of the initial sequence a for him. Output the modulo 65537 of each element instead because the absolute value of these elements can be extremely large. More specifically, for all integers i ( 1 \leq i \leq N ), output r_i that satisfies r_i $\equiv$ a_i $ \bmod \;$ 65537, 0 \leq r_i < 65537 . Here, we can prove that the original sequence Mr. T had can be uniquely determined under the given constraints. Input T N_1 K_1 C_{1,1} C_{1,2} ... C_{1,N} N_2 K_2 C_{2,1} C_{2,2} ... C_{2,N} : N_T K_T C_{T,1} C_{T,2} ... C_{T,N} The first line contains a single integer T that denotes the number of test cases. Each test case consists of 2 lines. The first line of the i -th test case contains two integers N_i and K_i . The second line of the i -th test case contains N_i integers C_{i,j} ( 1 \leq j \leq N_i ). These values denote that N = N_i , K = K_i , B_{j,1} = C_{i,j} ( 1 \leq j \leq N_i ) in the i -th test case. Constraints 1 \leq T \leq 10 1 \leq N \leq 50000 |K| \leq 10^9 |B_{i,1}| \leq 10^9 All input values are integers. Output Output T lines. For the i -th line, output the answer for the i -th test case a_1, a_2, ..., a_N in this order. Each number must be separated by a single space. Sample Input 1 2 3 0 1 2 3 3 1 1 2 3 Output for Sample Input 1 3 2 1 3 65536 0
| 38,897
|
Aizu PR An English booklet has been created for publicizing Aizu to the world. When you read it carefully, you found a misnomer (an error in writing) on the last name of Masayuki Hoshina, the lord of the Aizu domain. The booklet says "Hoshino" not "Hoshina". Your task is to write a program which replace all the words "Hoshino" with "Hoshina". You can assume that the number of characters in a text is less than or equal to 1000. Input The input consists of several datasets. There will be the number of datasets n in the first line. There will be n lines. A line consisting of english texts will be given for each dataset. Output For each dataset, print the converted texts in a line. Sample Input 3 Hoshino Hashino Masayuki Hoshino was the grandson of Ieyasu Tokugawa. Output for the Sample Input Hoshina Hashino Masayuki Hoshina was the grandson of Ieyasu Tokugawa.
| 38,898
|
Problem B: Kaeru Jump There is a frog living in a big pond. He loves jumping between lotus leaves floating on the pond. Interestingly, these leaves have strange habits. First, a leaf will sink into the water after the frog jumps from it. Second, they are aligned regularly as if they are placed on the grid points as in the example below. Figure 1: Example of floating leaves Recently, He came up with a puzzle game using these habits. At the beginning of the game, he is on some leaf and faces to the upper, lower, left or right side. He can jump forward or to the left or right relative to his facing direction, but not backward or diagonally. For example, suppose he is facing to the left side, then he can jump to the left, upper and lower sides but not to the right side. In each jump, he will land on the nearest leaf on his jumping direction and face to that direction regardless of his previous state. The leaf he was on will vanish into the water after the jump. The goal of this puzzle is to jump from leaf to leaf until there is only one leaf remaining. See the example shown in the figure below. In this situation, he has three choices, namely, the leaves A, B and C. Note that he cannot jump to the leaf D since he cannot jump backward. Suppose that he choose the leaf B. After jumping there, the situation will change as shown in the following figure. He can jump to either leaf E or F next. After some struggles, he found this puzzle difficult, since there are a lot of leaves on the pond. Can you help him to find out a solution? Input H W c 1,1 ... c 1, W . . . c H ,1 ... c H , W The first line of the input contains two positive integers H and W (1 †H , W †10). The following H lines, which contain W characters each, describe the initial configuration of the leaves and the frog using following characters: '.â : water âoâ : a leaf âUâ : a frog facing upward (i.e. to the upper side) on a leaf âDâ : a frog facing downward (i.e. to the lower side) on a leaf âLâ : a frog facing leftward (i.e. to the left side) on a leaf âRâ : a frog facing rightward (i.e. to the right side) on a leaf You can assume that there is only one frog in each input. You can also assume that the total number of leaves (including the leaf the frog is initially on) is at most 30. Output Output a line consists of the characters âUâ (up), âDâ (down), âLâ (left) and âRâ (right) that describes a series of movements. The output should not contain any other characters, such as spaces. You can assume that there exists only one solution for each input. Sample Input 1 2 3 Uo. .oo Output for the Sample Input 1 RDR Sample Input 2 10 10 .o....o... o.oo...... ..oo..oo.. ..o....... ..oo..oo.. ..o...o.o. o..U.o.... oo......oo oo........ oo..oo.... Output for the Sample Input 2 URRULULDDLUURDLLLURRDLDDDRRDR Sample Input 3 10 1 D . . . . . . . . o Output for the Sample Input 3 D
| 38,899
|
Score : 300 points Problem Statement Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: For each i ( 1 †i †N - 1 ), the i -th character of t' must be either the i -th or (i + 1) -th character of t . There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations. Constraints 1 †|s| †100 s consists of lowercase English letters. Input Input is given from Standard Input in the following format: s Output Print the minimum necessary number of operations to achieve the objective. Sample Input 1 serval Sample Output 1 3 One solution is: serval â srvvl â svvv â vvv . Sample Input 2 jackal Sample Output 2 2 One solution is: jackal â aacaa â aaaa . Sample Input 3 zzz Sample Output 3 0 All the characters in s are the same from the beginning. Sample Input 4 whbrjpjyhsrywlqjxdbrbaomnw Sample Output 4 8 In 8 operations, he can change s to rrrrrrrrrrrrrrrrrr .
| 38,900
|
Score : 300 points Problem Statement You are given four integers A , B , C , and D . Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D . Constraints 1\leq A\leq B\leq 10^{18} 1\leq C,D\leq 10^9 All values in input are integers. Input Input is given from Standard Input in the following format: A B C D Output Print the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D . Sample Input 1 4 9 2 3 Sample Output 1 2 5 and 7 satisfy the condition. Sample Input 2 10 40 6 8 Sample Output 2 23 Sample Input 3 314159265358979323 846264338327950288 419716939 937510582 Sample Output 3 532105071133627368
| 38,901
|
Problem Statement You want to compete in ICPC (Internet Contest of Point Collection). In this contest, we move around in $N$ websites, numbered $1$ through $N$, within a time limit and collect points as many as possible. We can start and end on any website. There are $M$ links between the websites, and we can move between websites using these links. You can assume that it doesn't take time to move between websites. These links are directed and websites may have links to themselves. In each website $i$, there is an advertisement and we can get $p_i$ point(s) by watching this advertisement in $t_i$ seconds. When we start on or move into a website, we can decide whether to watch the advertisement or not. But we cannot watch the same advertisement more than once before using any link in the website, while we can watch it again if we have moved among websites and returned to the website using one or more links, including ones connecting a website to itself. Also we cannot watch the advertisement in website $i$ more than $k_i$ times. You want to win this contest by collecting as many points as you can. So you decided to compute the maximum points that you can collect within $T$ seconds. Input The input consists of multiple datasets. The number of dataset is no more than $60$. Each dataset is formatted as follows. $N$ $M$ $T$ $p_1$ $t_1$ $k_1$ : : $p_N$ $t_N$ $k_N$ $a_1$ $b_1$ : : $a_M$ $b_M$ The first line of each dataset contains three integers $N$ ($1 \le N \le 100$), $M$ ($0 \le M \le 1{,}000$) and $T$ ($1 \le T \le 10{,}000$), which denote the number of websites, the number of links, and the time limit, respectively. All the time given in the input is expressed in seconds. The following $N$ lines describe the information of advertisements. The $i$-th of them contains three integers $p_i$ ($1 \le p_i \le 10{,}000$), $t_i$ ($1 \le t_i \le 10{,}000$) and $k_i$ ($1 \le k_i \le 10{,}000$), which denote the points of the advertisement, the time required to watch the advertisement, and the maximum number of times you can watch the advertisement in website $i$, respectively. The following $M$ lines describe the information of links. Each line contains two integers $a_i$ and $b_i$ ($1 \le a_i,b_i \le N$), which mean that we can move from website $a_i$ to website $b_i$ using a link. The end of input is indicated by a line containing three zeros. Output For each dataset, output the maximum points that you can collect within $T$ seconds. Sample Input 5 4 10 4 3 1 6 4 3 3 2 4 2 2 1 8 5 3 1 2 2 3 3 4 4 5 3 3 1000 1000 1 100 1 7 100 10 9 100 1 2 2 3 3 2 1 0 5 25 25 2 1 0 25 25 25 2 5 5 100 1 1 20 1 1 20 10 1 1 10 1 1 10 1 1 1 2 2 1 3 4 4 5 5 3 3 3 100 70 20 10 50 15 20 90 10 10 1 2 2 2 2 3 0 0 0 Output for the Sample Input 15 2014 0 25 40 390
| 38,902
|
Problem G: Telescope Dr. Extreme experimentally made an extremely precise telescope to investigate extremely curi- ous phenomena at an extremely distant place. In order to make the telescope so precise as to investigate phenomena at such an extremely distant place, even quite a small distortion is not allowed. However, he forgot the influence of the internal gas affected by low-frequency vibration of magnetic flux passing through the telescope. The cylinder of the telescope is not affected by the low-frequency vibration, but the internal gas is. The cross section of the telescope forms a perfect circle. If he forms a coil by putting extremely thin wire along the (inner) circumference, he can measure (the average vertical component of) the temporal variation of magnetic flux:such measurement would be useful to estimate the influence. But points on the circumference at which the wire can be fixed are limited; furthermore, the number of special clips to fix the wire is also limited. To obtain the highest sensitivity, he wishes to form a coil of a polygon shape with the largest area by stringing the wire among carefully selected points on the circumference. Your job is to write a program which reports the maximum area of all possible m -polygons (polygons with exactly m vertices) each of whose vertices is one of the n points given on a circumference with a radius of 1. An example of the case n = 4 and m = 3 is illustrated below. In the figure above, the equations such as " p 1 = 0.0" indicate the locations of the n given points, and the decimals such as "1.000000" on m -polygons indicate the areas of m -polygons. Parameter p i denotes the location of the i -th given point on the circumference (1 †i †n ). The location p of a point on the circumference is in the range 0 †p < 1, corresponding to the range of rotation angles from 0 to 2 Ï radians. That is, the rotation angle of a point at p to the point at 0 equals 2 Ï radians. ( Ï is the circular constant 3.14159265358979323846....) You may rely on the fact that the area of an isosceles triangle ABC (AB = AC = 1) with an interior angle BAC of α radians (0 < α < Ï ) is (1/2)sin α , and the area of a polygon inside a circle with a radius of 1 is less than Ï . Input The input consists of multiple subproblems followed by a line containing two zeros that indicates the end of the input. Each subproblem is given in the following format. n m p 1 p 2 ... p n n is the number of points on the circumference (3 †n †40). m is the number of vertices to form m -polygons (3 †m †n ). The locations of n points, p 1 , p 2 ,..., p n , are given as decimals and they are separated by either a space character or a newline. In addition, you may assume that 0 †p 1 < p 2 < ... < p n < 1. Output For each subproblem, the maximum area should be output, each in a separate line. Each value in the output may not have an error greater than 0.000001 and its fractional part should be represented by 6 decimal digits after the decimal point. Sample Input 4 3 0.0 0.25 0.5 0.666666666666666666667 4 4 0.0 0.25 0.5 0.75 30 15 0.00 0.03 0.06 0.09 0.12 0.15 0.18 0.21 0.24 0.27 0.30 0.33 0.36 0.39 0.42 0.45 0.48 0.51 0.54 0.57 0.61 0.64 0.66 0.69 0.72 0.75 0.78 0.81 0.84 0.87 40 20 0.351 0.353 0.355 0.357 0.359 0.361 0.363 0.365 0.367 0.369 0.371 0.373 0.375 0.377 0.379 0.381 0.383 0.385 0.387 0.389 0.611 0.613 0.615 0.617 0.619 0.621 0.623 0.625 0.627 0.629 0.631 0.633 0.635 0.637 0.639 0.641 0.643 0.645 0.647 0.649 0 0 Output for the Sample Input 1.183013 2.000000 3.026998 0.253581
| 38,903
|
7 ã»ã°ã¡ã³ã é»åãªã©ã§ããç®ã«ããããžã¿ã«æ°åã衚瀺ããŠããç»é¢ã¯ãããžã¿ã«æ°åã 7 ã€ã®éšå(ã»ã°ã¡ã³ ã)ã§æ§æãããããšãããã7ã»ã°ã¡ã³ããã£ã¹ãã¬ã€ããšåŒã°ããŠããŸãã ã¯ã«ããç€Ÿã§æ°ãã売ãåºãäºå®ã®è£œåã¯ã 7ã»ã°ã¡ã³ããã£ã¹ãã¬ã€ã補åã«çµã¿èŸŒãããšã«ãªãã瀟å¡ã§ããããªãã¯ãäžããããæ°åã 7 ã»ã°ã¡ã³ããã£ã¹ãã¬ã€ã«è¡šç€ºããããã°ã©ã ãäœæããããšã«ãªããŸããã ãã®7ã»ã°ã¡ã³ããã£ã¹ãã¬ã€ã¯ã次ã®åãæ¿ãã®æç€ºãéãããŠãããŸã§è¡šç€ºç¶æ
ã¯å€ãããŸããã7 ããããããªãã·ã°ãã«ãéãããšã§ããããã察å¿ããã»ã°ã¡ã³ãã®è¡šç€ºæ
å ±ãåãæ¿ããäºãã§ããŸããããããšã¯ 1 ã 0 ã®å€ãæã€ãã®ã§ãããã§ã¯ 1 ããåãæ¿ããã0 ãããã®ãŸãŸãã衚ããŸãã åããããšã»ã°ã¡ã³ãã®å¯Ÿå¿é¢ä¿ã¯äžã®å³ã®ããã«ãªã£ãŠããŸããã·ã°ãã«ã¯ 7 ã€ã®ãããã"gfedcba"ã®é çªã«éããŸããäŸãã°ãé衚瀺ã®ç¶æ
ããã0ãã衚瀺ããããã«ã¯"0111111"ãã·ã°ãã«ãšããŠãã£ã¹ãã¬ã€ã«éããªããã°ãªããŸãããã0ãããã5ãã«å€æŽããå Žåã«ã¯"1010010"ãéããŸããç¶ããŠã5ããã1ãã«å€æŽããå Žåã«ã¯"1101011"ãéããŸãã 衚瀺ããã n (1 †n †100) åã®æ°åãå
¥åãšãããããã®æ°å d i (0 †d i †9) ãé ã« 7 ã»ã°ã¡ã³ããã£ã¹ãã¬ã€ã«æ£ãã衚瀺ããããã«å¿
èŠãªã·ã°ãã«åãåºåããããã°ã©ã ãäœæããŠãã ããããªãã7 ã»ã°ã¡ã³ããã£ã¹ãã¬ã€ã®åæç¶æ
ã¯å
šãŠé衚瀺ã®ç¶æ
ã§ãããã®ãšããŸãã Input è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯-1 ã²ãšã€ã®è¡ã§ç€ºãããŸãã åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã n d 1 d 2 : d n ããŒã¿ã»ããã®æ°ã¯ 120 ãè¶
ããŸããã Output å
¥åããŒã¿ã»ããããšã«ãæ°åããã£ã¹ãã¬ã€ã«æ£ããåºåããããã«å¿
èŠãªã·ã°ãã«ã®åãåºåããŠãã ããã Sample Input 3 0 5 1 1 0 -1 Output for the Sample Input 0111111 1010010 1101011 0111111
| 38,904
|
D: Xor Array å顿 æŽæ° $N$ ãš $X$ ãäžããããŸãã 以äžã®æ¡ä»¶ãæºããé·ã $N$ ã®æ°åã®åæ°ã $998244353$ ã§å²ã£ãäœããæ±ããŠãã ããã æ°åã¯åºçŸ©å調å¢å ã§ããã æ°åã®åèŠçŽ ã¯ $0$ ä»¥äž $X$ 以äžã§ããã å
šãŠã®èŠçŽ ã®æä»çè«çå(xor)ã $X$ ã§ããã å¶çŽ $1 \leq N \leq 500$ $0 \leq X \leq 500$ $N$ ãš $X$ ã¯æŽæ°ã§ããã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããã $N$ $X$ åºå çããåºåããã å
¥åäŸ1 2 3 åºåäŸ1 2 æ°å $\{0,3\}$ ãš $\{1,2\}$ ãæ¡ä»¶ãæºãããŸãã å
¥åäŸ2 1 1 åºåäŸ2 1 æ°å $\{1\}$ ã®ã¿ãæ¡ä»¶ãæºãããŸãã å
¥åäŸ3 224 239 åºåäŸ3 400351036
| 38,905
|
Score : 100 points Problem Statement This contest is CODEFESTIVAL , which can be shortened to the string CF by deleting some characters. Mr. Takahashi, full of curiosity, wondered if he could obtain CF from other strings in the same way. You are given a string s consisting of uppercase English letters. Determine whether the string CF can be obtained from the string s by deleting some characters. Constraints 2 †|s| †100 All characters in s are uppercase English letters ( A - Z ). Input The input is given from Standard Input in the following format: s Output Print Yes if the string CF can be obtained from the string s by deleting some characters. Otherwise print No . Sample Input 1 CODEFESTIVAL Sample Output 1 Yes CF is obtained by deleting characters other than the first character C and the fifth character F . Sample Input 2 FESTIVALCODE Sample Output 2 No FC can be obtained but CF cannot be obtained because you cannot change the order of the characters. Sample Input 3 CF Sample Output 3 Yes It is also possible not to delete any characters. Sample Input 4 FCF Sample Output 4 Yes CF is obtained by deleting the first character.
| 38,906
|
KND Runs for Sweets Problem KNDåã¯äŒæŽ¥å€§åŠã«åšç±ããåŠçããã°ã©ãã§ããã圌ã¯çå
ã§ããããšã§ç¥ãããŠããã圌ã¯ãšããåžã«1å¹Žéæ»åšããããšã«ãªãããã®æéäžã«åžå
ã«ãã N ç®æã®çå³åŠããã¹ãŠåããããšæã£ãŠããããªã®ã§ãã®1幎éã®äœãå Žæã¯çå³åŠãåãã®ã«äžçªé©ããå ŽæããããšèããŠããã圌ã®é£äººã§ããããªãã¯ãåçå³åŠãžã®ææªã®ç§»åæéãæå°ã«ãªãå Žæãæ¢ãäºã«ãªã£ãããã®çå³åŠãããåžã¯ç°¡åã®ããäºæ¬¡å
å¹³é¢ã§è¡šãããšã«ããã圌ã¯ç®çã®çå³åŠãžã®ã¢ãããŒã·ã§ã³ã®éãã«ãããåäœæéãããã®ç§»åè·é¢ãå€åããããŸãã圌ã¯ã©ããªå Žæã«ã§ãïŒããšãçå³åŠãšåãå Žæã§ããããšïŒäœãã€ããã§ãããKNDåã¯çå³ã«é¢ããŠã¯åŠ¥åãèš±ããªãã®ã§ããã Input å
¥åã¯è€æ°ã®ãã¹ãã±ãŒã¹ãããªãã ã²ãšã€ã®ãã¹ãã±ãŒã¹ã¯ä»¥äžã®ãªåœ¢åŒã§äžããããã å
¥åã®çµäºã N = 0 ã®ãšã瀺ãã N x 1 y 1 v 1 x 2 y 2 v 2 ... x N y N v N ããã§ã N :çå³åŠã®æ° x i :içªç®ã®çå³åŠã®xåº§æš y i :içªç®ã®çå³åŠã®yåº§æš v i :içªç®ã®çå³åŠãžç§»åãããšãã®åäœæéãããã®ç§»åè·é¢ ã§ããã Constraints å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã å
¥åã¯ãã¹ãп޿°ã 2 †N †100 0 †x i , y i †100 1 †v i †100 ( 1 †i †N ) x i â x j or y i â y j ( ãã ã1 †i < j †N ) Output åãã¹ãã±ãŒã¹ã«ã€ãææªã®ç§»åæéã®æå°å€ãäžè¡ã«åºåããããã®å€ã¯ãžã£ããžåºåã®å€ãš10 -5 ãã倧ããå·®ãæã£ãŠã¯ãªããªãã Sample Input 2 1 1 1 2 2 1 4 1 1 3 3 1 3 4 2 1 1 5 3 0 Sample Output 0.70710678 1.06066017
| 38,907
|
Score : 100 points Problem Statement When you asked some guy in your class his name, he called himself S , where S is a string of length between 3 and 20 (inclusive) consisting of lowercase English letters. You have decided to choose some three consecutive characters from S and make it his nickname. Print a string that is a valid nickname for him. Constraints 3 \leq |S| \leq 20 S consists of lowercase English letters. Input Input is given from Standard Input in the following format: S Output Print your answer. Sample Input 1 takahashi Sample Output 1 tak Sample Input 2 naohiro Sample Output 2 nao
| 38,908
|
Taxi PCK Taxi in Aizu city, owned by PCK company, has adopted a unique billing system: the user can decide the taxi fare. Today as usual, many people are waiting in a queue at the taxi stand in front of the station. In front of the station, there are $N$ parking spaces in row for PCK taxis, each with an index running from $1$ to $N$. Each of the parking areas is occupied by a taxi, and a queue of potential passengers is waiting for the ride. Each one in the queue has his/her own plan for how much to pay for the ride. To increase the companyâs gain, the taxi driver is given the right to select the passenger who offers the highest taxi fare, rejecting others. The driver in the $i$-th parking space can perform the following actions any number of times in any sequence before he finally selects a passenger and starts driving. Offer a ride to the passenger who is at the head of the $i$-th parking spaceâs queue. Reject to offer a ride to the passenger who is at the head of the $i$-th parking spaceâs queue. The passenger is removed from the queue. Move to the $i + 1$-th parking area if it is empty. If he is in the $N$-th parking area, he leaves the taxi stand to cruise the open road. A preliminary listening is made as to the fare the users offer. Your task is to maximize the sales volume of PCK Taxi in reference to the table of offered fares. A taxi cannot accommodate more than one passenger. Given the number of taxi parking spaces and information regarding the persons waiting in the parking areas, calculate the maximum possible volume of sales. Input The input is given in the following format. $N$ $s_1$ $s_2$ $...$ $s_N$ The first line provides the number of taxi parking areas $N$ ($1 \leq N \leq 300,000$). Each of the subsequent $N$ lines provides information on the customers queueing in the $i$-th taxi parking area in the following format: $M$ $c_1$ $c_2$ ... $c_M$ The first integer $M$ ($1 \leq M \leq 300,000$) indicates the number of customers in the queue, and the subsequent array of integers $c_j$ ($1 \leq c_j \leq 10,000$) indicates the fare the $j$-th customer in the queue is willing to pay. The total number of customers in the taxi stand is equal to or less than $300,000$. Output Output the maximum volume of sales. Sample Input 3 3 8 10 1 4 7 1 2 15 3 11 8 19 Sample Output 45
| 38,909
|
Problem C: Chinese Classics Taro, a junior high school student, is working on his homework. Today's homework is to read Chinese classic texts. As you know, Japanese language shares the (mostly) same Chinese characters but the order of words is a bit different. Therefore the notation called "returning marks" was invented in order to read Chinese classic texts in the order similar to Japanese language. There are two major types of returning marks: 'Re' mark and jump marks. Also there are a couple of jump marks such as one-two-three marks, top-middle-bottom marks. The marks are attached to letters to describe the reading order of each letter in the Chinese classic text. Figure 1 is an example of a Chinese classic text annotated with returning marks, which are the small letters at the bottom-left of the big Chinese letters. Figure 1: a Chinese classic text Taro generalized the concept of jump marks, and summarized the rules to read Chinese classic texts with returning marks as below. Your task is to help Taro by writing a program that interprets Chinese classic texts with returning marks following his rules, and outputs the order of reading of each letter. When two (or more) rules are applicable in each step, the latter in the list below is applied first, then the former. Basically letters are read downwards from top to bottom, i.e. the first letter should be read (or skipped) first, and after the i -th letter is read or skipped, ( i + 1)-th letter is read next. Each jump mark has a type (represented with a string consisting of lower-case letters) and a number (represented with a positive integer). A letter with a jump mark whose number is 2 or larger must be skipped. When the i -th letter with a jump mark of type t , number n is read, and when there exists an unread letter L at position less than i that has a jump mark of type t , number n + 1, then L must be read next. If there is no such letter L , the ( k + 1)-th letter is read, where k is the index of the most recently read letter with a jump mark of type t , number 1. A letter with a 'Re' mark must be skipped. When the i -th letter is read and ( i - 1)-th letter has a 'Re' mark, then ( i - 1)-th letter must be read next. No letter may be read twice or more. Once a letter is read, the letter must be skipped in the subsequent steps. If no letter can be read next, finish reading. Let's see the first case of the sample input. We begin reading with the first letter because of the rule 1. However, since the first letter has a jump mark ' onetwo2 ', we must follow the rule 2 and skip the letter. Therefore the second letter, which has no returning mark, will be read first. Then the third letter will be read. The third letter has a jump mark ' onetwo1 ', so we must follow rule 3 and read a letter with a jump mark `onetwo2' next, if exists. The first letter has the exact jump mark, so it will be read third. Similarly, the fifth letter is read fourth, and then the sixth letter is read. Although we have two letters which have the same jump mark ' onetwo2 ', we must not take into account the first letter, which has already been read, and must read the fourth letter. Now we have read all six letters and no letter can be read next, so we finish reading. We have read the second, third, first, fifth, sixth, and fourth letter in this order, so the output is 2 3 1 5 6 4. Input The input contains multiple datasets. Each dataset is given in the following format: N mark 1 ... mark N N , a positive integer (1 †N †10,000), means the number of letters in a Chinese classic text. mark i denotes returning marks attached to the i -th letter. A 'Re' mark is represented by a single letter, namely, 'v' (quotes for clarity). The description of a jump mark is the simple concatenation of its type, specified by one or more lowercase letter, and a positive integer. Note that each letter has at most one jump mark and at most one 'Re' mark. When the same letter has both types of returning marks, the description of the jump mark comes first, followed by 'v' for the 'Re' mark. You can assume this happens only on the jump marks with the number 1. If the i -th letter has no returning mark, mark i is '-' (quotes for clarity). The length of mark i never exceeds 20. You may assume that input is well-formed, that is, there is exactly one reading order that follows the rules above. And in the ordering, every letter is read exactly once. You may also assume that the N -th letter does not have 'Re' mark. The input ends when N = 0. Your program must not output anything for this case. Output For each dataset, you should output N lines. The first line should contain the index of the letter which is to be read first, the second line for the letter which is to be read second, and so on. All the indices are 1-based. Sample Input 6 onetwo2 - onetwo1 onetwo2 - onetwo1 7 v topbottom2 onetwo2 - onetwo1 topbottom1 - 6 baz2 foo2 baz1v bar2 foo1 bar1 0 Output for the Sample Input 2 3 1 5 6 4 4 5 3 6 2 1 7 5 2 6 4 3 1
| 38,911
|
Score : 600 points Problem Statement We have a rectangular grid of squares with H horizontal rows and W vertical columns. Let (i,j) denote the square at the i -th row from the top and the j -th column from the left. On this grid, there is a piece, which is initially placed at square (s_r,s_c) . Takahashi and Aoki will play a game, where each player has a string of length N . Takahashi's string is S , and Aoki's string is T . S and T both consist of four kinds of letters: L , R , U and D . The game consists of N steps. The i -th step proceeds as follows: First, Takahashi performs a move. He either moves the piece in the direction of S_i , or does not move the piece. Second, Aoki performs a move. He either moves the piece in the direction of T_i , or does not move the piece. Here, to move the piece in the direction of L , R , U and D , is to move the piece from square (r,c) to square (r,c-1) , (r,c+1) , (r-1,c) and (r+1,c) , respectively. If the destination square does not exist, the piece is removed from the grid, and the game ends, even if less than N steps are done. Takahashi wants to remove the piece from the grid in one of the N steps. Aoki, on the other hand, wants to finish the N steps with the piece remaining on the grid. Determine if the piece will remain on the grid at the end of the game when both players play optimally. Constraints 2 \leq H,W \leq 2 \times 10^5 2 \leq N \leq 2 \times 10^5 1 \leq s_r \leq H 1 \leq s_c \leq W |S|=|T|=N S and T consists of the four kinds of letters L , R , U and D . Input Input is given from Standard Input in the following format: H W N s_r s_c S T Output If the piece will remain on the grid at the end of the game, print YES ; otherwise, print NO . Sample Input 1 2 3 3 2 2 RRL LUD Sample Output 1 YES Here is one possible progress of the game: Takahashi moves the piece right. The piece is now at (2,3) . Aoki moves the piece left. The piece is now at (2,2) . Takahashi does not move the piece. The piece remains at (2,2) . Aoki moves the piece up. The piece is now at (1,2) . Takahashi moves the piece left. The piece is now at (1,1) . Aoki does not move the piece. The piece remains at (1,1) . Sample Input 2 4 3 5 2 2 UDRRR LLDUD Sample Output 2 NO Sample Input 3 5 6 11 2 1 RLDRRUDDLRL URRDRLLDLRD Sample Output 3 NO
| 38,912
|
Sum of Sequences Problem n åã®èŠçŽ ãæã€æ°å A ã m åã®èŠçŽ ãæã€æ°å B ã ãããããæŽæ° c ãããªã q åã®ã¯ãšãªãäžããããã åã¯ãšãªã«ã€ããŠã æ°å A ã®[ l a , r a ]ãå
šãŠè¶³ããæ°ãšæ°å B ã®[ l b , r b ]ãå
šãŠè¶³ããæ°ã®å·®ã®çµ¶å¯Ÿå€ã c ã«ãªã l a , r a , l b , r b (0 †l a †r a †n â1, 0 †l b †r b †m â1, é
åã®çªå·ã¯0çªããå§ãŸã) ã®çµã¿åããã®æ°ãæ±ããã Input n m q a 0 a 1 ... a nâ1 b 0 b 1 ... b mâ1 c 0 c 1 ... c qâ1 å
¥åã¯å
šãп޿°ã§äžããããã 1è¡ç®ã«æ°åã®èŠçŽ æ° n ãš m ãã¯ãšãªæ° q ãäžããããã 2è¡ç®ã«æ°å A ã®èŠçŽ ã3è¡ç®ã«æ°å B ã®èŠçŽ ã空çœåºåãã§äžããããã 4è¡ç®ãã q è¡ã«åã¯ãšãªã®å€ c i ãäžããããã Constraints 1 †n , m †4Ã10 4 1 †q †10 5 1 †a i , b i †5 0 †c i †2Ã10 5 Output åºå㯠q è¡ãããªããåã¯ãšãªã®çµã¿åããã®æ°ãé çªã«äžè¡ã«åºåããã Sample Input 1 3 3 1 1 2 3 3 1 2 3 Sample Output 1 6 Sample Input 2 5 4 2 1 2 3 4 5 2 2 2 2 11 12 Sample Output 2 3 4
| 38,913
|
Problem C: Earn Big A group of N people is trying to challenge the following game to earn big money. First, N participants are isolated from each other. From this point, they are not allowed to contact each other, or to leave any information for other participants. The game organizer leads each participant, one by one, to a room with N boxes. The boxes are all closed at the beginning of the game, and the game organizer closes all the boxes whenever a participant enters the room. Each box contains a slip of paper on which a name of a distinct participant is written. The order of the boxes do not change during the game. Each participant is allowed to open up to M boxes. If every participant is able to open a box that contains a paper of his/her name, then the group wins the game, and everybody in the group earns big money. If anyone is failed to open a box that contains a paper of his/her name, then the group fails in the game, and nobody in the group gets money. Obviously, if every participant picks up boxes randomly, the winning probability will be (M/N) N . However, there is a far more better solution. Before discussing the solution, let us define some concepts. Let P = {p 1 , p 2 , ..., p N } be a set of the participants, and B = {b 1 , b 2 , ..., b N } be a set of the boxes. Let us define f , a mapping from B to P , such that f(b) is a participant whose name is written on a paper in a box b . Here, consider a participant p i picks up the boxes in the following manner: Let x := i . If p i has already opened M boxes, then exit as a failure. p i opens b x . If f(b x ) = p i , then exit as a success. If f(b x ) = p j ( i != j ), then let x := j , and go to 2. Assuming every participant follows the algorithm above, the result of the game depends only on the initial order of the boxes (i.e. the definition of f ). Let us define g to be a mapping from P to B , such that g(p i ) = b i . The participants win the game if and only if, for every i â {1, 2, ..., N} , there exists k(<=M) such that (f g) k (p i ) = p i . Your task is to write a program that calculates the winning probability of this game. You can assume that the boxes are placed randomly. Input The input consists of one line. It contains two integers N and M (1 <= M <= N <= 1,000) in this order, delimited by a space. Output For given N and M , your program should print the winning probability of the game. The output value should be in a decimal fraction and should not contain an error greater than 10 -8 . Sample Input 1 2 1 Output for the Sample Input 1 0.50000000 Sample Input 2 100 50 Output for the Sample Input 2 0.31182782
| 38,914
|
Short Phrase A Short Phrase (aka. Tanku) is a fixed verse, inspired by Japanese poetry Tanka and Haiku. It is a sequence of words, each consisting of lowercase letters 'a' to 'z', and must satisfy the following condition: (The Condition for a Short Phrase) The sequence of words can be divided into five sections such that the total number of the letters in the word(s) of the first section is five, that of the second is seven, and those of the rest are five, seven, and seven, respectively. The following is an example of a Short Phrase. do the best and enjoy today at acm icpc In this example, the sequence of the nine words can be divided into five sections (1) "do" and "the", (2) "best" and "and", (3) "enjoy", (4) "today" and "at", and (5) "acm" and "icpc" such that they have 5, 7, 5, 7, and 7 letters in this order, respectively. This surely satisfies the condition of a Short Phrase. Now, Short Phrase Parnassus published by your company has received a lot of contributions. By an unfortunate accident, however, some irrelevant texts seem to be added at beginnings and ends of contributed Short Phrases. Your mission is to write a program that finds the Short Phrase from a sequence of words that may have an irrelevant prefix and/or a suffix. Input The input consists of multiple datasets, each in the following format. n w 1 ... w n Here, n is the number of words, which is a positive integer not exceeding 40; w i is the i -th word, consisting solely of lowercase letters from 'a' to 'z'. The length of each word is between 1 and 10, inclusive. You can assume that every dataset includes a Short Phrase. The end of the input is indicated by a line with a single zero. Output For each dataset, output a single line containing i where the first word of the Short Phrase is w i . When multiple Short Phrases occur in the dataset, you should output the first one. Sample Input 9 do the best and enjoy today at acm icpc 14 oh yes by far it is wow so bad to me you know hey 15 abcde fghijkl mnopq rstuvwx yzz abcde fghijkl mnopq rstuvwx yz abcde fghijkl mnopq rstuvwx yz 0 Output for the Sample Input 1 2 6
| 38,915
|
Score : 300 points Problem Statement You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N , respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C . For that, you can use the following three kinds of magics any number: Extension Magic: Consumes 1 MP (magic point). Choose one bamboo and increase its length by 1 . Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1 . Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective? Constraints 3 \leq N \leq 8 1 \leq C < B < A \leq 1000 1 \leq l_i \leq 1000 All values in input are integers. Input Input is given from Standard Input in the following format: N A B C l_1 l_2 : l_N Output Print the minimum amount of MP needed to achieve the objective. Sample Input 1 5 100 90 80 98 40 30 21 80 Sample Output 1 23 We are obtaining three bamboos of lengths 100, 90, 80 from five bamboos 98, 40, 30, 21, 80 . We already have a bamboo of length 80 , and we can obtain bamboos of lengths 100, 90 by using the magics as follows at the total cost of 23 MP, which is optimal. Use Extension Magic twice on the bamboo of length 98 to obtain a bamboo of length 100 . (MP consumed: 2 ) Use Composition Magic on the bamboos of lengths 40, 30 to obtain a bamboo of length 70 . (MP consumed: 10 ) Use Shortening Magic once on the bamboo of length 21 to obtain a bamboo of length 20 . (MP consumed: 1 ) Use Composition Magic on the bamboo of length 70 obtained in step 2 and the bamboo of length 20 obtained in step 3 to obtain a bamboo of length 90 . (MP consumed: 10 ) Sample Input 2 8 100 90 80 100 100 90 90 90 80 80 80 Sample Output 2 0 If we already have all bamboos of the desired lengths, the amount of MP needed is 0 . As seen here, we do not necessarily need to use all the bamboos. Sample Input 3 8 1000 800 100 300 333 400 444 500 555 600 666 Sample Output 3 243
| 38,917
|
åå²çµ±æ²» 倪éãããšè±åãããšæ¬¡éããã¯3人㧠JAG çåœã統治ããŠããïŒJAG çåœã«ã¯ N åã®è¡ãååšãïŒããã€ãã®è¡ã¯åæ¹åã®éè·¯ã§ç¹ãã£ãŠããïŒã©ã®è¡ãããå¥ã®ãã¹ãŠã®è¡ãž 1 æ¬ä»¥äžã®éè·¯ãçµç±ããŠå¿
ã蟿ãçãããšãã§ããïŒ ããæ¥å€ªéãããšè±åããã¯ãšããšã仲éããèµ·ãããŠããŸãïŒ3 人ã§è¡ãåæ
ããŠçµ±æ²»ããããšã«æ±ºããïŒãããïŒããŸãã«ãä»²ãæªããªããããŠããŸã£ãããïŒå€ªéããã統治ããŠããè¡ãšè±åããã統治ããŠããè¡ã 1 æ¬ã®éè·¯ã§çŽæ¥ç¹ãã£ãŠããããšããå«ãã£ãŠããïŒããã§ïŒä»¥äžã®æ¡ä»¶ãæºããããã«çµ±æ²»ããè¡ãåæ
ããããšã«ããïŒ å€ªéããã統治ããè¡ãšè±åããã統治ããè¡ãããªãä»»æã®ãã¢ã¯ïŒçŽæ¥éè·¯ã§ç¹ãã£ãŠããªãïŒããã¯å€ªéãããšè±åããã®ä»²ããã¡ããã¡ãæªãããã§ããïŒ åã人ã«çµ±æ²»ãããŠããè¡å士ãçŽæ¥éè·¯ã§ç¹ãã£ãŠããªãïŒããã¯ïŒãããªäžã§ãä»è
ã®çµ±æ²»äžã®çµç±ã矩åä»ããããšã§å€äº€ãä¿ãããã§ããïŒ å€ªéããã®çµ±æ²»ããè¡ã®ç·æ°ãšè±åããã統治ããè¡ã®ç·æ°ã¯åãã§ãªããã°ãªããªãïŒããã¯ç·æ°ãçããããªããšå€ªéãããšè±åããã®ä»²ãããã«ãã¡ããã¡ãæªããªãããã ããã§ããïŒããã§ïŒæ¬¡éããã¯ãšãŠãå¿ãåºãã®ã§ïŒæ¬¡éããã統治ããè¡ã®ç·æ°ã¯ããã€ã§ãããïŒ ä»¥äžã®æ¡ä»¶ãæºãããããªåæ
ã§ããã°ïŒ3 人ã¯çŽåŸããŠçµ±æ²»ããããšãã§ãïŒããšã誰ãã®çµ±æ²»ããè¡ã 0 åã§ãã£ãŠãæå¥ã¯ãªãïŒãã®ãšãïŒå€ªéããã統治ããè¡ã®ç·æ° (=è±åããã統治ããè¡ã®ç·æ°) ãšããŠããåŸãæ°ããã¹ãŠåæããããã°ã©ã ãäœæããïŒ Input å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒ ããŒã¿ã»ããã®æ°ã¯æå€§ã§ 50 ã§ããïŒ åããŒã¿ã»ããã¯ïŒæ¬¡ã®åœ¢åŒã§è¡šãããïŒ N M u 1 v 1 ... u M v M 1 è¡ç®ã¯ 2 ã€ã®æŽæ° N ( 2 †N †10 3 ) ãš M ( 1 †M †10 3 ) ãããªãïŒããããè¡ã®æ°ãšéè·¯ã®æ°ã衚ãïŒç¶ã M è¡ã®ãã¡ i è¡ç®ã¯ 2 ã€ã®æŽæ° u i ãš v i ( 1 †u i < v i †N ) ãããªãïŒ i çªç®ã®éè·¯ãè¡ u i ãš è¡ v i ãåæ¹åã«ç¹ãã§ããããšã衚ãïŒããã§ïŒã©ã®è¡ãããå¥ã®ãã¹ãŠã®è¡ãž 1 æ¬ä»¥äžã®éè·¯ãçµç±ããŠå¿
ã蟿ãçãããšãã§ããããšãä¿èšŒãããïŒãŸãïŒåãè¡ã®ãã¢ãçµã¶éè·¯ãè€æ°äžããããããšã¯ãªãïŒããªãã¡ïŒãã¹ãŠã® 1 †i < j †M ã«ã€ã㊠(u i , v i ) â (u j , v j ) ãæºããïŒ å
¥åã®çµãã㯠2 ã€ã®ãŒããããªãè¡ã§è¡šãããïŒ Output åããŒã¿ã»ããã«ã€ããŠïŒå€ªéããã統治ããè¡ã®ç·æ°ãšããŠèããããæ°ã K éããããšãïŒãŸã 1 è¡ç®ã« K ãåºåãïŒãã®åŸïŒããåŸãç·æ°ã 1 è¡ã« 1 ã€ãã€æé ã§åºåããïŒ Sample Input 6 7 1 2 1 4 2 3 2 5 3 4 4 5 4 6 2 1 1 2 3 3 1 2 1 3 2 3 4 3 1 2 2 3 3 4 5 4 1 2 2 3 3 4 4 5 0 0 Output for the Sample Input 2 1 2 0 0 1 1 1 1
| 38,918
|
Jigsaw Puzzles for Computers Ordinary Jigsaw puzzles are solved with visual hints; players solve a puzzle with the picture which the puzzle shows on finish, and the diverse patterns of pieces. Such Jigsaw puzzles may be suitable for human players, because they require abilities of pattern recognition and imagination. On the other hand, "Jigsaw puzzles" described below may be just the things for simple-minded computers. As shown in Figure 1 , a puzzle is composed of nine square pieces, and each of the four edges of a piece is labeled with one of the following eight symbols: "R", "G", "B", "W", "r", "g", "b" , and "w". Figure 1 : The nine pieces of a puzzle In a completed puzzle, the nine pieces are arranged in a 3 x 3 grid, and each of the 12 pairs of edges facing each other must be labeled with one of the following four combinations of symbols: "R" with "r" , "G" with "g" , "B" with "b" , and "W" with "w" . For example, an edge labeled "R" can only face an edge with "r" . Figure 2 is an example of a completed state of a puzzle. In the figure, edges under this restriction are indicated by shadowing their labels. The player can freely move and rotate the pieces, but cannot turn them over. There are no symbols on the reverse side of a piece ! Figure 2 : A completed puzzle example Each piece is represented by a sequence of the four symbols on the piece, starting with the symbol of the top edge, followed by the symbols of the right edge, the bottom edge, and the left edge. For example, gwgW represents the leftmost piece in Figure 1 . Note that the same piece can be represented as wgWg , gWgw or Wgwg since you can rotate it in 90, 180 or 270 degrees. The mission for you is to create a program which counts the number of solutions. It is needless to say that these numbers must be multiples of four, because, as shown in Figure 3 , a configuration created by rotating a solution in 90, 180 or 270 degrees is also a solution. Figure 3 : Four obvious variations for a completed puzzle A term "rotationally equal" is defined; if two different pieces are identical when one piece is rotated (in 90, 180 or 270 degrees), they are rotationally equal. For example, WgWr and WrWg are rotationally equal. Another term "rotationally symmetric" is defined; if a piece is rotationally equal to itself, it is rotationally symmetric. For example, a piece gWgW is rotationally symmetric. Given puzzles satisfy the following three conditions: There is no identical pair of pieces in a puzzle. There is no rotationally equal pair of pieces in a puzzle. There is no rotationally symmetric piece in a puzzle. Input The input consists of multiple puzzles. N Puzzle 1 Puzzle 2 . . . Puzzle N N is the number of puzzles. Each Puzzle i gives a puzzle with a single line of 44 characters, consisting of four-character representations of the nine pieces of the puzzle, separated by a space character. For example, the following line represents the puzzle in Figure 1 . gwgW RBbW GWrb GRRb BWGr Rbgw rGbR gBrg GRwb Output For each Puzzle i , the number of its solutions should be the output, each in a separate line. Sample Input 6 WwRR wwrg RRGb rGBG RGrb RrRg RGrg rgBB Wrgr RrGb WWGR rGgb Wbrg wgBb GgBg WbBG Wwwg WWGG RBbr Wrbr wGGG wggR WgGR WBWb WRgB wBgG WBgG wBrg rGgb WRrB WWbw wRRB RbbB WRrb wrbb WgrG WrwB WWww wRRB WGGb Wbbg WBgG WrbG Wrww RBgg WWgg RBrr Rggr RGBg Wbgr WGbg WBbr WGWB GGGg Output for the Sample Input: 40 8 32 4 12 0
| 38,919
|
RMQ and RUQ Write a program which manipulates a sequence A = { a 0 , a 1 , . . . , a nâ1 } with the following operations: update(s, t, x) : change a s , a s+1 , ..., a t to x . find(s, t) : report the minimum element in a s , a s+1 , ..., a t . Note that the initial values of a i ( i = 0, 1, . . . , nâ1 ) are 2 31 -1. Input n q query 1 query 2 : query q In the first line, n (the number of elements in A ) and q (the number of queries) are given. Then, i th query query i is given in the following format: 0 s t x or 1 s t The first digit represents the type of the query. '0' denotes update(s, t, x) and '1' denotes find(s, t) . Output For each find operation, print the minimum value. Constraints 1 †n †100000 1 †q †100000 0 †s †t < n 0 †x < 2 31 â1 Sample Input 1 3 5 0 0 1 1 0 1 2 3 0 2 2 2 1 0 2 1 1 2 Sample Output 1 1 2 Sample Input 2 1 3 1 0 0 0 0 0 5 1 0 0 Sample Output 2 2147483647 5
| 38,920
|
Score : 1600 points Problem Statement There is a tree with N vertices, numbered 1 through N . The i -th of the N-1 edges connects vertices a_i and b_i . Currently, there are A_i stones placed on vertex i . Takahashi and Aoki will play a game using this tree. First, Takahashi will select a vertex and place a piece on it. Then, starting from Takahashi, they will alternately perform the following operation: Remove one stone from the vertex currently occupied by the piece. Then, move the piece to a vertex that is adjacent to the currently occupied vertex. The player who is left with no stone on the vertex occupied by the piece and thus cannot perform the operation, loses the game. Find all the vertices v such that Takahashi can place the piece on v at the beginning and win the game. Constraints 2 ⊠N ⊠3000 1 ⊠a_i,b_i ⊠N 0 ⊠A_i ⊠10^9 The given graph is a tree. Input The input is given from Standard Input in the following format: N A_1 A_2 ⊠A_N a_1 b_1 : a_{N-1} b_{N-1} Output Print the indices of the vertices v such that Takahashi can place the piece on v at the beginning and win the game, in a line, in ascending order. Sample Input 1 3 1 2 3 1 2 2 3 Sample Output 1 2 The following is one possible progress of the game when Takahashi places the piece on vertex 2 : Takahashi moves the piece to vertex 1 . The number of the stones on each vertex is now: (1,1,3) . Aoki moves the piece to vertex 2 . The number of the stones on each vertex is now: (0,1,3) . Takahashi moves the piece to vertex 1 . The number of the stones on each vertex is now: (0,0,3) . Aoki cannot take a stone from the vertex, and thus Takahashi wins. Sample Input 2 5 5 4 1 2 3 1 2 1 3 2 4 2 5 Sample Output 2 1 2 Sample Input 3 3 1 1 1 1 2 2 3 Sample Output 3 Note that the correct output may be an empty line.
| 38,921
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.