task stringlengths 0 154k | __index_level_0__ int64 0 39.2k |
|---|---|
Problem D: Trapezoids If you are a computer user, you should have seen pictures drawn with ASCII characters. Such a picture may not look as good as GIF or Postscript pictures, but is much easier to handle. ASCII pictures can easily be drawn using text editors, and can convey graphical information using only text-based media. Program s extracting information from such pictures may be useful. We are interested in simple pictures of trapezoids, consisting only of asterisk('*') characters and blank spaces. A trapezoid (trapezium in the Queen's English) is a four-side polygon where at least one pair of its sides is parallel. Furthermore, the picture in this problem satisfies the following conditions. All the asterisks in the picture belong to sides of some trapezoid. Two sides of a trapezoid are horizontal and the other two are vertical or incline 45 degrees. Every side is more than 2 characters long. Two distinct trapezoids do not share any asterisk characters. Sides of two trapezoids do not touch. That is, asterisks of one trapezoid do not appear in eight neighbors of asterisks of a different trapezoid. For example, the following arrangements never appear. **** | **** | ****** * * | * * *** | * * **** | ******* * | **** **** | *** | **** * * | | * * **** | | **** Some trapezoids may appear inside others. For example, the following is a valid picture. ********* * * * *** * * * * * * ***** * * * ********* Your task is to recognize trapezoids in the picture and to calculate the area of each trapezoid. The area of a trapezoid is the number of characters on or inside its four sides, including the areas of the trapezoids inside it, if any. Input The input contains several descriptions of pictures. Each of then starts with a line containing an integer h (1 †h †1000), where h is the height (number of lines) of the picture. Each line of the picture consists only of asterisk and space characters, and contains less than 80 characters. The lines of the picture do not necessarily have the same length and may contain redundant space characters at the end. After the last picture, and integer zero terminates the input. Output For each picture, your program should produce output lines each containing two integers m and n is this order, which means there are n trapezoids of area m in the picture. output lines for one picture should be in ascending order on m and count all the trapezoids in the picture. Output lines for two pictures should be separated by a line containing ten hyphen ('-') characters. This separator line should not appear before the output for the first picture nor after the output for the last. Sample Input 7 ******** * * * *** * * * * * * *** * * * ******** 9 *** * * ***** ***** * * *** ***** * * * * *** 11 **** ******************* * * ********* * * ****** * * **** * ********* * * *** * * * * * * * *** * * * * **** ******* * * *** *** * * * * * ***** * * * * * * * * * * * *** * * *** * * *** *** * * ********* * * * * * ********************* * * * ***************************** 0 (Spacing between lines in pictures is made narrower for better appearance. Note that a blank line exists as the first line of the second picture.) Output for the Sample Input 9 1 56 1 ---------- 12 2 15 1 ---------- 9 3 12 2 15 2 63 1 105 1 264 1 | 35,800 |
Score : 1000 points Problem Statement There are N towns in Takahashi Kingdom. They are conveniently numbered 1 through N . Takahashi the king is planning to go on a tour of inspection for M days. He will determine a sequence of towns c , and visit town c_i on the i -th day. That is, on the i -th day, he will travel from his current location to town c_i . If he is already at town c_i , he will stay at that town. His location just before the beginning of the tour is town 1 , the capital. The tour ends at town c_M , without getting back to the capital. The problem is that there is no paved road in this kingdom. He decided to resolve this issue by paving the road himself while traveling. When he travels from town a to town b , there will be a newly paved one-way road from town a to town b . Since he cares for his people, he wants the following condition to be satisfied after his tour is over: "it is possible to travel from any town to any other town by traversing roads paved by him". How many sequences of towns c satisfy this condition? Constraints 2âŠNâŠ300 1âŠMâŠ300 Input The input is given from Standard Input in the following format: N M Output Print the number of sequences of towns satisfying the condition, modulo 1000000007 (=10^9+7) . Sample Input 1 3 3 Sample Output 1 2 As shown below, the condition is satisfied only when c = (2,3,1) or c = (3,2,1) . Sequences such as c = (2,3,2) , c = (2,1,3) , c = (1,2,2) do not satisfy the condition. Sample Input 2 150 300 Sample Output 2 734286322 Sample Input 3 300 150 Sample Output 3 0 | 35,801 |
ãžãããïŒ N+1 éšå±ã1åã«äžŠãã æ°ç¯ã®å»ºç©ãããïŒåéšå±ã¯ãã¹ãŠ1人çšã®äœå±
ã§ããïŒçŸåšã©ã®éšå±ã空宀ã ãïŒæ¥æããæ°ãã« N 人ãããã«äœãäºå®ã§ããïŒãããã£ãŠåœŒããæ®ããå§ãããš1宀ã¯ç©ºãéšå±ã«ãªãïŒ ããªãã¯å€§å®¶ãšããŠïŒåœŒãã®å奜ã«åãããéšå±å²ããå€ãææ¡ããããšèããŠããïŒããã§éšå±å²ããšã¯ïŒããããã®äººãã©ã®éšå±ã«äœãã®ããäžãã衚ã§ããïŒäŸãã° N = 3 ã®ãšãïŒã1人ç®ã¯4å·å®€ïŒ2人ç®ã¯1å·å®€ïŒ3人ç®ã¯2å·å®€ããããããäžã€ã®éšå±å²ãã§ããïŒ ãã¡ããïŒãããããã¹ãŠã®éšå±å²ããææ¡ããã°è©±ã¯æ©ããïŒããã§ã¯ææ¡ã®æå³ããªãããïŒå€§å®¶ã®æéãšäœäººã®å奜ãèæ
®ããŠããã€ãå¶çŽãèšããïŒ ãŸãïŒææ¡ãããéšå±å²ãã®äžã€ã«åœŒããäœã¿å§ããŠããïŒãå¥ã®ææ¡ãããéšå±å²ãã®æ¹ã«å€æŽãããããšèšããããããããªãïŒãã®å»ºç©ã¯æ°ç¯ã§ããïŒåœŒãã¯ãŸã 誰ãå
¥å±
ããŠããªãæ°ããéšå±ã奜ã¿ã§ããããšãããã£ãŠããã®ã§ïŒåçŽã«èª°ã1人ã空ãéšå±ãžåŒã£è¶ããããã ãã§ææ¡ãããå¥ã®éšå±å²ãã«å€æŽã§ãããšãã«éããããèµ·ããããïŒããã倧家ãšããŠïŒããããé¢åããšã¯é¿ãããããïŒãã®ãããªå€æŽãèš±ãããªãããïŒææ¡ããéšå±å²ããããŸã調æŽãããïŒ ã€ãŸãïŒææ¡ããéšå±å²ãã®éåã¯æ¬¡ãæºãããªããã°ãªããªãïŒ ãä»»æã®äºã€ã®ç°ãªãææ¡ãããéšå±å²ã A, B ã«å¯ŸããŠïŒéšå±å²ã A ã®ç©ºãéšå±ã«èª°ã1人ãç§»ããŠãéšå±å²ã B ã«ãªããªãã æ¬¡ã«ïŒããããäœã N 人ã«ã¯ããããã¡ããã©1人奜ãŸãã人ãããããšãããã£ãŠããïŒãããã£ãŠïŒææ¡ãããã¹ãŠã®éšå±å²ãã¯ïŒãã¹ãŠã®äººã«å¯ŸããŠå¥œãŸãã人ãé£ã«äœããããªéšå±å²ãã«ããïŒ ãããã®æ¡ä»¶ãæºããéšå±å²ãã®éåã§ïŒæå€§ã®éåã®å€§ããã¯ãããã ãããïŒ 1, 000, 000, 007 ã§å²ã£ãäœããæ±ããŠã»ããïŒ Input å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒ åããŒã¿ã»ããã¯æ¬¡ã®åœ¢åŒã§è¡šãããïŒ N a 1 a 2 ... a N ããŒã¿ã»ããã® 1 è¡ç®ã«ã¯ïŒæ¥æå»ºç©ã«äœã人æ°ãè¡šãæŽæ° N ãäžããããïŒãã㯠2 †N †100, 000 ãæºããïŒ 2è¡ç®ã«ã¯ i çªç®ã®äººã«ãšã£ãŠé£ã®éšå±ã«äœãã§ããããšå¥œãŸãã人ã®çªå· a i ã®æ
å ±ãäžããããïŒããã«ã€ããŠã¯ 1 †a i †N ã〠a i â i ãæºããïŒ ãŸãïŒããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããªãïŒ å
¥åã®çµããã¯ïŒ1åã®ãŒãã ããããªãè¡ã§è¡šãããïŒ Output åããŒã¿ã»ããã«å¯ŸããŠïŒå顿ã«ãããããªïŒåæã«ææ¡ã§ããéšå±å²ãã®æ°ã®æå€§å€ãïŒ 1, 000, 000, 007 ã§å²ã£ãäœãã1è¡ã§åºåããïŒ Sample Input 2 2 1 3 3 1 2 10 2 1 1 1 1 1 1 1 1 1 8 2 1 4 3 3 7 6 6 25 2 3 2 5 4 5 8 7 8 11 10 13 12 15 14 17 16 19 18 21 20 23 22 25 24 10 2 1 4 3 6 5 8 7 10 9 0 Output for Sample Input 2 0 0 144 633544712 11520 | 35,802 |
Score : 100 points Problem Statement How many multiples of d are there among the integers between L and R (inclusive)? Constraints All values in input are integers. 1 \leq L \leq R \leq 100 1 \leq d \leq 100 Input Input is given from Standard Input in the following format: L R d Output Print the number of multiples of d among the integers between L and R (inclusive). Sample Input 1 5 10 2 Sample Output 1 3 Among the integers between 5 and 10 , there are three multiples of 2 : 6 , 8 , and 10 . Sample Input 2 6 20 7 Sample Output 2 2 Among the integers between 6 and 20 , there are two multiples of 7 : 7 and 14 . Sample Input 3 1 100 1 Sample Output 3 100 | 35,803 |
Problem A: ããããããã ããåŠåã®ãã£ã³ãã¹å
ã«ã¯ãå€ãã®ãããäœãã§ããããªã€ãã¯ããããã®ããããããããããšãæ¥èª²ãšããŠããã ããããããéã¯æ°ãŸããã§ããã£ã³ãã¹ã®å€ã«æ£æ©ã«åºãããŠãããããããªãã ãã£ã³ãã¹ã®æ·å°ã¯å蟺ã x 軞ãŸã㯠y 軞ã«å¹³è¡ãªé·æ¹åœ¢ã§ãããéã®éšåãé€ããŠãã§ã³ã¹ã§å²ãŸããŠããããããã¯éããèªç±ã«åºå
¥ãã§ãããããŸãããã§ã³ã¹ãä¹ãè¶ããŠç§»åããããšãããã ããæ¥ããªã€ãã¯ãã£ã³ãã¹å
ã«ãããããã¡ããªãã¹ãå¹³çã«ãããããããã«ããã£ã³ãã¹å
ã«äœå¹ã®ãããããã®ããç¥ããããšèããã ããªãã®ä»äºã¯ã座æšå¹³é¢äžã®ãã£ã³ãã¹ã®äœçœ®ãšããéã®åº§æšãäžãããããšãã«ããã£ã³ãã¹å
ã«ããããã®æ°ãæ±ããããšã§ããã ãã ãããã§ã³ã¹ã®äžãæ©ããŠããããããã¡ããã©éãééäžã®ããããã£ã³ãã¹å
ã«ãããšã¿ãªãã Input å
¥åã®1è¡ç®ã«ã¯ã4ã€ã®æŽæ° X , Y , W , H ããã¹ããŒã¹æåã§åºåãããŠäžããããããããã¯ããããããã£ã³ãã¹ã®å西端㮠x 座æšãåå°ç¹ã® y 座æšããã£ã³ãã¹ã®æ±è¥¿æ¹åã®å¹
ãããã³ãã£ã³ãã¹ã®ååæ¹åã®é·ãã衚ãããããã®å€ã¯ã-10000 <= X , Y <= 10000 ããã³ 0 < W , H <= 10000 ãæºããã å
¥åã®2è¡ç®ã«ã¯ããã®æ° N (0 < N <= 100) ãäžããããã ç¶ã N è¡ã«ã¯ãããããã®ããã«ã€ããŠ1è¡ã«1å¹ãã€ãããã®äœçœ®ã® x , y 座æšãè¡šãæŽæ°ã®çµ (-50000 <= x , y <= 50000) ãäžããããã x è»žã®æ£ã®æ¹åã¯æ±ã y è»žã®æ£ã®æ¹åã¯åã§ãããäžããããæ°å€ã¯ãã¹ãп޿°ã§ããã Output ãã£ã³ãã¹å
ã«ããããã®æ°ãåºåããã Notes on Submission äžèšåœ¢åŒã§è€æ°ã®ããŒã¿ã»ãããäžããããŸããå
¥åããŒã¿ã® 1 è¡ç®ã«ããŒã¿ã»ããã®æ°ãäžããããŸããåããŒã¿ã»ããã«å¯Ÿããåºåãäžèšåœ¢åŒã§é çªã«åºåããããã°ã©ã ãäœæããŠäžããã Sample Input 2 1 3 20 10 4 21 13 1 15 10 10 25 10 1 3 20 10 4 21 13 1 15 10 10 25 10 Output for the Sample Input 2 2 | 35,804 |
西æŠ20XX 幎ïŒåŠæ ¡å¯Ÿæéæ³ç«¶æå€§äŒãéãããŠããïŒå€§äŒãããããïŒæçµç«¶æãæ®ãã®ã¿ãšãªã£ãïŒããªãã¯ãã®ç«¶æã®éžæã®1 人ã§ããïŒ ããªããåºå Žããç«¶æã¯ïŒç©ºéå
ã«é
眮ãããéããªããžã§ããã¹ãŠç Žå£ãããŸã§ã®æéãç«¶ããšãããã®ã§ããïŒéžæã¯ç«¶æçšã®éã®æèŸŒãèš±å¯ãããŠããïŒç©ºéå
ã«ã¯è€æ°ã®éããªããžã§ãšåãæ°ã®èµ€ããªããžã§ïŒãããŠè€æ°ã®é害ç©ãé
眮ãããŠããïŒéããªããžã§ãšèµ€ããªããžã§ã¯1 察1 ã«å¯Ÿå¿ããŠããïŒèµ€ããªããžã§ãé
眮ãããŠãã座æšããéããªããžã§ã«åŒŸãæã€ããšã§éããªããžã§ãç Žå£ããªããã°ãªããªãïŒç©ºéå
ã«é
眮ãããŠããé害ç©ã¯çç¶ã§ããïŒå°ããã€çµæãç°ãªã£ãŠãããïŒéåžžã®åŒŸã§ããã°é害ç©ã«è§ŠãããšåŒŸã¯ãã®å Žã«æ¢ãŸã£ãŠããŸãïŒ ç«¶æã«äœ¿ããã匟ã¯Magic Bullet ãšããç¹æ®ãªåŒŸã§ããïŒãã®åŒŸã¯éåããã蟌ãããšãã§ãïŒåŒŸãé害ç©ã«æ¥è§Šããéã«èªåçã«éåãæ¶è²»ãïŒåŒŸã貫éããéæ³ãçºåããïŒé害ç©ã®çµæã®éãããïŒè²«éããããã«å¿
èŠãªéæ³ããã®çºåã®ããã«æ¶è²»ããéåã®éã¯ç°ãªã£ãŠããïŒãã®ããïŒããé害ç©ã«å¯Ÿããéæ³ãçºåããåŸã§ãã£ãŠãïŒå¥ã®é害ç©ã貫éããããã«ã¯æ°ãã«å¥ã®éæ³ãçºåããå¿
èŠãããïŒãŸãïŒåŒŸãè€æ°ã®é害ç©ã«åæã«æ¥è§Šããå Žåã¯åæã«éæ³ãçºåããïŒåŒŸã«èŸŒããããéåã®éã¯éæ³ã®çºåã®ãã³ã«æžå°ããïŒ é害ç©ã®äœçœ®ã倧ããïŒè²«éããéæ³ã®çºåã«å¿
èŠãªéåã®éã¯ãã§ã«å
¬éãããŠããã®ã«å¯ŸãïŒèµ€ããªããžã§ïŒéããªããžã§ã®äœçœ®ã¯å
¬éãããŠããªãïŒãããïŒéå»ã®åäžç«¶æã®æ
å ±ããïŒããçšåºŠãªããžã§ã®äœçœ®ãäºæ³ããããšãã§ããïŒéåã匟ã«ãããããšã¯éåžžã«äœåãæ¶èããŠããŸãããïŒããªãã¯éåãã§ããã ãç¯çŽããããšèããïŒããã§ïŒèµ€ããªããžã§ãšããã«å¯Ÿå¿ããéããªããžã§ã®äœçœ®ãä»®å®ããŠïŒãã®ãšãã«åŒŸã«ãããã¹ãå¿
èŠãªéåã®æå°éïŒã€ãŸãïŒéããªããžã§ã«å°éããŠããæç¹ã§åŒŸã«æ®ã£ãŠããéåã0 ã«ãªãéåã®éãæ±ãããïŒ Input å
¥åã¯ãã¹ãп޿°ã§ããïŒããããã®æ°ã¯1 ã€ã®ç©ºçœã«ããåºåãããïŒ N Q x 1 y 1 z 1 r 1 l 1 : x N y N z N r N l N sx 1 sy 1 sz 1 dx 1 dy 1 dz 1 : sx Q sy Q sz Q dx Q dy Q dz Q N ã¯é害ç©ã®åæ°ã§ããïŒ Q ã¯ä»®å®ããéããªããžã§ãšèµ€ããªããžã§ã®åº§æšã®çµã®åæ°ã§ããïŒ x i , y i , z i ã¯ãããã i åç®ã®é害ç©ã®äžå¿ã®äœçœ®ã衚ã x 座æšïŒ y 座æšïŒ z 座æšã§ããïŒ r i 㯠i åç®ã®é害ç©ã®ååŸã§ããïŒ l i 㯠i åç®ã®é害ç©ã貫éããããã®éæ³ã§æ¶è²»ããéåã®éã§ããïŒ sx j , sy j , sz j ã¯ãããã j çªç®ã®ä»®å®ã«ãããèµ€ããªããžã§ã®äœçœ®ã衚ã x 座æšïŒ y 座æšïŒ z 座æšã§ããïŒ dx j , dy j , dz j ã¯ãããã j çªç®ã®ä»®å®ã«ãããéããªããžã§ã®äœçœ®ã衚ã x 座æšïŒ y 座æšïŒ z 座æšã§ããïŒ Constraints 0 †N †50 1 †Q †50 -500 †x i , y i , z i †500 1 †r i †1,000 1 †l i †10 16 -500 †sx j , sy j , sz j †500 -500 †dx j , dy j , dz j †500 é害ç©ãä»ã®é害ç©ã«ãã蟌ãã§ããããšã¯ãªã ãªããžã§ã®åº§æšã¯é害ç©ã®å
éšïŒè¡šé¢ã«ã¯ãªã ããããã®ä»®å®ã«ãããŠïŒèµ€ããªããžã§ãšéããªããžã§ã®åº§æšã¯äžèŽããªã Output ãããã1 çµã®èµ€ããªããžã§ãšããã«å¯Ÿå¿ããéããªããžã§ã®äœçœ®ã®ä»®å®ã«ãããŠïŒç©ºéäžã«é害ç©ãšèµ€ããªããžã§ãšéããªããžã§1 察ãšã®ã¿ããããã®ãšããŠïŒåŒŸã«ãããã¹ãéåã®éã1 è¡ã«åºåããïŒåŒŸã¯èµ€ããªããžã§ã®äœçœ®ããéããªããžã§ã®äœçœ®ãŸã§äžçŽç·ã«é£ã¶ãã®ãšãïŒåŒŸã®å€§ããã¯éåžžã«å°ããã®ã§ç¹ãšããŠæ±ãïŒ Sample Input 1 5 1 0 10 0 5 2 0 20 0 5 12 0 30 0 5 22 0 40 0 5 32 0 50 0 5 42 0 0 0 0 60 0 Output for the Sample Input 1 110 Sample Input 2 1 1 10 5 0 5 9 0 0 0 9 12 0 Output for the Sample Input 2 9 Sample Input 3 5 5 -38 -71 -293 75 1 -158 -38 -405 66 1 -236 -303 157 266 1 316 26 411 190 1 207 -312 -27 196 1 -50 292 -375 -401 389 -389 460 278 409 -329 -303 411 215 -220 -200 309 -474 300 261 -494 -87 -300 123 -463 386 378 486 -443 -64 299 Output for the Sample Input 3 0 2 1 3 0 | 35,805 |
Problem F: Atomic Car Race In the year 2020, a race of atomically energized cars will be held. Unlike todayâs car races, fueling is not a concern of racing teams. Cars can run throughout the course without any refueling. Instead, the critical factor is tire (tyre). Teams should carefully plan where to change tires of their cars. The race is a road race having n checkpoints in the course. Their distances from the start are a 1 , a 2 , ... , and a n (in kilometers). The n -th checkpoint is the goal. At the i -th checkpoint ( i < n ), tires of a car can be changed. Of course, a team can choose whether to change or not to change tires at each checkpoint. It takes b seconds to change tires (including overhead for braking and accelerating). There is no time loss at a checkpoint if a team chooses not to change tires. A car cannot run fast for a while after a tire change, because the temperature of tires is lower than the designed optimum. After running long without any tire changes, on the other hand, a car cannot run fast because worn tires cannot grip the road surface well. The time to run an interval of one kilometer from x to x + 1 is given by the following expression (in seconds). Here x is a nonnegative integer denoting the distance (in kilometers) from the latest checkpoint where tires are changed (or the start). r , v , e and f are given constants. 1/( v - e à ( x - r )) (if x ⥠r ) 1/( v - f à ( r - x )) (if x < r ) Your mission is to write a program to determine the best strategy of tire changes which minimizes the total time to the goal. Input The input consists of multiple datasets each corresponding to a race situation. The format of a dataset is as follows. n a 1 a 2 . . . a n b r v e f The meaning of each of the input items is given in the problem statement. If an input line contains two or more input items, they are separated by a space. n is a positive integer not exceeding 100. Each of a 1 , a 2 , ... , and a n is a positive integer satisfying 0 < a 1 < a 2 < . . . < a n †10000. b is a positive decimal fraction not exceeding 100.0. r is a nonnegative integer satisfying 0 †r †a n - 1. Each of v , e and f is a positive decimal fraction. You can assume that v - e à ( a n - 1 - r ) ⥠0.01 and v - f à r ⥠0.01. The end of the input is indicated by a line with a single zero. Output For each dataset in the input, one line containing a decimal fraction should be output. The decimal fraction should give the elapsed time at the goal (in seconds) when the best strategy is taken. An output line should not contain extra characters such as spaces. The answer should not have an error greater than 0.001. You may output any number of digits after the decimal point, provided that the above accuracy condition is satisfied. Sample Input 2 2 3 1.0 1 1.0 0.1 0.3 5 5 10 15 20 25 0.15 1 1.0 0.04 0.5 10 1783 3640 3991 4623 5465 5481 6369 6533 6865 8425 4.172 72 59.4705 0.0052834 0.0611224 0 Output for the Sample Input 3.5397 31.9249 168.6682 | 35,806 |
Score : 300 points Problem Statement You are given N positive integers a_1, a_2, ..., a_N . For a non-negative integer m , let f(m) = (m\ mod\ a_1) + (m\ mod\ a_2) + ... + (m\ mod\ a_N) . Here, X\ mod\ Y denotes the remainder of the division of X by Y . Find the maximum value of f . Constraints All values in input are integers. 2 \leq N \leq 3000 2 \leq a_i \leq 10^5 Input Input is given from Standard Input in the following format: N a_1 a_2 ... a_N Output Print the maximum value of f . Sample Input 1 3 3 4 6 Sample Output 1 10 f(11) = (11\ mod\ 3) + (11\ mod\ 4) + (11\ mod\ 6) = 10 is the maximum value of f . Sample Input 2 5 7 46 11 20 11 Sample Output 2 90 Sample Input 3 7 994 518 941 851 647 2 581 Sample Output 3 4527 | 35,807 |
åé¡ 3 ããå·¥å Žã§ã¯ïŒåå¶æ¥æãã補åçç£ã®æ³šæãåããŠããïŒ åæ¥ã®æ³šæããŸãšããŠïŒå補åã®çç£åèšãæ±ãããïŒ å
¥åãã¡ã€ã«ã®ïŒè¡ç®ã«ã¯æ³šæããŒã¿ã®æ° n ãæžããŠããïŒ ç¶ã n è¡ã«ã¯è£œååãšæ³šææ°ã空çœã§åºåãããŠæžããŠããïŒ è£œååã¯5æå以å
ã®è±å€§æåã§æžãããŠããïŒ æ³šæããŒã¿ã«ã¯åã補åãå«ãŸããŠããããšãããïŒé åºã¯ãã©ãã©ã§ããïŒ ãã®æ³šæããŒã¿ã®äžã«çŸããåã補åã®æ³šææ°ãåèšãïŒ åºåãã¡ã€ã«ã«è£œååãšåèšã空çœãåºåãæåãšããŠåºåããªããïŒ ãã ãïŒè£œååã«æ¬¡ã®é åºãä»ããŠïŒãã®é ã§åºåããããšïŒ é åºïŒæåã®é·ãã®å°ããé ã«ïŒåãé·ãã®ãšãã¯ïŒåããæ¯ã¹ãŠ æåã«ç°ãªãæåã®ã¢ã«ãã¡ãããé ãšããïŒ å
¥åããŒã¿ã«ãããè£œåæ°ïŒæ³šææ°ãšãã®åèšã®ã©ãã10 6 以äžã§ããïŒ åºåãã¡ã€ã«ã«ãããŠã¯ïŒ åºåã®æåŸã®è¡ã«ãæ¹è¡ã³ãŒããå
¥ããããšïŒ å
¥åºåäŸ å
¥åäŸ1 5 A 20 B 20 A 20 AB 10 Z 10 åºåäŸ1 A 40 B 20 Z 10 AB 10 å
¥åäŸ2 5 AAA 20 ABA 20 AAA 20 AAB 20 AAA 20 åºåäŸ2 AAA 60 AAB 20 ABA 20 å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã | 35,808 |
çŽ æ°ã®æ§è³ª 4 ã§å²ããš 3 ããŸãçŽ æ° n (11ã19ã23 ãªã©) ã«ã¯ãé¢çœãæ§è³ªããããŸãã1 ä»¥äž n æªæºã®èªç¶æ° (1, 2,... , n - 1) ã 2 ä¹ãããã®ã n ã§å²ã£ãããŸããèšç®ããçµæã䞊ã¹ããšãåãæ°ã«ãªããã®ããããããäºãã«ç°ãªã£ãæ°ã®åæ°ã¯ã( n - 1)/2 ã«ãªããŸãã ãã®æ§ã«ããŠåŸãããæ°ã®éåã«ã¯ãç¹å¥ãªæ§è³ªããããŸããåŸãããæ°ã®éåãããäºãã«ç°ãªã 2 〠a ãš b ãéžãã§ãã®å·®ãèšç®ããŸããå·®ãè² ã«ãªã£ããšãã¯ããã®å·®ã« n ãè¶³ããŸããããã«çµæã ( n - 1)/2 ãã倧ãããšãã¯ããã®å·®ã n ããåŒããŸãã äŸãã°ã n = 11 ã®ãšã 1 ãš 9 ã®å·®ã¯ã 1 â 9 = â8 â â8 + n = â8 + 11 = 3 ã«ãªããŸãã9 ãš 1 ã®å·®ã 9 â1 = 8 â n â 8 = 11 â 8 = 3 ã§ãåãå€ 3 ã«ãªããŸãããã®å·®ã¯ãååšäžã« 0, 1, ã»ã»ã», n - 1 ãæžããŠãäºã€ã®æ°åã®éã®çãæ¹ã®å匧ãèãããšãããããããªããŸãã(äžå³åç
§) ããããŠåŸãããæ°ã®ãå·®ãã¯ã1, 2, . . ., ( n - 1)/2 ã®ããããã§ãããåãåæ°åºçŸããŸãã ãäŸã n = 11 ã®æã¯ã以äžã®ããã«ãªããŸãã 1 ãã n -1 ãŸã§ã®æ°ã 2 ä¹ãããã®ã n ã§å²ã£ãäœããèšç®ããŸãã 1 2 = 1 â 1 2 2 = 4 â 4 3 2 = 9 â 9 4 2 = 16 â 5 5 2 = 25 â 3 6 2 = 36 â 3 7 2 = 49 â 5 8 2 = 64 â 9 9 2 = 81 â 4 10 2 = 100 â 1 a , b ã®ãå·®ãã®èšç® 1 ã§åŸããã 1, 3, 4, 5, 9 ã«ã€ããŠç°ãªãæ°å士ã®å·®ãèšç®ããŸãã èšç®çµæãè² ã®å Žåã n = 11 ãå ç®ããŸãã ããã«ãèšç®çµæã ( n -1)/2 = 5 ãã倧ããå Žå n = 11 ããæžç®ããŸãã åºçŸåæ°ãæ±ãã èšç®çµæ 1, 2, 3, 4, 5 ã®åºçŸåæ°ãããããæ°ãäžããŸãã ãããã®èšç®çµæãã 1, 2, 3, 4, 5 ã®åºçŸåæ°ã 4 åã§ããããšãããããŸãããã®æ§è³ªã¯ 4 ã§å²ããš 3 ããŸãçŽ æ°ç¹æã®æ§è³ªã§ãã 4 ã§å²ããš 1 ããŸãçŽ æ°ã§ã¯ãã®ãããªããšã¯ãããŸããããã®ããšã確èªããããã10000 以äžã®å¥æ° n ãå
¥åãšããäŸé¡ã«ãããããªèšç® ( n ã§å²ã£ãããŸãã® 2 ä¹ã®å·®ã®é »åºŠãæ±ãã)ãå®è¡ãããã®åºçŸåæ°ãåºåããããã°ã©ã ãäœæããŠãã ããã Input è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ãããšããŠïŒã€ã®æŽæ° n ( n †10000) ãïŒè¡ã«äžããããŸããå
¥å㯠0 ãïŒã€å«ãè¡ã§ããããŸãã Output åããŒã¿ã»ããã«ã€ããŠãåºçŸé »åºŠã以äžã®åœ¢åŒã§åºåããŠãã ããã å°äœã®å¹³æ¹ã®å·®ã 1 ã§ãã( a, b )ã®åºçŸåæ°(æŽæ°) å°äœã®å¹³æ¹ã®å·®ã 2 ã§ãã( a, b )ã®åºçŸåæ°(æŽæ°) : : å°äœã®å¹³æ¹ã®å·®ã ( n -1)/2 ã§ãã( a, b )ã®åºçŸåæ°(æŽæ°) Sample Input 11 15 0 Output for the Sample Input 4 4 4 4 4 2 2 4 2 4 4 2 | 35,809 |
Set æ°å a_1,a_2,..,a_N ãäžããããŸãã ãã®æ°åã«å€ã¯äœçš®é¡ãããŸããã å
¥å N a_1 a_2...a_N åºå æ°åã®å€ã®çš®é¡æ°ãåºåããã å¶çŽ 1 \leq N \leq 10^5 1 \leq a_i \leq 10^9 å
¥åäŸ 6 8 6 9 1 2 1 åºåäŸ 5 | 35,810 |
é£é åé¡ æ¬¡ã®ãããªã²ãŒã ãããïŒ ãããã£ã©ã¯ã¿ãŒã瞊 1 åã« N å䞊ãã§ããïŒãããã®ãã£ã©ã¯ã¿ãŒã®è²ã¯èµ€ïŒéïŒé»ã®ããããã§ããïŒåæç¶æ
ã§åãè²ã®ãã£ã©ã¯ã¿ãŒã4ã€ä»¥äžé£ç¶ããŠäžŠãã§ããããšã¯ãªãïŒãã¬ãŒã€ãŒã¯ïŒããäœçœ®ã®ãã£ã©ã¯ã¿ãŒãéžã³ä»ã®è²ã«å€æŽããããšãã§ããïŒãã®æäœã«ããåãè²ã®ãã£ã©ã¯ã¿ãŒã4ã€ä»¥äžé£ç¶ããŠäžŠã¶ãšãããã®ãã£ã©ã¯ã¿ãŒã¯æ¶æ»
ããïŒãã£ã©ã¯ã¿ãŒãæ¶æ»
ããããšã«ããæ°ãã«åãè²ã®ãã£ã©ã¯ã¿ãŒã4ã€ä»¥äžé£ç¶ããŠäžŠã¶ãšãããã®ãã£ã©ã¯ã¿ãŒãæ¶æ»
ãïŒåãè²ã®ãã£ã©ã¯ã¿ãŒã4ã€ä»¥äžé£ç¶ããŠäžŠãã§ããç®æããªããªããŸã§ãã®é£éã¯ç¶ãïŒãã®ã²ãŒã ã®ç®çã¯ïŒæ¶æ»
ããªãã§æ®ã£ãŠãããã£ã©ã¯ã¿ãŒæ°ããªãã¹ãå°ãªãããããšã§ããïŒ äŸãã°ïŒäžå³ã®å·Šç«¯ã®ç¶æ
ã§ïŒäžãã6çªç®ã®ãã£ã©ã¯ã¿ãŒã®è²ãé»è²ããéã«å€æŽãããšïŒéã®ãã£ã©ã¯ã¿ãŒã5ã€é£ç¶ããã®ã§æ¶æ»
ãïŒæçµçã«3ã€ã®ãã£ã©ã¯ã¿ãŒãæ¶æ»
ããã«æ®ãïŒ åæç¶æ
ã«ããã N åã®ãã£ã©ã¯ã¿ãŒã®è²ã®äžŠã³ãäžãããããšãïŒ 1ç®æã ããã£ã©ã¯ã¿ãŒã®è²ã倿Žããå Žåã®ïŒæ¶æ»
ããªãã§æ®ã£ãŠãããã£ã©ã¯ã¿ãŒæ°ã®æå°å€ M ãæ±ããããã°ã©ã ãäœæããïŒ å
¥å å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ 1è¡ç®ã¯ãã£ã©ã¯ã¿ãŒæ° N (1 †N †10000) ã ããããªãïŒç¶ã N è¡ã«ã¯ 1, 2, 3 ã®ãããã1ã€ã®æŽæ°ãæžãããŠããïŒ i + 1 è¡ç® (1 †i †N) ã¯åæç¶æ
ã«ãããäžãã i çªç®ã®ãã£ã©ã¯ã¿ãŒã®è²ã衚ãïŒ1 ã¯èµ€ãïŒ2 ã¯éãïŒ3ã¯é»ã衚ãïŒïŒ N ã 0 ã®ãšãå
¥åã®çµäºã瀺ãïŒããŒã¿ã»ããã®æ°ã¯ 5 ãè¶
ããªãïŒ åºå ããŒã¿ã»ããããšã«, æ¶æ»
ããªãã§æ®ã£ãŠãããã£ã©ã¯ã¿ãŒæ°ã®æå°å€ M ãïŒè¡ã«åºåããïŒ å
¥åºåäŸ å
¥åäŸ 12 3 2 1 1 2 3 2 2 2 1 1 3 12 3 2 1 1 2 3 2 1 3 2 1 3 0 åºåäŸ 3 12 äžèšå顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã | 35,811 |
Debt Hell Your friend who lives in undisclosed country is involved in debt. He is borrowing 100,000-yen from a loan shark. The loan shark adds 5% interest of the debt and rounds it to the nearest 1,000 above week by week. Write a program which computes the amount of the debt in n weeks. Input An integer n (0 †n †100) is given in a line. Output Print the amout of the debt in a line. Sample Input 5 Output for the Sample Input 130000 | 35,812 |
Score : 200 points Problem Statement Iroha has a sequence of N strings S_1, S_2, ..., S_N . The length of each string is L . She will concatenate all of the strings in some order, to produce a long string. Among all strings that she can produce in this way, find the lexicographically smallest one. Here, a string s=s_1s_2s_3 ... s_n is lexicographically smaller than another string t=t_1t_2t_3 ... t_m if and only if one of the following holds: There exists an index i(1âŠiâŠmin(n,m)) , such that s_j = t_j for all indices j(1âŠj<i) , and s_i<t_i . s_i = t_i for all integers i(1âŠiâŠmin(n,m)) , and n<m . Constraints 1 ⊠N, L ⊠100 For each i , the length of S_i equals L . For each i , S_i consists of lowercase letters. Input The input is given from Standard Input in the following format: N L S_1 S_2 : S_N Output Print the lexicographically smallest string that Iroha can produce. Sample Input 1 3 3 dxx axx cxx Sample Output 1 axxcxxdxx The following order should be used: axx , cxx , dxx . | 35,813 |
Score : 800 points Problem Statement Given are integers N and X . For each integer k between 0 and X (inclusive), find the answer to the following question, then compute the sum of all those answers, modulo 998244353 . Let us repeat the following operation on the integer k . Operation: if the integer is currently odd, subtract 1 from it and divide it by 2 ; otherwise, divide it by 2 and add 2^{N-1} to it. How many operations need to be performed until k returns to its original value? (The answer is considered to be 0 if k never returns to its original value.) Constraints 1 \leq N \leq 2\times 10^5 0 \leq X < 2^N X is given in binary and has exactly N digits. (In case X has less than N digits, it is given with leading zeroes.) All values in input are integers. Input Input is given from Standard Input in the following format: N X Output Print the sum of the answers to the questions for the integers between 0 and X (inclusive), modulo 998244353 . Sample Input 1 3 111 Sample Output 1 40 For example, for k=3 , the operation changes k as follows: 1,0,4,6,7,3 . Therefore the answer for k=3 is 6 . Sample Input 2 6 110101 Sample Output 2 616 Sample Input 3 30 001110011011011101010111011100 Sample Output 3 549320998 | 35,815 |
Problem D: Land Mark âHey, whatâs up? Itâs already 30 minutes past eleven!â âIâm so sorry, but actually I got lost. I have no idea where I am now at all and I got tired wandering around. Please help!â - Today you came to the metropolis to play with your friend. But she didnât show up at the appointed time. What happened to her? After some uncomfortable minutes, finally you managed to get her on line, and have been just notified that sheâs been lost in the city. You immediately told her not to move, and asked her what are around her to figure out where she is. She told the names of some famous land marks, in the order where she caught in her sight while she made a full turn counterclockwise without moving around. Fortunately, today you have a map of the city. You located all the land marks she answered on the map, but want to know in which district of the city sheâs wandering. Write a program to calculate the area where she can be found, as soon as you can! Input Each input case is given in the format below: N x 1 y 1 ... x N y N l 1 . . . l N An integer N in the first line specifies the number of land marks she named ( N †10). The following N lines specify the x- and y-coordinates of the land marks in the city. Here you modeled the city as an unbounded two- dimensional plane. All coordinate values are integers between 0 and 100, inclusive. The last line of a test case specifies the order in which she found these land marks in a counterclockwise turn. A single line containing zero indicates the end of input. This is not a part of the input and should not be processed. Output Your program should output one line for each test case. The line should contain the case number followed by a single number which represents the area where she can be found. The value should be printed with the fifth digit after the decimal point, and should not contain an absolute error greater than 10 -5 . If there is no possible area found under the given condition, output âNo areaâ in a line, instead of a number. If you cannot bound the area, output âInfinityâ. Sample Input 8 1 0 2 0 3 1 3 2 2 3 1 3 0 2 0 1 1 2 3 4 5 6 7 8 8 1 0 2 0 3 1 3 2 2 3 1 3 0 2 0 1 4 3 2 1 8 7 6 5 4 0 0 1 0 1 1 0 1 1 2 3 4 0 Output for the Sample Input Case 1: 10.00000 Case 2: No area Case 3: Infinity | 35,816 |
D: Statement Coverage / åœä»€ç¶²çŸ
ãããã£ïŒãªããŠã²ã©ãã³ãŒãã ïŒã å€ããœãŒã¹ã³ãŒããéããªããå
茩ãå«ãã§ããïŒ ãŸãé¢åãªä»äºãæŒãä»ãããããã âŠâŠïŒ ãœãŒã¹ã³ãŒãã«ã¯ããŸããããããªã»ã©ããããã® if æã䞊ãã§ããïŒ if æ¡ä»¶æ 1; åœä»€ 1 if æ¡ä»¶æ 2; åœä»€ 2 if æ¡ä»¶æ 3; åœä»€ 3 ... ã©ãããå¶åŸ¡ã®æ§é ã¯ããã»ã©è€éã§ã¯ãªããããïŒ 1 ã€ã®æ¡ä»¶æã«ã¯ïŒå€æ°ãš NOT æŒç®å "~" ïŒãã㊠AND "&" / OR "|" ã® 2 é
æŒç®åãçŸããïŒ å€æ°ã¯çãŸãã¯åœã衚ãïŒå€æ°åã¯1æå以äžã®ã¢ã«ãã¡ãããã§è¡šãããïŒ æŒç®ã®é åºã¯ NOT æŒç®åãåªå
ã ãïŒæ¬åŒ§ã§å
ã«èšç®ããããé åºãå€ããŠãããïŒ å€æ°ã¯ 1 ã€ããã㯠2 ã€ïŒ2 é
æŒç®ã¯é«ã
1 åïŒãã以å€ã¯äœåºŠã§ãçŸããŠè¯ãïŒ ãšããããã³ã³ãã€ã«ã¯éã£ãïŒ ã³ãŒããä¿®æ£ããåã«ãã¹ããæžãå¿
èŠãããïŒ ä»åé ŒãŸããã®ã¯ïŒãã®ã³ãŒãã®ãã¹ãã±ãŒã¹ãæžãäœæ¥ã ïŒ ãã¹ãã±ãŒã¹ã®æ°ã¯ïŒå
šãŠã®åœä»€ã 1 床以äžå®è¡ãããã°ååã§ããïŒ ãã¹ãã±ãŒã¹ã®æ°ãèŠç©ãã£ãŠïŒ 1 ã€ã§æžããããªãåŒãåããããšã«ãããïŒ Input äžããããå
¥åã¯ä»¥äžã®ããã«è¡šãããïŒ N M cond 1 ; cond 2 ; ... cond N ; N ( 1 ⊠N ⊠500 ) è¡ã®æ¡ä»¶æãçŸãïŒæ¡ä»¶æäžã«ã¯ M ( 1 ⊠M ⊠500 ) çš®é¡ã®å€æ°ãååšããïŒ æ¡ä»¶æ cond i ã¯æå€§ 1000 æåã§ããïŒ ãŸãïŒå€æ°åã¯10æåãè¶
ããªãïŒ Output äœæ¥ãåŒãåãããªã acceptïŒæåŠãããªã reject ã 1 è¡åºåããïŒ Sample Input 1 3 4 ~~(~A|B); ~(~C&~D); ~(~A|~~D); Sample Output 1 accept Sample Input 2 2 1 var; ~var; Sample Output 2 reject | 35,817 |
Score : 300 points Problem Statement Given is a string S consisting of lowercase English letters. Find the maximum positive integer K that satisfies the following condition: There exists a partition of S into K non-empty strings S=S_1S_2...S_K such that S_i \neq S_{i+1} ( 1 \leq i \leq K-1 ). Here S_1S_2...S_K represents the concatenation of S_1,S_2,...,S_K in this order. Constraints 1 \leq |S| \leq 2 \times 10^5 S consists of lowercase English letters. Input Input is given from Standard Input in the following format: S Output Print the maximum positive integer K that satisfies the condition. Sample Input 1 aabbaa Sample Output 1 4 We can, for example, divide S into four strings aa , b , ba , and a . Sample Input 2 aaaccacabaababc Sample Output 2 12 | 35,818 |
Problem A: Ginkgo Numbers We will define Ginkgo numbers and multiplication on Ginkgo numbers. A Ginkgo number is a pair < m , n > where m and n are integers. For example, <1, 1>, <-2, 1> and <-3,-1> are Ginkgo numbers. The multiplication on Ginkgo numbers is defined by < m , n > · < x , y > = < mx â ny , my + nx >. For example, <1, 1> · <-2, 1> = <-3,-1>. A Ginkgo number < m , n > is called a divisor of a Ginkgo number < p , q > if there exists a Ginkgo number < x , y > such that < m , n > · < x , y > = < p , q >. For any Ginkgo number < m , n >, Ginkgo numbers <1, 0>, <0, 1>, <-1, 0>, <0,-1>, < m , n >, <- n , m >, <- m ,- n > and < n ,- m > are divisors of < m , n >. If m 2 + n 2 > 1, these Ginkgo numbers are distinct. In other words, any Ginkgo number such that m 2 + n 2 > 1 has at least eight divisors. A Ginkgo number < m , n > is called a prime if m 2 + n 2 > 1 and it has exactly eight divisors. Your mission is to check whether a given Ginkgo number is a prime or not. The following two facts might be useful to check whether a Ginkgo number is a divisor of another Ginkgo number. Suppose m 2 + n 2 > 0. Then, < m , n > is a divisor of < p , q > if and only if the integer m 2 + n 2 is a common divisor of mp + nq and mq â np . If < m , n > · < x , y > = < p , q >, then ( m 2 + n 2 )( x 2 + y 2 ) = p 2 + q 2 . Input The first line of the input contains a single integer, which is the number of datasets. The rest of the input is a sequence of datasets. Each dataset is a line containing two integers m and n , separated by a space. They designate the Ginkgo number < m , n >. You can assume 1 < m 2 + n 2 < 20000. Output For each dataset, output a character ' P ' in a line if the Ginkgo number is a prime. Output a character ' C ' in a line otherwise. Sample Input 8 10 0 0 2 -3 0 4 2 0 -13 -4 1 -2 -1 3 -1 Output for the Sample Input C C P C C P P C | 35,819 |
Problem I: Cousin's Aunt Sarah is a girl who likes reading books. One day, she wondered about the relationship of a family in a mystery novel. The story said, B is Aâs fatherâs brotherâs son, and C is Bâs aunt. Then she asked herself, âSo how many degrees of kinship are there between A and C?â There are two possible relationships between B and C, that is, C is either Bâs fatherâs sister or Bâs motherâs sister in the story. If C is Bâs fatherâs sister, C is in the third degree of kinship to A (Aâs fatherâs sister). On the other hand, if C is Bâs motherâs sister, C is in the fifth degree of kinship to A (Aâs fatherâs brotherâs wifeâs sister). You are a friend of Sarahâs and good at programming. You can help her by writing a general program to calculate the maximum and minimum degrees of kinship between A and C under given relationship. The relationship of A and C is represented by a sequence of the following basic relations: father, mother, son, daughter, husband, wife, brother, sister, grandfather, grandmother, grandson, granddaughter, uncle, aunt, nephew, and niece. Here are some descriptions about these relations: X âs brother is equivalent to X âs fatherâs or motherâs son not identical to X . X âs grandfather is equivalent to X âs fatherâs or motherâs father. X âs grandson is equivalent to X âs sonâs or daughterâs son. X âs uncle is equivalent to X âs fatherâs or motherâs brother. X âs nephew is equivalent to X âs brotherâs or sisterâs son. Similar rules apply to sister, grandmother, granddaughter, aunt and niece. In this problem, you can assume there are none of the following relations in the family: adoptions, marriages between relatives (i.e. the family tree has no cycles), divorces, remarriages, bigamous marriages and same-sex marriages. The degree of kinship is defined as follows: The distance from X to X âs father, X âs mother, X âs son or X âs daughter is one. The distance from X to X âs husband or X âs wife is zero. The degree of kinship between X and Y is equal to the shortest distance from X to Y deduced from the above rules. Input The input contains multiple datasets. The first line consists of a positive integer that indicates the number of datasets. Each dataset is given by one line in the following format: C is A(âs relation )* Here, relation is one of the following: father, mother, son, daughter, husband, wife, brother, sister, grandfather, grandmother, grandson, granddaughter, uncle, aunt, nephew, niece. An asterisk denotes zero or more occurance of portion surrounded by the parentheses. The number of relations in each dataset is at most ten. Output For each dataset, print a line containing the maximum and minimum degrees of kinship separated by exact one space. No extra characters are allowed of the output. Sample Input 7 C is Aâs fatherâs brotherâs sonâs aunt C is Aâs motherâs brotherâs sonâs aunt C is Aâs sonâs motherâs motherâs son C is Aâs auntâs nieceâs auntâs niece C is Aâs fatherâs sonâs brother C is Aâs sonâs sonâs mother C is A Output for the Sample Input 5 3 5 1 2 2 6 0 2 0 1 1 0 0 | 35,820 |
Score : 1200 points Problem Statement There are N jewels, numbered 1 to N . The color of these jewels are represented by integers between 1 and K (inclusive), and the color of Jewel i is C_i . Also, these jewels have specified values, and the value of Jewel i is V_i . Snuke would like to choose some of these jewels to exhibit. Here, the set of the chosen jewels must satisfy the following condition: For each chosen jewel, there is at least one more jewel of the same color that is chosen. For each integer x such that 1 \leq x \leq N , determine if it is possible to choose exactly x jewels, and if it is possible, find the maximum possible sum of the values of chosen jewels in that case. Constraints 1 \leq N \leq 2 \times 10^5 1 \leq K \leq \lfloor N/2 \rfloor 1 \leq C_i \leq K 1 \leq V_i \leq 10^9 For each of the colors, there are at least two jewels of that color. All values in input are integers. Input Input is given from Standard Input in the following format: N K C_1 V_1 C_2 V_2 : C_N V_N Output Print N lines. In the i -th line, if it is possible to choose exactly i jewels, print the maximum possible sum of the values of chosen jewels in that case, and print -1 otherwise. Sample Input 1 5 2 1 1 1 2 1 3 2 4 2 5 Sample Output 1 -1 9 6 14 15 We cannot choose exactly one jewel. When choosing exactly two jewels, the total value is maximized when Jewel 4 and 5 are chosen. When choosing exactly three jewels, the total value is maximized when Jewel 1, 2 and 3 are chosen. When choosing exactly four jewels, the total value is maximized when Jewel 2, 3, 4 and 5 are chosen. When choosing exactly five jewels, the total value is maximized when Jewel 1, 2, 3, 4 and 5 are chosen. Sample Input 2 5 2 1 1 1 2 2 3 2 4 2 5 Sample Output 2 -1 9 12 12 15 Sample Input 3 8 4 3 2 2 3 4 5 1 7 3 11 4 13 1 17 2 19 Sample Output 3 -1 24 -1 46 -1 64 -1 77 Sample Input 4 15 5 3 87 1 25 1 27 3 58 2 85 5 19 5 39 1 58 3 12 4 13 5 54 4 100 2 33 5 13 2 55 Sample Output 4 -1 145 173 285 318 398 431 491 524 576 609 634 653 666 678 | 35,821 |
Elevator Time Limit: 8 sec / Memory Limit: 64 MB E: ãšã¬ããŒã¿ ããªãã®å人ã¯ïŒããªã³ã®ããŒã¯ã®åŒè¶æ¥è
ã§ã¢ã«ãã€ããããŠããïŒ åœŒã®ä»äºã¯ïŒå»ºç©ããè·ç©ãéã³åºãããšã§ããïŒ ä»åïŒåœŒã¯ãã n é建ãŠã®ãã«ããããã€ãã®è·ç©ãéã³åºãããšã«ãªã£ãïŒ å¹žãïŒãã®ãã«ã«ã¯ãšã¬ããŒã¿ã1ã€åãä»ããããŠããããïŒ ãšã¬ããŒã¿ã§è·ç©ãéã³åºãããšã«ããïŒ éã³åºãã¹ãè·ç©ã¯ïŒåéã«è€æ°åããïŒè·ç©æ¯ã«éããç°ãªãïŒ ãšã¬ããŒã¿ã«ã¯ïŒééå¶éãèšå®ãããŠããïŒéã W ãè¶
ããè·ç©ãèŒããããšã¯ã§ããªãïŒ ãšã¬ããŒã¿ã¯ååã«åºãïŒééå¶éãæºãããªãã°ïŒã©ãã ãå€ãã®è·ç©ã§ãèŒããããšãã§ããïŒ ãšã¬ããŒã¿ã¯åæ¢ããéã§è·ç©ã®æ¬å
¥ãšæ¬åºãè¡ãããšãã§ããïŒ ããã©ã³ã¢ã«ãã€ã¿ãŒã§ãã圌ã¯ïŒãšã¬ããŒã¿ã«ä¹ããã«ïŒé段ã§ç§»åããïŒ ãšã¬ããŒã¿ã«è·ç©ãç©ã¿èŸŒãã åŸïŒéæ®µã§æ¬¡ã®ãšã¬ããŒã¿ã®åæ¢ããã¢ã«å
åããïŒè·ç©ã®æ¬å
¥ãšæ¬åºãè¡ãã®ã ïŒ ããã©ã³ã¢ã«ãã€ã¿ãŒã®åœŒã¯ïŒè·ç©ã®æ¬å
¥ãšæ¬åºãéåžžã«é«éã«è¡ãããšãã§ããã®ã§ïŒåããã¢ã§ã®ãšã¬ããŒã¿ã®åæ¢æéã¯ïŒç¡èŠããããšãã§ããïŒ ãã£ãŠïŒå
šãŠã®è·ç©ã1éã«ç§»åãããã®ã«å¿
èŠãªæéã¯ïŒãšã¬ããŒã¿ã®ç§»åè·é¢ãã容æã«ç®åºã§ããïŒ åœŒã¯ïŒè·ç©ãã§ããã ãæ©ã1éã«ç§»åããããïŒ åœŒã¯ããã©ã³ã¢ã«ãã€ã¿ãŒã§ã¯ãããïŒã©ã®ãããªæé ã§åéã§ã®è·ç©ã®åºãå
¥ããè¡ãã°ããã®ãåãããªãïŒ ããã§ïŒåœŒã¯ïŒå人ã§ããããªãã«å©ããæ±ããŠããïŒ ããªãã®ä»äºã¯ïŒåœŒãå
šãŠã®è·ç©ã1éã«ç§»åãããããã«å¿
èŠãªãšã¬ããŒã¿ã®æå°ã®ç§»åè·é¢ãæ±ããããšã§ããïŒ Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ n m W 1éã®è·ç©ã®æ
å ± ... i éã®è·ç©ã®æ
å ± ... n éã®è·ç©ã®æ
å ± i éã®è·ç©ã®æ
å ±ã¯ïŒä»¥äžã®åœ¢åŒã§äžããããïŒ(1 <= i <= n ) k i w 1 w 2 , ..., w j , ..., w k i å
¥åã®åœ¢åŒã®å倿°ã®æå³ã¯æ¬¡ã®éãã§ããïŒ n ã¯ããã¢æ°(1 <= n <= 10000) m ã¯ãšã¬ããŒã¿ã®åæäœçœ®(1 <= m <= n) W ã¯ãšã¬ããŒã¿ã®ééå¶é(1 <= W <= 10000) k i ã¯è·ç©ã®æ°(0 <= k i <= 15, 1 <= k 1 + k 2 + ... + k n <= 15) w j ã¯è·ç© j ã®éã(1 <= w j <= W ) Output æå°ã®ç§»åè·é¢ã1è¡ã§åºåããïŒ Sample Input 1 3 3 2 1 1 2 1 1 3 1 1 1 Sample Output 1 8 Sample Input 2 3 3 10 0 2 4 5 3 3 3 5 Sample Output 2 6 Sample Input 3 3 3 100 5 3 4 5 6 7 0 0 Sample Output 3 0 | 35,822 |
J - åºèº« å顿 ãã€ãã®ãããã¯å·ã§é£ããããŠããïŒé»ããŠçްé·ãéãæã«å
¥ããããšãã§ããã®ã§ïŒãã®å Žã§åãå»ãã§åºèº«ã«ããŠé£ã¹ãããšã«ããïŒ éã¯äœé·ã N ã»ã³ãã¡ãŒãã«ããïŒå¥åŠãªããšã«ïŒãã®éã¯èº«äœã®éšåããšã«å¯åºŠãç°ãªã£ãŠããïŒ éã®èº«äœãé ãã 1 ã»ã³ãã¡ãŒãã«ããšã«åºåã£ãŠçªå·ã 1, 2, ..., N ãšä»ãããšãïŒèº«äœã® i çªç®ã®éšåã®éã¿ã¯ w_i ã§ãã£ãïŒ éã® i çªç®ãã j çªç®ãŸã§ã®éšåã [i..j] ãšè¡šãããšã«ããïŒ æåïŒãããã¯éã®èº«äœ [0..N-1] ã 1 æã ãæã£ãŠãããšèŠãªããïŒãããã¯ãããåã£ãŠããæçµçã« N åã«åå²ãããéã®èº«äœ [0..0], [1..1], ..., [N-1..N-1] ãåŸããïŒ ãããã¯ä»éå€ã«ããïŒãŸãªæ¿ãªã©ãæã£ãŠããªãã®ã§ïŒæ¬¡ã®ãããªã¢ã¯ãããã£ãã¯ãªæ¹æ³ã§éã®èº«äœãåã£ãŠããããšã«ãã ïŒ ãŸãïŒéã®èº«äœã 1 æåãïŒããã [i..j] ãšããïŒãã®éã®èº«äœã¯é·ããå°ãªããšã 2 ã»ã³ãã¡ãŒãã«ä»¥äžã§ãªããã°ãªããªãïŒããªãã¡ïŒ j-i ⥠1 ã§ãªããã°ãªããªãïŒæ¬¡ã«ïŒããã空äžã«æããïŒãããŠæ¥æ¬åãæã«æã¡ïŒå®ã«èãéãçã£äºã€ã«åãïŒãã®ãšãïŒãããã¯åŒ·éãªéåç¥çµã«ãã£ãŠä»»æã®äœçœ®ã§ãã®éãåãããšãã§ãããïŒå¿
ã 1 ã»ã³ãã¡ãŒãã«åºåãã®äœçœ®ã§åããã®ãšããïŒããã«ããïŒå
ã®éã®èº«äœ [i..j] ãïŒä»»æã®åæäœçœ® k (i †k < j) ã«ãã£ãŠïŒ [i..k] ãš [k+1..j] ã® 2 ã€ã«åå²ããã®ã§ããïŒ ãã®ã¢ã¯ãããã£ãã¯ãªæ¹æ³ã§éã®èº«äœã 2 ã€ã«åããšãïŒå
ã®èº«äœã®éã (= w i +w i+1 +...+w j ) ã ãã³ã¹ãããããïŒ ãããã¯ïŒéã®ãã¹ãŠã®éšåã 1 ã»ã³ãã¡ãŒãã«åºåãã«åãã®ã«ãããã³ã¹ãã®åèšå€ãæå°ã«ãããïŒ å
¥ååœ¢åŒ å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ N w 1 w 2 ... w N N ã¯éã®äœé·ã§ããïŒ w i ã¯éã® i çªç®ã®éšåã®éãã§ããïŒ åºååœ¢åŒ éã N åã«åãåããã®ã«ãããã³ã¹ãã®åèšã®æå°å€ãåºåããïŒ å¶çŽ 2 †N †4,000 1 †w i †10 10 å
¥åå€ã¯ãã¹ãп޿°ã§ããïŒ ãã®åé¡ã®å€å®ã«ã¯ïŒ3 ç¹åã®ãã¹ãã±ãŒã¹ã®ã°ã«ãŒããèšå®ãããŠããïŒ ãã®ã°ã«ãŒãã«å«ãŸãããã¹ãã±ãŒã¹ã¯äžèšã®å¶çŽã«å ããŠäžèšã®å¶çŽãæºããïŒ 1 †N †100 å
¥åºåäŸ å
¥åäŸ 1 3 1 2 3 åºåäŸ 1 9 ãŸãïŒéå
šäœã 2 çªç®ãš 3 çªç®ã®éšåã®éã§åãïŒããã«ã¯ 1+2+3 = 6 ã®ã³ã¹ãããããïŒ æ¬¡ã«ïŒ1 çªç®ãš 2 çªç®ã®éšåã®éã§åãïŒããã«ã¯ 1+2=3 ã®ã³ã¹ãããããïŒåèšã§ 6+3=9 ã®ã³ã¹ãããããïŒãããæåæã§ããïŒ å
¥åäŸ 2 6 9876543210 9876543210 9876543210 9876543210 9876543210 9876543210 åºåäŸ 2 158024691360 å
¥åäŸ 3 10 127 131 137 139 149 151 157 163 167 173 åºåäŸ 3 5016 Writer: æ¥ æ¬å
Tester: è±ç°è£äžæ | 35,823 |
Score : 100 points Problem Statement We have 2N pots. The market price of the i -th pot (1 †i †2N) is p_i yen (the currency of Japan). Now, you and Lunlun the dachshund will alternately take one pot. You will go first, and we will continue until all the pots are taken by you or Lunlun. Since Lunlun does not know the market prices of the pots, she will always choose a pot randomly from the remaining pots with equal probability. You know this behavior of Lunlun, and the market prices of the pots. Let the sum of the market prices of the pots you take be S yen. Your objective is to maximize the expected value of S . Find the expected value of S when the optimal strategy is adopted. Constraints 1 †N †10^5 1 †p_i †2 à 10^5 All input values are integers. Input Input is given from Standard Input in the following format: N p_1 : p_{2N} Output Print the expected value of S when the strategy to maximize the expected value of S is adopted. The output is considered correct if its absolute or relative error from the judge's output is at most 10^{-9} . Sample Input 1 1 150000 108 Sample Output 1 150000.0 Naturally, you should choose the 150000 yen pot. Sample Input 2 2 50000 50000 100000 100000 Sample Output 2 183333.3333333333 First, you will take one of the 100000 yen pots. The other 100000 yen pot will become yours if it is not taken in Lunlun's next turn, with probability 2/3 . If it is taken, you will have to settle for a 50000 yen pot. Thus, the expected value of S when the optimal strategy is adopted is 2/3 à (100000 + 100000) + 1/3 à (100000 + 50000) = 183333.3333⊠| 35,824 |
Score : 300 points Problem Statement Find the price of a product before tax such that, when the consumption tax rate is 8 percent and 10 percent, the amount of consumption tax levied on it is A yen and B yen, respectively. (Yen is the currency of Japan.) Here, the price before tax must be a positive integer, and the amount of consumption tax is rounded down to the nearest integer. If multiple prices satisfy the condition, print the lowest such price; if no price satisfies the condition, print -1 . Constraints 1 \leq A \leq B \leq 100 A and B are integers. Input Input is given from Standard Input in the following format: A B Output If there is a price that satisfies the condition, print an integer representing the lowest such price; otherwise, print -1 . Sample Input 1 2 2 Sample Output 1 25 If the price of a product before tax is 25 yen, the amount of consumption tax levied on it is: When the consumption tax rate is 8 percent: \lfloor 25 \times 0.08 \rfloor = \lfloor 2 \rfloor = 2 yen. When the consumption tax rate is 10 percent: \lfloor 25 \times 0.1 \rfloor = \lfloor 2.5 \rfloor = 2 yen. Thus, the price of 25 yen satisfies the condition. There are other possible prices, such as 26 yen, but print the minimum such price, 25 . Sample Input 2 8 10 Sample Output 2 100 If the price of a product before tax is 100 yen, the amount of consumption tax levied on it is: When the consumption tax rate is 8 percent: \lfloor 100 \times 0.08 \rfloor = 8 yen. When the consumption tax rate is 10 percent: \lfloor 100 \times 0.1 \rfloor = 10 yen. Sample Input 3 19 99 Sample Output 3 -1 There is no price before tax satisfying this condition, so print -1 . | 35,825 |
ICPC Ranking Your mission in this problem is to write a program which, given the submission log of an ICPC (International Collegiate Programming Contest), determines team rankings. The log is a sequence of records of program submission in the order of submission. A record has four fields: elapsed time, team number, problem number, and judgment. The elapsed time is the time elapsed from the beginning of the contest to the submission. The judgment field tells whether the submitted program was correct or incorrect, and when incorrect, what kind of an error was found. The team ranking is determined according to the following rules. Note that the rule set shown here is one used in the real ICPC World Finals and Regionals, with some detail rules omitted for simplification. Teams that solved more problems are ranked higher. Among teams that solve the same number of problems, ones with smaller total consumed time are ranked higher. If two or more teams solved the same number of problems, and their total consumed times are the same, they are ranked the same. The total consumed time is the sum of the consumed time for each problem solved. The consumed time for a solved problem is the elapsed time of the accepted submission plus 20 penalty minutes for every previously rejected submission for that problem. If a team did not solve a problem, the consumed time for the problem is zero, and thus even if there are several incorrect submissions, no penalty is given. You can assume that a team never submits a program for a problem after the correct submission for the same problem. Input The input is a sequence of datasets each in the following format. The last dataset is followed by a line with four zeros. M T P R m 1 t 1 p 1 j 1 m 2 t 2 p 2 j 2 ..... m R t R p R j R The first line of a dataset contains four integers M , T , P , and R . M is the duration of the contest. T is the number of teams. P is the number of problems. R is the number of submission records. The relations 120 †M †300, 1 †T †50, 1 †P †10, and 0 †R †2000 hold for these values. Each team is assigned a team number between 1 and T , inclusive. Each problem is assigned a problem number between 1 and P , inclusive. Each of the following R lines contains a submission record with four integers m k , t k , p k , and j k (1 †k †R ). m k is the elapsed time. t k is the team number. p k is the problem number. j k is the judgment (0 means correct, and other values mean incorrect). The relations 0 †m k †M â1, 1 †t k †T , 1 †p k †P , and 0 †j k †10 hold for these values. The elapsed time fields are rounded off to the nearest minute. Submission records are given in the order of submission. Therefore, if i < j , the i -th submission is done before the j -th submission ( m i †m j ). In some cases, you can determine the ranking of two teams with a difference less than a minute, by using this fact. However, such a fact is never used in the team ranking. Teams are ranked only using time information in minutes. Output For each dataset, your program should output team numbers (from 1 to T ), higher ranked teams first. The separator between two team numbers should be a comma. When two teams are ranked the same, the separator between them should be an equal sign. Teams ranked the same should be listed in decreasing order of their team numbers. Sample Input 300 10 8 5 50 5 2 1 70 5 2 0 75 1 1 0 100 3 1 0 150 3 2 0 240 5 5 7 50 1 1 0 60 2 2 0 70 2 3 0 90 1 3 0 120 3 5 0 140 4 1 0 150 2 4 1 180 3 5 4 15 2 2 1 20 2 2 1 25 2 2 0 60 1 1 0 120 5 5 4 15 5 4 1 20 5 4 0 40 1 1 0 40 2 2 0 120 2 3 4 30 1 1 0 40 2 1 0 50 2 2 0 60 1 2 0 120 3 3 2 0 1 1 0 1 2 2 0 300 5 8 0 0 0 0 0 Output for the Sample Input 3,1,5,10=9=8=7=6=4=2 2,1,3,4,5 1,2,3 5=2=1,4=3 2=1 1,2,3 5=4=3=2=1 | 35,826 |
Score : 600 points Problem Statement You are given a positive integer N . Find the number of the pairs of integers u and v (0âŠu,vâŠN) such that there exist two non-negative integers a and b satisfying a xor b=u and a+b=v . Here, xor denotes the bitwise exclusive OR. Since it can be extremely large, compute the answer modulo 10^9+7 . Constraints 1âŠNâŠ10^{18} Input The input is given from Standard Input in the following format: N Output Print the number of the possible pairs of integers u and v , modulo 10^9+7 . Sample Input 1 3 Sample Output 1 5 The five possible pairs of u and v are: u=0,v=0 (Let a=0,b=0 , then 0 xor 0=0 , 0+0=0 .) u=0,v=2 (Let a=1,b=1 , then 1 xor 1=0 , 1+1=2 .ïŒ u=1,v=1 (Let a=1,b=0 , then 1 xor 0=1 , 1+0=1 .ïŒ u=2,v=2 (Let a=2,b=0 , then 2 xor 0=2 , 2+0=2 .ïŒ u=3,v=3 (Let a=3,b=0 , then 3 xor 0=3 , 3+0=3 .ïŒ Sample Input 2 1422 Sample Output 2 52277 Sample Input 3 1000000000000000000 Sample Output 3 787014179 | 35,827 |
æ®ãç©ã«ã¯çŠããã K åã®ç³ããã P 人ãé çªã«ïŒã€ãã€ç³ãåãã²ãŒã ããããŸãã P 人ç®ãç³ãåã£ãæç¹ã§ããŸã ç³ãæ®ã£ãŠããã°ããŸãïŒäººç®ããé çªã«ïŒã€ãã€ç³ãåã£ãŠãããŸãããã®ã²ãŒã ã§ã¯ãæåŸã®ç³ãåã£ã人ãåã¡ãšãªããŸãã K ãš P ãäžãããããšããäœäººç®ãåã€ãå€å®ããããã°ã©ã ãäœæããŠãã ããã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã N K 1 P 1 K 2 P 2 : K N P N ïŒè¡ç®ã«ã¯ã²ãŒã ãè¡ãåæ° N (1 †N †100) ãäžãããããç¶ã N è¡ã«ã i åç®ã®ã²ãŒã ã«ãããç³ã®åæ° K i (2 †K i †1000) ãšãã²ãŒã ã«åå ããäººæ° P i (2 †P i †1000) ãäžããããã åºå ããããã®ã²ãŒã ã«ã€ããŠãäœäººç®ãåã€ããïŒè¡ã«åºåããã å
¥åºåäŸ å
¥åäŸ 3 10 3 2 10 4 2 åºåäŸ 1 2 2 | 35,828 |
Intersection of Circles For given two circles $c1$ and $c2$, print 4 if they do not cross (there are 4 common tangent lines), 3 if they are circumscribed (there are 3 common tangent lines), 2 if they intersect (there are 2 common tangent lines), 1 if a circle is inscribed in another (there are 1 common tangent line), 0 if a circle includes another (there is no common tangent line). Input Coordinates and radii of $c1$ and $c2$ are given in the following format. $c1x \; c1y \; c1r$ $c2x \; c2y \; c2r$ $c1x$, $c1y$ and $c1r$ represent the center coordinate and radius of the first circle. $c2x$, $c2y$ and $c2r$ represent the center coordinate and radius of the second circle. All input values are given in integers. Output Print "4", "3", "2", "1" or "0" in a line. Constraints $-1,000 \leq c1x, c1y, c2x, c2y \leq 1,000$ $1 \leq c1r, c2r \leq 1,000$ $c1$ and $c2$ are different Sample Input 1 1 1 1 6 2 2 Sample Output 1 4 Sample Input 2 1 2 1 4 2 2 Sample Output 2 3 Sample Input 3 1 2 1 3 2 2 Sample Output 3 2 Sample Input 4 0 0 1 1 0 2 Sample Output 4 1 Sample Input 5 0 0 1 0 0 2 Sample Output 5 0 | 35,829 |
ããã°ã©ãã³ã°ã³ã³ãã¹ã II çœè倧åŠã§ã¯æ¯å¹Žããã°ã©ãã³ã°ã³ã³ãã¹ããéå¬ããŠããŸããã³ã³ãã¹ãã¯å
šãŠã®ããŒã ã®åŸç¹ã 0ã®ç¶æ
ããéå§ããè§£çç¶æ³ã«å¿ããŠåŸç¹ãå ç®ãããŠãããŸãããã®ã³ã³ãã¹ãã§ã¯ãåŸç¹ã®é«ãé ã«é äœä»ããè¡ãããŸããããŒã ã®ç·æ°ã N ãšãããšããããŒã ã«ã¯ 1 ãã N ã®çªå·ãããããå²ãåœãŠãããŠããŸããåŸç¹ãåãå Žåã¯çªå·ãããå°ããæ¹ãäžäœã«ãªããŸãã çœè倧åŠã§ã¯ãã³ã³ãã¹ããçãäžããããã«èгæŠçšã®ã©ã³ãã³ã°ã·ã¹ãã ãéçºããŠããŸããéçºããŒã ã®äžå¡ã§ããããªãã¯ããã®ã·ã¹ãã ã®äžéšã§ããããã°ã©ã ã®äœæãä»»ãããŠããŸãã äžããããåœä»€ã«åŸã£ãŠãåŸç¹ã®æŽæ°ãšãæå®ãããé äœã®ããŒã ã®çªå·ãšåŸç¹ãå ±åããããã°ã©ã ãäœæããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã N C command 1 command 2 : command C ïŒè¡ç®ã«ããŒã æ° N (2 †N †100000) ãšåœä»€ã®æ° C (1 †C †100000)ãäžãããããç¶ã C è¡ã«ãïŒè¡ãã€åœä»€ãäžãããããååœä»€ã¯ä»¥äžã®åœ¢åŒã§äžããããã 0 t p ãŸã㯠1 m æåã®æ°åã0ã®ãšãæŽæ°åœä»€ã1ã®ãšãå ±ååœä»€ã衚ããæŽæ°åœä»€ã§ã¯æå®ãããçªå· t (1 †t †N ) ã®ããŒã ã«ãæŽæ°ã§äžããããåŸç¹ p (1 †p †10 9 ) ãå ç®ãããå ±ååœä»€ã§ã¯æå®ãããé äœ m (1 †m †N ) ã®ããŒã ã®çªå·ãšåŸç¹ãå ±åããããã ããå ±ååœä»€ã¯å°ãªããšãïŒåçŸãããã®ãšããã Output åå ±ååœä»€ã«å¯ŸããŠãæå®ãããé äœã®ããŒã ã®çªå·ãšåŸç¹ã空çœåºåãã§ïŒè¡ã«åºåããã Sample Input 1 3 11 0 2 5 0 1 5 0 3 4 1 1 1 2 1 3 0 3 2 1 1 0 2 1 1 2 1 3 Sample Output 1 1 5 2 5 3 4 3 6 3 6 1 5 Sample Input 2 5 2 1 1 1 2 Sample Output 2 1 0 2 0 | 35,830 |
Score : 500 points Problem Statement We have N camels numbered 1,2,\ldots,N . Snuke has decided to make them line up in a row. The happiness of Camel i will be L_i if it is among the K_i frontmost camels, and R_i otherwise. Snuke wants to maximize the total happiness of the camels. Find the maximum possible total happiness of the camel. Solve this problem for each of the T test cases given. Constraints All values in input are integers. 1 \leq T \leq 10^5 1 \leq N \leq 2 \times 10^{5} 1 \leq K_i \leq N 1 \leq L_i, R_i \leq 10^9 The sum of values of N in each input file is at most 2 \times 10^5 . Input Input is given from Standard Input in the following format: T \mathrm{case}_1 \vdots \mathrm{case}_T Each case is given in the following format: N K_1 L_1 R_1 \vdots K_N L_N R_N Output Print T lines. The i -th line should contain the answer to the i -th test case. Sample Input 1 3 2 1 5 10 2 15 5 3 2 93 78 1 71 59 3 57 96 19 19 23 16 5 90 13 12 85 70 19 67 78 12 16 60 18 48 28 5 4 24 12 97 97 4 57 87 19 91 74 18 100 76 7 86 46 9 100 57 3 76 73 6 84 93 1 6 84 11 75 94 19 15 3 12 11 34 Sample Output 1 25 221 1354 In the first test case, it is optimal to line up the camels in the order 2, 1 . Camel 1 is not the frontmost camel, so its happiness will be 10 . Camel 2 is among the two frontmost camels, so its happiness will be 15 . In the second test case, it is optimal to line up the camels in the order 2, 1, 3 . Camel 1 is among the two frontmost camels, so its happiness will be 93 . Camel 2 is the frontmost camel, so its happiness will be 71 . Camel 3 is among the three frontmost camels, so its happiness will be 57 . | 35,831 |
Score : 1200 points Problem Statement Takahashi is a magician. He can cast a spell on an integer sequence (a_1,a_2,...,a_M) with M terms, to turn it into another sequence (s_1,s_2,...,s_M) , where s_i is the sum of the first i terms in the original sequence. One day, he received N integer sequences, each with M terms, and named those sequences A_1,A_2,...,A_N . He will try to cast the spell on those sequences so that A_1 < A_2 < ... < A_N will hold, where sequences are compared lexicographically. Let the action of casting the spell on a selected sequence be one cast of the spell. Find the minimum number of casts of the spell he needs to perform in order to achieve his objective. Here, for two sequences a = (a_1,a_2,...,a_M), b = (b_1,b_2,...,b_M) with M terms each, a < b holds lexicographically if and only if there exists i (1 ⊠i ⊠M) such that a_j = b_j (1 ⊠j < i) and a_i < b_i . Constraints 1 ⊠N ⊠10^3 1 ⊠M ⊠10^3 Let the j -th term in A_i be A_{(i,j)} , then 1 ⊠A_{(i,j)} ⊠10^9 . Partial Scores In the test set worth 200 points, Takahashi can achieve his objective by at most 10^4 casts of the spell, while keeping the values of all terms at most 10^9 . In the test set worth another 800 points, A_{(i,j)} ⊠80 . Input The input is given from Standard Input in the following format: N M A_{(1,1)} A_{(1,2)} ⊠A_{(1,M)} A_{(2,1)} A_{(2,2)} ⊠A_{(2,M)} : A_{(N,1)} A_{(N,2)} ⊠A_{(N,M)} Output Print the minimum number of casts of the spell Takahashi needs to perform. If he cannot achieve his objective, print -1 instead. Sample Input 1 3 3 2 3 1 2 1 2 2 6 3 Sample Output 1 1 Takahashi can achieve his objective by casting the spell on A_2 once to turn it into (2 , 3 , 5) . Sample Input 2 3 3 3 2 10 10 5 4 9 1 9 Sample Output 2 -1 In this case, Takahashi cannot achieve his objective by casting the spell any number of times. Sample Input 3 5 5 2 6 5 6 9 2 6 4 9 10 2 6 8 6 7 2 1 7 3 8 2 1 4 8 3 Sample Output 3 11 | 35,832 |
Problem H: Digital Racing Circuit You have an ideally small racing car on an x-y plane (0 †x, y †255, where bigger y denotes upper coordinate). The racing circuit course is figured by two solid walls. Each wall is a closed loop of connected line segments. End point coordinates of every line segment are both integers (See Figure 1). Thus, a wall is represented by a list of end point integer coordinates ( x 1 , y 1 ), ( x 2 , y 2 ), ...,( x n , y n ). The start line and the goal line are identical. Figure 1. A Simple Course For the qualification run, you start the car at any integer coordinate position on the start line, say ( s x , s y ). At any clock t (⥠0), according to the acceleration parameter at t , ( a x,t , a y,t ), the velocity changes instantly to ( v x,t-1 + a x,t , v y,t-1 + a y,t ), if the velocity at t - 1 is ( v x,t-1 , v y,t-1 ). The velocity will be kept constant until the next clock. It is assumed that the velocity at clock -1, ( v x,-1 , v y,-1 ) is (0, 0). Each of the acceleration components must be either -1, 0, or 1, because your car does not have so fantastic engine and brake. In other words, any successive pair of velocities should not differ more than 1 for either x -component or y -component. Note that your trajectory will be piecewise linear as the walls are. Your car should not touch nor run over the circuit wall, or your car will be crashed, even at the start line. The referee watches your car's trajectory very carefully, checking whether or not the trajectory touches the wall or attempts to cross the wall. The objective of the qualification run is to finish your run within as few clock units as possible, without suffering from any interference by other racing cars. That is, you run alone the circuit around clockwise and reach, namely touch or go across the goal line without having been crashed. Don't be crashed even in the last trajectory segment after you reach the goal line. But we don't care whatever happens after that clock Your final lap time is the clock t when you reach the goal line for the first time after you have once left the start line. But it needs a little adjustment at the goal instant. When you cross the goal line, only the necessary fraction of your car's last trajectory segment is counted. For example, if the length of your final trajectory segment is 3 and only its 1/3 fraction is needed to reach the goal line, you have to add only 0.333 instead of 1 clock unit. Drivers are requested to control their cars as cleverly as possible to run fast but avoiding crash. ALAS! The racing committee decided that it is too DANGEROUS to allow novices to run the circuit. In the last year, it was reported that some novices wrenched their fingers by typing too enthusiastically their programs. So, this year, you are invited as a referee assistant in order to accumulate the experience on this dangerous car race. A number of experienced drivers are now running the circuit for the qualification for semi-finals. They submit their driving records to the referee. The referee has to check the records one by one whether it is not a fake. Now, you are requested to make a program to check the validity of driving records for any given course configuration. Is the start point right on the start line without touching the walls? Is every value in the acceleration parameter list either one of -1, 0, and 1? Does the length of acceleration parameter list match the reported lap time? That is, aren't there any excess acceleration parameters after the goal, or are these enough to reach the goal? Doesn't it involve any crash? Does it mean a clockwise running all around? (Note that it is not inhibited to run backward temporarily unless crossing the start line again.) Is the lap time calculation correct? You should allow a rounding error up to 0.01 clock unit in the lap time. Input The input consists of a course configuration followed by a number of driving records on that course. A course configuration is given by two lists representing the inner wall and the outer wall, respectively. Each line shows the end point coordinates of the line segments that comprise the wall. A course configuration looks as follows: i x ,1 i y ,1 ..... i x ,N i y ,N 99999 o x ,1 o y ,1 ..... o x ,M o y ,M 99999 where data are alternating x -coordinates and y -coordinates that are all non-negative integers (†255) terminated by 99999. The start/goal line is a line segment connecting the coordinates ( i x ,1 , i y ,1 ) and ( o x ,1 , o y ,1 ). For simplicity, i y ,1 is assumed to be equal to o y ,1 ; that is, the start/goal line is horizontal on the x-y plane. Note that N and M may vary among course configurations, but do not exceed 100, because too many curves involve much danger even for experienced drivers. You need not check the validity of the course configuration. A driving record consists of three parts, which is terminated by 99999: two integers s x , s y for the start position ( s x , s y ), the lap time with three digits after the decimal point, and the sequential list of acceleration parameters at all clocks until the goal. It is assumed that the length of the acceleration parameter list does not exceed 500. A driving record looks like the following: s x s y lap-time a x ,0 a y ,0 a x ,1 a y ,1 ... a x , L a y , L 99999 Input is terminated by a null driving record; that is, it is terminated by a 99999 that immediately follows 99999 of the last driving record. Output The test result should be reported by simply printing OK or NG for each driving record, each result in each line. No other letter is allowed in the result. Sample Input 6 28 6 32 25 32 26 27 26 24 6 24 99999 2 28 2 35 30 35 30 20 2 20 99999 3 28 22.667 0 1 1 1 1 0 0 -1 0 -1 1 0 0 0 1 0 -1 0 0 -1 -1 -1 -1 0 -1 0 -1 -1 -1 1 -1 1 -1 1 -1 0 1 0 1 1 1 1 1 0 1 1 99999 5 28 22.667 0 1 -1 1 1 0 1 -1 1 -1 1 0 1 0 1 0 -1 -1 -1 0 -1 -1 -1 0 -1 1 -1 -1 -1 1 -1 0 -1 1 -1 0 1 0 1 0 1 1 1 1 1 1 99999 4 28 6.333 0 1 0 1 1 -1 -1 -1 0 -1 0 -1 0 -1 99999 3 28 20.000 0 -1 1 -1 1 0 1 1 1 1 1 0 -1 0 -1 0 -1 1 -1 1 -1 1 -1 0 -1 -1 -1 -1 -1 -1 -1 0 1 0 1 -1 1 -1 1 -1 99999 99999 Output for the Sample Input OK NG NG NG | 35,833 |
E: æ / Fuda ãã®åé¡ã¯ãªã¢ã¯ãã£ãåé¡ã§ãã ãµãŒããŒåŽã«çšæãããããã°ã©ã ãšå¯Ÿè©±çã«å¿çããããšã§æ£çãå°ãããã°ã©ã ãäœæããå¿
èŠããããŸãã å顿 æ¹ã«æµ®ãã¶ $N$ åã®å°å³¶ãããªããã¯ã³ãšããæãããã åå°å³¶ã«ã¯ $0$ ãã $N-1$ ãŸã§çªå·ãæ¯ãããŠããã æã«ã¯å³¶ãšå³¶ã®éã«æ¶ããæ©ã $M$ æ¬ããã$0$ ãã $M-1$ ãŸã§çªå·ãæ¯ãããŠããã æ©ã¯åæ¹åã«ç§»åå¯èœã§ããã ããã§èšãæ©ãšã¯åã«å³¶ãšå³¶ã®éã®éãéãšããããšã§ãããåãé€ããšäºãã«å°éäžå¯èœãªå³¶ã®çµãå¢ããæå³ã§ã¯ãªãã æè¿ãæ©ã®äž¡ç«¯ã«æ²ç€ºæ¿ãèšçœ®ãããã®æ©ãæž¡ã£ãå
ã®å³¶ããæ©ã $1$ æ¬ã ã䜿ã£ãŠç§»åã§ããå³¶ (ä»ããå³¶ãå«ãŸãªã) ã®çªå·ã®æžãããæã貌ãããšã§ã ã¹ã ãŒãºãªç§»åãå®çŸããèšç»ãæã¡äžãã£ãã äžæã®æã«ã¯äžã€ã®ç§»åå
ããæžãããšãåºæ¥ãªããããç§»åã§ããå³¶ã®æ°ã ãæãå¿
èŠã«ãªãã ãã®æã®äœæãåœããããããªãã¯ãæã¯å
šéšã§äœæå¿
èŠãã調ã¹ãããšã«ããã æã«ã¯ããã€ãŠå
šãŠã®æ©ãæ¶ããæ©è·äººãããã ãŸããåå³¶ã«ã¯ãã®å³¶ã«äœãã§ããæäººãããã æã¯åºå€§ã§å
šãŠã®æ²ç€ºæ¿ãèŠãŠåãã®ã¯éªšãæãããããæ¬éšããé»è©±ã§åœŒãã«è³ªåãããããšã§å¿
èŠãªæã®ææ°ãæ±ããããšã«ããã æ©è·äººãžã®è³ªåã§ã¯ããŸããäœçªã®æ©ã®æ
å ±ãç¥ãããããæ©è·äººã«äŒããã ãããšãã©ã®å³¶ãšã©ã®å³¶ã®éã«è©²åœããæ©ãæ¶ãããã確å®ã«æããŠããã (edgã¯ãšãª)ã äœäººãžã®è³ªåã§ã¯ããŸãèãããå³¶ã®çªå·$i$ãäŒããã ãããšãå³¶ $i$ ã«ãããæ©ã®æ°ãšãã®æ©ãã©ãã«ããã£ãŠããããæããŠããã (lst ã¯ãšãª)ã ãããã貧匱ãªéä¿¡ç¶²ã䜿çšããŠãããããåæ©ã«å¯ŸããŠã80% ã®ç¢ºçã§æ
å ±ãæãèœã¡ãŠããŸãã æã®çºæ³šãŸã§æéããªãã®ã§å
šäœã§å€ããŠã $3N$ åãã質åãã§ããªãã 以äžã®æ¡ä»¶ã®ããšã§ãå¿
èŠãªæã®æ°ãæ±ããããã°ã©ã ãæžããªããã å
¥åºå仿§ 以éã§ã¯ãããªããæåºããããã°ã©ã ããè§£çãããžã£ããžåŽãçšæããããã°ã©ã ãããžã£ããžããšåŒã¶ã å
¥åºåã®è©³çްãªä»æ§ã以äžã«ç€ºãããå
ã«ãµã³ãã«ãèŠããšéãã å³¶ãšæ©ã®æ° ãžã£ããžã¯ããŸãå³¶ã®æ° $N$ ãšæ©ã®æ°ã®åèš $M$ ã $1$ è¡ã«åºåããã N M ç¶ããŠãè§£ç㯠edg, lst ã¯ãšãªãæå€§ $3N$ åã ans ãã¡ããã© 1 åãžã£ããžã«å¯ŸããŠéãããšãã§ããã edg ã¯ãšãª è§£çã® edg ã¯ãšãªã«å¯Ÿãããžã£ããžã¯æ©$i$ã®äž¡ç«¯ã®å³¶ã®çªå·ãçãããè§£çã¯æ¬¡ã®åœ¢åŒã§åºåããã edg i ããã«å¯ŸããŠããžã£ããžã¯æ¬¡ã®åœ¢åŒã§å¿çããã a b $a$, $b$ ã¯æ© $i$ ãçµã¶å³¶ã®çªå·ã§ããã lst ã¯ãšãª è§£çã® lst ã¯ãšãªã«å¯Ÿãããžã£ããžã¯å°å³¶ $i$ ã«ãããæ©ã®æ¬æ°ãšãããããã®æ©ã®è¡ãå
ã®å³¶ã®çªå·ãçãããè§£çã¯æ¬¡ã®åœ¢åŒã§åºåããã lst i ããã«å¯ŸããŠããžã£ããžã¯æ¬¡ã®åœ¢åŒã§å¿çããã k v1 v2 v3 ⊠vk $k$ ã¯å³¶ $i$ ã«ãããæ©ã®æ°ã§ããã ç¶ã $v_1 \cdots v_k$ ã¯é ç¹$i$ããæ©ãäžåºŠã ã䜿ã£ãŠç§»åå¯èœãªé ç¹ã®çªå·ã®ãªã¹ãã§ããã åæ©ã®è¡ãå
$v_j$ ã«å¯Ÿãã$v_j \ge 0$ ã®å Žåã¯ãã®æ
å ±ããã£ããäŒãã£ãããšã衚ãã$v_j = -1$ ã®å Žåã¯æ
å ±ãæãèœã¡ãŠããããšã衚ãã $-1$ ãã©ããã¯ä¹±æ°ã§æ±ºãããã80% ã®ç¢ºçã§ $-1$ ãšãªãããããã£ãŠãåã $i$ ã«å¯ŸããŠè€æ°åãã®ã¯ãšãªãå®è¡ãããšãçµæã¯å€ããããããŸããé çªãäžå®ã§ããã ans ã¯ãšãª è§£çã® ans ã¯ãšãªã«ãã£ãŠãçããåºåã§ããããã®ã¯ãšãªã¯ 1 床ããè¡ãããšãåºæ¥ããçµæãæ£ãããªãå Žåã¯çŽã¡ã«èª€çãšãªãã ãã®ã¯ãšãªã®å®è¡åŸã«ãè§£çã¯çŽã¡ã«æ£åžžçµäºããã $X$ ãçããšããŠåºåãããå Žåã®åœ¢åŒã¯ä»¥äžã®éãã§ããã ans X å¶çŽãšæ³šæ $1 \le N \le 100$ $0 \le M \le N(N-1)/2$ æ©ã¯ç°ãªã 2 ã€ã®å³¶ã®éã«æ¶ãã£ãŠããã ç°ãªãæ©ããåã 2 ã€ã®å³¶ãçµã¶ããšã¯ãªãã ans 以å€ã®ã¯ãšãªã¯é«ã
$3N$ åããæããããªãã ãžã£ããžããã°ã©ã ã®åºåã¯å
šãŠ $1$ è¡ãã€ã¹ããŒã¹åºåãã®æŽæ°ãããªãã 仿§ã«åŸããªãåºåã®çµæã¯äžå®ã§ããã è§£çã¯ãžã£ããžã®å¿çãããã«æšæºå
¥åã§åãåããªããã°ãªããªãã è§£çã¯ã¯ãšãªãåºåããçŽåŸã«ãããã¡ã空ã«ãããæå°ã®è§£çããã°ã©ã äŸãäžã«ç€ºããCãC++以å€ã®èšèªã¯åèªã§èª¿ã¹ãŠã»ããã C #include <stdio.h> int main(){ int n,m; scanf("%d %d", & n, &m); printf("ans 100\n"); // çãããžã£ããžã«æåº fflush(stdout); // ãã©ãã·ã¥ return 0; } C++ #include <iostream> using namespace std; int main(){ int n,m; cin >> n >> m; cout << "ans 100" << endl; // æ¹è¡çŽåŸã«ãã©ãã·ã¥ // cout << "ans 100\n" << flush; // äžãšåã } ãµã³ãã« è§£çããã°ã©ã ãšãžã£ããžããã°ã©ã ã®å
¥åºåäŸã以äžã«ç€ºãã å顿ã®å³äžã®æã«å¯Ÿããçããæ±ããŠããã | 35,834 |
Connected Components Write a program which reads relations in a SNS (Social Network Service), and judges that given pairs of users are reachable each other through the network. Input In the first line, two integer $n$ and $m$ are given. $n$ is the number of users in the SNS and $m$ is the number of relations in the SNS. The users in the SNS are identified by IDs $0, 1, ..., n-1$. In the following $m$ lines, the relations are given. Each relation is given by two integers $s$ and $t$ that represents $s$ and $t$ are friends (and reachable each other). In the next line, the number of queries $q$ is given. In the following $q$ lines, $q$ queries are given respectively. Each query consists of two integers $s$ and $t$ separated by a space character. Output For each query, print "yes" if $t$ is reachable from $s$ through the social network, "no" otherwise. Constraints $2 \leq n \leq 100,000$ $0 \leq m \leq 100,000$ $1 \leq q \leq 10,000$ Sample Input 10 9 0 1 0 2 3 4 5 7 5 6 6 7 6 8 7 8 8 9 3 0 1 5 9 1 3 Sample Output yes yes no | 35,835 |
Score : 300 points Problem Statement There is a rectangle in a coordinate plane. The coordinates of the four vertices are (0,0) , (W,0) , (W,H) , and (0,H) . You are given a point (x,y) which is within the rectangle or on its border. We will draw a straight line passing through (x,y) to cut the rectangle into two parts. Find the maximum possible area of the part whose area is not larger than that of the other. Additionally, determine if there are multiple ways to cut the rectangle and achieve that maximum. Constraints 1 \leq W,H \leq 10^9 0\leq x\leq W 0\leq y\leq H All values in input are integers. Input Input is given from Standard Input in the following format: W H x y Output Print the maximum possible area of the part whose area is not larger than that of the other, followed by 1 if there are multiple ways to cut the rectangle and achieve that maximum, and 0 otherwise. The area printed will be judged correct when its absolute or relative error is at most 10^{-9} . Sample Input 1 2 3 1 2 Sample Output 1 3.000000 0 The line x=1 gives the optimal cut, and no other line does. Sample Input 2 2 2 1 1 Sample Output 2 2.000000 1 | 35,836 |
The Phantom Mr. Hoge is in trouble. He just bought a new mansion, but itâs haunted by a phantom. He asked a famous conjurer Dr. Huga to get rid of the phantom. Dr. Huga went to see the mansion, and found that the phantom is scared by its own mirror images. Dr. Huga set two flat mirrors in order to get rid of the phantom. As you may know, you can make many mirror images even with only two mirrors. You are to count up the number of the images as his assistant. Given the coordinates of the mirrors and the phantom, show the number of images of the phantom which can be seen through the mirrors. Input The input consists of multiple test cases. Each test cases starts with a line which contains two positive integers, p x and p y (1 †p x , p y †50), which are the x - and y -coordinate of the phantom. In the next two lines, each line contains four positive integers u x , u y , v x and v y (1 †u x , u y , v x , v y †50), which are the coordinates of the mirror. Each mirror can be seen as a line segment, and its thickness is negligible. No mirror touches or crosses with another mirror. Also, you can assume that no images will appear within the distance of 10 -5 from the endpoints of the mirrors. The input ends with a line which contains two zeros. Output For each case, your program should output one line to the standard output, which contains the number of images recognized by the phantom. If the number is equal to or greater than 100, print âTOO MANYâ instead. Sample Input 4 4 3 3 5 3 3 5 5 6 4 4 3 3 5 3 3 5 5 5 0 0 Output for the Sample Input 4 TOO MANY | 35,837 |
Score : 300 points Problem Statement We have a 2 \times N grid. We will denote the square at the i -th row and j -th column ( 1 \leq i \leq 2 , 1 \leq j \leq N ) as (i, j) . You are initially in the top-left square, (1, 1) . You will travel to the bottom-right square, (2, N) , by repeatedly moving right or down. The square (i, j) contains A_{i, j} candies. You will collect all the candies you visit during the travel. The top-left and bottom-right squares also contain candies, and you will also collect them. At most how many candies can you collect when you choose the best way to travel? Constraints 1 \leq N \leq 100 1 \leq A_{i, j} \leq 100 ( 1 \leq i \leq 2 , 1 \leq j \leq N ) Input Input is given from Standard Input in the following format: N A_{1, 1} A_{1, 2} ... A_{1, N} A_{2, 1} A_{2, 2} ... A_{2, N} Output Print the maximum number of candies that can be collected. Sample Input 1 5 3 2 2 4 1 1 2 2 2 1 Sample Output 1 14 The number of collected candies will be maximized when you: move right three times, then move down once, then move right once. Sample Input 2 4 1 1 1 1 1 1 1 1 Sample Output 2 5 You will always collect the same number of candies, regardless of how you travel. Sample Input 3 7 3 3 4 5 4 5 3 5 3 4 4 2 3 2 Sample Output 3 29 Sample Input 4 1 2 3 Sample Output 4 5 | 35,838 |
ã«ãŒãã®çµã¿åãã æŽæ°ãæžããŠããã«ãŒããäœæãå
¥ã£ãŠããè¢ã䜿ã£ãŠã²ãŒã ãããŸããããååã®ã²ãŒã ã§åå è
ã¯ãŸãã奜ããªæ° n ãäžã€å®£èšããŸãããããŠãè¢ã®äžããé©åœãªææ°ã ãã«ãŒããäžåºŠã«åãåºããŠããããã®ã«ãŒãã«æžãããæ°ã®ç·åã n ã«çãããã°è±ªè¯è³åãããããŸãããªããããããã®ã²ãŒã çµäºåŸã«ãŒãã¯è¢ã«æ»ãããŸãã è¢ã®äžã® m çš®é¡ã®ã«ãŒãã®æ
å ±ããã³ã g åã®ã²ãŒã ã§åå è
ã宣èšããæ°ãå
¥åãšããããããã®ã²ãŒã ã§è±ªè¯ååãããããã«ãŒãã®çµã¿åãããäœéãããããåºåããããã°ã©ã ãäœæããŠãã ããã Input è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸãã åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã m a 1 b 1 a 2 b 2 : a m b m g n 1 n 2 : n g ïŒè¡ç®ã«ã«ãŒãã®çš®é¡æ° m ïŒ1 †m †7ïŒãç¶ã m è¡ã« i çš®é¡ç®ã®ã«ãŒãã«æžãããæŽæ° a i (1 †a i †100) ãšãã®ææ° b i (1 †b i †10) ã空çœåºåãã§äžããããŸãã ç¶ãè¡ã«ã²ãŒã ã®åæ° g (1 †g †10)ãç¶ã g è¡ã«ã²ãŒã i ã§å®£èšãããæŽæ° n i (1 †n i †1,000) ãäžããããŸãã ããŒã¿ã»ããã®æ°ã¯ 100 ãè¶
ããªãã Output å
¥åããŒã¿ã»ããããšã«ã i è¡ç®ã«ã²ãŒã i ã§è±ªè¯è³åãããããã«ãŒãã®çµã¿åããæ°ãåºåããŸãã Sample Input 5 1 10 5 3 10 3 25 2 50 2 4 120 500 100 168 7 1 10 3 10 5 10 10 10 25 10 50 10 100 10 3 452 574 787 0 Output for the Sample Input 16 0 12 7 9789 13658 17466 | 35,839 |
Problem H: Count Words Problem $M$ çš®é¡ã®æåãããããããã䜿ã£ãŠé·ã $N$ ã®æååãäœãã䜿ãããŠããæåã®çš®é¡æ°ã $K$ 以äžã§ãããããªæååã¯äœéããããã$998244353$ ã§å²ã£ãããŸããæ±ããã ããã§é·ã $N$ ã®2ã€ã®æååãç°ãªããšã¯ä»¥äžã®ããã«å®çŸ©ãããã 2ã€ã®æååã $S = S_1S_2 \ldots S_N$, $T = T_1T_2 \ldots T_N$ ãšããå Žåã«ã$S_i \neq T_i$ ãšãªããã㪠$i$ $(1 \leq i \leq N)$ ãååšããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã $M$ $N$ $K$ 1è¡ã« $M, N, K$ ã空çœåºåãã§äžããããã Constraints å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã $1 \leq M \leq 10^{18} $ $1 \leq N \leq 10^{18} $ $1 \leq K \leq 1000 $ å
¥åã¯ãã¹ãп޿° Output 䜿ãããŠããæåã®çš®é¡æ°ã $K$ 以äžã§ãããããªé·ã $N$ ã®æååã®éãæ°ã $998244353$ ã§å²ã£ãããŸããåºåããã Sample Input 1 2 10 1 Sample Output 1 1024 Sample Input 2 1 1 2 Sample Output 2 0 Sample Input 3 5 10 3 Sample Output 3 9755400 Sample Input 4 7 8 3 Sample Output 4 5759460 Sample Input 5 1000000000000000000 1000000000000000000 1000 Sample Output 5 133611974 | 35,840 |
ãåç£è³Œå
¥èšç» (Gifts) åé¡ ãªãŒã¹ãã©ãªã¢ã«æ
è¡ã«æ¥ã JOI åã¯æ§ã
ãªå Žæã§èгå
ãæ¥œãã¿ïŒã€ãã«åž°åœããæ¥ããã£ãŠããïŒä»ïŒJOI åã¯åž°ãã®é£è¡æ©ãåºçºããåœé空枯ã®ããçºã«ããïŒãã®çºã¯æ±è¥¿ååã«åºç»æŽçãããŠããïŒååºç»ã«ã¯éïŒåç£åºïŒäœå®
ïŒåœé空枯ãããïŒ JOI åã¯æãå西ã®åºç»ããåºçºããŠæãåæ±ã®åºç»ã®åœé空枯ãç®æãïŒ JOI åã¯ä»ããåºç»ããé£ãåã£ãåºç»ã«ç§»åããããšãã§ãããïŒäœå®
ã®ããåºç»ã«ã¯å
¥ãããšã¯ã§ããªãïŒãŸãé£è¡æ©ã®æéã«éã«åãããããã«ïŒä»ããåºç»ã®æ±ãåã®åºç»ã«ã®ã¿ç§»åããïŒãã ãïŒæéã«ã¯ããããäœè£ãããããïŒK åãŸã§ä»ããåºç»ã®åã西ã®åºç»ãžç§»åããããšãã§ããïŒ JOI åã¯åç£åºã®ããåºç»ã«å
¥ããšïŒæ¥æ¬ã®å人ãã¡ã®ããã«ãåç£ãè²·ãïŒJOI åã¯åç£åºã«ã€ããŠå
¥å¿µã«äžèª¿ã¹ãããŠããã®ã§ïŒã©ã®åç£åºã«è¡ã£ããäœåã®ãåç£ãè²·ãããšãã§ããããåãã£ãŠããïŒJOI åã賌å
¥ã§ãããåç£ã®åæ°ã®æå€§å€ãæ±ããããã°ã©ã ãäœæããïŒ ãã ãïŒãåç£ãè²·ãæéã¯ç¡èŠã§ãããšãïŒåãåç£åºã« 2 床以äžèšªãããšãã¯æåã«èšªãããšãã ããåç£ãè²·ãïŒ å
¥å å
¥å㯠1 + H è¡ãããªãïŒ 1 è¡ç®ã«ã¯ïŒ3 ã€ã®æŽæ° H, W, K (2 ⊠H ⊠50, 2 ⊠W ⊠50, 1 ⊠K ⊠3) ã空çœãåºåããšããŠæžãããŠããïŒ ç¶ã H è¡ã«ã¯ãããã W æåãããªãæååãæžãããŠããïŒåºç»ã®æ
å ±ã衚ãïŒåãã i çªç®ïŒè¥¿ãã j çªç®ã®åºç»ã (i, j) ãšè¡šã (1 ⊠i ⊠H, 1 ⊠j ⊠W)ïŒ i è¡ç®ã® j çªç®ã®æåã¯ïŒåºç» (i, j) ãéãåœé空枯ã§ããå Žå㯠'.' ã§ããïŒäœå®
ã§ããå Žå㯠'#' ã§ããïŒ åç£åºã§ããå Žå㯠'1', '2', ..., '9' ã®ããããã§ããïŒãã®åç£åºã§è²·ãããšãã§ãããåç£ã®åæ°ã衚ãïŒ äžããããå
¥åããŒã¿ã«ãããŠã¯ïŒJOI åãã¯ããã«ããæãå西ã®åºç»ãéã§ããããšã¯ä¿èšŒãããŠããïŒãŸãïŒJOI åãåœé空枯ã«ãã©ãçããããšã¯ä¿èšŒãããŠããïŒ åºå JOI åã賌å
¥ã§ãããåç£ã®åæ°ã®æå€§å€ãè¡šãæŽæ°ã 1 è¡ã§åºåããïŒ å
¥åºåäŸ å
¥åäŸ 1 5 4 2 ...# .#.# .#73 8##. .... åºåäŸ 1 11 å
¥åºåäŸ 1 ã«ãããŠïŒJOI å㯠3 ååãžé²ã¿åºç» (4, 1) ã®åç£åºã§è²·ãç©ãããåŸïŒããã«åãž 1 åïŒæ±ãž 3 åé²ã¿ïŒããããåãž 2 åé²ãããšã§åºç» (3, 4) ã®åç£åºã§è²·ãç©ãããïŒæåŸã«åãž 2 åé²ãã§åœé空枯ãžãã©ãçããšïŒåèšã§ 11 åã®ãåç£ãè²·ãããšãã§ããïŒ å
¥åäŸ 2 4 4 3 .8#9 9.#. .#9. .... åºåäŸ 2 27 å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã | 35,841 |
Score : 600 points Problem Statement There are 2N people numbered 1 through 2N . The height of Person i is h_i . How many ways are there to make N pairs of people such that the following conditions are satisfied? Compute the answer modulo 998,244,353 . Each person is contained in exactly one pair. For each pair, the heights of the two people in the pair are different. Two ways are considered different if for some p and q , Person p and Person q are paired in one way and not in the other. Constraints 1 \leq N \leq 50,000 1 \leq h_i \leq 100,000 All values in input are integers. Input Input is given from Standard Input in the following format: N h_1 : h_{2N} Output Print the answer. Sample Input 1 2 1 1 2 3 Sample Output 1 2 There are two ways: Form the pair (Person 1 , Person 3 ) and the pair (Person 2 , Person 4 ). Form the pair (Person 1 , Person 4 ) and the pair (Person 2 , Person 3 ). Sample Input 2 5 30 10 20 40 20 10 10 30 50 60 Sample Output 2 516 | 35,842 |
Score: 300 points Problem Statement Mr. Infinity has a string S consisting of digits from 1 to 9 . Each time the date changes, this string changes as follows: Each occurrence of 2 in S is replaced with 22 . Similarly, each 3 becomes 333 , 4 becomes 4444 , 5 becomes 55555 , 6 becomes 666666 , 7 becomes 7777777 , 8 becomes 88888888 and 9 becomes 999999999 . 1 remains as 1 . For example, if S is 1324 , it becomes 1333224444 the next day, and it becomes 133333333322224444444444444444 the day after next. You are interested in what the string looks like after 5 \times 10^{15} days. What is the K -th character from the left in the string after 5 \times 10^{15} days? Constraints S is a string of length between 1 and 100 (inclusive). K is an integer between 1 and 10^{18} (inclusive). The length of the string after 5 \times 10^{15} days is at least K . Input Input is given from Standard Input in the following format: S K Output Print the K -th character from the left in Mr. Infinity's string after 5 \times 10^{15} days. Sample Input 1 1214 4 Sample Output 1 2 The string S changes as follows: Now: 1214 After one day: 12214444 After two days: 1222214444444444444444 After three days: 12222222214444444444444444444444444444444444444444444444444444444444444444 The first five characters in the string after 5 \times 10^{15} days is 12222 . As K=4 , we should print the fourth character, 2 . Sample Input 2 3 157 Sample Output 2 3 The initial string is 3 . The string after 5 \times 10^{15} days consists only of 3 . Sample Input 3 299792458 9460730472580800 Sample Output 3 2 | 35,843 |
Problem D: Lowest Pyramid You are constructing a triangular pyramid with a sheet of craft paper with grid lines. Its base and sides are all of triangular shape. You draw the base triangle and the three sides connected to the base on the paper, cut along the outer six edges, fold the edges of the base, and assemble them up as a pyramid. You are given the coordinates of the base's three vertices, and are to determine the coordinates of the other three. All the vertices must have integral X- and Y-coordinate values between -100 and +100 inclusive. Your goal is to minimize the height of the pyramid satisfying these conditions. Figure 3 shows some examples. Figure 3: Some craft paper drawings and side views of the assembled pyramids Input The input consists of multiple datasets, each in the following format. X 0 Y 0 X 1 Y 1 X 2 Y 2 They are all integral numbers between -100 and +100 inclusive. ( X 0 , Y 0 ), ( X 1 , Y 1 ), ( X 2 , Y 2 ) are the coordinates of three vertices of the triangular base in counterclockwise order. The end of the input is indicated by a line containing six zeros separated by a single space. Output For each dataset, answer a single number in a separate line. If you can choose three vertices ( X a , Y a ), ( X b , Y b ) and ( X c , Y c ) whose coordinates are all integral values between -100 and +100 inclusive, and triangles ( X 0 , Y 0 )-( X 1 , Y 1 )-( X a , Y a ), ( X 1 , Y 1 )-( X 2 , Y 2 )-( X b , Y b ), ( X 2 , Y 2 )-( X 0 , Y 0 )-( X c , Y c ) and ( X 0 , Y 0 )-( X 1 , Y 1 )-( X 2 , Y 2 ) do not overlap each other (in the XY-plane), and can be assembled as a triangular pyramid of positive (non-zero) height, output the minimum height among such pyramids. Otherwise, output -1. You may assume that the height is, if positive (non-zero), not less than 0.00001. The output should not contain an error greater than 0.00001. Sample Input 0 0 1 0 0 1 0 0 5 0 2 5 -100 -100 100 -100 0 100 -72 -72 72 -72 0 72 0 0 0 0 0 0 Output for the Sample Input 2 1.49666 -1 8.52936 | 35,844 |
Score : 200 points Problem Statement AtCoDeer the deer found two rectangles lying on the table, each with height 1 and width W . If we consider the surface of the desk as a two-dimensional plane, the first rectangle covers the vertical range of [0,1] and the horizontal range of [a,a+W] , and the second rectangle covers the vertical range of [1,2] and the horizontal range of [b,b+W] , as shown in the following figure: AtCoDeer will move the second rectangle horizontally so that it connects with the first rectangle. Find the minimum distance it needs to be moved. Constraints All input values are integers. 1â€Wâ€10^5 1â€a,bâ€10^5 Input The input is given from Standard Input in the following format: W a b Output Print the minimum distance the second rectangle needs to be moved. Sample Input 1 3 2 6 Sample Output 1 1 This input corresponds to the figure in the statement. In this case, the second rectangle should be moved to the left by a distance of 1 . Sample Input 2 3 1 3 Sample Output 2 0 The rectangles are already connected, and thus no move is needed. Sample Input 3 5 10 1 Sample Output 3 4 | 35,845 |
w ãæ£æŽæ°ïŒ p ãé·ã2 2 w +1 ã®æååãšããïŒ (w, p) - ã»ã«ãªãŒãããã³ãšã¯æ¬¡ã®ãããªãã®ã§ããïŒ 0 ãŸã㯠1 ã®ç¶æ
ããšãããšã®ã§ããã»ã«ãç¡éåäžæ¬¡å
ã«äžŠãã§ããïŒ æå» 0 ã«ïŒãã¬ãåã¯å¥œããªæéåã®ãã¹ãéžãã§ç¶æ
ã 1 ã«ããããšãã§ããïŒæ®ãã®ã»ã«ã¯ 0 ã§ããïŒ æå» t (> 0) ã®ã»ã« x ã®ç¶æ
f(t, x) ã¯ïŒ f(t â 1, x â w), . . . , f(t â 1, x + w) ã«ãã£ãŠä»¥äžã®ããã«å®ãŸã: \begin{eqnarray} f(t, x) = p[ \sum^w_{i=-w}2^{w+i} f(t â 1, x + i)] \;\;\;\;\;\;\;\;\;\;(1) \end{eqnarray} ãã¬ãåã¯ïŒæå» 0 ã«ã©ã®ããã«åæç¶æ
ãéžãã§ã 1 ã®åæ°ãåæç¶æ
ããå€ãããªããããªã»ã«ãªãŒãããã³ã奜ãã§ããïŒæŽæ° w ãšæåå s ãäžãããããšãïŒèŸæžé ã§ s 以äžã®æåå p ã§ãã£ãŠ (w, p) â ã»ã«ãªãŒãããã³ããã¬ãåã«å¥œããããããªæå°ã® p ãæ±ããïŒ Constraints 1 †w †3 |s| = 2 2 w +1 s ã«çŸããæå㯠'0', '1' ã®ã¿ã§ãã Input w s Output æ¡ä»¶ãæºããæå°ã® p ãåºåããïŒãã®ãããªãã®ãååšããªããšã㯠" no " ãšåºåããïŒ Sample Input 1 1 00011000 Sample Output 1 00011101 Sample Input 2 1 11111111 Sample Output 2 no | 35,846 |
Score : 200 points Problem Statement In some village, there are 999 towers that are 1,(1+2),(1+2+3),...,(1+2+3+...+999) meters high from west to east, at intervals of 1 meter. It had been snowing for a while before it finally stopped. For some two adjacent towers located 1 meter apart, we measured the lengths of the parts of those towers that are not covered with snow, and the results are a meters for the west tower, and b meters for the east tower. Assuming that the depth of snow cover and the altitude are the same everywhere in the village, find the amount of the snow cover. Assume also that the depth of the snow cover is always at least 1 meter. Constraints 1 \leq a < b < 499500(=1+2+3+...+999) All values in input are integers. There is no input that contradicts the assumption. Input Input is given from Standard Input in the following format: a b Output If the depth of the snow cover is x meters, print x as an integer. Sample Input 1 8 13 Sample Output 1 2 The heights of the two towers are 10 meters and 15 meters, respectively. Thus, we can see that the depth of the snow cover is 2 meters. Sample Input 2 54 65 Sample Output 2 1 | 35,847 |
Problem B: Moonlight Farm ããªãã¯å€§äººæ°webã²ãŒã ãã ãŒã³ã©ã€ãç§å Žãã«ç±äžããŠããïŒãã®ã²ãŒã ã®ç®çã¯ïŒçã§äœç©ãè²ãŠïŒãããã売åŽããŠåå
¥ãåŸãŠïŒãã®åå
¥ã«ãã£ãŠç§å Žã倧ããããŠããããšã§ããïŒ ããªãã¯éãçã倧ããããããšèããïŒããã§æå§ãã«ã²ãŒã äžã§è²ãŠãããšã®ã§ããäœç©ãïŒæéãããã®åå
¥å¹çã«ããšã¥ããŠäžŠã¹ãããšã«ããïŒ äœç©ãè²ãŠãã«ã¯çš®ãè²·ããªããã°ãªããªãïŒããã§äœç© i ã®çš®ã®åå㯠L i ïŒå€æ®µã¯ P i ã§ããããäžããããïŒçã«çš®ãæ€ãããšæé A i åŸã«èœãåºãïŒèœãåºãŠããæé B i åŸã«è¥èãåºãïŒè¥èãåºãŠããæé C i åŸã«èãèãïŒèãèã£ãŠããæé D i åŸã«è±ãå²ãïŒè±ãå²ããŠããæé E i åŸã«å®ãæãïŒäžã€ã®çš®ãã F i åã®å®ãæãïŒãããã®å®ã¯äžã€ããã S i ã®äŸ¡æ Œã§å£²ããïŒäžéšã®äœç©ã¯å€æäœã§ããïŒèš M i åå®ãã€ããïŒåæäœã®å Žå㯠M i = 1ã§è¡šãããïŒå€æäœã®äœç©ã¯ïŒ M i åç®ã®å®ãæããŸã§ã¯ïŒå®ãæã£ãããšèã«æ»ãïŒããçš®ã«å¯Ÿããåå
¥ã¯ïŒãã®çš®ããæã£ãå
šãŠã®å®ã売ã£ãéé¡ããïŒçš®ã®å€æ®µãåŒããå€ã§ããïŒãŸãïŒãã®çš®ã®åå
¥å¹çã¯ïŒãã®åå
¥ãïŒçš®ãæ€ããŠããå
šãŠã®å®ãæãçµãããŸã§ã®æéã§å²ã£ãå€ã§ããïŒ ããªãã®ä»äºã¯ïŒå
¥åãšããŠäžããããäœç©ã®æ
å ±ã«å¯ŸããŠïŒããããåå
¥å¹çã®éé ã«äžŠã¹æ¿ããŠåºåããããã°ã©ã ãæžãããšã§ããïŒ Input å
¥åã¯ããŒã¿ã»ããã®åã§ããïŒåããŒã¿ã»ããã¯æ¬¡ã®ãããªåœ¢åŒã§äžããããïŒ N L 1 P 1 A 1 B 1 C 1 D 1 E 1 F 1 S 1 M 1 L 2 P 2 A 2 B 2 C 2 D 2 E 2 F 2 S 2 M 2 ... L N P N A N B N C N D N E N F N S N M N äžè¡ç®ã¯ããŒã¿ã»ããã«å«ãŸããäœç©ã®æ° N ã§ãã (1 †N †50)ïŒ ããã«ç¶ã N è¡ã«ã¯ïŒåè¡ã«äžã€ã®äœç©ã®æ
å ±ãå«ãŸããïŒå倿°ã®æå³ã¯å顿äžã§è¿°ã¹ãéãã§ããïŒäœç©ã®åå L i ã¯ã¢ã«ãã¡ãããå°æåã®ã¿ãããªã20æå以å
ã®æååã§ããïŒãŸã 1 †P i , A i , B i , C i , D i , E i , F i , S i †100, 1 †M i †5ã§ããïŒäžã€ã®ã±ãŒã¹å
ã«åäžã®ååãæã€äœç©ã¯ååšããªããšä»®å®ããŠè¯ãïŒ å
¥åã®çµãã¯ãŒããäžã€ã ãå«ãè¡ã§è¡šãããïŒ Output åããŒã¿ã»ããã«ã€ããŠïŒåè¡ã«äžã€ïŒäœç©ã®ååãåå
¥å¹çã®éé ã«åºåããïŒåå
¥å¹çãåãäœç©ã«å¯ŸããŠã¯ïŒãããã®ååãèŸæžé ã®æé ã«åºåããïŒ åããŒã¿ã»ããã®åºåã®åŸã«ã¯â#âã®ã¿ãããªã1è¡ãåºåããããšïŒ Sample Input 5 apple 1 1 1 1 1 1 1 10 1 banana 1 2 2 2 2 2 1 10 1 carrot 1 2 2 2 2 2 1 10 2 durian 1 3 3 3 3 3 1 10 1 eggplant 1 3 3 3 3 3 1 100 1 4 enoki 1 3 3 3 3 3 1 10 1 tomato 1 3 3 3 3 3 1 10 1 potato 1 3 3 3 3 3 1 10 1 onion 1 3 3 3 3 3 1 10 1 3 a 10 1 1 1 1 1 1 10 1 b 10 2 2 2 2 2 2 10 1 c 10 2 2 2 2 2 2 10 1 0 Output for the Sample Input eggplant apple carrot banana durian # enoki onion potato tomato # b c a # | 35,848 |
Problem I: Beautiful Spacing Text is a sequence of words, and a word consists of characters. Your task is to put words into a grid with W columns and sufficiently many lines. For the beauty of the layout, the following conditions have to be satisfied. The words in the text must be placed keeping their original order. The following figures show correct and incorrect layout examples for a 4 word text "This is a pen" into 11 columns. Figure I.1: A good layout. Figure I.2: BAD | Do not reorder words. Between two words adjacent in the same line, you must place at least one space character. You sometimes have to put more than one space in order to meet other conditions. Figure I.3: BAD | Words must be separated by spaces. A word must occupy the same number of consecutive columns as the number of characters in it. You cannot break a single word into two or more by breaking it into lines or by inserting spaces. Figure I.4: BAD | Characters in a single word must be contiguous. The text must be justified to the both sides. That is, the first word of a line must startfrom the first column of the line, and except the last line, the last word of a line must end at the last column. Figure I.5: BAD | Lines must be justi ed to both the left and the right sides. The text is the most beautifully laid out when there is no unnecessarily long spaces. For instance, the layout in Figure I.6 has at most 2 contiguous spaces, which is more beautiful than that in Figure I.1, having 3 contiguous spaces. Given an input text and the number of columns, please find a layout such that the length of the longest contiguous spaces between words is minimum. Figure I.6: A good and the most beautiful layout. Input The input consists of multiple datasets, each in the following format. W N x 1 x 2 ... x N W , N , and x i are all integers. W is the number of columns (3 †W †80,000). N is the number of words (2 †N †50,000). x i is the number of characters in the i -th word (1 †x i †( W â1)/2 ). Note that the upper bound on x i assures that there always exists a layout satisfying the conditions. The last dataset is followed by a line containing two zeros. Output For each dataset, print the smallest possible number of the longest contiguous spaces between words. Sample Input 11 4 4 2 1 3 5 7 1 1 1 2 2 1 2 11 7 3 1 3 1 3 3 4 100 3 30 30 39 30 3 2 5 3 0 0 Output for the Sample Input 2 1 2 40 1 | 35,849 |
Problem J: Tree Construction Consider a two-dimensional space with a set of points ( x i , y i ) that satisfy x i < x j and y i > y j for all i < j . We want to have them all connected by a directed tree whose edges go toward either right ( x positive) or upward ( y positive). The figure below shows an example tree. Figure 1: An example tree Write a program that finds a tree connecting all given points with the shortest total length of edges. Input The input begins with a line that contains an integer n (1 <= n <= 1000), the number of points. Then n lines follow. The i -th line contains two integers x i and y i (0 <= x i , y i <= 10000), which give the coordinates of the i -th point. Output Print the total length of edges in a line. Sample Input 1 5 1 5 2 4 3 3 4 2 5 1 Output for the Sample Input 1 12 Sample Input 2 1 10000 0 Output for the Sample Input 2 0 | 35,850 |
Problem A: Pi is Three Ï (spelled pi in English) is a mathematical constant representing the circumference of a circle whose di- ameter is one unit length. The name Ï is said to come from the first letter of the Greek words ÏεÏιÏÎÏεια (meaning periphery) and ÏεÏίΌεÏÏÎ¿Ï (perimeter). Recently, the government of some country decided to allow use of 3, rather than 3.14, as the approximate value of Ï in school (although the decision was eventually withdrawn probably due to the blame of many people). This decision is very surprising, since this approximation is far less accurate than those obtained before the common era. Ancient mathematicians tried to approximate the value of Ï without calculators. A typical method was to calculate the perimeter of inscribed and circumscribed regular polygons of the circle. For example, Archimedes (287â212 B.C.) proved that 223/71 < Ï < 22/7 using 96-sided polygons, where 223/71 and 22/7 were both accurate to two fractional digits (3.14). The resultant approximation would be more accurate as the number of vertices of the regular polygons increased. As you see in the previous paragraph, Ï was approximated by fractions rather than decimal numbers in the older ages. In this problem, you are requested to represent Ï as a fraction with the smallest possible denominator such that the representing value is not different by more than the given allowed error. If more than one fraction meets this criterion, the fraction giving better approximation is preferred. Input The input consists of multiple datasets. Each dataset has a real number R (0 < R †1) representing the allowed difference between the fraction and Ï . The value may have up to seven digits after the decimal point. The input is terminated by a line containing 0.0, which must not be processed. Output For each dataset, output the fraction which meets the criteria in a line. The numerator and denominator of the fraction should be separated by a slash as shown in the sample output, and those numbers must be integers. Sample Input 0.15 0.05 0.0 Output for the Sample Input 3/1 19/6 | 35,851 |
Score : 100 points Problem Statement The window of Takahashi's room has a width of A . There are two curtains hung over the window, each of which has a horizontal length of B . (Vertically, the curtains are long enough to cover the whole window.) We will close the window so as to minimize the total horizontal length of the uncovered part of the window. Find the total horizontal length of the uncovered parts of the window then. Constraints 1 \leq A \leq 100 1 \leq B \leq 100 A and B are integers. Input Input is given from Standard Input in the following format: A B Output Print the total horizontal length of the uncovered parts of the window. Sample Input 1 12 4 Sample Output 1 4 We have a window with a horizontal length of 12 , and two curtains, each of length 4 , that cover both ends of the window, for example. The uncovered part has a horizontal length of 4 . Sample Input 2 20 15 Sample Output 2 0 If the window is completely covered, print 0 . Sample Input 3 20 30 Sample Output 3 0 Each curtain may be longer than the window. | 35,852 |
Score : 2000 points Problem Statement You are given a permutation P_1 ... P_N of the set { 1 , 2 , ..., N }. You can apply the following operation to this permutation, any number of times (possibly zero): Choose two indices i,j (1 ⊠i < j ⊠N) , such that j - i â§ K and |P_i - P_j| = 1 . Then, swap the values of P_i and P_j . Among all permutations that can be obtained by applying this operation to the given permutation, find the lexicographically smallest one. Constraints 2âŠNâŠ500,000 1âŠKâŠN-1 P is a permutation of the set { 1 , 2 , ..., N }. Input The input is given from Standard Input in the following format: N K P_1 P_2 ... P_N Output Print the lexicographically smallest permutation that can be obtained. Sample Input 1 4 2 4 2 3 1 Sample Output 1 2 1 4 3 One possible way to obtain the lexicographically smallest permutation is shown below: 4 2 3 1 4 1 3 2 3 1 4 2 2 1 4 3 Sample Input 2 5 1 5 4 3 2 1 Sample Output 2 1 2 3 4 5 Sample Input 3 8 3 4 5 7 8 3 1 2 6 Sample Output 3 1 2 6 7 5 3 4 8 | 35,853 |
Score : 300 points Problem Statement Snuke loves puzzles. Today, he is working on a puzzle using S - and c -shaped pieces. In this puzzle, you can combine two c -shaped pieces into one S -shaped piece, as shown in the figure below: Snuke decided to create as many Scc groups as possible by putting together one S -shaped piece and two c -shaped pieces. Find the maximum number of Scc groups that can be created when Snuke has N S -shaped pieces and M c -shaped pieces. Constraints 1 †N,M †10^{12} Input The input is given from Standard Input in the following format: N M Output Print the answer. Sample Input 1 1 6 Sample Output 1 2 Two Scc groups can be created as follows: Combine two c -shaped pieces into one S -shaped piece Create two Scc groups, each from one S -shaped piece and two c -shaped pieces Sample Input 2 12345 678901 Sample Output 2 175897 | 35,854 |
Drawing Lots Let's play Amidakuji. In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines. In the starting points (top of the figure), numbers are assigned to vertical lines in ascending order from left to right. At the first step, 2 and 4 are swaped by the first horizontal line which connects second and fourth vertical lines (we call this operation (2, 4)). Likewise, we perform (3, 5), (1, 2) and (3, 4), then obtain "4 1 2 5 3" in the bottom. Your task is to write a program which reads the number of vertical lines w and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., w are assigne to the vertical lines from left to right. Input w n a 1 , b 1 a 2 , b 2 . . a n , b n w ( w †30) is the number of vertical lines. n ( n †30) is the number of horizontal lines. A pair of two integers a i and b i delimited by a comma represents the i -th horizontal line. Output The number which should be under the 1st (leftmost) vertical line The number which should be under the 2nd vertical line : The number which should be under the w -th vertical line Sample Input 5 4 2,4 3,5 1,2 3,4 Output for the Sample Input 4 1 2 5 3 | 35,855 |
æå€ã®éºè·¡ åé¡ æ, ããã«ã¯éèœããã, å€ãã®äººãæ®ãããŠãã. 人ã
ã¯åœ¢ã倧ãããæ§ã
ãªå»ºç©ã建ãŠã. ã ã, ãããã®å»ºé ç©ã¯æ¢ã«å€±ãã, æç®ãš, éºè·¡ããèŠã€ãã£ãæ±ã ãã建é ç©ã®äœçœ®ãç¥ãæãããã ã£ã. æç®ã«ã¯ç¥æ®¿ã®èšè¿°ããã. ç¥æ®¿ã¯äžããèŠããšæ£ç¢ºã«æ£æ¹åœ¢ã«ãªã£ãŠãã, ãã®åé
ã«ã¯æ±ããã£ã. ç¥æ®¿ãã©ã®åããåããŠãããã¯ããããªã. ãŸã, 蟺äžãå
éšã«æ±ããã£ããã©ãããããããªã. èå€åŠè
ãã¡ã¯, éºè·¡ããèŠã€ãã£ãæ±ã®äžã§, æ£æ¹åœ¢ã«ãªã£ãŠãããã®ã®ãã¡, é¢ç©ãæå€§ã®ãã®ãç¥æ®¿ã«éããªããšèãã. æ±ã®äœçœ®ã®åº§æšãäžããããã®ã§, 4 æ¬ã®æ±ã§ã§ããæ£æ¹åœ¢ã®ãã¡é¢ç©ãæå€§ã®ãã®ãæ¢ã, ãã®é¢ç©ãåºåããããã°ã©ã ãæžã. ãªã, æ£æ¹åœ¢ã®èŸºã¯åº§æšè»žã«å¹³è¡ãšã¯éããªãããšã«æ³šæãã. äŸ äžã®å³ã®äŸã§ã¯, 10 æ¬ã®æ±ããã, åº§æš (4, 2), (5, 2), (5, 3), (4, 3) ã«ãã 4 æ¬ãšåº§æš (1, 1), (4, 0), (5, 3), (2, 4) ã«ãã 4 æ¬ãæ£æ¹åœ¢ããªããŠãã. é¢ç©ãæå€§ã®æ£æ¹åœ¢ã¯åŸè
ã§, ãã®é¢ç©ã¯ 10 ã§ãã. å
¥å å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããïŒå
¥åã¯ãŒãïŒã€ãå«ãè¡ã§çµäºããïŒ 1 è¡ç®ã«ã¯, éºè·¡ããèŠã€ãã£ãæ±ã®æ¬æ° n ãæžãããŠãã. 2 è¡ç®ãã n + 1 è¡ç®ãŸã§ã® n è¡ã®åã
ã«ã¯, æ±ã® x 座æšãš y 座æšã空çœåºåãã§æžãããŠãã. 1 æ¬ã®æ±ã 2 床以äžçŸããããšã¯ãªã. n 㯠1 †n †3000 ãæºããæŽæ°ã§ãã, æ±ã® x 座æšãš y 座æšã¯ 0 ä»¥äž 5000 以äžã®æŽæ°ã§ãã. æ¡ç¹çšããŒã¿ã®ãã¡, é
ç¹ã® 30% å㯠1 †n †100 ãæºãã, é
ç¹ã® 60% åã¯1 †n †500 ãæºãã. ããŒã¿ã»ããã®æ°ã¯ 10 ãè¶
ããªãïŒ åºå ããŒã¿ã»ããããšã« 1 åã®æŽæ°ãåºåãã. 4 æ¬ã®æ±ãããªãæ£æ¹åœ¢ãååšããå Žåã¯, ãã®ãããªæ£æ¹åœ¢ã®ãã¡é¢ç©ãæå€§ã®ãã®ã®é¢ç©ãåºåã, ãã®ãããªæ£æ¹åœ¢ãååšããªãå Žå㯠0 ãåºåãã. å
¥åºåäŸ å
¥åäŸ 10 9 4 4 3 1 1 4 2 2 4 5 8 4 0 5 3 0 5 5 2 10 9 4 4 3 1 1 4 2 2 4 5 8 4 0 5 3 0 5 5 2 0 åºåäŸ 10 10 äžèšå顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã | 35,856 |
E: ç·åã®åãåã åé¡ ãã³ã¡ããã¯æ°å (a_1, a_2, ..., a_n) ãæã£ãŠããŸãã ãã³ã¡ããã¯ïŒç©ºã§ãããïŒéšåé
åã®ç·åã®æå€§å€ãæ°ã«ãªãã®ã§ããããæ±ããŠãã ããã ããã§ãéšåé
åãšã¯é£ç¶ããéšååãæããŸãããªãã空åã®ç·å㯠0 ãšããŸãã ããã«ããã³ã¡ããããã®æ°åã q åæžãæããã®ã§ãåæžãæãã®çŽåŸã«ãã®å€ãæ±ããŠãã ããã å
¥ååœ¢åŒ n q a_1 a_2 ... a_n k_1 x_1 ... k_q x_q å k_j , x_j ( 1 \leq j \leq q ) ã¯ã a_{k_j} ã x_j ã«æžãæããããšãæå³ããŸãã åæžãæãã¯ç¬ç«ã§ã¯ãªãããã®åŸã®åŠçã«ãããŠé
åã¯æžãæãããããŸãŸã§ããããšã«æ³šæããŠãã ããã å¶çŽ 1\leq n\leq 10^5 1\leq q\leq 10^5 1\leq k_j\leq n |a_i|, |x_j| \leq 10^9 åºååœ¢åŒ q+1 è¡åºåããŠãã ããã 1 è¡ç®ã«ã¯æžãæããè¡ãåã®ã 1+i è¡ç®ã«ã¯ i åç®ã®æžãæãã®çŽåŸã®éšåé
åã®ç·åã®æå€§å€ãåºåããŠãã ããã å
¥åäŸ1 5 2 1 2 -3 4 -5 3 3 2 -6 åºåäŸ1 4 10 7 éšåé
å (a_l, âŠ, a_r) ã a[l, r] ãšè¡šãããšã«ãããšãæžãæãå㯠a[1, 4] ããã³ a[4, 4] ã®ç·åã 4 ã§ããããæå€§ã§ãã 1 åç®ã®æžãæãã®åŸãæ°å㯠(1, 2, 3, 4, -5) ãšãªããç·åã®æå€§å€ã¯ a[1, 4] ã® 10 ã§ãã 2 åç®ã®æžãæãã®åŸãæ°å㯠(1, -6, 3, 4, -5) ãšãªããç·åã®æå€§å€ã¯ a[3, 4] ã® 7 ã§ãã å
¥åäŸ2 3 1 -1 -2 -3 1 1 åºåäŸ2 0 1 空åã®ç·å㯠0 ã§ãããæžãæãåã¯ãããæå€§ã§ãã | 35,857 |
Get a Rectangular Field Karnaugh is a poor farmer who has a very small field. He wants to reclaim wasteland in the kingdom to get a new field. But the king who loves regular shape made a rule that a settler can only get a rectangular land as his field. Thus, Karnaugh should get the largest rectangular land suitable for reclamation. The map of the wasteland is represented with a 5 x 5 grid as shown in the following figures, where '1' represents a place suitable for reclamation and '0' represents a sandy place. Your task is to find the largest rectangle consisting only of 1's in the map, and to report the size of the rectangle. The size of a rectangle is defined by the number of 1's in it. Note that there may be two or more largest rectangles of the same size. Figure 1. The size of the largest rectangles is 4. There are two largest rectangles (shaded). Figure 2. The size of the largest rectangle is 3. There is one largest rectangle (shaded). Input The input consists of maps preceded by an integer m indicating the number of input maps. m map 1 map 2 map 3 ... map m Two maps are separated by an empty line. Each map k is in the following format: p p p p p p p p p p p p p p p p p p p p p p p p p Each p is a character either '1' or '0'. Two p 's in the same line are separated by a space character. Here, the character '1' shows a place suitable for reclamation and '0' shows a sandy place. Each map contains at least one '1'. Output The size of the largest rectangle(s) for each input map should be shown each in a separate line. Sample Input 3 1 1 0 1 0 0 1 1 1 1 1 0 1 0 1 0 1 1 1 0 0 1 1 0 0 0 1 0 1 1 0 1 0 1 0 0 0 1 0 0 0 0 1 1 0 1 0 1 0 0 1 1 1 1 0 0 1 1 1 0 0 1 1 0 1 0 1 1 1 0 0 0 0 0 1 Output for the Sample Input 4 3 8 | 35,858 |
ã«ãžã ããªãã®å€ããŠããäŒç€Ÿã§ã¯æ°ããªã«ãžãã²ãŒã ã®éçºãããŠããïŒä»æ¥ã¯æè¿ææ¡ãããã²ãŒã ã«ã€ããŠèå¯ããŠã¿ãããšã«ããïŒ ãã®ã²ãŒã ã§ã¯ N åã®ãµã€ã³ããåæã«æ¯ã£ãŠïŒåºãç®ã®åèšãåŸç¹ãšãªãïŒãã¬ã€ã€ãŒã¯åŸç¹ã倧ããããããšãç®æšãšããŠãã¬ãŒããïŒããåºãç®ãæ°ã«å
¥ããªããã°ãµã€ã³ããæ¯ãçŽãããšãã§ãããïŒãã®æã¯ N åã®ãµã€ã³ãå
šãŠãåæã«æ¯ãçŽããªããã°ãªããªãïŒãŸãïŒãµã€ã³ããæ¯ãããšã®ã§ããåæ°ã¯æå€§ã§ M åã§ããïŒååã«å€§ããç®ãåºããšæã£ãã®ã§ããã°ïŒ M åããå°ãªãåæ°ã§ã²ãŒã ãçµããŠãè¯ãïŒæåŸã«æ¯ã£ããµã€ã³ãã®ç®ã®åèšãåŸç¹ãšãªãïŒ é©åãªè³ãéãèšå®ããããã«ã¯ïŒåŸç¹ã®æåŸ
å€ãæ±ããªããã°ãªããªãïŒ N ãš M ãäžããããæïŒæé©ãªæŠç¥ããšã£ãå Žåã«åŸãããåŸç¹ã®æåŸ
å€ãæ±ããã®ã仿¥ã®ããªãã®ä»äºã§ããïŒ ãã ãïŒãã®ã²ãŒã ã§çšãããµã€ã³ãã«ã¯ 1 ãã 6 ãŸã§ã®ç®ãããïŒããããã®ç®ãåºã確çã¯åãã§ããïŒ Input å
¥åã¯æå€§ã§ 100 åã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯æ¬¡ã®åœ¢åŒã§è¡šãããïŒ N M æŽæ° N ïŒ M 㯠1 †N †20 ïŒ 1 †M †10 10 ãæºããïŒ å
¥åã®çµãã㯠2 ã€ã®ãŒããããªãè¡ã§è¡šãããïŒ Output åããŒã¿ã»ããã«ã€ããŠïŒæé©ãªæŠç¥ããšã£ãæã®æåŸ
å€ãäžè¡ã«åºåããïŒåºåã«ã¯ 10 -2 ãè¶
ãã絶察誀差ããã£ãŠã¯ãªããªãïŒãã®åé¡ã¯èšç®èª€å·®ã倧ãããªãè§£æ³ãæ³å®ãããããïŒç²ŸåºŠã®ããåãçšããããšãæšå¥šãããïŒ Sample Input 1 2 2 1 2 2 0 0 Output for the Sample Input 4.25 7 7.9722222222 | 35,859 |
RMQ and RAQ Write a program which manipulates a sequence $A$ = {$a_0, a_1, ..., a_{n-1}$} with the following operations: $add(s, t, x)$ : add $x$ to $a_s, a_{s+1}, ..., a_t$. $find(s, t)$ : report the minimum value in $a_s, a_{s+1}, ..., a_t$. Note that the initial values of $a_i ( i = 0, 1, ..., n-1 )$ are 0. Input $n$ $q$ $query_1$ $query_2$ : $query_q$ In the first line, $n$ (the number of elements in $A$) and $q$ (the number of queries) are given. Then, $i$th query $query_i$ is given in the following format: 0 $s$ $t$ $x$ or 1 $s$ $t$ The first digit represents the type of the query. '0' denotes $add(s, t, x)$ and '1' denotes $find(s, t)$. Output For each $find$ query, print the minimum value. Constraints $1 †n †100000$ $1 †q †100000$ $0 †s †t < n$ $-1000 †x †1000$ Sample Input 1 6 7 0 1 3 1 0 2 4 -2 1 0 5 1 0 1 0 3 5 3 1 3 4 1 0 5 Sample Output 1 -2 0 1 -1 | 35,860 |
Score : 400 points Problem Statement Given is a string S consisting of digits from 1 through 9 . Find the number of pairs of integers (i,j) ( 1 †i †j †|S| ) that satisfy the following condition: Condition: In base ten, the i -th through j -th characters of S form an integer that is a multiple of 2019 . Constraints 1 †|S| †200000 S is a string consisting of digits from 1 through 9 . Input Input is given from Standard Input in the following format: S Output Print the number of pairs of integers (i,j) ( 1 †i †j †|S| ) that satisfy the condition. Sample Input 1 1817181712114 Sample Output 1 3 Three pairs - (1,5) , (5,9) , and (9,13) - satisfy the condition. Sample Input 2 14282668646 Sample Output 2 2 Sample Input 3 2119 Sample Output 3 0 No pairs satisfy the condition. | 35,861 |
Score : 1000 points Problem Statement There are N integers written on a blackboard. The i -th integer is A_i , and the greatest common divisor of these integers is 1 . Takahashi and Aoki will play a game using these integers. In this game, starting from Takahashi the two player alternately perform the following operation: Select one integer on the blackboard that is not less than 2 , and subtract 1 from the integer. Then, divide all the integers on the black board by g , where g is the greatest common divisor of the integers written on the blackboard. The player who is left with only 1 s on the blackboard and thus cannot perform the operation, loses the game. Assuming that both players play optimally, determine the winner of the game. Constraints 1 ⊠N ⊠10^5 1 ⊠A_i ⊠10^9 The greatest common divisor of the integers from A_1 through A_N is 1 . Input The input is given from Standard Input in the following format: N A_1 A_2 ⊠A_N Output If Takahashi will win, print First . If Aoki will win, print Second . Sample Input 1 3 3 6 7 Sample Output 1 First Takahashi, the first player, can win as follows: Takahashi subtracts 1 from 7 . Then, the integers become: (1,2,2) . Aoki subtracts 1 from 2 . Then, the integers become: (1,1,2) . Takahashi subtracts 1 from 2 . Then, the integers become: (1,1,1) . Sample Input 2 4 1 2 4 8 Sample Output 2 First Sample Input 3 5 7 8 8 8 8 Sample Output 3 Second | 35,862 |
Problem M: Dial Problem ãã€ã€ã«åŒã®å京é ãããããã®å京é ã«ã¯ã5ã€ã®ãã€ã€ã«ãšã決å®ãã¿ã³ãçšæãããŠããã 5ã€ãããã€ã€ã«ãå転ãããŠ16鲿°ã§5ã±ã¿ã®æŽæ°ãäœããæ±ºå®ãã¿ã³ãæŒããŠå
¥åãããšãå
¥åããå€ãšãã¹ã¯ãŒããäžèŽããŠããã°éãä»çµã¿ã«ãªã£ãŠããã5ã€ã®ãã€ã€ã«ããããã«ã¯ 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,0,1,2, ... ã®é ã§æåãçŸããããã«æžãããŠããã æã¡äž»ã¯ãã¹ã¯ãŒããå¿ããŠããŸã£ãããããããã¹ã¯ãŒãã®5ã±ã¿ã®ãã¡ã1ã€ã®ã±ã¿ã ããå¶æ°ã§æ®ã4ã€ã¯å¥æ°ã§ãã£ãããšã¯èŠããŠããã ãã ããå¶æ°ãšã¯0,2,4,6,8,a,c,eã§ããã奿°ãšã¯1,3,5,7,9,b,d,fã§ããã ãŸããã®éµã¯äžè¯åã§ã以äžã®æ¡ä»¶ã§ãã¹ã¯ãŒããšç°ãªãæ°åãå
¥åããŠãéããŠããŸãããšãåãã£ãŠãããæ¬æ¥ãå
¥åããæŽæ°ãšãã¹ã¯ãŒãã5ã€ã®ã±ã¿ãã¹ãŠã«ã€ããŠäžèŽããŠããªããã°éµã¯éããªãããããããã¹ã¯ãŒãã®å¶æ°ãšãªã£ãŠããã±ã¿ã i ã±ã¿ç®ã ã£ãå Žåã i ã±ã¿ç®ã®äžèŽå€å®ãè¡ããšãããã®å¶æ°ã®ååŸã«ãã奿°ãå
¥åãããŠããå Žåã§ã i ã±ã¿ç®ã¯äžèŽããŠãããšèª€å€å®ãããŠããŸãã®ã ã äŸãã°ããã¹ã¯ãŒãã"57677"ã®å京é ãªãã°ã'6'ã®ååŸã«ã¯'5'ãš'7'ã®å¥æ°ããããã"57677"ã®ã»ãã«ã"57577"ã"57777"ãå
¥åãããšãã§ãéããŠããŸãã åæ§ã«ããã¹ã¯ãŒãã"130bd"ã®å京é ãªãã°ã'0'ã®ååŸã«ã¯'1'ãš'f'ã®å¥æ°ããããã"130bd"ã®ã»ãã«ã"13fbd"ã"131bd"ãå
¥åãããšãã§ãéããŠããŸãã ä»ããã¹ã¯ãŒãã®åè£ã N åããããããã®ãã¡ã©ãã1ã€ãæ£è§£ã®ãã¹ã¯ãŒãã§ããããšãåãã£ãŠããããããããªãã®ã§æã¡äž»ã¯ãéµãéããŸã§äœåºŠãæŽæ°ãå
¥åããŠè©Šãç¶ããããšã«ãããæã¡äž»ã¯ã§ããã ãæ±ºå®ãã¿ã³ãæŒãåæ°ãå°ãªããããã æã¡äž»ãæé©ãªæŠç¥ããšã£ããšããæå€§ã§äœå決å®ãã¿ã³ãæŒããªããã°ãªããªãã ããã? ãã®åæ°ãåºåããã ãŸããå®éã«æå€§ãšãªããšãã«å
¥åããæŽæ°ã®éåãæé ã«åºåããã çããäžæã«å®ãŸããªãå Žåã¯ãèŸæžé ã§æå°ãšãªããã®ãåºåããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã N password 1 password 2 ... password N 1è¡ç®ã« N ãäžããããã 2è¡ç®ãã N +1è¡ç®ã® i è¡ç®ã«ã¯ããã¹ã¯ãŒãã®åè£ã衚ã5ã±ã¿ã®16鲿°ã衚ãæåå password i ãäžããããã Constraints 1 †N †6000 password i â password j ( i < j ) æååã¯ã0ãã9ã®æ°åãŸãã¯è±å°æåaããfã®5æåã§æ§æããããã®ãã¡1æåã¯å¶æ°ã§ãããä»ã®4æåã¯å¥æ°ã§ãã Output éµãéããŸã§ã«æé©ãªæŠç¥ããšã£ããšãã®æ±ºå®ãã¿ã³ãæŒãåæ°ã®æå€§å€ã1è¡ã«åºåããã ç¶ããŠãæå€§ãšãªããšãã«å
¥åããæŽæ°ã®éåãæé ã«åºåããã ãããçããäžæã«å®ãŸããªãå Žåã¯ãèŸæžé ã§æå°ãšãªããã®ãåºåããã Sample Input 1 1 0111f Sample Output 1 1 0111f Sample Input 2 3 57567 57587 0d351 Sample Output 2 2 0d351 57577 Sample Input 3 6 1811b 1a11b f3b1e f3b1c b0df3 bedf3 Sample Output 3 3 1911b bfdf3 f3b1d | 35,863 |
Score : 100 points Problem Statement We call a 4 -digit integer with three or more consecutive same digits, such as 1118 , good . You are given a 4 -digit integer N . Answer the question: Is N good ? Constraints 1000 †N †9999 N is an integer. Input Input is given from Standard Input in the following format: N Output If N is good , print Yes ; otherwise, print No . Sample Input 1 1118 Sample Output 1 Yes N is good , since it contains three consecutive 1 . Sample Input 2 7777 Sample Output 2 Yes An integer is also good when all the digits are the same. Sample Input 3 1234 Sample Output 3 No | 35,864 |
Score : 1000 points Problem Statement Snuke participated in a magic show. A magician prepared N identical-looking boxes. He put a treasure in one of the boxes, closed the boxes, shuffled them, and numbered them 1 through N . Since the boxes are shuffled, now Snuke has no idea which box contains the treasure. Snuke wins the game if he opens a box containing the treasure. You may think that if Snuke opens all boxes at once, he can always win the game. However, there are some tricks: Snuke must open the boxes one by one. After he opens a box and checks the content of the box, he must close the box before opening the next box. He is only allowed to open Box i at most a_i times. The magician may secretly move the treasure from a closed box to another closed box, using some magic trick. For simplicity, assume that the magician never moves the treasure while Snuke is opening some box. However, he can move it at any other time (before Snuke opens the first box, or between he closes some box and opens the next box). The magician can perform the magic trick at most K times. Can Snuke always win the game, regardless of the initial position of the treasure and the movements of the magician? Constraints 2 \leq N \leq 50 1 \leq K \leq 50 1 \leq a_i \leq 100 Input Input is given from Standard Input in the following format: N K a_1 a_2 \cdots a_N Output If the answer is no, print a single -1 . Otherwise, print one possible move of Snuke in the following format: Q x_1 x_2 \cdots x_Q It means that he opens boxes x_1, x_2, \cdots, x_Q in this order. In case there are multiple possible solutions, you can output any. Sample Input 1 2 1 5 5 Sample Output 1 7 1 1 2 1 2 2 1 If Snuke opens the boxes 7 times in the order 1 \rightarrow 1 \rightarrow 2 \rightarrow 1 \rightarrow 2 \rightarrow 2 \rightarrow 1 , he can always find the treasure regardless of its initial position and the movements of the magician. Sample Input 2 3 50 5 10 15 Sample Output 2 -1 | 35,865 |
Score : 1100 points Problem Statement There are 2^N players, numbered 1, 2, ..., 2^N . They decided to hold a tournament. The tournament proceeds as follows: Choose a permutation of 1, 2, ..., 2^N : p_1, p_2, ..., p_{2^N} . The players stand in a row in the order of Player p_1 , Player p_2 , ... , Player p_{2^N} . Repeat the following until there is only one player remaining in the row: Play the following matches: the first player in the row versus the second player in the row, the third player versus the fourth player, and so on. The players who lose leave the row. The players who win stand in a row again, preserving the relative order of the players. The last player who remains in the row is the champion. It is known that, the result of the match between two players can be written as follows, using M integers A_1, A_2, ..., A_M given as input: When y = A_i for some i , the winner of the match between Player 1 and Player y ( 2 \leq y \leq 2^N ) will be Player y . When y \neq A_i for every i , the winner of the match between Player 1 and Player y ( 2 \leq y \leq 2^N ) will be Player 1 . When 2 \leq x < y \leq 2^N , the winner of the match between Player x and Player y will be Player x . The champion of this tournament depends only on the permutation p_1, p_2, ..., p_{2^N} chosen at the beginning. Find the number of permutation p_1, p_2, ..., p_{2^N} chosen at the beginning of the tournament that would result in Player 1 becoming the champion, modulo 10^9 + 7 . Constraints 1 \leq N \leq 16 0 \leq M \leq 16 2 \leq A_i \leq 2^N ( 1 \leq i \leq M ) A_i < A_{i + 1} ( 1 \leq i < M ) Input Input is given from Standard Input in the following format: N M A_1 A_2 ... A_M Output Print the answer. Sample Input 1 2 1 3 Sample Output 1 8 Examples of p that satisfy the condition are: [1, 4, 2, 3] and [3, 2, 1, 4] . Examples of p that do not satisfy the condition are: [1, 2, 3, 4] and [1, 3, 2, 4] . Sample Input 2 4 3 2 4 6 Sample Output 2 0 Sample Input 3 3 0 Sample Output 3 40320 Sample Input 4 3 3 3 4 7 Sample Output 4 2688 Sample Input 5 16 16 5489 5490 5491 5492 5493 5494 5495 5497 18993 18995 18997 18999 19000 19001 19002 19003 Sample Output 5 816646464 | 35,866 |
Score : 1000 points Problem Statement Note the unusual memory limit. For a rectangular grid where each square is painted white or black, we define its complexity as follows: If all the squares are black or all the squares are white, the complexity is 0 . Otherwise, divide the grid into two subgrids by a line parallel to one of the sides of the grid, and let c_1 and c_2 be the complexities of the subgrids. There can be multiple ways to perform the division, and let m be the minimum value of \max(c_1, c_2) in those divisions. The complexity of the grid is m+1 . You are given a grid with H horizontal rows and W vertical columns where each square is painted white or black. HW characters from A_{11} to A_{HW} represent the colors of the squares. A_{ij} is # if the square at the i -th row from the top and the j -th column from the left is black, and A_{ij} is . if that square is white. Find the complexity of the given grid. Constraints 1 \leq H,W \leq 185 A_{ij} is # or . . Input Input is given from Standard Input in the following format: H W A_{11} A_{12} ... A_{1W} : A_{H1} A_{H2} ... A_{HW} Output Print the complexity of the given grid. Sample Input 1 3 3 ... .## .## Sample Output 1 2 Let us divide the grid by the boundary line between the first and second columns. The subgrid consisting of the first column has the complexity of 0 , and the subgrid consisting of the second and third columns has the complexity of 1 , so the whole grid has the complexity of at most 2 . Sample Input 2 6 7 .####.# #....#. #....#. #....#. .####.# #....## Sample Output 2 4 | 35,867 |
Problem A: Approximate Circle Consider a set of n points ( x 1 , y 1 ), ..., ( x n , y n ) on a Cartesian space. Your task is to write a program for regression to a circle x 2 + y 2 + a x + b y + c = 0. In other words, your program should find a circle that minimizes the error. Here the error is measured by the sum over square distances between each point and the circle, which is given by: Input The input begins with a line containing one integer n (3 <= n <= 40,000). Then n lines follow. The i -th line contains two integers x i and y i (0 <= x i , y i <= 1,000), which denote the coordinates of the i -th point. You can assume there are no cases in which all the points lie on a straight line. Output Print three integers a , b and c , separated by space, to show the regressed function. The output values should be in a decimal fraction and should not contain an error greater than 0.001. Sample Input 1 4 0 0 100 0 100 100 0 100 Output for the Sample Input 1 -100.000 -100.000 0.000 Sample Input 2 3 0 0 10 0 5 100 Output for the Sample Input 2 -10.000 -99.750 0.000 | 35,868 |
F: ãã¿ã³ã®æš å顿 $N$ é ç¹ $N-1$ 蟺ãããªãæšãããã$i$ çªç®ã®èŸºã¯ $u_i$ çªç®ã®é ç¹ãš $v_i$ çªç®ã®é ç¹ãæ¥ç¶ããŠããŸãã åé ç¹ã«ã¯ãã¿ã³ãå²ããŠããã$i$ çªç®ã®é ç¹ã«å²ããŠãããã¿ã³ããã¿ã³ $i$ ãšåŒã¶ããšã«ããŸãã ã¯ããããã¿ã³ $i$ ã®çŸãã㯠$a_i$ ã§ãã ãã¿ã³ $i$ ãæŒããã³ã«ããã¿ã³ $i$ ã®çŸããã飿¥ãããã¿ã³ã« $1$ ãã€åãäžããŸãã ããªãã¡ã$i$ çªç®ã®é ç¹ã« $c_1, ..., c_k$ çªç®ã®é ç¹ã飿¥ããŠããå Žåããã¿ã³ $i$ ã®çŸããã $k$ æžå°ãããã¿ã³ $c_1, ..., c_k$ ã®çŸããããããã $1$ ãã€å¢å ããŸãã ãã®ãšããè² ã®çŸããã®ãã¿ã³ãæŒããŠãè¯ããããã¿ã³ãæŒããçµæãããã¿ã³ã®çŸãããè² ã«ãªã£ãŠãè¯ãã§ãã ããªãã®ç®çã¯ãã¿ã³ $1, 2, ..., N$ ã®çŸããããããã $b_1, ..., b_N$ ã«ããããšã§ãã æå°ã§åèšäœåãã¿ã³ãæŒãã°ç®çãéæã§ããã§ããããã å¶çŽ å
¥åã¯ãã¹ãп޿°ã§ãã $1 \leq N \leq 10^5$ $1 \leq u_i, v_i \leq N$ $-1000 \leq a_i, b_i \leq 1000$ $\sum_i a_i = \sum_i b_i$ äžããããã°ã©ãã¯æšã§ãã äžããããå
¥åã«ãããŠç®çã¯å¿
ãéæã§ãã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããã $N$ $u_1$ $v_1$ $\vdots$ $u_{N-1}$ $v_{N-1}$ $a_1$ $a_2$ $...$ $a_N$ $b_1$ $b_2$ $...$ $b_N$ åºå ç®çãéæããããã«ãã¿ã³ãæŒãåèšåæ°ã®æå°å€ãåºåããã å
¥åäŸ1 4 1 2 1 3 3 4 0 3 2 0 -3 4 5 -1 åºåäŸ1 4 次ã®ããã«åèš $4$ åãã¿ã³ãæŒãããšã§ç®çãéæã§ãããã®ãšããæå°ã§ãã ãã¿ã³ $1$ ã $2$ åæŒããŸãããã¿ã³ $1, 2, 3, 4$ ã®çŸããããããã $-4, 5, 4, 0$ ã«å€åããŸãã ãã¿ã³ $2$ ã $1$ åæŒããŸããçŸããããããã $-3, 4, 4, 0$ ã«å€åããŸãã ãã¿ã³ $4$ ã $1$ åæŒããŸããçŸããããããã $-3, 4, 5, -1$ ã«å€åããŸãã å
¥åäŸ2 5 1 2 1 3 3 4 3 5 -9 5 7 1 8 -7 4 5 1 9 åºåäŸ2 3 | 35,869 |
Score : 500 points Problem Statement We have N bulbs arranged on a number line, numbered 1 to N from left to right. Bulb i is at coordinate i . Each bulb has a non-negative integer parameter called intensity. When there is a bulb of intensity d at coordinate x , the bulb illuminates the segment from coordinate x-d-0.5 to x+d+0.5 . Initially, the intensity of Bulb i is A_i . We will now do the following operation K times in a row: For each integer i between 1 and N (inclusive), let B_i be the number of bulbs illuminating coordinate i . Then, change the intensity of each bulb i to B_i . Find the intensity of each bulb after the K operations. Constraints 1 \leq N \leq 2 \times 10^5 1 \leq K \leq 2 \times 10^5 0 \leq A_i \leq N Input Input is given from Standard Input in the following format: N K A_1 A_2 \ldots A_N Output Print the intensity A{'}_i of each bulb i after the K operations to Standard Output in the following format: A{'}_1 A{'}_2 \ldots A{'}_N Sample Input 1 5 1 1 0 0 1 0 Sample Output 1 1 2 2 1 2 Initially, only Bulb 1 illuminates coordinate 1 , so the intensity of Bulb 1 becomes 1 after the operation. Similarly, the bulbs initially illuminating coordinate 2 are Bulb 1 and 2 , so the intensity of Bulb 2 becomes 2 . Sample Input 2 5 2 1 0 0 1 0 Sample Output 2 3 3 4 4 3 | 35,870 |
BïŒ éå±€çèšç®æ© (Hierarchical Calculator) Problem Ebi-chan has N formulae: y = a_i x for i =1, ..., N (inclusive). Now she considers a subsequence of indices with length k : s_1 , s_2 , ... , s_k . At first, let x_0 be 1 and evaluate s_1 -th formulae with x = x_0 . Next, let x_1 be the output of s_1 and evaluate s_2 -th formulae with x = x_1 , and so on. She wants to maximize the final output of the procedure, x_{s_k} . If there are many candidates, she wants the """shortest one""". If there are still many candidates, she wants the """lexicographically smallest one""". Sequence s is lexicographically smaller than sequence t , if and only if either of the following conditions hold: there exists m < |s| such that s_i = t_i for i in 1 to m (inclusive) and s_{m+1} < t_{m+1} , or s_i = t_i for i in 1 to |s| (inclusive) and |s| < |t| , where |s| is the length of the s . Input N a_1 a_2 $\cdots$ a_N Constraints 1 \leq N \leq 60 -2 \leq a_i \leq 2 for i=1, ...,N (inclusive) Every input is given as the integer. Output Output k+1 lines. First line, the length of the sequence, k . Following k lines, the index of the i -th element of the subsequence, s_i (one element per line). Sample Input 1 4 2 0 -2 1 Sample Output for Input 1 1 1 She evaluates the first one and gets the maximum value 2 . Sample Input 2 3 2 -2 -2 Sample Output for Input 2 3 1 2 3 She evaluates all of them and gets the maximum value 8 . Sample Input 3 2 -1 0 Sample Output for Input 3 0 She evaluates none of them and gets the maximum value 0 . Empty sequence is the shorter and lexicographically smaller than any other sequences. Sample Input 4 5 -1 2 1 -2 -1 Sample Output for Input 4 3 1 2 4 She evaluates $\langle$ 1, 2, 4 $\rangle$ ones and gets the maximum value 4 . Note that $\langle$ 2, 4, 5 $\rangle$ is not lexicographically smallest one. | 35,871 |
Score : 1500 points Problem Statement We have a grid with 3 rows and N columns. The cell at the i -th row and j -th column is denoted ( i , j ). Initially, each cell ( i , j ) contains the integer i+3j-3 . A grid with N=5 columns Snuke can perform the following operation any number of times: Choose a 3Ã3 subrectangle of the grid. The placement of integers within the subrectangle is now rotated by 180° . An example sequence of operations (each chosen subrectangle is colored blue) Snuke's objective is to manipulate the grid so that each cell ( i , j ) contains the integer a_{i,j} . Determine whether it is achievable. Constraints 5â€Nâ€10^5 1â€a_{i,j}â€3N All a_{i,j} are distinct. Input The input is given from Standard Input in the following format: N a_{1,1} a_{1,2} ... a_{1,N} a_{2,1} a_{2,2} ... a_{2,N} a_{3,1} a_{3,2} ... a_{3,N} Output If Snuke's objective is achievable, print Yes . Otherwise, print No . Sample Input 1 5 9 6 15 12 1 8 5 14 11 2 7 4 13 10 3 Sample Output 1 Yes This case corresponds to the figure in the problem statement. Sample Input 2 5 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Sample Output 2 No Sample Input 3 5 1 4 7 10 13 2 5 8 11 14 3 6 9 12 15 Sample Output 3 Yes The objective is already achieved with the initial placement of the integers. Sample Input 4 6 15 10 3 4 9 16 14 11 2 5 8 17 13 12 1 6 7 18 Sample Output 4 Yes Sample Input 5 7 21 12 1 16 13 6 7 20 11 2 17 14 5 8 19 10 3 18 15 4 9 Sample Output 5 No | 35,872 |
Bozosort Bozosort, as well as Bogosort, is a very inefficient sort algorithm. It is a random number-based algorithm that sorts sequence elements following the steps as below: Randomly select two elements and swap them. Verify if all the elements are sorted in increasing order. Finish if sorted, else return to 1. To analyze Bozosort, you have decided to simulate the process using several predetermined pairs of elements. You are given several commands to swap two elements. Make a program to evaluate how many times you have to run the command before the sequence is aligned in increasing order. Input The input is given in the following format. $N$ $a_1$ $a_2$ ... $a_N$ $Q$ $x_1$ $y_1$ $x_2$ $y_2$ $...$ $x_Q$ $y_Q$ The first line provides the number of sequence elements $N$ ($2 \leq N \leq 300,000$). The second line provides an array of integers $a_i$ ($1 \leq a_i \leq 10^9$) that constitutes the sequence. Each of the subsequent $Q$ lines provides a pair of integers $x_i,y_i$ ($1 \leq x_i,y_i \leq N$) that represent the $i$-th command, which swaps the two elements indicated by $x_i$ and $y_i$ ($x_i \ne y_i$). Output If neat alignment in increasing order is realized the first time after execution of multiple commands, output at what time it was. Output 0 if the initial sequence is aligned in increasing order, and -1 if exhaustive execution still failed to attain the goal. Sample Input 1 6 9 7 5 6 3 1 3 1 6 2 5 3 4 Sample Output 1 2 Sample Input 2 4 4 3 2 1 2 1 2 3 4 Sample Output 2 -1 Sample Input 3 5 1 1 1 2 2 1 1 2 Sample Input 3 0 | 35,873 |
Problem D: Dungeon Wall In 2337, people are bored at daily life and have crazy desire of having extraordinary experience. These days,âDungeon Adventureâ is one of the hottest attractions, where brave adventurers risk their lives to kill the evil monsters and save the world. You are a manager of one of such dungeons. Recently you have been receiving a lot of complaints from soldiers who frequently enter your dungeon; they say your dungeon is too easy and they do not want to enter again. You are considering making your dungeon more difficult by increasing the distance between the entrance and the exit of your dungeon so that more monsters can approach the adventurers. The shape of your dungeon is a rectangle whose width is W and whose height is H . The dungeon is a grid which consists of W à H square rooms of identical size 1 à 1. The southwest corner of the dungeon has the coordinate (0; 0), and the northeast corner has ( W , H ). The outside of the dungeon is surrounded by walls, and there may be some more walls inside the dungeon in order to prevent adventurers from going directly to the exit. Each wall in the dungeon is parallel to either x -axis or y -axis, and both ends of each wall are at integer coordinates. An adventurer can move from one room to another room if they are adjacent vertically or horizontally and have no wall between. You would like to add some walls to make the shortest path between the entrance and the exit longer. However, severe financial situation only allows you to build at most only one wall of a unit length. Note that a new wall must also follow the constraints stated above. Furthermore, you need to guarantee that there is at least one path from the entrance to the exit. You are wondering where you should put a new wall to maximize the minimum number of steps between the entrance and the exit. Can you figure it out? Input W H N sx 0 sy 0 dx 0 dy 0 sx 1 sy 1 dx 1 dy 1 . . . ix iy ox oy The first line contains three integers: W , H and N (1 †W , H †50, 0 †N †1000). They are separated with a space. The next N lines contain the specifications of N walls inside the dungeon. Each wall specification is a line containing four integers. The i -th specification contains sx i , sy i , dx i and dy i , separated with a space. These integers give the position of the i -th wall: it spans from ( sx i , sy i ) to ( dx i , dy i ). The last two lines contain information about the locations of the entrance and the exit. The first line contains two integers ix and iy , and the second line contains two integers ox and oy . The entrance is located at the room whose south-west corner is ( ix , iy ), and the exit is located at the room whose southwest corner is ( ox , oy ). Output Print the maximum possible increase in the minimum number of required steps between the entrance and the exit just by adding one wall. If there is no good place to build a new wall, print zero. Sample Input 1 3 4 4 1 0 1 1 1 3 1 4 1 2 2 2 2 1 2 3 0 0 1 0 Output for the Sample Input 1 6 Sample Input 2 50 2 0 0 0 49 0 Output for the Sample Input 2 2 Sample Input 3 50 2 0 0 0 49 1 Output for the Sample Input 3 0 | 35,874 |
Score: 500 points Problem Statement Does there exist an undirected graph with N vertices satisfying the following conditions? The graph is simple and connected. The vertices are numbered 1, 2, ..., N . Let M be the number of edges in the graph. The edges are numbered 1, 2, ..., M , the length of each edge is 1 , and Edge i connects Vertex u_i and Vertex v_i . There are exactly K pairs of vertices (i,\ j)\ (i < j) such that the shortest distance between them is 2 . If there exists such a graph, construct an example. Constraints All values in input are integers. 2 \leq N \leq 100 0 \leq K \leq \frac{N(N - 1)}{2} Input Input is given from Standard Input in the following format: N K Output If there does not exist an undirected graph with N vertices satisfying the conditions, print -1 . If there exists such a graph, print an example in the following format (refer to Problem Statement for what the symbols stand for): M u_1 v_1 : u_M v_M If there exist multiple graphs satisfying the conditions, any of them will be accepted. Sample Input 1 5 3 Sample Output 1 5 4 3 1 2 3 1 4 5 2 3 This graph has three pairs of vertices such that the shortest distance between them is 2 : (1,\ 4) , (2,\ 4) , and (3,\ 5) . Thus, the condition is satisfied. Sample Input 2 5 8 Sample Output 2 -1 There is no graph satisfying the conditions. | 35,875 |
Score : 700 points Problem Statement Snuke is playing a puzzle game. In this game, you are given a rectangular board of dimensions R à C , filled with numbers. Each integer i from 1 through N is written twice, at the coordinates (x_{i,1},y_{i,1}) and (x_{i,2},y_{i,2}) . The objective is to draw a curve connecting the pair of points where the same integer is written, for every integer from 1 through N . Here, the curves may not go outside the board or cross each other. Determine whether this is possible. Constraints 1 †R,C †10^8 1 †N †10^5 0 †x_{i,1},x_{i,2} †R(1 †i †N) 0 †y_{i,1},y_{i,2} †C(1 †i †N) All given points are distinct. All input values are integers. Input Input is given from Standard Input in the following format: R C N x_{1,1} y_{1,1} x_{1,2} y_{1,2} : x_{N,1} y_{N,1} x_{N,2} y_{N,2} Output Print YES if the objective is achievable; print NO otherwise. Sample Input 1 4 2 3 0 1 3 1 1 1 4 1 2 0 2 2 Sample Output 1 YES The above figure shows a possible solution. Sample Input 2 2 2 4 0 0 2 2 2 0 0 1 0 2 1 2 1 1 2 1 Sample Output 2 NO Sample Input 3 5 5 7 0 0 2 4 2 3 4 5 3 5 5 2 5 5 5 4 0 3 5 1 2 2 4 4 0 5 4 1 Sample Output 3 YES Sample Input 4 1 1 2 0 0 1 1 1 0 0 1 Sample Output 4 NO | 35,876 |
Problem E: The Devil of Gravity Haven't you ever thought that programs written in Java, C++, Pascal, or any other modern computer languages look rather sparse? Although most editors provide sufficient screen space for at least 80 characters or so in a line, the average number of significant characters occurring in a line is just a fraction. Today, people usually prefer readability of programs to efficient use of screen real estate. Dr. Faust, a radical computer scientist, believes that editors for real programmers shall be more space efficient. He has been doing research on saving space and invented various techniques for many years, but he has reached the point where no more essential improvements will be expected with his own ideas. After long thought, he has finally decided to take the ultimate but forbidden approach. He does not hesitate to sacrifice anything for his ambition, and asks a devil to give him supernatural intellectual powers in exchange with his soul. With the transcendental knowledge and ability, the devil provides new algorithms and data structures for space efficient implementations of editors. The editor implemented with those evil techniques is beyond human imaginations and behaves somehow strange. The mighty devil Dr. Faust asks happens to be the devil of gravity. The editor under its control saves space with magical magnetic and gravitational forces. Your mission is to defeat Dr. Faust by re-implementing this strange editor without any help of the devil. At first glance, the editor looks like an ordinary text editor. It presents texts in two-dimensional layouts and accepts editing commands including those of cursor movements and character insertions and deletions. A text handled by the devil's editor, however, is partitioned into text segments, each of which is a horizontal block of non-blank characters. In the following figure, for instance, four text segments " abcdef ", " ghijkl ", " mnop ", " qrstuvw " are present and the first two are placed in the same row. abcdef ghijkl mnop qrstuvw The editor has the following unique features. A text segment without any supporting segments in the row immediately below it falls by the evil gravitational force. Text segments in the same row and contiguous to each other are concatenated by the evil magnetic force. For instance, if characters in the segment " mnop " in the previous example are deleted, the two segments on top of it fall and we have the following. abcdef qrstuvw ghijkl After that, if " x " is added at the tail (i.e., the right next of the rightmost column) of the segment " qrstuvw ", the two segments in the bottom row are concatenated. abcdef qrstuvwxghijkl Now we have two text segments in this figure. By this way, the editor saves screen space but demands the users' extraordinary intellectual power. In general, after a command execution, the following rules are applied, where S is a text segment, left( S ) and right( S ) are the leftmost and rightmost columns of S , respectively, and row( S ) is the row number of S . If the columns from left( S ) to right( S ) in the row numbered row( S )-1 (i.e., the row just below S ) are empty (i.e., any characters of any text segments do not exist there), S is pulled down to row( S )-1 vertically, preserving its column position. If the same ranges in row( S )-2, row( S )-3, and so on are also empty, S is further pulled down again and again. This process terminates sooner or later since the editor has the ultimate bottom, the row whose number is zero. If two text segments S and T are in the same row and right( S )+1 = left( T ), that is, T starts at the right next column of the rightmost character of S , S and T are automatically concatenated to form a single text segment, which starts at left( S ) and ends at right( T ). Of course, the new segment is still in the original row. Note that any text segment has at least one character. Note also that the first rule is applied prior to any application of the second rule. This means that no concatenation may occur while falling segments exist. For instance, consider the following case. dddddddd cccccccc bbbb aaa If the last character of the text segment " bbbb " is deleted, the concatenation rule is not applied until the two segments " cccccccc " and " dddddddd " stop falling. This means that " bbb " and " cccccccc " are not concatenated. The devil's editor has a cursor and it is always in a single text segment, which we call the current segment. The cursor is at some character position of the current segment or otherwise at its tail. Note that the cursor cannot be a support. For instance, in the previous example, even if the cursor is at the last character of " bbbb " and it stays at the same position after the deletion, it cannot support " cccccccc " and " dddddddd " any more by solely itself and thus those two segments shall fall. Finally, the cursor is at the leftmost " d " The editor accepts the following commands, each represented by a single character. F: Move the cursor forward (i.e., to the right) by one column in the current segment. If the cursor is at the tail of the current segment and thus it cannot move any more within the segment, an error occurs. B: Move the cursor backward (i.e., to the left) by one column in the current segment. If the cursor is at the leftmost position of the current segment, an error occurs. P: Move the cursor upward by one row. The column position of the cursor does not change. If the new position would be out of the legal cursor range of any existing text segment, an error occurs. N: Move the cursor downward by one row. The column position of the cursor does not change. If the cursor is in the bottom row or the new position is out of the legal cursor range of any existing text segment, an error occurs. D: Delete the character at the cursor position. If the cursor is at the tail of the current segment and so no character is there, an error occurs. If the cursor is at some character, it is deleted and the current segment becomes shorter by one character. Neither the beginning (i.e., leftmost) column of the current segment nor the column position of the cursor changes. However, if the current segment becomes empty, it is removed and the cursor falls by one row. If the new position would be out of the legal cursor range of any existing text segment, an error occurs. Note that after executing this command, some text segments may lose their supports and be pulled down toward the hell. If the current segment falls, the cursor also falls with it. C: Create a new segment of length one immediately above the current cursor position. It consists of a copy of the character under the cursor. If the cursor is at the tail, an error occurs. Also if the the position of the new segment is already occupied by another segment, an error occurs. After executing the command, the created segment becomes the new current segment and the column position of the cursor advances to the right by one column. Lowercase and numeric characters (` a ' to ` z ' and ` 0 ' to ` 9 '): Insert the character at the current cursor position. The current segment becomes longer by one character. The cursor moves forward by one column. The beginning column of the current segment does not change. Once an error occurs, the entire editing session terminates abnormally. Input The first line of the input contains an integer that represents the number of editing sessions. Each of the following lines contains a character sequence, where the first character is the initial character and the rest represents a command sequence processed during a session. Each session starts with a single segment consisting of the initial character in the bottom row. The initial cursor position is at the tail of the segment. The editor processes each command represented by a character one by one in the manner described above. You may assume that each command line is non-empty and its length is at most one hundred. A command sequence ends with a newline. Output For each editing session specified by the input, if it terminates without errors, your program should print the current segment at the completion of the session in a line. If an error occurs during the session, just print " ERROR " in capital letters in a line. Sample Input 3 12BC3BC4BNBBDD5 aaaBCNBBBCb aaaBBCbNBC Output for the Sample Input 15234 aba ERROR | 35,877 |
åé¡ A : Koto Distance å顿 Koto ã¯èšãããšç¥ããç¢ç€ã®ç®ã®è¡ã§ããïŒ ãã®è¡ã¯æ±è¥¿æ¹åã« W ã¡ãŒãã«ïŒååæ¹åã« H ã¡ãŒãã«ã«äŒžã³ãé·æ¹åœ¢ã®é åã«ãã£ãŠã§ããŠããïŒ ãã®è¡ã®è¥¿ç«¯ãã x ã¡ãŒãã«ïŒå端ãã y ã¡ãŒãã«ã®ç¹ã¯ (x, y) ãšèšãããïŒ ããã®è¡ã«äœã人ã¯å€ãããäŒããç¬èªã®æåãéãããŠããïŒãã®äžã€ã«Kotoè·é¢ãšããå€ãã£ãè·é¢å°ºåºŠãããïŒ 2ã€ã®ç¹ (x_1, y_1) ïŒ (x_2, y_2) ã® Koto è·é¢ã¯ïŒmin (|x_1 - x_2|, |y_1 - y_2|) ã«ãã£ãŠå®çŸ©ãããïŒ æè¿ãã®è¡å
šäœã« Wifi ã䜿ããããã«ããèšç»ãç«ã¡äžãã£ãïŒ çŸåšã®èšç»ã§ã¯ïŒèŠªæ©ã N åäœãããšã«ãªã£ãŠããïŒ i çªç®ã®èŠªæ©ã¯ç¹ (x_i, y_i) ã«èšçœ®ããïŒKotoè·é¢ã w_i 以äžã®é åã«å¯Ÿã㊠Wifi ãæäŸããïŒ èŠªæ©ãèšç»ã©ãã建ãŠãå Žåã«ïŒè¡ã®å
éšåã³å¢çäžã« Wifi ãæäŸã§ãããã©ãããå€å®ããïŒ ãªãïŒKotoè·é¢ã¯äžè¬ã«äžè§äžçåŒãæºãããªãããïŒè·é¢ã®å
¬çãæºãããªããšããããšã¯ããã ãã®ç§å¯ã§ããïŒ å
¥ååœ¢åŒ å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ N W H x_1 y_1 w_1 ... x_N y_N w_N åºååœ¢åŒ è¡ã®å
éšããã³å¢çäžã« Wifi ãæäŸã§ãããªã âYesâ ãïŒããã§ãªãå Žå㯠âNoâ ãåºåããïŒ å¶çŽ 1 †N †10^5 1 †W †10^5 1 †H †10^5 0 †x_i †W 0 †y_i †H 1 †w_i †10^5 åäžåº§æšã«èŠªæ©ã¯è€æ°ååšããªã å
¥åºåäŸ å
¥åäŸ 1 3 9 9 2 2 2 5 5 2 8 8 2 åºåäŸ 1 Yes ïŒçªç®ã®èŠªæ©ãæäŸããWifiã®ç¯å²ã¯ä»¥äžã®éãã§ããïŒ å
¥åäŸ 2 2 7 7 2 2 1 6 6 1 åºåäŸ 2 No å
¥åäŸ 3 3 10 20 5 10 5 2 10 1 8 10 1 åºåäŸ 3 Yes | 35,878 |
é»åã¬ã³ãž (Microwave) åé¡ JOI åã¯é£äºã®æºåã®ããïŒA âã®èãé»åã¬ã³ãžã§ B âãŸã§æž©ããããšããŠããïŒ èã¯æž©åºŠã 0 âæªæºã®ãšãåã£ãŠããïŒ ãŸãïŒæž©åºŠã 0 âããé«ããšãåã£ãŠããªãïŒ æž©åºŠãã¡ããã© 0 âã®ãšãã®èã®ç¶æ
ã¯ïŒåã£ãŠããå ŽåãšïŒåã£ãŠããªãå Žåã®äž¡æ¹ãããåŸãïŒ JOI åã¯ïŒèã®å ç±ã«ãããæéã¯ä»¥äžã®ããã«ãªããšä»®å®ããŠïŒèãæž©ããã®ã«ãããæéãèŠç©ããããšã«ããïŒ èãåã£ãŠããŠïŒãã®æž©åºŠã 0 âããå°ãããšãïŒ C ç§ã§ 1 âæž©ãŸãïŒ èãåã£ãŠããŠïŒãã®æž©åºŠãã¡ããã© 0 âã®ãšãïŒ D ç§ã§èãè§£åããïŒåã£ãŠããªãç¶æ
ã«ãªãïŒ èãåã£ãŠããªããšãïŒ E ç§ã§ 1 âæž©ãŸãïŒ ãã®èŠç©ããã«ãããŠïŒèã B âã«ããã®ã«äœç§ãããããæ±ããïŒ å
¥å å
¥å㯠5 è¡ãããªãïŒ1 è¡ã« 1 åãã€æŽæ°ãæžãããŠããïŒ 1 è¡ç®ã«ã¯ïŒããšããšã®èã®æž©åºŠ A ãæžãããŠããïŒ 2 è¡ç®ã«ã¯ïŒç®çã®æž©åºŠ B ãæžãããŠããïŒ 3 è¡ç®ã«ã¯ïŒåã£ãèã 1 âæž©ããã®ã«ãããæé C ãæžãããŠããïŒ 4 è¡ç®ã«ã¯ïŒåã£ãèãè§£åããã®ã«ãããæé D ãæžãããŠããïŒ 5 è¡ç®ã«ã¯ïŒåã£ãŠããªãèã 1 âæž©ããã®ã«ãããæé E ãæžãããŠããïŒ ããšããšã®æž©åºŠ A 㯠-100 ä»¥äž 100 以äžïŒç®çã®æž©åºŠ B 㯠1 ä»¥äž 100 以äžã§ããïŒA â 0 ããã³ A < B ãæºããïŒ æž©ããã®ã«ãããæé C, D, E ã¯ãã¹ãŠ 1 ä»¥äž 100 以äžã§ããïŒ åºå èã B âã«ããã®ã«ãããç§æ°ã 1 è¡ã§åºåããïŒ å
¥åºåäŸ å
¥åäŸ 1 -10 20 5 10 3 åºåäŸ 1 120 å
¥åäŸ 2 35 92 31 50 11 åºåäŸ 2 627 å
¥åºåäŸ 1 ã§ã¯ïŒããšããšã®è㯠-10 âã§åã£ãŠããïŒãããæéã¯ä»¥äžã®ããã«ãªãïŒ -10 âãã 0 âãŸã§æž©ããã®ã« 5 à 10 = 50 ç§ïŒ 0 âã®èãè§£åããã®ã« 10 ç§ïŒ 0 âãã 20 âãŸã§æž©ããã®ã« 3 à 20 = 60 ç§ïŒ ãããã£ãŠïŒãããæéã®åèšã¯ 120 ç§ã§ããïŒ å
¥åºåäŸ 2 ã§ã¯ïŒããšããšã®èã¯åã£ãŠããªãïŒãããã£ãŠïŒèã 35 âãã 92 âãŸã§æž©ããã®ã«ãããæé㯠627 ç§ã§ããïŒ æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒäœ ã第 16 åæ¥æ¬æ
å ±ãªãªã³ãã㯠JOI 2016/2017 äºéžç«¶æèª²é¡ã | 35,879 |
G: Toss Cut Tree Problem Statement You are given two trees T, U . Each tree has N vertices that are numbered 1 through N . The i -th edge ( 1 \leq i \leq N-1 ) of tree T connects vertices a_i and b_i . The i -th edge ( 1 \leq i \leq N-1 ) of tree U connects vertices c_i and d_i . The operation described below will be performed N times. On the i -th operation, flip a fair coin. If it lands heads up, remove vertex i and all edges directly connecting to it from tree T . If it lands tails up, remove vertex i and all edges directly connecting to it from tree U . After N operations, each tree will be divided into several connected components. Let X and Y be the number of connected components originated from tree T and U , respectively. Your task is to compute the expected value of X \times Y . More specifically, your program must output an integer R described below. First, you can prove X \times Y is a rational number. Let P and Q be coprime integers that satisfies \frac{P}{Q} = X \times Y . R is the only integer that satisfies R \times Q $\equiv$ P $ \bmod \;$ 998244353, 0 \leq R < 998244353 . Input N a_1 b_1 : a_{N-1} b_{N-1} c_1 d_1 : c_{N-1} d_{N-1} Constraints 1 \leq N \leq 2 \times 10^5 1 \leq a_i, b_i, c_i, d_i \leq N The given two graphs are trees. All values in the input are integers. Output Print R described above in a single line. Sample Input 1 3 1 2 2 3 1 2 3 1 Output for Sample Input 1 1 A coin is flipped 3 times. Therefore, there are 2^3 = 8 outcomes in total. Suppose that the outcome was (tail, head, tail) in this order. Vertex 2 of tree T and vertex 1 , 3 of tree U are removed along with all edges connecting to them. T , U are decomposed to 2 , 1 connected components, respectively. Thus, the value of XY is 2 \times 1 = 2 in this case. It is possible to calculate XY for the other cases in the same way and the expected value of XY is 1 . Sample Input 2 4 1 2 1 4 2 3 1 4 4 2 2 3 Output for Sample Input 2 374341634 The expected number of XY is \frac{13}{8} . | 35,880 |
Baseball Simulation Ichiro likes baseball and has decided to write a program which simulates baseball. The program reads events in an inning and prints score in that inning. There are only three events as follows: Single hit put a runner on the first base. the runner in the first base advances to the second base and the runner in the second base advances to the third base. the runner in the third base advances to the home base (and go out of base) and a point is added to the score. Home run all the runners on base advance to the home base. points are added to the score by an amount equal to the number of the runners plus one. Out The number of outs is increased by 1. The runners and the score remain stationary. The inning ends with three-out. Ichiro decided to represent these events using "HIT", "HOMERUN" and "OUT", respectively. Write a program which reads events in an inning and prints score in that inning. You can assume that the number of events is less than or equal to 100. Input The input consists of several datasets. In the first line, the number of datasets n is given. Each dataset consists of a list of events (strings) in an inning. Output For each dataset, prints the score in the corresponding inning. Sample Input 2 HIT OUT HOMERUN HIT HIT HOMERUN HIT OUT HIT HIT HIT HIT OUT HIT HIT OUT HIT OUT OUT Output for the Sample Input 7 0 | 35,881 |
ïŒã€ã®å€è§åœ¢ ã€ãšããã¯ïŒæ¬ä»¥äžã®çã£ãããªæ£ãç¹ããŠå€è§åœ¢ãäœããæäººã®ãžã§ãŠåã«ãã¬ãŒã³ãããããšã«ããŸãããæ£ã¯ãããã®ç«¯ç¹ã§ã®ã¿ç¹ããããšãã§ããŸãã端ç¹ã¯ãã¹ãŠåãå¹³é¢äžã«çœ®ããŸããäžã€ã®æ¥åç¹ã§ç¹ããæ£ã¯ïŒæ¬ã ãã§ããããããªãè§åºŠã¯èªç±ã«æ±ºããããšãã§ããŸãã ã€ãšããã¯ãèªåãæã£ãŠããæ£ããã¹ãŠäœ¿ã£ãŠå€§ãããåããããã®ïŒã€ã®å€è§åœ¢ãäœãããšããŠããŸãã äžãããããã¹ãŠã®æ£ã䜿ã£ãŠãïŒã€ã®å€è§åœ¢ãããããã®åšå²ã®é·ãã®å·®ã®çµ¶å¯Ÿå€ãæå°ãšãªãããã«äœãã忣ã®é·ããäžãããããšããïŒã€ã®å€è§åœ¢ã®åšå²ã®é·ãã®å·®ã®çµ¶å¯Ÿå€ãæ±ããããã°ã©ã ãäœæãããïŒã€ã®å€è§åœ¢ãäœæã§ããªãå Žåã¯ãã®ããšãå ±åããããã ããé·ãã$a_1 \leq a_2 \leq ... \leq a_m$ã§ãã$m$ ($3 \leq m$)æ¬ã®æ£ã§ã$a_m ïŒa_1+a_2+ ... +a_{m-1}$ãæºãããšããããã$m$æ¬ã®æ£ã§ã²ãšã€ã®å€è§åœ¢ãäœæã§ãããã®ãšããã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã $N$ $a_1$ $a_2$ ... $a_N$ ïŒè¡ç®ã«æ£ã®æ°$N$ ($6 \leq N \leq 40$)ãäžãããããïŒè¡ç®ã«åæ£ã®é·ã$a_i$ ($1 \leq a_i \leq 100$)ãäžããããã åºå äžãããããã¹ãŠã®æ£ã䜿ã£ãŠïŒã€ã®å€è§åœ¢ãäœããå Žåã¯ãé·ãã®å·®ã®çµ¶å¯Ÿå€ã®æå°å€ãïŒè¡ã«åºåãããïŒã€ã®å€è§åœ¢ãäœããªãå Žåã¯ã-1ããïŒè¡ã«åºåããã å
¥åºåäŸ å
¥åäŸïŒ 6 2 2 3 2 2 2 åºåäŸïŒ 1 å
¥åäŸïŒ 7 2 2 3 2 2 2 1 åºåäŸïŒ 0 å
¥åäŸïŒ 6 1 1 1 1 2 4 åºåäŸïŒ -1 | 35,882 |
Score : 600 points Problem Statement We have 3N cards arranged in a row from left to right, where each card has an integer between 1 and N (inclusive) written on it. The integer written on the i -th card from the left is A_i . You will do the following operation N-1 times: Rearrange the five leftmost cards in any order you like, then remove the three leftmost cards. If the integers written on those three cards are all equal, you gain 1 point. After these N-1 operations, if the integers written on the remaining three cards are all equal, you will gain 1 additional point. Find the maximum number of points you can gain. Constraints 1 \leq N \leq 2000 1 \leq A_i \leq N Input Input is given from Standard Input in the following format: N A_1 A_2 \cdots A_{3N} Output Print the maximum number of points you can gain. Sample Input 1 2 1 2 1 2 2 1 Sample Output 1 2 Let us rearrange the five leftmost cards so that the integers written on the six cards will be 2\ 2\ 2\ 1\ 1\ 1 from left to right. Then, remove the three leftmost cards, all of which have the same integer 2 , gaining 1 point. Now, the integers written on the remaining cards are 1\ 1\ 1 . Since these three cards have the same integer 1 , we gain 1 more point. In this way, we can gain 2 points - which is the maximum possible. Sample Input 2 3 1 1 2 2 3 3 3 2 1 Sample Output 2 1 Sample Input 3 3 1 1 2 2 2 3 3 3 1 Sample Output 3 3 | 35,883 |
æšé«å·® ä»ãŸã§ç»ã£ãããšã®ããå±±ã®æšé«ãèšé²ããããŒã¿ããããŸãããã®ããŒã¿ãèªã¿èŸŒãã§ãäžçªé«ãå±±ãšäžçªäœãå±±ã®æšé«å·®ãåºåããããã°ã©ã ãäœæããŠãã ããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã å±±ã®é«ã ... ... å±±ã®é«ããè€æ°è¡ã«æž¡ã£ãŠäžããããŸããå
¥åãããå€ã¯ãã¹ãŠ 0 ä»¥äž 1,000,000 以äžã®å®æ°ã§ããå
¥åãããå±±ã®é«ãã®æ°ã¯ 50 以äžã§ãã Output äžçªé«ãå±±ãšäžçªäœãå±±ã®æšé«å·®ã宿°ã§åºåãããåºåã¯0.01以äžã®èª€å·®ãå«ãã§ãããã Sample Input 3776.0 1819.0 645.2 2004.1 1208.6 Output for the Sample Input 3130.8 | 35,884 |
Score : 200 points Problem Statement We have a rectangular parallelepiped of size AÃBÃC , built with blocks of size 1Ã1Ã1 . Snuke will paint each of the AÃBÃC blocks either red or blue, so that: There is at least one red block and at least one blue block. The union of all red blocks forms a rectangular parallelepiped. The union of all blue blocks forms a rectangular parallelepiped. Snuke wants to minimize the difference between the number of red blocks and the number of blue blocks. Find the minimum possible difference. Constraints 2â€A,B,Câ€10^9 Input The input is given from Standard Input in the following format: A B C Output Print the minimum possible difference between the number of red blocks and the number of blue blocks. Sample Input 1 3 3 3 Sample Output 1 9 For example, Snuke can paint the blocks as shown in the diagram below. There are 9 red blocks and 18 blue blocks, thus the difference is 9 . Sample Input 2 2 2 4 Sample Output 2 0 For example, Snuke can paint the blocks as shown in the diagram below. There are 8 red blocks and 8 blue blocks, thus the difference is 0 . Sample Input 3 5 3 5 Sample Output 3 15 For example, Snuke can paint the blocks as shown in the diagram below. There are 45 red blocks and 30 blue blocks, thus the difference is 9 . | 35,885 |
Problem A: Hit and Blow Hit and blow is a popular code-breaking game played by two people, one codemaker and one codebreaker. The objective of this game is that the codebreaker guesses correctly a secret number the codemaker makes in his or her mind. The game is played as follows. The codemaker first chooses a secret number that consists of four different digits, which may contain a leading zero. Next, the codebreaker makes the first attempt to guess the secret number. The guessed number needs to be legal (i.e. consist of four different digits). The codemaker then tells the numbers of hits and blows to the codebreaker. Hits are the matching digits on their right positions, and blows are those on different positions. For example, if the secret number is 4321 and the guessed is 2401, there is one hit and two blows where 1 is a hit and 2 and 4 are blows. After being told, the codebreaker makes the second attempt, then the codemaker tells the numbers of hits and blows, then the codebreaker makes the third attempt, and so forth. The game ends when the codebreaker gives the correct number. Your task in this problem is to write a program that determines, given the situation, whether the codebreaker can logically guess the secret number within the next two attempts. Your program will be given the four-digit numbers the codebreaker has guessed, and the responses the codemaker has made to those numbers, and then should make output according to the following rules: if only one secret number is possible, print the secret number; if more than one secret number is possible, but there are one or more critical numbers, print the smallest one; otherwise, print â????â (four question symbols). Here, critical numbers mean those such that, after being given the number of hits and blows for them on the next attempt, the codebreaker can determine the secret number uniquely. Input The input consists of multiple data sets. Each data set is given in the following format: N four-digit-number 1 n-hits 1 n-blows 1 ... four-digit-number N n-hits N n-blows N N is the number of attempts that has been made. four-digit-number i is the four-digit number guessed on the i -th attempt, and n-hits i and n-blows i are the numbers of hits and blows for that number, respectively. It is guaranteed that there is at least one possible secret number in each data set. The end of input is indicated by a line that contains a zero. This line should not be processed. Output For each data set, print a four-digit number or â????â on a line, according to the rules stated above. Sample Input 2 1234 3 0 1245 3 0 1 1234 0 0 2 0123 0 4 1230 0 4 0 Output for the Sample Input 1235 ???? 0132 | 35,886 |
Score : 700 points Problem Statement 10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}} -th. The score of a participant is the product of his/her ranks in the two contests. Process the following Q queries: In the i -th query, you are given two positive integers A_i and B_i . Assuming that Takahashi was ranked A_i -th in the first contest and B_i -th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's. Constraints 1 \leq Q \leq 100 1\leq A_i,B_i\leq 10^9(1\leq i\leq Q) All values in input are integers. Input Input is given from Standard Input in the following format: Q A_1 B_1 : A_Q B_Q Output For each query, print the maximum possible number of participants whose scores are smaller than Takahashi's. Sample Input 1 8 1 4 10 5 3 3 4 11 8 9 22 40 8 36 314159265 358979323 Sample Output 1 1 12 4 11 14 57 31 671644785 Let us denote a participant who was ranked x -th in the first contest and y -th in the second contest as (x,y) . In the first query, (2,1) is a possible candidate of a participant whose score is smaller than Takahashi's. There are never two or more participants whose scores are smaller than Takahashi's, so we should print 1 . | 35,887 |
Problem K Min-Max Distance Game Alice and Bob are playing the following game. Initially, $n$ stones are placed in a straight line on a table. Alice and Bob take turns alternately. In each turn, the player picks one of the stones and removes it. The game continues until the number of stones on the straight line becomes two. The two stones are called result stones . Alice's objective is to make the result stones as distant as possible, while Bob's is to make them closer. You are given the coordinates of the stones and the player's name who takes the first turn. Assuming that both Alice and Bob do their best, compute and output the distance between the result stones at the end of the game. Input The input consists of a single test case with the following format. $n$ $f$ $x_1$ $x_2$ ... $x_n$ $n$ is the number of stones $(3 \leq n \leq 10^5)$. $f$ is the name of the first player, either Alice or Bob. For each $i$, $x_i$ is an integer that represents the distance of the $i$-th stone from the edge of the table. It is guaranteed that $0 \leq x_1 < x_2 < ... < x_n \leq 10^9$ holds. Output Output the distance between the result stones in one line. Sample Input 1 5 Alice 10 20 30 40 50 Sample Output 1 30 Sample Input 2 5 Bob 2 3 5 7 11 Sample Output 2 2 | 35,888 |
Score : 1000 points Problem Statement There is a stack of N cards, each of which has a non-negative integer written on it. The integer written on the i -th card from the top is A_i . Snuke will repeat the following operation until two cards remain: Choose three consecutive cards from the stack. Eat the middle card of the three. For each of the other two cards, replace the integer written on it by the sum of that integer and the integer written on the card eaten. Return the two cards to the original position in the stack, without swapping them. Find the minimum possible sum of the integers written on the last two cards remaining. Constraints 2 \leq N \leq 18 0 \leq A_i \leq 10^9 (1\leq i\leq N) 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 minimum possible sum of the integers written on the last two cards remaining. Sample Input 1 4 3 1 4 2 Sample Output 1 16 We can minimize the sum of the integers written on the last two cards remaining by doing as follows: Initially, the integers written on the cards are 3 , 1 , 4 , and 2 from top to bottom. Choose the first, second, and third card from the top. Eat the second card with 1 written on it, add 1 to each of the other two cards, and return them to the original position in the stack. The integers written on the cards are now 4 , 5 , and 2 from top to bottom. Choose the first, second, and third card from the top. Eat the second card with 5 written on it, add 5 to each of the other two cards, and return them to the original position in the stack. The integers written on the cards are now 9 and 7 from top to bottom. The sum of the integers written on the last two cards remaining is 16 . Sample Input 2 6 5 2 4 1 6 9 Sample Output 2 51 Sample Input 3 10 3 1 4 1 5 9 2 6 5 3 Sample Output 3 115 | 35,889 |
B - ã©ã€ãªã³ ããªãã¯åç©åã«æ¥ãŠã©ã€ãªã³ãèŠãŠããã ãã®åç©åã«ã¯ n åã®ã©ã€ãªã³ã®ãªãªãããã ããªãã¯ã©ã€ãªã³ãå
šéšã§äœé ããã®ãç¥ããããªã£ãã®ã ãã äžäººã§æ°ããã®ã¯å€§å€ã ã ããã§è¿ãã«ããåç©åã®æ¥åè
m 人ã«ååããŠãããããšã«ããã ã©ã€ãªã³ã®ãªãªã¯ããããã 1 çªãã n çªãŸã§ã®æ°åãã€ããŠããã é çªã«äžŠãã§ããã äžã€ã®ãªãªã«ã¯ 0 é ä»¥äž x é 以äžã®ã©ã€ãªã³ãããã m äººã®æ¥åè
ã§ i çªç®ã®äºº (1 †i †m) ã«ã¯ l_i çªãã r_i çªãŸã§ã® 䞡端ãå«ããã¹ãŠã®ãªãªã®ã©ã€ãªã³ã®æ°ã®ç·åãæ°ããŠããã£ãã ãã®æ
å ±ãå
ã«ã 1 ãã n åãªãªã®äžã®ã©ã€ãªã³ã®æ°ãæ±ããããšã«ããã å
¥ååœ¢åŒ å
¥åã¯ä»¥äžã®åœ¢åŒã§äžãããã n x m l_1 r_1 s_1 ... l_m r_m s_m 1è¡ç®ã¯3ã€ã®æŽæ° n x m ã§ã ãããããªãªã®æ°ãäžã€ã®ãªãªã®äžã®ã©ã€ãªã³ã®æå€§ã®æ°ã æ°ããã®ã«ååããäººã®æ°ã§ããã 2è¡ç®ããç¶ã m è¡ã¯åè¡3ã€ã®æŽæ°ã§ã ãããã i çªç®ã®äººãæ°ããçµæ l_i r_i s_i ã§ããã l_i çªãã r_i çªãŸã§ã®ãªãªã®ã©ã€ãªã³ãæ°ããã åèš s_i é ããããšã衚ããŠããã åºååœ¢åŒ æ°ããŠããã£ãçµæãå
šãŠæ£ãããšããŠã 1 ãã n ã® åãªãªã®äžã®ã©ã€ãªã³ã®æ°ã空çœåºåãã® n åã®æŽæ°ã§åºåããã ãã®ãããªçãè€æ°ãããšãã¯ã ã©ã€ãªã³ã®æ°ã®åèšãæå€§ã«ãªããã®ãã©ãã§ãè¯ãã®ã§äžã€åºåããã æ¡ä»¶ãæºããã©ã€ãªã³ã®é
眮ãäžã€ããªããšã㯠-1 ãåºåããã å¶çŽ 1 †n †6 1 †x †10 1 †m †10 1 †l_i †r_i †n 0 †s_i †60 å
¥åå€ã¯ãã¹ãп޿°ã§ããã å
¥åºåäŸ å
¥åäŸ 1 3 5 1 1 2 5 åºåäŸ 1 2 3 5 ãã®ä»"4 1 5"ã"0 5 5"ãªã©ãæ£ããåºåã§ããã å
¥åäŸ 2 4 5 2 1 3 15 3 4 3 åºåäŸ 2 -1 æ¡ä»¶ãæºããã©ã€ãªã³ã®é
眮ãäžã€ããªããšã㯠-1 ãåºåããã | 35,890 |
Problem D: Revenge of Champernowne Constant Champernowne constant is an irrational number. Its decimal representation starts with "0.", followed by concatenation of all positive integers in the increasing order. You will be given a sequence S which consists of decimal digits. Your task is to write a program which computes the position of the first occurrence of S in Champernowne constant after the decimal point. Input The input has multiple test cases. Each line of the input has one digit sequence. The input is terminated by a line consisting only of # . It is guaranteed that each sequence has at least one digit and its length is less than or equal to 100. Output For each sequence, output one decimal integer described above. You can assume each output value is less than 10 16 . Sample Input 45678 67891011 21 314159265358979 # Output for the Sample Input 4 6 15 2012778692735799 | 35,891 |
Score : 800 points Problem Statement Takahashi Lake has a perimeter of L . On the circumference of the lake, there is a residence of the lake's owner, Takahashi. Each point on the circumference of the lake has a coordinate between 0 and L (including 0 but not L ), which is the distance from the Takahashi's residence, measured counter-clockwise. There are N trees around the lake; the coordinate of the i -th tree is X_i . There is no tree at coordinate 0 , the location of Takahashi's residence. Starting at his residence, Takahashi will repeat the following action: If all trees are burnt, terminate the process. Specify a direction: clockwise or counter-clockwise. Walk around the lake in the specified direction, until the coordinate of a tree that is not yet burnt is reached for the first time. When the coordinate with the tree is reached, burn that tree, stay at the position and go back to the first step. Find the longest possible total distance Takahashi walks during the process. Partial Score A partial score can be obtained in this problem: 300 points will be awarded for passing the input satisfying N \leq 2000 . Constraints 2 \leq L \leq 10^9 1 \leq N \leq 2\times 10^5 1 \leq X_1 < ... < X_N \leq L-1 All values in input are integers. Input Input is given from Standard Input in the following format: L N X_1 : X_N Output Print the longest possible total distance Takahashi walks during the process. Sample Input 1 10 3 2 7 9 Sample Output 1 15 Takahashi walks the distance of 15 if the process goes as follows: Walk a distance of 2 counter-clockwise, burn the tree at the coordinate 2 and stay there. Walk a distance of 5 counter-clockwise, burn the tree at the coordinate 7 and stay there. Walk a distance of 8 clockwise, burn the tree at the coordinate 9 and stay there. Sample Input 2 10 6 1 2 3 6 7 9 Sample Output 2 27 Sample Input 3 314159265 7 21662711 77271666 89022761 156626166 160332356 166902656 298992265 Sample Output 3 1204124749 | 35,892 |
Problem E: Light Source Problem äºæ¬¡å
å¹³é¢äžã« n åã®åç¶ã®å
æºãé
眮ãããŠãããããå
æºãå
ãåãããšãäžå³ã®ããã«ãã®å
æºã®äžå¿ç¹ããæç¶ã«å
ãæŸåºãããã å
æºã®äžå¿ç¹ã¯( x , y )ãååŸã¯ r ã§è¡šãããã å
ãšãªãæåœ¢ã¯è§ β ãäžå¿ã«- Ξ /2, + Ξ /2ã®æ¹åãžå¯Ÿç§°ã«åºããããã®ååŸã¯ α ã§ããã å
æºã®åãæåã®å
ã«å®å
šã«èŠããããšããå
æºã¯ãã®å
ãåãããšã¿ãªããããå
æºããæŸåºãããå
ã®åŒ·ãã¯ãåããå
ã®åŒ·ãã®åèšãšãªãããã ããæŸåºãããå
ã®åŒ·ãã«ã¯äžéããããäžéãè¶
ããå Žåãå
ã®åŒ·ãã¯äžéå€ãšåãã«ãªãããªããããå
ãå
æºã«ãã£ãŠå
ãé®ãããããšã¯ãªãã ããå°ç¹ã«ååšããå
æºãç®çå
æºãšãããç®çå
æºã§ã¯å
ãæŸåºããããåããå
ã®åŒ·ãã«å¶éã¯ãªãã ããªãã¯åº§æš(0,0)ããããã匷ãã®æåœ¢ã®å
ããä»»æã®æ¹åã«ïŒåºŠã ãæŸåºããããšãã§ãããç®çå
æºãåããå
ã®åŒ·ãã®åèšã®æå€§å€ãæ±ããããã°ã©ã ãäœæããããã ããå
šãŠã®å
æºã«ãããŠãæŸåºãããå
ãå
ã®å
æºã«æ»ããããªå
¥åããŒã¿ã¯äžããããªããšä»®å®ããŠããããŸãããã®åé¡ã§ã¯ãé åã®å¢çããã®è·é¢ã0.000001以å
ã®å Žåãé åäžãšã¿ãªãããšã«ããã Input n Ξ 0 α 0 power x 1 y 1 r 1 Ξ 1 α 1 β 1 maxpower 1 . . x n y n r n Ξ n α n β n maxpower n x n+1 y n+1 r n+1 1è¡ç®ã«ã¯ç®çå
æºãé€ãå
æºã®æ° n ãäžããããã 2è¡ç®ã«æåã«å
ãæŸåºãã座æš(0,0)ã®æ
å ±ã3è¡ç®ããn+2è¡ç®ã«ç®çã§ãªãå
æºã®æ
å ±ãn+3è¡ç®ã«ç®çå
æºã®æ
å ±ããããã空çœåºåãã§äžããããã åæ
å ±ã«å¯ŸããŠã x i , y i ã¯å
æºã®äžå¿ç¹ã®åº§æšã r i ã¯å
æºã®ååŸã Ξ i ã¯å
ãåºããè§åºŠã α i ã¯å
ã®ååŸã β i ã¯å
ãåããæ¹åã衚ãã2è¡ç®ã® power ã¯æåã«æŸåºãããå
ã®åŒ·ãã3è¡ç®ããn+2è¡ç®ã® maxpower i ã¯æŸåºãããå
ã®äžéã衚ãã å
ã®æ¹å β i ã¯xè»žã®æ£ã®åãããåæèšåãã«å転ããåè§åºŠã®åäœã¯åºŠãšããã Constraints å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã å
¥åã¯å
šãп޿°ãããªã 1 †n †100 -1000 †x i , y i †1000 1 †r i †1000 1 †Ξ i †180 1 †α i †1000 0 †β i < 360 0 †power , maxpower i †1000 Output ç®çå
æºãå
šãŠå²ããããªå
ã®åŒ·ãã®åèšã®æå€§å€ã1è¡ã«åºåããã Sample Input 1 1 90 10 20 3 3 1 90 10 315 10 6 0 1 Sample Output 1 30 Sample Input 2 2 90 10 10 -3 0 1 45 10 90 10 -6 0 2 30 3 180 10 -9 0 1 Sample Output 2 10 | 35,893 |
10åè§£ãããäœç¹åããïŒ éžæã®çãããããœã³ã³ç²ååã«ãããããããœã³ã³ç²ååã¯ä»å¹Žã§10åšå¹Žã«ãªããŸãããåºé¡ãããå顿°ãåèšåŸç¹ã¯å¹Žã«ãã£ãŠç°ãªããŸããååé¡ã«ã¯é£æåºŠã«å¿ããŠåŸç¹ã決ããããŠããŸããå顿°ã10åã§ãããããã®åé¡ã®åŸç¹ãäžãããããšãããããã®åèšãåºåããããã°ã©ã ãäœæããŠäžããã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã s 1 s 2 . . s 10 å
¥åã¯10è¡ãããªããi è¡ç®ã«åé¡ i ã®åŸç¹ãè¡šãæŽæ° s i (0†s i †100)ãäžããããã åºå åèšåŸç¹ãïŒè¡ã«åºåããã å
¥åäŸ1 1 2 3 4 5 6 7 8 9 10 åºåäŸ1 55 å
¥åäŸ2 4 4 8 8 8 10 10 12 16 20 åºåäŸ2 100 | 35,894 |
Score : 200 points Problem Statement In a factory, there are N robots placed on a number line. Robot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative. We want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect. Here, for each i ( 1 \leq i \leq N ), the movable range of arms of Robot i is the part of the number line between the coordinates X_i - L_i and X_i + L_i , excluding the endpoints. Find the maximum number of robots that we can keep. Constraints 1 \leq N \leq 100,000 0 \leq X_i \leq 10^9 ( 1 \leq i \leq N ) 1 \leq L_i \leq 10^9 ( 1 \leq i \leq N ) If i \neq j , X_i \neq X_j . All values in input are integers. Input Input is given from Standard Input in the following format: N X_1 L_1 X_2 L_2 \vdots X_N L_N Output Print the maximum number of robots that we can keep. Sample Input 1 4 2 4 4 3 9 3 100 5 Sample Output 1 3 By removing Robot 2 , we can keep the other three robots. Sample Input 2 2 8 20 1 10 Sample Output 2 1 Sample Input 3 5 10 1 2 1 4 1 6 1 8 1 Sample Output 3 5 | 35,895 |
Score : 1000 points Problem Statement Welcome to CODE FESTIVAL 2016! In order to celebrate this contest, find a string s that satisfies the following conditions: The length of s is between 1 and 5000 , inclusive. s consists of uppercase letters. s contains exactly K occurrences of the string "FESTIVAL" as a subsequence. In other words, there are exactly K tuples of integers (i_0, i_1, ..., i_7) such that 0 †i_0 < i_1 < ... < i_7 †|s|-1 and s[i_0]='F', s[i_1]='E', ..., s[i_7]='L' . It can be proved that under the given constraints, the solution always exists. In case there are multiple possible solutions, you can output any. Constraints 1 †K †10^{18} Input The input is given from Standard Input in the following format: K Output Print a string that satisfies the conditions. Sample Input 1 7 Sample Output 1 FESSSSSSSTIVAL Sample Input 2 256 Sample Output 2 FFEESSTTIIVVAALL | 35,896 |
Problem G: Dominating Set What you have in your hands is a map of Aizu-Wakamatsu City. The lines on this map represent streets and the dots are street corners. Lion Dor Company is going to build food stores at some street corners where people can go to buy food. It is unnecessary and expensive to build a food store on every corner. Their plan is to build the food stores so that people could get food either right there on the corner where they live, or at the very most, have to walk down only one street to find a corner where there was a food store. Now, all they have to do is figure out where to put the food store. The problem can be simplified as follows. Let G = ( V, E ) be unweighted undirected graph. A dominating set D of G is a subset of V such that every vertex in V - D is adjacent to at least one vertex in D . A minimum dominating set is a dominating set of minimum number of vertices for G . In the example graph given below, the black vertices are the members of the minimum dominating sets. Design and implement an algorithm for the minimum domminating set problem. Input Input has several test cases. Each test case consists of the number of nodes n and the number of edges m in the first line. In the following m lines, edges are given by a pair of nodes connected by the edge. The graph nodess are named with the numbers 0, 1,..., n - 1 respectively. The input terminate with a line containing two 0. The number of test cases is less than 20. Constrants n †30 m †50 Output Output the size of minimum dominating set for each test case. Sample Input 5 4 0 1 0 4 1 2 3 4 5 4 0 1 0 4 1 2 3 4 0 0 Output for the Sample Input 2 2 | 35,897 |
I: Islands Survival åé¡ $N$ é ç¹ $M$ 蟺ã®åçŽé£çµç¡åã°ã©ããããïŒ é ç¹ã«ã¯ $1, 2, \dots, N$ ãšçªå·ãã€ããããŠããïŒ èŸºã«ã¯ $1, 2, \dots, M$ ãšçªå·ãã€ããããŠããïŒèŸº $i$ ã¯é ç¹ $a_i$ ãš $b_i$ ãã€ãªãã§ããïŒ ãŸãïŒèŸº $i$ ã¯æå» $t_i$ ã«æ¶ããïŒã©ã®èŸºãééããããã«åäœæéããããïŒ ããªãã¯æåïŒæå» 0 ã«ãããŠé ç¹ 1 ã«ããïŒ ããªãã¯æé©ã«è¡åããããšã§ïŒæå» $T$ ãŸã§ã«åŸãããã¹ã³ã¢ãæå€§åãããïŒ ã¹ã³ã¢ã¯æå 0 ã§ããïŒã€ãã³ãã¯ä»¥äžã«åŸã£ãŠèµ·ããïŒ ä»ã®æå» $t'$ ã $t' \geq T$ ãæºãããªãã°çµäºããïŒããã§ãªããã° 2. ãžïŒ $t_i = t'$ ãªããã¹ãŠã®èŸº $i$ ãæ¶ããïŒ ããªããããé ç¹ã $v$ ãšãããšãïŒé ç¹ $v$ ãå«ãé£çµæåã«å«ãŸããé ç¹æ°ã $x$ ãšãããšïŒã¹ã³ã¢ã« $x$ ãå ç®ãããïŒ ããªãã¯é ç¹ $v$ ãšé£æ¥ããŠããé ç¹ã®ããããã«ç§»åãããïŒé ç¹ $v$ ã«çãŸãïŒãã ãåè
ã®å ŽåïŒæ¢ã«æ¶ãã蟺ã䜿ãããšã¯ã§ããªãïŒ $t' \gets t' + 1$ ãšã㊠1. ãžïŒ åŸãããã¹ã³ã¢ã®æå€§å€ãæ±ããïŒ å¶çŽ $2 \le N \le 10^5$ $N - 1 \le M \le \min(2 \times 10^5, N(N - 1) / 2)$ $1 \le T \le 10^5$ $1 \le a_i , b_i \le N$ $1 \le t_i \le T$ äžããããã°ã©ãã¯åçŽãã€é£çµïŒ å
¥ååœ¢åŒ å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ $N \ M \ T$ $a_1 \ b_1 \ t_1$ $\vdots$ $a_M \ b_M \ t_M$ åºå ã¹ã³ã¢ã®æå€§å€ãåºåããïŒãŸãïŒæ«å°Ÿã«æ¹è¡ãåºåããïŒ ãµã³ãã« ãµã³ãã«å
¥å1 5 4 2 1 2 2 2 3 1 1 4 2 4 5 1 ãµã³ãã«åºå1 8 æå» 0 ã« 5ïŒæå» 1 ã« 3 ã®ã¹ã³ã¢ãåŸãããïŒ ãµã³ãã«å
¥å2 4 4 3 1 2 2 2 3 1 3 4 3 4 1 1 ãµã³ãã«åºå2 8 æå» 0 ã« 4ïŒæå» 1 ã« 2ïŒæå» 2 ã« 2 ã®ã¹ã³ã¢ãåŸãããïŒ | 35,898 |
Coin Combination Problem You have 4 bags A, B, C and D each of which includes N coins (there are totally 4N coins). Values of the coins in each bag are a i , b i , c i and d i respectively. Find the number of combinations that result when you choose one coin from each bag (totally 4 coins) in such a way that the total value of the coins is V . You should distinguish the coins in a bag. Constraints 1 †N †1000 1 †a i , b i , c i , d i †10 16 1 †V †10 16 All input values are given in integers Input The input is given in the following format. N V a 1 a 2 ... a N b 1 b 2 ... b N c 1 c 2 ... c N d 1 d 2 ... d N Output Print the number of combinations in a line. Sample Input 1 3 14 3 1 2 4 8 2 1 2 3 7 3 2 Sample Output 1 9 Sample Input 2 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Sample Output 2 625 | 35,899 |
ããã°ã©ãã³ã°ã³ã³ãã¹ã ä»å¹Žãçœè倧åŠã§ããã°ã©ãã³ã°ã³ã³ãã¹ããéå¬ãããããšã«ãªããŸãããã³ã³ãã¹ãã§ã¯ããã€ãã®åé¡ãåºé¡ãããããããé£æåºŠã«å¿ããåŸç¹ãå²ãåœãŠãããŠããŸãã å®è¡å§å¡äŒã¯ãè§£ããåé¡ã®æ°ãšãããã®åŸç¹ã®äž¡æ¹ãèæ
®ããæ¬¡ã®ã«ãŒã«ã«åºã¥ããŠåããŒã ã®ã¹ã³ã¢ãèšç®ããããšã«ããŸããã ãããããŒã ãæ£è§£ããåé¡ã®ãã¡ãåŸç¹ã A 以äžã§ãããã®ã A å以äžããããšãæºãããããªæå€§ã® A ãããã®ããŒã ã®ã¹ã³ã¢ãšããã ããããŒã ãæ£è§£ããåé¡ã®æ°ãšããããã®åé¡ã®åŸç¹ãããããŒã ã®ã¹ã³ã¢ãèšç®ããããã°ã©ã ãäœæããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã N p 1 p 2 ... p N ïŒè¡ç®ã«ããŒã ãæ£è§£ããåé¡ã®æ° N (1 †N †100) ãäžãããããïŒè¡ç®ã«æ£è§£ããååé¡ã®åŸç¹ p i (1 †p i †100) ãäžããããã Output ããŒã ã®ã¹ã³ã¢ãïŒè¡ã«åºåããã Sample Input 1 7 5 4 3 10 2 4 1 Sample Output 1 4 åŸç¹ã 4 以äžã®åé¡ã 4 åä»¥äžæ£è§£ããŠããã®ã§ãã¹ã³ã¢ã¯ 4 ãšãªãã Sample Input 2 3 1 1 100 Sample Output 2 1 åŸç¹ã 1 以äžã®åé¡ã 1 åä»¥äžæ£è§£ããŠããã®ã§ãã¹ã³ã¢ã¯ 1 ãšãªãã Sample Input 3 4 11 15 58 1 Sample Output 3 3 åŸç¹ã 3 以äžã®åé¡ã 3 åä»¥äžæ£è§£ããŠããã®ã§ãã¹ã³ã¢ã¯ 3 ãšãªãã | 35,900 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.