task
stringlengths 0
154k
| __index_level_0__
int64 0
39.2k
|
|---|---|
Problem J: Hanimon ããã«ã ã¢ã³ã¹ã¿ãŒã¯ããã«ã æš¡æ§ã®å
è§åœ¢ç¶ã®äžæè°ãªçãç©ã§ããã ããã«ã ã¢ã³ã¹ã¿ãŒã«ã¯æ§ã
ãªãµã€ãºã®ãã®ããããäžèŸºã N åã®æ£å
è§åœ¢ã®ãã¹ããæãããã«ã ã¢ã³ã¹ã¿ãŒããµã€ãº N ã®ããã«ã ã¢ã³ã¹ã¿ãŒãšããã äžæ¹ãèãªãæš¡æ§ã¯ããã«ã ã¢ã³ã¹ã¿ãŒãšåãããå
è§åœ¢ãšããŠå®çŸ©ãã1蟺ã P åã®æ£å
è§åœ¢ã®ãã¹ããæãèãªãæš¡æ§ããµã€ãº P ã®èãªãæš¡æ§ãšããã ããã«ã ã¢ã³ã¹ã¿ãŒãšèãªãæš¡æ§ã®åœ¢ã®äŸã以äžã«ç€ºãããµã€ãºã¯1èŸºã®æ£å
è§åœ¢ã®ãã¹ã®æ°ã«å¯Ÿå¿ããã å³1: ãµã€ãºã®äŸ å³2: ããã«ã ã¢ã³ã¹ã¿ãŒãšèãªãæš¡æ§ã®äŸ (Sample Input 1) ããã«ã ã¢ã³ã¹ã¿ãŒãšèãªãæš¡æ§ã®åãã¹ã«ã¯è²ãçããŠãã0ãš1ã«ãã£ãŠè¡šãããã ãµã€ãº P ã® Q åã®èãªãæš¡æ§ã®ãã¹ãŠãå«ãããã«ã ã¢ã³ã¹ã¿ãŒã¯äŒèª¬ã®ããã¢ã³ãšåŒã°ããŠããã ãµã€ãº N ã®ããã«ã ã¢ã³ã¹ã¿ãŒãšãã®æš¡æ§ã Q åã®ãµã€ãº P ã®èãªãæš¡æ§ãäžããããã®ã§ã ãã®ããã«ã ã¢ã³ã¹ã¿ãŒãäŒèª¬ã®ããã¢ã³ã§ãããã©ãããå€å®ããããã°ã©ã ãäœæããã Input å
¥åã¯æ¬¡ã®åœ¢åŒã§è¡šãããã N P Q (空è¡) ããã«ã ã¢ã³ã¹ã¿ãŒã®æš¡æ§ã®æ
å ± (空è¡) 1ã€ç®ã®èãªãæš¡æ§ã®æ
å ± (空è¡) 2ã€ç®ã®èãªãæš¡æ§ã®æ
å ± (空è¡) ... Q ã€ç®ã®èãªãæš¡æ§ã®æ
å ± N , P , Q ã¯ããããããã«ã ã¢ã³ã¹ã¿ãŒã®ãµã€ãº,èãªãæš¡æ§ã®ãµã€ãº,èãªãæš¡æ§ã®åæ°ã衚ãã ãµã€ãº N ã®ããã«ã ã¢ã³ã¹ã¿ãŒã®æš¡æ§ã®æ
å ±ã¯ä»¥äžã®æ§ã«2à N -1è¡ã§äžããããã N åã®ãã¹ N +1åã®ãã¹ N +2åã®ãã¹ . . 2à N -2åã®ãã¹ 2à N -1åã®ãã¹ 2à N -2åã®ãã¹ . . N +2åã®ãã¹ N +1åã®ãã¹ N åã®ãã¹ ãµã€ãº P ã®èãªãæš¡æ§ã®æ
å ±ã¯ä»¥äžã®æ§ã«2à P -1è¡ã§äžããããã P åã®ãã¹ P +1åã®ãã¹ P +2åã®ãã¹ . . 2à P -2åã®ãã¹ 2à P -1åã®ãã¹ 2à P -2åã®ãã¹ . . P +2åã®ãã¹ P +1åã®ãã¹ P åã®ãã¹ ããããã®ãã¹ã®éã«ã¯ïŒã€ã®ç©ºçœãå
¥ãããã¹ã«ã¯ïŒã1ãå
¥ãã Constraints 1 †N †1000 1 †P †50 1 †Q †100 åãæš¡æ§ã®èãªãæš¡æ§ãè€æ°åäžããããããšã¯ç¡ãã ããã«ã ã¢ã³ã¹ã¿ãŒã®ãããã¹ã«ã€ããŠã2ã€ä»¥äžã®èãªãæš¡æ§ã®äžéšåã§ããããšãããã ããã«ã ã¢ã³ã¹ã¿ãŒãšèãªãæš¡æ§ã¯å転ã§ããªãã Output äŒèª¬ã®ããã¢ã³ãªã YES ããããã§ãªããã° NO ãäžè¡ã«åºåããã Sample Input 1 6 2 2 1 1 1 1 1 1 1 0 0 0 0 1 0 1 0 1 0 0 1 0 1 1 1 1 1 1 1 1 0 0 0 0 1 0 0 0 1 0 1 1 1 1 1 0 1 0 0 1 1 0 1 0 1 0 1 0 0 1 1 1 0 0 1 1 1 1 0 0 1 1 0 0 0 0 1 0 1 0 1 1 1 0 1 1 0 0 1 1 0 0 1 0 1 1 1 1 1 0 0 0 0 1 0 1 1 Sample Output 1 YES Sample Input 2 6 2 2 0 0 0 1 0 0 1 0 1 1 0 0 1 1 0 1 0 0 1 1 0 0 1 0 1 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1 0 0 0 1 0 0 1 1 0 0 0 0 0 1 0 0 1 1 0 1 1 1 0 0 1 1 1 1 1 1 0 1 0 0 1 0 0 0 0 0 1 0 1 0 0 0 1 1 0 1 0 1 0 1 0 0 1 1 0 1 0 0 1 0 1 Sample Output 2 NO
| 38,284
|
Score : 600 points Problem Statement You are given a string s consisting of A , B and C . Snuke wants to perform the following operation on s as many times as possible: Choose a contiguous substring of s that reads ABC and replace it with BCA . Find the maximum possible number of operations. Constraints 1 \leq |s| \leq 200000 Each character of s is A , B and C . Input Input is given from Standard Input in the following format: s Output Find the maximum possible number of operations. Sample Input 1 ABCABC Sample Output 1 3 You can perform the operations three times as follows: ABCABC â BCAABC â BCABCA â BCBCAA . This is the maximum result. Sample Input 2 C Sample Output 2 0 Sample Input 3 ABCACCBABCBCAABCB Sample Output 3 6
| 38,285
|
å顿 1ã€ã®é°é¢æ° $Ax^2+Bxy+Cy^2+Dx+Ey+F=0$ ã§äžããããæ²ç·ãšã $N$ åã®é°é¢æ° $A_ix+B_iy+C_i=0$ ã§äžããããçŽç·ãããã ãããã®æ²ç·ãšçŽç·ã«ãã£ãŠå¹³é¢ãããã€ã®é åã«åå²ãããŠãããæ±ããã 以äžã¯Sample Inputã®ããŒã¿ã»ãããå³ç€ºãããã®ã§ããã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã«åŸããäžããããæ°ã¯å
šãп޿°ã§ããã $N$ $A$ $B$ $C$ $D$ $E$ $F$ $A_1$ $B_1$ $C_1$ $...$ $A_N$ $B_N$ $C_N$ å¶çŽ $1 \leq N \leq 20$ $-100 \leq A,B,C,D,E,F \leq 100$ $-100 \leq A_i,B_i,C_i \leq 100$ $A_i \neq 0$ ãŸã㯠$B_i \neq 0$ æ²ç·ã¯æ¥å(æ£åãå«ã)ãæŸç©ç·ãåæ²ç·ã®ããããã§ããã åäžã®çŽç·ãååšããå Žåãããã åºå é åã®æ°ã1è¡ã«åºåããã Sample Input 1 1 1 0 1 0 0 -1 1 -1 0 Output for the Sample Input 1 4 Sample Input 2 2 1 0 0 0 -1 0 2 -1 -1 6 9 1 Output for the Sample Input 2 7 Sample Input 3 2 1 0 -1 0 0 -1 3 0 6 -5 0 -10 Output for the Sample Input 3 6
| 38,286
|
Score : 200 points Problem Statement You have A 500 -yen coins, B 100 -yen coins and C 50 -yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different. Constraints 0 \leq A, B, C \leq 50 A + B + C \geq 1 50 \leq X \leq 20 000 A , B and C are integers. X is a multiple of 50 . Input Input is given from Standard Input in the following format: A B C X Output Print the number of ways to select coins. Sample Input 1 2 2 2 100 Sample Output 1 2 There are two ways to satisfy the condition: Select zero 500 -yen coins, one 100 -yen coin and zero 50 -yen coins. Select zero 500 -yen coins, zero 100 -yen coins and two 50 -yen coins. Sample Input 2 5 1 0 150 Sample Output 2 0 Note that the total must be exactly X yen. Sample Input 3 30 40 50 6000 Sample Output 3 213
| 38,287
|
Score : 400 points Problem Statement Let \mathrm{popcount}(n) be the number of 1 s in the binary representation of n . For example, \mathrm{popcount}(3) = 2 , \mathrm{popcount}(7) = 3 , and \mathrm{popcount}(0) = 0 . Let f(n) be the number of times the following operation will be done when we repeat it until n becomes 0 : "replace n with the remainder when n is divided by \mathrm{popcount}(n) ." (It can be proved that, under the constraints of this problem, n always becomes 0 after a finite number of operations.) For example, when n=7 , it becomes 0 after two operations, as follows: \mathrm{popcount}(7)=3 , so we divide 7 by 3 and replace it with the remainder, 1 . \mathrm{popcount}(1)=1 , so we divide 1 by 1 and replace it with the remainder, 0 . You are given an integer X with N digits in binary. For each integer i such that 1 \leq i \leq N , let X_i be what X becomes when the i -th bit from the top is inverted. Find f(X_1), f(X_2), \ldots, f(X_N) . Constraints 1 \leq N \leq 2 \times 10^5 X is an integer with N digits in binary, possibly with leading zeros. Input Input is given from Standard Input in the following format: N X Output Print N lines. The i -th line should contain the value f(X_i) . Sample Input 1 3 011 Sample Output 1 2 1 1 X_1 = 7 , which will change as follows: 7 \rightarrow 1 \rightarrow 0 . Thus, f(7) = 2 . X_2 = 1 , which will change as follows: 1 \rightarrow 0 . Thus, f(1) = 1 . X_3 = 2 , which will change as follows: 2 \rightarrow 0 . Thus, f(2) = 1 . Sample Input 2 23 00110111001011011001110 Sample Output 2 2 1 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 3
| 38,288
|
Problem 08: Provident Housewife 䞻婊ã®çŽåã¯ãã®äžæ³ã®ããªãé£è²»ãæããããšã«éå¿ãçãããŠããŸãããæ¯ææ°èåºåãå¿
ããã§ãã¯ãè²·ãç©ãªã¹ããšæãå®ã売ãããŠãããåºããã£ãããªã¹ãã¢ããããŠããåºãã¯ããããªããããšããã³ã»ãµã³ãã«ãšããæŠéã¹ã¿ã€ã«ã§èªè»¢è»ãããããè²·ãç©ã«è¡ããŸãã ããã§å€«ã®ããªãã¯å°ãã§ãçŽåã®åœ¹ã«ç«ãšããšãåŸæã®ããã°ã©ãã³ã°ã§å®¶èšç°¿ããã°ã©ã ãäœæããããšã«ããŸãããããã°ã©ã ã¯ãåã¹ãŒããŒã«å£²ã£ãŠããåç©ã®ååãšå€æ®µïŒåïŒãçŽåãå¿
èŠãªåç©ãå
¥åããå
šãŠã®åç©ãéããããã®æå°éé¡ãåºåããŸãã çŽåã¯å®¶ãåºãŠå¿
èŠãªåç©ãéããå®¶ã«æ»ã£ãŠããªããã°ãªããŸããã ããã§ãçŽåãæ°é£ã£ãããªãã¯ãæå°éé¡ãåãã«ãªãè²·ãç©ã«ãŒããè€æ°ããå Žåãèæ
®ããŠãããè·é¢ãçããªãã«ãŒãã®è·é¢ãå ±åããæ©èœã远å ããããšã«ããŸãããåŸã£ãŠãããã°ã©ã ã¯ã¹ãŒããŒã»å®¶éãç¹ãéã®æ
å ±ãå
¥åããŸãã ã¹ãŒããŒã®æ°ã n ãšããåã¹ãŒããŒã«ã¯ãããã 1 ãã n ãŸã§ã®çªå·ãå²ãåœãŠãããŸããããã«çŽåã®å®¶ã 0 çªãšããŸããéã®æ
å ±ã¯ãããã®çªå·ã®ãã¢ãšãã®è·é¢ïŒæŽæ°ïŒã§äžããããŸãã Input å
¥åãšããŠè€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã®åœ¢åŒã¯ä»¥äžã®éãã§ãïŒ n ïŒã¹ãŒããŒã®æ°ïŒæŽæ°ïŒ k 1 name 1 value 1 name 2 value 2 . . . name k 1 value k 1 ïŒ1 çªç®ã®ã¹ãŒããŒã«ããåç©ã®çš®é¡ã®æ°ã1ã€ç®ã®åç©åãšå€æ®µã2ã€ç®ã®åç©åãšå€æ®µ,,,ïŒæŽæ°ãšæååã®ç©ºçœåºåãïŒ k 2 name 1 value 1 name 2 value 2 . . . name k 2 value k 2 ïŒ2 çªç®ã®ã¹ãŒããŒã«ããåç©ã®çš®é¡ã®æ°ã1ã€ç®ã®åç©åãšå€æ®µã2ã€ç®ã®åç©åãšå€æ®µ,,,ïŒæŽæ°ãšæååã®ç©ºçœåºåãïŒ . . k n name 1 value 1 name 2 value 2 . . . name k n value k n ïŒ n çªç®ã®ã¹ãŒããŒã«ããåç©ã®çš®é¡ã®æ°ã1ã€ç®ã®åç©åãšå€æ®µã2ã€ç®ã®åç©åãšå€æ®µ,,,ïŒæŽæ°ãšæååã®ç©ºçœåºåãïŒ q ïŒå¿
èŠãªåç©ã®æ°ïŒæŽæ°ïŒ name 1 ïŒ1 ã€ç®ã®å¿
èŠãªåç©ã®ååïŒæååïŒ name 2 ïŒ2 ã€ç®ã®å¿
èŠãªåç©ã®ååïŒæååïŒ . . name q ïŒ q ã€ç®ã®å¿
èŠãªåç©ã®ååïŒæååïŒ m ïŒéã®æ°ïŒæŽæ°ïŒ s 1 t 1 d 1 ïŒ1 æ¬ç®ã®éã®æ
å ±ïŒç©ºçœåºåãã®æŽæ°ïŒ s 2 t 2 d 2 ïŒ2 æ¬ç®ã®éã®æ
å ±ïŒç©ºçœåºåãã®æŽæ°ïŒ . . s m t m d m ïŒ m æ¬ç®ã®éã®æ
å ±ïŒç©ºçœåºåãã®æŽæ°ïŒ s i t i d i 㯠s i çªç®ã®ã¹ãŒããŒïŒãŸãã¯å®¶ïŒãš t i çªç®ã®ã¹ãŒããŒïŒãŸãã¯å®¶ïŒãåæ¹åã«è¡ãæ¥ããããšãã§ãããã®è·é¢ã d i ã§ããããšã瀺ããŸãã å®¶ããïŒã¹ãŒããŒãçµç±ããŠïŒå
šãŠã®ã¹ãŒããŒãžè¡ãããšãã§ãããããªéãäžããããŸãã n 㯠10 以äžã§ããã q 㯠15 以äžãšããŸãã k i 㯠100 以äžã§ããã åç©åã®æåå㯠20æåãè¶ããåç©ã®å€æ®µã¯ 10000 ãè¶ããŸããã ãŸããéã®é·ã㯠1000 ãè¶ããŸããã n ã 0 ã®ãšããå
¥åã®çµãããšããŸãã Output åããŒã¿ã»ããã«ã€ããŠãæå°ã®éé¡ãšè·é¢ãïŒã€ã®ç©ºçœã§åºåã£ãŠïŒè¡ã«åºåããŠäžããããã ããå¿
èŠãªåç©ãå
šãŠéããããªãå Žå㯠" impossible " ãšåºåããŠäžããã Sample Input 3 3 apple 100 banana 200 egg 300 3 apple 150 banana 100 cola 200 3 apple 100 banana 150 cola 200 3 apple banana cola 5 0 2 4 0 1 3 0 3 3 1 2 3 2 3 5 3 3 apple 100 banana 200 egg 300 3 apple 150 banana 100 cola 200 3 apple 100 banana 150 cola 200 4 apple banana cola jump 5 0 2 4 0 1 3 0 3 3 1 2 3 2 3 5 0 Output for the Sample Input 400 10 impossible
| 38,289
|
ã²ãŒã ãã©ã³ã¹ ããªãã¯åéºã²ãŒã ãäœæããŠããïŒãã®ã²ãŒã ã®ãã¬ã€ã€ãŒã¯ïŒäž»äººå
¬ãæäœããŠæµã¢ã³ã¹ã¿ãŒãåãïŒäž»äººå
¬ã®ã¬ãã«ãäžããããšã§åéºãé²ããŠããïŒäž»äººå
¬ã®åæã¬ãã«ã¯ 1 ã§ããïŒ ãã®ã²ãŒã ã«ã¯ N çš®é¡ã®æµã¢ã³ã¹ã¿ãŒãçšæãããŠããïŒåŒ±ãé ã§ i çªç®ã®çš®é¡ã®æµã¢ã³ã¹ã¿ãŒã®åŒ·ã㯠s i ã§ããïŒäž»äººå
¬ã 1 åã®æŠéãè¡ããšãã«ã¯ïŒæ¬¡ã«æŠãæµã¢ã³ã¹ã¿ãŒã®çš®é¡ãèªç±ã«éžã³ïŒã¡ããã© 1 äœã®æµã¢ã³ã¹ã¿ãŒãšæŠéãè¡ãïŒäž»äººå
¬ã¯åãçš®é¡ã®æµã¢ã³ã¹ã¿ãŒãšäœåã§ãæŠãããšãã§ãïŒäœåã§ãåãããšãã§ããïŒ ããªãã¯ããŸïŒãã®ã²ãŒã ã®ãã©ã³ã¹ã調æŽããããã«ïŒãããã©ã¡ãŒã¿ãŒ X ãæ±ºããããšããŠããïŒãã©ã¡ãŒã¿ãŒ X ã¯æ£ã®æŽæ°ã§ããäžèšã®ããã«äœ¿ãããïŒ äž»äººå
¬ã®ã¬ãã«ã L ã®ãšãïŒåŒ·ã s i ã L+X æªæºã®æµã¯åãããïŒããããåŒ·ãæµã¢ã³ã¹ã¿ãŒã¯åããªãïŒ äž»äººå
¬ã®ã¬ãã«ã L ã®ãšãïŒåŒ·ã s i ã®æµãåããš max(1, X-|L-s i |) ã ã䞻人å
¬ã®ã¬ãã«ãäžããïŒ ãã®ã²ãŒã ã¯ïŒæã匷ãïŒ N çš®é¡ç®ã®ïŒæµã¢ã³ã¹ã¿ãŒãåããŠåãããšãã«ã²ãŒã ã¯ãªã¢ãšãªãïŒããªãã¯ïŒã²ãŒã ã¯ãªã¢ãŸã§ã«å¿
èŠãšãªãæŠéã®åæ°ãæäœã§ã M å以äžãšãªãããã«ãã©ã¡ãŒã¿ãŒ X ãæ±ºããããšèããŠããïŒãã ãïŒæµã¢ã³ã¹ã¿ãŒã®åŒ·ãã®èšå®ã«ãã£ãŠã¯ïŒ X ãã©ã®ããã«èšå®ããŠã M åæªæºã®æŠéåæ°ã§ã²ãŒã ã¯ãªã¢ã§ããŠããŸããïŒã²ãŒã ãã¯ãªã¢ã§ããªããªã£ãŠããŸãå Žåãããããšã«æ³šæããïŒ ãã©ã¡ãŒã¿ãŒ X ãæ±ºãããšãïŒäžèšã®æ¡ä»¶ãæºããç¯å²ã§æå€§ã®ãã©ã¡ãŒã¿ãŒå€ X max ãèšç®ããããã°ã©ã ãäœã£ãŠã»ããïŒ Input å
¥åã¯è€æ°ã®ããŒã¿ã»ããããæ§æãããïŒããŒã¿ã»ããã®åæ°ã¯æå€§ã§ã 50 ãè¶
ããªãïŒåããŒã¿ã»ããã¯æ¬¡ã®åœ¢åŒã§è¡šãããïŒ N M s 1 s 2 ... s N 1 è¡ç®ã¯ç©ºçœã§åºåããã 2 ã€ã®æŽæ° N, M ãããªãïŒ N ã¯çšæããæµã¢ã³ã¹ã¿ãŒã®çš®é¡ã®æ°ïŒ M ã¯ã²ãŒã ã¯ãªã¢ãŸã§ã«å¿
èŠãšãªãã¹ãæå°ã®æŠéã®æ°ã§ããïŒ 1 †N †100,000 , 2 †M â€1,000,000 ãæºããïŒ 2 è¡ç®ã¯ç©ºçœã§åºåããã N åã®æŽæ° s 1 , s 2 , ..., s N ãããªãïŒ N çš®é¡ã®æµã¢ã³ã¹ã¿ãŒããããã®åŒ·ãã衚ãïŒå s i 㯠1 †s i †1,000,000 ãæºããïŒãŸã s i < s i+1 ( 1 †i †N-1 ) ã§ããïŒ å
¥åã®çµããã¯ç©ºçœã§åºåããã 2 ã€ã®ãŒããããªãè¡ã§è¡šãããïŒ Output åããŒã¿ã»ããã«ã€ããŠïŒã²ãŒã ã¯ãªã¢ãŸã§ã«å¿
èŠãšãªãæŠéã®åæ°ã M å以äžãšãªããã©ã¡ãŒã¿ãŒ X ã®å
ã®æå€§å€ X max ãæŽæ°ã§åºåããïŒ X ãã©ã®ããã«èšå®ããŠã M åæªæºã®æŠéåæ°ã§ã²ãŒã ã¯ãªã¢ã§ããŠããŸããã²ãŒã ãã¯ãªã¢ã§ããªããªã£ãŠããŸããã¹ãã±ãŒã¹ã®å Žåã«ã¯ -1 ã®ã¿ãããªãè¡ãåºåããïŒ Sample Input 3 4 1 5 9 1 2 1 2 10 1 1000000 2 4 1 10 0 0 Output for Sample Input 3 -1 499996 4 2 çªç®ã®ãã¹ãã±ãŒã¹ã§ã¯ïŒ X = 1 ãšèšå®ãããš 1 åã®æŠéã§ã²ãŒã ãã¯ãªã¢ã§ããŠããŸãïŒ ãã®ã±ãŒã¹ã§ã¯ïŒå¿
èŠãšãªãæŠéã®åæ°ã M å以äžã§ããïŒãã€ã²ãŒã ãã¯ãªã¢ã§ããããã« X ãèšå®ããããšãåºæ¥ãªãïŒ ãã£ãŠ -1 ã®ã¿ãããªãè¡ãåºåããïŒ
| 38,290
|
Bubble Sort Write a program of the Bubble Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: BubbleSort(A) 1 for i = 0 to A.length-1 2 for j = A.length-1 downto i+1 3 if A[j] < A[j-1] 4 swap A[j] and A[j-1] Note that, indices for array elements are based on 0-origin. Your program should also print the number of swap operations defined in line 4 of the pseudocode. Input The first line of the input includes an integer N , the number of elements in the sequence. In the second line, N elements of the sequence are given separated by spaces characters. Output The output consists of 2 lines. In the first line, please print the sorted sequence. Two contiguous elements of the sequence should be separated by a space character. In the second line, please print the number of swap operations. Constraints 1 †N †100 Sample Input 1 5 5 3 2 4 1 Sample Output 1 1 2 3 4 5 8 Sample Input 2 6 5 2 4 6 1 3 Sample Output 2 1 2 3 4 5 6 9
| 38,291
|
颚ããç§ã®æ¢
ã®éŠããå±ããŠãããïŒ åŒã£è¶ããæ±ºãŸãããã®å°ãå»ãããšã«ãªã£ãããã®åå°èªäœã«æªç·Žã¯ç¡ãããïŒã€ã ãæ°ã«ãªãããšããããããã¯ãåºã«æ€ããæ¢
ã®æšã®ããšã ãç§ã¯æ¯å¹Žããã®æ¢
ãè±ãå²ããããšã楜ãã¿ã«ããŠããããããé¢ããåŸã¯æ¥ã®æ¥œãã¿ãïŒã€æžã£ãŠããŸããç§ã®æ¢
ã®éŠãã ãã§ã颚ã«ä¹ã£ãŠåŒã£è¶ãå
ã®å®¶ãŸã§å±ããæ¥ãæ¥œããŸããŠã¯ãããªããã®ãã æ¥æ¬ã«ã¯æ¥ã象城ããïŒã€ã®è±ããããæ¢
ã»æ¡ã»æ¡ã®ïŒã€ã ãåŒã£è¶ãå
ã«ã¯ãç§ã®æ¢
以å€ã«ãããããã®è±ã®éŠããå±ãã ãããããããç§ã®æ¢
ã®éŠãã ããå±ãæ¥æ°ãæãå€ãå®¶ã«äœã¿ããã å³ã®ããã«ãè±ã®éŠãã¯æç¶ã«åºããããã®é åã¯é¢šã®åããæ¹åãšåŒ·ãã«ãã£ãŠæ±ºãŸããæåœ¢ã¯é¢šã®åããæ¹å w ãäžå¿ã«ããŠå¯Ÿç§°ã«åºããã颚ã®åŒ·ã a ãååŸãšããé åããã€ãéŠããåºããè§åºŠ d ã¯è±ã®çš®é¡ã«ãã£ãŠæ±ºãŸã£ãŠãããã颚ã®åããæ¹åãšåŒ·ãã¯æ¥ã«ãã£ãŠç°ãªãããã ããåãæ¥ã§ã¯ããã¹ãŠã®å Žæã§é¢šã®åããæ¹åãšåŒ·ãã¯åãã§ããã æå
ã«ã¯ãç§ã®æ¢
以å€ã®æ¢
ã»æ¡ã»æ¡ã®äœçœ®ãšè±ã®çš®é¡ããšã®éŠããåºããè§åºŠãåŒã£è¶ãå
ã®å®¶ã®åè£ã®ããŒã¿ããããããã«ãæ°æ¥åã®é¢šã®åããæ¹åãšåŒ·ãã®ããŒã¿ããããç§ã®æ¢
以å€ã®æ¢
ã»æ¡ã»æ¡ã®æšãšå®¶ã®äœçœ®ã¯ãç§ã®æ¢
ã®äœçœ®ãåç¹ãšãã座æšã§ç€ºãããŠããã ãããã®ããŒã¿ã䜿ã£ãŠãç§ã®æ¢
ã®éŠãã ããå±ãæ¥æ°ã®æãå€ãå®¶ãæ¢ãããã®ããã°ã©ã ãæžããŠã¿ãããšãšããããç§ã¯æèœãªããã°ã©ããŒãªã®ã ããïŒ å
¥å å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªããå
¥åã®çµããã¯ãŒãïŒã€ã®è¡ã§ç€ºããããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããã H R hx 1 hy 1 hx 2 hy 2 : hx H hy H U M S du dm ds ux 1 uy 1 ux 2 uy 2 : ux U uy U mx 1 my 1 mx 2 my 2 : mx M my M sx 1 sy 1 sx 2 sy 2 : sx S sy S w 1 a 1 w 2 a 2 : w R a R åè¡ã§äžããããæ°å€ã¯ïŒã€ã®ç©ºçœã§åºåãããŠããã ïŒè¡ç®ã«åŒã£è¶ãå
ã®å®¶ã®åè£ã®æ° H (1 †H †100) ãšé¢šã®èšé²ã®æ° R (1 †R †100) ãäžãããããç¶ãH è¡ã«åŒã£è¶ãå
ã®å®¶ã®äœçœ®ãäžãããããhx i ãšhy i 㯠i çªç®ã®å®¶ã® x 座æšãš y 座æšã瀺ã-1000 以äž1000 以äžã®æŽæ°ã§ããã ç¶ãïŒè¡ã«ãç§ã®æ¢
以å€ã®æ¢
ã®æšã®æ° U ãšãæ¡ã»æ¡ã®æšã®æ° MãSãæ¢
ã»æ¡ã»æ¡ã®éŠããåºããè§åºŠduãdmãds ãäžãããããUãMãS ã®ç¯å²ã¯ 0 以äž10 以äžã§ãããè§åºŠã®åäœã¯åºŠã§ããã1 以äž180 æªæºã®æŽæ°ã§ããã ç¶ã U è¡ã«ç§ã®æ¢
以å€ã®æ¢
ã®æšã®äœçœ®ãç¶ã M è¡ã«æ¡ã®æšã®äœçœ®ãç¶ã S è¡ã«æ¡ã®æšã®äœçœ®ãäžãããããuxi ãš uyiãmxi ãš myiãsxi ãš syi ã¯ãããããi çªç®ã®æ¢
ã»æ¡ã»æ¡ã®æšã® x 座æšãš y 座æšã瀺ãã-1000 ä»¥äž 1000 以äžã®æŽæ°ã§ããã ç¶ã R è¡ã«é¢šã®èšé²ãäžãããããw i (0 †w i < 360) ãš a i (0 < a i †100) 㯠i æ¥ç®ã®é¢šã®åããæ¹åãšåŒ·ããè¡šãæŽæ°ã§ããã颚ã®åããæ¹åã¯ãx è»žã®æ£ã®åãããåæèšåãã«æž¬ã£ãè§åºŠã§è¡šããåäœã¯åºŠãšããã å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºãããšèããŠããã å
¥åããã座æšã¯ãã¹ãŠç°ãªããã®ãšããã åç¹ã«ã¯ç§ã®æ¢
以å€ç¡ãã ã©ã®è±ã«ã€ããŠããè±ã®éŠããå±ãé åã®å¢çããè·é¢ã 0.001 以å
ã«ã¯å®¶ã¯ç¡ãã ããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããªãã åºå ããŒã¿ã»ããããšã«ãç§ã®æ¢
ã®éŠãã ããå±ãæ¥æ°ã®æãå€ãå
šãŠã®å®¶ã®çªå·ããå°ããé ã«ïŒè¡ã«åºåãããå®¶ã®çªå·ã®éã¯ç©ºçœïŒã€ã§åºåããè¡ã®çµããã«ã¯ç©ºçœæåãåºåããªãã ãã ããã©ã®å®¶ã«ã€ããŠããç§ã®æ¢
ã®è±ã®éŠãã ããå±ãæ¥ãïŒæ¥ããªããã°ãNA ãšåºåããã å
¥åäŸ 6 3 2 1 1 2 5 2 1 3 1 5 -2 3 1 1 1 90 30 45 3 -4 -3 0 2 -2 45 6 90 6 135 6 2 1 1 3 5 2 0 1 1 90 30 45 -3 0 2 -2 45 6 0 0 åºåäŸ 5 6 NA
| 38,292
|
Anchored Balloon A balloon placed on the ground is connected to one or more anchors on the ground with ropes. Each rope is long enough to connect the balloon and the anchor. No two ropes cross each other. Figure E-1 shows such a situation. Figure E-1: A balloon and ropes on the ground Now the balloon takes off, and your task is to find how high the balloon can go up with keeping the rope connections. The positions of the anchors are fixed. The lengths of the ropes and the positions of the anchors are given. You may assume that these ropes have no weight and thus can be straightened up when pulled to whichever directions. Figure E-2 shows the highest position of the balloon for the situation shown in Figure E-1. Figure E-2: The highest position of the balloon Input The input consists of multiple datasets, each in the following format. n x 1 y 1 l 1 ... x n y n l n The first line of a dataset contains an integer n (1 †n †10) representing the number of the ropes. Each of the following n lines contains three integers, x i , y i , and l i , separated by a single space. P i = ( x i , y i ) represents the position of the anchor connecting the i -th rope, and l i represents the length of the rope. You can assume that â100 †x i †100, â100 †y i †100, and 1 †l i †300. The balloon is initially placed at (0, 0) on the ground. You can ignore the size of the balloon and the anchors. You can assume that P i and P j represent different positions if i â j . You can also assume that the distance between P i and (0, 0) is less than or equal to l i â1. This means that the balloon can go up at least 1 unit high. Figures E-1 and E-2 correspond to the first dataset of Sample Input below. The end of the input is indicated by a line containing a zero. Output For each dataset, output a single line containing the maximum height that the balloon can go up. The error of the value should be no greater than 0.00001. No extra characters should appear in the output. Sample Input 3 10 10 20 10 -10 20 -10 10 120 1 10 10 16 2 10 10 20 10 -10 20 2 100 0 101 -90 0 91 2 0 0 53 30 40 102 3 10 10 20 10 -10 20 -10 -10 20 3 1 5 13 5 -3 13 -3 -3 13 3 98 97 168 -82 -80 193 -99 -96 211 4 90 -100 160 -80 -80 150 90 80 150 80 80 245 4 85 -90 290 -80 -80 220 -85 90 145 85 90 170 5 0 0 4 3 0 5 -3 0 5 0 3 5 0 -3 5 10 95 -93 260 -86 96 211 91 90 177 -81 -80 124 -91 91 144 97 94 165 -90 -86 194 89 85 167 -93 -80 222 92 -84 218 0 Output for the Sample Input 17.3205081 16.0000000 17.3205081 13.8011200 53.0000000 14.1421356 12.0000000 128.3928757 94.1879092 131.1240816 4.0000000 72.2251798
| 38,293
|
F: ã¿ãã¿ãŒæåå - Miko Mi String - ç©èª ã¿ã£ãã¿ã£ãã¿ãïŒã¿ããªã®ã¢ã€ãã«ïŒç°æŸ€ã¿ãã¿ãïŒä»æ¥ã¯ãïŒã¿ããšäžç·ã«ãïŒæååã¢ã«ãŽãªãºã ã®ç·Žç¿ïŒããâ ã¿ãã®ãšã£ãŠããã® ãã£ã©äœã åèšèïŒãã¿ã£ãã¿ã£ãã¿ããã¯ïŒããŒãåã«ãããš âMikoMikoMiâ ã«ãªãã¿ãïŒã€ãŸãïŒ A= âMiâ, B= âKoâ ãšãããšïŒ ABABA ã®åœ¢ã§æžããã£ãŠããšãªã®ïŒãããªé¢šã«ïŒé©åã« A ãš B ãæ±ºãããš ABABA ã®åœ¢ã«åè§£ã§ããæååã®ããšããã¿ãã¿ãŒæååãã£ãŠèšããïŒæååã®ååã«ãŸã§ãªã£ã¡ãããªããŠïŒã¿ãã¯ã¿ããªã®äººæ°è
ã¿ããïŒ ã¿ããªã§ã¿ãã¿ãŒæååãããã£ãšäœ¿ã£ãŠããããã«ïŒäžããããæååãã¿ãã¿ãŒæååãã©ããå€å®ããããã°ã©ã ãäœãããšã«ãããã ãã©ïŒã¿ãïŒFizzBuzzããé·ãããã°ã©ã ãªããŠæžããªããïŒã ãããïŒã¿ãã®ããã«ãïŒã¿ãã¿ãŒæååãå€å®ããããã°ã©ã ãæžããŠæ¬²ãããªâ âŠâŠã¢ã³ã¿ïŒããŸå¯ãã£ãŠèšã£ãïŒïŒ åé¡ ã¢ã«ãã¡ããã倧æåã»å°æåãããªãæåå S ãäžããããïŒ ããã§ïŒ S = ABABA ãšæžãããããªïŒç©ºã§ãªã2ã€ã®æåå A, B ãååšãããªãã°ïŒ S ã¯ãã¿ãã¿ãŒæååãã§ãããšããïŒ ãã®ãšãïŒã¢ã«ãã¡ãããã®å€§æåãšå°æåã¯éãæåãšããŠåºå¥ãããã®ãšããïŒ äžããããæååãã¿ãã¿ãŒæååã§ãããã©ãããå€å®ããããã°ã©ã ãäœæããïŒ å
¥ååœ¢åŒ å
¥åã¯æåå S ãå«ã1è¡ã®ã¿ãããªãïŒ S ã¯ä»¥äžã®æ¡ä»¶ãæºãããšä»®å®ããŠããïŒ 1 †|S| †10^6 ïŒãã ãïŒ |S| ã¯æåå S ã®é·ãã衚ãïŒ S ã¯å€§æåïŒãããã¯å°æåã®ã¢ã«ãã¡ãããã®ã¿ãããªãïŒ ãªãïŒå
¥åãéåžžã«å€§ãããªãå ŽåãããããïŒå
¥åã®åãåãã«ã¯é«éãªé¢æ°ãçšããããšãæšå¥šããïŒ åºååœ¢åŒ S ãã¿ãã¿ãŒæååã§ãããªãã°ïŒ S = ABABA ãæºãããã㪠A, B ã«ã€ããŠïŒâLove AB !âãšåºåããïŒãã ãïŒè€æ°ã® A, B ã®çµãæ¡ä»¶ãæºããå ŽåïŒ |AB| ãæå°ã®ãã®ãåºåããïŒ S ãã¿ãã¿ãŒæååã§ãªããªãã°ïŒâmitomerarenaiWAâãšåºåããïŒ å
¥åäŸ1 NicoNicoNi åºåäŸ1 Love Nico! å
¥åäŸ2 KashikoiKawaiiElichika åºåäŸ2 mitomerarenaiWA å
¥åäŸ3 LiveLiveL åºåäŸ3 Love Live! å
¥åäŸ4 AizunyanPeroPero åºåäŸ4 mitomerarenaiWA å
¥åäŸ5 AAAAAAAAAAAAAA åºåäŸ5 Love AAAAA!
| 38,294
|
é¢é£åå ã€ã³ã¿ãŒãããé販ãµã€ãã§ã¯ããŠãŒã¶ãçŸåšèŠãŠããååãšåãããŒãžã«ãéå»ã«ä»ã®ãŠãŒã¶ã«ãã£ãŠãçŸåšèŠãŠããååãšäžç·ã«è²·ãããå¥ã®ååãããã€ã衚瀺ããŠãããŸããé¢é£æ§ã®é«ããšæãããååãæç€ºããããšã§ã売ãäžãã䌞ã°ãããšãã§ãããšèããããŠããããã§ãã 䌌ããããªããšã¯ãäžç·ã«è²·ãããããšãå€ãååãè¿ãã«é
眮ããããšãã工倫ãšããŠãè¿æã®ã¹ãŒããŒããŒã±ããã§ãç®ã«ããããšãã§ããŸãïŒäŸãã°ããã³ãšãžã£ã ã®ãããªïŒãããªãã®ä»äºã¯ãååé
眮ã®å·¥å€«ãå©ããããã°ã©ã ãæžãããšã§ããä»åã¯ãããåºæºãšãªãåæ°ãèšå®ããäžç·ã«è²·ãããåæ°ãåºæºåæ°ä»¥äžã§ãããïŒã€ã®ååã®çµã¿åãããæ±ããããšæããŸãã äžç·ã«è²·ãããååã®æ
å ±ãšåºæºåæ°ãäžãããããšããåºæºåæ°ä»¥äžäžç·ã«è²·ãããååïŒã€ã®çµã¿åãããåºåããããã°ã©ã ãäœæããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã N F info 1 info 2 : info N ïŒè¡ç®ã«ãäžç·ã«è²·ãããååã®æ
å ±ã®æ° N (1 †N †100) ãšãåºæºåæ° F (1 †F †100) ãäžãããããç¶ã N è¡ã«ãäžç·ã«è²·ãããååã®æ
å ±ãäžãããããäžç·ã«è²·ãããååã®æ
å ± info i ã¯ã以äžã®åœ¢åŒã§äžããããã M item 1 item 2 ... item M M (1 †M †10) ã¯ããã®æ
å ±ãããã€ã®ååãå«ããã衚ãã item j ã¯ããã®è²·ãç©ã§è²·ãããååã®ååã§ãããè±å°æåã ãããæãé·ã 1 ä»¥äž 30 以äžã®æååã§ããã info i ã®äžã«åãååãäžããããããšã¯ãªãã Output ïŒè¡ç®ã«åºæºåæ°ä»¥äžäžç·ã«è²·ãããååïŒã€ã®çµã¿åããã®æ°ãåºåããïŒè¡ç®ä»¥éã«çµã¿åããããã¹ãŠåºåããããã ããçµã¿åãããäžã€ããªãå Žåã¯ïŒè¡ç®ä»¥éã«ã¯äœãåºåããªãã åºåã®é çªã¯ãçµã¿åããå
ã®åååã©ããããèŸæžåŒé åºïŒè±åèŸæžã§åèªã䞊ãã§ããé çªïŒã§äžŠã¹ãããšãçµã¿åããã©ããã«ã€ããŠã¯ä»¥äžã®ããã«ããã äžã€ç®ã®åååã©ãããæ¯èŒããŠãèŸæžåŒé åºã§æ©ãã»ããå
ã åãå Žåã¯ãäºã€ç®ã®åååã©ãããæ¯èŒããŠãèŸæžåŒé åºã§æ©ãã»ããå
ã åååã¯ã¹ããŒã¹äžã€ã§åºåããååã®çµã¿åããã¯æ¹è¡äžã€ã§åºåãã Sample Input 1 5 2 3 bread milk banana 2 milk cornflakes 3 potato bread milk 4 cornflakes bread milk butter 2 potato bread Sample Output 1 3 bread milk bread potato cornflakes milk Sample Input 2 5 5 3 bread milk banana 2 milk cornflakes 3 potato bread milk 4 cornflakes bread milk butter 2 potato bread Sample Output 2 0
| 38,295
|
Problem F: It Prefokery Pio You are a member of a secret society named Japanese Abekobe Group , which is called J. A. G. for short. Those who belong to this society often exchange encrypted messages. You received lots of encrypted messages this morning, and you tried to decrypt them as usual. However, because you received so many and long messages today, you had to give up decrypting them by yourself. So you decided to decrypt them with the help of a computer program that you are going to write. The encryption scheme in J. A. G. utilizes palindromes. A palindrome is a word or phrase that reads the same in either direction. For example, âMADAMâ, âREVIVERâ and âSUCCUSâ are palindromes, while âADAMâ, âREVENGEâ and âSOCCERâ are not. Specifically to this scheme, words and phrases made of only one or two letters are not regarded as palindromes. For example, âAâ and âMMâ are not regarded as palindromes. The encryption scheme is quite simple: each message is encrypted by inserting extra letters in such a way that the longest one among all subsequences forming palindromes gives the original message. In other words, you can decrypt the message by extracting the longest palindrome subsequence . Here, a subsequence means a new string obtained by picking up some letters from a string without altering the relative positions of the remaining letters. For example, the longest palindrome subsequence of a string âYMAOKDOAMIMHAADAMMAâ is âMADAMIMADAMâ as indicated below by underline. Now you are ready for writing a program. Input The input consists of a series of data sets. Each data set contains a line made of up to 2,000 capital letters which represents an encrypted string. The end of the input is indicated by EOF (end-of-file marker). Output For each data set, write a decrypted message in a separate line. If there is more than one decrypted message possible (i.e. if there is more than one palindrome subsequence not shorter than any other ones), you may write any of the possible messages. You can assume that the length of the longest palindrome subsequence of each data set is always longer than two letters. Sample Input YMAOKDOAMIMHAADAMMA LELVEEL Output for the Sample Input MADAMIMADAM LEVEL
| 38,296
|
K - XORåå» å顿 KU倧åŠã§ã¯äžé¢šå€ãã£ãã©ãªãŒã²ãŒã ã人æ°ã§ããïŒ ãã®ã²ãŒã ã®èå°ã§ãããµãŒãããã«ã¯ïŒ N åã®äŒæ©æãš M åã®éãããïŒ i çªç®ã®é㯠f i çªç®ã®äŒæ©æãš t i çªç®ã®äŒæ©æã®éã«ããïŒ ãã¹ãŠã®éã«ã¯ãã§ãã¯ãã€ã³ããäžã€ãã€ååšãïŒé i ã®ãã§ãã¯ãã€ã³ããééãããšã©ã¡ãã®åãã§éã£ãŠã p i ã®åŸç¹ãXORã§å ç®ãããïŒ XORã§ å ç®ãããïŒå€§äºãªããšãªã®ã§2åèšããŸããïŒ ãã®ã²ãŒã ã§ã¯ïŒåãäŒæ©æãéãäœåºŠéã£ãŠãè¯ããïŒ ãŽãŒã«ã«ãã©ãçããŠããã®ãŸãŸã©ãªãŒãç¶è¡ããããšãã§ãããïŒ éã®éäžã«ãããã§ãã¯ãã€ã³ããè¿åããŠå¥ã®äŒæ©æãžè¡ãããšã¯çŠæ¢ãããŠããïŒ ãã®ããïŒã©ã®ãããªéé ããã©ãã°é«ãåŸç¹ãåãããšãã§ããããé 匵ã£ãŠèããªããã°ãªããªãç¹ã人æ°ã®ããæä»¥ã§ããïŒ ä»å㯠Q 人ã®åå è
ãããŠïŒ j çªç®ã®åå è
㯠a j ã®äŒæ©æããã¹ã¿ãŒãããŠïŒãŽãŒã«ã§ãã b j ã®äŒæ©æãŸã§è¡ãããšã«ãªã£ãŠããããã ïŒ éå¶åŽã®äººéãšããŠããããã®åå è
ã®æé«åŸç¹ãåãã£ãŠèª¿ã¹ãŠããããšã«ããïŒ å
¥ååœ¢åŒ å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒãªãäŒæ©æã®çªå·ã¯0-indexedã§ããïŒ N M Q f 1 t 1 p 1 ... f M t M p M a 1 b 1 ... a Q b Q åºååœ¢åŒ Q è¡åºåãïŒ j è¡ç®ã«ã¯ a j çªç®ã®äŒæ©æãã b j çªç®ã®äŒæ©æãžã®çµè·¯ã§åŸãããåŸç¹ã®æå€§å€ãåºåããïŒ å¶çŽ 1 †N †10 5 0 †M †2 à 10 5 1 †Q †10 5 0 †f i , t i < N , f i â t i 0 †p i < 2 60 0 †a j , b j < N ã©ã®äŒæ©æããã§ãïŒéã蟿ã£ãŠããã°ä»»æã®äŒæ©æãžãã©ãçããïŒ äŒæ©æ f i ,t i éãçµã¶éã¯é«ã
äžã€ããååšããªãïŒ å
¥åå€ã¯ãã¹ãп޿°ã§ããïŒ ãã®åé¡ã®å€å®ã«ã¯ïŒ60 ç¹åã®ãã¹ãã±ãŒã¹ã®ã°ã«ãŒããèšå®ãããŠããïŒãã®ã°ã«ãŒãã«å«ãŸãããã¹ãã±ãŒã¹ã¯äžèšã®å¶çŽã«å ããŠäžèšã®å¶çŽãæºããïŒ M †20 å
¥åºåäŸ å
¥åäŸ1 5 5 3 0 1 7 1 2 22 2 3 128 3 4 128 4 2 128 0 1 0 0 3 4 åºåäŸ1 135 128 128 Writer : æ£®æ§æ Tester : ç°æåç¯
| 38,297
|
Score : 300 points Problem Statement There are N cities on a number line. The i -th city is located at coordinate x_i . Your objective is to visit all these cities at least once. In order to do so, you will first set a positive integer D . Then, you will depart from coordinate X and perform Move 1 and Move 2 below, as many times as you like: Move 1 : travel from coordinate y to coordinate y + D . Move 2 : travel from coordinate y to coordinate y - D . Find the maximum value of D that enables you to visit all the cities. Here, to visit a city is to travel to the coordinate where that city is located. Constraints All values in input are integers. 1 \leq N \leq 10^5 1 \leq X \leq 10^9 1 \leq x_i \leq 10^9 x_i are all different. x_1, x_2, ..., x_N \neq X Input Input is given from Standard Input in the following format: N X x_1 x_2 ... x_N Output Print the maximum value of D that enables you to visit all the cities. Sample Input 1 3 3 1 7 11 Sample Output 1 2 Setting D = 2 enables you to visit all the cities as follows, and this is the maximum value of such D . Perform Move 2 to travel to coordinate 1 . Perform Move 1 to travel to coordinate 3 . Perform Move 1 to travel to coordinate 5 . Perform Move 1 to travel to coordinate 7 . Perform Move 1 to travel to coordinate 9 . Perform Move 1 to travel to coordinate 11 . Sample Input 2 3 81 33 105 57 Sample Output 2 24 Sample Input 3 1 1 1000000000 Sample Output 3 999999999
| 38,299
|
Score : 200 points Problem Statement Alice and Bob are controlling a robot. They each have one switch that controls the robot. Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up. Bob started holding down his button C second after the start-up, and released his button D second after the start-up. For how many seconds both Alice and Bob were holding down their buttons? Constraints 0â€A<Bâ€100 0â€C<Dâ€100 All input values are integers. Input Input is given from Standard Input in the following format: A B C D Output Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons. Sample Input 1 0 75 25 100 Sample Output 1 50 Alice started holding down her button 0 second after the start-up of the robot, and released her button 75 second after the start-up. Bob started holding down his button 25 second after the start-up, and released his button 100 second after the start-up. Therefore, the time when both of them were holding down their buttons, is the 50 seconds from 25 seconds after the start-up to 75 seconds after the start-up. Sample Input 2 0 33 66 99 Sample Output 2 0 Alice and Bob were not holding their buttons at the same time, so the answer is zero seconds. Sample Input 3 10 90 20 80 Sample Output 3 60
| 38,300
|
Score : 600 points Problem Statement We have one slime. You can set the health of this slime to any integer value of your choice. A slime reproduces every second by spawning another slime that has strictly less health. You can freely choose the health of each new slime. The first reproduction of our slime will happen in one second. Determine if it is possible to set the healths of our first slime and the subsequent slimes spawn so that the multiset of the healths of the 2^N slimes that will exist in N seconds equals a multiset S . Here S is a multiset containing 2^N (possibly duplicated) integers: S_1,~S_2,~...,~S_{2^N} . Constraints All values in input are integers. 1 \leq N \leq 18 1 \leq S_i \leq 10^9 Input Input is given from Standard Input in the following format: N S_1 S_2 ... S_{2^N} Output If it is possible to set the healths of the first slime and the subsequent slimes spawn so that the multiset of the healths of the 2^N slimes that will exist in N seconds equals S , print Yes ; otherwise, print No . Sample Input 1 2 4 2 3 1 Sample Output 1 Yes We will show one way to make the multiset of the healths of the slimes that will exist in 2 seconds equal to S . First, set the health of the first slime to 4 . By letting the first slime spawn a slime whose health is 3 , the healths of the slimes that exist in 1 second can be 4,~3 . Then, by letting the first slime spawn a slime whose health is 2 , and letting the second slime spawn a slime whose health is 1 , the healths of the slimes that exist in 2 seconds can be 4,~3,~2,~1 , which is equal to S as multisets. Sample Input 2 2 1 2 3 1 Sample Output 2 Yes S may contain multiple instances of the same integer. Sample Input 3 1 1 1 Sample Output 3 No Sample Input 4 5 4 3 5 3 1 2 7 8 7 4 6 3 7 2 3 6 2 7 3 2 6 7 3 4 6 7 3 4 2 5 2 3 Sample Output 4 No
| 38,301
|
Min Element æ°å a_1,a_2,..,a_N ãäžããããŸãã ãã®æ°åã®æå°å€ã®çªå·ãæ±ããŠãã ããã æå°å€ãè€æ°ã®å Žæã«ãããšãã¯ãçªå·ã®æãå°ãããã®ãçããŠãã ããã å
¥å N a_1 a_2...a_N åºå a_i ãæ°åã®æå°å€ãšãªããã㪠i ã®ãã¡ãæãå°ãããã®ãåºåããã å¶çŽ 1 \leq N \leq 10^5 1 \leq a_i \leq 10^9 å
¥åäŸ 6 8 6 9 1 2 1 åºåäŸ 4
| 38,302
|
Difference of Big Integers Given two integers $A$ and $B$, compute the difference, $A - B$. Input Two integers $A$ and $B$ separated by a space character are given in a line. Output Print the difference in a line. Constraints $-1 \times 10^{100000} \leq A, B \leq 10^{100000}$ Sample Input 1 5 8 Sample Output 1 -3 Sample Input 2 100 25 Sample Output 2 75 Sample Input 3 -1 -1 Sample Output 3 0 Sample Input 4 12 -3 Sample Output 4 15
| 38,303
|
I: ç Žå£ (Ravage) ãµã³ã¿ã¯ããŒã¹ã¯ãè¡ã®ã€ã«ãããŒã·ã§ã³ã«åŒã£ããããå£ããã ã€ã«ãããŒã·ã§ã³ã«ã¯Nåã®é»çãããã$i$ çªç®ã®é»çã¯é»å§ã $A_i$ ä»¥äž $B_i$ 以äžã®ãšãã«ããä»ããªããªã£ãŠããŸã£ãã é»å§ã¯ã€ã«ãããŒã·ã§ã³ã®ã©ãã§ãåãã«ããå¿
èŠãããã é»å§ã調ç¯ããããšã§ãæå€§ããã€ã®é»çãåæã«å
ãããããšãã§ãããæ±ããã å
¥å 1 è¡ç®ã«ã¯æŽæ° $N$ ãäžããããã ç¶ã $N$ è¡ã®ãã¡ $i$ è¡ç®ã«ã¯ $A_i, B_i$ ã空çœåºåãã§äžããããã åºå åæã«å
ãããããšãã§ããé»çã®åæ°ã®æå€§å€ãåºåããã å¶çŽ $N$ 㯠$1$ ä»¥äž $100 \ 000$ 以äžã®æŽæ° $A_1, A_2, A_3, \dots, A_N$ 㯠$1$ ä»¥äž $1 \ 000 \ 000 \ 000$ 以äžã®æŽæ° $B_1, B_2, B_3, \dots, B_N$ 㯠$1$ ä»¥äž $1 \ 000 \ 000 \ 000$ 以äžã®æŽæ° ãã¹ãŠã®é»ç $i$ ã«ã€ããŠã$A_i \leq B_i$ ãæºãã å
¥åäŸ1 4 1 4 3 6 2 7 5 8 åºåäŸ1 3 é»å§ã $5$ ã $3.14$ ã®ãšãã« $3$ ã€ã®é»çãã€ããŸãã å
¥åäŸ2 2 1 2 2 3 åºåäŸ2 2
| 38,304
|
Score : 300 points Problem Statement There are N cities numbered 1 through N , and M bidirectional roads numbered 1 through M . Road i connects City A_i and City B_i . Snuke can perform the following operation zero or more times: Choose two distinct cities that are not directly connected by a road, and build a new road between the two cities. After he finishes the operations, it must be possible to travel from any city to any other cities by following roads (possibly multiple times). What is the minimum number of roads he must build to achieve the goal? Constraints 2 \leq N \leq 100,000 1 \leq M \leq 100,000 1 \leq A_i < B_i \leq N No two roads connect the same pair of cities. All values in input are integers. Input Input is given from Standard Input in the following format: N M A_1 B_1 : A_M B_M Output Print the answer. Sample Input 1 3 1 1 2 Sample Output 1 1 Initially, there are three cities, and there is a road between City 1 and City 2 . Snuke can achieve the goal by building one new road, for example, between City 1 and City 3 . After that, We can travel between 1 and 2 directly. We can travel between 1 and 3 directly. We can travel between 2 and 3 by following both roads ( 2 - 1 - 3 ).
| 38,305
|
Problem E: Cyclic Shift Sort Problem é·ã $N$ ã®é å $P = \{ P_1, P_2, \ldots, P_N \} $ ãšæŽæ° $K$ ãäžããããã 以äžã®æäœã $0$ å以äžä»»æã®åæ°ç¹°ãè¿ãããšã§ãé å $P$ ãå調å¢å ã«ããããšãã§ãããã©ããå€å®ããã æŽæ° $x \ (0 \le x \le N-K)$ ãéžã¶ã $ P_{x+1}, \ldots, P_{x+K} $ ãå·¡åå³ã·ãããã ãã ããéšåå $U=U_1, \ldots, U_M$ ã®å·¡åå³ã·ãããšã¯ã $U=U_1, \ldots, U_M$ ã $U=U_M, U_1, \ldots, U_{M-1}$ ã«å€æŽããããšãæå³ããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã $N$ $K$ $P_1$ $\ldots$ $P_N$ 1è¡ç®ã«é åã®é·ã $N$ ãæŽæ° $K$ ã空çœåºåãã§äžããããã 2è¡ç®ã«é å $P$ ã®èŠçŽ ã空çœåºåãã§äžããããã Constraints å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã $2 \leq K \leq N \leq 10^5 $ $ 1 \leq P_i \leq N \ (1 \leq i \leq N) $ $ P_i \neq P_j \ (i \neq j) $ å
¥åã¯ãã¹ãп޿° Output $P$ ãå調å¢å ã«ããããšãã§ãããªã"Yes"ããã§ããªãã®ã§ããã°"No"ã $1$ è¡ã«åºåããã Sample Input 1 3 3 2 3 1 Sample Output 1 Yes $ x = 0 $ ãšããŠæäœã $1$ åè¡ããšã $P$ ãå調å¢å ã«ããããšãã§ããã Sample Input 2 3 2 1 2 3 Sample Output 2 Yes $P$ ãåãããå調å¢å ã§ããå Žåãããã Sample Input 3 3 3 3 2 1 Sample Output 3 No ã©ã®ããã«æäœãè¡ãªã£ããšããŠãã $P$ ãå調å¢å ã«ããããšã¯ã§ããªãã
| 38,306
|
Score : 100 points Problem Statement Decades have passed since the beginning of AtCoder Beginner Contest. The contests are labeled as ABC001 , ABC002 , ... from the first round, but after the 999 -th round ABC999 , a problem occurred: how the future rounds should be labeled? In the end, the labels for the rounds from the 1000 -th to the 1998 -th are decided: ABD001 , ABD002 , ... , ABD999 . You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N -th round of AtCoder Beginner Contest. Constraints 1 \leq N \leq 1998 N is an integer. Input Input is given from Standard Input in the following format: N Output Print the first three characters of the label of the N -th round of AtCoder Beginner Contest. Sample Input 1 999 Sample Output 1 ABC The 999 -th round of AtCoder Beginner Contest is labeled as ABC999 . Sample Input 2 1000 Sample Output 2 ABD The 1000 -th round of AtCoder Beginner Contest is labeled as ABD001 . Sample Input 3 1481 Sample Output 3 ABD The 1481 -th round of AtCoder Beginner Contest is labeled as ABD482 .
| 38,307
|
Score : 100 points Problem Statement Two deer, AtCoDeer and TopCoDeer, are playing a game called Honest or Dishonest . In this game, an honest player always tells the truth, and an dishonest player always tell lies. You are given two characters a and b as the input. Each of them is either H or D , and carries the following information: If a = H , AtCoDeer is honest; if a = D , AtCoDeer is dishonest. If b = H , AtCoDeer is saying that TopCoDeer is honest; if b = D , AtCoDeer is saying that TopCoDeer is dishonest. Given this information, determine whether TopCoDeer is honest. Constraints a = H or a = D . b = H or b = D . Input The input is given from Standard Input in the following format: a b Output If TopCoDeer is honest, print H . If he is dishonest, print D . Sample Input 1 H H Sample Output 1 H In this input, AtCoDeer is honest. Hence, as he says, TopCoDeer is honest. Sample Input 2 D H Sample Output 2 D In this input, AtCoDeer is dishonest. Hence, contrary to what he says, TopCoDeer is dishonest. Sample Input 3 D D Sample Output 3 H
| 38,308
|
Score : 100 points Problem Statement How many ways are there to choose two distinct positive integers totaling N , disregarding the order? Constraints 1 \leq N \leq 10^6 N is an integer. Input Input is given from Standard Input in the following format: N Output Print the answer. Sample Input 1 4 Sample Output 1 1 There is only one way to choose two distinct integers totaling 4 : to choose 1 and 3 . (Choosing 3 and 1 is not considered different from this.) Sample Input 2 999999 Sample Output 2 499999
| 38,309
|
Problem E: Geometric Map Your task in this problem is to create a program that finds the shortest path between two given locations on a given street map, which is represented as a collection of line segments on a plane. Figure 4 is an example of a street map, where some line segments represent streets and the others are signs indicating the directions in which cars cannot move. More concretely, AE , AM , MQ , EQ , CP and HJ represent the streets and the others are signs in this map. In general, an end point of a sign touches one and only one line segment representing a street and the other end point is open. Each end point of every street touches one or more streets, but no signs. The sign BF , for instance, indicates that at B cars may move left to right but may not in the reverse direction. In general, cars may not move from the obtuse angle side to the acute angle side at a point where a sign touches a street (note that the angle CBF is obtuse and the angle ABF is acute). Cars may directly move neither from P to M nor from M to P since cars moving left to right may not go through N and those moving right to left may not go through O . In a special case where the angle between a sign and a street is rectangular, cars may not move in either directions at the point. For instance, cars may directly move neither from H to J nor from J to H . You should write a program that finds the shortest path obeying these traffic rules. The length of a line segment between ( x 1 , y 1 ) and ( x 2 , y 2 ) is â{( x 2 â x 1 ) 2 + ( y 2 â y 1 ) 2 } . Input The input consists of multiple datasets, each in the following format. n x s y s x g y g x 1 1 y 1 1 x 2 1 y 2 1 . . . x 1 k y 1 k x 2 k y 2 k . . . x 1 n y 1 n x 2 n y 2 n n , representing the number of line segments, is a positive integer less than or equal to 200. ( x s , y s ) and ( x g , y g ) are the start and goal points, respectively. You can assume that ( x s , y s ) â ( x g , y g ) and that each of them is located on an end point of some line segment representing a street. You can also assume that the shortest path from ( x s , y s ) to ( x g , y g ) is unique. ( x 1 k , y 1 k ) and ( x 2 k , y 2 k ) are the two end points of the kth line segment. You can assume that ( x 1 k , y 1 k ) â ( x 2 k , y 2 k ). Two line segments never cross nor overlap. That is, if they share a point, it is always one of their end points. All the coordinates are non-negative integers less than or equal to 1000. The end of the input is indicated by a line containing a single zero. Output For each input dataset, print every street intersection point on the shortest path from the start point to the goal point, one in an output line in this order, and a zero in a line following those points. Note that a street intersection point is a point where at least two line segments representing streets meet. An output line for a street intersection point should contain its x - and y -coordinates separated by a space. Print -1 if there are no paths from the start point to the goal point. Sample Input 8 1 1 4 4 1 1 4 1 1 1 1 4 3 1 3 4 4 3 5 3 2 4 3 5 4 1 4 4 3 3 2 2 1 4 4 4 9 1 5 5 1 5 4 5 1 1 5 1 1 1 5 5 1 2 3 2 4 5 4 1 5 3 2 2 1 4 2 4 1 1 1 5 1 5 3 4 3 11 5 5 1 0 3 1 5 1 4 3 4 2 3 1 5 5 2 3 2 2 1 0 1 2 1 2 3 4 3 4 5 5 1 0 5 2 4 0 4 1 5 5 5 1 2 3 2 4 0 Output for the Sample Input 1 1 3 1 3 4 4 4 0 -1 5 5 5 2 3 1 1 0 0
| 38,310
|
ãã±ããã®å£²ãäžã 仿¥ã¯ãã¢ã€ã
ã»ãšã³ã¿ãŒãã€ã³ã¡ã³ã瀟ã€ããªã·ã®ã¢ã€ãã«ã°ã«ãŒããã¢ã«ãã³ïŒã³ããŠã·ãã®ãã±ããçºå£²æ¥ã§ãããã±ããã«ã¯ä»¥äžã®ïŒçš®é¡ããããŸãã ïŒ³åž 6000å ïŒ¡åž 4000å ïŒ¢åž 3000å ïŒ£åž 2000å 販売責任è
ã®ããªãã¯ãããããããªããçºå£²éå§ãåŸ
ã£ãŠããŸããããããçºå£²éå§ã売ãè¡ã絶奜調ã§ãïŒ çºå£²éå§ãããã°ããçµã£ããšããã§ããããŸã§ã®æ³šæããŸãšãã衚ãåãåããŸããã衚ã®åè¡ã«ã¯ããããŸã§ã«å£²ãããã±ããã®çš®é¡ãšææ°ãæžããŠãããŸãããã ãããã±ããã®çš®é¡ãïŒïŒ¡ïŒïŒ¢ïŒïŒ£ã®é ã«çŸãããšã¯éããŸããããã®è¡šã®è¡ããšã®å£²äžéé¡ãæ±ããããã°ã©ã ãäœæããŠãã ããã å
¥å å
¥åããŒã¿ã¯ä»¥äžã®åœ¢åŒã§äžããããã t 1 n 1 t 2 n 2 t 3 n 3 t 4 n 4 å
¥åã¯4è¡ãããªããiè¡ç®ã«ã¯ããã±ããã®çš®é¡ãè¡šãæŽæ° t i (1 †t i †4)ãšææ°ãè¡šãæŽæ° n i (0 †n i †10000)ãäžããããããã±ããã®çš®é¡ãè¡šãæŽæ°1, 2, 3, 4ã¯ãããããåžãåžãåžãåžã衚ãã t 1 , t 2 , t 3 , t 4 ã®å€ãšããŠ1ãã4ãŸã§ã®æ°ã¯å¿
ãïŒåºŠã ãçŸãããã1, 2, 3, 4ã®é ã§äžãããããšã¯éããªãã åºå è¡ããšã«å£²äžéé¡ãåºåããã å
¥åäŸ 1 3 10 1 4 4 1 2 5 åºåäŸ 1 30000 24000 2000 20000 å
¥åäŸ 2 1 1 2 0 3 1 4 1 åºåäŸ 2 6000 0 3000 2000
| 38,311
|
Problem A: Rational Irrationals Rational numbers are numbers represented by ratios of two integers. For a prime number p , one of the elementary theorems in the number theory is that there is no rational number equal to â p . Such numbers are called irrational numbers. It is also known that there are rational numbers arbitrarily close to â p Now, given a positive integer n , we define a set Q n of all rational numbers whose elements are represented by ratios of two positive integers both of which are less than or equal to n . For example, Q 4 is a set of 11 rational numbers {1/1, 1/2, 1/3, 1/4, 2/1, 2/3, 3/1, 3/2, 3/4, 4/1, 4/3}. 2/2, 2/4, 3/3, 4/2 and 4/4 are not included here because they are equal to 1/1, 1/2, 1/1, 2/1 and 1/1, respectively. Your job is to write a program that reads two integers p and n and reports two rational numbers x / y and u / v , where u / v < â p < x / y and there are no other elements of Q n between u/v and x/y . When n is greater than â p , such a pair of rational numbers always exists. Input The input consists of lines each of which contains two positive integers, a prime number p and an integer n in the following format. p n They are separated by a space character. You can assume that p and n are less than 10000, and that n is greater than â p . The end of the input is indicated by a line consisting of two zeros. Output For each input line, your program should output a line consisting of the two rational numbers x / y and u / v ( x / y > u / v ) separated by a space character in the following format. x/y u/v They should be irreducible. For example, 6/14 and 15/3 are not accepted. They should be reduced to 3/7 and 5/1, respectively. Sample Input 2 5 3 10 5 100 0 0 Output for the Sample Input 3/2 4/3 7/4 5/3 85/38 38/17
| 38,312
|
Big Maze ããªã㯠Jumbo Amusement GardenïŒç¥ããŠãJAGããšåŒã°ãã巚倧ãªéåå°ã§åããŠããïŒãã®éåå°ã®æ·å°ã¯åºå€§ã§ïŒã¢ãã©ã¯ã·ã§ã³ãããšããšã巚倧ãªãã®ãèšçœ®ãããïŒ ãã®åºŠJAGã«ïŒæ°ããªå·šå€§è¿·è·¯ã¢ãã©ã¯ã·ã§ã³ãBig Mazeããå°å
¥ãããããšã«ãªã£ãïŒ Big Maze ã®åœ¢ç¶ã¯ïŒå¹³é¢å³ã§èŠããšïŒçžŠæšªå
±ã« N ãã¹ã®æ£æ¹åœ¢ç¶ã®è¿·è·¯ M åãïŒé£æ¥ããå·Šå³ã®èŸºå士ãç¹ãåããïŒçžŠ N ãã¹ïŒæšª NM ãã¹ã®é·æ¹åœ¢ç¶ã«ãªãäºå®ã§ããïŒ M åã®è¿·è·¯ãå·Šããã©ã®é çªã§ç¹ãåããããã¯ãããããæ±ºãŸã£ãŠãããïŒé£ãåãè¿·è·¯ã®ã©ã®èŸºå士ãç¹ãåããããã¯æªå®ã§ããïŒ M åã®è¿·è·¯ãç¹ãåãããåã«ïŒåè¿·è·¯ã90 床å転ãããäºãåºæ¥ãïŒå転ã¯äœåºŠã§ãè¡ãããšãã§ãïŒåæ°ã¯è¿·è·¯æ¯ã«å¥ã
ã«æ±ºããŠããïŒå転ãããªãè¿·è·¯ããã£ãŠãããŸããªãïŒ åãã¹ã¯éè¡å¯èœãªãéè·¯ããïŒéè¡äžå¯èœãªãå£ãã®ããããã§ããïŒBig Maze ã®å
éšã§ã®ç§»åã¯ïŒäžäžå·Šå³ã® 4 æ¹åã«é£æ¥ããéè·¯ã®ãã¹ã«éãå¯èœã§ããïŒ Big Maze ã®å·Šç«¯ã® N ç®æã«äœçœ®ãïŒãã€éè·¯ã§ãããã¹ãã¹ã¿ãŒãå°ç¹ãšãïŒå³ç«¯ã® N ç®æã«äœçœ®ãïŒãã€éè·¯ã§ãããã¹ããŽãŒã«å°ç¹ãšããïŒ M åã®è¿·è·¯ãç¹ãåããã蟺ã®éžã³æ¹ã«ãã£ãŠã¯ïŒã¹ã¿ãŒãå°ç¹ããŽãŒã«å°ç¹ãè€æ°ååšããå ŽåãïŒååšããªãå ŽåãããåŸãïŒ ãŸãïŒã¹ã¿ãŒãå°ç¹ãããŽãŒã«å°ç¹ãžã®çµè·¯ãè€æ°ååšããå ŽåãïŒååšããªãå ŽåãããåŸãïŒ ããªãã®ä»äºã¯ïŒ å·Šããç¹ãåãããé çªããããããæ±ºãŸã£ãŠãã M åã®è¿·è·¯ãé©åã«å転ããïŒç¹ãåããã蟺ãäžæãéžã¶ããšã§ïŒã¹ã¿ãŒãå°ç¹ãããŽãŒã«å°ç¹ãžéè·¯ãç§»åããŠå°éå¯èœãªçžŠ N ãã¹ïŒæšª NM ãã¹ã®é·æ¹åœ¢ç¶ã® Big Maze ãäœãããšãåºæ¥ãã確èªããããšã§ããïŒ Input å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ãããé£ç¶ããŠäžããããïŒ ããŒã¿ã»ããã®æ°ã¯æå€§ã§ 50 ã§ããïŒ åããŒã¿ã»ããã¯ïŒæ¬¡ã®åœ¢åŒã§è¡šãããïŒ N M maze 1 maze 2 ... maze M æåã®è¡ã¯ãµãã€ã®æŽæ° N ïŒ M ã空çœåºåãã§äžãããïŒçžŠæšª N ãã¹ã®è¿·è·¯ã M åäžããããããšã瀺ãïŒ 1 †N †12 ã〠1 †M †1, 000 ã§ããïŒ ç¶ããŠïŒç©ºçœç¡ãã® N æåã 1 è¡ãšãã N è¡ã®å
¥å maze i ã M åç¶ãïŒ ããã§ïŒ 1 †i †M ã§ããïŒ N è¡ã®å
¥å maze i ã¯ïŒå·Šããç¹ãåãããé çªã§æ°ãããšãã® i çªç®ã®è¿·è·¯ã®æ
å ±ã衚ãïŒä»¥äžã®åœ¢åŒã§äžããããïŒ c 1, 1 c 1, 2 ... c 1, N c 2, 1 c 2, 2 ... c 2, N ... c N, 1 c N, 2 ... c N, N å c j, k ã¯ïŒâ.â ãŸã㯠â#â ã®ãããã 1 æåã§ïŒäžãã j çªç®ãã€å·Šãã k çªç®ã®ãã¹ã®æ
å ±ã衚ãïŒâ.â ã®ãšãéè·¯ïŒâ#âã®ãšãå£ã§ããïŒ ããã§ïŒ 1 †j, k †N ã§ããïŒ å
¥åã®çµããã¯ïŒç©ºçœã§åºåããã 2 åã®ãŒããããªãè¡ã§ç€ºãããïŒ Output åããŒã¿ã»ããã«ã€ããŠïŒã¹ã¿ãŒãå°ç¹ãããŽãŒã«å°ç¹ãžç§»åå¯èœãªçµè·¯ãå°ãªããšãã²ãšã€ååšãã Big Maze ãäœãããšãå¯èœãªã âYesâïŒäžå¯èœãªã âNoâ ã 1 è¡ã§åºåããïŒ Sample Input 3 2 #.# ... #.# ### ... ### 3 2 #.# ... #.# ### #.# ### 3 3 #.. ..# ### ..# #.# #.. #.. ..# ### 5 3 ..... ##### ##... ##.## ##... ..... ##### ..... ##### ..... ...## ##.## ...## ##### ..... 3 2 #.# ... #.# #.# #.# #.# 0 0 Output for Sample Input Yes No Yes Yes Yes 以äžã«ïŒãµã³ãã«ããŒã¿ã»ããã®å³ã瀺ãïŒ
| 38,313
|
Problem B: Monster Factory æ ªåŒäŒç€Ÿå倩å ã¯, Packet Monster ãšããã²ãŒã ãœãããçºå£²ããŠãã. ãã®ã²ãŒã ã¯ã¢ã³ã¹ã¿ãŒãæãŸã, è²ãŠ, æŠããããšããè¶£æšã®ãã®ã§, äžçäžã§å€§äººæ°ã®ã²ãŒã ã§ãã£ã. ãã®ã²ãŒã ã«ã¯åŸæ¥ã®ã²ãŒã ã«ã¯ç¡ãç¹åŸŽããã£ã. ãã®ã²ãŒã ã«ã¯ Red ãš Green ãšãã2ã€ã®ããŒãžã§ã³ããã, ããããã®ã²ãŒã ã§æãŸããããã¢ã³ã¹ã¿ãŒãç°ãªãã®ã . Red ã§ããæãŸããããªãã¢ã³ã¹ã¿ãŒã Green ã§å
¥æããã«ã¯, é信亀æãšããã·ã¹ãã ã䜿ã. ã€ãŸã, èªåã®ãœããå
ã®ã¢ã³ã¹ã¿ãŒãšåéã®ãœããå
ã®ã¢ã³ã¹ã¿ãŒã亀æããããšãã§ããã®ã . ãã®ã·ã¹ãã 㯠Packet Monster ã®äººæ°ã«å€§ããè²¢ç®ããŠãã. ããã, ãã®ã²ãŒã ã®ããã±ãŒãžã®è£œé å·¥çšã¯, 2ã€ã®ããŒãžã§ã³ã®ããã«å°ã
è€éã«ãªã£ã. ããã±ãŒãžã補é ããŠããå·¥å Žã«ã¯2ã€ã®çç£ã©ã€ã³ããã, çæ¹ã®ã©ã€ã³ã§ã¯ Red ã, ããäžæ¹ã®ã©ã€ã³ã§ã¯ Green ã補é ããŠãã. åã©ã€ã³ã§è£œé ãããããã±ãŒãžã¯, å·¥å Žå
ã§äžæãªè£œé çªå·ãå²ãåœãŠãã, äžç®æã«éãããã. ãããŠä»¥äžã®ãããªæªæïŒããã¯ãïŒè£
眮ã«ãã£ãŠæ··ããã, åºè·ãããã®ã . Red ã®ããã±ãŒãžã¯äžåŽãã, Green ã®ããã±ãŒãžã¯å·ŠåŽãã, ãã«ãã³ã³ãã¢ã«ãã£ãŠãã®æªæè£
眮ã«å±ãããã. æªæè£
眮ã¯ååã®åœ¢ããã2æ¬ã®ãã«ãã³ã³ãã¢ããåºæ¥ãŠãã, "push_down", "push_right" ãšãã2ã€ã®åœä»€ãåãä»ãã. "push_down"ã¯ãäžäžæ¹åã«èµ°ããã«ãã³ã³ãã¢ãããã±ãŒãž1ååäžæ¹åã«åããã, "push_right"ã¯ãå·Šå³æ¹åã«èµ°ããã«ãã³ã³ãã¢ãããã±ãŒãž1åå峿¹åã«åããããšããåœä»€ã§ãã. æªæã¯, Red ã®ããã±ãŒãžãšåãæ°ã® push_down åœä»€ãš Green ã®ããã±ãŒãžã®æ°ããïŒã€å€ã push_right åœä»€ã, ã©ã³ãã ãªé çªã§å®è¡ããããšã«ãã£ãŠè¡ããã. ãã ã, æåã«å®è¡ãããåœä»€ãšæåŸã«å®è¡ãããåœä»€ã¯ "push_right" ãšæ±ºãŸã£ãŠãã. ãã®å¶çŽã®å
ã§ã¯, Red ã®ããã±ãŒãžã®æ°ãšæªæè£
眮ã®äžç«¯ã«å±ãããã±ãŒãžã®æ°ãäžèŽã, Green ã®ããã±ãŒãžã®æ°ãšæªæè£
眮ã®å³ç«¯ã«å±ãããã±ãŒãžã®æ°ãäžèŽãã. æªæãããããã±ãŒãžã¯æçµçã«ãã«ãã³ã³ãã¢ã®äžç«¯ãŸãã¯å³ç«¯ã«å±ã, å±ããé ã«å
è£
ãããŠåºè·ããã. 以äžã«, äžé£ã®æªæã®æç¶ãã®äŸã瀺ã. ç°¡åã®ãã, 1ã€ã®ããã±ãŒãžã1æåã®ã¢ã«ãã¡ããããšããŠè¡šã. ããŠ, ãã®å·¥å Žã§ã¯äžè¯åã®è¿œè·¡ãªã©ã®ç®çã§, ãã«ãã³ã³ãã¢ã®äžç«¯ã»å³ç«¯ã«å±ããããã±ãŒãžãšãã®é çªãèšé²ããŠãã.ããããã®èšé²ã«ã¯ã³ã¹ããæãããã, å·¥å Žé·ã¯äžç«¯ã«å±ããããã±ãŒãžã«ã€ããŠã®ã¿èšé²ãåãããšãèãã.å³ç«¯ã«å±ããããã±ãŒãžã¯, äžç«¯ã»å·Šç«¯ã«éãããããã±ãŒãžãšäžç«¯ã«å±ããããã±ãŒãžã®èšé²ããæ±ããããã®ã§ã¯ãªãããšæã£ãã®ã . å·¥å Žé·ãå©ããŠ, å³ç«¯ã«å±ããããã±ãŒãžã®èšé²ãäœæããããã°ã©ã ãäœã£ãŠã»ãã. Input å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªã. å
¥åã®çµãã㯠- (ãã€ãã³)ïŒã€ã®è¡ã§ç€ºããã. 1ã€ã®å
¥åã¯3è¡ã®ã¢ã«ãã¡ãããã®å€§æåã»å°æåã®ã¿ãå«ãæååãããªã. ãããã¯ãããã, Red ã®ããã±ãŒãž, Green ã®ããã±ãŒãž, äžç«¯ã«å±ããããã±ãŒãžã衚ã.1æåã®ã¢ã«ãã¡ãããã1åã®ããã±ãŒãžã衚ã.倧æåãšå°æåã¯åºå¥ãããããšã«æ³šæãã. ã©ã®è¡ã«ã, åãæåã2å以äžçŸããããšã¯ç¡ã. 1è¡ç®ãš2è¡ç®ã«å
±éããŠå«ãŸããæåãååšããªã. å顿äžã§èª¬æãããã±ãŒã¹ã¯, Sample Inputã®1ã€ç®ã®äŸã«å¯Ÿå¿ããŠãã. Output å³ç«¯ã«å±ããããã±ãŒãžã, å±ããé çªã®ãšããã«åºåãã. Sample Input CBA cba cCa X ZY Z - Output for the Sample Input BbA XY
| 38,314
|
Runaway Domino ``Domino effect'' is a famous play using dominoes. A player sets up a chain of dominoes stood. After a chain is formed, the player topples one end of the dominoes. The first domino topples the second domino, the second topples the third and so on. You are playing domino effect. Before you finish to set up a chain of domino, a domino block started to topple, unfortunately. You have to stop the toppling as soon as possible. The domino chain forms a polygonal line on a two-dimensional coordinate system without self intersections. The toppling starts from a certain point on the domino chain and continues toward the both end of the chain. If the toppling starts on an end of the chain, the toppling continue toward the other end. The toppling of a direction stops when you touch the toppling point or the toppling reaches an end of the domino chain. You can assume that: You are a point without volume on the two-dimensional coordinate system. The toppling stops soon after touching the toppling point. You can step over the domino chain without toppling it. You will given the form of the domino chain, the starting point of the toppling, your coordinates when the toppling started, the toppling velocity and the your velocity. You are task is to write a program that calculates your optimal move to stop the toppling at the earliest timing and calculates the minimum time to stop the toppling. Input The first line contains one integer N , which denotes the number of vertices in the polygonal line of the domino chain (2 \leq N \leq 1000) . Then N lines follow, each consists of two integers x_{i} and y_{i} , which denote the coordinates of the i -th vertex (-10,000 \leq x, y \leq 10000) . The next line consists of three integers x_{t} , y_{t} and v_{t} , which denote the coordinates of the starting point and the velocity of the toppling. The last line consists of three integers x_{p} , y_{p} and v_{p} , which denotes the coordinates of you when the toppling started and the velocity (1 \leq v_{t} \lt v_{p} \leq 10) . You may assume that the starting point of the toppling lies on the polygonal line. Output Print the minimum time to stop the toppling. The output must have a relative or absolute error less than 10^{-6} . Sample Input 1 2 0 0 15 0 5 0 1 10 10 2 Output for the Sample Input 1 5.0 Sample Input 2 3 -10 0 0 0 0 10 -1 0 1 3 0 2 Output for the Sample Input 2 4.072027 Sample Input 3 2 0 0 10 0 5 0 1 9 0 3 Output for the Sample Input 3 2.0
| 38,315
|
Flame of Nucleus Year 20XX â a nuclear explosion has burned the world. Half the people on the planet have died. Fearful. One city, fortunately, was not directly damaged by the explosion. This city consists of N domes (numbered 1 through N inclusive) and M bidirectional transportation pipelines connecting the domes. In dome i , P i citizens reside currently and there is a nuclear shelter capable of protecting K i citizens. Also, it takes D i days to travel from one end to the other end of pipeline i . It has been turned out that this city will be polluted by nuclear radiation in L days after today. So each citizen should take refuge in some shelter, possibly traveling through the pipelines. Citizens will be dead if they reach their shelters in exactly or more than L days. How many citizens can survive at most in this situation? Input The input consists of multiple test cases. Each test case begins with a line consisting of three integers N , M and L (1 †N †100, M ⥠0, 1 †L †10000). This is followed by M lines describing the configuration of transportation pipelines connecting the domes. The i -th line contains three integers A i , B i and D i (1 †A i < B i †N , 1 †D i †10000), denoting that the i -th pipeline connects dome A i and B i . There is at most one pipeline between any pair of domes. Finally, there come two lines, each consisting of N integers. The first gives P 1 , . . ., P N (0 †P i †10 6 ) and the second gives K 1 , . . ., K N (0 †K i †10 6 ). The input is terminated by EOF. All integers in each line are separated by a whitespace. Output For each test case, print in a line the maximum number of people who can survive. Sample Input 1 0 1 51 50 2 1 1 1 2 1 1000 0 0 1000 4 3 5 1 2 4 1 3 1 3 4 2 0 1000 1000 1000 3000 0 0 0 Output for the Sample Input 50 0 3000
| 38,316
|
Problem F: Coupling Problem ææŽ¥å€§åŠã§ã¯æ¯å¹Žå€§èŠæš¡ãªåã³ã³ãè¡ãããŠããŸãã ä»å¹Žã¯ N 人ã®ç·æ§ãš M 人ã®å¥³æ§ãåå ããŸãã ããããç·æ§ã¯0ããé ã« N â1ãŸã§IDãå²ãæ¯ããããã女æ§ã¯0ããé ã« M â1ãŸã§IDãå²ãæ¯ãããŠããŸãã ãã®åã³ã³ã§ã¯èªåã®ã倧奜ããªäººããšããããã奜ããªäººãã®IDãæç€ºããŸãã ç·æ§ã¯ãããã女æ§ã®IDãã女æ§ã¯ããããç·æ§ã®IDãæç€ºããŸãã ãã®åŸã以äžã®ã«ãŒã«ã«åŸã£ãŠã«ããã«ãæç«ããŸãã ç·æ§ã¯è€æ°ã®å¥³æ§ã女æ§ã¯è€æ°ã®ç·æ§ãšã«ããã«ã«ãªã£ãŠã¯ãããªãã äºãã«ã倧奜ããªäººããšæç€ºããç·æ§ãšå¥³æ§ã§ãã¢ãã§ããã ãããããä»»æã®ãã¢ãéžã³ã«ããã«ãäœãããšãã§ããã çæ¹ãã倧奜ããªäººããããçæ¹ãããããã奜ããªäººããšæç€ºããç·æ§ãšå¥³æ§ã§ãã¢ãã§ããã ãããããä»»æã®ãã¢ãéžã³ã«ããã«ãäœãããšãã§ããã äºãã«ããããã奜ããªäººããšæç€ºããç·æ§ãšå¥³æ§ã§ãã¢ãã§ããã ãããããä»»æã®ãã¢ãéžã³ã«ããã«ãäœãããšãã§ããã ã«ãŒã«2ã§åºæ¥ãã«ããã«ãã«ãŒã«3ã§åºæ¥ãã«ããã«ãã«ãŒã«4ã§åºæ¥ãã«ããã«ã®é ã«ã«ããã«ã®æ°ãæå€§ã«ãªãããã«ã«ããã«ãæç«ããã ãµãžåã¯ãã®åã³ã³ã®äž»å¬è
ã§ãã è¿å¹Žã§ã¯åå è
ã®æ°ãå€ããªãæåã§ã«ããã«ã®æ°ãææ¡ããã®ã倧å€ã«ãªã£ãŠããŸãããããã§ããã°ã©ããŒã§ããããªãã¯ããµãžåã®æäŒããããããšã«ããŸãããäžèšã®ã«ãŒã«ã«åŸã£ãŠã«ããã«ãäœã£ãæã®ã倧奜ããªäººãå士ã®ã«ããã«ã®æ°ãšã倧奜ããªäººããšããããã奜ããªäººãã«ããã«ããã«ã®æ°ãšããããã奜ããªäººãå士ã®ã«ããã«ã®æ°ãåºåããããã°ã©ã ãäœæããŠãã ããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã N M L1 a 1 b 1 a 2 b 2 : a L1 b L1 L2 c 1 d 1 c 2 d 2 : c L2 d L2 L3 e 1 f 1 e 2 f 2 : e L3 f L3 L4 g 1 h 1 g 2 h 2 : g L4 h L4 1è¡ç®ã«ããããç·æ§ã®åå è
ã®æ°ãšå¥³æ§ã®åå è
ã®æ°ã衚ã2ã€ã®æŽæ° N , M ãäžãããããæ¬¡ã«ç·æ§åŽã®å€§å¥œããªäººã衚ãããŒã¿ã®æ° L1 ãäžãããããç¶ãL1è¡ã« a i ãš b i ã空çœåºåãã§äžããããããããããID a i ã®ç·æ§ãID b i ã®å¥³æ§ãã倧奜ããã§ããããšã瀺ãã ç¶ãè¡ã«ç·æ§åŽã®ãããã奜ããªäººã衚ãããŒã¿ã®æ° L2 ãäžãããããç¶ãL2è¡ã« c i ãš d i ã空çœåºåãã§äžããããããããããID c i ã®ç·æ§ãID d i ã®å¥³æ§ãããããã奜ããã§ããããšã瀺ããæ¬¡ã«å¥³æ§åŽã®å€§å¥œããªäººã衚ãããŒã¿ã®æ° L3 ãäžãããããç¶ãL3è¡ã« e i ãš f i ã空çœåºåãã§äžããããããããããID e i ã®å¥³æ§ãIDã® f i ã®ç·æ§ãã倧奜ããã§ããããšã瀺ãã ç¶ãè¡ã«å¥³æ§åŽã®ãããã奜ããªäººã衚ãããŒã¿ã®æ° L4 ãäžãããããç¶ãL4è¡ã« g i ãš h i ã空çœåºåãã§äžããããããããããID g i ã®å¥³æ§ãID h i ã®ç·æ§ãããããã奜ããã§ããããšã瀺ãã Constraints å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã 1 †N , M †100 0 †a i , c i , f i , h i †N â1 0 †b i , d i , e i , g i †M â1 0 †L1 , L2 , L3 , L4 †2000 L1 > 0, L2 > 0 ã«ãã㊠( a i , b i ) â ( c j , d j ) ( 0 †i < L1 , 0 †j < L2 ) L3 > 0, L4 > 0 ã«ãã㊠( e i , f i ) â ( g j , h j ) ( 0 †i < L3 , 0 †j < L4 ) ( a i , b i ) â ( a j , b j ) ( i â j ) ( 0 †i < L1 , 0 †j < L1 ) ( c i , d i ) â ( c j , d j ) ( i â j ) ( 0 †i < L2 , 0 †j < L2 ) ( e i , f i ) â ( e j , f j ) ( i â j ) ( 0 †i < L3 , 0 †j < L3 ) ( g i , h i ) â ( g j , h j ) ( i â j ) ( 0 †i < L4 , 0 †j < L4 ) Output å顿ã®ã«ãŒã«ã«åŸã£ãŠã«ããã«ãæç«ããæã®ãã倧奜ããªäººãå士ã®ãã¢ã®æ°ãšã倧奜ããªäººããšããããã奜ããªäººãã®ãã¢ã®æ°ãšããããã奜ããå士ã®ãã¢ã®æ°ã空çœåºåãã§1è¡ã«åºåããã Sample Input 1 3 3 3 0 0 1 1 2 2 2 1 0 2 1 3 1 1 2 2 0 1 2 1 0 2 0 Sample Output 1 2 0 0 ãã®å Žåç·æ§1ãšå¥³æ§1ãç·æ§2ãšå¥³æ§2ã倧奜ãå士ã§ã«ããã«ãšãªãã倧奜ãå士ãã®ãã¢æ°ã2ã«ãªãã ãããšãç·æ§0ã®ããšãã倧奜ãããªå¥³æ§ãããããã奜ãããªå¥³æ§ãããªããªã£ãŠããŸããŸãã ãŸãã女æ§0ã®ããšãã倧奜ãããªç·æ§ãããããã奜ãããªç·æ§ãããªããªã£ãŠããŸããã以éã«ããã«ã¯æç«ããªããªããŸãã Sample input 2 5 5 5 4 1 2 2 1 4 1 3 4 2 5 1 1 1 2 3 3 3 0 3 4 5 2 3 2 2 0 3 0 2 4 1 5 2 0 4 0 1 0 4 3 2 1 Sample Output2 2 1 0
| 38,317
|
G - æ å顿 ãã€ãã®ãããã¯ïŒäŒæã§ãšããå°ããªæã蚪ããŠããïŒåœŒå¥³ãé©ããã®ã¯ïŒãã®æã®è¡šæããã€æ§è³ªã§ããïŒ æã«ã¯ N åã®å®¶å±ãããïŒããã§ã¯ç°¡åã®ããïŒæã¯ 2 次å
å¹³é¢ã§ãããšãïŒå®¶å±ã¯ãã®å¹³é¢äžã®ç¹ã§ãããšèŠãªãïŒ ããããã®å®¶å±ã«ã¯è¡šæã 1 åèšããããŠããïŒãã®å®¶ã®èåã衚ããŠããïŒãããã¯æã®äžã蚪åããã«ã€ããŠïŒãã®æã®è¡šæã次ã®ãããªæ§è³ªãæã£ãŠããããšã«æ°ä»ããïŒ ãã宿° R ãååšããïŒ ãã 2 ã€ã®å®¶å±ã®è·é¢ã R 以äžã§ãããªãïŒãã® 2 ã€ã®å®¶å±ã¯åã衚æãæã€ïŒ ãã 2 ã€ã®å®¶å±ã®è·é¢ã 3R 以äžã§ãããªãïŒãã® 2 ã€ã®å®¶å±ã¯ç°ãªã衚æãæã€ïŒ ä»»æã® 2 ã€ã®å®¶å±ã®è·é¢ã¯ R 以äžã§ããã 3R 以äžã§ãããã®ã©ã¡ããã§ããïŒ ããã§ïŒå®¶å±å士ã®è·é¢ã¯ïŒå¹³é¢äžã®ãŠãŒã¯ãªããè·é¢ã«ãã£ãŠèšæž¬ãããã®ãšããïŒ ãããã¯ãã®æã«è¡šæãå
šéšã§äœçš®é¡ããã®ããæ°ã«ãªã£ããïŒãã®æã¯æå€ã«åºããšããããšã«æ°ä»ããã®ã§ïŒèšç®æ©ã䜿ã£ãŠãã®çããæš¡çŽ¢ããããšã«ããïŒ å
¥ååœ¢åŒ å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ N R x 1 y 1 x 2 y 2 ... x N y N N ã¯å®¶å±ã®åæ°ã§ããïŒ R ã¯å®¶å±ã®é
眮ã®å¶çŽã«é¢ããå€ã§ããïŒ (x i , y i ) ã¯å®¶å± i ã®åº§æšã衚ãïŒ åºååœ¢åŒ æã«ååšãã衚æã®çš®é¡ã®æ°ãæ±ããïŒ å¶çŽ 1 †N †2 à 10 5 1 †R †10 3 |x i |, |y i | †10 6 N ã¯æŽæ°ã§ããïŒ R, x i , y i ã¯å®æ°ã§ïŒå°æ°ç¬¬ 3 äœãŸã§è¡šãããïŒ ä»»æã® 1 †i < j †N ã«å¯Ÿã㊠d ij = â{(x i - x j ) 2 + (y i - y j ) 2 } ãšãããšãïŒ d ij †R ã 3R †d ij ã®ã©ã¡ãããæºããããïŒ ãã®åé¡ã®å€å®ã«ã¯ïŒ15 ç¹åã®ãã¹ãã±ãŒã¹ã®ã°ã«ãŒããèšå®ãããŠããïŒ ãã®ã°ã«ãŒãã«å«ãŸãããã¹ãã±ãŒã¹ã¯äžèšã®å¶çŽã«å ããŠäžèšã®å¶çŽãæºããïŒ çã㯠10 以äžã§ããïŒ å
¥åºåäŸ å
¥åäŸ 1 5 3.000 1.000 0.000 0.000 0.000 -1.000 0.000 10.000 0.000 -10.000 0.000 åºåäŸ 1 3 å®¶å± 1,2,3 ãšå®¶å± 4 ãšå®¶å± 5 ã§è¡šæãç°ãªãïŒå
šäœã§ 3 ã€ã®è¡šæãååšããïŒ å
¥åäŸ 2 12 1.234 0.500 0.000 -0.500 0.000 0.000 0.000 0.000 -0.500 55.500 55.000 -55.500 55.000 55.000 55.000 55.000 -55.500 99.500 99.000 -99.500 99.000 99.000 99.000 99.000 -99.500 åºåäŸ 2 7 å
¥åäŸ 3 5 99.999 0.000 0.000 49.999 0.001 0.000 0.000 -49.999 -0.001 0.000 0.000 åºåäŸ 3 1 Writer: æ¥ æ¬å
Tester: å°æµç¿å€ªé
| 38,318
|
Problem F: Controlled Tournament National Association of Tennis is planning to hold a tennis competition among professional players. The competition is going to be a knockout tournament, and you are assigned the task to make the arrangement of players in the tournament. You are given the detailed report about all participants of the competition. The report contains the results of recent matches between all pairs of the participants. Examining the data, youâve noticed that it is only up to the opponent whether one player wins or not. Since one of your special friends are attending the competition, you want him to get the best prize. So you want to know the possibility where he wins the gold medal. However it is not so easy to figure out because there are many participants. You have decided to write a program which calculates the number of possible arrangements of tournament in which your friend wins the gold medal. In order to make your trick hidden from everyone, you need to avoid making a factitive tourna- ment tree. So you have to minimize the height of your tournament tree. Input The input consists of multiple datasets. Each dataset has the format as described below. N M R 11 R 12 . . . R 1 N R 21 R 22 . . . R 2 N ... R N 1 R N 2 . . . R NN N (2 †N †16) is the number of player, and M (1 †M †N ) is your friendâs ID (numbered from 1). R ij is the result of a match between the i -th player and the j -th player. When i -th player always wins, R ij = 1. Otherwise, R ij = 0. It is guaranteed that the matrix is consistent: for all i â j , R ij = 0 if and only if R ji = 1. The diagonal elements R ii are just given for convenience and are always 0. The end of input is indicated by a line containing two zeros. This line is not a part of any datasets and should not be processed. Output For each dataset, your program should output in a line the number of possible tournaments in which your friend wins the first prize. Sample Input 2 1 0 1 0 0 2 1 0 0 1 0 3 3 0 1 1 0 0 1 0 0 0 3 3 0 1 0 0 0 0 1 1 0 3 1 0 1 0 0 0 0 1 1 0 3 3 0 1 0 0 0 1 1 0 0 6 4 0 0 0 0 0 1 1 0 1 0 1 0 1 0 0 1 1 0 1 1 0 0 1 0 1 0 0 0 0 0 0 1 1 1 1 0 7 2 0 1 0 0 0 1 0 0 0 1 0 1 1 1 1 0 0 1 1 0 0 1 1 0 0 0 1 0 1 0 0 1 0 0 1 0 0 1 0 1 0 0 1 0 1 1 0 1 0 8 6 0 0 0 0 1 0 0 0 1 0 1 1 0 0 0 0 1 0 0 0 1 0 0 0 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 1 1 0 1 0 0 1 1 1 1 1 0 1 0 0 1 1 1 0 1 0 1 0 0 0 Output for the Sample Input 1 0 0 3 0 1 11 139 78
| 38,319
|
æã®éè·¯èšç» äŒæŽ¥åœã®è¥æŸå¹³éã«ãéèœãç¹åšããŠããŸãããããã€ãã®éèœã®éã¯ãŸã£ããã§äºãã«è¡ãæ¥ã§ããéã§ç¹ãã£ãŠããŠãå¹³éã«ããã©ã®éèœã®éãéã蟿ã£ãŠè¡ãæ¥ãã§ããŸããããããã®éã«ã¯é·ãã«å¿ããç¶æè²»ãããããŸããããã¹ãŠã®éèœãè³éãåºãåã£ãŠéãç¶æããŠããŸããã ãããšãããã¹ãŠã®éèœãäžã€ã®æã«ãŸãšãŸãããšã決ãŸããæãå²ãå¢çç·ãåŒãããšã«ãªããŸãããåœã®æ±ºãŸãã§ã¯ãæãæ§æããã©ã®ïŒã€ã®éèœãçµãã ãŸã£ãããªç·ããæã®å€ãéã£ãŠã¯ãããŸããïŒå¢çç·äžãéãããšã¯èš±ãããŸãïŒãããã«ãäŒæŽ¥åœã§ã¯æãå²ãå¢çç·äžã«éããªããã°ãªããŸãããå¢çç·äžã«éããªãå Žæã«ã¯ãåœãæ°ãã«éãäœã£ãŠãããŸãã ããããéã®ç¶æè²»ã¯æãæ¯æãã®ã§ãæäººéã¯å¢çç·ãã§ããã ãçãããããšèããŠããŸããããã«ãæäººéã¯ãã¹ãŠã®éèœã®éãè¡ãæ¥ã§ããç¶æ
ãç¶æãã€ã€ãå¢çç·äžã«ãªãéã廿¢ããããšã§ãéã®é·ãã®åèšãæå°ã«ããããšã«ããŸããã éèœã®äœçœ®ãšå
ã
ãã£ãéã®æ
å ±ãäžãããããå¢çç·äžã«éã眮ãããã€ããã¹ãŠã®éèœãè¡ãæ¥ã§ããããã«ããå Žåã®ãéã®é·ãã®åèšã®æå°å€ãèšç®ããããã°ã©ã ãäœæããããã ããéèœã¯å€§ããã®ãªãç¹ãéã¯å¹
ã®ãªãç·åãšããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã V R x 1 y 1 x 2 y 2 : x V y V s 1 t 1 s 2 t 2 : s R t R ïŒè¡ç®ã«éèœã®æ° V (3 †V †100) ãšéã®æ° R (2 †R †1000) ãäžããããã ç¶ã V è¡ã«éèœã衚ãç¹ã®æ
å ±ãäžãããããåè¡ã«äžããããïŒã€ã®æŽæ° x i , y i (-1000 †x i , y i †1000)ã¯ããããã i çªç®ã®éèœã® x 座æšã y 座æšã衚ãã ç¶ã R è¡ã«å
ã
ãã£ãéã®æ
å ±ãäžãããããåè¡ã«äžããããïŒã€ã®æŽæ° s i , t i (1 †s i < t i †V )ã¯ã i çªç®ã®éã s i çªç®ã®éèœãš t i çªç®ã®éèœãã€ãªãã§ããããšã衚ãã å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã i â j ãªãã°ã i çªç®ã®éèœãš j çªç®ã®éèœã®åº§æšã¯ç°ãªãã ã©ã®ïŒã€ã®éèœã«ã€ããŠããããããçŽæ¥çµã¶éã¯é«ã
ïŒã€ããçŸããªãã ïŒã€ã®ç°ãªãéã端ç¹ä»¥å€ã®ç¹ãå
±æããããšã¯ãªãã ïŒã€ä»¥äžã®éèœãåäžçŽç·äžã«äžŠãã§ããããšã¯ãªãã Output æ¡ä»¶ãæºããéã®é·ãã®åèšã®æå°å€ãïŒè¡ã«å®æ°ã§åºåããããã ãã誀差ããã©ã¹ãã€ãã¹ 0.001 ãè¶
ããŠã¯ãªããªãããã®æ¡ä»¶ãæºããã°å°æ°ç¹ä»¥äžäœæ¡è¡šç€ºããŠãããã Sample Input 1 5 5 0 0 1 1 3 0 3 2 0 2 1 2 2 3 2 4 3 4 1 5 Sample Output 1 11.4142 Sample Input 2 7 6 0 2 3 0 2 2 1 0 4 1 2 3 3 5 1 3 2 4 2 3 3 5 3 7 6 7 Sample Output 2 18.2521
| 38,320
|
D: Complex Oracle - Complex Oracle - åé¡ â»ãã®åé¡ã¯ãªã¢ã¯ãã£ãåé¡ã§ãïŒããªãã¡ïŒãµãŒããŒåŽã«çšæãããããã°ã©ã ãšå¯Ÿè©±çã«å¿çããããšã§æ£çãå°ãããã°ã©ã ãäœæããå¿
èŠããããŸãïŒ ãŸãããµãŒããŒåŽã®ããã°ã©ã ãèšç®æ©è³æºãå
±æããé¢ä¿äžããµãŒããŒã ãã§æå€§ 3 secçšåºŠã®å®è¡æéãæå€§ 300 MBçšåºŠã®ã¡ã¢ãªã䜿çšããå ŽåããããŸãã®ã§ãTLEã»MLEã«ãæ°ãã€ããã ããã ãããã«ããã¯è¥ã¶æŸé«æ ¡ã®ããã°ã©ãã³ã°ã³ã³ãã¹ãéšãéç§°ã·ãããéšã«æå±ãã2幎çã§ãããèŠç®éºããããããã«ããã¯ãã®å°ããªäœãç¡éã«ååšãããã£ãŒã ãã€ã³ãã®1ã€ã§ããããæ¬äººã¯ã³ã³ãã¬ãã¯ã¹ãæããŠããããã ããã®ããããäžåã«äžŠãã§ãã人ãã¡ãèŠããšãããããã®äººã®åæ¹ã«ãã®äººãã身é·ãé«ã人ãäœäººäžŠãã§ããããç¬æã«æ°ããããèœåãæã£ãŠããã ããã³ã³ã®åéã»åŸåœé€šå€§åŠäžçéšåã®ãšãªãŒãç«¶æããã°ã©ãã§ãããã·ãããéšã®éšé·ã§ãããã£ã€ã¡ããã¯ããããã«ããã®ãã®èœåã䜿ãã°ã䞊ãã§ãã人ãã¡ãããããäœçªç®ã«èãé«ãã®ããåœãŠãããšãã§ããã®ã§ã¯ãªãããšèããã ä»ããã£ã€ã¡ãã㯠N 人ã䞊ãã§ããåããããã«ããã«èŠããŠããããã£ã€ã¡ããã¯ã人ã N 人䞊ãã§ããããšã¯ç¥ã£ãŠãããããã®äžŠã³é ãã©ããªã£ãŠãããã¯ããããªãããã£ã€ã¡ããã¯ãããã«ããã« â l çªç®ã®äººãã r çªç®ã®äººãŸã§ã³ã³ãã¬ãã¯ã¹åºŠâ ãæããŠãããããšãã§ãããããã§ã l çªç®ã®äººãã r çªç®ã®äººãŸã§ã®ã³ã³ãã¬ãã¯ã¹åºŠãšã¯ã i ( l \†i \†r ) çªç®ã®äººããããã«é¢ããŠã l çªç®ãã i â 1 çªç®ãŸã§ã®éã«ããèªå ( i ) ããèãé«ã人ã®äººæ°ã®ç·åã§ããã(ããå³å¯ãªå®çŸ©ã¯å
¥åºå圢åŒãåç
§ã®ããš) (ããããŸããããšã«) ã·ãããéšã®éšå¡ã§ããããªãã¯ã(ãšãŠãããšãŠãå¿èŠããã) ãããã«ããããªã©ã¯ã«ãšããŠå©çšããããšã§èº«é·é ãåœãŠãããã°ã©ã ãæžããããã£ã€ã¡ããã«åœãããããã€ããããããŠãããã«ããã«è² æ
ããããªããããå°ãªã質ååæ°ã§æ±ããããããé 匵ããã å
¥ååºååœ¢åŒ ãµãŒããŒã¯èã®é ã衚ãé·ã N ã®æ°å p ãä¿æããŠãããããã¯å
¥åãšããŠäžããããªãã p ã®åèŠçŽ p_i 㯠1 ä»¥äž N 以äžã§ãããããããå€ã¯ç°ãªãã p_i ã倧ããå€ãæã€æ¹ãèãé«ãããšã衚ãã ãµãŒããŒã¯ãŸãã p ã®é·ã N ã衚ã 1 ã€ã®æŽæ°ãããªã 1 è¡ãå
¥åãšããŠè§£çããã°ã©ã ã«äžããã æ¬¡ã«è§£çããã°ã©ã ã 2 ã€ã®æŽæ° l, r ( 1 \†l \†r \†N ) ãããªãã¯ãšãªããµãŒããŒã«éããã¯ãšãªã®åºå圢åŒã¯ ? l r ã§ãããããã¯äŸãã°C/C++ã ãšã printf("? %d %d\n", l, r); fflush(stdout); ãªã©ãšæžãã°ãããåºåã®åºŠã«ãã©ãã·ã¥ããããšãæšå¥šããã ãããšããµãŒããŒåŽã¯ä»¥äžã®å€ã衚ã 1 ã€ã®æŽæ° C ãããªã1è¡ãå
¥åãšããŠè§£çããã°ã©ã ã«äžããã C = (\{ (i, j) | p_i > p_j {\rm for} l \†i<j \†r \}ã®èŠçŽ æ°) ãã ããã¯ãšãªãšããŠæ£ãããªã l, r ( l, r ã 1 ä»¥äž N 以äžã®æ°ã§ã¯ãªãããŸã㯠l>r ã§ãã) ãäžããããå ŽåããµãŒããŒã¯ â1 ã C ãšããŠè¿ãã ãã®å¿çãäœåºŠãç¹°ãè¿ããè§£çããã°ã©ã ã p ãæšå®ã§ãããªãã°ã p ã以äžã®åœ¢åŒã§åºåããã ! p_1 ... p_N æšå®ããé åã®åºåã¯1床ããã§ããããã®åºåã p ãšç°ãªãå Žåã誀çãšãªãã200,000å以å
ã®ã¯ãšãªã§æ£ãã p ãåºåã§ããå Žåãæ£çãšãªãã åã¯ãšãªã§æ¹è¡ãè¡ãããæ°ãã€ããããšã å
¥åå¶çŽ 1 \†N \†100,000 æšå®ãããé·ã N ã®æ°å p ã¯é åãããªãã¡ã p_i \in \{1, ... , N\} {\rm for} 1 \†i \†N ãããã³ p_i \neq p_j {\rm for} 1 \†i < j \†N ãæºãã ãµãŒããŒãžã®ã¯ãšãªåæ°ã¯200,000åãŸã§ ãµãŒããŒããè¿çããã C ã¯32bitæŽæ°åã§ã¯åãŸããªã倧ããã«ãªãããããšã«æ³šæãã å
¥ååºåäŸ ãµãŒããŒã®åºå ãµãŒããŒãžã®å
¥å 4 ? 1 3 2 ? 2 4 1 ... ... ! 4 1 3 2
| 38,322
|
Integral Rectangles Let us consider rectangles whose height, h , and width, w , are both integers. We call such rectangles integral rectangles . In this problem, we consider only wide integral rectangles, i.e., those with w > h . We define the following ordering of wide integral rectangles. Given two wide integral rectangles, The one shorter in its diagonal line is smaller, and If the two have diagonal lines with the same length, the one shorter in its height is smaller. Given a wide integral rectangle, find the smallest wide integral rectangle bigger than the given one. Input The entire input consists of multiple datasets. The number of datasets is no more than 100. Each dataset describes a wide integral rectangle by specifying its height and width, namely h and w , separated by a space in a line, as follows. h w For each dataset, h and w (> h ) are both integers greater than 0 and no more than 100. The end of the input is indicated by a line of two zeros separated by a space. Output For each dataset, print in a line two numbers describing the height and width, namely h and w (> h ), of the smallest wide integral rectangle bigger than the one described in the dataset. Put a space between the numbers. No other characters are allowed in the output. For any wide integral rectangle given in the input, the width and height of the smallest wide integral rectangle bigger than the given one are both known to be not greater than 150. In addition, although the ordering of wide integral rectangles uses the comparison of lengths of diagonal lines, this comparison can be replaced with that of squares (self-products) of lengths of diagonal lines, which can avoid unnecessary troubles possibly caused by the use of floating-point numbers. Sample Input 1 2 1 3 2 3 1 4 2 4 5 6 1 8 4 7 98 100 99 100 0 0 Output for the Sample Input 1 3 2 3 1 4 2 4 3 4 1 8 4 7 2 8 3 140 89 109
| 38,323
|
Problem Statement Have you experienced $10$-by-$10$ grid calculation? It's a mathematical exercise common in Japan. In this problem, we consider the generalization of the exercise, $N$-by-$M$ grid calculation. In this exercise, you are given an $N$-by-$M$ grid (i.e. a grid with $N$ rows and $M$ columns) with an additional column and row at the top and the left of the grid, respectively. Each cell of the additional column and row has a positive integer. Let's denote the sequence of integers on the column and row by $a$ and $b$, and the $i$-th integer from the top in the column is $a_i$ and the $j$-th integer from the left in the row is $b_j$, respectively. Initially, each cell in the grid (other than the additional column and row) is blank. Let $(i, j)$ be the cell at the $i$-th from the top and the $j$-th from the left. The exercise expects you to fill all the cells so that the cell $(i, j)$ has $a_i \times b_j$. You have to start at the top-left cell. You repeat to calculate the multiplication $a_i \times b_j$ for a current cell $(i, j)$, and then move from left to right until you reach the rightmost cell, then move to the leftmost cell of the next row below. At the end of the exercise, you will write a lot, really a lot of digits on the cells. Your teacher, who gave this exercise to you, looks like bothering to check entire cells on the grid to confirm that you have done this exercise. So the teacher thinks it is OK if you can answer the $d$-th digit (not integer , see an example below), you have written for randomly chosen $x$. Let's see an example. For this example, you calculate values on cells, which are $8$, $56$, $24$, $1$, $7$, $3$ in order. Thus, you would write digits 8, 5, 6, 2, 4, 1, 7, 3. So the answer to a question $4$ is $2$. You noticed that you can answer such questions even if you haven't completed the given exercise. Given a column $a$, a row $b$, and $Q$ integers $d_1, d_2, \dots, d_Q$, your task is to answer the $d_k$-th digit you would write if you had completed this exercise on the given grid for each $k$. Note that your teacher is not so kind (unfortunately), so may ask you numbers greater than you would write. For such questions, you should answer 'x' instead of a digit. Input The input consists of a single test case formatted as follows. $N$ $M$ $a_1$ $\ldots$ $a_N$ $b_1$ $\ldots$ $b_M$ $Q$ $d_1$ $\ldots$ $d_Q$ The first line contains two integers $N$ ($1 \le N \le 10^5$) and $M$ ($1 \le M \le 10^5$), which are the number of rows and columns of the grid, respectively. The second line represents a sequence $a$ of $N$ integers, the $i$-th of which is the integer at the $i$-th from the top of the additional column on the left. It holds $1 \le a_i \le 10^9$ for $1 \le i \le N$. The third line represents a sequence $b$ of $M$ integers, the $j$-th of which is the integer at the $j$-th from the left of the additional row on the top. It holds $1 \le b_j \le 10^9$ for $1 \le j \le M$. The fourth line contains an integer $Q$ ($1 \le Q \le 3\times 10^5$), which is the number of questions your teacher would ask. The fifth line contains a sequence $d$ of $Q$ integers, the $k$-th of which is the $k$-th question from the teacher, and it means you should answer the $d_k$-th digit you would write in this exercise. It holds $1 \le d_k \le 10^{15}$ for $1 \le k \le Q$. Output Output a string with $Q$ characters, the $k$-th of which is the answer to the $k$-th question in one line, where the answer to $k$-th question is the $d_k$-th digit you would write if $d_k$ is no more than the number of digits you would write, otherwise 'x'. Examples Input Output 2 3 8 1 1 7 3 5 1 2 8 9 1000000000000000 853xx 3 4 271 828 18 2845 90 45235 3 7 30 71 8 61 28 90 42 7x406x0
| 38,324
|
è¡æ¶²å ããåŠçŽã®çåŸã®åºåžçªå·ãš ABO è¡æ¶²åãä¿åããããŒã¿ãèªã¿èŸŒãã§ããã®ãã®ã®è¡æ¶²åã®äººæ°ãåºåããããã°ã©ã ãäœæããŠãã ããããªããABO è¡æ¶²åã«ã¯ãA åãB åãAB åãO åã®ïŒçš®é¡ã®è¡æ¶²åããããŸãã Input ã«ã³ãã§åºåãããåºåžçªå·ãšè¡æ¶²åã®çµããè€æ°è¡ã«æž¡ã£ãŠäžããããŸããåºåžçªå·ã¯ 1 ä»¥äž 50 以äžã®æŽæ°ãè¡æ¶²åã¯æåå "A", "B", "AB" ãŸã㯠"O" ã®ããããã§ããçåŸã®äººæ°ã¯ 50 ãè¶
ããŸããã Output ïŒè¡ç®ã« A åã®äººæ° ïŒè¡ç®ã« B åã®äººæ° ïŒè¡ç®ã« AB åã®äººæ° ïŒè¡ç®ã« O åã®äººæ° ãåºåããŸãã Sample Input 1,B 2,A 3,B 4,AB 5,B 6,O 7,A 8,O 9,AB 10,A 11,A 12,B 13,AB 14,A Output for the Sample Input 5 4 3 2
| 38,325
|
Bit Operation II Given two non-negative decimal integers $a$ and $b$, calculate their AND (logical conjunction), OR (logical disjunction) and XOR (exclusive disjunction) and print them in binary representation of 32 bits. Input The input is given in the following format. $a \; b$ Output Print results of AND, OR and XOR in a line respectively. Constraints $0 \leq a, b \leq 2^{32} - 1$ Sample Input 1 8 10 Sample Output 1 00000000000000000000000000001000 00000000000000000000000000001010 00000000000000000000000000000010
| 38,326
|
å±±ãžåž°ãã è¿å¹Žã€ãºã¢åœã§ã¯ãå±±ããè¡ã«éããŠããåç©ã«æ©ãŸãããŠãããããªãã¯åç©ãå±±ãžåž°ãããšç ç©¶ãéãã以äžã®ããšãæããã«ããã ããããã®åç©ã«ã¯åºæã®ååãã€ããŠããã ïŒäœã®åç©ã«ã€ããŠãäžæ¹ã®åç©ã®ååã®ã©ããã®äœçœ®ã«ïŒæåãæ¿å
¥ãããšãããäžæ¹ã®åç©ã®ååãšäžèŽããå Žåããããããã¢ã«ããŠå±±ãžåž°ãããšãã§ããã äžåºŠå±±ãžåž°ã£ãåç©ããåã³è¡ã«éããŠããããšã¯ãªãã ããªãã¯ãè¡ã«éããŠããåç©ãããã®æ¹æ³ã§ã©ã®ãããå±±ãžåž°ãããšãã§ããããèšç®ããããšã«ããã è¡ã«éããŠããåç©ã®ååãäžãããããšãããã®æ¹æ³ã§æå€§ããã€ã®ãã¢ãå±±ãžåž°ãããšãã§ããããæ±ããããã°ã©ã ãäœæããã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã $N$ $str_1$ $str_2$ : $str_N$ ïŒè¡ç®ã«åç©ã®æ°$N$ ($2 \leq N \leq 100,000$)ãäžãããããç¶ã$N$è¡ã«$i$çªç®ã®åç©ã®ååã衚ãæåå$str_i$ãäžããããããã ã$str_i$ã¯è±å°æåãšè±å€§æåã§æ§æããã10æå以äžã®æååã§ããããŸãããã¹ãŠã®åç©ã®ååã¯ç°ãªã($i \ne j$ãªã$str_i \ne str_j$)ã åºå å±±ãžåž°ãããšãã§ããåç©ã®ãã¢ã®æ°ã®æå€§å€ãåºåããã å
¥åºåäŸ å
¥åäŸïŒ 4 aedb aeb ebCd cdE åºåäŸïŒ 1 å
¥åäŸïŒ 4 bcD bD AbD bc åºåäŸïŒ 2
| 38,327
|
C - ãã§ã³ã¬ãŒã ç®ã®åã« M \times N åã®ããŒã¹ã§ã§ããæ¿ãã§ã³ãããïŒ ããŒã¹ã«ã¯çãããŒã¹ãšèŸãããŒã¹ã®2çš®é¡ãããïŒã§ããã ãå€ãã®çãããŒã¹ãé£ã¹ããïŒ ãããïŒæ¿ãã§ã³ã®é£ã¹æ¹ã«ã¯ã«ãŒã«ãããïŒä»¥äžã®ã«ãŒã«ãå®ããªããã°ãªããªãïŒ ããããŒã¹ãé£ã¹ãããã«ã¯ïŒãã®ããŒã¹ã®çäžã«é£æ¥ããããŒã¹ãååšããïŒå ããŠãã®ããŒã¹ã®å°ãªããšãå·Šå³ã©ã¡ããã«ã¯ããŒã¹ãååšããªãå¿
èŠãããïŒ äŸãã°ïŒå³ã®ãããªåœ¢ã®ãã§ã³ã¬ãŒãã§ã¯ïŒèµ€ãè²ä»ããããããŒã¹ã次ã«é£ã¹ãããšãã§ããïŒ ãŸãå¥åŠãªããšã«ïŒããããŒã¹ãé£ã¹ããšãã®ããŒã¹ã®äžäžå·Šå³ã«é£æ¥ããŠããŠãã€ãŸã é£ã¹ãããŠããªãããŒã¹ã®å³ãå€åããïŒ (çãããŒã¹ã¯èŸãïŒèŸãããŒã¹ã¯çããªã£ãŠããŸã) äžæããã§ã³ã¬ãŒããé£ã¹ããšæå€§ã§ããã€ã®çãããŒã¹ãé£ã¹ãããšãã§ããã ããã? å
¥ååœ¢åŒ å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ M N a_{11} ⊠a_{1N} a_{21} ⊠a_{2N} : a_{M1} ⊠a_{MN} a_{ij} = 0 ã®ãšãäžããiçªç®ïŒå·Šããjçªç®ã®ããŒã¹ãèŸãïŒ a_{ij} = 1 ã®ãšãäžããiçªç®ïŒå·Šããjçªç®ã®ããŒã¹ãçãããšã衚ãããŠããïŒ åºååœ¢åŒ é£ã¹ãããšã®ã§ããçãããŒã¹ã®åæ°ã®æå€§å€ãäžè¡ã«åºåããïŒ å¶çŽ 1 \leq NïŒM \leq 100 0 \leq a_{ij} \leq 1 å
¥åå€ã¯ãã¹ãп޿°ã§ããïŒ å
¥åºåäŸ å
¥åäŸ1 2 3 1 1 1 1 1 1 åºåäŸ1 5 å
¥åäŸ2 4 2 1 0 0 1 0 1 0 1 åºåäŸ2 8
| 38,328
|
Score : 200 points Problem Statement There are N bags of biscuits. The i -th bag contains A_i biscuits. Takaki will select some of these bags and eat all of the biscuits inside. Here, it is also possible to select all or none of the bags. He would like to select bags so that the total number of biscuits inside is congruent to P modulo 2 . How many such ways to select bags there are? Constraints 1 \leq N \leq 50 P = 0 or 1 1 \leq A_i \leq 100 Input Input is given from Standard Input in the following format: N P A_1 A_2 ... A_N Output Print the number of ways to select bags so that the total number of biscuits inside is congruent to P modulo 2 . Sample Input 1 2 0 1 3 Sample Output 1 2 There are two ways to select bags so that the total number of biscuits inside is congruent to 0 modulo 2 : Select neither bag. The total number of biscuits is 0 . Select both bags. The total number of biscuits is 4 . Sample Input 2 1 1 50 Sample Output 2 0 Sample Input 3 3 0 1 1 1 Sample Output 3 4 Two bags are distinguished even if they contain the same number of biscuits. Sample Input 4 45 1 17 55 85 55 74 20 90 67 40 70 39 89 91 50 16 24 14 43 24 66 25 9 89 71 41 16 53 13 61 15 85 72 62 67 42 26 36 66 4 87 59 91 4 25 26 Sample Output 4 17592186044416
| 38,329
|
Score : 700 points Problem Statement You are given an integer N . Determine if there exists a tree with 2N vertices numbered 1 to 2N satisfying the following condition, and show one such tree if the answer is yes. Assume that, for each integer i between 1 and N (inclusive), Vertex i and N+i have the weight i . Then, for each integer i between 1 and N , the bitwise XOR of the weights of the vertices on the path between Vertex i and N+i (including themselves) is i . Constraints N is an integer. 1 \leq N \leq 10^{5} Input Input is given from Standard Input in the following format: N Output If there exists a tree satisfying the condition in the statement, print Yes ; otherwise, print No . Then, if such a tree exists, print the 2N-1 edges of such a tree in the subsequent 2N-1 lines, in the following format: a_{1} b_{1} \vdots a_{2N-1} b_{2N-1} Here each pair ( a_i , b_i ) means that there is an edge connecting Vertex a_i and b_i . The edges may be printed in any order. Sample Input 1 3 Sample Output 1 Yes 1 2 2 3 3 4 4 5 5 6 The sample output represents the following graph: Sample Input 2 1 Sample Output 2 No There is no tree satisfying the condition.
| 38,330
|
Problem B: Turn Left Taro got a driverâs license with a great effort in his campus days, but unfortunately there had been no opportunities for him to drive. He ended up obtaining a gold license. One day, he and his friends made a plan to go on a trip to Kyoto with you. At the end of their meeting, they agreed to go around by car, but there was a big problem; none of his friends was able to drive a car. Thus he had no choice but to become the driver. The day of our departure has come. He is going to drive but would never turn to the right for fear of crossing an opposite lane (note that cars keep left in Japan). Furthermore, he cannot U-turn for the lack of his technique. The car is equipped with a car navigation system, but the system cannot search for a route without right turns. So he asked to you: âI hate right turns, so, could you write a program to find the shortest left-turn-only route to the destination, using the road map taken from this navigation system?â Input The input consists of multiple data sets. The first line of the input contains the number of data sets. Each data set is described in the format below: m n name 1 x 1 y 1 ... name m x m y m p 1 q 1 ... p n q n src dst m is the number of intersections. n is the number of roads. name i is the name of the i -th intersection. ( x i , y i ) are the integer coordinates of the i -th intersection, where the positive x goes to the east, and the positive y goes to the north. p j and q j are the intersection names that represent the endpoints of the j -th road. All roads are bidirectional and either vertical or horizontal. src and dst are the names of the source and destination intersections, respectively. You may assume all of the followings: 2 †m †1000, 0 †x i †10000, and 0 †y i †10000; each intersection name is a sequence of one or more alphabetical characters at most 25 character long; no intersections share the same coordinates; no pair of roads have common points other than their endpoints; no road has intersections in the middle; no pair of intersections has more than one road; Taro can start the car in any direction; and the source and destination intersections are different. Note that there may be a case that an intersection is connected to less than three roads in the input data; the rode map may not include smaller roads which are not appropriate for the non-local people. In such a case, you still have to consider them as intersections when you go them through. Output For each data set, print how many times at least Taro needs to pass intersections when he drive the route of the shortest distance without right turns. The source and destination intersections must be considered as âpassedâ (thus should be counted) when Taro starts from the source or arrives at the destination. Also note that there may be more than one shortest route possible. Print âimpossibleâ if there is no route to the destination without right turns. Sample Input 2 1 KarasumaKitaoji 0 6150 KarasumaNanajo 0 0 KarasumaNanajo KarasumaKitaoji KarasumaKitaoji KarasumaNanajo 3 2 KujoOmiya 0 0 KujoAburanokoji 400 0 OmiyaNanajo 0 1150 KujoOmiya KujoAburanokoji KujoOmiya OmiyaNanajo KujoAburanokoji OmiyaNanajo 10 12 KarasumaGojo 745 0 HorikawaShijo 0 870 ShijoKarasuma 745 870 ShijoKawaramachi 1645 870 HorikawaOike 0 1700 KarasumaOike 745 1700 KawaramachiOike 1645 1700 KawabataOike 1945 1700 KarasumaMarutamachi 745 2445 KawaramachiMarutamachi 1645 2445 KarasumaGojo ShijoKarasuma HorikawaShijo ShijoKarasuma ShijoKarasuma ShijoKawaramachi HorikawaShijo HorikawaOike ShijoKarasuma KarasumaOike ShijoKawaramachi KawaramachiOike HorikawaOike KarasumaOike KarasumaOike KawaramachiOike KawaramachiOike KawabataOike KarasumaOike KarasumaMarutamachi KawaramachiOike KawaramachiMarutamachi KarasumaMarutamachi KawaramachiMarutamachi KarasumaGojo KawabataOike 8 9 NishikojiNanajo 0 0 NishiojiNanajo 750 0 NishikojiGojo 0 800 NishiojiGojo 750 800 HorikawaGojo 2550 800 NishiojiShijo 750 1700 Enmachi 750 3250 HorikawaMarutamachi 2550 3250 NishikojiNanajo NishiojiNanajo NishikojiNanajo NishikojiGojo NishiojiNanajo NishiojiGojo NishikojiGojo NishiojiGojo NishiojiGojo HorikawaGojo NishiojiGojo NishiojiShijo HorikawaGojo HorikawaMarutamachi NishiojiShijo Enmachi Enmachi HorikawaMarutamachi HorikawaGojo NishiojiShijo 0 0 Output for the Sample Input 2 impossible 13 4
| 38,331
|
Score : 1400 points Problem Statement You are given P , a permutation of (1,\ 2,\ ...\ N) . A string S of length N consisting of 0 and 1 is a good string when it meets the following criterion: The sequences X and Y are constructed as follows: First, let X and Y be empty sequences. For each i=1,\ 2,\ ...\ N , in this order, append P_i to the end of X if S_i= 0 , and append it to the end of Y if S_i= 1 . If X and Y have the same number of high elements, S is a good string. Here, the i -th element of a sequence is called high when that element is the largest among the elements from the 1 -st to i -th element in the sequence. Determine if there exists a good string. If it exists, find the lexicographically smallest such string. Constraints 1 \leq N \leq 2 \times 10^5 1 \leq P_i \leq N P_1,\ P_2,\ ...\ P_N are all distinct. All values in input are integers. Input Input is given from Standard Input in the following format: N P_1 P_2 ... P_N Output If a good string does not exist, print -1 . If it exists, print the lexicographically smallest such string. Sample Input 1 6 3 1 4 6 2 5 Sample Output 1 001001 Let S= 001001 . Then, X=(3,\ 1,\ 6,\ 2) and Y=(4,\ 5) . The high elements in X is the first and third elements, and the high elements in Y is the first and second elements. As they have the same number of high elements, 001001 is a good string. There is no good string that is lexicographically smaller than this, so the answer is 001001 . Sample Input 2 5 1 2 3 4 5 Sample Output 2 -1 Sample Input 3 7 1 3 2 5 6 4 7 Sample Output 3 0001101 Sample Input 4 30 1 2 6 3 5 7 9 8 11 12 10 13 16 23 15 18 14 24 22 26 19 21 28 17 4 27 29 25 20 30 Sample Output 4 000000000001100101010010011101
| 38,332
|
Score : 200 points Problem Statement There are N cities and M roads. The i -th road (1â€iâ€M) connects two cities a_i and b_i (1â€a_i,b_iâ€N) bidirectionally. There may be more than one road that connects the same pair of two cities. For each city, how many roads are connected to the city? Constraints 2â€N,Mâ€50 1â€a_i,b_iâ€N a_i â b_i All input values are integers. Input Input is given from Standard Input in the following format: N M a_1 b_1 : a_M b_M Output Print the answer in N lines. In the i -th line (1â€iâ€N) , print the number of roads connected to city i . Sample Input 1 4 3 1 2 2 3 1 4 Sample Output 1 2 2 1 1 City 1 is connected to the 1 -st and 3 -rd roads. City 2 is connected to the 1 -st and 2 -nd roads. City 3 is connected to the 2 -nd road. City 4 is connected to the 3 -rd road. Sample Input 2 2 5 1 2 2 1 1 2 2 1 1 2 Sample Output 2 5 5 Sample Input 3 8 8 1 2 3 4 1 5 2 8 3 7 5 2 4 1 6 8 Sample Output 3 3 3 2 2 2 1 1 2
| 38,333
|
Score : 400 points Problem Statement We have N bricks arranged in a row from left to right. The i -th brick from the left (1 \leq i \leq N) has an integer a_i written on it. Among them, you can break at most N-1 bricks of your choice. Let us say there are K bricks remaining. Snuke will be satisfied if, for each integer i (1 \leq i \leq K) , the i -th of those brick from the left has the integer i written on it. Find the minimum number of bricks you need to break to satisfy Snuke's desire. If his desire is unsatisfiable, print -1 instead. Constraints All values in input are integers. 1 \leq N \leq 200000 1 \leq a_i \leq N Input Input is given from Standard Input in the following format: N a_1 a_2 ... a_N Output Print the minimum number of bricks that need to be broken to satisfy Snuke's desire, or print -1 if his desire is unsatisfiable. Sample Input 1 3 2 1 2 Sample Output 1 1 If we break the leftmost brick, the remaining bricks have integers 1 and 2 written on them from left to right, in which case Snuke will be satisfied. Sample Input 2 3 2 2 2 Sample Output 2 -1 In this case, there is no way to break some of the bricks to satisfy Snuke's desire. Sample Input 3 10 3 1 4 1 5 9 2 6 5 3 Sample Output 3 7 Sample Input 4 1 1 Sample Output 4 0 There may be no need to break the bricks at all.
| 38,334
|
Score : 600 points Problem Statement There are N dots in a two-dimensional plane. The coordinates of the i -th dot are (x_i, y_i) . We will repeat the following operation as long as possible: Choose four integers a , b , c , d (a \neq c, b \neq d) such that there are dots at exactly three of the positions (a, b) , (a, d) , (c, b) and (c, d) , and add a dot at the remaining position. We can prove that we can only do this operation a finite number of times. Find the maximum number of times we can do the operation. Constraints 1 \leq N \leq 10^5 1 \leq x_i, y_i \leq 10^5 If i \neq j , x_i \neq x_j or y_i \neq y_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 maximum number of times we can do the operation. Sample Input 1 3 1 1 5 1 5 5 Sample Output 1 1 By choosing a = 1 , b = 1 , c = 5 , d = 5 , we can add a dot at (1, 5) . We cannot do the operation any more, so the maximum number of operations is 1 . Sample Input 2 2 10 10 20 20 Sample Output 2 0 There are only two dots, so we cannot do the operation at all. Sample Input 3 9 1 1 2 1 3 1 4 1 5 1 1 2 1 3 1 4 1 5 Sample Output 3 16 We can do the operation for all choices of the form a = 1 , b = 1 , c = i , d = j (2 \leq i,j \leq 5) , and no more. Thus, the maximum number of operations is 16 .
| 38,335
|
Score : 200 points Problem Statement Akaki, a patissier, can make N kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1 , Doughnut 2 , ..., Doughnut N . In order to make one Doughnut i (1 †i †N) , she needs to consume m_i grams of Moto. She cannot make a non-integer number of doughnuts, such as 0.5 doughnuts. Now, she has X grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition: For each of the N kinds of doughnuts, make at least one doughnut of that kind. At most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto. Also, under the constraints of this problem, it is always possible to obey the condition. Constraints 2 †N †100 1 †m_i †1000 m_1 + m_2 + ... + m_N †X †10^5 All values in input are integers. Input Input is given from Standard Input in the following format: N X m_1 m_2 : m_N Output Print the maximum number of doughnuts that can be made under the condition. Sample Input 1 3 1000 120 100 140 Sample Output 1 9 She has 1000 grams of Moto and can make three kinds of doughnuts. If she makes one doughnut for each of the three kinds, she consumes 120 + 100 + 140 = 360 grams of Moto. From the 640 grams of Moto that remains here, she can make additional six Doughnuts 2 . This is how she can made a total of nine doughnuts, which is the maximum. Sample Input 2 4 360 90 90 90 90 Sample Output 2 4 Making one doughnut for each of the four kinds consumes all of her Moto. Sample Input 3 5 3000 150 130 150 130 110 Sample Output 3 26
| 38,336
|
Problem H: Hth Number Problem é·ã$N$ã®æåå$S$ãããã$S$ã«å«ãŸããæåã¯ãã¹ãŠ0以äž9以äžã®æ°åã§ããã $S$ã®ãã¹ãŠã®éšåæååããäœãããæ°ãå
šåæããŠã§ããé
æ°$\frac{N\times(N+1)}{2}$ã®æ°åãäœã£ãæã ãã®æ°åã®äžã§$H$çªç®ã«å°ããå€ãæ±ããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã $N$ $H$ $S$ å
¥åã¯ãã¹ãп޿°ã§äžããããã 1è¡ç®ã«$N$ãš$H$ã空çœåºåãã§äžããããã 2è¡ç®ã«é·ã$N$ã®æåå$S$ãäžããããã Constraints å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã $1 \leq N \leq 10^5$ $1 \leq H \leq \frac{N \times (N+1)}{2}$ $|S| = N$ $S$ã«å«ãŸããæåã¯ãã¹ãŠ0, 1, 2, 3, 4, 5, 6, 7, 8, 9ã®ããããã§ãã Output $H$çªç®ã®å€ã1è¡ã«åºåããã (åºåã®å
é ã«äœèšãª0ã¯å«ãã§ã¯ãªããªãã) Sample Input 1 2 3 00 Sample Output 1 0 Sample Input 2 4 9 0012 Sample Output 2 12 Sample Input 3 5 13 10031 Sample Output 3 100 Sample Input3ã®å Žåã10031ã®éšåæååããäœãããæ°ã¯ä»¥äžã®éãã§ããã 1, 0, 0, 3, 1 10, 00, 03, 31 100, 003, 031 1003, 0031 10031 ãããããå°ããé ã«äžŠã¹ããš 0, 0, 0, 1, 1, 3, 3, 3, 10, 31, 31, 31, 100, 1003, 10031 ã«ãªãã13çªç®ã«å°ããå€ã¯100ã§ããã
| 38,337
|
Score : 100 points Problem Statement You are given a grid of N rows and M columns. The square at the i -th row and j -th column will be denoted as (i,j) . Some of the squares contain an object. All the remaining squares are empty. The state of the grid is represented by strings S_1,S_2,\cdots,S_N . The square (i,j) contains an object if S_{i,j}= # and is empty if S_{i,j}= . . Consider placing 1 \times 2 tiles on the grid. Tiles can be placed vertically or horizontally to cover two adjacent empty squares. Tiles must not stick out of the grid, and no two different tiles may intersect. Tiles cannot occupy the square with an object. Calculate the maximum number of tiles that can be placed and any configulation that acheives the maximum. Constraints 1 \leq N \leq 100 1 \leq M \leq 100 S_i is a string with length M consists of # and . . Input Input is given from Standard Input in the following format: N M S_1 S_2 \vdots S_N Output On the first line, print the maximum number of tiles that can be placed. On the next N lines, print a configulation that achieves the maximum. Precisely, output the strings t_1,t_2,\cdots,t_N constructed by the following way. t_i is initialized to S_i . For each (i,j) , if there is a tile that occupies (i,j) and (i+1,j) , change t_{i,j} := v , t_{i+1,j} := ^ . For each (i,j) , if there is a tile that occupies (i,j) and (i,j+1) , change t_{i,j} := > , t_{i,j+1} := < . See samples for further information. You may print any configulation that maximizes the number of tiles. Sample Input 1 3 3 #.. ..# ... Sample Output 1 3 #>< vv# ^^. The following output is also treated as a correct answer. 3 #>< v.# ^><
| 38,338
|
Score : 100 points Problem Statement A biscuit making machine produces B biscuits at the following moments: A seconds, 2A seconds, 3A seconds and each subsequent multiple of A seconds after activation. Find the total number of biscuits produced within T + 0.5 seconds after activation. Constraints All values in input are integers. 1 \leq A, B, T \leq 20 Input Input is given from Standard Input in the following format: A B T Output Print the total number of biscuits produced within T + 0.5 seconds after activation. Sample Input 1 3 5 7 Sample Output 1 10 Five biscuits will be produced three seconds after activation. Another five biscuits will be produced six seconds after activation. Thus, a total of ten biscuits will be produced within 7.5 seconds after activation. Sample Input 2 3 2 9 Sample Output 2 6 Sample Input 3 20 20 19 Sample Output 3 0
| 38,339
|
Array Update 2 Problem é
æ° N ãåé
a ãå
¬å·® d ã®çå·®æ°å A ãããã 以äžã®åœ¢åŒã§ãæ°åãæžãæãã M åã®åœä»€æãäžããããã®ã§ãäžããããé åºã§ M å æ°å A ãæžãæãããšãã®æ°å A ã® K é
ç®ã®å€ãæ±ããªããã i çªç®ã®åœä»€æã¯3ã€ã®æŽæ° x i , y i , z i ã§äžããããã(1 †i †M ) x i ã0ã ã£ãå Žåã y i é
ç®ãã z i é
ç®ãŸã§ã®åºéã«ãããŠãå€ã®é åºãå転ããã x i ã1ã ã£ãå Žåã y i é
ç®ãã z i é
ç®ãŸã§ã®åºéã«ãããŠãããããã®å€ã1å¢å ãããã x i ã2ã ã£ãå Žåã y i é
ç®ãã z i é
ç®ãŸã§ã®åºéã«ãããŠãããããã®å€ãååã«ããïŒå°æ°ç¹ä»¥äžã¯åãæšãŠãïŒã Input N a d M x 1 y 1 z 1 x 2 y 2 z 2 ... x M y M z M K 1è¡ç®ã«ã1ã€ã®æŽæ° N ãäžããããã 2è¡ç®ã«ã2ã€ã®æŽæ° a ãš d ã空çœåºåãã§äžããããã 3è¡ç®ã«ã1ã€ã®æŽæ° M ãäžããããã 4è¡ç®ããã® M è¡ã®ãã¡ i è¡ç®ã«ã¯ i çªç®ã®åœä»€æã衚ã 3 ã€ã®æŽæ° x i , y i , z i ã空çœåºåãã§äžããããã æåŸã®è¡ã«ã1ã€ã®æŽæ° K ãäžããããã Constraints 2 †N †200000 1 †a †5 1 †d †5 1 †M †200000 0 †x i †2 (1 †i †M ) 1 †y i †N (1 †i †M ) 1 †z i †N (1 †i †M ) y i < z i (1 †i †M ) 1 †K †N Output å
¥åã§äžããããé çªã§æ°å A ã M åæŽæ°ãããšãã® K é
ç®ãåºåããã Sample Input 1 4 2 1 3 0 1 2 1 1 4 2 2 4 3 Sample Output 1 2 { 2 , 3 , 4 , 5 } â 0 1 2 ... 1é
ç®ãã2é
ç®ãŸã§ã®åºéã®å€ã®é åºãå転ãã { 3 , 2 , 4 , 5 } â 1 1 4 ... 1é
ç®ãã4é
ç®ãŸã§ã®åºéã®å€ããããã1å¢ãã { 4 , 3 , 5 , 6 } â 2 2 4 ... 2é
ç®ãã4é
ç®ãŸã§ã®åºéã®å€ãããããååã«ããïŒå°æ°ç¹ä»¥äžåãæšãŠãïŒ { 3 , 1 , 2 , 3 } ãã£ãŠ3é
ç®ã®å€ã¯2ã§ããã Sample Input 2 5 1 2 3 1 2 3 2 3 5 0 1 5 1 Sample Output 2 4 { 1 , 3 , 5 , 7 , 9 } â 1 2 3 ... 2é
ç®ãã3é
ç®ãŸã§ã®åºéã®å€ããããã1å¢ãã { 1 , 4 , 6 , 7 , 9 } â 2 3 5 ... 3é
ç®ãã5é
ç®ãŸã§ã®åºéã®å€ãããããååã«ããïŒå°æ°ç¹ä»¥äžåãæšãŠãïŒ { 1 , 4 , 3 , 3 , 4 } â 0 1 5 ... 1é
ç®ãã5é
ç®ãŸã§ã®åºéã®å€ã®é åºãå転ãã { 4 , 3 , 3 , 4 , 1 } ãã£ãŠ1é
ç®ã®å€ã¯4ã§ããã
| 38,340
|
å顿 å§å¡é·ã®é女 PATRICIA ã¯ïŒèèã®ãããªç³žãåãçµçã®äžã§æ®ãããŠããïŒäœ¿ãéã® MATHIEU ã¯ïŒå§å¡é·ã®é女ãåãã糞ãåŒã£ã±ãèªåšã«ç©ºãé£ãã§ããïŒç³žã¯ç©ºéäžã®ç·åãšã¿ãªãããšã«ããïŒ æçŸã»ãã ã¯å§å¡é·ã®é女ã«å¯ŸããŠæ»æã仿ããããšãïŒç匟ãšééããŠè±ç«çãæã蟌ãã§ããŸã£ãïŒãã®çµæïŒããããã®ç³žã«ã€ããŠïŒé女ããè·é¢ p_1, ..., p_M ã®äœçœ®ã«ããéšåãåããã ããšãªã£ãŠããŸã£ãïŒè±ç«çãæããåïŒããããã®ç³žã«ã€ããŠïŒç³žã® 2 ã€ã®ç«¯ç¹ãšé女ã¯ãã®é çªã§åäžçŽç·äžã«äžŠãã§ããïŒç«¯ç¹ã®ã©ã¡ããäžæ¹ã䜿ãéãåŒã£åŒµã£ãŠããïŒççºã§ç³žã¯åãïŒäœ¿ãéãæã£ãŠããéšåãšããããäžã€çœ®ãã®éšåãæ®ããŠç³žã®äžéšã¯æ¶ããŠããŸã£ãïŒ ã»ãã ã¯æ¬¡ã®æŠç¥ãèããããã«ïŒæ®ã£ã糞ã«ã€ããŠã®æ
å ±ãç¥ããããšæã£ãŠããïŒæ®ã£ã糞ã®é·ãã®åèšå€ãæ±ããïŒ å
¥ååœ¢åŒ å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ N\ M\\ s_1\ t_1\\ ...\\ s_N\ t_N\\ p_1\\ ...\\ p_M\\ N ã¯ç©ºéäžã®ç³žã®åæ°ïŒ M ã¯è±ç«çã«ãã£ãŠçºçãã糞ã®åæã®ç®æã®åæ°ã§ããïŒ s_i, t_i ã¯ç³žã®æ
å ±ã§ããïŒ s_i ã¯äœ¿ãéãåŒã£åŒµã£ãŠããåŽã®ç«¯ç¹ïŒ t_i ã¯ããã§ãªãåŽã®ç«¯ç¹ã®é女ããã®è·é¢ã§ããïŒ p_i ã¯è±ç«çã«ãã£ãŠåæãããäœçœ®ã®æ
å ±ã§ããïŒ åºååœ¢åŒ è±ç«çãæããåŸïŒæ®ã£ã糞ã®é·ãã®åèšå€ã1è¡ã«åºåããïŒ å¶çŽ 1 †N †10 5 1 †M †10 5 1 †s_i †10^9 1 †t_i †10^9 1 †p_i †10^9 å
¥åå€ã¯å
šãп޿°ã§ããïŒ s_1, ..., s_N, t_1, ..., t_N, p_1, ..., p_M ã¯å
šãŠçžç°ãªãïŒ å
¥åºåäŸ å
¥åäŸ 1 2 3 1 8 20 5 3 7 15 åºåäŸ1 10 ççºã®åŸïŒ 1 ã€ç®ã®ã²ãã¯ç«¯ç¹ã®é女ããã®è·é¢ããããã (1,3), (7,8) ã® 2 ã€ã®ã²ãã«ïŒ 2 ã€ç®ã®ã²ã㯠(20, 15), (7, 5) ã® 2 ã€ã®ã²ãã«åãããïŒçµæïŒæ®ã£ãã²ãã®é·ãã®åèšã¯ 2+1+5+2 = 10 ãšãªãïŒ å
¥åäŸ 2 1 1 100 1 70 åºåäŸ 2 30 å
¥åäŸ 3 6 8 1 10 11 23 99 2 56 58 66 78 88 49 5 15 25 35 45 55 65 75 åºåäŸ 3 99 Problem Setter: Flat35
| 38,342
|
AïŒæ²¢å±±ã®çš®é¡ã®ææª (Many Kinds of Apples) Problem Statement Apple Farmer Mon has two kinds of tasks: "harvest apples" and "ship apples". There are N different species of apples, and N distinguishable boxes. Apples are labeled by the species, and boxes are also labeled, from 1 to N . The i -th species of apples are stored in the i -th box. For each i , the i -th box can store at most c_i apples, and it is initially empty (no apple exists). Mon receives Q instructions from his boss Kukui, and Mon completely follows in order. Each instruction is either of two types below. "harvest apples": put d x -th apples into the x -th box. "ship apples": take d x -th apples out from the x -th box. However, not all instructions are possible to carry out. Now we call an instruction which meets either of following conditions "impossible instruction": When Mon harvest apples, the amount of apples exceeds the capacity of that box. When Mon tries to ship apples, there are not enough apples to ship. Your task is to detect the instruction which is impossible to carry out. Input Input is given in the following format. N c_1 c_2 $\cdots$ c_N Q t_1 x_1 d_1 t_2 x_2 d_2 $\vdots$ t_Q x_Q d_Q In line 1, you are given the integer N , which indicates the number of species of apples. In line 2, given c_i ( 1 \leq i \leq N ) separated by whitespaces. c_i indicates the capacity of the i -th box. In line 3, given Q , which indicates the number of instructions. Instructions are given successive Q lines. t_i x_i d_i means what kind of instruction, which apple Mon handles in this instruction, how many apples Mon handles, respectively. If t_i is equal to 1 , it means Mon does the task of "harvest apples", else if t_i is equal to 2 , it means Mon does the task of "ship apples". Constraints All input values are integers, and satisfy following constraints. 1 \leq N \leq 1,000 1 \leq c_i \leq 100,000 ( 1 \leq i \leq N ) 1 \leq Q \leq 100,000 t_i \in \{1, 2\} ( 1 \leq i \leq Q ) 1 \leq x_i \leq N ( 1 \leq i \leq Q ) 1 \leq d_i \leq 100,000 ( 1 \leq i \leq Q ) Output If there is "impossible instruction", output the index of the apples which have something to do with the first "impossible instruction". Otherwise, output 0 . Sample Input 1 2 3 3 4 1 1 2 1 2 3 2 1 3 2 2 3 Sample Output 1 1 In this case, there are not enough apples to ship in the first box. Sample Input 2 2 3 3 4 1 1 3 2 1 2 1 2 3 1 1 3 Sample Output 2 1 In this case, the amount of apples exceeds the capacity of the first box. Sample Input 3 3 3 4 5 4 1 1 3 1 2 3 1 3 5 2 2 2 Sample Output 3 0 Sample Input 4 6 28 56 99 3 125 37 10 1 1 10 1 1 14 1 3 90 1 5 10 2 3 38 2 1 5 1 3 92 1 6 18 2 5 9 2 1 4 Sample Output 4 3
| 38,343
|
Problem G: Sports Days äŒæŽ¥å€§åŠéå±å°åŠæ ¡ïŒäŒæŽ¥å€§å°ïŒã¯æ¥æ¬ææ°ã®ç«¶æããã°ã©ããŒé€ææ ¡ãšããŠæåã§ããã ãã¡ãããéåäŒã«åå ããŠãããšãã§ããã¢ã«ãŽãªãºã ã®ä¿®è¡ãæ¬ ãããªãã ç«¶æããã°ã©ãã³ã°éšéšé·ã®ããªãã¯ãã¡ãããã®å€§äŒã§ãåå©ãããã ä»åã¯ããç«¶æã«æ³šç®ããã ããç«¶æãšã¯äŒæŽ¥å€§å°ã§è¡ãããŠããäŒçµ±çãªç«¶æã ã æ ¡åºã«ã³ãŒã³ãnå眮ããŠããã ã³ãŒã³ã¯4è²çšæãããŠããã ã³ãŒã³ã®ããã€ãã®ãã¢ã¯çœç·ã§æãããç¢å°ã§çµã°ããŠããã ç¢å°ã¯çåŽã ãã«ã€ããŠãããæŽæ°ã䜵èšãããŠããã ç«¶æè
ã¯k人1ããŒã ãšããŠè¡åããã ããã¹ã¿ãŒãå°ç¹ã®ã³ãŒã³ãããŽãŒã«å°ç¹ã®ã³ãŒã³ãŸã§ç¢å°ã®äžããã®åãã«ç§»åããã ãã ããk人ããããããŽãŒã«å°ç¹ãŸã§ã®çµè·¯ã¯ç°ãªãå¿
èŠãããã çµè·¯1ãšçµè·¯2ãç°ãªããšããã®ã¯ã æ¡ä»¶1 çµè·¯1ãšçµè·¯2ã§çµç±ããç¢å°ã®æ¬æ°ãçããå Žåãçµè·¯1ã§içªç®ã«çµç±ããç¢å°ãšçµè·¯2ã§içªç®ã«çµç±ããç¢å°ãç°ãªããããªiãååšããããšã æ¡ä»¶2 çµè·¯1ãšçµè·¯2ã§çµç±ããç¢å°ã®æ¬æ°ãç°ãªã£ãŠããããšã ã®ãããããæºããã°çµè·¯ãç°ãªã£ãŠãããšèšããã ããã«ãã³ãŒã³ã®èŸ¿ãæ¹ã«ã¯çŠæ¢ãããè²ã®ãã¿ãŒã³ããããã¹ã¿ãŒãå°ç¹ãããŽãŒã«å°ç¹ãŸã§ã®çµè·¯ã§ãã®ãã¿ãŒã³ãå«ãã§ããŸã£ãéžæã¯ãªã¿ã€ã¢ãšãªãã ãã ãããã以å€ã®çµè·¯ã¯ã©ã®ãããªçµè·¯ã蟿ã£ãŠããããäœåºŠãåãã³ãŒã³ïŒã¹ã¿ãŒãå°ç¹ããŽãŒã«å°ç¹ã®ã³ãŒã³ãå«ãïŒãéã£ãŠè¯ãã ãŸããç¢å°ã«äœµèšãããæ°åãã¹ã³ã¢ãšããŠå ç®ãããŠããã ãã®ç«¶æã¯ããå€ãã®ããŒã ã¡ã€ããããå°ããªåèšã¹ã³ã¢ã§ãŽãŒã«å°ç¹ã®ã³ãŒã³ã«èŸ¿ãã€ããããŒã ãåå©ãšãªãã éšé·ã®ããªãã¯ãã¡ããããã°ã©ãã³ã°ã§ãã®åé¡ã解決ã§ããã¯ãã ã ãŽãŒã«ãŸã§ç§»åå¯èœãªæå€§ã®äººæ°ãæ±ããã ãŸããæå€§äººæ°ã§èŸ¿ãçããæã®æå°ã¹ã³ã¢ãæ±ããã ãã ãããããã§ãã¹ã³ã¢ãå°ããåºæ¥ãå Žå㯠-1 ãåºåããã Input å
¥åã¯è€æ°ã®ãã¹ãã±ãŒã¹ããæãç«ã£ãŠããã ãã¹ãã±ãŒã¹ã®æ°ã¯20ã±ãŒã¹ãè¶
ããªãã n col 1 col 2 ... col n m a 1 b 1 c 1 a 2 b 2 c 2 ... a m b m c m k pattern n( 2 †n †100)ã¯ã³ãŒã³ã®æ°ã衚ãã col i (1 †col i †4)ã¯içªç®ã®ã³ãŒã³ã®è²ã瀺ãã m(0 †m †1,000) ã¯ç¢å°ã®æ°ã衚ãã a i ã¯ç¢å°ã®å§ç¹ã®ã³ãŒã³ã®çªå·, b i ã¯çµç¹ã®ã³ãŒã³ã®çªå·ã衚ããc i ã¯ãã®ç¢å°ã®ã¹ã³ã¢ã衚ã. ãŸããã²ãšã€ã®ã³ãŒã³ãã䌞ã³ãç¢å°ã¯10æ¬ãŸã§ã§ããã (1 †a i , b i †n, -1,000 †c i †1,000) kã¯ç«¶æãè¡ãããŒã ã®äººæ°ã瀺ãã (1 †k †10) pattern ã¯é·ãã10以äžã®1~4ãŸã§ã®æ°åãããªãæååã§ã ç§»åãçŠæ¢ãããŠãããã¿ãŒã³ã瀺ãã ã¹ã¿ãŒãå°ç¹ã®ã³ãŒã³ã¯1çªç®ã®ã³ãŒã³ã§ããã nçªç®ã®ã³ãŒã³ããŽãŒã«ã§ããã å
¥åã§äžããããæ°(n, col, m, a, b, c, k)ã¯ãã¹ãп޿°ã§ããã å
¥åã®çµããã¯0ãå«ã1è¡ã§ç€ºãããã Output åºåã¯ç©ºçœã§åºåãããäºã€ã®æŽæ°ãããªãã 1ã€ç®ã¯å°éã§ãã人æ°ã§ã2ã€ç®ã¯ãã®æå°ã³ã¹ãã§ããã ããããããã§ãã¹ã³ã¢ãå°ããåºæ¥ãå Žåã¯-1ã®ã¿ãå«ãïŒè¡ãåºåããã äžäººãå°éã§ããªãå Žåã¯0 0ãåºåããã Sample Input 2 1 1 2 1 2 1 2 1 1 1 1111 2 1 1 2 1 2 1 2 1 1 1 11 2 1 1 2 1 2 1 2 1 1 10 1111 2 1 1 2 1 2 1 2 1 1 10 111111 2 1 1 2 1 2 -1 2 1 0 10 11 2 1 1 2 1 2 -1 2 1 0 10 1111 2 1 1 2 1 2 -1 2 1 0 10 12 2 1 1 2 1 2 -1 2 1 0 10 1111111111 0 Sample Output 1 1 0 0 1 1 2 4 0 0 1 -1 -1 4 -10
| 38,344
|
Score : 700 points Problem Statement We have a rooted binary tree with N vertices, where the vertices are numbered 1 to N . Vertex 1 is the root, and the parent of Vertex i ( i \geq 2 ) is Vertex \left[ \frac{i}{2} \right] . Each vertex has one item in it. The item in Vertex i has a value of V_i and a weight of W_i . Now, process the following query Q times: Given are a vertex v of the tree and a positive integer L . Let us choose some (possibly none) of the items in v and the ancestors of v so that their total weight is at most L . Find the maximum possible total value of the chosen items. Here, Vertex u is said to be an ancestor of Vertex v when u is an indirect parent of v , that is, there exists a sequence of vertices w_1,w_2,\ldots,w_k ( k\geq 2 ) where w_1=v , w_k=u , and w_{i+1} is the parent of w_i for each i . Constraints All values in input are integers. 1 \leq N < 2^{18} 1 \leq Q \leq 10^5 1 \leq V_i \leq 10^5 1 \leq W_i \leq 10^5 For the values v and L given in each query, 1 \leq v \leq N and 1 \leq L \leq 10^5 . Input Let v_i and L_i be the values v and L given in the i -th query. Then, Input is given from Standard Input in the following format: N V_1 W_1 : V_N W_N Q v_1 L_1 : v_Q L_Q Output For each integer i from 1 through Q , the i -th line should contain the response to the i -th query. Sample Input 1 3 1 2 2 3 3 4 3 1 1 2 5 3 5 Sample Output 1 0 3 3 In the first query, we are given only one choice: the item with (V, W)=(1,2) . Since L = 1 , we cannot actually choose it, so our response should be 0 . In the second query, we are given two choices: the items with (V, W)=(1,2) and (V, W)=(2,3) . Since L = 5 , we can choose both of them, so our response should be 3 . Sample Input 2 15 123 119 129 120 132 112 126 109 118 103 115 109 102 100 130 120 105 105 132 115 104 102 107 107 127 116 121 104 121 115 8 8 234 9 244 10 226 11 227 12 240 13 237 14 206 15 227 Sample Output 2 256 255 250 247 255 259 223 253
| 38,345
|
ãã¶ãã¬ãã€ãã Aåããã®å®¶ã«èŠªæã®Bç·åããã£ãŠããŸããã圌ã¯3æ³ã§æã倧奜ãã§ãã圌ã¯å¹Œçšåã§ãªãã£ãããã¶ãã¬ãã€ããã(å±±æ¬çŽçŽäœè©ã»äœæ²)ãšããæãäžçæžåœã«æã£ãŠããŸãããã®æã§ã¯ã4ã€ã®ããšã°ããã¶ãã ããã¬ãã ããã€ãããããããé ã«ãããšãã«ãªã£ãŠããŠãããã«æåŸã®é³ãšæåã®é³ãåãã«ãªã£ãŠããŸããBç·åã¯ãAåããã«ãåããããªãããšãããBç·åãèšã£ãåèªããäœãããæããŠæ¬²ãããšèšãããŸããã ããã§ãAåãããå©ããããã«ãäžããããåèªããããã®åèªããã¹ãŠäœ¿ã£ãŠãé ã«ãããšããã€ããããã®äžã§ã 第1 ã®åèªã®æåã®æåãšæçµã®åèªã®æåŸã®æåãåãã§ããããã«ã§ãããåŠããå€å®ããããã°ã©ã ãäœæããŸãããã n åã®åèªãå
¥åãšãããããã®åèªã®çµãããããšããäœæã§ãããåŠããå€å®ããå¯èœãªå Žåã¯OK ãšãäžå¯èœãªå Žå㯠NG ãšåºåããããã°ã©ã ãäœæããŠãã ããã Input è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸãã åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã n word 1 word 2 : word n 1 è¡ç®ã«åèªã®åæ° n (2 †n †10000) ãäžããããŸããç¶ã n è¡ã« n åã®åèª word i (32 æå以äžã®åè§è±å°æåã ããããªãæåå) ãäžããããŸãã ããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã Output å
¥åããŒã¿ã»ããããšã«ãå€å®çµæãïŒè¡ã«åºåããŸãã Sample Input 5 apple yellow georgia king email 7 apple yellow georgia king email wink lucky 0 Output for the Sample Input NG OK
| 38,346
|
G: äžçªé ãçº å顿 $N$ åã®çºãš $N-1$ åã®éããããŸãã ãã¹ãŠã®çºãšéã«ã¯ãããã $1$ ãã $N$, $1$ ãã $N-1$ ã®çªå·ãã€ããŠããŸãã é $i$ ã¯çº $a_i$ ãšçº $b_i$ ãè·é¢ $d_i$ ã§åæ¹åã«ã€ãªãã§ããŸãã æåã¯ãã¹ãŠã®éãéè¡å¯èœãªç¶æ
ã§ãããã©ã®çºãããããã€ãã®éãéãããšã§ãã¹ãŠã®çºã«è¡ãããšãã§ããŸãã ããã°ãããã¯æåãçº $1$ ã«ããŸãã $Q$ åã®ã¯ãšãªãäžããããã®ã§é çªã«åŠçããŠãã ãããã¯ãšãªã¯ $3$ çš®é¡ããã以äžã®åœ¢åŒã§äžããããŸãã ã¯ãšãª $1$ : 1 x â ããã°ããããçº $x$ ã«ç§»åããããã ãããã®ã¯ãšãªæç¹ã§ãããã°ããããããçºãšçº $x$ ã¯éè¡å¯èœãª $1$ ã€ã®éã§çŽæ¥ã€ãªãããŠããããšãä¿èšŒãããã ã¯ãšãª $2$ : 2 y â é $y$ ãå°éãããããã ãããã®ã¯ãšãªæç¹ã§ãé $y$ ã¯éè¡å¯èœã§ããããšãä¿èšŒãããã ã¯ãšãª $3$ : 3 z â é $z$ ãéè¡å¯èœã«ãªãããã ãããã®ã¯ãšãªæç¹ã§ãé $z$ ã¯å°éãããŠããããšãä¿èšŒãããã ããã«ãåã¯ãšãªãè¡ã£ãçŽåŸã«ãããã°ãããããã®æç¹ã§éè¡å¯èœãªéã®ã¿ã䜿ã£ãŠå°éå¯èœãªçºã®ãã¡ãããã°ããããããçºããäžçªé ãçºã®çªå·ãæé ã§ãã¹ãŠåºåããŠãã ããã å¶çŽ $1 \leq N \leq 2 \times 10^5$ $1 \leq a_i, b_i \leq N$, $a_i \neq b_i$ $1 \leq d_i \leq 10^6$ $1 \leq Q \leq 2 \times 10^5$ ã¯ãšãª $1$ ã«ãããŠã$1 \leq x \leq N$ ãæºããããŸãããã®ã¯ãšãªæç¹ã§ãããã°ããããããçºãšçº $x$ ã¯éè¡å¯èœãª $1$ ã€ã®éã§çŽæ¥ã€ãªãããŠããã ã¯ãšãª $2$ ã«ãããŠã$1 \leq y \leq N-1$ ãæºããããŸãããã®ã¯ãšãªæç¹ã§ãé $y$ ã¯éè¡å¯èœã§ããã ã¯ãšãª $3$ ã«ãããŠã$1 \leq z \leq N-1$ ãæºããããŸãããã®ã¯ãšãªæç¹ã§ãé $z$ ã¯å°éãããŠããã $i$ çªç®ã®ã¯ãšãªã§åºåãã¹ãçºã®åæ°ã $c_i$ ãšãããšãã$\sum_{i=1}^{Q}c_i \leq 4 \times 10^5$ ãæºããã å
¥åã¯ãã¹ãп޿°ã§ããã å
¥å 以äžã®åœ¢åŒã§æšæºå
¥åããäžããããã $N$ $a_1$ $b_1$ $d_1$ $a_2$ $b_2$ $d_2$ $:$ $a_{N-1}$ $b_{N-1}$ $d_{N-1}$ $Q$ $Query_1$ $Query_2$ $:$ $Query_Q$ $Query_i$ ã¯å顿ã«ãã $3$ çš®é¡ã®ã¯ãšãªã®ããããã®åœ¢åŒã§äžããããã åºå $Q$ è¡åºåããã $i$ è¡ç®ã«ã¯ã$i$ çªç®ã¯ãšãªåŸã®åºåãã¹ãçºã®çªå·ãæé ã§ $v_1$, $v_2$, $...$, $v_c$ ã® $c$ åã§ãããšãã以äžã®ããã«ç©ºçœåºåãã§åºåããã $c$ $v_1$ $v_2$ $...$ $v_c$ å
¥åäŸ 1 6 2 4 1 1 2 1 4 6 1 2 3 1 4 5 1 5 2 5 2 3 1 2 3 5 1 4 åºåäŸ 1 1 6 2 3 4 3 1 3 4 1 5 2 1 3 $1$ ã€ç®ã®ã¯ãšãªã§ãé $5$ ãå°éãããŸãããã®çŽåŸã«ãããã°ããããå°éå¯èœãªçºã¯ $1$, $2$, $3$, $4$, $6$ ã§ãããããã°ããããããçº $1$ ããã®è·é¢ã¯ãããã $0$, $1$, $2$, $2$, $3$ ãªã®ã§ãçãã¯çº $6$ ã«ãªããŸãã $2$ ã€ç®ã®ã¯ãšãªã§ãé $3$ ãå°éãããŸãããã®çŽåŸã«ãããã°ããããå°éå¯èœãªçºã¯ $1$, $2$, $3$, $4$ ã§ãããããã°ããããããçº $1$ ããã®è·é¢ã¯ãããã $0$, $1$, $2$, $2$ ãªã®ã§ãçãã¯çº $3$, $4$ ã«ãªããŸãã $3$ ã€ç®ã®ã¯ãšãªã§ãããã°ãããã¯çº $2$ ã«ç§»åããŸãããã®çŽåŸã«ãããã°ããããå°éå¯èœãªçºã¯ $1$, $2$, $3$, $4$ ã§ãããããã°ããããããçº $2$ ããã®è·é¢ã¯ãããã $1$, $0$, $1$, $1$ ãªã®ã§ãçãã¯çº $1$, $3$, $4$ ã«ãªããŸãã $4$ ã€ç®ã®ã¯ãšãªã§ãé $5$ ãéè¡å¯èœã«ãªããŸãããã®çŽåŸã«ãããã°ããããå°éå¯èœãªçºã¯ $1$, $2$, $3$, $4$, $5$ ã§ãããããã°ããããããçº $2$ ããã®è·é¢ã¯ãããã $1$, $0$, $1$, $1$, $2$ ãªã®ã§ãçãã¯çº $5$ ã«ãªããŸãã $5$ ã€ç®ã®ã¯ãšãªã§ãããã°ãããã¯çº $4$ ã«ç§»åããŸãããã®çŽåŸã«ãããã°ããããå°éå¯èœãªçºã¯ $1$, $2$, $3$, $4$, $5$ ã§ãããããã°ããããããçº $4$ ããã®è·é¢ã¯ãããã $2$, $1$, $2$, $0$, $1$ ãªã®ã§ãçãã¯çº $1$, $3$ ã«ãªããŸãã å
¥åäŸ 2 5 3 4 1 2 1 1 4 5 1 3 2 1 6 2 2 3 2 1 2 1 3 2 4 1 4 åºåäŸ 2 1 1 1 5 1 5 2 1 5 1 5 2 3 5
| 38,347
|
Problem E: Enclose Points There are $N$ points and $M$ segments on the $xy$-plane. Each segment connects two of these points and they don't intersect each other except at the endpoints. You are also given $Q$ points as queries. Your task is to determine for each query point whether you can make a polygon that encloses the query point using some of the given segments. Note that the polygon should not necessarily be convex. Input Each input is formatted as follows. $N$ $M$ $Q$ $x_1$ $y_1$ ... $x_N$ $y_N$ $a_1$ $b_1$ ... $a_M$ $b_M$ $qx_1$ $qy_1$ ... $qx_Q$ $qy_Q$ The first line contains three integers $N$ ($2 \leq N \leq 100,000$), $M$ ($1 \leq M \leq 100,000$), and $Q$ ($1 \leq Q \leq 100,000$), which represent the number of points, the number of segments, and the number of queries, respectively. Each of the following $N$ lines contains two integers $x_i$ and $y_i$ ($-100,000 \leq x_i, y_i \leq 100,000$), the coordinates of the $i$-th point. The points are guaranteed to be distinct, that is, $(x_i, y_i) \ne (x_j, y_j)$ when $i \ne j$. Each of the following $M$ lines contains two integers $a_i$ and $b_i$ ($1 \leq a_i < b_i \leq N$), which indicate that the $i$-th segment connects the $a_i$-th point and the $b_i$-th point. Assume that those segments do not intersect each other except at the endpoints. Each of the following $Q$ lines contains two integers $qx_i$ and $qy_i$ ($-100,000 \leq qx_i, qy_i \leq 100,000$), the coordinates of the $i$-th query point. You can assume that, for any pair of query point and segment, the distance between them is at least $10^{-4}$. Output The output should contain $Q$ lines. Print "Yes" on the $i$-th line if there is a polygon that contains the $i$-th query point. Otherwise print "No" on the $i$-th line. Sample Input 4 5 3 -10 -10 10 -10 10 10 -10 10 1 2 1 3 1 4 2 3 3 4 -20 0 1 0 20 0 Output for the Sample Input No Yes No Sample Input 8 8 5 -20 -20 20 -20 20 20 -20 20 -10 -10 10 -10 10 10 -10 10 1 2 1 4 2 3 3 4 5 6 5 8 6 7 7 8 -25 0 -15 0 0 0 15 0 25 0 Output for the Sample Input No Yes Yes Yes No Sample Input 8 8 5 -20 -10 -10 -10 -10 10 -20 10 10 -10 20 -10 20 10 10 10 1 2 2 3 3 4 1 4 5 6 6 7 7 8 5 8 -30 0 -15 0 0 0 15 0 30 0 Output for the Sample Input No Yes No Yes No
| 38,348
|
Problem C: Cut the Cake Today is the birthday of Mr. Bon Vivant, who is known as one of the greatest pâtissiers in the world. Those who are invited to his birthday party are gourmets from around the world. They are eager to see and eat his extremely creative cakes. Now a large box-shaped cake is being carried into the party. It is not beautifully decorated and looks rather simple, but it must be delicious beyond anyone's imagination. Let us cut it into pieces with a knife and serve them to the guests attending the party. The cake looks rectangular, viewing from above (Figure C-1). As exemplified in Figure C-2, the cake will iteratively be cut into pieces, where on each cut exactly a single piece is cut into two smaller pieces. Each cut surface must be orthogonal to the bottom face and must be orthogonal or parallel to a side face. So, every piece shall be rectangular looking from above and every side face vertical. Figure C-1: The top view of the cake Figure C-2: Cutting the cake into pieces Piece sizes in Figure C-2 vary significantly and it may look unfair, but you don't have to worry. Those guests who would like to eat as many sorts of cakes as possible often prefer smaller pieces. Of course, some prefer larger ones. Your mission of this problem is to write a computer program that simulates the cutting process of the cake and reports the size of each piece. Input The input is a sequence of datasets, each of which is of the following format. n w d p 1 s 1 ... p n s n The first line starts with an integer n that is between 0 and 100 inclusive. It is the number of cuts to be performed. The following w and d in the same line are integers between 1 and 100 inclusive. They denote the width and depth of the cake, respectively. Assume in the sequel that the cake is placed so that w and d are the lengths in the east-west and north-south directions, respectively. Each of the following n lines specifies a single cut, cutting one and only one piece into two. p i is an integer between 1 and i inclusive and is the identification number of the piece that is the target of the i -th cut. Note that, just before the i -th cut, there exist exactly i pieces. Each piece in this stage has a unique identification number that is one of 1, 2, ..., i and is defined as follows: The earlier a piece was born, the smaller its identification number is. Of the two pieces born at a time by the same cut, the piece with the smaller area (looking from above) has the smaller identification number. If their areas are the same, you may define as you like the order between them, since your choice in this case has no influence on the final answer. Note that identification numbers are adjusted after each cut. s i is an integer between 1 and 1000 inclusive and specifies the starting point of the i -th cut. From the northwest corner of the piece whose identification number is p i , you can reach the starting point by traveling s i in the clockwise direction around the piece. You may assume that the starting point determined in this way cannot be any one of the four corners of the piece. The i -th cut surface is orthogonal to the side face on which the starting point exists. The end of the input is indicated by a line with three zeros. Output For each dataset, print in a line the areas looking from above of all the pieces that exist upon completion of the n cuts specified in the dataset. They should be in ascending order and separated by a space. When multiple pieces have the same area, print it as many times as the number of the pieces. Sample Input 3 5 6 1 18 2 19 1 2 3 4 1 1 1 2 1 3 1 0 2 5 0 0 0 Output for the Sample Input 4 4 6 16 1 1 1 1 10
| 38,349
|
Swapping Characters You are given a string and a number k . You are suggested to generate new strings by swapping any adjacent pair of characters in the string up to k times. Write a program to report the lexicographically smallest string among them. Input The input is given in the following format. s k The first line provides a string s . The second line provides the maximum number of swapping operations k (0 †k †10 9 ). The string consists solely of lower-case alphabetical letters and has a length between 1 and 2 à 10 5 . Output Output the lexicographically smallest string. Sample Input 1 pckoshien 3 Sample Output 1 ckopshien Sample Input 2 pckoshien 10 Sample Output 2 cekophsin
| 38,350
|
NINJA GAME æ°äœã²ãŒã "NIN JA G AME" ãã€ãã«çºå£²ãšãªã£ãïŒãã®ã²ãŒã ã§ã¯ãã¬ã€ã€ãŒã¯äºæ¬¡å
ãããäžã®å¿è
ãæäœããŠç§»åãè¡ãïŒäºæ¬¡å
ããã㯠x 軞ïŒãŸã㯠y 軞ã®ã©ã¡ããäžæ¹ã«å¹³è¡ãªèŸºã®ã¿ãããªãïŒèªå·±äº€å·®ã®ãªãå€è§åœ¢ã§è¡šãããïŒããŸïŒå€è§åœ¢ã®å
éšã«ååšããã¹ã¿ãŒãå°ç¹ãããŽãŒã«å°ç¹ãžãšç§»åããå¿
èŠãããïŒ ç§»åã¯äžäžå·Šå³ãšæã45°ã®8æ¹åãå¯èœã§ïŒããããã®å¯Ÿå¿ããã³ãã³ããå
¥åãããšïŒæå®ããæ¹åã«èªåã§é²ã¿ç¶ããïŒãã®èªåç§»åã®æäžã®ä»»æã®ã¿ã€ãã³ã°ã§å¥ã®ã³ãã³ããå
¥åããå ŽåïŒå³åº§ã«ç§»åæ¹åã®è»¢æãå¯èœã§ããïŒããªãã®ç®æšã¯ïŒãã®ã²ãŒã ã§ã®å®çžŸãè§£é€ããããïŒæå°ã®ã³ãã³ãå
¥ååæ°ã§ã¹ã¿ãŒãå°ç¹ãããŽãŒã«å°ç¹ã«ç§»åããããšã§ããïŒ ããã§æ°ãä»ããå¿
èŠãããã®ã¯ïŒãã£ã©ãå¿è
ã§ããã®ã§ïŒå£äŒãã®ç§»åãå¯èœã§ãããšããããšã ïŒããã§å£äŒãã®ç§»åãããšã¯ïŒå€è§åœ¢ã®èŸºäžãç§»åããããšã§ããïŒãã ãïŒãã¡ããå€è§åœ¢ã®å€éšã«åºãããšã¯ã§ããªãïŒå£äŒãã®ç§»åäžã«ãã®å£ã«å¯ŸãåçŽæ¹åã«ç§»åããããšããå Žåã¯ãã以äžç§»åã§ããã«æ¢ãŸãã®ã ãïŒäžæ¹ã§å£äŒãã®ç§»åäžã«æãæ¹åã«ç§»åããããšããå ŽåïŒå£ãšå¹³è¡ãªæ¹åãžã®å£äŒãã®èªåç§»åãç¶ãïŒå£ããªããªã£ããšããã§å
ã®æãæ¹åã«ãŸãèªåç§»åãç¶ããïŒäŸãã°äžå³ã®ããã« y 軞ã«å¹³è¡ãªå£ã« x è»žæ£æ¹åãš y è»žè² æ¹åãããªãæãæ¹åããã¶ã€ãã£ãå ŽåïŒã¶ã€ãã£ãåŸã¯å£ã«æ²¿ã£ãŠ y è»žè² æ¹åã«é²ã¿ïŒå£ããªããªã£ããšããã§ãŸã x è»žæ£æ¹åãš y è»žè² æ¹åãããªãæãæ¹åãžãšé²ã¿å§ããïŒ ããã§ïŒæãæ¹åã«ç§»åããªããè§ã«ã¶ã€ãã£ããšãã®æåã¯ä»¥äžã®ããã«ãªãïŒ(a) ã®ããã«äž¡æ¹åã«å£ãå²ãŸããŠããå Žåã¯ããã§æ¢ãŸãïŒæ¹å転æãããªããã°åããªãïŒ(b) ã (c) ã®ããã«è§ãéãéããŠãã®ãŸãŸé²ããå Žåã¯ïŒæãæ¹åã«èªåç§»åãç¶ããïŒ(d) ã®ããã«äž¡æ¹åã«é²ããå ŽåïŒå¥œããªæ¹åãéžãã§é²ãããã®ãšããŠããïŒå³ã§ã¯ç§»åã衚ãç¢å°ã§å£ãé ããããå°ãå
éšåŽã«å¯ããŠå³ç€ºããŠãããïŒãããå®éã«ã¯èŸºäžãç§»åããããšã衚ãå³ã§ããïŒ ãŸãïŒäžäžå·Šå³æ¹åã®ç§»åäžã«è§ã«ã¶ã€ãã£ããšãã®æåã¯ä»¥äžã®ããã«ãªãïŒ(e), (f), (g) ã®ãããªå Žåã¯ãã®ãŸãŸã®æ¹åã«èªåç§»åãç¶ããïŒ(h) ã®ããã«å£ã«åçŽã«ã¶ã€ãã£ãå Žåã¯ããã§æ¢ãŸãïŒæ¹å転æãããªããã°åããªãïŒãã ãïŒåæ§ã«ç§»åã衚ãç¢å°ãå£ããå°ãå
éšåŽã«å¯ããŠãããïŒå®éã«ã¯èŸºäžãç§»åããããšã衚ãå³ã§ããïŒ äžèšã®ç§»åã«é¢ããæåã«åŸã£ãäžã§ïŒã¹ã¿ãŒãå°ç¹ãããŽãŒã«å°ç¹ã«å°éããããã«å
¥åããå¿
èŠãããã³ãã³ãã®æ°ã®æå°å€ãæ±ããããã°ã©ã ãäœæããŠã»ããïŒäŸãã°äžå³ã«ãããæå°ã®ã³ãã³ãå
¥ååæ°ã¯ïŒå³äžã«ç€ºãããã«2ã§ããïŒããã¯3ã€ç®ã®ãµã³ãã«å
¥åã«å¯Ÿå¿ããŠããïŒ Input å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒ ããŒã¿ã»ããã®æ°ã¯æå€§ã§ 100 ã§ããïŒ åããŒã¿ã»ããã¯ïŒæ¬¡ã®åœ¢åŒã§è¡šãããïŒ N sx sy gx gy x 1 y 1 ... x N y N ããŒã¿ã»ããã® 1 è¡ç®ã¯ãããã衚ãå€è§åœ¢ã®é ç¹æ°ã衚ã1ã€ã®æŽæ° N ( 4 †N †100 ) ãããªãïŒ2è¡ç®ã¯4ã€ã®æŽæ° sx , sy , gx , gy ( -10,000 †sx, sy, gx, gy †10,000 ) ãããªãïŒã¹ã¿ãŒãå°ç¹ã®åº§æšã (sx, sy) ïŒãŽãŒã«å°ç¹ã®åº§æšã (gx, gy) ã§ããããšã衚ããŠããïŒç¶ã N è¡ã§ã¯å€è§åœ¢ã®åé ç¹ãåæèšåãé ã«äžããããïŒãã®ãã¡ i è¡ç®ã¯2ã€ã®æŽæ° x i , y i ( -10,000 †x i , y i †10,000 ) ãããªãïŒ i çªç®ã®é ç¹ã®åº§æšã (x i , y i ) ã§ããããšã衚ãïŒããã§ïŒäžããããã¹ã¿ãŒãå°ç¹ïŒãŽãŒã«å°ç¹ïŒå€è§åœ¢ã¯ä»¥äžã®å¶çŽãæºããïŒ å
šãŠã®èŸºã¯ x 軞ã y 軞ã®ããããäžæ¹ã«å¯ŸããŠå¹³è¡ã§ããïŒ äžããããå€è§åœ¢ã¯èªå·±äº€å·®ãæããªãïŒããªãã¡ïŒå蟺ã¯ç«¯ç¹ä»¥å€ã§ä»ã®èŸºãšäº€å·®ããïŒç°ãªã i, j ã«ã€ã㊠(x i , y i ) â (x j , y j ) ã§ããïŒ (sx, sy) ãš (gx, gy) ã¯ãšãã«ãã®å€è§åœ¢ã®å
éš (蟺äžãå«ãŸãªã) ã«ããããšãä¿èšŒãããïŒ ã¹ã¿ãŒããšãŽãŒã«ã¯ç°ãªãïŒããªãã¡ (sx, sy) â (gx, gy) ã§ããããšãä¿èšŒãããïŒ å
¥åã®çµãã㯠1 ã€ã®ãŒããããªãè¡ã§è¡šãããïŒ Output åããŒã¿ã»ããã«å¯ŸãïŒã¹ã¿ãŒãå°ç¹ãããŽãŒã«å°ç¹ã«èŸ¿ãçãããã«å¿
èŠãªæå°ã®ã³ãã³ãå
¥åã®åæ°ã 1 è¡ã§åºåããïŒ Sample Input 8 1 1 2 2 0 2 0 0 2 0 2 1 3 1 3 3 1 3 1 2 12 -9 5 9 -9 0 0 0 -13 3 -13 3 -10 10 -10 10 10 -1 10 -1 13 -4 13 -4 10 -10 10 -10 0 12 3 57 53 2 0 0 64 0 64 18 47 18 47 39 64 39 64 60 0 60 0 44 33 44 33 30 0 30 0 Output for the Sample Input 1 1 2 1ã€ç®ã®å
¥åã¯äžå³ (1)ïŒ2ã€ç®ã®å
¥åã¯äžå³ (2) ã«å¯Ÿå¿ããïŒ
| 38,351
|
Cube Surface Puzzle Given a set of six pieces, âCube Surface Puzzleâ is to construct a hollow cube with filled surface. Pieces of a puzzle is made of a number of small unit cubes laid grid-aligned on a plane. For a puzzle constructing a cube of its side length n , unit cubes are on either of the following two areas. Core (blue): A square area with its side length n â2. Unit cubes fill up this area. Fringe (red): The area of width 1 unit forming the outer fringe of the core. Each unit square in this area may be empty or with a unit cube on it. Each piece is connected with faces of its unit cubes. Pieces can be arbitrarily rotated and either side of the pieces can be inside or outside of the constructed cube. The unit cubes on the core area should come in the centers of the faces of the constructed cube. Consider that we have six pieces in Fig. E-1 (The first dataset of Sample Input). Then, we can construct a cube as shown in Fig. E-2. Fig. E-1 Pieces from the first dataset of Sample Input Fig. E-2 Constructing a cube Mr. Hadrian Hex has collected a number of cube surface puzzles. One day, those pieces were mixed together and he cannot find yet from which six pieces he can construct a cube. Your task is to write a program to help Mr. Hex, which judges whether we can construct a cube for a given set of pieces. Input The input consists of at most 200 datasets, each in the following format. n x 1,1 x 1,2 ⊠x 1, n x 2,1 x 2,2 ⊠x 2, n ⊠x 6 n ,1 x 6 n ,2 ⊠x 6 n , n The first line contains an integer n denoting the length of one side of the cube to be constructed (3 †n †9, n is odd). The following 6 n lines give the six pieces. Each piece is described in n lines. Each of the lines corresponds to one grid row and each of the characters in the line, either âXâ or â.â, indicates whether or not a unit cube is on the corresponding unit square: âXâ means a unit cube is on the column and â.â means none is there. The core area of each piece is centered in the data for the piece. The end of the input is indicated by a line containing a zero. Output For each dataset, output â Yes â if we can construct a cube, or â No â if we cannot. Sample Input 5 ..XX. .XXX. XXXXX XXXXX X.... ....X XXXXX .XXX. .XXX. ..... ..XXX XXXX. .XXXX .XXXX ...X. ...X. .XXXX XXXX. XXXX. .X.X. XXX.X .XXXX XXXXX .XXXX .XXXX XX... .XXXX XXXXX XXXXX XX... 5 ..XX. .XXX. XXXXX XXXX. X.... ....X XXXXX .XXX. .XXX. ..... .XXXX XXXX. .XXXX .XXXX ...X. ...X. .XXXX XXXX. XXXX. .X.X. XXX.X .XXXX XXXXX .XXXX .XXXX XX... XXXXX XXXXX .XXXX XX... 0 Output for the Sample Input Yes No
| 38,352
|
Problem A: Adhoc Translation One day, during daily web surfing, you encountered a web page which was written in a language you've never seen. The character set of the language was the same as your native language; moreover, the grammar and words seemed almost the same. Excitedly, you started to "decipher" the web page. The first approach you tried was to guess the meaning of each word by selecting a similar word from a dictionary of your native language. The closer two words (although from the different languages) are, the more similar meaning they will have. You decided to adopt edit distance for the measurement of similarity between two words. The edit distance between two character sequences is defined as the minimum number of insertions, deletions and substitutions required to morph one sequence into the other. For example, the pair of "point" and "spoon" has the edit distance of 3: the latter can be obtained from the former by deleting 't', substituting 'i' to 'o', and finally inserting 's' at the beginning. You wanted to assign a word in your language to each word in the web text so that the entire assignment has the minimum edit distance. The edit distance of an assignment is calculated as the total sum of edit distances between each word in the text and its counterpart in your language. Words appearing more than once in the text should be counted by the number of appearances. The translation must be consistent across the entire text; you may not match different words from your dictionary for different occurrences of any word in the text. Similarly, different words in the text should not have the same meaning in your language. Suppose the web page says "qwerty asdf zxcv" and your dictionary contains the words "qwert", "asf", "tyui", "zxcvb" and "ghjk". In this case, you can match the words in the page as follows, and the edit distance of this translation is 3: "qwert" for "qwerty", "asf" for "asdf" and "zxcvb" for "zxcv". Write a program to calculate the minimum possible edit distance among all translations, for given a web page text and a word set in the dictionary. Input The first line of the input contains two integers N and M . The following N lines represent the text from the web page you've found. This text contains only lowercase alphabets and white spaces. Then M lines, each containing a word, describe the dictionary to use. Every word consists of lowercase alphabets only, and does not contain more than 20 characters. It is guaranteed that 1 †N †100 and 1 †M †400. Also it is guaranteed that the dictionary is made up of many enough words, which means the number of words in the dictionary is no less than the kinds of words in the text to translate. The length of each line in the text does not exceed 1000. Output Output the minimum possible edit distance in a line. Sample Input 1 1 5 qwerty asdf zxcv qwert asf tyui zxcvb ghjk Output for the Sample Input 1 3
| 38,353
|
A : Soccer / ãµãã«ãŒ å顿 AåœãšBåœã®éã§AIãµãã«ãŒã®è©Šåããããããªãã®æå
ã«ã¯ãããæå»ã«ããŒã«ãæã£ãŠããéžæãšãã®äœçœ®ãèšé²ãã衚ãããã衚㯠N è¡ãããªããäžãã i çªç®ã®è¡ã¯æ¬¡ã«ç€ºãèŠçŽ ãããªãã ãã¬ãŒã æ° f_i ããŒã«ãæã£ãŠããéžæã®èçªå· a_i ãã®éžæãå±ããããŒã t_i ãã®éžæã®äœçœ®ã衚ãåº§æš x_i , y_i ãã¬ãŒã æ°ãšã¯ãã²ãŒã ã®éå§æå»ã« 0 ã«èšå®ããã 1 / 60 ç§ããšã« 1 å ç®ãããæŽæ°ã®ããšã§ãããäŸãã°ãã²ãŒã éå§ããã¡ããã© 1.5 ç§åŸã®ãã¬ãŒã æ°ã¯ 90 ã§ããã èçªå·ã¯åããŒã å
ã® 11 人ã®éžæã«äžæã«ãµãããæŽæ°ã§ãããããã«ã衚äžã®é£ç¶ãã 2 ã€ã®èšé²ã«ãããŠãåãããŒã ã®ç°ãªãèçªå·ã®éžæãããŒã«ãæã£ãŠãããšãããã®éã«ããã¹ããè¡ããããšãããèšé²ã«ååšããªããã¬ãŒã ã¯èæ
®ããªããŠããã ããŠããšã³ãžãã¢ã§ããããªãã®ä»äºã¯ãåããŒã ã®éžæéã§è¡ããããã¹ã®ãã¡ã æãè·é¢(ãŠãŒã¯ãªããè·é¢)ãé·ããã®ã®è·é¢ãšãããã«ããã£ãæéãæ±ããããšã§ããã è·é¢ãæé·ãšãªããã¹ãè€æ°ããå Žåã¯ãããã£ãæéãæãçããã®ãåºåããã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã t_i=0 ã®ãšãAåœã t_i=1 ã®ãšãBåœã衚ãã N f_0 a_0 t_0 x_0 y_0 ⊠f_{Nâ1} a_{Nâ1} t_{Nâ1} x_{Nâ1} y_{Nâ1} å¶çŽ å
¥åã¯ãã¹ãп޿°ã§ãã 1 \†N \†100 0 \†f_i \lt f_{i+1} \†324\,000 1 \†a_i \†11 t_i = 0,1 0 \†x_i \†120 0 \†y_i \†90 åºå Aåœã®æé·ã®ãã¹ã«ããã£ãè·é¢ãšæéãBåœã®æé·ã®ãã¹ã«ããã£ãè·é¢ãšæéãããããã1è¡ã«åºåãããæéã¯ç§åäœãšããè·é¢ãæéãšãã« 10^{â3} 以äžã®çµ¶å¯Ÿèª€å·®ã¯èš±ãããããã¹ãäžåºŠãè¡ãããªãã£ãå Žåã¯ãšãã« â1 ãšåºåããã ãµã³ãã« ãµã³ãã«å
¥å1 5 0 1 0 3 4 30 1 0 3 4 90 2 0 6 8 120 1 1 1 1 132 2 1 2 2 ãµã³ãã«åºå1 5.00000000 1.00000000 1.41421356 0.20000000 Aåœã¯é·ã 5 ã®ãã¹ã 30 ãã¬ãŒã ã®æå»ã« 60 ãã¬ãŒã =1 ç§ã§ããBåœã¯é·ã â2 ã®ãã¹ã 120 ãã¬ãŒã ã®æå»ã« 12 ãã¬ãŒã =0.2 ç§ã§ãããããããããããã®æé·ã®ãã¹ã§ããã ãµã³ãã«å
¥å2 2 0 1 0 0 0 10 1 1 0 0 ãµã³ãã«åºå2 -1 -1 -1 -1 ãµã³ãã«å
¥å3 3 0 1 0 0 0 30 2 0 1 1 40 1 0 2 2 ãµã³ãã«åºå3 1.4142135624 0.1666666667 -1 -1 ãµã³ãã«å
¥å4 3 0 1 0 0 0 10 2 0 1 1 40 1 0 3 3 ãµã³ãã«åºå4 2.8284271247 0.5000000000 -1 -1
| 38,354
|
Score : 300 points Problem Statement Takahashi has come to an integer shop to buy an integer. The shop sells the integers from 1 through 10^9 . The integer N is sold for A \times N + B \times d(N) yen (the currency of Japan), where d(N) is the number of digits in the decimal notation of N . Find the largest integer that Takahashi can buy when he has X yen. If no integer can be bought, print 0 . Constraints All values in input are integers. 1 \leq A \leq 10^9 1 \leq B \leq 10^9 1 \leq X \leq 10^{18} Input Input is given from Standard Input in the following format: A B X Output Print the greatest integer that Takahashi can buy. If no integer can be bought, print 0 . Sample Input 1 10 7 100 Sample Output 1 9 The integer 9 is sold for 10 \times 9 + 7 \times 1 = 97 yen, and this is the greatest integer that can be bought. Some of the other integers are sold for the following prices: 10: 10 \times 10 + 7 \times 2 = 114 yen 100: 10 \times 100 + 7 \times 3 = 1021 yen 12345: 10 \times 12345 + 7 \times 5 = 123485 yen Sample Input 2 2 1 100000000000 Sample Output 2 1000000000 He can buy the largest integer that is sold. Note that input may not fit into a 32 -bit integer type. Sample Input 3 1000000000 1000000000 100 Sample Output 3 0 Sample Input 4 1234 56789 314159265 Sample Output 4 254309
| 38,355
|
Problem A: Cubist Artwork International Center for Picassonian Cubism is a Spanish national museum of cubist artworks, dedicated to Pablo Picasso. The center held a competition for an artwork that will be displayed in front of the facade of the museum building. The artwork is a collection of cubes that are piled up on the ground and is intended to amuse visitors, who will be curious how the shape of the collection of cubes changes when it is seen from the front and the sides. The artwork is a collection of cubes with edges of one foot long and is built on a flat ground that is divided into a grid of one foot by one foot squares. Due to some technical reasons, cubes of the artwork must be either put on the ground, fitting into a unit square in the grid, or put on another cube in the way that the bottom face of the upper cube exactly meets the top face of the lower cube. No other way of putting cubes is possible. You are a member of the judging committee responsible for selecting one out of a plenty of artwork proposals submitted to the competition. The decision is made primarily based on artistic quality but the cost for installing the artwork is another important factor. Your task is to investigate the installation cost for each proposal. The cost is proportional to the number of cubes, so you have to figure out the minimum number of cubes needed for installation. Each design proposal of an artwork consists of the front view and the side view (the view seen from the right-hand side), as shown in Figure 1. Figure 1: An example of an artwork proposal The front view (resp., the side view) indicates the maximum heights of piles of cubes for each column line (resp., row line) of the grid. There are several ways to install this proposal of artwork, such as the following figures. In these figures, the dotted lines on the ground indicate the grid lines. The left figure makes use of 16 cubes, which is not optimal. That is, the artwork can be installed with a fewer number of cubes. Actually, the right one is optimal and only uses 13 cubes. Note that, a single pile of height three in the right figure plays the roles of two such piles in the left one. Notice that swapping columns of cubes does not change the side view. Similarly, swapping rows does not change the front view. Thus, such swaps do not change the costs of building the artworks. For example, consider the artwork proposal given in Figure 2. Figure 2: Another example of artwork proposal An optimal installation of this proposal of artwork can be achieved with 13 cubes, as shown in the following figure, which can be obtained by exchanging the rightmost two columns of the optimal installation of the artwork of Figure 1. Input The input is a sequence of datasets. The end of the input is indicated by a line containing two zeros separated by a space. Each dataset is formatted as follows. w d h 1 h 2 ... h w h' 1 h' 2 ... h' d The integers w and d separated by a space are the numbers of columns and rows of the grid, respectively. You may assume 1 †w †10 and 1 †d †10. The integers separated by a space in the second and third lines specify the shape of the artwork. The integers h i (1 †h i †20, 1 †i †w ) in the second line give the front view, i.e., the maximum heights of cubes per each column line, ordered from left to right (seen from the front). The integers h i (1 †h i †20, 1 †i †d ) in the third line give the side view, i.e., the maximum heights of cubes per each row line, ordered from left to right (seen from the right-hand side). Output For each dataset, output a line containing the minimum number of cubes. The output should not contain any other extra characters. You can assume that, for each dataset, there is at least one way to install the artwork. Sample Input 5 5 1 2 3 4 5 1 2 3 4 5 5 5 2 5 4 1 3 4 1 5 3 2 5 5 1 2 3 4 5 3 3 3 4 5 3 3 7 7 7 7 7 7 3 3 4 4 4 4 3 4 4 3 4 2 2 4 4 2 1 4 4 2 8 8 8 2 3 8 3 10 10 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 10 9 20 1 20 20 20 20 20 18 20 20 20 20 20 20 7 20 20 20 20 0 0 Output for the Sample Input 15 15 21 21 15 13 32 90 186
| 38,356
|
Problem D: THE BYDOLM@STER Description THE BYDOLM@STER(ãã€ãã«ãã¹ã¿ãŒ)ãšã¯1rem瀟ãã2010/4/1ã«EXIDNAã§çºå£²ãäºå®ãããŠããè²æã·ãã¥ã¬ãŒã·ã§ã³ã²ãŒã ã§ãããäžå¿æã£ãŠãããã仿åãã«ãããã¯ãŒã¯æ¥ç¶ãµãŒãã¹ã忢ããæã¢ãŒã±ãŒãã²ãŒã ãšã¯ãã¶ãé¢ä¿ãç¡ãã ãã®ã²ãŒã ã¯ãã€ãã«ãã¡ãããããã¥ãŒã¹ãããŠããã(ç·šé)ã®ã¡ã³ããŒãéžæããã¡ã³ããŒãã¡ãšã®ã¬ãã¹ã³ãã³ãã¥ãã±ãŒã·ã§ã³ãéããŠã圌女(圌)ãããã€ãã«ã®é ç¹ãããããã€ãã«ã«è²ãŠäžããã²ãŒã ã§ããã åãã€ãã«ã«ã¯èœåå€ãšããŠããŒã«ã«ããã³ã¹ãã«ãã¯ã¹ã®3ã€ã®ãã©ã¡ãŒã¿ãæã¡ããŠãããã®èœåå€ã¯ãŠãããã«å±ããŠããå
šãŠã®ãã€ãã«ã®ãã©ã¡ãŒã¿ã®åèšå€ãšãªãããŠãããã®3ã€ã®èœåå€ã®ãã¡æå€§ã®ç©ããŠãããã®ã©ã³ã¯ãšãªãã ãŠãããã«äººæ°å¶éã¯ç¡ããã¡ã³ããŒã®äººæ°ã1äœã§ãã3äœã§ãã100äœã§ããŠããããšããŠæŽ»åã§ããããã¡ããåããã€ãã«ãè€æ°éãããšåºæ¥ããããã€ãã«ãéãããã«ã¯è²»çšããããã®ã§ãããèæ
®ã«å
¥ããªããã°ãªããªãã ãããã¥ãŒãµãŒã§ããããªãã¯æé«ã®ãŠããããäœãããã«ããã°ã©ã ãæžããŠèšç®ããããšã«ããã Input å
¥åã¯è€æ°ã®ãã¹ãã±ãŒã¹ãããªãã åãã¹ãã±ãŒã¹ã®1è¡ç®ã«ã¯ãã€ãã«ã®æ°Nãšäœ¿çšå¯èœãªè²»çšMãäžããããã(1<=N,M<=300) 次ã®2*Nè¡ã«ã¯åãã€ãã«ã«é¢ããŠã®æ
å ±ãæžãããŠããã ãã€ãã«ã®æ
å ±ã®1è¡ç®ã«ã¯ãã€ãã«ã®ååããã€ãã«ã®ååã¯ã¢ã«ãã¡ããããšç©ºçœããæãã30æåã以äžã§ããããŸãåäžåã®ãã€ãã«ã¯ååšããªãã 2è¡ç®ã«ã¯æŽæ°CãVãDãLãäžãããããCã¯ãã®ãã€ãã«ã1äœéçšããã³ã¹ããVã¯ããŒã«ã«ãDã¯ãã³ã¹ãLã¯ã«ãã¯ã¹ã®èœåå€ã衚ãã(1<=C,V,D,L<=300) å
¥åã¯EOFã§çµããã Output äžããããè²»çšã®äžã§äœãããŠãããã®ã©ã³ã¯ã®æå€§å€ãçããã ãŠããããäœããªãå Žåã¯0ãåºåããã Sample Input 3 10 Dobkeradops 7 5 23 10 PataPata 1 1 2 1 dop 5 3 11 14 2 300 Bydo System Alpha 7 11 4 7 Green Inferno 300 300 300 300 Output for Sample Input 29 462
| 38,357
|
ïŒéœåžéã®è·é¢ å°çäžã®2 éœåžã®åç·¯ãšæ±çµãå
¥åãšããå°è¡šè·é¢ãèšç®ããŠåºåããããã°ã©ã ãäœæããŠãã ããããã ããå°çã¯ååŸ 6,378.1 km ã®çãšãã2 ç¹éã®å°è¡šè·é¢ãšã¯ãã®çé¢ã«æ²¿ã£ãæçè·é¢ã§ãããŸããååçã§ãåç·¯ã¯çšããã«åç·¯ 0 ~ -90 床ãçšããã°ãªãããžååç·ã®è¥¿ã§ã西çµã¯çšããã«æ±çµ 180 ~ 360 床ãçšããããšãšããŸããå°è¡šè·é¢ã¯ km åäœã§æ±ããå°æ°ç¹ä»¥äžã¯åæšäºå
¥ããæŽæ°å€ãšããŠåºåããŠãã ããã 以äžã«äž»èŠéœåžã®åç·¯ãæ±çµã®äŸã瀺ããŸãã å°å åç·¯(床) æ±çµ(床) æ±äº¬ 35.68 139.77 ã·ã³ã¬ããŒã« 1.37 103.92 ã·ãã㌠-33.95 151.18 ã·ã«ãŽ 41.78 272.25 ããšãã¹ã¢ã€ã¬ã¹ -34.58 301.52 ãã³ãã³ 51.15 359.82 Input è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯-1 åã€ã®è¡ã§ç€ºãããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã a b c d 1 è¡ã«ç¬¬ 1 ã®éœåžã®åç·¯ a ã第 1 ã®éœåžã®æ±çµ b ã第 2 ã®éœåžã®åç·¯ c ã第 2 ã®éœåžã®æ±çµ d ã空çœåºåãã§äžããããŸããå
¥åã¯ãã¹ãŠå®æ°ã§äžããããŸãã ããŒã¿ã»ããã®æ°ã¯ 30 ãè¶
ããŸããã Output ããŒã¿ã»ããæ¯ã« 2 éœåžã®å°è¡šè·é¢ãïŒè¡ã«åºåããŸãã Sample Input 35.68 139.77 51.15 359.82 1.37 103.92 41.78 272.25 51.15 359.82 -34.58 301.52 -1 -1 -1 -1 Output for the Sample Input 9609 15092 11112
| 38,358
|
IOI åè»ã§è¡ãã(Take the 'IOI' train) IOI åœã§ã¯ãã®ãã³æ°ãã«ééãæ·èšããïŒIOI åœã®ééãèµ°ãåè»ã¯ããã€ãã®è»äž¡ãé£çµããããã®ã§ããïŒè»äž¡ã«ã¯ I , O ã® 2 çš®é¡ãããïŒè»äž¡ã¯ããããç°ãªãçš®é¡ã®è»äž¡ãšããé£çµã§ããªãïŒãŸãïŒåè»ã«é転åžãèšããé¢ä¿äžïŒåè»ã®äž¡ç«¯ã®è»äž¡ã¯çš®é¡ I ã§ãªããã°ãªããªãïŒåè»ã¯è»äž¡ã®çš®é¡ã衚ãæåãé ã«ã€ãªããæååã§è¡šããïŒåè»ã®é·ãã¯ãã®æååã®é·ãã§ãããšããïŒããšãã°ïŒ IOIOI ã®é ã«è»äž¡ãé£çµãããšé·ã 5 ã®åè»ãç·šæã§ãïŒãŸãè»äž¡ I ã¯åç¬ã§é·ã 1 ã®åè»ã§ããïŒè»äž¡ã OIOI ã IOOI ãšãã£ãé ã«äžŠã¹ãŠãåè»ãç·šæããããšã¯ã§ããªãïŒ ããã€ãã®è»äž¡ã 2 ã€ã®è»åº«ã«æ ŒçŽãããŠããïŒããããã®è»åº«ã®äžã«ã¯è»äž¡ãäžåã«äžŠãã§ããïŒåè»ãç·šæãããšãã¯è»åº«ããè»äž¡ãåºããŠããŠè»åº«åã§é£çµããŠããïŒè»åº«ããåºããè»äž¡ã¯æãè»åº«ã®å
¥ãå£ã«è¿ãè»äž¡ã®ã¿ã§ãããïŒã©ã¡ãã®è»åº«ããè»äž¡ãåºããã®é çªã«ã€ããŠã¯èªç±ã§ããïŒ åè»ãç·šæããåã«ïŒè»äž¡ã奜ããªã ãè»åº«ããåºããŠå¥ã®åŸ
æ©çšã¬ãŒã«ã«ç§»ãããšãã§ããïŒäžåºŠåŸ
æ©çšã¬ãŒã«ã«ç§»ããè»äž¡ã¯ä»åŸåè»ãç·šæããããã«äœ¿ãããšã¯ã§ããªãïŒãŸãïŒäžåºŠåè»ã®ç·šæãå§ãããšãã®ç·šæãçµãããŸã§ã®éã¯è»äž¡ãè»åº«ããåŸ
æ©çšã¬ãŒã«ã«ç§»ãããšã¯ã§ããªãïŒ åè»ãç·šæãããšãïŒè»åº«å
ã®å
šãŠã®è»äž¡ã䜿ãåãå¿
èŠã¯ãªãïŒããªãã¡ïŒåè»ã®ç·šæãçµããåŸïŒè»åº«å
ã«äœ¿ãããªãã£ãè»äž¡ãæ®ã£ãŠããŠãæ§ããªãïŒ IOI åœã§ã¯ééã«ä¹ã人ããšãŠããããããããšèããããŠããã®ã§ïŒã§ããã ãé·ãåè»ãç·šæãããïŒ å³: åè»ãç·šæããŠããéäžã§ããïŒãã®ãšãè»åº«ã«ããè»äž¡ãåŸ
æ©çšã¬ãŒã«ã«ç§»ãããšã¯ã§ããªãïŒãã®å³ã¯å
¥åºåäŸ1 ã«å¯Ÿå¿ããŠããïŒ èª²é¡ è»åº«ã«æ ŒçŽãããè»äž¡ã®æ
å ±ãäžãããããšãïŒç·šæã§ããåè»ã®é·ãã®æå€§å€ãæ±ããããã°ã©ã ãäœæããïŒããããã®è»åº«ã«æ ŒçŽãããè»äž¡ã®å㯠2 çš®é¡ã®æå I , O ã®ã¿ãããªãæååã§è¡šããïŒ 2 ã€ã®è»åº«ã®æ
å ±ã¯ããããé·ã M ã®æåå S ããã³é·ã N ã®æåå T ãšããŠäžããããïŒåæåã 1 ã€ã®è»äž¡ã衚ãïŒãã®æåã¯è»äž¡ã®çš®é¡ãšåãã§ããïŒæååã®1 æåç®ã¯æãè»åº«ã®å
¥ãå£ã«è¿ãè»äž¡ã衚ãïŒæ«å°Ÿã®æåãè»åº«ã®æã奥ã«ããè»äž¡ã衚ãïŒ å¶é 1 †M †2000 æåå S ã®é·ã 1 †N †2000 æåå T ã®é·ã å
¥å æšæºå
¥åãã以äžã®ããŒã¿ãèªã¿èŸŒãïŒ 1 è¡ç®ã«ã¯ M , N ã空çœåºåãã§æžãããŠããïŒ 2 è¡ç®ã«ã¯æåå S ãæžãããŠããïŒ 3 è¡ç®ã«ã¯æåå T ãæžãããŠããïŒ åºå æšæºåºåã«ïŒç·šæã§ããåè»ã®é·ãã®æå€§å€ãè¡šãæŽæ°ã 1 è¡ã§åºåããïŒ åè»ã 1 ã€ãç·šæã§ããªãå Žåã¯ïŒ 0 ãåºåããïŒ å
¥åºåäŸ å
¥åäŸ 1 5 5 OIOOI OOIOI åºåäŸ 1 7 S ã«ãã£ãŠè¡šãããè»åº«ãè»åº« S ãšãïŒ T ã«ãã£ãŠè¡šãããè»åº«ãè»åº« T ãšãããïŒãã®ãšãïŒããšãã°è»åº« S ããæåã®1 è»äž¡ïŒè»åº« T ããæåã® 2 è»äž¡ãåºããŠåŸ
æ©ãããåŸïŒè»åº« SïŒè»åº« SïŒè»åº« TïŒè»åº« SïŒè»åº« SïŒè»åº« TïŒè»åº« T ã®é çªã«è»äž¡ãåºãã°ïŒé·ã7 ã®åè» IOIOIOI ãç·šæã§ããïŒ ä»ã«ãïŒè»åº« S ããæåã® 1 è»äž¡ïŒè»åº« T ããæåã® 2 è»äž¡ãåºããŠåŸ
æ©ãããåŸïŒè»åº« TïŒè»åº« TïŒè»åº« SïŒè»åº« SïŒè»åº« TïŒè»åº« SïŒè»åº« S ã®é çªã«è»äž¡ãåºãããšã§ãé·ã 7 ã®åè»ãç·šæã§ããïŒããããé·ãåè»ãç·šæããããšã¯ã§ããªãã®ã§ 7 ãåºåããïŒ å
¥åäŸ 2 5 9 IIIII IIIIIIIII åºåäŸ 2 1 1 ã€ã®è»äž¡ã®ã¿ãããªãåè» I ãåè»ãšããŠã®æ¡ä»¶ãæºããããšã«æ³šæããïŒ å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
| 38,359
|
ãã©ã¹ãã£ãã¯æ¿ æ©æ¢°ã«èŸºã»å¯Ÿè§ç·ã®é·ãã®ããŒã¿ãå
¥åãããã©ã¹ãã£ãã¯æ¿ã®åæããããŠããå·¥å ŽããããŸãããã®å·¥å Žã§ã¯ããµã€ãºã¯æ§ã
ã§ãããå¹³è¡å蟺圢ã®åã®ã¿ãåãåºããŠããŸããããªãã¯ãåãåºãããå¹³è¡å蟺圢ã®ãã¡ãé·æ¹åœ¢ãšã²ã圢ã®è£œé åæ°ãæ°ããããã«äžåžããåœããããŸããã ãæ©æ¢°ã«å
¥åããããŒã¿ããèªã¿èŸŒãã§ãé·æ¹åœ¢ãšã²ã圢ã®è£œé åæ°ãåºåããããã°ã©ã ãäœæããŠãã ããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã a 1 , b 1 , c 1 a 2 , b 2 , c 2 : æ©æ¢°ã«å
¥åããããŒã¿ãè€æ°è¡ã«äžããããŸãã i è¡ç®ã« i çªç®ã®å¹³è¡å蟺圢ã®é£ãåãïŒèŸºã®é·ããè¡šãæŽæ° a i , b i ãšå¯Ÿè§ç·ã®é·ããè¡šãæŽæ° c i ãã«ã³ãåºåãã§äžããããŸã (1 †a i , b i , c i †1000, a i + b i > c i )ãããŒã¿ã®æ°ã¯ 100 ä»¶ãè¶
ããŸããã Output ïŒè¡ç®ã«é·æ¹åœ¢ã®è£œé åæ°ãïŒè¡ç®ã²ã圢ã®è£œé åæ°ãåºåããŸãã Sample Input 3,4,5 5,5,8 4,4,4 5,4,3 Output for the Sample Input 1 2
| 38,360
|
ãã¶ åé¡ JOI ãã¶ã§ã¯,åžã®äžå¿éšãéãå
šé· d ã¡ãŒãã«ã®ç°ç¶ç·ã®æ²¿ç·äžã§ãã¶ã®å®
é
販 売ãè¡ã£ãŠãã. JOI ãã¶ã¯,ç°ç¶ç·äžã« n åã®åºè S 1 , ... , S n ãæã€.æ¬åºã¯ S 1 ã§ãã. S 1 ãã S i ãŸã§,æèšåãã«ç°ç¶ç·ãç§»åãããšãã®éã®ãã d i ã¡ãŒãã«ãšãã. d 2 , ... , d n 㯠1 ä»¥äž d - 1 以äžã®æŽæ°ã§ãã. d 2 , ... , d n ã¯å
šãŠç°ãªã. ãã¶ã®æ³šæãåãããš, ãã¶ãå·ããªãããã«, å®
é
å
ãŸã§ã®ç§»åè·é¢ããã£ãšãçãåºèã§ãã¶ãçŒãå®
é
ãã. å®
é
å
ã®äœçœ®ã¯ 0 ä»¥äž d - 1 以äžã®æŽæ° k ã§è¡šããã.ããã¯, æ¬åº S 1 ããå®
é
å
ãŸã§ã«æèšåãã§ç°ç¶ç·ãç§»åãããšãã®éã®ãã k ã¡ãŒãã«ã§ããããšãæå³ãã. ãã¶ã®å®
é
ã¯ç°ç¶ç·ã«æ²¿ã£ãŠè¡ãã, ãã以å€ã®éãéãããšã¯èš±ãããªã. ãã ã, ç°ç¶ç·äžã¯æèšåãã«ç§»åããŠãåæèšåãã«ç§»åããŠããã. äŸãã°,åºèã®äœçœ®ãšå®
é
å
ã®äœçœ®ãäžå³ã®ããã«ãªã£ãŠããå Žå (ãã®äŸã¯ãå
¥åºåã®äŸãã®äŸ 1 ãšå¯Ÿå¿ããŠãã), å®
é
å
1 ã«ãã£ãšãè¿ãåºè㯠S 2 ãªã®ã§, åºè S 2 ããå®
é
ãã.ãã®ãšã, åºèããã®ç§»åè·é¢ã¯ 1 ã§ãã.ãŸã, å®
é
å
2 ã«ãã£ãšãè¿ãåºè㯠S 1 (æ¬åº) ãªã®ã§, åºè S 1 (æ¬åº) ããå®
é
ãã.ãã®ãšã,åºèããã®ç§»åè·é¢ã¯ 2 ã§ãã. ç°ç¶ç·ã®å
šé· d , JOI ãã¶ã®åºèã®åæ° n , 泚æã®åæ° m , æ¬åºä»¥å€ã®äœçœ®ã衚ã n - 1 åã®æŽæ° d 2 , ... , d n , å®
é
å
ã®å Žæãè¡šãæŽæ° k 1 , ... , k m ãäžãããããšã, åæ³šæã«å¯Ÿããå®
é
æã®ç§»åè·é¢ (ããªãã¡,æå¯åºèããå®
é
å
ãŸã§ã®éã®ã) ã®å
šæ³šæã«ãããç·åãæ±ããããã°ã©ã ãäœæãã. å
¥å å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ 1 è¡ç®ã«ã¯ç°ç¶ç·ã®å
šé·ãè¡šãæ£æŽæ° d (2 †d †1000000000 = 10 9 ), 2 è¡ç®ã«ã¯åºèã®åæ°ãè¡šãæ£æŽæ° n (2 †n †100000), 3 è¡ç®ã«ã¯æ³šæã®åæ°ãè¡šãæ£æŽæ° m (1 †m †10000) ãæžãããŠãã. 4 è¡ç®ä»¥éã® n - 1 è¡ã«ã¯æ¬åºä»¥å€ã®åºèã®äœçœ®ãè¡šãæŽæ° d 2 , d 3 , ... , d n (1 †d i †d - 1) ããã®é ã«æžãããŠãã, n + 3 è¡ç®ä»¥éã® m è¡ã«ã¯å®
é
å
ã®å Žæãè¡šãæŽæ° k 1 , k 2 , ... , k m (0 †k i †d - 1) ããã®é ã«æžãããŠãã. æ¡ç¹çšããŒã¿ã®ãã¡,é
ç¹ã® 40% åã«ã€ããŠã¯, n †10000 ãæºãã. ãŸã,é
ç¹ã® 40% åã«ã€ããŠã¯, æ±ããç§»åè·é¢ã®ç·åãš d ã®å€ã¯ãšãã« 1000000 以äžã§ãã. ããã«,å
šãŠã®æ¡ç¹çšããŒã¿ã«ãããŠ, æ±ããç§»åè·é¢ã®ç·å㯠1000000000 = 10 9 以äžã§ãã. d ã 0 ã®ãšãå
¥åã®çµäºã瀺ã. ããŒã¿ã»ããã®æ°ã¯ 10 ãè¶
ããªãïŒ åºå ããŒã¿ã»ããããšã«,å®
é
æã®ç§»åè·é¢ã®ç·åã衚ã 1 ã€ã®æŽæ°ã1 è¡ã«åºåãã. å
¥åºåäŸ å
¥åäŸ 8 3 2 3 1 4 6 20 4 4 12 8 16 7 7 11 8 0 åºåäŸ 3 3 äžèšå顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã
| 38,361
|
ç«æ¹äœã®äœå èžè¡å®¶åå·ã¯ n ç¹ã®äœåãåºå±ããããã«äŸé ŒãããŸãããããã§ãç«æ¹äœã® 6 é¢ããã³ãã§è²ä»ããããã®ãäœåãšããŠåºå±ããããšã«ããŸãããäœåã¯ãRedãYellowãBlueãMagentaãGreenãCyan ã® 6 è²å
šãŠã䜿ãããŠããŠãåé¢ã¯ 1 è²ã§å¡ãã€ã¶ãããŠããŸããåå·ã¯åœ¢ãåãç«æ¹äœã®äœåã§ãè²ã®é
眮ã®ä»æ¹ãå€ããç°ãªãäœåãšã㊠n ç¹äœæããŸããã 圌ã®å人ã§ããããªãã¯ãå人ã®ããã¿ã§äœåãåºå±åã«é²èЧãããŠããããŸããããããã§ããããšã«æ°ãä»ããŸããããããã®äœåã®äžã«ç°ãªãè²ä»ãããããŠããããã«èŠããŠããå®ã¯åãè²ã®çµã¿åãããããç«æ¹äœãååšããŠããã®ã§ãããã®ãŸãŸã§ã¯ã n ç¹ã®äœåãåºå±ããããšã§ããªããªã£ãŠããŸããŸãã äœæããäœåã®æ°ãšåäœåã®è²ã®æ
å ±ãå
¥åãšããåºå±ããããã«ããšäœç¹å¿
èŠããåºåããããã°ã©ã ãäœæããŠãã ããã ç«æ¹äœã®åé¢ã®è²ã¯ c1 ãã c6 ãŸã§ã®èšå·ã§è¡šããã 以äžã®ãããªé
眮ãšãªã£ãŠããŸãããŸããc1 ãã c6 ã®ãããã㯠RedãYellowãBlueãMagentaãGreenãCyan ã®ãããã 1 è²ãšãªããŸãã Input è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸãã å
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸãã åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã n cube 1 cube 2 : cube n ïŒè¡ç®ã«äœåã®æ° n (1 †n †30)ãç¶ã n è¡ã« i çªç®ã®äœåã®æ
å ±ãäžããããŸããåäœåã®æ
å ±ã¯æ¬¡ã®åœ¢åŒã§äžããããŸãã c1 c2 c3 c4 c5 c6 äœåã®è²ã®é
眮 c i ã空çœåºåãã§äžããããŸãã ããŒã¿ã»ããã®æ°ã¯ 100 ãè¶
ããŸããã Output ããŒã¿ã»ããããšã«ãåºå±ããã®ã«ããšäœç¹ã®äœåãå¿
èŠããïŒè¡ã«åºåããŸãã Sample Input 3 Cyan Yellow Red Magenta Green Blue Cyan Yellow Red Magenta Green Blue Red Yellow Magenta Blue Green Cyan 4 Red Magenta Blue Green Yellow Cyan Red Yellow Magenta Blue Green Cyan Magenta Green Red Cyan Yellow Blue Cyan Green Yellow Blue Magenta Red 0 Output for the Sample Input 1 1
| 38,362
|
38,363
|
|
Problem H: Cornering at Poles You are invited to a robot contest. In the contest, you are given a disc-shaped robot that is placed on a flat field. A set of poles are standing on the ground. The robot can move in all directions, but must avoid the poles. However, the robot can make turns around the poles touching them. Your mission is to find the shortest path of the robot to reach the given goal position. The length of the path is defined by the moving distance of the center of the robot. Figure H.1 shows the shortest path for a sample layout. In this figure, a red line connecting a pole pair means that the distance between the poles is shorter than the diameter of the robot and the robot cannot go through between them. Figure H.1. The shortest path for a sample layout Input The input consists of a single test case. $N$ $G_x$ $G_y$ $x_1$ $y_1$ . . . $x_N$ $y_N$ The first line contains three integers. $N$ represents the number of the poles ($1 \leq N \leq 8$). $(G_x, G_y)$ represents the goal position. The robot starts with its center at $(0, 0)$, and the robot accomplishes its task when the center of the robot reaches the position $(G_x, G_y)$. You can assume that the starting and goal positions are not the same. Each of the following $N$ lines contains two integers. $(x_i, y_i)$ represents the standing position of the $i$-th pole. Each input coordinate of $(G_x, G_y)$ and $(x_i, y_i)$ is between $â1000$ and $1000$, inclusive. The radius of the robot is $100$, and you can ignore the thickness of the poles. No pole is standing within a $100.01$ radius from the starting or goal positions. For the distance $d_{i,j}$ between the $i$-th and $j$-th poles $(i \ne j)$, you can assume $1 \leq d_{i,j} < 199.99$ or $200.01 < d_{i,j}$. Figure H.1 shows the shortest path for Sample Input 1 below, and Figure H.2 shows the shortest paths for the remaining Sample Inputs. Figure H.2. The shortest paths for the sample layouts Output Output the length of the shortest path to reach the goal. If the robot cannot reach the goal, output 0.0. The output should not contain an error greater than 0.0001. Sample Input 1 8 900 0 40 100 70 -80 350 30 680 -20 230 230 300 400 530 130 75 -275 Sample Output 1 1210.99416 Sample Input 2 1 0 200 120 0 Sample Output 2 200.0 Sample Input 3 3 110 110 0 110 110 0 200 10 Sample Output 3 476.95048 Sample Input 4 4 0 200 90 90 -90 90 -90 -90 90 -90 Sample Output 4 0.0 Sample Input 5 2 0 -210 20 -105 -5 -105 Sample Output 5 325.81116 Sample Input 6 8 680 -50 80 80 80 -100 480 -120 -80 -110 240 -90 -80 100 -270 100 -420 -20 Sample Output 6 1223.53071
| 38,364
|
Problem A: Infected Computer Adam Ivan is working as a system administrator at Soy Group, Inc. He is now facing at a big trouble: a number of computers under his management have been infected by a computer virus. Unfortunately, anti-virus system in his company failed to detect this virus because it was very new. Adam has identified the first computer infected by the virus and collected the records of all data packets sent within his network. He is now trying to identify which computers have been infected. A computer is infected when receiving any data packet from any infected computer. The computer is not infected, on the other hand, just by sending data packets to infected computers. It seems almost impossible for him to list all infected computers by hand, because the size of the packet records is fairly large. So he asked you for help: write a program that can identify infected computers. Input The input consists of multiple datasets. Each dataset has the following format: N M t 1 s 1 d 1 t 2 s 2 d 2 ... t M s M d M N is the number of computers; M is the number of data packets; t i (1 †i †M ) is the time when the i -th data packet is sent; s i and d i (1 †i †M ) are the source and destination computers of the i -th data packet respectively. The first infected computer is indicated by the number 1; the other computers are indicated by unique numbers between 2 and N . The input meets the following constraints: 0 < N †20000, 0 †M †20000, and 0 †t i †10 9 for 1 †i †N ; all t i 's are different; and the source and destination of each packet are always different. 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, print the number of computers infected by the computer virus. Sample Input 3 2 1 1 2 2 2 3 3 2 2 3 2 1 2 1 0 0 Output for the Sample Input 3 1
| 38,365
|
J - Unfair Game Problem Statement Rabbit Hanako and Fox Jiro are great friends going to JAG primary school. Today they decided to play the following game during the lunch break. This game is played by two players with $N$ heaps of some number of stones. The players alternatively take their turn to play the game. Jiro is a kind gentleman, so he yielded the first turn to Hanako. In each turn, the player must take some stones, satisfying the following conditions: If the player is Hanako, she must take between $1$ to $A$ stones, inclusive, from a heap. If the player is Jiro, he must take between $1$ to $B$ stones, inclusive, from a heap. The winner is the player who takes the last stone. Jiro thinks it is rude to go easy on her because he is a perfect gentleman. Therefore, he does him best. Of course, Hanako also does so. Jiro is worried that he may lose the game. Being a cadet teacher working at JAG primary school as well as a professional competitive programmer, you should help him by programming. Your task is to write a program calculating the winner, assuming that they both play optimally. Input The first line contains three integers $N$, $A$, and $B$. $N$ ($1 \leq N \leq 10^5$) is the number of heaps. $A$ and $B$ ($1 \leq A, B \leq 10^9$) are the maximum numbers of stones that Hanako and Jiro can take in a turn, respectively. Then $N$ lines follow, each of which contains a single integer $S_i$ ($1 \leq S_i \leq 10^9$), representing the number of stones in the $i$-th heap at the beginning of the game. Output Output a line with "Hanako" if Hanako wins the game or "Jiro" in the other case. Sample Input 1 3 5 4 3 6 12 Output for the Sample Input 1 Hanako Sample Input 2 4 7 8 8 3 14 5 Output for the Sample Input 2 Jiro
| 38,366
|
B: äžå³¶ãããããããïŒ - Match Peas War - åé¡ äžå³¶ããã
ã£ã»ã»ã»ã 磯éãäžå³¶ïŒå€§äžå€«ãïŒã äžå³¶ãã»ã»ã»ãªãã ãå«ãªå€¢ãèŠãŠããæ°ããããã 磯éãã©ããªå€¢ã ãïŒã äžå³¶ãç¡éã«éã¶å€¢ã 磯éãæå³ããããïŒãŸããããïŒäžå³¶ïŒããããããïŒã äžå³¶ãããã£ãŠãŸããïŒãããããªãããªã»ã»ã»ã 磯éãããã ãïŒããã äžå³¶ããã£ïŒãããããªããïŒããããããã 磯éããããããïŒãŸãã¯ãããããã ãªïŒã ãªã«ããïŒå
¬åã§2人ã®åäŸãéãã§ããããã§ãïŒæããããæããŸããïŒãšããã§ïŒããªãã¯ããããã»ã°ãªãŒã³ããŒã¹ã»æŠäºããªã©ãšåŒã°ããæéã³ãç¥ã£ãŠããŸããïŒãã®åç§°ã«ãã³ãšããªãã£ããšããŠãïŒãã£ãšïŒåäŸæä»£ã«å¹ŸåºŠãšãªãéãã ããšãããã§ãããïŒ ããã§ã¯ïŒããããã»ã°ãªãŒã³ããŒã¹ã»æŠäºãã®ã«ãŒã«ãç°¡ç¥åããæéã³ãèãïŒãããããšåä»ããŸãïŒããããã¯æ¬¡ã®ãããª2人ãã¬ã€ã®éã³ã§ãïŒ (1)ïŒåãã¬ã€ã€ãŒãäž¡æã®æã1æ¬ãã€ç«ãŠãç¶æ
ããéã³ãéå§ããïŒ (2)ïŒå
æã®ãã¬ã€ã€ãŒããé çªã«ä»¥äžã®(3)ã(5)ãè¡ãïŒ (3)ïŒãã¬ã€ã€ãŒã¯ïŒèªèº«ã®ã©ã¡ããäžæ¹ã®æã§çžæã®ã©ã¡ããäžæ¹ã®æã«è§ŠããïŒ (4)ïŒè§Šããããæã¯ïŒè§Šããæã«ç«ã£ãŠããæã®æ¬æ°ã ã远å ã§æãç«ãŠãïŒ ããã§ïŒ5æ¬ä»¥äžã®æãç«ã€ã¹ãç¶æ³ã«ãªã£ãæã¯éå ŽããïŒ ïŒéå Žããæã¯ïŒä»åŸè§Šãããè§Šãããããšãã«éžã°ããããšã¯ãªãïŒïŒ (5)ïŒäž¡æãšãéå Žãããã¬ã€ã€ãŒããããã©ãã確èªããïŒãããªãã°ïŒäž¡ãã¬ã€ã€ãŒã¯(6)ã«åŸãïŒ (6)ïŒéã³ãçµäºããïŒãã®ãšãïŒå°ãªããšãäžæ¹ã®æãæ®ã£ãŠãããã¬ã€ã€ãŒãåè
ã§ããïŒ ç£¯éãããŒãïŒåããã ãïŒã ããïŒã©ãããïŒç£¯éåãå
æã«ãªã£ãããã§ããïŒ2人ã®éã³ã®è¡ãæ«ãèŠå®ã£ãŠã¿ãŸãããïŒ ç£¯éããããåã¯ïŒå³æã«2æ¬ïŒå·Šæã«1æ¬ã§ã¯ããããïŒã äžå³¶ããããªãåã¯ïŒå³æã«2æ¬ïŒå·Šæã«2æ¬ã§ãããïŒã ã¡ãã£ãšåŸ
ãŠïŒãªãã ãã®ã«ãŒã«ã¯â ã©ãããïŒç£¯éåãã¡ã®éã§ã¯ïŒéã³éå§æã«åæã«ç«ã£ãŠããæã®æ¬æ°ã1 ã 4æ¬ã®ãã¡èªç±ã«æ±ºããããããã§ãïŒããŒã«ã«ã«ãŒã«ã£ãŠãã€ã§ããïŒ ããããã®ãããªé¡ã®éã³ã¯ïŒå
æåŸæã§ã©ã¡ããå¿
åãªã®ããç°¡åã«èª¿ã¹ãããšãã§ããŸãïŒãããïŒããããã«ç£¯éåãã¡ã®ããŒã«ã«ã«ãŒã«ãåãå
¥ãããšïŒå
æåŸæã®åæãå€ãã£ãŠãããã§ãïŒãšãŠãæ°ã«ãªããŸããïŒçãããèå³ãããããªã®ã§ã¯ïŒãããããªãã°ïŒå®éã«èª¿æ»ããŠã¿ãŸãããïŒ ç£¯éåãšäžå³¶åãããŒã«ã«ã«ãŒã«ãåãå
¥ããããããã§éã¶ãšããŸãïŒç£¯éåãå
æãšä»®å®ããŠïŒç£¯éåã®å·Šæã«ã¯ L_i æ¬ïŒå³æã«ã¯ R_i æ¬ã®æãïŒäžå³¶åã®å·Šæã«ã¯ L_n æ¬ïŒå³æã«ã¯ R_n æ¬ã®æãç«ã£ãŠãããšããŸãïŒ2人ãšãæé©ãªè¡åãéžæããå ŽåïŒã©ã¡ããåã€ããå€å®ããŠãã ããïŒ å
¥ååœ¢åŒ å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ L_i R_i L_n R_n 1è¡ç®ã«ã¯ç£¯éåã®æã®åæç¶æ
ã衚ã L_i ïŒ R_i ã空çœåºåãã§äžããããïŒ L_i ã¯å·Šæã§ç«ã£ãŠããæã®æ¬æ°ïŒ R_i ã¯å³æã§ç«ã£ãŠããæã®æ¬æ°ã§ããïŒ 2è¡ç®ã«ã¯äžå³¶åã®æã®åæç¶æ
ã衚ã L_n ïŒ R_n ã空çœåºåãã§äžããããïŒ L_n ã¯å·Šæã§ç«ã£ãŠããæã®æ¬æ°ïŒ R_n ã¯å³æã§ç«ã£ãŠããæã®æ¬æ°ã§ããïŒ ãŸãïŒå
¥åã¯ä»¥äžã®å¶çŽãæºããïŒ 1 †L_i, R_i, L_n, R_n †4 åºååœ¢åŒ ç£¯éåãåã€å Žåã¯âISONOâãïŒäžå³¶åãåã€å Žåã¯âNAKAJIMAâã1è¡ã«åºåããïŒ å
¥åäŸ1 3 2 2 2 åºåäŸ1 NAKAJIMA å
¥åäŸ2 3 2 2 3 åºåäŸ2 ISONO å
¥åäŸ3 1 1 1 1 åºåäŸ3 NAKAJIMA ããããã¯åŸæã§åžžå
| 38,368
|
Score: 600 points Problem Statement After being invaded by the Kingdom of AlDebaran, bombs are planted throughout our country, AtCoder Kingdom. Fortunately, our military team called ABC has managed to obtain a device that is a part of the system controlling the bombs. There are N bombs, numbered 1 to N , planted in our country. Bomb i is planted at the coordinate A_i . It is currently activated if B_i=1 , and deactivated if B_i=0 . The device has M cords numbered 1 to M . If we cut Cord j , the states of all the bombs planted between the coordinates L_j and R_j (inclusive) will be switched - from activated to deactivated, and vice versa. Determine whether it is possible to deactivate all the bombs at the same time. If the answer is yes, output a set of cords that should be cut. Constraints All values in input are integers. 1 \leq N \leq 10^5 1 \leq A_i \leq 10^9\ (1 \leq i \leq N) A_i are pairwise distinct. B_i is 0 or 1 . (1 \leq i \leq N) 1 \leq M \leq 2 \times 10^5 1 \leq L_j \leq R_j \leq 10^9\ (1 \leq j \leq M) Input Input is given from Standard Input in the following format: N M A_1 B_1 : A_N B_N L_1 R_1 : L_M R_M Output If it is impossible to deactivate all the bombs at the same time, print -1 . If it is possible to do so, print a set of cords that should be cut, as follows: k c_1 c_2 \dots c_k Here, k is the number of cords (possibly 0 ), and c_1, c_2, \dots, c_k represent the cords that should be cut. 1 \leq c_1 < c_2 < \dots < c_k \leq M must hold. Sample Input 1 3 4 5 1 10 1 8 0 1 10 4 5 6 7 8 9 Sample Output 1 2 1 4 There are two activated bombs at the coordinates 5, 10 , and one deactivated bomb at the coordinate 8 . Cutting Cord 1 switches the states of all the bombs planted between the coordinates 1 and 10 , that is, all of the three bombs. Cutting Cord 4 switches the states of all the bombs planted between the coordinates 8 and 9 , that is, Bomb 3 . Thus, we can deactivate all the bombs by cutting Cord 1 and Cord 4 . Sample Input 2 4 2 2 0 3 1 5 1 7 0 1 4 4 7 Sample Output 2 -1 Cutting any set of cords will not deactivate all the bombs at the same time. Sample Input 3 3 2 5 0 10 0 8 0 6 9 66 99 Sample Output 3 0 All the bombs are already deactivated, so we do not need to cut any cord. Sample Input 4 12 20 536130100 1 150049660 1 79245447 1 132551741 0 89484841 1 328129089 0 623467741 0 248785745 0 421631475 0 498966877 0 43768791 1 112237273 0 21499042 142460201 58176487 384985131 88563042 144788076 120198276 497115965 134867387 563350571 211946499 458996604 233934566 297258009 335674184 555985828 414601661 520203502 101135608 501051309 90972258 300372385 255474956 630621190 436210625 517850028 145652401 192476406 377607297 520655694 244404406 304034433 112237273 359737255 392593015 463983307 150586788 504362212 54772353 83124235 Sample Output 4 5 1 7 8 9 11 If there are multiple sets of cords that deactivate all the bombs when cut, any of them can be printed.
| 38,369
|
Largest Square Given a matrix ( H à W ) which contains only 1 and 0, find the area of the largest square matrix which only contains 0s. Input H W c 1,1 c 1,2 ... c 1,W c 2,1 c 2,2 ... c 2,W : c H,1 c H,2 ... c H,W In the first line, two integers H and W separated by a space character are given. In the following H lines, c i , j , elements of the H à W matrix, are given. Output Print the area (the number of 0s) of the largest square. Constraints 1 †H , W †1,400 Sample Input 4 5 0 0 1 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 Sample Output 4
| 38,370
|
Score : 100 points Problem Statement There is a grid with H horizontal rows and W vertical columns. Let (i, j) denote the square at the i -th row from the top and the j -th column from the left. For each i and j ( 1 \leq i \leq H , 1 \leq j \leq W ), Square (i, j) is described by a character a_{i, j} . If a_{i, j} is . , Square (i, j) is an empty square; if a_{i, j} is # , Square (i, j) is a wall square. It is guaranteed that Squares (1, 1) and (H, W) are empty squares. Taro will start from Square (1, 1) and reach (H, W) by repeatedly moving right or down to an adjacent empty square. Find the number of Taro's paths from Square (1, 1) to (H, W) . As the answer can be extremely large, find the count modulo 10^9 + 7 . Constraints H and W are integers. 2 \leq H, W \leq 1000 a_{i, j} is . or # . Squares (1, 1) and (H, W) are empty squares. Input Input is given from Standard Input in the following format: H W a_{1, 1} \ldots a_{1, W} : a_{H, 1} \ldots a_{H, W} Output Print the number of Taro's paths from Square (1, 1) to (H, W) , modulo 10^9 + 7 . Sample Input 1 3 4 ...# .#.. .... Sample Output 1 3 There are three paths as follows: Sample Input 2 5 2 .. #. .. .# .. Sample Output 2 0 There may be no paths. Sample Input 3 5 5 ..#.. ..... #...# ..... ..#.. Sample Output 3 24 Sample Input 4 20 20 .................... .................... .................... .................... .................... .................... .................... .................... .................... .................... .................... .................... .................... .................... .................... .................... .................... .................... .................... .................... Sample Output 4 345263555 Be sure to print the count modulo 10^9 + 7 .
| 38,371
|
Score : 1600 points Problem Statement Snuke found a random number generator. It generates an integer between 0 and 2^N-1 (inclusive). An integer sequence A_0, A_1, \cdots, A_{2^N-1} represents the probability that each of these integers is generated. The integer i ( 0 \leq i \leq 2^N-1 ) is generated with probability A_i / S , where S = \sum_{i=0}^{2^N-1} A_i . The process of generating an integer is done independently each time the generator is executed. Snuke has an integer X , which is now 0 . He can perform the following operation any number of times: Generate an integer v with the generator and replace X with X \oplus v , where \oplus denotes the bitwise XOR. For each integer i ( 0 \leq i \leq 2^N-1 ), find the expected number of operations until X becomes i , and print it modulo 998244353 . More formally, represent the expected number of operations as an irreducible fraction P/Q . Then, there exists a unique integer R such that R \times Q \equiv P \mod 998244353,\ 0 \leq R < 998244353 , so print this R . We can prove that, for every i , the expected number of operations until X becomes i is a finite rational number, and its integer representation modulo 998244353 can be defined. Constraints 1 \leq N \leq 18 1 \leq A_i \leq 1000 All values in input are integers. Input Input is given from Standard Input in the following format: N A_0 A_1 \cdots A_{2^N-1} Output Print 2^N lines. The (i+1) -th line ( 0 \leq i \leq 2^N-1 ) should contain the expected number of operations until X becomes i , modulo 998244353 . Sample Input 1 2 1 1 1 1 Sample Output 1 0 4 4 4 X=0 after zero operations, so the expected number of operations until X becomes 0 is 0 . Also, from any state, the value of X after one operation is 0 , 1 , 2 or 3 with equal probability. Thus, the expected numbers of operations until X becomes 1 , 2 and 3 are all 4 . Sample Input 2 2 1 2 1 2 Sample Output 2 0 499122180 4 499122180 The expected numbers of operations until X becomes 0 , 1 , 2 and 3 are 0 , 7/2 , 4 and 7/2 , respectively. Sample Input 3 4 337 780 799 10 796 875 331 223 941 67 148 483 390 565 116 355 Sample Output 3 0 468683018 635850749 96019779 657074071 24757563 745107950 665159588 551278361 143136064 557841197 185790407 988018173 247117461 129098626 789682908
| 38,373
|
Score : 1000 points Problem Statement For an n \times n grid, let (r, c) denote the square at the (r+1) -th row from the top and the (c+1) -th column from the left. A good coloring of this grid using K colors is a coloring that satisfies the following: Each square is painted in one of the K colors. Each of the K colors is used for some squares. Let us number the K colors 1, 2, ..., K . For any colors i and j ( 1 \leq i \leq K, 1 \leq j \leq K ), every square in Color i has the same number of adjacent squares in Color j . Here, the squares adjacent to square (r, c) are ((r-1)\; mod\; n, c), ((r+1)\; mod\; n, c), (r, (c-1)\; mod\; n) and (r, (c+1)\; mod\; n) (if the same square appears multiple times among these four, the square is counted that number of times). Given K , choose n between 1 and 500 (inclusive) freely and construct a good coloring of an n \times n grid using K colors. It can be proved that this is always possible under the constraints of this problem, Constraints 1 \leq K \leq 1000 Input Input is given from Standard Input in the following format: K Output Output should be in the following format: n c_{0,0} c_{0,1} ... c_{0,n-1} c_{1,0} c_{1,1} ... c_{1,n-1} : c_{n-1,0} c_{n-1,1} ... c_{n-1,n-1} n should represent the size of the grid, and 1 \leq n \leq 500 must hold. c_{r,c} should be an integer such that 1 \leq c_{r,c} \leq K and represent the color for the square (r, c) . Sample Input 1 2 Sample Output 1 3 1 1 1 1 1 1 2 2 2 Every square in Color 1 has three adjacent squares in Color 1 and one adjacent square in Color 2 . Every square in Color 2 has two adjacent squares in Color 1 and two adjacent squares in Color 2 . Output such as the following will be judged incorrect: 2 1 2 2 2 3 1 1 1 1 1 1 1 1 1 Sample Input 2 9 Sample Output 2 3 1 2 3 4 5 6 7 8 9
| 38,374
|
Score : 400 points Problem Statement You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1 , Katana 2 , ⊠, Katana N , and can perform the following two kinds of attacks in any order: Wield one of the katana you have. When you wield Katana i (1 †i †N) , the monster receives a_i points of damage. The same katana can be wielded any number of times. Throw one of the katana you have. When you throw Katana i (1 †i †N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana. The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total? Constraints 1 †N †10^5 1 †H †10^9 1 †a_i †b_i †10^9 All input values are integers. Input Input is given from Standard Input in the following format: N H a_1 b_1 : a_N b_N Output Print the minimum total number of attacks required to vanish the monster. Sample Input 1 1 10 3 5 Sample Output 1 3 You have one katana. Wielding it deals 3 points of damage, and throwing it deals 5 points of damage. By wielding it twice and then throwing it, you will deal 3 + 3 + 5 = 11 points of damage in a total of three attacks, vanishing the monster. Sample Input 2 2 10 3 5 2 6 Sample Output 2 2 In addition to the katana above, you also have another katana. Wielding it deals 2 points of damage, and throwing it deals 6 points of damage. By throwing both katana, you will deal 5 + 6 = 11 points of damage in two attacks, vanishing the monster. Sample Input 3 4 1000000000 1 1 1 10000000 1 30000000 1 99999999 Sample Output 3 860000004 Sample Input 4 5 500 35 44 28 83 46 62 31 79 40 43 Sample Output 4 9
| 38,375
|
Score : 200 points Problem Statement Takahashi is standing on a two-dimensional plane, facing north. Find the minimum positive integer K such that Takahashi will be at the starting position again after he does the following action K times: Go one meter in the direction he is facing. Then, turn X degrees counter-clockwise. Constraints 1 \leq X \leq 179 X is an integer. Input Input is given from Standard Input in the following format: X Output Print the number of times Takahashi will do the action before he is at the starting position again. Sample Input 1 90 Sample Output 1 4 Takahashi's path is a square. Sample Input 2 1 Sample Output 2 360
| 38,377
|
Score : 900 points Problem Statement We have a connected undirected graph with N vertices and M edges. Edge i in this graph ( 1 \leq i \leq M ) connects Vertex U_i and Vertex V_i bidirectionally. We are additionally given N integers D_1, D_2, ..., D_N . Determine whether the conditions below can be satisfied by assigning a color - white or black - to each vertex and an integer weight between 1 and 10^9 (inclusive) to each edge in this graph. If the answer is yes, find one such assignment of colors and integers, too. There is at least one vertex assigned white and at least one vertex assigned black. For each vertex v ( 1 \leq v \leq N ), the following holds. The minimum cost to travel from Vertex v to a vertex whose color assigned is different from that of Vertex v by traversing the edges is equal to D_v . Here, the cost of traversing the edges is the sum of the weights of the edges traversed. Constraints 2 \leq N \leq 100,000 1 \leq M \leq 200,000 1 \leq D_i \leq 10^9 1 \leq U_i, V_i \leq N The given graph is connected and has no self-loops or multiple edges. All values in input are integers. Input Input is given from Standard Input in the following format: N M D_1 D_2 ... D_N U_1 V_1 U_2 V_2 \vdots U_M V_M Output If there is no assignment satisfying the conditions, print a single line containing -1 . If such an assignment exists, print one such assignment in the following format: S C_1 C_2 \vdots C_M Here, the first line should contain the string S of length N . Its i -th character ( 1 \leq i \leq N ) should be W if Vertex i is assigned white and B if it is assigned black. The (i + 1) -th line ( 1 \leq i \leq M ) should contain the integer weight C_i assigned to Edge i . Sample Input 1 5 5 3 4 3 5 7 1 2 1 3 3 2 4 2 4 5 Sample Output 1 BWWBB 4 3 1 5 2 Assume that we assign the colors and integers as the sample output, and let us consider Vertex 5 , for example. To travel from Vertex 5 , which is assigned black, to a vertex that is assigned white with the minimum cost, we should make these moves: Vertex 5 \to Vertex 4 \to Vertex 2 . The total cost of these moves is 7 , which satisfies the condition. We can also verify that the condition is satisfied for other vertices. Sample Input 2 5 7 1 2 3 4 5 1 2 1 3 1 4 2 3 2 5 3 5 4 5 Sample Output 2 -1 Sample Input 3 4 6 1 1 1 1 1 2 1 3 1 4 2 3 2 4 3 4 Sample Output 3 BBBW 1 1 1 2 1 1
| 38,378
|
Reverse Polish notation is a notation where every operator follows all of its operands. For example, an expression (1+2)*(5+4) in the conventional Polish notation can be represented as 1 2 + 5 4 + * in the Reverse Polish notation. One of advantages of the Reverse Polish notation is that it is parenthesis-free. Write a program which reads an expression in the Reverse Polish notation and prints the computational result. An expression in the Reverse Polish notation is calculated using a stack. To evaluate the expression, the program should read symbols in order. If the symbol is an operand, the corresponding value should be pushed into the stack. On the other hand, if the symbols is an operator, the program should pop two elements from the stack, perform the corresponding operations, then push the result in to the stack. The program should repeat this operations. Input An expression is given in a line. Two consequtive symbols (operand or operator) are separated by a space character. You can assume that +, - and * are given as the operator and an operand is a positive integer less than 10 6 Output Print the computational result in a line. Constraints 2 †the number of operands in the expression †100 1 †the number of operators in the expression †99 -1 à 10 9 †values in the stack †10 9 Sample Input 1 1 2 + Sample Output 1 3 Sample Input 2 1 2 + 3 4 - * Sample Output 2 -3 Notes Template in C
| 38,379
|
ã¹ããŒã(Stove) JOI åã®éšå±ã«ã¯ã¹ããŒããããïŒJOI åèªèº«ã¯å¯ãã«åŒ·ãã®ã§ã²ãšãã§éšå±ã«ãããšãã¯ã¹ããŒããã€ããå¿
èŠã¯ãªããïŒæ¥å®¢ããããšãã¯ã¹ããŒããã€ããå¿
èŠãããïŒ ãã®æ¥ïŒJOI åã®ããšã«ã¯ N äººã®æ¥å®¢ãããïŒ i çªç®( 1 \leq i \leq N ) ã®æ¥å®¢ã¯æå» T_i ã«å°çãïŒæå» T_i + 1 ã«éåºããïŒåæã«è€æ°äººã®æ¥å®¢ãããããšã¯ãªãïŒ JOI åã¯ä»»æã®æå»ã«ã¹ããŒããã€ãããæ¶ãããã§ããïŒãã ãïŒã¹ããŒããã€ãã床ã«ãããã1æ¬æ¶è²»ããïŒJOI åã¯ãããã K æ¬ããæã£ãŠããªãã®ã§ïŒ K åãŸã§ããã¹ããŒããã€ããããšãã§ããªãïŒäžæ¥ã®ã¯ããã«ã¹ããŒãã¯æ¶ããŠããïŒ ã¹ããŒããã€ããŠãããšãã®åã ãçæãæ¶è²»ããã®ã§ïŒã¹ããŒããã€ãããæ¶ãããããæå»ãããŸãå®ããŠïŒã¹ããŒããã€ããŠããæéã®åèšãæå°åãããïŒ èª²é¡ JOI åã®éšå±ãžã®æ¥å®¢ã®æ
å ±ãšïŒJOI åã®æã£ãŠãããããã®æ¬æ°ãäžãããããšãïŒã¹ããŒããã€ããŠããæéã®åèšã®æå°å€ãæ±ããïŒ å
¥å æšæºå
¥åãã以äžã®å
¥åãèªã¿èŸŒãïŒ 1 è¡ç®ã«ã¯ïŒ2 ã€ã®æŽæ° N, K ã空çœãåºåããšããŠæžãããŠããïŒããã¯ïŒJOI åã®éšå±ã« N äººã®æ¥å®¢ãããïŒJOI å㯠K æ¬ã®ããããæã£ãŠããããšã衚ãïŒ ç¶ã N è¡ã®ãã¡ã® i è¡ç®( 1 \leq i \leq N ) ã«ã¯ïŒæŽæ° T_i ãæžãããŠããïŒããã¯ïŒ i çªç®ã®æ¥å®¢ãæå» T_i ã«å°çãïŒæå» T_i + 1 ã«éåºããããšã衚ãïŒ åºå æšæºåºåã«ïŒã¹ããŒããã€ããŠããæéã®åèšã®æå°å€ã1 è¡ã§åºåããïŒ å¶é ãã¹ãŠã®å
¥åããŒã¿ã¯ä»¥äžã®æ¡ä»¶ãæºããïŒ 1 \leq N \leq 100 000ïŒ 1 \leq K \leq NïŒ 1 \leq T_i \leq 1 000 000 000 (1 \leq i \leq N)ïŒ T_i < T_{i+1} (1 \leq i \leq N - 1) ïŒ åå
¥åºåäŸ å
¥åäŸ1 3 2 1 3 6 åºåäŸ1 4 ãã®å
¥åäŸã§ã¯ïŒJOI åã®éšå±ãžã®æ¥å®¢ã3 人ããïŒä»¥äžã®ããã«ã¹ããŒããã€ãããæ¶ããããããšïŒæ¥å®¢ãããéã¯ã¹ããŒããã€ããŠããïŒã¹ããŒããã€ããåæ°ã¯2 åã§ããïŒã¹ããŒããã€ããŠããæéã®åèšã¯(4 - 1) + (7 - 6) = 4 ã§ããïŒ 1 çªç®ã®æ¥å®¢ãå°çããæå»1 ã«ã¹ããŒããã€ããïŒ 2 çªç®ã®æ¥å®¢ãéåºããæå»4 ã«ã¹ããŒããæ¶ãïŒ 3 çªç®ã®æ¥å®¢ãå°çããæå»6 ã«ã¹ããŒããã€ããïŒ 3 çªç®ã®æ¥å®¢ãéåºããæå»7 ã«ã¹ããŒããæ¶ãïŒ ã¹ããŒããã€ããŠããæéã®åèšã4 æªæºã«ããããšã¯ã§ããªãã®ã§ïŒçããšããŠ4 ãåºåããïŒ å
¥åäŸ2 3 1 1 2 6 åºåäŸ2 6 ãã®å
¥åäŸã§ã¯ïŒJOI åã¯1 åããã¹ããŒããã€ããããšãã§ããªãã®ã§ïŒ1 çªç®ã®æ¥å®¢ãå°çããæå»1 ã«ã¹ããŒããã€ãïŒ3 çªç®ã®æ¥å®¢ãéåºããæå»7 ã«ã¹ããŒããæ¶ãã°ããïŒ æ¥å®¢ãéåºããæå»ãšïŒãã®æ¬¡ã®æ¥å®¢ãå°çããæå»ãäžèŽããå Žåãããããšã«æ³šæããïŒ å
¥åäŸ3 3 3 1 3 6 åºåäŸ3 3 ãã®å
¥åäŸã§ã¯ïŒJOI åã¯æ¥å®¢ãå°çãã床ã«ã¹ããŒããã€ãïŒæ¥å®¢ãéåºãã床ã«ã¹ããŒããæ¶ãã°ããïŒ å
¥åäŸ4 10 5 1 2 5 6 8 11 13 15 16 20 åºåäŸ4 12 æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒäœ ã第17 åæ¥æ¬æ
å ±ãªãªã³ããã¯(JOI 2017/2018) æ¬éžã
| 38,380
|
ããã£ã·ãš ã±ãŒãå±ãããããŸã¡ãŸã¡ãªå€§ããã®ããŒã«ã±ãŒããããããäœããŸãããããªãã¯ããã®ã±ãŒããç®±ã«äžŠã¹ãä»äºãä»»ãããŸããã ããŒã«ã±ãŒãã¯ãšãŠããããããã®ã§ãä»ã®ããŒã«ã±ãŒããäžã«ä¹ããšã€ã¶ããŠããŸããŸããã§ããããå³(a) ã®ããã«å
šãŠã®ããŒã«ã±ãŒãã¯å¿
ãç®±ã®åºé¢ã«æ¥ããŠããããã«äžŠã¹ãªããã°ãªããŸãããäžŠã¹æ¿ãããšå¿
èŠãªå¹
ãå€ãããŸãã å³(a) å³(b) n åã®ããŒã«ã±ãŒãã®ååŸ r 1 , r 2 , ..., r n ãšç®±ã®é·ããèªã¿èŸŒã¿ãããããã«ã€ããŠãç®±ã®äžã«ããŸãåãŸããã©ããå€å®ãã䞊ã¹ãé çªã工倫ãããšç®±ã«å
¥ãå Žå㯠"OK"ãã©ã䞊ã¹ãŠãå
¥ããªãå Žåã«ã¯ "NA"ãåºåããããã°ã©ã ãäœæããŠãã ããã ããŒã«ã±ãŒãã®æé¢ã¯åã§ãããç®±ã®å£ã®é«ãã¯ååã«é«ããã®ãšããŸãã ãã ããããŒã«ã±ãŒãã®ååŸã¯ 3 ä»¥äž 10 以äžã®æŽæ°ãšããŸããã€ãŸããã±ãŒãã®ååŸã«æ¥µç«¯ãªå·®ã¯ãªããå³(b) ã®ããã«å€§ããªã±ãŒãã®éã«å°ããªã±ãŒããã¯ãŸã蟌ãã§ããŸãããšã¯ãããŸããã Input å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã W r 1 r 2 ... r n æåã«ç®±ã®é·ããè¡šãæŽæ° W (1 †W †1,000) ãäžããããŸãã ç¶ããŠã空çœåºåãã§åããŒã«ã±ãŒãã®ååŸãè¡šãæŽæ° r i (3 †r i †10) ãäžããããŸããã±ãŒãã®åæ° n 㯠12 以äžã§ãã ããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã Output ããŒã¿ã»ããããšã« OK ãŸã㯠NA ãïŒè¡ã«åºåããŠãã ããã Sample Input 30 4 5 6 30 5 5 5 50 3 3 3 10 10 49 3 3 3 10 10 Output for the Sample Input OK OK OK NA
| 38,381
|
Problem C: Dungeon Quest II The cave, called "Mass of Darkness", had been a agitating point of the evil, but the devil king and all of his soldiers were destroyed by the hero and the peace is there now. One day, however, the hero was worrying about the rebirth of the devil king, so he decided to ask security agency to patrol inside the cave. The information of the cave is as follows: The cave is represented as a two-dimensional field which consists of rectangular grid of cells. The cave has R à C cells where R is the number of rows and C is the number of columns. Some of the cells in the cave contains a trap, and those who enter the trapping cell will lose his hit points. The type of traps varies widely: some of them reduce hit points seriously, and others give less damage. The following is how the security agent patrols: The agent will start his patrol from upper left corner of the cave. - There are no traps at the upper left corner of the cave. The agent will patrol by tracing the steps which are specified by the hero. - The steps will be provided such that the agent never go outside of the cave during his patrol. The agent will bring potions to regain his hit point during his patrol. The agent can use potions just before entering the cell where he is going to step in. The type of potions also varies widely: some of them recover hit points so much, and others are less effective. - Note that agentâs hit point can be recovered up to HP max which means his maximum hit point and is specified by the input data. The agent can use more than one type of potion at once. If the agent's hit point becomes less than or equal to 0, he will die. Your task is to write a program to check whether the agent can finish his patrol without dying. Input The input is a sequence of datasets. Each dataset is given in the following format: HP init HP max R C a 1,1 a 1,2 ... a 1, C a 2,1 a 2,2 ... a 2, C . . . a R ,1 a R ,2 ... a R , C T [ A-Z ] d 1 [ A-Z ] d 2 . . . [ A-Z ] d T S [ UDLR ] n 1 [ UDLR ] n 2 . . . [ UDLR ] n S P p 1 p 2 . . . p P The first line of a dataset contains two integers HP init and HP max (0 < HP init †HP max †1000), meaning the agent's initial hit point and the agentâs maximum hit point respectively. The next line consists of R and C (1 †R , C †100). Then, R lines which made of C characters representing the information of the cave follow. The character a i,j means there are the trap of type a i,j in i -th row and j -th column, and the type of trap is denoted as an uppercase alphabetic character [ A-Z ]. The next line contains an integer T , which means how many type of traps to be described. The following T lines contains a uppercase character [ A-Z ] and an integer d i (0 †d i †1000), representing the type of trap and the amount of damage it gives. The next line contains an integer S (0 †S †1000) representing the number of sequences which the hero specified as the agent's patrol route. Then, S lines follows containing a character and an integer n i ( â S i =1 n i †1000), meaning the direction where the agent advances and the number of step he takes toward that direction. The direction character will be one of ' U ', ' D ', ' L ', ' R ' for Up, Down, Left, Right respectively and indicates the direction of the step. Finally, the line which contains an integer P (0 †P †12) meaning how many type of potions the agent has follows. The following P lines consists of an integer p i (0 < p i †1000) which indicated the amount of hit point it recovers. The input is terminated by a line with two zeros. This line should not be processed. Output For each dataset, print in a line " YES " if the agent finish his patrol successfully, or " NO " otherwise. If the agent's hit point becomes less than or equal to 0 at the end of his patrol, the output should be " NO ". Sample Input 1 10 3 3 AAA ABA CCC 3 A 0 B 5 C 9 3 D 2 R 1 U 2 5 10 10 10 10 10 100 100 10 10 THISISAPEN THISISAPEN THISISAPEN THISISAPEN THISISAPEN THISISAPEN THISISAPEN THISISAPEN THISISAPEN THISISAPEN 8 T 0 H 1 I 2 S 3 A 4 P 5 E 6 N 7 9 R 1 D 3 R 8 D 2 L 9 D 2 R 9 D 2 L 9 2 20 10 0 0 Output for the Sample Input YES NO
| 38,382
|
Draw in Straight Lines You plan to draw a black-and-white painting on a rectangular canvas. The painting will be a grid array of pixels, either black or white. You can paint black or white lines or dots on the initially white canvas. You can apply a sequence of the following two operations in any order. Painting pixels on a horizontal or vertical line segment, single pixel wide and two or more pixel long, either black or white. This operation has a cost proportional to the length (the number of pixels) of the line segment multiplied by a specified coefficient in addition to a specified constant cost. Painting a single pixel, either black or white. This operation has a specified constant cost. You can overpaint already painted pixels as long as the following conditions are satisfied. The pixel has been painted at most once before. Overpainting a pixel too many times results in too thick layers of inks, making the picture look ugly. Note that painting a pixel with the same color is also counted as overpainting. For instance, if you have painted a pixel with black twice, you can paint it neither black nor white anymore. The pixel once painted white should not be overpainted with the black ink. As the white ink takes very long to dry, overpainting the same pixel black would make the pixel gray, rather than black. The reverse, that is, painting white over a pixel already painted black, has no problem. Your task is to compute the minimum total cost to draw the specified image. Input The input consists of a single test case. The first line contains five integers $n$, $m$, $a$, $b$, and $c$, where $n$ ($1 \leq n \leq 40$) and $m$ ($1 \leq m \leq 40$) are the height and the width of the canvas in the number of pixels, and $a$ ($0 \leq a \leq 40$), $b$ ($0 \leq b \leq 40$), and $c$ ($0 \leq c \leq 40$) are constants defining painting costs as follows. Painting a line segment of length $l$ costs $al + b$ and painting a single pixel costs $c$. These three constants satisfy $c \leq a + b$. The next $n$ lines show the black-and-white image you want to draw. Each of the lines contains a string of length $m$. The $j$-th character of the $i$-th string is â # â if the color of the pixel in the $i$-th row and the $j$-th column is to be black, and it is â . â if the color is to be white. Output Output the minimum cost. Sample Input 1 3 3 1 2 3 .#. ### .#. Sample Output 1 10 Sample Input 2 2 7 0 1 1 ###.### ###.### Sample Output 2 3 Sample Input 3 5 5 1 4 4 ..#.. ..#.. ##.## ..#.. ..#.. Sample Output 3 24 Sample Input 4 7 24 1 10 10 ###...###..#####....###. .#...#...#.#....#..#...# .#..#......#....#.#..... .#..#......#####..#..... .#..#......#......#..... .#...#...#.#.......#...# ###...###..#........###. Sample Output 4 256
| 38,383
|
Nathan O. Davis has been running an electronic bulletin board system named JAG-channel. He is now having hard time to add a new feature there --- threaded view. Like many other bulletin board systems, JAG-channel is thread-based. Here a thread (also called a topic) refers to a single conversation with a collection of posts. Each post can be an opening post, which initiates a new thread, or a reply to a previous post in an existing thread. Threaded view is a tree-like view that reflects the logical reply structure among the posts: each post forms a node of the tree and contains its replies as its subnodes in the chronological order (i.e. older replies precede newer ones). Note that a post along with its direct and indirect replies forms a subtree as a whole. Let us take an example. Suppose: a user made an opening post with a message hoge ; another user replied to it with fuga ; yet another user also replied to the opening post with piyo ; someone else replied to the second post (i.e. fuga â) with foobar ; and the fifth user replied to the same post with jagjag . The tree of this thread would look like: hoge ââfuga â ââfoobar â ââjagjag ââpiyo For easier implementation, Nathan is thinking of a simpler format: the depth of each post from the opening post is represented by dots. Each reply gets one more dot than its parent post. The tree of the above thread would then look like: hoge .fuga ..foobar ..jagjag .piyo Your task in this problem is to help Nathan by writing a program that prints a tree in the Nathan's format for the given posts in a single thread. Input Input contains a single dataset in the following format: n k_1 M_1 k_2 M_2 : : k_n M_n The first line contains an integer n ( 1 †n †1,000 ), which is the number of posts in the thread. Then 2n lines follow. Each post is represented by two lines: the first line contains an integer k_i ( k_1 = 0 , 1 †k_i < i for 2 †i †n ) and indicates the i -th post is a reply to the k_i -th post; the second line contains a string M_i and represents the message of the i -th post. k_1 is always 0, which means the first post is not replying to any other post, i.e. it is an opening post. Each message contains 1 to 50 characters, consisting of uppercase, lowercase, and numeric letters. Output Print the given n messages as specified in the problem statement. Sample Input 1 1 0 icpc Output for the Sample Input 1 icpc Sample Input 2 5 0 hoge 1 fuga 1 piyo 2 foobar 2 jagjag Output for the Sample Input 2 hoge .fuga ..foobar ..jagjag .piyo Sample Input 3 8 0 jagjag 1 hogehoge 1 buhihi 2 fugafuga 4 ponyoponyo 5 evaeva 4 nowawa 5 pokemon Output for the Sample Input 3 jagjag .hogehoge ..fugafuga ...ponyoponyo ....evaeva ....pokemon ...nowawa .buhihi Sample Input 4 6 0 nakachan 1 fan 2 yamemasu 3 nennryou2 4 dannyaku4 5 kouzai11 Output for the Sample Input 4 nakachan .fan ..yamemasu ...nennryou2 ....dannyaku4 .....kouzai11 Sample Input 5 34 0 LoveLive 1 honoka 2 borarara 2 sunohare 2 mogyu 1 eri 6 kasikoi 7 kawaii 8 eriichika 1 kotori 10 WR 10 haetekurukotori 10 ichigo 1 umi 14 love 15 arrow 16 shoot 1 rin 18 nyanyanya 1 maki 20 6th 20 star 22 nishikino 1 nozomi 24 spiritual 25 power 1 hanayo 27 darekatasukete 28 chottomattete 1 niko 30 natsuiro 30 nikkonikkoni 30 sekaino 33 YAZAWA Output for the Sample Input 5 LoveLive .honoka ..borarara ..sunohare ..mogyu .eri ..kasikoi ...kawaii ....eriichika .kotori ..WR ..haetekurukotori ..ichigo .umi ..love ...arrow ....shoot .rin ..nyanyanya .maki ..6th ..star ...nishikino .nozomi ..spiritual ...power .hanayo ..darekatasukete ...chottomattete .niko ..natsuiro ..nikkonikkoni ..sekaino ...YAZAWA Sample Input 6 6 0 2ch 1 1ostu 1 2get 1 1otsu 1 1ostu 3 pgr Output for the Sample Input 6 2ch .1ostu .2get ..pgr .1otsu .1ostu
| 38,384
|
Problem E: Molecular Formula Your mission in this problem is to write a computer program that manipulates molecular for- mulae in virtual chemistry . As in real chemistry, each molecular formula represents a molecule consisting of one or more atoms. However, it may not have chemical reality. The following are the definitions of atomic symbols and molecular formulae you should consider. An atom in a molecule is represented by an atomic symbol, which is either a single capital letter or a capital letter followed by a small letter. For instance H and He are atomic symbols. A molecular formula is a non-empty sequence of atomic symbols. For instance, HHHeHHHe is a molecular formula, and represents a molecule consisting of four Hâs and two Heâs. For convenience, a repetition of the same sub-formula where n is an integer between 2 and 99 inclusive, can be abbreviated to ( X ) n . Parentheses can be omitted if X is an atomic symbol. For instance, HHHeHHHe is also written as H2HeH2He, (HHHe)2, (H2He)2, or even ((H)2He)2. The set of all molecular formulae can be viewed as a formal language. Summarizing the above description, the syntax of molecular formulae is defined as follows. Each atom in our virtual chemistry has its own atomic weight. Given the weights of atoms, your program should calculate the weight of a molecule represented by a molecular formula. The molecular weight is defined by the sum of the weights of the constituent atoms. For instance, assuming that the atomic weights of the atoms whose symbols are H and He are 1 and 4, respectively, the total weight of a molecule represented by (H2He)2 is 12. Input The input consists of two parts. The first part, the Atomic Table, is composed of a number of lines, each line including an atomic symbol, one or more spaces, and its atomic weight which is a positive integer no more than 1000. No two lines include the same atomic symbol. The first part ends with a line containing only the string END OF FIRST PART. The second part of the input is a sequence of lines. Each line is a molecular formula, not exceeding 80 characters, and contains no spaces. A molecule contains at most 10 5 atoms. Some atomic symbols in a molecular formula may not appear in the Atomic Table. The sequence is followed by a line containing a single zero, indicating the end of the input. Output The output is a sequence of lines, one for each line of the second part of the input. Each line contains either an integer, the molecular weight for a given molecular formula in the correspond- ing input line if all its atomic symbols appear in the Atomic Table, or UNKNOWN otherwise. No extra characters are allowed. Sample Input H 1 He 4 C 12 O 16 F 19 Ne 20 Cu 64 Cc 333 END_OF_FIRST_PART H2C (MgF)2As Cu(OH)2 H((CO)2F)99 0 Output for the Sample Input 14 UNKNOWN 98 7426
| 38,385
|
Problem B: å®å
šæ° ããæŽæ° N ã«å¯ŸãïŒãã®æ°èªèº«ãé€ãçŽæ°ã®åã S ãšããïŒ N = S ã®ãšã N ã¯å®å
šæ° (perfect number)ïŒ N > S ã®ãšã N ã¯äžè¶³æ° (deficient number)ïŒ N < S ã®ãšã N ã¯éå°æ° (abundant number) ãšåŒã°ããïŒ äžããããæŽæ°ãïŒå®å
šæ°ã»äžè¶³æ°ã»éå°æ°ã®ã©ãã§ãããã å€å®ããããã°ã©ã ãäœæããïŒ ããã°ã©ã ã®å®è¡æéãå¶éæéãè¶ããªãããã«æ³šæããããšïŒ Input å
¥åã¯ããŒã¿ã»ããã®äžŠã³ãããªãïŒ ããŒã¿ã»ããã®æ°ã¯ 100 以äžã§ããïŒ åããŒã¿ã»ããã¯æŽæ° N (0 < N †100000000) ã®ã¿ãå«ã1è¡ãããªãïŒ æåŸã®ããŒã¿ã»ããã®åŸã«ïŒå
¥åã®çµããã瀺ã 0 ãšæžããã1è¡ãããïŒ Output åããŒã¿ã»ããã«å¯ŸãïŒ æŽæ° N ãå®å
šæ°ãªãã° â perfect number âïŒ äžè¶³æ°ãªãã° â deficient number âïŒ éå°æ°ãªãã° â abundant number â ãšããæååã 1è¡ã«åºåããïŒ Sample Input 1 2 3 4 6 12 16 28 33550336 99999998 99999999 100000000 0 Output for the Sample Input deficient number deficient number deficient number deficient number perfect number abundant number deficient number perfect number perfect number deficient number deficient number abundant number
| 38,387
|
Score: 100 points Problem Statement There is a train going from Station A to Station B that costs X yen (the currency of Japan). Also, there is a bus going from Station B to Station C that costs Y yen. Joisino got a special ticket. With this ticket, she can take the bus for half the fare if she travels from Station A to Station B by train and then travels from Station B to Station C by bus. How much does it cost to travel from Station A to Station C if she uses this ticket? Constraints 1 \leq X,Y \leq 100 Y is an even number. All values in input are integers. Input Input is given from Standard Input in the following format: X Y Output If it costs x yen to travel from Station A to Station C , print x . Sample Input 1 81 58 Sample Output 1 110 The train fare is 81 yen. The train fare is 58 â 2=29 yen with the 50 % discount. Thus, it costs 110 yen to travel from Station A to Station C . Sample Input 2 4 54 Sample Output 2 31
| 38,388
|
H - Rings Problem Statement There are two circles with radius 1 in 3D space. Please check two circles are connected as chained rings. Input The input is formatted as follows. {c_x}_1 {c_y}_1 {c_z}_1 {v_x}_{1,1} {v_y}_{1,1} {v_z}_{1,1} {v_x}_{1,2} {v_y}_{1,2} {v_z}_{1,2} {c_x}_2 {c_y}_2 {c_z}_2 {v_x}_{2,1} {v_y}_{2,1} {v_z}_{2,1} {v_x}_{2,2} {v_y}_{2,2} {v_z}_{2,2} First line contains three real numbers( -3 \leq {c_x}_i, {c_y}_i, {c_z}_i \leq 3 ). It shows a circle's center position. Second line contains six real numbers( -1 \leq {v_x}_{i,j}, {v_y}_{i,j}, {v_z}_{i,j} \leq 1 ). A unit vector ( {v_x}_{1,1}, {v_y}_{1,1}, {v_z}_{1,1} ) is directed to the circumference of the circle from center of the circle. The other unit vector ( {v_x}_{1,2}, {v_y}_{1,2}, {v_z}_{1,2} ) is also directed to the circumference of the circle from center of the circle. These two vectors are orthogonalized. Third and fourth lines show the other circle information in the same way of first and second lines. There are no cases that two circles touch. Output If two circles are connected as chained rings, you should print "YES". The other case, you should print "NO". (quotes for clarity) Sample Input 1 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0 0.0 1.0 0.0 0.5 1.0 0.0 0.0 0.0 0.0 1.0 Output for the Sample Input 1 YES Sample Input 2 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0 0.0 0.0 3.0 0.0 0.0 1.0 0.0 -1.0 0.0 0.0 Output for the Sample Input 2 NO Sample Input 3 1.2 2.3 -0.5 1.0 0.0 0.0 0.0 1.0 0.0 1.1 2.3 -0.4 1.0 0.0 0.0 0.0 0.70710678 0.70710678 Output for the Sample Input 3 YES Sample Input 4 1.2 2.3 -0.5 1.0 0.0 0.0 0.0 1.0 0.0 1.1 2.7 -0.1 1.0 0.0 0.0 0.0 0.70710678 0.70710678 Output for the Sample Input 4 NO
| 38,389
|
Score : 600 points Problem Statement We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N-1 or smaller. (The operation is the same as the one in Problem D.) Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N , and increase each of the other elements by 1 . It can be proved that the largest element in the sequence becomes N-1 or smaller after a finite number of operations. You are given the sequence a_i . Find the number of times we will perform the above operation. Constraints 2 †N †50 0 †a_i †10^{16} + 1000 Input Input is given from Standard Input in the following format: N a_1 a_2 ... a_N Output Print the number of times the operation will be performed. Sample Input 1 4 3 3 3 3 Sample Output 1 0 Sample Input 2 3 1 0 3 Sample Output 2 1 Sample Input 3 2 2 2 Sample Output 3 2 Sample Input 4 7 27 0 0 0 0 0 0 Sample Output 4 3 Sample Input 5 10 1000 193 256 777 0 1 1192 1234567891011 48 425 Sample Output 5 1234567894848
| 38,390
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.