task stringlengths 0 154k | __index_level_0__ int64 0 39.2k |
|---|---|
Problem F: TV Watching You are addicted to watching TV, and you watch so many TV programs every day. You have been in trouble recently: the airtimes of your favorite TV programs overlap. Fortunately, you have both a TV and a video recorder at your home. You can therefore watch a program on air while another program (on a different channel) is recorded to a video at the same time. However, it is not easy to decide which programs should be watched on air or recorded to a video. As you are a talented computer programmer, you have decided to write a program to find the way of watching TV programs which gives you the greatest possible satisfaction. Your program (for a computer) will be given TV listing of a day along with your score for each TV program. Each score represents how much you will be satisfied if you watch the corresponding TV program on air or with a video. Your program should compute the maximum possible sum of the scores of the TV programs that you can watch. Input The input consists of several scenarios. The first line of each scenario contains an integer N (1 †N †1000) that represents the number of programs. Each of the following N lines contains program information in the format below: T T b T e R 1 R 2 T is the title of the program and is composed by up to 32 alphabetical letters. T b and T e specify the start time and the end time of broadcasting, respectively. R 1 and R 2 indicate the score when you watch the program on air and when you have the program recorded, respectively. All times given in the input have the form of âhh:mmâ and range from 00:00 to 23:59. You may assume that no program is broadcast across the twelve midnight. The end of the input is indicated by a line containing only a single zero. This is not part of scenarios. Output For each scenario, output the maximum possible score in a line. Sample Input 4 OmoikkiriTV 12:00 13:00 5 1 WaratteIitomo 12:00 13:00 10 2 WatarusekennhaOnibakari 20:00 21:00 10 3 SuzumiyaharuhiNoYuuutsu 23:00 23:30 100 40 5 a 0:00 1:00 100 100 b 0:00 1:00 101 101 c 0:00 1:00 102 102 d 0:00 1:00 103 103 e 0:00 1:00 104 104 0 Output for the Sample Input 121 207 | 37,018 |
Score : 900 points Problem Statement We have a tree with N vertices. The vertices are numbered 0 through N - 1 , and the i -th edge ( 0 †i < N - 1 ) comnnects Vertex a_i and b_i . For each pair of vertices u and v ( 0 †u, v < N ), we define the distance d(u, v) as the number of edges in the path u - v . It is expected that one of the vertices will be invaded by aliens from outer space. Snuke wants to immediately identify that vertex when the invasion happens. To do so, he has decided to install an antenna on some vertices. First, he decides the number of antennas, K ( 1 †K †N ). Then, he chooses K different vertices, x_0 , x_1 , ..., x_{K - 1} , on which he installs Antenna 0 , 1 , ..., K - 1 , respectively. If Vertex v is invaded by aliens, Antenna k ( 0 †k < K ) will output the distance d(x_k, v) . Based on these K outputs, Snuke will identify the vertex that is invaded. Thus, in order to identify the invaded vertex no matter which one is invaded, the following condition must hold: For each vertex u ( 0 †u < N ), consider the vector (d(x_0, u), ..., d(x_{K - 1}, u)) . These N vectors are distinct. Find the minumum value of K , the number of antennas, when the condition is satisfied. Constraints 2 †N †10^5 0 †a_i, b_i < N The given graph is a tree. Input Input is given from Standard Input in the following format: N a_0 b_0 a_1 b_1 : a_{N - 2} b_{N - 2} Output Print the minumum value of K , the number of antennas, when the condition is satisfied. Sample Input 1 5 0 1 0 2 0 3 3 4 Sample Output 1 2 For example, install an antenna on Vertex 1 and 3 . Then, the following five vectors are distinct: (d(1, 0), d(3, 0)) = (1, 1) (d(1, 1), d(3, 1)) = (0, 2) (d(1, 2), d(3, 2)) = (2, 2) (d(1, 3), d(3, 3)) = (2, 0) (d(1, 4), d(3, 4)) = (3, 1) Sample Input 2 2 0 1 Sample Output 2 1 For example, install an antenna on Vertex 0 . Sample Input 3 10 2 8 6 0 4 1 7 6 2 3 8 6 6 9 2 4 5 8 Sample Output 3 3 For example, install an antenna on Vertex 0 , 4 , 9 . | 37,019 |
Score : 100 points Problem Statement There are three airports A, B and C, and flights between each pair of airports in both directions. A one-way flight between airports A and B takes P hours, a one-way flight between airports B and C takes Q hours, and a one-way flight between airports C and A takes R hours. Consider a route where we start at one of the airports, fly to another airport and then fly to the other airport. What is the minimum possible sum of the flight times? Constraints 1 \leq P,Q,R \leq 100 All values in input are integers. Input Input is given from Standard Input in the following format: P Q R Output Print the minimum possible sum of the flight times. Sample Input 1 1 3 4 Sample Output 1 4 The sum of the flight times in the route A \rightarrow B \rightarrow C: 1 + 3 = 4 hours The sum of the flight times in the route A \rightarrow C \rightarrow C: 4 + 3 = 7 hours The sum of the flight times in the route B \rightarrow A \rightarrow C: 1 + 4 = 5 hours The sum of the flight times in the route B \rightarrow C \rightarrow A: 3 + 4 = 7 hours The sum of the flight times in the route C \rightarrow A \rightarrow B: 4 + 1 = 5 hours The sum of the flight times in the route C \rightarrow B \rightarrow A: 3 + 1 = 4 hours The minimum of these is 4 hours. Sample Input 2 3 2 3 Sample Output 2 5 | 37,020 |
åé¡ 5 IOI å®é£Ÿåºã§ã¯ããŒãºã®ããã¯ã¬ã¹ã売ãåºãããšã«ãªã£ãïŒ ããŒãºã¯ n è²ããïŒ ãããããããã m å以äžãã€éžãã§ r åã®ããŒãºãããªãããã¯ã¬ã¹ãšãïŒ ïŒã€ãã€åç²§ç®±ã«å
¥ããŠè²©å£²ãããïŒ è²ã®çµåããéããã®ããã¹ãŠïŒã€ãã€çšæããããïŒ åç²§ç®±ãäœåçšæããããããåºå¡ã®èª°ãããããªãïŒ n, m, r ã«ãã£ãŠã¯çŸå®çã§ãªãåæ°ã®åç²§ç®±ãå¿
èŠãšãªãã®ã§ã¯ãªãããšåºé·ã¯å¿é
ããŠããïŒ IOI å®é£Ÿåºã®åºé·ã«ä»£ãã£ãŠïŒ å¿
èŠãªåç²§ç®±ã®åæ°ãåºåããããã°ã©ã ãäœæããªããïŒ n, m, r ã¯æŽæ°ã§ïŒ0âŠmïŒnâŠrâŠ10000 ã§ããïŒ å
¥åãã¡ã€ã«ã¯ïŒè¡ã§ïŒ 空çœãåºåããšã㊠n, m, r ããã®é ã«æžããŠããïŒ å
¥åãã¡ã€ã«ïŒã€ã®ãã¡ã®ïŒã€ã§ã¯ nâŠ10 ã§ããïŒ åºåãã¡ã€ã«ã«ãããŠã¯ïŒ åºåã®æåŸã®è¡ã«ãæ¹è¡ã³ãŒããå
¥ããããšïŒ å
¥åºåäŸ å
¥åäŸïŒ 2 0 3 åºåäŸïŒ 4 å
¥åäŸïŒ 3 1 4 åºåäŸïŒ 3 å
¥åäŸïŒ 4 2 5 åºåäŸïŒ 0 å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã | 37,021 |
ãã±ãã転é ã€ã³ã¿ãŒãããã§ã¯ãããŒã¿ã¯ãã±ããã«åå²ããããã±ããããšã«ã«ãŒã¿ãšåŒã°ããäžç¶æ©åšãä»ããŠå®å
ã«è»¢éãããŸããåã«ãŒã¿ã¯ãã±ããã«èšèŒãããå®å
ããæ¬¡ã«è»¢éãã¹ãã«ãŒã¿ã倿ããŸããããã«ãç¡éã«ã«ãŒã¿éã転éããç¶ããããšãé²ãããããã±ããã«ã¯ TTLïŒTime To LiveïŒ ãšããå€ãä»å ãããŠããŸããã«ãŒã¿ã¯åãåã£ããã±ããã® TTL ã 1 æžç®ãããã®çµæã 0 ãªããã®ãã±ãããç Žæ£ãããã以å€ãªã次ã®ã«ãŒã¿ã«è»¢éããŸãã ããã§ããããã¯ãŒã¯ã®èšèšãæå©ãããããã°ã©ã ãäœãããšã«ãªããŸããããããã¯ãŒã¯ã®æ¥ç¶æ
å ±ãšéä¿¡ãã±ããã®æ
å ±ãå
¥åãšããŠãåãã±ãããå®å
ã«ãŒã¿ã«å°çãããŸã§ã«çµç±ããã«ãŒã¿ã®æ°ã®ãã¡æå°ã®å€ã衚瀺ããããã°ã©ã ãäœæããŠãã ããã ãããã¯ãŒã¯ã¯å³ã®ããã«è€æ°ã®ã«ãŒã¿ãšããããçµã¶ã±ãŒãã«ã§æ§æãããŠããŸãããã ãã忥ç¶ïŒã±ãŒãã«ïŒã¯åæ¹åã§ããããšã«æ³šæããŠãã ãããåã«ãŒã¿ãçŽæ¥ã€ãªãã£ãŠããã«ãŒã¿ã®çªå·ã®é
åããããã¯ãŒã¯ã®æ¥ç¶ã®æ
å ±ãšããŠäžããããŸããã«ãŒã¿ã®æ°ã n ãšããã°ãåã«ãŒã¿ã¯ 1 ãã n ãŸã§ã®æŽæ°ã§èå¥ãããŸããéä¿¡å
ããå®å
ã«ãŒã¿ãŸã§ã®çµè·¯ãè€æ°ããå Žåã¯ãçµç±ããã«ãŒã¿ã®æ°ãå°ãªãæ¹ã®å€ãåºåããŠãã ããããŸãããã±ãããå®å
ã«å°éããªãå Žå㯠NA ãšåºåããŠãã ããã äŸãã°ã以äžã®å³ã®ãããªãããã¯ãŒã¯ã§ãéä¿¡å
ã«ãŒã¿ã 6ãå®å
ã«ãŒã¿ã 5 ã®å ŽåãèããŸããæççµè·¯ã¯ 6â1â5 ã§ããçµç±ããã«ãŒã¿ã¯ 3 åã§ãããã®å ŽåãTTL ã¯ã«ãŒã¿ 6ã1 ã§ããããæžç®ãããã®ã§ãéä¿¡æã® TTL ã 3 以äžã§ããã°ãã±ããã¯å°éã§ããŸããå®å
ã«ãŒã¿ã§ã¯ TTL ãæžç®ããå¿
èŠã¯ãããŸããããŸããéä¿¡å
ãšå®å
ãåãã«ãŒã¿ã«ãªããããªãã±ããã¯ç¡ããã®ãšããŸãã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã n r 1 k 1 t 11 t 12 ... t 1k 1 r 2 k 2 t 21 t 22 ... t 2k 2 : r n k n t n1 t n2 ... t nk n p s 1 d 1 v 1 s 2 d 2 v 2 : s p d p v p 1 è¡ç®ã«ã«ãŒã¿ã®ç·æ° n ïŒ n †100ïŒãç¶ã n è¡ã« i çªç®ã®ã«ãŒã¿ã®æ¥ç¶æ
å ±ãäžããããŸããæ¥ç¶æ
å ±ãšããŠã i çªç®ã®ã«ãŒã¿ã®çªå· r i ã i çªç®ã®ã«ãŒã¿ãšçŽæ¥æ¥ç¶ããŠããã«ãŒã¿ã®åæ° k i ã i çªç®ã®ã«ãŒã¿ããéä¿¡ã§ããã«ãŒã¿ã®çªå· t i1 , t i2 , ... t ik i ãäžããããŸãã ç¶ãè¡ã«ãã±ããã®åæ° p ïŒ p †1000ïŒãç¶ã p è¡ã« i çªç®ã®ãã±ããã®æ
å ±ãäžããããŸãããã±ããã®æ
å ±ãšããŠã éä¿¡å
ã«ãŒã¿ã®çªå· s i , å®å
ã«ãŒã¿ã®çªå· d i , TTL ã®å€ v i (0 †v i †10000) ãäžããããŸãã Output åãã±ããããšã«ãçµç±ããã«ãŒã¿ã®åæ°ãŸã㯠NA ãïŒè¡ã«åºåããŠãã ããã Sample Input 7 1 4 2 5 4 3 2 1 5 3 1 6 4 1 7 5 2 7 6 6 1 1 7 0 6 1 2 2 1 5 3 1 2 1 5 1 3 6 3 3 1 7 4 Output for the Sample Input 2 2 NA 3 3 3 | 37,022 |
E: ã¢ã³ã¹ã¿ãŒãã¹ã¿ãŒ åé¡ AORã€ã«ã¡ããã¯ã¢ã³ã¹ã¿ãŒãã¹ã¿ãŒã§ãã. ããæ¥, éãæ©ããŠãããšå¯ãŠããã¢ã³ã¹ã¿ãŒã«åºäŒã£ã. éäºå¿ã匷ãAORã€ã«ã¡ããã¯,ã¢ã³ã¹ã¿ãŒã«å¯èµ·ãã®äžæããèŠèãããããšã«æ±ºãã. ããã, çŸåšã®AORã€ã«ã¡ããã®æ»æå㯠$0$ ã§ãã, ãã®ãŸãŸã§ã¯ãŸãšããªæ»æãã§ããªã. ã¢ã³ã¹ã¿ãŒãã¹ã¿ãŒã®ç²Ÿé²ãããŠããAORã€ã«ã¡ããã¯, å®ã¯åž«å ããç¹æ®ãªç¬ãèšãããŠãã. ãã®ç¬ã§ç¹å®ã®æ²ãå¹ããšäžå®æéæ»æåãäžããã®ã§ãã. ä¿®è¡ãç©ãã AORã€ã«ã¡ãã㯠$N$ åã®æ²ãå¹ãããšãã§ãã. $i$ çªç®ã®æ²ã¯æŒå¥ã« $R_i$ ç§ããã, æŒå¥çµäºåŸã«æ»æåã $A_i$ ã ãäžæãã. æŒå¥çµäºãã $T_i$ ç§åŸã«ãã®æŒå¥ã®å¹æã¯åã, æŒå¥åã®æ»æåã«æ»ã£ãŠããŸã. ãŸã, AORã€ã«ã¡ããã¯éãæŒå¥ãããããšãã§ãã. æŒå¥ã®å¹ææéäžã«åãæ²ãæŒå¥ãçµãããšæ»æåã $A_i$ ã§ã¯ãªã $W_i$ äžæãã. éãæŒå¥ã¯äœåã§ãã§ããã广æéã¯å»¶é·ããªã. ãã®ããçŸåšå¹æäžã® $i$ çªç®ã®æ²ã®æåã«ããã广ãåãããšéãæŒå¥ã®å¹æããã¹ãŠåãã. AORã€ã«ã¡ããã®æ»æåã®æå€§å€ãåºåãã. ãªã, ãããæŒå¥ããŠãã¢ã³ã¹ã¿ãŒã¯èµ·ããªãã, AORã€ã«ã¡ãã㯠$0.5$ ç§ã§æ»æã§ãã. å¶çŽ å
¥åå€ã¯å
šãп޿°ã§ãã. $1 \leq N \leq 2000$ $-2000 \leq A_i, W_i \leq 2000$ $1 \leq R_i , T_i \leq 2000$ å
¥ååœ¢åŒ å
¥åã¯ä»¥äžã®åœ¢åŒã§äžãããã. $N$ $R_1\ A_1\ W_1\ T_1$ $\vdots$ $R_N\ A_N\ W_N\ T_N$ åºå AORã€ã«ã¡ããã®æ»æåã®æå€§å€ãåºåãã. ãŸã, æ«å°Ÿã«æ¹è¡ãåºåãã. ãµã³ãã« ãµã³ãã«å
¥å 1 2 5 10 5 5 4 4 2 2 ãµã³ãã«åºå 1 14 ãµã³ãã«å
¥å 2 2 5 10 5 11 8 8 2 1 ãµã³ãã«åºå 2 20 | 37,023 |
Score : 200 points Problem Statement You are given a string S of length N consisting of lowercase English letters. We will cut this string at one position into two strings X and Y . Here, we would like to maximize the number of different letters contained in both X and Y . Find the largest possible number of different letters contained in both X and Y when we cut the string at the optimal position. Constraints 2 \leq N \leq 100 |S| = N S consists of lowercase English letters. Input Input is given from Standard Input in the following format: N S Output Print the largest possible number of different letters contained in both X and Y . Sample Input 1 6 aabbca Sample Output 1 2 If we cut the string between the third and fourth letters into X = aab and Y = bca , the letters contained in both X and Y are a and b . There will never be three or more different letters contained in both X and Y , so the answer is 2 . Sample Input 2 10 aaaaaaaaaa Sample Output 2 1 However we divide S , only a will be contained in both X and Y . Sample Input 3 45 tgxgdqkyjzhyputjjtllptdfxocrylqfqjynmfbfucbir Sample Output 3 9 | 37,024 |
Problem C: ã«ãŒãã²ãŒã ããã®ã²ã€ããšãžã£ãããŒã¯ã2人ã§éã¶ã«ãŒãã²ãŒã ã®ã«ãŒã«ãèããããã®ã«ãŒã«ãšã¯æ¬¡ã®ãããªãã®ã§ããã ãŸãã1ãã18ã®æ°åãæžãããã«ãŒããã·ã£ããã«ããããããã®ãã¬ãŒã€ãŒã«9æãã€é
ããäž¡è
ã¯åæã«1æã®ã«ãŒããåæã«åºãããã®å€ã«ãã£ãŠã¹ã³ã¢ãåŸããå€ã®å€§ããã«ãŒããåºãããã¬ãŒã€ãŒã¯ã倧ããæ¹ã®å€ãšå°ããæ¹ã®å€ã®åãèªåã®ã¹ã³ã¢ã«å ããããã®éãå€ã®å°ããã«ãŒããåºãããã¬ãŒã€ãŒã¯ã¹ã³ã¢ãåŸãããªãããŸããäžåºŠå Žã«åºãããã«ãŒãã¯äºåºŠãšäœ¿ãããšã¯ã§ããªããã«ãŒãããã¹ãŠäœ¿ãçµãã£ãåŸã«ã¹ã³ã¢ã倧ããã£ããã¬ãŒã€ãŒã®åã¡ãšããã ã²ã€ããšãžã£ãããŒã¯äºãã«ç¡äœçºã«ã«ãŒããéžãã§åºããŠã¿ãããšã«ãããæåã«é
ãããã«ãŒããäžãããããšããã²ã€ããšãžã£ãããŒãåã€ç¢ºçãããããæ±ããã Input ã²ã€ãããžã£ãããŒããããã®ææã¯ã9åã®æŽæ°ãããªããäž¡ãã¬ãŒã€ãŒã®ææã¯1ãã18ãŸã§ã®äºãã«ç°ãªãæŽæ°ã§ãããå
¥åã®1è¡ç®ã«ã¯ã²ã€ãã®ææã衚ã9åã®æŽæ°ãäžãããã2è¡ç®ã«ã¯ãžã£ãããŒã®ææã衚ã9åã®æŽæ°ãäžãããããæŽæ°ãšæŽæ°ã®éã¯ç©ºçœ1åã§åºåãããã Output ã²ã€ãããžã£ãããŒãåã€ç¢ºçããããããã¹ããŒã¹ã§åºåã£ãŠå°æ°ç¹ä»¥äž5æ¡ãŸã§åºåããã 10 -5 以å
ã®èª€å·®ã¯èš±å®¹ããããã0æªæºãããã¯1ãè¶ããå€ãåºåããŠã¯ãªããªãã Notes on Submission äžèšåœ¢åŒã§è€æ°ã®ããŒã¿ã»ãããäžããããŸããå
¥åããŒã¿ã® 1 è¡ç®ã«ããŒã¿ã»ããã®æ°ãäžããããŸããåããŒã¿ã»ããã«å¯Ÿããåºåãäžèšåœ¢åŒã§é çªã«åºåããããã°ã©ã ãäœæããŠäžããã Sample Input 2 1 3 5 7 9 11 13 15 17 2 4 6 8 10 12 14 16 18 1 5 7 9 11 13 15 17 18 2 3 4 6 8 10 12 14 16 Output for the Sample Input 0.30891 0.69109 0.92747 0.07253 | 37,025 |
Score : 100 points Problem Statement You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0 . Then, just after completing the i -th task, you can complete the j -th task at cost |A_j - A_i| . Here, |x| denotes the absolute value of x . Find the minimum total cost required to complete all the task. Constraints All values in input are integers. 1 \leq A_1, A_2, A_3 \leq 100 Input Input is given from Standard Input in the following format: A_1 A_2 A_3 Output Print the minimum total cost required to complete all the task. Sample Input 1 1 6 3 Sample Output 1 5 When the tasks are completed in the following order, the total cost will be 5 , which is the minimum: Complete the first task at cost 0 . Complete the third task at cost 2 . Complete the second task at cost 3 . Sample Input 2 11 5 5 Sample Output 2 6 Sample Input 3 100 100 100 Sample Output 3 0 | 37,026 |
Score : 700 points Problem Statement Squid loves painting vertices in graphs. There is a simple undirected graph consisting of N vertices numbered 1 through N , and M edges. Initially, all the vertices are painted in color 0 . The i -th edge bidirectionally connects two vertices a_i and b_i . The length of every edge is 1 . Squid performed Q operations on this graph. In the i -th operation, he repaints all the vertices within a distance of d_i from vertex v_i , in color c_i . Find the color of each vertex after the Q operations. Constraints 1 †N,M,Q †10^5 1 †a_i,b_i,v_i †N a_i â b_i 0 †d_i †10 1 †c_i â€10^5 d_i and c_i are all integers. There are no self-loops or multiple edges in the given graph. Partial Score 200 points will be awarded for passing the testset satisfying 1 †N,M,Q †2{,}000 . Input Input is given from Standard Input in the following format: N M a_1 b_1 : a_{M} b_{M} Q v_1 d_1 c_1 : v_{Q} d_{Q} c_{Q} Output Print the answer in N lines. In the i -th line, print the color of vertex i after the Q operations. Sample Input 1 7 7 1 2 1 3 1 4 4 5 5 6 5 7 2 3 2 6 1 1 1 2 2 Sample Output 1 2 2 2 2 2 1 0 Initially, each vertex is painted in color 0 . In the first operation, vertices 5 and 6 are repainted in color 1 . In the second operation, vertices 1 , 2 , 3 , 4 and 5 are repainted in color 2 . Sample Input 2 14 10 1 4 5 7 7 11 4 10 14 7 14 3 6 14 8 11 5 13 8 3 8 8 6 2 9 7 85 6 9 3 6 7 5 10 3 1 12 9 4 9 6 6 8 2 3 Sample Output 2 1 0 3 1 5 5 3 3 6 1 3 4 5 3 The given graph may not be connected. | 37,027 |
ç€é¢äžã«ãããããšå£ïŒãŽãŒã«ãèšçœ®ãããŠããïŒ ããããã®è¡åãã¿ãŒã³ãèšè¿°ããããã°ã©ã ãäžããããïŒ äžããããããã°ã©ã ã¯ä»¥äžã®EBNF ã§è¡šãããïŒ ããã°ã©ã := {æ}; æ:= if æ|while æ|åäœæ; if æ:= "[", æ¡ä»¶, ããã°ã©ã , "]"; while æ:= "{", æ¡ä»¶, ããã°ã©ã , "}"; åäœæ:= "^"|"v"|"<"|">"; æ¡ä»¶:= ["~"], "N"|"E"|"S"|"W"|"C"|"T"; ãããã°ã©ã ãã¯0å以äžã®ãæããããªãïŒ1ã€ä»¥äžã®æãååšããå Žå㯠1 ã€ç®ã®æããé çªã«1 ã€ãã€æãå®è¡ãããïŒãæãã¯ãåäœæãïŒãif æãïŒãwhile æãã®ããããã§ããïŒãåäœæãã¯" ^ ", " v "," < "," > " ã®ããããã§ããïŒãããã以äžã®åäœãå®è¡ãããïŒ " ^ ": åé² " v ": åŸé " < ": å·Šã«90 床å転 " > ": å³ã«90 床å転 ãif æã㯠" [ "ïŒãæ¡ä»¶ãïŒãããã°ã©ã ãïŒ" ] " ãé çªã«äžŠã¹ããã®ã§ïŒä»¥äžã®æé ã§å®è¡ãããïŒ ãæ¡ä»¶ãã®å
容ãçãã©ããå€å®ãã å€å®ãçãªããããã°ã©ã ãã®å
容ãå®è¡ãïŒãã®if æã®åŠçãçµäºãã å€å®ãåœãªããã®if æã®åŠçãçµäºãã ãwhile æã㯠" { "ïŒãæ¡ä»¶ãïŒãããã°ã©ã ãïŒ" } " ãé çªã«äžŠã¹ããã®ã§ïŒä»¥äžã®æé ã§å®è¡ãããïŒ ãæ¡ä»¶ãã®å
容ãçãã©ããå€å®ãã å€å®ãçãªããããã°ã©ã ãã®å
容ãå®è¡ãïŒ1 ã«æ»ã å€å®ãåœãªãïŒãã® while æã®åŠçãçµäºãã ãæ¡ä»¶ã㯠" N ", " E ", " S ", " W ", " C ", " T " ã®ããããã§ããïŒå
é ã«ã¯" ~ " ãã€ããããšãã§ããïŒããããã®èšè¿°ã¯ä»¥äžã®çåœå€ã衚ãïŒ å
é ã« " ~ " ãä»ããŠããå Žåã¯çåœå€ãé転 N : åãåããŠãããªãã°çïŒããã§ãªããã°åœ E : æ±ãåããŠãããªãã°çïŒããã§ãªããã°åœ S : åãåããŠãããªãã°çïŒããã§ãªããã°åœ W : 西ãåããŠãããªãã°çïŒããã§ãªããã°åœ C : ç®ã®åã«å£ããããªãã°çïŒããã§ãªããã°åœ T : åžžã«ç ããããã¯æåïŒåãåããŠãããã®ãšããïŒããããã¯å£ãéãããšãã§ããïŒäœããªããã¹ã®ã¿ãç§»åã§ããïŒããïŒããã°ã©ã ãå£ã®äžãéããããªåäœãå®è¡ããããšããå ŽåïŒããããã¯ç§»åãããã®å Žã«ãšã©ãŸãïŒæåŸã«ïŒããããã¯ãŽãŒã«ã«å°éããæïŒå®è¡éäžã®ããã°ã©ã ãæ®ã£ãŠãããšããŠããã¹ãŠäžæããŠåäœã忢ããïŒ ãã®ãšãïŒããããããŽãŒã«ã«ãã©ãçããŸã§ã«ã©ã®ãããæéããããã®ãç¥ãããïŒããããã¯æ¡ä»¶å€å®ãããã°ã©ã ã®èªã¿èŸŒã¿ã«é¢ããŠã¯éåžžã«é«éã«å®è¡ã§ããã®ã§å®éã®åäœæéãæ±ºå®ããã®ã¯ãåäœæãã®ã¿ã§ããïŒããã§ïŒãã®ããããããŽãŒã«ã«èŸ¿ãçããŸã§ã«ãåäœæããäœåå®è¡ããããæããŠã»ããïŒ ãªãïŒå£ã®äžãéããããªåäœãå®è¡ããããšããŠïŒå®éã«ã¯ãåäœæãã®åäœãè¡ãããªãã£ãå Žåã«ããåäœæãã¯å®è¡ããããã®ãšã¿ãªãïŒ Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ H W a 1,1 a 1,2 . . . a 1,W a 2,1 a 2,2 . . . a 2,W : : : a H,1 a H,2 . . . a H,W s H ã¯ç€é¢ã®é«ãïŒ W ã¯ç€é¢ã®å¹
ã衚ãïŒ æ¬¡ã«ç€é¢ãçäžããèŠãç¶æ
ãäžããããïŒãã®ç€é¢ã¯äžïŒäžïŒå·ŠïŒå³ãããããåïŒåïŒè¥¿ïŒæ±ã«å¯Ÿå¿ããïŒåãã¹ã®ç¶æ
ã衚ã a i,j ã¯ä»¥äžã®ããããã®æåã§ããïŒ " s " : ããããïŒããããã®åæäœçœ®ïŒãã®ãã¹ã«ã¯å£ããªãããšãä¿èšŒãããŠããïŒ " g " : ãŽãŒã« " # " : å£ïŒããããã¯å£ã®äžãç§»åããããšã¯ã§ããªãïŒ " . " : äœããªããã¹ s ã«ã¯ããããã«äžããããããã°ã©ã ãæååãšããŠå
¥åãããïŒ Constraints 1 †H,W †50 1 †s ã®æåæ° †1,000 a i,j ã¯" . ", " # ", " s ", " g " ã®ãããã " s ", " g " ã¯ãããã 1 åããç»å Žããªã i = 1 ãŸã㯠i = H ãŸã㯠j = 1 ãŸã㯠j = W ãªãã° a i,j = " # "ïŒç€é¢ã®å€åšã¯å£ã§å²ãŸããŠããããšãä¿èšŒãããŠããïŒ s ãšããŠäžããããããã°ã©ã ã¯æ§æçã«æ£ãã Output ãã©ãçããå Žåã¯"å°éãããŸã§ã«å®è¡ãããåäœæãã®æ°" ãïŒãã©ãã€ããªãå Žå㯠"-1" ãåºåããïŒãªãïŒå£ã®äžãéããããªåäœãå®è¡ããããšããŠïŒå®éã«ã¯ãåäœæãã®åäœãè¡ãããªãã£ãå Žåã«ããåäœæããå®è¡ããããã®ãšã¿ãªãç¹ã«æ³šæããïŒå
¥åäŸ1ïŒïŒ Sample Input 1 5 3 ### #g# #.# #s# ### ^<^<vv Output for the Sample Input 1 5 Sample Input 2 5 7 ####### #.#g..# #.###.# #s....# ####### {T{~C^}<} Output for the Sample Input 2 17 Sample Input 3 5 7 ####### #.#g..# #.###.# #s....# ####### {T{~C^}>} Output for the Sample Input 3 -1 | 37,028 |
Problem C: Cubic Eight-Puzzle Let's play a puzzle using eight cubes placed on a 3 Ã 3 board leaving one empty square. Faces of cubes are painted with three colors. As a puzzle step, you can roll one of the cubes to the adjacent empty square. Your goal is to make the specified color pattern visible from above by a number of such steps. The rules of this puzzle are as follows. Coloring of Cubes: All the cubes are colored in the same way as shown in Figure 3. The opposite faces have the same color. Figure 3: Coloring of a cube Initial Board State: Eight cubes are placed on the 3 Ã 3 board leaving one empty square. All the cubes have the same orientation as shown in Figure 4. As shown in the figure, squares on the board are given x and y coordinates, (1, 1), (1, 2), .. ., and (3, 3). The position of the initially empty square may vary. Figure 4: Initial board state Rolling Cubes: At each step, we can choose one of the cubes adjacent to the empty square and roll it into the empty square, leaving the original position empty. Figure 5 shows an example. Figure 5: Rolling a cube Goal: The goal of this puzzle is to arrange the cubes so that their top faces form the specified color pattern by a number of cube rolling steps described above. Your task is to write a program that finds the minimum number of steps required to make the specified color pattern from the given initial state. Input The input is a sequence of datasets. The end of the input is indicated by a line containing two zeros separated by a space. The number of datasets is less than 16. Each dataset is formatted as follows. x y F 11 F 21 F 31 F 12 F 22 F 32 F 13 F 23 F 33 The first line contains two integers x and y separated by a space, indicating the position ( x , y ) of the initially empty square. The values of x and y are 1, 2, or 3. The following three lines specify the color pattern to make. Each line contains three characters F 1 j , F 2 j , and F 3 j , separated by a space. Character F ij indicates the top color of the cube, if any, at position ( i , j ) as follows: B: Blue W: White R: Red E: the square is Empty. There is exactly one ' E ' character in each dataset. Output For each dataset, output the minimum number of steps to achieve the goal, when the goal can be reached within 30 steps. Otherwise, output " -1 " for the dataset. Sample Input 1 2 W W W E W W W W W 2 1 R B W R W W E W W 3 3 W B W B R E R B R 3 3 B W R B W R B E R 2 1 B B B B R B B R E 1 1 R R R W W W R R E 2 1 R R R B W B R R E 3 2 R R R W E W R R R 0 0 Output for the Sample Input 0 3 13 23 29 30 -1 -1 | 37,029 |
Problem G: Oil Company Irving & Cohen Petroleum Corporation has decided to develop a new oil field in an area. A preliminary survey has been done and they created a detailed grid map of the area which indicates the reserve of oil. They are now planning to construct mining plants on several grid blocks according this map, but they decided not to place any two plants on adjacent positions to avoid spreading of fire in case of blaze. Two blocks are considered to be adjacent when they have a common edge. You are one of the programmers working for the company and your task is to write a program which calculates the maximum amount of oil they can mine, given the map of the reserve. Input The first line of the input specifies N, the number of test cases. Then N test cases follow, each of which looks like the following: W H r 1,1 r 2,1 . . . r W ,1 ... r 1, H r 2, H . . . r W , H The first line of a test case contains two integers W and H (1 †W , H †20). They specifies the dimension of the area. The next H lines, each of which contains W integers, represent the map of the area. Each integer r x , y (0 †r x , y < 10000) indicates the oil reserve at the grid block ( x , y ). Output For each test case, output the case number (starting from 1) and the maximum possible amount of mining in a line. Refer to the sample output section about the format. Sample Input 2 2 2 2 3 3 5 3 2 4 1 1 2 1 4 Output for the Sample Input Case 1: 7 Case 2: 8 | 37,030 |
Score : 1500 points Problem Statement Iroha has a sequence of N strings s_1, s_2, ..., s_N . She will choose some (possibly all) strings from the sequence, then concatenate those strings retaining the relative order, to produce a long string. Among all strings of length K that she can produce in this way, find the lexicographically smallest one. Constraints 1 ⊠N ⊠2000 1 ⊠K ⊠10^4 For each i , 1 ⊠|s_i| ⊠K . |s_1| + |s_2| + ... + |s_N| ⊠10^6 For each i , s_i consists of lowercase letters. There exists at least one string of length K that Iroha can produce. Input The input is given from Standard Input in the following format: N K s_1 s_2 : s_N Output Print the lexicographically smallest string of length K that Iroha can produce. Sample Input 1 3 7 at coder codar Sample Output 1 atcodar at and codar should be chosen. Sample Input 2 3 7 coder codar at Sample Output 2 codarat codar and at should be chosen. Sample Input 3 4 13 kyuri namida zzzzzzz aaaaaa Sample Output 3 namidazzzzzzz namida and zzzzzzz should be chosen. | 37,031 |
Score : 800 points Problem Statement Takahashi has received an undirected graph with N vertices, numbered 1 , 2 , ..., N . The edges in this graph are represented by (u_i, v_i) . There are no self-loops and multiple edges in this graph. Based on this graph, Takahashi is now constructing a new graph with N^2 vertices, where each vertex is labeled with a pair of integers (a, b) ( 1 \leq a \leq N , 1 \leq b \leq N ). The edges in this new graph are generated by the following rule: Span an edge between vertices (a, b) and (a', b') if and only if both of the following two edges exist in the original graph: an edge between vertices a and a' , and an edge between vertices b and b' . How many connected components are there in this new graph? Constraints 2 \leq N \leq 100,000 0 \leq M \leq 200,000 1 \leq u_i < v_i \leq N There exists no pair of distinct integers i and j such that u_i = u_j and v_i = v_j . Input The input is given from Standard Input in the following format: N M u_1 v_1 u_2 v_2 : u_M v_M Output Print the number of the connected components in the graph constructed by Takahashi. Sample Input 1 3 1 1 2 Sample Output 1 7 The graph constructed by Takahashi is as follows. Sample Input 2 7 5 1 2 3 4 3 5 4 5 2 6 Sample Output 2 18 | 37,032 |
Score : 1500 points Problem Statement There are 2N points generally positioned on the circumference of a circle, numbered 1,\dots,2N in counterclockwise order. Here, a set of points is said to be generally positioned if, for any six distinct points U, V, W, X, Y, and Z among them, the segments UV, WX, and YZ do not intersect at the same point. Additionally, you will be given a 2N\times 2N matrix A . Find the number of ways to divide the 2N points into N pairs such that all of the following are satisfied: Let us draw a red segment connecting the two points for each pair. Then, those red segments form a tree . For each pair (P, Q) , A_{P,Q} = A_{Q,P} = 1 holds. Here, a set of segments is said to form a tree if they are all connected and form no cycles. For example, see the figure below: Upper left: the conditions are satisfied. Upper right: the red segments form a cycle, so the conditions are not satisfied. Lower left: the red segments are not connected, so the conditions are not satisfied. Lower right: some vertices belong to no pair or multiple pairs, so the conditions are not satisfied. Figure: A division satisfying the conditions (upper left) and divisions violating them (the others) Notes It can be proved that, as long as the 2N points are generally positioned, the answer does not depend on their specific positions. Constraints 1 \leq N \leq 20 A_{i,j} is 0 or 1 . A_{i,i} is 0 . A_{i,j}=A_{j,i} N is an integer. Input Input is given from Standard Input in the following format: N A_{1,1}...A_{1,2N} : A_{2N,1}...A_{2N,2N} Output Print the number of ways to divide the 2N points into N pairs such that all of the conditions are satisfied. It can be proved that the answer fits into a 64 -bit signed integer under the given constraints. Sample Input 1 3 011111 101111 110111 111011 111101 111110 Sample Output 1 3 There are three possible divisions that satisfy the conditions: ((1,4),(2,6),(3,5)) , ((1,3),(2,5),(4,6)) , and ((1,5),(2,4),(3,6)) . Sample Input 2 4 01111100 10011111 10011100 11101111 11110111 11111011 01011101 01011110 Sample Output 2 6 Sample Input 3 8 0111101111111111 1011101111111111 1101101111011101 1110111111111111 1111011111110111 0001101111111111 1111110111011111 1111111011111111 1111111101111111 1111111110111111 1101110111011111 1111111111101111 1111011111110111 1111111111111011 1101111111111101 1111111111111110 Sample Output 3 4762 | 37,033 |
Cube of Two Problem Statement æ¥æ¬ã§è²©å£²ãããŠããã«ãŒããã¯ãã¥ãŒãã®åé¢ã®é
è²ãïŒ äžçã§æšæºçã«æ¡çšãããŠãããã®ã«åãããããã®ã¯ã€ãæè¿ã®ããšã ïŒ ããã«æ
£ããããïŒãŸãã¯ç°¡åãª2x2x2ã®ãã¥ãŒããã¹ã¯ã©ã³ãã«ããŠéãŒãïŒ åæç¶æ
ã®ã«ãŒããã¯ãã¥ãŒãã¯ïŒåè²ã1ã€ã®é¢ã«éãŸãããã«æããããŠããïŒ äžé¢ã«èµ€è²ïŒæ£é¢ã«é»è²ïŒå³åŽé¢ã«éè²ãèŠããïŒ ãŸãïŒäžé¢ã¯æ©è²ïŒèé¢ã¯çœè²ïŒå·ŠåŽé¢ã¯ç·è²ã§ããïŒ å±éå³ãçšãããšæ¬¡ã®ããã«è¡šããïŒ åé¢ã«å¯ŸãïŒåãã£ãŠæèšåãã«90°å転ãããæäœãïŒããããã®é æåããšã£ãŠU,F,R,D,B,Lãšè¡šãïŒ ã«ãŒããã¯ãã¥ãŒãã®ã¹ã¯ã©ã³ãã«ã¯ïŒåæåã1ã€ã®å転æäœã«å¯Ÿå¿ããæåå S ãšããŠè¡šãããïŒ åæç¶æ
ããå
¥åã«åŸã£ãŠã¹ã¯ã©ã³ãã«ãããšãã®ïŒã«ãŒããã¯ãã¥ãŒãã®åé¢ã®è²ãå±éå³ãšããŠåºåããïŒ Input å
¥åã¯ä»¥äžã®åœ¢åŒã«åŸãïŒ S Constraints 1âŠ|S|âŠ100 ïŒ |S| ã¯æååã®é·ãïŒ S ã¯U,F,R,D,B,Lã®ã¿ãå«ãïŒ Output åæç¶æ
ã®ã«ãŒããã¯ãã¥ãŒãã«å¯ŸãïŒåå転æäœãé ã«é©çšããåŸã®åé¢ã®ç¶æ
ãå±éå³ãšããŠåºåããïŒ åé¢ã®è²ã¯r(èµ€),o(æ©),y(é»),g(ç·),b(é),w(çœ)ã®6çš®é¡ã®è±å°æåã§è¡šãïŒ ãŸãïŒç©ºçœéšã¯ããªãªã(.)ã§è¡šãïŒ Sample Input 1 R Output for the Sample Input 1 ..ry.... ..ry.... ggyobbrw ggyobbrw ..ow.... ..ow.... å³åŽé¢ãæèšåãã«90°å転ããããšæ¬¡ã®ããã«ãªãïŒ Sample Input 2 UFRDBL Output for the Sample Input 2 ..go.... ..yb.... rbrwrwby wogoygwo ..yb.... ..gr.... åå転æäœã«å¯Ÿããç¶æ
ã®é·ç§»ã¯æ¬¡ã®ããã«ãªãïŒ | 37,034 |
Problem I: Encircling Circles You are given a set of circles C of a variety of radii (radiuses) placed at a variety of positions, possibly overlapping one another. Given a circle with radius r , that circle may be placed so that it encircles all of the circles in the set C if r is large enough. There may be more than one possible position of the circle of radius r to encircle all the member circles of C . We define the region U as the union of the areas of encircling circles at all such positions. In other words, for each point in U , there exists a circle of radius r that encircles that point and all the members of C . Your task is to calculate the length of the periphery of that region U . Figure I.1 shows an example of the set of circles C and the region U . In the figure, three circles contained in C are expressed by circles of solid circumference, some possible positions of the encircling circles are expressed by circles of dashed circumference, and the area U is expressed by a thick dashed closed curve. Input The input is a sequence of datasets. The number of datasets is less than 100. Each dataset is formatted as follows. n r x 1 y 1 r 1 x 2 y 2 r 2 . . . x n y n r n The first line of a dataset contains two positive integers, n and r , separated by a single space. n means the number of the circles in the set C and does not exceed 100. r means the radius of the encircling circle and does not exceed 1000. Each of the n lines following the first line contains three integers separated by a single space. ( x i , y i ) means the center position of the i -th circle of the set C and r i means its radius. You may assume â500†x i â€500, â500†y i â€500, and 1†r i â€500. The end of the input is indicated by a line containing two zeros separated by a single space. Output For each dataset, output a line containing a decimal fraction which means the length of the periphery (circumferential length) of the region U . The output should not contain an error greater than 0.01. You can assume that, when r changes by ε (|ε| < 0.0000001), the length of the periphery of the region U will not change more than 0.001. If r is too small to cover all of the circles in C , output a line containing only 0.0. No other characters should be contained in the output. Sample Input 1 10 5 5 7 2 12 5 5 7 8 6 3 3 10 3 11 2 2 1 1 2 16 3 3 15 -5 2 5 9 2 9 5 8 6 3 38 -25 -10 8 30 5 7 -3 35 11 3 39 -25 -10 8 30 5 7 -3 35 11 3 800 -400 400 2 300 300 1 300 302 1 3 800 400 -400 2 300 300 1 307 300 3 8 147 130 80 12 130 -40 12 -110 80 12 -110 -40 12 70 140 12 70 -100 12 -50 140 12 -50 -100 12 3 493 345 154 10 291 111 75 -275 -301 46 4 55 54 0 1 40 30 5 27 36 10 0 48 7 3 30 0 3 3 -3 0 4 400 0 3 3 7 2 3 2 -5 -4 2 -4 3 2 3 10 -5 -4 5 2 3 5 -4 3 5 4 6 4 6 1 5 5 1 1 7 1 0 1 1 3 493 345 154 10 291 111 75 -275 -301 46 5 20 -9 12 5 0 15 5 3 -3 3 12 9 5 -12 9 5 0 0 Output for the Sample Input 81.68140899333463 106.81415022205297 74.11215318612639 108.92086846105579 0.0 254.85616536128433 8576.936716409238 8569.462129048667 929.1977057481128 4181.124698202453 505.09134735536804 0.0 46.82023824234038 65.66979416387915 50.990642291793506 4181.124698202453 158.87951420768937 | 37,035 |
å
±ééšåæåå åé¡ 2 åã®æååãäžãããããšã, äž¡æ¹ã®æååã«å«ãŸããæååã®ãã¡æãé·ããã®ãæ¢ã, ãã®é·ããçããããã°ã©ã ãäœæãã. ããã§, æåå s ãæåå t ã«å«ãŸãããšã¯, t ã®äžã« s ãé£ç¶ããŠçŸããããšããã. 空æåå, ããªãã¡é·ã 0 ã®æååã¯, ã©ããªæååã«ãå«ãŸãã. äŸãã°, æåå ABRACADABRA ã«ã¯æ¬¡ã®æååãå«ãŸãã: ABRA, RAC, D, ACADABRA, ABRACADABRA,空æååãªã©. äžæ¹, æåå ABRACADABRA ã«ã¯æ¬¡ã®æååã¯å«ãŸããªã: ABRC, RAA,BA, K ãªã©. äŸ äŸ 1: æååãšã㊠ABRACADABRA ãš ECADADABRBCRDARA ãäžããããå Žå, äž¡æ¹ã«å«ãŸããæååã«ã¯ CA ã CADA ã ADABR ã空æååãªã©ããã. ãã®ãã¡æãé·ãã®ã¯ ADABR ã§ãã, ãã®é·ã㯠5 ã§ãã. 2 åã®æååã®äžã«å«ãŸãã ADABR ã®äœçœ®ã以äžã«ç€ºã. ABRAC ADABR A ECAD ADABR BCRDARA äŸ 2: æååãšã㊠UPWJCIRUCAXIIRGL ãš SBQNYBSBZDFNEV ãäžããããå Žå, äž¡æ¹ã«å«ãŸããæååã¯ç©ºæååã®ã¿ã§ãã, ãã®é·ã㯠0 ã§ãã. å
¥å å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ å
¥å㯠2 è¡ãããªã, 1 è¡ç®ã« 1 åç®ã®æååã, 2 è¡ç®ã« 2 åç®ã®æååãäžãããã. æååã¯è±å€§æåãããªã, åã
ã®æååã®é·ã㯠1 ä»¥äž 4000 以äžã§ãã. æ¡ç¹çšããŒã¿ã®ãã¡, é
ç¹ã® 30% åã«ã€ããŠã¯, åã
ã®æååã®é·ã㯠1 ä»¥äž 50以äžã§ãã. å
¥åã®çµãã㯠EOF ã§ç€ºããã. ããŒã¿ã»ããã®æ°ã¯ 10 ãè¶
ããªãïŒ åºå ããŒã¿ã»ããããšã«äžãããã 2 åã®æååã®äž¡æ¹ã«å«ãŸããæååã®ãã¡æãé·ããã®ã®é·ãã 1 è¡ã«åºåãã. å
¥åºåäŸ å
¥åäŸ ABRACADABRA ECADADABRBCRDARA UPWJCIRUCAXIIRGL SBQNYBSBZDFNEV åºåäŸ 5 0 äžèšå顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã | 37,036 |
Queries with Six Inequeties åã€ã®æŽæ°ã®çµ (a,b,c,d) ã®éåãäžããããŸãã j çªç®ã®ã¯ãšãªã§ã¯ã x_j < a_i < y_j < b_i ã〠z_j < c_i < w_j < d_i ãªã i ãååšãããå€å®ããŸãã å
¥å N Q a_1 b_1 c_1 d_1 a_2 b_2 c_2 d_2 : a_n b_n c_n d_n x_1 y_1 z_1 w_1 x_2 y_2 z_2 w_2 : x_q y_q z_q w_q åºå ans_1 ans_2 : ans_q j è¡ç®ã«ã¯ã j çªç®ã®ã¯ãšãªã«å¯Ÿããçããåºåããã æ¡ä»¶ãæºããæ·»å i ãååšãããªã Yes ãååšããªããªã No ãåºåããã å¶çŽ 1 \leq N,Q \leq 10^5 1 \leq a_i < b_i \leq 10^5 1 \leq c_i < d_i \leq 10^5 1 \leq x_j < y_j \leq 10^5 1 \leq z_j < w_j \leq 10^5 å
¥åäŸ 2 2 14 86 9 121 3 34 3 34 1 14 5 14 1 9 1 9 åºåäŸ No Yes | 37,037 |
List of Top 3 Hills There is a data which provides heights (in meter) of mountains. The data is only for ten mountains. Write a program which prints heights of the top three mountains in descending order. Input Height of mountain 1 Height of mountain 2 Height of mountain 3 . . Height of mountain 10 Constraints 0 †height of mountain (integer) †10,000 Output Height of the 1st mountain Height of the 2nd mountain Height of the 3rd mountain Sample Input 1 1819 2003 876 2840 1723 1673 3776 2848 1592 922 Output for the Sample Input 1 3776 2848 2840 Sample Input 2 100 200 300 400 500 600 700 800 900 900 Output for the Sample Input 2 900 900 800 | 37,038 |
ééè·¯ç·II ãããã®äœãè¡ã«ã¯ãå³ã®ãã㪠N åã®é§
ãããªãåç°ç¶ã®ééè·¯ç·ããããŸãããã®è·¯ç·ã®åé§
ã«ã¯ 0 ãã N -1 ãŸã§ã®çªå·ãé çªã«å²ãåœãŠãããŠããŠãé£ã®é§
ãŸã§100 åã§ç§»åããããšãã§ããŸããç§»åã¯ã©ã¡ãã®æ¹åã«ã§ãå¯èœã§ãã ãããã¯ãã®è·¯ç·äžã®ããã€ãã®é§
ã§è²·ãç©ãããããšæã£ãŠããŸããããã§ãããã°ã©ã ãäœæããŠç§»åè²»ãèšç®ããããšã«ããŸãããããé§
ãå§ç¹ãšããŠãè²·ãç©ããããã¹ãŠã®é§
ã蚪åããæå°ã®è²»çšïŒåïŒãæ±ããããã°ã©ã ãäœæããŠãã ããããã ããåãé§
ãäœåºŠèšªåããŠãè¯ããã©ã®ãããªé çªã§é§
ã蚪åããŠãæ§ããŸããã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã N M p d 1 d 2 : d M 1è¡ç®ã«é§
ã®æ° N (2 †N †100000)ãè²·ãç©ãããé§
ã®æ° M (1 †M †10000 ã〠M < N )ãåºçºããé§
ã®çªå· p (0 †p †N -1) ãäžãããããç¶ã M è¡ã«è²·ãç©ãããé§
ã®çªå· d i (0 †d i †N -1) ãäžããããããã ãã d i ã¯å
šãŠç°ãªãã p ããŸãã©ã® d i ãšãç°ãªããã®ãšããã åºå æå°ã®è²»çšãïŒè¡ã«åºåããã å
¥åºåäŸ å
¥åäŸïŒ 5 4 0 1 2 3 4 åºåäŸïŒ 400 å
¥åäŸïŒ 7 2 1 6 2 åºåäŸïŒ 400 | 37,039 |
Score : 100 points Problem Statement In AtCoder City, there are three stations numbered 1 , 2 , and 3 . Each of these stations is operated by one of the two railway companies, A and B. A string S of length 3 represents which company operates each station. If S_i is A , Company A operates Station i ; if S_i is B , Company B operates Station i . To improve the transportation condition, for each pair of a station operated by Company A and one operated by Company B, there will be a bus service connecting them. Determine if there is a pair of stations that will be connected by a bus service. Constraints Each character of S is A or B . |S| = 3 Input Input is given from Standard Input in the following format: S Output If there is a pair of stations that will be connected by a bus service, print Yes ; otherwise, print No . Sample Input 1 ABA Sample Output 1 Yes Company A operates Station 1 and 3 , while Company B operates Station 2 . There will be a bus service between Station 1 and 2 , and between Station 2 and 3 , so print Yes . Sample Input 2 BBA Sample Output 2 Yes Company B operates Station 1 and 2 , while Company A operates Station 3 . There will be a bus service between Station 1 and 3 , and between Station 2 and 3 , so print Yes . Sample Input 3 BBB Sample Output 3 No Company B operates all the stations. Thus, there will be no bus service, so print No . | 37,040 |
Score : 800 points Problem Statement You are given an integer sequence x of length N . Determine if there exists an integer sequence a that satisfies all of the following conditions, and if it exists, construct an instance of a . a is N^2 in length, containing N copies of each of the integers 1 , 2 , ... , N . For each 1 †i †N , the i -th occurrence of the integer i from the left in a is the x_i -th element of a from the left. Constraints 1 †N †500 1 †x_i †N^2 All x_i are distinct. Input The input is given from Standard Input in the following format: N x_1 x_2 ... x_N Output If there does not exist an integer sequence a that satisfies all the conditions, print No . If there does exist such an sequence a , print Yes in the first line, then print an instance of a in the second line, with spaces inbetween. Sample Input 1 3 1 5 9 Sample Output 1 Yes 1 1 1 2 2 2 3 3 3 For example, the second occurrence of the integer 2 from the left in a in the output is the fifth element of a from the left. Similarly, the condition is satisfied for the integers 1 and 3 . Sample Input 2 2 4 1 Sample Output 2 No | 37,041 |
Closest Pair For given n points in metric space, find the distance of the closest points. Input n x 0 y 0 x 1 y 1 : x n-1 y n-1 The first integer n is the number of points. In the following n lines, the coordinate of the i -th point is given by two real numbers x i and y i . Each value is a real number with at most 6 digits after the decimal point. Output Print the distance in a line. The output values should be in a decimal fraction with an error less than 0.000001. Constraints 2 †n †100,000 -100 †x , y †100 Sample Input 1 2 0.0 0.0 1.0 0.0 Sample Output 1 1.000000 Sample Input 2 3 0.0 0.0 2.0 0.0 1.0 1.0 Sample Output 2 1.41421356237 | 37,042 |
Satan Attacks Time Limit: 8 sec / Memory Limit: 64 MB G: éçã®è¥²æ äŒèª¬ã®å£ãç Žå£ããéçã¯ïŒã€ãã«åè
ãããéºè·¡ã«è¿œãè©°ããïŒ æ¢ã«åè
ã¯è¢ã®éŒ ã§ãããïŒçžæã¯ç¥ã
ã®å è·ãåŸãåè
ã§ããïŒ ããšãäŒèª¬ã®å£ããªããšãïŒãããªãå¥è·¡ã奎ã«å³æ¹ãããããã£ããã®ã§ã¯ãªãïŒ éçãäŒèª¬ã®å£ã®ç Žå£ããããŸã§ã®æŠéã§ïŒéåã倧éã«æ¶è²»ãïŒç²åŒããŠããïŒ ããã§ïŒäžå
šãæãããã«ïŒåŒ·åãªäœ¿ãéã倧éã«å¬åãïŒäžææ»æã仿ããããšã«ããïŒ ãããïŒåŒ·åãªäœ¿ãéã䜿圹ããã«ã¯ïŒéåã倧éã«æ¶è²»ããŠããŸãïŒ äžãäžïŒåè
ã䜿ãéã«ããç·æ»æãçªç Žããå Žåã«åãïŒã§ããã ãéåãæž©åãããïŒ ããã§ïŒå
¥ãå£ãã䜿ãéãäžåºŠã«çªå
¥ããïŒäœäœã®äœ¿ãéãäžæã«åè
ãæ»æã§ããã®ã調ã¹ãããšã«ãªã£ãïŒ éçã®å³è
ã§ããããªãã¯ïŒäœçŽãªäœ¿ãéãå¬åãïŒéºè·¡ã®æ§é ã調ã¹ãããïŒ ãããïŒäœçŽãªäœ¿ãéãå©çšãããããïŒå ±åãããå
容ã¯éåžžã«ãããã¥ãããã®ãšãªã£ãŠããŸã£ãïŒ ãã®ãŸãŸã§ã¯åœ¹ã«ç«ããªãã®ã§ïŒä»æ¹ãªã䜿ãéã®å ±åãåæããããšã«ããïŒ ãŸãïŒéºè·¡ã®å
¥å£ã«ã€ããŠã ãïŒè€æ°ã®å
¥å£ãããïŒ ãããã®å
¥å£ã¯ïŒå¿
ãéè·¯ã®ç«¯ãŸãã¯ããã€ãã®éè·¯ã亀差ããå Žæã«ããããšãããã£ãïŒ ãŸãïŒåè
ã¯å
¥å£ã§ã¯ãªãéè·¯ã®ç«¯ã亀差ããå Žæã«ããããã ïŒ ãããŠïŒåé¡ã¯éºè·¡å
ã®éè·¯ã§ããïŒ ãã®éºè·¡ã«ã¯éè¡çãªçµçãã¬ãŒãã£ã¢ã³ãªã©ã¯ååšããªããïŒéè·¯ãè€éã«å
¥ãçµãã§ããïŒ å¹žããšãã£ãŠããã®ãïŒéè·¯ã«ã¯ç¹ã«äžæ¹éè¡ç³»ã®ãã©ãããïŒ äžåºŠéã£ãéè·¯ãäºåºŠãšéããªããªããããªãã©ããã¯ååšããªãããã ïŒ ãã¡ããïŒå
¥ã床ã«éºè·¡å
éšå
šäœã®æ§é ãå€ãã£ãŠããŸããããªãã©ããããªãïŒ äœ¿ãéãã¡ã¯ïŒåéè·¯ã®æ
å ±ãïŒéºè·¡ã®äžã«ããéè·¯ã®2ã€ã®ç«¯ç¹ã®åº§æšãšïŒ ãã®éè·¯ãåæã«éãããšãã§ãã䜿ãéã®æ°ãšãã圢ã§å ±åããŠããïŒ å³1 䜿ãéã®å ±åããéºè·¡å
ã®éè·¯å士ã¯ïŒäº€å·®ããããšãããïŒ äºã€ã®éè·¯ãäžç¹ã§äº€ããå Žåã«ïŒãããäžã€ã®äº€ç¹ãšããŠæ°ããïŒ ãã®ãšãïŒéãã䜿ãéã®æ°ã¯ïŒéè·¯ã®é·ãã«å¯ŸããŠæ¯äŸé
åããããïŒ äŸãã°å³1ã®ããã«ïŒäœ¿ãéã20å¹éãã(0,0)ãš(10,0)ãç¹ãéè·¯ã«å¯ŸããŠïŒ 亀ç¹ã(4.5,0)ã«ã§ããå Žåã¯ïŒäœ¿ãéã9å¹éãã(0,0)ãš(4.5,0)ãç¹ãéè·¯ãšïŒ 䜿ãéã11å¹éãã(4.5,0)ãš(10,0)ãç¹ãéè·¯ã®2ã€ã«åå²ãããïŒ å³2 ããã«ïŒå ±åãããéè·¯å士ã¯éãªãããšãããïŒ ãã®ãšãã¯éãªã£ãéè·¯éšåå士ã®åã䜿ãéã®éããæ°ã«ãªãïŒ äŸãã°å³2ã®ããã«ïŒäœ¿ãéã10å¹éãã(0,0)ãš(10,0)ãç¹ãéè·¯ãšïŒ 䜿ãéã20å¹éãã(2,0)ãš(12,0)ãç¹ãéè·¯ãäžãããããšãã¯ïŒ 䜿ãéã2å¹éãã(0,0)ãš(2,0)ãç¹ãéè·¯ãšïŒ 䜿ãéã8+16ã§24å¹éãã(2,0)ãš(10,0)ãç¹ãéè·¯ãšïŒ 䜿ãéã4å¹éãã(10,0)ãš(12,0)ãç¹ãéè·¯ã«åå²ãããïŒ å ±åãããéè·¯ã®æ
å ±ãåºã«ïŒåå²ã䜵åãè¡ã£ãŠãããšïŒèšç®äžéãã䜿ãéã®æ°ã«å°æ°ãåºãããšãããïŒ äœ¿ãéã¯å°ãããªã£ããïŒååã®å€§ããã«åè£ãããã¯ã§ããªãããïŒå°æ°éšåã¯åãæšãŠãŠèããã°ããã ããïŒ äœ¿ãéããã®æ
å ±ããããŸã§åæããããšã§ïŒéºè·¡å
ã®æ§é ãèŠããŠããïŒ åŸã¯ïŒã©ãã ãã®äœ¿ãéãäžæã«åè
ãæ»æã§ããã®ãå²ãåºãã ãã§ããïŒ Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ n ax 1 ay 1 bx 1 by 1 w 1 ã»ã»ã» ax n ay n bx n by n w n m cx 1 cy 1 ã»ã»ã» cx n cy n dx dy å
¥åã®åœ¢åŒã«å«ãŸããå倿°ã®æå³ãšå¶çŽã¯ä»¥äžã®éãã§ããïŒ n (0 < n <=50)ã¯å»ºç©å
ã®éè·¯ã®æ°ã衚ãïŒ ( ax i , ay i )ãš( bx i , by i ) (0 <= ax i , ay i , bx i , by i <= 100)ã¯ããéè·¯ã®ç«¯ç¹ã衚ã ïŒããã§( ax i , ay i )â ( bx i , by i )ã§ããããšãä¿èšŒãããïŒãŸãããããã®éè·¯ã«å¯ŸããŠïŒäœ¿ãéã w i (0 < w i <= 100)å¹éãããšãã§ããïŒ m (0 < m <= 10) ã¯å
¥ãå£ã®æ°ã衚ãïŒ( cx i , cy i )ãå
¥ãå£ã®äœçœ®ãïŒ ( dx , dy ) ã¯åè
ãé ããŠããäœçœ®ã衚ãïŒãŸã cx i , cy i , dx , dy ã¯ãã¹ãŠå°æ°ç¬¬6äœã®æ°å€ãŸã§äžããããïŒå
¥å£ã®å ŽæïŒåè
ãé ããŠããäœçœ®ã¯ïŒéè·¯ã®ç«¯ç¹ã亀ç¹äžã§ããïŒãŸãåå²ãããéè·¯ã®é·ãã¯ïŒ0.000001ãã倧ããããšãä¿èšŒãããŠããïŒ Output åè
ãé ããŠããäœçœ®ã«ïŒåæã«è¥²ãããšãåºæ¥ã䜿ãéã®æå€§ã®æ°ãåºåããïŒ Sample Input 1 2 0 0 5 0 10 1 0 6 0 10 1 0.000000 0.000000 6.000000 0.000000 Sample Output 1 2 Sample Input 2 2 3 0 7 0 10 0 0 10 0 100 1 0.000000 0.000000 10.000000 0.000000 Sample Output 2 30 Sample Input 3 2 0 0 5 5 7 0 5 5 0 4 1 0.000000 0.000000 2.500000 2.500000 Sample Output 3 3 Sample Input 4 2 0 0 5 0 9 3 0 8 0 9 1 3.000000 0.000000 5.000000 0.000000 Sample Output 4 7 Sample Input 5 10 30 58 43 79 60 16 68 71 61 66 45 59 66 63 63 19 84 28 42 46 45 82 12 76 68 25 57 31 17 59 75 62 18 41 78 32 77 67 18 46 27 89 29 7 32 26 52 14 38 30 4 25.000000 57.000000 61.708447 62.182561 27.000000 89.000000 27.249448 78.772627 36.776964 68.947403 Sample Output 5 12 | 37,043 |
Score : 500 points Problem Statement There is a rooted tree (see Notes) with N vertices numbered 1 to N . Each of the vertices, except the root, has a directed edge coming from its parent. Note that the root may not be Vertex 1 . Takahashi has added M new directed edges to this graph. Each of these M edges, u \rightarrow v , extends from some vertex u to its descendant v . You are given the directed graph with N vertices and N-1+M edges after Takahashi added edges. More specifically, you are given N-1+M pairs of integers, (A_1, B_1), ..., (A_{N-1+M}, B_{N-1+M}) , which represent that the i -th edge extends from Vertex A_i to Vertex B_i . Restore the original rooted tree. Notes For "tree" and other related terms in graph theory, see the article in Wikipedia , for example. Constraints 3 \leq N 1 \leq M N + M \leq 10^5 1 \leq A_i, B_i \leq N A_i \neq B_i If i \neq j , (A_i, B_i) \neq (A_j, B_j) . The graph in input can be obtained by adding M edges satisfying the condition in the problem statement to a rooted tree with N vertices. Input Input is given from Standard Input in the following format: N M A_1 B_1 : A_{N-1+M} B_{N-1+M} Output Print N lines. In the i -th line, print 0 if Vertex i is the root of the original tree, and otherwise print the integer representing the parent of Vertex i in the original tree. Note that it can be shown that the original tree is uniquely determined. Sample Input 1 3 1 1 2 1 3 2 3 Sample Output 1 0 1 2 The graph in this input is shown below: It can be seen that this graph is obtained by adding the edge 1 \rightarrow 3 to the rooted tree 1 \rightarrow 2 \rightarrow 3 . Sample Input 2 6 3 2 1 2 3 4 1 4 2 6 1 2 6 4 6 6 5 Sample Output 2 6 4 2 0 6 2 | 37,044 |
Score : 100 points Problem Statement Consider an infinite sequence a_1, a_2, ⊠Initially, the values of all the terms are 0 , and from this state we will sequentially perform Q operations. The i -th operation (1 †i †Q) is as follows: For every positive integer j , add x_i to the value of a_{j à m_i} . Find the value of the largest term after these Q operations. Constraints 1 †Q †299 2 †m_i †300 -10^6 †x_i †10^6 All m_i are distinct. All input values are integers. Input Input is given from Standard Input in the following format: Q m_1 x_1 : m_Q x_Q Output Print the value of the largest term after the Q operations. Sample Input 1 3 2 10 3 -20 6 15 Sample Output 1 10 The values of each terms in the sequence a_1, a_2, ⊠change as follows: Before the operations: 0, 0, 0, 0, 0, 0, ⊠After the 1 -st operation: 0, 10, 0, 10, 0, 10, ⊠After the 2 -nd operation: 0, 10, -20, 10, 0, -10, ⊠After the 3 -rd operation: 0, 10, -20, 10, 0, 5, ⊠The value of the largest term after all the operations is 10 . Sample Input 2 3 10 -3 50 4 100 -5 Sample Output 2 1 Sample Input 3 5 56 114834 72 -149861 100 190757 192 -132693 240 133108 Sample Output 3 438699 | 37,045 |
Score : 500 points Problem Statement There are N integers, A_1, A_2, ..., A_N , written on a blackboard. We will repeat the following operation N-1 times so that we have only one integer on the blackboard. Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y . Find the maximum possible value of the final integer on the blackboard and a sequence of operations that maximizes the final integer. Constraints 2 \leq N \leq 10^5 -10^4 \leq A_i \leq 10^4 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 possible value M of the final integer on the blackboard, and a sequence of operations x_i, y_i that maximizes the final integer, in the format below. Here x_i and y_i represent the integers x and y chosen in the i -th operation, respectively. If there are multiple sequences of operations that maximize the final integer, any of them will be accepted. M x_1 y_1 : x_{N-1} y_{N-1} Sample Input 1 3 1 -1 2 Sample Output 1 4 -1 1 2 -2 If we choose x = -1 and y = 1 in the first operation, the set of integers written on the blackboard becomes (-2, 2) . Then, if we choose x = 2 and y = -2 in the second operation, the set of integers written on the blackboard becomes (4) . In this case, we have 4 as the final integer. We cannot end with a greater integer, so the answer is 4 . Sample Input 2 3 1 1 1 Sample Output 2 1 1 1 1 0 | 37,046 |
Score : 300 points Problem Statement AtCoDeer the deer is going on a trip in a two-dimensional plane. In his plan, he will depart from point (0, 0) at time 0 , then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i . If AtCoDeer is at point (x, y) at time t , he can be at one of the following points at time t+1 : (x+1,y) , (x-1,y) , (x,y+1) and (x,y-1) . Note that he cannot stay at his place . Determine whether he can carry out his plan. Constraints 1 †N †10^5 0 †x_i †10^5 0 †y_i †10^5 1 †t_i †10^5 t_i < t_{i+1} ( 1 †i †N-1 ) All input values are integers. Input Input is given from Standard Input in the following format: N t_1 x_1 y_1 t_2 x_2 y_2 : t_N x_N y_N Output If AtCoDeer can carry out his plan, print Yes ; if he cannot, print No . Sample Input 1 2 3 1 2 6 1 1 Sample Output 1 Yes For example, he can travel as follows: (0,0) , (0,1) , (1,1) , (1,2) , (1,1) , (1,0) , then (1,1) . Sample Input 2 1 2 100 100 Sample Output 2 No It is impossible to be at (100,100) two seconds after being at (0,0) . Sample Input 3 2 5 1 1 100 1 1 Sample Output 3 No | 37,047 |
Reading Brackets in English Shun and his professor are studying Lisp and S-expressions. Shun is in Tokyo in order to make a presen- tation of their research. His professor cannot go with him because of another work today. He was making final checks for his slides an hour ago. Then, unfortunately, he found some serious mistakes! He called his professor immediately since he did not have enough data in his hand to fix the mistakes. Their discussion is still going on now. The discussion looks proceeding with difficulty. Most of their data are written in S-expressions, so they have to exchange S-expressions via telephone. Your task is to write a program that outputs S-expressions represented by a given English phrase. Input The first line of the input contains a single positive integer N , which represents the number of test cases. Then N test cases follow. Each case consists of a line. The line contains an English phrase that represents an S-expression. The length of the phrase is up to 1000 characters. The rules to translate an S-expression are as follows. An S-expression which has one element is translated into âa list of < the element of the S-expression >â. (e.g. â(A)â will be âa list of Aâ) An S-expression which has two elements is translated into âa list of < the first element of the S-expression > and < the second element of the S-expression >â. (e.g. â(A B)â will be âa list of A and Bâ) An S-expression which has more than three elements is translated into âa list of < the first element of the S-expression >, < the second element of the S-expression >, . . . and < the last element of the S-expression >â. (e.g. â(A B C D)â will be âa list of A, B, C and Dâ) The above rules are applied recursively. (e.g. â(A (P Q) B (X Y Z) C)â will be âa list of A, a list of P and Q, B, a list of X, Y and Z and Câ) Each atomic element of an S-expression is a string made of less than 10 capital letters. All words (âaâ, âlistâ, âofâ and âandâ) and atomic elements of S-expressions are separated by a single space character, but no space character is inserted before comma (â,â). No phrases for empty S-expressions occur in the input. You can assume that all test cases can be translated into S-expressions, but the possible expressions may not be unique. Output For each test case, output the corresponding S-expression in a separate line. If the given phrase involves two or more different S-expressions, output âAMBIGUOUSâ (without quotes). A single space character should be inserted between the elements of the S-expression, while no space character should be inserted after open brackets (â(â) and before closing brackets (â)â). Sample Input 4 a list of A, B, C and D a list of A, a list of P and Q, B, a list of X, Y and Z and C a list of A a list of a list of A and B Output for the Sample Input (A B C D) (A (P Q) B (X Y Z) C) (A) AMBIGUOUS | 37,048 |
Score : 500 points Problem Statement Given are N integers A_1,\ldots,A_N . We will choose exactly K of these elements. Find the maximum possible product of the chosen elements. Then, print the maximum product modulo (10^9+7) , using an integer between 0 and 10^9+6 (inclusive). Constraints 1 \leq K \leq N \leq 2\times 10^5 |A_i| \leq 10^9 Input Input is given from Standard Input in the following format: N K A_1 \ldots A_N Output Print the maximum product modulo (10^9+7) , using an integer between 0 and 10^9+6 (inclusive). Sample Input 1 4 2 1 2 -3 -4 Sample Output 1 12 The possible products of the two chosen elements are 2 , -3 , -4 , -6 , -8 , and 12 , so the maximum product is 12 . Sample Input 2 4 3 -1 -2 -3 -4 Sample Output 2 1000000001 The possible products of the three chosen elements are -24 , -12 , -8 , and -6 , so the maximum product is -6 . We print this value modulo (10^9+7) , that is, 1000000001 . Sample Input 3 2 1 -1 1000000000 Sample Output 3 1000000000 The possible products of the one chosen element are -1 and 1000000000 , so the maximum product is 1000000000 . Sample Input 4 10 10 1000000000 100000000 10000000 1000000 100000 10000 1000 100 10 1 Sample Output 4 999983200 Be sure to print the product modulo (10^9+7) . | 37,049 |
Score : 1000 points Problem Statement You are given a string S consisting of digits between 1 and 9 , inclusive. You will insert at most K commas ( , ) into this string to separate it into multiple numbers. Your task is to minimize the maximum number among those produced by inserting commas. Find minimum possible such value. Constraints 0 ⊠K < |S| ⊠100,000 S consists of digits between 1 and 9 , inclusive. Partial Scores In the test set worth 100 points, |S| ⊠2 . In the test set worth another 100 points, |S| ⊠16 . In the test set worth another 200 points, |S| ⊠100 . In the test set worth another 200 points, |S| ⊠2,000 . Input The input is given from Standard Input in the following format: K S Output Print the minimum possible value. Sample Input 1 2 15267315 Sample Output 1 315 When the string is separated into 152 , 67 and 315 , the maximum among these is 315 , which is the minimum possible value. Sample Input 2 0 12456174517653111 Sample Output 2 12456174517653111 12456174517653111 itself is the answer. Sample Input 3 8 127356176351764127645176543176531763517635176531278461856198765816581726586715987216581 Sample Output 3 5317635176 | 37,050 |
BïŒ ãã³ã¡ãããšæ°å - Ebi-chan and Integer Sequences - åé¡ ãã³ã¡ããã¯æ°åã奜ãã§ããäžã§ãçå·®æ°åãç¹ã«å¥œãã§ãã ä»åã¯ä»¥äžã®æ¡ä»¶ãæºããæ°åãäœãããšã«ããŸããã é·ã n ã®çå·®æ°åã§ãã æ°åã® i çªç®ã®èŠçŽ ã s_i ãšå®ããæãå
šãŠã® s_i (1 \leq i \leq n) ã 0 \leq s_i \leq m ãæºããæŽæ°ã§ãã äžã®æ¡ä»¶ãæºãããããªæ°åã¯ããã€ããã§ããããïŒ ãã ãçãã¯éåžžã«å€§ãããªãããšãããã®ã§ã 10^9 + 7 ã§å²ã£ãäœããåºåããŠãã ããã å
¥ååœ¢åŒ å
¥åã¯äžè¡ã§äžããããã n m n ã¯æ°åã®é·ãã衚ãã å¶çŽ 1 \leq n \leq 10^{15} 0 \leq m \leq 10^{15} åºååœ¢åŒ æ¡ä»¶ãæºããçå·®æ°åã®æ°ã 10^9 + 7 ã§å²ã£ãäœããäžè¡ã«åºåããã å
¥åäŸ1 3 9 åºåäŸ1 50 å
¥åäŸ2 10000000000 10000000000 åºåäŸ2 999999942 å
¥åã¯32bitæŽæ°ã«ã¯åãŸããããªãããšã«æ³šæããŠãã ããã | 37,051 |
15 Puzzle The goal of the 15 puzzle problem is to complete pieces on $4 \times 4$ cells where one of the cells is empty space. In this problem, the space is represented by 0 and pieces are represented by integers from 1 to 15 as shown below. 1 2 3 4 6 7 8 0 5 10 11 12 9 13 14 15 You can move a piece toward the empty space at one step. Your goal is to make the pieces the following configuration in the shortest move (fewest steps). 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 Write a program which reads an initial state of the puzzle and prints the fewest steps to solve the puzzle. Input The $4 \times 4$ integers denoting the pieces or space are given. Output Print the fewest steps in a line. Constraints The given puzzle is solvable in at most 45 steps. Sample Input 1 2 3 4 6 7 8 0 5 10 11 12 9 13 14 15 Sample Output 8 | 37,052 |
Problem B: Lattice Practices Once upon a time, there was a king who loved beautiful costumes very much. The king had a special cocoon bed to make excellent cloth of silk. The cocoon bed had 16 small square rooms, forming a 4 Ã 4 lattice, for 16 silkworms. The cocoon bed can be depicted as follows: The cocoon bed can be divided into 10 rectangular boards, each of which has 5 slits: Note that, except for the slit depth, there is no difference between the left side and the right side of the board (or, between the front and the back); thus, we cannot distinguish a symmetric board from its rotated image as is shown in the following: Slits have two kinds of depth, either shallow or deep. The cocoon bed should be constructed by fitting five of the boards vertically and the others horizontally, matching a shallow slit with a deep slit. Your job is to write a program that calculates the number of possible configurations to make the lattice. You may assume that there is no pair of identical boards. Notice that we are interested in the number of essentially different configurations and therefore you should not count mirror image configurations and rotated configurations separately as different configurations. The following is an example of mirror image and rotated configurations, showing vertical and horizontal boards separately, where shallow and deep slits are denoted by '1' and '0' respectively. Notice that a rotation may exchange position of a vertical board and a horizontal board. Input The input consists of multiple data sets, each in a line. A data set gives the patterns of slits of 10 boards used to construct the lattice. The format of a data set is as follows: XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX XXXXX Each x is either '0' or '1'. '0' means a deep slit, and '1' a shallow slit. A block of five slit descriptions corresponds to a board. There are 10 blocks of slit descriptions in a line. Two adjacent blocks are separated by a space. For example, the first data set in the Sample Input means the set of the following 10 boards: The end of the input is indicated by a line consisting solely of three characters "END". Output For each data set, the number of possible configurations to make the lattice from the given 10 boards should be output, each in a separate line. Sample Input 10000 01000 00100 11000 01100 11111 01110 11100 10110 11110 10101 01000 00000 11001 01100 11101 01110 11100 10110 11010 END Output for the Sample Input 40 6 | 37,053 |
C: 倱ãããã°ã©ã / Lost Graph å顿 ããªããš AOR ã€ã«ã¡ããã¯ç«¶æããã°ã©ãã³ã°ã®ã°ã©ãåé¡ã®æºåãããŠããã å
¥åã±ãŒã¹ã®çæã¯ AOR ã€ã«ã¡ããã®ä»äºã§ããã ãã®åé¡ã®å
¥åã±ãŒã¹ã¯ $N$ é ç¹ã®æåã°ã©ãã§ããã é ç¹ã«ã¯ $1$ ãã $N$ ãŸã§ã®çªå·ãä»ããŠããã 蟺ã«ã¯èªå·±ã«ãŒããå«ãŸãããããããªãããå€é蟺ã¯å«ãŸããªãã ãšããããAOR ã€ã«ã¡ããã¯çªç¶é³ä¿¡äžéãšãªã£ãŠããŸããå
ã®ã°ã©ããæã«å
¥ããªããªã£ãŠããŸã£ããæ®ã£ãŠããã®ã¯æ¬¡ã®æ
å ±ã ãã§ããã å
¥æ¬¡æ°ã $i$ ã®é ç¹ã®æ°ã¯ $a_i$ åã§ãããã€ãŸãã $i$ ãçµç¹ãšããé ç¹ã®æ°ã¯ $a_i$ åã§ããã åºæ¬¡æ°ã $i$ ã®é ç¹ã®æ°ã¯ $b_i$ åã§ãããã€ãŸãã $i$ ãå§ç¹ãšããé ç¹ã®æ°ã¯ $b_i$ åã§ããã æ®ãããæ
å ±ãšççŸããªãæåã°ã©ãã¯ååšããã ãããã ãããå€å®ããååšãããªã YES ãšåºåããåŸççŸããªãæåã°ã©ãã 1 ã€åºåããã è€æ°ããå Žåã¯ã©ããåºåããŠããããååšããªããªã NO ãšåºåããã å
¥å $n$ $a_0 \cdots a_n$ $b_0 \cdots b_n$ å
¥åã®å¶çŽ $1 \leq n \leq 50$ $0 \leq a_i \leq n$ $0 \leq b_i \leq n$ åºå æ¡ä»¶ãæºããã°ã©ããååšããå Žåã¯ä»¥äžã®åœ¢åŒã§åºåããã$e_{ij}$ ã¯ã $i$ ãã $j$ ãžã®æå蟺ãååšãããªãã° 1 ãããªããªã 0 ãšããã è¡æ«ã«ç©ºçœãåºåããªãããã«æ³šæããã YES $e_{11} \ e_{12} \cdots e_{1n}$ $e_{21} \ e_{22} \cdots e_{2n}$ $\vdots$ $e_{n1} \ e_{n2} \cdots e_{nn}$ ããªãå Žåã¯ä»¥äžã®ãšããã«åºåããã NO ãµã³ãã« ãµã³ãã«å
¥å1 3 1 2 0 0 1 2 0 0 ãµã³ãã«åºå1 YES 0 1 0 0 0 1 0 0 0 ãµã³ãã«å
¥å2 1 1 0 1 0 ãµã³ãã«åºå2 YES 0 ãµã³ãã«å
¥å3 2 0 2 0 0 2 0 ãµã³ãã«åºå3 YES 0 1 1 0 ãµã³ãã«å
¥å4 4 1 3 0 0 0 3 0 0 1 0 ãµã³ãã«åºå4 YES 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 ãµã³ãã«å
¥å5 1 1 1 0 0 ãµã³ãã«åºå5 NO | 37,054 |
Problem G: Polygons on the Grid The ultimate Tantra is said to have been kept in the most distinguished temple deep in the sacred forest somewhere in Japan. Paleographers finally identified its location, surprisingly a small temple in Hiyoshi, after years of eager research. The temple has an underground secret room built with huge stones. This underground megalith is suspected to be where the Tantra is enshrined. The room door is, however, securely locked. Legends tell that the key of the door lock was an integer, that only highest priests knew. As the sect that built the temple decayed down, it is impossible to know the integer now, and the Agency for Cultural Affairs bans breaking up the door. Fortunately, a figure of a number of rods that might be used as a clue to guess that secret number is engraved on the door. Many distinguished scholars have challenged the riddle, but no one could have ever succeeded in solving it, until recently a brilliant young computer scientist finally deciphered the puzzle. Lengths of the rods are multiples of a certain unit length. He found that, to find the secret number, all the rods should be placed on a grid of the unit length to make one convex polygon. Both ends of each rod must be set on grid points. Elementary mathematics tells that the polygon's area ought to be an integer multiple of the square of the unit length. The area size of the polygon with the largest area is the secret number which is needed to unlock the door. For example, if you have five rods whose lengths are 1, 2, 5, 5, and 5, respectively, you can make essentially only three kinds of polygons, shown in Figure 7. Then, you know that the maximum area is 19. Figure 7: Convex polygons consisting of five rods of lengths 1, 2, 5, 5, and 5 Your task is to write a program to find the maximum area of convex polygons using all the given rods whose ends are on grid points. Input The input consists of multiple datasets, followed by a line containing a single zero which indicates the end of the input. The format of a dataset is as follows. n r 1 r 2 ... r n n is an integer which means the number of rods and satisfies 3 †n †6. r i means the length of the i -th rod and satisfies 1 †r i †300. Output For each dataset, output a line containing an integer which is the area of the largest convex polygon. When there are no possible convex polygons for a dataset, output " -1 ". Sample Input 3 3 4 5 5 1 2 5 5 5 6 195 221 255 260 265 290 6 130 145 169 185 195 265 3 1 1 2 6 3 3 3 3 3 3 0 Output for the Sample Input 6 19 158253 -1 -1 18 | 37,055 |
m é ç¹ã®å®å
šã°ã©ããããïŒæåïŒå®å
šã°ã©ãã®èŸºã«ã¯è²ã¯å¡ãããŠããªãïŒãã¬ãåã¯ïŒå i (1 †i †n ) ã«ã€ããŠæ¬¡ã®æäœãè¡ã£ã: å®å
šã°ã©ããã a i åã®é ç¹ãéžã³ïŒéžã°ããé ç¹å士ãçµã¶èŸºãã¹ãŠãè² i ã§ã¬ãïŒè€æ°åã®è²ãå¡ããã蟺ã¯ãªãã£ãïŒ m ãšããŠèããããæå°å€ãæ±ããïŒ Constraints 1 †n †5 2 †a i †10 9 Input n a 1 . . . a n Output m ã®æå°å€ãäžè¡ã«åºåããïŒ Sample Input 1 2 3 3 Sample Output 1 5 ããšãã°ïŒé ç¹1, 2, 3, 4, 5 ãããªãã°ã©ãããã£ãå ŽåïŒæ¬¡ã®ããã«è²ãå¡ãããšãã§ããïŒ é ç¹1, 2, 3 ãéžã³ãã®éãçµã¶èŸºãè²1 ã§ã¬ãïŒ é ç¹1, 4, 5 ãéžã³ãã®éãçµã¶èŸºãè²2 ã§ã¬ãïŒ Sample Input 2 5 2 3 4 5 6 Sample Output 2 12 | 37,056 |
Score : 100 points Problem Statement Takahashi has decided to distribute N AtCoder Crackers to K users of as evenly as possible. When all the crackers are distributed, find the minimum possible (absolute) difference between the largest number of crackers received by a user and the smallest number received by a user. Constraints 1 \leq N,K \leq 100 All values in input are integers. Input Input is given from Standard Input in the following format: N K Output Print the minimum possible (absolute) difference between the largest number of crackers received by a user and the smallest number received by a user. Sample Input 1 7 3 Sample Output 1 1 When the users receive two, two and three crackers, respectively, the (absolute) difference between the largest number of crackers received by a user and the smallest number received by a user, is 1 . Sample Input 2 100 10 Sample Output 2 0 The crackers can be distributed evenly. Sample Input 3 1 1 Sample Output 3 0 | 37,057 |
Problem K: Cat Numbers! ããã®ã¢ãªã¹ããã¬ã¹ã¯æ°åŠã®åé¡ãèããã®ãè¶£å³ã«ããŠãããä»åœŒãèããŠããåé¡ã¯ä»¥äžã®ãããªãã®ã§ããã 1以äžã®èªç¶æ° A , B ( A < B ) ã«å¯ŸããŠã A ãã B ãŸã§ã®èªç¶æ°ã®åã C ã A ãš B ãåé²è¡šèšã㊠A , B ã®é ã«çµåãããã®ã D ãšãããšãäž¡è
ãçãããªãããšããããããšãã°1ãã5ãŸã§ã®åã¯15ã2ãã7ãŸã§ã®åã¯27ã7ãã119ãŸã§ã®å㯠7119ããšãã£ãå
·åã§ããããã®ãã㪠A ãš B ã®ãã¢ã®ããšã cat numbers ãšåŒã¶ããšã«ãããã¢ãªã¹ããã¬ã¹ã¯ã A ãš B ã®æ¡æ°ãäžãããããšãã«ãcat numbersãå
šãŠåæãããããšèããã ã¢ãªã¹ããã¬ã¹ã¯ã A ãŸã㯠B ãåºå®ããå Žåã«è§£ãååšãããã©ããã確ãããæ¹æ³ã¯æãã€ããã®ã§ãå°ããæ¡æ°ã«å¯ŸããŠã¯çããåŸãããšãã§ãããããããæ¡æ°ã倧ãããªãã«ãããã£ãŠèšç®ãããã®ã倧å€ã«ãªããéäžã§ããããããŠæãåºããŠããŸã£ããããã§ãããªãã«ãé¡ãããããã¢ãªã¹ããã¬ã¹ã«ä»£ãã£ãŠãæå®ãããæ¡æ°ã®cat numbersãå
šãŠåæããããã°ã©ã ãæžããŠã»ããã Input å
¥åã¯1è¡ã®ã¿ãããªãã A ã®æ¡æ° a ããã³ B ã®æ¡æ° b ã1ã€ã®ç©ºçœæåã§åºåãããŠäžãããããããã㯠1 †a †b †16 ãæºããã Output æå®ãããæ¡æ°ã®cat numbersãã A ãå°ãããã®ããé ã«åºåããã A ãåããã®ãè€æ°ããå Žåã¯ã B ãå°ãããã®ããåºåãããåè¡ã«ã¯1ã€ã®cat numbersã«ããã A ãš B ã1ã€ã®ç©ºçœæåã§åºåã£ããã®ãåºåããããŸããæ¡ä»¶ã«åãcat numbersãååšããªãå Žå㯠"No cats." ãš1è¡ã«åºåããã Notes on Submission äžèšåœ¢åŒã§è€æ°ã®ããŒã¿ã»ãããäžããããŸããå
¥åããŒã¿ã® 1 è¡ç®ã«ããŒã¿ã»ããã®æ°ãäžããããŸããåããŒã¿ã»ããã«å¯Ÿããåºåãäžèšåœ¢åŒã§é çªã«åºåããããã°ã©ã ãäœæããŠäžããã Sample Input 4 1 1 1 3 1 4 2 2 Output for the Sample Input 1 5 2 7 7 119 No cats. 13 53 18 63 33 88 35 91 | 37,058 |
ããŠãªã³ã° ã¯ã©ã¹ã®ã¬ã¯ãªãšãŒã·ã§ã³ãšããŠããŠãªã³ã°ãè¡ãããšã«ãªããŸãããåå è
ããšã®æçæ
å ±ãå
¥åãšããåŸç¹ã®é«ãé ã«æçžŸæ
å ±ãåºåããããã°ã©ã ãäœæããŠãã ããããªããåç¹ã®å Žåã¯åŠç±çªå·ã®è¥ãé ã«åºåããŠãã ããããã ãåå è
㯠3 åä»¥äž 40 å以äžãšãã1人åœãã1ã²ãŒã ãã€æçããŠãããã®ãšããŸãã ããŠãªã³ã°ãšã¯ããã¬ã€ã€ãŒã«å¯ŸããŠé ç¹ãåããŠæ£äžè§åœ¢ã«äžŠã¹ãããã10 æ¬ã®ãã³ãããããŠããŒã«ã転ããããã³ãåãã¹ããŒãã§ãã 1 åç®ã®æçã§ãã¹ãŠè»¢åããå Žåãã¹ãã©ã€ã¯ãšèšãããã®æçã®ã¿ã§æ¬¡ã®ãã¬ãŒã ã«é²ã¿ãŸããã¹ãã©ã€ã¯ã§ãªãå Žåã¯ãæ®ã£ããã³ããã®ãŸãŸã«ã㊠2 åç®ã®æçãè¡ããŸãã2 åç®ã®æçã§ãã¹ãŠè»¢åããå Žåãã¹ãã¢ãšèšããŸãã2 åç®ã®æççµäºåŸã次ã®ãã¬ãŒã ã«é²ã¿ãŸãã 1 ã²ãŒã 㯠10 ã®ãã¬ãŒã ããæ§æããã第 1 ãã第 9 ã®åãã¬ãŒã 㯠2 åæçã§ããŸããåãã¬ãŒã ã®éå§æç¹ã§ã¯ã10 æ¬ã®ãã³ããã¹ãŠç«ã£ãç¶æ
ã§çšæãããŸãã第 10 ãã¬ãŒã ã¯ãã¹ãã©ã€ã¯ãããã¯ã¹ãã¢ãåºãå Žåã«ã¯èš 3 åã®æçãããã以å€ã®å Žå㯠2 åã®æçãè¡ããã²ãŒã çµäºãšãªããŸãã ã¹ã³ã¢äŸïŒ ã¹ã³ã¢äŸïŒïŒæé«åŸç¹300ç¹ã®å ŽåïŒ ã¹ã³ã¢èšç®ã®æ¹æ³ åãã¬ãŒã ã«ãããŠã¹ãã¢ãã¹ãã©ã€ã¯ããªãå Žåã¯ã 2 åã®æçã§åãããã³ã®æ¬æ°ããã®ãã¬ãŒã ã®åŸç¹ãšãªããŸããïŒã¹ã³ã¢äŸïŒã®ç¬¬ 4 ãã¬ãŒã ãšç¬¬ 8 ãã¬ãŒã ïŒ ã¹ãã¢ãåºããå Žåãåããæ¬æ°ã§ãã 10 ç¹ã«å ããæ¬¡ã®æçã§åãããã³ã®æ¬æ°ããã®ãã¬ãŒã ã®åŸç¹ã«å ç®ãããŸããïŒã¹ã³ã¢äŸïŒã®ç¬¬ 1 ãã¬ãŒã ãšç¬¬ 2 ãã¬ãŒã ã®é¢ä¿ãªã©ïŒã¹ã³ã¢äŸïŒã®ç¬¬ 1 ãã¬ãŒã ã§ã¯ç¬¬ 2 ãã¬ãŒã ã® 1 æã§åãã 10 æ¬ïŒç¹ïŒãå ãã 20 ç¹ãåŸç¹ãšãªããŸãã第 3 ãã¬ãŒã ãåæ§ã®èšç®æ¹æ³ã§ãã ã¹ãã©ã€ã¯ãåºããå Žåãåããæ¬æ°ã§ãã 10 ç¹ã«å ããç¶ã 2 åã®æçã§åãããã³ã®æ¬æ°ãå ç®ãããŸããïŒã¹ã³ã¢äŸïŒã®ç¬¬ 2 ãã¬ãŒã ãšç¬¬ 3 ãã¬ãŒã ã®é¢ä¿ãªã©ïŒãã¡ããç¶ã 2 æäžã«ã¹ãã©ã€ã¯ã®å ŽåããããŸããïŒã¹ã³ã¢äŸïŒã®ç¬¬ 5 ãã¬ãŒã ãšç¬¬ 6ã7 ãã¬ãŒã ã®é¢ä¿ãªã©ïŒ 第 10 ãã¬ãŒã ã®ã¿ãã¹ãã¢ãã¹ãã©ã€ã¯ãåºããå Žåã3 æããŠåãããã³ã®ç·æ°ã第 10 ãã¬ãŒã ã®åŸç¹ãšããŠå ç®ãããŸãã åãã¬ãŒã ã®åŸç¹ã®åèšã 1 ã²ãŒã ã®åŸç¹ãšãªããæé«åŸç¹ã¯ 300 ç¹ãšãªããŸãã Input è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸãã åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã m score 1 score 2 : score m 1è¡ç®ã«åå è
æ° m ïŒ3 †m †40ïŒãç¶ã m è¡ã« i 人ç®ã®åå è
æ
å ± score i ãäžããããŸããååå è
æ
å ±ã¯ïŒè¡ãã€æ¬¡ã®åœ¢åŒã§äžããããŸãã id s 1 s 2 ... s n å
é ã«åŠç±çªå· id (0 †id †9999)ãç¶ããŠç¬¬ j æã®è»¢åãã³æ° s j (0 †s j †10) ãäžããããŸããç·æçæ° n ã¯ã12 ä»¥äž 21 以äžã§ãããåŸç¹èšç®ã«å¿
èŠãªãã³æ°ãéäžè¶³ãªãäžãããããã®ãšããŸãã Output å
¥åããŒã¿ã»ããããšã«ãåŠç±çªå·ãšåŸç¹ããåŸç¹ã®é«ãé ïŒåç¹ã®å Žåã¯åŠç±çªå·ã®è¥ãé ïŒã«åºåããŸããåŠç±çªå·ãšåŸç¹ãïŒã€ã®ç©ºçœã§åºåã£ãŠïŒè¡ã«åºåããŠãã ããã Sample Input 3 1010 6 3 10 7 1 0 7 9 1 10 6 2 4 3 9 1 9 0 1200 5 3 9 1 7 1 0 0 8 1 10 10 4 3 9 1 8 2 9 1101 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 3321 8 2 10 9 1 7 0 10 10 10 0 8 10 10 10 10 3332 5 0 10 9 1 4 1 9 0 10 10 7 1 5 2 8 1 3335 10 10 10 10 10 10 10 10 10 10 10 10 3340 8 2 7 3 6 4 8 2 8 2 9 1 7 3 6 4 8 2 9 1 7 0 Output for the Sample Input 1200 127 1010 123 1101 60 3335 300 3321 200 3340 175 3332 122 | 37,059 |
æãæ¥ã
(Hot days) åé¡ æ¥æ¬ãå¬ã§ãããã®ææïŒååçã«ãããªãŒã¹ãã©ãªã¢ã§ã¯æãæ¥ãç¶ããŠããïŒãªãŒã¹ãã©ãªã¢ã«äœã IOI åã¯ïŒãã D æ¥éã®å€©æ°äºå ±ãããšã«ïŒçãæã®èšç»ãç«ãŠãããšã«ããïŒi æ¥ç® (1 ⊠i ⊠D) ã®æé«æ°æž©ã¯ T i 床ã§ãããšäºå ±ãããŠããïŒ IOI å㯠N çš®é¡ã®æãæã£ãŠããïŒãããã«ã¯ 1 ãã N ãŸã§ã®çªå·ãã€ããŠããïŒæ j (1 ⊠j ⊠N) ã¯æé«æ°æž©ã A j åºŠä»¥äž B j 床以äžã®æ¥ã«çãã®ã«é©ããŠããïŒãŸãïŒããããã®æã«ã¯ã掟æãããšãã°ããæŽæ°ãå®ãŸã£ãŠããïŒæ j ã®æŽŸæã㯠C j ã§ããïŒ D æ¥éã®ããããã«å¯ŸãïŒIOI åã¯ïŒæé«æ°æž©ã倩æ°äºå ±ã«åŸã£ããšãã«çãã®ã«é©ããæã®ãã¡ 1 ã€ãçãæãšããŠéžã¶ïŒåãæãäœåºŠéžãã§ããããïŒD æ¥éã§äžåºŠãéžã°ããªãæããã£ãŠãããïŒ äŒŒãŠããæãé£ç¶ããŠçãããšããªãã¹ãé¿ããããšæã£ã IOI åã¯ïŒé£ç¶ããæ¥ã«çãæã®æŽŸæãã®å·®ã®çµ¶å¯Ÿå€ã®åèšãã§ããã ã倧ããããããšèããïŒããªãã¡ïŒi æ¥ç®ã«æ x i ãéžãã ãšããŠïŒå€ |C x 1 - C x 2 | + |C x 2 - C x 3 | + ⊠+ |C x D-1 - C x D | ãæå€§ã«ãããïŒãã®æå€§å€ãæ±ããããã°ã©ã ãäœæããïŒ å
¥å å
¥å㯠1 + D + N è¡ãããªãïŒ 1 è¡ç®ã«ã¯ïŒ2 ã€ã®æŽæ° D, N (2 ⊠D ⊠200ïŒ1 ⊠N ⊠200) ã空çœãåºåããšããŠæžãããŠããïŒD ã¯æã®èšç»ãç«ãŠãæ¥æ°ïŒN 㯠IOI åãæã£ãŠããæã®çš®é¡ã®æ°ã衚ãïŒ ç¶ã D è¡ã®ãã¡ã® i è¡ç® (1 ⊠i ⊠D) ã«ã¯ïŒ1 ã€ã®æŽæ° T i (0 ⊠T i ⊠60) ãæžãããŠããïŒããã¯ïŒi æ¥ç®ã®æé«æ°æž©ã T i 床ã§ãããšäºå ±ãããŠããããšã衚ãïŒ ç¶ã N è¡ã®ãã¡ã® j è¡ç® (1 ⊠j ⊠N) ã«ã¯ïŒ3 ã€ã®æŽæ° A j , B j , C j (0 ⊠A j ⊠B j ⊠60ïŒ0 ⊠C j ⊠100) ãæžãããŠããïŒãããã¯ïŒæ j ã¯æé«æ°æž©ã A j åºŠä»¥äž B j 床以äžã®æ¥ã«çãã®ã«é©ããŠããïŒæŽŸæãã C j ã§ããããšã衚ãïŒ æé«æ°æž©ã倩æ°äºå ±ã«åŸã£ããšãã«çãã®ã«é©ããæãïŒD æ¥éã®ã©ã®æ¥ã«å¯ŸããŠã 1 ã€ä»¥äžååšããããšãä¿èšŒãããŠããïŒ åºå é£ç¶ããæ¥ã«çãæã®æŽŸæãã®å·®ã®çµ¶å¯Ÿå€ã®åèšïŒããªãã¡ïŒå€ |C x 1 - C x 2 | + |C x 2 - C x 3 | + ⊠+ |C x D-1 - C x D | ã®æå€§å€ã 1 è¡ã§åºåããïŒ å
¥åºåäŸ å
¥åäŸ 1 3 4 31 27 35 20 25 30 23 29 90 21 35 60 28 33 40 åºåäŸ 1 80 å
¥åºåäŸ 1 ã«ãããŠïŒ1 æ¥ç®ã®æã®åè£ã¯æ 3 ãšæ 4 ã§ããïŒ2 æ¥ç®ã®æã®åè£ã¯æ 2 ãšæ 3 ã§ããïŒ3 æ¥ç®ã®æã®åè£ã¯æ 3 ã®ã¿ã§ããïŒ1 æ¥ç®ã«æ 4 ãïŒ2 æ¥ç®ã«æ 2 ãïŒ3 æ¥ç®ã«æ 3 ãéžã¶ïŒããªãã¡ïŒx 1 = 4ïŒx 2 = 2ïŒx 3 = 3 ãšããïŒãã®ãšãïŒ1 æ¥ç®ãš 2 æ¥ç®ã®æã®æŽŸæãã®å·®ã®çµ¶å¯Ÿå€ã¯ |40 - 90| = 50 ã§ããïŒ2 æ¥ç®ãš 3 æ¥ç®ã®æã®æŽŸæãã®å·®ã®çµ¶å¯Ÿå€ã¯ |90 - 60| = 30 ã§ããïŒåèšã¯ 80 ãšãªãïŒãããæå€§å€ã§ããïŒ å
¥åäŸ 2 5 2 26 28 32 29 34 30 35 0 25 30 100 åºåäŸ 2 300 å
¥åºåäŸ 2 ã«ãããŠïŒ1 æ¥ç®ã«ã¯æ 2 ãïŒ2 æ¥ç®ã«ã¯æ 2 ãïŒ3 æ¥ç®ã«ã¯æ 1 ãïŒ4 æ¥ç®ã«ã¯æ 2 ãïŒ5 æ¥ç®ã«ã¯æ 1 ãéžã°ãªããã°ãªããªãïŒãã®ãšãïŒæ±ããå€ã¯ |100 - 100| + |100 - 0| + |0 - 100| + |100 - 0| = 300 ãšãªãïŒ å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã | 37,060 |
Caesar Cipher In cryptography, Caesar cipher is one of the simplest and most widely known encryption method. Caesar cipher is a type of substitution cipher in which each letter in the text is replaced by a letter some fixed number of positions down the alphabet. For example, with a shift of 1, 'a' would be replaced by 'b', 'b' would become 'c', 'y' would become 'z', 'z' would become 'a', and so on. In that case, a text: this is a pen is would become: uijt jt b qfo Write a program which reads a text encrypted by Caesar Chipher and prints the corresponding decoded text. The number of shift is secret and it depends on datasets, but you can assume that the decoded text includes any of the following words: "the", "this", or "that". Input Input consists of several datasets. Each dataset consists of texts in a line. Input ends with EOF. The text consists of lower-case letters, periods, space, and end-of-lines. Only the letters have been encrypted. A line consists of at most 80 characters. You may assume that you can create one decoded text which includes any of "the", "this", or "that" from the given input text. The number of datasets is less than or equal to 20. Output Print decoded texts in a line. Sample Input xlmw mw xli tmgxyvi xlex m xsso mr xli xvmt. Output for the Sample Input this is the picture that i took in the trip. | 37,061 |
F: å鿢ã åé¡ $1$ ãã $N$ ãŸã§ã®çªå·ãä»ãããã $N$ 人ã®äººã«å¯ŸããŠïŒããéšå±ã®å
¥é宀èšé²ã $M$ åäžããããïŒ $i$ çªç®ã®å
¥é宀èšé²ã¯ $A_i\ B_i\ C_i$ ã® $3$ ã€ã®æŽæ°ãããªãïŒããã¯ä»¥äžã瀺ããŠããïŒ $C_i = 1$ ã®ãšãïŒæå» $A_i$ ã« $B_i$ ãããéšå±ã«å
¥å®€ããããšã衚ã. $C_i = 0$ ã®ãšãïŒæå» $A_i$ ã« $B_i$ ãããéšå±ããé宀ããããšã衚ã. $i$ çªç®($1 \leq i \leq N$)ã®äººã«ã€ããŠïŒæå» $T$ ãŸã§ã«éšå±ã§äžç·ã«éãããæéãæãé·ã人ãçããïŒ å¶çŽ å
¥åå€ã¯å
šãп޿°ã§ãã. $2 \leq N,\ M \leq 10^5$ $1 \leq T \leq 10^9$ $1 \leq A_i \leq T$ $A_i \leq A_{i+1}$ $1 \leq B_i \leq N$ $(A_i = A_j$ ã〠$B_i = B_j$) ãªãã° $i=j$ $0 \leq C_i \leq 1$ æå» $0$ ã«ã¯éšå±ã«èª°ãããªã å
¥é宀ãççŸããå
¥åã¯äžããããªã éšå±ã« $100$ 人ããå€ãã®äººãããããšã¯ãªã å
¥ååœ¢åŒ å
¥åã¯ä»¥äžã®åœ¢åŒã§äžãããã. $N\ M\ T$ $A_1\ B_1\ C_1$ ⊠$A_M\ B_M\ C_M$ åºå $i$ è¡ç®ã«ã¯ $i$ çªç®ã®äººã«ã€ããŠïŒæå» $T$ ãŸã§ã«éšå±ã§äžç·ã«éãããæéãæãé·ã人ãåºåããïŒ ãã ãïŒèªå以å€ã§äžç·ã«éãããæéãæãé·ã人ãè€æ°äººããå Žåã¯ïŒæãå°ããçªå·ã®äººãåºåããïŒ ãŸãïŒåè¡ã®æ«å°Ÿã«æ¹è¡ãåºåããïŒ ãµã³ãã« ãµã³ãã«å
¥å 1 3 6 10 1 1 1 2 2 1 4 3 1 5 1 0 6 2 0 6 3 0 ãµã³ãã«åºå 1 2 1 2 ãµã³ãã«å
¥å 2 3 2 5 1 1 1 2 2 1 ãµã³ãã«åºå 2 2 1 1 $3$ çªç®ã®äººã¯ïŒ$1$ çªç®ã®äººãšã $2$ çªç®ã®äººãšãäžç·ã«ããæéã $0$ ãªã®ã§ïŒæãå°ãã $1$ ãåºåãã. | 37,062 |
æåº§æ¢ã åé¡ ããªãã¯æç©ºã®åçã®äžããæåº§ãæ¢ããŠããïŒåçã«ã¯å¿
ãïŒæ¢ãããæåº§ãšåã圢ã»åãã»å€§ããã®å³åœ¢ãã¡ããã©äžã€å«ãŸããŠããïŒãã ãïŒåçã®äžã«ã¯æåº§ãæ§æããæä»¥å€ã«äœåãªæãåã£ãŠããå¯èœæ§ãããïŒ äŸãã°ïŒå³ 1 ã®æåº§ã¯å³ 2 ã®åçã«å«ãŸããŠããïŒäžžã§å²ãã§ç€ºããïŒïŒäžããããæåº§ã®æã®åº§æšã x æ¹åã« 2ïŒ y æ¹åã« â3 ã ãå¹³è¡ç§»åãããšåçã®äžã®äœçœ®ã«ãªãïŒ æ¢ãããæåº§ã®åœ¢ãšåçã«åã£ãŠããæã®äœçœ®ãäžãããããšãïŒæåº§ã®åº§æšãåçã®äžã®åº§æšã«å€æããããã«å¹³è¡ç§»åããã¹ãéãçããããã°ã©ã ãæžãïŒ å³ 1: æ¢ãããæåº§ å³ 2: æç©ºã®åç å
¥å å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ å
¥åã® 1 è¡ç®ã«ã¯æ¢ãããæåº§ãæ§æããæã®åæ° m ãæžãããŠããïŒç¶ã m è¡ã«ã¯æ¢ãããæåº§ãæ§æãã m åã®æã® x 座æšãš y 座æšãç€ºãæŽæ°ã空çœåºåãã§æžãããŠããïŒ m +2 è¡ç®ã«ã¯åçã«åã£ãŠããæã®åæ° n ãæžãããŠããïŒç¶ã n è¡ã«ã¯åçã«åã£ãŠãã n åã®æã® x 座æšãš y 座æšãç€ºãæŽæ°ã空çœåºåãã§æžãããŠããïŒ æåº§ãæ§æãã m åã®æã®äœçœ®ã¯ãã¹ãŠç°ãªãïŒãŸãïŒåçã«åã£ãŠãã n åã®æã®äœçœ®ã¯ãã¹ãŠç°ãªãïŒ 1 †m †200ïŒ 1 †n †1000 ã§ããïŒæã® x 座æšãš y 座æšã¯ãã¹ãŠ 0 ä»¥äž 1000000 以äžã§ããïŒ m ã 0 ã®ãšãå
¥åã®çµããã瀺ã. ããŒã¿ã»ããã®æ°ã¯ 5 ãè¶
ããªãïŒ åºå åããŒã¿ã»ããã®åºå㯠1 è¡ãããªãïŒ 2 åã®æŽæ°ã空çœåºåãã§æžãïŒãããã¯æ¢ãããæåº§ã®åº§æšãã©ãã ãå¹³è¡ç§»åããã°åçã®äžã®åº§æšã«ãªããã衚ãïŒæåã®æŽæ°ã x æ¹åã«å¹³è¡ç§»åããéïŒæ¬¡ã®æŽæ°ã y æ¹åã«å¹³è¡ç§»åããéã§ããïŒ å
¥åºåäŸ å
¥åäŸ 5 8 5 6 4 4 3 7 10 0 10 10 10 5 2 7 9 7 8 10 10 2 1 2 8 1 6 7 6 0 0 9 5 904207 809784 845370 244806 499091 59863 638406 182509 435076 362268 10 757559 866424 114810 239537 519926 989458 461089 424480 674361 448440 81851 150384 459107 795405 299682 6700 254125 362183 50795 541942 0 åºåäŸ 2 -3 -384281 179674 å
¥åºåäŸã®ïŒã€ç®ã¯äžã®å³ã«å¯Ÿå¿ããŠããïŒ äžèšå顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã | 37,063 |
Score : 500 points Problem Statement There are 2N squares arranged from left to right. You are given a string of length 2N representing the color of each of the squares. The color of the i -th square from the left is black if the i -th character of S is B , and white if that character is W . You will perform the following operation exactly N times: choose two distinct squares, then invert the colors of these squares and the squares between them. Here, to invert the color of a square is to make it white if it is black, and vice versa. Throughout this process, you cannot choose the same square twice or more. That is, each square has to be chosen exactly once. Find the number of ways to make all the squares white at the end of the process, modulo 10^9+7 . Two ways to make the squares white are considered different if and only if there exists i (1 \leq i \leq N) such that the pair of the squares chosen in the i -th operation is different. Constraints 1 \leq N \leq 10^5 |S| = 2N Each character of S is B or W . Input Input is given from Standard Input in the following format: N S Output Print the number of ways to make all the squares white at the end of the process, modulo 10^9+7 . If there are no such ways, print 0 . Sample Input 1 2 BWWB Sample Output 1 4 There are four ways to make all the squares white, as follows: Choose Squares 1, 3 in the first operation, and choose Squares 2, 4 in the second operation. Choose Squares 2, 4 in the first operation, and choose Squares 1, 3 in the second operation. Choose Squares 1, 4 in the first operation, and choose Squares 2, 3 in the second operation. Choose Squares 2, 3 in the first operation, and choose Squares 1, 4 in the second operation. Sample Input 2 4 BWBBWWWB Sample Output 2 288 Sample Input 3 5 WWWWWWWWWW Sample Output 3 0 | 37,064 |
Problem A: Equal Sum Sets Let us consider sets of positive integers less than or equal to n . Note that all elements of a set are different. Also note that the order of elements doesn't matter, that is, both {3, 5, 9} and {5, 9, 3} mean the same set. Specifying the number of set elements and their sum to be k and s , respectively, sets satisfying the conditions are limited. When n = 9, k = 3 and s = 23, {6, 8, 9} is the only such set. There may be more than one such set, in general, however. When n = 9, k = 3 and s = 22, both {5, 8, 9} and {6, 7, 9} are possible. You have to write a program that calculates the number of the sets that satisfy the given conditions. Input The input consists of multiple datasets. The number of datasets does not exceed 100. Each of the datasets has three integers n , k and s in one line, separated by a space. You may assume 1 †n †20, 1 †k †10 and 1 †s †155. The end of the input is indicated by a line containing three zeros. Output The output for each dataset should be a line containing a single integer that gives the number of the sets that satisfy the conditions. No other characters should appear in the output. You can assume that the number of sets does not exceed 2 31 - 1. Sample Input 9 3 23 9 3 22 10 3 28 16 10 107 20 8 102 20 10 105 20 10 155 3 4 3 4 2 11 0 0 0 Output for the Sample Input 1 2 0 20 1542 5448 1 0 0 | 37,065 |
Sliding GCD Problem Statement èªç¶æ°ã®éå S ã«å¯ŸããŠïŒéå \{ GCD(T) | T â S, T ã¯ç©ºã§ãªã \} ã®èŠçŽ æ°ã f(S) ãšããïŒ ããã§ïŒ GCD(T) 㯠T ã«å«ãŸãããã¹ãŠã®æ°ãå²ãåããããªæå€§ã®æŽæ°ã§ããïŒ ç¹ã«ïŒ T ãäžã€ã®æŽæ° a ã®ã¿ãããªããšã㯠GCD(\{a\}) = a ã§ããããšã«æ³šæããïŒ i = 1, 2, . . ., N - W+1 ã«å¯Ÿã㊠f(\{i, i+1, . . ., i+W - 1\}) ãæ±ããïŒ Input å
¥åã¯ä»¥äžã®åœ¢åŒã«åŸãïŒäžããããæ°ã¯å
šãп޿°ã§ããïŒ N W Constraints 1 ⊠W ⊠N ⊠10^5 Output i = 1, 2, . . ., N-W+1 ã®ãšãã® f(\{i, i+1, . . ., i+W-1\}) ã®å€ãåè§ã¹ããŒã¹åºåãã§ 1 è¡ã«åºåããïŒ Sample Input 1 10 2 Output for the Sample Input 1 2 3 3 3 3 3 3 3 3 GCD(\{1\}) = 1, GCD(\{2\}) = 2, GCD(\{1,2\}) = 1 ãšãªããã f(\{1,2\}) = 2 ã§ããïŒ Sample Input 2 30 7 Output for the Sample Input 2 7 8 9 10 10 11 11 11 11 12 11 12 10 12 12 11 10 12 12 12 10 11 11 13 | 37,066 |
Score: 500 points Problem Statement Takahashi will take part in an eating contest. Teams of N members will compete in this contest, and Takahashi's team consists of N players numbered 1 through N from youngest to oldest. The consumption coefficient of Member i is A_i . In the contest, N foods numbered 1 through N will be presented, and the difficulty of Food i is F_i . The details of the contest are as follows: A team should assign one member to each food, and should not assign the same member to multiple foods. It will take x \times y seconds for a member to finish the food, where x is the consumption coefficient of the member and y is the difficulty of the dish. The score of a team is the longest time it takes for an individual member to finish the food. Before the contest, Takahashi's team decided to do some training. In one set of training, a member can reduce his/her consumption coefficient by 1 , as long as it does not go below 0 . However, for financial reasons, the N members can do at most K sets of training in total. What is the minimum possible score of the team, achieved by choosing the amounts of members' training and allocating the dishes optimally? Constraints All values in input are integers. 1 \leq N \leq 2 \times 10^5 0 \leq K \leq 10^{18} 1 \leq A_i \leq 10^6\ (1 \leq i \leq N) 1 \leq F_i \leq 10^6\ (1 \leq i \leq N) Input Input is given from Standard Input in the following format: N K A_1 A_2 ... A_N F_1 F_2 ... F_N Output Print the minimum possible score of the team. Sample Input 1 3 5 4 2 1 2 3 1 Sample Output 1 2 They can achieve the score of 2 , as follows: Member 1 does 4 sets of training and eats Food 2 in (4-4) \times 3 = 0 seconds. Member 2 does 1 set of training and eats Food 3 in (2-1) \times 1 = 1 second. Member 3 does 0 sets of training and eats Food 1 in (1-0) \times 2 = 2 seconds. They cannot achieve a score of less than 2 , so the answer is 2 . Sample Input 2 3 8 4 2 1 2 3 1 Sample Output 2 0 They can choose not to do exactly K sets of training. Sample Input 3 11 14 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 Sample Output 3 12 | 37,067 |
Score : 900 points Problem Statement You are developing frog-shaped robots, and decided to race them against each other. First, you placed N robots onto a number line. These robots are numbered 1 through N . The current coordinate of robot i is x_i . Here, all x_i are integers, and 0 < x_1 < x_2 < ... < x_N . You will repeatedly perform the following operation: Select a robot on the number line. Let the coordinate of the robot be x . Select the destination coordinate, either x-1 or x-2 , that is not occupied by another robot. The robot now jumps to the selected coordinate. When the coordinate of a robot becomes 0 or less, the robot is considered finished and will be removed from the number line immediately. You will repeat the operation until all the robots finish the race. Depending on your choice in the operation, the N robots can finish the race in different orders. In how many different orders can the N robots finish the race? Find the answer modulo 10^9+7 . Constraints 2 †N †10^5 x_i is an integer. 0 < x_1 < x_2 < ... < x_N †10^9 Partial Score In a test set worth 500 points, N †8 . Input The input is given from Standard Input in the following format: N x_1 x_2 ... x_N Output Print the number of the different orders in which the N robots can finish the race, modulo 10^9+7 . Sample Input 1 3 1 2 3 Sample Output 1 4 There are four different orders in which the three robots can finish the race: ( Robot 1 â Robot 2 â Robot 3) ( Robot 1 â Robot 3 â Robot 2) ( Robot 2 â Robot 1 â Robot 3) ( Robot 2 â Robot 3 â Robot 1) Sample Input 2 3 2 3 4 Sample Output 2 6 There are six different orders in which the three robots can finish the race: ( Robot 1 â Robot 2 â Robot 3) ( Robot 1 â Robot 3 â Robot 2) ( Robot 2 â Robot 1 â Robot 3) ( Robot 2 â Robot 3 â Robot 1) ( Robot 3 â Robot 1 â Robot 2) ( Robot 3 â Robot 2 â Robot 1) For example, the order ( Robot 3 â Robot 2 â Robot 1) can be achieved as shown in the figure below: Sample Input 3 8 1 2 3 5 7 11 13 17 Sample Output 3 10080 Sample Input 4 13 4 6 8 9 10 12 14 15 16 18 20 21 22 Sample Output 4 311014372 Remember to print the answer modulo 10^9+7 . This case is not included in the test set for the partial score. | 37,068 |
Problem G: Time Trial Some people like finishing computer games in an extremely short time. Terry A. Smith is one of such and prefers role playing games particularly. He is now trying to find a shorter play for one of the key events in a role playing game. In this event, a player is presented a kind of puzzle on a grid map with three rocks and three marked squares. The objective is to have all the rocks placed on the marked squares by controlling the hero of this game appropriately. Figure 1: Example Map The hero can move to the four adjacent squares, that is, to the north, east, south, and west, unless his move is blocked by walls or rocks. He can never enter squares occupied by walls. On the other hand, when he is moving to a square occupied by a rock, he pushes the rock in his moving direction. Nonetheless, he cannot push the rock if the next square is occupied by a wall or another rock and his move is blocked in this case. Also, he can only move one rock at a time. It is allowed to have rocks pass through marked squares. Terry thinks he can reduce his playing time by finding the optimal way to move the rocks and then playing the event accordingly. However, it is too hard for him to find the solution of this puzzle by hand. So you are asked by him to write a program that finds the smallest number of steps for the maps given as the input. Here, each move from a square to its adjacent square is counted as one step. Input The input is a sequence of datasets. Each dataset has the following format: W H Row 1 ... Row H W and H are the width and height of the map (4 †W , H †16). Row i denotes the i -th row of the map and consists of W characters. Each character represents a square and is one of the following: â # â (wall), â . â (floor), â * â (rock), â _ â (marked square), and â @ â (hero). Each map contains exactly three rocks, three marked squares, and one hero. The outermost squares are always occupied by walls. You may assume that the number of non-wall squares does not exceed fifty. It is also guaranteed that there is at least one solution for every map. The input is terminated by a line with two zeros. This line is not part of any datasets and should not be processed. Output For each dataset, print the smallest number of steps in a line. Sample Input 7 6 ####### #.._..# #.*.*.# #.@.*.# #_..._# ####### 10 13 ########## ####___### ####...### ####...### #####.#### #.....#..# #.#*.*.*.# #...###..# ###.#.#.## ###.#.#.## ###.....## ###..@..## ########## 0 0 Output for the Sample Input 15 118 | 37,069 |
Score : 300 points Problem Statement Sitting in a station waiting room, Joisino is gazing at her train ticket. The ticket is numbered with four digits A , B , C and D in this order, each between 0 and 9 (inclusive). In the formula A op1 B op2 C op3 D = 7 , replace each of the symbols op1 , op2 and op3 with + or - so that the formula holds. The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted. Constraints 0â€A,B,C,Dâ€9 All input values are integers. It is guaranteed that there is a solution. Input Input is given from Standard Input in the following format: ABCD Output Print the formula you made, including the part =7 . Use the signs + and - . Do not print a space between a digit and a sign. Sample Input 1 1222 Sample Output 1 1+2+2+2=7 This is the only valid solution. Sample Input 2 0290 Sample Output 2 0-2+9+0=7 0 - 2 + 9 - 0 = 7 is also a valid solution. Sample Input 3 3242 Sample Output 3 3+2+4-2=7 | 37,070 |
Problem I: Sort by Hand It's time to arrange the books on your bookshelf. There are n books in the shelf and each book has a unique number; you want to sort the books according to the numbers. You know that the quick sort and the merge sort are fast sorting methods, but it is too hard for you to simulate them by hand - they are efficient for computers, but not for humans. Thus, you decided to sort the books by inserting the book with the number i into the i -th position. How many insertions are required to complete this task? Input The first line of the input is n (1 †n †20), which is the number of books. The second line contains n integers v 1 , ... , v n (1 †v i †n ), where v i indicates the number of the book at the i -th position before the sorting. All v i 's are distinct. Output Print the minimum number of insertions in a line. If it is impossible for him to complete the sort, print "impossible" (without quotes). Sample Input 1 3 1 2 3 Output for the Sample Input 1 0 Sample Input 2 3 2 1 3 Output for the Sample Input 2 1 Sample Input 3 3 3 2 1 Output for the Sample Input 3 2 Sample Input 4 20 4 14 11 13 17 10 1 12 2 6 16 15 8 7 19 18 3 5 9 20 Output for the Sample Input 4 14 | 37,071 |
Problem K: Escape of Lappin the Phantom Thief Problem æªçã©ããã³ã¯å®ç³ãçã¿ã«ãã£ãŠãããç°¡åã«å®ç³ãæã«ããããšãã§ããããå®ç³ã«ã¯ã»ã³ãµãŒãä»èŸŒãŸããŠãããèŠåããããã«å²ãŸããŠããŸã£ãã èŠåããããã¯å®ç³ã«åãã£ãŠç§»åããããã«ä»çµãŸããŠãããã»ã³ãµãŒã¯ç°¡åã«å€ãããã«ãªãã£ãã®ã§ãå®ç³ã眮ããŠéèµ°ããããšã«ãããå®ç³ãã§ããã ãèŠåããããããé ãã«çœ®ããŠãéããããã®æé皌ããããããšã«ããã æ·å°ã¯ n à m ã®ãã¹ãããªãé·æ¹åœ¢ã®åœ¢ãããŠããŠãé害ç©ã¯ãªãã k äœã®èŠåããããã¯ããããããã¹( x i , y i )(0 †x i †n â1, 0 †y i †m â1)ã«é
眮ãããŠãããäžäžå·Šå³ã®ãã¹ã«åäœæéã§ç§»åã§ããã èŠåããããã¯å®ç³ããããã¹ã«æççµè·¯ã§ç§»åããã æ·å°å
ã«èªç±ã«å®ç³ã眮ãããšãã1å°ä»¥äžã®èŠåãããããå®ç³ã®ãããã¹ã«å°éãããŸã§ã«ãããç§»åæéã®æå€§å€ãæ±ããã Input n m k x 1 y 1 x 2 y 2 ... x k y k å
¥åã¯ãã¹ãп޿°ã§äžããããã 1è¡ç®ã« n , m , k ã空çœåºåãã§äžããããã 2è¡ç®ä»¥é k è¡ã«èŠåããããã®ãããã¹ã®åº§æš( x i , y i )ã空çœåºåãã§äžããããã Constraints 1 †n , m †5 à 10 4 1 †k †min(10 5 , n à m ) 0 †x i †n â1 0 †y i †m â1 äžãããã座æšã¯ãã¹ãŠç°ãªã Output èŠåãããããå°éãããŸã§ã«ãæãæéããããå Žæãžã®ç§»åæéã1è¡ã«åºåããã Sample Input 1 20 10 1 0 0 Sample Output 1 28 Sample Input 2 20 10 2 0 0 17 5 Sample Output 2 15 Sample Input 3 20 10 3 0 0 17 5 6 9 Sample Output 3 11 | 37,072 |
Score : 1000 points Problem Statement There is an infinitely large triangular grid, as shown below. Each point with integer coordinates contains a lamp. Initially, only the lamp at (X, 0) was on, and all other lamps were off. Then, Snuke performed the following operation zero or more times: Choose two integers x and y . Toggle (on to off, off to on) the following three lamps: (x, y), (x, y+1), (x+1, y) . After the operations, N lamps (x_1, y_1), \cdots, (x_N, y_N) are on, and all other lamps are off. Find X . Constraints 1 \leq N \leq 10^5 -10^{17} \leq x_i, y_i \leq 10^{17} (x_i, y_i) are pairwise distinct. The input is consistent with the statement, and you can uniquely determine X . Input Input is given from Standard Input in the following format: N x_1 y_1 : x_N y_N Output Print X . Sample Input 1 4 -2 1 -2 2 0 1 1 0 Sample Output 1 -1 The following picture shows one possible sequence of operations: | 37,073 |
Railroad Conflict Nate U. Smith ã¯å€§éœåžåã®ééäŒç€Ÿãçµå¶ããŠããïŒãã®å€§éœåžåã«ã¯ïŒåœŒã®ééäŒç€Ÿä»¥å€ã«ã©ã€ãã«ã®ééäŒç€ŸãããïŒ2 瀟ã¯äºãã«ç«¶åé¢ä¿ã«ããïŒ ãã®å€§éœåžåã§ã¯ïŒåè»ã®éè¡ã容æã«ããããïŒå
šãŠã®è·¯ç·ã¯äž¡ç«¯ã®é§
ãçµãã ç·åãçµè·¯ãšããŠããïŒãŸãïŒèžåçã®èšçœ®ããããããïŒå
šãŠã®è·¯ç·ã¯é«æ¶ãŸãã¯å°äžã«æ·èšãããŠããïŒæ¢åè·¯ç·ã¯ïŒå
šç·ã«ããã£ãŠé«æ¶ãèµ°ããïŒãŸãã¯å
šç·ã«ããã£ãŠå°äžãèµ°ããã®ããããã§ããïŒ ãšããã§ïŒæè¿ïŒãã®å€§éœåžåã«ãã 2 ã€ã®è¡åº AïŒB ããããã«éçºãããŠããããšããïŒNate ã®äŒç€Ÿã§ã¯ãããã®è¡åºã®éã«æ°ããè·¯ç·ãèšããããšã決æããïŒãã®æ°è·¯ç·ã¯ïŒåŸæ¥ã®è·¯ç·ãšåæ§ã« AïŒB ã䞡端ãšããç·åãçµè·¯ãšããããïŒçµè·¯ã®éäžã«ã¯å¥ã®è·¯ç·ãããããšããïŒé«æ¶ãããã¯å°äžã®ããããã«å
šç·ãæ·èšããããšã¯äžå¯èœã§ããïŒããã§ïŒè·¯ç·ã®äžéšã髿¶ã«ïŒæ®ãã®éšåãå°äžã«æ·èšããããšã«ããïŒãã®ãšãïŒæ°è·¯ç·ãèªç€Ÿã®æ¢åè·¯ç·ãšäº€ãããšããã§ã¯ïŒæ°è·¯ç·ãšæ¢åè·¯ç·ãšã®éã®ä¹ãç¶ãã䟿å©ã«ããããïŒæ¢åè·¯ç·ã髿¶ãªãã°æ°è·¯ç·ã髿¶ã«ïŒæ¢åè·¯ç·ãå°äžãªãã°æ°è·¯ç·ãå°äžãèµ°ãããã«ããïŒãŸãïŒæ°è·¯ç·ãä»ç€Ÿã®æ¢åè·¯ç·ãšäº€ãããšããã§ã¯ïŒä»ç€Ÿã«ãã劚害ããããããïŒæ¢åè·¯ç·ã髿¶ãªãã°æ°è·¯ç·ã¯å°äžã«ïŒæ¢åè·¯ç·ãå°äžãªãã°æ°è·¯ç·ã¯é«æ¶ãèµ°ãããã«ããïŒA é§
ããã³ B é§
ããããã髿¶ãããã¯å°äžã®ãããã«èšãããã¯ç¹ã«åããªãïŒ åœç¶ã®ããšãªããïŒæ°è·¯ç·ã髿¶ããå°äžã«ïŒãããã¯å°äžãã髿¶ã«ç§»ããšããã«ã¯åºå
¥å£ãèšããªããã°ãªããªãïŒãšãããïŒåºå
¥å£ãèšããããã«ã¯è²»çšããããããïŒæ°è·¯ç·ã«èšããåºå
¥å£ã®åæ°ã¯æå°éã«æãããïŒããã«ã¯ïŒããã°ã©ãã§ããããªãã®å©ããèŠãããšèãã Nate ã¯ïŒããªãã圌ã®äŒç€Ÿã«åŒã³åºããïŒ ããªãã®ä»äºã¯ïŒA é§
ïŒB é§
ã®äœçœ®ïŒãããŠæ¢åè·¯ç·ã«é¢ããæ
å ±ãäžãããããšãã«ïŒæ°è·¯ç·ã«ãããŠæäœéèšããªããã°ãªããªãåºå
¥å£ã®åæ°ãæ±ããããã°ã©ã ãäœæããããšã§ããïŒ ä»¥äžã®å³ã¯ïŒãµã³ãã«ãšããŠäžããå
¥åããã³åºåã®å
容ã瀺ãããã®ã§ããïŒ Input å
¥åã®å
é è¡ã«ã¯åäžã®æ£ã®æŽæ°ãå«ãŸãïŒããã¯ããŒã¿ã»ããã®åæ°ã衚ãïŒããããã®ããŒã¿ã»ããã¯æ¬¡ã®åœ¢åŒã§äžããããïŒ xa ya xb yb n xs 1 ys 1 xt 1 yt 1 o 1 l 1 xs 2 ys 2 xt 2 yt 2 o 2 l 2 ... xs n ys n xt n yt n o n l n ãã ãïŒ( xa , ya ) ããã³ ( xb , yb ) ã¯ãããã A é§
ïŒB é§
ã®åº§æšã衚ãïŒ N ã¯æ¢åè·¯ç·ã®æ°ã衚ã 100 以äžã®æ£ã®æŽæ°ã§ããïŒ( xs i , ys i ) ããã³ ( ys i , yt i ) 㯠i çªç®ã®æ¢åè·¯ç·ã«ãããå§ç¹ããã³çµç¹ã®åº§æšã衚ãïŒ o i 㯠i çªç®ã®æ¢åè·¯ç·ã®ææè
ãè¡šãæŽæ°ã§ããïŒãã㯠1 ãŸã㯠0 ã®ããããã§ããïŒ1 ã¯ãã®è·¯ç·ãèªç€Ÿææã§ããããšãïŒ0 ã¯ä»ç€Ÿææã§ããããšããããã衚ãïŒ l i 㯠i çªç®ã®æ¢åè·¯ç·ã髿¶ãŸãã¯å°äžã®ãããã«ããããè¡šãæŽæ°ã§ããïŒããã 1 ãŸã㯠0 ã®ããããã§ããïŒ1 ã¯ãã®è·¯ç·ã髿¶ã«ããããšãïŒ0 ã¯å°äžã«ããããšããããã衚ãïŒ å
¥åäžã«çŸãã x 座æšããã³ y 座æšã®å€ã¯ -10000 ãã 10000 ã®ç¯å²ã«ããïŒäž¡ç«¯ãç¯å²ã«å«ãŸããïŒïŒãŸãïŒããããã®ããŒã¿ã»ããã«ãããŠïŒæ°è·¯ç·ãå«ããå
šãŠã®è·¯ç·ã«å¯ŸããŠïŒä»¥äžã®æ¡ä»¶ãæºãããšä»®å®ããŠããïŒããã§ 2 ç¹ãéåžžã«è¿ããšã¯ïŒãã® 2 ç¹éã®è·é¢ã 10 -9 以äžã§ããããšã衚ãïŒ ãã亀ç¹ã®éåžžã«è¿ãã«å¥ã®äº€ç¹ãããããšã¯ãªãïŒ ããè·¯ç·ã®ç«¯ç¹ã®éåžžã«è¿ããå¥ã®è·¯ç·ãéãããšã¯ãªãïŒ 2 ã€ã®è·¯ç·ã®äžéšãŸãã¯å
šéšãéãªãããšã¯ãªãïŒ Output ããããã®ããŒã¿ã»ããã«å¯ŸããŠïŒæäœéèšããªããã°ãªããªãåºå
¥å£ã®åæ°ã 1 è¡ã«åºåããªããïŒ Sample Input 2 -10 1 10 1 4 -6 2 -2 -2 0 1 -6 -2 -2 2 1 0 6 2 2 -2 0 0 6 -2 2 2 1 1 8 12 -7 -3 8 4 -5 4 -2 1 1 4 -2 4 9 1 0 6 9 6 14 1 1 -7 6 7 6 0 0 1 0 1 10 0 0 -5 0 -5 10 0 1 -7 0 7 0 0 1 -1 0 -1 -5 0 1 Output for the Sample Input 1 3 | 37,074 |
Paper Fortune If you visit Aizu Akabeko shrine, you will find a unique paper fortune on which a number with more than one digit is written. Each digit ranges from 1 to 9 (zero is avoided because it is considered a bad omen in this shrine). Using this string of numeric values, you can predict how many years it will take before your dream comes true. Cut up the string into more than one segment and compare their values. The difference between the largest and smallest value will give you the number of years before your wish will be fulfilled. Therefore, the result varies depending on the way you cut up the string. For example, if you are given a string 11121314 and divide it into segments, say, as 1,11,21,3,14, then the difference between the largest and smallest is 21 - 1 = 20. Another division 11,12,13,14 produces 3 (i.e. 14 - 11) years. Any random division produces a game of luck. However, you can search the minimum number of years using a program. Given a string of numerical characters, write a program to search the minimum years before your wish will be fulfilled. Input The input is given in the following format. n An integer n is given. Its number of digits is from 2 to 100,000, and each digit ranges from 1 to 9. Output Output the minimum number of years before your wish will be fulfilled. Sample Input 1 11121314 Sample Output 1 3 Sample Input 2 123125129 Sample Output 2 6 Sample Input 3 119138 Sample Output 3 5 | 37,075 |
The Smallest Window I For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $S$, find the smallest sub-array size (smallest window length) where the sum of the sub-array is greater than or equal to $S$. If there is not such sub-array, report 0. Constraints $1 \leq N \leq 10^5$ $1 \leq S \leq 10^9$ $1 \leq a_i \leq 10^4$ Input The input is given in the following format. $N$ $S$ $a_1$ $a_2$ ... $a_N$ Output Print the smallest sub-array size in a line. Sample Input 1 6 4 1 2 1 2 3 2 Sample Output 1 2 Sample Input 2 6 6 1 2 1 2 3 2 Sample Output 2 3 Sample Input 3 3 7 1 2 3 Sample Output 3 0 | 37,076 |
Cyber Guardian In the good old days, the Internet was free from fears and terrorism. People did not have to worry about any cyber criminals or mad computer scientists. Today, however, you are facing atrocious crackers wherever you are, unless being disconnected. You have to protect yourselves against their attacks. Counting upon your excellent talent for software construction and strong sense of justice, you are invited to work as a cyber guardian. Your ultimate mission is to create a perfect firewall system that can completely shut out any intruders invading networks and protect children from harmful information exposed on the Net. However, it is extremely difficult and none have ever achieved it before. As the first step, instead, you are now requested to write a software simulator under much simpler assumptions. In general, a firewall system works at the entrance of a local network of an organization (e.g., a company or a university) and enforces its local administrative policy. It receives both inbound and outbound packets (note: data transmitted on the Net are divided into small segments called packets) and carefully inspects them one by one whether or not each of them is legal. The definition of the legality may vary from site to site or depend upon the local administrative policy of an organization. Your simulator should accept data representing not only received packets but also the local administrative policy. For simplicity in this problem we assume that each network packet consists of three fields: its source address, destination address, and message body. The source address specifies the computer or appliance that transmits the packet and the destination address specifies the computer or appliance to which the packet is transmitted. An address in your simulator is represented as eight digits such as 03214567 or 31415926, instead of using the standard notation of IP addresses such as 192.168.1.1. Administrative policy is described in filtering rules, each of which specifies some collection of source-destination address pairs and defines those packets with the specified address pairs either legal or illegal. Input The input consists of several data sets, each of which represents filtering rules and received packets in the following format: n m rule 1 rule 2 ... rule n packet 1 packet 2 ... packet m The first line consists of two non-negative integers n and m . If both n and m are zeros, this means the end of input. Otherwise, n lines, each representing a filtering rule, and m lines, each representing an arriving packet, follow in this order. You may assume that n and m are less than or equal to 1,024. Each rule i is in one of the following formats: permit source-pattern destination-pattern deny source-pattern destination-pattern A source-pattern or destination-pattern is a character string of length eight, where each character is either a digit ('0' to '9') or a wildcard character '?'. For instance, "1????5??" matches any address whose first and fifth digits are '1' and '5', respectively. In general, a wildcard character matches any single digit while a digit matches only itself. With the keywords "permit" and "deny", filtering rules specify legal and illegal packets, respectively. That is, if the source and destination addresses of a packed are matched with source-pattern and destination-pattern , respectively, it is permitted to pass the firewall or the request is denied according to the keyword. Note that a permit rule and a deny rule can contradict since they may share the same source and destination address pair. For the purpose of conflict resolution, we define a priority rule: rule i has a higher priority over rule j if and only if i > j . For completeness, we define the default rule: any packet is illegal unless being explicitly specified legal by some given rule. A packet is in the following format: source-address destination-address message-body Each of the first two is a character string of length eight that consists solely of digits. The last one is a character string consisting solely of alphanumeric characters ('a' to 'z', 'A' to 'Z', and '0' to '9'). Neither whitespaces nor special characters can occur in a message body. You may assume that it is not empty and that its length is at most 50. You may also assume that there is exactly one space character between any two adjacent fields in an input line representing a rule or a packet. Output For each data set, print the number of legal packets in the first line, followed by all legal packets in the same order as they occur in the data set. Each packet must be written exactly in one line. If the data set includes two packets consisting of the same source and destination addresses and the same message body, you should consider them different packets and so they must be written in different lines. Any extra whitespaces or extra empty lines must not be written. Sample Input 2 5 permit 192168?? ?12??34? deny 19216899 012343?5 19216711 11233340 HiIamACracker 19216891 01234345 Hello 19216899 01234345 HiIamAlsoACracker 19216809 11200340 World 00000000 99999999 TheEndOfTheWorld 1 2 permit 12345678 23456789 19216891 01234345 Hello 12345678 23456789 Hello 0 0 Output for the Sample Input 2 19216891 01234345 Hello 19216809 11200340 World 1 12345678 23456789 Hello | 37,077 |
æ¹å
å¹³æ31幎4æ30æ¥ããã£ãŠçŸè¡ã®å
å·ã§ããå¹³æãçµäºãïŒãã®ç¿æ¥ããæ°ããå
å·ãå§ãŸãããšã«ãªã£ãïŒå¹³ææåŸã®æ¥ã®ç¿æ¥ã¯æ°å
å·å
幎5æ1æ¥ã«ãªãïŒ ACM-ICPC OB/OGã®äŒ (Japanese Alumni Group; JAG) ãéçºããã·ã¹ãã ã§ã¯ïŒæ¥ä»ãåæŠïŒå
å·ãšããã«ç¶ã幎æ°ã«ãã£ãŠå¹Žã衚çŸããæ¥æ¬ã®æŠïŒãçšã㊠"å¹³æ y 幎 m æ d æ¥" ãšãã圢åŒã§ããŒã¿ããŒã¹ã«ä¿åãããŠããïŒãã®ä¿å圢åŒã¯å€æŽããããšãã§ããªãããïŒJAGã¯å
å·ã倿Žãããªããšä»®å®ããŠåæŠã§è¡šããæ¥ä»ãããŒã¿ããŒã¹ã«ä¿åãïŒåºåã®éã«æ¥ä»ãæ£ããå
å·ãçšãã圢åŒã«å€æããããšã«ããïŒ ããªãã®ä»äºã¯JAGã®ããŒã¿ããŒã¹ã«ä¿åãããŠããæ¥ä»ãïŒå¹³æãŸãã¯æ°å
å·ãçšããæ¥ä»ã«å€æããããã°ã©ã ãæžãããšã§ããïŒæ°å
å·ã¯ãŸã çºè¡šãããŠããªãããïŒ"?" ãçšããŠè¡šãããšã«ããïŒ Input å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯æ¬¡ã®åœ¢åŒã§è¡šãããïŒ g y m d g ã¯å
å·ã衚ãæååã§ããïŒ g= HEISEI ãæãç«ã€ïŒ y, m, d ã¯æŽæ°ã§ããïŒããããå¹ŽïŒæïŒæ¥ã衚ãïŒ 1 †y †100, 1 †m †12, 1 †d †31 ãæãç«ã€ïŒ 2æ30æ¥ãªã©ã®åæŠã«ååšããªãæ¥ä»ã¯ããŒã¿ã»ãããšããŠäžããããªãïŒåæŠãšããŠæ£ãã倿ãããšãã«ïŒå¹³æãããåã®å
å·ãçšããå¿
èŠãããæ¥ä»ãããŒã¿ã»ãããšããŠäžããããªãïŒ å
¥åã®çµãã㯠'#' äžã€ã®ã¿ãããªãè¡ã§ããããããïŒããŒã¿ã»ããã®åæ°ã¯ 100 åãè¶
ããªãïŒ Output åããŒã¿ã»ããã«ã€ããŠïŒå€æåŸã®å
å·ïŒå¹ŽïŒæïŒæ¥ã空çœã§åºåã£ãŠ 1 è¡ã«åºåããïŒå€æåŸã®å
å·ã "å¹³æ" ã§ããå Žå㯠"HEISEI" ãå
å·ãšããŠçšãïŒæ°å
å·ã§ããã° "?" ãçšããïŒ éåžžïŒå
å·ã®ç¬¬ 1 幎ç®ã¯å
幎ãšè¡šèšãããïŒæ¬åé¡ã®åºåã§ã¯ãã®èŠåãç¡èŠãïŒ1 ã幎ãšããŠåºåããïŒ Sample Input HEISEI 1 1 8 HEISEI 31 4 30 HEISEI 31 5 1 HEISEI 99 12 31 HEISEI 38 8 30 HEISEI 98 2 22 HEISEI 2 3 26 HEISEI 28 4 23 # Output for the Sample Input HEISEI 1 1 8 HEISEI 31 4 30 ? 1 5 1 ? 69 12 31 ? 8 8 30 ? 68 2 22 HEISEI 2 3 26 HEISEI 28 4 23 | 37,078 |
Problem F: ICPC: Intelligent Congruent Partition of Chocolate The twins named Tatsuya and Kazuya love chocolate. They have found a bar of their favorite chocolate in a very strange shape. The chocolate bar looks to have been eaten partially by Mam. They, of course, claim to eat it and then will cut it into two pieces for their portions. Since they want to be sure that the chocolate bar is fairly divided, they demand that the shapes of the two pieces are congruent and that each piece is connected . The chocolate bar consists of many square shaped blocks of chocolate connected to the adjacent square blocks of chocolate at their edges. The whole chocolate bar is also connected. Cutting the chocolate bar along with some edges of square blocks, you should help them to divide it into two congruent and connected pieces of chocolate. That is, one piece fits into the other after it is rotated, turned over and moved properly. Figure F-1: A partially eaten chocolate bar with 18 square blocks of chocolate For example, there is a partially eaten chocolate bar with 18 square blocks of chocolate as depicted in Figure F-1. Cutting it along with some edges of square blocks, you get two pieces of chocolate with 9 square blocks each as depicted in Figure F-2. Figure F-2: Partitioning of the chocolate bar in Figure F-1 You get two congruent and connected pieces as the result. One of them consists of 9 square blocks hatched with horizontal lines and the other with vertical lines. Rotated clockwise with a right angle and turned over on a horizontal line, the upper piece exactly fits into the lower piece. Figure F-3: A shape that cannot be partitioned into two congruent and connected pieces Two square blocks touching only at their corners are regarded as they are not connected to each other. Figure F-3 is an example shape that cannot be partitioned into two congruent and connected pieces. Note that, without the connectivity requirement, this shape can be partitioned into two congruent pieces with three squares (Figure F-4). Figure F-4: Two congruent but disconnected pieces Your job is to write a program that judges whether a given bar of chocolate can be partitioned into such two congruent and connected pieces or not. Input The input is a sequence of datasets. The end of the input is indicated by a line containing two zeros separated by a space. Each dataset is formatted as follows. w h r (1, 1) ... r (1, w ) r (2, 1) ... r (2, w ) ... r ( h , 1) ... r ( h , w ) The integers w and h are the width and the height of a chocolate bar, respectively. You may assume 2 †w †10 and 2 †h †10. Each of the following h lines consists of w digits delimited by a space. The digit r ( i , j ) represents the existence of a square block of chocolate at the position ( i , j ) as follows. '0': There is no chocolate (i.e., already eaten). '1': There is a square block of chocolate. You can assume that there are at most 36 square blocks of chocolate in the bar, i.e., the number of digit '1's representing square blocks of chocolate is at most 36 in each dataset. You can also assume that there is at least one square block of chocolate in each row and each column. You can assume that the chocolate bar is connected. Since Mam does not eat chocolate bars making holes in them, you can assume that there is no dataset that represents a bar in a shape with hole(s) as depicted in Figure F-5. Figure F-5: A partially eaten chocolate bar with a hole (You can assume that there is no dataset like this example) Output For each dataset, output a line containing one of two uppercase character strings "YES" or "NO". "YES" means the chocolate bar indicated by the dataset can be partitioned into two congruent and connected pieces, and "NO" means it cannot be partitioned into such two pieces. No other characters should be on the output line. Sample Input 2 2 1 1 1 1 3 3 0 1 0 1 1 0 1 1 1 4 6 1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 0 0 1 1 0 1 1 1 0 7 5 0 0 1 0 0 1 1 0 1 1 1 1 1 0 0 1 1 1 1 1 0 1 1 1 1 1 1 0 1 0 0 0 1 1 0 9 7 0 0 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 0 1 1 0 0 0 0 0 0 0 1 0 0 0 0 0 9 7 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 7 6 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 0 0 1 1 1 1 1 0 0 1 1 1 1 1 0 10 10 0 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 1 0 1 1 1 1 1 1 1 1 1 0 0 0 Output for the Sample Input YES NO YES YES YES NO NO YES | 37,079 |
Score : 600 points Problem Statement Given are an integer N and arrays S , T , U , and V , each of length N . Construct an NÃN matrix a that satisfy the following conditions: a_{i,j} is an integer. 0 \leq a_{i,j} \lt 2^{64} . If S_{i} = 0 , the bitwise AND of the elements in the i -th row is U_{i} . If S_{i} = 1 , the bitwise OR of the elements in the i -th row is U_{i} . If T_{i} = 0 , the bitwise AND of the elements in the i -th column is V_{i} . If T_{i} = 1 , the bitwise OR of the elements in the i -th column is V_{i} . However, there may be cases where no matrix satisfies the conditions. Constraints All values in input are integers. 1 \leq N \leq 500 0 \leq S_{i} \leq 1 0 \leq T_{i} \leq 1 0 \leq U_{i} \lt 2^{64} 0 \leq V_{i} \lt 2^{64} Input Input is given from Standard Input in the following format: N S_{1} S_{2} ... S_{N} T_{1} T_{2} ... T_{N} U_{1} U_{2} ... U_{N} V_{1} V_{2} ... V_{N} Output If there exists a matrix that satisfies the conditions, print one such matrix in the following format: a_{1,1} ... a_{1,N} : a_{N,1} ... a_{N,N} Note that any matrix satisfying the conditions is accepted. If no matrix satisfies the conditions, print -1 . Sample Input 1 2 0 1 1 0 1 1 1 0 Sample Output 1 1 1 1 0 In Sample Input 1 , we need to find a matrix such that: the bitwise AND of the elements in the 1 -st row is 1 ; the bitwise OR of the elements in the 2 -nd row is 1 ; the bitwise OR of the elements in the 1 -st column is 1 ; the bitwise AND of the elements in the 2 -nd column is 0 . Sample Input 2 2 1 1 1 0 15 15 15 11 Sample Output 2 15 11 15 11 | 37,080 |
Score : 400 points Problem Statement Snuke has decided to play a game using cards. He has a deck consisting of N cards. On the i -th card from the top, an integer A_i is written. He will perform the operation described below zero or more times, so that the values written on the remaining cards will be pairwise distinct. Find the maximum possible number of remaining cards. Here, N is odd, which guarantees that at least one card can be kept. Operation: Take out three arbitrary cards from the deck. Among those three cards, eat two: one with the largest value, and another with the smallest value. Then, return the remaining one card to the deck. Constraints 3 ⊠N ⊠10^{5} N is odd. 1 ⊠A_i ⊠10^{5} A_i is an integer. Input The input is given from Standard Input in the following format: N A_1 A_2 A_3 ... A_{N} Output Print the answer. Sample Input 1 5 1 2 1 3 7 Sample Output 1 3 One optimal solution is to perform the operation once, taking out two cards with 1 and one card with 2 . One card with 1 and another with 2 will be eaten, and the remaining card with 1 will be returned to deck. Then, the values written on the remaining cards in the deck will be pairwise distinct: 1 , 3 and 7 . Sample Input 2 15 1 3 5 2 1 3 2 8 8 6 2 6 11 1 1 Sample Output 2 7 | 37,081 |
ãããã ããŒããã square1001åãšE869120åã¯çžŠ $H$ è¡ã暪 $W$ åã®ã°ãªããã®äžçã«è¿·ã蟌ãã§ããŸããŸãã! ãã®äžçã®ç¥ã¯èšããŸããã ããªã³ãŽã $K$ åéããŠäºäººãåºäŒã£ããšãããããã°å
ã®äžçã«åž°ããã§ããããã ãã®èšèãèããsquare1001åã¯ããªã³ãŽã $K$ å以äžéããŠE869120åããããã¹ãžåããããšã«ããŸããã ããã§ãã°ãªããã®åãã¹ã¯æ¬¡ã®ããã«è¡šãããŸãã 's'ïŒsquare1001åããããã¹ã§ãã 'e'ïŒE869120åããããã¹ã§ãã 'a'ïŒãªã³ãŽã1ã€èœã¡ãŠãããã¹ã§ãããã®ãã¹ãåããŠèšªãããšãã«ãªã³ãŽã1ã€åŸãããšãã§ããŸãã ãã®ã°ãªããäžã«ãã®ãã¹ã¯20å以äžãããããŸããã '#'ïŒå£ã§ãããã®ãã¹ã«èšªããããšã¯ã§ããŸããã '.'ïŒäœããªããã¹ã§ãããã®ãã¹ã«èšªããããšãã§ããŸãã square1001åã¯èªåããããã¹ããäžäžå·Šå³ã«é£ãåããã¹ãžã®ç§»åãç¹°ãè¿ãããšã§ãç®çãéæããããšããŸãããã ããã°ãªããããå€ã«åºãããšã¯ã§ããŸããã square1001åãç®çãéæããããã«å¿
èŠãªç§»ååæ°ã®æå°å€ãæ±ããŠãã ããã ãã ããE869120åãåãããšã¯ãªããã®ãšããŸãããŸããsquare1001åã¯ãªã³ãŽã $K$ åä»¥äžæã¡éã¶èœåããããã®ãšããŸãã ãŸããç®æšãéæã§ããªããšãã¯ã-1ããåºåããŠãã ããã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããã ã°ãªããã®äžãã $i$ ãã¹ç®ãå·Šãã $j$ ãã¹ç®ã®æåã $A_{i, j}$ ãšããã $H$ $W$ $K$ $A_{1,1} A_{1,2} A_{1,3} \cdots A_{1,W}$ $A_{2,1} A_{2,2} A_{2,3} \cdots A_{2,W}$ $A_{3,1} A_{3,2} A_{3,3} \cdots A_{3,W}$ $\ldots$ $A_{H,1} A_{H,2} A_{H,3} \cdots A_{H,W}$ åºå square1001åãç®çãéæãããŸã§ã«å¿
èŠãªç§»ååæ°ã®æå°å€ãæ±ããŠãã ããããã ããäžå¯èœãªå Žåã¯ã-1ããåºåããŠãã ããã ãã ããæåŸã«ã¯æ¹è¡ãå
¥ããããšã å¶çŽ $1 \leq H \leq 1000$ $1 \leq W \leq 1000$ $1 \leq K \leq 20$ $H, W, K$ ã¯æŽæ°ã§ããã $A_{i, j}$ 㯠's'ã'e'ã'a'ã'#'ã'.'ã®ããããã§ããã ã°ãªããã« 's'ã'e'ã¯ãããããã 1 ã€ã®ã¿å«ãŸããã ã°ãªããã«å«ãŸãã 'a' ã®æ°ã¯ $K$ åä»¥äž $20$ å以äžã§ããã å
¥åäŸ1 5 5 2 s..#a .#... a#e.# ...#a .#... åºåäŸ1 14 å
¥åäŸ2 7 7 3 ....... .s...a. a##...a ..###.. .a#e#.a #.###.. a..#..a åºåäŸ2 -1 ç®çãéæäžå¯èœãªå Žåã¯ã-1ããåºåããŠãã ããã å
¥åäŸ3 12 12 10 .#####...... .##.....#... ....a.a#a..# .#..#a...... ##.....a#s.. #..a###.##.# .e#.#.#.#a.. ..#a#.....#. #..##a...... .a...a.a..#. a....#a.aa.. ...a.#...#a. åºåäŸ3 30 | 37,082 |
Meeting in a City You are a teacher at Iazu High School is the Zuia Kingdom. There are $N$ cities and $N-1$ roads connecting them that allow you to move from one city to another by way of more than one road. Each of the roads allows bidirectional traffic and has a known length. As a part of class activities, you are planning the following action assignment for your students. First, you come up with several themes commonly applicable to three different cities. Second, you assign each of the themes to a group of three students. Then, each student of a group is assigned to one of the three cities and conducts a survey on it. Finally, all students of the group get together in one of the $N$ cities and compile their results. After a theme group has completed its survey, the three members move from the city on which they studied to the city for getting together. The longest distance they have to travel for getting together is defined as the cost of the theme. You want to select the meeting city so that the cost for each theme becomes minimum. Given the number of cities, road information and $Q$ sets of three cities for each theme, make a program to work out the minimum cost for each theme. Input The input is given in the following format. $N$ $Q$ $u_1$ $v_1$ $w_1$ $u_2$ $v_2$ $w_2$ $...$ $u_{N-1}$ $v_{N-1}$ $w_{N-1}$ $a_1$ $b_1$ $c_1$ $a_2$ $b_2$ $c_2$ $...$ $a_Q$ $b_Q$ $c_Q$ The first line provides the number of cities in the Zuia Kingdom $N$ ($3 \leq N \leq 100,000$) and the number of themes $Q$ ($1 \leq Q \leq 100,000$). Each of the subsequent $N-1$ lines provides the information regarding the $i$-th road $u_i,v_i,w_i$ ($ 1 \leq u_i < v_i \leq N, 1 \leq w_i \leq 10,000$), indicating that the road connects cities $u_i$ and $v_i$, and the road distance between the two is $w_i$. Each of the $Q$ lines that follows the above provides the three cities assigned to the $i$-th theme: $a_i,b_i,c_i$ ($1 \leq a_i < b_i < c_i \leq N$). Output For each theme, output the cost in one line. Sample Input 1 5 4 1 2 3 2 3 4 2 4 2 4 5 3 1 3 4 1 4 5 1 2 3 2 4 5 Sample Output 1 4 5 4 3 In the first theme, traveling distance from City 3 (the student conducts survey) to City 2 (meeting venue) determines the cost 4. As no other meeting city can provide smaller cost, you should output 4. In the second theme, you can minimize the cost down to 5 by selecting City 2 or City 4 as the meeting venue. Sample Input 2 5 3 1 2 1 2 3 1 3 4 1 4 5 1 1 2 3 1 3 5 1 2 4 Sample Output 2 1 2 2 Sample Input 3 15 15 1 2 45 2 3 81 1 4 29 1 5 2 5 6 25 4 7 84 7 8 56 4 9 2 4 10 37 7 11 39 1 12 11 11 13 6 3 14 68 2 15 16 10 13 14 13 14 15 2 14 15 7 12 15 10 14 15 9 10 15 9 14 15 8 13 15 5 6 13 11 13 15 12 13 14 2 3 10 5 13 15 10 11 14 6 8 11 Sample Output 3 194 194 97 90 149 66 149 140 129 129 194 111 129 194 140 | 37,083 |
Score : 300 points Problem Statement Given are an integer X and an integer sequence of length N : p_1, \ldots, p_N . Among the integers not contained in the sequence p_1, \ldots, p_N (not necessarily positive), find the integer nearest to X , that is, find the integer whose absolute difference with X is the minimum. If there are multiple such integers, report the smallest such integer. Constraints 1 \leq X \leq 100 0 \leq N \leq 100 1 \leq p_i \leq 100 p_1, \ldots, p_N are all distinct. All values in input are integers. Input Input is given from Standard Input in the following format: X N p_1 ... p_N Output Print the answer. Sample Input 1 6 5 4 7 10 6 5 Sample Output 1 8 Among the integers not contained in the sequence 4, 7, 10, 6, 5 , the one nearest to 6 is 8 . Sample Input 2 10 5 4 7 10 6 5 Sample Output 2 9 Among the integers not contained in the sequence 4, 7, 10, 6, 5 , the ones nearest to 10 are 9 and 11 . We should print the smaller one, 9 . Sample Input 3 100 0 Sample Output 3 100 When N = 0 , the second line in the input will be empty. Also, as seen here, X itself can be the answer. | 37,084 |
Score : 800 points Problem Statement There are N rabbits on a number line. The rabbits are conveniently numbered 1 through N . The coordinate of the initial position of rabbit i is x_i . The rabbits will now take exercise on the number line, by performing sets described below. A set consists of M jumps . The j -th jump of a set is performed by rabbit a_j ( 2â€a_jâ€N-1 ). For this jump, either rabbit a_j-1 or rabbit a_j+1 is chosen with equal probability (let the chosen rabbit be rabbit x ), then rabbit a_j will jump to the symmetric point of its current position with respect to rabbit x . The rabbits will perform K sets in succession. For each rabbit, find the expected value of the coordinate of its eventual position after K sets are performed. Constraints 3â€Nâ€10^5 x_i is an integer. |x_i|â€10^9 1â€Mâ€10^5 2â€a_jâ€N-1 1â€Kâ€10^{18} Input The input is given from Standard Input in the following format: N x_1 x_2 ... x_N M K a_1 a_2 ... a_M Output Print N lines. The i -th line should contain the expected value of the coordinate of the eventual position of rabbit i after K sets are performed. The output is considered correct if the absolute or relative error is at most 10^{-9} . Sample Input 1 3 -1 0 2 1 1 2 Sample Output 1 -1.0 1.0 2.0 Rabbit 2 will perform the jump. If rabbit 1 is chosen, the coordinate of the destination will be -2 . If rabbit 3 is chosen, the coordinate of the destination will be 4 . Thus, the expected value of the coordinate of the eventual position of rabbit 2 is 0.5Ã(-2)+0.5Ã4=1.0 . Sample Input 2 3 1 -1 1 2 2 2 2 Sample Output 2 1.0 -1.0 1.0 x_i may not be distinct. Sample Input 3 5 0 1 3 6 10 3 10 2 3 4 Sample Output 3 0.0 3.0 7.0 8.0 10.0 | 37,085 |
Score : 200 points Problem Statement Some number of chocolate pieces were prepared for a training camp. The camp had N participants and lasted for D days. The i -th participant ( 1 \leq i \leq N ) ate one chocolate piece on each of the following days in the camp: the 1 -st day, the (A_i + 1) -th day, the (2A_i + 1) -th day, and so on. As a result, there were X chocolate pieces remaining at the end of the camp. During the camp, nobody except the participants ate chocolate pieces. Find the number of chocolate pieces prepared at the beginning of the camp. Constraints 1 \leq N \leq 100 1 \leq D \leq 100 1 \leq X \leq 100 1 \leq A_i \leq 100 ( 1 \leq i \leq N ) All input values are integers. Input Input is given from Standard Input in the following format: N D X A_1 A_2 : A_N Output Find the number of chocolate pieces prepared at the beginning of the camp. Sample Input 1 3 7 1 2 5 10 Sample Output 1 8 The camp has 3 participants and lasts for 7 days. Each participant eats chocolate pieces as follows: The first participant eats one chocolate piece on Day 1 , 3 , 5 and 7 , for a total of four. The second participant eats one chocolate piece on Day 1 and 6 , for a total of two. The third participant eats one chocolate piece only on Day 1 , for a total of one. Since the number of pieces remaining at the end of the camp is one, the number of pieces prepared at the beginning of the camp is 1 + 4 + 2 + 1 = 8 . Sample Input 2 2 8 20 1 10 Sample Output 2 29 Sample Input 3 5 30 44 26 18 81 18 6 Sample Output 3 56 | 37,086 |
Problem G: Nezumi's Treasure There were a mouse and a cat living in a field. The mouse stole a dried fish the cat had loved. The theft was found soon later. The mouse started running as chased by the cat for the dried fish. There were a number of rectangular obstacles in the field. The mouse always went straight ahead as long as possible, but he could not jump over or pass through these obstacles. When he was blocked by an obstacle, he turned leftward to the direction he could go forward, and then he started again to run in that way. Note that, at the corner, he might be able to keep going without change of the direction. He found he was going to pass the same point again and again while chased by the cat. He then decided to hide the dried fish at the first point where he was blocked by an obstacle twice from that time. In other words, he decided to hide it at the first turn after he entered into an infinite loop. He thought he could come there again after the chase ended. For example, in the following figure, he first went along the blue line and turned left at point B. Then he went along the red lines counter-clockwise, and entered into an infinite loop. In this case, he hid dried fish at NOT point B but at point A, because when he reached point B on line C for the second time, he just passed and didn't turn left. Example of dried fish point Finally the cat went away, but he remembered neither where he thought of hiding the dried fish nor where he actually hid it. Yes, he was losing his dried fish. You are a friend of the mouse and talented programmer. Your task is to write a program that counts the number of possible points the mouse hid the dried fish, where information about the obstacles is given. The mouse should be considered as a point. Input The input begins with a line with one integer N (4 <= N <= 40,000), which denotes the number of obstacles. Then N lines follow. Each line describes one obstacle with four integers X i,1 , Y i,1 , X i,2 , and Y i,2 (-100,000,000 <= X i,1 , Y i,1 , X i,2 , Y i,2 <= 100,000,000). (X i,1 , Y i,1 ) and (X i,2 , Y i,2 ) represent the coordinates of the lower-left and upper-right corners of the obstacle respectively. As usual, X -axis and Y -axis go right and upward respectively. No pair of obstacles overlap. Output Print the number of points the mouse could hide the dried fish. You can assume this number is positive (i.e. nonzero). Sample Input 1 4 0 0 2 1 3 0 4 2 0 2 1 4 2 3 4 4 Output for the Sample Input 1 4 Sample Input 2 8 0 0 2 1 2 2 4 3 5 3 7 4 7 5 9 6 0 2 1 4 2 4 3 6 6 0 7 2 8 2 9 4 Output for the Sample Input 2 8 | 37,087 |
Score : 500 points Problem Statement Snuke received a positive integer N from Takahashi. A positive integer m is called a favorite number when the following condition is satisfied: The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds. Find all favorite numbers and print the sum of those. Constraints All values in input are integers. 1 \leq N \leq 10^{12} Input Input is given from Standard Input in the following format: N Output Print the answer. Sample Input 1 8 Sample Output 1 10 There are two favorite numbers: 3 and 7 . Print the sum of these, 10 . Sample Input 2 1000000000000 Sample Output 2 2499686339916 Watch out for overflow. | 37,088 |
E: Red Black Balloons Story Homura-chan's dream comes true. It means ICPC Asia regional contest 20xx will be held in Sapporo! Homura-chan has been working hard for the preparation. And finally, it's the previous day of the contest. Homura-chan started to stock balloons to be delivered to contestants who get accepted. However, she noticed that there were only two colors of balloons: red and black. Problem Statement ICPC Asia regional contest in Sapporo plans to provide N problems to contestants. Homura-chan is a professional of contest preparation, so she already knows how many contestants would get acceptance for each problem (!!), a_i contestants for the i -th problem. You can assume the prediction is perfectly accurate. Ideally, Homura-chan would assign a distinct color of a balloon to each problem respectively. But you know, she has only two colors red and black now. Thus, Homura-chan comes up with the idea to differentiate the size of balloons in K levels , that is, each problem has a balloon with a distinct pair of (color, size). Homura-chan now has r_i red balloons with size i ( 1 \leq i \leq K ) and b_j black balloons with size j ( 1 \leq j \leq K ). Suppose we assign a pair (c_i, s_i) of a color c_i (red or black) and a size s_i to the i -th problem, for each i . As noted, we have to assign distinct pairs to each problem, more precisely, (c_i, s_i) \neq (c_j, s_j) holds for i \neq j . Moreover, the number of balloons with (c_i, s_i) must be no less than a_i . In the case that there are no such assignments, Homura-chan can change the size of balloons by her magic power. Note that Homura-chan doesn't know magic to change the color of balloons, so it's impossible. Your task is to write a program computing the minimum number of balloons whose size is changed by Homura-chan's magic to realize an assignment satisfying the above-mentioned conditions. If there is no way to achieve such an assignment even if Homura-chan changes the size of balloons infinitely, output -1 instead. Input N K a_1 ... a_N r_1 ... r_K b_1 ... b_K Constraints 1 \leq N,K \leq 60 N \leq 2K 1 \leq a_i \leq 50 (1 \leq i \leq N) 1 \leq r_j,b_j \leq 50 (1 \leq j \leq K) Inputs consist only of integers. Output Output the minimum number of balloons whose size is changed to achieve an assignment in a line. If there are no ways to achieve assignments, output -1 instead. Sample Input 1 3 2 6 5 4 8 1 7 1 Output for Sample Input 1 3 Homura-chan changes the size of three red balloons from 1 to 2. Then she can assign (black,1) to the problem 1, (red,1) to the problem 2, and (red,2) to the problem 3. Sample Input 2 2 1 50 50 2 3 Output for Sample Input 2 -1 Sample Input 3 4 3 3 10 28 43 40 18 2 26 7 11 Output for Sample Input 3 5 | 37,089 |
Score : 100 points Problem Statement You are given an array a_0, a_1, ..., a_{N-1} of length N . Process Q queries of the following types. 0 l r b c : For each i = l, l+1, \dots, {r - 1} , set a_i \gets b \times a_i + c . 1 l r : Print \sum_{i = l}^{r - 1} a_i \bmod 998244353 . Constraints 1 \leq N, Q \leq 500000 0 \leq a_i, c < 998244353 1 \leq b < 998244353 0 \leq l < r \leq N All values in Input are integer. Input Input is given from Standard Input in the following format: N Q a_0 a_1 ... a_{N - 1} \textrm{Query}_0 \textrm{Query}_1 : \textrm{Query}_{Q - 1} Output For each query of the latter type, print the answer. Sample Input 1 5 7 1 2 3 4 5 1 0 5 0 2 4 100 101 1 0 3 0 1 3 102 103 1 2 5 0 2 5 104 105 1 0 5 Sample Output 1 15 404 41511 4317767 | 37,090 |
äŒæ©ã¹ããŒã¹ (Refreshment Area) åé¡ äžççãªããã°ã©ãã³ã°ã³ã³ãã¹ããæ¥æ¬ã§éå¬ãããããšã«ãªãïŒçŸåšäŒå Žã®èšå¶ãè¡ãããŠããïŒãã®äŒå Žã¯ååæ¹åã« N ãã¹ïŒæ±è¥¿æ¹åã« M ãã¹ã®ãã¹ç®ç¶ã«åºåãããŠããïŒããã€ãã®ãã¹ã«ã¯ç«¶æçšã®æ©æã眮ãããŠããïŒ ãã®ã³ã³ãã¹ãã§ã¯ïŒéžæãç«¶æäžã«äŒæ©ããããã«ïŒè»œé£ã飲ã¿ç©ãªã©ã眮ããäŒæ©ã¹ããŒã¹ã 1 ç®æäŒå Žå
ã«èšããããšã«ãªã£ãïŒäŒæ©ã¹ããŒã¹ã¯ååæ¹åãŸãã¯æ±è¥¿æ¹åã«é£ç¶ãã D ãã¹ã§ãªããã°ãªããªãïŒãã ãïŒæ©æã®çœ®ããããã¹ç®ã«äŒæ©ã¹ããŒã¹ãèšããããšã¯ã§ããªãïŒ äŒå Žå
ã«äŒæ©ã¹ããŒã¹ãèšããæ¹æ³ã¯äœéãããããæ±ããããã°ã©ã ãäœæããïŒ å
¥å å
¥å㯠1 + N è¡ãããªãïŒ 1 è¡ç®ã«ã¯ 3 åã®æŽæ° N, M, D (1 ⊠N ⊠100, 1 ⊠M ⊠100, 2 ⊠D ⊠100) ã空çœãåºåããšããŠæžãããŠããïŒäŒå Žãååæ¹åã« N ãã¹ïŒæ±è¥¿æ¹åã« M ãã¹ã®ãã¹ç®ç¶ã«åºåãããŠããïŒäŒæ©ã¹ããŒã¹ãååæ¹åãŸãã¯æ±è¥¿æ¹åã«é£ç¶ãã D ãã¹ãããªãããšã衚ãïŒ ç¶ã N è¡ã«ã¯ãããã M æåãããªãæååãæžãããŠããïŒäŒå Žã®æ
å ±ã衚ãïŒ N è¡ã®ãã¡ã® i è¡ç®ã® j æåç® (1 ⊠i ⊠N, 1 ⊠j ⊠M) ã¯ïŒäŒå Žã®ãã¹ç®ã®åãã i è¡ç®ïŒè¥¿ãã j åç®ã®ãã¹ã®ç¶æ
ã衚ã '#' ãŸã㯠'.' ã®ããããã®æåã§ããïŒ'#' ã¯ãã®ãã¹ã«æ©æã眮ãããŠããããšãïŒ'.' ã¯ãã®ãã¹ã«æ©æã眮ãããŠããªãããšã衚ãïŒ åºå äŒå Žå
ã«äŒæ©ã¹ããŒã¹ãèšããæ¹æ³ã¯äœéããããã 1 è¡ã§åºåããïŒ å
¥åºåäŸ å
¥åäŸ 1 3 5 2 ...#. #...# ....# åºåäŸ 1 12 å
¥åäŸ 2 4 7 5 .#..... .....## ....... #...... åºåäŸ 2 7 å
¥åºåäŸ 1 ã§ã¯ïŒäžã®å³ã«ç€ºãããã«ïŒäŒæ©ã¹ããŒã¹ãèšããæ¹æ³ã¯å
šéšã§ 12 éãããïŒ æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒäœ ã第 16 åæ¥æ¬æ
å ±ãªãªã³ãã㯠JOI 2016/2017 äºéžç«¶æèª²é¡ã | 37,091 |
Problem B: U&U Problem $2$ã€ã®ããŒã ãããŒã UKUãšããŒã ããããããæåãããŒã UKUã«ã¯$N$人ãããŒã ããã«ã¯$M$人ã®äººãããã ããŒã UKUãšããŒã ããã¯ãU&Uããšããã²ãŒã ãè¡ãããšã«ããããU&Uãã¯$2$ã€ã®ããŒã ã§å
±éã®ã¹ã³ã¢ãæã£ãŠãããäºãã«ååãããå
±éã®ã¹ã³ã¢ãæå°åããããšãç®çã§ããããU&Uãã¯æåããã¹ãŠã®äººã®äœåã$2$ã§ãå
±éã®ã¹ã³ã¢ã¯$0$ã®ç¶æ
ã§ä»¥äžã®ãããªæé ã§é²ããããã ããŒã UKUã®äººã¯1人ãã€ãããŒã ããã®èª°ã$1$人ã«å¯ŸããŠã¡ããã©$1$åã®æ»æãè¡ãã æ»æãåãã人ã¯äœåã$1$æžããäœåã$0$ã«ãªã£ãå Žåãã®ããŒã ããæããã ãã®ãšãããŒã ããã®äººæ°ã$0$人ã«ãªã£ãããã²ãŒã ãçµäºããã ããŒã UKUã®ãã¹ãŠã®äººãã¡ããã©$1$åã®æ»æãçµããæç¹ã§ã²ãŒã ãçµäºããŠãªããã°å
±éã®ã¹ã³ã¢ã«$1$ãå ç®ããã$2$.ã«é²ã åæ§ã«ãããŒã ããã®äººã$1$人ãã€ãããŒã UKUã®èª°ã$1$人ã«å¯ŸããŠã¡ããã©$1$åã®æ»æãè¡ãã æ»æãåãã人ã¯äœåã$1$æžããäœåã$0$ã«ãªã£ãå Žåãã®ããŒã ããæããã ãã®ãšãããŒã UKUã®äººæ°ã$0$人ã«ãªã£ãããã²ãŒã ãçµäºããã ããŒã ããã®ãã¹ãŠã®äººãã¡ããã©$1$åã®æ»æãçµããæç¹ã§ã²ãŒã ãçµäºããŠãªããã°å
±éã®ã¹ã³ã¢ã«$1$ãå ç®ããã$1$.ã«æ»ã ããŒã UKUã®äººæ°ãšããŒã ããã®äººæ°ãäžãããããšãããU&Uãã²ãŒã çµäºæã®å
±éã®ã¹ã³ã¢ãšããŠãããããã®ã®æå°å€ãããšããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã $N$ $M$ ããŒã UKUã®äººæ°ãè¡šãæŽæ°$N$ãšããŒã ããã®äººæ°ãè¡šãæŽæ°$M$ã空çœåºåãã§äžããããã Constraints å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã $1 \le N, M \le 10^{18}$ $N$ãš$M$ã¯æŽæ° Output æå°ã®ã¹ã³ã¢ã$1$è¡ã«åºåããã Sample Input 1 20 10 Sample Output 1 0 Sample Input 2 10 20 Sample Output 2 1 Sample Input 3 64783 68943 Sample Output 3 4 Sample Input 4 1000000000000000000 1000000000000000000 Sample Output 4 2 | 37,092 |
Book Index Books are indexed. Write a program which reads a list of pairs of a word and a page number, and prints the word and a list of the corresponding page numbers. You can assume that a word consists of at most 30 characters, and the page number is less than or equal to 1000. The number of pairs of a word and a page number is less than or equal to 100. A word never appear in a page more than once. The words should be printed in alphabetical order and the page numbers should be printed in ascending order. Input word page_number : : Output word a_list_of_the_page_number word a_list_of_the_Page_number : : Sample Input style 12 even 25 introduction 3 easy 9 style 7 document 13 style 21 even 18 Output for the Sample Input document 13 easy 9 even 18 25 introduction 3 style 7 12 21 | 37,093 |
Score : 500 points Problem Statement Ken loves ken-ken-pa (Japanese version of hopscotch). Today, he will play it on a directed graph G . G consists of N vertices numbered 1 to N , and M edges. The i -th edge points from Vertex u_i to Vertex v_i . First, Ken stands on Vertex S . He wants to reach Vertex T by repeating ken-ken-pa. In one ken-ken-pa, he does the following exactly three times: follow an edge pointing from the vertex on which he is standing. Determine if he can reach Vertex T by repeating ken-ken-pa. If the answer is yes, find the minimum number of ken-ken-pa needed to reach Vertex T . Note that visiting Vertex T in the middle of a ken-ken-pa does not count as reaching Vertex T by repeating ken-ken-pa. Constraints 2 \leq N \leq 10^5 0 \leq M \leq \min(10^5, N (N-1)) 1 \leq u_i, v_i \leq N(1 \leq i \leq M) u_i \neq v_i (1 \leq i \leq M) If i \neq j , (u_i, v_i) \neq (u_j, v_j) . 1 \leq S, T \leq N S \neq T Input Input is given from Standard Input in the following format: N M u_1 v_1 : u_M v_M S T Output If Ken cannot reach Vertex T from Vertex S by repeating ken-ken-pa, print -1 . If he can, print the minimum number of ken-ken-pa needed to reach vertex T . Sample Input 1 4 4 1 2 2 3 3 4 4 1 1 3 Sample Output 1 2 Ken can reach Vertex 3 from Vertex 1 in two ken-ken-pa, as follows: 1 \rightarrow 2 \rightarrow 3 \rightarrow 4 in the first ken-ken-pa, then 4 \rightarrow 1 \rightarrow 2 \rightarrow 3 in the second ken-ken-pa. This is the minimum number of ken-ken-pa needed. Sample Input 2 3 3 1 2 2 3 3 1 1 2 Sample Output 2 -1 Any number of ken-ken-pa will bring Ken back to Vertex 1 , so he cannot reach Vertex 2 , though he can pass through it in the middle of a ken-ken-pa. Sample Input 3 2 0 1 2 Sample Output 3 -1 Vertex S and Vertex T may be disconnected. Sample Input 4 6 8 1 2 2 3 3 4 4 5 5 1 1 4 1 5 4 6 1 6 Sample Output 4 2 | 37,094 |
Score : 300 points Problem Statement Snuke has N dogs and M monkeys. He wants them to line up in a row. As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys. How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that). Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished. Constraints 1 †N,M †10^5 Input Input is given from Standard Input in the following format: N M Output Print the number of possible arrangements, modulo 10^9+7 . Sample Input 1 2 2 Sample Output 1 8 We will denote the dogs by A and B , and the monkeys by C and D . There are eight possible arrangements: ACBD , ADBC , BCAD , BDAC , CADB , CBDA , DACB and DBCA . Sample Input 2 3 2 Sample Output 2 12 Sample Input 3 1 8 Sample Output 3 0 Sample Input 4 100000 100000 Sample Output 4 530123477 | 37,095 |
Problem F: Bouldering Bouldering is a style of rock climbing. Boulderers are to climb up the rock with bare hands without supporting ropes. Your friend supposed that it should be interesting and exciting, so he decided to come to bouldering gymnasium to practice bouldering. Since your friend has not tried bouldering yet, he chose beginnerâs course. However, in the beginnerâs course, he found that some of two stones have too distant space between them, which might result his accidentally failure of grabbing certain stone and falling off to the ground and die! He gradually becomes anxious and wonders whether the course is actually for the beginners. So, he asked you to write the program which simulates the way he climbs up and checks whether he can climb up to the goal successfully. For the sake of convenience, we assume that a boulderer consists of 5 line segments, representing his body, his right arm, his left arm, his right leg, and his left leg. One of his end of the body is connected to his arms on their end points. And the other end of the body is connected to his legs on their end points, too. The maximum length of his body, his arms, and his legs are A , B and C respectively. He climbs up the wall by changing the length of his body parts from 0 to their maximum length, and by twisting them in any angle (in other word, 360 degrees). Refer the following figure representing the possible body arrangements. Figure 2: An example of possible body arrangements. 5 line segments representing his body, arms and legs. The length of his body, arms and legs are 8, 3 and 4 respectively. The picture describes his head as a filled circle for better understanding, which has no meaning in this problem. A boulderer climbs up the wall by grabbing at least three different rocks on the wall with his hands and feet. In the initial state, he holds 4 rocks with his hands and feet. Then he changes one of the holding rocks by moving his arms and/or legs. This is counted as one movement. His goal is to grab a rock named âdestination rockâ with one of his body parts. The rocks are considered as points with negligible size. You are to write a program which calculates the minimum number of movements required to grab the destination rock. Input The input data looks like the following lines: n A B C x 1 y 1 x 2 y 2 x 3 y 3 . . . x n y n The first line contains n (5 †n †30), which represents the number of rocks. The second line contains three integers A , B , C (1 †A , B , C †50), which represent the length of body, arms, and legs of the climber respectively. The last n lines describes the location of the rocks. The i -th contains two integers x i and y i (0 †x i , y i †100), representing the x and y -coordinates of the i -th rock. In the initial state, the boulderer is grabbing the 1st rock with his right hand, 2nd with his left hand, 3rd with his right foot, and 4th with left foot. You may assume that the first 4 rocks are close to each other so that he can grab them all in the way described above. The last rock is the destination rock. Output Your program should output the minimum number of movements to reach the destination stone. If it is impossible to grab the destination stone, output -1. You may assume that, if A , B , C would be changed within 0.001, the answer would not change. Following figures represent just an example of how the boulderer climbs up to the destination in minimum number of movements. Note that the minimum number of movements can be obtained, by taking different way of climbing up, shortening the parts, rotating parts etc. Figure 3: An example of minimum movement for sample input 1. Figure 4: An example of minimum movement for sample input 2. Sample Input 1 6 4 3 3 10 17 15 14 10 15 11 12 16 18 15 22 Output for the Sample Input 1 3 Sample Input 2 7 4 2 4 11 18 14 18 10 14 13 14 14 17 17 21 16 26 Output for the Sample Input 2 3 Sample Input 3 6 2 2 4 12 22 13 21 14 15 10 16 16 24 10 35 Output for the Sample Input 3 -1 Sample Input 4 6 2 3 3 11 22 12 20 10 15 11 17 13 23 16 22 Output for the Sample Input 4 -1 | 37,096 |
Problem D: 77377 At the risk of its future, International Cellular Phones Corporation (ICPC) invests its resources in developing new mobile phones, which are planned to be equipped with Web browser, mailer, instant messenger, and many other advanced communication tools. Unless members of ICPC can complete this stiff job, it will eventually lose its market share. You are now requested to help ICPC to develop intriguing text input software for small mobile terminals. As you may know, most phones today have twelve buttons, namely, ten number buttons from " 0 " to " 9 " and two special buttons " * " and " # ". Although the company is very ambitious, it has decided to follow today's standards and conventions. You should not change the standard button layout, and should also pay attention to the following standard button assignment. button letters button letters 2 a, b, c 6 m, n, o 3 d, e, f 7 p, q, r, s 4 g, h, i 8 t, u, v 5 j, k, l 9 w, x, y, z This means that you can only use eight buttons for text input. Most users of current ICPC phones are rushed enough to grudge wasting time on even a single button press. Your text input software should be economical of users' time so that a single button press is suffcient for each character input. In consequence, for instance, your program should accept a sequence of button presses " 77377 " and produce the word " press ". Similarly, it should translate " 77377843288866 " into "press the button". Ummm... It seems impossible to build such text input software since more than one English letter is represented by a digit!. For instance, " 77377 " may represent not only "press" but also any one of 768 (= 4 Ã 4 Ã 3 Ã 4 Ã 4) character strings. However, we have the good news that the new model of ICPC mobile phones has enough memory to keep a dictionary. You may be able to write a program that filters out false words , i.e., strings not listed in the dictionary. Input The input consists of multiple data sets, each of which represents a dictionary and a sequence of button presses in the following format. n word 1 . . . word n sequence n in the first line is a positive integer, representing the number of words in the dictionary. The next n lines, each representing a word in the dictionary, only contain lower case letters from ` a ' to ` z '. The order of words in the dictionary is arbitrary (not necessarily in the lexicographic order). No words occur more than once in the dictionary. The last line, sequence, is the sequence of button presses, and only contains digits from ` 2 ' to ` 9 '. You may assume that a dictionary has at most one hundred words and that the length of each word is between one and fifty, inclusive. You may also assume that the number of input digits in the sequence is between one and three hundred, inclusive. A line containing a zero indicates the end of the input. Output For each data set, your program should print all sequences that can be represented by the input sequence of button presses. Each sequence should be a sequence of words in the dictionary, and should appear in a single line. The order of lines does not matter. Two adjacent words in a line should be separated by a single space character and the last word should be followed by a single period (` . '). Following those output lines, your program should also print a terminating line consisting solely of two hyphens (` -- '). If there are no corresponding sequences of words, your program should only print the terminating line. You may assume that for each data set the number of output lines is at most twenty, excluding the terminating line. Sample Input 5 push press the button bottom 77377843288866 4 i am going go 42646464 3 a b c 333 0 Output for the Sample Input press the button. -- i am going. i am go go i. -- -- | 37,098 |
åé¡ C : Apples å顿 ãããšããã«éã®è
ã«èªä¿¡ããã€çåž«ãããŸããïŒ çåž«ã¯ããæ¥ïŒããŠã£ãªã¢ã ãã«ãšããã¹ã€ã¹äººãïŒæ¯åã®é ã«ããããä¹ããŠé ãããç¢ã§æã¡èœãšãããã©ãŒãã³ã¹ã§æåã«ãªã£ãããšããã話ãèããŸããïŒ ãããèããŠ"èªåã®ã»ãããã£ãšåã!!"ãšæã£ãçåž«ã¯åããŠãã人ã®äžã«ããããä¹ããŠæã¡ã¬ãããã©ãŒãã³ã¹ãèãã€ããŸããïŒ çåž«ã¯åºå Žã« N 人ã®äººãéãïŒããããã®äººã®äžã«ããããä¹ããŸããïŒ i çªç®ã®äººã¯æå» t=0 ã®ãšãïŒåº§æš (x_i, y_i) ã«ããŸãïŒ ããããåäœæéãããé床ãã¯ãã« (u_i, v_i) ã«ãããã£ãŠæ©ããŸãïŒ ããªãã¡ïŒæå» t ⥠0 ã®ãšãïŒ i çªç®ã®äººã¯åº§æš (x_i + t \times u_i , y_i + t \times v_i) ã«ããŸãïŒ ããã§ïŒäººã
ã¯ååå°ããã®ã§ïŒåã座æšã«è€æ°ã®äººããããïŒåã座æšã§ããéã£ããã§ãããšä»®å®ããŸãïŒ çåž«ã¯äººã
ãé©åãããããã«ïŒäžçºã®åŒŸäžžã§ã§ããã ãå€ãã®ããããæã¡èœãšãããšã«ããŸããïŒ ç垫㯠t ⥠0 ã§ãããããªä»»æã®æå»ã«ïŒä»»æã®åº§æšããä»»æã®æ¹åã«åããŠåŒŸäžžãæŸã€ããšãã§ããŸãïŒ æŸããã匟䞞ã¯ç¡éã®éãã§çŽç·è»éã§ç§»åãïŒãããã«åœãã£ãå Žå貫éããŠç§»åããŸãïŒ åŒŸäžžãäžçºã ãæã€ãšãïŒæå€§ã§äœåã®ããããæã¡èœãšãããèšç®ããŠãã ããïŒ å
¥ååœ¢åŒ å
¥åã¯ä»¥äžã®åœ¢åŒã§äžãããã N x_0 y_0 u_0 v_0 ... x_{N-1} y_{N-1} u_{N-1} v_{N-1} åºååœ¢åŒ æã¡èœãšãããããã®æå€§åæ°ã1è¡ã«åºåããïŒ å¶çŽ 1 †N †200 0 †|x_i|, |y_i| †10 0 †|u_i|, |v_i| †3 å
¥åå€ã¯ãã¹ãп޿°ã§ããã å
¥åºåäŸ å
¥åäŸ 1 5 0 0 0 0 1 0 -1 1 -1 0 1 -1 1 1 -1 1 -1 -1 1 -1 åºåäŸ 1 5 æå»ïŒã«ïŒäººãïœè»žäžã«äžŠã¶ã®ã§æå€§ïŒã€ã®ããããæã¡èœãšããïŒ å
¥åäŸ 2 5 0 0 0 0 1 0 1 0 -1 0 -1 0 1 1 1 1 -1 -1 -1 -1 åºåäŸ 2 3 å
¥åäŸ 3 15 -10 9 2 1 2 10 0 -1 -10 -4 0 -3 -2 8 0 -1 0 -10 -1 -2 -8 5 0 -1 -7 -8 -3 1 10 -6 -2 -3 9 -6 1 0 10 -5 3 1 10 1 0 -3 -4 7 0 -1 10 -9 2 2 2 -5 -1 1 9 -10 3 1 åºåäŸ 3 5 | 37,099 |
Score : 100 points Problem Statement You are given three strings A , B and C . Check whether they form a word chain . More formally, determine whether both of the following are true: The last character in A and the initial character in B are the same. The last character in B and the initial character in C are the same. If both are true, print YES . Otherwise, print NO . Constraints A , B and C are all composed of lowercase English letters ( a - z ). 1 †|A|, |B|, |C| †10 , where |A| , |B| and |C| are the lengths of A , B and C , respectively. Input Input is given from Standard Input in the following format: A B C Output Print YES or NO . Sample Input 1 rng gorilla apple Sample Output 1 YES They form a word chain. Sample Input 2 yakiniku unagi sushi Sample Output 2 NO A and B form a word chain, but B and C do not. Sample Input 3 a a a Sample Output 3 YES Sample Input 4 aaaaaaaaab aaaaaaaaaa aaaaaaaaab Sample Output 4 NO | 37,100 |
Exact Arithmetic Let X be a set of all rational numbers and all numbers of form q â r , where q is a non-zero rational number and r is an integer greater than 1. Here r must not have a quadratic number except for 1 as its divisor. Also, let X * be a set of all numbers which can be expressed as a sum of one or more elements in X . A machine Y is a stack-based calculator which operates on the values in X * and has the instructions shown in the table below. push n Pushes an integer specified in the operand onto the stack. add Pops two values x 1 and x 2 from the top of the stack in this order, then pushes ( x 2 + x 1 ). sub Pops two values x 1 and x 2 from the top of the stack in this order, then pushes ( x 2 - x 1 ). mul Pops two values x 1 and x 2 from the top of the stack in this order, then pushes ( x 2 à x 1 ). div Pops two values x 1 and x 2 from the top of the stack in this order, then pushes ( x 2 ÷ x 1 ). x 1 must be a non-zero value in X ( not X * ). sqrt Pops one value x from the stack and pushes the square root of x . x must be a non-negative rational number. disp Pops one value x from the stack, and outputs the string representation of the value x to the display. The representation rules are stated later. stop Terminates calculation. The stack must be empty when this instruction is called. Table 1: Instruction Set for the Machine Y A sufficient number of values must exist in the stack on execution of every instruction. In addition, due to the limitation of the machine Y, no more values can be pushed when the stack already stores as many as 256 values. Also, there exist several restrictions on values to be pushed onto the stack: For rational numbers, neither numerator nor denominator in the irreducible form may exceed 32,768 in its absolute value. For any element in X of the form q â r = ( a / b )â r , | a â r | †32,768 and | b | †32,768. For any element in X * , each term in the sum must satisfy the above conditions. The rules for the string representations of the values (on the machine Y) are as follows: A rational number is represented as either an integer or an irreducible fraction with a denominator greater than 1. A fraction is represented as "< numerator >/< denominator >". A sign symbol - precedes in case of a negative number. A number of the form q â r is represented as "< string representation of q > * sqrt( r )" except for the case with q = ±1, in which the number is represented as "sqrt( r )" ( q = 1) or "-sqrt( r )" ( q = -1). For the sum of two or more elements of X , string representations of all the (non-zero) elements are con- nected using the binary operator +. In this case, all terms with the same rooted number are merged into a single term, and the terms must be shown in the ascending order of its root component. For the purpose of this rule, all rational numbers are regarded to accompany â1. There is exactly one space character before and after each of the binary operator +. No space character appears at any other place. The followings are a few examples of valid string representations: 0 1 -1/10 2*sqrt(2) + 1/2*sqrt(3) + -1/2*sqrt(5) 1/2 + sqrt(10) + -sqrt(30) Your task is to write a program that simulates the machine Y. Input The input is a sequence of instructions. Each line contains a single instruction. You may assume that every instruction is called in a legal way. The instruction stop appears only once, at the end of the entire input. Output Output the strings which the machine Y will display. Write each string in a line. Sample Input push 1 push 2 sqrt div push 1 push 3 sqrt div add disp push 8 sqrt push 3 push 2 sqrt mul add disp stop Output for the Sample Input 1/2*sqrt(2) + 1/3*sqrt(3) 5*sqrt(2) | 37,101 |
Score : 600 points Problem Statement Snuke's town has a subway system, consisting of N stations and M railway lines. The stations are numbered 1 through N . Each line is operated by a company. Each company has an identification number. The i -th ( 1 \leq i \leq M ) line connects station p_i and q_i bidirectionally. There is no intermediate station. This line is operated by company c_i . You can change trains at a station where multiple lines are available. The fare system used in this subway system is a bit strange. When a passenger only uses lines that are operated by the same company, the fare is 1 yen (the currency of Japan). Whenever a passenger changes to a line that is operated by a different company from the current line, the passenger is charged an additional fare of 1 yen. In a case where a passenger who changed from some company A's line to another company's line changes to company A's line again, the additional fare is incurred again. Snuke is now at station 1 and wants to travel to station N by subway. Find the minimum required fare. Constraints 2 \leq N \leq 10^5 0 \leq M \leq 2Ã10^5 1 \leq p_i \leq N (1 \leq i \leq M) 1 \leq q_i \leq N (1 \leq i \leq M) 1 \leq c_i \leq 10^6 (1 \leq i \leq M) p_i \neq q_i (1 \leq i \leq M) Input The input is given from Standard Input in the following format: N M p_1 q_1 c_1 : p_M q_M c_M Output Print the minimum required fare. If it is impossible to get to station N by subway, print -1 instead. Sample Input 1 3 3 1 2 1 2 3 1 3 1 2 Sample Output 1 1 Use company 1 's lines: 1 â 2 â 3 . The fare is 1 yen. Sample Input 2 8 11 1 3 1 1 4 2 2 3 1 2 5 1 3 4 3 3 6 3 3 7 3 4 8 4 5 6 1 6 7 5 7 8 5 Sample Output 2 2 First, use company 1 's lines: 1 â 3 â 2 â 5 â 6 . Then, use company 5 's lines: 6 â 7 â 8 . The fare is 2 yen. Sample Input 3 2 0 Sample Output 3 -1 | 37,102 |
Problem I Routing a Marathon Race As a member of the ICPC (Ibaraki Committee of Physical Competitions), you are responsible for planning the route of a marathon event held in the City of Tsukuba. A great number of runners, from beginners to experts, are expected to take part. You have at hand a city map that lists all the street segments suited for the event and all the junctions on them. The race is to start at the junction in front of Tsukuba High, and the goal is at the junction in front of City Hall, both of which are marked on the map. To avoid congestion and confusion of runners of divergent skills, the route should not visit the same junction twice. Consequently, although the street segments can be used in either direction, they can be included at most once in the route. As the main objective of the event is in recreation and health promotion of citizens, time records are not important and the route distance can be arbitrarily decided. A number of personnel have to be stationed at every junction on the route. Junctions adjacent to them, i.e., junctions connected directly by a street segment to the junctions on the route, also need personnel staffing to keep casual traffic from interfering the race. The same number of personnel is required when a junction is on the route and when it is adjacent to one, but different junctions require different numbers of personnel depending on their sizes and shapes, which are also indicated on the map. The municipal authorities are eager in reducing the costs including the personnel expense for events of this kind. Your task is to write a program that plans a route with the minimum possible number of personnel required and outputs that number. Input The input consists of a single test case representing a summary city map, formatted as follows. $n$ $m$ $c_1$ ... $c_n$ $i_1$ $j_1$ ... $i_m$ $j_m$ The first line of a test case has two positive integers, $n$ and $m$. Here, $n$ indicates the number of junctions in the map $(2 \leq n \leq 40)$, and $m$ is the number of street segments connecting adjacent junctions. Junctions are identified by integers 1 through $n$. Then comes $n$ lines indicating numbers of personnel required. The $k$-th line of which, an integer $c_k$ $(1 \leq c_k \leq 100)$, is the number of personnel required for the junction $k$. The remaining $m$ lines list street segments between junctions. Each of these lines has two integers $i_k$ and $j_k$, representing a segment connecting junctions $i_k$ and $j_k$ $(i_k \ne j_k)$. There is at most one street segment connecting the same pair of junctions. The race starts at junction 1 and the goal is at junction $n$. It is guaranteed that there is at least one route connecting the start and the goal junctions. Output Output an integer indicating the minimum possible number of personnel required. Figure I.1. The Lowest-Cost Route for Sample Input 1 Figure I.1 shows the lowest-cost route for Sample Input 1. The arrows indicate the route and the circles painted gray are junctions requiring personnel assignment. The minimum number of required personnel is 17 in this case. Sample Input 1 6 6 3 1 9 4 3 6 1 2 1 4 2 6 5 4 6 5 3 2 Sample Output 1 17 | 37,103 |
Problem Statement Let b_i(x) be the i -th least significant bit of x , i.e. the i -th least significant digit of x in base 2 ( i \geq 1 ). For example, since 6 = (110)_2 , b_1(6) = 0 , b_2(6) = 1 , b_3(6) = 1 , b_4(6) = 0 , b_5(6) = 0 , and so on. Let A and B be integers that satisfy 1 \leq A \leq B \leq 10^{18} , and k_i be the number of integers x such that A \leq x \leq B and b_i(x) = 1 . Your task is to write a program that determines A and B for a given \{k_i\} . Input The input consists of multiple datasets. The number of datasets is no more than 100,000. Each dataset has the following format: n k_1 k_2 ... k_n The first line of each dataset contains an integer n ( 1 \leq n \leq 64 ). Then n lines follow, each of which contains k_i ( 0 \leq k_i \leq 2^{63} - 1 ). For all i > n , k_i = 0 . The input is terminated by n = 0 . Your program must not produce output for it. Output For each dataset, print one line. If A and B can be uniquely determined, output A and B . Separate the numbers by a single space. If there exists more than one possible pair of A and B , output Many (without quotes). Otherwise, i.e. if there exists no possible pair, output None (without quotes). Sample Input 3 2 2 1 49 95351238128934 95351238128934 95351238128932 95351238128936 95351238128936 95351238128936 95351238128960 95351238128900 95351238128896 95351238129096 95351238128772 95351238129096 95351238129096 95351238126156 95351238131712 95351238131712 95351238149576 95351238093388 95351238084040 95351237962316 95351238295552 95351237911684 95351237911684 95351235149824 95351233717380 95351249496652 95351249496652 95351226761216 95351226761216 95351082722436 95351082722436 95352054803020 95352156464260 95348273971200 95348273971200 95354202286668 95356451431556 95356451431556 95346024826312 95356451431556 95356451431556 94557999988736 94256939803780 94256939803780 102741546035788 87649443431880 87649443431880 140737488355328 32684288648324 64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 11 0 0 1 1 1 0 1 1 1 1 1 63 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 4 1 1 1 1 0 Output for the Sample Input 1 4 123456789101112 314159265358979 None 2012 2012 None Many | 37,104 |
Score : 1600 points Problem Statement Yui loves shopping. She lives in Yamaboshi City and there is a train service in the city. The city can be modelled as a very long number line. Yui's house is at coordinate 0 . There are N shopping centres in the city, located at coordinates x_{1}, x_{2}, ..., x_{N} respectively. There are N + 2 train stations, one located at coordinate 0 , one located at coordinate L , and one located at each shopping centre. At time 0 , the train departs from position 0 to the positive direction. The train travels at a constant speed of 1 unit per second. At time L , the train will reach the last station, the station at coordinate L . The train immediately moves in the opposite direction at the same speed. At time 2L , the train will reach the station at coordinate 0 and it immediately moves in the opposite direction again. The process repeats indefinitely. When the train arrives at a station where Yui is located, Yui can board or leave the train immediately. At time 0 , Yui is at the station at coordinate 0 . Yui wants to go shopping in all N shopping centres, in any order, and return home after she finishes her shopping. She needs to shop for t_{i} seconds in the shopping centre at coordinate x_{i} . She must finish her shopping in one shopping centre before moving to the next shopping centre. Yui can immediately start shopping when she reaches a station with a shopping centre and she can immediately board the train when she finishes shopping. Yui wants to spend the minimum amount of time to finish her shopping. Can you help her determine the minimum number of seconds required to complete her shopping? Constraints 1 \leq N \leq 300000 1 \leq L \leq 10^{9} 0 < x_{1} < x_{2} < ... < x_{N} < L 1 \leq t_{i} \leq 10^{9} All values in the input are integers. Partial Score 1000 points will be awarded for passing the testset satisfying 1 \leq N \leq 3000 . Input Input is given from Standard Input in the following format: N L x_{1} x_{2} ... x_{N} t_{1} t_{2} ... t_{N} Output Print the minimum time (in seconds) required for Yui to finish shopping at all N shopping centres and return home. Sample Input 1 2 10 5 8 10 4 Sample Output 1 40 Here's one possible way for Yui to finish her shopping : Travel to the station at coordinate 8 with the train. She arrives at coordinate 8 at time 8 . Shop in the shopping centre at coordinate 8 . She finishes her shopping at time 12 . The train arrives at coordinate 8 at time 12 . She boards the train which is currently moving in the negative direction. She arrives at coordinate 5 at time 15 . She finishes her shopping at time 25 . The train arrives at coordinate 5 at time 25 . She boards the train which is currently moving in the positive direction. She arrives at coordinate L = 10 at time 30 . The train starts moving in the negative direction immediately. She arrives at coordinate 0 at time 40 , ending the trip. Sample Input 2 2 10 5 8 10 5 Sample Output 2 60 Sample Input 3 5 100 10 19 28 47 68 200 200 200 200 200 Sample Output 3 1200 Sample Input 4 8 1000000000 2018 123456 1719128 1929183 9129198 10100101 77777777 120182018 99999999 1000000000 1000000000 11291341 1 200 1 123812831 Sample Output 4 14000000000 Beware of overflow issues. | 37,105 |
ãã³ãžã§ã³ïŒ ããªãã¯æåãªåéºå®¶ã§ããããã§ã«ïŒã€ã®ãã³ãžã§ã³ãå¶èŠãããããªãã¯ããã€ãã®éè·¯ãšå®ç©åº«ãèšãããæ°ããªãã³ãžã§ã³ã®å°å³ãå
¥æãããå°å³ã«ã¯ããããã®å®ç©åº«ã«ãã財å®ã®äŸ¡å€ãæžãããŠããã ããªãã¯ãä»»æã®å®ç©åº«ãããã³ãžã§ã³ã«äŸµå
¥ããä»»æã®å®ç©åº«ãããã³ãžã§ã³ãè±åºããããšãã§ããã䟵å
¥ããè±åºãŸã§ã®éã«ãéè·¯ãéã£ãŠå®ç©åº«ã®éãäœåºŠãç§»åããŠã蚪ããå®ç©åº«ã®è²¡å®ãæã«å
¥ããããšãã§ãããå°å³ã«ããã°ãåéè·¯ã¯åæ¹åã«éãããšãã§ããã©ã®å®ç©åº«ããã©ã®å®ç©åº«ã«ãïŒæ¬ä»¥äžã®éè·¯ãçµç±ããŠãã©ãã€ãããšãã§ãããããããéè·¯ã¯äžåºŠéããšäºåºŠç®ä»¥éã¯äžåºŠç®ãšåãåãã«ããéãããšãã§ããªããªããå®ç©åº«ã®è²¡å®ã¯ããããæåã«èšªãããšãã ãæã«å
¥ããããšãã§ããããã®ãšããæã«ãã財å®ã®äŸ¡å€ã®ç·åãæå€§ã«ãããã å°å³ã®æ
å ±ãäžãããããšãã䟵å
¥ããè±åºãŸã§ã®éã«æã«ãããããšã®ã§ãã財å®ã®äŸ¡å€ã®ç·åã®æå€§å€ãæ±ããããã°ã©ã ãäœæããããã ããå®ç©åº«ã«ã¯1ããNãŸã§ã®çªå·ãå²ãåœãŠãããŠãããã®ãšããã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã $N$ $M$ $v_1$ $v_2$ : $v_N$ $s_1$ $t_1$ $s_2$ $t_2$ : $s_M$ $t_M$ ïŒè¡ç®ã«å®ç©åº«ã®æ°$N$ ($2 \leq N \leq 10^5$)ãšéè·¯ã®æ°$M$ ($1 \leq M \leq 2 \times 10^5$)ãäžãããããç¶ã$N$è¡ã«ã$i$çªç®ã®å®ç©åº«ã«çœ®ãããŠãã財å®ã®äŸ¡å€$v_i$ ($1 \leq v_i \leq 1000$)ãäžãããããç¶ã$M$è¡ã«ãããããã®éè·¯ã®äž¡ç«¯ã«æ¥ç¶ãããŠããå®ç©åº«ã®çªå·$s_i$,$t_i$ ($1 \leq s_i,t_i \leq N, s_i \ne t_i$)ãäžããããããã ããåãå®ç©åº«å士ãã€ãªãéè·¯ã¯ïŒåºŠä»¥äžäžããããªãã åºå åŸãããšãã§ãã財å®ã®äŸ¡å€ã®ç·åã®æå€§å€ãïŒè¡ã«åºåããã å
¥åºåäŸ å
¥åäŸ 5 4 2 1 3 6 4 1 2 2 3 2 4 4 5 åºåäŸ 14 | 37,106 |
ã¢ãã£ã³æå· ç°¡åãªæå·æ³ã®äžã€ã«ãã¢ãã£ã³æå·ãšãããã®ããããŸãããŸããã¢ã«ãã¡ããã aãz ã a = 0, b = 1, c = 2,..., x = 23, y = 24, z = 25 ãš 0ã25 ã®æ°åã«çœ®ãæããŸãããããŠã以äžã®åŒã§ãåæã®ã¢ã«ãã¡ãããã眮æããŸãã $F(\gamma) = (\alpha \cdot \gamma + \beta)$ mod $26$ ãã ããmod 26 㯠26 ã§å²ã£ãäœãã衚ããŸããäŸãã°ã$\alpha = 3, \beta = 2$ ã®ãšããã¢ã«ãã¡ãããã® 'a' (=0) ã¯ã$F(0) = (3 \cdot 0 + 2)$ mod $26 = 2$ ã§ 'c' ã«ãã¢ã«ãã¡ãããã® 'n' (=13) 㯠$F(13) = (3 \cdot 13 + 2)$ mod $26 = 15$ ã§ 'p' ã«çœ®æãããŸãã ãã®ãšãã$\gamma$ ã«å¯Ÿãã $F(\gamma)$ ãå¿
ã 1 察 1 ã§å¯Ÿå¿ä»ããããããã«ã$\alpha$ ãš $\beta$ ã¯æ
éã«éžã°ããŠãããã®ãšããŸãïŒ$\alpha$ ãš 26 ãäºãã«çŽ ã§ããããšãæ¡ä»¶ïŒã$\alpha = 4, \beta = 7$ ã®ãšãã®ããã«ã$F('a') = 7, F('n') = 7$ ãšã'a' ã 'n' ãåã 'h' ã«çœ®æããããããªããšã¯ãããŸããããŸããã¢ã«ãã¡ããã以å€ã®æåã¯çœ®æãããŸããã æå·åãããæååãå
ã®æç« ã«åŸ©å·ãããã®ãåºåããããã°ã©ã ãäœæããŠãã ãããå
ã®æç« ã«ã¯ãããŒã¯ãŒããšã㊠that this ã®ãããããå¿
ãå«ãŸããŠãããã®ãšããŸãã Input è€æ°ã®ããŒã¿ã»ãããäžããããŸããïŒè¡ç®ã«ããŒã¿ã»ããæ° $n$ ($n \leq 30$) ãäžããããŸããç¶ã㊠$n$ è¡ã®ããŒã¿ãäžããããŸããåããŒã¿ã»ããã«è±å°æåãšç©ºçœãããªã 256 æå以å
ã®æå·åãããæç« ãïŒè¡ã«äžããããŸãã Output åããŒã¿ã»ããã«å¯ŸããŠã埩å·ããå
ã®æç« ãïŒè¡ã«åºåããŠäžããã Sample Input 1 y eazqyp pnop pngtg ye obmpngt xmybp mr lygw Output for the Sample Input i submit that there is another point of view | 37,107 |
Score : 600 points Problem Statement We have N strings of lowercase English letters: S_1, S_2, \cdots, S_N . Takahashi wants to make a string that is a palindrome by choosing one or more of these strings - the same string can be chosen more than once - and concatenating them in some order of his choice. The cost of using the string S_i once is C_i , and the cost of using it multiple times is C_i multiplied by that number of times. Find the minimum total cost needed to choose strings so that Takahashi can make a palindrome. If there is no choice of strings in which he can make a palindrome, print -1 . Constraints 1 \leq N \leq 50 1 \leq |S_i| \leq 20 S_i consists of lowercase English letters. 1 \leq C_i \leq 10^9 Input Input is given from Standard Input in the following format: N S_1 C_1 S_2 C_2 : S_N C_N Output Print the minimum total cost needed to choose strings so that Takahashi can make a palindrome, or -1 if there is no such choice. Sample Input 1 3 ba 3 abc 4 cbaa 5 Sample Output 1 7 We have ba , abc , and cbaa . For example, we can use ba once and abc once for a cost of 7 , then concatenate them in the order abc , ba to make a palindrome. Also, we can use abc once and cbaa once for a cost of 9 , then concatenate them in the order cbaa , abc to make a palindrome. We cannot make a palindrome for a cost less than 7 , so we should print 7 . Sample Input 2 2 abcab 5 cba 3 Sample Output 2 11 We can choose abcab once and cba twice, then concatenate them in the order abcab , cba , cba to make a palindrome for a cost of 11 . Sample Input 3 4 ab 5 cba 3 a 12 ab 10 Sample Output 3 8 We can choose a once, which is already a palindrome, but it is cheaper to concatenate ab and cba . Sample Input 4 2 abc 1 ab 2 Sample Output 4 -1 We cannot make a palindrome, so we should print -1 . | 37,108 |
Score : 200 points Problem Statement Given are 1 -digit positive integers a and b . Consider these two strings: the concatenation of b copies of the digit a , and the concatenation of a copies of the digit b . Which of these is lexicographically smaller? Constraints 1 \leq a \leq 9 1 \leq b \leq 9 a and b are integers. Input Input is given from Standard Input in the following format: a b Output Print the lexicographically smaller of the two strings. (If the two strings are equal, print one of them.) Sample Input 1 4 3 Sample Output 1 3333 We have two strings 444 and 3333 . Between them, 3333 is the lexicographically smaller. Sample Input 2 7 7 Sample Output 2 7777777 | 37,109 |
Score : 1000 points Problem Statement There are N cities in a two-dimensional plane. The coordinates of the i -th city is (x_i, y_i) . Initially, the amount of water stored in the i -th city is a_i liters. Snuke can carry any amount of water from a city to another city. However, water leaks out a bit while he carries it. If he carries l liters of water from the s -th city to the t -th city, only max(l-d_{s,t}, 0) liters of water remains when he arrives at the destination. Here d_{s,t} denotes the (Euclidean) distance between the s -th city and the t -th city. He can perform arbitrary number of operations of this type. Snuke wants to maximize the minimum amount of water among the N cities. Find the maximum X such that he can distribute at least X liters of water to each city. Constraints 1 †N †15 0 †x_i, y_i, a_i †10^9 All values in the input are integers. No two cities are at the same position. Input The input is given from Standard Input in the following format: N x_1 y_1 a_1 : x_N y_N a_N Output Print the maximum of the minimum amount of water among the N cities. The absolute error or the relative error must be at most 10^{-9} . Sample Input 1 3 0 0 10 2 0 5 0 5 8 Sample Output 1 6.500000000000 The optimal solution is to carry 3.5 liters of water from the 1st city to the 2nd city. After the operation, both the 1st and the 2nd cities will have 6.5 liters of water, and the 3rd city will have 8 liters of water. Sample Input 2 15 335279264 849598327 822889311 446755913 526239859 548830120 181424399 715477619 342858071 625711486 448565595 480845266 647639160 467825612 449656269 160714711 336869678 545923679 61020590 573085537 816372580 626006012 389312924 135599877 547865075 511429216 605997004 561330066 539239436 921749002 650693494 63219754 786119025 849028504 632532642 655702582 285323416 611583586 211428413 990607689 590857173 393671555 560686330 679513171 501983447 Sample Output 2 434666178.237122833729 | 37,110 |
ãããããäœã 倪éåã¯ãåäŸäŒã®å¬ãã§ã¿ããªã§éã¹ãããã«ãããããäœããŸãããã²ãŒã ããããããããããã«ãããµãã ãããšããããã以å€ã®ããããã®ãã¹ã®ããã€ãã«ãïŒã€é²ããããïŒã€æ»ããã®ããã«æç€ºãæžã蟌ãã§ãããŸãããã«ãŒã¬ãããåããŠåºãæ°ã ãé²ã¿ãæ¢ãŸã£ããã¹ã«æç€ºãæžã蟌ãã§ããã°ããã®æç€ºã«åŸã£ãŠç§»åããŸãããã ããæç€ºã«åŸã£ãŠé²ãã å
ã®ãã¹ã®æç€ºã«ã¯åŸããŸããã ã«ãŒã¬ããã¯ïŒããããæ°ãŸã§ã®éã®æ°ãç確çã§åºãããšãã§ãããã®ãšããŸãããŸãããããããã«éãããã倧ããªæ°ãåºããšãããæç€ºã«åŸããšãããããããå
ã«é²ãã§ããŸããšãã¯ãããããã«ç§»åããŸããæç€ºã«åŸã£ãŠæ»ããšãã«ããµãã ããããåã«æ»ã£ãŠããŸããšãã¯ããµãã ããã«æ»ãããšã«ããŸãã ãšããããã«ãŒã¬ãããšãã¹ã®æç€ºã«ãã£ãŠã¯ãããããã«ãã©ãã€ããªãå ŽåãåºãŠããŠããŸããŸããããšãã°ãå³ã®ãããªãããããäœã£ããšããŸããããïŒãšïŒããåºãªãã«ãŒã¬ããã䜿ããšãïŒïŒïŒã®é ã«åºãã°ãããããã«è¡ããŸãããã¯ããã«ïŒãåºãããã®åŸã¯äœãåºãŠãæ°žä¹
ã«ãããããã«ã¯ãã©ãçããŸããã倪éåã¯ããããšã¯ç¥ããã«èª¿åã«ä¹ã£ãŠãã¡ãã¡ã®ãã¹ã«æç€ºãæžã蟌ãã§ããŸããŸããã ããã§ã倪éåã«ä»£ãã£ãŠãã«ãŒã¬ãããšãã¹ã®æç€ºã«ãã£ãŠã¯ããããããã«ãã©ãçããªãå Žåãçãããã©ããå€å®ããããã°ã©ã ãäœæããŠãã ããã å
¥å å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªããå
¥åã®çµããã¯ãŒãïŒã€ã®è¡ã§ç€ºããããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããã max n d 1 d 2 . . . d n ïŒè¡ç®ã«ã«ãŒã¬ãããåºãæ°ã®æå€§å€ max (2 †max †250) ãäžããããïŒè¡ç®ã«ããµãã ãããšããããã以å€ã®ãã¹ã®æ° n (2 †n †250) ãäžãããããç¶ã n è¡ã«åãã¹ã®æç€ºãè¡šãæ° d i (-n †d i †n) ãäžãããããd i ããŒãã®ãšãã¯æç€ºãæžããŠããªãããšããæ£ã®æ°ã®ãšã㯠|d i | é²ãæç€ºããè² ã®æ°ã®ãšã㯠|d i | æ»ãæç€ºã衚ãïŒããã§ã|x| 㯠x ã®çµ¶å¯Ÿå€ã衚ãïŒãå
¥åãããå€ã¯ãã¹ãп޿°ã§ããã ããŒã¿ã»ããã®æ°ã¯ 100 ãè¶
ããªãã åºå åããŒã¿ã»ããããšã«å€å®çµæãïŒè¡ã«åºåãããã«ãŒã¬ãããšãã¹ã®æç€ºã«ãã£ãŠã¯ããããããã«ãã©ãçããªãå Žåãçãããšãã¯ãNGããããã§ãªããã°ãOKããåºåããã å
¥åäŸ 3 3 -2 1 0 2 4 2 0 -1 -2 2 2 -2 -2 0 åºåäŸ OK NG NG | 37,111 |
Problem C: Emacs-like Editor Emacs is a text editor which is widely used by many programmers. The advantage of Emacs is that we can move a cursor without arrow keys and the mice. For example, the cursor can be moved right, left, down, and up by pushing f , b , n , p with the Control Key respectively. In addition, cut-and-paste can be performed without the mouse. Your task is to write a program which simulates key operations in the Emacs-like editor. The program should read a text and print the corresponding edited text. The text consists of several lines and each line consists of zero or more alphabets and space characters. A line, which does not have any character, is a blank line. The editor has a cursor which can point out a character or the end-of-line in the corresponding line. The cursor can also point out the end-of-line in a blank line. In addition, the editor has a buffer which can hold either a string (a sequence of characters) or a linefeed. The editor accepts the following set of commands (If the corresponding line is a blank line, the word "the first character" should be "the end-of-line"): a Move the cursor to the first character of the current line. e Move the cursor to the end-of-line of the current line. p Move the cursor to the first character of the next upper line, if it exists. If there is no line above the current line, move the cursor to the first character of the current line. n Move the cursor to the first character of the next lower line, if it exists. If there is no line below the current line, move the cursor to the first character of the current line. f Move the cursor by one character to the right, unless the cursor points out the end-of-line. If the cursor points out the end-of-line and there is a line below the current line, move the cursor to the first character of the next lower line. Otherwise, do nothing. b Move the cursor by one character to the left, unless the cursor points out the first character. If the cursor points out the first character and there is a line above the current line, move the cursor to the end-of-line of the next upper line. Otherwise, do nothing. d If the cursor points out a character, delete the character (Characters and end-of-line next to the deleted character are shifted to the left). If the cursor points out the end-of-line and there is a line below, the next lower line is appended to the end-of-line of the current line (Lines below the current line are shifted to the upper). Otherwise, do nothing. k If the cursor points out the end-of-line and there is a line below the current line, perform the command d mentioned above, and record a linefeed on the buffer. If the cursor does not point out the end-of-line, cut characters between the cursor (inclusive) and the end-of-line, and record them on the buffer. After this operation, the cursor indicates the end-of-line of the current line. y If the buffer is empty, do nothing. If the buffer is holding a linefeed, insert the linefeed at the cursor. The cursor moves to the first character of the new line. If the buffer is holding characters, insert the characters at the cursor. The cursor moves to the character or end-of-line which is originally pointed by the cursor. The cursor position just after reading the text is the beginning of the first line, and the initial buffer is empty. Input The input consists of only one data-set which includes two parts. The first part gives a text consisting of several lines. The end of the text is indicated by a line (without quotes): "END_OF_TEXT" This line should not be included in the text. Next part gives a series of commands. Each command is given in a line. The end of the commands is indicated by a character ' - '. Output For the input text, print the text edited by the commands. Constraints The number of lines in the text given as input †10 The number of characters in a line given as input †20 The number of commands †300 The maximum possible number of lines in the text during operations †100 The maximum possible number of characters in a line during operations †1000 Sample Input hyo ni END_OF_TEXT f d f f k p p e y a k y y n y - Output for the Sample Input honihoni honi | 37,112 |
K: AOR ã€ã«ã¡ããã®æçžŸ åé¡ AOR ã€ã«ã¡ãã㯠$N$ åã®ã¬ããŒãã®ç¹æ°ã®ã¿ã§æçžŸã決ãŸãææ¥ãåããŠããã AOR ã€ã«ã¡ããã¯åãææ¥ãåããŠããåéã $M$ 人ããŠãèªåãèŠæãªããŒãã®ã¬ããŒãã¯ããã®ããŒããåŸæãªåéã®ã¬ããŒããåãããšã§ããã®åéãšåãç¹æ°ãåãããšãã§ããã ãã ããä»äººã®ã¬ããŒããåããŠããããšãå
çã«æ°ä»ãããŠã¯ãããªãã®ã§ã $N$ åã®ãã¡å°ãªããšã $K$ åã¯ä»äººã®ã¬ããŒããåãããèªåã§ã¬ããŒããä»äžããªããŠã¯ãªããªãã ãŸãã AOR ã€ã«ã¡ããã¯åéã«è¿·æããããããªããšæã£ãã®ã§åé $i$ ã«å¯ŸããŠã¬ããŒããåãã®ã¯ $T_i$ å以äžã«ããããšã«ããã AOR ã€ã«ã¡ãããèªåã§ã¬ããŒããä»äžãããšãã®ç¹æ°ãšãåéãã¬ããŒããä»äžããæã®ç¹æ°ãäžãããããšãã«ã AOR ã€ã«ã¡ãããåãããšã®ã§ããåèšç¹æ°ã®æå€§å€ãçããã å¶çŽ $1 \le N \le 100$ $0 \le M \le 100$ $0 \le K \le N$ $0 \le a_i \le 100$ $0 \le b_{ij} \le 100$ $0 \le T_i \le N$ å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããã $N \ M \ K$ $a_1 \ \cdots \ a_N$ $b_{11} \ \cdots \ b_{1N}$ $\vdots$ $b_{M1} \ \cdots \ b_{MN}$ $T_1 \ \cdots \ T_M$ $a_i$ ã¯AORã€ã«ã¡ããã $i$ çªç®ã®ã¬ããŒããä»äžããæã®ç¹æ°ãã$b_{ij}$ ã¯åé $i$ ã $j$ çªç®ã®ã¬ããŒããä»äžããæã®ç¹æ°ã衚ãã åºå AOR ã€ã«ã¡ãããåãããšã®ã§ããåèšç¹æ°ã®æå€§å€ãåºåããããŸããæ«å°Ÿã«æ¹è¡ãåºåããã ãµã³ãã« å
¥åäŸ 1 3 2 2 50 65 70 80 100 80 90 65 45 1 1 åºåäŸ 1 225 AOR ã€ã«ã¡ãã㯠1 åã ãä»äººã®ã¬ããŒããåãããšãã§ããã®ã§ãåé 2 ã® 1 ã€ãã®ã¬ããŒããåãããšã§ã AOR ã€ã«ã¡ããã¯æé«ç¹æ°ãåãããšãã§ããã å
¥åäŸ 2 3 0 3 0 0 0 åºåäŸ 2 0 AOR ã€ã«ã¡ããã«ã¯åéãããªããããã¬ããŒããåãããšã¯ã§ããªãã | 37,114 |
Score : 100 points Problem Statement There is a tree with N vertices, numbered 1, 2, \ldots, N . For each i ( 1 \leq i \leq N - 1 ), the i -th edge connects Vertex x_i and y_i . Taro has decided to paint each vertex in white or black, so that any black vertex can be reached from any other black vertex by passing through only black vertices. You are given a positive integer M . For each v ( 1 \leq v \leq N ), answer the following question: Assuming that Vertex v has to be black, find the number of ways in which the vertices can be painted, modulo M . Constraints All values in input are integers. 1 \leq N \leq 10^5 2 \leq M \leq 10^9 1 \leq x_i, y_i \leq N The given graph is a tree. Input Input is given from Standard Input in the following format: N M x_1 y_1 x_2 y_2 : x_{N - 1} y_{N - 1} Output Print N lines. The v -th ( 1 \leq v \leq N ) line should contain the answer to the following question: Assuming that Vertex v has to be black, find the number of ways in which the vertices can be painted, modulo M . Sample Input 1 3 100 1 2 2 3 Sample Output 1 3 4 3 There are seven ways to paint the vertices, as shown in the figure below. Among them, there are three ways such that Vertex 1 is black, four ways such that Vertex 2 is black and three ways such that Vertex 3 is black. Sample Input 2 4 100 1 2 1 3 1 4 Sample Output 2 8 5 5 5 Sample Input 3 1 100 Sample Output 3 1 Sample Input 4 10 2 8 5 10 8 6 5 1 5 4 8 2 10 3 6 9 2 1 7 Sample Output 4 0 0 1 1 1 0 1 0 1 1 Be sure to print the answers modulo M . | 37,115 |
Problem J: Blue Forest John is playing a famous console game named 'Tales of Algorithmers.' Now he is facing the last dungeon called 'Blue Forest.' To find out the fastest path to run through the very complicated dungeon, he tried to draw up the dungeon map. The dungeon consists of several floors. Each floor can be described as a connected simple plane graph. Vertices of the graph are identified by X-Y coordinate, and the length of an edge is calculated by Euclidean distance. A vertex may be equipped with a one-way warp gate. If John chooses to use the gate, it brings John to another vertex in a possibly different floor. The distance between a warp gate and its destination is considered as 0. One vertex has at most one warp gate, though some vertices might be the destination of multiple warp gates. He believed he made one map for each floor, however after drawing maps of all the floors, he noticed that he might have made a few mistakes. He might have drawn the same floor several times, and might have forgotten to mark some warp gates in the maps. However, he was sure he marked all warp gates at least once. So if the maps of same floor are unified to one map, all the warp gates must be described there. Luckily there are no floors which have the same shape as the other floors, so if two (or more) maps can be unified, they must be the maps of the same floor. Also, there is no floor which is circular symmetric (e.g. a regular triangle and a square). Map A and map B can be unified if map B can be transformed to map A using only rotation and parallel translation. Since some of the warp gates on maps might be missing, you should not consider the existence of warp gates when checking unification. If it is possible to unify map A and map B, a vertex on map A and the corresponding vertex on map B are considered as 'identical' vertices. In other words, you should treat warp gates on map B as those on map A where the warp gates are located on the corresponding vertices on map A. Destinations of warp gates should be treated similarly. After that you can forget map B. It is guaranteed that if both map A and map B have warp gates which are on the identical vertices, the destinations of them are also identical. Remember, your task is to find the shortest path from the entrance to the exit of the dungeon, using the unified maps. Input The input consists of multiple datasets. Each dataset is in the following format. n component 1 component 2 ... component n sl sn dl dn n is a positive integer indicating the number of maps. component i describes the i -th map in the following format. A x 1 y 1 x 2 y 2 ... x A y A B s 1 d 1 s 2 d 2 ... s B d B C sn 1 dl 1 dn 1 sn 2 dl 2 dn 2 ... sn C dl C dn C A denotes the number of vertices in the map. Each of the following A lines contains two integers x i and y i representing the coordinates of the i -th vertex in the 2-dimensional plane. B denotes the number of the edges connecting the vertices in the map. Each of the following B lines contains two integers representing the start and the end vertex of each edge. Vertices on the same map are numbered from 1. C denotes the number of warp gates. Each of the following C lines has three integers describing a warp gate. The first integer is the vertex where the warp gate is located. The second and the third integer are the indices of the map and the vertex representing the destination of the warp gate, respectively. Similarly to vertices, maps are also numbered from 1. After the description of all maps, two lines follow. The rst line contains two integers sl and dl , meaning that the entrance of the dungeon is located in the sl -th map, at the vertex dl . The last line has two integers sn and dn , similarly describing the location of the exit. The values in each dataset satisfy the following conditions: 1 †n †50, 3 †A †20, A - 1 †B †A ( A - 1)/2, 0 †C †A , and -10,000 †x i , y i †10,000. Output For each dataset, print the distance of the shortest path from the entrance to the exit. The output should not contain an absolute error greater than 10 -1 . If there is no route, print -1. Sample Input 2 5 0 0 10 0 20 0 30 0 30 10 4 1 2 2 3 3 4 4 5 2 1 2 4 3 2 2 5 -10 0 0 0 0 -10 0 -20 0 -30 4 1 2 2 3 3 4 4 5 1 4 1 3 1 1 2 1 4 3 4 3 0 0 5 0 2 1 2 2 3 0 3 0 0 3 4 0 5 2 1 2 1 3 1 2 3 4 4 0 13 0 0 13 0 13 13 4 1 2 1 4 2 3 2 4 0 4 5 12 0 0 -7 17 -12 5 4 1 2 2 3 2 4 4 3 0 1 1 4 1 4 3 0 0 2 0 0 4 2 1 2 1 3 0 3 0 0 -2 0 0 4 2 1 2 1 3 1 1 4 1 3 0 0 1 0 0 2 2 1 2 1 3 1 1 4 1 3 0 0 2 0 0 4 2 1 2 2 3 0 1 1 4 1 0 Output for the Sample Input 10.0000000000 41.3847763109 -1.000000000 | 37,116 |
Problem A: Password 倪éåã¯ãèªåã®ããœã³ã³ãæã£ãŠããŠããã°ã€ã³æã®ãã¹ã¯ãŒããèšå®ããŠãããããããäžæ³šæã«ã倪éåã¯ãã®ãã¹ã¯ãŒããå¿ããŠããŸã£ããããã§ããã¹ã¯ãŒããã¡ã¢ããçŽãããããšãæãåºããçŽãèŠã€ãã倪éåã¯ãããèŠãŠé©ããããªããšçŽã¯åããŠããŠæçããååšããããšããã©ããã«æ±ãããããèªããªããªã£ãŠããã®ã ã倪éåã¯ãã®ã¡ã¢ãåèã«ãã¹ã¯ãŒããæšæž¬ããããšã«ããã Problem äºã€ã®æååA, BãäžãããããæååAã®äžã«æååBãå«ãŸããŠãããã©ãããå€å®ããå«ãŸããŠããå Žåã¯"Yes"ããããã§ãªããã°"No"ãåºåããã æååAã«ã¯ã¢ã«ãã¡ãããã®å€§æåã®ã¿ãå«ãŸããŠãããæååBã«ã¯ã¢ã«ãã¡ãããã®å€§æåã«å ããŠã'_'(åè§ã¢ã³ããŒããŒ)ãå«ãŸããŠãããåè§ã¢ã³ããŒããŒã¯ä»»æã®ïŒæåã衚ãã Input æåå A æåå B Constraints A,Bã®æååã®é·ãã¯ã©ã¡ãã1æå以äž1000æå以äžã§ããã Bã®æååã®é·ããAã®æååã®é·ããè¶
ããããšã¯ãªãã Output "Yes"ãŸãã¯"No"ã1è¡ã§åºåããã Sample Input 1 ABCDE ABC Sample Output 1 Yes Sample Input 2 KUSATSU KSATSU Sample Output 2 No Sample Input 3 ABCABC ACBA_B Sample Output 3 No Sample Input 4 RUPCUAPC __PC Sample Output 4 Yes Sample Input 5 AIZU _A Sample Output 5 No | 37,117 |
Problem I: Tampopo Machine "Today is another day of endless, tedious work to put a tampopo on sashimi..." Yaruo works in a sashimi (sliced raw fish) factory. His job is to put tampopos on sashimi packages everyday. Tired of this menial job, he decided to develop a tampopo machine to do the job instead of him. The tampopo machine has the following properties. Sashimi packages are put on a conveyor belt and move from left to right. The width of a package is $W$ and the interval between two adjacent packages is $D$. The machine has $N$ magic hands placed above the conveyor belt at regular intervals of $M$. These magic hands put tampopos every $T$ seconds. In initial state, the right end of the first package is under the leftmost magic hand. The magic hands start putting a tampopo as soon as he turns on the power of the machine. The conveyor belt moves one unit length per one second. Unfortunately, after building the machine, Yaruo noticed that there exist some packages with no tampopos. Calculate the ratio of packages with no tampopos for him. When a magic hand puts a tampopo on the left or right end of a package, you can assume that the tampopo is on the package. Input The input consists of 5 integers, $W$, $D$, $N$, $M$ and $T$ which are described in the problem statement. ($1 \leq W, D, N, M, T \leq 1,000,000,000$) Output Output the ratio of packages with no tampopos in a line. The absolute error should be less than or equal to $10^{-9}$. Sample Input 1 1 1 1 1 1 Sample Output 1 0.000000000000 Sample Input 2 1 2 3 4 5 Sample Output 2 0.200000000000 Sample Input 3 3 2 2 1 6 Sample Output 3 0.166666666667 | 37,118 |
Problem G: Gather on the Clock There is a self-playing game called Gather on the Clock . At the beginning of a game, a number of cards are placed on a ring. Each card is labeled by a value. In each step of a game, you pick up any one of the cards on the ring and put it on the next one in clockwise order. You will gain the score by the difference of the two values. You should deal with the two cards as one card in the later steps. You repeat this step until only one card is left on the ring, and the score of the game is the sum of the gained scores. Your task is to write a program that calculates the maximum score for the given initial state, which specifies the values of cards and their placements on the ring. The figure shown below is an example, in which the initial state is illustrated on the left, and the subsequent states to the right. The picked cards are 1, 3 and 3, respectively, and the score of this game is 6. Figure 6: An illustrative play of Gather on the Clock Input The input consists of multiple test cases. The first line contains the number of cases. For each case, a line describing a state follows. The line begins with an integer n (2 †n †100), the number of cards on the ring, and then n numbers describing the values of the cards follow. Note that the values are given in clockwise order. You can assume all these numbers are non-negative and do not exceed 100. They are separated by a single space character. Output For each case, output the maximum score in a line. Sample Input 2 4 0 1 2 3 6 1 8 0 3 5 9 Output for the Sample Input 6 34 | 37,119 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.