task stringlengths 0 154k | __index_level_0__ int64 0 39.2k |
|---|---|
Rank Checker æã¯2020 幎ãããœã³ã³ç²åå 2020 ã®äºéžçµæãä¿åããããŒã¿ããããŸãããã®ããŒã¿ã«ã¯ãåããŒã ã«æ¯ãããæŽççªå·ãšæ£è§£æ°ãä¿åãããŠããŸããããã§ã¯ãæ£è§£æ°ã§é äœã決å®ãããã®ãšããæ£è§£æ°ã®å€ãã»ãããé ã« 1 äœã2 äœ ... ãšé äœãã€ããŠããããšãšããŸãã äºéžçµæã®ããŒã¿ãšæŽççªå·ãããŒããŒãããå
¥åããŠããã®çªå·ã®ããŒã ã®é äœãåºåããããã°ã©ã ãäœæããŠãã ããã Input å
¥åããŒã¿ã¯ïŒã€ã®éšåãããªããŸããååã®éšåã¯ãäºéžçµæã®ããŒã¿ãåŸåã®éšåã¯é äœãç¥ãããããŒã çªå·ã®åãåããã§ããäºéžçµæã®ããŒã¿ã®åœ¢åŒã¯ä»¥äžã®éãã§ãã p 1 , s 1 p 2 , s 2 ... ... 0 , 0 p i (1 †p i †100 )ã s i (0 †s i †30) ã¯ãããã i ããŒã ç®ã®æŽççªå·ãšæ£è§£æ°ãè¡šãæŽæ°ã§ããæŽççªå·ãšæ£è§£æ°ããšãã« 0 ã®ãšããã®ããŒã¿ã®å
¥åãçµãããã®ãšããŸãã ç¶ããŠåŸåã®åãåãããè€æ°äžããããŸããåãåããã®åœ¢åŒã¯ä»¥äžã®éãã§ãã q 1 q 2 : ååãåããã¯ïŒè¡ã«æŽççªå· q i (1 †q i †30) ãäžããããŸãããããå
¥åã®æåŸãŸã§åŠçããŠäžãããåãåããã®æ°ã¯ 100 ãè¶
ããŸããã Output ååãåããã«ã€ããŠãããŒã ã®é äœãïŒè¡ã«åºåããŠäžããã Sample Input 1,20 2,20 3,30 4,10 5,10 6,20 0,0 1 2 4 5 Output for the Sample Input 2 2 3 3 Note å
¥åäŸã®ããŒã¿ã«ãããŠãããŒã ãæ£è§£æ°é ã«æŽåãããšïŒ 3,30 1,20 2,20 6,20 4,10 5,10 ãšãªããŸããããã§ã¯ãæ£è§£æ°ãåºã«é äœã決å®ããããã30åæ£è§£ããŒã ã1äœã20åæ£è§£ããŒã ã2äœã10åæ£è§£ããŒã ã3äœãšããŸãïŒäžäœã®ããŒã æ°ãèæ
®ãã10åæ£è§£ããŒã ã5äœãšããéåžžã®é äœä»ããšã¯ç°ãªãããšã«æ³šæããŠäžããïŒã | 36,605 |
Score : 400 points Problem Statement There are N cells arranged in a row, numbered 1, 2, \ldots, N from left to right. Tak lives in these cells and is currently on Cell 1 . He is trying to reach Cell N by using the procedure described below. You are given an integer K that is less than or equal to 10 , and K non-intersecting segments [L_1, R_1], [L_2, R_2], \ldots, [L_K, R_K] . Let S be the union of these K segments. Here, the segment [l, r] denotes the set consisting of all integers i that satisfy l \leq i \leq r . When you are on Cell i , pick an integer d from S and move to Cell i + d . You cannot move out of the cells. To help Tak, find the number of ways to go to Cell N , modulo 998244353 . Constraints 2 \leq N \leq 2 \times 10^5 1 \leq K \leq \min(N, 10) 1 \leq L_i \leq R_i \leq N [L_i, R_i] and [L_j, R_j] do not intersect ( i \neq j ) All values in input are integers. Input Input is given from Standard Input in the following format: N K L_1 R_1 L_2 R_2 : L_K R_K Output Print the number of ways for Tak to go from Cell 1 to Cell N , modulo 998244353 . Sample Input 1 5 2 1 1 3 4 Sample Output 1 4 The set S is the union of the segment [1, 1] and the segment [3, 4] , therefore S = \{ 1, 3, 4 \} holds. There are 4 possible ways to get to Cell 5 : 1 \to 2 \to 3 \to 4 \to 5 , 1 \to 2 \to 5 , 1 \to 4 \to 5 and 1 \to 5 . Sample Input 2 5 2 3 3 5 5 Sample Output 2 0 Because S = \{ 3, 5 \} holds, you cannot reach to Cell 5 . Print 0 . Sample Input 3 5 1 1 2 Sample Output 3 5 Sample Input 4 60 3 5 8 1 3 10 15 Sample Output 4 221823067 Note that you have to print the answer modulo 998244353 . | 36,606 |
æ¯èã®è±èµ°(Snake Escaping) JOI ç ç©¶æã§ã¯ 2^L å¹ã®æ¯èã飌ã£ãŠããïŒãããã 0, 1, ..., 2^L - 1 ã®çªå·ãä»ããããŠããïŒãã¹ãŠã®æ¯èã¯é ããé ã« L åã®éšåã«åãããŠããïŒããããã®éšåã¯éãŸãã¯èµ€ã§ããïŒæ¯è i ã«å¯ŸãïŒ i ã2é²è¡šèšã㊠i = $\sum_{k=1}^{L}$ c_k2^{L-k} (0 \leq c_k \leq 1) ãšããããšãïŒ c_k = 0 ã§ããã°ïŒæ¯è i ã®é ããæ°ã㊠k çªç®ã®éšåã¯éã§ããïŒ c_k = 1 ã§ããã°ïŒæ¯è i ã®é ããæ°ã㊠k çªç®ã®éšåã¯èµ€ã§ããïŒ åæ¯èã«ã¯æ¯æ§ãšåŒã°ãã0 以äž9 以äžã®æŽæ°å€ãå®ãŸã£ãŠããïŒ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ãããªãé·ã 2^L ã®æåå S ãäžãããïŒãã® i æåç®( 1 \leq i \leq 2^L ) ã¯æ¯è i - 1 ã®æ¯æ§ã衚ãïŒ æ¯èãã¡ã®åãã¯çŽ æ©ãã®ã§ïŒJOI ç ç©¶æããã¯ïŒããæ¯èãã¡ãè±èµ°ããŠããŸãïŒJOI ç ç©¶æã«ã¯è±èµ°ããæ¯èãç®æããåšèŸºäœæ°ããèŠæ
ãå¯ããããïŒ ããªãã«ã¯ïŒ Q æ¥éã«ãããèŠæ
ã®æ
å ±ãäžããããïŒ d æ¥ç®( 1 \leq d \leq Q ) ã«å¯ããããèŠæ
ã¯ïŒ 0 , 1 , ? ãããªãé·ã L ã®æåå T_d ãšããŠè¡šããïŒ T_d ã® j æåç®( 1 \leq j \leq L ) ã 0 ã®å Žåã¯ïŒ d æ¥ç®ã«è±èµ°ãããã¹ãŠã®æ¯èã®é ããæ°ã㊠j çªç®ã®éšåãéã§ããããšã衚ãïŒ T_d ã® j æåç®( 1 \leq j \leq L ) ã 1 ã®å Žåã¯ïŒ d æ¥ç®ã«è±èµ°ãããã¹ãŠã®æ¯èã®é ããæ°ã㊠j çªç®ã®éšåãèµ€ã§ããããšã衚ãïŒ T_d ã® j æåç®( 1 \leq j \leq L ) ã ? ã®å Žåã¯ïŒ d æ¥ç®ã«è±èµ°ããæ¯èã®é ããæ°ã㊠j çªç®ã®éšåã«ã€ããŠã¯ïŒåšèŸºäœæ°ããã¯æ
å ±ãäžããããªãã£ãããšã衚ãïŒ èŠæ
ã¯ãã¹ãŠæ£ç¢ºãªæ
å ±ã§ããïŒè±èµ°ããæ¯èã¯JOI ç ç©¶æã®è·å¡ããã®æ¥ã®ãã¡ã«æç²ããïŒæç²ãããæ¯èãïŒç¿æ¥ä»¥éã«åã³è±èµ°ããããšã¯ããåŸãïŒ æ¯èã®è±èµ°ã«ãããªã¹ã¯ãèŠç©ããããã«ïŒJOI ç ç©¶æã®K çäºé·ã¯è±èµ°ããå¯èœæ§ã®ããæ¯èã®æ¯æ§ã®åèšãç¥ãããïŒããªãã®ä»äºã¯ïŒ Q æ¥éã«ãããèŠæ
ã®æ
å ±ããïŒããããã®æ¥ããšã«ïŒãã®æ¥ã«è±èµ°ããå¯èœæ§ã®ããæ¯èã®æ¯æ§ã®åèšãæ±ããããã°ã©ã ãäœæããããšã§ããïŒ èª²é¡ æ¯èã®æ¯æ§ã衚ãæåå S ãšïŒ Q æ¥éã®èŠæ
ã®æ
å ±ãäžããããã®ã§ïŒããããã®æ¥ããšã«ïŒãã®æ¥ã«è±èµ°ããå¯èœæ§ã®ããæ¯èã®æ¯æ§ã®åèšãæ±ããããã°ã©ã ãäœæããïŒ ã¡ã¢ãªå¶éãå°ããããšã«æ³šæããããšïŒ å
¥å æšæºå
¥åãã以äžã®å
¥åãèªã¿èŸŒãïŒ 1 è¡ç®ã«ã¯ïŒæŽæ° L, Q ã空çœãåºåããšããŠæžãããŠããïŒãããã¯é ã«ïŒæ¯èã®éšåã®åæ°ãšïŒèŠæ
ã®å¯ããããæ¥æ°ã衚ãïŒ 2 è¡ç®ã«ã¯ïŒé·ã 2^L ã®æåå S ãæžãããŠããïŒãã®æååã¯æ¯èã®æ¯æ§ã衚ãïŒ ç¶ã Q è¡ã®ãã¡ã® d è¡ç®( 1 \leq d \leq Q ) ã«ã¯ïŒé·ã L ã®æåå T_d ãæžãããŠããïŒãã®æåå㯠d æ¥ç®ã®èŠæ
ã衚ãïŒ åºå æšæºåºåã« Q è¡ã§åºåããïŒ d è¡ç®ã«ã¯ïŒ d æ¥ç®ã«è±èµ°ããå¯èœæ§ã®ããæ¯èã®æ¯æ§ã®åèšãè¡šãæŽæ°ãåºåããïŒ å¶é ãã¹ãŠã®å
¥åããŒã¿ã¯ä»¥äžã®æ¡ä»¶ãæºããïŒ 1 \leq L \leq 20 ïŒ 1 \leq Q \leq 1 000 000 ïŒ S ã¯é·ã 2^L ã®æååã§ããïŒ æåå S 㯠0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ãããªãïŒ T_d ã¯é·ã L ã®æååã§ãã( 1 \leq d \leq Q )ïŒ æåå T_d 㯠0 , 1 , ? ãããªã( 1 \leq d \leq Q )ïŒ å
¥åºåäŸ å
¥åäŸ1 3 5 12345678 000 0?? 1?0 ?11 ??? åºåäŸ1 1 10 12 12 36 ãã®å
¥åäŸã§ã¯ïŒ L = 3 ã§ããïŒ3 ã€ã®éšåã«åãããæ¯èãïŒå
šéšã§ 2^3 = 8 å¹ããïŒèŠæ
ã¯5 æ¥éã«ããã£ãŠå¯ããããïŒ 1 æ¥ç®ã«è±èµ°ããå¯èœæ§ã®ããæ¯èã¯ïŒæ¯è0 ã®ã¿ã§ããïŒæ¯æ§ã®åèšã¯1 ã§ããïŒ 2 æ¥ç®ã«è±èµ°ããå¯èœæ§ã®ããæ¯èã¯ïŒæ¯è0, 1, 2, 3 ã§ããïŒæ¯æ§ã®åèšã¯10 ã§ããïŒ 3 æ¥ç®ã«è±èµ°ããå¯èœæ§ã®ããæ¯èã¯ïŒæ¯è4, 6 ã§ããïŒæ¯æ§ã®åèšã¯12 ã§ããïŒ 4 æ¥ç®ã«è±èµ°ããå¯èœæ§ã®ããæ¯èã¯ïŒæ¯è3, 7 ã§ããïŒæ¯æ§ã®åèšã¯12 ã§ããïŒ 5 æ¥ç®ã«è±èµ°ããå¯èœæ§ã®ããæ¯èã¯ïŒæ¯è0, 1, 2, 3, 4, 5, 6, 7 ã§ããïŒæ¯æ§ã®åèšã¯36 ã§ããïŒ å
¥åäŸ2 4 8 3141592653589793 0101 ?01? ??1? ?0?? 1?00 01?1 ??10 ???? åºåäŸ2 9 18 38 30 14 15 20 80 æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒäœ ã第17 åæ¥æ¬æ
å ±ãªãªã³ããã¯(JOI 2017/2018) æ¬éžã | 36,607 |
Problem I: Making Pairs Problem æ¬æ¥ãã€ãã«å®å
šæåŸ
å¶ã®é«çŽã¬ã¹ãã©ã³ããã€ã
ã¬ã¹ãã©ã³ãããªãŒãã³ãããæ°ããªäŒå¡ãæåŸ
ããæš©å©ãæã€ã®ã¯ãã®ã¬ã¹ãã©ã³ã®äŒå¡ã®ã¿ã§ãæåãäŒå¡ã¯äŒå¡çªå·0ã§ããã¬ã¹ãã©ã³ã®ãªãŒããŒã®ã¿ã§ããã ãã€ã
ã¬ã¹ãã©ã³ã¯ãã®é«çŽãæ
ããªãŒãã³åæ¥ãã$N$æ¥éããéãããªãããã®æéäžãæ¯æ¥äŒå¡ã®ãã¡èª°ãäžäººããèªåã®å人ãäžäººã ãæ°ãã«äŒå¡ãšããŠæåŸ
ããã$i$æ¥ç®ã«æåŸ
ãããäŒå¡ã«ã¯äŒå¡çªå·$i$ãå²ãåœãŠããããã®äŒå¡ã¯æåŸ
ãããæ¥ãå«ãããä»¥éæ¯æ¥æ¥åºããã ãã®ã¬ã¹ãã©ã³ã«ã¯äºäººçšããŒãã«ããååšããªãã®ã§ãäŒå¡ã®äººã
ã¯ã§ããã ããã¢ã§ããŒãã«ã䜿çšããŠé£äºããããé£äºã«ã¯ãªãŒããŒãåå ããã®ã§ãä»ã®äŒå¡ã¯ãªãŒããŒãšãã¢ãçµãããšãã§ãããããããäŒå¡ã®äººã
ã¯ç人èŠç¥ãã§ãããèªåãæåŸ
ããå人ããèªåãæåŸ
ããå人ãšãããã¢ãçµã¿ããããªããåäŒå¡ã¯ããå人ãšãã¢ãçµããªãã£ãå Žåãäžäººå¯ããé£äºãããã $N$æ¥éã®åæ¥ã«ã€ããŠãå人ã©ããã®ãã¢ã®æ°ãæå€§ãšãªãããã«ãã¢ãçµãã ãšããããã€ã®ãã¢ãã§ãããæ±ããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã $N$ $p_1$ $p_2$ ... $p_N$ 1è¡ç®ã«ã¬ã¹ãã©ã³ãéãããæ¥æ°$N$ãäžããããã ç¶ã$N$è¡ã«ãäŒå¡çªå·ã$i$ã®äŒå¡ãæåŸ
ããäŒå¡ã®äŒå¡çªå·$p_i$ãäžããããã Constraints å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã $1 \leq N \leq 5000$ $0 \leq p_i \leq i-1$ ($1 \leq i \leq N$) $N$, $p_i$ã¯æŽæ° Output åºåã¯$N$è¡ãããªãã $i$è¡ç®ã«ã¯ã$i$æ¥ç®ã«äœãããšã®ã§ããå人ã©ããã®ãã¢ã®æå€§æ°ãåºåããã ($1 \leq i \leq N$) Sample Input 1 3 0 0 2 Sample Output 1 1 1 2 Sample Input 2 5 0 1 2 3 4 Sample Output 2 1 1 2 2 3 | 36,608 |
ãªãŒã°æŠã®ã¹ã³ã¢ã·ãŒã ã¹ããŒãã®å€§äŒã«ã¯ãªãŒã°æŠãšããŒãã¡ã³ãæŠããããŸãããµãã«ãŒã®ãªãŒã°æŠã§ã¯åã»è² ã»åŒåã«ããããç¹æ°ãä»ãããã®åã¡ç¹ã§é äœãç«¶ããŸããåã¡ç¹ã¯ããããå(3ç¹)ãè² (0ç¹)ãåŒå(1ç¹)ã§ãã ããŒã æ°ãšãªãŒã°æŠã®æçžŸãå
¥åãšããæçžŸã®è¯ãé (åã¡ç¹ã®å€ãé )ã«äžŠã¹æ¿ããããŒã åãšåã¡ç¹ãåºåããããã°ã©ã ãäœæããŠãã ãããåã¡ç¹ãåç¹ã®å Žåã¯å
¥åé ã«åºåããŠãã ããã Input è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã n name 1 w 1 l 1 d 1 name 2 w 2 l 2 d 2 : name n w n l n d n ïŒè¡ç®ã«ããŒã æ° n ( n †10) ãäžããããŸããç¶ã n è¡ã«ããŒã i ã®åå name i (20æå以å
ã®ã¢ã«ãã¡ããã)ãåã®æ° w i ãè² ã®æ° l i ãåŒåã®æ° d i (0 †w i , l i , d i †9) ã空çœåºåãã§äžããããŸãã ããŒã æ°ã 0 ã®ãšããå
¥åã®çµäºãšããŸããããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã Output ããŒã¿ã»ããããšã«ãäžŠã¹æ¿ããããŒã ã®ãªã¹ããåºåããŠãã ããã i è¡ç®ã« i çªç®ã®ããŒã ã®ååãšåã¡ç¹ãã«ã³ãã§åºåã£ãŠåºåããŠãã ããã ããŒã¿ã»ããã®éã«ïŒã€ã®ç©ºè¡ãå
¥ããŠãã ããã Sample Input 4 Japan 1 0 2 Egypt 1 2 0 Canada 0 2 1 Spain 2 0 1 3 India 0 2 0 Poland 1 0 1 Italy 1 0 1 0 Output for the Sample Input Spain,7 Japan,5 Egypt,3 Canada,1 Poland,4 Italy,4 India,0 | 36,609 |
Problem G: Camera Control "ACM48" is one of the most popular dance vocal units in Japan. In this winter, ACM48 is planning a world concert tour. You joined the tour as a camera engineer. Your role is to develop software which controls the camera on a stage. For simplicity you can regard the stage as 2-dimensional space. You can rotate the camera to an arbitrary direction by the software but cannot change its coordinate. During a stage performance, each member of ACM48 moves along her route and sings the part(s) assigned to her. Here, a route is given as a polygonal line. You have to keep focusing the camera on a member during a stage performance. You can change the member focused by the camera if and only if the current and next members are in the same direction from the camera. Your task is to write a program which reads the stage performance plan and calculates the maximum time that you can focus the camera on members that are singing. You may assume the following are satisfied: You can focus the camera on an arbitrary member at the beginning time. Each route of the member does not touch the camera. Each member stays at the last coordinates after she reaches there. Input The input contains multiple test cases. Each test case has the following format: N c x c y The information of the 1-st member . . . The information of the N -th member N (1 †N †50) is the number of the members. ( c x , c y ) is the coordinates of the camera. Then the information of the N members follow. The information of the i -th member has the following format: M i x i ,1 y i ,1 t i ,1 . . . x i , M i y i , M i t i , M i L i b i ,1 e i ,1 . . . b i , L i e i , L i M i (1 †M i †100) is the number of the points in the route. ( x i,j , y i,j ) is the coordinates of the j -th in the route. t i,j (0 = t i ,0 < t i , j < t i , j +1 †10 3 for 0 < j ) is the time that the i -th member reaches the j -th coordinates. L i (0 †L i †100) is the number of the vocal part. b i,k and e i,k (0 †b i,k < e i,k < b i , k +1 < e i , k +1 †10 3 ) are the beginning and the ending time of the k -th vocal part, respectively. All the input values are integers. You may assume that the absolute of all the coordinates are not more than 10 3 . N = 0 denotes the end of the input. You may not process this as a test case. Output For each dataset, print the maximum time that you can focus the camera on singing members with an absolute error of at most 10 -6 . You may output any number of digits after the decimal point. Sample Input 2 0 0 2 -5 5 0 5 5 10 1 0 6 2 5 5 0 -5 5 10 1 6 10 1 7 -65 2 -65 10 0 65 1 3 2 0 1 23 24 2 0 0 2 100 10 0 -10 10 10 5 0 1 2 3 4 5 6 7 8 9 2 10 0 0 0 10 10 5 1 2 3 4 5 6 7 8 9 10 0 Output for the Sample Input 9.00000000 2.00000000 5.98862017 | 36,610 |
Score : 800 points Problem Statement There is a tree with N vertices numbered 1 through N . The i -th edge connects Vertex x_i and y_i . Each vertex is painted white or black. The initial color of Vertex i is represented by a letter c_i . c_i = W represents the vertex is white; c_i = B represents the vertex is black. A cat will walk along this tree. More specifically, she performs one of the following in one second repeatedly: Choose a vertex that is adjacent to the vertex where she is currently, and move to that vertex. Then, invert the color of the destination vertex. Invert the color of the vertex where she is currently. The cat's objective is to paint all the vertices black. She may start and end performing actions at any vertex. At least how many seconds does it takes for the cat to achieve her objective? Constraints 1 †N †10^5 1 †x_i,y_i †N ( 1 †i †N-1 ) The given graph is a tree. c_i = W or c_i = B . Input Input is given from Standard Input in the following format: N x_1 y_1 x_2 y_2 : x_{N-1} y_{N-1} c_1c_2..c_N Output Print the minimum number of seconds required to achieve the objective. Sample Input 1 5 1 2 2 3 2 4 4 5 WBBWW Sample Output 1 5 The objective can be achieved in five seconds, for example, as follows: Start at Vertex 1 . Change the color of Vertex 1 to black. Move to Vertex 2 , then change the color of Vertex 2 to white. Change the color of Vertex 2 to black. Move to Vertex 4 , then change the color of Vertex 4 to black. Move to Vertex 5 , then change the color of Vertex 5 to black. Sample Input 2 6 3 1 4 5 2 6 6 1 3 4 WWBWBB Sample Output 2 7 Sample Input 3 1 B Sample Output 3 0 Sample Input 4 20 2 19 5 13 6 4 15 6 12 19 13 19 3 11 8 3 3 20 16 13 7 14 3 17 7 8 10 20 11 9 8 18 8 2 10 1 6 13 WBWBWBBWWWBBWWBBBBBW Sample Output 4 21 | 36,611 |
Problem A: The Balance Ms. Iyo Kiffa-Australis has a balance and only two kinds of weights to measure a dose of medicine. For example, to measure 200mg of aspirin using 300mg weights and 700mg weights, she can put one 700mg weight on the side of the medicine and three 300mg weights on the opposite side (Figure 1). Although she could put four 300mg weights on the medicine side and two 700mg weights on the other (Figure 2), she would not choose this solution because it is less convenient to use more weights. You are asked to help her by calculating how many weights are required. Figure 1: To measure 200mg of aspirin using three 300mg weights and one 700mg weight Figure 2: To measure 200mg of aspirin using four 300mg weights and two 700mg weights Input The input is a sequence of datasets. A dataset is a line containing three positive integers a , b , and d separated by a space. The following relations hold: a â b , a †10000, b †10000, and d †50000. You may assume that it is possible to measure d mg using a combination of a mg and b mg weights. In other words, you need not consider âno solutionâ cases. The end of the input is indicated by a line containing three zeros separated by a space. It is not a dataset. Output The output should be composed of lines, each corresponding to an input dataset ( a , b , d ). An output line should contain two nonnegative integers x and y separated by a space. They should satisfy the following three conditions. You can measure d mg using x many a mg weights and y many b mg weights. The total number of weights ( x + y ) is the smallest among those pairs of nonnegative integers satisfying the previous condition. The total mass of weights ( ax + by ) is the smallest among those pairs of nonnegative integers satisfying the previous two conditions. No extra characters (e.g. extra spaces) should appear in the output. Sample Input 700 300 200 500 200 300 500 200 500 275 110 330 275 110 385 648 375 4002 3 1 10000 0 0 0 Output for the Sample Input 1 3 1 1 1 0 0 3 1 1 49 74 3333 1 | 36,612 |
Fox Ciel is developing an artificial intelligence (AI) for a game. This game is described as a game tree T with n vertices. Each node in the game has an evaluation value which shows how good a situation is. This value is the same as maximum value of child nodesâ values multiplied by -1. Values on leaf nodes are evaluated with Cielâs special function -- which is a bit heavy. So, she will use alpha-beta pruning for getting root nodeâs evaluation value to decrease the number of leaf nodes to be calculated. By the way, changing evaluation order of child nodes affects the number of calculation on the leaf nodes. Therefore, Ciel wants to know the minimum and maximum number of times to calculate in leaf nodes when she could evaluate child node in arbitrary order. She asked you to calculate minimum evaluation number of times and maximum evaluation number of times in leaf nodes. Ciel uses following algotithm: function negamax(node, α, β) if node is a terminal node return value of leaf node else foreach child of node val := -negamax(child, -β, -α) if val >= β return val if val > α α := val return α [NOTE] negamax algorithm Input Input follows following format: n p_1 p_2 ... p_n k_1 t_{11} t_{12} ... t_{1k} : : k_n t_{n1} t_{n2} ... t_{nk} The first line contains an integer n , which means the number of vertices in game tree T. The second line contains n integers p_i , which means the evaluation value of vertex i . Then, next n lines which contain the information of game tree T. k_i is the number of child nodes of vertex i , and t_{ij} is the indices of the child node of vertex i . Input follows following constraints: 2 \leq n \leq 100 -10,000 \leq p_i \leq 10,000 0 \leq k_i \leq 5 2 \leq t_{ij} \leq n Index of root node is 1 . Evaluation value except leaf node is always 0 . This does not mean the evaluation values of non-leaf nodes are 0 . You have to calculate them if necessary. Leaf node sometimes have evaluation value of 0 . Game tree T is tree structure. Output Print the minimum evaluation number of times and the maximum evaluation number of times in leaf node. Please separated by whitespace between minimum and maximum. minimum maximum Sample Input 1 3 0 1 1 2 2 3 0 0 Output for the Sample Input 1 2 2 Sample Input 2 8 0 0 100 100 0 -100 -100 -100 2 2 5 2 3 4 0 0 3 6 7 8 0 0 0 Output for the Sample Input 2 3 5 Sample Input 3 8 0 0 100 100 0 100 100 100 2 2 5 2 3 4 0 0 3 6 7 8 0 0 0 Output for the Sample Input 3 3 4 Sample Input 4 19 0 100 0 100 0 0 0 0 0 1 2 3 4 5 6 7 8 9 10 2 2 3 0 2 4 5 0 3 6 7 8 3 9 10 11 3 12 13 14 3 15 16 17 2 18 19 0 0 0 0 0 0 0 0 0 0 Output for the Sample Input 4 7 12 | 36,613 |
Score : 900 points Problem Statement Nukes has an integer that can be represented as the bitwise OR of one or more integers between A and B (inclusive). How many possible candidates of the value of Nukes's integer there are? Constraints 1 †A †B < 2^{60} A and B are integers. Input The input is given from Standard Input in the following format: A B Output Print the number of possible candidates of the value of Nukes's integer. Sample Input 1 7 9 Sample Output 1 4 In this case, A=7 and B=9 . There are four integers that can be represented as the bitwise OR of a non-empty subset of { 7 , 8 , 9 }: 7 , 8 , 9 and 15 . Sample Input 2 65 98 Sample Output 2 63 Sample Input 3 271828182845904523 314159265358979323 Sample Output 3 68833183630578410 | 36,614 |
Score : 500 points Problem Statement You are given a tree with N vertices 1,2,\ldots,N , and positive integers c_1,c_2,\ldots,c_N . The i -th edge in the tree (1 \leq i \leq N-1) connects Vertex a_i and Vertex b_i . We will write a positive integer on each vertex in T and calculate our score as follows: On each edge, write the smaller of the integers written on the two endpoints. Let our score be the sum of the integers written on all the edges. Find the maximum possible score when we write each of c_1,c_2,\ldots,c_N on one vertex in T , and show one way to achieve it. If an integer occurs multiple times in c_1,c_2,\ldots,c_N , we must use it that number of times. Constraints 1 \leq N \leq 10000 1 \leq a_i,b_i \leq N 1 \leq c_i \leq 10^5 The given graph is a tree. Input Input is given from Standard Input in the following format: N a_1 b_1 : a_{N-1} b_{N-1} c_1 \ldots c_N Output Use the following format: M d_1 \ldots d_N where M is the maximum possible score, and d_i is the integer to write on Vertex i . d_1,d_2,\ldots,d_N must be a permutation of c_1,c_2,\ldots,c_N . If there are multiple ways to achieve the maximum score, any of them will be accepted. Sample Input 1 5 1 2 2 3 3 4 4 5 1 2 3 4 5 Sample Output 1 10 1 2 3 4 5 If we write 1,2,3,4,5 on Vertex 1,2,3,4,5 , respectively, the integers written on the four edges will be 1,2,3,4 , for the score of 10 . This is the maximum possible score. Sample Input 2 5 1 2 1 3 1 4 1 5 3141 59 26 53 59 Sample Output 2 197 59 26 3141 59 53 c_1,c_2,\ldots,c_N may not be pairwise distinct. | 36,615 |
Score : 400 points Problem Statement We say that a odd number N is similar to 2017 when both N and (N+1)/2 are prime. You are given Q queries. In the i -th query, given two odd numbers l_i and r_i , find the number of odd numbers x similar to 2017 such that l_i †x †r_i . Constraints 1â€Qâ€10^5 1â€l_iâ€r_iâ€10^5 l_i and r_i are odd. All input values are integers. Input Input is given from Standard Input in the following format: Q l_1 r_1 : l_Q r_Q Output Print Q lines. The i -th line (1â€iâ€Q) should contain the response to the i -th query. Sample Input 1 1 3 7 Sample Output 1 2 3 is similar to 2017, since both 3 and (3+1)/2=2 are prime. 5 is similar to 2017, since both 5 and (5+1)/2=3 are prime. 7 is not similar to 2017, since (7+1)/2=4 is not prime, although 7 is prime. Thus, the response to the first query should be 2 . Sample Input 2 4 13 13 7 11 7 11 2017 2017 Sample Output 2 1 0 0 1 Note that 2017 is also similar to 2017. Sample Input 3 6 1 53 13 91 37 55 19 51 73 91 13 49 Sample Output 3 4 4 1 1 1 2 | 36,616 |
Score : 1500 points Problem Statement Given are an integer K and integers a_1,\dots, a_K . Determine whether a sequence P satisfying below exists. If it exists, find the lexicographically smallest such sequence. Every term in P is an integer between 1 and K (inclusive). For each i=1,\dots, K , P contains a_i occurrences of i . For each term in P , there is a contiguous subsequence of length K that contains that term and is a permutation of 1,\dots, K . Constraints 1 \leq K \leq 100 1 \leq a_i \leq 1000 \quad (1\leq i\leq K) a_1 + \dots + a_K\leq 1000 All values in input are integers. Input Input is given from Standard Input in the following format: K a_1 a_2 \dots a_K Output If there is no sequence satisfying the conditions, print -1 . Otherwise, print the lexicographically smallest sequence satisfying the conditions. Sample Input 1 3 2 4 3 Sample Output 1 2 1 3 2 2 3 1 2 3 For example, the fifth term, which is 2 , is in the subsequence (2, 3, 1) composed of the fifth, sixth, and seventh terms. Sample Input 2 4 3 2 3 2 Sample Output 2 1 2 3 4 1 3 1 2 4 3 Sample Input 3 5 3 1 4 1 5 Sample Output 3 -1 | 36,617 |
C: ä»å·çŒããã³ - Imagawayaki Man - ç©èª ä»å·çŒããã³ã¯ãæ£çŸ©ã®ããŒããŒã§ãããé¡ã¯çŽåŸ 1 ã¡ãŒãã«ã®ä»å·çŒãïŒäž»ã«å°éºŠç²ã§ã§ããçå°ã®äžã«ãã£ã·ããšé€¡ãè©°ããŠçŒããé£ã¹ç©ã§ãããèŠãç®ã¯å圢ã§ãããçŸå³ãããåæµ·éã§ã¯ãåã«ããçŒãããšåŒã°ããããšãå€ãã逡ãšããŠå°è±é€¡ã®ã»ãã«ãã«ã¹ã¿ãŒãã¯ãªãŒã ãªã©ãçšããããšããããããŸããŸãªå³ã®ããªãšãŒã·ã§ã³ãããããã®ãããããã€é£ã¹ãŠã飜ããªããå°è±é€¡ãã«ã¹ã¿ãŒãã¯ãªãŒã ã®ã»ãã«ãæ¹è¶é€¡ãããããžã£ã ãªã©ãçŸå³ãããäžã«ã¿ã³ãå
¥ããããçŒãã®ãããªãã®ãããããã ãã©ã®å³ãçŸå³ãããäžã®åçã¯æšæºçãªä»å·çŒãã§ãããå·Šã¯ã¯ãªãŒã 逡ãå³ã¯å°è±é€¡ãå
¥ã£ãŠãããçŸå³ãããã§ãããå®éã«é£ã¹ãŠèŠããšããããã¯ãçŸå³ããã£ãããšããã§ãä»å·çŒãã®çŽåŸã¯éåžž 10 ã»ã³ãã¡ãŒãã«çšåºŠã§ããã®ã§ãçŽåŸ 1 ã¡ãŒãã«ã®ä»å·çŒãã¯ããªã倧ããªãã®ã§ããããšã«æ³šæããããïŒã§ã§ããŠããããè
¹ã®ç©ºããè
ã«èªåã®é¡ãåããŠå·®ãåºãããšãããããã®ãããå¿
èŠã«å¿ããŠé¡ãåãæ¿ããå¿
èŠãããããã€ã§ãåãæ¿ããããããã«ãä»å·çŒãå·¥å Žã§ãããããäžäººã§ãã£ããšäžã€ãã€ä»å·çŒããçŒããŠæ¥ã
åããŠããã ãšããã§ãä»å·çŒãã¯é£åã§ãããããåœç¶ãªããè³å³æéãååšãããç¡é§ã«ããªãããã«ã¯ãçŒããŠããæéãçµã£ããã®ããé ã«äœ¿ãããšãæãŸãããããããã¯äžå³ã®ããã«ã宿ããçŽåŸ 1 ã¡ãŒãã«ã®ä»å·çŒã (å³äžã®çè²éš) ãå¹
1 ã¡ãŒãã«ã®ã¬ãŒã³ (å³äžã®ç°è²éš) ã®äžã«ééãªã䞊ã¹ãŠä¿åããŠããã ããæ¥ã倧æªå
ã®èçãã³ãå·¥å Žã«çŸããä»å·çŒããã³ãå°ãããããšãèªæ
¢ã®èçåã䜿ã£ãŠå·šå€§ãªä»å·çŒãããã£ããšéã³ã奜ãåæã«äžŠã³æ¿ããŠããŸã£ããèçãã³ã¯èçåã ãã§ãªãèšæ¶åãè¯ãã®ã§ãã©ã®ä»å·çŒããå
ã
äœçªç®ã«ãã£ãã®ãèŠããŠããããã ãè² ããèªããããªãä»å·çŒããã³ã¯ãäœãšãããŠãããããã®ä»å·çŒããäœçªç®ã«åºæ¥ããŠãªã®ãç¥ãããããèŠãç®ã§ã¯åããããã«ãªããããã§ãèçãã³ã«ããã¡ãããåã¯ã¡ãããšèŠããŠããããã§ããèçãã³ã¯æ¬åœã«ã¡ãããšèŠããŠããã®ããªïŒïŒããšæçºããããã«ãæ¬åœã«èŠããŠãããåããã¹ããããïŒããšèšã£ãŠè³ªåãç¹°ãè¿ãããšã§ãäœçªç®ã«åºæ¥ããŠãªã®ãç¥ãããšã«ããããã ããããŸã質åãããããšãæ¢ã£ãŠããããšãåä»ãããŠããŸãã®ã§ãã»ã©ã»ã©ã«ããªããã°ãªããªããããªãã«ã¯ãä»å·çŒããã³ãå©ããããã質åãç¹°ãè¿ãçæããããããã®ä»å·çŒããäœçªç®ã«åºæ¥ããŠãªã®ããåœãŠãããã°ã©ã ãäœæããŠã»ããã åé¡ ãŸããå·¥å Žã«äžŠãã§ããä»å·çŒãã®åæ° N ( 1 \leq N \leq 10,000 ) ãæšæºå
¥åã«ãã1è¡ã§äžããããããããã®ä»å·çŒãã®è£œé æ¥æã¯äºãã«ç°ãªããã€ãŸãã 1 \leq i \leq N ãæºããä»»æã®æŽæ° i ã«ã€ããŠã i çªç®ã«åºæ¥ããŠã®ä»å·çŒãã¯ãã ã²ãšã€ååšããã ãã以éãä»»æã®2æŽæ° a , b ( 1 \leq a, b \leq N ) ã«ãããŠãæšæºåºåã« ? a b ãšåºåãããšãã a çªç®ã«åºæ¥ããŠã®ä»å·çŒãã®äžå¿ãã b çªç®ã«åºæ¥ããŠã®ä»å·çŒãã®äžå¿ãŸã§ã®è·é¢ã¯äœã¡ãŒãã«ãïŒããšãã質åãè¡ãããšãã§ããããã®çãã¯æšæºå
¥åã«äžè¡ã§æŽæ°ãšããŠããã«äžãããããç©èªã§ãè¿°ã¹ãéããã¬ãŒã³äžã«ééãªãçŽåŸ 1 ã¡ãŒãã«ã®ä»å·çŒãã䞊ã¹ãããŠããã®ã§ãå·Šããæ°ã㊠i çªç®ã®ä»å·çŒãã®äžå¿ãã j çªç®ã®ä»å·çŒãã®äžå¿ãŸã§ã®è·é¢ã¯æ£ç¢ºã« |i - j| ã¡ãŒãã«ã§ããããã®è³ªå㯠20,000 åãŸã§ç¹°ãè¿ãè¡ãããšãã§ããã ããããã®ä»å·çŒããäœçªç®ã«åºæ¥ããŠãªã®ãåãã£ãããæšæºåºåã«æçµçãªçããåºåããªããã°ãªããªããåºå圢åŒã¯ãå i ( 1 \leq i \leq N ) ã«ãããŠãå·Šãã i çªç® ã®ä»å·çŒãã x_i çªç®ã«åºæ¥ããŠã®ãšãã ! x_1 x_2 x_3 ... x_N ãŸãã¯ã ! x_N x_{N-1} x_{N-2} ... x_1 ãšããã°ãããã€ãŸããå·Šããé ã«çããŠããå³ããé ã«çããŠãæ§ããªãããã®æçµçãªè§£çã¯ã1床ããè¡ãããšãã§ããªãããã®è§£çãæ£ããåºåã ã£ããšããæ£çãšã¿ãªãã æšæºåºåãè¡ãæ¯ã«ãã¹ããªãŒã ããã©ãã·ã¥ (flush) ããå¿
èŠãããããšã«æ³šæããããäž»èŠãªèšèªã§ã®ãã©ãã·ã¥äŸã以äžã«ç€ºãããã¡ããããã以å€ã®æ¹æ³ã§ãã©ãã·ã¥ãè¡ã£ãŠãæ§ããªãã C èšèª: #include <stdio.h> fflush(stdout); C++: #include <iostream> std::cout.flush(); Java: System.out.flush(); å
¥åºåäŸ æšæºå
¥å æšæºåºå 3 ? 1 2 2 ? 2 3 1 ? 1 3 1 ! 2 3 1 | 36,619 |
Search I You are given a sequence of n integers S and a sequence of different q integers T. Write a program which outputs C, the number of integers in T which are also in the set S. Input In the first line n is given. In the second line, n integers are given. In the third line q is given. Then, in the fourth line, q integers are given. Output Print C in a line. Constraints n †10000 q †500 0 †an element in S †10 9 0 †an element in T †10 9 Sample Input 1 5 1 2 3 4 5 3 3 4 1 Sample Output 1 3 Sample Input 2 3 3 1 2 1 5 Sample Output 2 0 Sample Input 3 5 1 1 2 2 3 2 1 2 Sample Output 3 2 Notes | 36,620 |
Maximum Heap A binary heap which satisfies max-heap property is called max-heap. In a max-heap, for every node $i$ other than the root, $A[i] \leq A[parent(i)]$, that is, the value of a node is at most the value of its parent. The largest element in a max-heap is stored at the root, and the subtree rooted at a node contains values no larger than that contained at the node itself. Here is an example of a max-heap. Write a program which reads an array and constructs a max-heap from the array based on the following pseudo code. $maxHeapify(A, i)$ move the value of $A[i]$ down to leaves to make a sub-tree of node $i$ a max-heap. Here, $H$ is the size of the heap. 1 maxHeapify(A, i) 2 l = left(i) 3 r = right(i) 4 // select the node which has the maximum value 5 if l †H and A[l] > A[i] 6 largest = l 7 else 8 largest = i 9 if r †H and A[r] > A[largest] 10 largest = r 11 12 if largest â i // value of children is larger than that of i 13 swap A[i] and A[largest] 14 maxHeapify(A, largest) // call recursively The following procedure buildMaxHeap(A) makes $A$ a max-heap by performing maxHeapify in a bottom-up manner. 1 buildMaxHeap(A) 2 for i = H/2 downto 1 3 maxHeapify(A, i) Input In the first line, an integer $H$ is given. In the second line, $H$ integers which represent elements in the binary heap are given in order of node id (from $1$ to $H$). Output Print values of nodes in the max-heap in order of their id (from $1$ to $H$). Print a single space character before each value. Constraint $1 \leq H \leq 500,000$ $-2,000,000,000 \leq$ value of a node $\leq 2,000,000,000$ Sample Input 1 10 4 1 3 2 16 9 10 14 8 7 Sample Output 1 16 14 10 8 7 9 3 2 4 1 Reference Introduction to Algorithms, Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. The MIT Press. | 36,621 |
Score: 200 points Problem Statement You are an immigration officer in the Kingdom of AtCoder. The document carried by an immigrant has some number of integers written on it, and you need to check whether they meet certain criteria. According to the regulation, the immigrant should be allowed entry to the kingdom if and only if the following condition is satisfied: All even numbers written on the document are divisible by 3 or 5 . If the immigrant should be allowed entry according to the regulation, output APPROVED ; otherwise, print DENIED . Notes The condition in the statement can be rephrased as "If x is an even number written on the document, x is divisible by 3 or 5 ". Here " if " and " or " are logical terms. Constraints All values in input are integers. 1 \leq N \leq 100 1 \leq A_i \leq 1000 Input Input is given from Standard Input in the following format: N A_1 A_2 \dots A_N Output If the immigrant should be allowed entry according to the regulation, print APPROVED ; otherwise, print DENIED . Sample Input 1 5 6 7 9 10 31 Sample Output 1 APPROVED The even numbers written on the document are 6 and 10 . All of them are divisible by 3 or 5 , so the immigrant should be allowed entry. Sample Input 2 3 28 27 24 Sample Output 2 DENIED 28 violates the condition, so the immigrant should not be allowed entry. | 36,622 |
Score : 100 points Problem Statement Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "A x C". Here, x is the uppercase English letter at the beginning of s . Given the name of the contest, print the abbreviation of the name. Constraints The length of s is between 1 and 100 , inclusive. The first character in s is an uppercase English letter. The second and subsequent characters in s are lowercase English letters. Input The input is given from Standard Input in the following format: AtCoder s Contest Output Print the abbreviation of the name of the contest. Sample Input 1 AtCoder Beginner Contest Sample Output 1 ABC The contest in which you are participating now. Sample Input 2 AtCoder Snuke Contest Sample Output 2 ASC This contest does not actually exist. Sample Input 3 AtCoder X Contest Sample Output 3 AXC | 36,623 |
Knapsack Problem with Limitations II You have $N$ items that you want to put them into a knapsack. Item $i$ has value $v_i$, weight $w_i$ and limitation $m_i$. You want to find a subset of items to put such that: The total value of the items is as large as possible. The items have combined weight at most $W$, that is capacity of the knapsack. You can select at most $m_i$ items for $i$-th item. Find the maximum total value of items in the knapsack. Input $N$ $W$ $v_1$ $w_1$ $m_1$ $v_2$ $w_2$ $m_2$ : $v_N$ $w_N$ $m_N$ The first line consists of the integers $N$ and $W$. In the following $N$ lines, the value, weight and limitation of the $i$-th item are given. Output Print the maximum total values of the items in a line. Constraints $1 \le N \le 50$ $1 \le v_i \le 50$ $1 \le w_i \le 10^9$ $1 \le m_i \le 10^9$ $1 \le W \le 10^9$ Sample Input 1 4 8 4 3 2 2 1 1 1 2 4 3 2 2 Sample Output 1 12 Sample Input 2 2 100 1 1 100 2 1 50 Sample Output 2 150 Sample Input 3 5 1000000000 3 5 1000000000 7 6 1000000000 4 4 1000000000 6 8 1000000000 2 5 1000000000 Sample Output 3 1166666666 | 36,624 |
Score : 1000 points Problem Statement Snuke has a rooted tree with N+1 vertices. The vertices are numbered 0 through N , and Vertex 0 is the root of the tree. The parent of Vertex i (1 \leq i \leq N) is Vertex p_i . Besides this tree, Snuke also has an box which is initially empty and many marbles, and playing with them. The play begins with placing one marble on some of the vertices, then proceeds as follows: If there is a marble on Vertex 0 , move the marble into the box. Move each marble from the vertex to its parent (all at once). For each vertex occupied by two or more marbles, remove all the marbles from the vertex. If there exists a vertex with some marbles, go to Step 1. Otherwise, end the play. There are 2^{N+1} ways to place marbles on some of the vertices. For each of them, find the number of marbles that will be in the box at the end of the play , and compute the sum of all those numbers modulo 1,000,000,007 . Constraints 1 \leq N < 2 \times 10^{5} 0 \leq p_i < i Partial Scores In the test set worth 400 points, N < 2{,}000 . Input Input is given from Standard Input in the following format: N p_1 p_2 ... p_{N} Output Print the answer. Sample Input 1 2 0 0 Sample Output 1 8 When we place a marble on both Vertex 1 and 2 , there will be multiple marbles on Vertex 0 by step 2. In such a case, these marbles will be removed instead of being moved to the box. Sample Input 2 5 0 1 1 0 4 Sample Output 2 96 Sample Input 3 31 0 1 0 2 4 0 4 1 6 4 3 9 7 3 7 2 15 6 12 10 12 16 5 3 20 1 25 20 23 24 23 Sample Output 3 730395550 Be sure to compute the sum modulo 1,000,000,007 . | 36,625 |
Score : 100 points Problem Statement There are N items, numbered 1, 2, \ldots, N . For each i ( 1 \leq i \leq N ), Item i has a weight of w_i and a value of v_i . Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W , which means that the sum of the weights of items taken must be at most W . Find the maximum possible sum of the values of items that Taro takes home. Constraints All values in input are integers. 1 \leq N \leq 100 1 \leq W \leq 10^5 1 \leq w_i \leq W 1 \leq v_i \leq 10^9 Input Input is given from Standard Input in the following format: N W w_1 v_1 w_2 v_2 : w_N v_N Output Print the maximum possible sum of the values of items that Taro takes home. Sample Input 1 3 8 3 30 4 50 5 60 Sample Output 1 90 Items 1 and 3 should be taken. Then, the sum of the weights is 3 + 5 = 8 , and the sum of the values is 30 + 60 = 90 . Sample Input 2 5 5 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 Sample Output 2 5000000000 The answer may not fit into a 32-bit integer type. Sample Input 3 6 15 6 5 5 6 6 4 6 6 3 5 7 2 Sample Output 3 17 Items 2, 4 and 5 should be taken. Then, the sum of the weights is 5 + 6 + 3 = 14 , and the sum of the values is 6 + 6 + 5 = 17 . | 36,626 |
å¹³é¢äžã®å³åœ¢ 瞊 8ãæšª 8 ã®ãã¹ãããªãå³ 1 ã®ãããªå¹³é¢ããããŸãã â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ å³ïŒ ãã®å¹³é¢äžã«ã以äžã® A ãã G ã®å³åœ¢ã®ã©ãããäžã€ã ã眮ãããŠããŸãã A â â â â B â â â â C â â â â D â â â â E â â â â F â â â â G â â â â ããšãã°ã次ã®å³ 2 ã®äŸã§ã¯ E ã®å³åœ¢ã眮ãããŠããŸãã â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â â â¡ â¡ â¡ â¡ â¡ â¡ â¡ â â â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ â¡ å³ïŒ å¹³é¢ã®äžã§å³åœ¢ãå ããŠãããã¹ã 1ãå ããŠããªããã¹ã 0 ã§è¡šçŸããæ°åã®åãèªã¿èŸŒãã§ã眮ãããŠããå³åœ¢ã®çš®é¡ïŒAãGïŒãåºåããããã°ã©ã ãäœæããŠãã ããã ãã ããã²ãšã€ã®å¹³é¢ã«çœ®ãããŠããå³åœ¢ã¯å¿
ãïŒã€ã§ãè€æ°ã®å³åœ¢ã眮ãããŠããããšã¯ãããŸããããŸããAãG ã§è¡šãããå³åœ¢ä»¥å€ã®ãã®ã眮ãããŠããããšã¯ãããŸããã Input å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªããŸãã ïŒã€ã®ããŒã¿ã»ãããšããŠãå¹³é¢ã®äžã§å³åœ¢ãå ããŠãããã¹ã 1ãå ããŠããªããã¹ã 0 ã§è¡šçŸãã 8 æåãããªã 8 ã€ã®æååãäžããããŸããäŸãã°ãå³ 2 ã«å¯Ÿå¿ããæååã®äžŠã³ã¯æ¬¡ã®ããã«ãªããŸãã 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ããŒã¿ã»ããã®éã¯ïŒã€ã®ç©ºè¡ã§åºåãããŠããŸããããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã Output åããŒã¿ã»ããããšã«ãå¹³é¢ã«äžããããå³åœ¢ã®çš®é¡ïŒAãG ã®ããããïŒãïŒè¡ã«åºåããŠãã ããã Sample Input 00000000 00000000 01100000 00110000 00000000 00000000 00000000 00000000 00011110 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00110000 00110000 00000000 00000000 00000000 00000000 Output for the Sample Input E C A | 36,628 |
ã¬ã·ãŒã åé¡ å€ªéåã¯10åã®æ¬ã賌å
¥ããïŒ åŸæ¥ïŒ ã¬ã·ãŒããããšã«äŸ¡æ Œã調ã¹ãããšãããïŒ ã¬ã·ãŒãã«ã¯æ±ããããïŒ ããæ¬ã®äŸ¡æ Œãèªã¿åããªãã£ãïŒ ãã®æ¬ã®äŸ¡æ ŒãïŒ 10åã®ç·é¡ãšä»ã®9åã®äŸ¡æ Œããèšç®ããããšã«ããïŒ äŸ¡æ Œãèªã¿åããªãã£ãæ¬ã®äŸ¡æ Œãåºåããããã°ã©ã ãæžãïŒ ãªãïŒæ¬ã®äŸ¡æ Œã¯ãã¹ãŠæ£ã®æŽæ°ã§ããïŒ ãŸãïŒæ¶è²»çšãèæ
®ããå¿
èŠã¯ãªãïŒ å
¥å å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ åããŒã¿ã»ããã¯10è¡ãããªãïŒ1è¡ã«1ã€ãã€æ£ã®æŽæ°ãæžãããŠããïŒ 1è¡ç®ã®æŽæ°ã¯10åã®ç·é¡ãïŒ 2è¡ç®ãã10è¡ç®ã®æŽæ°ã¯èªã¿åããäŸ¡æ Œã衚ããŠããïŒ ãªãïŒ10åã®ç·é¡ã¯10000以äžã§ããïŒ ç·é¡ ã 0 ã®ãšãå
¥åã®çµäºã瀺ã.ããŒã¿ã»ããã®æ°ã¯ 5 ãè¶
ããªãïŒ åºå ããŒã¿ã»ããããšã«ïŒäŸ¡æ Œãèªã¿åããªãã£ãæ¬ã®äŸ¡æ Œã1 è¡ã«åºåããïŒ å
¥åºåäŸ å
¥åäŸ 9850 1050 800 420 380 600 820 2400 1800 980 0 åºåäŸ 600 äžèšå顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã | 36,629 |
Score : 1600 points Problem Statement Snuke has permutations (P_0,P_1,\cdots,P_{N-1}) and (Q_0,Q_1,\cdots,Q_{N-1}) of (0,1,\cdots,N-1) . Now, he will make new permutations A and B of (0,1,\cdots,N-1) , under the following conditions: For each i ( 0 \leq i \leq N-1 ), A_i should be i or P_i . For each i ( 0 \leq i \leq N-1 ), B_i should be i or Q_i . Let us define the distance of permutations A and B as the number of indices i such that A_i \neq B_i . Find the maximum possible distance of A and B . Constraints 1 \leq N \leq 100000 0 \leq P_i \leq N-1 P_0,P_1,\cdots,P_{N-1} are all different. 0 \leq Q_i \leq N-1 Q_0,Q_1,\cdots,Q_{N-1} are all different. All values in input are integers. Input Input is given from Standard Input in the following format: N P_0 P_1 \cdots P_{N-1} Q_0 Q_1 \cdots Q_{N-1} Output Print the maximum possible distance of A and B . Sample Input 1 4 2 1 3 0 0 2 3 1 Sample Output 1 3 For example, if we make A=(0,1,2,3) and B=(0,2,3,1) , the distance will be 3 , which is the maximum result possible. Sample Input 2 10 0 4 5 3 7 8 2 1 9 6 3 8 5 6 4 0 2 1 7 9 Sample Output 2 8 Sample Input 3 32 22 31 30 29 7 17 16 3 14 9 19 11 2 5 10 1 25 18 15 24 20 0 12 21 27 4 26 28 8 6 23 13 22 3 2 7 17 9 16 4 14 8 19 26 28 5 10 1 25 18 15 13 11 0 12 23 21 20 29 24 27 6 30 31 Sample Output 3 28 | 36,630 |
Problem A Decimal Sequences Hanako learned the conjecture that all the non-negative integers appear in the infinite digit sequence of the decimal representation of $\pi$ = 3.14159265..., the ratio of a circle's circumference to its diameter. After that, whenever she watches a sequence of digits, she tries to count up non-negative integers whose decimal representations appear as its subsequences. For example, given a sequence " 3 0 1 ", she finds representations of five non-negative integers 3, 0, 1, 30 and 301 that appear as its subsequences. Your job is to write a program that, given a finite sequence of digits, outputs the smallest non-negative integer not appearing in the sequence. In the above example, 0 and 1 appear, but 2 does not. So, 2 should be the answer. Input The input consists of a single test case. $n$ $d_1$ $d_2$ ... $d_n$ $n$ is a positive integer that indicates the number of digits. Each of $d_k$'s $(k = 1, ... , n)$ is a digit. There is a space or a newline between $d_k$ and $d_{k+1}$ $(k = 1, ..., n - 1)$. You can assume that $1 \leq n \leq 1000$. Output Print the smallest non-negative integer not appearing in the sequence. Sample Input 1 3 3 0 1 Sample Output 1 2 Sample Input 2 11 9 8 7 6 5 4 3 2 1 1 0 Sample Output 2 12 Sample Input 3 10 9 0 8 7 6 5 4 3 2 1 Sample Output 3 10 Sample Input 4 100 3 6 7 5 3 5 6 2 9 1 2 7 0 9 3 6 0 6 2 6 1 8 7 9 2 0 2 3 7 5 9 2 2 8 9 7 3 6 1 2 9 3 1 9 4 7 8 4 5 0 3 6 1 0 6 3 2 0 6 1 5 5 4 7 6 5 6 9 3 7 4 5 2 5 4 7 4 4 3 0 7 8 6 8 8 4 3 1 4 9 2 0 6 8 9 2 6 6 4 9 Sample Output 4 11 Sample Input 5 100 7 2 7 5 4 7 4 4 5 8 1 5 7 7 0 5 6 2 0 4 3 4 1 1 0 6 1 6 6 2 1 7 9 2 4 6 9 3 6 2 8 0 5 9 7 6 3 1 4 9 1 9 1 2 6 4 2 9 7 8 3 9 5 5 2 3 3 8 4 0 6 8 2 5 5 0 6 7 1 8 5 1 4 8 1 3 7 3 3 5 3 0 6 0 6 5 3 2 2 2 Sample Output 5 86 Sample Input 6 1 3 Sample Output 6 0 | 36,631 |
Problem A: 鿥18ãã£ã· 2013 Problem Statement äŒæŽ¥å宿ã«åå äºå®ã®é«æ§»ããã¯ãå®¶ãè²§ä¹ã§ããŸããéãæã£ãŠããªãããã®ããã鿥18ãã£ã·ã䜿çšããŠããéãç¯çŽããããšããŠããã18ãã£ã·ã¯ããã1æã ãã§ãéè¡åè»ãªãã°1æ¥äžä¹ãæŸé¡ãæ¹æã®åºå
¥ããèªç±ãšããåªããã®ã§ããïŒè©³ããå©çšã«ãŒã«ã«ã€ããŠã¯çç¥ïŒã 18ãã£ã·ã®é
åã¯ãä¹ãæããè¡ãé§
ã§ã空ããŠããæéã䜿ã£ãŠããåœå°ã®ãåç£çãèŠãŠãŸãããç¹ã§ããã圌女ã¯ããã£ããã®æ©äŒãªã®ã§ãæ
ã®éäžã§ãããããªé§
ãèŠãŠåããããšèããŠããããã ããæ¬¡ã®é»è»ã«ä¹ãé
ããŠã¯å°ããããä¹ãæãé§
ã«å°çããæå»ãããä¹ãæãé§
ãåºçºããæå»ãŸã§ã®éãTå以äžã®ãšãã ãããã®é§
ãèŠãŠåãããšã«ããã 髿§»ããã®18ãã£ã·ã䜿ã£ãä¹ãæãèšç»ãäžããããã®ã§ãèŠãŠåããé§
ã®ååãšæéãåºåãããäžçªæåã«åºçºããé§
ãšãäžçªæåŸã«å°çããé§
ã¯ãèŠãŠåãåè£ã«ã¯å
¥ããªãããšã«æ³šæããŠã»ããã Input åããŒã¿ã»ããã¯ã以äžã®åœ¢åŒã§å
¥åãããã N T st_time1 st_name1 ar_time1 ar_name1 st_time2 st_name2 ar_time2 ar_name2 ... st_timeN st_nameN ar_timeN ar_nameN Nã¯åè»ã«ä¹è»ããåæ°ã衚ããæŽæ°ãTã¯ä¹ãæãé§
ãèŠãŠåãã蚱容æé(å)ã衚ããæŽæ°ã§ãããç¶ããŠãNè¡ã«ããã£ãŠãåè»ã®åºçºãšå°çã®ãã¢ãäžãããããåè¡ã®å
¥åã¯ãst_timeiã®æå»ã¡ããã©ã«st_nameiã®é§
ã髿§»ããã®ä¹ãåè»ãåºçºããããšããar_timeiã®æå»ã¡ããã©ã«ar_nameiã®é§
ã«é«æ§»ããã®ä¹ãåè»ãå°çããããšãæå³ããã Constraints 1 <= N <= 10 1 <= T <= 180 st_timeiãar_timei "HH:MM"ã«ãã衚ããããHHã«ã¯00以äž23以äžãMMã«ã¯00以äž59以äžã®2æ¡ã®æ°å€ãå
¥ããHHãæéã§ãMMãåã§ããã 00:00 <= st_time1 < ar_time1 < st_time2 < ar_time2 < ... < st_timeN < ar_timeN <= 23:59 st_nameiãar_namei ã¢ã«ãã¡ããã倧æåã»å°æåã«ãã衚ããããæååã§ããã 1 <= æååã®é·ã <= 50 içªç®ã®å°çé§
ar_nameiãšãi+1çªç®ã®åºçºé§
st_namei+1ã®ååã¯äžèŽããã st_name1ãar_nameNãä¹ãæãã®é§
ã®ååã¯ãããããç°ãªãæååã§ããã Output åããŒã¿ã»ããã«ã€ããŠã以äžã®åœ¢åŒã§åºåãè¡ãã M stay_name1 stay_time1 stay_name2 stay_time2 ... stay_nameM stay_timeM MïŒ0 <= M <= N - 1ïŒã¯ãèŠãŠåããé§
ã®æ°ã衚ããæŽæ°ã§ãããç¶ããŠãMè¡ã«ããã£ãŠãèŠãŠåããé§
ã®ãªã¹ããæå»ã®æé ã«åºåãããåè¡ã¯ãstay_nameiã®é§
ãstay_timeiåéèŠãŠåããããšãæå³ããã Sample Input 1 8 24 05:30 Kyoto 06:37 Maibara 06:50 Maibara 07:36 Tsuruga 07:42 Tsuruga 10:03 Kanazawa 10:58 Kanazawa 12:07 Toyama 12:15 Toyama 14:12 Naoetsu 14:29 Naoetsu 15:57 Nagaoka 16:11 Nagaoka 17:14 Niitsu 17:38 Niitsu 20:06 AizuWakamatsu Output for the Sample Input 1 2 Kanazawa 55 Niitsu 24 Kanazawaé§
ã¯ã10:03ã«å°çã10:58ã«åºçºãããããä¹ãæãã«55åã®ç©ºãæéããããNiitsué§
ã¯ã17:14ã«å°çã17:38ã«åºçºãããããä¹ãæãã«24åã®ç©ºãæéããããã©ã¡ãããå
¥åã§æå®ããã24å以äžã®ç©ºãæéããããããåºåããã Sample Input 2 1 180 10:44 Koriyama 11:52 AizuWakamatsu Output for the Sample Input 2 0 ä¹ãæãé§
ã¯1ã€ããªãããã0ãšåºåããã | 36,632 |
Problem E: Symmetry Open Binary and Object Group organizes a programming contest every year. Mr. Hex belongs to this group and joins the judge team of the contest. This year, he created a geometric problem with its solution for the contest. The problem required a set of points forming a line-symmetric polygon for the input. Preparing the input for this problem was also his task. The input was expected to cover all edge cases, so he spent much time and attention to make them satisfactory. However, since he worked with lots of care and for a long time, he got tired before he finished. So He might have made mistakes - there might be polygons not meeting the condition. It was not reasonable to prepare the input again from scratch. The judge team thus decided to find all line-asymmetric polygons in his input and fix them as soon as possible. They asked a programmer, just you, to write a program to find incorrect polygons. You can assume the following: Edges of the polygon must not cross or touch each other except for the end points of adjacent edges. It is acceptable for the polygon to have adjacent three vertexes on a line, but in such a case, there must be the vertex symmetric to each of them. Input The input consists of a set of points in the following format. N x 1 y 1 x 2 y 2 ... x N y N The first line of the input contains an integer N (3 †N †1000), which denotes the number of points. The following N lines describe each point. The i -th line contains two integers x 1 , y 1 (-10000 †x i , y i †10000), which denote the coordinates of the i -th point. Note that, although the points are the vertexes of a polygon, they are given in an artibrary order, not necessarily clockwise or counterclockwise. Output Output " Yes " in a line if the points can form a line-symmetric polygon, otherwise output " No ". Sample Input 1 4 0 1 1 0 0 0 1 1 Sample Output 1 Yes Sample Input 2 4 0 1 1 -1 0 0 1 1 Sample Output 2 No Sample Input 3 9 -1 1 0 1 1 1 -1 0 0 0 1 0 -1 -1 0 -1 1 -1 Sample Output 3 No Sample Input 4 3 -1 -1 0 0 1 1 Sample Output 4 No Sample Input 5 4 0 2 0 0 -1 0 1 0 Sample Output 5 Yes | 36,633 |
Problem G: Search of Concatenated Strings The amount of information on the World Wide Web is growing quite rapidly. In this information explosion age, we must survive by accessing only the Web pages containing information relevant to our own needs. One of the key technologies for this purpose is keyword search. By using well-known search engines, we can easily access those pages containing useful information about the topic we want to know. There are many variations in keyword search problems. If a single string is searched in a given text, the problem is quite easy. If the pattern to be searched consists of multiple strings, or is given by some powerful notation such as regular expressions, the task requires elaborate algorithms to accomplish efficiently. In our problem, a number of strings (element strings) are given, but they are not directly searched for. Concatenations of all the element strings in any order are the targets of the search here. For example, consider three element strings aa, b and ccc are given. In this case, the following six concatenated strings are the targets of the search, i.e. they should be searched in the text. aabccc aacccb baaccc bcccaa cccaab cccbaa The text may contain several occurrences of these strings. You are requested to count the number of occurrences of these strings, or speaking more precisely, the number of positions of occurrences in the text. Two or more concatenated strings may be identical. In such cases, it is necessary to consider subtle aspects of the above problem statement. For example, if two element strings are x and xx, the string xxx is an occurrence of both the concatenation of x and xx and that of xx and x. Since the number of positions of occurrences should be counted, this case is counted as one, not two. Two occurrences may overlap. For example, the string xxxx has occurrences of the concatenation xxx in two different positions. This case is counted as two. Input The input consists of a number of datasets, each giving a set of element strings and a text. The format of a dataset is as follows. n m e 1 e 2 . . . e n t 1 t 2 . . . t m The first line contains two integers separated by a space. n is the number of element strings. m is the number of lines used to represent the text. n is between 1 and 12, inclusive. Each of the following n lines gives an element string. The length (number of characters) of an element string is between 1 and 20, inclusive. The last m lines as a whole give the text. Since it is not desirable to have a very long line, the text is separated into m lines by newlines, but these newlines should be ignored. They are not parts of the text. The length of each of these lines (not including the newline) is between 1 and 100, inclusive. The length of the text is between 1 and 5000, inclusive. The element strings and the text do not contain characters other than lowercase letters. The end of the input is indicated by a line containing two zeros separated by a space. CAUTION! Although the sample input contains only small datasets, note that 12! Ã 5000 is far larger than 2 31 . Output For each dataset in the input, one line containing the number of matched positions should be output. An output line should not contain extra characters. Sample Input 3 1 aa b ccc aabccczbaacccbaazaabbcccaa 3 1 a b c cbbcbcbabaacabccaccbaacbccbcaaaccccbcbcbbcacbaacccaccbbcaacbbabbabaccc 3 4 aaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 0 0 Output for the Sample Input 5 12 197 | 36,634 |
C : Pruning / æåã Problem ãšã«ãããã€ãããã¥ãåã®äœãã§ããå°åã¯ä»å¹Žçæã§ãã£ãã ããã«ãå®¶ã®åºã«ã¯ 1 æ¬ã®æšãçããŠãããæ¯æ¥ãããŸãã鳎ãèãæããå¢å¹
ãããŠãããããªæ°ãããã åºã®æšã¯ããŸãã«ã°ã©ãçè«ã§ãããšããã®æšã®ãããªåœ¢ãããŠããããã®æšã«ã¯ããããã®èãæ¢ãŸã£ãŠããã èã¯ãå¿
ãæã®å
端(è)ãŸãã¯æã®åããç®(é ç¹)ã«æ¢ãŸãç¿æ§ãããã ãã ããæšã®æ ¹ã«ã¯ 1 å¹ãæ¢ãŸãããšã¯ãªãã ãã®æšã®ããæ(蟺)ãåããšããããã空åŽ(æ ¹ãšå察åŽ)ã«ããèãå
šãŠé§é€ããããšãã§ããã ãã ããæãåãããã«ã¯ããã®æã«å¿ããåŽåãå¿
èŠãšãªãã (泚 : æ¬åŒ§å
ã®èšèã¯ã°ã©ãçè«ã®èšèã§çœ®ãæãããã®ã§ããã以éã¯å
šãŠã°ã©ãçè«ã®èšèã§è¡šçŸããããšã«ããã) é«åºŠæ
å ±å瀟äŒãšãªã£ãçŸä»£ã«ãããŠã¯ã éšå±ã«å±
ãªããã«ããŠé ç¹ã«äœå¹ã®èããããã ãããŠå蟺ãåãã®ã«èŠããåŽåã調ã¹ãããšãåºæ¥ãã ãã¥ãåã¯ãã®æ
å ±ãçšããŠã æšã«æ¢ãŸã£ãŠããå
šãŠã®èãé§é€ããã®ã«å¿
èŠãªæå°ã®åŽåã調ã¹ãããã°ã©ã ãæžãããšã«ããã Input å
¥åã¯æ¬¡ã®ãããªåœ¢åŒã§äžããããïŒ N C 1 ... C N-1 u 0 v 0 p 0 ... u N-2 v N-2 p N-2 N ã¯æšã«å«ãŸããé ç¹ã®æ°ã§ããã åé ç¹ã«ã¯ 0 ... N - 1 ã®çªå·ãæ¯ããã0çªç®ã®é ç¹ãæ ¹ãšããã C 1 ... C N-1 ã¯ãåé ç¹ã«æ¢ãŸã£ãŠããèã®æ°ã§ããã C i ã i çªç®ã®é ç¹ã«æ¢ãŸã£ãŠããèã®æ°ã§ããã æ ¹ã«ã¯ãèã¯1å¹ãæ¢ãŸã£ãŠããªãã 2 + i è¡ç®ã® u i , v i , p i ã¯ãæšã«å«ãŸããèŸºã®æ
å ±ã§ããã u i , v i ã¯èŸºãçµã¶ 2 é ç¹ã®çªå·ã§ããã p i ã¯ãã®èŸºãåãã®ã«å¿
èŠãªåŽåã§ããã Constraints å
¥åã¯å
šãп޿°ã§ããã äžããããã°ã©ãã¯æšã§ããã 2 ⊠N ⊠1,000 0 ⊠C i ⊠1,000 0 ⊠u i , v i < N 1 ⊠p i ⊠1,000 Output èãå
šãŠé§é€ããããã«å¿
èŠãªæå°ã®åŽåã 1 è¡ã§åºåããã Samples Sample Input 1 5 2 2 2 2 0 1 4 1 2 1 1 3 1 1 4 1 Sample Output 1 4 é ç¹ 0 ãš 1 ãã€ãªã蟺ãåãã°ãå
šãŠã®èãé§é€ããããšãã§ããã Sample Input 2 5 0 2 2 2 0 1 4 1 2 1 1 3 1 1 4 1 Sample Output 2 3 é ç¹ 1 ãš 2 ã 1 ãš 3 ã 1 ãš 4 ãã€ãªã蟺ã®3æ¬ãåãã°æå°ã®åŽåã§èãé§é€ããããšãã§ããã ãªããé ç¹ 0 ãš 1 ãã€ãªã蟺ãåãããšã§å
šãŠã®èãé§é€ããããšãã§ããããããã«ã¯ã³ã¹ãã 4 ããã£ãŠããŸãã | 36,635 |
Problem F: Water Tank You built an apartment. The apartment has a water tank with a capacity of L in order to store water for the residents. The tank works as a buffer between the water company and the residents. It is required to keep the tank "not empty" at least during use of water. A pump is used to provide water into the tank. From the viewpoint of avoiding water shortage, a more powerful pump is better, of course. But such powerful pumps are expensive. Thatâs the life. You have a daily schedule table of water usage. It does not differ over days. The table is composed of some schedules. Each schedule is indicated by the starting time of usage, the ending time and the used volume per unit of time during the given time span. All right, you can find the minimum required speed of providing water for days from the schedule table. You are to write a program to compute it. You can assume the following conditions. A day consists of 86,400 units of time. No schedule starts before the time 0 (the beginning of the day). No schedule ends after the time 86,400 (the end of the day). No two schedules overlap. Water is not consumed without schedules. The tank is full of water when the tank starts its work. Input The input is a sequence of datasets. Each dataset corresponds to a schedule table in the following format: N L s 1 t 1 u 1 ... s N t N u N The first line of a dataset contains two integers N and L (1 †N †86400, 1 †L †10 6 ), which represents the number of schedule in the table and the capacity of the tank, respectively. The following N lines describe the N schedules. The ( i + 1)-th line of the dataset corresponds to the i -th schedule, which consists of three integers s i , t i and u i . The first two integers s i and t i indicate the starting time and the ending time of the schedule. The last integer u i (1 †u i †10 6 ) indicates the consumed volume per unit of time during the schedule. It is guaranteed that 0 †s 1 < t 1 †s 2 < t 2 †... †s n < t n †86400. The input is terminated by a line with two zeros. This line should not be processed. Output For each case, print the minimum required amount of water per unit of time provided by the pump in a line. The amount may be printed with an arbitrary number of digits after the decimal point, but should not contain an absolute error greater than 10 -6 . Sample Input 1 100 0 86400 1 1 100 43200 86400 1 0 0 Output for the Sample Input 1.000000 0.997685 | 36,636 |
Problem L: Problem L: 3ã€ã®ã·ã«ãšãã JAVA(Japan Aerospace Voyage Agency: æ¥æ¬å®å®é£è¡ç ç©¶æ©æ§)ã¯ãå®å®éçºäºæ¥ã®äžç°ãšããŠ2003å¹Žã«æ¢æ»æ©ãæã¡äžããã ãã®æ¢æ»æ©æã¡äžãã®ç®çã®äžã€ã«ãå°ææã€ã·ã«ã¯ã«æ¥è¿ãããã®è¡šé¢ç©è³ªã®ãµã³ãã«ãæ¡éããããšãããã æ§ã
ãªã¢ã¯ã·ãã³ãã«èŠèãããªããããæ¢æ»æ©ã¯ã€ã·ã«ã¯ã«å°éãããããŠã€ãã«2010幎ãå°çãžåž°éããã€ã·ã«ã¯ã®ãµã³ãã«è©Šæã®å
¥ã£ãã«ãã»ã«ãååããããšã«æåããã æ±äº¬å€§åŠã忥ããJAVAã«å°±è·ãããããŸãåã¯ããã®è©Šæã®ç ç©¶ãæ
åœããŠããã äžå»ãæ©ã詊æã®åæãããããšããã§ãããããšãŠãæ
éãªãããŸãåã¯ãããã«ãã»ã«ã®äžã«å¶æŽãªãšã€ãªã¢ã³ãå
¥ã£ãŠããã倧å€ã§ãããšèããã ããã§ãã«ãã»ã«ãéããåã«Xç·ãçšããŠå
éšã®ç©è³ªã®åœ¢ç¶ã調ã¹ããšã€ãªã¢ã³ãå
¥ã£ãŠããªãããšã確èªããããšã«ããã ã«ãã»ã«ã«Xç·ãåœãŠããšãç©è³ªãååšããŠãããšããã¯çœè²ã«ãååšããŠããªããšããã¯é»è²ã«ãªã£ãåçãåŸãããã æ§ã
ãªè§åºŠããXç·ãåœãŠãŠåçãåŸãããšã«ãããå
éšã®ç©è³ªã®åœ¢ç¶ãç¹å®ããããšãã§ããã ããããããã§ãŸãåé¡ãçããã æ£é¢ãããå³åŽé¢ãããäžé¢ããã®ïŒæã®åçãåŸããšããã§Xç·è£
眮ãæ
éããŠããŸã£ãã®ã§ããã ããã«ãïŒæã®åçã®çŸåã«ã倱æããæ¬æ¥é»è²ã«ãªãã¹ãéšåãäžéšçœè²ãšãªã£ãŠããŸã£ãå¯èœæ§ãããã ãã®ãŸãŸã§ã¯ç©è³ªã®åœ¢ç¶ãæ£ç¢ºã«ç¹å®ããããšã¯åºæ¥ãªããããäžã«ãšã€ãªã¢ã³ãå
¥ã£ãŠããªãããšã確èªã§ãããã«ãã»ã«ãéããããšãã§ããªãã ç ç©¶ãç¶ããããã«ã¯ãXç·è£
眮ãè²·ãæãããããªãã®ã ããJAVAã«ã¯äºæ¥ä»åãã«ããäºç®åæžã®åœ±é¿ã§ãXç·è£
眮ãããã«è²·ãæããã ãã®ãéããªãã ããã§ãããŸãåã¯æ¥å¹ŽåºŠã®äºç®ãå¢ãããŠãããããã®ãéã§æ°ããXç·è£
眮ãè²·ãããšãèããã ãã¡ãããäºç®ã¯ç°¡åã«ã¯å¢ããªããããæ¢æ»æ©ã®ææãæå€§éã«ã¢ããŒã«ããå¿
èŠãããã ã«ãã»ã«äžã«å€§ããªç©è³ªãå«ãŸããŠããã»ã©ææã匷ãã¢ããŒã«ããããšãã§ãããããç©è³ªãåãããæå€§äœç©ãèšç®ããããšã«ããã ïŒæã®Xç·åçãšççŸããªããããªå
éšã®ç©è³ªã®åœ¢ç¶ã®ãã¡ã§ãäœç©ãæå€§ã§ãããã®ãæ±ãããã®äœç©ãåºåããã Input åXç·åçã®çœè²ãšé»è²ã®å¢çã¯äžã€ã®å€è§åœ¢ãããªãã å€è§åœ¢ã¯åžãšã¯éããããŸãèªå·±äº€å·®ã¯ããªãã å€è§åœ¢ã®å
åŽãçœè²ãå€åŽãé»è²ã§ããã å
¥åã®åœ¢åŒã¯ä»¥äžã®ããã§ããã n x y 1 z 1 y 2 z 2 ... y n x z n x n y z 1 x 1 z 2 x 2 ... z n y x n y n z x 1 y 1 x 2 y 2 ... x n z y n z n x , n y , n z ã¯ãããããæ£é¢ã»å³åŽé¢ã»äžé¢ããã®Xç·åçã«å¯Ÿå¿ããå€è§åœ¢ã®é ç¹æ°ã§ããã åé ç¹æ°ã¯3以äž20以äžã§ããã ç¶ã n è¡ã«ã¯å€è§åœ¢ã®é ç¹ã®åº§æšãåæèšåãã«äžããããã é ç¹ã®åº§æšã¯0以äž300以äžã®æŽæ°ã§ããã ãŸãã座æšè»žã¯ã«ãã»ã«ã®äžå¿ããæ£é¢æ¹åã«x軞ããå³åŽé¢æ¹åã«y軞ããäžé¢æ¹åã«z軞ãåã£ãŠããã Output ïŒæã®Xç·åçãšççŸããªããããªç©è³ªã®æå€§äœç©ãäžè¡ã«åºåããã åºåããå€ã¯10 -3 以äžã®èª€å·®ãå«ãã§ããŠãæ§ããªããå€ã¯å°æ°ç¹ä»¥äžäœæ¡è¡šç€ºããŠãæ§ããªãã Notes on Test Cases äžèšå
¥å圢åŒã§è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã«å¯ŸããŠäžèšåºå圢åŒã§åºåãè¡ãããã°ã©ã ãäœæããŠäžããã n x , n y , n z ããã¹ãŠ 0 ã®ãšãå
¥åã®çµããã瀺ããŸãã Sample Input 4 0 0 100 0 100 100 0 100 4 0 0 100 0 100 100 0 100 4 0 0 100 0 100 100 0 100 3 0 0 100 0 0 100 3 0 0 100 0 0 100 3 0 0 100 0 0 100 5 0 0 200 0 200 200 100 100 0 200 5 0 0 200 0 100 100 200 200 0 200 4 0 0 200 0 200 200 0 200 0 0 0 Output for Sample Input 1000000.0000 250000.0000 5333333.3333 | 36,637 |
ãåã屿· äŒæŽ¥åŠåé«çåŠæ ¡ã§ã¯ãæ¯å¹ŽåŠåç¥ããããªã£ãŠããŸãããã®äžã§ãäžçªäººæ°ã¯ãåã屿·ã§ããäžçªäººæ°ã®çç±ã¯ããåã屿·ããããªãã¯ã©ã¹ã 1ã¯ã©ã¹ã 2ã¯ã©ã¹ã§ã¯ãªãã9ã¯ã©ã¹ããåã屿·ããããªãããšã§ããããããã工倫ããããšããããããããåæ§çãªãåã屿·ã«ãªã£ãŠããŸãããã®ãããæè¿ã§ã¯è¿é£ããå€ãã®æ¥å Žè
ã蚪ããŸãã ããã§ãåŠåç¥å®è¡å§å¡äŒã§ã¯ããåã屿·ã®å
¥å Žæéãäžè¡šã®ããã«æ ¡å
ã§çµ±äžããããã«ããšã¥ãåã¯ã©ã¹ããšã«å
¥å Žè
ç·æ°ãšåå
¥ã®éèšããããªãããšã«ããŸããã å
¥å Žæé衚(å
¥å Žè
1人ãããã®å
¥å Žæ) åå ååŸ 200å 300å åã¯ã©ã¹æ¯ã®ååãšååŸã®å
¥å Žè
æ°ãå
¥åãšããåã¯ã©ã¹æ¯ã®å
¥å Žè
ç·æ°åã³åå
¥ã®äžèŠ§è¡šãäœæããããã°ã©ã ãäœæããŠãã ããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã name 1 a 1 b 1 name 2 a 2 b 2 : name 9 a 9 b 9 å
¥åã¯ïŒè¡ãããªãã i è¡ç®ã«ç¬¬ i ã®ã¯ã©ã¹ã®ã¯ã©ã¹å name i (æ°åãšã¢ã«ãã¡ããããå«ã 1 æåä»¥äž 15 æå以äžã®åè§æåå)ãååã®å
¥å Žè
æ° a i (0 †a i †400)ã ååŸã®å
¥å Žè
æ° b i (0 †b i †400) ãäžããããŸãã Output i è¡ç®ã«ç¬¬ i ã®ã¯ã©ã¹ã®ã¯ã©ã¹åã å
¥å Žè
ç·æ°ã æéåå
¥ã空çœåºåãã§ïŒè¡ã«åºåããŠãã ããã Sample Input 1a 132 243 1c 324 183 1f 93 199 2b 372 163 2c 229 293 2e 391 206 3a 118 168 3b 263 293 3d 281 102 Output for the Sample Input 1a 375 99300 1c 507 119700 1f 292 78300 2b 535 123300 2c 522 133700 2e 597 140000 3a 286 74000 3b 556 140500 3d 383 86800 | 36,638 |
ãµãã«ãŒ (Soccer) åé¡ JOI åœã§ã¯ãµãã«ãŒã人æ°ã§ããïŒJOI ãªãŒã°ãšãããªãŒã°æŠãæ¯é±è¡ãããŠããïŒ JOI ãªãŒã°ã«ã¯ N åã®ããŒã ãæå±ããŠããŠïŒ1 ãã N ãŸã§ã®çªå·ãã€ããããŠããïŒãã¹ãŠã®çµã¿åããã®è©Šåãã¡ããã©äžåºŠãã€è¡ãããïŒã€ãŸãïŒ N à (N - 1) / 2 詊åãè¡ãããïŒå詊åã®åæã¯ããããã®ããŒã ã®åŸç¹ã§æ±ºãŸãïŒåã£ãããŒã ã®åã¡ç¹ã¯ 3 ç¹ã§ããïŒè² ããããŒã ã®åã¡ç¹ã¯ 0 ç¹ã§ããïŒåŒãåãã®å ŽåïŒäž¡ããŒã ã®åã¡ç¹ã¯ 1 ç¹ã§ããïŒé äœã¯åããŒã ã®ç²åŸããåã¡ç¹ã®åèšã§æ±ºå®ãïŒåŸå€±ç¹å·®ã¯èããªãïŒåã¡ç¹ã®åèšãçããããŒã ã®é äœã¯äžäœã«æããïŒ äŸãšããŠïŒ 4 ããŒã ã§ã®ãªãŒã°æŠãèããïŒ 4 à (4 - 1) / 2 = 6 詊åãè¡ãããïŒãããã®çµæã以äžã®è¡šã®ããã«ãªã£ããšããïŒãã€ãã³ã®å·ŠåŽã¯ãã®æšªã®ããŒã ã®åŸç¹ã§ããïŒå³åŽã¯ãã®çžŠã®ããŒã ã®åŸç¹ã§ããïŒ ããŒã 1 ããŒã 2 ããŒã 3 ããŒã 4 åã¡æ° è² ãæ° åŒãåãæ° åã¡ç¹ ããŒã 1 --- 0 - 1 2 - 1 2 - 2 1 1 1 4 ããŒã 2 1 - 0 --- 1 - 1 3 - 0 2 0 1 7 ããŒã 3 1 - 2 1 - 1 --- 1 - 3 0 2 1 1 ããŒã 4 2 - 2 0 - 3 3 - 1 --- 1 1 1 4 ãã®ãšãïŒåã¡ç¹ã®æãå€ãããŒã 2 ã 1 äœã§ããïŒ ãã®æ¬¡ã«åã¡ç¹ãå€ãããŒã ã¯ããŒã 1 ãšããŒã 4 ã§ããïŒãããã®ããŒã ã®é äœã¯å
±ã« 2 äœã§ããïŒ ãããŠåã¡ç¹ãæãå°ãªãããŒã 3 ã 4 äœã§ããïŒ å
šãŠã®è©Šåã®çµæãäžãããããšãïŒåããŒã ã®é äœãæ±ããããã°ã©ã ãäœæããïŒ å
¥å å
¥åãã¡ã€ã«ã® 1 è¡ç®ã«ã¯ããŒã ã®åæ° N (2 ⊠N ⊠100) ãæžãããŠããïŒç¶ã N à (N - 1) / 2 è¡ã«ã¯å詊åã®çµæãæžãããŠããïŒi + 1 è¡ç® (1 ⊠i ⊠N à (N - 1) / 2 ) ã«ã¯æŽæ° A i ïŒB i ïŒC i ïŒD i (1 ⊠A i ⊠NïŒ1 ⊠B i ⊠NïŒ0 ⊠C i ⊠100ïŒ0 ⊠D i ⊠100) ã空çœãåºåããšããŠæžãããŠããïŒããŒã A i ãšããŒã B i ã察æŠãïŒããŒã A i ã®åŸç¹ã C i ç¹ïŒããŒã B i ã®åŸç¹ã D i ç¹ã§ãã£ãããšã衚ãïŒå
šãŠã® i ã«ã€ã㊠A i â B i ã§ããïŒåãçµã¿åããã®å¯ŸæŠãæžãããŠããããšã¯ãªãïŒ åºå åºå㯠N è¡ãããªãïŒåè¡ã¯ 1 ã€ã®æŽæ°ãããªãïŒ i è¡ç® (1 ⊠i ⊠N) ã®æŽæ°ã¯ããŒã i ã®é äœã衚ãïŒ å
¥åºåäŸ å
¥åäŸ 1 4 1 2 0 1 1 3 2 1 1 4 2 2 2 3 1 1 2 4 3 0 3 4 1 3 åºåäŸ 1 2 1 4 2 å
¥åºåäŸ 1 ã¯å顿äžã®äŸã«å¯Ÿå¿ããŠããïŒ å
¥åäŸ 2 5 1 2 1 1 3 4 3 1 5 1 1 2 2 3 0 0 4 5 2 3 1 3 0 2 5 2 2 2 4 1 4 5 3 5 4 0 2 4 0 1 åºåäŸ 2 2 4 1 4 3 å
¥åºåäŸ 2 ã«ãããçµæã¯ä»¥äžã®éãã§ããïŒ åã¡æ° è² ãæ° åŒãåãæ° åã¡ç¹ ããŒã 1 2 1 1 7 ããŒã 2 0 1 3 3 ããŒã 3 3 0 1 10 ããŒã 4 1 3 0 3 ããŒã 5 1 2 1 4 å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã | 36,639 |
ããŒã ã¯ãŒãã³(Baumkuchen) JOI åã¯åйã®JOI åã¡ãããšJOI çŸã¡ãããšäžç·ã«ããã€ãé£ã¹ãããšããŠããïŒä»æ¥ã®ããã€ã¯3 人ã®å€§å¥œç©ã®ããŒã ã¯ãŒãã³ã ïŒ ããŒã ã¯ãŒãã³ã¯äžå³ã®ãããªåç圢ã®ãèåã§ããïŒ3 人ã«åããããã«ïŒJOI åã¯ååŸæ¹åã«åã3åå
¥ããŠïŒããã3 ã€ã®ããŒã¹ã«åãåããªããã°ãªããªãïŒãã ããã®ããŒã ã¯ãŒãã³ã¯æ¬ç©ã®æšæã®ããã«åºãã®ã§ïŒåãå
¥ããã®ã¯ç°¡åã§ã¯ãªãïŒãã®ãããã®ããŒã ã¯ãŒãã³ã«ã¯ããããã $N$ åã®åã蟌ã¿ãå
¥ã£ãŠããïŒJOI åã¯åã蟌ã¿ã®ããäœçœ®ã§ã®ã¿åãããšãã§ããïŒåã蟌ã¿ã«1 ãã $N$ ãŸã§æèšåãã«çªå·ããµã£ããšãïŒ$1 \leq i \leq N - 1$ ã«å¯ŸãïŒ $i$ çªç®ã®åã蟌ã¿ãš$i + 1$ çªç®ã®åã蟌ã¿ã®éã®éšåã®å€§ãã㯠$A_i$ ã§ããïŒãŸã $N$ çªç®ã®åã蟌ã¿ãš1 çªç®ã®åã蟌ã¿ã®éã®éšåã®å€§ãã㯠$A_N$ ã§ããïŒ å³1: ããŒã ã¯ãŒãã³ã®äŸ $N = 6, A_1 = 1, A_2 = 5, A_3 = 4, A_4 = 5, A_5 = 2, A_6 = 4$ èª²é¡ åã蟌ã¿ã®åæ° $N$ ãšïŒåéšåã®å€§ãããè¡šãæŽæ° $A_1,...,A_N$ ãäžããããïŒããŒã ã¯ãŒãã³ã3 ã€ã«åãåãããšãã®ïŒæãå°ããããŒã¹ã®å€§ããã®æå€§å€ãåºåããããã°ã©ã ãäœæããïŒ å
¥å æšæºå
¥åãã以äžã®ããŒã¿ãèªã¿èŸŒãïŒ 1 è¡ç®ã«ã¯ïŒæŽæ° $N$ ãæžãããŠããïŒããã¯ããŒã ã¯ãŒãã³ã« $N$ åã®åã蟌ã¿ãããããšã衚ãïŒ ç¶ã$N$ è¡ã®ãã¡ã® $i$ è¡ç®$(1 \leq i \leq N)$ ã«ã¯ïŒæŽæ° $A_i$ ãæžãããŠããïŒãã㯠$i$ çªç®ã®åã蟌ã¿ãš $i + 1$ çªç®ã®åã蟌ã¿ã®éã®éšå ($i = N$ ã®ãšã㯠$N$ çªç®ã®åã蟌ã¿ãš1 çªç®ã®åã蟌ã¿ã®éã®éšå) ã®å€§ããã $A_i$ ã§ããããšã衚ãïŒ åºå æšæºåºåã«ïŒããŒã ã¯ãŒãã³ã3 ã€ã«åãåãããšãã®ïŒæãå°ããããŒã¹ã®å€§ããã®æå€§å€ãè¡šãæŽæ°ã1 è¡ã§åºåããïŒ å¶é ãã¹ãŠã®å
¥åããŒã¿ã¯ä»¥äžã®æ¡ä»¶ãæºããïŒ $3 \leq N \leq 100000$ $1 \leq A_i \leq 1000000000 (1 \leq i \leq N)$ å
¥åºåäŸ å
¥åäŸ 1 6 1 5 4 5 2 4 åºåäŸ 1 6 å³2: 1 çªç®ã®åã蟌ã¿ãš3 çªç®ã®åã蟌ã¿ãš5 çªç®ã®åã蟌ã¿ã§åãã®ãæåã§ããïŒ å
¥åäŸ 2 30 1 34 44 13 30 1 9 3 7 7 20 12 2 44 6 9 44 31 17 20 33 18 48 23 19 31 24 50 43 15 åºåäŸ 2 213 å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã | 36,640 |
Problem A: Equal Total Scores Taro and Hanako have numbers of cards in their hands. Each of the cards has a score on it. Taro and Hanako wish to make the total scores of their cards equal by exchanging one card in one's hand with one card in the other's hand. Which of the cards should be exchanged with which? Note that they have to exchange their cards even if they already have cards of the same total score. Input The input consists of a number of datasets. Each dataset is formatted as follows. n m s 1 s 2 ... s n s n +1 s n +2 ... s n + m The first line of a dataset contains two numbers n and m delimited by a space, where n is the number of cards that Taro has and m is the number of cards that Hanako has. The subsequent n + m lines list the score for each of the cards, one score per line. The first n scores (from s 1 up to s n ) are the scores of Taro's cards and the remaining m scores (from s n +1 up to s n + m ) are Hanako's. The numbers n and m are positive integers no greater than 100. Each score is a non-negative integer no greater than 100. The end of the input is indicated by a line containing two zeros delimited by a single space. Output For each dataset, output a single line containing two numbers delimited by a single space, where the first number is the score of the card Taro gives to Hanako and the second number is the score of the card Hanako gives to Taro. If there is more than one way to exchange a pair of cards that makes the total scores equal, output a pair of scores whose sum is the smallest. In case no exchange can make the total scores equal, output a single line containing solely -1. The output must not contain any superfluous characters that do not conform to the format. Sample Input 2 2 1 5 3 7 6 5 3 9 5 2 3 3 12 2 7 3 5 4 5 10 0 3 8 1 9 6 0 6 7 4 1 1 2 1 2 1 4 2 3 4 3 2 3 1 1 2 2 2 0 0 Output for the Sample Input 1 3 3 5 -1 2 2 -1 | 36,641 |
Score : 500 points Problem Statement There are N children standing in a line from left to right. The activeness of the i -th child from the left is A_i . You can rearrange these children just one time in any order you like. When a child who originally occupies the x -th position from the left in the line moves to the y -th position from the left, that child earns A_x \times |x-y| happiness points. Find the maximum total happiness points the children can earn. Constraints 2 \leq N \leq 2000 1 \leq A_i \leq 10^9 All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the maximum total happiness points the children can earn. Sample Input 1 4 1 3 4 2 Sample Output 1 20 If we move the 1 -st child from the left to the 3 -rd position from the left, the 2 -nd child to the 4 -th position, the 3 -rd child to the 1 -st position, and the 4 -th child to the 2 -nd position, the children earns 1 \times |1-3|+3 \times |2-4|+4 \times |3-1|+2 \times |4-2|=20 happiness points in total. Sample Input 2 6 5 5 6 1 1 1 Sample Output 2 58 Sample Input 3 6 8 6 9 1 2 1 Sample Output 3 85 | 36,642 |
Problem I: Live Programming A famous Japanese idol group, JAG48, is planning the program for its next live performance. They have $N$ different songs, $song_1$, $song_2$, ..., and $song_N$. Each song has three integer param- eters, $t_i$, $p_i$, and $f_i$: $t_i$ denotes the length of $song_i$, $p_i$ denotes the basic satisfaction points the audience will get when $song_i$ is performed, and $f_i$ denotes the feature value of songi that affects the audience's satisfaction. During the live performance, JAG48 can perform any number (but at least one) of the $N$ songs, unless the total length of the chosen songs exceeds the length of the live performance $T$. They can decide the order of the songs to perform, but they cannot perform the same song twice or more. The goal of this live performance is to maximize the total satisfaction points that the audience will get. In addition to the basic satisfaction points of each song, the difference between the feature values of the two songs that are performed consecutively affects the total satisfaction points. If there is no difference, the audience will feel comfortable. However, the larger the difference will be, the more frustrated the audience will be. Thus, the total satisfaction points will be calculated as follows: If $song_x$ is the first song of the live performance, the total satisfaction points just after $song_x$ is equal to $p_x$. If $song_x$ is the second or subsequent song of the live performance and is performed just after $song_y$, $p_x -(f_x -f_y)^2$ is added to the total satisfaction points, because the audience will get frustrated if $f_x$ and $f_y$ are different. Help JAG48 find a program with the maximum total satisfaction points. Input The input is formatted as follows. $N$ $T$ $t_1$ $p_1$ $f_1$ : : : $t_N$ $p_N$ $f_N$ The first line contains two integers $N$ and $T$: the number of the available $song_s$ $N$ ($1 \leq N \leq 4,000$), and the length of the live performance $T$ ($1 \leq T \leq 4,000$). The following $N$ lines represent the parameters of the songs. The $i$-th line of them contains three integers, which are the parameters of $song_i$: the length $t_i$ ($1 \leq t_i \leq 4,000$), the basic satisfaction points $p_i$ ($1 \leq p_i \leq 10^8$), and the feature value $f_i$ ($1 \leq f_i \leq 10^4$). You can assume that there is at least one song whose length is less than or equal to $T$. Output Output the maximum total satisfaction points that the audience can get during the live performance. Sample Input 2 10 10 200 1 10 100 100 Output for the Sample Input 200 Sample Input 3 15 5 100 1 5 100 2 5 100 4 Output for the Sample Input 295 Sample Input 3 10 5 200 200 5 200 201 5 300 1 Output for the Sample Input 399 Sample Input 3 20 5 100 200 5 100 201 5 300 1 Output for the Sample Input 300 Sample Input 5 61 14 49 7 31 46 4 30 55 5 52 99 1 34 70 3 Output for the Sample Input 103 | 36,643 |
Bange Hills Tower A project is underway to build a new viewing tower in Bange town called âBange Hills Towerâ whose selling point will be the gorgeous view of the entire main keep of Wakamatsu Castle from top to bottom. Therefore, the view line from the top of the tower must reach the bottom of the keep without being hindered by any of the buildings in the town. Write a program to calculate the minimum tower height required to view the keep in its entirety based on the following information: the planned location of the tower and the heights and locations of existing buildings. Assume all the buildings, including the keep, are vertical lines without horizontal stretch. âview of the entire keepâ means that the view line from the tower top can cover the keep from the bottom to the top without intersecting (contacts at the top are exempted) any of the other vertical lines (i.e., buildings). Input The input is given in the following format. N t x_1 h_1 x_2 h_2 : x_N h_N The first line provides the number of existing buildings N (1†N â€1000) and the planned location of the tower t (2†t â€10 5 ) in integers. Each of the subsequent N lines provides the information of the i -th building: location x_i (1 †x_i < t ) and height from the ground h_i (1 †h_i †100). All position information is one-dimensional along the ground line whose origin coincides with the Keep location. No more than one building is located in the same location (i.e. if i â j , then x_i â x_j ). Output Output the required height as a real number. No limits on the number of decimal places as long as the error does not exceed ± 10 -3 . Sample Input 1 3 10 6 4 4 2 3 2 Sample Output 1 6.666667 | 36,644 |
The Maximum Number of Customers $N$ persons visited a restaurant. The restaurant is open from 0 to $T$. The $i$-th person entered the restaurant at $l_i$ and left at $r_i$. Find the maximum number of persons during the business hours. Constraints $ 1 \leq N \leq 10^5 $ $ 1 \leq T \leq 10^5 $ $ 0 \leq l_i < r_i \leq T $ Input The input is given in the following format. $N$ $T$ $l_1$ $r_1$ $l_2$ $r_2$ : $l_N$ $r_N$ Output Print the maximum number of persons in a line. Sample Input 1 6 10 0 2 1 3 2 6 3 8 4 10 5 10 Sample Output 1 4 Sample Input 2 2 2 0 1 1 2 Sample Output 2 1 | 36,645 |
Mysterious Gems å®å®æŠ 1603ã1867 幎ïŒäººã
ã¯ãã®æä»£ã®ããšã EDO æä»£ãšåŒã¶ïŒEDO ãšã¯åœææå
端ã®å®å®èªè¡æè¡ïŒEnhanced Driving Operation ã®ããšã§ããã1603 幎㫠Dr.Izy ã«ãã£ãŠéçºãããïŒ ããªãã¯å®å®åéºå®¶ã§ããïŒå®å®ãé£ã³åã£ãŠæ§ã
ãªææãåéºããŠããïŒãã®åéºã®éäžã§ïŒããªãã¯ãšãŠãäžæè°ãªææãçºèŠããïŒãã®ææã«ã¯ïŒè³ããšããã«äžè²ã«èŒãäžæè°ãªå®ç³ãèœã¡ãŠããïŒããªãã¯ãã®ææãžã®éäžã詊ã¿ãããšèãããïŒé倧ãªåé¡ã®ããã«ããã¯äžå¯èœã§ããããšãããã£ãïŒãã®ææã®ç©ºæ°ã«ã¯ïŒäººéãè§Šããã ãã§å³æ»ããŠããŸããããªçæ¯ã®æåãå«ãŸããŠããã®ã ïŒ ããã§ïŒããªãã¯ããããã䜿ã£ãŠå®ç³ãååããããšãèãã€ããïŒããªãã¯ãã®ææã®åšåè»éã«ãŠåŸ
æ©ããïŒãããŠïŒéäžããããããããé éæäœããããšã«ãã£ãŠå®ç³ãååããã®ã ïŒããªãã¯ïŒããããã«ãç§»åããæ¹åããšãç§»åããè·é¢ãã®çµãããªãåœä»€ã®åã«ãã£ãŠãããããé éæäœããïŒããããã¯ç§»åçµè·¯äžïŒå°éç¹ãå«ãïŒã«å®ç³ãèŠã€ãããšïŒããããå
šãŠååããïŒ ããªãã®ä»äºã¯ïŒãããããäžããããå
šãŠã®åœä»€ã®å®è¡ãçµãããšãã«ïŒå
šãŠã®å®ç³ãååããããšãã§ãããã©ãããå€å®ããããã°ã©ã ãæžãããšã§ããïŒ ãªãïŒãããããäžæè°ãªå®ç³ãååããç¯å²ã¯ããã»ã©åºããªãïŒãã®ããïŒãããããç§»åããç¯å²ã¯å
šãŠ 2 次å
ã®å¹³é¢ã§è¡šãããšãã§ããïŒãããŠïŒãããããç§»åããç¯å²ã¯ (0,0) ããã³ (20,20) ãããããå·Šäžé
ããã³å³äžé
ãšããæ£æ¹åœ¢ã®å
éšïŒå¢çç·ãå«ãïŒã§ããïŒããããã¯åžžã«ç¯å²ã®äžå€®ïŒããªãã¡ (10,10) ã®åº§æšã«éäžããïŒãŸãïŒå
šãŠã®å®ç³ã¯äžå€®ä»¥å€ã®æ Œåç¹äžã«ããããšãä¿èšŒãããŠããïŒ Input å
¥åã¯è€æ°ã®ããŒã¿ã»ããã«ããæ§æãããïŒ ããããã®ããŒã¿ã»ããã®å
é è¡ã«ã¯ïŒåäžã®æ£ã®æŽæ° N (1 <= N <= 20) ãå«ãŸãããããã¯ãããããç§»åå¯èœãªç¯å²å
ã«ããäžæè°ãªå®ç³ã®åæ°ã衚ãïŒæ¬¡ã® N è¡ã«ã¯ïŒãããã x i ããã³ y i (0 <= x i , y i <= 20) ãå«ãŸãïŒãã㯠i çªç®ã®äžæè°ãªå®ç³ã®èœã¡ãŠãã座æšã衚ãïŒãªãïŒ1 ã€ã®å Žæã«è€æ°ã®å®ç³ãèœã¡ãŠããããšã¯ãªãïŒ æ¬¡ã®è¡ã«ã¯åäžã®æŽæ° M (1 <= M <= 30) ãå«ãŸãïŒããã¯ããããã«äžããåœä»€ã®åæ°ã衚ãïŒãã®åŸã® M è¡ã«ã¯ãããã d j ãšã²ãšã€ã®æ£ã®æŽæ° l j ãå«ãŸããïŒãã㯠j çªç®ã®åœä»€ã«ãããæ¹åããã³ç§»åéã衚ãïŒãã ãïŒæ¹å㯠NïŒEïŒSïŒW ã®ããããã®æåã§ããïŒé ã«åïŒæ±ïŒåïŒè¥¿ã衚ãïŒå㯠y è»žã®æ£æ¹åïŒæ±ã¯ x è»žã®æ£æ¹åïŒïŒãªãïŒãããããç§»åå¯èœãªç¯å²ãè¶
ãããããªåœä»€ã¯äžããããªãããšãä¿èšŒãããŠããïŒ å
¥å㯠N = 0 ã®ãšãã«çµäºãïŒããã¯ããŒã¿ã»ããã«å«ãŸããªãïŒ Output ããããã®ããŒã¿ã»ããã«ã€ããŠïŒãããããå
šãŠã®å®ç³ãåéã§ãããšãã¯ãYesããšïŒããã§ãªããšãã¯ãNoããš 1 è¡ã«åºåããªããïŒ Sample Input 2 10 11 11 12 2 N 2 E 1 2 10 11 11 12 2 N 2 W 1 3 0 15 5 10 5 15 5 W 10 S 10 N 20 E 10 S 10 0 Output for the Sample Input Yes No No | 36,647 |
Score : 200 points Problem Statement We have a long seat of width X centimeters. There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters. We would like to seat as many people as possible, but they are all very shy, and there must be a gap of length at least Z centimeters between two people, and between the end of the seat and a person. At most how many people can sit on the seat? Constraints All input values are integers. 1 \leq X, Y, Z \leq 10^5 Y+2Z \leq X Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Sample Input 1 13 3 1 Sample Output 1 3 There is just enough room for three, as shown below: Figure Sample Input 2 12 3 1 Sample Output 2 2 Sample Input 3 100000 1 1 Sample Output 3 49999 Sample Input 4 64146 123 456 Sample Output 4 110 Sample Input 5 64145 123 456 Sample Output 5 109 | 36,648 |
Problem E: Dungeon Master Once upon a time, in a fantasy world far, far away, monsters dug caves and dungeons for adventurers. They put some obstacles in their caves so it becomes more difficult and more exciting for the adventurers to reach the goal. One day, Emils, one of the monsters in the caves, had a question about the caves. How many patterns of a cave can they make, by changing the locations of the obstacles in it? Here's the detail of the question. A cave consists of W à H squares. Monsters can put obstacles at some of the squares, so that adventurers can't go into them. The total number of obstacles is fixed, and there can't be two or more obstacles in one square. Adventurers enter the cave from the top-left square, and try to reach the bottom-right square. They can move from one square to any of the four adjacent squares, as long as there are no obstacles in the destination square. There must be at least one path between any two squares that don't have obstacles. There must be no obstacles in the top-left square, nor in right-bottom square. The question is, given the width W and height H of the cave, and the number S of obstacles, how many patterns of the caves the monsters can make. As the obstacles have the same look, they should not be distinguished each other. It was a very interesting mathematical question. Emils couldn't solve this question by himself, so he told it to his colleagues instead. None of them could answer to it, though. After that, the question soon got popular among the monsters working in the caves, and finally, they became unable to sleep well as they always thought about the question. You are requested to write a program that answers to the question. Input The input has a line, containing three integers W , H , and S , separated by a space. W and H are the horizontal and vertical sizes of the cave, and S is the number of obstacles to put in the cave. It is guaranteed that 2 †W , H †8, and that 0 †S †W à H . Output Output the number of patterns of the cave, in a line. Sample Input 1 2 2 2 Output for the Sample Input 1 0 Sample Input 2 2 2 1 Output for the Sample Input 2 2 | 36,649 |
Product Sale Lines Problem ãŠãã¯ã坿ãããšç®é»åããã¯SEARIGHT LIVE FESã®ç©è²©ã«æ¥ãŠãããäžå³ã®ããã«ãç©è²©åã¯äºåãããªããæšªã« W 人ã瞊㫠H 人䞊ã¹ã倧ããã§ã³ã®åã®åœ¢ãããŠãããåã®å
é ã®äººã¯è²·ãç©ãããåŸã«åããã¯ããåãåã®åŸãã®äººã
ã¯ããããäžäººåãã€åãè©°ããã äºäººã¯æåã«ç©è²©åã®æåŸå°Ÿã«é£å士ã§ãããããéãåã«ïŒäžå³ãªã¬ã³ãžãšæ¿ãéè²ã®äœçœ®ïŒäžŠãã§ãããäºäººã¯ãšãŠã仲ããããããåžžã«ã§ããã ãè¿ãã«ãããããããã人ã®ã¯ãæ¹ã¯åã«ãã£ãŠéããããéãåã«äžŠãã§ããäºäººã®äœçœ®ã¯é¢ããŠããŸãå¯èœæ§ãããã ããªãã®ä»äºã¯ãåã®ã¯ãæ¹ãäžãããããšããäºäººãé£å士ã«ãªãåæ°ãæ±ããããšã§ããã ãã ããäºäººãšãã³ã®åã®è§ã«ããïŒäžå³ã®é»è²ã®ç¶æ
ã®ïŒãšãã¯ãé£å士ãšã¿ãªããªãããŸãã䞊ãã çŽåŸã¯é£å士ã«äžŠãã§ããããããã¯æ°ããªãã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã W H N p 1 p 2 ... p N 1è¡ç®ã«åã®å€§ãããè¡šãæŽæ° W ãš H ã空çœåºåãã§äžããããã W ã¯ã³ã®åã®æšªã«äžŠã¹ãå€åŽã®äººæ°ãã H ã¯çžŠã«äžŠã¹ãå€åŽã®äººæ°ã衚ãã2è¡ç®ã«äººãäžäººã©ã¡ããã®åããã¯ããåæ° N ãäžããããã3è¡ç®ã«ã¯åã®ã¯ãæ¹ã«ã€ããŠã®æ
å ± p 1 ... p N ã空çœåºåãã§äžããããã p i ã«â0âãŸãã¯â1âã§ãããâ0âã®ãšããå€åŽã®äººãäžäººã¯ããããšããâ1âã®ãšãå
åŽã®äººãäžäººã¯ããããšã衚ãããã ãããŠãã¯ã坿ãããŸãã¯ç®é»åãããåããåºãããšã¯ãªãã Constraints 4 †W †100 4 †H †100 0 †N †100 Output äºäººãé£å士ã«ãªãåæ°ãäžè¡ã«åºåããã Sample Input 1 11 11 5 0 0 0 0 0 Sample Output 1 0 Sample Input 2 11 11 5 0 0 1 1 1 Sample Output 2 1 | 36,650 |
å顿 ãã³ã®é女 H.N.ELLY ã¯ãšããåç»ãµã€ãã®ç±ççãªãã¡ã³ã§ããïŒãã³ã®é女ã®åŒ·ãã¯ãã®æã
ã®ãã®åç»ãµã€ãããã®è»¢éé床ã«å¿ããŠå€åããã®ã§ã¯ãªãããš çŸæš¹ããã ã¯èããïŒããã§åç»ãµã€ããããã³ã®éå¥³ã®æã€ã³ã³ãã¥ãŒã¿ãŸã§ã®éå»ã®è»¢éé床 (=åäœæéãããã®ããŒã¿ã®è»¢éé) ã調ã¹ããïŒ åæã®ã€ã³ã¿ãŒãããã®ãããã¯ãŒã¯ã®æ§é ãšãã以éã®ãããã¯ãŒã¯ã®æ§é ã®å€åã衚ãã¯ãšãªãäžããããã®ã§ïŒåå€åã«ã€ããŠå€åããçŽåŸã®åç»ãµã€ããããã³ã®éå¥³ã®æã€ã³ã³ãã¥ãŒã¿ãŸã§ã®è»¢ééåºŠãæ±ããïŒ ã€ã³ã¿ãŒãããã¯è€æ°ã®è»¢éè£
眮ãããªããã®ãšèŠãªãïŒåã
ãã€ãªãåç·ã¯åæ¹åã«æ
å ±ãéãããšãã§ãïŒãã®è»¢ééåºŠã®æå€§ã¯ 1 ã§ãããšããïŒãŸãïŒãããã¯ãŒã¯ã¯åžžã«åç»ãµã€ããããã³ã®é女ãžéãããããŒã¿ã®è»¢éé床ãæå€§åããããã«éã¶ãã®ãšããïŒ å
¥ååœ¢åŒ å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ N\ E\ Q\\ F_1\ T_1\\ F_2\ T_2\\ âŠ\\ F_E\ T_E\\ M_1\ A_1\ B_1\\ M_2\ A_2\ B_2\\ ...\\ M_Q\ A_Q\ B_Q\\ N ã¯åç»ãµã€ããšãã³ã®éå¥³ã®æã€ã³ã³ãã¥ãŒã¿ãå«ãã転éè£
çœ®ã®æ°ã§ããïŒçªå·ã 1 ã§ãã転éè£
眮ã¯åç»ãµã€ãã§ããïŒçªå·ã N ã§ãã転éè£
眮ã¯ãã³ã®éå¥³ã®æã€ã³ã³ãã¥ãŒã¿ã§ããïŒ E ã¯åæç¶æ
ã§æ¥ç¶ãããŠãã転éè£
眮ã®çµã¿åããã®æ°ã§ããïŒ Q ã¯ã€ã³ã¿ãŒããããå€åããåæ°ã§ããïŒåæã®ã€ã³ã¿ãŒããã㯠F_i ãš T_i ã転éé床 1 ã§åæ¹åã«æ¥ç¶ãããŠããããšã衚ãïŒ ãããã¯ãŒã¯ã®å€åã¯æç³»åé ã«äžãããïŒ j çªç®ã®å€å㯠M_j ã 1 ã§ããã° A_j,\ B_j éãã€ãªãããããšã衚ãïŒ M_j ã 2 ã§ããã° A_j,\ B_j éã®æ¥ç¶ãåããããšã衚ãïŒ åºååœ¢åŒ åå€åã®çŽåŸã«ãããïŒåç»ãµã€ããããã³ã®éå¥³ã®æã€ã³ã³ãã¥ãŒã¿ãŸã§ã®è»¢éé床ãåºåããïŒ å¶çŽ 2 \leq N \leq 500 0 \leq E \leq 20,000 1 \leq Q \leq 1,000 1 \leq F_i \leq N,\ 1 \leq T_i \leq N,\ F_i \neq T_i \ (1 \leq i \leq E) ãã¹ãŠã® \{F_i, T_i\} ã®ãã¢ã¯ç°ãªãïŒ 1 \leq M_j \leq 2,\ 1 \leq A_j \leq N\ ,\ 1 \leq B_j \leq N\ ,\ A_j \neq B_j (1 \leq j \leq Q) ãããã¯ãŒã¯ã®ã©ã®æ®µéã«ãããŠã次ã®ããšãæãç«ã€ : ã©ã® 2 ã€ã®è»¢éè£
眮ã®éãé«ã
1 ã€ã®åç·ã§ããç¹ãããŠããªãïŒ 2 ã€ã®è»¢éè£
眮ã®éãæ¢ã«ç¹ãããŠããç¶æ
ã§ãããã®éãæ¥ç¶ãããããªã¯ãšãªãæ¥ããïŒ 2 ã€ã®è»¢éè£
眮ã®éãåç·ã§ç¹ãããŠããªãç¶æ
ã§ãããã®éã®æ¥ç¶ãåããããªã¯ãšãªãæ¥ãããšã¯ãªãïŒ å
¥åºåäŸ å
¥åäŸ 1 2 1 2 1 2 2 1 2 1 2 1 åºåäŸ1 0 1 æåã®å€åã®åŸïŒãã³ã®é女ã®ã³ã³ãã¥ãŒã¿ãšåç»ãµã€ãã¯ç¹ãããªããªã£ãŠããã®ã§è»¢éé床㯠0 ã§ããïŒ 2 床ç®ã®å€åã®åŸã¯äž¡è
ã¯çŽæ¥ç¹ãã£ãŠããïŒè»¢éé床㯠1 ã«ãªãïŒ å
¥åäŸ 2 3 0 4 1 2 3 1 2 1 1 3 1 2 2 3 åºåäŸ 2 0 1 2 1 å
¥åäŸ 3 6 4 8 1 2 1 3 4 6 5 6 1 2 4 1 3 5 1 2 5 1 3 4 2 2 4 2 3 5 1 2 4 2 2 1 åºåäŸ 3 1 2 2 2 2 2 2 1 å
¥åäŸ 4 12 38 6 1 2 1 3 1 4 1 5 2 3 2 4 2 5 2 6 2 7 2 8 2 12 3 4 3 5 3 6 3 7 3 8 4 5 4 6 4 7 4 8 5 6 5 7 5 8 6 7 6 8 6 9 6 10 6 12 7 8 7 9 7 10 8 9 8 10 9 10 9 11 9 12 10 11 11 12 2 6 12 2 9 12 1 9 12 1 6 12 2 6 12 1 6 12 åºåäŸ 4 3 2 3 4 3 4 Problem Setter: Flat35 | 36,651 |
Problem C: Live Schedule YOKARI TAMURAã¯å
šåœçã«æåãªã¢ãŒãã£ã¹ãã§ããã仿YOKARI㯠D æ¥éã«ããã£ãŠã©ã€ããã¢ãŒãè¡ãããã¢ãŒã®ã¹ã±ãžã¥ãŒã«ã®æ±ºå®ã«ãããŠãã®åœã C çš®é¡ã®å°åã§ããããYOKARIãããå°åã§ã©ã€ããè¡ãããšã«ããå©çãåŸãããããã¯æ£ã®æŽæ°ã§è¡šããããYOKARIã¯ååãšã㊠1 æ¥ã«æå€§ 1 ã€ãŸã§ã©ã€ããè¡ãããã ããããå°åã§ã©ã€ããè¡ã£ãåŸã飿¥ããå°åã§ã©ã€ããè¡ããå Žåã¯ãã®å°åã§åãæ¥ã«åã³ã©ã€ããè¡ãããšãã§ããããã®æ¡ä»¶ãæºããéããå°åãç§»åããªããäœåºŠãã©ã€ããè¡ãããšãã§ããããŸããåãæ¥ã«åãå°åã§ã©ã€ãã 2 床以äžè¡ãããšã¯ã§ããªããããã«ãåãæ¥ã« 2 å以äžã®ã©ã€ããè¡ãæ¥ã®æ°ã¯ãã¢ãŒæéäžåèš X 以äžã§ãªããã°ãªããªãã ããªãã¯YOKARIã®é¢ä¿è
ã§ããã圌女ã®ã©ã€ããã¢ãŒã®ã¹ã±ãžã¥ãŒã«ã仮決ãããªããŠã¯ãªããªããã©ã®æ¥ã«ã©ã®å°åã§ã©ã€ããè¡ãã°ãã£ãšãæçã ãããããã ã 1 åã®ã©ã€ãããšã«YOKARIã«ã¯éè² ã®æŽæ°ã§è¡šãããè² æ
ããããããã¢ãŒæéäžã®åèšè² æ
㯠W 以å
ã§ãªããã°ãªããªããããªãã®ä»äºã¯åã©ã€ãã§YOKARIã«ãããè² æ
ãšæåŸ
ãããå©çãèªã¿èŸŒã¿ãã¹ã±ãžã¥ãŒã«ã仮決ãããŠãå©çåèšã®æå€§å€ãåºåããããšã§ããã Input å
¥åã¯è€æ°ã®ãã¹ãã±ãŒã¹ãããªãã ã²ãšã€ã®ãã¹ãã±ãŒã¹ã¯ä»¥äžã®åœ¢åŒã«åŸãã C D W X E 1,1 E 1,1 ⊠E 1,D E 2,1 E 2,1 ⊠E 2,D ⊠E C,1 E C,2 ⊠E C,D F 1,1 F 1,1 ⊠F 1,D F 2,1 F 2,1 ⊠F 2,D ⊠F C,1 F C,2 ⊠F C,D C ã¯å°åã®çš®é¡æ°ãD ã¯ãã¢ãŒæéã®é·ããW ã¯ãã®ãã¢ãŒã§YOKARIã«èš±å®¹ãããè² æ
ã®åèšã®æå€§å€ãX ã¯ãã¢ãŒæéäžã«ã©ã€ããåãæ¥ã« 2 床以äžè¡ããåèšæ¥æ°ã®äžéã§ããã E i,j ( 1 †i †C ã〠1 †j †D ) ã¯å°å i ã§ j æ¥ç®ã«ã©ã€ããè¡ãããšã§æåŸ
ãããå©çã§ãããE i,j ã 0 ã®ãšãå°å i ã§ j æ¥ç®ã«ã©ã€ããè¡ããªãããšã瀺ãã F i,j ( 1 †i †C ã〠1 †j †D ) ã¯å°å i ã§ j æ¥ç®ã«ã©ã€ããè¡ãããšã§YOKARIã«ãããè² æ
ã§ãããE i,j ã 0 ã®ãšãããã®å€ã¯0ã§ããã å°å i ã¯å°å i + 1 ãš i - 1 ããããã«é£æ¥ããããã ãå°å 1 ãšå°å C ( C > 2 ) ã¯é£æ¥ããªãã å
¥åã®çµããã¯ã4åã®0ãããããäžæåã®ç©ºçœã§åºåãããäžè¡ã§ç€ºãããã Constraints å
¥åã¯ãã¹ãп޿° 1 †C †15 1 †D †30 0 †W †50 0 †X †5 0 †E i,j †1,000 0 †F i,j †10 ãã¹ãã±ãŒã¹ã®æ°ã¯ 100 ãè¶
ããªãã Output åã±ãŒã¹ã«ä»ããã¹ã±ãžã¥ãŒã«ã仮決ãããŠæåŸ
ãããå©çåèšã®æå€§å€ã 1 è¡ã«åºåããã Sample Input 5 5 10 2 1 1 0 1 1 0 9 1 0 1 1 1 1 9 1 1 1 9 0 1 1 1 1 1 0 1 1 0 1 1 0 9 1 0 1 1 1 1 9 1 1 1 1 0 1 1 1 1 1 0 1 1 10 0 3 7 1 1 5 0 3 6 1 2 10 1 6 7 5 6 2 1 10 1 4 8 3 7 2 1 10 0 4 8 3 7 2 1 5 0 4 8 3 6 0 0 0 0 Sample Output 18 3 0 7 12 8 4 | 36,652 |
Separate String You are given a string $t$ and a set $S$ of $N$ different strings. You need to separate $t$ such that each part is included in $S$. For example, the following 4 separation methods satisfy the condition when $t = abab$ and $S = \{a, ab, b\}$. $a,b,a,b$ $a,b,ab$ $ab,a,b$ $ab,ab$ Your task is to count the number of ways to separate $t$. Because the result can be large, you should output the remainder divided by $1,000,000,007$. Input The input consists of a single test case formatted as follows. $N$ $s_1$ : $s_N$ $t$ The first line consists of an integer $N$ ($1 \leq N \leq 100,000$) which is the number of the elements of $S$. The following $N$ lines consist of $N$ distinct strings separated by line breaks. The $i$-th string $s_i$ represents the $i$-th element of $S$. $s_i$ consists of lowercase letters and the length is between $1$ and $100,000$, inclusive. The summation of length of $s_i$ ($1 \leq i \leq N$) is at most $200,000$. The next line consists of a string $t$ which consists of lowercase letters and represents the string to be separated and the length is between $1$ and $100,000$, inclusive. Output Calculate the number of ways to separate $t$ and print the remainder divided by $1,000,000,007$. Sample Input 1 3 a b ab abab Output for Sample Input 1 4 Sample Input 2 3 a b c xyz Output for Sample Input 2 0 Sample Input 3 7 abc ab bc a b c aa aaabcbccababbc Output for Sample Input 3 160 Sample Input 4 10 a aa aaa aaaa aaaaa aaaaaa aaaaaaa aaaaaaaa aaaaaaaaa aaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa Output for Sample Input 4 461695029 | 36,653 |
FizzBuzz ãFizz Buzzããšèšãããæ°åã䜿ã£ãã²ãŒã ããããŸãããã®ã²ãŒã ã¯è€æ°ã®ãã¬ã€ã€ãŒã§æ°åã1 ããé ã«ã²ãšã€ãã€æ°ãäžããŠãããã®ã§ãåãã¬ã€ã€ãŒã¯çŽåã®ãã¬ã€ã€ãŒãçºèšããæ¬¡ã®æ°åãã²ãšã€ã ãçºèšããŸãããã®æã3 ã§å²ãåããå Žå㯠ãFizzã, 5 ã§å²ãåããå Žå㯠ãBuzzããäž¡è
ã§å²ãåããå Žåã¯ãFizzBuzzããšæ°ã®ä»£ããã«çºèšããªããã°ãªããŸãããäŸãã°ãæåã® 16 ãŸã§ã®çºèšã¯ä»¥äžã®ããã«ãªããŸãã 1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, ã»ã»ã» 倪éåã¯åéãšãFizz BuzzããããŠéã¶ããšã«ããŸããã倪éåãã¡ã¯ã«ãŒã«ã次ã®ããã«æ±ºããŸããã ãééãã人ã¯è±èœããããã®æ¬¡ã®äººã¯ééããæ°ã®æ¬¡ã®æ°ããå§ãããã€ãŸãã1, 2, 3 ãšçºèšããå Žåã3 ã§ééããã®ã§æ¬¡ã¯ 4 ããå§ããããšã«ãªããã ãã®ã«ãŒã«ã«åŸã£ãŠã²ãŒã ãè¡ãã®ã§ãããã²ãŒã ã«æ
£ããŠããªããããééããããšã«æ°ä»ããªãããšããããå
¬å¹³ãªå€æãã§ããŸãããããã§ããªãã¯å€ªéåãã¡ããã®ã²ãŒã ãæ¥œãããããã«ã決ããããçºèšåæ°ãçµãã£ãæç¹ã§æ®ã£ãŠãã人ãåºåããããã°ã©ã ãäœæããããšã«ããŸããã ãã¬ã€ã€ãŒæ°ãã²ãŒã äžã«çºèšãããåæ°ãããããã®çºèšãå
¥åãšããå
¥åãçµãã£ãæç¹ã§æ®ã£ãŠãããã¬ã€ã€ãŒã®çªå·ãå°ããé ã«åºåããããã°ã©ã ãäœæããŠãã ããããã ãããã¬ã€ã€ãŒã«ã¯ 1 ããçªå·ãå²ãæ¯ãããŠãããçºèšé çªã 1 çªç®ã®ãã¬ã€ã€ãŒããé ã«è¡ããäžéãçºèšãçµãããšãå床 1 çªç®ã®ãã¬ã€ã€ãŒããçºèšããããšãšããŸããé çªã®åã£ãŠãããã¬ã€ã€ãŒãæ¢ã«è±èœããŠããå Žåã¯ããã®æ¬¡ã®ãã¬ã€ã€ãŒãçºèšããŸãããŸãããã®ããã°ã©ã ã¯ããã¬ã€ã€ãŒãäžäººã«ãªã£ãæç¹ã§ããã®åŸã®çºèšãç¡èŠããªããã°ãªããŸããã Input è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒããµãã€ã®è¡ã§ç€ºãããŸãã åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã m n s 1 s 2 : s n 1 è¡ç®ã«ãã¬ã€ã€ãŒæ° m (2 †m †1000) ãšçºèšåæ° n (1 †n †10000) ãäžããããŸãã ç¶ã n è¡ã« i çªç®ã®çºèš s 1 ãäžããããŸãã s i ã¯æŽæ°ãFizzãBuzzããŸã㯠FizzBuzz ã瀺ãæååïŒ8æå以äžïŒã§ãã ããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã Output å
¥åããŒã¿ã»ããããšã«ãæå®ãããçºèšåæ°ãŸã§å
¥åããããšãã«æ®ã£ãŠãããã¬ã€ã€ãŒã®çªå·ãå°ããé ã«åºåããŸãã Sample Input 5 7 1 2 Fizz 4 Buzz 6 7 3 5 1 2 3 4 5 0 0 Output for the Sample Input 2 3 4 5 1 | 36,654 |
Score : 200 points Problem Statement Takahashi loves palindromes. Non-palindromic strings are unacceptable to him. Each time he hugs a string, he can change one of its characters to any character of his choice. Given is a string S . Find the minimum number of hugs needed to make S palindromic. Constraints S is a string consisting of lowercase English letters. The length of S is between 1 and 100 (inclusive). Input Input is given from Standard Input in the following format: S Output Print the minimum number of hugs needed to make S palindromic. Sample Input 1 redcoder Sample Output 1 1 For example, we can change the fourth character to o and get a palindrome redooder . Sample Input 2 vvvvvv Sample Output 2 0 We might need no hugs at all. Sample Input 3 abcdabc Sample Output 3 2 | 36,655 |
é·å¹Žã®ç ç©¶ã®æ«ãã€ã¯ã¿åã¯æªæ¥äºç¥èœåãæã«å
¥ããïŒ åœŒããã®ç ç©¶ã«è²»ãããæéãééã¯è«å€§ãªãã®ã§ãã£ãããã€ãã«å ±ãããæããã£ãŠããã®ã ãæå§ãã«ééãåãæ»ããããã€ã¯ã¿åã¯æ ªåŒæè³ãå§ããããšã«ããã ã€ã¯ã¿åã¯çŸåšæ ªåŒã¯å
šãä¿æããŠãããã x åãææããŠããã圌ãæè³å¯Ÿè±¡ã«å®ããæ ªåŒã¯ n çš®é¡ã§ããããã«ã€ããŠä»æ¥ãã d æ¥åã®æ ªäŸ¡ãäºç¥ããããšã«æåããããã®çµæãé©ãã¹ãããšã«ä»æ¥ãã d æ¥éã¯æ¥äžã®æ ªäŸ¡å€åãå
šããªãããšã倿ãããã€ãŸãã仿¥ã1æ¥ç®ãšãããšãã® i ïŒ 1 †i †d ïŒæ¥ç®ã®æ ªåŒ j ïŒ 1 †j †n ïŒã®æ ªäŸ¡ p i,j åãããã£ãŠãããã€ã¯ã¿åã¯ããããã®æ¥ã«èªç±ã«æ ªåŒã売買ã§ãããããªãã¡ãä»»æã®æç¹ã§ä»¥äžã®æäœïŒè³Œå
¥ã»å£²åŽïŒãä»»æã®é çªã§ä»»æã®åæ°è¡ããããã ããåæäœã®ååŸã§ã®ææéãšæ ªåŒã®ä¿æåäœæ°ã¯éè² æŽæ°ã§ãªããã°ãªããªãã 賌å
¥ : i æ¥ç®ã«ãæ ªåŒã®çš®é¡ j ïŒ 1 †j †n ïŒãäžã€éžã³ãææé p i,j åãæ¯æã1åäœã®æ ªåŒ j ãåŸãã å£²åŽ : i æ¥ç®ã«ãæ ªåŒã®çš®é¡ j ïŒ 1 †j †n ïŒãäžã€éžã³ã1åäœã®æ ªåŒ j ãæ¯æã p i,j åãåŸãã ïŒåœŒãç ç©¶ã«æ²¡é ããéã«èšŒåžååŒã·ã¹ãã ã¯å€§ããªçºéãéããååŒææ°æã¯ããããªããªã£ããïŒ ã€ã¯ã¿åã¯å€§åŠã§æ
å ±ç§åŠãä¿®ããŠããããæªæ¥äºç¥ç ç©¶ã«æãæ®ããããã«å€§åŠã§åŠãã ããšããã¹ãŠå¿ããŠããŸã£ãŠããããããªåœŒã®ä»£ããã«æçµæ¥ã®ææéãæå€§åããããã°ã©ã ãæžããŠãããŠã»ããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã n d x p 1,1 ... p 1,n ... p d,1 ... p d,n n : æ ªåŒã®çš®é¡æ° d : æ¥æ° x : 1æ¥ç®ã®ææé p i,j : i æ¥ç®ã®éæ j ã®æ ªäŸ¡ïŒä»æ¥ã1æ¥ç®ãšããïŒ Constraints å
¥åäžã®å倿°ã¯ä»¥äžã®å¶çŽãæºããæŽæ°ã§ããã 1 †n †10 1 †d †10 1 †x, p i,j †10 5 æçµæ¥ã®ææéã 10 5 以äžãšãªãããšãä¿èšŒãããŠããã Output æé©ã«æè³ããå Žåã®æçµæ¥ã®ææéã1è¡ã«åºåããã Sample Input 1 2 2 5 3 2 5 4 Output for the Sample Input 1 9 äŸãã°ãããããã®æ ªåŒã1åäœãã€è³Œå
¥ããŸãã Sample Input 2 1 2 5 6 10000 Output for the Sample Input 2 5 1åäœããå°ããååŒã¯ã§ããŸãããå°å£æè³å®¶ã®æ²åã§ãã Sample Input 3 2 3 5 4 5 6 3 8 5 Output for the Sample Input 3 11 1æ¥ç®ã¯1çš®é¡ç®ã®æ ªåŒã«ã2æ¥ç®ã¯2çš®é¡ç®ã®æ ªåŒã«æè³ããŸãã Sample Input 4 3 3 10 10 9 6 8 7 3 7 5 1 Output for the Sample Input 4 10 æ¯æ°ãæªãæããããŸãã | 36,656 |
Score : 500 points Problem Statement Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice. First, Takahashi created a tree with N vertices numbered 1 through N , and wrote 0 at each edge. Then, Aoki gave him M queries. The i -th of them is as follows: Increment the number written at each edge along the path connecting vertices a_i and b_i , by one. After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number. However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries. Determine whether there exists a tree that has the property mentioned by Takahashi. Constraints 2 †N †10^5 1 †M †10^5 1 †a_i,b_i †N a_i â b_i Input Input is given from Standard Input in the following format: N M a_1 b_1 : a_M b_M Output Print YES if there exists a tree that has the property mentioned by Takahashi; print NO otherwise. Sample Input 1 4 4 1 2 2 4 1 3 3 4 Sample Output 1 YES For example, Takahashi's graph has the property mentioned by him if it has the following edges: 1-2 , 1-3 and 1-4 . In this case, the number written at every edge will become 2 . Sample Input 2 5 5 1 2 3 5 5 1 3 4 2 3 Sample Output 2 NO | 36,657 |
Problem A: Ennichi çžæ¥ã«æ¥ããããã, ããåºåºã®ã²ãŒã ã®æ¯åããã£ãããã±ãŒãã§ããã®ãèŠã€ãã. ãã®ã²ãŒã ã®ã«ãŒã«ã¯ä»¥äžã®éãã§ãã. 瞊h ãã¹Ã 暪w ãã¹ã®æ Œåç¶ã®ãã£ãŒã«ãããã, åãã¹ã«ã€ãé«ã
1 åã®ãããã¯ã眮ããã. åãããã¯ã«ã¯ã¢ã«ãã¡ããã倧æå(âAâ - âZâ) ã®ããããã§è¡šãããè²ãã€ããŠãã. åè²ã®ãããã¯ã瞊ãŸãã¯æšªã«äžçŽç·äžã«n å以äžé£ç¶ããŠäžŠã¶ãš, ãããã®ãããã¯ã¯æ¶æ»
ãã. åå è
ã¯æšªã«é£ãåã2 ã€ã®ãã¹ãéžãã§, ãããã®ç¶æ
ãäºãã«å
¥ãæ¿ããæäœãã§ãã. ãããã¯ã®å
¥ãæ¿ã, æ¶æ»
, èœäžã«ãã£ãŠãããã¯ã®æããã¹ã®1 ã€äžã®ãã¹ã«ãããã¯ãç¡ããªããš, ãã®ãããã¯ã¯èœäžãã. ãã®ãšããµããã³åè²ã®ãããã¯ãn å以äžäžŠã¶ãšæ¶æ»
ãã. ãã ã, ãããã¯ã®æ¶æ»
ã¯, èœäžãããããã¯ãååšããéã¯èµ·ããã, ãã¹ãŠã®ãããã¯ã®èœäžãçµäºããã¿ã€ãã³ã°ã§åæã«èµ·ãã. 1 åã®æäœã§ãã£ãŒã«ãäžã®ãã¹ãŠã®ãããã¯ãæ¶æ»
ããããš, ãã®ã²ãŒã ã¯æåãšãªãæ¯åã®ã±ãŒããåŸãããšãã§ãã. ãããã¯1 ååã®åå è²»ã§ç¢ºå®ã«ã±ãŒããæã«å
¥ããã, ãããã§ããªãå Žåã¯åå ããããªã. ã²ãŒã éå§æã®ãã£ãŒã«ãã®ç¶æ
ãã, ãããããã®ã²ãŒã ã«åå ãã¹ãã§ãããçãã. Input å
¥åã®äžè¡ç®ã«ã¯h, w, n ãã¹ããŒã¹ã§åºåãããŠäžãããã. 2 †h , w , n †30 ç¶ã h è¡ã«ã¯ãã£ãŒã«ãã®ç¶æ
ãäžããé ã«äžãããã. ã¢ã«ãã¡ããã倧æåã¯ãããã¯ã, â.â ã¯ç©ºããã¹ã衚ã. äžãããããã£ãŒã«ãã®ç¶æ
ã«ã¯, 瞊ãããã¯æšªã« n å以äžé£ç¶ããåè²ã®ãããã¯ã¯ãªã, èœäžããç¶æ
ã«ãããããã¯ããªã. 1 å以äžã®ãããã¯ãååšãã. Output ãããããã®ã²ãŒã ã«åå ãã¹ãã§ãããªãâYESâã, ããã§ãªããªãâNOâãäžè¡ã«åºåãã. Sample Input 1 4 6 3 ...... ...Y.. ...Y.. RRYRYY Sample Output 2 YES Sample Input 1 4 6 3 ...... ...Y.. ...Y.. RRYRY. Sample Output 2 NO | 36,658 |
Problem L: Tree Fragments Problem ããã¡ããã¯ã$N$åã®é ç¹ãš$N-1$æ¬ã®èŸºãããªãæš$T$ãæã£ãŠãããåé ç¹ã«ã¯$1$ãã$N$ãŸã§ã®çªå·ãšãæ£ã®æŽæ°ã®éã¿ãã€ããŠããã æ¬¡ã®$Q$åã®ã¯ãšãªã«é ã«çããã $1 \le a_i,b_i \le N$($a_i \ne b_i$)ãäžããããã®ã§ã$T$ã®$a_i$-$b_i$ãã¹äžã®é ç¹ãšããã«æ¥ç¶ãã蟺ãåãé€ããŠã§ãããããã€ãã®é£çµæåã®äžã§ãéã¿ãæå€§ãšãªãé£çµæåã®éã¿ãåºåããããã®ãããªé£çµæåã1ã€ããªãå Žåã0ãšåºåããã ãã ããé£çµæåã®éã¿ã¯ãã®é£çµæåã«å«ãŸããé ç¹ã®éã¿ã®åã§å®çŸ©ãããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã $N$ $w_1$ $w_2$ ... $w_N$ $u_1$ $v_1$ $u_2$ $v_2$ ... $u_{N-1}$ $v_{N-1}$ $Q$ $a_1$ $b_1$ $a_2$ $b_2$ ... $a_Q$ $b_Q$ å
¥åã¯ãã¹ãп޿°ã§äžããããã 1è¡ç®ã«$T$ã®é ç¹æ°$N$ãäžããããã 2è¡ç®ã«é ç¹$i$($1 \le i \le N$)ã®éã¿$w_i$ã空çœåºåãã§äžããããã 3è¡ç®ä»¥éã®$N$-1è¡ã«èŸº$_i$($1 \le i \le N-1$)ã®ç«¯ç¹$u_i,v_i$ã空çœåºåãã§äžããããã $N$+2è¡ç®ã«ã¯ãšãªã®æ°$Q$ãäžããããã $N$+3è¡ç®ä»¥éã®$Q$è¡ã«ãã¯ãšãª$_i$($1 \le i \le Q$)ã衚ã$a_i,b_i$ã空çœåºåãã§äžããããã Constraints å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã $2 \le N \le 10^5$ $1 \le Q \le 10^5$ $1 \le w_i \le 10^8$($1 \le i \le N$) $1 \le u_i,v_i \le N$($1 \le i \le N-1$) $u_i \ne v_i$ $i \ne j$ãªã$(u_i,v_i) \ne (u_j,v_j)$ãã€$(u_i,v_i) \ne (v_j, u_j)$ $1 \le a_i,b_i \le N$($1 \le i \le Q$) $a_i \ne b_i$ Ouput ã¯ãšãªæ¯ã«ã0ãŸãã¯éã¿ãæå€§ãšãªãé£çµæåã®éã¿ã1è¡ã«åºåããã Sample Input 1 10 1 2 3 4 5 6 7 8 9 10 1 2 2 3 3 4 3 5 2 6 6 7 2 8 8 9 8 10 3 3 8 7 1 7 10 Sample Output 1 13 27 12 Sample Input 2 5 1 2 3 4 5 1 2 2 3 3 4 4 5 3 1 2 1 5 2 4 Sample Output 2 12 0 5 Sample Input 3 15 3 8 4 2 6 5 1 2 10 3 4 2 6 1 1 1 2 2 3 3 4 3 5 2 6 6 7 6 8 1 9 9 10 10 11 10 12 9 13 13 14 13 15 5 1 1 2 7 6 10 1 15 3 4 Sample Output 3 28 30 12 28 46 | 36,660 |
åºçŸé »åºŠæäœ æéæ°åã®å€ææäœã«åºçŸé »åºŠæäœãšãããã®ããããŸããæ°å $S = \{s_1, s_2,... s_n\}$ ã®å€æçµæã¯åãé·ãã®æ°åãšãªããŸãããã®çµæã $C = \{c_1,c_2, ..., c_n\}$ ãšãããšã $c_i$ ã¯æ°å $S$ ã«ããã $s_i$ ã®åæ°ã衚ããŸãã äŸãã° $S = \{3,4,1,5,9,2,6,5,3\}$ ãªãã° $C = {2,1,1,2,1,1,1,2,2}$ ãšãªããŸããããã«ãã®æ°å $C$ ã«åºçŸé »åºŠæäœãè¡ããš $P = \{4,5,5,4,5,5,5,4,4\}$ ãåŸãŸãããã®æ°åã¯åºçŸé »åºŠæäœã§å€ããããšããããŸããããã®ãããªæ°å $P$ ãæ°å $S$ ã®äžåç¹ãšåŒã³ãŸããã©ã®ãããªæ°åã«å¯ŸããŠãåºçŸé »åºŠæäœãç¹°ãè¿ãã°ããã®äžåç¹ãæ±ããããšãåºæ¥ããšããããšãç¥ãããŠããŸãã äžã®äŸã¯åºçŸé »åºŠæäœã®æé ã瀺ãããã®ã§ãã1 è¡ç®ãæ°å $S$ ã2 è¡ç®ãæ°å $C$ãæçµè¡ãæ°å $P$ ãšããŸããæ°å $S$ ã®æåã®èŠçŽ ($s_1 = 2$) ãšåãæ°ã¯ 3 åããã®ã§æ°å $C$ ã®æåã®èŠçŽ $c_1$ 㯠3ãæ¬¡ã®èŠçŽ ($s_2 = 7$) ãšåãæ°ã¯ 2 åããã®ã§ $c_2 = 2$ããšãã£ãå
·åã«åæ°ãæ°ã $c_i$ ãæ±ããŠãããŸãã æ°åã®é·ã $n$ ãšæ°å $S$ ãå
¥åããäžåç¹ã®æ°å $P$ ããã³ã$P$ ãåŸãããã«å®è¡ããåºçŸé »åºŠæäœã®æå°ã®åæ°ãåºåããããã°ã©ã ãäœæããŠãã ããã Input è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã $n$ $s_1$ $s_2$ ... $s_n$ 1 è¡ç®ã«æ°åã®é·ããè¡šãæŽæ° $n$ ($n \leq 12$) ãäžããããŸããïŒè¡ç®ã«æ°å $S$ ã®èŠçŽ ãè¡šãæŽæ° $s_i$ ($1 \leq s_i \leq 100$) ã空çœåºåãã§äžããããŸãã å
¥åã¯ïŒäžã€ã®è¡ã§çµãããŸããããŒã¿ã»ããã®æ°ã¯ 200 ãè¶
ããŸããã Output åããŒã¿ã»ããã«ã€ããŠãïŒè¡ç®ã«åºçŸé »åºŠæäœã®æå°ã®å®è¡åæ°(æŽæ°)ãïŒè¡ç®ã«å¯Ÿå¿ããäžåç¹ã®æ°å $P$ ã®èŠçŽ $p_1$, $p_2$, ..., $p_n$ ã空çœåºåãã§åºåããŠãã ããã Sample Input 10 4 5 1 1 4 5 12 3 5 4 0 Output for the Sample Input 3 6 6 4 4 6 6 4 4 6 6 | 36,661 |
Score : 100 points Problem Statement Consider placing N flags on a line. Flags are numbered through 1 to N . Flag i can be placed on the coordinate X_i or Y_i . For any two different flags, the distance between them should be at least D . Decide whether it is possible to place all N flags. If it is possible, print such a configulation. Constraints 1 \leq N \leq 1000 0 \leq D \leq 10^9 0 \leq X_i < Y_i \leq 10^9 All values in Input are integer. Input Input is given from Standard Input in the following format: N D X_1 Y_1 X_2 Y_2 \vdots X_N Y_N Output Print No if it is impossible to place N flags. If it is possible, print Yes first. After that, print N lines. i -th line of them should contain the coodinate of flag i . Sample Input 1 3 2 1 4 2 5 0 6 Sample Output 1 Yes 4 2 0 Sample Input 2 3 3 1 4 2 5 0 6 Sample Output 2 No | 36,662 |
ããã® JOI å (Snake JOI) åé¡ ããã® JOI åã¯ïŒãã倧ããªå±æ·ã«è¿·ã蟌ãã§ããŸã£ãïŒå±æ·ã®äœäººã«èŠã€ããåã«ïŒå±æ·ãè±åºããªããã°ãªããªãïŒ ãã®å±æ·ã«ã¯éšå±ã N åããïŒ1, 2, ..., N ã®çªå·ãä»ããããŠããïŒãŸãïŒå»äžã M æ¬ããïŒi æ¬ç®ã®å»äž (1 ⊠i ⊠M) ã¯éšå± A i ãšéšå± B i ãçµãã§ããïŒJOI åã¯ãããã®å»äžãã©ã¡ãã®åãã«ãéãããšãã§ãïŒå»äž i ãéãã®ã«ã¯ D i åãããïŒéšå±ãšéšå±ã®éãå»äžãéã以å€ã®ææ®µã§ç§»åããæ¹æ³ã¯ãªãïŒ ãã®å±æ·ã®éšå±ã®æž©åºŠã¯ããããäžå®ã«èª¿ç¯ãããŠããïŒJOI åã«ãšã£ãŠå¯ããããïŒå¿«é©ã§ãããïŒæããããã§ããïŒJOI åã¯ïŒæ¥ãªæž©åºŠå€åã«å¯Ÿå¿ã§ããªãããïŒæåŸã«å¯ãããéšå±ãåºãŠãã X åæªæºã®ãã¡ã«æãããéšå±ã«å
¥ãããšã¯ã§ããªãïŒåæ§ã«ïŒæåŸã«æãããéšå±ãåºãŠãã X åæªæºã®ãã¡ã«å¯ãããéšå±ã«å
¥ãããšãã§ããªãïŒ JOI åã¯ïŒç§»åäžã«éšå±ã«å
¥ããšããã«éšå±ããåºãªããã°ãªããªãïŒãŸãïŒå»äžã®éäžã§åŒãè¿ãããïŒå»äž i ã D i åããé·ãæéãããŠéãããšãã§ããªãïŒãã ãïŒäžåºŠèšªããéšå±ã«ããäžåºŠå
¥ãããšãïŒäžåºŠäœ¿ã£ãå»äžãããäžåºŠäœ¿ãããšã¯èš±ãããïŒ JOI åã¯çŸåšéšå± 1 ã«ããïŒãã®éšå±ã¯ JOI åã«ãšã£ãŠå¯ãããïŒJOI åã¯å±æ·ã®åºå£ã®ããéšå± N ã«å
¥ããšïŒå±æ·ããè±åºã§ããïŒ JOI åã屿·ããè±åºããã®ã«ãããæçã®æéãæ±ããïŒ å
¥å å
¥å㯠1 + N + M è¡ãããªãïŒ 1 è¡ç®ã«ã¯ïŒ3 åã®æŽæ° N, M, X (2 ⊠N ⊠10000, 1 ⊠M ⊠20000, 1 ⊠X ⊠200) ã空çœãåºåããšããŠæžãããŠããïŒããã¯ïŒå±æ·ã« N åã®éšå±ãš M æ¬ã®å»äžãããïŒJOI åãæž©åºŠå€åã«å¯Ÿå¿ããã®ã« X åãããããšã衚ãïŒ ç¶ã N è¡ã®ãã¡ã® i è¡ç® (1 ⊠i ⊠N) ã«ã¯ïŒéšå± i ã®æž©åºŠãè¡šãæŽæ° T i (0 ⊠T i ⊠2) ãæžãããŠããïŒJOI åã«ãšã£ãŠéšå± i ã¯ïŒT i = 0 ã®ãšãå¯ããïŒT i = 1 ã®ãšãå¿«é©ã§ããïŒT i = 2 ã®ãšãæãããïŒT 1 = 0 ã§ããããšãä¿èšŒãããŠããïŒ ç¶ã M è¡ã®ãã¡ã® j è¡ç® (1 ⊠j ⊠M) ã«ã¯ïŒ3 åã®æŽæ° A j , B j , D j (1 ⊠A j < B j ⊠N, 1 ⊠D j ⊠200) ã空çœãåºåããšããŠæžãããŠããïŒããã¯ïŒå»äž j ãéšå± A j ãšéšå± B j ãçµãã§ããïŒéãã®ã« D j åãããããšã衚ãïŒåãéšå±ã®çµãçµã¶å»äžãè€æ°ããå¯èœæ§ãããããšã«æ³šæããïŒ äžããããå
¥åããŒã¿ã§ã¯ïŒJOI åã屿·ããè±åºã§ããããšã¯ä¿èšŒãããŠããïŒ åºå JOI åã屿·ããè±åºããã®ã«æçã§äœåãããããè¡šãæŽæ°ã 1 è¡ã§åºåããïŒ å
¥åºåäŸ å
¥åäŸ 1 8 10 4 0 1 1 2 1 1 2 0 1 2 1 1 3 1 2 3 3 2 4 5 3 4 1 4 5 1 5 6 1 5 8 1 1 7 2 7 8 2 åºåäŸ 1 9 å
¥åäŸ 2 15 25 4 0 1 1 0 2 1 0 1 1 2 0 0 1 0 1 8 11 1 7 10 1 12 14 1 3 8 1 1 5 1 3 9 1 3 8 1 1 5 1 6 15 1 11 12 1 2 14 1 7 10 1 11 12 1 5 13 1 2 8 1 1 4 1 2 11 1 5 6 1 1 13 1 6 12 1 5 10 1 9 13 1 4 10 1 3 12 1 7 13 1 åºåäŸ 2 6 å
¥åäŸ 1 ã§ã¯ïŒéšå±ã 1 â 2 â 3 â 4 â 5 â 6 â 5 â 8 ã®é ã«ç§»åããã®ãæçãšãªãïŒ å
¥åäŸ 2 ã§ã¯ïŒããã€ãã®éšå±ã®çµ (ããšãã°éšå± 1 ãšéšå± 5) ãçµã¶å»äžãè€æ°ããïŒ æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒäœ ã第 16 åæ¥æ¬æ
å ±ãªãªã³ãã㯠JOI 2016/2017 äºéžç«¶æèª²é¡ã | 36,663 |
Problem Statement One day (call it day 0), you find a permutation $P$ of $N$ integers written on the blackboard in a single row. Fortunately you have another permutation $Q$ of $N$ integers, so you decide to play with these permutations. Every morning of the day 1,2,3,... , you rewrite every number on the blackboard in such a way that erases the number $x$ and write the number $Q_x$ at the same position. Please find the minimum non-negative integer $d$ such that in the evening of the day $d$ the sequence on the blackboard is sorted in increasing order. Input The input consists of a single test case in the format below. $N$ $P_1$ $\ldots$ $P_N$ $Q_1$ $\ldots$ $Q_N$ The first line contains an integer $N$ ($1 \leq N \leq 200$). The second line contains $N$ integers $P_1,\ldots,P_N$ ($1 \leq P_i \leq N$) which represent the permutation $P$. The third line contains $N$ integers $Q_1,\ldots,Q_N$ ($1 \leq Q_i \leq N$) which represent the permutation $Q$. Output Print the minimum non-negative integer $d$ such that in the evening of the day $d$ the sequence on the blackboard is sorted in increasing order. If such $d$ does not exist, print -1 instead. It is guaranteed that the answer does not exceed $10^{18}$. Examples Input Output 6 2 3 1 4 5 6 3 1 2 5 4 6 4 6 1 2 3 4 5 6 3 1 2 5 4 6 0 6 2 3 1 4 5 6 3 4 5 6 1 2 -1 | 36,664 |
Shuffle Your task is to shuffle a deck of n cards, each of which is marked by a alphabetical letter. A single shuffle action takes out h cards from the bottom of the deck and moves them to the top of the deck. The deck of cards is represented by a string as follows. abcdeefab The first character and the last character correspond to the card located at the bottom of the deck and the card on the top of the deck respectively. For example, a shuffle with h = 4 to the above deck, moves the first 4 characters "abcd" to the end of the remaining characters "eefab", and generates the following deck: eefababcd You can repeat such shuffle operations. Write a program which reads a deck (a string) and a sequence of h , and prints the final state (a string). Input The input consists of multiple datasets. Each dataset is given in the following format: A string which represents a deck The number of shuffle m h 1 h 2 . . h m The input ends with a single character '-' for the string. Constraints The length of the string †200 1 †m †100 1 †h i < The length of the string The number of datasets †10 Output For each dataset, print a string which represents the final state in a line. Sample Input aabc 3 1 2 1 vwxyz 2 3 4 - Sample Output aabc xyzvw | 36,665 |
Score : 500 points Problem Statement You are given a sequence with N integers: A = \{ A_1, A_2, \cdots, A_N \} . For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied: If A_i and A_j (i < j) are painted with the same color, A_i < A_j . Find the minimum number of colors required to satisfy the condition. Constraints 1 \leq N \leq 10^5 0 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N A_1 : A_N Output Print the minimum number of colors required to satisfy the condition. Sample Input 1 5 2 1 4 5 3 Sample Output 1 2 We can satisfy the condition with two colors by, for example, painting 2 and 3 red and painting 1 , 4 , and 5 blue. Sample Input 2 4 0 0 0 0 Sample Output 2 4 We have to paint all the integers with distinct colors. | 36,666 |
Score : 300 points Problem Statement Snuke and Raccoon have a heap of N cards. The i -th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y , respectively. They would like to minimize |x-y| . Find the minimum possible value of |x-y| . Constraints 2 \leq N \leq 2 \times 10^5 -10^{9} \leq a_i \leq 10^{9} a_i is an integer. Input Input is given from Standard Input in the following format: N a_1 a_2 ... a_{N} Output Print the answer. Sample Input 1 6 1 2 3 4 5 6 Sample Output 1 1 If Snuke takes four cards from the top, and Raccoon takes the remaining two cards, x=10 , y=11 , and thus |x-y|=1 . This is the minimum possible value. Sample Input 2 2 10 -10 Sample Output 2 20 Snuke can only take one card from the top, and Raccoon can only take the remaining one card. In this case, x=10 , y=-10 , and thus |x-y|=20 . | 36,667 |
Score : 300 points Problem Statement You are given a string S of length N and another string T of length M . These strings consist of lowercase English letters. A string X is called a good string when the following conditions are all met: Let L be the length of X . L is divisible by both N and M . Concatenating the 1 -st, (\frac{L}{N}+1) -th, (2 \times \frac{L}{N}+1) -th, ... , ((N-1)\times\frac{L}{N}+1) -th characters of X , without changing the order, results in S . Concatenating the 1 -st, (\frac{L}{M}+1) -th, (2 \times \frac{L}{M}+1) -th, ... , ((M-1)\times\frac{L}{M}+1) -th characters of X , without changing the order, results in T . Determine if there exists a good string. If it exists, find the length of the shortest such string. Constraints 1 \leq N,M \leq 10^5 S and T consist of lowercase English letters. |S|=N |T|=M Input Input is given from Standard Input in the following format: N M S T Output If a good string does not exist, print -1 ; if it exists, print the length of the shortest such string. Sample Input 1 3 2 acp ae Sample Output 1 6 For example, the string accept is a good string. There is no good string shorter than this, so the answer is 6 . Sample Input 2 6 3 abcdef abc Sample Output 2 -1 Sample Input 3 15 9 dnsusrayukuaiia dujrunuma Sample Output 3 45 | 36,668 |
C - ãœãŒã·ã£ã« å顿 ãããã N å¹ããïŒããŒãã䜿ã£ãŠå·ãæž¡ãããšããŠããïŒããŒã㯠K åããïŒèª°ãã©ã®ããŒãã«ä¹ãããé©åœã«æ±ºããŠä¹ãããšã«ããïŒ ãšããã§ããããšããã®ã¯äºãã®ä»²ã®è¯ãæªãã«ææã§ããïŒçã空éã«ä»²ã®æªãããããšäžç·ã«éã蟌ãããããšæ°åãæªãããŠããŸãïŒ ãã® N å¹ã®ãããã«ã€ããŠãäœçµãã®ãããã¯ä»²ãæªããšããããšãåãã£ãŠããïŒä»ã®å²ãåœãŠã§ã¯äœå¹ãã¯æ°åãæªãããŠããŸãå¯èœæ§ãããïŒ ãã£ãšè¯ãå²ãåœãŠãèããã®ããããšããã§ã¯ãããïŒã²ãšãŸãä»ã®å²ãåœãŠã§äœå¹ã®ããããæ°åãæªãããããæ±ããŠæ¬²ããïŒ å
¥ååœ¢åŒ å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ N K m 1 bunny 1,1 ... bunny 1,m 1 m 2 bunny 2,1 ... bunny 2,m 2 ... m K bunny K,1 ... bunny K,m K R p 1 q 1 ... p R q R N ã¯ããŒãã«ä¹ããããã®æ°ã§ããïŒ K ã¯ããŒãã®åæ°ã§ããïŒ m i ã¯ããŒã i ã«ä¹ããããã®æ°ã§ããïŒ bunny i,1 , ..., bunny i,m i ã¯ããŒã i ã«ä¹ããããã®çªå· (1 ä»¥äž N 以äž) ã衚ãïŒ R ã¯ä»²ã®æªããããã®çµã®åæ°ã衚ãïŒ p j , q j ã¯ããã p j ãšããã q j ã®ä»²ãæªãããšã衚ãïŒ åºååœ¢åŒ æ°åãæªããããããã®æ°ãåºåããïŒ å¶çŽ 1 †N †50 1 †K †N m 1 + ... + m K = N {bunny 1,1 , ..., bunny 1,m 1 , bunny 2,1 , ..., bunny K,m K } = {1, 2, ..., N} 0 †R †N(N-1)/2 1 †p j < q j †N çµ (p j , q j ) ã¯å
šãŠç°ãªãïŒ å
¥åå€ã¯ãã¹ãп޿°ã§ããïŒ å
¥åºåäŸ å
¥åäŸ 1 6 2 2 1 5 4 2 3 4 6 2 1 2 2 5 åºåäŸ 1 0 æ°åãæªãããŠãããããã¯ããªãïŒ å
¥åäŸ 2 6 2 2 1 5 4 2 3 4 6 3 2 3 3 4 1 2 åºåäŸ 2 3 å²ãåœãŠã¯äŸ 1 ãšåãã§ãããä»²ã®æªãã衚ãçµãç°ãªã£ãŠããïŒãã®äŸã§ã¯ããã 2,3,4 ãæ°åãæªãããŠããŸãïŒ å
¥åäŸ 3 10 3 3 4 1 9 3 10 5 2 4 3 8 7 6 9 3 4 1 2 1 9 6 8 1 6 1 8 6 7 6 10 7 8 åºåäŸ 3 5 Writer: æ¥ æ¬å
Tester: å°æµç¿å€ªé | 36,669 |
Problem B: Headstrong Student You are a teacher at a cram school for elementary school pupils. One day, you showed your students how to calculate division of fraction in a class of mathematics. Your lesson was kind and fluent, and it seemed everything was going so well - except for one thing. After some experiences, a student Max got so curious about how precise he could compute the quotient. He tried many divisions asking you for a help, and finally found a case where the answer became an infinite fraction. He was fascinated with such a case, so he continued computing the answer. But it was clear for you the answer was an infinite fraction - no matter how many digits he computed, he wouldnât reach the end. Since you have many other things to tell in todayâs class, you canât leave this as it is. So you decided to use a computer to calculate the answer in turn of him. Actually you succeeded to persuade him that he was going into a loop, so it was enough for him to know how long he could compute before entering a loop. Your task now is to write a program which computes where the recurring part starts and the length of the recurring part, for given dividend/divisor pairs. All computation should be done in decimal numbers. If the specified dividend/divisor pair gives a finite fraction, your program should treat the length of the recurring part as 0. Input The input consists of multiple datasets. Each line of the input describes a dataset. A dataset consists of two positive integers x and y , which specifies the dividend and the divisor, respectively. You may assume that 1 †x < y †1,000,000. The last dataset is followed by a line containing two zeros. This line is not a part of datasets and should not be processed. Output For each dataset, your program should output a line containing two integers separated by exactly one blank character. The former describes the number of digits after the decimal point before the recurring part starts. And the latter describes the length of the recurring part. Sample Input 1 3 1 6 3 5 2 200 25 99 0 0 Output for the Sample Input 0 1 1 1 1 0 2 0 0 2 | 36,670 |
Problem C: TransferTrain ããªãã¯é»è»ã«ä¹ãã®ã奜ãã§ãã. ããŸïŒããªãã¯é§
A ããé§
B ãžé»è»ã䜿ã£ãŠè¡ãããšããŠãã. ããªãã¯æ¥ãã§ããã®ã§, æçæéã®çµè·¯ãéžã¶ããšã«ãã. ãã ãïŒããªãã¯ä¹ãæããèŠæãªã®ã§, æçæéã®çµè·¯ãè€æ°ããå Žåã¯æãä¹ãæãåæ°ã®å°ãªãçµè·¯ãéžã¶ããšã«ãã. $N$ æ¬ã®è·¯ç·ããã. $i$ æ¬ç®ã®è·¯ç·ã¯ $a_i$ åã®é§
ãéã£ãŠãã. $i$ æ¬ç®ã®è·¯ç·ã®éãé§
åã¯éãé ã« $s_{i,0}, ... , s_{i,a_i -1}$ ã§ãã, é§
éã®æèŠæé㯠$t_{i,0}, ..., t_{i,a_i - 2}$ ã§ãã. é»è»ã¯è·¯ç·äžãäžäžæ¹åã«èµ°ã£ãŠãã, å
¥åã§äžããããéé ã«ä¹ãããšãã§ãã. è€æ°ã®è·¯ç·ã®åãé§
åã¯åãé§
ã衚ããŠããïŒä¹ãæããããããšãåºæ¥ã. ä¹ãæãã«ã¯é§
ãè·¯ç·ã«ããã $T$ åããã. äžæ¬ã®è·¯ç·ãåãé§
ãè€æ°åéãããšãããïŒããåãè·¯ç·ïŒåãé§
ã®ïŒè·¯ç·å
ã§ç°ãªãäœçœ®ã®é§
ã«ç§»åãããå Žåã¯ä¹ãæããããå¿
èŠããã. ããšãã°, C - D - E - F - D - G ãšããè·¯ç·ã䜿ã£ãŠ C ãã G ãŸã§è¡ãå Žå, å§ç¹ããçµç¹ãŸã§äžæ¬ã®é»è»ã§è¡ãããšãïŒD é§
ã§ä¹ãæã㊠C - D, D - G ãšä¹ãããšãã§ãã. ããªããé§
A ããé§
B ãžè¡ãã®ã«ãããæéãšä¹ãæãåæ°ãæ±ãã. é»è»ã¯ãšãŠãé »ç¹ã«æ¥ãã®ã§åŸ
ã¡æéã¯ç¡èŠããŠãã. Constraints $N$ will be between 1 and 50,000, inclusive. $T$ will be an integer between 1 and 1,000, inclusive. At least one train stops at A. At least one train stops at B. A and B will be distinct. $a_i$ will be bigger than or equal to 2. $a_1 + ... + a_N$ will be between 2 and 100,000, inclusive. $s_{i,j}$ will contain between 1 and 10 characters, inclusive. Each character in $s_{i,j}$ will be a letter ('A'-'Z', 'a'-'z'). $t_{i,j}$ will be an integer between 1 and 1,000, inclusive. Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžãããã: $N$ $T$ $A$ $B$ $a_1$ $s_{1,1}$ ... $s_{1,a_1}$ $t_{1,1}$ ... $t_{1,a_1 -1}$ ... $a_N$ $s_{N,1}$ ... $s_{N,a_N}$ $t_{N,1}$ ... $t_{N,a_N-1}$ Output ããªããé§
A ããé§
B ãžè¡ãã®ã«ãããæéãšä¹ãæãåæ°ã空çœã§åºåã£ãŠ1 è¡ã«åºåãã. Sample Input 1 2 10 Warsaw Petersburg 3 Kiev Moscow Petersburg 150 120 3 Moscow Minsk Warsaw 100 150 Sample Output 1 380 1 Sample Input 2 2 10 Warsaw Petersburg 3 Kiev Moscow Petersburg 150 120 2 Minsk Warsaw 150 Sample Output 2 -1 | 36,671 |
ãã¥ãŒã¿ãŠã³ äŒæŽ¥çã§ã¯äººå£å¢å ã®ããã«ãã¥ãŒã¿ãŠã³ãäœãããšã«ããŸããããã®ããã«ãæ°ãã«é·æ¹åœ¢ã®åå°ãéæãããã®åå°ãäœããšãããªãããã¹ãŠåã倧ããã®æ£æ¹åœ¢ãããªãåºç»ã«åºåãããšã決ããŸããããã®åå°ã®æŽåã«ã¯ãåºç»æ°ã«æ¯äŸããè²»çšãããããŸãããçãšããŠã¯ãã®è²»çšãæå°ã«ããããšèããŠããŸãã æ°ãã«éæããåå°ã®æ±è¥¿æ¹åãšååæ¹åã®é·ããšãïŒåºç»åœããã®æŽåè²»çšãäžãããããšãããã¹ãŠã®åºç»ãæŽåãããšãã«ããããæå°ã®æŽåè²»çšãæ±ããããã°ã©ã ãäœæããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã W H C å
¥åã¯ïŒè¡ã§ãããæ°ãã«éæããåå°ã®æ±è¥¿æ¹åã®é·ã W (1 †W †1000)ãšååæ¹åã®é·ã H (1 †H †1000)ãåºç»åœããã®æŽåè²»çš C (1 †C †1000)ãæŽæ°ã§äžããããã Output åå°ãæŽåããããã«å¿
èŠãªæå°ã®è²»çšãïŒè¡ã«åºåããã Sample Input 1 10 20 5 Sample Output 1 10 ïŒåã®æ£æ¹åœ¢ã§åå°ãäœããšãããªãåºåãããšãã§ããïŒåºç»åœããã®æŽåè²»çšãïŒãªã®ã§ãïŒïŒãš åºåããã Sample Input 2 27 6 1 Sample Output 2 18 ïŒïŒåã®æ£æ¹åœ¢ã§åå°ãäœããšãããªãåºåãããšãã§ããïŒåºç»åœããã®æŽåè²»çšãïŒãªã®ã§ãïŒïŒãšåºåããã | 36,672 |
Railway Connection Tokyo has a very complex railway system. For example, there exists a partial map of lines and stations as shown in Figure D-1. Figure D-1: A sample railway network Suppose you are going to station D from station A. Obviously, the path with the shortest distance is AâBâD. However, the path with the shortest distance does not necessarily mean the minimum cost. Assume the lines A-B, B-C, and C-D are operated by one railway company, and the line B-D is operated by another company. In this case, the path AâBâCâD may cost less than AâBâD. One of the reasons is that the fare is not proportional to the distance. Usually, the longer the distance is, the fare per unit distance is lower. If one uses lines of more than one railway company, the fares charged by these companies are simply added together, and consequently the total cost may become higher although the distance is shorter than the path using lines of only one company. In this problem, a railway network including multiple railway companies is given. The fare table (the rule to calculate the fare from the distance) of each company is also given. Your task is, given the starting point and the goal point, to write a program that computes the path with the least total fare. Input The input consists of multiple datasets, each in the following format. n m c s g x 1 y 1 d 1 c 1 ... x m y m d m c m p 1 ... p c q 1,1 ... q 1, p 1 -1 r 1,1 ... r 1, p 1 ... q c ,1 ... q c,p c -1 r c ,1 ... r c,p c Every input item in a dataset is a non-negative integer. Input items in the same input line are separated by a space. The first input line gives the size of the railway network and the intended trip. n is the number of stations (2 †n †100). m is the number of lines connecting two stations (0 †m †10000). c is the number of railway companies (1 †c †20). s is the station index of the starting point (1 †s †n ). g is the station index of the goal point (1 †g †n , g â s ). The following m input lines give the details of (railway) lines. The i -th line connects two stations x i and y i (1 †x i †n , 1 †y i †n , x i â y i ). Each line can be traveled in both directions. There may be two or more lines connecting the same pair of stations. d i is the distance of the i -th line (1 †d i †200). c i is the company index of the railway company operating the line (1 †c i †c ). The fare table (the relation between the distance and the fare) of each railway company can be expressed as a line chart. For the railway company j , the number of sections of the line chart is given by p j (1 †p j †50). q j,k (1 †k †p j -1) gives the distance separating two sections of the chart (1 †q j,k †10000). r j,k (1 †k †p j ) gives the fare increment per unit distance for the corresponding section of the chart (1 †r j,k †100). More precisely, with the fare for the distance z denoted by f j ( z ), the fare for distance z satisfying q j , k -1 +1 †z †q j , k is computed by the recurrence relation f j ( z ) = f j ( z -1)+ r j,k . Assume that q j ,0 and f j (0) are zero, and q j , p j is infinity. For example, assume p j = 3, q j ,1 = 3, q j ,2 = 6, r j ,1 = 10, r j ,2 = 5, and r j ,3 = 3. The fare table in this case is as follows. distance 1 2 3 4 5 6 7 8 9 fare 10 20 30 35 40 45 48 51 54 q j,k increase monotonically with respect to k . r j,k decrease monotonically with respect to k . The last dataset is followed by an input line containing five zeros (separated by a space). Output For each dataset in the input, the total fare for the best route (the route with the minimum total fare) should be output as a line. If the goal cannot be reached from the start, output "-1". An output line should not contain extra characters such as spaces. Once a route from the start to the goal is determined, the total fare of the route is computed as follows. If two or more lines of the same railway company are used contiguously, the total distance of these lines is used to compute the fare of this section. The total fare of the route is the sum of fares of such "sections consisting of contiguous lines of the same company". Even if one uses two lines of the same company, if a line of another company is used between these two lines, the fares of sections including these two lines are computed independently. No company offers transit discount. Sample Input 4 4 2 1 4 1 2 2 1 2 3 2 1 3 4 5 1 2 4 4 2 3 1 3 6 10 5 3 10 2 0 1 1 2 1 1 4 5 2 4 1 4 3 10 1 3 2 2 1 3 2 1 2 3 2 5 2 2 1 10 1 3 3 20 30 3 2 1 5 10 3 2 1 5 5 2 1 5 1 2 10 2 1 3 20 2 2 4 20 1 3 4 10 1 4 5 20 1 2 2 20 4 1 20 3 1 0 0 0 0 0 Output for the Sample Input 54 -1 63 130 | 36,673 |
G: å¡ãã ã / Paint å顿 æ
倪ãããšç«åããã¯ïŒ å¹³é¢ã®äžçã«ããåºä»ãã®å®¶ã«äœãã§ããïŒäºäººã¯ç¹ãšã¿ãªãïŒ åºã¯ $N$ é ç¹ã®åçŽå€è§åœ¢ (é£ãåããªãã©ã® $2$ 蟺ãäº€å·®ãæ¥è§Šãããªãå€è§åœ¢) ã®åœ¢ãããŠããïŒ ããæ¥ïŒäºäººã¯äžæ¬ã®äŒžã³çž®ã¿ããããŒã©ãŒãæã«å
¥ããïŒ ããŒã©ãŒã¯ç·åãšã¿ãªãïŒããŒã©ãŒãééããé åã«è²ãå¡ãããšãã§ããïŒ äºäººã¯ããŒã©ãŒã䜿ã£ãŠåºå
šäœã«è²ãå¡ããããšæã£ãŠããïŒ äœæ¥ã®åã«ïŒäºäººã¯ä»¥äžã®ãããªæºåãäžããé ã«è¡ãïŒ åºã®å
éšã®ä»»æã® $1$ ç®æã«æãæã€ïŒ åºã®å€éšã®ãã $1$ ç¹ã«éãŸãïŒ ååã«é·ãçŽãçšæãïŒçæ¹ã®ç«¯ãæ
倪ããïŒããäžæ¹ã®ç«¯ãç«åããã®äœã«çµã¶ïŒ æ
倪ãããããŒã©ãŒã®çæ¹ã®ç«¯ãïŒç«åãããããäžæ¹ã®ç«¯ãæã€ïŒ æºåãã§ãããïŒä»¥äžã®ã«ãŒã«ã«åŸã£ãŠå¡ãå§ããïŒ ãã ãïŒããŒã©ãŒã¯æã®äžç©ºãééãããããšãã§ãããïŒçŽã¯ã§ããªãïŒ åºã®ã©ã®éšåããå¡ãå§ããŠãããïŒ åºã®å€éšãŸãã¯åšäžãç§»åã§ãããïŒå
éšã«å
¥ã£ãŠã¯ãããªãïŒ å¡ãçµãããŸã§ããŒã©ãŒããæãé¢ããŠã¯ãããªãïŒ ããã«ïŒå¡ãçµãã£ããšãã«ä»¥äžã®æ¡ä»¶ãæºãããŠããªããã°ãªããªãïŒ äºäººãåã³ãã $1$ ç¹ã«éãŸã£ãŠããïŒ åºã®å
éšã®ä»»æã®ç¹ã®äžãããŒã©ãŒãééããŠããïŒ äºäººã®äœã®çŽãè§£ãïŒäž¡ç«¯ãçµãã§èŒªãäœãïŒãã®èŒªãå€ããåŒã£åŒµã£ããšãã«ïŒæã«åŒã£ããã£ãŠæããªãïŒ ããŠïŒäºäººã¯ã§ããã ãé¢ããããªãã®ã§ïŒå¡ã£ãŠããæäžã«ãšãäºäººã®è·é¢ã®æå€§å€ãæå°åãããïŒ äºäººã«ä»£ãã£ãŠãã®ãããªå€ãæ±ããŠã»ããïŒ å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ$N$ ã¯å€è§åœ¢ãæ§æããé ç¹ã®æ°ïŒ $(x_i,y_i)$ ã¯ããé ç¹ããå§ããŠæèšåããŸãã¯åæèšåãã«èŠããšãã® $i$ çªç®ã®ç¹ã®åº§æšã§ããïŒ $N$ $x_1 \ y_1$ $\vdots$ $x_N \ y_N$ å¶çŽ $3 \leq N \leq 50$ $|x_i|, |y_i| \leq 100$ å
šãп޿°ã§ãã é ç¹ã¯æèšåããŸãã¯åæèšåãã«äžãããã åºã®åœ¢ã¯åçŽå€è§åœ¢ã§ãã åšäžã®é£ç¶ãã $3$ ç¹ã¯äžçŽç·äžã«ååšããªã åºå çãã $1$ è¡ã§åºåããïŒ$10^{-5}$ æªæºã®çµ¶å¯Ÿèª€å·®ã¯èš±å®¹ãããïŒ ãµã³ãã« åãµã³ãã«ã§ã®åºã®åœ¢ãšå¡ãçµãããŸã§ã®ããŒã©ãŒã®åããå³ç€ºãããšä»¥äžã®ããã«ãªãïŒæŽæ°ã¯æå»ã衚ãïŒå³ç€ºããéœåäžããŒã©ãŒã®åãã¯é£ã³é£ã³ã«ç€ºããã,å®éã«ã¯é£ç¶çã«åããŠããïŒ ããŒã©ãŒã倪ããªã£ãŠããéšåã§è·é¢ã®æå€§å€ãéæããŠããïŒ ãµã³ãã«å
¥å1 4 0 0 0 1 1 1 1 0 ãµã³ãã«åºå1 1 ãµã³ãã«å
¥å2 3 0 0 0 1 1 0 ãµã³ãã«åºå2 0.7071067811865476 ãµã³ãã«å
¥å3 8 0 0 5 0 5 3 0 3 0 2 4 2 4 1 0 1 ãµã³ãã«åºå3 1.4142135623730951 | 36,674 |
åŠé£ 仿¥ã¯ïŒºå€§åŠã®ãªãŒãã³ãã£ã³ãã¹ã§ããæ¯å¹Žãã®æ¥ã®æŒäŒã¿ã«ã¯ã倧å¢ã®é«æ ¡çãã¡ãåŠé£ã«åãã€ãããŸããããã§ïŒºå€§åŠã®äºåå±ã¯ãè¡åã®é·ããæå€§ã§ã©ã®ãããã®è·é¢ã«ãªãããäºæž¬ããããšã«ããŸãããäºå調æ»ã®çµæã§ã以äžã®ããšãåãã£ãŠããŸãã è¡åã«ã¯ãããã 1 ãã N ãŸã§ã®çªå·ãæ¯ããã N 人ã䞊ã³ãŸãã C åã®é«æ ¡çã®ã㢠( a i , b i ) ããããã«ã€ããŠã以äžã®ïŒçš®é¡ã®å¶çŽããããŸãïŒ ïŒã€ç®ã®å¶çŽã¯é åºã«é¢ãããã®ã§ä»¥äžã®ããããã§ãïŒ a i 㯠b i ãããå
ããŸãã¯åãäœçœ®ã«äžŠã°ãªããŠã¯ãªããªã a i 㯠b i ãããåŸããŸãã¯åãäœçœ®ã«äžŠã°ãªããŠã¯ãªããªã a i 㯠b i ããå
ã§ããåãäœçœ®ã§ããåŸã§ããã ïŒã€ç®ã®å¶çŽã¯è·é¢ã«é¢ãããã®ã§ä»¥äžã®ããããã§ãïŒ a i ãš b i 㯠d i ã¡ãŒãã«ä»¥äžé¢ããªããã°ãªããªã a i ãš b i 㯠d i ã¡ãŒãã«ä»¥å
ã«äžŠã°ãªããã°ãªããªã ãŸããå
é ããåãè·é¢ã®å Žæã«è€æ°ã®äººã䞊ã¶ããšãã§ããè¡åã®å
é ã«ã¯åžžã«çªå· 1 ã®äººã䞊ã¶ããšãåãã£ãŠããŸãã äžãããã C åã®å¶çŽããã¹ãŠæºããè¡åã«ã€ããŠãå
é ããæåŸå°ŸãŸã§ã®è·é¢ãæå€§ãšãªããããªäžŠã³æ¹ãããå Žåã®è·é¢ãæ±ããããã°ã©ã ãäœæããŠãã ããããã ããã©ããŸã§ãé¢ããããšãã§ããå Žå㯠inf ãšãå¶çŽãæºããäžŠã³æ¹ãäžå¯èœãªå Žå㯠-1 ãšåºåããŠãã ããã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã N C constraint 1 constraint 2 : constraint C 1 è¡ç®ã«è¡åã«äžŠã¶é«æ ¡çã®äººæ° N (2 †N †100) ãšå¶çŽã®æ° C (0 †C †200) ãäžãããããç¶ã C è¡ã«åå¶çŽ constraint i ãæ¬¡ã®åœ¢åŒã§äžããããã a i o i b i s i d i å¶çŽã«ã¯ç©ºçœã¯å«ãŸããªãã a i , o i , b i , s i , d i ã®æå³ã以äžã«ç€ºãã a i ãš b i (1 †a i , b i †N ã〠a i â b i ) ã¯é«æ ¡çã®çªå·ã d i ã¯è·é¢ (0 †d †10000) ãè¡šãæŽæ°ã§ããã o i ã¯é åºã®å¶çŽãæå®ãã <= ã >= ã * ã®ããããã®æååã§ããã <= ã®å Žåã a i 㯠b i ãããå
ããŸãã¯åãäœçœ®ã«äžŠã°ãªããŠã¯ãªããªããã >= ã®å Žåã a i 㯠b i ãããåŸããŸãã¯åãäœçœ®ã«äžŠã°ãªããŠã¯ãªããªããã * ã®å Žåã a i 㯠b i ããå
ã§ããåãäœçœ®ã§ããåŸã§ããããããšãæå³ããããã ã o i ã * ãšãªãå¶çŽã¯ïŒå以äžäžããããããšã¯ãªãã s i ã¯è·é¢ã®å¶çŽãæå®ãã + ãŸã㯠- ã®æåã§ããã + ã®å Žåã a i ãš b i 㯠d i ã¡ãŒãã«ä»¥äžé¢ããªããã°ãªããªããã - ã®å Žåã a i ãš b i 㯠d i ã¡ãŒãã«ä»¥å
ã«äžŠã°ãªããã°ãªããªããããšãæå³ããã ãã ãããããã¢ã«å¯ŸããŠè€æ°ã®å¶çŽãäžããããããšã¯ãªããã®ãšããã åºå å
é ããæåŸå°ŸãŸã§ã®è·é¢ãïŒè¡ã«åºåããã å
¥åºåäŸ å
¥åäŸïŒ 3 2 1<=2-1 2<=3-2 åºåäŸïŒ 3 å
¥åäŸïŒ 3 3 1<=2-1 2<=3-2 1<=3+4 åºåäŸïŒ -1 å
¥åäŸïŒ 3 2 1<=2-2 2*3+1 åºåäŸïŒ inf | 36,675 |
é£åœ¢ ããã°ã©ããŒé€ææ ¡ã§ããã¢ã«ã髿 ¡ã§ã¯ãããŒã æŠã®ç«¶æããã°ã©ããŒã®åœ¹å²ã以äžã®ïŒã¿ã€ãã«åããŠããŸãã ïŒ£ïŒ ã³ãŒã㌠èšèªãçç¥ããŠãããã³ãŒãã£ã³ã°ãè¡ãã ïŒ¡ïŒ ã¢ã«ãŽãªãºã㌠è«ççæèãåŸæã§ãããã¢ã«ãŽãªãºã ãèããã ïŒ®ïŒ ããã²ãŒã¿ãŒ èªè§£åã«é·ããŠãããåé¡ã®åæã»ãããã°ãããã ãã®é«æ ¡ã§ã¯ä»¥äžã®ããããã®é£åœ¢ã§ïŒäººäžçµã®ããŒã ãæ§æããŠããŸãã ïŒ£ïŒ£ïŒ¡ïŒ ãã©ã³ã¹ããšããŠããå®å®å ïŒ£ïŒ£ïŒ£ïŒ ã¹ããŒããèŠèŸŒããããªã¹ã¯ã®é«ãéæ»å ïŒ£ïŒ¡ïŒ®ïŒ æ£ç¢ºã«åé¡ãè§£ãæ
éå ç«¶æããã°ã©ãã³ã°éšã®ã³ãŒãã§ããããªãã¯ããããã®éšå¡ãããŸãçµã¿åãããã§ããã ãå€ãã®ããŒã ãçµæã§ãããããæ¯å¹Žæ°ãé
ã£ãŠããŸããããã§ãã³ãŒããŒã®äººæ°ãã¢ã«ãŽãªãºããŒã®äººæ°ãããã²ãŒã¿ãŒã®äººæ°ãå
¥åãšããŠäžãããããšããæå€§äœããŒã äœããããåºåããããã°ã©ã ãäœæããŠãã ããã å
¥å å
¥åã¯1ã€ã®ããŒã¿ã»ãããããªããå
¥åããŒã¿ã¯ä»¥äžã®åœ¢åŒã§äžããããã Q c 1 a 1 n 1 c 2 a 2 n 2 : c Q a Q n Q 1è¡ç®ã® Q (0 †Q †100)ã¯ããŒã æ°ãæ±ããã幎æ°ã§ãããç¶ã Q è¡ã«å幎ã®åœ¹å²å¥ã®äººæ°ãäžãããããåè¡ã«ã¯ã³ãŒããŒã®äººæ° c i (0 †c i †1000)ãã¢ã«ãŽãªãºããŒã®äººæ° a i (0 †a i †1000)ãããã²ãŒã¿ãŒã®äººæ° n i (0 †n i †1000)ãäžããããã åºå 幎ããšã«ãäœæã§ããæå€§ã®ããŒã æ°ã1è¡ã«åºåããã å
¥åäŸ 4 3 0 0 1 1 1 9 4 1 0 1 2 åºåäŸ 1 1 4 0 | 36,676 |
Problem F: Chocolate with Heart Marks 倪éåã¯ãã§ã³ã¬ãŒãã倧奜ãã§, åŠæ ¡ããåž°ããšããŒãããŒã¯ãæããããæ°ã«å
¥ãã®æ¿ãã§ã³ãé£ã¹ãŸã, æè¿ã®æ¥œãã¿ã¯, ãã¹ãŠã®ããŒãããŒã¯ã®ãããã¯ãæåŸãŸã§æ®ãããã«é£ã¹ãããšã§ã. 倪éåã¯, ãã¹ãŠã®ããŒãããŒã¯ã®ãããã¯ãã€ãªãã£ããŸãŸ, ã§ããã ãå€ãã®ããŒãããŒã¯ã®ãªããããã¯ãé£ã¹ãããšããŸã. ããã倪éåã¯ãŸã 幌ã, äžèšã®ããã«é£ã¹ãããšããŠãç¡é§ãªãããã¯ãæ®ã£ãŠããŸããŸã. ããã§å€ªéåã¯, ãã¹ãŠã®ããŒãããŒã¯ã®ãããã¯ãã€ãªãã£ããŸãŸæ®ããšãã«é£ã¹ãããæå€§ã®ãããã¯æ°ãæ±ããããã°ã©ã ã®äœæãããªãã«äŸé ŒããŸãã. 倪éåã¯, ãã¹ãŠã®ããŒãããŒã¯ã®ãããã¯ãã€ãªãã£ãŠããéããã©ããªé£ã¹æ¹ãããŠãããŸããŸãã. ãããã¯ã®ããããäžèŸºãä»ã®ãããã¯ã«æ¥ããŠããªããšåãããŠããããšã«ãªããŸã. Input å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªããŸã. åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸã: H W H à W åã®æ°å H , W ã¯ããããæ¿ãã§ã³ã®çžŠã®ãµã€ãº, 暪ã®ãµã€ãºãç€ºãæŽæ°ã§ã. H à W åã®æ°åã¯ãããã¯ã®æ
å ±ã衚ã, ããŒãããŒã¯ã®ãªããããã¯ã衚ã ' 0 ', ããŒãããŒã¯ã®ãããã¯ã衚ã ' 1 ' ããæ§æãããŸã. å
¥åã®çµäºã¯, H = W = 0 ã§ããããŒã¿ã»ããã«ãã£ãŠç€ºãããŸã. ãã®ã±ãŒã¹ã«å¯ŸããŠåºåãããŠã¯ãããŸãã. 1 †H , W †12 ã§ãããããŒãããŒã¯ã®ãããã¯ã®æ°ã¯ 6 å以äžãšä»®å®ããŠããŸããŸãã. Output ããããã®ããŒã¿ã»ããã«å¯ŸããŠ, 倪éåãé£ã¹ãããæå€§ã®ãããã¯æ°ãåºåããŠãã ãã. Sample Input 4 4 1 0 0 0 0 0 1 0 0 1 0 0 1 0 0 1 1 1 1 2 3 1 0 0 0 0 1 0 0 Output for the Sample Input 7 0 2 | 36,677 |
D: 次å
æ
è¡ åé¡ æ¬¡å
ã $1$ 次å
ãã $N$ 次å
ãŸã§ååšããã AORã€ã«ã¡ããã¯æ¬¡å
éãç§»åã§ããã å
·äœçã«ã¯ãAORã€ã«ã¡ããã $i$ 次å
ã«ãããšãã $j$ 次å
( $i > j$ )ã«ã¯èªç±ã«ç§»åããäºãã§ãããã $k$ 次å
( $i < k$ )ã«ç§»åããã«ã¯éæ³ã䜿ãå¿
èŠãããã AORã€ã«ã¡ãã㯠$M$ çš®é¡ã®éæ³ã䜿ãã $1, 2, \dots, M$ ãšçªå·ãæ¯ãããŠããã $i$ çªç®ã®éæ³ã§ã¯ $a_i$ 次å
ãã $b_i$ 次å
ã«ç§»åã§ããã ãã㯠$a_i$ 次å
ã«ãããšããã䜿ããªãã $i$ 次å
ã«è¡ããšæ¬¡å
ç¹æã®ã次å
ã®åªãããåããã $i$ 次å
ã®ã次å
ã®åªããã«ãããAORã€ã«ã¡ãã㯠$d_i$ ãã¡ãŒãžãè² ãã $i$ 次å
ã®ã次å
ã®åªãããåããå Žåããã®åŸãã£ãšã $j$ 次å
( $i > j$ )ã®ã次å
ã®åªããã¯åããªãã AORã€ã«ã¡ããã $s$ 次å
ãã $t$ 次å
ã«ç§»åãããšãã è² ããã¡ãŒãžã®åèšã®æå°å€ãæ±ããã ãã ããAORã€ã«ã¡ããã¯æ¢ã« $s$ 次å
ã®ã次å
ã®åªããã¯åããŠããããã®ãã¡ãŒãžã¯èããªããã®ãšããã ãŸããAORã€ã«ã¡ãã㯠$t$ 次å
ã«è¡ããããšãä¿èšŒãããŠããã å¶çŽ $2 \leq N \leq 10^5$ $1 \leq M \leq min(10^5, N \times (N - 1) / 2)$ $1 \leq s, t \leq N$ $s \neq t$ $1 \leq d_i \leq 10^3$ $1 \leq a_i < b_i \leq N$ $i \neq j$ ã®ãšã $( a_i \neq a_j$ ãŸã㯠$b_i \neq b_j )$ ãã¿ãã å
¥åã¯å
šãп޿°ã§äžããããã å
¥ååœ¢åŒ å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã $N \ M \ s \ t$ $d_1 \dots d_N$ $a_1 \ b_1$ $a_2 \ b_2$ $\vdots$ $a_M \ b_M$ åºå AORã€ã«ã¡ãããåãããã¡ãŒãžã®åèšã®æå°å€ãåºåããããŸããæ«å°Ÿã«æ¹è¡ãåºåããã ãµã³ãã« ãµã³ãã«å
¥å 1 3 1 2 3 1 2 3 1 3 ãµã³ãã«åºå 1 3 ãµã³ãã«å
¥å 2 3 2 1 2 1 3 2 1 2 1 3 ãµã³ãã«åºå 2 2 ãµã³ãã«å
¥å 3 7 5 2 3 277 390 2 784 401 641 917 2 5 5 6 1 5 2 4 5 7 ãµã³ãã«åºå 3 401 | 36,679 |
å顿 2ã€ã®æŽæ° $A$ïŒ$B$ ãããã å鲿°ã§ã®çç®ã«ãã£ãŠ $A - B$ ãæ±ããåŠçã以äžã«ç€ºãã 1. $A$ïŒ$B$ ãå鲿°ã§è¡šçŸãããæ·»åã¯äžäœããé ã« $0,1,2,...,n-1$ ãšãã $A = A_{n-1} A_{n-2} ... A_{0}$ïŒ$B = B_{n-1} B_{n-2} ... B_{0}$ ãšããã $n$ ã¯å鲿°ã§è¡šçŸããæã®$A$ã®æ¡æ°ãšããã $B$ ã®æ¡æ°ã $n$ ããå°ãããšããäžäœæ¡ã« $0$ ãè£ãã 2. $borrow_{0} = 0$ ãšããã 3. 以äžã®åŠçã $i = 0$ ãã $n-1$ ãŸã§ç¹°ãè¿ãã 3.1. $A_{i} - borrow_{i} \geq B_{i}$ ãªãã°ã $C_{i} = A_{i} - borrow_{i} - B_{i}$ ïŒ $borrow_{i+1} = 0$ãšããã 3.2. $A_{i} - borrow_{i} \lt B_{i}$ ãªãã°ã $C_{i} = A_{i} - borrow_{i} + 10 - B_{i}$ ïŒ $borrow_{i+1} = 1$ãšããã $A - B$ ã®èšç®çµæã¯ $C_{n-1} C_{n-2} ... C_{0}$ ãšãªãããã ããæäžäœã«é£ç¶ãã $0$ ã¯åãé€ãã ç¹°ãäžãããå¿ãããš3.2ã®åŠçã§ã® $borrow_{i+1} = 1$ ã $borrow_{i+1} = 0$ ãšãªãã æå€§ $K$ åç¹°ãäžãããå¿ãããšãã®èšç®çµæã®æå€§å€ãæ±ããã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã«åŸããäžããããæ°ã¯å
šãп޿°ã§ããã $A$ $B$ $K$ å¶çŽ $1 \leq B \lt A \leq 10^9$ $1 \leq K \leq 9$ åºå èšç®çµæã®æå€§å€ã1è¡ã«åºåããã Sample Input 1 99 98 1 Output for the Sample Input 1 1 Sample Input 2 100 2 3 Output for the Sample Input 2 198 Sample Input 3 538 84 1 Output for the Sample Input 3 554 Sample Input 4 2012 1987 1 Output for the Sample Input 4 1025 | 36,680 |
Problem A: A White Wall Background ãšããéœåžã«äœãæ°ã®å®¶ã®æ·å°ã¯ãçã£çœãªå£ã«å²ãŸããŠãããå£ã«ç©è¶³ããªããæããæ°ã¯ãè¿æã®åäŸãã¡ãåŒãã§ãå£ãèªç±ã«å¡ã£ãŠãããããšã«ãããåäŸéã«ã¯ããããå£ã®å¥œããªåºéãéžãã§è²ãå¡ã£ãŠãããã ããŠãå£ã¯ã©ã®ããã«å¡ãããã ãããã Problem 0ã N -1ã®åºç»ã§æ§æããã以äžã®ãããªååã®çœãå£ãããã M 人ã®åäŸãã¡ããã®å£ã®éå§äœçœ® a ãšéå§äœçœ®ããã®é·ã L ãæå®ããåæèšåãã« a ãã (a+L) mod N ãŸã§è²ãå¡ã(ãã ãã a mod N ãšã¯ã a ã N ã§å²ã£ããšãã®äœãã衚ã)ãããã§ãä»ã®äººãè²ãå¡ã£ãåºéãšéããŠå¡ãããšãã§ãããã®å Žåã¯ãè²ãå¡ããã1ã€ã®åºéãšã¿ãªããè²ãå¡ãããåºéã倧ããé ã«åºåããããŸãããã®å€§ããã®åºéãããã€ããããåæã«åºåããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã N M a 0 L 0 a 1 L 1 ... a Mâ1 L Mâ1 1è¡ç®ã«ããããå£ã®é·ããšå£ã«è²ãå¡ãäººã®æ°ã衚ã2ã€ã®æŽæ° N , M ã空çœåºåãã§äžãããããç¶ã M è¡ã«ã¯ãå人ãè²ãå¡ãåºéã®éå§äœçœ® a i ãšé·ã L i ãäžããããã Constrains å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºãã 2 †N †100 1 †M †50 0 †a i < N 1 †L i †N Output è²ãå¡ãããåºéã®é·ããšãã®é·ãã®ç·æ°ãè²ãå¡ãããåºéã倧ããé ã«åºåããã Sample Input 1 5 3 0 1 2 1 3 1 Sample Output 1 2 1 1 1 Sample Input 2 4 2 0 2 1 2 Sample Output 2 3 1 Sample Input 3 10 3 2 1 4 1 9 2 Sample Output 3 2 1 1 2 | 36,681 |
Problem A: AOJ50M Problem AliceãšBobã50mèµ°ã§åè² ããŠããŸãã ãããããã®äžçã«ãããŠã¯AOJã®ã¬ãŒããé«ãæ¹ãåãã®ã§ãAOJã®ã¬ãŒããé«ãæ¹ãåã¡ãŸãã ã©ã¡ããäžæ¹ã§ãAOJã®ã¬ãŒããç¡ãå Žåã¯æ¯ã¹ãããç¡ãã®ã§ã仿¹ãªã50mèµ°ã®ã¿ã€ã ã§åè² ããŸãããã®å Žåã¯ã¿ã€ã ãçãæ¹ãåã¡ãšããŸãã AOJã®ã¬ãŒããåãå Žåã¯åŒãåãã50mèµ°ã®ã¿ã€ã ã§åè² ããªããã°ãªããªãå Žåã¯ã¿ã€ã ãåããªãåŒãåãã§ãã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã $T_1$ $T_2$ $R_1$ $R_2$ åèŠçŽ ã空çœåºåãã§äžããããã $T_1,T_2$ ã¯ããããAliceãBobã®50mèµ°ã®ã¿ã€ã ãã$R_1,R_2$ ã¯ããããAliceãBobã®AOJã®ã¬ãŒãã衚ãã ãã ãã$R_1=-1$ ã®ãšãã¯Aliceã®ã¬ãŒãããªãããšãã$R_2=-1$ ã®ãšãã¯Bobã®ã¬ãŒãããªãããšã瀺ãã Constraints å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã $1 \leq T_1,T_2 \lt 100 $ $-1 \leq R_1,R_2 \lt 2850 $ å
¥åã¯å
šãп޿°ã§ãã Output Aliceãåã€ãªããªã"Alice"ããBobãåã€ãªããªã"Bob"ããåŒãåãã§ããã°"Draw"ã$1$è¡ã«åºåããã Sample Input 1 9 8 1000 999 Sample Output 1 Alice Aliceã®æ¹ãAOJã®ã¬ãŒããé«ããããAliceã®åã¡ã§ãã Sample Input 2 9 8 1000 1000 Sample Output 2 Draw AliceãšBobã®AOJã®ã¬ãŒããåããããåŒãåãã§ãããã®å Žå50mèµ°ã®çµæã¯é¢ä¿ããªãããšã«æ³šæããŠãã ããã Sample Input 3 9 8 2849 -1 Sample Output 3 Bob Aliceã®ã¬ãŒãã¯é«ãã§ãããBobã®ã¬ãŒããç¡ããã50mèµ°ã®ã¿ã€ã ãçãBobã®åã¡ã§ãã | 36,682 |
Score: 100 points Problem Statement E869120's and square1001's 16 -th birthday is coming soon. Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-shaped pieces. E869120 and square1001 were just about to eat A and B of those pieces, respectively, when they found a note attached to the cake saying that "the same person should not take two adjacent pieces of cake". Can both of them obey the instruction in the note and take desired numbers of pieces of cake? Constraints A and B are integers between 1 and 16 (inclusive). A+B is at most 16 . Input Input is given from Standard Input in the following format: A B Output If both E869120 and square1001 can obey the instruction in the note and take desired numbers of pieces of cake, print Yay! ; otherwise, print :( . Sample Input 1 5 4 Sample Output 1 Yay! Both of them can take desired number of pieces as follows: Sample Input 2 8 8 Sample Output 2 Yay! Both of them can take desired number of pieces as follows: Sample Input 3 11 4 Sample Output 3 :( In this case, there is no way for them to take desired number of pieces, unfortunately. | 36,683 |
Score : 200 points Problem Statement You are given a string S . Each character of S is uppercase or lowercase English letter. Determine if S satisfies all of the following conditions: The initial character of S is an uppercase A . There is exactly one occurrence of C between the third character from the beginning and the second to last character (inclusive). All letters except the A and C mentioned above are lowercase. Constraints 4 †|S| †10 ( |S| is the length of the string S .) Each character of S is uppercase or lowercase English letter. Input Input is given from Standard Input in the following format: S Output If S satisfies all of the conditions in the problem statement, print AC ; otherwise, print WA . Sample Input 1 AtCoder Sample Output 1 AC The first letter is A , the third letter is C and the remaining letters are all lowercase, so all the conditions are satisfied. Sample Input 2 ACoder Sample Output 2 WA The second letter should not be C . Sample Input 3 AcycliC Sample Output 3 WA The last letter should not be C , either. Sample Input 4 AtCoCo Sample Output 4 WA There should not be two or more occurrences of C . Sample Input 5 Atcoder Sample Output 5 WA The number of C should not be zero, either. | 36,684 |
Score : 300 points Problem Statement There are N towns in a coordinate plane. Town i is located at coordinates ( x_i , y_i ). The distance between Town i and Town j is \sqrt{\left(x_i-x_j\right)^2+\left(y_i-y_j\right)^2} . There are N! possible paths to visit all of these towns once. Let the length of a path be the distance covered when we start at the first town in the path, visit the second, third, \dots , towns, and arrive at the last town (assume that we travel in a straight line from a town to another). Compute the average length of these N! paths. Constraints 2 \leq N \leq 8 -1000 \leq x_i \leq 1000 -1000 \leq y_i \leq 1000 \left(x_i, y_i\right) \neq \left(x_j, y_j\right) (if i \neq j ) (Added 21:12 JST) All values in input are integers. Input Input is given from Standard Input in the following format: N x_1 y_1 : x_N y_N Output Print the average length of the paths. Your output will be judges as correct when the absolute difference from the judge's output is at most 10^{-6} . Sample Input 1 3 0 0 1 0 0 1 Sample Output 1 2.2761423749 There are six paths to visit the towns: 1 â 2 â 3 , 1 â 3 â 2 , 2 â 1 â 3 , 2 â 3 â 1 , 3 â 1 â 2 , and 3 â 2 â 1 . The length of the path 1 â 2 â 3 is \sqrt{\left(0-1\right)^2+\left(0-0\right)^2} + \sqrt{\left(1-0\right)^2+\left(0-1\right)^2} = 1+\sqrt{2} . By calculating the lengths of the other paths in this way, we see that the average length of all routes is: \frac{\left(1+\sqrt{2}\right)+\left(1+\sqrt{2}\right)+\left(2\right)+\left(1+\sqrt{2}\right)+\left(2\right)+\left(1+\sqrt{2}\right)}{6} = 2.276142... Sample Input 2 2 -879 981 -866 890 Sample Output 2 91.9238815543 There are two paths to visit the towns: 1 â 2 and 2 â 1 . These paths have the same length. Sample Input 3 8 -406 10 512 859 494 362 -955 -475 128 553 -986 -885 763 77 449 310 Sample Output 3 7641.9817824387 | 36,685 |
Score : 100 points Problem Statement Dolphin loves programming contests. Today, he will take part in a contest in AtCoder. In this country, 24-hour clock is used. For example, 9:00 p.m. is referred to as " 21 o'clock". The current time is A o'clock, and a contest will begin in exactly B hours. When will the contest begin? Answer in 24-hour time. Constraints 0 \leq A,B \leq 23 A and B are integers. Input The input is given from Standard Input in the following format: A B Output Print the hour of the starting time of the contest in 24-hour time. Sample Input 1 9 12 Sample Output 1 21 In this input, the current time is 9 o'clock, and 12 hours later it will be 21 o'clock in 24-hour time. Sample Input 2 19 0 Sample Output 2 19 The contest has just started. Sample Input 3 23 2 Sample Output 3 1 The contest will begin at 1 o'clock the next day. | 36,686 |
Score : 300 points Problem Statement You are given integers N and K . Find the number of triples (a,b,c) of positive integers not greater than N such that a+b,b+c and c+a are all multiples of K . The order of a,b,c does matter, and some of them can be the same. Constraints 1 \leq N,K \leq 2\times 10^5 N and K are integers. Input Input is given from Standard Input in the following format: N K Output Print the number of triples (a,b,c) of positive integers not greater than N such that a+b,b+c and c+a are all multiples of K . Sample Input 1 3 2 Sample Output 1 9 (1,1,1),(1,1,3),(1,3,1),(1,3,3),(2,2,2),(3,1,1),(3,1,3),(3,3,1) and (3,3,3) satisfy the condition. Sample Input 2 5 3 Sample Output 2 1 Sample Input 3 31415 9265 Sample Output 3 27 Sample Input 4 35897 932 Sample Output 4 114191 | 36,687 |
Score : 400 points Problem Statement For an integer N , we will choose a permutation \{P_1, P_2, ..., P_N\} of \{1, 2, ..., N\} . Then, for each i=1,2,...,N , let M_i be the remainder when i is divided by P_i . Find the maximum possible value of M_1 + M_2 + \cdots + M_N . Constraints N is an integer satisfying 1 \leq N \leq 10^9 . Input Input is given from Standard Input in the following format: N Output Print the maximum possible value of M_1 + M_2 + \cdots + M_N . Sample Input 1 2 Sample Output 1 1 When the permutation \{P_1, P_2\} = \{2, 1\} is chosen, M_1 + M_2 = 1 + 0 = 1 . Sample Input 2 13 Sample Output 2 78 Sample Input 3 1 Sample Output 3 0 | 36,688 |
Problem F: Directional Resemblance Vectors have their directions and two vectors make an angle between them. Given a set of three-dimensional vectors, your task is to find the pair among them that makes the smallest angle. Input The input is a sequence of datasets. A dataset specifies a set of three-dimensional vectors, some of which are directly given in the dataset and the others are generated by the procedure described below. Each dataset is formatted as follows. m n S W x 1 y 1 z 1 x 2 y 2 z 2 : x m y m z m The first line contains four integers m , n , S , and W . The integer m is the number of vectors whose three components are directly specified in the dataset. Starting from the second line, m lines have the three components of m vectors. The i -th line of which indicates the vector v i = ( x i , y i , z i ). All the vector components are positive integers less than or equal to 100. The integer n is the number of vectors generated by the following procedure. int g = S; for(int i=m+1; i<=m+n; i++) { x[i] = (g/7) %100 + 1; y[i] = (g/700) %100 + 1; z[i] = (g/70000)%100 + 1; if( g%2 == 0 ) { g = (g/2); } else { g = (g/2) ^ W; } } For i = m + 1, . . . , m + n , the i -th vector v i of the set has three components x[i] , y[i] , and z[i] generated by this procedure. Here, values of S and W are the parameters S and W given in the first line of the dataset. You may assume 1 †S †10 9 and 1 †W †10 9 . The total number of vectors satisfies 2 †m + n †12 à 10 4 . Note that exactly the same vector may be specified twice or more in a single dataset. A line containing four zeros indicates the end of the input. The total of m+n for all the datasets in the input never exceeds 16 à 10 5 . Output For each dataset, output the pair of vectors among the specified set with the smallest non-zero angle in between. It is assured that there are at least two vectors having different directions. Vectors should be indicated by their three components. The output for a pair of vectors v a and v b should be formatted in a line as follows. x a y a z a x b y b z b Two vectors ( x a , y a , z a ) and ( x b , y b , z b ) are ordered in the dictionary order, that is, v a < v b if x a < x b , or if x a = x b and y a < y b , or if x a = x b , y a = y b and z a < z b . When a vector pair is output, the smaller vector in this order should be output first. If more than one pair makes the equal smallest angle, the pair that is the smallest among them in the dictionary order between vector pairs should be output. The pair ( v i , v j ) is smaller than the pair ( v k , v l ) if v i < v k , or if v i = v k and v j < v l . Sample Input 4 0 2013 1124 1 1 1 2 2 2 2 1 1 1 2 1 2 100 131832453 129800231 42 40 46 42 40 46 0 100000 7004674 484521438 0 0 0 0 Output for the Sample Input 1 1 1 1 2 1 42 40 46 83 79 91 92 92 79 99 99 85 | 36,689 |
Score : 200 points Problem Statement The word internationalization is sometimes abbreviated to i18n . This comes from the fact that there are 18 letters between the first i and the last n . You are given a string s of length at least 3 consisting of lowercase English letters. Abbreviate s in the same way. Constraints 3 †|s| †100 ( |s| denotes the length of s .) s consists of lowercase English letters. Input Input is given from Standard Input in the following format: s Output Print the abbreviation of s . Sample Input 1 internationalization Sample Output 1 i18n Sample Input 2 smiles Sample Output 2 s4s Sample Input 3 xyz Sample Output 3 x1z | 36,690 |
Multiplication of Big Integers II Given two integers $A$ and $B$, compute the product, $A \times B$. Input Two integers $A$ and $B$ separated by a space character are given in a line. Output Print the product in a line. Constraints $-1 \times 10^{200000} \leq A, B \leq 10^{200000}$ Sample Input 1 5 8 Sample Output 1 40 Sample Input 2 100 25 Sample Output 2 2500 Sample Input 3 -1 0 Sample Output 3 0 Sample Input 4 12 -3 Sample Output 4 -36 | 36,691 |
M: ãã¬ãŒã³ã (Presents) çœçŸœããã¯ããšããæªéã«ãµãã©ã€ãºãã¬ãŒã³ããšããŠæ¬¡ã®ãããªéåãçšæããã $N$ 以äžã®ç°ãªã $K$ åã®èªç¶æ°ãããªã ã©ã® 2 ã€ã®å€ã®çµãéåããéžãã§ããçæ¹ã®æ°ãããçæ¹ã®æ°ã§å²ãåãã å®ã¯ãã®ãããªéåã«ã¯æªéã®åãå¥ªãæ§è³ªãããããã®ãŸãŸã ãšåã倱ã£ãŠããŸãã æªéãå©ããããã«ããã®ãããªéåãããã€ãããèšç®ããã å
¥å 2 ã€ã®æŽæ° $N, K$ ã空çœåºåãã§äžããããã åºå æ¡ä»¶ãæºããéåã®åæ°ãåºåããã å¶çŽ $N$ 㯠$1$ ä»¥äž $100 \ 000$ 以äžã®æŽæ° $K$ 㯠$1$ ä»¥äž $N$ 以äžã®æŽæ° å
¥åäŸ1 6 3 åºåäŸ1 3 éå $(1,2,4), (1,2,6), (1,3,6)$ ãæ¡ä»¶ãæºããã å
¥åäŸ2 100000 7 åºåäŸ2 58848855 $N = 100 \ 000, K = 7$ ã®ãšããæ¡ä»¶ãæºããéå㯠$58 \ 848 \ 855$ éãããã | 36,692 |
C: è¶³ãç®æãç® / AddMul å顿 æ
倪ãã㯠a ãã z ãŸã§ã®æåãšïŒ è¶³ãç®ã®èšå· + ããç¥ããŸããïŒ æ
倪ããã«ã¯å§ã®ç«åãããããŸãïŒ ç«åããã¯ããã«å ããŠïŒæãç® * ãšæ¬åŒ§ ( ïŒ ) ïŒ ãã㊠1 ä»¥äž 9 以äžã®æŽæ° (æ°å) ãç¥ã£ãŠããŸãïŒ ãããïŒæ¬åŒ§ãå€éã«äœ¿çšããããšïŒæ¬åŒ§ã®äžã§æãç®ãè¡ãããšã¯ç¥ããŸããïŒ äŸãã°ïŒæ¬¡ã®ãããªæ°åŒããã£ããšããŸãïŒ a+a+a a+4*(b+c) a+3*(b+2*(c+d)) a-b a/b 11*a ãã®ãã¡ïŒæ
倪ãã㯠1. ã®ã¿ïŒç«åãã㯠1. ãš 2. ãæžãããšãã§ããŸãïŒ 3. ãã 6. ã¯äºäººãšãæžãããšãã§ããŸããïŒ ããæ¥ïŒæ
倪ããã¯æååãšããŠã®é·ãã $n$ ã®å€é
åŒ $S$ ãæžããŸããïŒ ã·ã§ãŒãã³ãŒããŒã®ç«åããã¯ïŒæãç®ãšæ¬åŒ§ãš 1 ä»¥äž 9 以äžã®æŽæ°ã䜿ã£ãŠïŒ$S$ ãæååãšããŠããçãæçãªå€é
åŒ $T$ ã«æžããªãããŠãããããšæã£ãŠããŸãïŒ ãããïŒããç°¡åã§ã¯ãªãããã§ãïŒ ããŠïŒç«åããã®ãããã«ïŒæååãšããŠæãçã $T$ ãäœãïŒ ãã®é·ããåºåããããã°ã©ã ãæžããŠãã ããïŒ å
¥å $N$ $S$ å¶çŽ $1 \leq N \leq 499$ $N$ ã¯å¥æ°ã§ãã $S$ 㯠a ãã z ãŸã§ã®ã¢ã«ãã¡ãããå°æåãš + ã®ã¿ãããªã $S$ ã®æåã®æåã¯ã¢ã«ãã¡ãããã§ããïŒãã®åŸ + ãšã¢ã«ãã¡ããã $1$ æåã亀äºã«äžŠã¶ $S$ ã«åãã¢ã«ãã¡ããã㯠$9$ å以äžããå«ãŸããªã åºå çãã $1$ è¡ã§åºåããŠãã ããïŒ ãµã³ãã« ãµã³ãã«å
¥å1 5 a+a+a ãµã³ãã«åºå1 3 a*3 ã® $3$ æåãæçã§ãïŒ ãµã³ãã«å
¥å2 9 a+a+b+a+b ãµã³ãã«åºå2 7 a*3+2*b ãŸã㯠a*3+b+b ã® $7$ æåãæçã§ãïŒ ãµã³ãã«å
¥å3 11 a+a+b+a+b+b ãµã³ãã«åºå3 7 (a+b)*3 ã§ $7$ æå ãµã³ãã«å
¥å4 3 a+a ãµã³ãã«åºå4 3 a+a ãŸã㯠a*2 ã§ $3$ æå | 36,693 |
Score : 200 points Problem Statement You are visiting a large electronics store to buy a refrigerator and a microwave. The store sells A kinds of refrigerators and B kinds of microwaves. The i -th refrigerator ( 1 \le i \le A ) is sold at a_i yen (the currency of Japan), and the j -th microwave ( 1 \le j \le B ) is sold at b_j yen. You have M discount tickets. With the i -th ticket ( 1 \le i \le M ), you can get a discount of c_i yen from the total price when buying the x_i -th refrigerator and the y_i -th microwave together. Only one ticket can be used at a time. You are planning to buy one refrigerator and one microwave. Find the minimum amount of money required. Constraints All values in input are integers. 1 \le A \le 10^5 1 \le B \le 10^5 1 \le M \le 10^5 1 \le a_i , b_i , c_i \le 10^5 1 \le x_i \le A 1 \le y_i \le B c_i \le a_{x_i} + b_{y_i} Input Input is given from Standard Input in the following format: A B M a_1 a_2 ... a_A b_1 b_2 ... b_B x_1 y_1 c_1 \vdots x_M y_M c_M Output Print the answer. Sample Input 1 2 3 1 3 3 3 3 3 1 2 1 Sample Output 1 5 With the ticket, you can get the 1 -st refrigerator and the 2 -nd microwave for 3+3-1=5 yen. Sample Input 2 1 1 2 10 10 1 1 5 1 1 10 Sample Output 2 10 Note that you cannot use more than one ticket at a time. Sample Input 3 2 2 1 3 5 3 5 2 2 2 Sample Output 3 6 You can get the 1 -st refrigerator and the 1 -st microwave for 6 yen, which is the minimum amount to pay in this case. Note that using a ticket is optional. | 36,694 |
Vampire Mr. C is a vampire. If he is exposed to the sunlight directly, he turns into ash. Nevertheless, last night, he attended to the meeting of Immortal and Corpse Programmers Circle, and he has to go home in the near dawn. Fortunately, there are many tall buildings around Mr. C's home, and while the sunlight is blocked by the buildings, he can move around safely. The top end of the sun has just reached the horizon now. In how many seconds does Mr. C have to go into his safe coffin? To simplify the problem, we represent the eastern dawn sky as a 2-dimensional x - y plane, where the x axis is horizontal and the y axis is vertical, and approximate building silhouettes by rectangles and the sun by a circle on this plane. The x axis represents the horizon. We denote the time by t , and the current time is t =0. The radius of the sun is r and its center is at (0, - r ) when the time t =0. The sun moves on the x - y plane in a uniform linear motion at a constant velocity of (0, 1) per second. The sunlight is blocked if and only if the entire region of the sun (including its edge) is included in the union of the silhouettes (including their edges) and the region below the horizon (y †0). Write a program that computes the time of the last moment when the sunlight is blocked. The following figure shows the layout of silhouettes and the position of the sun at the last moment when the sunlight is blocked, that corresponds to the first dataset of Sample Input below. As this figure indicates, there are possibilities that the last moment when the sunlight is blocked can be the time t =0. The sunlight is blocked even when two silhouettes share parts of their edges. The following figure shows the layout of silhouettes and the position of the sun at the last moment when the sunlight is blocked, corresponding to the second dataset of Sample Input. In this dataset the radius of the sun is 2 and there are two silhouettes: the one with height 4 is in -2 †x †0, and the other with height 3 is in 0 †x †2. Input The input consists of multiple datasets. The first line of a dataset contains two integers r and n separated by a space. r is the radius of the sun and n is the number of silhouettes of the buildings. (1 †r †20, 0 †n †20) Each of following n lines contains three integers x li , x ri , h i (1 †i †n ) separated by a space. These three integers represent a silhouette rectangle of a building. The silhouette rectangle is parallel to the horizon, and its left and right edges are at x = x li and x = x ri , its top edge is at y = h i , and its bottom edge is on the horizon. (-20 †x li < x ri †20, 0 < h i †20) The end of the input is indicated by a line containing two zeros separated by a space. Note that these silhouettes may overlap one another. Output For each dataset, output a line containing the number indicating the time t of the last moment when the sunlight is blocked. The value should not have an error greater than 0.001. No extra characters should appear in the output. Sample Input 2 3 -2 -1 3 0 1 3 2 3 3 2 2 -2 0 4 0 2 3 2 6 -3 3 1 -2 3 2 -1 3 3 0 3 4 1 3 5 2 3 6 2 6 -3 3 1 -3 2 2 -3 1 3 -3 0 4 -3 -1 5 -3 -2 6 0 0 Output for the Sample Input 0.0000 3.0000 2.2679 2.2679 | 36,695 |
Edit Distance (Levenshtein Distance) Find the edit distance between given two words s1 and s2 . The disntace is the minimum number of single-character edits required to change one word into the other. The edits including the following operations: insertion : Insert a character at a particular position. deletion : Delete a character at a particular position. substitution : Change the character at a particular position to a different character Input s1 s2 Two words s1 and s2 are given in the first line and the second line respectively. The words will consist of lower case characters. Output Print the edit distance in a line. Constraints 1 †length of s1 †1000 1 †length of s2 †1000 Sample Input 1 acac acm Sample Output 1 2 Sample Input 2 icpc icpc Sample Output 2 0 | 36,696 |
ããã°ã©ã 忢å€å® çããã¯ãèŠåŽããŠäœã£ãããã°ã©ã ãå®è¡ããŠã¿ãããç¡éã«ãŒãã«ãªã£ãŠããŸã£ãçµéšã¯ãããŸãããïŒ ããã°ã©ã ã®å®è¡ã忢ãããã©ããããå®è¡ããªããŠãäºåã«å€å®ã§ãããšäŸ¿å©ã§ãããã æ®å¿µãªãããçããããµã ã䜿ã£ãŠããããã°ã©ãã³ã°èšèªã§ã¯ãããããããã°ã©ã ã«å¯ŸããŠãã®ãããªå€å®ãããããšã¯äžå¯èœã§ãããããããããããã¯ããã«èšç®èœåã®äœãããã°ã©ãã³ã°èšèªãªãããã®èšèªã§æžããããã°ã©ã ã忢ãããã©ãããå€å®ããããã°ã©ã ãæžããå ŽåããããŸãã TinyPowerãšããããã°ã©ãã³ã°èšèªãèããŸãããã®èšèªã®ããã°ã©ã ã¯è¡ã®äžŠã³ã§ããããã°ã©ã ã®åè¡ã«ã¯ãå
é ã«è¡çªå·ãæžãããã®åŸãã«æãäžã€æžããŸãããã®èšèªã§æžããæã®çš®é¡ã¯ä»¥äžã®éãã§ãã æã®çš®é¡ åäœ ADD var 1 var 2 var 3 倿° var 2 ã®å€ãš var 3 ã®å€ãå ç®ããçµæã倿° var 1 ã«ä»£å
¥ãã ADD var 1 var 2 con 倿° var 2 ã®å€ãšå®æ° con ãå ç®ããçµæã倿° var 1 ã«ä»£å
¥ãã SUB var 1 var 2 var 3 倿° var 2 ã®å€ãã var 3 ã®å€ãæžç®ããçµæã倿° var 1 ã«ä»£å
¥ãã SUB var 1 var 2 con 倿° var 2 ã®å€ãã宿° con ãæžç®ããçµæã倿° var 1 ã«ä»£å
¥ãã SET var 1 var 2 倿° var 2 ã®å€ã倿° var 1 ã«ä»£å
¥ãã SET var 1 con 宿° con ã倿° var 1 ã«ä»£å
¥ãã IF var 1 dest 倿° var 1 ã®å€ãïŒã§ãªããšãã ããè¡çªå· dest ã«ãžã£ã³ããã HALT ããã°ã©ã ã忢ããã è¡çªå·ã¯æ£ã®æŽæ°ã§ãããã°ã©ã äžã«åãè¡çªå·ãïŒã€ä»¥äžçŸããããšã¯ãããŸããã倿°ã¯è±å°æåäžæåã§è¡šãã宿°ãšå€æ°ã®å€ã¯æŽæ°ã§ãã倿°ã®å®£èšã¯äžèŠã§ã倿°ã®åæå€ã¯ïŒã§ãã ããã°ã©ã ã®å®è¡ã¯å
é ã®æããå§ãŸãã䞊ãã§ããé ã«æãå®è¡ãããŸãããã ããäžã®è¡šã«æžãããããã«ãIFæã®å€æ°ã®å€ãïŒã§ãªããšãã¯ã倿°ã®åŸãã«æžãããè¡çªå·ã§æå®ãããè¡ã«ãžã£ã³ããããã®è¡ã«æžãããæããå®è¡ãç¶ããŸããããã°ã©ã ã¯ä»¥äžã®ãšãã«åæ¢ããŸãã HALTæãå®è¡ãããšãã è² ã®æŽæ°ãŸãã¯ïŒïŒä»¥äžã®æŽæ°ã倿°ã«ä»£å
¥ããããšãããšãïŒå€æ°ã®å€ã¯æŽæ°ãããªãïŒã ããã°ã©ã ã«çŸããªãè¡çªå·ã«ãžã£ã³ãããããšãããšãã ããã°ã©ã ã®æåŸã®æãå®è¡ããåŸãããããã©ã®è¡ã«ããžã£ã³ãããªããšãã TinyPowerã®ããã°ã©ã ãäžãããããšãããããåãŸããã©ãããå€å®ããããã°ã©ã ãäœæããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã N stmt 1 stmt 2 : stmt N ïŒè¡ç®ã«ããã°ã©ã ã®è¡æ° N (1 †N †50) ãäžãããããç¶ã N è¡ã«ãTinyPowerããã°ã©ã ã®æ stmt i ãäžããããã stmt i ã¯ã以äžã®ããããã®åœ¢åŒã§äžããããã line ADD var 1 var 2 var 3 ãŸã㯠line ADD var 1 var 2 con ãŸã㯠line SUB var 1 var 2 var 3 ãŸã㯠line SUB var 1 var 2 con ãŸã㯠line SET var 1 var 2 ãŸã㯠line SET var 1 con ãŸã㯠line IF var 1 dest ãŸã㯠line HALT line , dest (1 †line , dest †1000) ã¯è¡çªå·ã var j (è±å°æåïŒæå)ã¯å€æ°ã con (0 †con †15) ã¯å®æ°ã衚ãã stmt i äžã®åºåãã¯ç©ºçœïŒæåãšããããªããããã°ã©ã äžã«å€æ°ã¯å¿
ãïŒã€ä»¥äžçŸããç°ãªã倿°åã¯ïŒã€ãŸã§ããçŸããªããã®ãšããã Output ããã°ã©ã ã忢ãããšãã¯ãããã°ã©ã ã«çŸãã倿°ã®çµæãã倿°åã®èŸæžé ã«æ¹è¡åºåãã§åºåãã忢ããªããšãã¯ãinfããåºåããã倿°ã®çµæã¯ã倿°åãšå€æ°ã®å€ãã=ãã§åºåã£ãŠåºåããã Sample Input 1 6 10 SET c 1 20 SET i 5 100 ADD s s i 110 SUB i i c 120 IF i 100 200 HALT Sample Output 1 c=1 i=0 s=15 å
¥åäŸïŒã¯ãïŒããïŒãŸã§ã®æŽæ°ã®åãèšç®ãããã®çµæã倿°sã«æ ŒçŽããããšãHALTæã®å®è¡ã§åæ¢ããã Sample Input 2 3 10 SET c 1 120 IF c 10 20 HALT Sample Output 2 inf å
¥åäŸïŒã¯ãè¡çªå·10ã§cã«1ã代å
¥ããæ¬¡ã®è¡çªå·120ã®IFæã§è¡çªå·10ã«æ»ãããšãç¹°ãè¿ãã®ã§ã忢ããªãã Sample Input 3 3 111 SET c 1 12 SUB c c 2 777 SET a 4 Sample Output 3 a=0 c=1 å
¥åäŸïŒã¯ãè¡çªå·111ã§cã«1ã代å
¥ããæ¬¡ã®è¡çªå·12ã§cã«-1ã代å
¥ããããšããã®ã§ã忢ããããã®ãšãcã®å€ã¯-1ã«æŽæ°ãããªããè¡çªå·777ã¯å®è¡ãããªãã®ã§ãaã®å€ã¯åæå€0ã®ãŸãŸã§ããã | 36,697 |
Problem B: Sort the Panels There was an explorer Henry Nelson traveling all over the world. One day he reached an ancient building. He decided to enter this building for his interest, but its entrance seemed to be locked by a strange security system. There were some black and white panels placed on a line at equal intervals in front of the entrance, and a strange machine with a cryptogram attached. After a while, he managed to read this cryptogram: this entrance would be unlocked when the panels were rearranged in a certain order, and he needed to use this special machine to change the order of panels. All he could do with this machine was to swap arbitrary pairs of panels. Each swap could be performed by the following steps: move the machine to one panel and mark it; move the machine to another panel and again mark it; then turn on a special switch of the machine to have the two marked panels swapped. It was impossible to have more than two panels marked simultaneously. The marks would be erased every time the panels are swapped. He had to change the order of panels by a number of swaps to enter the building. Unfortunately, however, the machine was so heavy that he didnât want to move it more than needed. Then which steps could be the best? Your task is to write a program that finds the minimum cost needed to rearrange the panels, where moving the machine between adjacent panels is defined to require the cost of one. You can arbitrarily choose the initial position of the machine, and donât have to count the cost for moving the machine to that position. Input The input consists of multiple datasets. Each dataset consists of three lines. The first line contains an integer N , which indicates the number of panels (2 †N †16). The second and third lines contain N characters each, and describe the initial and final orders of the panels respectively. Each character in these descriptions is either âBâ (for black) or âWâ (for white) and denotes the color of the panel. The panels of the same color should not be distinguished. The input is terminated by a line with a single zero. Output For each dataset, output the minimum cost on a line. You can assume that there is at least one way to change the order of the panels from the initial one to the final one. Sample Input 4 WBWB BWBW 8 WWWWBWBB WWBBWBWW 0 Output for the Sample Input 3 9 | 36,698 |
Score : 600 points Problem Statement The server in company A has a structure where N devices numbered 1, 2, ..., N are connected with N - 1 cables. The i -th cable connects Device U_i and Device V_i . Any two different devices are connected through some number of cables. Each device v ( 1 \leq v \leq N ) has a non-zero integer A_v , which represents the following: If A_v < 0 , Device v is a computer that consumes an electric power of -A_v . If A_v > 0 , Device v is a battery that supplies an electric power of A_v . You have decided to disconnect some number of cables (possibly zero) to disable the server. When some cables are disconnected, the devices will be divided into some number of connected components. The server will be disabled if all of these connected components satisfy one of the following conditions: There is no computer in the connected component. That is, A_v is positive for every device v that belongs to the connected component. There is not enough supply of electric power in the connected component. That is, the sum of A_v over all devices v that belong to the connected component is negative. At least how many cables do you need to disconnect in order to disable the server? Constraints 1 \leq N \leq 5 000 1 \leq |A_i| \leq 10^9 ( 1 \leq i \leq N ) 1 \leq U_i, V_i \leq N ( 1 \leq i \leq N - 1 ) U_i \neq V_i ( 1 \leq i \leq N - 1 ) Any two different devices are connected through some number of cables. All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N U_1 V_1 U_2 V_2 : U_{N - 1} V_{N - 1} Output Print the answer. Sample Input 1 7 -2 7 5 6 -8 3 4 1 2 2 3 2 4 1 5 5 6 5 7 Sample Output 1 1 We should disconnect the cable connecting Device 1 and Device 2 . Sample Input 2 4 1 2 3 4 1 2 1 3 1 4 Sample Output 2 0 Sample Input 3 6 10 -1 10 -1 10 -1 1 2 2 3 3 4 4 5 5 6 Sample Output 3 5 Sample Input 4 8 -2 3 6 -2 -2 -5 3 2 3 4 7 6 6 2 8 2 5 3 1 8 3 7 Sample Output 4 3 Sample Input 5 10 3 4 9 6 1 5 -1 10 -10 -10 7 4 5 6 8 1 9 5 7 1 10 3 2 8 4 10 9 2 Sample Output 5 3 | 36,699 |
Anipero 2012 D: ã¢ããã2012 ã¢ããããµããŒã©ã€ãïŒéç§°ã¢ãããã¯ïŒããŸããŸãªã¢ãã¡ãœã³ã°ã¢ãŒãã£ã¹ããã¡ãéçµããïŒæ¥æ¬åœå
æå€§ã®ã¢ãã¡ãœã³ã°ã©ã€ãã€ãã³ãã§ããïŒã¢ããœã³ã倧奜ããª2Dåã¯ïŒæšå¹Žã«åŒãç¶ãïŒä»å¹Žãã¢ãããã«è¡ãããšã«ããïŒ åœŒã¯ïŒã¢ããããæ¥œããããã«ïŒãã§ã«ãµã€ãªãŠã ã m æ¬è³Œå
¥ããŠããïŒãµã€ãªãŠã ãšã¯ïŒæããšååŠåå¿ã§å
ãã¹ãã£ãã¯ã§ããïŒãªãºã ã«åãããŠãµã€ãªãŠã ãæ¯ãããšã§ïŒã©ã€ããçãäžããããšãã§ãïŒèªåã®æºè¶³åºŠãäžæããïŒä»åïŒåœŒã賌å
¥ããå
šãŠã®ãµã€ãªãŠã ã¯ïŒæ¬¡ã®ãããªæ§è³ªãæã€ïŒ ãµã€ãªãŠã ã¯ïŒæã£ãŠããæéãçµéããã«ã€ãæããªã£ãŠããïŒ10åã§å
ã倱ãïŒ æã£ãŠãã5åã®éã¯ïŒéåžžã«æããïŒä»¥äžïŒãã¬ãã«2ããšåŒã¶ïŒïŒ æã£ãŠãã5åçµéããåŸã¯ïŒå°ãæããªãïŒä»¥äžïŒãã¬ãã«1ããšåŒã¶ïŒïŒ æ¯ã£ãŠãæ¯ããªããŠãïŒå
ã倱ãã¹ããŒãã¯å€ãããªãïŒ 2Dåã¯ïŒéããããµã€ãªãŠã ãæ²ã«ãã£ãŠããŸã䜿ãåããããšã§ïŒä»å¹Žã®ã¢ãããã§ã©ãã ãã®æºè¶³åºŠãåŸãããããïŒä»¥äžã®åé¡ãèããããšã«ããïŒ åœŒã¯ïŒã©ã€ãäžã«æµããã§ãããæ²ã n æ²äºæ³ããŠããïŒ åæ²ã®é·ãã¯ïŒå
šãŠ5åã§ããïŒ n æ²ã¯ïŒé£ç¶ã§æµãç¶ãïŒæ²ãšæ²ã®éã¯ïŒ0åãšèããŠããïŒ åæ²ã«ã¯ïŒä»¥äžã®3ã€ã®ãã©ã¡ãŒã¿ãäžããããïŒ ããæ²ã«å¯ŸããŠïŒã¬ãã«2ã1æ¬ã ãæ¯ã£ããšãã«å¢ããæºè¶³åºŠ ããæ²ã«å¯ŸããŠïŒã¬ãã«1ã1æ¬ã ãæ¯ã£ããšãã«å¢ããæºè¶³åºŠ ããæ²ã«ãããŠïŒ1æ¬ãæ¯ããªããšãã«å¢ããæºè¶³åºŠ ãµã€ãªãŠã ãæ¯ã£ããããšãã£ãŠïŒæºè¶³åºŠãå¢ãããšã¯éããªãïŒ æ¯ã£ããéã«äŒå Žã®é°å²æ°ãä¹±ããŠïŒæºè¶³åºŠãæžãå ŽåãããïŒ æ¯ããªãå ŽåãïŒåæ§ã®ããšãèšããïŒ ãµã€ãªãŠã ã¯ïŒä»¥äžã®ã«ãŒã«ã«åŸã£ãŠäœ¿çšããªããã°ãªããªãïŒ æ²ãå§ãŸãæç¹ã§ã®ã¿æãããšãã§ãïŒäžåºŠã«äœæ¬ã§ãæãããšãã§ããïŒãµã€ãªãŠã ãæãã®ã«ãããæéã¯ç¡èŠããŠããïŒ 1æ²ã§æå€§8æ¬åæã«æ¯ãããšãã§ããïŒ è€æ°ã®ãµã€ãªãŠã ãæ¯ãéïŒä»¥äžã®åŒã«ããå ç®ããæºè¶³åºŠãèšç®ããïŒ (ã¬ãã«1ã®æ¬æ°)Ã(ã¬ãã«1ã®1æ¬ãããã®æºè¶³åºŠ)ïŒ(ã¬ãã«2ã®æ¬æ°)Ã(ã¬ãã«2ã®1æ¬ãããã®æºè¶³åºŠ) 1æ¬ããµã€ãªãŠã ãæ¯ããªãå Žåã¯ïŒ1æ¬ãæ¯ããªãå Žåã®æºè¶³åºŠã ããå ç®ããïŒ äžåºŠæ¯ããšæ±ºãããµã€ãªãŠã ã¯ïŒ1æ²ãçµäºãããŸã§æã¡æ¿ããããšã¯ã§ããªãïŒ ãµã€ãªãŠã ã¯ïŒæ¯ããã«çœ®ããŠããããšãã§ããïŒãŸãïŒãµã€ãªãŠã ãå
šãŠäœ¿ãããå¿
èŠã¯ãªãïŒ 2Dåã¯ïŒã©ã€ãã®æ²äºæ³ãŸã§ã¯æžãŸãããïŒããã ãã§ç²ããŠããŸã£ãŠïŒåé¡ãè§£ãæ°ã«ãªããªãã£ãïŒ ããªãã®ä»äºã¯ïŒåœŒã®ä»£ããã«ïŒä»å¹Žã®ã©ã€ãã§åŸãããããªæå€§æºè¶³åºŠãæ±ããããã°ã©ã ãæžãããšã§ããïŒ Input ã©ã€ãã®äºæ³æ²ãªã¹ãã«å¯Ÿããæºè¶³åºŠæ
å ±ãå
¥åãããïŒ 1è¡ç®ã«ïŒã©ã€ãã§æãããæ²æ° n (1 <= n <= 50)ãšïŒã©ã€ãéå§æã«2Dåãæã£ãŠããæ°åã®ãµã€ãªãŠã ã®æ°m (0 <= m <= 50)ãã¹ããŒã¹åºåãã§å
¥åãããïŒ ç¶ã n è¡ã§ã¯ïŒ1è¡ãã€1æ²ã®æ
å ±ãå
¥åãããïŒ i çªç®(1 <= i <= n )ã®æ²æ
å ±ã¯ïŒ æ² i ã«å¯ŸããŠïŒã¬ãã«2ã®ãµã€ãªãŠã ã1æ¬æ¯ã£ããšãã®æºè¶³åºŠ a i æ² i ã«å¯ŸããŠïŒã¬ãã«1ã®ãµã€ãªãŠã ã1æ¬æ¯ã£ããšãã®æºè¶³åºŠ b i æ² i ã«ãããŠïŒãµã€ãªãŠã ã1æ¬ãæ¯ããªããšãã®æºè¶³åºŠ c i ãã¹ããŒã¹åºåãã§å
¥åããã(-100 <= a i , b i , c i <= 100)ïŒ Output ã©ã€ãçµäºæã®2Dåã®æå€§æºè¶³åºŠã®äºæ³ã1è¡ã«åºåããïŒ æå€§æºè¶³åºŠããã€ãã¹ã«ãªãããšãããã®ã§ïŒæ³šæããããšïŒ è¡ã®æåŸã«ã¯ïŒæ¹è¡ãåºåããããšïŒ Sample Input 1 1 5 2 3 8 Sample Output 1 10 Sample Input 2 2 10 2 2 20 2 3 -10 Sample Output 2 44 Sample Input 3 3 10 5 1 9 -3 2 1 1 11 0 Sample Output 3 102 | 36,700 |
Score : 100 points Problem Statement Ringo Kingdom Congress is voting on a bill. N members are present, and the i -th member (1 †i †N) has w_i white ballots and b_i blue ballots. Each member i will put all the w_i white ballots into the box if he/she is in favor of the bill, and put all the b_i blue ballots into the box if he/she is not in favor of the bill. No other action is allowed. For example, a member must not forfeit voting, or put only a part of his/her white ballots or a part of his/her blue ballots into the box. After all the members vote, if at least P percent of the ballots in the box is white, the bill is passed; if less than P percent of the ballots is white, the bill is rejected. In order for the bill to pass, at least how many members must be in favor of it? Constraints 1 †N †10^5 1 †P †100 1 †w_i †10^9 1 †b_i †10^9 All input values are integers. Input Input is given from Standard Input in the following format: N P w_1 b_1 w_2 b_2 : w_N b_N Output Print the minimum number of members in favor of the bill required for passage. Sample Input 1 4 75 1 1 1 1 1 1 1 1 Sample Output 1 3 This is a "normal" vote, where each of the four members has one white ballot and one blue ballot. For the bill to pass, at least 75 percent of the four, that is, at least three must be in favor of it. Sample Input 2 4 75 1 1 1 1 1 1 100 1 Sample Output 2 1 The "yes" vote of the member with 100 white ballots alone is enough to pass the bill. Sample Input 3 5 60 6 3 5 9 3 4 7 8 4 7 Sample Output 3 3 | 36,701 |
Problem F: Remainder Zero Problem æŽæ°ã®éåA,Bã«ã€ããŠ,æ¬¡ã®æ¡ä»¶ãæºããæŽæ° x ãããã€ååšãããçããã A i mod x = 0 ã〠x mod B j = 0 ããã¹ãŠã® i (1 †i †N), j (1 †j †M) ã«ã€ããŠæãç«ã€ã ( a mod b 㯠a ã b ã§å²ã£ããšãã®äœããæå³ãã) Input N M A 1 A 2 ... A N B 1 B 2 ... B M Constraints å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã 1 †N , M †5 1 †A i , B j †10 14 (1 †i †N , 1 †j †M ) Output æ¡ä»¶ãæºããæŽæ° x ãããã€ååšãããäžè¡ã§åºåããã Sample Input 1 1 2 18 6 9 Sample Output 1 1 Sample Input 2 1 2 256 2 4 Sample Output 2 7 | 36,702 |
å顿 宿°å€æ° $x_1, x_2, ..., x_N$ ã¯ä»¥äžã®æ¡ä»¶ãæºããã $0 \leq x_i \leq 1$ ($1 \leq i \leq N$) $w_1x_1+w_2x_2+...+w_Nx_N \leq W$ ãã®ãšã $v_1x_1+v_2x_2+...+v_Nx_N$ ã®ãšãããæå€§å€ãæ±ããããã®ãããªæå€§å€ã¯å®éã«ååšããããšãç¥ãããŠããã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã«åŸããäžããããæ°ã¯å
šãп޿°ã§ããã $N$ $W$ $w_1$ $v_1$ $w_2$ $v_2$ $...$ $w_N$ $v_N$ å¶çŽ $1 \leq N \leq 10^5$ $1 \leq W \leq 10^5$ $-10^4 \leq w_i \leq 10^4$ $-10^4 \leq v_i \leq 10^4$ åºå $v_1x_1+v_2x_2+...+v_Nx_N$ ã®ãšãããæå€§å€ã1è¡ã«åºåããã åºåã«ã¯ $10^{-3}$ ãè¶
ãã誀差ããã£ãŠã¯ãªããªãã Sample Input 1 1 1 3 1 Output for the Sample Input 1 0.333333 $x_1=1/3$ ã®ãšãæå€§ãšãªãã Sample Input 2 2 3 3 3 1 2 Output for the Sample Input 2 4.000000 Sample Input 3 2 1 -1 -3 3 10 Output for the Sample Input 3 3.666667 | 36,703 |
G: æã®ãžã¥ã³ã¬ãRun!Run!Run! - Love Permutation, Run run run! - ç©èª ããããªãžã¥ã³ã¬ã ããããããã§ã¶ãŒâª Hello, æç©ºèã«ãïŒ å¥œããªããŒã¿æ§é 㯠Starry Sky Tree ã«ãïŒ èã¯æè¿ç©çåŠç§ã«å
¥åŠãããã ãã©ãã©ãããããã§ãããã°ã©ãã³ã°ããããªããšãããªãããããã ã èãã¢ã«ãŽãªãºã ãããŒã¿æ§é ã®çè«ã¯å¥œããªãã ãã©ãå®è£
ã¯ã©ããèŠæãªãã ããâŠâŠ ã ãããèéã¯äººéãªã®ã«ãã©ãããŠæ©æ¢°ã®èšèãå匷ããªãã¡ããããªãã®ïŒïŒ ãšã¯ããã課é¡ããããªãããšã«ã¯åäœãåºãªãããããããªãã«ãã ä»ååºã課é¡ã¯é åã® run ãšãããã®ãé¢ä¿ããŠããããããã ãŒã ãã®åé¡ãæããã«äœè
ãã¿ã€ãã«äžçºãã¿ã§èããŠãã®ãèŠãèŠãã«ããã¡ãã£ãšå¯ããªããã«ããŒã ãšã«ãããããã°ã©ãã³ã°ãåŸæãªããªãã«æäŒã£ãŠãããããããã³ã·ã§ã³äžããã«ããŒïŒ ãããããåé¡ãè¡ã£ãã«ããïŒ åé¡ é·ã K ã®æ°å a ã 1 \leq a_i \leq K (1 \leq i \leq K) ã〠a_i \neq a_j (1 \leq i < j \leq K) ãæºãããšãã a ã¯é·ã K ã®é åã§ãããšããã ããã§é åã®ãã¿ãŒã³ãããã³ã°ã以äžã®ããã«å®çŸ©ããã ããã¹ãé å q ããã¿ãŒã³é å p ã«ããããããšã¯ã p ãšçžå¯Ÿé åºãäžèŽãããããªã p ãšåãé·ãã® q ã® (é£ç¶ãšã¯éããªã) éšååãååšããããšãããã ããå³å¯ã«ã¯ã q ã®é·ãã N ã p ã®é·ãã M ãšãããšãã q ã p ã«ããããããšã¯ãããæ¡ä»¶ãæºããæ·»ãåå 1 \leq i_1 < ... < i_M \leq N ãååšããããšã§ããããã®æ¡ä»¶ãšã¯ã p_x < p_y (1 \leq x<y \leq M) ãªãã°ããã€ãã®ãšãã«éã q_{i_x} < q_{i_y} ãšãªãããšã§ããã äŸãã°ãé å (3, 4, 2, 1, 5) ã¯é å (2, 1, 3) ã«ãããããããªããªãã°ãæ·»ãåå (1, 4, 5) ãäžèšã®æ¡ä»¶ãæºããããã§ããã ããã«ãé åã® run ãå®çŸ©ããã é åã®runãšã¯ãå調å¢å ããããã¯å調æžå°ãªæ¥µå€§é£ç¶éšååã§ãããããªãã¡ãrun ã¯é£ç¶éšåå a_l, ..., , a_r (l<r) ã®ãã¡ã a_i < a_{i+1} (l \leq i < r) ( a_i > a_{i+1} (l \leq i < r) ) ãæºããããã€ãã®åºéãçã«å
å«ããé£ç¶åºéãããªã run ãååšããªããã®ãèšãã äŸãã°ãé å (3, 4, 2, 1, 5) 㯠(3, 4) , (4, 2, 1) , (1, 5) ãšãã3ã€ã®runãæã€ã é·ã N ã®ããã¹ãé å q ãšé·ã M ã®ãã¿ãŒã³é å p ãäžããããã ããã§ã q ã¯å¿
ãã¡ããã©3ã€ã ãã® run ãæã€ããšãä¿èšŒãããã q ã p ã«ããããããã©ãããå€å®ããã å
¥ååœ¢åŒ å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã N q_1 ... q_N M p_1 ... p_M å
¥åã¯å
šãп޿°ãããªãã 1è¡ç®ã«ã¯ããã¹ããšãªãé å q ã®é·ã N ãäžããããã ç¶ã2è¡ç®ã¯ N åã®æŽæ°ã空çœåºåãã§äžãããã i (1 \leq i \leq N) çªç®ã®æŽæ°ã¯ q ã® i çªç®ã®èŠçŽ q_i ã衚ãã 3è¡ç®ã«ã¯ãã¿ãŒã³ãšãªãé å p ã®é·ã M ãäžããããã ç¶ã4è¡ç®ã¯ M åã®æŽæ°ã空çœåºåãã§äžãããã j (1 \leq j \leq M) çªç®ã®æŽæ°ã¯ p ã® j çªç®ã®èŠçŽ p_j ã衚ãã å¶çŽ 4 \leq N \leq 10^5 1 \leq M \leq N q, p ã¯ããããé·ã N, M ã®é åã§ããã q ãæã€ run ã®æ°ã¯ã¡ããã©3ã åºååœ¢åŒ é å q ãé å p ã«ããããããšã"Yes"ãããã§ãªããã°"No"ãš1è¡ã«åºåããã å
¥åäŸ1 5 3 4 2 1 5 3 1 2 3 åºåäŸ1 Yes å
¥åäŸ2 5 3 5 4 1 2 3 1 2 3 åºåäŸ2 No | 36,704 |
Problem P04: CamelCase ããã°ã©ãã³ã°ã«ãããèå¥åïŒå€æ°ã颿°ïŒã®åœåã§ã¯ã åèªãé£çµããè€åèªã䜿ãããã ãããããã®ãŸãŸé£çµãããšåèªã®åºåããããããªããªãããã äžè¬çã«ä»¥äžã®åœåèŠåã®äžããçµ±äžãããã®ãéžã³é©çšããïŒ Upper CamelCase ã«ãã åèªãçŽæ¥é£çµãè€åèªãšããååèªã®å
é æåã®ã¿ã倧æåã«ããã äŸïŒ GetUserName Lower CamelCase ã«ãã åèªãçŽæ¥é£çµãè€åèªãšããååèªã®å
é æåã®ã¿ã倧æåã«ããããã ããè€åèªã®å
é æåã¯å°æåã«ããã äŸïŒ getUserName ã¢ã³ããŒã¹ã³ã¢ã§ç¹ã åèªãã¢ã³ããŒã¹ã³ã¢ã§é£çµãè€åèªãšãããåèªã®æåã¯ãã¹ãŠå°æåã«ããã äŸïŒ get_user_name äžããããèå¥åããæå®ãããåœåèŠåãé©çšããŠåºåããããã°ã©ã ãäœæããã äžããããèå¥åã¯ãäžèšã®åœåèŠåã®ãã¥ãããæ¢ã«é©çšãããŠãããã®ãšããã Input å
¥åãšããŠè€æ°ã®ããŒã¿ã»ãããäžãããããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ name type ïŒèå¥åãåœåèŠåïŒ ç©ºçœåºåãã®æååãšæåïŒ type ã¯åœåèŠåã瀺ãæåã§ããã以äžã®è¡šã®éããšããïŒ type åœåèŠå U Upper CamelCase ã«ãã L Lower CamelCase ã«ãã D ã¢ã³ããŒã¹ã³ã¢ã§ç¹ã äžããããèå¥åã®æåæ°ã¯ 1 ä»¥äž 100 以äžã§ããã type ã ' X ' ã®ãšãå
¥åã®çµãããšããããã®å
¥åã«å¯Ÿããåºåãè¡ã£ãŠã¯ãªããªãã Output åããŒã¿ã»ããã«ã€ããŠãåœåèŠåãé©çšããèå¥åã1è¡ã«åºåããã Sample Input get_user_name L getUserName U GetUserName D EndOfInput X Output for the Sample Input getUserName GetUserName get_user_name | 36,705 |
ãããŸã£ããã ãããšããã«ãé«ãå¡ã«å²ãŸãã倧ããªã屿·ããããŸããããã®ã屿·ã®äž»äººã¯ç«ããšãŠã倧奜ãã§ãææãã£ãŠããç«ãã¡ã®ããã«ããã€ããããããã¯ããçšæããŠããŸããããè
¹ã空ãããç«ãã¡ã¯ãé«ãå¡ãã²ãããšé£ã³è¶ããã屿·ã®è³ãæã«çœ®ããŠãããã¯ãã«ãŸã£ãããã«é§ãå¯ãã®ã§ããã ããæ¥äž»äººã¯ã屿·ã®äžã§äœå¹ãã®ç«ãåããŠããã®ãèŠã€ããŸãããç«ãã¡ã¯ãã¯ããæ¢ããŠå±æ·ã®äžã瞊暪ç¡å°œã«èµ°ãåã£ãã®ã§ãã¶ã€ãã£ãã転ãã ãããŠããŸã£ãã®ã§ãã䞻人ã¯ç«ãã¡ã®å®å
šãèããŠããã¯ãã®çœ®ãå Žæã工倫ããããšã«ããŸããã äžç©ºããèŠããšããã®ã屿·ã®å¡ã¯å€è§åœ¢ããªããŠããŸãã䞻人ã¯ç«ãã¡ããã¯ããèŠã€ããããããã«ãæ·å°å
ã®äžã§ããå€è§åœ¢ã®é ç¹ã«ãããå Žæã ãã«ãã¯ãã眮ãããšã«ããŸããããŸãç«ãã¡ã¯æ°ãŸãããªã®ã§ãå€è§åœ¢ã®åšäžã®ã©ã®ç¹ããã屿·ã«å
¥ã£ãŠãããã¯äºæ³ã§ããŸãããããã§äž»äººã¯ãç«ãã©ã®ç¹ããå
¥ã£ããšããŠãããã®ç¹ããçŽé²ããŠããããã®ãã¯ãã«ãã©ãçããããã«ããã¯ããé
眮ããããšã決ããŸããã ãã¹ãŠã®é ç¹ã«ãã¯ããé
眮ããã°ããã®æ¡ä»¶ãæºããããšãã§ããŸãããããããã¯ããè£å
ããŠåãã®ã¯å€§å€ãªã®ã§ã䞻人ã¯ã§ããã ãå°ãªãæ°ã®é ç¹ã«ãã¯ããé
眮ããããšæããŸãããããŠãäž»äººã¯æäœäœç®æã«ãã¯ããé
眮ããå¿
èŠãããã§ããããã ã屿·ã®å¡ã衚ãå€è§åœ¢ãå
¥åãšãããã¯ããé
眮ããé ç¹ã®æ°ã®æå°å€ãæ±ããããã°ã©ã ãäœæããŠäžããããã ããç«ã¯å€è§åœ¢ã®å
éšã®ã¿ãçŽé²ã§ãããã®ãšããŸãïŒèŸºã¯å€è§åœ¢ã®å
éšã«å«ãããã®ãšããŸãïŒã å
¥å å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªããå
¥åã®çµããã¯ãŒãïŒã€ã®è¡ã§ç€ºããããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããã n x 1 y 1 x 2 y 2 ... x n y n ïŒè¡ç®ã«å€è§åœ¢ã®é ç¹ã®æ° n (3 †n †16) ãäžãããããç¶ã n è¡ã«å€è§åœ¢ã®é ç¹ã®åº§æšãäžãããããn è¡ã®ããããã¯ãïŒã€ã®ç©ºçœã§åºåãããïŒã€ã®æŽæ°ãããªããx i (-1000 †x i †1000) 㯠i çªç®ã®é ç¹ã® x 座æšãy i (-1000 †y i †1000) 㯠i çªç®ã®é ç¹ã® y 座æšã瀺ããå€è§åœ¢ã®é ç¹ã¯ãé£ãåã£ãé ç¹ãåæèšåãã«èšªåãããããªé çªã§äžããããã ããŒã¿ã»ããã®æ°ã¯ 20 ãè¶
ããªãã åºå åããŒã¿ã»ããããšã«ãã飯ãé
眮ããé ç¹ã®æ°ãïŒè¡ã«åºåããã å
¥åäŸ 8 0 0 3 2 6 2 8 6 6 5 7 7 0 4 3 4 8 0 0 5 3 5 2 4 1 6 1 8 6 6 4 2 4 0 åºåäŸ 1 2 | 36,706 |
Multisect We are developing the world's coolest AI robot product. After the long struggle, we finally managed to send our product at revision $R_{RC}$ to QA team as a release candidate. However, they reported that some tests failed! Because we were too lazy to set up a continuous integration system, we have no idea when our software corrupted. We only know that the software passed all the test at the past revision $R_{PASS}$. To determine the revision $R_{ENBUG}$ ($R_{PASS} < R_{ENBUG} \leq R_{RC}$) in which our software started to fail, we must test our product revision-by-revision. Here, we can assume the following conditions: When we test at the revision $R$, the test passes if $R < R_{ENBUG}$, or fails otherwise. It is equally possible, which revision between $R_{PASS} + 1$ and $R_{RC}$ is $R_{ENBUG}$. From the first assumption, we don't need to test all the revisions. All we have to do is to find the revision $R$ such that the test at $R - 1$ passes and the test at $R$ fails. We have $K$ testing devices. Using them, we can test at most $K$ different revisions simultaneously. We call this "parallel testing". By the restriction of the testing environment, we cannot start new tests until a current parallel testing finishes, even if we don't use all the $K$ devices. Parallel testings take some cost. The more tests fail, the more costly the parallel testing becomes. If $i$ tests fail in a parallel testing, its cost is $T_i$ ($0 \leq i \leq K$). And if we run parallel testings multiple times, the total cost is the sum of their costs. Of course we want to minimize the total cost to determine $R_{ENBUG}$, by choosing carefully how many and which revisions to test on each parallel testing. What is the minimum expected value of the total cost if we take an optimal strategy? Input The input consists of a single test case with the following format. $R_{PASS}$ $R_{RC}$ $K$ $T_0$ $T_1$ ... $T_K$ $R_{PASS}$ and $R_{RC}$ are integers that represent the revision numbers of our software at which the test passed and failed, respectively. $1 \leq R_{PASS} < R_{RC} \leq 1,000$ holds. $K$ ($1 \leq K \leq 30$) is the maximum number of revisions we can test in a single parallel testing. $T_i$ is an integer that represents the cost of a parallel testing in which $i$ tests fail ($0 \leq i \leq K$). You can assume $1 \leq T_0 \leq T_1 \leq ... \leq T_K \leq 100,000$. Output Output the minimum expected value of the total cost. The output should not contain an error greater than 0.0001. Sample Input 1 1 10 2 1 1 1 Output for the Sample Input 1 2.0 Sample Input 2 1 100 1 100 100 Output for the Sample Input 2 670.7070707 Sample Input 3 100 200 4 1 1 2 2 3 Output for the Sample Input 3 4.6400000 Sample Input 4 2 3 4 1 2 3 4 5 Output for the Sample Input 4 0.0 Sample Input 5 998 1000 4 10 100 1000 10000 100000 Output for the Sample Input 5 55.0 | 36,707 |
Score : 600 points Problem Statement Let us consider the following operations on a string consisting of A and B : Select a character in a string. If it is A , replace it with BB . If it is B , replace with AA . Select a substring that is equal to either AAA or BBB , and delete it from the string. For example, if the first operation is performed on ABA and the first character is selected, the string becomes BBBA . If the second operation is performed on BBBAAAA and the fourth through sixth characters are selected, the string becomes BBBA . These operations can be performed any number of times, in any order. You are given two string S and T , and q queries a_i, b_i, c_i, d_i . For each query, determine whether S_{a_i} S_{{a_i}+1} ... S_{b_i} , a substring of S , can be made into T_{c_i} T_{{c_i}+1} ... T_{d_i} , a substring of T . Constraints 1 \leq |S|, |T| \leq 10^5 S and T consist of letters A and B . 1 \leq q \leq 10^5 1 \leq a_i \leq b_i \leq |S| 1 \leq c_i \leq d_i \leq |T| Input Input is given from Standard Input in the following format: S T q a_1 b_1 c_1 d_1 ... a_q b_q c_q d_q Output Print q lines. The i -th line should contain the response to the i -th query. If S_{a_i} S_{{a_i}+1} ... S_{b_i} can be made into T_{c_i} T_{{c_i}+1} ... T_{d_i} , print YES . Otherwise, print NO . Sample Input 1 BBBAAAABA BBBBA 4 7 9 2 5 7 9 1 4 1 7 2 5 1 7 2 4 Sample Output 1 YES NO YES NO The first query asks whether the string ABA can be made into BBBA . As explained in the problem statement, it can be done by the first operation. The second query asks whether ABA can be made into BBBB , and the fourth query asks whether BBBAAAA can be made into BBB . Neither is possible. The third query asks whether the string BBBAAAA can be made into BBBA . As explained in the problem statement, it can be done by the second operation. Sample Input 2 AAAAABBBBAAABBBBAAAA BBBBAAABBBBBBAAAAABB 10 2 15 2 13 2 13 6 16 1 13 2 20 4 20 3 20 1 18 9 19 2 14 1 11 3 20 3 15 6 16 1 17 4 18 8 20 7 20 3 14 Sample Output 2 YES YES YES YES YES YES NO NO NO NO | 36,708 |
éè·¯ã®ãªãé£çµãªæåã°ã©ããäžããããïŒ(æåã°ã©ããé£çµã§ãããšã¯ïŒãããç¡åã°ã©ããšããæã«é£çµã§ãããšããäºã§ããïŒ) ãã®ã°ã©ãã«å¯ŸããŠäžã€ã®é ç¹ãéžãã§éŠéœ s ãå®ãããïŒ T(v) = " v ããå
šãŠã®ç¹ãå°éå¯èœã«ããããã«å¿
èŠãªã蟺ã®å転ãæäœã®åæ°ã®æå°å€"ãšããïŒ ãã ãïŒã蟺ã®å転ããšã¯ïŒé ç¹ v, u ã«é¢ã㊠(v, u) ã«åŒµãããŠããæå蟺ãåé€ã㊠(u, v) ã«åŒµãçŽãããšã§ããïŒ é ç¹ s ãéŠéœã§ãããšã¯ä»»æã®é ç¹ v ã«å¯ŸããŠïŒ T(s) †T(v) ãæç«ããããšã§ããïŒ éŠéœã§ãããããªé ç¹ããã¹ãŠåæããŠçããïŒ Input å
¥åã¯ä»¥äžã®ãããªåœ¢åŒã§ M + 1 è¡ã§äžããããïŒ N M a 1 b 1 : a M b M 1 è¡ç®ã«ã¯äºã€ã®æŽæ° N, M ãäžãããïŒäžããããã°ã©ã㯠N é ç¹ M 蟺ã§ããããšã衚ãïŒ 2 è¡ç®ãã M + 1 è¡ç®ã«ã¯ããããäºã€ã®æŽæ° a i , b i ãäžãããïŒ a i ãã b i ã«æå蟺ã匵ãããŠããããšã衚ãïŒ Constraints 1 †N †10,000 0 †M †100,000 0 †a i †N â 1 0 †b i †N â 1 a i â b i i â j ãªãã° (a i , b i ) â (a j , b j ) äžããããã°ã©ãã¯é£çµã§éè·¯ã¯ãªãïŒ äžããããã°ã©ãã«å¯ŸããŠïŒå
¥æ¬¡æ°ã 0 ã§ããé ç¹ã®åæ°ã¯ 50 以äžã§ããïŒ Output 以äžã®åœ¢åŒã§2 è¡ã§åºåããïŒ cnum cost c 1 c 2 . . . c cnum 1 è¡ç®ã«ã¯äºã€ã®æŽæ° cnum , cost ã空çœåºåãã§åºåããïŒ 2 è¡ç®ã«ã¯ cnum åã®æŽæ° c i ã空çœåºåãã§åºåããïŒ å€æ°ã®æå³ã¯ä»¥äžã®éãã§ããïŒ â cnum : éŠéœã®æ§è³ªãæºããé ç¹æ° â cost : éŠéœãšãªãé ç¹ v ã«å¯Ÿãã T(v) ã®å€ â c i : éŠéœã®æ§è³ªãæºããé ç¹ãçªå·ã«é¢ããŠæé ã«äžŠã¹ãæïŒ i çªç®ã®é ç¹çªå· Sample Input 1 3 2 0 1 2 1 Output for the Sample Input 1 2 1 0 2 é ç¹ 0 ãéŠéœãšãããšãã«ã¯èŸº (2,1) ãå転ããã°ïŒ(0,1), (1,2) ã®èŸºãæã€ã°ã©ããã§ããã®ã§ 1 ãçãïŒ T(0) = 1, T(1) = 2, T(2) = 1 ã§ããïŒ Sample Input 2 5 4 0 1 2 1 2 3 4 3 Output for the Sample Input 2 3 2 0 2 4 Sample Input 3 5 5 0 1 1 2 3 2 3 4 4 1 Output for the Sample Input 3 2 1 0 3 | 36,709 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.