task stringlengths 0 154k | __index_level_0__ int64 0 39.2k |
|---|---|
ãã¿ã ãã åé¡ ããªã㯠J åãšäžç·ã«ãã¿ã ããã䜿ã£ãŠéãã§ãã.ãã¿ã ãã㯠n æ¬ã®çžŠæ£ãš m æ¬ã®æšªæ£ãããªã.瞊æ£ã«ã¯å·Šããé ã« 1 ãã n ã®çªå·ãã€ããŠãã,çžŠæ£ i ã®äžç«¯ã«ã¯æ£æŽæ° s i ãæžãããŠãã. å³ 3-1 ãã¿ã ããã®äŸ( n = 4, m = 5, s 1 = 20, s 2 = 80, s 3 = 100, s 4 = 50) çžŠæ£ i ã®äžçªäžããé ã«éããã©ã£ãŠããå°éããäžç«¯ã«æžãããŠããæŽæ°ã, 瞊 æ£ i ãéžãã å Žåã®åŸç¹ã§ãã.äŸãã°,å³ 3-1 ã§ã¯,çžŠæ£ 1 ãéžã¶ãšåŸç¹ã¯ 80 ç¹ ã§ãã,çžŠæ£ 2 ãéžã¶ãšåŸç¹ã¯ 100 ç¹ã§ãã. å³ 3-2 éã®ãã©ãæ¹ã®äŸ J åã¯çžŠæ£ 1 ããçžŠæ£ k ãŸã§ã®é£ç¶ãã k æ¬ãéžã¶ããšã«ãã.ããã k æ¬ã®çžŠæ£ãéžãã ãšãã®ç¹æ°ã®åèšã J åã®åŸç¹ãšãªã.ãã ã,ããªãã¯ãã¿ã ããå
㮠暪æ£ãäžæ¬éžã³,ãã®æšªæ£ããã¿ã ããããåé€ããããšãã§ãã. (åé€ããªããŠããã.) ãã,ããªããæšªæ£ãäžæ¬åé€ããå Žåã¯,åé€åŸã®ãã¿ã ããã«ãããŠ, çžŠæ£ 1 ããçžŠæ£ k ãŸã§ã®é£ç¶ãã k æ¬ã®çžŠæ£ãéžãã ãšãã®ç¹æ°ã®åèšã J åã®åŸç¹ãšãªã. å
¥åãšããŠãã¿ã ããã®åœ¢ãš J åã®éžã¶çžŠæ£ã®æ¬æ° k ãäžãããããšã,J åã®åŸ ç¹ã®æå°å€ãæ±ããããã°ã©ã ãäœæãã. å
¥å å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ 1 è¡ç®ã«ã¯ 4 ã€ã®æŽæ° n , m , h , k ã空çœåºåãã§æžãããŠãã. n (2 †n †1000) ã¯çžŠæ£ã®æ¬æ°ã, m (1 †m †100000) ã¯æšªæ£ã®æ¬æ°ã, h (2 †h †1000) ã¯çžŠæ£ã®é·ãã, k (1 †k †n) 㯠J åãéžã¶çžŠæ£ã®æ¬æ°ã衚ã. ç¶ã n è¡ã«ã¯çžŠæ£ã®äžç«¯ã«æžãããŠããç¹æ°ãæžãããŠãã. i + 1 è¡ç® (1 †i †n)ã«ã¯æ£æŽæ° s i ãæžãããŠãã. ãŸã, s 1 + s 2 + ... + s n †2000000000 = 2 à 10 9 ãæºãã. ç¶ã m è¡ã«ã¯æšªæ£ã®äœçœ®ãæžãããŠãã.暪æ£ã«ã¯ 1 ãã m ãŸã§ã®çªå·ãã€ããŠãã. i + n + 1 è¡ç® (1 †i †m ) ã«ã¯, æšªæ£ i ã®äœçœ®ã衚ã 2 ã€ã®æŽæ° a i , b i (1 †a i †n - 1, 1 †b i †h - 1) ã空çœåºåãã§æžãããŠãã,æšªæ£ i ãçžŠæ£ a i ãšçžŠæ£ a i + 1 ãçµã³, æšªæ£ i ã®äžç«¯ããã®è·é¢ã b i ã§ããããšã衚ã. ãã ã,ã©ã® 2 ã€ã®æšªæ£ã端ç¹ãå
±æããããšã¯ãªã. æ¡ç¹çšããŒã¿ã®ãã¡,é
ç¹ã® 20 % åã¯æšªæ£ãåé€ããªãå Žåã« J åã®åŸç¹ãæå°ãšãªã.ãŸã,é
ç¹ã® 30 % å㯠n †20, m †30, h †10 ãæºãã,é
ç¹ã® 60 % å㯠m †1000 ãæºãã. å
¥åã®çµãã㯠4ã€ã®ãŒããå«ãè¡ã§ç€ºããã. ããŒã¿ã»ããã®æ°ã¯ 10 ãè¶
ããªãïŒ åºå ããŒã¿ã»ããããšã«, J åã®åŸç¹ã®æå°å€ã1 è¡ã«åºåãã. å
¥åºåäŸ å
¥åäŸ 4 5 7 2 20 80 100 50 1 1 2 6 2 3 1 5 3 1 2 2 5 1 10 20 1 1 1 3 0 0 0 0 åºåäŸ 100 10 1ã€ç®ã®äŸ ã¯å³ 3-1 ã«å¯Ÿå¿ã,ããªããæšªæ£ 4 (çžŠæ£ 1 ãšçžŠæ£ 2 ãäžç«¯ããè·é¢ 5 ã®å Žæã§çµã¶æšªæ£)ãåé€ãããšã,J åã®åŸç¹ã¯æå°ã«ãªã.äŸ 2 ã§ã¯,ããªããæšªæ£ãåé€ããªãå Žåã« J åã®åŸç¹ãæå°ã«ãªã. (å³3-3 ãèŠã.) å³ 3-3 äžèšå顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã | 39,132 |
é£åãªäººãã¡ãåº§ãæ€
å 4ã€ã®åœã®äžå¿ã«ããäžç«éœåžã¢ã€ãºã·ãã£ã«ã¯ãå€§éžæšªæåè»ãã³ãã€å·ã®ããŒã ããããŸãã ããŒã ã«ã¯ããã³ãã€å·ãåŸ
ã€ä¹å®¢çšã®æ€
åãäžåã«çšæãããŠãããããŒã ã«å
¥ã£ãŠãã人ã¯èªç±ã«æ€
åãå©çšããããšãã§ããŸãã ãã®ãã³ãã€å·ãå®ããæ©ããå¿«é©ãšããããšã§ãåšå²ã®4ã€ã®åœããã®å©çšè
ãçµ¶ããŸããã仿¥ã¯ééèšå¿µæ¥ãšããããšã§ãããŒã ã«åº§ã£ãŠãã人ãã¡ã«ç¹å¥ãªããšãããŠãããããšæã£ãŠããŸãããã®ããã«ã¯ãæ¹æãéã£ã人ãã¡ãã©ãã«åº§ã£ãŠãããææ¡ããªããã°ãªããŸããã4ã€ã®åœã®äººãã¡ã®é£åãªæ§æ Œãèæ
®ããŠãæ€
åãã©ã®ããã«åãŸã£ãŠããããã·ãã¥ã¬ãŒãããããã°ã©ã ãäœæããŠãã ãããæ¹æãéã£ã人ãã¡ã¯ã次ã
ã«äžåã«äžŠãã æ€
åã«åº§ã£ãŠãããŸãã4ã€ã®åœã®äººãã¡ã¯ãåœããšã«æ±ºãŸã£ãæ§æ Œãšåº§ãæ¹ããããŸããããããã®åº§ãæ¹ã¯ä»¥äžã®éãã§ãã Aåœäººã®æ§æ Œ A åœäººã¯åº§ããã°ããã巊端ããèŠãŠãã空ããŠããæ€
åã«åº§ãã Båœäººã®æ§æ Œ B åœäººã¯ A åœäººãèŠæã A åœäººã®é£ä»¥å€ã§ãå³ç«¯ãã空ããŠããæ€
åã«åº§ãããã ãã Aåœäººã®é£ãã空ããŠããªãå Žåãææ
¢ããŠå·Šç«¯ãã空ããŠããæ€
åã«åº§ãã Cåœäººã®æ§æ Œ C åœäººã¯äººã®é£ã«åº§ããããå·ŠåŽããé ã«åº§ã£ãŠãã人ãèŠãŠãããäžçªå·ŠåŽã«åº§ã£ãŠãã人 ã®å³é£ã«åº§ãããšãããããããåãŸã£ãŠãããªããã®äººã®å·Šé£ã«åº§ãããšããããããåãŸã£ ãŠãããªã次ã®äººã®é£ã«åæ¡ä»¶ã§åº§ãããšãããã©ã®æ€
åã«ã人ã座ã£ãŠããªããã°çãäž(æ€
åã®æ° n ã奿°ã®å Žå ( n +1)/2 ãå¶æ°ã®å Žå n /2+1 )ã®æ€
åã«åº§ãã Dåœäººã®æ§æ Œ D åœäººã¯äººã®é£ã«åº§ããããªããäžçªè¿ã人ãšã®è·é¢ããäžçªå€§ãããªãæ€
åã«åº§ãããšãããåæ¡ä»¶ã®æ€
åãè€æ°ããå Žåããã©ãããŠã誰ãã®é£ã«åº§ããªããã°ãªããªãå Žåããã®äžã§äžçªå·ŠåŽã«ããæ€
åã«åº§ãã誰ã座ã£ãŠããªãå Žåã¯å·Šç«¯ã®æ€
åã«åº§ãã ãã³ãã€å·ã«ä¹ãããšããŠããä¹å®¢ã®æ
å ±ãå
¥åãšãã æ€
åã«ã©ã®ããã«åº§ã£ãŠããããåºåããããã°ã©ã ãäœæããŠãã ãããå·Šããé çªã«åº§ã£ãŠãã人ã®åœç±ãåºåããŸãããã ãã空åžã®å Žå㯠# (åè§ã·ã£ãŒã)ãåºåããŠãã ããã Input è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸãã å
¥åã®çµããã¯ãŒããµãã€ã®è¡ã§ç€ºãããŸãã åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã n m a 1 a 2 : a m 1 è¡ç®ã«æ€
åã®æ° n (1 †n †100) ãšä¹å®¢ã®æ° m ( m †n ) ãäžããããŸããç¶ã m è¡ã« i 人ç®ã®æ
å ± a i ãäžããããŸãã a i ã¯ïŒã€ã®æåã§ã'A' ãªãã° A åœäººã'B' ãªãã° B åœäººã'C' ãªãã° C åœäººã'D' ãªãã° D åœäººã衚ããŸãã ããŒã¿ã»ããã®æ°ã¯ 100 ãè¶
ããŸããã Output ããŒã¿ã»ããããšã«ãæçµçãªæ€
åã®ç¶æ
ãïŒè¡ã«åºåããŸãã Sample Input 5 4 A B C D 5 4 D C B A 0 0 Output for the Sample Input ACD#B DCA#B | 39,133 |
ååã®èªæžææ³æ ååã®ã¢ããšãããéãåŠæ ¡ã§ã¯æ©ããå€äŒã¿ã«çªå
¥ãïŒä»å¹Žããã³ãã ããéã®å®¿é¡ãåºãããïŒ ãããïŒéã³çãã®2人ã¯ä»æ¥ã宿é¡ã«ã¯äžåæãã€ããã«å€ãžéã³ã«è¡ãããšããŠããïŒ ãã®ãŸãŸã§ã¯å€äŒã¿æçµæ¥ã«æ³£ããèŠãã®ã¯æãããªã®ã§ïŒä¿è·è
圹ã®ããªãã¯ïŒå¿ã鬌ã«ããŠä»æ¥ã¯èªæžææ³æã®å®¿é¡ãçµãããŸã§2人ãå®¶ããåºããªãããšã«ããïŒ æºåã®è¯ãããªãã¯æ¢ã«å³æžé€šããå
šãŠã®èª²é¡å³æžãåããŠããïŒ ãã ãïŒå³æžé€šã®èŠåã«ãã忬ã¯1åãã€ããåããããŠããªãïŒ ããŠïŒæè²äžã®çç±ãã2人ã«ã¯äºãã«ååããããšãªãïŒããããå
šãŠã®æ¬ãèªã¿ïŒææ³ãæžããŠãããäºã«ããïŒ å ããŠïŒæ¬ã®è¿åŽæéãè¿ãããïŒãŸãã¯ãªãã¹ãæ©ããã¹ãŠã®æ¬ãèªã¿çµããããã«ããŠãããäºã«ããïŒ ãããŠïŒããªãã¯ãã®æ¡ä»¶äžã§ãªãã¹ãæ©ã宿é¡ãçµãããããªå®¿é¡ã®é²ãæ¹ãèããããšã«ããïŒ ããã§ïŒæ¬ãèªã¿çµããæéïŒå®¿é¡ãçµããæéã¯ïŒããããååã®äž¡æ¹ãäœæ¥ãçµããæéã§èããïŒ åæ¬ã¯1åãã€ãããªãããïŒ2人ãåæå»ã«åãæ¬ãèªãããšã¯ã§ããªãïŒ å ããŠïŒå€§äººã®äºæ
ã«ããïŒããæ¬ãèªã¿å§ããããããäžæããäºã¯ã§ããïŒããæ¬ã«ã€ããŠã®ææ³æãæžãå§ããããããäžæããããšãã§ããªãïŒ åœç¶ãªããïŒèªãã§ããªãæ¬ã«ã€ããŠææ³ãæžãããšãã§ããªãïŒ ãªãïŒã¢ããšããã¯ååã§ããããïŒåæ¬ã«ã€ããŠèªãã®ã«ãããæéïŒææ³æãæžãã®ã«ãããæéã¯2人ã§å
±éããŠããïŒ äŸãã°ïŒ3åã®æ¬ãããïŒããããæ¬ãèªãã®ã«ãããæéïŒææ³æãæžãã®ã«ãããæéã以äžã®éãã§ãããšããïŒ æ¬ãèªãæé ææ³æãæžãæé æ¬1 5 3 æ¬2 1 2 æ¬3 1 2 ãã®å Žåã¯ïŒå³C-1ã®ããã«å®¿é¡ãé²ãããšïŒæé10ã§å
šãŠã®æ¬ãèªã¿çµãïŒæé15ã§å®¿é¡ãçµããäºãã§ããïŒ å³C-2ã®é²ãæ¹ã§ã¯æé14ã§å®¿é¡ãçµããŠãããïŒæ¬ãèªã¿çµããæéãæçã§ãªãããïŒä»åã¯æ¡çšã§ããªãïŒ ãŸãïŒå³C-3ã®ããã«2人ãåæã«åãæ¬ãèªãã ãïŒ å³C-4ã®ããã«æ¬ãèªãã®ãäžæãããïŒèªãã§ããªãæ¬ã®ææ³ãæžãäºãã§ããªãïŒ å³ C-1: æçã§å®¿é¡ãçµããããé²ãæ¹ã®äŸ å³ C-2: æ¬ãèªã¿çµããæéãæçã§ãªãäŸ å³ C-3: 2人ãåæã«åãæ¬ãèªãã§ããŸã£ãŠããäŸ å³ C-4: èªãã§ããªãæ¬ã®ææ³ãæžãããïŒäœæ¥ãäžæãããããŠããäŸ æ§ã
ãªå€§äººã®äºæ
ãèæ
®ãã€ã€ïŒéã³ã«è¡ãããã£ãŠããååã®ããã«ãªãã¹ãæ©ã宿é¡ãçµãããããªé²ãæ¹ãèããŠããããïŒ Input å
¥åã¯è€æ°ã®ããŒã¿ã»ããããæ§æãããïŒåããŒã¿ã»ããã®åœ¢åŒã¯æ¬¡ã®éãã§ããïŒ N r 1 w 1 r 2 w 2 ... r N w N Nã¯èª²é¡å³æžã®æ°ãè¡šãæŽæ°ã§ããïŒ1以äž1,000以äžãšä»®å®ããŠè¯ãïŒ ç¶ãNè¡ã¯èª²é¡å³æžã«ã€ããŠã®æ
å ±ã衚ãïŒ åè¡ã¯ã¹ããŒã¹ã§åºåããã2ã€ã®æŽæ°ãå«ã¿ïŒr i (1 †r i †1,000) 㯠i çªç®ã®æ¬ãèªãã®ã«ãããæéïŒw i (1 †w i †1,000) 㯠i çªç®ã®æ¬ã®ææ³æãæžãã®ã«ãããæéã衚ãïŒ N=0 ã¯å
¥åã®çµããã瀺ãïŒ ããã¯ããŒã¿ã»ããã«ã¯å«ããªãïŒ Output åããŒã¿ã»ããã«ã€ããŠïŒ2人ãå
šãŠã®æ¬ãèªã¿çµãããŸã§ã®æéãæå°ã«ãããšãã®ïŒå
šãŠã®ææ³æãæžãçµãããŸã§ã®æå°ã®æéã1è¡ã«åºåããªããïŒ Sample Input 4 1 1 3 1 4 1 2 1 3 5 3 1 2 1 2 1 1000 1000 10 5 62 10 68 15 72 20 73 25 75 30 77 35 79 40 82 45 100 815 283 6 74 78 53 55 77 77 12 13 39 42 1 1 0 Output for Sample Input 14 15 3000 2013 522 | 39,134 |
Problem G: Flipping Parentheses A string consisting only of parentheses '(' and ')' is called balanced if it is one of the following. A string "()" is balanced. Concatenation of two balanced strings are balanced. When a string $s$ is balanced, so is the concatenation of three strings "(", $s$, and ")" in this order. Note that the condition is stronger than merely the numbers of '(' and ')' are equal. For instance, "())(()" is not balanced. Your task is to keep a string in a balanced state, under a severe condition in which a cosmic ray may flip the direction of parentheses. You are initially given a balanced string. Each time the direction of a single parenthesis is flipped, your program is notified the position of the changed character in the string. Then, calculate and output the leftmost position that, if the parenthesis there is flipped, the whole string gets back to the balanced state. After the string is balanced by changing the parenthesis indicated by your program, next cosmic ray flips another parenthesis, and the steps are repeated several times. Input The input consists of a single test case formatted as follows. $N$ $Q$ $s$ $q_1$ . . . $q_Q$ The first line consists of two integers $N$ and $Q$ ($2 \leq N \leq 300000$, $1 \leq Q \leq 150000$). The second line is a string $s$ of balanced parentheses with length $N$. Each of the following $Q$ lines is an integer $q_i$ ($1 \leq q_i \leq N$) that indicates that the direction of the $q_i$-th parenthesis is flipped. Output For each event $q_i$, output the position of the leftmost parenthesis you need to flip in order to get back to the balanced state. Note that each input flipping event $q_i$ is applied to the string after the previous flip $q_{iâ1}$ and its fix. Sample Input 1 6 3 ((())) 4 3 1 Sample Output 1 2 2 1 Sample Input 2 20 9 ()((((()))))()()()() 15 20 13 5 3 10 3 17 18 Sample Output 2 2 20 8 5 3 2 2 3 18 In the first sample, the initial state is "((()))". The 4th parenthesis is flipped and the string becomes "(((())". Then, to keep the balance you should flip the 2nd parenthesis and get "()(())". The next flip of the 3rd parenthesis is applied to the last state and yields "())())". To rebalance it, you have to change the 2nd parenthesis again yielding "(()())". | 39,135 |
Problem F: Shore Erosion ããªãã¯å°å
ã®åžåœ¹æã«å€ããããã°ã©ããŒã§ããïŒããªãã®äœãã§ããçºã¯èгå
æ¥ãçãã§ïŒãšãã«é¢ãå°å³¶ã«ããæµ·å²žã®æµ·æ°ŽæµŽå Žã人æ°ãããïŒãã®å³¶ã®åšå²ã¯ç æµã«ããæ§æãããŠããã®ã ãïŒè¿å¹Žæµ·å²žæµžé£ã«ãã£ãŠç æµã®é¢ç©ãæžã£ãŠããïŒäºæ
ãéãèŠã芳å
課ã¯ïŒããªãã«ç æµã®åœ¢ç¶å€åã®ã·ãã¥ã¬ãŒã·ã§ã³ãäŸé ŒããŠããïŒ ã·ãã¥ã¬ãŒã·ã§ã³ã§ã¯ïŒçŸåšã®ç æµã®åœ¢ç¶ãããšã«ïŒããæéãçµéããåŸã®ç æµã®åœ¢ç¶ãæ±ããïŒç°¡åã®ããïŒå³¶ã®æµ·å²žç·ã®åœ¢ç¶ã¯å€è§åœ¢ïŒåžãšã¯éããªãïŒãšã¿ãªãïŒæéã®ãã¡ã«ïŒç æµã¯çŸåšã®æµ·å²žç·ãããã³ããã¿ã³è·é¢ã§ R ã ãæµžé£ãããŠæµ·ã«æ²ããã®ãšä»®å®ããïŒããã§ïŒãã³ããã¿ã³è·é¢ãšã¯ x 座æšå士ã®å·®ãš y 座æšå士ã®å·®ãè¶³ãããã®ã§ããïŒããªãã¡ïŒ( x 1 , y 1 ) ãš ( x 2 , y 2 ) ã®ãã³ããã¿ã³è·é¢ã¯ | x 1 - x 2 | + | y 1 - y 2 | ã§äžããããïŒ ããªãã®ä»äºã¯ïŒå
¥åãšããŠäžããããç æµã®æµ·å²žç·ããïŒã·ãã¥ã¬ãŒã·ã§ã³ã®çµæãšããŠåŸãããæµ·å²žç·ã®é·ããæ±ããããã°ã©ã ãæžãããšã§ããïŒãªãïŒå³¶ã海岞浞é£ã«ãã 2 ã€ä»¥äžã«åå²ãããå Žåã¯ïŒåå²ãããããããã®å³¶ã«ã€ããŠæµ·å²žç·ã®é·ããæ±ããŠïŒãããã®åãåºåããããšïŒ ãªãïŒæµ·å²žç·ã«å«ãŸãã 2 æ¬ã®ç·åã«ã€ããŠïŒå¹³è¡ã§ãã€ãã³ããã¿ã³è·é¢ãã¡ããã© 2 R ã«ãªãããšã¯ãªãïŒ Input å
¥åã¯ïŒè€æ°ã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯æ¬¡ã®åœ¢åŒã§äžããããïŒ N R x 1 y 1 x 2 y 2 ... x N y N æåã®è¡ã§ã¯ 2 ã€ã®éè² ã®æŽæ° N (3 †N †100)ïŒ R (0 < R †100) ãäžããããïŒ ãããã®æŽæ°ã¯ïŒããããæµ·å²žç·ã®é ç¹æ°ãšæµžé£ãããè·é¢ã衚ãïŒ ç¶ã N è¡ã§ã¯é ç¹ã®æ
å ±ãåè¡ã« 1 ã€ãã€äžããããïŒ é ç¹ã®æ
å ±ã¯ 2 ã€ã®æŽæ° x i , y i (-10000 †x i , y i †10000) ã§äžããããïŒ åº§æš ( x i , y i ) ã¯ïŒããããæµ·å²žç·ã® i çªç®ã®é ç¹ã®åº§æšã衚ãïŒ ãªãïŒå³¶ã®é ç¹åº§æšã¯åžžã«åæèšåãã§äžããããïŒ å
¥åã®çµããã¯ïŒç©ºçœã§åºåããã 2 ã€ã® 0 ãå«ã 1 è¡ã§ç€ºãããïŒ Output åããŒã¿ã»ããã«å¯ŸããŠïŒæµžé£ãããæµ·å²žç·ã®é·ããåºåããïŒãªãïŒå³¶ãå®å
šã«æµžé£ããæ¶å€±ããå Žåã¯æµ·å²žç·ã®é·ã㯠0.0 ãšæ±ãããšïŒåºåããå€ã¯ 0.01 以äžã®èª€å·®ãå«ãã§ããŠãæ§ããªãïŒãŸãïŒå€ã¯å°æ°ç¹ä»¥äžäœæ¡è¡šç€ºããŠãæ§ããªãïŒ Sample Input 3 1 0 0 10 0 5 10 3 1 0 0 10 0 0 10 4 1 0 0 10 0 10 10 0 10 0 0 Output for the Sample Input 22.6524758425 23.8994949366 32.0000000000 | 39,136 |
I - Tokyo Olympics Center Problem Statement You are participating in the Summer Training Camp for Programming Cotests. The camp is held in an accommodation facility called Tokyo Olympics Center . Today is the last day of the camp. Unfortunately, you are ordered to check if all the participants have properly cleaned their rooms. The accommodation facility is a rectangular field whose height is $H$ and width is $W$. The field is divided into square cells. The rows are numbered $1$ through $H$ from top to bottom and the columns are numbered $1$ through $W$ from left to right. The cell in row $i$, column $j$ is denoted by $(i, j)$. Two cells are adjacent if they share an edge. Each cell is called either a wall cell or a floor cell . A wall cell represents a wall which no one can enter. A floor cell is a part of the inside of the accommodation facility. Everybody can move between two adjacent floor cells. The floor cells are divided into several units. Each unit is assigned an uppercase English letter ( A , B , C , ...). A floor cell adjacent to exactly one floor cell is called a room . Otherwise the floor cell is called an aisle . For example, the accommodation facility can be shown as the following figure. We denote a wall cell by . (single period). ................... .....AAABBBBBBB.... ...A.AA.A...B.B..B. ..AAAAAAAABBBBBBBB. ...A..A.A.....B.... ......A.......BBBB. ....A.AA..C.C...B.. ...AAAAACCCCCCBBBB. ...A..A...C.C...B.. ................... In the above figure, there are $7$ rooms in unit A, $4$ rooms in unit B, and $4$ rooms in unit C. Because the accommodation facility is too large to explore alone, you asked the other participants of the camp to check the rooms. For simplicity's sake, we call them staffs . Now, there are $K$ staffs at the cell $(s, t)$. You decided to check the rooms according to the following procedure. First, you assign each staff to some of units. Every unit must be assigned to exactly one staff. Note that it is allowed to assign all the units to one staff or to assign no units to some staffs. Then, each staff starts to check the rooms in the assigned units at the same time. The staffs can move between two adjacent floor cells in $T_{\mathit{move}}$ time. To check the room at $(i, j)$, the staffs must move to the cell $(i, j)$ and spend $T_{\mathit{check}}$ time there. Each staff first determines the order of the units to check and he or she must check the rooms according to the order. For example, suppose that there is a staff who is assigned units A, C, and E. He may decide that the order is E->A->C. After that, he must check all the rooms in unit E at first. Then, he must check all the rooms in unit A, and so on. The staffs can pass any floor cells. However, the staffs cannot check rooms that are not assigned to them. Further, the staffs cannot check rooms against the order of units that they have decided. After checking all the assigned rooms, the staffs must return to the cell $(s, t)$. When every staff returns to the cell $(s, t)$, the task is done. Because you do not have enough time before the next contest, you want to minimize the total time to check all the rooms. Input The first line of the input contains three integers $H$, $W$, and $K$ ($1 \le H \le 50$, $1 \le W \le 50$, $1 \le K \le 12$). The second line contains four integers $s$, $t$, $T_{\mathit{move}}$, and $T_{\mathit{check}}$ ($1 \le s \le H$, $1 \le t \le W$, $1 \le T_{\mathit{move}},T_{\mathit{check}} \le 10{,}000$). Each of the following $H$ lines contains exactly $W$ characters. Each character represents a cell in the accommodation facility. The $j$-th character in the $i$-th line of these lines is . if the cell $(i, j)$ is a wall cell. Otherwise, the character is an uppercase English letter ( A - L ) representing the unit to which the cell $(i, j)$ belongs. You can assume that the following conditions are satisfied. The number of rooms in each unit is between $1$ and $12$, inclusive. The cell $(s, t)$ is guaranteed to be an aisle. Floor cells in each unit are connected. Floor cells in the field are connected. Every unit contains at least two cells. Output Output the minimum required time to check all the rooms in one line. Sample Input 1 3 3 1 1 1 10 10 AAA A.. A.. Output for the Sample Input 1 100 Sample Input 2 3 3 2 1 1 10 10 ABB A.. A.. Output for the Sample Input 2 50 Sample Input 3 5 10 3 3 6 1 100 ...G.H.A.. .AAGAHAABB FFAAAAAAA. .EEAAADACC ..E...D... Output for the Sample Input 3 316 Sample Input 4 10 19 2 6 15 3 10 ................... .....AAABBBBBBB.... ...A.AA.A...B.B..B. ..AAAAAAAABBBBBBBB. ...A..A.A.....B.... ......A.......BBBB. ....A.AA..C.C...B.. ...AAAAACCCCCCBBBB. ...A..A...C.C...B.. ................... Output for the Sample Input 4 232 Sample Input 5 27 36 6 24 19 616 1933 .................................... ..........B...............B......... ..........BBB..........BBBB......... ..........BBBBB.......BBBB.......... ...........BBBBBBBBBBBBBBB.......... ...........BBBBBBBBBBBBBBB.......... ...........BBBBBBBBBBBBBB........... ............BBBBBBBBBBBBB........... ...........BBBBBBBBBBBBBBB.......... ..........BBBBBBBBBBBBBBBBB......... ......B...BBBBBBBBBBBBBBBBB...B..... ......BB.BBBBBBBBBBBBBBBBBB..BB..... .......BBBBBBBBBBBBBBBBBBBB.BB...... .........BBBBBBBBBBBBBBBBBBBB....... ........BBBBB..BBBBBBBB..BBBBB...... ......BBBBBB....BBBBB....BBBBBB..... .....BBBBBBBB...BBBBB..BBBBBBBB.B... ...BBBBBBB..B...BBBBB..B..BBBBBBBB.. .BBBBBBBBB.....BBBBBBB......BBBBBBB. ..BBBBBBB......BBBBBBB........BBB... .BBBB.........BBBBBBBBB........BBB.. ..............BBBBBBBBB............. .............BBBBBBBBBB............. .............BBBBBBBBBB............. ..............BBBBBBBB.............. ..............BBBBBBBB.............. .................................... Output for the Sample Input 5 137071 | 39,137 |
Barter Problem ãããåã¯ãããŸãæ£ã x æ¬ããµããã y æ¬æã£ãŠããã n 人ã®ãèå亀æäººãããã ããããã®äº€æäºº i ã¯ã ãããåã®ããŸãæ£ a i æ¬ãšäº€æäººã®ãµãã b i æ¬ ãããåã®ãµãã c i æ¬ãšäº€æäººã®ãã¿ã¡ãœ d i å ã®ã©ã¡ãã1ã€ã®æ¹æ³ã§1åã ã亀æããŠãããã ãã®å¶çŽã®äžã§ãæçµçã«ææããŠãããã¿ã¡ãœã®åæ°ãæå€§åããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã n x y a 1 b 1 c 1 d 1 a 2 b 2 c 2 d 2 ... a n b n c n d n 1è¡ç®ã«æŽæ° n ãäžããããã 2è¡ç®ã«æŽæ° x , y ã空çœåºåãã§äžããããã 3è¡ç®ãã n +2è¡ç®ã«æŽæ° a i , b i , c i , d i ã空çœåºåãã§äžããããã Constraints 1 †n †100 0 †x , y †300 1 †a i , b i , c i , d i †300 \(\sum_{i=1}^na_i\) †300, \(\sum_{i=1}^nb_i\) †300, \(\sum_{i=1}^nc_i\) †300, \(\sum_{i=1}^nd_i\) †300 Output æçµçã«ãããåãææããŠãããã¿ã¡ãœã®åæ°ã®æå€§å€ã1è¡ã«åºåãã Sample Input 1 3 3 3 3 2 4 1 5 1 2 1 3 1 3 2 Sample Output 1 3 Sample Input 2 3 3 4 3 1 3 1 3 1 4 1 3 1 2 1 Sample Output 2 2 Sample Input 3 4 5 0 5 1 1 1 2 1 2 1 4 1 1 1 3 1 3 1 Sample Output 3 2 Sample Input 4 4 0 0 1 10 1 10 2 5 2 5 3 25 5 6 1 15 2 20 Sample Output 4 0 | 39,138 |
Score : 2200 points Problem Statement You are given a tree T with N vertices and an undirected graph G with N vertices and M edges. The vertices of each graph are numbered 1 to N . The i -th of the N-1 edges in T connects Vertex a_i and Vertex b_i , and the j -th of the M edges in G connects Vertex c_j and Vertex d_j . Consider adding edges to G by repeatedly performing the following operation: Choose three integers a , b and c such that G has an edge connecting Vertex a and b and an edge connecting Vertex b and c but not an edge connecting Vertex a and c . If there is a simple path in T that contains all three of Vertex a, b and c in some order, add an edge in G connecting Vertex a and c . Print the number of edges in G when no more edge can be added. It can be shown that this number does not depend on the choices made in the operation. Constraints 2 \leq N \leq 2000 1 \leq M \leq 2000 1 \leq a_i, b_i \leq N a_i \neq b_i 1 \leq c_j, d_j \leq N c_j \neq d_j G does not contain multiple edges. T is a tree. Input Input is given from Standard Input in the following format: N M a_1 b_1 : a_{N-1} b_{N-1} c_1 d_1 : c_M d_M Output Print the final number of edges in G . Sample Input 1 5 3 1 2 1 3 3 4 1 5 5 4 2 5 1 5 Sample Output 1 6 We can have at most six edges in G by adding edges as follows: Let (a,b,c)=(1,5,4) and add an edge connecting Vertex 1 and 4 . Let (a,b,c)=(1,5,2) and add an edge connecting Vertex 1 and 2 . Let (a,b,c)=(2,1,4) and add an edge connecting Vertex 2 and 4 . Sample Input 2 7 5 1 5 1 4 1 7 1 2 2 6 6 3 2 5 1 3 1 6 4 6 4 7 Sample Output 2 11 Sample Input 3 13 11 6 13 1 2 5 1 8 4 9 7 12 2 10 11 1 9 13 7 13 11 8 10 3 8 4 13 8 12 4 7 2 3 5 11 1 4 2 11 8 10 3 5 6 9 4 10 Sample Output 3 27 | 39,139 |
å顿 ãã¥ã¥ã¹ã ã¯ã¯ã«ãã«ã®ã¹ã®å€ã«åããŠé女ã®åæã«æãæ®ããŠããïŒã¯ã«ãã«ã®ã¹ã®å€ã®ããã«ïŒç¹å¥ãª ã°ãªãŒãã·ãŒã (é女ã®åµ) ã䜿ã£ãŠæã«å
¥ããããé女ãããŸãåæãç®çã§ããèå°è£
眮ã®é女ãåµãäžããªããã°ãªããªãããã§ããïŒ ãã¥ã¥ã¹ã ã¯æã«å
¥ããããçš®é¡ã®é女㮠ã°ãªãŒãã·ãŒã ããé女ã®çŽ ãšãªããã®ãåãåºãïŒç©ºã®ç¹å¥ãª ã°ãªãŒãã·ãŒã ã«å
¥ããããšã§ïŒãã® ã°ãªãŒãã·ãŒã ã«é女ã宿ãããããšãã§ããïŒãŸãïŒãã®äžçã«ã¯ïŒããçµã¿åããã§è€æ°ã®é女ãåæãããšæ°ã㪠1 ã€ã®é女ãçã¿åºãããšãã§ãããšããåææ³åãããã€ãããïŒããã§ïŒããã€ãã®ç¹å¥ãª ã°ãªãŒãã·ãŒã ã䜿ãïŒãããã®äžã«ããé女ã®çŽ ãšãªããã®ãåæãïŒ 1 ã€ã®ç¹å¥ãª ã°ãªãŒãã·ãŒã ã«æ°ããªé女ã宿ãããããšãã§ããïŒãŸãïŒåæããçµæç©ºãšãªã£ãç¹å¥ãª ã°ãªãŒãã·ãŒã ã¯åå©çšããããšãã§ããïŒäŸãã°ïŒ 3 åã®ç¹å¥ãª ã°ãªãŒãã·ãŒã ã«å
¥ã£ãé女ãåæãããšïŒãããã® 3 åã® ã°ãªãŒãã·ãŒã ã¯ïŒæ°ããªé女ã宿ã£ã 1 åã®ç¹å¥ãª ã°ãªãŒãã·ãŒã ãš 2 åã®ç©ºã®ç¹å¥ãª ã°ãªãŒãã·ãŒã ãšãªãïŒãããïŒåãçš®é¡ã®é女ãåæã«è€æ°ã® ã°ãªãŒãã·ãŒã ã«å
¥ããããšã¯åºæ¥ãªãïŒ ãã¥ã¥ã¹ã ã¯é女ã®ç¹å¥ãª ã°ãªãŒãã·ãŒã ãžã®å¯å®¿ãšé女ã®åæãç¹°ãè¿ãããšã«ããèå°è£
眮ã®é女ãåµãã ãããïŒèå°è£
眮ã®é女ãåµãã ãã«ã¯ããã€ã®ç¹å¥ãª ã°ãªãŒãã·ãŒã ãå¿
èŠãæ±ããïŒ å
¥ååœ¢åŒ å
¥åã¯ä»¥äžã®ãããªåœ¢åŒã§äžããããïŒ N\ E\ T\\ W_1\ W_2\ âŠ\ W_N\\ G_1\ C_1\ S_{1,1}\ S_{1,2}\ âŠ\ S_{1,C_1}\\ G_2\ C_2\ S_{2,1}\ S_{2,2}\ âŠ\ S_{2,C_2}\\ âŠ\\ G_E\ C_E\ S_{E,1}\ S_{E,2}\ âŠ\ S_{E,C_E}\\ N ã¯é女ã®çš®é¡ã®åæ°ïŒ E ã¯åææ³åã®åæ°ïŒ T ã¯èå°è£
眮ã®é女ã®çªå·ã§ããïŒ W_i 㯠i çªç®ã®é女ãæã«å
¥ããããé女ã§ãããã©ããã衚ãïŒ 1 ãªãã°æã«å
¥ããããé女ã§ããïŒ 0 ãªãã°æã«å
¥ããããé女ã§ã¯ãªãïŒ ç¶ã E è¡ã«åææ³åãæ¬¡ã®ããã«è¡šãããïŒãçªå·ã S_{i,1}\ S_{i,2}\ âŠ\ S_{i,C_i} ã®é女ãåæããããšã«ãã£ãŠ G_i ã®çªå·ã®é女ãåŸãããïŒã åºååœ¢åŒ èå°è£
眮ã®é女ãåµãã ãã®ã«æäœéå¿
èŠãªç¹å¥ãª ã°ãªãŒãã·ãŒã ã®åæ°ãåºåããïŒåµãã ãããšãã§ããªãå Žå㯠-1 ãåºåããïŒ å¶çŽ 1 \lt N \leq 300 0 \leq E \leq 1000 1 \leq T \leq N 0 \leq W_i \leq 1\ (1 \leq i \leq N) 1 \leq G_i \leq N\ (1 \leq i \leq E) 2 \leq C_i \leq 10\ (1 \leq i \leq E) 1 \leq S_{i,j} \leq N\ (1 \leq i \leq E,\ 1 \leq j \leq C_i) \{G_i, S_{i,1}\ S_{i,2}\ âŠ\ S_{i,C_i}\} ã¯å
šãŠç°ãªãïŒ å
¥åäžã«åäžã®åææ³åã 2 å以äžçŸããããšã¯ãªãïŒ å
¥åºåäŸ å
¥åäŸ 1 3 1 3 1 1 0 3 2 1 2 åºåäŸ1 2 å
¥åäŸ 2 5 0 1 1 1 1 1 1 åºåäŸ 2 1 å
¥åäŸ 3 18 5 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4 2 3 4 5 2 2 6 7 3 3 8 9 10 4 4 11 12 13 14 5 4 15 16 17 18 åºåäŸ 3 5 å
¥åäŸ 4 6 4 6 1 1 1 0 0 0 4 2 1 2 5 2 2 3 6 2 4 5 6 3 1 2 4 åºåäŸ 4 3 å
¥åäŸ 5 13 9 13 1 1 0 1 1 0 1 1 0 1 1 0 0 3 2 1 2 6 2 4 5 9 2 7 8 12 2 10 11 6 2 2 3 9 2 5 6 12 2 8 9 3 2 11 12 13 4 3 6 9 12 åºåäŸ 5 5 å
¥åäŸ 6 4 4 4 1 1 0 0 1 2 2 3 2 2 3 1 3 2 1 2 3 3 1 2 4 åºåäŸ 6 -1 Problem Setter: Flat35 | 39,140 |
Score : 200 points Problem Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i -th blue card is s_i , and the string written on the i -th red card is t_i . Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces atcoder , he will not earn money even if there are blue cards with atcoderr , atcode , btcoder , and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards. Constraints N and M are integers. 1 \leq N, M \leq 100 s_1, s_2, ..., s_N, t_1, t_2, ..., t_M are all strings of lengths between 1 and 10 (inclusive) consisting of lowercase English letters. Input Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M Output If Takahashi can earn at most X yen on balance, print X . Sample Input 1 3 apple orange apple 1 grape Sample Output 1 2 He can earn 2 yen by announcing apple . Sample Input 2 3 apple orange apple 5 apple apple apple apple apple Sample Output 2 1 If he announces apple , he will lose 3 yen. If he announces orange , he can earn 1 yen. Sample Input 3 1 voldemort 10 voldemort voldemort voldemort voldemort voldemort voldemort voldemort voldemort voldemort voldemort Sample Output 3 0 If he announces voldemort , he will lose 9 yen. If he announces orange , for example, he can avoid losing a yen. Sample Input 4 6 red red blue yellow yellow red 5 red red yellow green blue Sample Output 4 1 | 39,141 |
Conveyor Belt Awesome Conveyor Machine (ACM) is the most important equipment of a factory of Industrial Conveyor Product Corporation (ICPC). ACM has a long conveyor belt to deliver their products from some points to other points. You are a programmer hired to make efficient schedule plan for product delivery. ACM's conveyor belt goes through $N$ points at equal intervals. The conveyor has plates on each of which at most one product can be put. Initially, there are no plates at any points. The conveyor belt moves by exactly one plate length per unit time; after one second, a plate is at position 1 while there are no plates at the other positions. After further 1 seconds, the plate at position 1 is moved to position 2 and a new plate comes at position 1, and so on. Note that the conveyor has the unlimited number of plates: after $N$ seconds or later, each of the $N$ positions has exactly one plate. A delivery task is represented by positions $a$ and $b$; delivery is accomplished by putting a product on a plate on the belt at $a$, and retrieving it at $b$ after $b - a$ seconds ($a < b$). (Of course, it is necessary that an empty plate exists at the position at the putting time.) In addition, putting and retrieving products must bedone in the following manner: When putting and retrieving a product, a plate must be located just at the position. That is, products must be put and retrieved at integer seconds. Putting and retrieving at the same position cannot be done at the same time. On the other hand, putting and retrieving at the different positions can be done at the same time. If there are several tasks, the time to finish all the tasks may be reduced by changing schedule when each product is put on the belt. Your job is to write a program minimizing the time to complete all the tasks... wait, wait. When have you started misunderstanding that you can know all the tasks initially? New delivery requests are coming moment by moment, like plates on the conveyor! So you should update your optimal schedule per every new request. A request consists of a start point $a$, a goal point $b$, and the number $p$ of products to deliver from $a$ to $b$. Delivery requests will be added $Q$ times. Your (true) job is to write a program such that for each $1 \leq i \leq Q$, minimizing the entire time to complete delivery tasks in requests 1 to $i$. Input The input consists of a single test case formatted as follows. $N$ $Q$ $a_1$ $b_1$ $p_1$ : $a_Q$ $b_Q$ $p_Q$ A first line includes two integers $N$ and $Q$ ($2 \leq N \leq 10^5, 1 \leq Q \leq 10^5$): $N$ is the number of positions the conveyor belt goes through and $Q$ is the number of requests will come. The $i$-th line of the following $Q$ lines consists of three integers $a_i, b_i,$ and $p_i$ ($1 \leq a_i < b_i \leq N, 1 \leq p_i \leq 10^9$), which mean that the $i$-th request requires $p_i$ products to be delivered from position $a_i$ to position $b_i$. Output In the $i$-th line, print the minimum time to complete all the tasks required by requests $1$ to $i$. Sample Input 1 5 2 1 4 1 2 3 1 Output for Sample Input 1 4 4 Sample Input 2 5 2 1 4 1 2 3 5 Output for Sample Input 2 4 8 Sample Input 3 5 2 1 3 3 3 5 1 Output for Sample Input 3 5 6 Sample Input 4 10 4 3 5 2 5 7 5 8 9 2 1 7 5 Output for Sample Input 4 6 11 11 16 Regarding the first example, the minimum time to complete only the first request is 4 seconds. All the two requests can be completed within 4 seconds too. See the below figure. | 39,142 |
Score : 800 points Problem Statement Given are N pairwise distinct non-negative integers A_1,A_2,\ldots,A_N . Find the number of ways to choose a set of between 1 and K numbers (inclusive) from the given numbers so that the following two conditions are satisfied: The bitwise AND of the chosen numbers is S . The bitwise OR of the chosen numbers is T . Constraints 1 \leq N \leq 50 1 \leq K \leq N 0 \leq A_i < 2^{18} 0 \leq S < 2^{18} 0 \leq T < 2^{18} A_i \neq A_j ( 1 \leq i < j \leq N ) Input Input is given from Standard Input in the following format: N K S T A_1 A_2 ... A_N Output Print the answer. Sample Input 1 3 3 0 3 1 2 3 Sample Output 1 2 The conditions are satisfied when we choose \{1,2\} or \{1,2,3\} . Sample Input 2 5 3 1 7 3 4 9 1 5 Sample Output 2 2 Sample Input 3 5 4 0 15 3 4 9 1 5 Sample Output 3 3 | 39,143 |
Problem F: Strawberry Cake äŒæŽ¥å€§åŠéå±å°åŠæ ¡ (äŒæŽ¥å€§å°) ã«å
¥åŠããã·ã£ãããããšãªãã³ãŒã¯ç«¶æããã°ã©ããšããŠæŽ»èºããããã« IPPC ãšããããã°ã©ãã³ã°ã³ã³ãã¹ãã«åºå Žããããšã«ãããããã IPPC 㯠3 人 1 çµã§ããŒã ãšããŠã³ã³ãã¹ãã«åºå Žããæ±ºãŸãã§ã4 人ã§ããŒã ãçµãããšã¯ã§ããªããããã§åœŒã㯠2 人ãã€ã«åãããŠããŒã ãçµã¿ã2 人 1 çµã§åå ã§ãã IPOCH ãšããããã°ã©ãã³ã°ã³ã³ãã¹ãã«åºå Žããããšã«ããã ããŒã ã¯åãããŠããŸã£ãããå®åã¯æ®æããŠããäºãã«è¯ãç·Žç¿çžæã«ãªã£ãŠããã ããæ¥åœŒãã®ã³ãŒããå·®ãå
¥ãã«ããŒã«ã±ãŒããè²·ã£ãŠããã圌ãã¯ãããã·ã£ã®å®¶ã§é£ã¹ãããšã«ããããããå®¶ã«çããŠç®±ãéããŠã¿ããšã±ãŒããå€åœ¢ããŠããŠã圢ã¯äžããèŠããšå圢ã§ã¯ãªãåžå€è§åœ¢ã®ããã«ãªã£ãŠãããããã«éã°ããã®ãæªãã£ãããã ã ã±ãŒãã®äžã«ã¯ã€ããŽã 1 ã€ä¹ã£ãŠããããšãããã 2 ããŒã ã§åããããã«ãããŸãã®ã±ãŒããã€ããŽãéãçŽç·ã«ãã£ãŠååã«ãªãããã«ãã€ãã§åãããšã決å®ãããã±ãŒããåãåã«ã€ããŽãå
ã«ãšã£ãŠããŸãã®ã¯åœŒãã®çŸæèã«åããã ããªãã®ä»äºã¯ 2 次å
å¹³é¢äžã«äžããããåžå€è§åœ¢ K ãåç¹ (0, 0) ãéãçŽç· L ã§åå²ãããšããåå²ã§åºæ¥ã 2 ã€ã®åžå€è§åœ¢ã®é¢ç©ãçãããªãããã«çŽç· L ãå®ããããšã§ãããããè€æ°ãããªãããããã²ãšã€ã§æ§ããªãã Input å
¥åã¯è€æ°ã®ãã¹ãã±ãŒã¹ãããªããåãã¹ãã±ãŒã¹ã¯ä»¥äžã®åœ¢åŒã«åŸãã N x 1 y 1 x 2 y 2 ... x N y N N ã¯äžããããåžå€è§åœ¢ K ã®é ç¹æ°ã§ãããç¹ (x i , y i ) ( 1 †i †N ) ã¯ãã¹ãŠåžå€è§åœ¢ K ãæãé ç¹ã®åº§æšã§ãããäºãã«ç°ãªãããããã¯åæèšåãã®é ã§äžããããããŸããåžå€è§åœ¢ K ã®ã©ã®èŸºäžã®ç¹ãåç¹ãšã®è·é¢ã 1 以äžã§ãåžå€è§åœ¢ K ã¯åžžã«åç¹ãå
å
ãããå
¥åã®çµäºã¯ã²ãšã€ã®0ãå«ãïŒè¡ã§ç€ºããããåç¹ãå«ããå
¥åã§äžããããç°ãªã 3 ç¹ã¯å
±ç·ãšãªãããããšã«æ³šæããŠæ¬²ããã Constraints å
¥åã¯ãã¹ãп޿° 3 †N †20 -100 †x i †100 ( 1 †i †N ) -100 †y i †100 ( 1 †i †N ) ãã¹ãã±ãŒã¹ã®æ°ã¯ 1,000 ãè¶
ããªãã Output 以äžã®åœ¢åŒã§çŽç· L äžã®ç¹ A (A x , A y ) ãåºåããããã ãç¹ A ãšåç¹ãšã®è·é¢ã¯ 1 以äžã§ãªããã°ãªããªãã A x A y åç¹ãšãã®ç¹ A ãéãçŽç·ã§åžå€è§åœ¢ K ãåå²ãããšã 2 ã€ã®åžå€è§åœ¢ã®é¢ç©ã®å·®ã 10 -5 æªæºã§ãªããã°ãªããªããç¹ A ã®åº§æšã¯å°æ°ç¹ä»¥äž 15 æ¡åºåããŠæ¬²ããã Sample Input 4 -100 -100 100 -100 100 100 -100 100 4 -99 -100 100 -100 100 100 -99 100 4 -100 -99 100 -99 100 100 -100 100 14 -99 -70 -92 -79 10 -98 37 -100 62 -95 77 -69 88 -47 92 -10 96 28 100 91 42 92 -62 92 -88 91 -98 64 0 Sample Output 100.000000000000000 0.000000000000000 100.000000000000000 0.000000000000000 0.000000000000000 100.000000000000000 -96.983291994836122 66.745111613942484 | 39,144 |
H: éæ³äœ¿ãã®å¡ å顿 ããªããæã£ãŠããéå°æžã«ã¯ã $N$ åã®éæ³ãèŒã£ãŠããŸãã éæ³ã«ã¯ $1$ ãã $N$ ãŸã§ã®çªå·ãã€ããŠããŠãéæ³ $i (1 \le i \le N)$ ã®ã³ã¹ãã¯ã¯ããæŽæ° $A_i$ ã§ãã ããªãã®ç®çã¯ãéå°æžã«èŒã£ãŠãããã¹ãŠã®éæ³ã $1$ åãã€å±ããããšã§ãã éæ³ãå±ãã¯ãããåã«ãããªãã¯ã¯ãããŒã $K$ æé£ã¹ãããšãã§ããŸããã¯ãããŒãé£ã¹ãã®ã«æéã¯ããããŸããã ããªãã¯ã¯ãããŒã $1$ æé£ã¹ããã³ã«ãã³ã¹ããæ£ã®éæ³ã $1$ ã€éžã³ããã®ã³ã¹ãã $1$ äžããããšãã§ããŸãã ã¯ãããŒãé£ã¹ãããšãããªãã¯éæ³ãå±ãå§ããŸãã ããªãã® MP ã¯ã¯ãã $M$ ã§ããããªãã¯ä»¥äžã®ã©ã¡ãããç¹°ãè¿ããŠã $N$ åã®éæ³ãä»»æã®é çªã§ $1$ åãã€å±ããŸãã æŽæ° $i (1 \le i \le N)$ ã $1$ ã€éžã³ãéæ³ $i$ ãå±ããããã ãã çŸåšã® MP ã¯éæ³ $i$ ã®ã³ã¹ã以äžã§ãªããã°ãªããªãã æéã¯çµéããªãã MP ãéæ³ $i$ ã®ã³ã¹ãã ãæ¶è²»ããã äŒæ©ããããã ããçŸåšã® MP ã $m$ ãšãããšã $m < M$ ã§ãªããã°ãªããªãã æéã $M - m$ çµéããã MP ã $1$ å埩ããã ããªãã $N$ åã®éæ³ãä»»æã®é çªã§ $1$ åãã€å±ããããã«ãããæéã®æå°å€ãæ±ããŠãã ããã å¶çŽ $1 \leq N \leq 10^5$ $1 \leq M \leq 10^6$ $0 \leq K \leq \sum_{i=1}^{N} A_i$ $1 \leq A_i \leq M$ å
¥åã¯ãã¹ãп޿°ã§ããã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããã $N$ $M$ $K$ $A_1$ $A_2$ $\ldots$ $A_N$ åºå $N$ åã®éæ³ã $1$ åãã€å±ããããã«ãããæéã®æå°å€ãåºåããã å
¥åäŸ1 2 4 0 2 4 åºåäŸ1 3 ã©ã®éæ³ã®ã³ã¹ããæžããããšãã§ããªãã®ã§ããã®ãŸãŸéæ³ãå±ããŠããããšã«ããŸãã ãŸããéæ³ $1$ ãå±ããŸãã MP ã $2$ æ¶è²»ããã®ã§ãæ®ãã® MP 㯠$4 - 2 = 2$ ã«ãªããŸãã éæ³ $2$ ãå±ããã«ã¯ MP ã $4$ å¿
èŠãªã®ã§ããã®ãŸãŸã§ã¯éæ³ $2$ ãå±ããããšã¯ã§ããŸããã äŒæ©ããŸããæéã $4 - 2 = 2$ ç§çµéããŸãã MP ã $1$ å埩ããã®ã§ãæ®ãã® MP 㯠$2 + 1 = 3$ ã«ãªããŸãã äŒæ©ããŸããæéã $4 - 3 = 1$ ç§çµéããŸãã MP ã $1$ å埩ããã®ã§ãæ®ãã® MP 㯠$3 + 1 = 4$ ã«ãªããŸãã éæ³ $2$ ãå±ããŸãã MP ã $4$ æ¶è²»ããã®ã§ãæ®ãã® MP 㯠$4 - 4 = 0$ ã«ãªããŸãã 以äžãããæéã $2 + 1 = 3$ ç§ãããã°ãéæ³ $1,2$ ã $1$ åãã€å±ããããšãã§ããŸãã ããããçãæéã§ãã¹ãŠã®éæ³ãå±ããããšã¯ã§ããªãã®ã§ãæ±ããçã㯠$3$ ãšãªããŸãã å
¥åäŸ2 3 9 6 2 3 9 åºåäŸ2 0 æçµçãªéæ³ã®ã³ã¹ãã $2, 2, 4$ ãšãããšãäŒæ©ããããšãªããã¹ãŠã®éæ³ãå±ããããšãã§ããŸãã å
¥åäŸ3 3 16 2 6 9 9 åºåäŸ3 21 å
¥åäŸ4 2 1000000 0 1000000 1000000 åºåäŸ4 500000500000 çã㯠32bit æŽæ°ã§è¡šããç¯å²ã«åãŸããªãããšããããŸãã | 39,145 |
èªè»¢è»ã§ãã€ãšãã A ããã¯çããã®ã倧奜ãã§ãããæè¿ã¯å¥¥ãããããã€ãšããããããã«èšãããŠããŸããããæ¥ãA ãããèªå®
ããåžåœ¹æã«åºããããšãã奥ããã¯èªè»¢è»ã§è¡ãããšãå§ããŸãããããã§A ããã¯ãã¶ãã¶èªè»¢è»ã«ä¹ã£ãŠåºãããŸããããçãç©ã®å¥œã㪠A ããã¯ãéäžã«ããã±ãŒãå±ããã«ç«ã¡å¯ãã±ãŒãã®é£ã¹æ©ããããããšæãã€ããŸããã èªè»¢è»ãããã°èµ°è¡è·é¢ã«å¿ããŠã«ããªãŒãæ¶è²»ãããŸãããã±ãŒããé£ã¹ãã°ãã®åã«ããªãŒãæåãããŸããæ£å³ã®æ¶è²»ã«ããªãŒã¯ãèªè»¢è»ãããã§æ¶è²»ããã«ããªãŒããã±ãŒããé£ã¹ãŠæåããã«ããªãŒãåŒããå€ã«ãªããŸãããããã£ãŠãæ£å³ã®æ¶è²»ã«ããªãŒã 0 ããå°ãããªãããšããããŸãã ã±ãŒãå±ããã§ã±ãŒããè²·ã£ããã Aããã¯ãã®å Žã§ã±ãŒããå
šéšé£ã¹ãŠããŸããŸãã Aããããã¹ãŠã®ã±ãŒãå±ããã«ç«ã¡å¯ããšã¯éããŸããããã±ãŒãå±ãããååšããå°ç¹ãéããšãã«ã¯ãå¿
ãç«ã¡å¯ã£ãŠã±ãŒãã 1 ã€è²·ã£ãŠé£ã¹ããã®ãšããŸãããã ããåãã±ãŒãå±ããã®åãäœåºŠãéãã®ã¯ãããã«æ°ãã²ããã®ã§ãåã±ãŒãå±ããã«èšªããããã®ã¯ 1 åã ããšããŸãããŸããç®çå°ã®åžåœ¹æããã£ããéãéããŠããã±ãŒãå±ããã«ç«ã¡å¯ãããã®åŸã§åžåœ¹æã«æ»ã£ãŠçšãæžãŸããŠããããã®ãšããã±ãŒãå±ãã以å€ã¯äœåºŠèšªããŠãè¯ããã®ãšããŸãã A ããã®èªå®
ããåžåœ¹æãŸã§ã®å°å³æ
å ±ãšããã®éäžã«ããã±ãŒãå±ããã§é£ã¹ãããã±ãŒãã®ã«ããªãŒã®äžèЧãåäœè·é¢ã®èµ°è¡ã«ããæ¶è²»ã«ããªãŒãå
¥åãšããèªå®
ãåºçºããŠããåžåœ¹æã«å
¥ããŸã§ã®æ£å³ã®æ¶è²»ã«ããªãŒã®æå°å€ãåºåããããã°ã©ã ãäœæããŠãã ããã å°å³ã«ã¯ãA ããã®èªå®
ãšåžåœ¹æãã±ãŒãå±ãããšã©ã³ãããŒã¯(ç®å°)ã«ãªã建ç©ãæžãããŠããŸããå°å³ã衚ãå
¥åããŒã¿ã¯ãA ããã®èªå®
ãåžåœ¹æãã±ãŒãå±ãããšã©ã³ãããŒã¯ã®åå°ç¹ã®éãã€ãªãéããããšãã2 ã€ã®å°ç¹ã衚ãèšå·ãšãã®éã®è·é¢ãããªãè¡ãå«ã¿ãŸããããšãã°ã5 çªç®ã®ã±ãŒãå±ãããš 3 çªç®ã®ã©ã³ãããŒã¯ã®éã®è·é¢ã 10 ãªããå
¥åããŒã¿ã¯ä»¥äžã®ãããªè¡ãå«ã¿ãŸãã C5 L3 10 ãã®ããã«ã±ãŒãå±ããã«ã¯ Cãã©ã³ãããŒã¯ã«ã¯ L ãçªå·ã®åã«ã€ããŠè¡šããŸãããŸããA ããã®èªå®
㯠Hãåžåœ¹æã¯ D ã§è¡šããŸããå
¥åããŒã¿ã« 2 ã€ã®å°ç¹ãšãã®éã®è·é¢ãäžããããŠãããªãã2 å°ç¹ã®éãã©ã¡ãåãã«ãé²ããŸããããšãã°ãäžã®äŸã§ã¯ã±ãŒãå±ããããã©ã³ãããŒã¯ãžãããã®éåããžãé²ãããšãã§ããŸãããŸããèªå®
ããåžåœ¹æãŸã§ã¯å¿
ããã©ãçãããã®ãšããŸãããã以å€ã«äžããããå
¥åããŒã¿ã¯ãã±ãŒãå±ããã®æ° m ãã©ã³ãããŒã¯ã®æ° n ãåäœè·é¢ãããã®æ¶è²»ã«ããªãŒ k ã 1 çªç®ã®ã±ãŒãå±ãããã m çªç®ã®ã±ãŒãå±ãããŸã§ã®ããããã§è²·ããã±ãŒãã®ã«ããªãŒã衚ã m åã®ããŒã¿ãè·é¢ã®ããŒã¿ã®ç·æ° d ã§ãã Input è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯åã€ã® 0 ã®è¡ã§ç€ºãããŸãã åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã m n k d c 1 c 2 ... c m s 1 t 1 e 1 s 2 t 2 e 2 : s d t d e d 1 è¡ç®ã«ã±ãŒãå±ããã®æ° m (1 †m †6)ã ã©ã³ãããŒã¯ã®æ° n (1 †n †100) ãåäœè·é¢ãããã®æ¶è²»ã«ããªãŒ k (1 †k †5)ãè·é¢ã®ããŒã¿ã®ç·æ° d (5 †d †256) ãäžããããŸãã 2 è¡ç®ã«åã±ãŒãå±ã§è²·ãã±ãŒãã®ã«ããªãŒ c i (1 †c i †100) ãäžããããŸãã ç¶ã d è¡ã« i çªç®ã® 2 ã€ã®å°ç¹éã®è·é¢ããŒã¿ s i , t i , e i (1 †e i †20) ãäžããããŸãã ããŒã¿ã»ããã®æ°ã¯ 100 ãè¶
ããŸããã Output å
¥åããŒã¿ã»ããããšã«ãå
šäœã®æ¶è²»ã«ããªãŒã®æå°å€ãïŒè¡ã«åºåããŸãã Sample Input 1 1 2 5 35 H L1 5 C1 D 6 C1 H 12 L1 D 10 C1 L1 20 2 1 4 6 100 70 H L1 5 C1 L1 12 C1 D 11 C2 L1 7 C2 D 15 L1 D 8 0 0 0 0 Output for the Sample Input 1 -2 | 39,146 |
Problem F: Marching Course Since members of Kitafuji High School Brass Band Club succeeded in convincing their stern coach of their playing skills, they will be able to participate in Moon Light Festival as a marching band. This festival is a prelude in terms of appealing their presence for the coming domestic contest. Hence, they want to attract a festival audience by their performance. Although this festival restricts performance time up to $P$ minutes, each team can freely determine their performance course from a provided area. The provided area consists of $N$ checkpoints, numbered 1 through $N$, and $M$ bidirectional roads connecting two checkpoints. Kitafuji Brass Band already has the information about each road: its length and the expected number of people on its roadside. Each team must start at the checkpoint 1, and return back to the checkpoint 1 in $P$ minutes. In order to show the performance ability of Kitafuji Brass Band to a festival audience, their stern coach would like to determine their performance course so that many people listen their march as long as possible. The coach uses "impression degree" to determine their best course. If they play $m$ minutes on the road with length $d$ and the expected number $v$ of people, then the impression degree will be $m \times v/d$. The impression degree of a course is the sum of impression degree of their performance on the course. Marching bands must move at a constant speed during marching: 1 unit length per 1 minute. On the other hand, they can turn in the opposite direction at any time, any place including a point on a road. The impression degree is accumulated even if they pass the same interval two or more times. Your task is to write a program to determine a course with the maximum impression degree in order to show the performance ability of Kitafuji Brass Band to an audience as much as possible. Input The input is formatted as follows. $N$ $M$ $P$ $s_1$ $t_1$ $d_1$ $v_1$ : : : $s_M$ $t_M$ $d_M$ $v_M$ The first line contains three integers $N$, $M$, and $P$: the number of checkpoints $N$ ($2 \leq N \leq 200$), the number of roads $M$ ($N - 1 \leq M \leq N(N - 1)/2$), and the performance time $P$ ($1 \leq P \leq 1,000$). The following $M$ lines represent the information about roads. The $i$-th line of them contains four integers $s_i$, $t_i$, $d_i$, and $v_i$: the $i$-th road bidirectionally connects between checkpoints $s_i$ and $t_i$ ($1 \leq s_i, t_i \leq N, s_i \ne t_i$) with length $d_i$ ($1 \leq d_i \leq 1,000$) and the expected number $v_i$ ($1 \leq v_i \leq 1,000$) of people. You can assume that any two checkpoints are directly or indirectly connected with one or more roads. You can also assume that there are no pair of roads having the same pair of endpoints. Output Output the maximum impression degree of a course for a $P$-minute performance. The absolute error should be less than $10^{-4}$. Sample Input 3 3 4 1 2 1 1 2 3 2 4 3 1 1 1 Output for the Sample Input 6 Sample Input 4 3 9 1 2 2 1 1 3 2 2 1 4 2 3 Output for the Sample Input 13.5 Sample Input 4 3 5 1 2 10 1 2 3 2 100 1 4 3 10 Output for the Sample Input 16.6666666667 Sample Input 3 3 10 1 2 3 1 1 3 4 5 2 3 2 10 Output for the Sample Input 22 | 39,147 |
Problem D: Cliff Climbing At 17:00, special agent Jack starts to escape from the enemy camp. There is a cliff in between the camp and the nearest safety zone. Jack has to climb the almost vertical cliff by stepping his feet on the blocks that cover the cliff. The cliff has slippery blocks where Jack has to spend time to take each step. He also has to bypass some blocks that are too loose to support his weight. Your mission is to write a program that calculates the minimum time to complete climbing. Figure D-1 shows an example of cliff data that you will receive. The cliff is covered with square blocks. Jack starts cliff climbing from the ground under the cliff, by stepping his left or right foot on one of the blocks marked with 'S' at the bottom row. The numbers on the blocks are the "slippery levels". It takes t time units for him to safely put his foot on a block marked with t , where 1 †t †9. He cannot put his feet on blocks marked with 'X'. He completes the climbing when he puts either of his feet on one of the blocks marked with 'T' at the top row. Figure D-1: Example of Cliff Data Jack's movement must meet the following constraints. After putting his left (or right) foot on a block, he can only move his right (or left, respectively) foot. His left foot position ( lx , ly ) and his right foot position ( rx , ry ) should satisfy lx < rx and | lx - rx | + | ly - ry | †3 . This implies that, given a position of his left foot in Figure D-2 (a), he has to place his right foot on one of the nine blocks marked with blue color. Similarly, given a position of his right foot in Figure D-2 (b), he has to place his left foot on one of the nine blocks marked with blue color. Figure D-2: Possible Placements of Feet 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 h s(1,1) ... s(1,w) s(2,1) ... s(2,w) ... s(h,1) ... s(h,w) The integers w and h are the width and the height of the matrix data of the cliff. You may assume 2 †w †30 and 5 †h †60. Each of the following h lines consists of w characters delimited by a space. The character s(y, x) represents the state of the block at position ( x , y ) as follows: 'S': Jack can start cliff climbing from this block. 'T': Jack finishes climbing when he reaches this block. 'X': Jack cannot put his feet on this block. '1' - '9' ( = t ): Jack has to spend t time units to put either of his feet on this block. You can assume that it takes no time to put a foot on a block marked with 'S' or 'T'. Output For each dataset, print a line only having a decimal integer indicating the minimum time required for the cliff climbing, when Jack can complete it. Otherwise, print a line only having "-1" for the dataset. Each line should not have any characters other than these numbers. Sample Input 6 6 4 4 X X T T 4 7 8 2 X 7 3 X X X 1 8 1 2 X X X 6 1 1 2 4 4 7 S S 2 3 X X 2 10 T 1 1 X 1 X 1 X 1 1 1 X 1 X 1 1 1 X S S 2 10 T X 1 X 1 X 1 X 1 1 1 X 1 X 1 1 1 X S S 10 10 T T T T T T T T T T X 2 X X X X X 3 4 X 9 8 9 X X X 2 9 X 9 7 7 X 7 3 X X 8 9 X 8 9 9 9 6 3 X 5 X 5 8 9 9 9 6 X X 5 X 5 8 6 5 4 6 8 X 5 X 5 8 9 3 9 6 8 X 5 X 5 8 3 9 9 6 X X X 5 X S S S S S S S S S S 10 7 2 3 2 3 2 3 2 3 T T 1 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 4 3 2 3 2 3 2 3 2 3 5 3 2 3 1 3 2 3 2 3 5 2 2 3 2 4 2 3 2 3 5 S S 2 3 2 1 2 3 2 3 0 0 Output for the Sample Input 12 5 -1 22 12 | 39,148 |
Road Improvement Aizu is a country famous for its rich tourism resources and has N cities, each of which is uniquely identified with a number (0 to N -1). It has a road network consisting of M one-way roads connecting a city to another. All the roads connecting the cities in Aizu have a row of cherry trees along their routes. For enhancing the cherry-viewing experience, a proposal was made to modify the road network so that a tourist can travel around all the roads. To achieve this target, it was decided to construct several one-way roads, each connecting two cities and abiding by the following rules. The newly constructed road is for one-way traffic Starting from any city, a tourist is able to make a roundtrip and return to the city, whereby he/she drives all the roads exhaustively, including the newly constructed ones. Multiple passages of some of the roads are allowed. You, as a tourism promotion officer, are assigned with the task of writing a program for the road construction project. Write a program to determine the minimum number of roads to be constructed given the road network information in Aizu. Input The input is given in the following format. N M s_1 t_1 s_2 t_2 : s_M t_M The first line provides the number of cities N (1 †N †10 4 ) and roads M (0 †M †10 5 ). Each of the subsequent M lines provides the numbers assigned to start and destination cities for the i -th road: s_i , t_i (0 †s_i , t_i †N -1) , where s_i â t_i . (no duplicate appearance of a road) Output Output the minimum number of roads to be newly constructed. Sample Input 1 6 7 0 2 2 1 1 0 2 3 4 3 4 5 5 4 Sample Output 1 2 Sample Input 2 6 9 0 2 2 1 1 0 2 3 4 3 4 5 5 4 5 2 3 4 Sample Output 2 0 | 39,149 |
A: IPã¢ãã¬ã¹ (Internet Protocol Address) åé¡ æ°ååã 1 ã€äžããããã®ã§ãIPv4ã®IPã¢ãã¬ã¹ãšããŠæå¹ãªåºåãæ¹ã®åæ°ãæ±ããã ãã ããIPv4ã®IPã¢ãã¬ã¹ãšããŠæå¹ãªåºåãæ¹ã¯ä»¥äžã®éãã§ããã æ°åå㯠4 ã€ã«åºåãããåºåãããååã«ã€ããŠä»¥äžããã¹ãŠæºããã 空åã§ãªãã 10 鲿°ãšããŠèªããš 0 ä»¥äž 255 以äžã®æŽæ°ã§ããã ãã®æ°ã 0 ãªãã°ããã®å㯠0 ã§ããïŒ 00 ãªã©ã¯èªããããªãïŒã ãã®æ°ã 0 ã§ãªããªãã°ãå
é ã®æ°å㯠0 ã§ãªãïŒ 01 ãªã©ã¯èªããããªãïŒã å
¥ååœ¢åŒ S å¶çŽ 4 \leq |S| \leq 12 S ã«å«ãŸããæåã¯æ°åã®ã¿ã§ããã åºååœ¢åŒ æå¹ãªåºåãæ¹ã®éãæ°ãäžè¡ã«åºåããã å
¥åäŸ1 123456789 åºåäŸ1 1 æå¹ãªåºåãæ¹ã¯ 123.45.67.89 ã® 1 éãã§ããã å
¥åäŸ2 768426 åºåäŸ2 6 | 39,150 |
Tally Counters A number of tally counters are placed in a row. Pushing the button on a counter will increment the displayed value by one, or, when the value is already the maximum, it goes down to one. All the counters are of the same model with the same maximum value. Fig. D-1 Tally Counters Starting from the values initially displayed on each of the counters, you want to change all the displayed values to target values specified for each. As you don't want the hassle, however, of pushing buttons of many counters one be one, you devised a special tool. Using the tool, you can push buttons of one or more adjacent counters, one push for each, in a single operation. You can choose an arbitrary number of counters at any position in each operation, as far as they are consecutively lined up. How many operations are required at least to change the displayed values on counters to the target values? Input The input consists of multiple datasets, each in the following format. n m a 1 a 2 ... a n b 1 b 2 ... b n Each dataset consists of 3 lines. The first line contains n (1 †n †1000) and m (1 †m †10000), the number of counters and the maximum value displayed on counters, respectively. The second line contains the initial values on counters, a i (1 †a i †m ), separated by spaces. The third line contains the target values on counters, b i (1 †b i †m ), separated by spaces. The end of the input is indicated by a line containing two zeros. The number of datasets does not exceed 100. Output For each dataset, print in a line the minimum number of operations required to make all of the counters display the target values. Sample Input 4 5 2 3 1 4 2 5 5 2 3 100 1 10 100 1 10 100 5 10000 4971 7482 1238 8523 1823 3287 9013 9812 297 1809 0 0 Output for the Sample Input 4 0 14731 | 39,151 |
Usoperanto Usoperanto is an artificial spoken language designed and regulated by Usoperanto Academy. The academy is now in study to establish Strict Usoperanto, a variation of the language intended for formal documents. In Usoperanto, each word can modify at most one other word, and modifiers are always put before modifiees. For example, with a noun uso ("truth") modified by an adjective makka ("total"), people say makka uso , not uso makka . On the other hand, there have been no rules about the order among multiple words modifying the same word, so in case uso is modified by one more adjective beta ("obvious"), people could say both makka beta uso and beta makka uso . In Strict Usoperanto, the word order will be restricted according to modification costs . Words in a phrase must be arranged so that the total modification cost is minimized. Each pair of a modifier and a modifiee is assigned a cost equal to the number of letters between the two words; the total modification cost is the sum of the costs over all modifier-modifiee pairs in the phrase. For example, the pair of makka and uso in a phrase makka beta uso has the cost of 4 for beta (four letters). As the pair of beta and uso has no words in between and thus the cost of zero, makka beta uso has the total modification cost of 4. Similarly beta makka uso has the total modification cost of 5. Applying the "minimum total modification cost" rule, makka beta uso is preferred to beta makka uso in Strict Usoperanto. Your mission in this problem is to write a program that, given a set of words in a phrase, finds the correct word order in Strict Usoperanto and reports the total modification cost. Input The format of the input is as follows. N M 0 L 0 ... M N-1 L N-1 The first line contains an integer N ( 1 †N †10 6 ). N is the number of words in a phrase. Each of the following N lines contains two integers M i ( 1 †M i †10 ) and L i ( -1 †L i †N - 1 , L i â i ) describing the i -th word ( 0 †i †N-1 ). M i is the number of the letters in the word. L i specifies the modification: L i = -1 indicates it does not modify any word; otherwise it modifies the L i -th word. Note the first sample input below can be interpreted as the uso - beta - makka case. Output Print the total modification cost. Sample Input 1 3 3 -1 4 0 5 0 Output for the Sample Input 1 4 Sample Input 2 3 10 -1 10 0 10 1 Output for the Sample Input 2 0 Sample Input 3 4 1 -1 1 0 1 1 1 0 Output for the Sample Input 3 1 | 39,152 |
éçŽ ãã¯ã·ã³ã°ã¯äœéã«ãã£ãŠéçŽãåããããŠããŸããäœéãèªã¿èŸŒãã§ããã®éçŽãåºåããããã°ã©ã ãäœæããŠãã ãããéçŽãšäœéã®é¢ä¿ã¯ä»¥äžã®è¡šã®ãšãããšããŸãã éçŽ äœéïŒkgïŒ light fly 48.00kg ä»¥äž fly 48.00kg è¶
51.00kg ä»¥äž bantam 51.00kg è¶
54.00kg ä»¥äž feather 54.00kg è¶
57.00kg ä»¥äž light 57.00kg è¶
60.00kg ä»¥äž light welter 60.00kg è¶
64.00kg ä»¥äž welter 64.00kg è¶
69.00 kg ä»¥äž light middle 69.00kg è¶
75.00 kg ä»¥äž middle 75.00kg è¶
81.00 kg ä»¥äž light heavy 81.00kg è¶
91.00 kg ä»¥äž heavy 91.00kg è¶
Input å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªããŸããåããŒã¿ã»ãããšããŠãäœéã衚ãïŒã€ã®å®æ° w (40 †w †150) ãïŒè¡ã«äžããããŸããããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã Output ããŒã¿ã»ããããšã«ã察å¿ããéçŽãïŒè¡ã«åºåããŸãã Sample Input 60.2 70.2 48.0 80.2 Output for the Sample Input light welter light middle light fly middle | 39,153 |
Problem Statement Your friend, Tatsumi, is a producer of Immortal Culture Production in Chiba (ICPC). His company is planning to form a zombie rock band named Gray Faces and cheer Chiba Prefecture up. But, unfortunately, there is only one zombie in ICPC. So, Tatsumi decided to release the zombie on a platform of Soga station to produce a sufficient number of zombies. As you may know, a zombie changes a human into a new zombie by passing by the human. In other words, a human becomes a zombie when the human and a zombie are at the same point. Note that a zombie who used to be a human changes a human into a zombie too. The platform of Soga station is represented by an infinitely long line, and Tatsumi will release a zombie at a point with coordinate $x_Z$. After the release, the zombie will start walking in the positive direction at $v_Z$ per second. If $v_Z$ is negative, the zombie will walk in the negative direction at $|v_Z|$ per second. There are $N$ humans on the platform. When Tatsumi releases the zombie, the $i$-th human will be at a point with coordinate $x_i$ and will start walking in the positive direction at $v_i$ per second. If $v_i$ is negative, the human will walk in the negative direction at $|v_i|$ per second as well as the zombie. For each human on the platform, Tatsumi wants to know when the human becomes a zombie. Please help him by writing a program that calculates a time when each human on the platform becomes a zombie. Input The input consists of a single test case in the following format. $N$ $x_Z$ $v_Z$ $x_1$ $v_1$ $\vdots$ $x_N$ $v_N$ The first line consists of an integer $N \, (1 \le N \le 2 \times 10^5)$ which is the number of humans on a platform of Soga station. The second line consists of two integers $x_Z \, (-10^9 \le x_Z \le 10^9)$ and $v_Z \, (-10^9 \le v_Z \le 10^9)$ separated by a space, where $x_Z$ is an initial position of a zombie Tatsumi will release and $v_Z$ is the velocity of the zombie. The $i$-th line in the following $N$ lines contains two integers $x_i \, (-10^9 \le x_i \le 10^9)$ and $v_i \, (-10^9 \le v_i \le 10^9)$ separated by a space, where the $x_i$ is an initial position of the $i$-th human and $v_i$ is the velocity of the human. There is no human that shares their initial position with the zombie. In addition, initial positions of the humans are different from each other. Output The output consists of $N$ lines. In the $i$-th line, print how many seconds it will take for the $i$-th human to become a zombie. If the $i$-th human will never become a zombie, print $-1$ instead. The answer will be considered as correct if the values output have an absolute or relative error less than $10^{-9}$. Examples Input Output 6 3 1 -5 0 5 0 -4 -3 0 -2 6 -3 2 -1 3.66666666666667 2.00000000000000 -1 6.00000000000000 0.75000000000000 2.00000000000000 5 31415 -926 5358 979 323846 26 -433832 7950 288 -4 -1971 -69 13.67821522309711 95.61812216052499 52.41629112212708 33.76030368763558 38.95682613768962 | 39,154 |
決ãŸãããšã®å€ããžã ã€ã
ã¢æã®ã¹ããŒããžã ã«ã¯$1$ãã$N$ãŸã§ã®çªå·ãä»ãã$N$å°ã®ãã¬ãŒãã³ã°æ©åšããããŸãããã¬ãŒãã³ã°æ©åšãïŒåå©çšããã«ã¯ããã®æ©åšã®çªå·ãæžããããã±ãããïŒæå¿
èŠã§ãããã¬ãŒãã³ã°æ©åšãïŒåå©çšãããšãã®æ¶è²»ã«ããªãŒã¯ãæ©åšããšã«æ±ºãŸã£ãŠããŸãã ãã®ã¹ããŒããžã ã®ãã±ãããäœæãããã£ãã¢ãã·åã¯ãéåäžè¶³è§£æ¶ã®ããã«ãžã ã«è¡ããŸããããã®ãžã ã§ã¯ãå©çšè
ãéåããããããŠäœãçããªãããã«ãæ©åšã®å©çšåæ°ã«ã«ãŒã«ããããŸããããšãã°ããïŒçªã®æ©åšã¯ïŒçªã®æ©åšãããïŒå以äžå€ã䜿ã£ãŠã¯ãããŸããããšãããããªã«ãŒã«ã§ããæ©åšã䜿ã人ã¯ãã«ãŒã«ãå®ã£ãŠæ©åšãå©çšããªããã°ãªããŸããã ã¢ãã·åã¯ãããã£ããã±ããã䜿ã£ãŠãã«ãŒã«ã§èš±ãããç¯å²ã§ãªãã¹ãå€ãã®ã«ããªãŒãæ¶è²»ããããšæã£ãŠããŸãã ããã£ããã±ãããšããããã®æ©åšã®æ
å ±ãäžãããããšããã«ãŒã«ãå®ã£ããšãã®æ¶è²»ã«ããªãŒã®æå€§å€ãæ±ããããã°ã©ã ãäœæããªããã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã $N$ $R$ $t_1$ $e_1$ $t_2$ $e_2$ : $t_N$ $e_N$ $a_1$ $b_1$ $c_1$ $a_2$ $b_2$ $c_2$ : $a_R$ $b_R$ $c_R$ ïŒè¡ç®ã«ãã¬ãŒãã³ã°æ©åšã®å°æ°$N$ ($1 \leq N \leq 100,000$)ãšã«ãŒã«ã®æ°$R$ ($0 \leq R \leq 100,000$)ãäžãããããç¶ã$N$è¡ã«ã$i$çªã®æ©åšã«ã€ããŠãã¢ãã·åãããã£ããã±ããã®ææ°$t_i$ ($1 \leq t_i \leq 200,000$)ãšãã®æ©åšã䜿ã£ããšãã®æ¶è²»ã«ããªãŒ$e_i$ ($0 \leq e_i \leq 100,000$)ãäžãããããç¶ã$R$è¡ã«ãã$a_i$çªã®æ©åšã¯$b_i$çªã®æ©åšããã$c_i$å以äžå€ã䜿ã£ãŠã¯ãããŸããããšããã«ãŒã«ãè¡šãæ°$a_i$ ($1 \leq a_i \leq N$)ã$b_i$ ($1 \leq b_i \leq N$)ã$c_i$ ($1 \leq c_i \leq 100,000$)ãäžããããã å
¥åã¯ä»¥äžã®å¶çŽãæºããã åãæ©åšã®ãã¢ã«å¯Ÿããã«ãŒã«ã¯ïŒåºŠããäžããããªã($i \ne j$ãªã$a_i \ne a_j$ãŸãã¯$b_i \ne b_j$)ã åãæ©åšèªèº«ã«å¯Ÿããã«ãŒã«ã¯äžããããªã($a_i \ne b_i$)ã åºå æ¶è²»ã«ããªãŒã®æå€§å€ãïŒè¡ã«åºåããã å
¥åºåäŸ å
¥åäŸïŒ 3 2 5 1 10 4 6 2 2 1 3 3 2 1 åºåäŸïŒ 45 ããã£ããã±ããã䜿ã£ãŠãã«ãŒã«ãå®ã£ãŠäœ¿ããåæ©åšã®æå€§ã®åæ°ã¯ã$1$çªã$5$åã$2$çªã$7$åã$3$çªã$6$åãªã®ã§ãæ¶è²»ã«ããªãŒã®æå€§å€ã¯$5 \times 1 + 7 \times 4 + 6 \times 2 = 45$ãšãªãã å
¥åäŸïŒ 4 5 5 1 6 2 2 3 7 1 1 2 4 2 1 3 1 3 2 3 2 3 3 4 2 åºåäŸïŒ 26 å
¥åäŸïŒ 1 0 200000 100000 åºåäŸïŒ 20000000000 | 39,155 |
Bit Flag A state with $n$ flags of ON or OFF can be represented by a sequence of bits where $0, 1, ..., n-1$ -th flag corresponds to 1 (ON) or 0 (OFF). The state can be managed by the corresponding decimal integer, because the sequence of bits is a binary representation where each bit is 0 or 1. Given a sequence of bits with 64 flags which represent a state, perform the following operations. Note that each flag of the bits is initialized by OFF. test(i): Print 1 if $i$-th flag is ON, otherwise 0 set(i): Set $i$-th flag to ON clear(i): Set $i$-th flag to OFF flip(i): Inverse $i$-th flag all: Print 1 if all flags are ON, otherwise 0 any: Print 1 if at least one flag is ON, otherwise 0 none: Print 1 if all flags are OFF, otherwise 0 count: Print the number of ON flags val: Print the decimal value of the state Input The input is given in the following format. $q$ $query_1$ $query_2$ : $query_q$ Each query $query_i$ is given in the following format: 0 $i$ or 1 $i$ or 2 $i$ or 3 $i$ or 4 or 5 or 6 or 7 or 8 The first digit 0 , 1 ,..., 8 represents the operation test(i), set(i), clear(i), flip(i), all, any, none, count or val respectively. Output Print the result in a line for each test, all, any, none, count and val operation. Constraints $1 \leq q \leq 200,000$ $0 \leq i < 64$ Sample Input 1 14 1 0 1 1 1 2 2 1 0 0 0 1 0 2 0 3 3 3 4 5 6 7 8 Sample Output 1 1 0 1 0 0 1 0 3 13 | 39,156 |
Score : 900 points Problem Statement Mole decided to live in an abandoned mine. The structure of the mine is represented by a simple connected undirected graph which consists of N vertices numbered 1 through N and M edges. The i -th edge connects Vertices a_i and b_i , and it costs c_i yen (the currency of Japan) to remove it. Mole would like to remove some of the edges so that there is exactly one path from Vertex 1 to Vertex N that does not visit the same vertex more than once. Find the minimum budget needed to achieve this. Constraints 2 \leq N \leq 15 N-1 \leq M \leq N(N-1)/2 1 \leq a_i, b_i \leq N 1 \leq c_i \leq 10^{6} There are neither multiple edges nor self-loops in the given graph. The given graph is connected. Input Input is given from Standard Input in the following format: N M a_1 b_1 c_1 : a_M b_M c_M Output Print the answer. Sample Input 1 4 6 1 2 100 3 1 100 2 4 100 4 3 100 1 4 100 3 2 100 Sample Output 1 200 By removing the two edges represented by the red dotted lines in the figure below, the objective can be achieved for a cost of 200 yen. Sample Input 2 2 1 1 2 1 Sample Output 2 0 It is possible that there is already only one path from Vertex 1 to Vertex N in the beginning. Sample Input 3 15 22 8 13 33418 14 15 55849 7 10 15207 4 6 64328 6 9 86902 15 7 46978 8 14 53526 1 2 8720 14 12 37748 8 3 61543 6 5 32425 4 11 20932 3 12 55123 8 2 45333 9 12 77796 3 9 71922 12 15 70793 2 4 25485 11 6 1436 2 7 81563 7 11 97843 3 1 40491 Sample Output 3 133677 | 39,157 |
D - ã«ãŒããã ç·åç ç©¶7å·é€šã®åŒè¶ãã«äŒŽãïŒç 究宀ã«ã«ãŒããããæ·ãããšã«ãªã£ãïŒ ãã®åé¡ã§ã¯ç 究宀ãäžããèŠããšãã®åºãïŒäºæ¬¡å
å¹³é¢äžã®å€è§åœ¢ãšã¿ãªãïŒ åºã®åœ¢ç¶ã衚ãèŠçŽ æ° N ã®æ°å \{a_i\} ãäžããããïŒ R_i ãïŒå·Šäžã®åº§æšã (i,0) ã§å³äžã®åº§æšã (i+1,a_i) ã§ããå蟺ãx軞ãŸãã¯y軞ã«å¹³è¡ãªé·æ¹åœ¢ã®å¢çåã³å
éšé åãšããïŒ ãã®ãšãïŒåºã衚ãå€è§åœ¢ã¯ R_1 ⪠R_2 ⪠R_3 ⪠⊠⪠R_N ã«ãã£ãŠè¡šãããïŒ ã«ãŒãããã¯é·æ¹åœ¢ã§ããã°ã©ããªå€§ããã®ãã®ãäœæã§ãçšæããããšãã§ããïŒ ä»¥äžã®æ¡ä»¶ãæºããããã«ã«ãŒããããé
眮ãïŒç 究宀ã®åºãå
šãŠèŠãã€ããããïŒ ã«ãŒãããã¯ç 究宀ããã¯ã¿åºããŠã¯ãããªãïŒ ã«ãŒãããã¯ãããã§ãéããŠæ·ãããšãå¯èœã§ããïŒãã®ãšãïŒã«ãŒãããã®åãã¯ç¡èŠããïŒ ã«ãŒããããåãé¢ããŠå©çšããããšã¯ã§ããªãïŒ ã«ãŒãããã¯å蟺ãx軞ãŸãã¯y軞ã«å¹³è¡ã«ãªãããã«é
眮ããªããã°ãªããªãïŒ ç 究宀ã®åºãèŠãå°œããããã«å¿
èŠãªã«ãŒãããã®æå°æ°ãæ±ããïŒ å³D-1. å
¥åäŸ1ã®åº å³D-2. å
¥åäŸ2ã®åº å
¥ååœ¢åŒ å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ N a_1 ⊠a_N åºååœ¢åŒ ç 究宀ã®åºãèŠãå°œããããã«å¿
èŠãªã«ãŒãããã®æå°æ°ãïŒè¡ã«åºåããïŒ å¶çŽ 1 \leq N \leq 2 \times 10^5 1 \leq a_i \leq 10^9 å
¥åå€ã¯ãã¹ãп޿°ã§ããïŒ å
¥åºåäŸ å
¥åäŸ1 3 1 2 1 åºåäŸ1 2 å
¥åäŸ2 10 1 2 2 1 3 4 3 1 2 2 åºåäŸ2 5 | 39,158 |
Score : 700 points Problem Statement You are given a simple connected undirected graph with N vertices and M edges. The vertices are numbered 1 to N , and the i -th edge connects Vertex A_i and Vertex B_i . Takahashi will assign one of the two possible directions to each of the edges in the graph to make a directed graph. Determine if it is possible to make a directed graph with an even number of edges going out from every vertex. If the answer is yes, construct one such graph. Notes An undirected graph is said to be simple when it contains no self-loops or multiple edges. Constraints 2 \leq N \leq 10^5 N-1 \leq M \leq 10^5 1 \leq A_i,B_i \leq N (1\leq i\leq M) The given graph is simple and connected. Input Input is given from Standard Input in the following format: N M A_1 B_1 : A_M B_M Output If it is impossible to assign directions to satisfy the requirement, print -1 . Otherwise, print an assignment of directions that satisfies the requirement, in the following format: C_1 D_1 : C_M D_M Here each pair ( C_i , D_i ) means that there is an edge directed from Vertex C_i to Vertex D_i . The edges may be printed in any order. Sample Input 1 4 4 1 2 2 3 3 4 4 1 Sample Output 1 1 2 1 4 3 2 3 4 After this assignment of directions, Vertex 1 and 3 will each have two outgoing edges, and Vertex 2 and 4 will each have zero outgoing edges. Sample Input 2 5 5 1 2 2 3 3 4 2 5 4 5 Sample Output 2 -1 | 39,159 |
Score : 900 points Problem Statement There are 2N points evenly spaced on the circumference of a circle. These points are numbered 1 to 2N in clockwise order, starting from some of them. Snuke will divide these points into N pairs, then for each pair, he will draw a line segment connecting the two points. After the line segments are drawn, two points are connected when one can reach from one of those points to the other by traveling only on the line segments. The number of the connected parts here is the number of the connected components in the graph with 2N vertices, corresponding to the 2N points, where every pair of vertices corresponding to two connected points is connected with an edge. Snuke has already decided K of the pairs, and the i -th of them is a pair of Point A_i and Point B_i . He is thinking of trying all possible ways to make the remaining N-K pairs and counting the number of the connected parts for each of those ways. Find the sum of those numbers of the connected parts. As the answer can be extremely large, compute the sum modulo 10^9+7 . Constraints 1 \leq N \leq 300 0 \leq K \leq N 1 \leq A_i,B_i \leq 2N A_1,\ A_2,\ ...\ A_K,\ B_1,\ B_2,\ ...\ B_K are all distinct. All values in input are integers. Input Input is given from Standard Input in the following format: N K A_1 B_1 A_2 B_2 : A_K B_K Output Print the sum of the numbers of the connected parts for all possible ways to make the remaining N-K pairs. Sample Input 1 2 0 Sample Output 1 5 There are three ways to draw line segments, as shown below, and the number of the connected parts for these ways are 2 , 2 and 1 , respectively. Thus, the answer is 2+2+1=5 . Sample Input 2 4 2 5 2 6 1 Sample Output 2 6 Sample Input 3 20 10 10 18 11 17 14 7 4 6 30 28 19 24 29 22 25 32 38 34 36 39 Sample Output 3 27087418 | 39,160 |
Problem C: ! You are one of ICPC participants and in charge of developing a library for multiprecision numbers and radix conversion. You have just finished writing the code, so next you have to test if it works correctly. You decided to write a simple, well-known factorial function for this purpose: Your task is to write a program that shows the number of trailing zeros when you compute M ! in base N , given N and M . Input The input contains multiple data sets. Each data set is described by one line in the format below: N M where N is a decimal number between 8 and 36 inclusive, and M is given in the string repre- sentation in base N . Exactly one white space character appears between them. The string representation of M contains up to 12 characters in base N . In case N is greater than 10, capital letters A, B, C, ... may appear in the string representation, and they represent 10, 11, 12, ..., respectively. The input is terminated by a line containing two zeros. You should not process this line. Output For each data set, output a line containing a decimal integer, which is equal to the number of trailing zeros in the string representation of M ! in base N . Sample Input 10 500 16 A 0 0 Output for the Sample Input 124 2 | 39,161 |
Score : 300 points Problem Statement There is an empty array. The following N operations will be performed to insert integers into the array. In the i -th operation (1â€iâ€N) , b_i copies of an integer a_i are inserted into the array. Find the K -th smallest integer in the array after the N operations. For example, the 4 -th smallest integer in the array \{1,2,2,3,3,3\} is 3 . Constraints 1â€Nâ€10^5 1â€a_i,b_iâ€10^5 1â€Kâ€b_1âŠ+âŠb_n All input values are integers. Input Input is given from Standard Input in the following format: N K a_1 b_1 : a_N b_N Output Print the K -th smallest integer in the array after the N operations. Sample Input 1 3 4 1 1 2 2 3 3 Sample Output 1 3 The resulting array is the same as the one in the problem statement. Sample Input 2 10 500000 1 100000 1 100000 1 100000 1 100000 1 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 Sample Output 2 1 | 39,162 |
Score : 500 points Problem Statement For an integer n not less than 0 , let us define f(n) as follows: f(n) = 1 (if n < 2 ) f(n) = n f(n-2) (if n \geq 2 ) Given is an integer N . Find the number of trailing zeros in the decimal notation of f(N) . Constraints 0 \leq N \leq 10^{18} Input Input is given from Standard Input in the following format: N Output Print the number of trailing zeros in the decimal notation of f(N) . Sample Input 1 12 Sample Output 1 1 f(12) = 12 Ã 10 Ã 8 Ã 6 Ã 4 Ã 2 = 46080 , which has one trailing zero. Sample Input 2 5 Sample Output 2 0 f(5) = 5 Ã 3 Ã 1 = 15 , which has no trailing zeros. Sample Input 3 1000000000000000000 Sample Output 3 124999999999999995 | 39,163 |
Score : 100 points Problem Statement X and A are integers between 0 and 9 (inclusive). If X is less than A , print 0 ; if X is not less than A , print 10 . Constraints 0 \leq X, A \leq 9 All values in input are integers. Input Input is given from Standard Input in the following format: X A Output If X is less than A , print 0 ; if X is not less than A , print 10 . Sample Input 1 3 5 Sample Output 1 0 3 is less than 5 , so we should print 0 . Sample Input 2 7 5 Sample Output 2 10 7 is not less than 5 , so we should print 10 . Sample Input 3 6 6 Sample Output 3 10 6 is not less than 6 , so we should print 10 . | 39,164 |
Problem G: Combine Two Elements Problem $N$åã®éè² æŽæ°ã®ãã¢$(a_i, b_i)$ãšéè² æŽæ°$A$, $B$ ãäžããããã 以äžã®ããããã®æäœãã§ããã ãããããè¡ãããã $|a_i - b_i| \leq A$ ãŸã㯠$B \leq |a_i - b_i| \leq 2A$ãæºããèŠçŽ $i$ãåãåºããåé€ãã $|(a_i + a_j) - (b_i + b_j)| \leq A$ ãŸã㯠$B \leq |(a_i + a_j) - (b_i + b_j)| \leq 2A$ ãæºããèŠçŽ $i$ãšèŠçŽ $j$ ($i \neq j$)ã®çµãåãåºããåé€ãã æå€§ã®æäœåæ°ãæ±ããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã $N$ $A$ $B$ $a_1$ $b_1$ $a_2$ $b_2$ ... $a_N$ $b_N$ å
¥åã¯ãã¹ãп޿°ã§äžããããã 1è¡ç®ã«$N$,$A$,$B$ã空çœåºåãã§äžããããã 2è¡ç®ä»¥éã®$N$è¡ã«$i$åç®ã®ãã¢$a_i$ãš$b_i$($1 \leq i \leq N$)ã空çœåºåãã§äžããããã Constraints å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã $1 \leq N \leq 800 $ $0 \leq A, B \leq 10^5 $ $0 \leq a_i, b_i \leq 10^5$ $A \leq B$ ã〠$B \leq 2A$ Output æå€§ã®æäœåæ°ã1è¡ã«åºåããã Sample Input 1 5 3 5 7 2 13 1 1 1 2 9 2 4 Sample Output 1 4 (7,2)ãéžãã§åé€ããã (1,1)ãéžãã§åé€ããã (2,4)ãéžãã§åé€ããã (13, 1)ãš(2, 9)ãéžãã§åé€ããã 以äžã®ããã«æäœãããšïŒåæäœããããšãã§ãããããæå€§ãšãªãã Sample Input 2 10 7 12 34 70 36 0 12 50 76 46 33 45 61 21 0 1 24 3 98 41 23 84 Sample Output 2 5 | 39,166 |
Score : 100 points Problem Statement In this problem, you should process T testcases. For each testcase, you are given four integers N, M, A, B . Calculate \sum_{i = 0}^{N - 1} floor((A \times i + B) / M) . Constraints 1 \leq T \leq 100,000 1 \leq N, M \leq 10^9 0 \leq A, B < M Input Input is given from Standard Input in the following format: T N_0 M_0 A_0 B_0 N_1 M_1 A_1 B_1 : N_{T - 1} M_{T - 1} A_{T - 1} B_{T - 1} Output Print the answer for each testcase. Sample Input 1 5 4 10 6 3 6 5 4 3 1 1 0 0 31415 92653 58979 32384 1000000000 1000000000 999999999 999999999 Sample Output 1 3 13 0 314095480 499999999500000000 | 39,167 |
å
¥å Žæé ã¢ã€ã
æž©æ³ã«ã¯ãæµŽå ŽãšããŒã«ããããæµŽå Žãå©çšããã«ã¯å
¥æµŽåžããããŒã«ãå©çšããã«ã¯ããŒã«åžãããããè²·ãå¿
èŠããããŸãããããã®åžã®å€æ®µã¯ãæ¥ã«ãã£ãŠå€ãããããããŸããããŸããã¢ã€ã
æž©æ³ã«ã¯ä»¥äžã®ãããªã«ãŒã«ããããŸãã åžã¯è³Œå
¥åœæ¥ïŒåã®å©çšã«éãæå¹ã ãå
¥æµŽåžïŒæä»¥äžãã€ããŒã«åžïŒæä»¥äžãã§ãŸãšããŠè²·ããšããã¹ãŠã®åžãïŒå²åŒã«ãªãã æž©æ³å¥œãã®è²åãããšãã®å人ãã¡ã¯ãã¢ã€ã
æž©æ³ã«æ¯æ¥ã®ããã«éã£ãŠããŸãã圌ãã¯çæ°ãŸããã§ãæ¥ã«ãã£ãŠäœ¿ãææ°ã¯ç°ãªããŸããã¢ã€ã
æž©æ³ã«ã¯å²åŒã«ãŒã«ããããããã°ã«ãŒãã§ååããŠäžæã«è²·ãã°ãåèšæéãå®ãæžãŸãããšãã§ãããããããŸããã å
¥æµŽåžãšããŒã«åžã®æéã䜿çšããå
¥æµŽåžã®ææ°ãšããŒã«åžã®ææ°ãå
¥åãšããŠäžãããããšããæãå®ãåèšæéãåºåããããã°ã©ã ãäœæããŠãã ããããã ãã䜿çšããææ°ããå€ãåžãè²·ãããšã§åèšæéãå®ããªããªããè²·ã£ãåžãã¹ãŠã䜿ããªããšããããã®ãšããŸãã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã N x 1 y 1 b 1 p 1 x 2 y 2 b 2 p 2 : x N y N b N p N ïŒè¡ç®ã® N (1 †N †365)ã¯æéãèšç®ãããæ¥æ°ã§ãããç¶ã N è¡ã«ã i æ¥ç®ã®å
¥æµŽåžã®æé x i (100 †x i †1000)ãããŒã«åžã®æé y i (100 †y i †1000)ã䜿çšããå
¥æµŽåžã®ææ° b i (0 †b i †6)ã䜿çšããããŒã«åžã®ææ° p i (0 †p i †6)ãäžãããããå
¥æµŽåžãšããŒã«åžå
±ã«æéã¯50åå»ã¿ã§ããã åºå ããããã®æ¥ã«ã€ããŠæãå®ãåèšæéãïŒè¡ã«åºåããã å
¥åäŸ 1 2 100 100 1 1 1000 500 5 2 åºåäŸ 1 200 4800 å
¥åäŸ 2 5 500 500 1 1 500 500 5 2 1000 100 0 6 1000 100 6 0 100 1000 0 0 åºåäŸ 2 1000 2800 600 4960 0 | 39,168 |
Problem B: Square Coins People in Silverland use square coins. Not only they have square shapes but also their values are square numbers. Coins with values of all square numbers up to 289 (= 17 2 ), i.e., 1-credit coins, 4-credit coins, 9-credit coins, ..., and 289-credit coins, are available in Silverland. There are four combinations of coins to pay ten credits: ten 1-credit coins, one 4-credit coin and six 1-credit coins, two 4-credit coins and two 1-credit coins, and one 9-credit coin and one 1-credit coin. Your mission is to count the number of ways to pay a given amount using coins of Silverland. Input The input consists of lines each containing an integer meaning an amount to be paid, followed by a line containing a zero. You may assume that all the amounts are positive and less than 300. Output For each of the given amount, one line containing a single integer representing the number of combinations of coins should be output. No other characters should appear in the output. Sample Input 2 10 30 0 Output for the Sample Input 1 4 27 | 39,169 |
A: äžžä»ã åé¡ AORã€ã«ã¡ããã¯ãã¹ãã«åæ Œããããå匷ããŠããŸãã AORã€ã«ã¡ããã¯ã $N$ åãåé¡ãè§£ããŸããã ãã®åŸãè§£ããåé¡ã®äžžä»ãã以äžã®æé ã§è¡ããŸãã è§£çã®æ£èª€ã確èªããã è§£çãæ£ããå Žåã¯ãã«å°ã誀ã£ãŠããå Žåã¯ããå°ãè§£ççšçŽã«æžã蟌ãã è§£çã $2$ åé£ç¶ã§èª€ãã§ãããšããã£ãç¬éããã¹ãã«äžåæ Œã«ãªã£ãŠããŸãææãããAORã€ã«ã¡ããã¯å€±ç¥ããŠããŸããŸãããããŠããã以éäžžä»ããè¡ãããšã¯ã§ããŸããã 倱ç¥ã¯æé $1$ ãš $2$ ã®éã§èµ·ãããŸãã AORã€ã«ã¡ãããè§£ããåé¡ã®æ°ãè¡šãæŽæ° $N$ ãšãè§£çã®æ£èª€ã衚ããé·ã $N$ ã®æåå $S$ ãäžããããŸãã æåå㯠'o' ãš 'x' ãããªãã 'o' ã¯è§£çãæ£ããã 'x' ã¯è§£çã誀ãã§ããããšã衚ããŠããŸãã $i$ æåç®ã $i$ åç®ã®æ£èª€ã衚ããŠãããAORã€ã«ã¡ãã㯠$1$ åç®ããé çªã«äžžä»ããè¡ããŸãã AORã€ã«ã¡ãããæ£èª€ãæžã蟌ããå顿°ãåºåããŠãã ããã å¶çŽ $1 \leq N \leq 10^5$ å
¥ååœ¢åŒ å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã $N$ $S$ åºå AORã€ã«ã¡ãããæ£èª€ãæžã蟌ããå顿°ã $1$ è¡ã§åºåããããŸããæ«å°Ÿã«æ¹è¡ãåºåããã ãµã³ãã« ãµã³ãã«å
¥å 1 3 oxx ãµã³ãã«åºå 1 2 $3$ åç®ã®æé $1$ ãè¡ããšå€±ç¥ãããããæé $2$ ã¯è¡ããŸããã ãµã³ãã«å
¥å 2 8 oxoxoxox ãµã³ãã«åºå 2 8 ãµã³ãã«å
¥å 3 4 xxxx ãµã³ãã«åºå 3 1 | 39,170 |
Problem C: Midnight Teatime ICPCã®åœå
äºéžã«åããŠåé¡ãè§£ããŠããåã¯, ãã®æ¥3ã€ç®ã®Acceptãè²°ã£ããšããã§ããŒããŒããå©ãæãæ¢ãã. æèšãèŠãã°, ããæ¥ä»ãå€ãããããšããæå»ã . çŽ
è¶ãšãèåã§äžæããŠ, 仿¥ã¯ããå¯ãããšã«ããã. ããæã£ãŠåã¯ãããã³ãžãšåãã£ã. ããŒãžãªã³ã®ãããããéŠãããããã³ãæºãããé , 効ããã£ãŠãã. åéšçã§ãã圌女ã¯ä»æ¥ããããªæéãŸã§çé¢ç®ã«å匷ããŠããããã . åã¯åœŒå¥³ãèªã£ãŠ, å°ããªæ·±å€ã®ãè¶äŒãéãããšã«ãã. éœåã®è¯ãããšã«, ãããã³ã«ã¯4ã€ã®ãèåããã£ã. ããããã 2人ã§åããã®ãã€ãŸããªãã®ã§, åã¯ãã®ãèåãè³ããŠç°¡åãªã²ãŒã ãããªãããšææ¡ãã. ãã®ã²ãŒã ã®å
容ã説æããã. ãŸãæåã«, åã¯ã©ã®ããŒãã0åãŸãã¯2åã®åãæã€ãããªäºåæšãæžã. 次ã«, ãã®æšã®èã«åœãã(ã€ãŸã, åãæããªã)ããŒãã«, ãããã S = {a, b, c, d} ã®ä»»æã®éšåéåãæžã蟌ã. 4ã€ã®ãèåã¯, ãããã a, b, c, d ã«å¯Ÿå¿ãã. æåŸã«åйã¯, æšã®å
éšæ¥ç¹(ã€ãŸãã2ã€ã®åãæã€)ããŒãã« 'A', 'O', 'X' ã®ããããã®æåãæžã蟌ã. 効ã¯, æšã®æ ¹ã«ãããããŒãã瀺ããèåãåŸã. ãã ã, ããŒãã瀺ããèåãšã¯, ãã®ããŒããèã§ããã°, ããã«æžãããŠãããèå ãã®ããŒããå
éšæ¥ç¹ã§ããã°, ãã®ããŒãã«æžãããæåã A ã®ãšãã sl ãš sr ã®ç©éå ãã®ããŒãã«æžãããæåã O ã®ãšãã sl ãš sr ã®åéå ãã®ããŒãã«æžãããæåã X ã®ãšãã sl ãš sr ã®å¯Ÿç§°å·® ã®ããšã§ãã. ããã§ãsl ã¯ãã®ããŒãã®å·Šã®åããŒãã瀺ããèå, sr ã¯ãã®ããŒãã®å³ã®åããŒãã瀺ããèåãæã. 2ã€ã®éåã®å¯Ÿç§°å·®ã¯, ã©ã¡ããäžæ¹ã®éåã«ã®ã¿å«ãŸãããããªå
ããæãéåã§ãã. ãã®ã²ãŒã ã«åйã¯ä¹ã£ãŠãã. ããã©ããã, ãèåã4ã€ãšãå·»ãäžããŠããããšç®ãèŒãããŠãã. åºæ¥ãã°åã®åãæ®ããŠãããŠããããšå¬ããã®ã ããã©ã. åãæžããæšã«å¯ŸããŠ, 効ãå
šãŠã®ãèåãåŸããããããªå
éšæ¥ç¹ã®æžãèŸŒã¿æ¹ã¯, ãã£ããäœéãããã ãããïŒ Input å
¥åãã¡ã€ã«ã¯ãè€æ°ã®ããŒã¿ã»ãããå«ã. ããŒã¿ã»ããã®æåã®è¡ã«ã¯, æšã®æ
å ±ãäžãããã. æšã®èšè¿°ã¯, "(" <å·Šéšåæšã®èšè¿°> <äžã€ã®ã¹ããŒã¹> <å³éšåæšã®èšè¿°> ")" ãŸãã¯, <äžã€ã®æ°å> ã®ã©ã¡ããã®åœ¢åŒãåã. åè
ãå
éšæ¥ç¹ã®èšè¿°, åŸè
ãèã®èšè¿°ã§ãã. 次ã®è¡ã¯1ã€ã®æŽæ° N (N < 10) ãå«ã¿, ç¶ã N è¡ã«èã«æžã蟌ãŸããéšåéåã®æ
å ±ãäžãããã. éšåéåã®æ
å ±ã¯, ç©ºçœæåã§åºåããã4ã€ã®æ°åã§è¡šããã. 4ã€ã®æåã¯ãããã, ãã®éšåéåã a, b, c, d ãå«ããã©ããã衚ã. å«ããªãã° 1 ããå«ãŸãªããªãã° 0 ãäžãããã. èã®èšè¿°ãšããŠäžããããæ°åã n ã§ãããšãããã®èã«æžã蟌ãŸããéšåéåã¯ããã N åã®ãã¡ n çªç®ã®ãã®ã§ãã. 1 †n †N ãšä»®å®ããŠãã. äžããããæšã¯ãæå€§ 8 åã®å
éšæ¥ç¹ãå«ã. æšã®èšè¿°ã®ä»£ããã«äžãããã "END" ãšããæååã, å
¥åã®çµããã衚ã. Output åããŒã¿ã»ããã«ã€ããŠ, 効ãå
šãŠã®ãèåãåŸããããããªå
éšæ¥ç¹ã®æžãèŸŒã¿æ¹ã®æ°ããäžè¡ã«åºåãã. Sample Input (1 2) 2 0 1 0 1 1 0 1 0 ((1 2) 3) 3 1 1 0 0 1 0 1 0 0 0 0 1 END Output for the Sample Input 2 2 | 39,171 |
Network Reliability An undirected graph is given. Each edge of the graph disappears with a constant probability. Calculate the probability with which the remained graph is connected. Input The first line contains three integers N ( 1 \leq N \leq 14 ), M ( 0 \leq M \leq 100 ) and P ( 0 \leq P \leq 100 ), separated by a single space. N is the number of the vertices and M is the number of the edges. P is the probability represented by a percentage. The following M lines describe the edges. Each line contains two integers v_i and u_i ( 1 \leq u_i, v_i \leq N ). ( u_i, v_i ) indicates the edge that connects the two vertices u_i and v_i . Output Output a line containing the probability with which the remained graph is connected. Your program may output an arbitrary number of digits after the decimal point. However, the absolute error should be 10^{-9} or less. Sample Input 1 3 3 50 1 2 2 3 3 1 Output for the Sample Input 1 0.500000000000 Sample Input 2 3 3 10 1 2 2 3 3 1 Output for the Sample Input 2 0.972000000000 Sample Input 3 4 5 50 1 2 2 3 3 4 4 1 1 3 Output for the Sample Input 3 0.437500000000 | 39,172 |
Dock to the Future You had long wanted a spaceship, and finally you bought a used one yesterday! You have heard that the most difficult thing on spaceship driving is to stop your ship at the right position in the dock. Of course you are no exception. After a dozen of failures, you gave up doing all the docking process manually. You began to write a simple program that helps you to stop a spaceship. First, you somehow put the spaceship on the straight course to the dock manually. Let the distance to the limit line be x [m], and the speed against the dock be v [m/s]. Now you turn on the decelerating rocket. Then, your program will control the rocket to stop the spaceship at the best position. Your spaceship is equipped with a decelerating rocket with n modes. When the spaceship is in mode- i (0 †i < n ), the deceleration rate is a i [m/s 2 ]. You cannot re-accelerate the spaceship. The accelerating rocket is too powerful to be used during docking. Also, you cannot turn off-and-on the decelerating rocket, because your spaceship is a used and old one, once you stopped the rocket, it is less certain whether you can turn it on again. In other words, the time you turn off the rocket is the time you stop your spaceship at the right position. After turning on the deceleration rocket, your program can change the mode or stop the rocket at every sec- ond, starting at the very moment the deceleration began. Given x and v , your program have to make a plan of deceleration. The purpose and the priority of your program is as follows: Stop the spaceship exactly at the limit line. If this is possible, print âperfectâ. If it is impossible, then stop the spaceship at the position nearest possible to the limit line, but before the line. In this case, print âgood d â, where d is the distance between the limit line and the stopped position. Print three digits after the decimal point. If it is impossible again, decelerate the spaceship to have negative speed, and print âtry againâ. If all of these three cases are impossible, then the spaceship cannot avoid overrunning the limit line. In this case, print âcrashâ. Input The first line of the input consists of a single integer c , the number of test cases. Each test case begins with a single integer n (1 †n †10), the number of deceleration modes. The following line contains n positive integers a 0 , . . . , a n-1 (1 †a i †100), each denoting the deceleration rate of each mode. The next line contains a single integer q (1 †q †20), and then q lines follow. Each of them contains two positive integers x and v (1 †x , v †100) defined in the problem statement. Output For each pair of x and v , print the result in one line. A blank line should be inserted between the test cases. Sample Input 1 3 2 4 6 4 10 100 2 3 10 6 7 6 Output for the Sample Input crash try again good 1.000 perfect | 39,173 |
Problem E: Rooted Tree Game Problem åæç¶æ
ãšããŠè€æ°ã®æ ¹ä»ãæšãäžãããããããã«å¯ŸãAliceãšBobã¯ã²ãŒã ãè¡ããã²ãŒã ã¯2人亀äºã«è¡ããå
æãAliceã§åŸæãBobã§ãããã¿ãŒã³ãåã£ãŠãããã¬ã€ã€ãŒã¯ä»¥äžã®è¡åãåãã æ ¹(芪ãæããªãé ç¹)ã1ã€éžæããããã®é ç¹ã S ãšããã S ãæ ¹ãšããæ ¹ä»ãæšã«å«ãŸããé ç¹ãéžæãã(ããã§ã¯ S ãéžæå¯èœ)ããã®é ç¹ã T ãšããã S ãã T ãžã®çµè·¯äžã«ããé ç¹ãã S ãš T ãå«ããã¹ãŠåé€ããããŸããåé€ãããé ç¹ã端ç¹ã§ãããããªèŸºããã¹ãŠåé€ããã ã¿ãŒã³ãåã£ãŠããæç¹ã§é ç¹ããã¹ãŠåé€ãããŠããå Žåããã®ãã¬ã€ã€ãŒã®è² ããšãªãã AliceãšBobãåžžã«æé©ãªè¡åãåãæãäžããããåæç¶æ
ã«å¯Ÿããåå©ãããã¬ã€ã€ãŒãå€å®ããã 以äžã®å³ã¯ããã¬ã€ã€ãŒã®è¡åã®äŸã瀺ãã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã N M p 1 p 2 : p M 1è¡ç®ã«ãåæç¶æ
ã®é ç¹æ° N ãšèŸºã®æ° M ã空çœåºåãã§äžããããããã®æãåé ç¹ã衚ãçªå·ã¯1~ N ã§ãããæ¬¡ã® M è¡ã§ã¯ãèŸºã®æ
å ±ãäžããããããã®ãã¡ i è¡ç®ã§ã¯1ã€ã®æŽæ° p i ãäžãããããããã¯ãé ç¹ p i ããé ç¹ i ãžã®èŸºãããããšã衚ããèšãæãããšãé ç¹ i ã®èŠªãé ç¹ p i ã§ããããšã衚ãã Constraints å
¥åã¯ä»¥äžã®å¶çŽãæºããã 1 †N †1000 0 †M < N i < p i †N ( 1 †i †M ) Output åå©ãããã¬ã€ã€ãŒã®åå(AliceãŸãã¯Bob)ã1è¡ã«åºåããã Sample Input1 6 3 4 4 5 Sample Output1 Alice Sample Input2 6 4 2 5 4 5 Sample Output2 Bob | 39,174 |
H - æ€æ å顿 ãšãã倧åŠã®éæ³åŠéšã®çåŸã§ããKåã¯åºå€§ãªå±æ·ã«äœãã§ããïŒ å±æ·ã®è£ã«ã¯æãåºãã£ãŠãããïŒæã
æšãçããŠããªãç®æããã£ãïŒ ãã®ãŸãŸã§ã¯å±æ·ããã®èŠãç®ãæªããšæããã®ã§ïŒKåã¯æšãçããŠããªãç®æã«æšãæ€ããããšã«æ±ºããïŒ éæ³äœ¿ãã®åµã§ããKåã¯äœ¿ãéãå¬åããããšãåºæ¥ãã®ã§ïŒæ€æã®äœæ¥ã䜿ãéã«ããããããšèããïŒ æã¯ H à W åã®ã»ã«ãæã€é·æ¹åœ¢é åãšã¿ãªãããšãåºæ¥ãïŒ åã»ã«ã¯æšã1æ¬çããŠããã1æ¬ãçããŠããªããã®ã©ã¡ããã§ããïŒ Kåã¯ãã® H à W åã®ã»ã«ã®ã©ãã 1 ã€ãæå®ãïŒããã«äœ¿ãéãå¬åããïŒ ãããKåã¯ãŸã æªçè
ãªã®ã§ïŒéåã調ç¯ããããšãåºæ¥ãïŒäœ¿ãéãå¬åãããšãã¯å¿
ã 5 å¹å¬åããŠããŸãïŒ ããã«æªãããšã«ïŒKåãå¬åãã䜿ãéã¯ã²ããããã®ã§ïŒèšªããã»ã«ã«æšãçããŠããªãå Žåã¯ããã«æšãæ€ãããïŒèšªããã»ã«ã«æ¢ã«æšãçããŠããå Žåã¯ãã®ã»ã«ã®æšãæ¶ããŠããŸãïŒ å¬åããã䜿ãéã®ãã¡ã® 4 å¹ã¯ïŒæå®ãããã»ã«ãå§ç¹ãšããŠæ±è¥¿ååã«æ£ãã°ã1çŽç·äžãé²ã¿ïŒ1ã€1ã€ã»ã«ã蚪ããŠããïŒãããã®äœ¿ãéã¯æã®å€ã«åºããšæ¶ããïŒ æ®ãã®äœ¿ãéã¯æå®ãããã»ã«ã®ã¿ã蚪åãïŒãã®åŸçŽã¡ã«æ¶ããïŒ ããæ£ç¢ºã«èšãã°ïŒKåãã»ã« (i, j) ã«äœ¿ãéãå¬åãããšïŒ i è¡ç®ãæã㯠j åç®ã«ãã H+W-1 åã®ã»ã«ã«å¯ŸãïŒ æšãçããŠããªããã°æšãæ€ãããïŒæšãçããŠããã°æšãæ¶ããããšããæäœãè¡ãããïŒ å¬åã«ã¯å€ãã®éåãå¿
èŠãšããã®ã§ïŒåºæ¥ãã ãå°ãªãå¬ååæ°ã§æãæšã§èŠãã€ããããïŒ Kåã¯ã©ã®ã»ã«ã«äœ¿ãéãå¬åããã°æå°ã®å¬ååæ°ã§æãæšã§èŠãã€ããããšãåºæ¥ãã ãããïŒ å
¥ååœ¢åŒ å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ H W a 1,1 ... a 1,W ... a H,1 ... a H,W a i,j ã 1 ãªãã»ã« (i,j) ã«æšãçããŠããããšãæå³ã, 0 ãªãçããŠããªãããšãæå³ããïŒ åºååœ¢åŒ ããæãæšã§èŠãã€ããããšãäžå¯èœãªãïŒ1è¡ã« Impossible ãåºåããïŒ ããã§ãªããã°ïŒå¬ååæ°ãæå°ã«ãããããªå¬åæé ã以äžã®åœ¢åŒã§ H è¡ã«åºåããïŒ b 1,1 ... b 1,W ... b H,1 ... b H,W b i,j 㯠0 ããã㯠1 ã§ãªããã°ãªãã, 1 ãªãã»ã« (i,j) ã«äœ¿ãéãå¬åããäºãæå³ãïŒ 0 ãªãå¬åããªãäºãæå³ããïŒ 2ååãå Žæã«äœ¿ãéãå¬åããŠãæå³ãç¡ãããšã«æ³šæããïŒå¬ååæ°ãæå°ã«ãããããªå¬åæé ãè€æ°ããå Žåã¯ã©ããåºåããŠãè¯ãïŒ å¶çŽ 2 †HïŒW †1000 HïŒW ã¯å¶æ° a i,j â {0, 1} ãã®åé¡ã®å€å®ã«ã¯ïŒ3 ç¹åã®ãã¹ãã±ãŒã¹ã®ã°ã«ãŒããèšå®ãããŠããïŒ ãã®ã°ã«ãŒãã«å«ãŸãããã¹ãã±ãŒã¹ã¯äžèšã®å¶çŽã«å ããŠäžèšã®å¶çŽãæºããïŒ H à W †20 å
¥åºåäŸ å
¥åäŸ 1 4 4 0 0 0 1 0 1 1 0 0 1 1 0 1 0 0 0 åºåäŸ 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 ã»ã« (1,1) ãšã»ã« (4,4) ã«äœ¿ãéãå¬åããããšã§æãæšã§èŠãã€ããããšãåºæ¥ãïŒ Writer: ç°æåç¯ Tester: è±ç°è£äžæ | 39,175 |
Problem G: Entangled Tree The electronics division in Ishimatsu Company consists of various development departments for electronic devices including disks and storages, network devices, mobile phones, and many others. Each department covers a wide range of products. For example, the department of disks and storages develops internal and external hard disk drives, USB thumb drives, solid-state drives, and so on. This situation brings staff in the product management division difficulty categorizing these numerous products because of their poor understanding of computer devices. One day, a staff member suggested a tree-based diagram named a category diagram in order to make their tasks easier. A category diagram is depicted as follows. Firstly, they prepare one large sheet of paper. Secondly, they write down the names of the development departments on the upper side of the sheet. These names represent the start nodes of the diagram. Each start node is connected to either a single split node or a single end node (these nodes will be mentioned soon later). Then they write down a number of questions that distinguish features of products in the middle, and these questions represent the split nodes of the diagram. Each split node is connected with other split nodes and end nodes, and each line from a split node is labeled with the answer to the question. Finally, they write down all category names on the lower side, which represents the end nodes . The classification of each product is done like the following. They begin with the start node that corresponds to the department developing the product. Visiting some split nodes, they traces the lines down until they reach one of the end nodes labeled with a category name. Then they find the product classified into the resultant category. The visual appearance of a category diagram makes the diagram quite understandable even for non-geek persons. However, product managers are not good at drawing the figures by hand, so most of the diagrams were often messy due to many line crossings. For this reason, they hired you, a talented programmer, to obtain the clean diagrams equivalent to their diagrams. Here, we mean the clean diagrams as those with no line crossings. Your task is to write a program that finds the clean diagrams. For simplicity, we simply ignore the questions of the split nodes, and use integers from 1 to N instead of the category names. Input The input consists of multiple datasets. Each dataset follows the format below: N M Q split node info 1 split node info 2 ... split node info M query 1 query 2 ... query Q The first line of each dataset contains three integers N (1 †N †100000), M (0 †M †N - 1), and Q (1 †Q †1000, Q †N ), representing the number of end nodes and split nodes, and the number of queries respectively. Then M lines describing the split nodes follow. Each split node is described in the format below: Y L label 1 label 2 . . . The first two integers, Y (0 †Y †10 9 ) and L , which indicates the y -coordinate where the split node locates (the smaller is the higher) and the size of a label list. After that, L integer numbers of end node labels which directly or indirectly connected to the split node follow. This is a key information for node connections. A split node A is connected to another split node B if and only if both A and B refer (at least) one identical end node in their label lists, and the y-coordinate of B is the lowest of all split nodes referring identical end nodes and located below A. The split node is connected to the end node if and only if that is the lowest node among all nodes which contain the same label as the end nodeâs label. The start node is directly connected to the end node, if and only if the end node is connected to none of the split nodes. After the information of the category diagram, Q lines of integers follow. These integers indicate the horizontal positions of the end nodes in the diagram. The leftmost position is numbered 1. The input is terminated by the dataset with N = M = Q = 0, and this dataset should not be processed. Output Your program must print the Q lines, each of which denotes the label of the end node at the position indicated by the queries in the clean diagram. One blank line must follow after the output for each dataset. Sample Input 3 2 3 10 2 1 2 20 2 3 2 1 2 3 5 2 5 10 3 1 2 4 20 3 2 3 5 1 2 3 4 5 4 1 4 10 2 1 4 1 2 3 4 4 3 4 30 2 1 4 20 2 2 4 10 2 3 4 1 2 3 4 4 3 4 10 2 1 4 20 2 2 4 30 2 3 4 1 2 3 4 4 3 4 10 2 1 2 15 2 1 4 20 2 2 3 1 2 3 4 3 2 3 10 2 2 3 20 2 1 2 1 2 3 1 0 1 1 0 0 0 Output for the Sample Input 1 2 3 1 2 3 5 4 1 4 2 3 1 4 2 3 1 2 3 4 1 4 2 3 1 2 3 1 | 39,176 |
ç¹°ãè¿ãåªæ å€ä»£åœå®¶ã€ã¯ã·ããçºèŠã調æ»ãé²ããæã
ç ç©¶è
ã¯ãã€ãã«ã€ã¯ã·ãã®äžå¿éšã«ããç¥æ®¿ãçºèŠãããç¥æ®¿ã«ã¯ã€ã¯ã·ãã®ç¥ã«ããããç³çãä¿ç®¡ãããŠãããç³çã«ã¯ãæç« ãšåªæãäžã€ãã€ãïŒã€ã®æååãæžãããŠããã ã€ã¯ã·ãã§ã¯åªæãæç« ã®äžã«ãäœåçŸããããéèŠãªæå³ãæã€ããã ããåªæã«å«ãŸãããã¹ãŠã®æåãé çªã«ãæç« ã®äžã«ãšã³ãšã³ã§çŸãããã®ãïŒåçŸããŠãããšèãããäŸãã°ãæç« ã"abab" ã§ãåªæã "ab" ã§ããã°ãé£ç¶ã§ãªããã®ãå«ã㊠"ab" 㯠"abab" ã®äžã«ïŒåçŸãããŠããïŒ ab ab, ab ab , a ba b ã®ïŒéãïŒã æç« ãšåªæãäžãããããšããåªæãæç« ã®äžã«äœåçŸããããåºåããããã°ã©ã ãäœæããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã t b ïŒè¡ç®ã«ãç³çã«æžãããæç« ã衚ãæååtãäžãããããïŒè¡ç®ã«ãç³çã«æžãããåªæã衚ãæååbãäžãããããã©ã¡ãã®æååãè±å°æåã ãããæããé·ãã1以äž1000以äžã®æååã§ããã Output åªæãæç« ã®äžã«äœåçŸããããïŒè¡ã«åºåããããã ããåºåãã¹ãå€ã¯éåžžã«å€§ãããªãããã®ã§ã代ããã« 1,000,000,007 ã§å²ã£ãäœããåºåããã Sample Input 1 abab ab Sample Output 1 3 Sample Input 2 aaaabaaaabaaaabaaaab aaaaa Sample Output 2 4368 Sample Input 3 data structure Sample Output 3 0 | 39,177 |
C: æé·ããç¹ - Growing Point - åé¡ ç²èã³ã³ãã¥ãŒã¿ãšãããã®ãããã ããçš®ã®ç²èã«ã¯ãé€ãæ±ããé€ãšé€ã®æçè·é¢ãã€ãªã圢ã«å€åœ¢ããã ãšããæ§è³ªãããã ãããå©çšããé€ããå
¥åãã圢ããåºåããšã¿ãªã㊠ã³ã³ãã¥ãŒã¿ãšããŠå©çšããããšãã§ããã ä»ãäºæ¬¡å
å¹³é¢äžã«1ã€ã®ç²èã®æ ç¹ãš N åã®é€ãååšãããããããã®é€ã«ã¯ 1 ãã N ãŸã§ã®ç°ãªãçªå·ãäžããããæ ç¹ã«ã¯çªå·0ãäžããããŠããã ãã®ç²èã¯ããé€ãé£ã¹ãããã«ããã®é€ãšæãè¿ãæ ç¹ã®æçè·é¢ãçµã¶ç®¡ç¶ã« æé·ããé£ã¹ãäœçœ®ã«æ°ãã«æ ç¹ã圢æããã æ°ãã«åœ¢æããæ ç¹ã¯æ ç¹ã圢æããçŽåã«é£ã¹ãé€ãšåãçªå·ãæã€ã ç²èã¯æ ç¹ä»¥å€ã®å Žæããæé·ããããšã¯ã§ããªãã 以éã§ã¯ãæ ç¹ãšé€ãäºæ¬¡å
å¹³é¢äžã®ç¹ã管ç¶ã«æé·ããç²èãè€æ°ã®ç·åãšããŠèããã ãã¹ãŠã®æ ç¹ãšç·åãããªãæ§é ãç²èç¶²ãšåŒã¶ã ç²èã¯1ã€ã®é€ãé£ã¹ãããã«æ¬¡ã®ãããªæäœãç¹°ãè¿ãã ãŸã é£ã¹ãŠããªãé€ã®äžã§ç²èç¶²ã«æãè¿ãé€ãéžã¶ããã®ãããªé€ãè€æ°ååšããå Žåã¯çªå·ãæãå°ããé€ãéžã¶ã éžãã é€ãšæãè¿ãæ ç¹ãéžã¶ããã®ãããªæ ç¹ãè€æ°ååšããå Žåã¯ãæãæ ç¹ã®çªå·ãå°ãããã®ããåãã éžãã æ ç¹ãšé€ãçµã¶ç·åãåŒãã以éã§ã¯ãã®ãšãéžãã é€ãæ ç¹ãšããŠæ±ãã ãã®ç²èã¯çããããã«å¿
èŠãªæ é€ãåãã®ã« M åã®é€ãé£ã¹ãå¿
èŠãããã ç²èã M åã®é€ãé£ã¹ããŸã§ã«åŒãããã¹ãŠã®ç·åã®é·ãã®åèšãæ±ããã ãŸããåºåããå€ã¯0.0001以äžã®èª€å·®ãå«ãã§ããŠãè¯ãã 以äžã®å³ã§ã¯å
¥åäŸ2ã®ç²èã®æ§åã瀺ããŠããã å
¥ååœ¢åŒ N M X Y px_1 py_1 ... px_n py_n 1 è¡ç®ã«ã¯é€ã®æ° N ïŒ 1 \†N \†5,000 ïŒãé£ã¹ãé€ã®åæ° M ïŒ 1 \†M \†N ïŒãçªå·0ã®æ ç¹ã®åº§æš X , Y ïŒ â5,000 \†X, Y \†5,000 ïŒãæŽæ°å€ã§äžãããããç¶ã N è¡ã«ã¯çªå·é ã«é€ã®åº§æš px_i , py_i ïŒ 1 \†i \†N ïŒãæŽæ°å€ã§äžãããããïŒ â5,000 \†px_i, py_i \†5,000 ïŒ ãŸããçªå·ãç°ãªãé€ã¯ç°ãªã座æšã«ååšããããããã®é€ãšçªå·0ã®æ ç¹ã®åº§æšã¯ç°ãªãã åºååœ¢åŒ æé·ããè·é¢ã®åèšã1è¡ã§åºåããããŸããåºåããå€ã¯0.0001以äžã®èª€å·®ãå«ãã§ããŠãè¯ãã å
¥åäŸ1 2 2 0 0 3 3 4 0 åºåäŸ1 7.16227766017 æåã¯çªå·1ã®é€ãšæ ç¹ã®è·é¢ã $3\sqrt{2}$ ãšçªå·2ã®é€ãšæ ç¹ã®è·é¢ã 4 ãªã®ã§ çªå·2ã®é€ãéžã°ããããã®åŸçªå·1ã®é€ãšç²èç¶²ãšã®è·é¢ã 3 ã«ãªããçªå·1ã®é€ãéžã°ããã å
¥åäŸ2 4 4 1 3 3 3 2 1 3 1 1 1 åºåäŸ2 6.2360679775 å³ã®ããã«é€1ã2ã4ã3ã®é ã«ç²èã¯é€ãé£ã¹ãŠãã å
¥åäŸ3 16 15 -4077 763 -2480 2841 -2908 -1096 676 -4080 -4988 -2634 3004 -1360 -2272 1773 -4344 -3631 -355 4426 -3740 3634 -3330 2191 -3423 -2999 -3438 2281 4754 -1500 -3440 -3873 -2089 -3419 1426 2793 åºåäŸ3 25349.9626798834 | 39,178 |
Patisserie ACM Amber Claes Maes, a patissier, opened her own shop last month. She decided to submit her work to the International Chocolate Patissier Competition to promote her shop, and she was pursuing a recipe of sweet chocolate bars. After thousands of trials, she finally reached the recipe. However, the recipe required high skill levels to form chocolate to an orderly rectangular shape. Sadly, she has just made another strange-shaped chocolate bar as shown in Figure G-1. Figure G-1: A strange-shaped chocolate bar Each chocolate bar consists of many small rectangular segments of chocolate. Adjacent segments are separated with a groove in between them for ease of snapping. She planned to cut the strange-shaped chocolate bars into several rectangular pieces and sell them in her shop. She wants to cut each chocolate bar as follows. The bar must be cut along grooves. The bar must be cut into rectangular pieces. The bar must be cut into as few pieces as possible. Following the rules, Figure G-2 can be an instance of cutting of the chocolate bar shown in Figure G-1. Figures G-3 and G-4 do not meet the rules; Figure G-3 has a non-rectangular piece, and Figure G-4 has more pieces than Figure G-2. Figure G-2: An instance of cutting that follows the rules Figure G-3: An instance of cutting that leaves a non-rectangular piece Figure G-4: An instance of cutting that yields more pieces than Figure G-2 Your job is to write a program that computes the number of pieces of chocolate after cutting according to the rules. 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. h w r (1, 1) ... r (1, w ) r (2, 1) ... r (2, w ) ... r ( h , 1) ... r ( h , w ) The integers h and w are the lengths of the two orthogonal dimensions of the chocolate, in number of segments. You may assume that 2 †h †100 and 2 †w †100. Each of the following h lines consists of w characters, each is either a " . " or a " # ". The character r ( i , j ) represents whether the chocolate segment exists at the position ( i , j ) as follows. " . ": There is no chocolate. " # ": There is a segment of chocolate. You can assume that there is no dataset that represents either multiple disconnected bars as depicted in Figure G-5 or a bar in a shape with hole(s) as depicted in Figure G-6 and G-7. You can also assume that there is at least one " # " character in each dataset. Figure G-5: Disconnected chocolate bars Figure G-6: A chocolate bar with a hole Figure G-7: Another instance of a chocolate bar with a hole Output For each dataset, output a line containing the integer representing the number of chocolate pieces obtained by cutting according to the rules. No other characters are allowed in the output. Sample Input 3 5 ###.# ##### ###.. 4 5 .#.## .#### ####. ##.#. 8 8 .#.#.#.# ######## .######. ######## .######. ######## .######. ######## 8 8 .#.#.#.# ######## .##.#.#. ##....## .##.###. ##...### .##.###. ###.#.## 4 4 #### #### #### #### 0 0 Output for the Sample Input 3 5 11 19 1 | 39,180 |
Score : 400 points Problem Statement There is a grid of square cells with H horizontal rows and W vertical columns. The cell at the i -th row and the j -th column will be denoted as Cell (i, j) . In Cell (i, j) , a_{ij} coins are placed. You can perform the following operation any number of times: Operation: Choose a cell that was not chosen before and contains one or more coins, then move one of those coins to a vertically or horizontally adjacent cell. Maximize the number of cells containing an even number of coins. Constraints All values in input are integers. 1 \leq H, W \leq 500 0 \leq a_{ij} \leq 9 Input Input is given from Standard Input in the following format: H W a_{11} a_{12} ... a_{1W} a_{21} a_{22} ... a_{2W} : a_{H1} a_{H2} ... a_{HW} Output Print a sequence of operations that maximizes the number of cells containing an even number of coins, in the following format: N y_1 x_1 y_1' x_1' y_2 x_2 y_2' x_2' : y_N x_N y_N' x_N' That is, in the first line, print an integer N between 0 and H \times W (inclusive), representing the number of operations. In the (i+1) -th line ( 1 \leq i \leq N ), print four integers y_i, x_i, y_i' and x_i' ( 1 \leq y_i, y_i' \leq H and 1 \leq x_i, x_i' \leq W ), representing the i -th operation. These four integers represents the operation of moving one of the coins placed in Cell (y_i, x_i) to a vertically or horizontally adjacent cell, (y_i', x_i') . Note that if the specified operation violates the specification in the problem statement or the output format is invalid, it will result in Wrong Answer . Sample Input 1 2 3 1 2 3 0 1 1 Sample Output 1 3 2 2 2 3 1 1 1 2 1 3 1 2 Every cell contains an even number of coins after the following sequence of operations: Move the coin in Cell (2, 2) to Cell (2, 3) . Move the coin in Cell (1, 1) to Cell (1, 2) . Move one of the coins in Cell (1, 3) to Cell (1, 2) . Sample Input 2 3 2 1 0 2 1 1 0 Sample Output 2 3 1 1 1 2 1 2 2 2 3 1 3 2 Sample Input 3 1 5 9 9 9 9 9 Sample Output 3 2 1 1 1 2 1 3 1 4 | 39,182 |
Score : 300 points Problem Statement We have N clocks. The hand of the i -th clock (1â€iâ€N) rotates through 360° in exactly T_i seconds. Initially, the hand of every clock stands still, pointing directly upward. Now, Dolphin starts all the clocks simultaneously. In how many seconds will the hand of every clock point directly upward again? Constraints 1â€Nâ€100 1â€T_iâ€10^{18} All input values are integers. The correct answer is at most 10^{18} seconds. Input Input is given from Standard Input in the following format: N T_1 : T_N Output Print the number of seconds after which the hand of every clock point directly upward again. Sample Input 1 2 2 3 Sample Output 1 6 We have two clocks. The time when the hand of each clock points upward is as follows: Clock 1 : 2 , 4 , 6 , ... seconds after the beginning Clock 2 : 3 , 6 , 9 , ... seconds after the beginning Therefore, it takes 6 seconds until the hands of both clocks point directly upward. Sample Input 2 5 2 5 10 1000000000000000000 1000000000000000000 Sample Output 2 1000000000000000000 | 39,183 |
Score : 100 points Problem Statement You will be given a string S of length 3 representing the weather forecast for three days in the past. The i -th character (1 \leq i \leq 3) of S represents the forecast for the i -th day. S , C , and R stand for sunny, cloudy, and rainy, respectively. You will also be given a string T of length 3 representing the actual weather on those three days. The i -th character (1 \leq i \leq 3) of S represents the actual weather on the i -th day. S , C , and R stand for sunny, cloudy, and rainy, respectively. Print the number of days for which the forecast was correct. Constraints S and T are strings of length 3 each. S and T consist of S , C , and R . Input Input is given from Standard Input in the following format: S T Output Print the number of days for which the forecast was correct. Sample Input 1 CSS CSR Sample Output 1 2 For the first day, it was forecast to be cloudy, and it was indeed cloudy. For the second day, it was forecast to be sunny, and it was indeed sunny. For the third day, it was forecast to be sunny, but it was rainy. Thus, the forecast was correct for two days in this case. Sample Input 2 SSR SSR Sample Output 2 3 Sample Input 3 RRR SSS Sample Output 3 0 | 39,184 |
G: Restricted DFS åé¡ N é ç¹ N-1 蟺ãããªããèªå·±ã«ãŒããå€é蟺ãååšããªãç¡åæš G ããããé ç¹ã¯ãããã 1 ãã N ãŸã§çªå·ä»ããããŠããã蟺ããããã 1 ãã N-1 ãŸã§çªå·ä»ããããŠããã i çªç®ã®èŸºã¯ u_i ãš v_i ãçµãã§ããããŸãã i çªç®ã®é ç¹ã«ã¯éè² æŽæ° A_i ãããããå²ãåœãŠãããŠããã ãã®æšã«å¯ŸããŠãæ ¹ r ãã以äžã®æ¬äŒŒã³ãŒãã«ãããã£ãŠ DFS (æ·±ãåªå
æ¢çŽ¢) ãè¡ãããšãèããã // [input] // G: dfs ã®å¯Ÿè±¡ãšãªãã°ã©ã // A: ããããã®é ç¹ã«å²ãåœãŠãããéè² æŽæ° // v: dfs ãéå§ããé ç¹ // step: ã¹ãããæ°ãèšé²ããæŽæ° // [output] // 以äžã®ãã¡ã©ã¡ããã®äºå€ // - SUCCESS: dfs ãéäžã§çµäºããããšãªããé ç¹ v ãŸã§æ»ã£ãŠãã // - FAILURE: dfs ãéäžã§çµäºãã function dfs(G, A, v, step) if (A[v] ã 0 ã§ãã) then return FAILURE A[v] â A[v] - 1 step â step + 1 v ã®åãé ç¹çªå·ãå°ããé ã«ãœãŒã // c ã¯é ç¹çªå·ãå°ããé ã«èŠããã for each (v ã®å c) do if (dfs(G, A, c, step) ã FAILURE ã§ãã) then return FAILURE if (A[v] ã 0 ã§ãã) then return FAILURE A[v] â A[v] - 1 step â step + 1 return SUCCESS ã€ãŸããäžãããã G ãš A ã«å¯ŸããŠãæ ¹ r ã«ã€ã㊠dfs(G, A, r, 0) ãå®è¡ããããšãèããã ããããã®é ç¹ãæ ¹ãšãããšãã®ããã® DFS ã®ã¹ãããæ°ãæ±ããã å
¥ååœ¢åŒ N A_1 ... A_N u_1 v_1 ... u_{N-1} v_{N-1} 1 è¡ç®ã§ã¯ãäžããããã°ã©ãã®é ç¹æ° N ãäžããããã 2 è¡ç®ã¯ N åã®æŽæ°ãããªãã i åç®ã®æŽæ° A_i ã¯ã i çªç®ã®é ç¹ã«æžãããŠããå€ã衚ãã 3 è¡ç®ãã N+1 è¡ç®ãŸã§ã¯ãäžããããã°ã©ãã®èŸºã®æ
å ±ãäžããããã u_i, v_i ã¯ãé ç¹ u_i ãšé ç¹ v_i ãçµã¶ç¡å蟺ãã°ã©ãäžã«ååšããããšã衚ãã å¶çŽ 1 \leq N \leq 3 \times 10^5 0 \leq A_i \leq 10^9 1 \leq u_i < v_i \leq N äžããããã°ã©ãã¯æšã§ããããšãä¿èšŒããã å
¥åã¯å
šãп޿°ã§äžãããã åºååœ¢åŒ N è¡åºåããã i è¡ç®ã«ã¯ãé ç¹ i ãæ ¹ãšãããšãã®ã¹ãããæ°ãåºåããã å
¥åäŸ1 3 1 2 3 1 2 1 3 åºåäŸ1 2 3 3 1 çªç®ã®é ç¹ãæ ¹ãšãããšã é ç¹ 1 ( A_1 : 1 â 0 ) â é ç¹ 2 ( A_2 : 2 â 1 ) â é ç¹ 1 ( A_1 ã 0 ã§ãããããé ç¹ 1 ã«èšªããããšãªãçµäºãã) 2 çªç®ã®é ç¹ãæ ¹ãšãããšã é ç¹ 2 ( A_2 : 2 â 1 ) â é ç¹ 1 ( A_1 : 1 â 0 ) â é ç¹ 3 ( A_3 : 3 â 2 ) â é ç¹ 1 ( A_1 ã 0 ã§ãããããé ç¹ 1 ã«èšªããããšãªãçµäºãã) 3 çªç®ã®é ç¹ãæ ¹ãšãããšã é ç¹ 3 ( A_3 : 3 â 2 ) â é ç¹ 1 ( A_1 : 1 â 0 ) â é ç¹ 2 ( A_2 : 2 â 1 ) â é ç¹ 1 ( A_1 ã 0 ã§ãããããé ç¹ 1 ã«èšªããããšãªãçµäºãã) ãã£ãŠãçãã¯ãããã 2, 3, 3 ãšãªããã¯ããã«æ ¹ããåºçºãããšãã A_i ã®å€ãæžããããšã«æ³šæããã å
¥åäŸ2 3 1 2 3 1 2 2 3 åºåäŸ2 4 4 5 | 39,185 |
Addition of Big Integers Given two integers $A$ and $B$, compute the sum, $A + B$. Input Two integers $A$ and $B$ separated by a space character are given in a line. Output Print the sum in a line. Constraints $-1 \times 10^{100000} \leq A, B \leq 10^{100000}$ Sample Input 1 5 8 Sample Output 1 13 Sample Input 2 100 25 Sample Output 2 125 Sample Input 3 -1 1 Sample Output 3 0 Sample Input 4 12 -3 Sample Output 4 9 | 39,186 |
H: æ
æ² (Mercy) ãµã³ã¿ã¯ããŒã¹ã¯ãã¯ãªã¹ãã¹ãªã®ã«ããã°ã©ãã³ã°ããã£ãŠããéå£ãèŠã€ããã ãµã³ã¿ã¯ããŒã¹ã¯åœŒããå¯åæ³ã«æã£ãã®ã§ãã±ãŒãããã¬ãŒã³ãããããšã«ããã ã¯ãªãŒã ã $N$ çš®é¡ãã£ãŠãçŸå³ãã㯠$A_1, A_2, A_3, \dots, A_N$ ã§ããã ã¹ãã³ãžã $M$ çš®é¡ãã£ãŠãçŸå³ãã㯠$B_1, B_2, B_3, \dots, B_M$ ã§ããã ã¯ãªãŒã 1 çš®é¡ãšã¹ãã³ãž 1 çš®é¡ãçµã¿åãããŠã±ãŒããäœãããã®çŸå³ãã㯠(ã¯ãªãŒã ã®çŸå³ãã) à (ã¹ãã³ãžã®çŸå³ãã) ã«ãªãã ãµã³ã¿ã¯ããŒã¹ã¯æ
æ²æ·±ãã®ã§ã$N \times M$ éãã®çµã¿åããã®ã±ãŒãããã¹ãŠäžã€ãã€äœã£ãã ã±ãŒãã®çŸå³ããã¯åèšããã€ãã å
¥å 1 è¡ç®ã«ã¯ãæŽæ° $N, M$ ã空çœåºåãã§äžããããã 2 è¡ç®ã«ã¯ãæŽæ° $A_1, A_2, A_3, \dots, A_N$ ã空çœåºåãã§äžããããã 3 è¡ç®ã«ã¯ãæŽæ° $B_1, B_2, B_3, \dots, B_M$ ã空çœåºåãã§äžããããã åºå ãµã³ã¿ã¯ããŒã¹ã®äœã£ãã±ãŒãã®çŸå³ããã®åèšãåºåãããæåŸã«ã¯æ¹è¡ãå
¥ããããšã å¶çŽ $N, M$ 㯠$1$ ä»¥äž $100 \ 000$ 以äžã®æŽæ° $A_1, A_2, A_3, \dots, A_N$ 㯠$1$ ä»¥äž $1 \ 000$ 以äžã®æŽæ° $B_1, B_2, B_3, \dots, B_M$ 㯠$1$ ä»¥äž $1 \ 000$ 以äžã®æŽæ° 泚æ çãã 32 bit æŽæ°å (int åãªã©) ã®ç¯å²ã«åãŸããªãå¯èœæ§ãããã®ã§ã64 bit æŽæ°å (long long åãªã©) ã䜿ããŸãããã å
¥åäŸ1 3 2 3 1 5 2 4 åºåäŸ1 54 ãµã³ã¿ã¯ããŒã¹ã¯ã次㮠6 çš®é¡ã®ã±ãŒããäœããŸãã ã¯ãªãŒã 1 ãšã¹ãã³ãž 1 ãçµã¿åãããã±ãŒãã®çŸå³ããïŒ$3 \times 2 = 6$ ã¯ãªãŒã 1 ãšã¹ãã³ãž 2 ãçµã¿åãããã±ãŒãã®çŸå³ããïŒ$3 \times 4 = 12$ ã¯ãªãŒã 2 ãšã¹ãã³ãž 1 ãçµã¿åãããã±ãŒãã®çŸå³ããïŒ$1 \times 2 = 2$ ã¯ãªãŒã 2 ãšã¹ãã³ãž 2 ãçµã¿åãããã±ãŒãã®çŸå³ããïŒ$1 \times 4 = 4$ ã¯ãªãŒã 3 ãšã¹ãã³ãž 1 ãçµã¿åãããã±ãŒãã®çŸå³ããïŒ$5 \times 2 = 10$ ã¯ãªãŒã 3 ãšã¹ãã³ãž 2 ãçµã¿åãããã±ãŒãã®çŸå³ããïŒ$5 \times 4 = 20$ åèšã®çŸå³ãã㯠$54$ ãšãªããŸãã å
¥åäŸ2 10 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 åºåäŸ2 3025 | 39,187 |
Score : 400 points Problem Statement You are given a sequence A_1, A_2, ..., A_N and an integer K . Print the maximum possible length of a sequence B that satisfies the following conditions: B is a (not necessarily continuous) subsequence of A . For each pair of adjacents elements of B , the absolute difference of the elements is at most K . Constraints 1 \leq N \leq 300,000 0 \leq A_i \leq 300,000 0 \leq K \leq 300,000 All values in input are integers. Input Input is given from Standard Input in the following format: N K A_1 A_2 : A_N Output Print the answer. Sample Input 1 10 3 1 5 4 3 8 6 9 7 2 4 Sample Output 1 7 For example, B = (1, 4, 3, 6, 9, 7, 4) satisfies the conditions. It is a subsequence of A = (1, 5, 4, 3, 8, 6, 9, 7, 2, 4) . All of the absolute differences between two adjacent elements ( |1-4|, |4-3|, |3-6|, |6-9|, |9-7|, |7-4| ) are at most K = 3 . | 39,188 |
Problem F: Bus Problem åç°ç¶ã« $1$ ãã $N$ ãŸã§ã®çªå·ãã€ãããã $N$ åã®ãã¹åãå³åãã«äžŠãã§ããã 飿¥ãããã¹åã©ããã¯éã§çµã°ããŠããã å $i \ (1 \le i \le N)$ ã«ã€ããŠããã¹å $i$ ãšãã¹å $i+1$ ã®éãçŽæ¥çµã¶éã®é·ã㯠$d_i$ ã¡ãŒãã«ã§ããã ãã ãããã¹å $N+1$ ã¯ãã¹å $1$ ã®ããšã衚ãã $M$ å°ã®ãã¹ãããã $j \ (1 \le j \le M)$ çªç®ã®ãã¹ã¯ $c_j='R'$ ã®ãšãå³åãã$c_j='L'$ ã®ãšãå·Šåãã«èµ°è¡ããã ãŸããæå» $0$ ã«ãã¹å $b_j$ ãåºçºãã$1$ ã¡ãŒãã«é²ãã®ã« $t_j$ ç§ãããã ãã®åé¡ã«ãããŠã ãã¹ã¯æ°žé ã«èµ°ãç¶ãã ãã¹ã®ä¹ãéãã«ã¯æéãããããªã ãã¹åã§ã¯ããããã¹ããã®ãã¹åãééããç¬éããã®ãã¹ã«ä¹ãéãã§ãã ãã¹å以å€ã§ãã¹ã«ä¹ãéãããããšã¯ã§ããªã äœå°ã®ãã¹ã«ä¹ã£ãŠããã ãšããã 以äžã®ã¯ãšãªãåèš $Q$ ååŠçããã æå» $0$ ã«ãã¹å $x_k$ ãåºçºãããã¹å $y_k$ ãŸã§ãã¹ã®ã¿ãå©çšããŠç§»åãããšãã®ãæèŠæéã®æå°å€ãæ±ããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã $N$ $M$ $Q$ $d_1$ $\ldots$ $d_N$ $c_1$ $b_1$ $t_1$ $\vdots$ $c_M$ $b_M$ $t_M$ $x_1$ $y_1$ $\vdots$ $x_Q$ $y_Q$ 1è¡ç®ã«ãã¹åã®æ° $N$ããã¹ã®æ° $M$ãã¯ãšãªã®æ° $Q$ ã空çœåºåãã§äžããããã 2è¡ç®ã«é£æ¥ãããã¹åãç¹ãéã®æ
å ±ã空çœåºåãã§äžããããã 3è¡ç®ããç¶ã $M$ è¡ã«ãã¹ã®æ
å ±ã空çœåºåãã§äžããããã ç¶ã $Q$ è¡ã«ã¯ãšãªã®æ
å ±ã空çœåºåãã§äžããããã Constraints å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã $3 \leq N \leq 10^5 $ $1 \leq M \leq 10^5 $ $1 \leq Q \leq 10^5 $ $ 1 \leq d_i \leq 10^2 \ (1 \leq i \leq N) $ $ c_j = 'R' \ or \ 'L' \ (1 \leq j \leq M) $ $ 1 \leq b_j \leq N \ (1 \leq j \leq M) $ $ 1 \leq t_j \leq 10^5 \ (1 \leq j \leq M) $ $ 1 \leq x_k, y_k \leq N \ (1 \leq k \leq Q) $ $ x_k \neq y_k \ (1 \leq k \leq Q) $ å
¥åã§äžããããæ°ã¯ãã¹ãп޿° Output åºå㯠$Q$ è¡ãããªãã åã¯ãšãªã«å¯ŸããæèŠæéã®æå°å€ãåºåããã $k$ è¡ç®ã«ã¯ $k$ çªç®ã®ã¯ãšãªã«å¯Ÿããçããåºåããã Sample Input 1 3 1 6 1 2 3 R 1 1 1 2 1 3 2 1 2 3 3 1 3 2 Sample Output 1 1 3 6 3 6 7 $1$ ã€ç®ã®ã¯ãšãªã§ã¯ãæå» $0$ ã«ãã¹å $1$ ãããã¹ $1$ ã«ä¹ããæå» $1$ ã«ãã¹å $2$ ã§éããã®ãæé©ã§ããã Sample Input 2 4 6 7 45 72 81 47 R 1 47202 L 1 2156 L 2 95728 R 1 30739 L 3 39679 L 4 86568 3 2 3 4 1 2 2 4 4 3 1 4 2 1 Sample Output 2 431200 629552 431200 629552 275968 101332 528220 | 39,189 |
Score: 400 points Problem Statement Takahashi became a pastry chef and opened a shop La Confiserie d'ABC to celebrate AtCoder Beginner Contest 100. The shop sells N kinds of cakes. Each kind of cake has three parameters "beauty", "tastiness" and "popularity". The i -th kind of cake has the beauty of x_i , the tastiness of y_i and the popularity of z_i . These values may be zero or negative. Ringo has decided to have M pieces of cakes here. He will choose the set of cakes as follows: Do not have two or more pieces of the same kind of cake. Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity). Find the maximum possible value of (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity) for the set of cakes that Ringo chooses. Constraints N is an integer between 1 and 1 \ 000 (inclusive). M is an integer between 0 and N (inclusive). x_i, y_i, z_i \ (1 \leq i \leq N) are integers between -10 \ 000 \ 000 \ 000 and 10 \ 000 \ 000 \ 000 (inclusive). Input Input is given from Standard Input in the following format: N M x_1 y_1 z_1 x_2 y_2 z_2 : : x_N y_N z_N Output Print the maximum possible value of (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity) for the set of cakes that Ringo chooses. Sample Input 1 5 3 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 Sample Output 1 56 Consider having the 2 -nd, 4 -th and 5 -th kinds of cakes. The total beauty, tastiness and popularity will be as follows: Beauty: 1 + 3 + 9 = 13 Tastiness: 5 + 5 + 7 = 17 Popularity: 9 + 8 + 9 = 26 The value (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity) here is 13 + 17 + 26 = 56 . This is the maximum value. Sample Input 2 5 3 1 -2 3 -4 5 -6 7 -8 -9 -10 11 -12 13 -14 15 Sample Output 2 54 Consider having the 1 -st, 3 -rd and 5 -th kinds of cakes. The total beauty, tastiness and popularity will be as follows: Beauty: 1 + 7 + 13 = 21 Tastiness: (-2) + (-8) + (-14) = -24 Popularity: 3 + (-9) + 15 = 9 The value (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity) here is 21 + 24 + 9 = 54 . This is the maximum value. Sample Input 3 10 5 10 -80 21 23 8 38 -94 28 11 -26 -2 18 -69 72 79 -26 -86 -54 -72 -50 59 21 65 -32 40 -94 87 -62 18 82 Sample Output 3 638 If we have the 3 -rd, 4 -th, 5 -th, 7 -th and 10 -th kinds of cakes, the total beauty, tastiness and popularity will be -323 , 66 and 249 , respectively. The value (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity) here is 323 + 66 + 249 = 638 . This is the maximum value. Sample Input 4 3 2 2000000000 -9000000000 4000000000 7000000000 -5000000000 3000000000 6000000000 -1000000000 8000000000 Sample Output 4 30000000000 The values of the beauty, tastiness and popularity of the cakes and the value to be printed may not fit into 32-bit integers. | 39,190 |
Score : 400 points Problem Statement You are given N items. The value of the i -th item (1 \leq i \leq N) is v_i . Your have to select at least A and at most B of these items. Under this condition, find the maximum possible arithmetic mean of the values of selected items. Additionally, find the number of ways to select items so that the mean of the values of selected items is maximized. Constraints 1 \leq N \leq 50 1 \leq A,B \leq N 1 \leq v_i \leq 10^{15} Each v_i is an integer. Input The input is given from Standard Input in the following format: N A B v_1 v_2 ... v_N Output Print two lines. The first line should contain the maximum possible arithmetic mean of the values of selected items. The output should be considered correct if the absolute or relative error is at most 10^{-6} . The second line should contain the number of ways to select items so that the mean of the values of selected items is maximized. Sample Input 1 5 2 2 1 2 3 4 5 Sample Output 1 4.500000 1 The mean of the values of selected items will be maximized when selecting the fourth and fifth items. Hence, the first line of the output should contain 4.5 . There is no other way to select items so that the mean of the values will be 4.5 , and thus the second line of the output should contain 1 . Sample Input 2 4 2 3 10 20 10 10 Sample Output 2 15.000000 3 There can be multiple ways to select items so that the mean of the values will be maximized. Sample Input 3 5 1 5 1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996 Sample Output 3 1000000000000000.000000 1 | 39,191 |
Problem F: Slim Span Given an undirected weighted graph G , you should find one of spanning trees specified as follows. The graph G is an ordered pair ( V , E ), where V is a set of vertices { v 1 , v 2 , ... , v n } and E is a set of undirected edges { e 1 , e 2 , ... , e m }. Each edge e â E has its weight w ( e ). A spanning tree T is a tree (a connected subgraph without cycles) which connects all the n vertices with n - 1 edges. The slimness of a spanning tree T is defined as the difference between the largest weight and the smallest weight among the n - 1 edges of T . Figure 5: A graph G and the weights of the edges For example, a graph G in Figure 5(a) has four vertices { v 1 , v 2 , v 3 , v 4 } and five undirected edges { e 1 , e 2 , e 3 , e 4 , e 5 }. The weights of the edges are w ( e 1 ) = 3, w ( e 2 ) = 5, w ( e 3 ) = 6, w ( e 4 ) = 6, w ( e 5 ) = 7 as shown in Figure 5(b). Figure 6: Examples of the spanning trees of G There are several spanning trees for G . Four of them are depicted in Figure 6(a)-(d). The spanning tree T a in Figure 6(a) has three edges whose weights are 3, 6 and 7. The largest weight is 7 and the smallest weight is 3 so that the slimness of the tree T a is 4. The slimnesses of spanning trees T b , T c and T d shown in Figure 6(b), (c) and (d) are 3, 2 and 1, respectively. You can easily see the slimness of any other spanning tree is greater than or equal to 1, thus the spanning tree T d in Figure 6(d) is one of the slimmest spanning trees whose slimness is 1. Your job is to write a program that computes the smallest slimness. Input The input consists of multiple datasets, followed by a line containing two zeros separated by a space. Each dataset has the following format. n m a 1 b 1 w 1 . . . a m b m w m Every input item in a dataset is a non-negative integer. Items in a line are separated by a space. n is the number of the vertices and m the number of the edges. You can assume 2 †n †100 and 0 †m †n ( n - 1)/2. a k and b k ( k = 1, ... , m ) are positive integers less than or equal to n , which represent the two vertices v a k and v b k connected by the k th edge e k . w k is a positive integer less than or equal to 10000, which indicates the weight of e k . You can assume that the graph G = ( V , E ) is simple, that is, there are no self-loops (that connect the same vertex) nor parallel edges (that are two or more edges whose both ends are the same two vertices). Output For each dataset, if the graph has spanning trees, the smallest slimness among them should be printed. Otherwise, -1 should be printed. An output should not contain extra characters. Sample Input 4 5 1 2 3 1 3 5 1 4 6 2 4 6 3 4 7 4 6 1 2 10 1 3 100 1 4 90 2 3 20 2 4 80 3 4 40 2 1 1 2 1 3 0 3 1 1 2 1 3 3 1 2 2 2 3 5 1 3 6 5 10 1 2 110 1 3 120 1 4 130 1 5 120 2 3 110 2 4 120 2 5 130 3 4 120 3 5 110 4 5 120 5 10 1 2 9384 1 3 887 1 4 2778 1 5 6916 2 3 7794 2 4 8336 2 5 5387 3 4 493 3 5 6650 4 5 1422 5 8 1 2 1 2 3 100 3 4 100 4 5 100 1 5 50 2 5 50 3 5 50 4 1 150 0 0 Output for the Sample Input 1 20 0 -1 -1 1 0 1686 50 | 39,192 |
Score : 600 points Problem Statement We will create an artwork by painting black some squares in a white square grid with 10^9 rows and N columns. The current plan is as follows: for the i -th column from the left, we will paint the H_i bottommost squares and will not paint the other squares in that column. Before starting to work, you can choose at most K columns (possibly zero) and change the values of H_i for these columns to any integers of your choice between 0 and 10^9 (inclusive). Different values can be chosen for different columns. Then, you will create the modified artwork by repeating the following operation: Choose one or more consecutive squares in one row and paint them black. (Squares already painted black can be painted again, but squares not to be painted according to the modified plan should not be painted.) Find the minimum number of times you need to perform this operation. Constraints 1 \leq N \leq 300 0 \leq K \leq N 0 \leq H_i \leq 10^9 All values in input are integers. Input Input is given from Standard Input in the following format: N K H_1 H_2 ... H_N Output Print the minimum number of operations required. Sample Input 1 4 1 2 3 4 1 Sample Output 1 3 For example, by changing the value of H_3 to 2 , you can create the modified artwork by the following three operations: Paint black the 1 -st through 4 -th squares from the left in the 1 -st row from the bottom. Paint black the 1 -st through 3 -rd squares from the left in the 2 -nd row from the bottom. Paint black the 2 -nd square from the left in the 3 -rd row from the bottom. Sample Input 2 6 2 8 6 9 1 2 1 Sample Output 2 7 Sample Input 3 10 0 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 Sample Output 3 4999999996 | 39,193 |
Score : 800 points Problem Statement Takahashi and Aoki will take N exams numbered 1 to N . They have decided to compete in these exams. The winner will be determined as follows: For each exam i , Takahashi decides its importance c_i , which must be an integer between l_i and u_i (inclusive). Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i ), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i ). Takahashi wins if A \geq B , and Aoki wins if A < B . Takahashi knows that Aoki will score b_i on Exam i , with his supernatural power. Takahashi himself, on the other hand, will score 0 on all the exams without studying more. For each hour of study, he can increase his score on some exam by 1 . (He can only study for an integer number of hours.) However, he cannot score more than X on an exam , since the perfect score for all the exams is X . Print the minimum number of study hours required for Takahashi to win. Constraints 1 \leq N \leq 10^5 1 \leq X \leq 10^5 0 \leq b_i \leq X (1 \leq i \leq N) 1 \leq l_i \leq u_i \leq 10^5 (1 \leq i \leq N) All values in input are integers. Input Input is given from Standard Input in the following format: N X b_1 l_1 u_1 b_2 l_2 u_2 : b_N l_N u_N Output Print the minimum number of study hours required for Takahashi to win. Sample Input 1 2 100 85 2 3 60 1 1 Sample Output 1 115 One optimal strategy is as follows: Choose c_1 = 3, c_2 = 1 . Study to score 100 on Exam 1 and 15 on Exam 2 . Then, A = 3 \times 100 + 1 \times 15 = 315 , B = 3 \times 85 + 1 \times 60 = 315 and Takahashi will win. Sample Input 2 2 100 85 2 3 60 10 10 Sample Output 2 77 Sample Input 3 1 100000 31415 2718 2818 Sample Output 3 31415 Sample Input 4 10 1000 451 4593 6263 324 310 6991 378 1431 7068 71 1757 9218 204 3676 4328 840 6221 9080 684 1545 8511 709 5467 8674 862 6504 9835 283 4965 9980 Sample Output 4 2540 | 39,194 |
Problem I: Sum of Last Digits Problem 3ã€ã®æŽæ° n , m , k ãäžããããã®ã§ n 1 %10 + n 1+ m %10 + n 1+2 m %10 + ... + n 1+( k -1) m %10 ãèšç®ããã a % b 㯠a ã b ã§å²ã£ããšãã®äœãã衚ãã Input n m k 1è¡ã« n , m , k ãäžããããã Constraints å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºãã 0 †n †10 18 0 †m †10 9 1 †k †10 9 Output çãã1è¡ã«åºåããã Sample Input 1 1 1 9 Sample Output 1 9 Sample Input 2 2 1 3 Sample Output 2 14 Sample Input 3 6 11 11 Sample Output 3 66 Sample Input 4 100 7 12 Sample Output 4 0 Sample Input 5 123 123 3 Sample Output 5 11 | 39,195 |
å顿 以äžã®æ¡ä»¶ãæºããæŽæ°å $X_1, X_2, ..., X_N$ ã®åæ°ãæ±ããã ä»»æã®æŽæ° $i$ ($1 \leq i \leq N$)ã«å¯ŸããŠã$X_j=i$ ãšãªã $j$ ($1 \leq j \leq N$)ãååšããã $X_s = t$ $X_{a_i} < X_{b_i}$ ($1 \leq i \leq C$) å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã«åŸããäžããããæ°ã¯å
šãп޿°ã§ããã $N$ $C$ $s$ $t$ $a_1$ $b_1$ $a_2$ $b_2$ $...$ $a_C$ $b_C$ å¶çŽ $1 \leq N \leq 2000$ $0 \leq C \leq N$ $1 \leq s \leq N$ $1 \leq t \leq N$ $1 \leq a_i \leq N$ $1 \leq b_i \leq N$ $a_i \neq b_i$ $i \neq j$ ãªãã° $a_i \neq a_j$ åºå æ¡ä»¶ãæºããæ°åã®åæ°ã $10^9+7$ ã§å²ã£ãäœãã1è¡ã«åºåãã(æ¡ä»¶ãæºããæ°åã®åæ°ãããã ãæéåãããªãããšã¯ç°¡åã«ç€ºããã)ã Sample Input 1 3 1 1 1 1 3 Output for the Sample Input 1 2 $\{X_1, X_2, X_3\} = \{1, 2, 3\}, \{1, 3, 2\}$ ã®2ã€ãæ¡ä»¶ãæºããã Sample Input 2 4 2 1 1 2 3 3 2 Output for the Sample Input 2 0 $X_2<X_3$ ã〠$X_3<X_2$ ãæºããæ°åã¯ååšããªãã | 39,197 |
Problem 09: Building Houses ãã®ç§ãå²ç«ããŠã¹ã¯æè¿éæãé²ãã§ããæŸçå°åºã®ç¥æéãæ²¿ãã®åå°ãåè²ããããšã«ããã å
æ¥åéãããã仿¥ã¯è³Œå
¥è
ã«åè²èª¬æäŒãéå¬ããã 賌å
¥è
ã説æäŒå Žã«éãŸãã ãããšããããªãã ã空æ°ããšãŠãåãä»ããŠãããäžæè°ã«æã£ãæ
åœè
ã¯éå¬åã« ãçããæ°å€©å°ãæ±ããŠãããšããã®ã«ãã¡ãã£ãšè¡šæ
ãæãã§ãã倧äžå€«ã§ããïŒã ãšèããŠã¿ããããã§æãã¬äºå®ã倿ãããå®ã¯ã賌å
¥è
å
šå¡ãçŸåšé£çºã®éåå£å°ã®äœäººã§ãããŸãã«ãåšèŸºã®äººãã¡ãšæãåããåããªãããä»ååŒè¶ããããããšæ€èšããŠããã®ã ã£ãã 賌å
¥è
ãã¡ã¯ãã§ã«è²»çšãæ¯ææžã¿ã§ä»¥åã®äœãŸããåŒãæã£ãŠãããåŸã£ãŠãä»ååè²ããæŸçå°åºã®ç¥æéãã«å®¶ãç«ãŠã仿¹æ³ã¯ãªãã ããããªãããå°ãã§ãå¿«é©ãªæ°å±
ã©ã€ããéã£ãŠãããããšæ
åœè
ã¯é ãæ©ãŸããããããã話ãèããŠã¿ããšãä»²ã®æªãã«ã¯ãã©ããããã£ãã®ã§ãèã蟌ã¿ãè¡ãå³ïŒã®ãããªä»²ã®æªã床ãã§ãã¯è¡šãäœæããïŒ å³ïŒïŒä»²ã®æªã床ãã§ãã¯è¡š 賌å
¥è
ã®æ°ã n ãšãããšã衚㯠n à n ã®è¡åãšãªããèŠçŽ a i,j ã¯ã賌å
¥è
i ãèªåã®å®¶ãã賌å
¥è
j ã®å®¶ãæäœã§ãäœ m é¢ããããã瀺ããäŸãã°ãå³ïŒã®è¡šã«ãããŠã賌å
¥è
A ã¯èªåã®å®¶ãšè³Œå
¥è
B ã®å®¶ã®è·é¢ã 2 m 以äžé¢ããŠããªããšçŽåŸããªããããã«ã賌å
¥è
B ã¯èªåã®å®¶ãšè³Œå
¥è
A ã®å®¶ã®è·é¢ã 4 m 以äžé¢ããŠããªããšçŽåŸããªããåŸã£ãŠ A ãš B ã®è·é¢ã¯ 4 m 以äžé¢ãå¿
èŠãããã æ
åœè
ã¯ãã®è¡šã«åºã¥ãé£ã®å®¶ãšã®ééãèšãåå°ã®ã¬ã€ã¢ãŠããèšèšããããšã«ããã ããªãã®ä»äºã¯ãä»²ã®æªã床ãã§ãã¯è¡šãå
¥åãã賌å
¥è
ã®å®¶ãç¥æéãïŒäžçŽç·äžïŒã«å»ºãŠãããã«æäœéå¿
èŠãªéãã®é·ãïŒmïŒãåºåããããã°ã©ã ãäœæããããšã§ããã ãªãç°¡åã®ããã«ãå®¶ã¯ç¹ãšããŠæ±ãããã®å¹
㯠0 m ãšä»®å®ããã Input å
¥åãšããŠè€æ°ã®ããŒã¿ã»ãããäžãããããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ n ïŒè³Œå
¥è
ã®æ°ïŒæŽæ°ïŒ a 1,1 a 1,2 ... a 1, n ïŒ a 1, j ïŒæŽæ°ïŒ a 2,1 a 2,2 ... a 2, n ïŒ a 2, j ïŒæŽæ°ïŒ . . a n ,1 a n ,2 ... a n , n ïŒ a n , j ïŒæŽæ°ïŒ n 㯠10 以äžãšããã a i , i 㯠0 ã§ããã a i , j ( i â j ) 㯠1 以äžã§ããã n ã 0 ã®ãšãå
¥åã®çµãããšããã Output åããŒã¿ã»ããã«ã€ããŠãæäœéå¿
èŠãªéãã®é·ããïŒè¡ã«åºåããã Sample Input 4 0 2 3 1 4 0 4 2 1 1 0 3 3 1 5 0 2 0 3 3 0 0 Output for the Sample Input 8 3 | 39,198 |
Score : 300 points Problem Statement Let f(n) be the number of triples of integers (x,y,z) that satisfy both of the following conditions: 1 \leq x,y,z x^2 + y^2 + z^2 + xy + yz + zx = n Given an integer N , find each of f(1),f(2),f(3),\ldots,f(N) . Constraints All values in input are integers. 1 \leq N \leq 10^4 Input Input is given from Standard Input in the following format: N Output Print N lines. The i -th line should contain the value f(i) . Sample Input 1 20 Sample Output 1 0 0 0 0 0 1 0 0 0 0 3 0 0 0 0 0 3 3 0 0 For n=6 , only (1,1,1) satisfies both of the conditions. Thus, f(6) = 1 . For n=11 , three triples, (1,1,2) , (1,2,1) , and (2,1,1) , satisfy both of the conditions. Thus, f(6) = 3 . For n=17 , three triples, (1,2,2) , (2,1,2) , and (2,2,1) , satisfy both of the conditions. Thus, f(17) = 3 . For n=18 , three triples, (1,1,3) , (1,3,1) , and (3,1,1) , satisfy both of the conditions. Thus, f(18) = 3 . | 39,199 |
åžå€è§åœ¢æ±å·¥æ¥éœåž åžå€è§åœ¢æ±å·¥æ¥éœåž (Industrial Convex Pillar City, ICPC) ã¯ããã€ãã®åžå€è§åœ¢æ±ã®åœ¢ç¶ããã建ç©ãããªãè¡ã§ããïŒããªãã¯ãã®è¡ã®äžãçŸåšå° S ããç®çå° T ã«åããŠæ©ãããšããŠããïŒä»æ¥ã¯æ¥å·®ãã匷ãã®ã§ïŒåºæ¥ãéãã²ãªããéããã«ç®çå°ãžåããããïŒããªããç«ã£ãŠããå°ç¹ãšå€ªéœãäžçŽç·ã«çµãã ç·äžã«å»ºç©ãããå ŽåïŒããªãã¯å»ºç©ã®é°ã«ããã®ã§æ¥å·®ããåããã«ããïŒãŸãïŒãã®è¡ã®å»ºç©ã®å€åšã«ã¯å
šãŠã²ãããä»ããŠããã®ã§ïŒå»ºç©ã®å€åšã«æ²¿ã£ãŠæ©ããŠããéã¯ïŒæ¥ãåœããçžã«æ²¿ã£ãŠæ©ããŠãæ¥å·®ããåããããšã¯ãªãïŒããªãã¯å»ºç©ã®å
éšä»¥å€ã¯ãã®è¡ãã©ãã§ãèªç±ã«æ©ãããšãã§ããïŒ ãã£ãšãæ¥å·®ããåããªãããã«çŸåšå°ããç®çå°ãŸã§æ©ããæã®ïŒã²ãªããæ©ãè·é¢ãåºåããããã°ã©ã ãäœæããªããïŒ å³E1: 第1ã€ã³ãããã®å Žå å³E2: 第2ã€ã³ãããã®å Žå å³E3: 第3ã€ã³ãããã®å Žå Input å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒ ããŒã¿ã»ããã®åæ°ã¯æå€§ã§ã 30 åãè¶
ããªãïŒ åããŒã¿ã»ããã¯æ¬¡ã®åœ¢åŒã§è¡šãããïŒ N NV 1 H 1 X 1,1 Y 1,1 X 1,2 Y 1,2 ... X 1,NV 1 Y 1,NV 1 ... NV N H N X N,1 Y N,1 X N,2 Y N,2 ... X N,NV N Y N,NV N Ξ Ï S x S y T x T y ïŒè¡ç®ã® N ã¯å»ºç©ã®æ°ã衚ãïŒç¶ã N è¡ã¯å建ç©ã®åœ¢ç¶ãæå®ããïŒ NV i 㯠i çªç®ã®å»ºç©ãäžããèŠãå€è§åœ¢ã®é ç¹æ°ïŒ H i 㯠i çªç®ã®å»ºç©ã®é«ãã衚ãïŒ X i, j ãš Y i, j 㯠i çªç®ã®å»ºç©ãäžããèŠãå€è§åœ¢ã® j çªç®ã®é ç¹ã® x 座æšãš y 座æšã衚ãïŒé ç¹ã¯åæèšåãã®é ã§äžããããïŒå
šãŠã®å»ºç©ã¯äžããèŠããšåžå€è§åœ¢ã§ããïŒå»ºç©ã®å
éšã«ä»ã®å»ºç©ããã£ããïŒé ç¹ã蟺ãä»ã®å€è§åœ¢ãšéãªã£ããããããšã¯ãªãïŒç¶ãè¡ã«ã¯å€ªéœã®æ¹åã衚ã Ξ ãš Ï ãäžãããïŒ Îž ã¯å€ªéœã®åãã x ã®æ£ã®æ¹åããåæèšåãã®è§åºŠã§è¡šãïŒ Ï ã¯å°å¹³ç·ããã®å€ªéœã®ä»°è§ïŒããªãã¡å€ªéœãèŠäžããæã®èŠç·ã®æ¹åãšå°è¡šé¢ããªãè§åºŠã衚ãïŒãã ãïŒå€ªéœã¯ç¡éé ã«ããïŒç§»åäžã«ã¯äœçœ®ãå€ããªããã®ãšããïŒç¶ãè¡ã«ã¯çŸåšå°ãšç®çå°ã®åº§æšïŒ ( S x , S y ) ãš ( T x , T y ) ãäžããããïŒ å
¥åã§äžããããæ°å€ã¯å
šãп޿°ã§ããïŒä»¥äžã®æ¡ä»¶ãæºããïŒ 1 †N †100 3 †NV i †12 1 †H i †1, 000 0 †Ξ < 360 0 < Ï < 90 座æšã¯å
šãŠ -1, 000 ä»¥äž 1, 000 以äžã§ããïŒ çŸåšå°ãšç®çå°ã¯ç°ãªãïŒã©ã¡ãã建ç©ã®å
éšåã³å€åšã«ã¯ååšããªãïŒ å
¥åã®çµããã¯ïŒïŒã€ã®ãŒããããªãè¡ã§è¡šãããïŒ Output åããŒã¿ã»ããã«ã€ããŠïŒã²ãªããæ©ãæçè·é¢ãïŒè¡ã«åºåããïŒåºåã«ã¯ 0.001 ãè¶
ãã絶察誀差ããã£ãŠã¯ãªããªãïŒ Sample Input 2 4 1 0 0 1 0 1 1 0 1 4 2 2 2 3 2 3 3 2 3 60 45 -1 -1 4 4 4 4 1 0 0 3 1 1 2 0 1 3 2 10 7 8 2 12 4 6 8 7 12 8 13 9 15 10 19 11 24 10 25 5 4 16 2 16 4 12 8 14 2 15 0 167 38 3 3 15 21 12 4 3 -8 -3 -9 -3 -9 -5 -8 -6 4 5 -4 -5 -7 -5 -7 -6 -5 -6 4 2 -4 1 -5 1 -5 -4 -4 -4 4 1 -1 1 -2 1 -2 -4 -1 -3 4 2 2 3 -1 3 -2 2 3 2 4 1 3 1 2 1 2 -3 3 -4 4 7 1 0 0 0 0 -1 1 -1 4 4 9 5 7 5 7 4 10 4 4 3 6 5 5 4 5 0 6 0 4 5 8 -1 5 -1 6 -2 8 -2 4 1 10 0 9 0 9 -2 10 -1 4 6 10 2 8 2 8 1 10 1 131 78 -10 10 10 -10 0 Output for Sample Input 1.93185 7.87174 20.86840 | 39,200 |
ã¢ãžã¥ãã»ã¯ãšãª ããªãã« N æã®ã«ãŒããæž¡ããŸããã©ã®ã«ãŒãã«ãäžã€ã ãèªç¶æ°ãæžããŠãããŸãããã ããåãæ°ãæžããŠããããšã¯ãããŸããã ãããã質åãšããŠãé©åœãªèªç¶æ°ãèšããŸããããªããæã£ãŠããã«ãŒãã«æžããŠããæ°ãç§ãèšã£ãæ°ã§å²ã£ããšãã«åŸãããäœãã®ãã¡æã倧ããªãã®ãçããŠãã ããã ããšãã°ãããªã㯠3 æã®ã«ãŒããæã£ãŠããŠããããã 9ã3ã8 ãšæžããŠãããšããŸããç§ãã4ããšèšã£ããã9 ãš 3 ãš 8 ããããã4 ã§å²ã£ãäœããæ±ããŠãã ãããäœãã¯ãããã 1ã3ã0 ã§ããããã®äžã§ãã£ãšã倧ããªäœãã¯3 ãªã®ã§ã3 ãæ£ããçãã«ãªããŸãã ã§ã¯å§ããŸããããããïŒ ã«ãŒãããã£ã±ããããšãããžãã ïŒ ãããããªãã§ãããããã§ã¯ã³ ã³ãã¥ãŒã¿ã䜿ã£ãп倧ã®äœããèŠã€ããããšã«ããŸããããã«ãŒãã«æžããŠããæ°ãã質åãããæ°ã§å²ã£ãäœãã®ãã¡ãæå€§ã®ãã®ãèŠã€ããããã°ã©ã ãäœæããŠãã ããããªãã質åã¯ïŒåã ãã§ãªãäœåºŠãããŸãããåãæ°ã 2 å以äžè³ªåããããšã¯ãããŸããã å
¥å å
¥åã¯ïŒã€ã®ããŒã¿ã»ãããããªããå
¥åããŒã¿ã¯ä»¥äžã®åœ¢åŒã§äžããããã N Q c 1 c 2 ... c N q 1 q 2 : q Q ïŒè¡ç®ã«ã«ãŒãã®ææ° N (2 †N †300000) ãšè³ªåã®åæ° Q (2 †Q †100000) ãïŒã€ã®ç©ºçœåºåãã§äžããããïŒè¡ç®ã«ã«ãŒãã«æžãããæ° c i (1 †c i †300000) ãïŒã€ã®ç©ºçœåºåãã§äžãããããç¶ãQ è¡ã«è³ªåãšããŠäžããããæ° q i (1 †q i †300000) ãäžããããã åºå 質åããšã«æå€§ã®äœããïŒè¡ã«åºåããã å
¥åäŸ 3 3 9 3 8 4 6 5 åºåäŸ 3 3 4 | 39,201 |
Maximum Profit You can obtain profits from foreign exchange margin transactions. For example, if you buy 1000 dollar at a rate of 100 yen per dollar, and sell them at a rate of 108 yen per dollar, you can obtain (108 - 100) Ã 1000 = 8000 yen. Write a program which reads values of a currency $R_t$ at a certain time $t$ ($t = 0, 1, 2, ... n-1$), and reports the maximum value of $R_j - R_i$ where $j > i$ . Input The first line contains an integer $n$. In the following $n$ lines, $R_t$ ($t = 0, 1, 2, ... n-1$) are given in order. Output Print the maximum value in a line. Constraints $2 \leq n \leq 200,000$ $1 \leq R_t \leq 10^9$ Sample Input 1 6 5 3 1 3 4 3 Sample Output 1 3 Sample Input 2 3 4 3 2 Sample Output 2 -1 | 39,202 |
Prime Caves An international expedition discovered abandoned Buddhist cave temples in a giant cliff standing on the middle of a desert. There were many small caves dug into halfway down the vertical cliff, which were aligned on square grids. The archaeologists in the expedition were excited by Buddha's statues in those caves. More excitingly, there were scrolls of Buddhism sutras (holy books) hidden in some of the caves. Those scrolls, which estimated to be written more than thousand years ago, were of immeasurable value. The leader of the expedition wanted to collect as many scrolls as possible. However, it was not easy to get into the caves as they were located in the middle of the cliff. The only way to enter a cave was to hang you from a helicopter. Once entered and explored a cave, you can climb down to one of the three caves under your cave; i.e., either the cave directly below your cave, the caves one left or right to the cave directly below your cave. This can be repeated for as many times as you want, and then you can descent down to the ground by using a long rope. So you can explore several caves in one attempt. But which caves you should visit? By examining the results of the preliminary attempts, a mathematician member of the expedition discovered that (1) the caves can be numbered from the central one, spiraling out as shown in Figure D-1; and (2) only those caves with their cave numbers being prime (let's call such caves prime caves ), which are circled in the figure, store scrolls. From the next attempt, you would be able to maximize the number of prime caves to explore. Figure D-1: Numbering of the caves and the prime caves Write a program, given the total number of the caves and the cave visited first, that finds the descending route containing the maximum number of prime caves. Input The input consists of multiple datasets. Each dataset has an integer m (1 †m †10 6 ) and an integer n (1 †n †m ) in one line, separated by a space. m represents the total number of caves. n represents the cave number of the cave from which you will start your exploration. The last dataset is followed by a line with two zeros. Output For each dataset, find the path that starts from the cave n and contains the largest number of prime caves, and output the number of the prime caves on the path and the last prime cave number on the path in one line, separated by a space. The cave n , explored first, is included in the caves on the path. If there is more than one such path, output for the path in which the last of the prime caves explored has the largest number among such paths. When there is no such path that explores prime caves, output " 0 0 " (without quotation marks). Sample Input 49 22 46 37 42 23 945 561 1081 681 1056 452 1042 862 973 677 1000000 1000000 0 0 Output for the Sample Input 0 0 6 43 1 23 20 829 18 947 10 947 13 947 23 947 534 993541 | 39,203 |
E: æã®äœãæ¹ - How To Make Stars - ç©èª åãæšååŠé¢1幎çã®æå±éŽã ãã£ïŒéŽã¯ãææ§ãã ãã奜ãïŒå€ã¯ãã€ã幌銎æã®è±ä»£ã¡ããšäžç·ã«ïŒãã£ãããšåŠæ ¡ã®å±äžã§ãææ§ãèŠãŠããã ïŒã ãã©ïŒä»æ¥ã®ã倩æ°ã¯ããã«ãã®éšã»ã»ã»ïŒããããïŒãææ§ãèŠãããšãã§ããªããã£ïŒè±ä»£ã¡ãã©ãããããïŒ éŽãã»ã»ã»ããã£ïŒããããšæãä»ãããã£ïŒè²ããªãææ§ãèŠãããããªïŒãã£ããªãã©ãã¿ãªãŠã ãäœããã£ïŒè±ä»£ã¡ãïŒãã£ãããããã£ïŒã è±ä»£ããã£ïŒããã£ïŒéŽã¡ããã¡ãã£ãšåŸ
ã£ãŠïŒãã©ãã¿ãªãŠã ã®äœãæ¹ãªããŠïŒç§ç¥ããªããïŒã éŽã倧äžå€«ãã£ïŒ2人ã§åãåãããã°ãã£ãšã§ãããïŒãã£ãã£ãã£ãã£ãïŒã è±ä»£ãã ïŒãã¬ã«ã¿ã¹ã±ããïŒã åé¡ èªå·±äº€å·®ã®ãªãå€è§åœ¢ã®äžã§ïŒé ç¹æ°ã10ã§ãããã€ïŒä»»æã®é ç¹ããäžå®ã®æ¹åã«åšäžããã©ã£ããšãïŒå
è§ã30床以äž60床以äžã§ããéšåãšïŒå
è§ã240床以äž270床以äžã§ããéšåã亀äºã«çŸãããã®ããæããšå®çŸ©ããïŒ æã¯é¢ç©ã«ãã£ãŠéçŽãå®ãŸãïŒå
·äœçã«ã¯ïŒé¢ç©ã S_1 以äžã®ãã®ã1çŽæïŒ S_{iâ1} ããå°ãã S_i 以äžã®ãã®ã i çŽæ ( i ⥠2 ) ãšåŒã¶ããã«éçŽãä»ããïŒ éçŽã n åãããšããŠïŒéçŽã®ç®å®ãšãªã n çš®é¡ã®é¢ç© S_1 , ..., S_n ãäžããããã®ã§ïŒå k (1 †k †n) ã«ã€ã㊠k çŽæãšãªãæãäœãïŒ2次å
å¹³é¢äžã«é
眮ããïŒ ãã ãïŒåæãäºãã«éãªã£ãŠã¯ãªããªãïŒ å
¥ååœ¢åŒ å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ n S_1 ... S_n 1è¡ç®ã«ã¯éçŽã®æ° n ãäžããããïŒ 2è¡ç®ã«ã¯ïŒéçŽã®ç®å®ãšãªãé¢ç©ãè¡šãæŽæ° S_1 ãã S_n ãé ã«ç©ºçœåºåãã§äžããããïŒ å
¥åã¯ä»¥äžã®å¶çŽãæºããïŒ 1 †n †100 1 †S_i †100,000 (1 †i †n) i < j ãªãã° S_i > S_j åºååœ¢åŒ å
šãŠã®éçŽã®æã«ã€ããŠïŒ1è¡ç®ã«ã¯éçŽãè¡šãæŽæ° k ãïŒç¶ã10è¡ã«ã¯ä»»æã®é ç¹ããåæèšåãã§10åã®é ç¹ã®åº§æš (x, y) ã1è¡ããšã«åºåããïŒé ç¹ã®åº§æš (x, y) 㯠x ãš y ã空çœåºåãã§åºåããïŒæã¯ïŒ1çŽæããé ã«åºåããïŒããªãã¡ïŒåºåã¯ä»¥äžã®ããã«ãªãïŒ 1 çŽæã®åºå ... n çŽæã®åºå k çŽæã®æã«ã€ããŠã¯ïŒä»¥äžã®ããã«åºåããïŒ k x_1 y_1 ... x_{10} y_{10} ãã ãïŒåº§æšã®çµ¶å¯Ÿå€ã 5,000 ãè¶
ããŠã¯ãªããªãïŒãŸãïŒåºåãéåžžã«å€§ãããªãå¯èœæ§ãããããïŒåº§æšå€ã®åºåã¯å°æ°ç¹ä»¥äž9æ¡ãŸã§ãšããïŒ æã®å
è§ã«ã€ããŠïŒæå®ã®ç¯å²ããã®çµ¶å¯Ÿèª€å·®ã 10^{â3} rad(ã©ãžã¢ã³)ãŸã§èš±ãïŒ æãäºãã«äº€å·®ããããšãïŒæ¥è§ŠããŠããããšïŒããæãä»ã®æã«å
å
ããããšãã£ãããšã¯èš±ãããªãïŒããã§ïŒæãæ¥è§ŠããŠãããšã¯ïŒç°ãªãæã«å«ãŸããä»»æã®2蟺ã®è·é¢ã 10^{â7} 以äžã§ãããšããæãïŒ 1çŽæã®é¢ç©ã¯ S_1 以äžïŒ i çŽæ ( i ⥠2 ) ã®é¢ç©ã¯ S_{iâ1} æªæº S_i 以äžã§ãªããã°ãªããªããïŒçµ¶å¯Ÿèª€å·®ã 10^{â7} ãŸã§èš±ãïŒ 1ã€ã®æãæ§æããä»»æã®2é ç¹éã®è·é¢ã¯ 10^{â3} 以äžã§ãªããã°ãªããªãïŒ å
¥åäŸ1 2 10 5 åºåäŸ1 1 -10.00 -6.48 -10.79 -8.91 -13.34 -8.91 -11.28 -10.41 -12.07 -12.84 -10.00 -11.34 -7.93 -12.84 -8.72 -10.41 -6.66 -8.91 -9.21 -8.91 2 10.00 12.34 9.47 10.72 7.77 10.72 9.15 9.72 8.62 8.10 10.00 9.10 11.38 8.10 10.85 9.72 12.23 10.72 10.53 10.72 å
¥åäŸ2 3 10 8 5 åºåäŸ2 1 -10.00 -6.48 -10.79 -8.91 -13.34 -8.91 -11.28 -10.41 -12.07 -12.84 -10.00 -11.34 -7.93 -12.84 -8.72 -10.41 -6.66 -8.91 -9.21 -8.91 2 10.00 12.93 9.34 10.91 7.21 10.91 8.94 9.65 8.28 7.63 10.00 8.88 11.72 7.63 11.06 9.65 12.79 10.91 10.66 10.91 3 20.00 22.34 19.47 20.72 17.77 20.72 19.15 19.72 18.62 18.10 20.00 19.10 21.38 18.10 20.85 19.72 22.23 20.72 20.53 20.72 | 39,204 |
çŽæ¹äœ ã¢ã€ã
æŸéåäŒã®æè²çªçµ(æè²)ã§ã¯ãåäŸåãã®å·¥äœçªçµããããã§ã€ããããšããçªçµãæŸéããŠããŸãã仿¥ã¯ç»çšçŽã§ç®±ãäœãåã§ãããçšæããé·æ¹åœ¢ã®ç»çšçŽã§çŽæ¹äœãã§ãããã確ãããããšæããŸãããã ããç»çšçŽã¯åã£ããæã£ããããŠã¯ãããŸããã ïŒã€ã®é·æ¹åœ¢ãäžããããã®ã§ããããã䜿ã£ãŠçŽæ¹äœãäœãããã©ããå€å®ããããã°ã©ã ãäœæããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã h 1 w 1 h 2 w 2 h 3 w 3 h 4 w 4 h 5 w 5 h 6 w 6 å
¥åã¯ïŒè¡ãããªããããããã®è¡ã«åé·æ¹åœ¢ã®çžŠã®é·ããè¡šãæŽæ° h i (1 †h i †1000) ãšæšªã®é·ããè¡šãæŽæ° w i (1 †w i †1000) ãäžããããã Output çŽæ¹äœãäœæã§ããå Žåã«ã¯ãyesãããäœæã§ããªãå Žåã«ã¯ãnoããåºåããããã ããç«æ¹äœã¯çŽæ¹äœã®äžçš®ãªã®ã§ãç«æ¹äœã®å Žåã§ããyesããšåºåããã Sample Input 1 2 2 2 3 2 3 2 3 2 2 3 2 Sample Output 1 yes Sample Input 2 2 2 2 3 2 3 2 3 2 2 2 2 Sample Output 2 no | 39,205 |
Problem G: Traffic You are a resident of Kyoot (oh, well, itâs not a misspelling!) city. All streets there are neatly built on a grid; some streets run in a meridional (north-south) direction and others in a zonal (east-west) direction. The streets that run from north to south are called avenues, whereas those which run from east to west are called drives . Every avenue and drive in the city is numbered to distinguish one from another. The westernmost avenue is called the 1st avenue . The avenue which lies next to the 1st avenue is the 2nd avenue , and so forth. Similarly, drives are numbered from south to north. The figure below illustrates this situation. Figure 1: The Road Map of the Kyoot City There is an intersection with traffic signals to regulate traffic on each crossing point of an avenue and a drive. Each traffic signal in this city has two lights. One of these lights is colored green, and means âyou may goâ. The other is red, and means âyou must stop hereâ. If you reached an intersection during the red light (including the case where the light turns to red on your arrival), you must stop and wait there until the light turns to green again. However, you do not have to wait in the case where the light has just turned to green when you arrived there. Traffic signals are controlled by a computer so that the lights for two different directions always show different colors. Thus if the light for an avenue is green, then the light for a drive must be red, and vice versa. In order to avoid car crashes, they will never be green together. Nor will they be red together, for efficiency. So all the signals at one intersection turn simultaneously; no sooner does one signal turn to red than the other turns to green. Each signal has a prescribed time interval and permanently repeats the cycle. Figure 2: Signal and Intersection By the way, you are planning to visit your friend by car tomorrow. You want to see her as early as possible, so you are going to drive through the shortest route. However, due to existence of the traffic signals, you cannot easily figure out which way to take (the city also has a very sophisticated camera network to prevent crime or violation: the police would surely arrest you if you didnât stop on the red light!). So you decided to write a program to calculate the shortest possible time to her house, given the town map and the configuration of all traffic signals. Your car runs one unit distance in one unit time. Time needed to turn left or right, to begin moving, and to stop your car is negligible. You do not need to take other cars into consideration. Input The input consists of multiple test cases. Each test case is given in the format below: w h d A,1 d A,2 . . . d A,wâ1 d D,1 d D,2 . . . d D,hâ1 ns 1,1 ew 1,1 s 1,1 . . . ns w,1 ew w,1 s w,1 ns 1,2 ew 1,2 s 1,2 . . . ns w,h ew w,h s w,h x s y s x d y d Two integers w and h (2 †w , h †100) in the first line indicate the number of avenues and drives in the city, respectively. The next two lines contain ( w - 1) and ( h - 1) integers, each of which specifies the distance between two adjacent avenues and drives. It is guaranteed that 2 †d A,i , d D,j †1, 000. The next ( w à h ) lines are the configuration of traffic signals. Three parameters ns i,j , ew i,j and s i,j describe the traffic signal ( i , j ) which stands at the crossing point of the i -th avenue and the j -th drive. ns i,j and ew i,j (1 †ns i,j , ew i,j < 100) are time intervals for which the light for a meridional direction and a zonal direction is green, respectively. s i,j is the initial state of the light: 0 indicates the light is green for a meridional direction, 1 for a zonal direction. All the traffic signal have just switched the state to s i,j at your departure time. The last two lines of a case specify the position of your house ( x s , y s ) and your friendâs house ( x d , y d ), respectively. These coordinates are relative to the traffic signal (0, 0). x -axis is parallel to the drives, and y -axis is parallel to the avenues. x-coordinate increases as you go east, and y-coordinate increases as you go north. You may assume that these positions are on streets and will never coincide with any intersection. All parameters are integers and separated by a blank character. The end of input is identified by a line containing two zeros. This is not a part of the input and should not be processed. Output For each test case, output a line containing the shortest possible time from your house to your friendâs house. Sample Input 4 4 2 2 2 2 2 2 99 1 0 1 99 1 1 99 1 1 99 1 1 99 1 1 99 1 1 99 1 99 1 0 99 1 0 1 99 1 1 99 1 1 99 1 1 99 1 1 99 1 1 99 1 99 1 0 1 0 1 6 2 2 10 10 5 5 0 5 5 0 5 5 0 5 5 0 5 0 5 10 0 0 Output for the Sample Input 28 25 | 39,206 |
Flick Input A: ããªãã¯å
¥å äºæ¬¡å
ã倧奜ããªå€§åŠçïŒéç§°2Dåã¯ïŒé·å¹Žäœ¿çšããŠããã¬ã©ããŽã¹æºåž¯ããã¹ããã«è²·ããããïŒåããŠã¹ãããæäœãã2Dåã¯ïŒæåå
¥åã®æ¹åŒãïŒæã®æºåž¯ãšå°ãéãããšã«æ°ä»ããïŒã¹ããã§ã¯ïŒç»é¢ãã¿ããã»ããªãã¯ã§ããããšãå©çšããŠïŒããªãã¯å
¥åãšããæ¹åŒãæ¡çšãããŠããã®ã§ãã(ããªãã¯ãšã¯ïŒãç»é¢äžã§æãæ»ãããŠåŒŸãæäœããæå³ãã)ïŒããªãã¯å
¥åã¯ïŒæ¬¡ã«ç€ºããããªæåå
¥åæ¹åŒã§ããïŒ ããªãã¯å
¥åã§ã¯ïŒå³A(a)ã®ããã«ïŒ0-9ã®10åã®ãã¿ã³ã«ããå
¥åãè¡ã(#ãš*ã«ã€ããŠã¯ïŒä»åã¯çç¥ããŠãã)ïŒåãã¿ã³ã«ã¯ïŒå³ã®ããã«ãè¡-ãè¡ã1ã€ãã€å²ãåœãŠãããŠããïŒ å³A: ã¹ããã®ãã¿ã³è©³çް ãã1ã€ã®ãã¿ã³ã¯ïŒå³A(b)ã«è¡šãæ¹æ³ã«ããæäœããããšãã§ããïŒã€ãŸãïŒ ãã¿ã³ããã¿ãããããã ãã ãšïŒãã®ãã¿ã³ã«å¯Ÿå¿ããããæ®µãã®æåãåºå ãã¿ã³ããå·Šã«åãã£ãŠããªãã¯ããããšïŒããæ®µããåºå ãã¿ã³ããäžã«åãã£ãŠããªãã¯ããããšïŒããæ®µããåºå ãã¿ã³ããå³ã«åãã£ãŠããªãã¯ããããšïŒããæ®µããåºå ãã¿ã³ããäžã«åãã£ãŠããªãã¯ããããšïŒããæ®µããåºå ãšããããšã§ããïŒããªãã¯å
¥åã®ä»æ¹ãå
šãŠã®ãã¿ã³ã«ã€ããŠè¡šããšå³A(c)ã®ããã«ãªãïŒããããåºåããããã«ã¯ïŒãã¿ã³0ãäžåŽã«ããªãã¯ããããšã«æ³šæããŠã»ããïŒ ããªãã®ä»äºã¯ïŒããªãã¯å
¥åã®æäœã瀺ãæååãäžãããããšãïŒãã®æäœã®çµæåºåãããæååãæ±ããããšã§ããïŒ Input ããªãã¯å
¥åã®æäœã衚ãæååãïŒ1è¡ã§äžãããã(2æå以äž1000æå以äž)ïŒãã®æååã¯ïŒæäœãããã¿ã³ã衚ã'0'-'9'ã®æ°åãšïŒããªãã¯æ¹åã衚ã'T'ïŒ'L'ïŒ'U'ïŒ'R'ïŒ'D'ã®5çš®é¡ã®æåã®çµã¿åãããããªãïŒ ããªãã¯æ¹åã衚ãæåã¯ïŒæ¬¡ã®æå³ã衚ãïŒ 'T'ïŒã¿ããããã ã 'L'ïŒå·Šã«ããªãã¯ãã 'U'ïŒäžã«ããªãã¯ãã 'R'ïŒå³ã«ããªãã¯ãã 'D'ïŒäžã«ããªãã¯ãã äŸãã°ïŒ"2D"ã¯ïŒã2ã®ãã¿ã³ãäžã«åãã£ãŠããªãã¯ããšããæäœã衚ãããïŒããããåºåããããšãã§ããïŒ äžããããæååã¯ïŒæ°å1æåãšããªãã¯æ¹åã衚ã1æåã亀äºã«çŸããïŒãŸãïŒå¿
ãæ°å1æåããå§ãŸãïŒããªãã¯æ¹åã衚ã1æåã§çµããïŒããã«ïŒå³A(c)ã«ãããŠïŒæåããªãå Žæã«åãã£ãŠããªãã¯ãè¡ãããšã¯ãªã("8L"ãªã©ã®å
¥åã¯ãªã)ïŒ Output ããªãã¯å
¥åæäœã®çµæã衚ãæååãããŒãå衚èšã§åºåããïŒ ããŒãåã®åé³ã«ã¯ïŒ ãè¡ïŒ'k' ãè¡ïŒ's' ãè¡ïŒ't' ãªè¡ïŒ'n' ã¯è¡ïŒ'h' ãŸè¡ïŒ'm' ãè¡ïŒ'y' ãè¡ïŒ'r' ãè¡ïŒ'w' ã䜿çšããããšïŒã²ãããª1æåã衚ãããŒãåã¯ïŒäžèšã§è¡šãããåé³ãšæ¯é³ïŒ'a'ïŒ'i'ïŒ'u'ïŒ'e'ïŒ'o'ïŒãã»ããã«ããŠ2æåã§åºåããããšïŒ"shi"ã"fu"ã¯ãã®æ¡ä»¶ã«åããããééãã§ããïŒãã ãïŒããè¡ãã®æåã¯æ¯é³1æåã ããåºåãïŒãããã¯'n'ã2åç¶ããŠ"nn"ãšåºåããããšïŒ æååã®æåŸã«ã¯ïŒæ¹è¡ãåºåããããšïŒ Sample Input 1 5R2D Sample Output 1 neko Sample Input 2 8U9U6U0T Sample Output 2 yuruhuwa Sample Input 3 9L4U7R1L2D0U4R3U4D Sample Output 3 ritumeikonntesuto | 39,207 |
E: åŸåŸ©æåå / Round-trip String ç©èª ããã¯å
šäººé¡ãç«¶æããã°ã©ããŒã«ãªã£ãäžçããã®äžçã§ã¯ã¿ãªããã®çããçŸä»£ã§ã¯èããããªããããªç¿æ
£ã倿°ååšããããã®äžã®äžã€ã«ã䞡芪ãç¹ã«æ¯èŠªã«æè¬ã®èšŒã衚ãæã¯ãæååãéããšãã颚ç¿ããããéãæååãšããŠã©ã®ãããªæååããµãããããã¯å°åå·®ãããããåã®å€§å°åæµ·éã§ã¯ãã§ããã ãã·ã³ãã«ãªæååãèŽãç©ãšããŠãµããããããŸããéãããåŽã®æ¯èŠªã¯åäŸã«è¿ç€ŒãšããŠãéãããæååãã©ãã»ã©çŸããããçããå¿
èŠãããã ããŠãä»ããªãã¯1å
ã®æ¯èŠªããçžè«ãåããŠããããã®æ¯èŠªã¯åäŸããçŽ æŽãããããªæååãããã£ãã®ã ããã©ããããçŽ æŽãããã®ãããŸã枬ããªãã§ããããã ãåæµ·éã®é¢šç¿ã§ã¯ãæ¯èŠªã«éãæåå T ã¯ããæåå S ãåŸåŸ©ãããŠäœãããšã«ãªã£ãŠããããã®æã S ãã§ããã ãçãæååãªãã°ããçŽ æŽãããæåå T ã§ãããæ¯èŠªã¯åäŸã®é 匵ãã«å ±ããããã T ãäœãããšãã§ããæååã®äžã§ãæçã®æååãèŠã€ããŠããããããããã¯ãªããªãé£ãããšã®ããšã ãããªãã®ããã°ã©ãã³ã°èœåãé§äœ¿ããŠæ¯èŠªã®æ©ã¿ã解決ããŠæ¬²ããã åé¡ é·ãã 2 以äžã®æåå S ããã以äžã®ã«ãŒã«ã«åŸã£ãŠé·ã N ã®æåå T ãçæãããããã§ã S ã®æååé·ã K ãšãã T[i] ã¯æåå T ã® i çªç®ã®æåã衚ããããã§ã T ã®å
é æå㯠0 çªç®ã®æåãšããã T[i] = S[K - 1 - | (i $\bmod$ (2K - 2)) - K + 1 |] T ã®ã¿ãäžãããããšãã T ãçæããæååã¯è€æ°èããããã ãããã®æååã®äžã§æå°ã®æååé· K_{min} ãåºåããã å
¥ååœ¢åŒ N T å¶çŽ 2 \leq N = |T| \leq 1,000,000 æååã¯è±å°æåã®ã¿ãããªã åºååœ¢åŒ T ãçæããé·ãæå°ã®æåå S ã®é·ã K_{min} ãåºåããŠãã ããã å
¥åäŸ1 6 tabata åºåäŸ1 3 tabata ã tabat ã tab ã® 3 ã€ãèããããŸããã tab ãé·ãæå°ãªã®ã§ãçã㯠3 ã§ãã å
¥åäŸ2 4 hcpc åºåäŸ2 3 å
¥åäŸ3 60 aaaaaabbbbbbbbbbbaaaaaaaaaaabbbbbbbbbbbaaaaaaaaaaabbbbbbbbbb åºåäŸ3 12 | 39,208 |
Prime Number Write a program which reads an integer n and prints the number of prime numbers which are less than or equal to n . A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7. Input Input consists of several datasets. Each dataset has an integer n (1 †n †999,999) in a line. The number of datasets is less than or equal to 30. Output For each dataset, prints the number of prime numbers. Sample Input 10 3 11 Output for the Sample Input 4 2 5 | 39,209 |
Set Intersection Find the intersection of two sets $A = \{a_0, a_1, ..., a_{n-1}\}$ and $B = \{b_0, b_1, ..., b_{m-1}\}$. Input The input is given in the following format. $n$ $a_0 \; a_1 \; ... \; a_{n-1}$ $m$ $b_0 \; b_1 \; ... \; b_{m-1}$ Elements of $A$ and $B$ are given in ascending order respectively. There are no duplicate elements in each set. Output Print elements in the intersection in ascending order. Print an element in a line. Constraints $1 \leq n, m \leq 200,000$ $0 \leq a_0 < a_1 < ... < a_{n-1} \leq 10^9$ $0 \leq b_0 < b_1 < ... < b_{m-1} \leq 10^9$ Sample Input 1 4 1 2 5 8 5 2 3 5 9 11 Sample Output 1 2 5 | 39,210 |
ã·ã£ããã« åé¡ 1 ãã n ãŸã§ã®çªå·ãæžããã n æã®ã«ãŒããããïŒãŸãïŒäžçªäžãçªå· 1 ã®ã«ãŒãïŒäžãã2æç®ãçªå· 2 ã®ã«ãŒãïŒâŠïŒäžçªäžãçªå· n ã®ã«ãŒããšãªãããã«é çªã«éããŠïŒã«ãŒãã®å±±ãäœãïŒ ã«ãŒãã®å±±ã«å¯ŸããŠïŒãã·ã£ããã«(x,y)ããšåŒã°ããæ¬¡ã®ãããªæäœãè¡ãããšã§ïŒã«ãŒããäžŠã³æ¿ããïŒx, y 㯠1 †x < y < n ãã¿ããæŽæ°ïŒïŒ ã·ã£ããã«(x,y) n æã®ã«ãŒããïŒäžçªäžãã x æç®ãŸã§ã®ã«ãŒããããªãå±±AïŒ x+1 æç®ãã y æç®ã®ã«ãŒããããªãå±±BïŒ y+1 æç®ãã n æç®ã®ã«ãŒããããªãå±±C ã®3ã€ã®å±±ã«åããïŒãããŠïŒå±±Aã®äžã«å±±BãéãïŒããã«ãã®äžã«å±±CãéããïŒ äŸãã°ïŒé çªã«äžŠãã§ãã9æã®ã«ãŒãã«å¯ŸããŠãã·ã£ããã«(3,5)ããè¡ããšïŒ 9 æã®ã«ãŒãã«æžãããçªå·ã¯, äžããé çªã« 6, 7, 8, 9, 4, 5, 1, 2, 3 ãšãªãïŒ æåã®å±±ã®ç¶æ
ãã m åã®ã·ã£ããã«ãã·ã£ããã«(x 1 , y 1 )ããã·ã£ããã«(x 2 , y 2 )ã ⊠ãã·ã£ããã«(x m , y m )ããé çªã«è¡ã£ãåŸã®ã«ãŒãã®å±±ã«ãããŠïŒäžããæ°ã㊠p æç®ãã q æç®ã®ã«ãŒãã®äžã«çªå·ã r 以äžã®ã«ãŒããäœæå«ãŸããŠããããæ±ããããã°ã©ã ãäœæããïŒ å
¥å å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ å
¥å㯠m+3 è¡ãããªãïŒ 1 è¡ç®ã«ã¯ã«ãŒãã®ææ° n ãæžãããŠããïŒ3 †n †1000000000 = 10 9 ïŒïŒ 2 è¡ç®ã«ã¯ã·ã£ããã«ã®åæ°ãè¡šãæŽæ° m ãæžãããŠããïŒ1 †m †5000ïŒïŒ 3 è¡ç®ã«ã¯æŽæ° p, q, r ãæžãããŠããïŒ1 †p †q †n, 1 †r †nïŒïŒ i + 3 è¡ç®ïŒ1 †i †mïŒã«ã¯2ã€ã®æŽæ° x i , y i (1 †x i < y i < n) ã空çœãåºåããšããŠæžãããŠããïŒ n ã 0 ã®ãšãå
¥åã®çµäºã瀺ã. ããŒã¿ã»ããã®æ°ã¯ 5 ãè¶
ããªãïŒ åºå ããŒã¿ã»ããããšã«, m åã®ã·ã£ããã«åŸã®ã«ãŒãã®å±±ã«ãããŠïŒäžããæ°ã㊠p æç®ãã q æç®ã®ã«ãŒãã®äžã«å«ãŸããŠããçªå·ã r 以äžã®ã«ãŒãã®ææ°ãïŒè¡ã«åºåããïŒ å
¥åºåäŸ å
¥åäŸ 9 1 3 7 4 3 5 12 3 3 8 5 3 8 2 5 6 10 0 åºåäŸ 2 3 1ã€ç®ã®å
¥åäŸã®å±±ã«å¯ŸããŠ, ãã·ã£ããã«(3,5)ããè¡ããšïŒã«ãŒãã¯äžããé çªã« 6, 7, 8, 9, 4, 5, 1, 2, 3 ãšãªãïŒäžããæ°ã㊠3 æç®ãã 7 æç®ã«å«ãŸããçªå·ã 4 以äžã®ã«ãŒãã¯ïŒçªå· 4 ãšçªå· 1 ã® 2 æã§ããïŒ ãŸãïŒ2ã€ç®ã®å
¥åäŸã®å±±ã«å¯ŸããŠ, ãã·ã£ããã«(3,8)ããã·ã£ããã«(2,5)ããã·ã£ããã«(6,10)ããé çªã«è¡ããšïŒã«ãŒãã¯äžããé çªã« 9, 10, 3, 11, 12, 4, 5, 6, 7, 8, 1, 2 ãšãªãïŒäžããæ°ã㊠3 æç®ãã 8 æç®ã«å«ãŸããçªå·ã 5 以äžã®ã«ãŒã㯠3 æã§ããïŒ äžèšå顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã | 39,211 |
Score : 500 points Problem Statement Given are two strings s and t consisting of lowercase English letters. Determine if there exists an integer i satisfying the following condition, and find the minimum such i if it exists. Let s' be the concatenation of 10^{100} copies of s . t is a subsequence of the string {s'}_1{s'}_2\ldots{s'}_i (the first i characters in s' ). Notes A subsequence of a string a is a string obtained by deleting zero or more characters from a and concatenating the remaining characters without changing the relative order. For example, the subsequences of contest include net , c , and contest . Constraints 1 \leq |s| \leq 10^5 1 \leq |t| \leq 10^5 s and t consists of lowercase English letters. Input Input is given from Standard Input in the following format: s t Output If there exists an integer i satisfying the following condition, print the minimum such i ; otherwise, print -1 . Sample Input 1 contest son Sample Output 1 10 t = son is a subsequence of the string contestcon (the first 10 characters in s' = contestcontestcontest... ), so i = 10 satisfies the condition. On the other hand, t is not a subsequence of the string contestco (the first 9 characters in s' ), so i = 9 does not satisfy the condition. Similarly, any integer less than 9 does not satisfy the condition, either. Thus, the minimum integer i satisfying the condition is 10 . Sample Input 2 contest programming Sample Output 2 -1 t = programming is not a substring of s' = contestcontestcontest... . Thus, there is no integer i satisfying the condition. Sample Input 3 contest sentence Sample Output 3 33 Note that the answer may not fit into a 32 -bit integer type, though we cannot put such a case here. | 39,212 |
F: Opeartion training for BYDOL / BYDOLã®æäœèšç·Ž u'sãšããã¹ã¯ãŒã«ã¢ã€ãã«ãçµæããç§éã¯ïŒãããªãé«ã¿ãç®æãããïŒéšå®€ã«ãã£ãDVDã§æ§ãã®841ãããã¯ã·ã§ã³ã«æå±ããã¢ã€ãã«éãèŠãŠããïŒ ãã®ã¢ã€ãã«éã¯ä»ã§ããèŒãã¹ããŒãžã®äžã§æŽ»èºããŠãããïŒä»¥åã¯BYDOLãšåŒã°ããããããã«ä¹ã蟌ã¿ïŒéç³ã®æ€å»äœæ¥ãããŠãããããïŒ ããã§ïŒãããã¢ã€ãã«ã«ãªãããã«ïŒBYDOLã®æçžŠæè¡ãå¿
èŠã§ããããšãç¥ã£ãç§éã¯ïŒæ¥éœBYDOLãå
¥æãïŒä»æ ¡ã®ã¹ã¯ãŒã«ã¢ã€ãã«ãšBYDOLãçšããæš¡æ¬æŠãããããšã«ããïŒ ãã®æš¡æ¬æŠã§ã¯ïŒçœã®è»ãšèµ€ã®è»ã«åããïŒBYDOLã«ç©ãŸããŠãã匟ã«ããæã¡åããè¡ãïŒ åè»ã®ã¡ã³ãã¯ïŒããããBYDOLã«ä¹ã蟌ã¿ïŒåå³ãåºããšåæã« ã1床ã ãã 匟ãæã€ïŒ åå³ãåºãæç¹ã§ã®å
šãŠã®BYDOLã®åº§æšã¯æ±ºãŸã£ãŠããïŒBYDOLå士ã¯ã¬ãŒããŒã«ãã£ãŠäºãã®åº§æšãææ¡ã§ããïŒ åã座æšã«BYDOLã2å°ä»¥äžçŸããããšã¯ãªãïŒ BYDOLãç§»åã§ãããã£ãŒã«ãã¯2次å
å¹³é¢ã§è¡šããïŒéåžžã«åºããã£ãŒã«ãå
šäœãå²ãå£ã¯ãªããã®ãšããŠèããïŒ ãããïŒãã£ãŒã«ãå
éšã«ããã€ãã®å圢ã®å£ãçšæãããŠããïŒ ãã®å£ã®å
åŽã¯ïŒã³ã³ã¯ãªãŒãã§å¡ãåºããããŠããããïŒBYDOLã䟵å
¥ããããšã¯ã§ããªãïŒ å£ãæ§æããåã¯ïŒäºãã«æ¥ããã亀差ãããå
å
é¢ä¿ã«ãªã£ããããããšã¯ãªãïŒBYDOLããã座æšäžã«å£ã¯ååšããªãïŒ åBYDOLã«ã¯ïŒåå³ãåºãæç¹ã§äœçœ®ãã座æšïŒå°çšïŒ1床ã«çºå°ã§ãã匟æ°ïŒå£ã§åå°ãã匟ãç©ãã§ãããïŒåãããæã«æµè»ãåŸãç¹æ°ã®5ã€ã®ãã©ã¡ãŒã¿ãèšå®ãããŠããïŒ åŒŸã¯ïŒBYDOLãããäœçœ®ãã360床ã©ã®æ¹åãžãçºå°ããããšãã§ãïŒäžçŽç·ç¶ã«é²ãïŒ çºå°ãããŠããé²ãã 匟ã®è·é¢ãå°çšã®å€ä»¥äžã§ããéïŒãã€ä»ã®BYDOLãå£ã«åŒŸãåœãããªãéã§ããã°ïŒåŒŸã¯é²ã¿ç¶ããïŒ ãã£ãŒã«ãäžãåãå
šãŠã®åŒŸã¯ïŒåŒŸéã亀差ããŠããŠãè¡çªããªããã®ãšããïŒ BYDOLã«ãã£ãŠã¯å£ã§åå°ãã匟ãç©ãã§ããå ŽåãããïŒ ãã®å Žåã®BYDOLã®åŒŸã¯å
šãŠïŒ1åã®ã¿å£ã§åå°ããïŒ ãã ãïŒèªåã®BYDOLããå£ã®åå°ããå°ç¹ãŸã§ã®è·é¢ãšïŒåå°ããå°ç¹ããçžæã®BYDOLãŸã§ã®è·é¢ã®åèšãïŒå°çšã®å€ä»¥äžã§ãªããã°ïŒçžæã«åœãã£ãããšã«ã¯ãªããªãïŒ å£ã§åå°ãããšãã¯å³1ã®ããã«ïŒåŒŸãå£ã«åœãã£ãå°ç¹ã«å¯ŸããŠæ¥ç·ãåŒãïŒãã®ç·ãåºæºã«å
¥å°è§ Ξ 1 ãšåå°è§ Ξ 2 ãçãããªãããã«åå°ããïŒ åŒŸéãå£ãæ§æããåã«æ¥ããå ŽåïŒãã®ãŸãŸãŸã£ãã匟ã¯é²ã¿ïŒå£ã§åå°ããããšã«ã¯ãªããªãïŒ å³1: 匟ã®åå° ããBYDOLã¯ïŒçºå°ã§ãã匟æ°ã®ç¯å²ã§ïŒ1床ã«è€æ°ã®åŒŸãæã¡ïŒè€æ°ã®BYDOLã«åœãŠãããšãã§ããïŒãã ãïŒåãBYDOLãïŒå
šãåãæ¹åãžåãã£ãŠåŒŸã2çºä»¥äžæã€ããšã¯èš±ãããªãïŒ åBYDOLã«ã¯ïŒåãããæã«æµè»ãåŸãç¹æ°ãèšå®ãããŠããïŒ ãã®æã¡åãã§ã¯ïŒããå€ãã®ç¹æ°ãåŸãè»ãåè
ãšãªãïŒ åãç¹æ°ãåŸãå Žåã¯ïŒåŒãåããšããïŒ BYDOLã¯1çºåŒŸãåœãŠãã°åããããïŒåãBYDOLã«äœçºæã¡èŸŒãããïŒåŸãããç¹æ°ã¯1床ããã§ããïŒ å³æ¹ã®BYDOLãæã£ãå ŽåïŒå€±æ Œã«ãªã£ãŠããŸãããçµ¶å¯Ÿã«æã£ãŠã¯ãããªãïŒ èªæ»
ããããšãèš±ãããªãïŒ u'sã«ãããäœæŠææ®æ
åœã§ããããªãã®ä»äºã¯ïŒåè»ãæå€§ã®ç¹æ°ããšããããã«è¡åãããšãã®ç¹æ°ãæ±ãïŒã©ã¡ãã®è»ãåã€ããšãã§ããã®ããå€å®ããããšã§ããïŒ ãããã§ããã°ïŒu'sã¯ãããã¢ã€ãã«ãžäžæ©è¿ã¥ãããšãã§ããã ããïŒ Input å
¥åã¯æ¬¡ã®åœ¢åŒã§è¡šãããïŒ n m o ax 1 ay 1 ap 1 aq 1 ar 1 as 1 ... ax n ay n ap n aq n ar n as n bx 1 by 1 bp 1 bq 1 br 1 bs 1 ... bx m by m bp m bq m br m bs m wx 1 wy 1 wr 1 ... wx o wy o wr o å
šãŠã®æ°å€ã¯æŽæ°ã§å
¥åãããïŒ n , m (1 ⊠n , m ⊠50) ã¯çœã®è»ãšèµ€ã®è»ã®BYDOLã®æ°ïŒ o (0 ⊠o ⊠15) ã¯å£ã®æ°ã衚ãïŒ ax i , ay i (0 ⊠ax i , ay i ⊠100) ã¯içªç®ã®çœã®è»ã®BYDOLã®åº§æšïŒ ap i (0 ⊠ap i ⊠200) ã¯å°çšïŒ aq i (1 ⊠aq i ⊠5) ã¯1床ã«çºå°ã§ããåŒŸã®æ°ïŒ ar i (0 <= ar i <= 1) ã¯å£ã§åå°ãã匟ãç©ãã§ãããã©ããïŒ as i (0⊠as i ⊠100) ã¯åãããæã«ïŒæµè»ãåŸãç¹æ°ã§ããïŒ ar i ãïŒ0ã§ãããšãã¯ææããŠãã匟ãåå°ã§ããªãããšïŒ1ã§ãããšãã¯åå°ã§ããããšã衚ããŠããïŒ èµ€ã®è»ã®BYDOLã®æ
å ±ãåæ§ã«äžããããïŒ ãã®åŸïŒå£ã®äžå¿åº§æš( wx i , wy i )ãšååŸ wr i ãäžãããã(0 ⊠wx i , wy i ⊠100, 1 ⊠wr i ⊠30) ïŒ Output çœã®è»ãšèµ€ã®è»ãããããïŒæãç¹æ°ãåŸãããããã«åŒŸãçºå°ãããšãã®ç¹æ°ã空çœåºåãã§1è¡ç®ã«åºåããïŒ ããã«ïŒçœã®è»ãåã€å Žåã¯winïŒè² ããå Žåã¯loseïŒåŒãåãã®å Žåã¯drawã2è¡ç®ã«åºåããïŒ åºåã«ã¯ïŒããã以å€ã®æåããã£ãŠã¯ãªããªãïŒ Sample Input 1 2 2 0 0 0 5 1 0 0 1 0 5 1 0 0 0 1 5 1 0 10 1 1 5 1 0 10 Sample Output 1 20 0 win Sample Input 2 2 3 0 0 0 5 1 0 20 1 0 5 1 0 10 10 10 4 1 0 100 10 0 1 1 0 50 4 0 5 1 0 10 Sample Output 2 10 10 draw Sample Input 3 1 1 2 0 0 20 1 1 20 10 0 20 1 0 20 5 0 2 5 8 2 Sample Output 3 20 0 win Sample Input 4 1 1 1 0 0 5 1 0 5 5 0 5 1 0 10 1 1 1 Sample Output 4 10 5 win Sample Input 5 1 2 5 13 27 19 4 0 30 14 14 34 4 1 9 49 71 21 3 1 31 5 86 18 85 27 3 90 91 1 34 50 10 92 54 15 Sample Output 5 9 30 lose | 39,213 |
Problem I: Text Justification You are hired by the âI¶×Îâ, an extraterrestrial intelligence, as a programmer of their typesetting system. Your task today is to design an algorithm for text justification . Text justification is to equalize the line widths as much as possible by inserting line breaks at appropriate posi- tions, given a word sequence called a paragraph and the width of the paper. Since you have not developed an automatic hyphenation algorithm yet, you cannot break a line in the middle of a word. And since their language does not put spaces between words, you do not need to consider about spacing. To measure how well the text is justified in one configuration (i.e., a set of lines generated by inserting line breaks to a paragraph), you have defined its cost as follows: The total cost of a paragraph is the sum of the cost of each line. The cost for the last line is defined as max(0, s - w ). The cost for other lines are given by | s - w |. where s is the sum of the widths of the words in the line, and w is the width of the paper. Please design the algorithm which takes a paragraph and calculates the configuration of the minimum cost. Input The input consists of multiple test cases. The first line of each test case contains two positive integers n and w (0 †n †1000 and 0 †w †1,000,000). n is the length of paragraph and w is the width of the used paper. Each of the following n lines contains one positive integer a i which indicates the width of the i -th word in the paragraph. Here it is guaranteed that 0 †a i †w . The input terminates with the line containing two zeros. This is not a part of any test case and should not be processed. Output For each test case, print the case number and the minimum cost for the paragraph. Sample Input 4 10 8 6 9 1 4 7 1 2 3 4 0 0 Output for the Sample Input Case 1: 4 Case 2: 1 | 39,215 |
Problem Setting Overview Concept: In this programming contest, you will run a delivery service. Customers will place orders with your shop. Each order has a unique \text{ID} and should be delivered to the corresponding customer. Your delivery service has one car. The car will fetch the ordered item from the shop and deliver it to the customer. Score: Your goal is to deliver as many items as possible, as quickly as possible in a given amount of time T_{\text{max}} . (Orders are expected until 0.95 \times T_{\text{max}} ). Constraint: In this contest there is no constraint on the number of items you can place in the car. However, an item can only be loaded in the car, by fetching it from the shop, after the order has been placed. Problem A/B: In problem A all order positions and times are given to the contestant in advance and the contestant algorithm shall optimize the moves of the car to make as many deliveries as possible as fast as possible. On the other hand, in problem B orders appear online, that is new orders appear, while you move your car to make as many deliveries as possible as fast as possible. Specification of Time and Space: Time: In this contest we model the progress of time by integer values 0 \le t < T_{\text{max}} . Map: In this contest we model a map by a simple, undirected, and connected graph G=(V, E) , consisting of a set of vertices V and a set of edges E Shop and customer locations: The vertices u \in V are labeled from 1 to |V| and the vertex u=1 denotes the location of your shop, while vertices u = 2,...,|V| denote locations of potential customers. Here, |V| denotes the number of elements of the set V . Streets: Each edge \left\{ u, v \right\} \in E represents a street connecting the vertices u, v \in V . The corresponding length is given by an integer edge weight d_{u, v} \ge 1 . Graph creation: The algorithm for generating the map graph based on a random seed is specified in the following pseudo-code. For further details, please see the sample code below. Pseudo code: Map graph generator Input: |V| , |E| , \mathrm{MaxDegree}=5 2d vertex grid: First, find the largest integer R>0 such that |V| = R^{2} + r , with r being the smallest possible non-negative integer. Then we plot points (x, y) on the 2d vertex grid (0 \leq x, y \lt R) . For each point (x, y) add a uniform random offset dx, dy \in [0, 1] , giving the final vertex position (x + dx, y + dy)\in [0,R] \times [0,R] . Finally, add the remaining r vertices at a uniform random position (x, y) with 0 \leq x, y \leq R . Vertex labels u \in V are assigned by random shuffling. The shop is the vertex u=1 . How we create Highways: To generate a highway network, we create a complete graph G_{\text{comp}} on the vertex set u \in V , assigning each vertex pair u, v \in V \times V the Euclidean distance W_{u, v} as an edge weight. Next, we construct a minimum spanning tree of G_{\text{comp}} . The |V|-1 edges of the minimum spanning tree are the highway network of the graph G . We assign each of those edges \left\{ u, v \right\} an edge weight d_{u,v} \leftarrow \lceil 2 \times W_{u, v} \rceil . How we add side roads: To create a network of side roads, we successively add |E|-(|V|-1) edges to the graph G as follows: Update \mathrm{cost}(u,v) . Among the vertex pairs \left( u, v \right) \in V\times V , not yet connected by an edge, select a pair with minimal \mathrm{cost}(u,v) . Assign the edge weight d_{u,v} \leftarrow \lceil 4 \times W_{u, v} \rceil . Here, \mathrm{cost}(u,v) is essentially based on the Euclidean distance of vertices, giving preference to connecting nearby vertices with low degree. In addition, preference is given to side roads along the rectangular grid, to avoid too many bridges. The detailed definitions are as follows: Define \mathrm{degree}(u) , the degree of vertex u\in V as the number of incident edges. Define \mathrm{color}(u) for each vertex u\in V according to its original position (x,y) on the vertex grid as: If x+y is even : \mathrm{color}(u) = 0 If x+y is odd : \mathrm{color}(u) = 1 For the remaining r vertices : Assign a color \mathrm{color}(u) \in \left\{0,1\right\} at random. Define a factor f(u,v) as follows: If \mathrm{color}(u) and \mathrm{color}(v) are the same : Set \mathrm{f}(u,v) = 5 If \mathrm{color}(u) and \mathrm{color}(v) are different : Set \mathrm{f}(u,v) = 1 Define a factor g(u) as follows: If \mathrm{degree}(u) \lt \mathrm{MaxDegree} : Set g(u)=1 If \mathrm{degree}(u) \geq \mathrm{MaxDegree} : Set g(u)=\infty Finally, the cost is defined as follows: \mathrm{cost}(u,v) = W_{u,v}\times \mathrm{degree}(u) \times \mathrm{degree}(v) \times f(u,v) \times g(u) \times g(v) . How we assign order frequencies: Assign each vertex u \in V an order frequency f_u \in \left\{0,1,2\right\} . Init the order frequency of the shop vertex: f_1 \leftarrow 0 . Init the order frequency of the other vertices: f_u \leftarrow 1 Now determine vertices with order frequency 2. For this draw a uniform random center point c=(c_x,c_y)\in [R/4,3R/4]\times[R/4,3R/4] and then for all vertices u=2,...,|V| do: If \mathrm{EuclideanDistance}(c,u)\le R/8 + \mathrm{uniformRandom}[0,R/8] : f_{u} \leftarrow 2 Specification of Car Locations and Moves: In order to make deliveries you will operate a delivery car, which can take positions and make moves as specified below. Car position: A car can generally take two types of position: on a vertex u \in V . on an edge \left\{ u, v \right\} \in E . More specifically, it is located at a distance x (0 \lt x \lt d_{u, v}) from u to v . Car move: At each step 0 \le t < T_{\text{max}} you have to choose one of the following actions in order to control your delivery car. stay : stay at the current position. move w : Take one step towards vertex w \in V . In case of choosing move w , w must obey the following constraints. A failure to obey these constraints results in a wrong answer WA . w must be a vertex, i.e., w \in V . If the car is on vertex u \in V , there must be an edge connecting u and v , i.e., \left\{ u, w \right\} \in E . If the car is on the edge \left\{ u, v \right\} \in E , w must either be w = u or w = v . Orders, Deliveries, and Constraints: Orders: Throughout the contest each order is characterized by three quantities: A unique order ID, a vertex v \in V indicating the order destination, and the order time t at which the order appeared. For the detailed format see below. Order generation: At each time 0 \le t \le T_{\text{last}} = 0.95 \times T_{\text{max}} up to one new order can appear with probability p_{\text{order}}(t) . In case there is an order, the order destination i is chosen from the vertex set V with probability proportional to the order frequency f_i . For details, see the pseudo-code below or the sample code further below. Pseudo code: Order generation Input: Last order time T_{\text{last}} and average order probability p_{\text{order}}(t) . Init: \mathrm{ID} \leftarrow 0 . For each step t = 0, ..., T_{\text{last}} do: Generate a uniform random number r \in [0,1] . If r \le p_{\text{order}}(t) : Select a vertex position u \in V at random with probability proportional to the order frequency f_{u} of the vertex. \mathrm{ID} \leftarrow \mathrm{ID} + 1 place order (new order ID, order time t , vertex position u \in V ) Else: place no order Note: The average order probability is defined as follows: p_{\text{order}}(t) = \begin{cases} t / T_{\text{peak}}, & \text{if } 0\le t \lt T_{\text{peak}}, \\ (T_{\text{last}} - t) / (T_{\text{last}}- T_{\text{peak}}), & \text{if } T_{\text{peak}} \le t \lt T_{\text{last}}, \\ 0, & \text{if } T_{\text{last}} \le t, \end{cases} where T_{\text{last}}:=0.95 \times T_{\max} and T_{\text{peak}} is drawn randomly uniform from the interval [0, T_{\text{last}}] . Note: The value of T_{\text{peak}} will not be given as an input. Delivery: To deliver an order, the contestant must do the following steps after the order has been placed: (1st) Move the car onto the shop: Note: When moving a car onto the shop, all orders with order time less than or equal to the current time, will be transfered into the car. On the other hand, orders which have not appeared yet, cannot be placed into the car. (2nd) Move the car to the customer position: To finalize a delivery, move the car onto the vertex of the customer position. Note: Orders which have not been transfered into the car yet, will not be delivered, even if you arrive at the customer position. Constraints: Throughout the contest, we assume each order has a unique \text{ID} and should be delivered to the corresponding customer. It is further assumed that an unlimited number of orders can be placed in the car. Scoring During the contest the total score of a submission is determined by summing the score of the submission with respect to 30 input cases. After the contest a system test will be performed. To this end, the contestant's last submission will be scored by summing the score of the submission on 100 previously unseen input cases. For each input case, the score is calculated as follows: \text{Score} = \sum_{i \in D} {(T_{\text{max}})}^{2} - {(\mathrm{waitingTime}_i)}^{2}, Here we use the following definitions: D : the set of orders delivered until t=T_{\text{max}} the waiting time of the i th order: \mathrm{waitingTime}_i = \mathrm{deliveredTime}_i - \mathrm{orderedTime}_i . Note that an input case giving the output WA will receive 0 points. Particulars of Problem B: Problem B is an interactive contest, where the contestant code successively receives updates on newly generated and delivered orders from a host code, while simultaneously servicing the customer by moving the car to a neighboring position in every step t=0,...,T_{\max}-1 . The precise flow which details the interaction of the contestant and host code is shown below. Contestant Code Host Code Generate and output graph G + Time t : Generate and output new orders + Time t : If on shop, output orders loaded into car + Time t : Determine and output a move + Check feasibility of move; If move unfeasible: output NG , If feasible: output OK + Time t+1 : update and output information on delivered items (if any) Note: The host code outputs the graph only once. The processes marked by a "+" on the left side of the table are repeated iteratively for integers t in t = 0,..., T_{\max} - 1 . Input/Output Format for the Standard IO At first, the host code will output a graph G , the order frequencies f_{i} for each vertex i , which are proportional to the probability of an order to appear at vertex i , and the total number of steps T_{\max} . |V| |E| u_1 v_1 d_{u_1, v_1} u_2 v_2 d_{u_2, v_2} \vdots u_{|E|} v_{|E|} d_{u_{|E|}, v_{|E|}} f_1 f_2 \ldots f_{|V|} T_{\max} First line: |V| number of vertices, |E| number of edges The next |E| lines: The edges of the graph. In particular, the i th line denotes the vertices u_i and v_i which form an edge, along with the corresponding edge weight d_{u_i, v_i} . The next line: The order frequencies f_i which determine the probability of an order at vertex i as p_{i}=\frac{f_{i}}{\sum_{i}f_{i}} . The last line: The total number of car updates T_{\max} . At time t we first obtain the following information through the standard input. N_{\text{new}} \mathrm{new\_id}_1 \mathrm{dst}_1 \mathrm{new\_id}_2 \mathrm{dst}_2 \vdots \mathrm{new\_id}_{N_{\text{new}}} \mathrm{dst}_{N_{\text{new}}} N_{\text{put}} \mathrm{put\_id}_1 \mathrm{put\_id}_2 \mathrm{put\_id}_{N_{\text{put}}} N_{\text{new}} represents the number of new orders which appeared at time t . The next N_{\text{new}} lines give the newly generated order information. The i th order information indicates that the order ID \mathrm{new_{id}}_i of the new order, while \mathrm{dst}_i denotes the vertex to which the customer wishes the order to be delivered. N_{\text{put}} represents the number of items transfered into the car at time t . If the car is not at the vertex of the store N_{\text{put}} will be zero. The subsequent N_{\text{put}} lines indicate the order information for the newly loaded items. In particular, the i th line indicates that the order ID corresponding to the product loaded in the car is \mathrm{put_{id}}_i . Next, in order to move the delivery car to a neighboring position the contestant code must at every time t ( 0 \leq t \lt T_{\max} ) output the following \mathrm{command} to the standard output. \mathrm{command} Here, \mathrm{command} must be of the following form If you want the car to stay at its current position, send -1 to the standard output If you want the car to move one step towards a neigboring vertex move w , send w to the standard output Note: In case you choose move w , w must meet all of the following conditions. If any of the following conditions is violated, the host code will output NG and the contestant should terminate the program, ultimately leading to WA (incorrect). w is a vertex index with w \in \left\{1, ... , |V|\right\} If the car is on a vertex u , the edge \left\{ u, w \right\} \in E must exist If the car is on an edge \left\{ u, v \right\} , w must either be w = u or w = v After your action at time t is send to the standard output, the host code will send the following information about time t + 1 to the standard input. \mathrm{verdict} N_{\text{achieve}} \mathrm{achieve\_id}_1 \mathrm{achieve\_id}_2 \vdots \mathrm{achieve\_id}_{N_{\text{achieve}}} \mathrm{verdict} is a string indicating whether your action at time t was valid. It can be one of the two following options. OK : Indicating that your action was feasible NG : Indicates that your action is infeasible. If you receive this input, you must terminate the program immediately. It is guaranteed to be WA (incorrect), if it is terminated immediately.If you do not terminate immediately the behavior is undefined. N_{\text{achieve}} represents the number of orders that have been delivered at time t . If the car is not at a delivery vertex, no orders have been delivered and N_{\text{achieve}}=0 . The subsequent N_{\text{achieve}} lines indicate the delivered orders. In particular, the i th line indicates the order ID \mathrm{achieve\_{id}}_i . Finally, after receiving the standard input of the host code after the last step T_{\max} you must terminate the program immediately. Constraints I/O Constraints All numbers given through the standard input are integers. All outputs must be integers T_{\text{max}} = 10000 200 \leq |V| \leq 400 1.5 |V| \leq |E| \leq 2|V| 1 \leq u_{i}, v_{i} \leq |V| (1 \leq i \leq |E|) 1 \leq d_{u_i, v_i} \leq \lceil 4\sqrt{2|V|} \rceil (1 \leq i \leq |E|) The given graph has no self-loops, no multiple edges and is guaranteed to be connected. f_1 = 0 f_i \in \left\{ 1, 2 \right\} ( 2 \leq i \leq |V| ) \mathrm{verdict} \in \left\{ \text{"OK"}, \text{"NG"} \right\} 0 \leq N_{\text{new}} \leq 1 1 \leq \mathrm{new\_id}_{i} \leq T_{\text{last}}+1 (1 \leq i \leq N_{\text{new}}) . Note: If all orders are generated by the order generation rule as explained above, the total number of orders is at most T_{\text{last}}+1 . Therefore, the possible range of \mathrm{new\_id}_{i} should be from 1 to T_{\text{last}}+1 . The order IDs \mathrm{new\_{id}}_i are unique. 2 \leq \mathrm{dst}_i \leq |V| (1 \leq i \leq N_{\text{new}}) The integer which the contestant outputs to the standard output at time t must either be -1 or 1 \leq w \leq |V| Input/Output Example Time Contestant Host Code Explanation 5 7 1 2 5 5 3 4 2 4 8 1 5 1 2 3 3 4 5 3 4 3 9 0 1 1 5 5 500 At first, the host code provides the graph data through the standard input. In this example, the graph has |V| = 5 vertices and | E | = 7 edges. Next, the order frequency for each vertex is given in one line. Finally, T_{\max} is given. 0 \rightarrow 1 1 1 5 1 1 At time t=0 we get one order. This order has ID = 1 and should be delivered to vertex 5 . Because your car is currently at vertex one, the order will be automatically transfered into your car. In this way, when your car is at the shop, all orders which have been made at present and before, will automatically be loaded into your car. 2 You decided to move one step towards vertex. OK 0 The first line indicates that your move was feasible. The second line shows that no orders have been delivered. 1 \rightarrow 2 1 2 2 0 One new order (ID =2 , delivery vertex =2 ) has occured. Your car is on the edge between vertex 1 and 2 , so zero orders have been transfered to your car. -1 You decided to keep your car in the same position. OK 0 Your move was valid. No orders will be delivered, because you are not at a delivery item position. 2 \rightarrow 3 1 3 4 0 A new order (ID =3 , delivery vertex =4 ) has appeared. 1 You decided to move back one step towards vertex 1 . In this way you are allowed to perform a U-turn. OK 0 No orders have been delivered. 3 \rightarrow 4 0 2 2 3 Since the car has returned to the store, products corresponding to order ID 2 and 3 are loaded onto the car. 5 The contestant has decided to move one step towards vertex 5. OK 1 1 Since you arrived at vertex 5, the order with ID 1 was delivered. 4 \rightarrow 5 0 0 There is no new order. 5 The contestant decides to move one step towards vertex 5 . NG The input was invalid and you should terminate your program. Using the Standard Output When returning your move instruction to the standard output, please use the flush command. As an example, consider the case where you want to output -1 . This is how to do it in some of the major programming languages. C++ std::cout << "-1" << std::endl; Java System.out.println("-1"); Python 3.4 print("-1", flush=True) Sample Code B A software toolkit for generation of input samples, scoring and testing on a local contestant environment, and sample codes for beginners is provided through the following link . In addition we provide software for visualizing the contestants results. | 39,217 |
Score : 200 points Problem Statement Snuke signed up for a new website which holds programming competitions. He worried that he might forget his password, and he took notes of it. Since directly recording his password would cause him trouble if stolen, he took two notes: one contains the characters at the odd-numbered positions, and the other contains the characters at the even-numbered positions. You are given two strings O and E . O contains the characters at the odd-numbered positions retaining their relative order, and E contains the characters at the even-numbered positions retaining their relative order. Restore the original password. Constraints O and E consists of lowercase English letters ( a - z ). 1 \leq |O|,|E| \leq 50 |O| - |E| is either 0 or 1 . Input Input is given from Standard Input in the following format: O E Output Print the original password. Sample Input 1 xyz abc Sample Output 1 xaybzc The original password is xaybzc . Extracting the characters at the odd-numbered positions results in xyz , and extracting the characters at the even-numbered positions results in abc . Sample Input 2 atcoderbeginnercontest atcoderregularcontest Sample Output 2 aattccooddeerrbreeggiunlnaerrccoonntteesstt | 39,218 |
Score : 400 points Problem Statement There is a grid with N rows and N columns of squares. Let (i,j) be the square at the i -th row from the top and the j -th column from the left. These squares have to be painted in one of the C colors from Color 1 to Color C . Initially, (i,j) is painted in Color c_{i,j} . We say the grid is a good grid when the following condition is met for all i,j,x,y satisfying 1 \leq i,j,x,y \leq N : If (i+j) \% 3=(x+y) \% 3 , the color of (i,j) and the color of (x,y) are the same. If (i+j) \% 3 \neq (x+y) \% 3 , the color of (i,j) and the color of (x,y) are different. Here, X \% Y represents X modulo Y . We will repaint zero or more squares so that the grid will be a good grid. For a square, the wrongness when the color of the square is X before repainting and Y after repainting, is D_{X,Y} . Find the minimum possible sum of the wrongness of all the squares. Constraints 1 \leq N \leq 500 3 \leq C \leq 30 1 \leq D_{i,j} \leq 1000 (i \neq j),D_{i,j}=0 (i=j) 1 \leq c_{i,j} \leq C All values in input are integers. Input Input is given from Standard Input in the following format: N C D_{1,1} ... D_{1,C} : D_{C,1} ... D_{C,C} c_{1,1} ... c_{1,N} : c_{N,1} ... c_{N,N} Output If the minimum possible sum of the wrongness of all the squares is x , print x . Sample Input 1 2 3 0 1 1 1 0 1 1 4 0 1 2 3 3 Sample Output 1 3 Repaint (1,1) to Color 2 . The wrongness of (1,1) becomes D_{1,2}=1 . Repaint (1,2) to Color 3 . The wrongness of (1,2) becomes D_{2,3}=1 . Repaint (2,2) to Color 1 . The wrongness of (2,2) becomes D_{3,1}=1 . In this case, the sum of the wrongness of all the squares is 3 . Note that D_{i,j} \neq D_{j,i} is possible. Sample Input 2 4 3 0 12 71 81 0 53 14 92 0 1 1 2 1 2 1 1 2 2 2 1 3 1 1 2 2 Sample Output 2 428 | 39,219 |
Problem J: Ukunichia Query Problem $N$ 人ã®äººãå·Šããå³ãžäžåã«äžŠãã§ããã圌ãã®éã§ã¯æåå $S$ ãæµè¡ããŠããã å人ã¯ã以äžã®æ¡ä»¶ãæºãããšã 幞ã ã§ãããããã§ãªããšã 幞ã ã§ã¯ãªãã ä»ãŸã§ã« $|S|$ æå以äžã®æåãäŒããããŠããŠããã€çŽè¿ã® $|S|$ æåãå€ãé ããæ°ããé ã«äžŠã¹ããš $S$ ãšäžèŽãã 以äžã® $2$ çš®é¡ã®ã¯ãšãªãåèš $Q$ ååŠçããã ã¯ãšãª1 $1$ $l$ $r$ $c$ åºé $[l, r]$ ã«å«ãŸããäººã«æåå $c$ ãå·Šããäžæåãã€äŒããã ã¯ãšãª2 $2$ $l$ $r$ åºé $[l, r]$ ã«å«ãŸãã 幞ã ãªäººã®æ°ãæ±ããã ãã ããåºé $[l, r]$ ãšã¯ãå·Šãã $l$ çªç®ãã $r$ çªç®ãŸã§ã®äººã®ããšã衚ãã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã $S$ $N$ $Q$ $query_1$ $\vdots$ $query_Q$ $1$ è¡ç®ã«æµè¡ããŠããæåå $S$ ãäžããããã $2$ è¡ç®ã«äžŠãã§ããäººã®æ° $N$ ãšã¯ãšãªã®æ° $Q$ ã空çœåºåãã§äžããããã $3$ è¡ç®ããç¶ã $Q$ è¡ã«ã¯ãšãªã®æ
å ±ãäžããããã Constraints å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã $1 \leq |S| \leq 20 $ $1 \leq N \leq 10^5 $ $1 \leq Q \leq 10^5 $ $1 \leq l \leq r \leq N$ $1 \leq |c| \leq 10 $ $S, c$ ã¯è±å°æåãããªã åã¯ãšãªã¯ã¯ãšãª1ãã¯ãšãª2ã®ããããã§ãã ã¯ãšãª2ãå¿
ãäžã€ä»¥äžå«ãŸãã Output åã¯ãšãª2ã«ã€ããŠã 幞ã ãªäººã®æ°ã1è¡ã«åºåããã Sample Input 1 abab 5 5 2 2 4 1 1 5 abab 2 3 5 1 3 3 a 2 1 5 Sample Output 1 0 3 4 Sample Input 2 uku 1333 5 2 232 423 1 13 532 uku 2 322 567 1 3 33 ku 2 1 333 Sample Output 2 0 211 321 Sample Input 3 aabb 1879 20 2 69 1585 1 415 1680 aabb 1 756 1628 abbabbaa 1 849 1273 abba 2 418 1172 2 1063 1164 2 203 623 2 481 1209 1 107 110 ababaaaab 1 857 985 bbbbabbbaa 1 868 947 aaa 1 1619 1789 aabab 2 204 844 2 493 1422 2 821 1499 1 757 1817 abbabbb 2 232 911 1 653 797 aaabaaaab 2 701 1657 1 868 940 aaabbbaaa Sample Output 3 0 338 0 209 275 341 263 0 341 0 | 39,220 |
人çã²ãŒã 倪éåã¯ãããã¡ãå±ããã«äŒæŽ¥ãããŒç€Ÿè£œã®äººçã²ãŒã ãè²·ãã«è¡ããŸããã人çã²ãŒã ã¯ããã¹ç®ã®æžãããããŒããšã«ãŒã¬ããã䜿ã£ãŠéã³ãŸããããŒãã«ã¯å³ã®ããã«ã¹ã¿ãŒãå°ç¹ãšãŽãŒã«å°ç¹ãäžã€ãã€ããããããã¯ã²ãšã€ãªããã®ãã¹ç®ã§ã€ãªãã£ãŠããŸããæåã«ãã³ãã¯ã¹ã¿ãŒãå°ç¹ã®ãã¹ã«çœ®ãããã«ãŒã¬ãããåããŠåºãæ°ã«ãã£ãŠã³ããé²ããŸãããã¹ã«ãã£ãŠã¯ãããã«æ¢ãŸã£ããééãããããããšã§ãéãåŸãããã³ãã®äœçœ®ãå€ãããããã€ãã³ããã¹ããããŸããæçµçãªåæã¯ãã³ãããŽãŒã«å°ç¹ã«å°éããæç¹ã®ææéã®å€å¯¡ã§æ±ºãŸããŸãã ãã®äŒç€Ÿã®äººçã²ãŒã ã®é¢çœããšããã¯ãã«ãŒã¬ããã®åºãç®ã®å€§ããããŽãŒã«ãŸã§ã®ãã¹ã®æ°ãã€ãã³ããã¹ã®é
眮ãã²ãšã€ã²ãšã€ããã±ãŒãžããšã«ç°ãªããšããã§ãããããã¯ã±ãŒã¹ã«æžãããŠããããããèªãããšã§ç¢ºèªããããšãã§ããŸãããéãæãåŸããã人çã²ãŒã ãéžã³ãã倪éåã¯ãåŸããéã®æåŸ
å€ãäžçªå€§ãããã®ãè²·ãããã£ãŠããŸããããã§ããªãã¯ã倪éåã®ã²ãŒã éžã³ãæäŒãããšã«ããŸããã ã«ãŒã¬ããã¯ãååšã X çåã«åºåãããããããã« V 1 ã V 2 ã...ã V X ãšããå€ãèšå
¥ãããŠãããšããŸããããŒãã«ã¯ã0 çªã1 çªã...ã Y çªãšçªå·ããµããããã¹ç®ããããé çªã«ã€ãªãã£ãŠããŸãããã¹ç®ã®äžã«ã¯ãã€ãã³ããã¹ãšåŒã°ããç¹å¥ãªãã¹ã Z åãããããã«å°éãããšç¹å¥ãªåäœãè¡ããŸããã€ãã³ããã¹ã®ãã¹ç®ã®çªå·ã¯ N i ã§äžããããŸããã€ãã³ããã¹ã«ã¯ 1 ~ 3 ã®çš®é¡ ( E i ) ããããããããæ¬¡ã®åäœãè¡ãããŸãã çš®é¡ ( E i ) ç¹å¥åäœ å€ ( A i ) ã®ç¯å² 1 æå®ã®å€ A i ã ãå
ãžé²ã 1~10 2 æå®ã®å€ A i ã®éé¡ãåŸã 1~100 3 æå®ã®å€ A i ã®éé¡ãæ¯æã 1~100 æåã®ææé㯠0 åã§ã第 0 ãã¹ç®ããã¹ã¿ãŒããã第 Y ãã¹ç®ã«å°éãããšãŽãŒã«ãšãªããŸãããŽãŒã«ãè¶ããå ŽåããŽãŒã«ãšèŠãªããŸããã¹ã¿ãŒããšãŽãŒã«ã«ã€ãã³ãã¯ç¡ãã1 ãã¹ã«è€æ°ã®ã€ãã³ããéãªãããšã¯ãããŸãããã€ãã³ãã«ãã£ãŠé²ãã å
ã®ãã¹ã®ã€ãã³ãã¯ç¡èŠããŸããææéã 0 åããå°ãªããªãå Žå㯠0 åãšããŸãã äŸãã°ããã人çã²ãŒã ã§åŸããããéã®æåŸ
å€ã¯ä»¥äžã®ããã«èšç®ã§ããŸãã ãã®äŸã§ã¯ãã¹ã¿ãŒããã€ãã³ããã¹(100 åå
¥æ) ããŽãŒã«ã® 3 ã€ã®ãã¹ãšã1 ã 2 ãåºãã«ãŒã¬ãããããªã人çã²ãŒã ã衚ãããŠããŸãããŸãã1 åç®ã«ã«ãŒã¬ãããåããæã1 ãåºãã°ã€ãã³ããã¹ã«å°éããææé㯠100 åã«ãªããŸããäžæ¹ã2 ãåºãå Žåã¯ãŽãŒã«ã«å°éããææé㯠0 åã®ãŸãŸã§ãããããã¯ã©ã¡ãã 2 åã® 1 ã®ç¢ºçã§èµ·ãããŸãã ããã«ã1 åç®ã§ã€ãã³ããã¹ã«å°éããå Žå㯠2 åç®ã®ã«ãŒã¬ãããåããŸãããã©ã®å€ãåºãŠããŽãŒã«ã«å°éããææéã¯ã©ã®å Žåã 100 åã§ãã ãã®ããã«ãå
šéšã§ 3 éãã®ãŽãŒã«ã®ä»æ¹ããããŸãããŽãŒã«ããæç¹ã®ææéã«çç®ãããšã0 åã«ãªãå Žåã 1 éãã§ãã®ç¢ºç㯠2 åã® 1ã100 åã«ãªãå Žåã 2 éãã§ãã®ç¢ºçã 4 åã® 1 ã§ãããã®å ŽåããŽãŒã«ã§ã®ææéã®æåŸ
å€ã¯ããŽãŒã«ã®ä»æ¹ããšã® (ææé à ãã®ç¢ºç) ãè¶³ããå€ã§ããããã®äººçã²ãŒã ã®æåŸ
å€ã¯ 50 åã«ãªããŸãã ã«ãŒã¬ããã®æ
å ±ãšããŒãã®æ
å ±ãå
¥åãšãããŽãŒã«æã®ææéã®æåŸ
å€ãåºåããããã°ã©ã ãäœæããŠãã ããã Input è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã¿ã£ã€ã®è¡ã§ç€ºãããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã X Y Z V 1 V 2 ... V X N 1 E 1 A 1 N 2 E 2 A 2 : N Z E Z A Z X (1 †X †4)ã V i (1 †V i †10)ã Y (1 †Y †50)ã N i (1 †N i †Y -1)ã Z (0 †Z †Y -1)ã E i (1 †E i †3)ã A i (1 †A i †100) ã¯æŽæ°ã§äžããããŸãã ããŒã¿ã»ããã®æ°ã¯ 100 ãè¶
ããŸããã Output å
¥åããŒã¿ã»ããããšã«ãæçµçãªææéã®æåŸ
å€ãïŒè¡ã«åºåããŸãããªããææéã®æåŸ
å€ã¯å°æ°ç¹ä»¥äžåãæšãŠã®æŽæ°ã§åºåããŠãã ããã Sample Input 1 2 0 1 1 2 1 1 1 2 100 1 2 1 2 1 2 100 2 2 1 1 2 1 2 100 4 5 3 1 2 3 4 1 1 2 2 2 100 4 3 60 0 0 0 Output for the Sample Input 0 100 0 50 20 | 39,221 |
Problem D: The Great Summer Contest çŸåšã人ã
ã®å𝿥œã¯ããã°ã©ãã³ã°ã³ã³ãã¹ãã«éãããŠããã圌女ãæå±ããŠãããšããäžåŠæ ¡ã®å𝿥œéšã®æŽ»åå
容ã¯ãããã°ã©ãã³ã°ã³ã³ãã¹ããäŒç»ãéå¶ããããšã ã圌女ã®ä»äºã¯åé¡ãäœæããããšã§ã¯ãªããå€ãã®äººããåé¡ãåãã審å€å£ãçµç¹ãããŸãã³ã³ãã¹ãã®å®£äŒãè¡ããããã°è£æ¹ã®ãä»äºã ãã«ãªã¹ãäœé¡è
ãèåãªã¢ã«ãŽãªãºããŒãšéãããããã£ãä»äºããã人ã«å
ãåœããããšã¯ã»ãšãã©ãªããååšæã¯ãªãããã©ãæ¬ ããããšã®ã§ããªããã®ä»äºã«ã圌女ã¯èªããæã£ãŠåãçµãã§ããã 嚯楜éšã¯åžžã«åé¡ãåéããŠãããããããã®åé¡ã¯ä»¥äžã® 6 çš®é¡ã«åé¡ãããã Math Greedy Geometry DP Graph Other 幞ãã«ãå€ãã®åé¡ãéãŸã£ãã®ã§ã圌女ã¯ããããã³ã³ãã¹ããéãããšèãããã³ã³ãã¹ã㯠3 åã®åé¡ãããªããã圌女ã¯ã³ã³ãã¹ããããæè²çã«ãªãããã«ãšã以äžã® 4 çš®é¡ã®ã³ã³ãã¹ããéãããšã«æ±ºããã æ°åŠã²ãŒã³ã³ãã¹ã: Math ã®åé¡ãš DP ã®åé¡åãããŠ3åã®åé¡ã»ãã ã¢ã«ãŽãªãºã ã²ãŒã³ã³ãã¹ã: Greedy ã®åé¡ãš Graph ã®åé¡åãããŠ3åã®åé¡ã»ãã å®è£
ã²ãŒã³ã³ãã¹ã: Geometry ã®åé¡ãš Other ã®åé¡åãããŠ3åã®åé¡ã»ãã ãã©ã³ã¹ã®è¯ãã³ã³ãã¹ã: Math ãŸã㯠DP ãã 1 åãGreedy ãŸã㯠Graph ãã 1 åãGeometry ãŸã㯠Other ãã 1 åãåãããŠ3åã®åé¡ã»ãã ãã¡ãããããã³ã³ãã¹ãã«åºé¡ããåé¡ã¯ä»ã®ã³ã³ãã¹ãã«åºé¡ããããšã¯ã§ããªããåœŒå¥³ã®æã¿ã¯ãã§ããã ãå€ãã®ã³ã³ãã¹ããéãããšã ã6 çš®é¡ã®åé¡ã®ã¹ããã¯æ°ã¯åãã£ãŠããããããŠãæå€§äœåã³ã³ãã¹ããéããã ãããã圌女ã«ãšã£ãŠããã¯é£ããåé¡ã ããã«ãªã¹ãã¢ã«ãŽãªãºããŒã§ããããªããªã解決ã§ããã¯ãã ã Input å
¥åã¯è€æ°ã®ã±ãŒã¹ãããªãã åã±ãŒã¹ã¯ä»¥äžã®ãã©ãŒãããã§äžããããã n Math n Greedy n Geometry n DP n Graph n Other åå
¥åã®å€ã¯ããããã®çš®é¡ã®åé¡ã®ã¹ããã¯ã®æ°ã衚ãã å
¥åã®çµãã㯠0 0 0 0 0 0 ãããªãè¡ã«ãã£ãŠäžããããã åå€ã¯ä»¥äžã®æ¡ä»¶ãæºããã n Math + n Greedy + n Geometry + n DP + n Graph + n Other †100,000,000 ãŸããã¹ãã±ãŒã¹ã®æ°ã¯20,000åãè¶
ããªãã Output éå¬å¯èœãªã³ã³ãã¹ãã®æå€§æ°ã1è¡ã«åºåããã Sample input 1 1 1 1 1 1 1 1 1 0 0 0 1 0 0 0 1 1 3 0 0 3 0 0 3 1 0 1 3 1 1 2 0 2 0 1 0 0 1 1 0 3 1 0 0 1 1 0 0 0 0 0 0 0 Sample output 2 1 1 2 3 1 1 0 The University of Aizu Programming Contest 2011 Summer åæ¡: Tomoya Sakai å顿: Takashi Tayama | 39,222 |
DïŒ çŽ å æ°åè§£ã®å€æ§æ§ (The Diversity of Prime Factorization) Problem Ebi-chan has the FACTORIZATION MACHINE, which can factorize natural numbers M (greater than 1) in O( $\log$ M) time! But unfortunately, the machine could display only digits and whitespaces. In general, we consider the factorization of M as p_1^{e_1} \times p_2^{e_2} \times ... \times p_K^{e_K} where (1) i < j implies p_i < p_j and (2) p_i is prime. Now, she gives M to the machine, and the machine displays according to the following rules in ascending order with respect to i : If e_i = 1 , then displays p_i , otherwise, displays p_i e_i . For example, if she gives either 22 or 2048 , then 2 11 is displayed. If either 24 or 54 , then 2 3 3 . Okay, Ebi-chan has written down the output of the machine, but she notices that she has forgotten to write down the input! Now, your task is to count how many natural numbers result in a noted output. Note that Ebi-chan has mistaken writing and no input could result in the output. The answer could be too large, so, you must output it modulo 10^9+7 (prime number). Input N q_1 q_2 $\cdots$ q_N In the first line, the number of the output of the machine is given. In the second line, the output of the machine is given. Constraints 1 \leq N \leq 10^5 2 \leq q_i \leq 10^6 ( 1 \leq i \leq N ) Output Print the number of the natural numbers that result in the given output of the machine. Sample Input 1 3 2 3 3 Sample Output for Input 1 2 24 = 2^3 \times 3 and 54 = 2 \times 3^3 satisfy the condition. Sample Input 2 3 2 3 4 Sample Output 2 for Input 2 1 Only 162 = 2 \times 3^4 satisfies the condition. Note that 4 is not prime. Sample Input 3 3 3 5 2 Sample Output for Input 3 1 Since 2 < 3 < 5 , only 75 = 3 \times 5^2 satisfies the condition. Sample Input 4 1 4 Sample Output for Input 4 0 Ebi-chan should have written down it more carefully. | 39,223 |
Road Construction The Zuia Kingdom has finally emerged through annexation of $N$ cities, which are identified by index from $1$ to $N$. You are appointed the Minister of Transport of the newly born kingdom to construct the inter-city road network. To simplify the conceptual design planning, you opted to consider each city as a point on the map, so that the $i$-th city can be represented by an coordinate ($x_i, y_i$). The cost of road construction connecting $u$-th and $v$-th cities is equal to the distance $|x_u - x_v|$ or $|y_u - y_v|$, whichever the larger. The notation $|A|$ represents the absolute value of $A$. The object here is to explore the minimum cost required to construct the road network in such a way that people can move between different cities along one or more roads. Make a program to calculate the minimum of total road construction cost from the number of cities and their coordinates. Input The input is given in the following format. $N$ $x_1$ $y_1$ $x_2$ $y_2$ ... $x_N$ $y_N$ The first line provides the number of cities $N$ ($2 \leq N \leq 10^5$). Each of the subsequent $N$ lines provides the coordinate of the $i$-th city $x_i, y_i$ ($0 \leq x_i, y_i \leq 10^9$) as integers. Note that none of these coordinates coincides if: $i \ne j$, then $x_i \ne x_j$ or $y_i \ne y_j$. Output Output the minimum road construction cost. Sample Input 1 3 1 2 3 4 10 1 Sample Output 1 9 The road connecting city 1 and 2 can be constructed at the cost of 2, and that connecting city 2 and 3 at the cost of 7. Therefore, the total cost becomes 9, which is the minimum. Sample Input 2 3 1 2 3 4 3 2 Sample Output 2 4 Sample Input 3 5 7 41 10 0 99 27 71 87 14 25 Sample Output 3 163 | 39,224 |
Rabbit Party A rabbit Taro decided to hold a party and invite some friends as guests. He has n rabbit friends, and m pairs of rabbits are also friends with each other. Friendliness of each pair is expressed with a positive integer. If two rabbits are not friends, their friendliness is assumed to be 0. When a rabbit is invited to the party, his satisfaction score is defined as the minimal friendliness with any other guests. The satisfaction of the party itself is defined as the sum of satisfaction score for all the guests. To maximize satisfaction scores for the party, who should Taro invite? Write a program to calculate the maximal possible satisfaction score for the party. Input The first line of the input contains two integers, n and m ( 1 \leq n \leq 100 , 0 \leq m \leq 100 ). The rabbits are numbered from 1 to n . Each of the following m lines has three integers, u , v and f . u and v ( 1 \leq u, v \leq n , u \neq v , 1 \leq f \leq 1,000,000 ) stands for the rabbits' number, and f stands for their friendliness. You may assume that the friendliness of a pair of rabbits will be given at most once. Output Output the maximal possible satisfaction score of the party in a line. Sample Input 1 3 3 1 2 3 2 3 1 3 1 2 Output for the Sample Input 1 6 Sample Input 2 2 1 1 2 5 Output for the Sample Input 2 10 Sample Input 3 1 0 Output for the Sample Input 3 0 Sample Input 4 4 5 1 2 4 1 3 3 2 3 7 2 4 5 3 4 6 Output for the Sample Input 4 16 | 39,225 |
Problem B: Potatoes Problem ãã£ã¡ãå㯠N é¢ã®çãš M åã®èãææããŠãããåçã«ã¯ãããã1ãã N ãŸã§ã®çªå·ãä»ããããŠããããã£ã¡ãåã¯çã«èãæ€ãåç©«ããããšã§ãèã®æ°ãå¢ãããããšèããŠããã ãã£ã¡ãåã¯äžäººæ®ããã§ããã1人ã§ã¯ K é¢ãŸã§ã®çãã管çããããšãã§ããªãããŸããåçã®åã®ç¶æ
ãé¢ç©ã¯æ§ã
ã§ãèã®åç©«æ°ãæ€ããããšã®ã§ããèã®æ°ãæ§ã
ã§ãããèãç i ã«æ€ããå Žåã1幎åŸã«ã¯ç i ã«æ€ããè1ã€ã«ã€ã a i åã®èãåç©«ããããšãã§ããããã ããç i ã«ã¯æå€§ã§ã b i åã®èããæ€ããããšãã§ããªãã ãã£ã¡ãåã K é¢ä»¥å
ã®çã« M å以å
ã®èãæ€ããæã1幎åŸã«ææããããšãã§ããèã®æ°ã®æå€§å€ãæ±ããŠã»ããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã N M K a 1 a 2 ... a N b 1 b 2 ... b N 1è¡ç®ã«3åã®æŽæ° N , M , K ã空çœåºåãã§äžããããã 2è¡ç®ã« N åã®æŽæ° a i ã空çœåºåãã§äžããããã 3è¡ç®ã« N åã®æŽæ° b i ã空çœåºåãã§äžããããã Constraints 1 †N †15 1 †M †10 4 1 †K †min( N ,3) 1 †a i †10 3 1 †b i †10 4 Output èã®æ°ã®æå€§å€ã1è¡ã§åºåããã Sample Input 1 5 100 3 2 3 4 5 6 50 40 20 10 5 Sample Output 1 280 ç1ã«40åãç2ã«40åãç3ã«20忀ããããšã§åç©«åŸã«280åã®èãææããããšãã§ããã Sample Input 2 5 100 3 2 3 4 5 100 50 40 20 10 1 Sample Output 2 339 ç2ã«40åãç3ã«20åãç5ã«1忀ããããšã§300åã®èãåç©«ããããšãã§ããæ€ããªãã£ãèãšåãããŠçãã¯339ã«ãªãã | 39,226 |
Problem I: Strange Currency System The currency system in the Kingdom of Yoax-Musty is strange and fairly inefficient. Like other countries, the kingdom has its own currencty unit denoted by K $ (kingdom dollar). However, the Ministry of Finance issues bills for every value between 1 K $ and (2 31 - 1) K $ worth. On the other hand, this system often enables people to make many different values just with a small number of bills. For example, if you have four bills of 1 K $ , 2 K $ , 4 K $ , and 8 K $ worth respectively, you can make any values from 1 K #36; to 15 K $ . In this problem, you are requested to write a program that finds the minimum value that cannot be made with a given set (multiset in a mathematical sense) of bills. For the case with the four bills (1 K $ , 2 K $ , 4 K $ , and 8 K $ ), since you can make any values up to 15 K $ , your program should report 16 K $ . Input The input consists of two lines. The first line contains an integer N (1 †N †10000), the number of bills. The second line contains N integers, each of which represents the value of a bill in K $ . There may be multiple bills of the same value. Output Print the minimum value unable to be made on a line. The value should be given in K $ and without any currency sign or name. Sample Input and Output Input #1 4 1 2 4 8 Output #1 16 Input #2 5 1 1 3 11 2 Output #2 8 | 39,227 |
Pipeline Plans There are twelve types of tiles in Fig. 1. You were asked to fill a table with R à C cells with these tiles. R is the number of rows and C is the number of columns. How many arrangements in the table meet the following constraints? Each cell has one tile. the center of the upper left cell (1,1) and the center of the lower right cell ( C , R ) are connected by some roads. Fig. 1: the types of tiles Input The first line contains two integers R and C (2 †R à C †15) . You can safely assume at least one of R and C is greater than 1. The second line contains twelve integers, t 1 , t 2 , ..., t 12 (0 †t 1 + .... + t 12 †15) . t i represents the number of the i -th tiles you have. Output Output the number of arrangments in a line. Sample Input 1 3 3 4 2 2 0 0 0 0 0 0 0 0 1 Output for the Sample Input 1 2 Sample Input 2 3 3 0 1 1 0 0 0 0 0 0 0 0 7 Output for the Sample Input 2 66 Sample Input 3 3 3 0 0 0 0 0 0 0 0 0 0 0 10 Output for the Sample Input 3 1 Sample Input 4 2 4 0 0 1 1 1 2 0 1 0 0 1 1 Output for the Sample Input 4 2012 Sample Input 5 5 2 0 1 1 1 0 1 2 1 2 0 0 1 Output for the Sample Input 5 8512 | 39,228 |
Problem F: Gather the Maps! ã¯ããæãå
«å°Ÿæ°ãæ®ãããšãããäŒèª¬ã®ç§å®ãå
«çåã®ã©ããã«ç ã£ãŠãããšããã ãã®åšåŠã瀺ããšãããå®ã®å°å³ã¯ãããã€ãã®æçã«åå²ãããç¶æ
ã§ãå
«å°Ÿæ°ã® n 人ã®åå«éã«ãã£ãŠåãç¶ãããŠããã ä»ãå
«å°Ÿæ°ã®åå«éã¯ååããŠãã®ç§å®ãæã«å
¥ããããšããŠããã ãšããããç§å®ã®åšåŠãæã瀺ãå®ã®å°å³ã®äžéšåã ãã§ã¯ç§å®ãèŠã€ããããšãã§ããªãã ããã§ãå
«å°Ÿæ°ã®åå«éã¯å
šå¡ã§éãŸã£ãŠå°å³ã 1 ã¶æã«éããããšããã ãšããããããå®è¡ã«ç§»ãããšããŠããªããªãäºå®ãåããã«éãŸãããšãã§ããªãã ããããã®ç§å®ã«é¢ããæ
å ±ã¯ãäžæã«ãããŠç§å¯è£ã«äŒããããŠãã貎éãªæ
å ±ã§ããã æŒæŽ©ã®å±éºæ§ãèæ
®ãããšãå
Œ
±ã®éä¿¡ææ®µãçšããŠå°å³ããããšãããããšãªã©åé¡å€ã§ããã ããã§ãåå«å士ãçŽæ¥äŒã£ãŠå°å³ãææž¡ããšããããšãç¹°ãè¿ãããšã§ããã 1 人ã®åå«ã®ãšããã«å°å³ãéããããšã«ããã ãªãã1 人ã 1 æ¥ã«äŒãã人æ°ã«å¶éã¯ãªãããäºãã«ã¹ã±ãžã¥ãŒã«ã空ããŠããããšãå¿
èŠã§ããã ããªãã®ä»äºã¯ãããããã®åå«ã«å¯Ÿããã¹ã±ãžã¥ãŒã«ã®ç©ºããŠããæ¥ã®ãªã¹ããããå°å³ãéããã«ã¯æäœã§äœæ¥å¿
èŠããæ±ããããã°ã©ã ãæžãããšã§ããã ã¡ãªã¿ã«ãå
«å°Ÿæ°äžæã®çµæã¯éåžžã«åºãã æçµçã«å°å³å
šäœãæã«ããåå«ããä»ã®åå«ãè£åã£ãŠç§å®ãæã¡éãããã°ãäžæããå¶è£ãåããããšã«ãªãããã®å¶è£ã¯ããããŠæããããã®ã§ãããããå®éã«ãã®åå«ãç§å®ãæã¡éãããããšã¯äºå®äžäžå¯èœã§ããã Input å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãã ããããã®ããŒã¿ã»ããã¯è€æ°ã®è¡ãããªãã ãã®æåã®è¡ã«ã¯ãå°å³ã®æçãæã£ãè
ã®äººæ°ãè¡šãæŽæ° n (1 < n <= 50) ãèšè¿°ãããŠããã ç¶ã n è¡ã«ã¯ãããããã®åå«ã®ã¹ã±ãžã¥ãŒã«ãæžãããŠããã i è¡ç®ã¯ i 人ç®ã®åå«ã®ã¹ã±ãžã¥ãŒã«ã衚ããŠãããããã€ãã®æŽæ°ã 1 æåã®ã¹ããŒã¹ãåºåããšããŠæžãããŠããã æåã®æŽæ° f i (0 <= f i <= 30) ã¯ããã®åå«ã®ã¹ã±ãžã¥ãŒã«ã空ããŠããæ¥ã®æ¥æ°ãè¡šãæŽæ°ã§ããã ç¶ã f i åã®æŽæ°ã¯ãã¹ã±ãžã¥ãŒã«ã空ããŠããæ¥ä»ã衚ãã ãããã®æ¥ä»ã¯äºãã«ç°ãªããå
šãŠ 1 ä»¥äž 30 以äžã§ããã å
¥åã®æåŸã« 0 ã®ã¿ãå«ãã 1 è¡ãããã Output åããŒã¿ã»ããã«å¯ŸããŠã1 ã€ã®æŽæ°ã 1 è¡ã«åºåããã ããã30 æ¥ä»¥å
ã«å°å³ãéããããšãã§ããå Žåã¯ãå°å³ãéããã®ã«æäœéå¿
èŠãšãªãæ¥æ°ããéããããšãã§ããªãå Žå㯠-1 ãåºåããã è¿œèš : äžèšã®ãå°å³ãéããã®ã«æäœéå¿
èŠãšãªãæ¥æ°ã㯠1 æ¥ãèµ·ç¹ãšããŠæãæ©ãå
šãŠã®å°å³ãéãŸãæ¥ä»ãæå³ããïŒ Sample Input 4 1 1 2 2 3 2 1 2 3 3 4 5 0 Output for the Sample Input 3 | 39,229 |
Cake Party Iâm planning to have a party on my birthday. Many of my friends will come to the party. Some of them will come with one or more pieces of cakes, but it is not certain if the number of the cakes is a multiple of the number of people coming. I wish to enjoy the cakes equally among the partiers. So, I decided to apply the following rules. First, all the party attendants are given the same number of cakes. If some remainder occurs, a piece goes on a priority basis to the party host (thatâs me!). How many pieces of cake can I enjoy? Given the number of my friends and cake information, make a program to calculate how many pieces of cake I can enjoy. Note that I am not counted in the number of my friends. Input The input is given in the following format. $N$ $C$ $p_1$ $p_2$ ... $p_C$ The first line provides the number of my friends $N$ ($1 \leq N \leq 100$) and the number of those among them who brought one or more pieces of cake with them $C$ ($1 \leq C \leq N$). The second line provides an array of integers $p_i$ ($1 \leq p_i \leq100$), each of which shows the number of cakes of the $i$-th friend of mine who was willing to come up with one or more pieces of cake. Output Output the number of cakes I can enjoy. Sample Input 1 5 4 5 5 6 5 Sample Output 1 4 Sample Input 2 7 5 8 8 8 8 8 Sample Output 2 5 Sample Input 3 100 3 3 3 3 Sample Output 3 1 | 39,230 |
Problem F Secrets in Shadows Long long ago, there were several identical columns (or cylinders) built vertically in a big open space near Yokohama (Fig. F-1). In the daytime, the shadows of the columns were moving on the ground as the sun moves in the sky. Each column was very tall so that its shadow was very long. The top view of the shadows is shown in Fig. F-2. The directions of the sun that minimizes and maximizes the widths of the shadows of the columns were said to give the important keys to the secrets of ancient treasures. Fig. F-1: Columns (or cylinders) Gig. F-2: Top view of the columns (Fig. F-1) and their shadows The width of the shadow of each column is the same as the diameter of the base disk. But the width of the whole shadow (the union of the shadows of all the columns) alters according to the direction of the sun since the shadows of some columns may overlap those of other columns. Fig. F-3 shows the direction of the sun that minimizes the width of the whole shadow for the arrangement of columns in Fig. F-2. Fig. F-3: The direction of the sun for the minimal width of the whole shadow Fig. F-4 shows the direction of the sun that maximizes the width of the whole shadow. When the whole shadow is separated into several parts (two parts in this case), the width of the whole shadow is defined as the sum of the widths of the parts. Fig. F-4: The direction of the sun for the maximal width of the whole shadow A direction of the sun is specified by an angle Ξ defined in Fig. F-5. For example, the east is indicated by Ξ = 0, the south by Ξ = Ï /2, and the west by Ξ = Ï . You may assume that the sun rises in the east ( Ξ = 0) and sets in the west ( Ξ = Ï ). Your job is to write a program that, given an arrangement of columns, computes two directions Ξ min and Ξ max of the sun that give the minimal width and the maximal width of the whole shadow, respectively. The position of the center of the base disk of each column is specified by its ( x , y ) coordinates. The x -axis and y -axis are parallel to the line between the east and the west and that between the north and the south, respectively. Their positive directions indicate the east and the north, respectively. You can assume that the big open space is a plane surface. Fig. F-5: The definition of the angle of the direction of the sun There may be more than one Ξ min or Ξ max for some arrangements in general, but here, you may assume that we only consider the arrangements that have unique Ξ min and Ξ max in the range 0 †Ξ min < Ï , 0 †Ξ max < Ï . Input The input consists of multiple datasets, followed by the last line containing a single zero. Each dataset is formatted as follows. n x 1 y 1 x 2 y 2 ... x n y n n is the number of the columns in the big open space. It is a positive integer no more than 100. x k and y k are the values of x -coordinate and y -coordinate of the center of the base disk of the k -th column ( k =1, ..., n ). They are positive integers no more than 30. They are separated by a space. Note that the radius of the base disk of each column is one unit (the diameter is two units). You may assume that some columns may touch each other but no columns overlap others. For example, a dataset 3 1 1 3 1 4 3 corresponds to the arrangement of three columns depicted in Fig. F-6. Two of them touch each other. Fig. F-6: An arrangement of three columns Output For each dataset in the input, two lines should be output as specified below. The output lines should not contain extra characters such as spaces. In the first line, the angle Ξ min , the direction of the sun giving the minimal width, should be printed. In the second line, the other angle Ξ max , the direction of the sun giving the maximal width, should be printed. Each angle should be contained in the interval between 0 and Ï (abbreviated to [0, Ï ]) and should not have an error greater than ε =0.0000000001 (=10 -10 ). When the correct angle Ξ is in [0, ε ], approximate values in [0, Ξ + ε ] or in [ Ï + Ξ - ε , Ï ] are accepted. When the correct angle Ξ is in [ Ï - ε , Ï ], approximate values in [0, Ξ + ε - Ï ] or in [ Ξ - ε , Ï ] are accepted. You may output any number of digits after the decimal point, provided that the above accuracy condition is satisfied. Sample Input 3 1 1 3 1 4 3 4 1 1 2 3 3 8 1 9 8 1 1 3 1 6 1 1 3 5 3 1 7 3 5 5 5 8 20 7 1 27 30 14 9 6 17 13 4 2 17 7 8 9 0 Output for the Sample Input 2.553590050042226 0.982793723247329 1.570796326794896 2.819842099193151 1.325817663668032 2.094395102393196 2.777613697080149 0.588002603547568 | 39,231 |
Score : 500 points Problem Statement There are N boxes arranged in a circle. The i -th box contains A_i stones. Determine whether it is possible to remove all the stones from the boxes by repeatedly performing the following operation: Select one box. Let the box be the i -th box. Then, for each j from 1 through N , remove exactly j stones from the (i+j) -th box. Here, the (N+k) -th box is identified with the k -th box. Note that the operation cannot be performed if there is a box that does not contain enough number of stones to be removed. Constraints 1 ⊠N ⊠10^5 1 ⊠A_i ⊠10^9 Input The input is given from Standard Input in the following format: N A_1 A_2 ⊠A_N Output If it is possible to remove all the stones from the boxes, print YES . Otherwise, print NO . Sample Input 1 5 4 5 1 2 3 Sample Output 1 YES All the stones can be removed in one operation by selecting the second box. Sample Input 2 5 6 9 12 10 8 Sample Output 2 YES Sample Input 3 4 1 2 3 1 Sample Output 3 NO | 39,232 |
Donut Decoration Donut maker's morning is early. Mr. D, who is also called Mr. Donuts, is an awesome donut maker. Also today, he goes to his kitchen and prepares to make donuts before sunrise. In a twinkling, Mr. D finishes frying $N$ donuts with a practiced hand. But these donuts as they are must not be displayed in a showcase. Filling cream, dipping in chocolate, topping somehow cute, colorful things, etc., several decoration tasks are needed. There are $K$ tasks numbered 1 through $K$, and each of them must be done exactly once in the order $1, 2, ..., K$ to finish the donuts as items on sale. Instantly, Mr. D arranges the $N$ donuts in a row. He seems to intend to accomplish each decoration tasks sequentially at once. However, what in the world is he doing? Mr. D, who stayed up late at yesterday night, decorates only a part of the donuts in a consecutive interval for each task. It's clearly a mistake! Not only that, he does some tasks zero or several times, and the order of tasks is also disordered. The donuts which are not decorated by correct process cannot be provided as items on sale, so he should trash them. Fortunately, there are data recording a sequence of tasks he did. The data contain the following information: for each task, the consecutive interval $[l, r]$ of the decorated donuts and the ID $x$ of the task. Please write a program enumerating the number of the donuts which can be displayed in a showcase as items on sale for given recorded data. Input The input consists of a single test case. The test case is formatted as follows. $N$ $K$ $T$ $l_1$ $r_1$ $x_1$ ... $l_T$ $r_T$ $x_T$ The first line contains two integers $N$ and $K$, where $N$ ($1 \leq N \leq 200,000$) is the number of the donuts fried by Mr. D, and $K$ ($1 \leq K \leq 200,000$) is the number of decoration tasks should be applied to the donuts. The second line contains a single integer $T$ ($1 \leq T \leq 200,000$), which means the number of information about tasks Mr. D did. Each of next $T$ lines contains three integers $l_i$, $r_i$, and $x_i$ representing the $i$-th task Mr. D did: the $i$-th task was applied to the interval $[l_i, r_i]$ ($1 \leq l_i \leq r_i \leq N$) of the donuts inclusive, and has ID $x_i$ ($1 \leq x_i \leq K$). Output Output the number of the donuts that can be provided as items on sale. Sample Input 1 3 2 3 1 2 1 2 3 2 3 3 1 Output for the Sample Input 1 1 Sample Input 2 5 3 6 2 3 1 1 3 2 4 5 1 2 4 3 3 5 2 5 5 3 Output for the Sample Input 2 2 Sample Input 3 10 1 2 2 9 1 5 7 1 Output for the Sample Input 3 5 | 39,233 |
Score: 400 points Problem Statement Amidakuji is a traditional method of lottery in Japan. To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 [cm], and the endpoints of the horizontal lines must be at 1, 2, 3, ..., or H [cm] from the top of a vertical line. A valid amidakuji is an amidakuji that satisfies the following conditions: No two horizontal lines share an endpoint. The two endpoints of each horizontal lines must be at the same height. A horizontal line must connect adjacent vertical lines. Find the number of the valid amidakuji that satisfy the following condition, modulo 1\ 000\ 000\ 007 : if we trace the path from the top of the leftmost vertical line to the bottom, always following horizontal lines when we encounter them, we reach the bottom of the K -th vertical line from the left. For example, in the following amidakuji, we will reach the bottom of the fourth vertical line from the left. Constraints H is an integer between 1 and 100 (inclusive). W is an integer between 1 and 8 (inclusive). K is an integer between 1 and W (inclusive). Input Input is given from Standard Input in the following format: H W K Output Print the number of the amidakuji that satisfy the condition, modulo 1\ 000\ 000\ 007 . Sample Input 1 1 3 2 Sample Output 1 1 Only the following one amidakuji satisfies the condition: Sample Input 2 1 3 1 Sample Output 2 2 Only the following two amidakuji satisfy the condition: Sample Input 3 2 3 3 Sample Output 3 1 Only the following one amidakuji satisfies the condition: Sample Input 4 2 3 1 Sample Output 4 5 Only the following five amidakuji satisfy the condition: Sample Input 5 7 1 1 Sample Output 5 1 As there is only one vertical line, we cannot draw any horizontal lines. Thus, there is only one amidakuji that satisfies the condition: the amidakuji with no horizontal lines. Sample Input 6 15 8 5 Sample Output 6 437760187 Be sure to print the answer modulo 1\ 000\ 000\ 007 . | 39,234 |
Score : 400 points Problem Statement Given is a string S . Each character in S is either a digit ( 0 , ..., 9 ) or ? . Among the integers obtained by replacing each occurrence of ? with a digit, how many have a remainder of 5 when divided by 13 ? An integer may begin with 0 . Since the answer can be enormous, print the count modulo 10^9+7 . Constraints S is a string consisting of digits ( 0 , ..., 9 ) and ? . 1 \leq |S| \leq 10^5 Input Input is given from Standard Input in the following format: S Output Print the number of integers satisfying the condition, modulo 10^9+7 . Sample Input 1 ??2??5 Sample Output 1 768 For example, 482305, 002865, and 972665 satisfy the condition. Sample Input 2 ?44 Sample Output 2 1 Only 044 satisfies the condition. Sample Input 3 7?4 Sample Output 3 0 We may not be able to produce an integer satisfying the condition. Sample Input 4 ?6?42???8??2??06243????9??3???7258??5??7???????774????4?1??17???9?5?70???76??? Sample Output 4 153716888 | 39,236 |
Score : 200 points Problem Statement We will call a string that can be obtained by concatenating two equal strings an even string. For example, xyzxyz and aaaaaa are even, while ababab and xyzxy are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S . It is guaranteed that such a non-empty string exists for a given input. Constraints 2 \leq |S| \leq 200 S is an even string consisting of lowercase English letters. There exists a non-empty even string that can be obtained by deleting one or more characters from the end of S . Input Input is given from Standard Input in the following format: S Output Print the length of the longest even string that can be obtained. Sample Input 1 abaababaab Sample Output 1 6 abaababaab itself is even, but we need to delete at least one character. abaababaa is not even. abaababa is not even. abaabab is not even. abaaba is even. Thus, we should print its length, 6 . Sample Input 2 xxxx Sample Output 2 2 xxx is not even. xx is even. Sample Input 3 abcabcabcabc Sample Output 3 6 The longest even string that can be obtained is abcabc , whose length is 6 . Sample Input 4 akasakaakasakasakaakas Sample Output 4 14 The longest even string that can be obtained is akasakaakasaka , whose length is 14 . | 39,237 |
List For a dynamic list $L$ of integers, perform a sequence of the following operations. $L$ has a special element called END at the end of the list and an element of $L$ is indicated by a cursor. insert($x$): Insert $x$ before the element indicated by the cursor. After this operation, the cursor points the inserted element. move($d$): Move the cursor to the end by $d$, if $d$ is positive. Move the cursor to the front by $d$, if $d$ is negative. erase(): Delete the element indicated by the cursor. After this operation, the cursor points the element next to the deleted element. In case there is no such element, the cursor should point END. In the initial state, $L$ is empty and the cursor points END. Input The input is given in the following format. $q$ $query_1$ $query_2$ : $query_q$ Each query $query_i$ is given by 0 $x$ or 1 $d$ or 2 where the first digits 0 , 1 and 2 represent insert, move and erase operations respectively. Output Print all elements of the list in order after performing given operations. Print an element in a line. Constraints $1 \leq q \leq 500,000$ The cursor indicates an element of $L$ or END during the operations Erase operation will not given when the cursor points END $-1,000,000,000 \leq x \leq 1,000,000,000$ Moving distance of the cursor ($\sum{|d|}$) does not exceed 1,000,000 $L$ is not empty after performing all operations Sample Input 1 5 0 1 0 2 0 3 1 1 2 Sample Output 1 3 1 | 39,238 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.