task stringlengths 0 154k | __index_level_0__ int64 0 39.2k |
|---|---|
Balls and Boxes 9 Balls Boxes Any way At most one ball At least one ball Distinguishable Distinguishable 1 2 3 Indistinguishable Distinguishable 4 5 6 Distinguishable Indistinguishable 7 8 9 Indistinguishable Indistinguishable 10 11 12 Problem You have $n$ balls and $k$ boxes. You want to put these balls into the boxes. Find the number of ways to put the balls under the following conditions: Each ball is distinguished from the other. Each box is not distinguished from the other. Each ball can go into only one box and no one remains outside of the boxes. Each box must contain at least one ball. Note that you must print this count modulo $10^9+7$. Input $n$ $k$ The first line will contain two integers $n$ and $k$. Output Print the number of ways modulo $10^9+7$ in a line. Constraints $1 \le n \le 1000$ $1 \le k \le 1000$ Sample Input 1 4 3 Sample Output 1 6 Sample Input 2 10 5 Sample Output 2 42525 Sample Input 3 100 30 Sample Output 3 203169470 | 37,223 |
æ°è¬éçº è±äžåå£«ã¯æ¥ã
ç ç©¶ãè¡ããæ°ããè¬ãéçºããããšããŠããŸããæ°è¬ãéçºããããã«ã¯ãè²ã
ãªç©è³ªãçµã¿åãããŠè¬ãäœã詊éšãè¡ããè¯ãè¬ãèŠã€ããªããã°ãªããŸãããæ§ã
ãªçµã¿åããã詊ããŠãããã¡ã«ãè±äžå士ã¯ç©è³ªã®çµã¿åãããæš¹åœ¢å³ã§è¡šããããšãçªãæ¢ããŸããã å³ã®å³ã¯ãè¬ã®èª¿åãè¡šãæš¹åœ¢å³ã®äŸã§ããå³ã®äžã§äžžãå²ãŸãããã®ãç©è³ªããŒããäžè§ã§å²ãŸãããã®ãéžæããŒããšåŒã³ãŸããç©è³ªããŒãã¯ç©è³ªã衚ããŸããéžæããŒãã¯ãç©è³ªã®éžæã衚ããã®ã§ãããèªäœã¯ç©è³ªã衚ããŸãããéžæããŒãã«ã¯ or åïŒâšãä»ãããã®ïŒãš alt åïŒâãä»ãããã®ïŒã®ïŒçš®é¡ããããŸãããŸã ? ãä»ããããŒãã¯ãããããªãã·ã§ã³ã§ããããšã衚ããŸãããã ããéžæããŒãã®åããŒãïŒäžåãã®æã®å
ã«ããããŒãïŒããªãã·ã§ã³ã«ãªãããšã¯ãããŸãããæš¹åœ¢å³ã«çŸããç°ãªãç©è³ªããŒãã¯ãããããå¥ã®ç©è³ªã衚ããã®ãšããŸãã è¬ã®èª¿åãè¡ããšãã¯ã暹圢å³ã®äžçªäžã®ããŒãããã¯ãããŠãé ã
ã«ããŒãããã©ã£ãŠãããªãã以äžã®ããã«ããŠããŒããéžãã§ãããŸãã ãã©ãçããããŒãããªãã·ã§ã³ã§ãªãç©è³ªããŒããªãããããå¿
ãéžã¶ã ãªãã·ã§ã³ã®ç©è³ªããŒããªãããããéžã¶ãã©ããã¯ä»»æã or åã®éžæããŒããªãããã®åããå°ãªããšãäžã€ãéžã¶ããã ãããã®éžæããŒãããªãã·ã§ã³ãªããåãäžã€ãéžã°ãªããŠãããã alt åã®éžæããŒããªãããã®åããäžã€ã ããéžã¶ããã ãããã®éžæããŒãããªãã·ã§ã³ãªããåãéžã°ãªããŠãããã ããããŒããéžã°ãããšãã ãããã®ããŒãããäžã«åããæããããããã©ã£ãŠãããŸããéžã°ããªããã°ããããããã©ãããšã¯ãããŸããã ããªãã¯è±äžå士ãããè¬ã®ç©è³ªã®çµã¿åãããè¡šãæš¹åœ¢å³ãåãåããçµã¿åããã®æ°ãå
šéšã§äœéããããæ±ããããæç€ºãããŸãããæš¹åœ¢å³ãäžãããããšããçµã¿åããã®ç·æ°ãåºåããããã°ã©ã ãäœæããŠãã ããã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã N node 1 node 2 : node N s 1 t 1 s 2 t 2 : s N -1 t N -1 ïŒè¡ç®ã«ããŒãã®æ° N (1 †N †1000) ãäžãããããç¶ã N è¡ã«ã i çªç®ã®ããŒãã®æ
å ± node i ãäžãããããïŒçªç®ã®ããŒããæš¹åœ¢å³ã®äžçªäžã®ããŒããšãããç¶ã N -1 è¡ã« s i çªç®ã®ããŒããããã®åã§ãã t i çªç®ã®ããŒã (1 †s i â t i †N ) ãžåããæãäžããããã t 1 ãã t N -1 ãŸã§ã«ã¯ã2 ãã N ãŸã§ã®æ°ãäžåºŠã ãçŸããã ããŒãã®æ
å ±ã¯ä»¥äžã®åœ¢åŒã§ããã E ãªãã·ã§ã³ã§ãªãç©è³ªããŒãã E? ãªãã·ã§ã³ã§ããç©è³ªããŒãã type ãªãã·ã§ã³ã§ãªãéžæããŒãã type 㯠A ã R ã®ããããã§ã A 㯠altåã R 㯠or åã衚ãã type ? ãªãã·ã§ã³ã§ããéžæããŒãã type ã®åœ¢åŒã¯åäžã å
¥åããåŸãããæš¹åœ¢å³ã¯ã以äžã®æ¡ä»¶ãæºããã éžæããŒãã¯ïŒã€ä»¥äžã®åããŒããæã€ã éžæããŒãã®åããŒãã¯ãªãã·ã§ã³ã§ãªãã æš¹åœ¢å³ã®äžçªäžã®ããŒãã¯ãªãã·ã§ã³ã§ãªãã ã©ã®ããŒãã«ã€ããŠããåããŒãã®æ°ã¯ 10 ãè¶
ããªãã åºå äžããããæš¹åœ¢å³ããåŸããããã¹ãŠã®çµã¿åããã®ç·æ°ãïŒè¡ã«åºåããããã ããåºåãã¹ãå€ã¯éåžžã«å€§ãããªãããã®ã§ã代ããã« 1,000,000,007 ã§å²ã£ãäœããåºåããã å
¥åºåäŸ å
¥åäŸïŒ 12 A E E E R? E? E? E E E E? E 1 2 1 3 1 4 2 5 4 6 4 7 5 8 5 9 7 10 7 11 11 12 åºåäŸïŒ 11 å
¥åäŸïŒ 10 E R? E R E E A E E E 1 2 1 7 2 3 2 4 4 5 4 6 7 8 7 9 7 10 åºåäŸïŒ 24 | 37,224 |
Score : 500 points Problem Statement You are given a string S consisting of 0 and 1 . Find the maximum integer K not greater than |S| such that we can turn all the characters of S into 0 by repeating the following operation some number of times. Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r , do the following: if S_i is 0 , replace it with 1 ; if S_i is 1 , replace it with 0 . Constraints 1\leq |S|\leq 10^5 S_i(1\leq i\leq N) is either 0 or 1 . Input Input is given from Standard Input in the following format: S Output Print the maximum integer K such that we can turn all the characters of S into 0 by repeating the operation some number of times. Sample Input 1 010 Sample Output 1 2 We can turn all the characters of S into 0 by the following operations: Perform the operation on the segment S[1,3] with length 3 . S is now 101 . Perform the operation on the segment S[1,2] with length 2 . S is now 011 . Perform the operation on the segment S[2,3] with length 2 . S is now 000 . Sample Input 2 100000000 Sample Output 2 8 Sample Input 3 00001111 Sample Output 3 4 | 37,225 |
Princess' Japanese ãå§«æ§ã®æ¥æ¬èª English text is not available in this practice contest. ããè²§ä¹ãªåœã®ããŠãã°ã§åæ¢ãªãå§«æ§ã¯ïŒæ¥æ¬èªã®å匷ãããŠããïŒè² ããå«ããªæ§æ ŒãæäŒã£ãŠïŒãå§«æ§ã¯æ¥æ¬èªãæµæ¢ã«è©±ããããã«ãªã£ããïŒçºé³ã«å°ãã°ããäžèªç¶ãªãšãããæ®ã£ãŠããïŒã©ãããïŒæ¯é³ã®ç¡å£°åãšããæ¥æ¬èªåºæã®çºé³æ³ãé¢ä¿ããŠãããããïŒãå§«æ§ã¯å®ç§ãªæ¥æ¬èªè©±è
ãç®æããŠããããïŒäœãšããŠãèªåã®äžèªç¶ãªçºé³ãç¯æ£ããããšæã£ãŠããïŒããã§ãå§«æ§ã¯ïŒåŸè
ã§ããããªãã«å¯ŸããŠïŒçºé³ãç¯æ£ããããã®ããã°ã©ã ãäœæããããã«åœããïŒããªãã®ä»äºã¯ïŒå
¥åã§äžããããæ¥æ¬èªã®èªå¥ã«å¯ŸããŠïŒç¡å£°åã®çããæ§åã瀺ãããã°ã©ã ãäœæããããšã§ããïŒ ãå§«æ§ã¯ã²ãããªïŒã«ã¿ã«ãïŒæ¥åžžçã«äœ¿çšãããæŒ¢åãªã©ïŒæ¥æ¬èªã®è¡šèšäœç³»ã«ã€ããŠååã«ç¿åŸããŠããããïŒèªã¿æžãã«å°ãããšã¯ãã£ãã«ãªãïŒãšãããïŒãå§«æ§ã®åœã«ããã³ã³ãã¥ãŒã¿ã§ã¯æ¥æ¬èªã®å
¥åã«å°é£ãããããïŒããã°ã©ã ã«ãããŠã¯ïŒãããŒãåããšåŒã°ããè±æåã«ãã衚èšãçšããããšã«æ±ºããïŒ ãŸãïŒæ¥æ¬èªã®çºé³äœç³»ã«ã€ããŠå€§ãŸãã«èª¬æããå¿
èŠãããã ããïŒæ¥æ¬èªã§ã¯æïŒã¢ãŒã©ïŒãåäœãšããŠçºé³ããªãããïŒæã¯ä»¥äžã®ããããã®åœ¢ãããŠããïŒ ïŒæ¯é³ïŒ ïŒåé³ïŒ+ïŒæ¯é³ïŒ ïŒãyããwã以å€ã®åé³ïŒ+ãyã+ïŒæ¯é³ïŒ ä¿é³ïŒãã£ãïŒ æ¥é³ïŒãããïŒ é·é³ïŒããŒãïŒ ããã§ïŒæ¯é³ã¯ãaããiããuããeããoãã®ããããïŒåé³ã¯ãkããsããtããnããhããmããyããrããwããgããzããdããbããpãã®ããããã§ããïŒãã ãïŒãyãã®çŽåŸã«çŸããæ¯é³ã¯ãaããuããoãã«éãããïŒãŸãïŒãwãã®çŽåŸã«çŸããæ¯é³ã¯ãaãã«éãããïŒ ä¿é³ã¯çŽåŸã®æã®åé³ãéããŠè¡šèšãããïŒããšãã°ïŒãse k kiãïŒç³åšïŒã¯ä¿é³ãå«ãèªå¥ã®ã²ãšã€ã§ããïŒä¿é³ã¯æ¯é³ãããã¯ãnããyããwãã®åã«ã¯çŸããªãïŒãŸãã«ä¿é³ãæç¯æ«ã«çŸããããšã¯ãããïŒããã§ã¯ãã®ãããªäŸã¯èããªãïŒ æ¥é³ã¯åç¬ã®ãnãã«ãã£ãŠè¡šèšãããïŒãã ãïŒæ¯é³ãŸãã¯ãyãã®çŽåã«çŸãããšãã¯ïŒäžèšã®2.ãŸãã¯3.ãšã®åºå¥ãã€ããªããªãããïŒãnãã®çŽåŸã«ã¢ãã¹ãããã£ãŒãã€ããïŒä»¥äžã«ããã€ãã®äŸããããïŒ ta n goïŒåèªïŒïŒni n genïŒäººéïŒïŒha n 'eiïŒç¹æ ïŒ ç¹ã«ïŒä»¥äžã®éãã«ã¯æ³šæããããïŒ zeninïŒæ¯èªïŒïŒzen'inïŒå
šå¡ïŒïŒzenninïŒåä»»ïŒ é·é³ã¯åç¬ã§é³ç¯ãæ§æããããã§ã¯ãªããïŒåžžã«1æãäœåã«äœ¿ã£ãŠïŒããªãã¡2æã§ïŒçºé³ãããïŒæ¥æ¬èªã§ã¯é·é³ãšçé³ã®å¯Ÿç«ãããïŒãããé·é³ãšçé³ã®éãã«ãã£ãŠèªå¥ãåºå¥ãããããïŒé·é³ãšçé³ã®éãã¯éèŠã§ããïŒããã§ã¯é·é³ã¯æ¯é³ïŒãaããiããuãã®ããããïŒãéããŠè¡šèšããããšãšããïŒä»¥äžã«ããã€ãã®äŸããããïŒ ra a menïŒã©ãŒã¡ã³ïŒïŒbi i ruïŒããŒã«ïŒïŒkyu u syu u ïŒä¹å·ïŒïŒkare i ïŒã«ã¬ãŒïŒïŒkyo u toïŒäº¬éœïŒ æ¥é³ïŒä¿é³ïŒé·é³ã¯å
é ã«çŸããïŒãŸãé£ç¶ããŠçŸããªãïŒãŸãæ¥é³ãšä¿é³ãäºãã«é£ãåã£ãŠçŸããããšããªãïŒ ããŠïŒæ¥æ¬èªã§ã¯ç¹å®ã®æ¡ä»¶äžã«ãããŠæ¯é³ããã¡ããšçºé³ãããªãããšãããïŒãããæ¯é³ã®ç¡å£°åãšåŒã°ããçŸè±¡ã§ããïŒæ¯é³ãç¡å£°åãããæ¡ä»¶ã«é¢ããŠã¯è«žèª¬ãããïŒããã§ã¯æ¯èŒçç°¡åã§ãã€æ©æ¢°çé©çšãå¯èœã§ãã以äžã®ãããªå Žåã«ã€ããŠèããããšã«ããïŒãã ãïŒç¡å£°åé³ãšã¯ãkããsããtããhããpãã®ããšã§ããïŒãŸãïŒãããã«ãyããç¶ãããã®ïŒãkyããªã©ïŒã䟿å®çã«ç¡å£°åé³ãšã¿ãªãïŒ æ¯é³ãiããuãã®çé³ã«ã€ããŠïŒãã®æ¯é³ãç¡å£°åé³ã«ã¯ããŸãããšãïŒãŸãã¯ç¡å£°åé³ã®çŽåŸã§ãããèªå¥ã®æ«å°Ÿã«ãããšãïŒãã®èŠåã¯ïŒæ¯é³ãiããuãã®çŽåŸã®æãä¿é³ã§ãã£ãŠãé©çšãããïŒä»¥äžã«ããã€ãã®äŸã瀺ãïŒ k u saïŒèïŒïŒhat i ïŒèïŒïŒk i k u ïŒèïŒïŒk i tteïŒåæïŒïŒk i pp u ïŒå笊ïŒïŒsuup u ïŒã¹ãŒãïŒ æ¯é³ãaããoãã«ã€ããŠïŒåäžã®æ¯é³ãç¡å£°åé³ãšãšãã«é£ç¶ãã2ã€ä»¥äžã®æã§çŸãããšãïŒãã ãïŒãã®é£ç¶ããæã®ãã¡ã§æåŸã®ãã®ã«ã€ããŠã¯é€å€ãããïŒä»¥äžã«ããã€ãã®äŸã瀺ãïŒä¿é³ããã³é·é³ã¯ã²ãšã€ã®æãæ§æããããšããïŒé£ç¶éšåã®å
é ãŸãã¯éäžã«ïŒä¿é³ãŸãã¯é·é³ããã£ãŠã¯ãªããªããšããç¹ã«ã¯æ³šæããããšïŒ h a haïŒæ¯ïŒïŒk o toïŒçŽïŒïŒh a k a taïŒåå€ïŒïŒs a kanaïŒéïŒïŒk a katoïŒãããšïŒ ãã ãïŒäžèšã«è©²åœããå
šéšã®æ¯é³ãç¡å£°åãããããã§ã¯ãªãïŒããã¯ïŒè€æ°ã®æ¯é³ãç¶ããŠç¡å£°åãããããšã¯ãªãããšã«ããïŒæ¯é³ãç¡å£°åãããã®ã¯ïŒæåã®æ¯é³ã§ããå ŽåïŒãŸãã¯çŽè¿ã®æ¯é³ãç¡å£°åãããªãã£ãå Žåã§ããïŒãŸããããã®å Žåã«ãããïŒããšãã°ïŒãh a k a taãã«ã€ããŠã¯ïŒæåã®ãaãã¯ç¡å£°åããããïŒ2çªç®ã®ãaãã¯ç¡å£°åãããªãïŒåæ§ã«ããŠïŒãk i pp u ãã«ã€ããŠã¯ïŒèªäžã®ãiãã¯ç¡å£°åããããïŒèªå°Ÿã®ãuãã¯ç¡å£°åãããã«çºé³ãããïŒ ãhott o kouhiiãïŒãããã³ãŒããŒïŒã¯ãããã«ããäŸã®ã²ãšã€ã§ããïŒãããæã«åè§£ãããšãho-ïŒä¿é³ïŒ-to-ko-ïŒé·é³ïŒ-hi-ïŒé·é³ïŒãã®ããã«ãªãïŒæåã®ãoãã¯ïŒçŽåŸã®æãä¿é³ã§ããããïŒäžèšã®æ³šææžãã«ããããã«ãç¡å£°åé³ + oããé£ç¶ããŠãããšã¯ã¿ãªãããªãïŒããªãã¡ïŒæåïŒ1æç®ïŒã®ãoãã¯ç¡å£°åãããªãïŒãšãããïŒæ¬¡ã®ãoãã«ã€ããŠã¯ïŒçŽåŸã«é·é³ããããã®ã®ãtoããkoããšããããã«ãç¡å£°åé³ + oããé£ç¶ããŠçŸããŠããïŒãããã£ãŠïŒ2çªç®ïŒ3æç®ïŒã®ãoãã¯ç¡å£°åãããïŒãŸãïŒèªå°Ÿä»è¿ã«ç¡å£°åé³ãhãã®åŸã«çŸãããiããååšãããïŒããã¯é·é³ã§ããããç¡å£°åãããªãïŒ Input å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒããããã®ããŒã¿ã»ããã¯100æå以äžã®1ã€ã®èªå¥ãå«ãŸãã1è¡ã ããããªãïŒããããã®èªå¥ã«ã¯è±å°æåãšã¢ãã¹ãããã£ãŒã ããå«ãŸããïŒãŸãïŒããããã®èªå¥ã¯ïŒå顿äžã§èª¬æããæã ãããæ§æããããïŒæšæºæ¥æ¬èªã®èªå¥ã§ãããšã¯éããªãïŒ å
¥åã®çµããã¯ã#ãã®ã¿ãå«ãŸããè¡ã«ãã£ãŠè¡šãããïŒããã¯ããŒã¿ã»ããã«å«ãŸããªãïŒ Output ããããã®ããŒã¿ã»ããã«ã€ããŠïŒäžããããèªå¥ãïŒç¡å£°åãããæ¯é³ãæ¬åŒ§ã§å²ãã ããã§äžè¡ã«åºåããªããïŒ Sample Input kusa haha hakata kippu sasakisan sosonokasu hottokouhii i # Output for the Sample Input k(u)sa h(a)ha h(a)kata k(i)ppu s(a)sak(i)san s(o)sonokas(u) hott(o)kouhii i | 37,226 |
Score : 100 points Problem Statement Find the number of integers between 1 and K (inclusive) satisfying the following condition, modulo 10^9 + 7 : The sum of the digits in base ten is a multiple of D . Constraints All values in input are integers. 1 \leq K < 10^{10000} 1 \leq D \leq 100 Input Input is given from Standard Input in the following format: K D Output Print the number of integers satisfying the condition, modulo 10^9 + 7 . Sample Input 1 30 4 Sample Output 1 6 Those six integers are: 4, 8, 13, 17, 22 and 26 . Sample Input 2 1000000009 1 Sample Output 2 2 Be sure to print the number modulo 10^9 + 7 . Sample Input 3 98765432109876543210 58 Sample Output 3 635270834 | 37,227 |
Equation æçåŒ English text is not available in this practice contest. è«çæŒç®ã§ã¯ïŒå€ã¯ T ãš F ã®2çš®é¡ã ããæ±ãïŒ "-"ãåé
æŒç®åïŒå
¥åã 1 ã€ã®æŒç®ã衚ãèšå·ïŒïŒ "*", "+", "->" ã 2 é
æŒç®åïŒå
¥åã 2 ã€ã®æŒç®ã衚ãèšå·ïŒãšããïŒ "-" ã¯è«çåŠå®(NOT)ïŒ "*" ã¯è«çç©(AND)ïŒ "+" ã¯è«çå(OR)ïŒ "->" ã¯è«çå
å«(IMP)ãè¡šãæŒç®åã§ããïŒ ãããã®è«çæŒç®ã®ççå€è¡šãäžã®è¡šã«ç€ºãïŒ x y -x (x*y) (x+y) (x->y) T T F T T T T F F F T F F T T F T T F F T F F T è«çåŒã¯ä»¥äžã®ããããã®åœ¢åŒã§ããïŒ X, Yã¯è«çåŒãšãïŒ 2 é
æŒç®åã¯å¿
ãæ¬åŒ§ã§å²ããã®ãšããïŒ å®æ°: T, F 倿°: a, b, c, d, e, f, g, h, i, j, k è«çåŠå®: -X è«çç©: (X*Y) è«çå: (X+Y) è«çå
å«: (X->Y) 2 ã€ã®è«çåŒãçå· "=" ã§çµåããçåŒãäžããããïŒ æçåŒãšã¯ïŒåŒã«çŸãã倿°ãã©ã®ãããªå€ã§ãã£ãŠãæç«ããçåŒã®ããšã§ããïŒ äžããããçåŒãæçåŒã§ããããå€å®ããããã°ã©ã ãäœãããïŒ Input å
¥åã¯è€æ°ã®è¡ã§æ§æããïŒåè¡ã¯ 1 ã€ã®ããŒã¿ã»ããã§ããïŒ ããŒã¿ã»ããã¯T, F, a, b, c, d, e, f, g, h, i, j, k, (, ), =, -, +, *, > ããæãæååã§ããïŒ ç©ºçœãªã©ä»ã®æåãå«ãŸãªãïŒ 1 è¡ã®æåæ°ã¯ 1000 æå以äžãšä»®å®ããŠããïŒ 1 ã€ã®ããŒã¿ã»ããã¯çåŒã²ãšã€ãå«ãïŒ çåŒã®ææ³ã¯æ¬¡ã® BNF ã§äžããããïŒ ãã¹ãŠã®çåŒã¯ãã®æ§æèŠåã«åŸãïŒ <equation> ::= <formula> "=" <formula> <formula> ::= "T" | "F" | "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "-" <formula> | "(" <formula> "*" <formula> ")" | "(" <formula> "+" <formula> ")" | "(" <formula> "->" <formula> ")" å
¥åã®çµãã㯠"#" ã ããããªãè¡ã§ç€ºãããŠããïŒãã®è¡ã¯ããŒã¿ã»ããã§ã¯ãªãïŒ Output åããŒã¿ã»ããã«ã€ããŠïŒçåŒãæçåŒã§ããã°âYESâãïŒ ããã§ãªããã°âNOâããããã1è¡ã«åºåããªããïŒ åºåã«ã¯äœåãªæåãå«ãã§ã¯ãªããªãïŒ Sample Input -(a+b)=(-a*-b) (a->b)=(-a+b) ((a*T)+b)=(-c+(a*-b)) # Output for Sample Input YES YES NO | 37,228 |
Problem G. Additions You are given an integer $N$ and a string consisting of ' + ' and digits. You are asked to transform the string into a valid formula whose calculation result is smaller than or equal to $N$ by modifying some characters. Here, you replace one character with another character any number of times, and the converted string should still consist of ' + ' and digits. Note that leading zeros and unary positive are prohibited. For instance, ' 0123+456 ' is assumed as invalid because leading zero is prohibited. Similarly, ' +1+2 ' and ' 2++3 ' are also invalid as they each contain a unary expression. On the other hand, ' 12345 ', ' 0+1+2 ' and ' 1234+0+0 ' are all valid. Your task is to find the minimum number of the replaced characters. If there is no way to make a valid formula smaller than or equal to $N$, output $-1$ instead of the number of the replaced characters. Input The input consists of a single test case in the following format. $N$ $S$ The first line contains an integer $N$, which is the upper limit of the formula ($1 \leq N \leq 10^9$). The second line contains a string $S$, which consists of ' + ' and digits and whose length is between $1$ and $1,000$, inclusive. Note that it is not guaranteed that initially $S$ is a valid formula. Output Output the minimized number of the replaced characters. If there is no way to replace, output $-1$ instead. Examples Sample Input 1 100 +123 Output for Sample Input 1 2 Sample Input 2 10 +123 Output for Sample Input 2 4 Sample Input 3 1 +123 Output for Sample Input 3 -1 Sample Input 4 10 ++1+ Output for Sample Input 4 2 Sample Input 5 2000 1234++7890 Output for Sample Input 5 2 In the first example, you can modify the first two characters and make a formula ' 1+23 ', for instance. In the second example, you should make ' 0+10 ' or ' 10+0 ' by replacing all the characters. In the third example, you cannot make any valid formula less than or equal to $1$. | 37,230 |
æç³ãã¿ãã ãèªåã®éã¯èªåã§åãéãããã¢ãããŒã«ãããç¥ç€Ÿãèªåèªèº«ã®æã§éå¢ã決ãããã¿ãããäœããŸããããã®ãã¿ãããåŒã人ã«ã¯ãŸã6ã€ã®ç³ãæããŠãããããã®æããç³ã®äžã€ç®ãšäºã€ç®ãçµã¶ ç·åãäžã€ç®ãšåã€ç®ãçµã¶ ç·åãäºã€ç®ãšå
ã€ç®ãçµã¶ ç·åã®3æ¬ã®ç·åã®äº€ç¹ãé ç¹ãšãã äžè§åœ¢ã®é¢ç©ããéå¢ã決ãããšãããã®ã§ããåéå¢ãšäžè§åœ¢ã®é¢ç©ãšã®é¢ä¿ã¯ä»¥äžã®ãšããã§ãã ç·åã®äº€ç¹ãé ç¹ãšããäžè§åœ¢ã®é¢ç© éå¢ 1,900,000ä»¥äž å€§å (dai-kichi) 1,000,000以äž1,900,000æªæº äžå (chu-kichi) 100,000以äž1,000,000æªæº å (kichi) 0ãã倧ãã 100,000æªæº å°å (syo-kichi) äžè§åœ¢ãªã å¶ (kyo) ããããäžè§åœ¢ã®é¢ç©ã®å€§ããã®å€å®ã¯ç¥äž»ãããæèšç®ã§ãã£ãŠããã®ã§æ£ç¢ºãšã¯ããããæéãããã£ãŠããŸããŸããããã§è¿æã«äœãåªç§ãªããã°ã©ãã§ããããªãã¯ãäžå»ã§ãæ©ãããã°ã©ã ãæžããŠç¥äž»ãããå©ããŠãããããšã«ããŸããã 3 æ¬ã®ç·åã®æ
å ±ãå
¥åãšããç·åã®äº€ç¹ãé ç¹ãšãã äžè§åœ¢ã®é¢ç©ããéå¢ãåºåããããã°ã©ã ãäœæããŠãã ãããç·åã®æ
å ±ã¯å§ç¹ã®åº§æš ( x 1 , y 1 ) ãšãçµç¹ã®åº§æš ( x 2 , y 2 ) ãäžããããå§ç¹ãšçµç¹ã®åº§æšã¯å¿
ãç°ãªãããšãšããŸãããŸãã2 ã€ä»¥äžã®ç·åãåäžçŽç·äžã«ããå Žåã亀ç¹ãæããªã 2 ã€ã®ç·åãããå Žåã3 ã€ã®ç·åã 1 ç¹ã§äº€ããå Žåã¯ããäžè§åœ¢ãªãããšãªããŸãã Input è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒã4ã€ã®è¡ã§ç€ºãããŸãã åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã line 1 line 2 line 3 i è¡ç®ã« i çªç®ã®ç·åã®æ
å ±ãäžããããŸããåç·åã®æ
å ±ã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã x 1 y 1 x 2 y 2 ç·åã®ç«¯ç¹ã®åº§æšãè¡šãæŽæ° ( x 1 , y 1 ), ( x 2 , y 2 ) (-1000 †x 1 , y 1 , x 2 , y 2 †1000 ) ã空çœåºåãã§äžããããŸãã Output ããŒã¿ã»ããæ¯ã«ããã¿ããã®çµæãïŒè¡ã«åºåããŸãã Sample Input -3 -2 9 6 3 -2 7 6 -1 0 5 0 2 2 -1 -1 0 1 2 1 -3 -1 3 1 0 0 0 0 Output for the Sample Input syo-kichi kyo | 37,231 |
Min-Max Element Write a program which manipulates a sequence $A = \{a_0, a_1, ..., a_{n-1}\}$ by the following operations: min($b, e$): report the minimum element in $a_b, a_{b+1}, ..., a_{e-1}$ max($b, e$): report the maximum element in $a_b, a_{b+1}, ..., a_{e-1}$ Input The input is given in the following format. $n$ $a_0 \; a_1, ..., \; a_{n-1}$ $q$ $com_1 \; b_1 \; e_1$ $com_2 \; b_2 \; e_2$ : $com_{q} \; b_{q} \; e_{q}$ In the first line, $n$ (the number of elements in $A$) is given. In the second line, $a_i$ (each element in $A$) are given. In the third line, the number of queries $q$ is given and each query is given in the following $q$ lines. $com_i$ denotes a type of query. 0 and 1 represents min($b, e$) and max($b, e$) respectively. Output For each query, print the minimum element or the maximum element in a line. Constraints $1 \leq n \leq 1,000$ $-1,000,000,000 \leq a_i \leq 1,000,000,000$ $1 \leq q \leq 1,000$ $0 \leq b < e \leq n$ Sample Input 1 7 8 3 7 1 9 1 4 3 0 0 3 0 1 5 1 0 7 Sample Output 1 3 1 9 | 37,232 |
Score : 300 points Problem Statement Snuke is making sugar water in a beaker. Initially, the beaker is empty. Snuke can perform the following four types of operations any number of times. He may choose not to perform some types of operations. Operation 1: Pour 100A grams of water into the beaker. Operation 2: Pour 100B grams of water into the beaker. Operation 3: Put C grams of sugar into the beaker. Operation 4: Put D grams of sugar into the beaker. In our experimental environment, E grams of sugar can dissolve into 100 grams of water. Snuke will make sugar water with the highest possible density. The beaker can contain at most F grams of substances (water and sugar combined), and there must not be any undissolved sugar in the beaker. Find the mass of the sugar water Snuke will make, and the mass of sugar dissolved in it. If there is more than one candidate, any of them will be accepted. We remind you that the sugar water that contains a grams of water and b grams of sugar is \frac{100b}{a + b} percent. Also, in this problem, pure water that does not contain any sugar is regarded as 0 percent density sugar water. Constraints 1 \leq A < B \leq 30 1 \leq C < D \leq 30 1 \leq E \leq 100 100A \leq F \leq 3 000 A , B , C , D , E and F are all integers. Inputs Input is given from Standard Input in the following format: A B C D E F Outputs Print two integers separated by a space. The first integer should be the mass of the desired sugar water, and the second should be the mass of the sugar dissolved in it. Sample Input 1 1 2 10 20 15 200 Sample Output 1 110 10 In this environment, 15 grams of sugar can dissolve into 100 grams of water, and the beaker can contain at most 200 grams of substances. We can make 110 grams of sugar water by performing Operation 1 once and Operation 3 once. It is not possible to make sugar water with higher density. For example, the following sequences of operations are infeasible: If we perform Operation 1 once and Operation 4 once, there will be undissolved sugar in the beaker. If we perform Operation 2 once and Operation 3 three times, the mass of substances in the beaker will exceed 200 grams. Sample Input 2 1 2 1 2 100 1000 Sample Output 2 200 100 There are other acceptable outputs, such as: 400 200 However, the output below is not acceptable: 300 150 This is because, in order to make 300 grams of sugar water containing 150 grams of sugar, we need to pour exactly 150 grams of water into the beaker, which is impossible. Sample Input 3 17 19 22 26 55 2802 Sample Output 3 2634 934 | 37,233 |
Score : 500 points Problem Statement Given is a string S of length N . Find the maximum length of a non-empty string that occurs twice or more in S as contiguous substrings without overlapping. More formally, find the maximum positive integer len such that there exist integers l_1 and l_2 ( 1 \leq l_1, l_2 \leq N - len + 1 ) that satisfy the following: l_1 + len \leq l_2 S[l_1+i] = S[l_2+i] (i = 0, 1, ..., len - 1) If there is no such integer len , print 0 . Constraints 2 \leq N \leq 5 \times 10^3 |S| = N S consists of lowercase English letters. Input Input is given from Standard Input in the following format: N S Output Print the maximum length of a non-empty string that occurs twice or more in S as contiguous substrings without overlapping. If there is no such non-empty string, print 0 instead. Sample Input 1 5 ababa Sample Output 1 2 The strings satisfying the conditions are: a , b , ab , and ba . The maximum length among them is 2 , which is the answer. Note that aba occurs twice in S as contiguous substrings, but there is no pair of integers l_1 and l_2 mentioned in the statement such that l_1 + len \leq l_2 . Sample Input 2 2 xy Sample Output 2 0 No non-empty string satisfies the conditions. Sample Input 3 13 strangeorange Sample Output 3 5 | 37,234 |
Problem G JAG-channel II JAG (Japan Alumni Group) is a group of $N$ members that devotes themselves to activation of the competitive programming world. The JAG staff members talk every day on the BBS called JAG-channel. There are several threads in JAG-channel and these are kept sorted by the time of their latest posts in descending order. One night, each of the $N$ members, identified by the first $N$ uppercase letters respectively, created a thread in JAG-channel. The next morning, each of the $N$ members posted in exactly $K$ different threads which had been created last night. Since they think speed is important, they viewed the threads from top to bottom and posted in the thread immediately whenever they came across an interesting thread. Each member viewed the threads in a different period of time, that is, there was no post of other members while he/she was submitting his/her $K$ posts. Your task is to estimate the order of the members with respect to the periods of time when members posted in the threads. Though you do not know the order of the threads created, you know the order of the posts of each member. Since the threads are always kept sorted, there may be invalid orders of the members such that some members cannot post in the top-to-bottom order of the threads due to the previous posts of other members. Find out the lexicographically smallest valid order of the members. Input The input consists of a single test case. The first line contains two integers separated by a space: $N$ $(4 \leq N \leq 16)$ and $K$ $(N - 3 \leq K \leq N - 1)$. Then $N$ lines of strings follow. Each of the $N$ lines consists of exactly $K$ distinct characters. The $j$-th character of the $i$-th line denotes the $j$-th thread in which the member denoted by the $i$-th uppercase letter posted. Each thread is represented by its creator (e.g. ' B ' represents the thread created by member B, the second member). It is guaranteed that at least one valid order exists. Output Display a string that consists of exactly $N$ characters in a line, which denotes the valid order in which the members posted in the threads. The $i$-th character of the output should represent the member who posted in the $i$-th period. In case there are multiple valid orders, output the lexicographically smallest one. Sample Input 1 7 4 DEFG FEDA EFGB BGEA AGFD DABC CADE Output for the Sample Input 1 ABCDEFG Sample Input 2 4 3 CDB DAC BAD ABC Output for the Sample Input 2 DCBA Sample Input 3 16 13 NDHPFJIBLMCGK CMDJKPOLGIHNE MOLBIEJFPHADN KPNAOHBLMCGEI FCMLBHDOANJPK NHIGLOAPKJDMC KMLBIPHDEOANJ IEGCMLBOAPKJD JNAOEDHBLMCGF OEDHPFIBLMGKC GMLBIFPHDNAEO ENHGOPKJDMCAF JKPAOBLGEIHNF HPKFGJEIBLCOM LBINEJDAGFKPH FGMOCADJENIBL Output for the Sample Input 3 PONCAKJGIEDHMFBL | 37,235 |
Problem A: Membership Management Peter is a senior manager of Agile Change Management (ACM) Inc., where each employee is a member of one or more task groups. Since ACM is agile, task groups are often reorganized and their members frequently change, so membership management is his constant headache. Peter updates the membership information whenever any changes occur: for instance, the following line written by him means that Carol and Alice are the members of the Design Group. design:carol,alice. The name preceding the colon is the group name and the names following it specify its members. A smaller task group may be included in a larger one. So, a group name can appear as a member of another group, for instance, as follows. development:alice,bob,design,eve. Simply unfolding the design above gives the following membership specification, which is equivalent to the original. development:alice,bob,carol,alice,eve. In this case, however, alice occurs twice. After removing one of the duplicates, we have the following more concise specification. development:alice,bob,carol,eve. Your mission in this problem is to write a program that, given group specifications, identifies group members. Note that Peter's specifications can include deeply nested groups. In the following, for instance, the group one contains a single member dave. one:another. another:yetanother. yetanother:dave. Input The input is a sequence of datasets, each being in the following format. n group 1 : member 1,1 ,..., member 1, m 1 . . . . group i : member i ,1 ,..., member i , m i . . . . group n : member n ,1 ,..., member n , m n . The first line contains n, which represents the number of groups and is a positive integer no more than 100. Each of the following n lines contains the membership information of a group: group i (1 †i †n ) is the name of the i -th task group and is followed by a colon ( : ) and then the list of its m i member s that are delimited by a comma ( , ) and terminated by a period ( . ). Those group names are mutually different. Each m i (1 †i †n ) is between 1 and 10, inclusive. A member is another group name if it is one of group 1 , group 2 ,..., or groupn. Otherwise it is an employee name. There are no circular (or recursive) definitions of group(s). You may assume that m i member names of a group are mutually different. Each group or employee name is a non-empty character string of length between 1 and 15, inclusive, and consists of lowercase letters. The end of the input is indicated by a line containing a zero. Output For each dataset, output the number of employees included in the first group of the dataset, that is group 1 , in a line. No extra characters should occur in the output. Sample Input 2 development:alice,bob,design,eve. design:carol,alice. 3 one:another. another:yetanother. yetanother:dave. 3 friends:alice,bob,bestfriends,carol,fran,badcompany. bestfriends:eve,alice. badcompany:dave,carol. 5 a:b,c,d,e. b:c,d,e,f. c:d,e,f,g. d:e,f,g,h. e:f,g,h,i. 4 aa:bb. cc:dd,ee. ff:gg. bb:cc. 0 Output for the Sample Input 4 1 6 4 2 | 37,236 |
Score : 200 points Problem Statement Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X , and that of Empire B is located at coordinate Y . One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control. If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out. X < Z \leq Y x_1, x_2, ..., x_N < Z y_1, y_2, ..., y_M \geq Z Determine if war will break out. Constraints All values in input are integers. 1 \leq N, M \leq 100 -100 \leq X < Y \leq 100 -100 \leq x_i, y_i \leq 100 x_1, x_2, ..., x_N \neq X x_i are all different. y_1, y_2, ..., y_M \neq Y y_i are all different. Input Input is given from Standard Input in the following format: N M X Y x_1 x_2 ... x_N y_1 y_2 ... y_M Output If war will break out, print War ; otherwise, print No War . Sample Input 1 3 2 10 20 8 15 13 16 22 Sample Output 1 No War The choice Z = 16 satisfies all of the three conditions as follows, thus they will come to an agreement. X = 10 < 16 \leq 20 = Y 8, 15, 13 < 16 16, 22 \geq 16 Sample Input 2 4 2 -48 -1 -20 -35 -91 -23 -22 66 Sample Output 2 War Sample Input 3 5 3 6 8 -10 3 1 5 -100 100 6 14 Sample Output 3 War | 37,237 |
Score : 900 points Problem Statement You are in charge of controlling a dam. The dam can store at most L liters of water. Initially, the dam is empty. Some amount of water flows into the dam every morning, and any amount of water may be discharged every night, but this amount needs to be set so that no water overflows the dam the next morning. It is known that v_i liters of water at t_i degrees Celsius will flow into the dam on the morning of the i -th day. You are wondering about the maximum possible temperature of water in the dam at noon of each day, under the condition that there needs to be exactly L liters of water in the dam at that time. For each i , find the maximum possible temperature of water in the dam at noon of the i -th day. Here, consider each maximization separately, that is, the amount of water discharged for the maximization of the temperature on the i -th day, may be different from the amount of water discharged for the maximization of the temperature on the j -th day (jâ i) . Also, assume that the temperature of water is not affected by anything but new water that flows into the dam. That is, when V_1 liters of water at T_1 degrees Celsius and V_2 liters of water at T_2 degrees Celsius are mixed together, they will become V_1+V_2 liters of water at \frac{T_1*V_1+T_2*V_2}{V_1+V_2} degrees Celsius, and the volume and temperature of water are not affected by any other factors. Constraints 1†N †5*10^5 1†L †10^9 0†t_i †10^9(1â€iâ€N) 1†v_i †L(1â€iâ€N) v_1 = L L , each t_i and v_i are integers. Input Input is given from Standard Input in the following format: N L t_1 v_1 t_2 v_2 : t_N v_N Output Print N lines. The i -th line should contain the maximum temperature such that it is possible to store L liters of water at that temperature in the dam at noon of the i -th day. Each of these values is accepted if the absolute or relative error is at most 10^{-6} . Sample Input 1 3 10 10 10 20 5 4 3 Sample Output 1 10.0000000 15.0000000 13.2000000 On the first day, the temperature of water in the dam is always 10 degrees: the temperature of the only water that flows into the dam on the first day. 10 liters of water at 15 degrees of Celsius can be stored on the second day, by discharging 5 liters of water on the night of the first day, and mix the remaining water with the water that flows into the dam on the second day. 10 liters of water at 13.2 degrees of Celsius can be stored on the third day, by discharging 8 liters of water on the night of the first day, and mix the remaining water with the water that flows into the dam on the second and third days. Sample Input 2 4 15 0 15 2 5 3 6 4 4 Sample Output 2 0.0000000 0.6666667 1.8666667 2.9333333 Sample Input 3 4 15 1000000000 15 9 5 8 6 7 4 Sample Output 3 1000000000.0000000 666666669.6666666 400000005.0000000 293333338.8666667 Although the temperature of water may exceed 100 degrees Celsius, we assume that water does not vaporize. | 37,238 |
H : Typing Game / ã¿ã€ãã³ã°ã²ãŒã ç©èª ããããã¯ïŒã¿ã€ãã³ã°åãéããæéã§ãïŒçããã¯æ©ãæ£ç¢ºãªã¿ã€ãã³ã°ãããããšãã§ããŸããïŒ Letâs enjoy Typing Game! åé¡ ã¿ã€ãã³ã°ã²ãŒã ã®ã²ãŒã ã·ã¹ãã ãšããŠïŒãžã£ããžåŽãçšæããAIã®åºåã«å¯ŸããŠå¯Ÿè©±çã«åäœããããã°ã©ã ãäœæããïŒ AI㯠N åã®æååãã¿ã€ãããã²ãŒã ããã¬ã€ããïŒAIã¯äœåãæã£ãŠããïŒãã®åæå€ã¯ H ã§ããïŒAIã¯äœåãããéãæåã®ã¿ã€ããè¡ãïŒã·ã¹ãã ã¯AIãã¿ã€ããã¹ãæååãæç€ºããïŒã·ã¹ãã ã¯AIãã¿ã€ãããæåãåãåãïŒæ¬¡ã«ã¿ã€ããã¹ãæåãšäžèŽãããå€å®ããïŒAIãæååã 1 ã€ã¿ã€ããçµãããšïŒã·ã¹ãã ã¯æ¬¡ã®æååãæç€ºããïŒ ãŸãïŒåæååã«ã¯ãã¹ã¿ã€ãã®èš±å®¹åæ°ãå®ããããŠããïŒAIã®ããæååã«ããããã¹ã¿ã€ãã®åæ°ãèš±å®¹åæ°ãè¶
ããŠããŸããšAIã®äœåã 1 æžãïŒã·ã¹ãã ã¯åŒ·å¶çã«æ¬¡ã®æååãæç€ºããïŒAIã®äœåã 0 ã«ãªã£ããã²ãŒã ãªãŒããŒãšãªãïŒæåŸã®æååã«ãããŠïŒã¿ã€ãã®æåãŸãã¯ãã¹ã¿ã€ãåæ°ã®è¶
éãèµ·ãã£ãåŸã§ïŒAIã®äœåãæ®ã£ãŠããã°ã²ãŒã ã¯ãªã¢ãšãªãïŒ å
¥åºååœ¢åŒ ãŸãïŒå
¥åã以äžã®åœ¢åŒã§äžããããïŒ N H S_1 T_1 ... S_N T_N 1è¡ç®ã«æååã®æ° N ãšAIã®äœå H ã空çœåºåãã§äžããããïŒ ç¶ã N è¡ã«ã¯ i è¡ç®ã« i çªç®ã®æåå S_i ãšïŒãã®æååã«å¯Ÿãããã¹ã¿ã€ãã®èš±å®¹åæ° T_i ã空çœåºåãã§äžããããïŒ ãã®å
¥åã¯ä»¥äžã®å¶çŽãæºããïŒ 1 †N †100 1 †H †10 1 †|S_i| †15 S_i ã¯ã¢ã«ãã¡ããã'a'-'z'ïŒãŸãã¯'A'-'Z'ã®ã¿ãå«ãïŒ 0 †T_i †20 ã·ã¹ãã ã¯æåå S_1 ããæåå S_N ãŸã§é çªã«åŠçãããïŒ i çªç®ã®æåå S_i ã«ã€ããŠïŒAIã j æåç®ãŸã§ã¿ã€ããæåãããŠããå ŽåïŒä»¥äžã®åŠçãããïŒ ã·ã¹ãã ã¯AIã«å¯ŸããŠïŒ S_i ãåºåããïŒãã®ãšãïŒ S_i ã®1æåç®ãã j æåç®ã"_" (ã¢ã³ããŒã¹ã³ã¢) ã«çœ®ãæããïŒã·ã¹ãã ãééã£ãæååãåºåãããšïŒAIã¯åäœãäžæãWrong AnswerãšãªãïŒã·ã¹ãã ãåºåããæååã S ã§ããå ŽåïŒC/C++ã§ã®åºåäŸã¯ä»¥äžã®ããã«ãªãïŒ printf("? %s\n", S); fflush(stdout); AIã¯ã·ã¹ãã ã®åºåãåãåããšïŒ c ã®åœ¢åŒã§è¿çããïŒ c ã¯AIãã¿ã€ãããæåã§ããïŒ c ã¯ã¢ã«ãã¡ããã'a'-'z'ãããªãïŒC/C++ã§ã®è¿çã®åãåãæ¹ã®äŸã¯ä»¥äžã®ããã«ãªãïŒ char c[2]; scanf("%s", c); /* char c; scanf("%c", &c); ã¯ç©ºçœæåèªã¿èŸŒã¿ã®ä»æ§äžã®çç±ã§éæšå¥šã§ãïŒ */ ã·ã¹ãã ã¯AIã®åºåãåãåããšãŸãAIãã¿ã€ãããæåãš S_i ã® j+1 æåç®ãäžèŽããŠãããå€å®ããïŒãã®å€å®ã®éïŒå€§æåãšå°æåã¯åºå¥ããªãããšã«æ³šæããïŒäžèŽããŠãããšãã¯ïŒ j+1 æåç®ãŸã§ã¿ã€ãã«æåãããšããïŒããã§ j+1 æåç®ã S_i ã®æåŸã®æåã ã£ãå ŽåïŒ S_i ã®ã¿ã€ãã«æåãããšã S_i ã®åŠçãçµããïŒAIãã¿ã€ãããæåãš S_i ã® j+1 æåç®ãäžèŽããŠããªããã°ïŒ S_i ã«å¯Ÿãããã¹ã¿ã€ãåæ°ã1ã ãå¢ããïŒãã®ãšã T_i ãè¶
ããŠããã°AIã®äœåã 1 æžããïŒ S_i ã®åŠçãçµããïŒ S_i ã®åŠçãçµãããšãïŒAIã®äœåã 0 ã§ããã°ã²ãŒã ãªãŒããŒãšããïŒã²ãŒã ãªãŒããŒã§ãªããã° i ã N ã®ãšãã²ãŒã ã¯ãªã¢ãšãïŒããã§ãªããã° S_{i+1} ã®åŠçã«ç§»ãïŒ ãŸãïŒã²ãŒã ãªãŒããŒã®éã«ã¯"! Game Over"ãïŒã²ãŒã ã¯ãªã¢ã®éã«ã¯"! Game Clear [ã¿ã€ãæåç]"ãåºåããïŒã¿ã€ãæåç㯠(æåã¿ã€ãæ°) / (åèšã¿ã€ãæ°) à 100 ã§èšç®ãããå€ãå°æ°ç¹ä»¥äžç¬¬2äœã§åãæšãŠãå€ãšããïŒå°æ°ç¹ä»¥äžç¬¬1äœã0ã§ãã£ãŠãå°æ°ç¹ä»¥äžç¬¬1äœãŸã§åºåããïŒC/C++ã§ã®åºåäŸã¯ä»¥äžã®ããã«ãªãïŒ printf("! Game Over\n"); fflush(stdout); printf("! Game Clear %.1lf\n", success_type_rate); fflush(stdout); â»printfã®æžåŒã"%.1lf"ãšããå ŽåïŒåºåãããæµ®åå°æ°ç¹æ°ã¯å°æ°ç¹ä»¥äžç¬¬2äœãåæšäºå
¥ãããïŒãã®ããïŒã¿ã€ãæåçãæµ®åå°æ°ç¹æ°ãšããŠèšç®ãïŒäžèšã®ææ³ã§åºåããå ŽåïŒæ£ããåºåçµæãåŸãããªãããšãããããšã«æ³šæããïŒ å
¥åºåäŸ1 ã·ã¹ãã ã®åºå ã·ã¹ãã ãžã®å
¥åã»AIã®è¿ç 2 5 ICPC 2 Tsurai 5 ? ICPC i ? _CPC g ? _CPC p ? _CPC c ? __PC p ? ___C c ? Tsurai t ? _surai s ? __urai u ? ___rai r ? ____ai a ? _____i i ! Game Clear 83.3 å
¥åºåäŸ2 ã·ã¹ãã ã®åºå ã·ã¹ãã ãžã®å
¥åã»AIã®è¿ç 2 1 ICPC 1 Tsurai 1 ? ICPC i ? _CPC c ? __PC o ? __PC p ? ___C d ! Game Over | 37,239 |
Score: 500 points Problem Statement N programmers are going to participate in the preliminary stage of DDCC 20XX. Due to the size of the venue, however, at most 9 contestants can participate in the finals. The preliminary stage consists of several rounds, which will take place as follows: All the N contestants will participate in the first round. When X contestants participate in some round, the number of contestants advancing to the next round will be decided as follows: The organizer will choose two consecutive digits in the decimal notation of X , and replace them with the sum of these digits. The number resulted will be the number of contestants advancing to the next round. For example, when X = 2378 , the number of contestants advancing to the next round will be 578 (if 2 and 3 are chosen), 2108 (if 3 and 7 are chosen), or 2315 (if 7 and 8 are chosen). When X = 100 , the number of contestants advancing to the next round will be 10 , no matter which two digits are chosen. The preliminary stage ends when 9 or fewer contestants remain. Ringo, the chief organizer, wants to hold as many rounds as possible. Find the maximum possible number of rounds in the preliminary stage. Since the number of contestants, N , can be enormous, it is given to you as two integer sequences d_1, \ldots, d_M and c_1, \ldots, c_M , which means the following: the decimal notation of N consists of c_1 + c_2 + \ldots + c_M digits, whose first c_1 digits are all d_1 , the following c_2 digits are all d_2 , \ldots , and the last c_M digits are all d_M . Constraints 1 \leq M \leq 200000 0 \leq d_i \leq 9 d_1 \neq 0 d_i \neq d_{i+1} c_i \geq 1 2 \leq c_1 + \ldots + c_M \leq 10^{15} Input Input is given from Standard Input in the following format: M d_1 c_1 d_2 c_2 : d_M c_M Output Print the maximum possible number of rounds in the preliminary stage. Sample Input 1 2 2 2 9 1 Sample Output 1 3 In this case, N = 229 contestants will participate in the first round. One possible progression of the preliminary stage is as follows: 229 contestants participate in Round 1 , 49 contestants participate in Round 2 , 13 contestants participate in Round 3 , and 4 contestants advance to the finals. Here, three rounds take place in the preliminary stage, which is the maximum possible number. Sample Input 2 3 1 1 0 8 7 1 Sample Output 2 9 In this case, 1000000007 will participate in the first round. | 37,240 |
Problem A: Strange String Manipulation A linear congruential generator produces a series R(â
) of pseudo-random numbers by the following for- mulas: where S , A , C , and M are all parameters. In this problem, 0 †S , A , C †15 and M = 256. Now suppose we have some input string I (â
), where each character in the string is an integer between 0 and ( M - 1). Then, using the pseudo-random number series R (â
), we obtain another string O (â
) as the output by the following formula: Your task is to write a program that shows the parameters S , A , and C such that the information entropy of the output string O (â
) is minimized. Here, the information entropy H is given by the following formula: where N is the length of the string and #( x ) is the number of occurences of the alphabet x . Input The input consists of multiple datasets. Each dataset has the following format: N I (1) I (2) ... I ( N ) N does not exceed 256. The last dataset is followed by a line containing one zero. This line is not a part of any dataset and should not be processed. Output For each dataset, print in a line the values of the three parameters S , A , and C separated by a single space. If more than one solution gives the same minimum entropy, choose the solution with the smallest S , A , and then C . Sample Input 5 5 4 3 2 1 5 7 7 7 7 7 10 186 8 42 24 154 40 10 56 122 72 0 Output for the Sample Input 0 1 1 0 0 0 8 7 14 | 37,241 |
Score : 1100 points Problem Statement You are given integers N, K , and an integer sequence A of length M . An integer sequence where each element is between 1 and K (inclusive) is said to be colorful when there exists a contiguous subsequence of length K of the sequence that contains one occurrence of each integer between 1 and K (inclusive). For every colorful integer sequence of length N , count the number of the contiguous subsequences of that sequence which coincide with A , then find the sum of all the counts. Here, the answer can be extremely large, so find the sum modulo 10^9+7 . Constraints 1 \leq N \leq 25000 1 \leq K \leq 400 1 \leq M \leq N 1 \leq A_i \leq K All values in input are integers. Input Input is given from Standard Input in the following format: N K M A_1 A_2 ... A_M Output For every colorful integer sequence of length N , count the number of the contiguous subsequences of that sequence which coincide with A , then print the sum of all the counts modulo 10^9+7 . Sample Input 1 3 2 1 1 Sample Output 1 9 There are six colorful sequences of length 3 : (1,1,2) , (1,2,1) , (1,2,2) , (2,1,1) , (2,1,2) and (2,2,1) . The numbers of the contiguous subsequences of these sequences that coincide with A=(1) are 2 , 2 , 1 , 2 , 1 and 1 , respectively. Thus, the answer is their sum, 9 . Sample Input 2 4 2 2 1 2 Sample Output 2 12 Sample Input 3 7 4 5 1 2 3 1 2 Sample Output 3 17 Sample Input 4 5 4 3 1 1 1 Sample Output 4 0 Sample Input 5 10 3 5 1 1 2 3 3 Sample Output 5 1458 Sample Input 6 25000 400 4 3 7 31 127 Sample Output 6 923966268 Sample Input 7 9954 310 12 267 193 278 294 6 63 86 166 157 193 168 43 Sample Output 7 979180369 | 37,242 |
Problem I: çãŸããå®ç³ ãã«çåœã®åœå®ã§ããå®ç³ãçè³ãã¡ã«çãŸããã åéºè
ã®ããªãã¯ãã®åãèãã€ããŠçè³ã®ã¢ãžãã«åããããªããšãå®ç³ãåãæ»ãããšãåºæ¥ãã ãšããããå®ç³ããã«çåœã®åãžè¿ãã«åºåãããšãããåã®å®è¡å
µããã ãæãçã¯ãŸã ããªããå®å
šã«ä¿¡çšããŠããªãããã®å®ç³ãæ¬ç©ãã©ããæªããããããããå®ç³ãåãæ»ãããšããã®ããŠãœã§ãçã®åœãçãçè³ã®ä»²éãªã®ã§ã¯ãªããïŒãšçã£ãŠãããããã ãšããããã ããªãã¯ãå®è¡å
µããæ¬åœã«ä¿¡é Œã§ãã人ç©ãã©ãã詊ãããã®è©Šç·Žãäžããããã詊緎ã®å
容ã¯ã ãåã®å°äžå庫ãžè¡ãæå®ãããå Žæã«å®ç³ã眮ããããã«å®ç³ãæ¬ç©ã ã£ããšãã«åå¿ããéæ³é£ãæžãããŠããããã ãããªããæªããè¡åãèµ·ãããªãããã«ãããããå°äžå庫ã®å
¥ãå£ããæå®ãããå Žæã«åãããŸã§ãå®è¡å
µãèšã£ãç§»åãã¿ãŒã³ããšã£ãŠã¯ãªããªããã ãšãããã®ã ã£ãã äŸãã°ãäžå³ã«ããå°äžå庫ã®åœ¢ç¶ãçŠæ¢ãã¿ãŒã³ã«å¯Ÿããå³ã«ããããŠãããããªç§»åãã¿ãŒã³ãåã£ãŠã¯ãªããªããç§»åãã¿ãŒã³ã®äžéš(èµ€ããã€ã©ã€ããããŠãã)ããçŠæ¢ãã¿ãŒã³ã®äžã«å«ãŸããããã§ããã(ãŸãããã®ç§»åãã¿ãŒã³ã®äžã®2,3çªç®ã®åããââããçŠæ¢ãã¿ãŒã³ã®äžã«å«ãŸãã) äžæ¹ã äžå³ã®ãããªç§»åãã¿ãŒã³ã¯ãç§»åãã¿ãŒã³ã®ã©ã®éšåãçŠæ¢ãã¿ãŒã³ã®äžã«å«ãŸããªãã®ã§èš±ãããã å
¥åãšããŠãå°äžå庫ã®åœ¢ç¶ãçŠæ¢ãã¿ãŒã³ãäžãããããçŠæ¢ãã¿ãŒã³ãåããã«ãå
¥ãå£ããéæ³é£ãžç§»åããã®ã«æäœéå¿
èŠãªç§»ååæ°ãæ±ããã Input å
¥åã«ã¯ãå°äžå庫ã®åœ¢ç¶ãšçŠæ¢ãã¿ãŒã³ãå«ãŸããã å°äžå庫ã®åœ¢ç¶ã¯ã以äžã®ããã«è¡šãããã ãŸããäºã€ã®æŽæ° N,M ãäžãããããããããå°äžå庫ã®è¡æ°ãšåæ°ãæå³ããã(1 †N,M †50) ç¶ããŠãããããMåã®æåãããªãæååãNè¡äžããããã å«ãŸããæåãšãã®æå³ã¯ä»¥äžã®éãã§ããã æå æå³ S å°äžå庫ã®å
¥ãå£ãäžã€ã®å°äžå庫ã«ã€ãå¿
ãäžã€ã ãå«ãŸããã G éæ³é£ãäžã€ã®å°äžå庫ã«ã€ãå¿
ãäžã€ã ãå«ãŸããã . éè·¯ã(çŠæ¢ãã¿ãŒã³ããšããªããã°)éãããšãåºæ¥ãã # å£ãå£ã®äžãéãããšã¯ã§ããªãã æ¬¡ã«ãçŠæ¢ãã¿ãŒã³ãäžãããããçŠæ¢ãã¿ãŒã³ã¯ä»¥äžã®ããã«è¡šãããã ãŸããäžã€ã®æŽæ° P ãäžãããããçŠæ¢ãã¿ãŒã³ã®æ°ãæå³ããã(0 †P †10) ç¶ããŠãçŠæ¢ãã¿ãŒã³ãæå³ããæååãPè¡ã«ããã£ãŠäžããããã çŠæ¢ãã¿ãŒã³ã«å«ãŸããæåãšãã®æå³ã¯ä»¥äžã®éãã§ããã æå æå³ U âã®ç§»åã R âã®ç§»åã D âã®ç§»åã L âã®ç§»åã çŠæ¢ãã¿ãŒã³ã®é·ãã¯1以äžã10以äžã§ããã ããçŠæ¢ãã¿ãŒã³ããå¥ã®çŠæ¢ãã¿ãŒã³ã®éšåæååãšãªã£ãŠããããšãããããŸããåäžã®çŠæ¢ãã¿ãŒã³ãå«ãŸããããšãããã Output æäœéå¿
èŠãªç§»ååæ°ãæå³ããæŽæ°ãåºåãããéæ³é£ãžèŸ¿ãã€ããªãå Žå㯠-1 ãåºåããã Notes on Test Cases äžèšå
¥å圢åŒã§è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã«å¯ŸããŠäžèšåºå圢åŒã§åºåãè¡ãããã°ã©ã ãäœæããŠäžããã n, m ã 0 ã®ãšãå
¥åã®çµããã瀺ããŸãã Sample Input 7 6 ...... .####. .####. ...S#. ...##. ...##. .....G 3 LD DD LLL 7 8 S#...... .#.####. .#.#G.#. .#.##.#. .#....#. .######. ........ 8 DDDD DDDU UUUU UUUD RRRR RRRL LLLL LLLR 3 8 ######## S......G ######## 2 U D 6 10 .......... .S........ .......... .......... ........G. .......... 0 6 7 ....... ...#... ...#.S. ...###. .G..... ....... 2 LL DD 0 0 Output for Sample Input 13 60 7 10 -1 | 37,243 |
芳é³å äžéåã®å®¶ã®è£å±±ã«ã¯èгé³å ããããŸãããã®èгé³å ãŸã§ã¯ãµããšãã 30 段ã®é段ããããäžéåã¯ãæ¯æ¥ã®ããã«èгé³å ãŸã§éã³ã«è¡ããŸããäžéåã¯é段ãïŒè¶³ã§ïŒæ®µãŸã§äžããããšãã§ããŸããéãã§ãããã¡ã«é段ã®äžãæ¹ã®çš®é¡ïŒæ®µã®é£ã°ãæ¹ã®åæ°ïŒãéåžžã«ããããããããšã«æ°ãã€ããŸããã ããã§ãäžæ¥ã« 10 çš®é¡ã®äžãæ¹ããããã¹ãŠã®äžãæ¹ã詊ãããšèããŸããããããæ°åŠãçç¥ããŠããããªãã¯ãããªããšã§ã¯äžéåã®å¯¿åœãå°œããŠããŸãããšãç¥ã£ãŠããã¯ãã§ãã äžéåã®èšç»ãå®çŸäžå¯èœã§ããããšãäžéåã«çŽåŸãããããã«ãéæ®µã®æ®µæ° n ãå
¥åãšããäžæ¥ã« 10 çš®é¡ã®äžãæ¹ããããšããŠãäžéåããã¹ãŠã®äžãæ¹ãå®è¡ããã®ã«èŠãã幎æ°ãåºåããããã°ã©ã ãäœæããŠãã ãããäžå¹Žã¯ 365 æ¥ãšããŠèšç®ããŠãã ãããäžæ¥ã§ãå¿
èŠãªãäžå¹ŽãšããŸãã365 æ¥ãªã 1 幎ã§ããã366 æ¥ãªã 2 幎ãšãªããŸãã Input è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸãã åããŒã¿ã»ãããšããŠã段æ°ã衚ãïŒã€ã®æŽæ° n (1 †n †30) ãïŒè¡ã«äžããããŸãã ããŒã¿ã»ããã®æ°ã¯ 30 ãè¶
ããŸããã Output ããŒã¿ã»ããããšã«äžéåããã¹ãŠã®äžãæ¹ãå®è¡ããã®ã«å¿
èŠãªå¹Žæ°ïŒæŽæ°ïŒãïŒè¡ã«åºåããŸãã Sample Input 1 10 20 25 0 Output for the Sample Input 1 1 34 701 | 37,244 |
Problem G: First Kiss Problem ãããåã®éãç·åæ ¡ã§ã¯æŒäŒã¿ã«ããããŒã²ãŒã ãè¡ãããŠããã ãã®åŠæ ¡ã®ããããŒã²ãŒã ã¯å°ãå€ãã£ãŠããããšã§æåã ã ãŸãã$N$æ¬ã®ããããŒãçšæããã$i$æ¬ç®ã®ããããŒã®é·ãã¯$a_i$ã§ããã å
æãšåŸæã亀äºã«ããããŒãé£ã¹ãã ãããé·ãã®ããããŒãäžæ°ã«é£ã¹ããšåã«åºãã£ãŠããŸãã®ã§ã$1$以äž$D$以äžã®å¥œããªé·ãã ãé£ã¹ãã 圌ãã¯äžåšçšãªã®ã§ãæŽæ°é·ã§ã®ã¿ããããŒãé£ã¹ãããšãã§ããã æåã«ããããã®ããããŒãé£ã¹ã€ãããããšããé£ã¹ãã£ã人ã®è² ããšãªãã äž¡è
ãæé©ã«è¡åãããšããå
æãåã€ãªã"First"ãåŸæãåã€ãªã"Second"ãåºåããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã $N$ $D$ $a_1$ $a_2$ $...$ $a_N$ å
¥åã¯ãã¹ãп޿°ã§äžããããã Constraints å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã $1 \le N \le 3\times 10^5$ $1 \le D \le 10^9$ $1 \le a_i \le 10^9$ Output äž¡è
ãæé©ã«è¡åãããšããã©ã¡ããåã€ãåºåããã å
æãåã€ãªã"First"ãåŸæãåã€ãªã"Second"ãåºåããã Sample Input 1 1 1 2 Sample Output 1 First Sample Input 2 2 25 19 19 Sample Output 2 Second Sample Input 3 3 5 10 8 4 Sample Output 3 First Sample Input 4 4 10 3 8 5 2 Sample Output 4 Second | 37,245 |
ã€ã«ãããŒã·ã§ã³ (Illumination) åé¡ JOI 瀟ã®å»ºç©ã¯å³ã®ãã㪠1 蟺 1 ã¡ãŒãã«ã®æ£å
è§åœ¢ãã€ãªãåããã圢ã§ããïŒã¯ãªã¹ãã¹ãè¿ã¥ããŠããã®ã§ïŒJOI 瀟ã§ã¯å»ºç©ã®å£é¢ãã€ã«ãããŒã·ã§ã³ã§é£Ÿãä»ããããšã«ããïŒãã ãïŒå€ããèŠããªãéšåã«ã€ã«ãããŒã·ã§ã³ãæœãã®ã¯ç¡é§ãªã®ã§ïŒã€ã«ãããŒã·ã§ã³ã¯å€ãã建ç©ã®äžãéããã«è¡ãããšã®ã§ããå£é¢ã«ã®ã¿é£Ÿãä»ããããšã«ããïŒ å³: JOI 瀟ã®å»ºç©ã®é
眮ã®äŸ äžã®å³ã¯äžç©ºããèŠã JOI 瀟ã®å»ºç©ã®é
眮ã®äŸã§ããïŒæ£å
è§åœ¢å
ã®æ°åã¯åº§æšã衚ãïŒç°è²ã®æ£å
è§åœ¢ã¯å»ºç©ãããå Žæã衚ãïŒçœè²ã®æ£å
è§åœ¢ã¯å»ºç©ããªãå Žæã衚ãïŒãã®äŸã§ã¯ïŒèµ€ã®å®ç·ã§ç€ºãããéšåãã€ã«ãããŒã·ã§ã³ã§é£Ÿãä»ããè¡ãå£é¢ãšãªãïŒãã®å£é¢ã®é·ãã®åèšã¯ 64 ã¡ãŒãã«ãšãªãïŒ JOI 瀟ã®å»ºç©ã®é
眮ã衚ãå°å³ãäžãããããšãïŒé£Ÿãä»ããè¡ãå£é¢ã®é·ãã®åèšãæ±ããããã°ã©ã ãäœæããïŒãã ãïŒå°å³ã®å€åŽã¯èªç±ã«è¡ãæ¥ã§ãããã®ãšãïŒé£æ¥ãã建ç©ã®éã¯éãããšã¯ã§ããªããã®ãšããïŒ å
¥å å
¥åãã¡ã€ã«ã® 1 è¡ç®ã«ã¯ 2 ã€ã®æŽæ° W, H (1 ⊠W ⊠100ïŒ1 ⊠H ⊠100) ã空çœãåºåããšããŠæžãããŠããïŒç¶ã H è¡ã«ã¯ JOI 瀟ã®å»ºç©ã®é
çœ®ãæžãããŠããïŒi + 1 è¡ç® (1 ⊠i ⊠H) ã«ã¯ W åã®æŽæ°ã空çœãåºåããšããŠæžãããŠããïŒj åç® (1 ⊠j ⊠W) ã®æŽæ°ã¯åº§æš (j, i) ã®æ£å
è§åœ¢ã«å»ºç©ãããæã¯ 1 ã§ããïŒãªãæã¯ 0 ã§ããïŒãŸãïŒäžããããå
¥åããŒã¿ã«ã¯å»ºç©ãå¿
ã 1 ã€ä»¥äžããïŒ å°å³ã¯ä»¥äžã®èŠåã«ãã£ãŠèšè¿°ãããŠããïŒ å°å³ã®æãåã®è¡ã®æãè¥¿ã®æ£å
è§åœ¢ã¯åº§æš (1, 1) ã§ããïŒ åº§æš (x, y) ã®æ£å
è§åœ¢ã«é£æ¥ããæ±é£ã®æ£å
è§åœ¢ã¯åº§æš (x + 1, y) ã§ããïŒ y ã奿°ã®æïŒåº§æš (x, y) ã®æ£å
è§åœ¢ã«é£æ¥ããåè¥¿ã®æ£å
è§åœ¢ã®åº§æšã¯ (x, y + 1) ã§ããïŒ y ãå¶æ°ã®æïŒåº§æš (x, y) ã®æ£å
è§åœ¢ã«é£æ¥ããåæ±ã®æ£å
è§åœ¢ã®åº§æšã¯ (x, y + 1) ã§ããïŒ åºå ã€ã«ãããŒã·ã§ã³ã§é£Ÿãä»ããè¡ãå£é¢ã®é·ãã®åèšã 1 è¡ã§åºåããïŒ å
¥åºåäŸ å
¥åäŸ 1 8 4 0 1 0 1 0 1 1 1 0 1 1 0 0 1 0 0 1 0 1 0 1 1 1 1 0 1 1 0 1 0 1 0 åºåäŸ 1 64 å
¥åºåäŸ 1 ã¯å顿äžã®äŸã«å¯Ÿå¿ããŠããïŒã€ã«ãããŒã·ã§ã³ã§é£Ÿãä»ããè¡ãå£é¢ã®é·ãã®åèšã¯ 64 ã¡ãŒãã«ã§ããïŒ å
¥åäŸ 2 8 5 0 1 1 1 0 1 1 1 0 1 0 0 1 1 0 0 1 0 0 1 1 1 1 1 0 1 0 1 1 0 1 0 0 1 1 0 1 1 0 0 åºåäŸ 2 56 å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã | 37,246 |
ã±ãŒãã®åãåãïŒ (Cake 2) JOI ãããš IOI ã¡ããã¯ååã®å
効ã§ããïŒJOI ããã¯æè¿ãèåäœãã«åã£ãŠããŠïŒä»æ¥ã JOI ããã¯ã±ãŒããçŒããŠé£ã¹ãããšããã®ã ãïŒçŒãããã£ããšããã§åããããã€ãã IOI ã¡ãããæ¥ãã®ã§ 2人ã§ã±ãŒããåããããšã«ãªã£ãïŒ ã±ãŒãã¯å圢ã§ããïŒããç¹ããæŸå°ç¶ã«åãç®ãå
¥ãïŒã±ãŒãã N åã®ããŒã¹ã«åãåãïŒããŒã¹ã« 1 ãã N ãŸã§åæèšåãã«çªå·ãã€ããïŒã€ãŸãïŒ1 †i †N ã«å¯ŸãïŒ i çªç®ã®ããŒã¹ã¯ i â 1 çªç®ãš i + 1 çªç®ã®ããŒã¹ãšé£æ¥ããŠãã (ãã ã 0 çªç®ã¯ N çªç®ïŒ N + 1 çªç®ã¯ 1 çªç®ãšã¿ãªã) ïŒ i çªç®ã®ããŒã¹ã®å€§ãã㯠A i ã ã£ããïŒåãæ¹ããšãŠãäžæã ã£ãã®ã§ A i ã¯ãã¹ãŠç°ãªãå€ã«ãªã£ãïŒ å³ 1: ã±ãŒãã®äŸ ( N = 5, A 1 = 2, A 2 = 8, A 3 = 1, A 4 = 10, A 5 = 9) ãã® N åã JOI ãããš IOI ã¡ããã§åããããšã«ããïŒåãæ¹ã¯æ¬¡ã®ããã«ããããšã«ããïŒ ãŸã JOI ããã N åã®ãã¡ã®å¥œã㪠1 ã€ãéžãã§åãïŒ ãã®åŸïŒIOI ã¡ããããã¯ãã㊠IOI ã¡ãããš JOI ããã亀äºã«æ®ãã®ããŒã¹ã 1 ã€ãã€åã£ãŠããïŒãã ãïŒäž¡é£ã®ããŒã¹ã®ãã¡å°ãªããšãäžæ¹ãæ¢ã«åãããŠãããããªããŒã¹ããåãããšãã§ããïŒåããããŒã¹ãè€æ°ãããšãã¯ïŒIOI ã¡ããã¯ãã®ãã¡æã倧ãããã®ãéžãã§åãïŒJOI ããã¯ãã®ãã¡ã§å¥œããªãã®ãéžãã§åãããšãã§ããïŒ JOI ããã¯ïŒèªåãæçµçã«åãããŒã¹ã®å€§ããã®åèšãæå€§åãããïŒ èª²é¡ ã±ãŒãã®ããŒã¹ã®æ° N ãšïŒ N åã®ããŒã¹ã®å€§ããã®æ
å ±ãäžãããããšãïŒJOI ãããåããããŒã¹ã®å€§ããã®åèšã®æå€§å€ãæ±ããããã°ã©ã ãäœæããïŒ å
¥å æšæºå
¥åãã以äžã®å
¥åãèªã¿èŸŒãïŒ 1 è¡ç®ã«ã¯æŽæ° N ãæžãããŠããïŒã±ãŒãã N åã®ããŒã¹ã«åãåããããŠããããšã衚ãïŒ ç¶ã N è¡ã®ãã¡ã® i è¡ç® (1 †i †N ) ã«ã¯æŽæ° A i ãæžãããŠããïŒ i çªç®ã®ããŒã¹ã®å€§ããã A i ã§ããããšã衚ãïŒ åºå æšæºåºåã«ïŒJOI ãããåããããŒã¹ã®å€§ããã®åèšã®æå€§å€ãè¡šãæŽæ°ã 1 è¡ã§åºåãã. å¶é ãã¹ãŠã®å
¥åããŒã¿ã¯ä»¥äžã®æ¡ä»¶ãæºããïŒ 1 †N †2 000ïŒ 1 †A i †1 000 000 000ïŒ A i ã¯ãã¹ãŠç°ãªãïŒ å
¥åºåäŸ å
¥åäŸ 1 5 2 8 1 10 9 åºåäŸ 1 18 JOI ããã¯ïŒæ¬¡ã®ããã«ããŒã¹ãåãã®ãæé©ã§ããïŒ JOI ãã㯠2 çªç®ã®ããŒã¹ãåãïŒãã®ããŒã¹ã®å€§ãã㯠8 ã§ããïŒ IOI ã¡ãã㯠1 çªç®ã®ããŒã¹ãåãïŒãã®ããŒã¹ã®å€§ãã㯠2 ã§ããïŒ JOI ãã㯠5 çªç®ã®ããŒã¹ãåãïŒãã®ããŒã¹ã®å€§ãã㯠9 ã§ããïŒ IOI ã¡ãã㯠4 çªç®ã®ããŒã¹ãåãïŒãã®ããŒã¹ã®å€§ãã㯠10 ã§ããïŒ JOI ãã㯠3 çªç®ã®ããŒã¹ãåãïŒãã®ããŒã¹ã®å€§ãã㯠1 ã§ããïŒ æçµçã«ïŒJOI ãããåã£ãããŒã¹ã®å€§ããã®åèšã¯ïŒ8 + 9 + 1 = 18 ãšãªã. å
¥åäŸ 2 8 1 10 4 5 6 2 9 3 åºåäŸ 2 26 å
¥åäŸ 3 15 182243672 10074562 977552215 122668426 685444213 3784162 463324752 560071245 134465220 21447865 654556327 183481051 20041805 405079805 564327789 åºåäŸ 3 3600242976 å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã | 37,247 |
Score : 1200 points Problem Statement We have N lamps numbered 1 to N , and N buttons numbered 1 to N . Initially, Lamp 1, 2, \cdots, A are on, and the other lamps are off. Snuke and Ringo will play the following game. First, Ringo generates a permutation (p_1,p_2,\cdots,p_N) of (1,2,\cdots,N) . The permutation is chosen from all N! possible permutations with equal probability, without being informed to Snuke. Then, Snuke does the following operation any number of times he likes: Choose a lamp that is on at the moment. (The operation cannot be done if there is no such lamp.) Let Lamp i be the chosen lamp. Press Button i , which switches the state of Lamp p_i . That is, Lamp p_i will be turned off if it is on, and vice versa. At every moment, Snuke knows which lamps are on. Snuke wins if all the lamps are on, and he will surrender when it turns out that he cannot win. What is the probability of winning when Snuke plays optimally? Let w be the probability of winning. Then, w \times N! will be an integer. Compute w \times N! modulo (10^9+7) . Constraints 2 \leq N \leq 10^7 1 \leq A \leq \min(N-1,5000) Input Input is given from Standard Input in the following format: N A Output Print w \times N! modulo (10^9+7) , where w is the probability of Snuke's winning. Sample Input 1 3 1 Sample Output 1 2 First, Snuke will press Button 1 . If Lamp 1 turns off, he loses. Otherwise, he will press the button that he can now press. If the remaining lamp turns on, he wins; if Lamp 1 turns off, he loses. The probability of winning in this game is 1/3 , so we should print (1/3)\times 3!=2 . Sample Input 2 3 2 Sample Output 2 3 Sample Input 3 8 4 Sample Output 3 16776 Sample Input 4 9999999 4999 Sample Output 4 90395416 | 37,248 |
Problem A: K Cards ããæ¥ãå
çã¯æ¬¡ã®ãããªã²ãŒã ãæãã€ããã ã²ãŒã 㯠1 ãã 10 ãŸã§ã®æ°ãã²ãšã€æžãããã«ãŒãã n æäœ¿çšãã以äžã®ããã«é²ãã å
çã n æã®ã«ãŒããæ°ãèŠããããã«ããŠæšªäžåã«é»æ¿ã«è²Œãä»ããããæŽæ° k (k ⥠1) ãçåŸã«å®£èšãããæšªäžåã«äžŠã¹ããã n æã®ã«ãŒãã«ã€ããŠãé£ç¶ãã k æã®ã«ãŒãã®ç©ã®æå€§å€ã C k ãšããããŸããå
çã䞊ã¹ãæç¹ã§ã® C k ã C k ' ãšããã çåŸã¯ 1. ã§è²Œãããã«ãŒãã®åãèŠãŠ C k ã倧ããããããšãèããããã 2 æãå
¥ãæ¿ããããšã§ C k ããã倧ããããããšãã§ããå ŽåãçåŸã®æçžŸã¯ C k - C k ' ç¹äžããã誰ããæçžŸç¹ãåŸããã²ãŒã ãçµäºããã ããªãã®ä»äºã¯å
çã䞊ã¹ãã«ãŒãã®åãå
¥åããçåŸãåŸãããæå€§ã®æçžŸç¹ãåºåããããã°ã©ã ãæžãããšã§ããããã ããããããã©ã® 2 æãéžãã§äº€æããŠãC k ãäžããããšããã§ããªã (C k - C k ' < 0) å Žåãæåå "NO GAME" (åŒçšç¬Šãå«ãŸãªã)ãåºåããã å
çã䞊ã¹ãã«ãŒãã7, 2, 3, 5ã®å Žåããã®ãšã 7 ãš 3 ã亀æããããšã§çåŸã¯æå€§ã§ 35 - 15 = 20 æçžŸç¹ãåŸãã Input å
¥åã¯è€æ°ã®ãã¹ãã±ãŒã¹ãããªããã²ãšã€ã®ãã¹ãã±ãŒã¹ã¯ä»¥äžã®åœ¢åŒã«åŸãã n k c 1 c 2 c 3 ⊠c n n ã¯å
çã䞊ã¹ãã«ãŒãã®ææ°ãk ã¯å®£èšããæŽæ°ã§ããã ãŸã c i (1 †i †n) ã¯ã«ãŒãã«æžãããæ°ã瀺ãããŸãããã®é ã§å
çãæšªã«é»æ¿ã«è²Œãä»ãããšãããå
¥åã®çµããã¯ããµãã€ã®0ãäžæåã®ç©ºçœã§åºåãããäžè¡ã§ç€ºãããã Constraints å
¥åã¯ãã¹ãп޿° 2 â€n †100 1 â€k †5 k †n 1 †c i †10 (1 †i †n) ãã¹ãã±ãŒã¹ã®æ°ã¯ 100 ãè¶
ããªãã Output çåŸãåŸãããæçžŸç¹ã®æå€§å€ãããã¯æåå "NO GAME" (åŒçšç¬Šãå«ãŸãªã)ãåãã¹ãã±ãŒã¹ã«ä»ã 1 è¡ã§åºåããã Sample Input 4 2 2 3 7 5 0 0 Sample Output 0 Hint ãµã³ãã«ã«ãã㊠C 2 ' = 35 ã§ãããããããã©ã® 2 æãäžŠã³æ¿ããŠã C 2 ã®æå€§å€ã¯ 35 ãã倧ãããªããªãããããã£ãŠçåŸãåŸãããæçžŸç¹ã¯æå€§ 0 ç¹ã§ããã | 37,249 |
Beautiful Sequence Alice is spending his time on an independent study to apply to the Nationwide Mathematics Contest. This yearâs theme is "Beautiful Sequence." As Alice is interested in the working of computers, she wants to create a beautiful sequence using only 0 and 1. She defines a "Beautiful" sequence of length $N$ that consists only of 0 and 1 if it includes $M$ successive array of 1s as its sub-sequence. Using his skills in programming, Alice decided to calculate how many "Beautiful sequences" she can generate and compile a report on it. Make a program to evaluate the possible number of "Beautiful sequences" given the sequence length $N$ and sub-sequence length $M$ that consists solely of 1. As the answer can be extremely large, divide it by $1,000,000,007 (= 10^9 + 7)$ and output the remainder. Input The input is given in the following format. $N$ $M$ The input line provides the length of sequence $N$ ($1 \leq N \leq 10^5$) and the length $M$ ($1 \leq M \leq N$) of the array that solely consists of 1s. Output Output the number of Beautiful sequences in a line. Sample Input 1 4 3 Sample Output 1 3 The sequences with length 4 that include 1s in successive array of length 3 are: 0111, 1110 and 1111. Sample Input 2 4 2 Sample Output 2 8 The sequences with length 4 that include 1s in successive array of length 2 are: 0011, 0110, 0111, 1011, 1100, 1101, 1110 and 1111. | 37,251 |
ã³ã³ãã¹ãTã·ã£ã (Contest T-shirts) Segtree åã¯ã $M$ æã®ã³ã³ãã¹ãTã·ã£ããæã£ãŠããŸãã 圌ã¯ä»ãã $N$ æ¥éãã³ã³ãã¹ãTã·ã£ãã ãã§éããããšèãã$i = 1, 2, 3, \dots, N$ ã«å¯ŸããŠã $i$ æ¥ç®ã« $A_i$ æç®ã®Tã·ã£ããçãããšãã $N$ åã®èšç»ãç«ãŠãŸããã ããããä»ã®èšç»ã®ãŸãŸã ãšæŽæ¿¯ãéã«åããªãå¯èœæ§ãããã®ã§ãå¿
èŠã«å¿ããŠèšç»ã倿Žãã2æ¥é£ç¶ã§åãæãçãªãããã«ãããã§ãã 倿Žããå¿
èŠã®ããèšç»ã®åæ°ã®æå°å€ãæ±ããŠãã ããããªããäžããããå¶çŽã®å
ã§ãèšç»ã®å€æŽã«ãã£ãŠå¿
ãæ¡ä»¶ãæºããããã«ã§ããããšã蚌æã§ããŸãã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããã $M$ $N$ $A_1$ $A_2$ $\ldots$ $A_N$ åºå 倿Žããå¿
èŠã®ããèšç»ã®åæ°ã®æå°å€ãåºåããŠãã ããã ãã ããæåŸã«ã¯æ¹è¡ãå
¥ããããšã å¶çŽ $2 \leq M \leq 10^9$ $1 \leq N \leq 10^5$ $1 \leq A_i \leq M$ å
¥åã¯å
šãп޿°ã§ããã å
¥åäŸ1 2 3 2 2 1 åºåäŸ1 1 å
¥åäŸ2 3 6 1 1 1 2 2 3 åºåäŸ2 2 | 37,252 |
ã«ããªãŒèšç® é£ã¹ç©ã«ã¯3倧æ é€çŽ ãšåŒã°ãããããã±ã質ããè質ããçæ°Žåç©ãã®ïŒã€ã®æ é€çŽ ãå«ãŸããŠããŸããïŒgïŒã°ã©ã ïŒãããããã±ã質ãšçæ°Žåç©ã¯ 4 kcalïŒããã«ããªãŒïŒãè質㯠9 kcal ãšèšç®ãããŸããããšãã°ãäžã®è¡šã«ãããšçªå·ïŒã®ã±ãŒãã«ã¯ã¿ã³ãã¯è³ª 7 gãè質 14 gãçæ°Žåç© 47 g ãå«ãŸããŠããŸãããããããšã«å«ãŸããã«ããªãŒãèšç®ãããšã4 à 7 + 9 à 14 + 4 à 47 = 342 kcal ãšãªããŸãããã®ä»ãåæ§ã«èšç®ãããŠããŸãã çªå· åå ããã±ã質(g) è質(g) çæ°Žåç©(g) ã«ããªãŒ(kcal) 1 ã±ãŒã 7 14 47 342 2 ããããããã¹ 5 35 55 555 3 ã©ãçŒã 6 3 59 287 4 ããªã³ 6 5 15 129 åé¡ã®å¯Ÿè±¡ãšãªããèåã®åæ° n ãšåãèåã®æ
å ±ãå¶éã®æ
å ±ãå
¥åãšãããã®ãèåäžã€ã ããªãå¶éãè¶
ããããšããªãïŒé£ã¹ãŠãããïŒãèåã®äžèЧãåºåããããã°ã©ã ãäœæããŠãã ããã ãèåã®æ
å ±ã¯ããèåã®çªå· s ããã®ãèåã«å«ãŸããããã±ã質ã®éé p ãè質ã®éé q ãçæ°Žåç©ã®éé r ããæ§æãããŠããŸããå¶éã®æ
å ±ã«ã¯ãå«ãããšãã§ããæå€§ã®ããã±ã質ã®éé P ãè質ã®éé Q ãçæ°Žåç©ã®éé R ãããã³æåããããšãã§ããæå€§ã®ã«ããªãŒ C ãããªã£ãŠãããã¿ã³ãã¯è³ªãè質ãçæ°Žåç©ãã«ããªãŒã®ããããã®äžã€ã§ãè¶
ãããšå¶ééåãšãªãããé£ã¹ãŠã¯ãããªããèåããšå€æãããŸãã é£ã¹ãŠããããèåã®äžèЧã¯ãé£ã¹ãŠããããèåã®çªå·ãå
¥åé ã«åºåããŠãã ããããªããé£ã¹ãŠããããèåããªããã°âNAâãšåºåããŠãã ããã äžã®è¡šã«ãã4åã®ãèåã«ã€ããŠã P = 10, Q = 15, R = 50, C = 400 ãšããå¶éã®å Žåãã±ãŒããšããªã³ã¯ããããã®æ é€çŽ åã³ã«ããªãŒãå¶éå€ä»¥äžãªã®ã§é£ã¹ãŠããããèåã«åé¡ãããŸãããããããããã¹ã¯çæ°Žåç©ãšã«ããªãŒãã©ãçŒãã¯çæ°Žåç©ã®éãå¶éå€ãè¶
ããŠããããé£ã¹ãŠã¯ãããªããèåã«åé¡ãããŸãã å
¥å è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã n s 1 p 1 q 1 r 1 s 2 p 2 q 2 r 2 : s n p n q n r n P Q R C 1è¡ç®ã«ãèåã®æ° n (1 †n †1000)ãäžããããŸããç¶ã n è¡ã«ç¬¬ i ã®ãèåã®çªå· s i (1 †s i †1000)ãåæ é€çŽ ã®ééãè¡šãæŽæ° p i , q i , r i (0 †p i , q i , r i †100) ãäžããããŸãã ç¶ãè¡ã«åæ é€çŽ åã³ã«ããªãŒã®å¶éå€ãè¡šãæŽæ° P , Q , R (0 †P , Q , R †100), C (0 †C †1700) ãäžããããŸãã ããŒã¿ã»ããã®æ°ã¯ 100 ãè¶
ããŸããã åºå ããŒã¿ã»ããããšã«ãé£ã¹ãŠããããèåã®çªå·ãŸã㯠âNAâ ãåºåããŸãã å
¥åäŸ 4 1 7 14 47 2 5 35 55 3 6 3 59 4 6 5 15 10 15 50 400 2 1 8 10 78 2 4 18 33 10 10 50 300 0 åºåäŸ 1 4 NA | 37,253 |
Problem G: Star Problem ååŸ1ã®åã«å
æ¥ããæ£ N / K è§åœ¢ã®é¢ç©ãæ±ããã ãã ããæ£ N / K è§åœ¢ã ãååšäžã«çééã« N åã®ç¹ãåãã K -1åããã«ããããã®ç¹ãçµãã äžçªå€åŽã®å³åœ¢ã ãšå®çŸ©ããã äŸãã°ã5/2è§åœ¢ã¯æ¬¡ã®ããã«æãããšãã§ããã ãŸããååŸ1ã®ååšäžã«çééã«5ã€ã®ç¹ãåãã æ¬¡ã«ãããããã®ç¹ã2-1=1ã€ããã«çµã¶ã äžçªå€åŽã®å³åœ¢ãæ£5/2è§åœ¢ã«ãªãã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã N K 2ã€ã®æŽæ° N , K ã1è¡ã«äžããããã Constraints å
¥åã¯ä»¥äžã®å¶çŽãæºããã 5 †N †10 6 1 < K < N /2 N , K ã¯äºãã«çŽ ã§ããæŽæ° Output ååŸ1ã®åã«å
æ¥ããæ£ N / K è§åœ¢ã®é¢ç©ã1è¡ã«åºåããã10 -5 以äžã®èª€å·®ã蚱容ãããã Sample Input 1 5 2 Sample Output 1 1.12256994 æ£5/2è§åœ¢ã¯äžèšã®å³åœ¢ã§ããã Sample Input 2 20 3 Sample Output 2 2.93114293 æ£20/3è§åœ¢ã¯äžã®ãããªå³åœ¢ã§ããã Sample Input 3 7 3 Sample Output 3 1.08395920 Sample Input 4 100000 3 Sample Output 4 3.14159265 | 37,254 |
Score : 500 points Problem Statement There are N cards placed face down in a row. On each card, an integer 1 or 2 is written. Let A_i be the integer written on the i -th card. Your objective is to guess A_1, A_2, ..., A_N correctly. You know the following facts: For each i = 1, 2, ..., M , the value A_{X_i} + A_{Y_i} + Z_i is an even number. You are a magician and can use the following magic any number of times: Magic : Choose one card and know the integer A_i written on it. The cost of using this magic is 1 . What is the minimum cost required to determine all of A_1, A_2, ..., A_N ? It is guaranteed that there is no contradiction in given input. Constraints All values in input are integers. 2 \leq N \leq 10^5 1 \leq M \leq 10^5 1 \leq X_i < Y_i \leq N 1 \leq Z_i \leq 100 The pairs (X_i, Y_i) are distinct. There is no contradiction in input. (That is, there exist integers A_1, A_2, ..., A_N that satisfy the conditions.) Input Input is given from Standard Input in the following format: N M X_1 Y_1 Z_1 X_2 Y_2 Z_2 \vdots X_M Y_M Z_M Output Print the minimum total cost required to determine all of A_1, A_2, ..., A_N . Sample Input 1 3 1 1 2 1 Sample Output 1 2 You can determine all of A_1, A_2, A_3 by using the magic for the first and third cards. Sample Input 2 6 5 1 2 1 2 3 2 1 3 3 4 5 4 5 6 5 Sample Output 2 2 Sample Input 3 100000 1 1 100000 100 Sample Output 3 99999 | 37,255 |
Problem B: Cover Time Let G be a connected undirected graph where N vertices of G are labeled by numbers from 1 to N . G is simple, i.e. G has no self loops or parallel edges. Let P be a particle walking on vertices of G . At the beginning, P is on the vertex 1. In each step, P moves to one of the adjacent vertices. When there are multiple adjacent vertices, each is selected in the same probability. The cover time is the expected number of steps necessary for P to visit all the vertices. Your task is to calculate the cover time for each given graph G. Input The input has the following format. N M a 1 b 1 . . . a M b M N is the number of vertices and M is the number of edges. You can assume that 2 †N †10. a i and b i (1 †i †M ) are positive integers less than or equal to N , which represent the two vertices connected by the i -th edge. You can assume that the input satisfies the constraints written in the problem description, that is, the given graph G is connected and simple. Output There should be one line containing the cover time in the output. The answer should be printed with six digits after the decimal point, and should not have an error greater than 10 -6 . Sample Input and Output Input #1 3 2 1 2 2 3 Output #1 4.000000 Input #2 4 6 1 2 1 3 1 4 2 3 2 4 3 4 Output #2 5.500000 | 37,256 |
å顿 ãèåã®é女 CHARLOTTE 㯠巎ãã ãšã¯ãããŒã²ãŒã ãæ¥œããã§ããïŒã¯ãããŒã²ãŒã 㯠8\times 8 ã®æ Œåç¶ã«åºåãããããŒãã«ã¯ãã¹ã®äžã«ããŒãºã¯ãããŒãšãã§ã³ã¬ãŒãã¯ãããŒã眮ããŠè¡ãããïŒåæ Œåã«ã¯é«ã
1 åã®ãã§ã³ã¬ãŒãã¯ãããŒãŸãã¯ããŒãºã¯ãããŒãã眮ãããšã¯ã§ããªãïŒ ãèåã®é女ã¯ããŒãºã¯ãããŒãïŒ å·Žãã ã¯ãã§ã³ã¬ãŒãã¯ãããŒã亀äºã«çœ®ããŠã²ãŒã ãè¡ãïŒèªåã®ã¯ãããŒã眮ããããšïŒãã®ã¯ãããŒããäžäžå·Šå³æãã®å 8 æ¹åã«ã€ããŠïŒçœ®ãã¯ãããŒãšãã§ã«çœ®ããŠããèªåã®ã¯ãããŒã®éã«çžæã®ã¯ãããŒã®ã¿ãçŽç·ã«äžŠãã§ããå Žåã«ïŒãã®æãŸããçžæã®ã¯ãããŒã®ãã¹ãŠãèªåã®ã¯ãããŒã§çœ®ãæããããïŒã¯ãããŒã²ãŒã ã®ãã¬ã€ã€ãŒã¯èªåã®ã¿ãŒã³ãåã£ãŠããæïŒ 1 ã€èªåã®ã¯ãããŒã眮ãããšãã§ããïŒãã ãïŒçžæã®ã¯ãããŒãå°ãªããšã 1 ã€ä»¥äžèªåã®ã¯ãããŒã«çœ®ãæããããªããã°ãªããªãïŒãã®ãããªçœ®ãå Žããªãå ŽåïŒèªåã®ã¿ãŒã³ããã¹ãããªããã°ãªããªãïŒ ãèåã®é女ã å·Žãã ãèããã®ãå°ã
èŠæã§ããïŒããã§ïŒåã£ãŠããã¿ãŒã³æ¯ã«ãã®ã¿ãŒã³ã®äžã§çœ®ãæããããã¯ãããŒã®æ°ãæå€§åããããšãèããããšã«ããïŒ å·Žãã ã®ã¿ãŒã³ã®ãšãã«çœ®ãæããããã¯ãããŒã®æ°ãæå€§ã«ãããããªã¯ãããŒã眮ãå Žæã®åè£ãè€æ°ããå Žåã¯ïŒããäžã®å ŽæãïŒããã§ãè€æ°ããå Žåã¯ããå·Šã®å Žæãéžæããããšã«ããïŒãŸãåæ§ã«ïŒãèåã®é女ã®ã¿ãŒã³ã®ãšãã«åè£ãè€æ°ããå Žåã¯ããäžã®å ŽæãïŒããã§ãè€æ°ããå Žåã¯ããå³ã®å Žæãéžæããããšã«ããïŒ ããŒãã«ã¯ãã¹ã«çœ®ãããã¯ãããŒã®ç¶æ
ãäžããããã®ã§ïŒå·Žããããã¯ããïŒåœŒå¥³ãã¡ãããããã¯ãããŒã²ãŒã ãè¡ãïŒå
±ã«æ°ããªã¯ãããŒã眮ããªããªããŸã§ã²ãŒã ãç¶ããæã®ããŒãã«ã¯ãã¹ã®äžã«çœ®ãããã¯ãããŒã®ç¶æ
ãæ±ããïŒ å
¥ååœ¢åŒ å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ s_{11} s_{12} ... s_{18}\\ s_{21} s_{22} ... s_{28}\\ ...\\ s_{81} s_{82} ... s_{88}\\ s_{ij} ã¯ããŒãã«ã¯ãã¹ã«çœ®ãããã¯ãããŒã®åæç¶æ
ã衚ãæåã§ïŒäžãã i è¡ç®ïŒå·Šãã j åç®ã®æ Œåã®ç¶æ
ã衚ãïŒãã§ã³ã¬ãŒãã¯ãããŒã眮ãããŠãããšã s_{ij} 㯠'o' ã§ããïŒããŒãºã¯ãããŒã眮ãããŠãããšã㯠'x' , äœã眮ãããŠããªããšã㯠'.' ãšãªãïŒ åºååœ¢åŒ ã¯ãããŒã²ãŒã ãè¡ãããåŸã®ããŒãã«ã¯ãã¹ã®äžã«çœ®ãããã¯ãããŒã®ç¶æ
ãïŒå
¥å圢åŒãšåã圢åŒã§åºåããïŒ å¶çŽ s_{ij} 㯠'o' , 'x' , '.' ã®ããããã§ããïŒ å
¥åºåäŸ å
¥åäŸ 1 ooox.... .x...... ooo..... ........ ........ ........ ........ ........ åºåäŸ1 ooooo... .o...... ooo..... ...o.... ....o... ........ ........ ........ å
¥åäŸ 2 ........ ........ ........ ...ox... ...xo... ........ ........ ........ åºåäŸ 2 xxxxxxxx xxxooxxx xxxxooxx xxxxxxxx ooxxooox ooxoooox oxooooox ooooooox å
¥åäŸ 3 ........ ........ ..ooo... ..oxo... ..ooo... ........ ........ ........ åºåäŸ 3 ........ ........ ..ooo... ..ooo... ..ooo... .....o.. ......o. ........ Problem Setter: Flat35 | 37,257 |
Score : 100 points Problem Statement We have a 3Ã3 square grid, where each square contains a lowercase English letters. The letter in the square at the i -th row from the top and j -th column from the left is c_{ij} . Print the string of length 3 that can be obtained by concatenating the letters in the squares on the diagonal connecting the top-left and bottom-right corner of the grid, from the top-left to bottom-right. Constraints Input consists of lowercase English letters. Input Input is given from Standard Input in the following format: c_{11}c_{12}c_{13} c_{21}c_{22}c_{23} c_{31}c_{32}c_{33} Output Print the string of length 3 that can be obtained by concatenating the letters on the diagonal connecting the top-left and bottom-right corner of the grid, from the top-left to bottom-right. Sample Input 1 ant obe rec Sample Output 1 abc The letters in the squares on the diagonal connecting the top-left and bottom-right corner of the grid are a , b and c from top-right to bottom-left. Concatenate these letters and print abc . Sample Input 2 edu cat ion Sample Output 2 ean | 37,258 |
Score : 2000 points Problem Statement You are given a connected graph with N vertices and M edges. The vertices are numbered 1 to N . The i -th edge is an undirected edge of length C_i connecting Vertex A_i and Vertex B_i . Additionally, an odd number MOD is given. You will be given Q queries, which should be processed. The queries take the following form: Given in the i -th query are S_i , T_i and R_i . Print YES if there exists a path from Vertex S_i to Vertex T_i whose length is R_i modulo MOD , and print NO otherwise. A path may traverse the same edge multiple times, or go back using the edge it just used. Here, in this problem, the length of a path is NOT the sum of the lengths of its edges themselves, but the length of the first edge used in the path gets multiplied by 1 , the second edge gets multiplied by 2 , the third edge gets multiplied by 4 , and so on. (More formally, let L_1,...,L_k be the lengths of the edges used, in this order. The length of that path is the sum of L_i \times 2^{i-1} .) Constraints 1 \leq N,M,Q \leq 50000 3 \leq MOD \leq 10^{6} MOD is odd. 1 \leq A_i,B_i\leq N 0 \leq C_i \leq MOD-1 1 \leq S_i,T_i \leq N 0 \leq R_i \leq MOD-1 The given graph is connected. (It may contain self-loops or multiple edges.) Input Input is given from Standard Input in the following format: N M Q MOD A_1 B_1 C_1 \vdots A_M B_M C_M S_1 T_1 R_1 \vdots S_Q T_Q R_Q Output Print the answers to the i -th query in the i -th line. Sample Input 1 3 2 2 2019 1 2 1 2 3 2 1 3 5 1 3 4 Sample Output 1 YES NO The answer to each query is as follows: The first query: If we take the path 1,2,3 , its length is 1 \times 2^0 + 2 \times 2^1 = 5 , so there exists a path whose length is 5 modulo 2019 . The answer is YES . The second query: No matter what path we take from Vertex 1 to Vertex 3 , its length will never be 4 modulo 2019 . The answer is NO . Sample Input 2 6 6 3 2019 1 2 4 2 3 4 3 4 4 4 5 4 5 6 4 6 1 4 2 6 1110 3 1 1111 4 5 1112 Sample Output 2 YES NO NO Sample Input 3 1 2 3 25 1 1 1 1 1 2 1 1 13 1 1 6 1 1 14 Sample Output 3 YES YES YES Sample Input 4 10 15 10 15 1 2 1 2 3 6 3 4 6 2 5 1 5 6 1 4 7 6 1 8 11 2 9 6 5 10 11 9 10 11 3 6 1 2 5 1 2 7 11 9 10 11 5 6 11 1 3 5 9 8 3 7 7 7 7 10 13 4 1 10 9 3 12 10 10 14 9 2 1 6 6 5 8 8 4 Sample Output 4 YES NO NO NO NO NO NO YES YES NO | 37,259 |
3D Printing We are designing an installation art piece consisting of a number of cubes with 3D printing technology for submitting one to Installation art Contest with Printed Cubes (ICPC). At this time, we are trying to model a piece consisting of exactly k cubes of the same size facing the same direction. First, using a CAD system, we prepare n ( n ⥠k ) positions as candidates in the 3D space where cubes can be placed. When cubes would be placed at all the candidate positions, the following three conditions are satisfied. Each cube may overlap zero, one or two other cubes, but not three or more. When a cube overlap two other cubes, those two cubes do not overlap. Two non-overlapping cubes do not touch at their surfaces, edges or corners. Second, choosing appropriate k different positions from n candidates and placing cubes there, we obtain a connected polyhedron as a union of the k cubes. When we use a 3D printer, we usually print only the thin surface of a 3D object. In order to save the amount of filament material for the 3D printer, we want to find the polyhedron with the minimal surface area. Your job is to find the polyhedron with the minimal surface area consisting of k connected cubes placed at k selected positions among n given ones. Figure E1. A polyhedron formed with connected identical cubes. Input The input consists of multiple datasets. The number of datasets is at most 100. Each dataset is in the following format. n k s x 1 y 1 z 1 ... x n y n z n In the first line of a dataset, n is the number of the candidate positions, k is the number of the cubes to form the connected polyhedron, and s is the edge length of cubes. n, k and s are integers separated by a space. The following n lines specify the n candidate positions. In the i -th line, there are three integers x i , y i and z i that specify the coordinates of a position, where the corner of the cube with the smallest coordinate values may be placed. Edges of the cubes are to be aligned with either of three axes. All the values of coordinates are integers separated by a space. The three conditions on the candidate positions mentioned above are satisfied. The parameters satisfy the following conditions: 1 †k †n †2000, 3 †s †100, and -4Ã10 7 †x i , y i , z i †4Ã10 7 . The end of the input is indicated by a line containing three zeros separated by a space. Output For each dataset, output a single line containing one integer indicating the surface area of the connected polyhedron with the minimal surface area. When no k cubes form a connected polyhedron, output -1. Sample Input 1 1 100 100 100 100 6 4 10 100 100 100 106 102 102 112 110 104 104 116 102 100 114 104 92 107 100 10 4 10 -100 101 100 -108 102 120 -116 103 100 -124 100 100 -132 99 100 -92 98 100 -84 100 140 -76 103 100 -68 102 100 -60 101 100 10 4 10 100 100 100 108 101 100 116 102 100 124 100 100 132 102 100 200 100 103 192 100 102 184 100 101 176 100 100 168 100 103 4 4 10 100 100 100 108 94 100 116 100 100 108 106 100 23 6 10 100 100 100 96 109 100 100 118 100 109 126 100 118 126 100 127 118 98 127 109 104 127 100 97 118 91 102 109 91 100 111 102 100 111 102 109 111 102 118 111 102 91 111 102 82 111 114 96 111 114 105 102 114 114 93 114 114 84 114 105 84 114 96 93 114 87 102 114 87 10 3 10 100 100 100 116 116 102 132 132 104 148 148 106 164 164 108 108 108 108 124 124 106 140 140 104 156 156 102 172 172 100 0 0 0 Output for the Sample Input 60000 1856 -1 1632 1856 2796 1640 | 37,260 |
Score : 100 points Problem Statement Given is a three-digit integer N . Does N contain the digit 7 ? If so, print Yes ; otherwise, print No . Constraints 100 \leq N \leq 999 Input Input is given from Standard Input in the following format: N Output If N contains the digit 7 , print Yes ; otherwise, print No . Sample Input 1 117 Sample Output 1 Yes 117 contains 7 as its last digit. Sample Input 2 123 Sample Output 2 No 123 does not contain the digit 7 . Sample Input 3 777 Sample Output 3 Yes | 37,262 |
Score : 100 points Problem Statement Alice and Bob are playing One Card Poker . One Card Poker is a two-player game using playing cards. Each card in this game shows an integer between 1 and 13 , inclusive. The strength of a card is determined by the number written on it, as follows: Weak 2 < 3 < 4 < 5 < 6 < 7 < 8 < 9 < 10 < 11 < 12 < 13 < 1 Strong One Card Poker is played as follows: Each player picks one card from the deck. The chosen card becomes the player's hand. The players reveal their hands to each other. The player with the stronger card wins the game. If their cards are equally strong, the game is drawn. You are watching Alice and Bob playing the game, and can see their hands. The number written on Alice's card is A , and the number written on Bob's card is B . Write a program to determine the outcome of the game. Constraints 1âŠAâŠ13 1âŠBâŠ13 A and B are integers. Input The input is given from Standard Input in the following format: A B Output Print Alice if Alice will win. Print Bob if Bob will win. Print Draw if the game will be drawn. Sample Input 1 8 6 Sample Output 1 Alice 8 is written on Alice's card, and 6 is written on Bob's card. Alice has the stronger card, and thus the output should be Alice . Sample Input 2 1 1 Sample Output 2 Draw Since their cards have the same number, the game will be drawn. Sample Input 3 13 1 Sample Output 3 Bob | 37,263 |
Where's Your Robot? You have full control over a robot that walks around in a rectangular field paved with square tiles like a chessboard. There are m columns of tiles from west to east, and n rows of tiles from south to north (1 <= m, n <= 100). Each tile is given a pair of coordinates, such as ( i, j ), where 1 <= i <= m and 1 <= j <= n. Your robot is initially on the center of the tile at (1, 1), that is, one at the southwest corner of the field, facing straight north. It can move either forward or backward, or can change its facing direction by ninety degrees at a time, according to a command you give to it, which is one of the following. FORWARD k Go forward by k tiles to its facing direction (1 <= k < 100). BACKWARD k Go backward by k tiles, without changing its facing direction (1 <= k < 100). RIGHT Turn to the right by ninety degrees. LEFT Turn to the left by ninety degrees. STOP Stop. While executing either a " FORWARD " or a " BACKWARD " command, the robot may bump against the wall surrounding the field. If that happens, the robot gives up the command execution there and stands at the center of the tile right in front of the wall, without changing its direction. After finishing or giving up execution of a given command, your robot will stand by for your next command. Input The input consists of one or more command sequences. Each input line has at most fifty characters. The first line of a command sequence contains two integer numbers telling the size of the field, the first number being the number of columns and the second being the number of rows. There might be white spaces (blanks and/or tabs) before, in between, or after the two numbers. Two zeros as field size indicates the end of input. Each of the following lines of a command sequence contains a command to the robot. When a command has an argument, one or more white spaces are put between them. White spaces may also appear before and after the command and/or its argument. A command sequence is terminated by a line containing a " STOP " command. The next command sequence, if any, starts from the next line. Output The output should be one line for each command sequence in the input. It should contain two numbers i and j of the coordinate pair ( i, j ), in this order, of the tile on which your robot stops. Two numbers should be separated by one white spaces. Sample Input 6 5 FORWARD 3 RIGHT FORWARD 5 LEFT BACKWARD 2 STOP 3 1 FORWARD 2 STOP 0 0 Output for the Sample Input 6 2 1 1 | 37,264 |
FïŒ 01 æååãšçª (Binary String with Slit) åé¡ æåã®çš®é¡ã 0 ãš 1 ã®ã¿ãããªãæåå S ãäžããããŸãã以äžã®æäœãç¹°ãè¿ãããšã§ã S ã T ã«å€ãããã§ãã æåå S äžã®æãå³åŽã«ç»å Žãã 1 ãå«ãããã«ãå¹
2 ã®ã¹ãªããã眮ããã¹ãªããå
ã«ã¯é£ç¶ãã 2 æåãå¿
ãå«ãŸãªããã°ãªããªããã€ãŸããæååã®ç«¯ 1 æåã®ã¿ãå«ãããã«çœ®ãããšã¯ã§ããªãã 2 éã眮ããå Žåãèãããããããã®å Žåã¯ã©ã¡ãã®æ¹æ³ã§çœ®ããŠãæ§ããªãã ã¹ãªããäžã® 2 æåã 2 æ¡ã®äºé²æ°ãšæãããšããå
ã®æ°å€ãšã®å·®ã®çµ¶å¯Ÿå€ã 1 ã«ãªãããã«ã¹ãªããäžã®æåã倿Žããããã ããã¹ãªããäžã®æåã®äž¡æ¹ã 0 ã«ãªã£ãŠã¯ãªããªããã€ãŸãã倿ŽåŸã®ã¹ãªããå
ã®æ°å€ã¯ 1 ãã 3 ãŸã§ã®ãããããšãªãã ã¯ãšãªã Q åäžããããŸãã i çªç®ã®ã¯ãšãªã§ 1 ãå°ãªããšãäžã€å«ãæåå S_i, T_i ãäžããããã®ã§ã S_i ã T_i ã«å€ããããã«å¿
èŠãªæäœåæ°ã®æå°å€ããããããã®ã¯ãšãªã«ã€ããŠæ±ããŠãã ããã å
¥ååœ¢åŒ Q S_1 T_1 ... S_Q T_Q 1 è¡ç®ã§ã¯ãã¯ãšãªã®åæ° Q ãäžããããã 2 è¡ç®ä»¥é Q è¡ã¯ãã¯ãšãªãäžããããã i+1 è¡ç®ã§ã¯ S_i ãš T_i ã空çœåºåãã§äžããããã å¶çŽ 1 \leq Q \leq 10^5 2 \leq |S_i| = |T_i| \leq 50 S_i, T_i 㯠0 ãš 1 ã®ã¿ãããªãæååã§ããã S_i, T_i ã¯ãšãã« 1 ãå°ãªããšã 1 ã€å«ãæååã§ããã åºååœ¢åŒ åºå㯠Q è¡ãããªãã i è¡ç®ã«ã¯ã i çªç®ã®ã¯ãšãªã«å¯Ÿããçµæãåºåããã å
¥åäŸ1 4 101 110 101 101 1010 1101 11011001 10010101 åºåäŸ1 1 0 3 12 1 åç®ã®ã¯ãšãªã§ã¯ã S = 101 ã T = 110 ãšäžèŽãããããã«å¿
èŠãªæäœåæ°ã®æå°å€ãæ±ããå¿
èŠããããŸãã以äžã®ç»åã®ããã«ã S ã®äžã«ç»å Žãã 1 ã®äžã§æãå³ã«ãããã®ãå«ãŸããããã«ã¹ãªããã眮ããã¹ãªããäžã®æååãæžãæããããšã§ 1 åã®æäœã§ S ãš T ãäžèŽãããããšãã§ããŸãã 2 åç®ã®ã¯ãšãªã§ã¯ãã¯ãããã S ãš T ãäžèŽããŠãããããæäœã®å¿
èŠããããŸããã 3 åç®ã®ã¯ãšãªã«ã€ããŠã以äžã®ç»åã®ããã«æååã倿Žããããš 3 åã®æäœã§ S ãš T ãäžèŽãããããšãã§ããŸãã | 37,265 |
Balls and Boxes 11 Balls Boxes Any way At most one ball At least one ball Distinguishable Distinguishable 1 2 3 Indistinguishable Distinguishable 4 5 6 Distinguishable Indistinguishable 7 8 9 Indistinguishable Indistinguishable 10 11 12 Problem You have $n$ balls and $k$ boxes. You want to put these balls into the boxes. Find the number of ways to put the balls under the following conditions: Each ball is not distinguished from the other. Each box is not distinguished from the other. Each ball can go into only one box and no one remains outside of the boxes. Each box can contain at most one ball. Note that you must print this count modulo $10^9+7$. Input $n$ $k$ The first line will contain two integers $n$ and $k$. Output Print the number of ways modulo $10^9+7$ in a line. Constraints $1 \le n \le 1000$ $1 \le k \le 1000$ Sample Input 1 5 10 Sample Output 1 1 Sample Input 2 200 100 Sample Output 2 0 | 37,266 |
Score : 700 points Problem Statement There is an H \times W grid ( H vertical, W horizontal), where each square contains a lowercase English letter. Specifically, the letter in the square at the i -th row and j -th column is equal to the j -th character in the string S_i . Snuke can apply the following operation to this grid any number of times: Choose two different rows and swap them. Or, choose two different columns and swap them. Snuke wants this grid to be symmetric . That is, for any 1 \leq i \leq H and 1 \leq j \leq W , the letter in the square at the i -th row and j -th column and the letter in the square at the (H + 1 - i) -th row and (W + 1 - j) -th column should be equal. Determine if Snuke can achieve this objective. Constraints 1 \leq H \leq 12 1 \leq W \leq 12 |S_i| = W S_i consists of lowercase English letters. Input Input is given from Standard Input in the following format: H W S_1 S_2 : S_H Output If Snuke can make the grid symmetric, print YES ; if he cannot, print NO . Sample Input 1 2 3 arc rac Sample Output 1 YES If the second and third columns from the left are swapped, the grid becomes symmetric, as shown in the image below: Sample Input 2 3 7 atcoder regular contest Sample Output 2 NO Sample Input 3 12 12 bimonigaloaf faurwlkbleht dexwimqxzxbb lxdgyoifcxid ydxiliocfdgx nfoabgilamoi ibxbdqmzxxwe pqirylfrcrnf wtehfkllbura yfrnpflcrirq wvcclwgiubrk lkbrwgwuiccv Sample Output 3 YES | 37,267 |
Problem K Black and White Boxes Alice and Bob play the following game. There are a number of straight piles of boxes. The boxes have the same size and are painted either black or white. Two players, namely Alice and Bob, take their turns alternately. Who to play first is decided by a fair random draw. In Alice's turn, she selects a black box in one of the piles, and removes the box together with all the boxes above it, if any. If no black box to remove is left, she loses the game. In Bob's turn, he selects a white box in one of the piles, and removes the box together with all the boxes above it, if any. If no white box to remove is left, he loses the game. Given an initial configuration of piles and who plays first, the game is a definite perfect information game . In such a game, one of the players has sure win provided he or she plays best. The draw for the first player, thus, essentially decides the winner. In fact, this seemingly boring property is common with many popular games, such as chess. The chess game, however, is complicated enough to prevent thorough analyses, even by supercomputers, which leaves us rooms to enjoy playing. This game of box piles, however, is not as complicated. The best plays may be more easily found. Thus, initial configurations should be fair, that is, giving both players chances to win. A configuration in which one player can always win, regardless of who plays first, is undesirable. You are asked to arrange an initial configuration for this game by picking a number of piles from the given candidate set. As more complicated configuration makes the game more enjoyable, you are expected to find the configuration with the maximum number of boxes among fair ones. Input The input consists of a single test case, formatted as follows. $n$ $p_1$ . . . $p_n$ A positive integer $n$ ($\leq 40$) is the number of candidate piles. Each $p_i$ is a string of characters B and W , representing the $i$-th candidate pile. B and W mean black and white boxes, respectively. They appear in the order in the pile, from bottom to top. The number of boxes in a candidate pile does not exceed 40. Output Output in a line the maximum possible number of boxes in a fair initial configuration consisting of some of the candidate piles. If only the empty configuration is fair, output a zero. Sample Input 1 4 B W WB WB Sample Output 1 5 Sample Input 2 6 B W WB WB BWW BWW Sample Output 2 10 | 37,268 |
Score : 100 points Problem Statement Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier. He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though. Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious. Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it. Write a program that outputs delicious if he found it delicious, safe if he did not found it delicious but did not get a stomachache either, and dangerous if he got a stomachache. Constraints 1 †X,A,B †10^9 Input Input is given from Standard Input in the following format: X A B Output Print delicious if Takahashi found the food delicious; print safe if he neither found it delicious nor got a stomachache; print dangerous if he got a stomachache. Sample Input 1 4 3 6 Sample Output 1 safe He ate the food three days after the "best-by" date. It was not delicious or harmful for him. Sample Input 2 6 5 1 Sample Output 2 delicious He ate the food by the "best-by" date. It was delicious for him. Sample Input 3 3 7 12 Sample Output 3 dangerous He ate the food five days after the "best-by" date. It was harmful for him. | 37,269 |
Problem K: Collector â»ãã®ç©èªã¯ãã£ã¯ã·ã§ã³ã§ãããå®åšã®äººç©ãå£äœãªã©ãšã¯äžåé¢ä¿ããããŸããã æè¿ãœãŒã·ã£ã«ã²ãŒã ããšãŠã人æ°ã§ã ããããã®äŒç€ŸããœãŒã·ã£ã«ã²ãŒã ãéçºããŠããŸãã ããªãã¯ç«¶åããŠãããœãŒã·ã£ã«ã²ãŒã éçºäŒç€Ÿã®äžã€ã«ã¹ãã€ãšããŠæœå
¥ããŠããŸãã åé¡ ããªãã®åããŠããäŒç€Ÿã§ã¯ããœãŒã·ã£ã«ã²ãŒã ãéçºããŠããã éçºããŠããã²ãŒã ã¯ãã«ãŒããéããŠæŠãã²ãŒã ã§ããã 1å300å ã®ææâã¬ãã£ã¬ãã£âãåçã®æ±ã«ããŠããã ãã®ã²ãŒã ã®ã«ãŒãã«ã¯ãâããŒãã«âãâã¬ã¢âãâSã¬ã¢âã®3çš®é¡ããããâSã¬ã¢âã«ãŒãã¯Nçš®é¡ååšããã ææâã¬ãã£ã¬ãã£âã§ã¯ã1åè¡ãããšã«97ïŒ
ã®ç¢ºçã§1æã®ã¬ã¢ã«ãŒããæã«å
¥ãã3%ã®ç¢ºçã§1æã®Sã¬ã¢ã«ãŒããæã«å
¥ãã ææâã¬ãã£ã¬ãã£âã«ãããåSã¬ã¢ã«ãŒãã®åºçŸå²å(åèš3%)ãæäœããæš©éãæã£ãŠããããªãã¯ã äŒç€Ÿã®å©çããæžå°ããããããšã«ããã ãŸããæ§ã
ãªãã¬ã€ã€ãŒã®ææâã¬ãã£ã¬ãã£âã®å©çšåŸåã調ã¹ããšããã ãåãã¬ã€ã€ãŒã¯ã åã
ã®å¥œããªSã¬ã¢ã«ãŒããåŒããšã æºè¶³ãããã®åŸã¯âã¬ãã£ã¬ãã£âã®å©çšãè¡ããªãããšããããšãæããã«ãªã£ãã 以äžã®æ
å ±ããã ããªã㯠âåãã¬ã€ã€ãŒã¯ãç¹å®ã®Sã¬ã¢ã«ãŒãã奜ã¿ããã®Sã¬ã¢ã«ãŒããåŒããŸã§ã¬ãã£ã¬ãã£ããç¶ããâ ãšããä»®å®ã®äžã§äŒç€Ÿã®å©çãã¢ãã«åããã ããªãã¡äŒç€Ÿã®å©çãšã¯ã Sã¬ã¢ã«ãŒãiã奜ã人ã®å²å à Sã¬ã¢ã«ãŒãiãåŸããããŸã§ã®æ¶è²»éé¡ã®æåŸ
å€ ã®ç·åã§ããã Sã¬ã¢ã«ãŒãã®åºçŸå²åãé©åã«æäœããããšã§ã äŒç€Ÿã®å©çããæå°åãããã ãã ããåºçŸå²åã¯ä»¥äžã®æ¡ä»¶ãæºãããªããã°ãªããªãã Sã¬ã¢ã«ãŒãå
šäœã®åºçŸå²åã®åã¯3%ã§ãã åSã¬ã¢ã«ãŒãã®åºçŸå²åã¯æäœ0.01%ã§ãã å
¥å N (Sã¬ã¢ã«ãŒãã®çš®é¡) P_1 (ã«ãŒã1ã奜ããªäººã®å²å) P_2 (ã«ãŒã2ã奜ããªäººã®å²å) ... P_N (ã«ãŒãNã奜ããªäººã®å²å) åºå å顿ã§å®çŸ©ãããäŒç€Ÿã®å©çã®æå°å€ãåºåããã å¶çŽ \( N \)ã¯æŽæ° \( 1 \leq N \leq 300 \) \( 0.0 \leq P_i (1 \leq i \leq N) \leq 1.0 \) \( P_1 + P_2 + \cdots + P_N = 1.0 \) \( P_i \)ã¯å°æ°ç¹ä»¥äž5æ¡ãŸã§äžãããã 誀差ã¯çžå¯Ÿ\( 10 ^ {-6} \) ãŸã§èš±å®¹ããã å
¥åºåäŸ å
¥å1 1 1.00000 åºå1 10000 å
¥å2 2 0.00001 0.99999 åºå2 10063.3444816 ã«ãŒã1ã¯\( 0.01% \)ã®å²åã§åºçŸããã«ãŒã2ã¯\( 2.99% \)ã®å²åã§åºçŸããããã«èšå®ããã å
¥å3 2 0.50000 0.50000 åºå3 20000.0000000 | 37,270 |
Score : 400 points Problem Statement You are given N integers; the i -th of them is A_i . Find the maximum possible sum of the absolute differences between the adjacent elements after arranging these integers in a row in any order you like. Constraints 2 \leq N \leq 10^5 1 \leq A_i \leq 10^9 All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 : A_N Output Print the maximum possible sum of the absolute differences between the adjacent elements after arranging the given integers in a row in any order you like. Sample Input 1 5 6 8 1 2 3 Sample Output 1 21 When the integers are arranged as 3,8,1,6,2 , the sum of the absolute differences between the adjacent elements is |3 - 8| + |8 - 1| + |1 - 6| + |6 - 2| = 21 . This is the maximum possible sum. Sample Input 2 6 3 1 4 1 5 9 Sample Output 2 25 Sample Input 3 3 5 5 1 Sample Output 3 8 | 37,272 |
Problem H: Petoris You are playing a puzzle game named petoris . It is played with a board divided into square grids and square tiles each of which fits to a single grid. In each step of the game, you have a board partially filled with tiles. You also have a block consisting of several tiles. You are to place this block somewhere on the board or to discard it, under the following restrictions on placement: the block can be rotated, but cannot be divided nor flipped; no tiles of the block can collide with any tiles existing on the board; and all the tiles of the block need to be placed inside the board. Your task is to write a program to find the maximum score you can earn in this step. Here, the score is the number of the horizontal lines fully filled with tiles after the block is placed, or -1 in case of discard. Input The first line of the input is N , the number of data sets. Then N data sets follow. Each data set consists of lines describing a block and a board. Each description (both for a block and a board) starts with a line containing two integer H and W , the vertical and horizontal dimension. Then H lines follow, each with W characters, where a â#â represents a tile and â.â a vacancy. You can assume that 0 < H †64 and 0 < W †64. Each block consists of one or more tiles all of which are connected. Each board contains zero or more tiles, and has no horizontal line fully filled with tiles at the initial state. Output For each data set, print in a single line the maximum possible score. Sample Input 5 4 4 .... .... #### .... 12 8 ........ ........ ........ ........ ........ .......# ##.##..# .####### .####### .####### .####### .####.#. 4 4 .... .... .### ...# 12 8 ........ ........ ........ ........ ........ ........ ........ ##...### ##.##### #######. #######. #######. 4 4 #### #..# #..# #### 12 8 ........ ........ ........ ........ ........ .......# ##.##..# ##....## ##.##.## ##.##.## ##....## .####.#. 2 2 ## #. 3 3 .## .## ##. 4 4 .... .##. .##. .... 2 2 .. .. Output for the Sample Input 4 1 4 -1 2 | 37,273 |
Score : 1800 points Problem Statement This is an output-only problem. You shouldn't read anything from the input. In short, your task is to simulate multiplication by using only comparison (x < y) and addition (x + y) . There is no input in this problem, you just print a sequence of operations. Imagine that there is a big array a[0], a[1], ..., a[N-1] of length N . The first two values are initially two non-negative integers A and B (which are unknown to you), the other elements are zeros. Your goal is to get the product A \cdot B in a[2] at the end. You are allowed operations of two types, with the following format (where 0 \leq i, j, k < N ): + i j k â applies operation a[k] = a[i] + a[j] . < i j k â applies operation a[k] = a[i] < a[j] . That is, if a[i] < a[j] then a[k] becomes 1 , otherwise it becomes 0 . You can use at most Q operations. Elements of a can't exceed V . Indices (i, j, k) don't have to be distinct. It's allowed to modify any element of the array (including the first two). The actual checker simulates the process for multiple pairs (A, B) within a single test. Each time, the checker chooses values A and B , creates the array a = [A, B, 0, 0, \ldots, 0] , applies all your operations and ensures that a[2] = A \cdot B . Constraints 0 \leq A, B \leq 10^9 N = Q = 200\,000 V = 10^{19} = 10\,000\,000\,000\,000\,000\,000 Partial Score 800 points will be awarded for passing tests that satisfy A, B \leq 10 . Another 1000 points will be awarded for passing all tests. Input The Standard Input is empty. Output In the first line, print the number of operations. Each operation should then be printed in a single line of format + i j k or < i j k . Sample Input 1 Sample Output 1 4 < 0 1 8 + 0 1 2 + 2 8 2 + 0 0 0 In the first sample test, the checker checks your sequence only for a pair (A, B) = (2, 3) . The provided output is correct for this test: Initially, a[0] = 2 , a[1] = 3 , a[2] = a[3] = \ldots = a[N-1] = 0 . < 0 1 8 applies a[8] = 1 because a[0] < a[1] . + 0 1 2 applies a[2] = a[0] + a[1] = 5 . + 2 8 2 applies a[2] = a[2] + a[8] = 6 . + 0 0 0 applies a[0] = a[0] + a[0] = 4 . As required, at the end we have a[2] = 6 = A \cdot B . | 37,274 |
æ°å 次ã®ããã«å®çŸ©ãããŠããæ°åããããŸãã ãã¹ãŠã®å¶æ°çªç®ã®é
ã¯äžã€åã®é
ã« 2 ãæãããã®ãšçããæ°ã§ããã ãã¹ãŠã®å¥æ°çªç®ã®é
ã¯äžã€åã®é
ã 3 ã§å²ã£ããã®ãšçããæ°ã§ããã ãã®æ°åã®åé
a ãèªã¿èŸŒã¿ãåé
ãã第 10 é
ãŸã§ã®å s(10) ãåºåããããã°ã©ã ãäœæããŠãã ããã Input å
¥åã¯è€æ°ã®ãã¹ãã±ãŒã¹ãããªããŸããåãã¹ãã±ãŒã¹ãšããŠãæ°åã®åé
ã衚ã宿° a (1.0 †a †10.0) ãïŒè¡ã«äžããããŸãã ãã¹ãã±ãŒã¹ã®æ°ã¯ 50 ãè¶
ããŸããã Output ãã¹ãã±ãŒã¹ããšã« s(10) ãïŒè¡ã«åºåããŸãã åºåã¯0.000001以äžã®èª€å·®ãå«ãã§ãããã Sample Input 1.0 2.0 3.0 Output for the Sample Input 7.81481481 15.62962963 23.44444444 | 37,275 |
Problem Statement You are given a positive integer sequence $A$ of length $N$. You can remove any numbers from the sequence to make the sequence âfriendly". A sequence is called friendly if there exists an integer $k$ (>1) such that every number in the sequence is a multiple of $k$. Since the empty sequence is friendly, it is guaranteed that you can make the initial sequence friendly. You noticed that there may be multiple ways to make the sequence friendly. So you decide to maximize the sum of all the numbers in the friendly sequence. Please calculate the maximum sum of the all numbers in the friendly sequence which can be obtained from the initial sequence. Input The input consists of a single test case formatted as follows. $N$ $A_1$ $\vdots$ $A_N$ The first line consists of a single integer $N$ ($1 \le N \le 1000$). The $i+1$-st line consists of an integer $A_i$ ($1 \le A_i \le 10^9$ for $1 \le i \le N$). Output Print the maximum sum of all the numbers in the friendly sequence which can be obtained from the initial sequence. Examples Input Output 6 1 2 3 4 5 6 12 3 173 1733 111733 111733 4 1 1 1 1 0 10 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 9999999990 1 999999999 999999999 10 28851 8842 9535 2311 25337 26467 12720 10561 8892 6435 56898 | 37,276 |
ã¢ã«ãã³ïŒïŒ ãã¢ã«ãã³ïŒïŒãã¯ãã€ã
ã¢å°æ¹ã®å°çšåå Žã§å
¬æŒãéå¬ããŠããã°ã«ãŒãã§ããã¢ã«ãã³ïŒïŒã®ããããã®ã¡ã³ããŒã¯ãããäžå®ã®æ¥æ°ããšã«å
¬æŒã«åå ããããšã«ãªã£ãŠããŸãã 仿¥ã®å
¬æŒã§ã¯ã¡ã³ããŒãå
šå¡åå ããŠããŸããããããã¥ãŒãµãŒã§ããããªãã¯ãã¡ã³ããŒãããä»åŸã®å
¬æŒã®ã¡ã³ããŒã®çµã¿åãããæããŠã»ããããšé ŒãŸããŸãããããªãã¯ãå
¬æŒã«åå ããã¡ã³ããŒã®çµã¿åãããããã€ããã®ããæ°ããããšã«ããŸããã ã¢ã«ãã³ïŒïŒã®ã¡ã³ããŒæ°ãšãããããã®ã¡ã³ããŒãå
¬æŒã«åå ããåšæãïŒæ¥åäœã§äžãããããšããåå ããã¡ã³ããŒã®çµã¿åãããäœéãããããæ°ããããã°ã©ã ãäœæããããã®ãšããã°ã«ãŒãã¯åãã¡ã³ããŒã§æ°žé ã«åç¶ãããšä»®å®ããããã ããã ããåå ããªãå Žåã¯çµã¿åããã«å«ããªãããšãšããã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã $N$ $p_1$ $p_2$ ... $p_N$ ïŒè¡ç®ã«ã¢ã«ãã³ïŒïŒã®ã¡ã³ããŒæ°$N$ ($1 \leq N \leq 20$)ãäžãããããç¶ãïŒè¡ã«ãããããã®ã¡ã³ããŒãå
¬æŒã«åå ããåšæ$p_i$ ($1 \leq p_i \leq 40$)ãäžããããã åºå åå ããã¡ã³ããŒã®çµã¿åããã®æ°ãïŒè¡ã«åºåããã å
¥åºåäŸ å
¥åäŸïŒ 3 3 5 2 åºåäŸïŒ 7 å
¥åäŸïŒ 3 2 3 6 åºåäŸïŒ 3 åšæãïŒæ¥ã®ã¡ã³ããŒã®ã¿ãåå ããå
¬æŒïŒåšæãïŒæ¥ã®ã¡ã³ããŒã®ã¿ãåå ããå
¬æŒïŒåšæãïŒæ¥ãïŒæ¥ãïŒæ¥ã®ã¡ã³ããŒãåå ããå
¬æŒã®ïŒéããšãªãã | 37,277 |
Splice For $n$ lists $L_i$ $(i = 0, 1, ..., n-1)$, perform a sequence of the following operations. insert($t$, $x$): Insert an integer $x$ at the end of $L_t$. dump($t$): Print all elements in $L_t$. splice($s$, $t$): Transfer elements of $L_s$ to the end of $L_t$. $L_s$ becomes empty. In the initial state, $L_i$ $(i = 0, 1, ..., n-1)$ are empty. Input The input is given in the following format. $n \; q$ $query_1$ $query_2$ : $query_q$ Each query $query_i$ is given by 0 $t$ $x$ or 1 $t$ or 2 $s$ $t$ where the first digits 0 , 1 and 2 represent insert, dump and splice operations respectively. Output For each dump operation, print elements of the corresponding list in a line. Separete adjacency elements by a space character (do not print the space after the last element). Note that, if the list is empty, an empty line should be printed. Constraints $1 \leq n \leq 1,000$ $1 \leq q \leq 500,000$ For a splice operation, $s \ne t$ For a splice operation, $L_s$ is not empty The total number of elements printed by dump operations do not exceed 1,000,000 $-1,000,000,000 \leq x \leq 1,000,000,000$ Sample Input 1 3 10 0 0 1 0 0 2 0 0 3 0 1 4 0 1 5 2 1 0 0 2 6 1 0 1 1 1 2 Sample Output 1 1 2 3 4 5 6 | 37,278 |
èŠé¢ç® æ°åŒã®äžéšãé ããŠããŸã£ãŠãé ããæ°åãæ¢ãåé¡ãèŠé¢ç®ãšãããŸããä»åã¯ãæ°åŒã®äžã®ããæ°åã®ããã€ãã X ã§é ããŠããŸã£ãåŒãæ±ããŸãã以äžã®æ°åŒãå
¥åããŠãçµæãåºåããããã°ã©ã ãäœæããŠãã ããã æ°åŒ ãæ°åå + æ°åå = æ°ååãã®åœ¢ã§ã1 è¡ã®åçŽãªè¶³ãç®åŒã§ãã ãæ°ååãã¯ãæ°å 0 ãã 9 ãšæå X ã®äžŠã³ã§ãã 2 æ¡ä»¥äžã®ãæ°ååãã®å·Šç«¯ã®æ°å㯠0 ã§ã¯ãªããã®ãšããŸãã X ã¯ãæ°åŒå
šäœã®äžã§å¿
ã 1 ã€ä»¥äžå«ãŸããŸãã çµæ èŠé¢ç®ã®çãã§ããæ°åŒãæãç«ã€æ§ãª X ã®å€ã§ 0 ~ 9 ã®ã©ãã 1 ã€ã§ãã2 ã€ä»¥äžã®çãã¯ãªããã®ãšããŸãã çãããªãå Žåãçµæã¯âNAâãšããŠãã ããã Input è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ãããšããŠãX ã 1 ã€ä»¥äžå«ãè¶³ãç®åŒ(空çœãå«ãŸãªã 126 æå以å
ã®æåå) ãïŒè¡ã«äžããããŸããããŒã¿ã»ããã®æ°ã¯ 150 ãè¶
ããŸããã Output åããŒã¿ã»ããã«ã€ããŠãèŠé¢ç®ã®çµæãïŒè¡ã«åºåããŠãã ãããæ°å 0 ~ 9 ãŸã㯠NA ãåºåããŠãã ããã Sample Input 123+4X6=X79 12X+4X6=X79 XX22+89=X2XX Output for the Sample Input 5 NA 1 | 37,279 |
èèžäŒ (Ball) IOI çåœã§ã¯ïŒç女ã§ãã JOI å§«ã®èªçæ¥ãç¥ã£ãŠèèžäŒãéãããããšã«ãªã£ãïŒ èèžäŒã«ã¯ N 人ã®è²Žæãåå ããäºå®ã§ããïŒ N ã¯å¥æ°ã§ããïŒè²Žæã«ã¯ 1 ãã N ãŸã§ã®çªå·ãä»ããããŠããïŒããããã®è²Žæã«ã¯èžãã®ããŸããšããæŽæ°ãå®ããããŠããïŒè²Žæ i (1 †i †N ) ã®èžãã®ããŸã㯠D i ã§ããïŒ èèžäŒã§ã¯ JOI å§«ãå«ã N + 1 人㧠2 人ãã€çµãäœã£ãŠèžãïŒIOI çåœã§ã¯ïŒäžçŽè
ãåçŽè
ãè£å©ã§ããããã«ïŒäŒçµ±çã«ä»¥äžã®æ¹æ³ã§èžãã®çµã決å®ããŠããïŒ æåã«ïŒ N 人ã®è²Žæã 1 åã«äžŠã¶ïŒ åã«äžŠãã§ãã貎æã 1 人ã«ãªããŸã§ïŒä»¥äžã®æäœãç¹°ãè¿ãïŒ - åã®å
é ãã 3 人ã®è²Žæã®èžãã®ããŸãã調ã¹ãïŒ - ãã® 3 人ã®è²Žæã®äžã§ïŒæãèžãã®ããŸãã倧ãã貎æã A ãšããïŒãã ãïŒè€æ°ããå Žåã¯ïŒæãèžãã®ããŸãã倧ãã貎æã®äžã§ïŒæãçªå·ã®å°ãã貎æ ã A ãšããïŒ - ãã® 3 人ã®è²Žæã®äžã§ïŒæãèžãã®ããŸããå°ãã貎æã B ãšããïŒãã ãïŒè€æ°ããå Žåã¯ïŒæãèžãã®ããŸããå°ãã貎æã®äžã§ïŒæãçªå·ã®å€§ãã貎æ ã B ãšããïŒ - A ãš B ãåããæããŠçµã«ãªãïŒ - æ®ã£ã 1 人ã¯åã®æåŸå°Ÿã«ç§»åããïŒ æçµçã«æ®ã£ã 1 人ã JOI å§«ãšçµã«ãªãïŒ è²Žæ 1 ãã貎æ M (1 †M †N â 2) ã® M 人ã®è²Žæã«ã€ããŠã¯ïŒãã§ã«åæç¶æ
ã§åã®äœçªç®ã«äžŠã¶ã®ããæ±ºãŸã£ãŠããïŒæ®ãã® N â M 人ã®è²Žæã®äžŠã³æ¹ã¯åœçãèªç±ã«æ±ºããããšãã§ããïŒ JOI å§«ã¯èžããåŠãã ã°ãããªã®ã§ïŒåœç㯠JOI å§«ãšçµã«ãªã貎æã®èžãã®ããŸããã§ããã ã倧ããããããšèããŠããïŒJOI å§«ãšçµã«ãªã貎æã®èžãã®ããŸããšããŠèããããæå€§å€ãæ±ããïŒ èª²é¡ ããããã®è²Žæã®èžãã®ããŸããšïŒ M 人ã®è²Žæã®åæç¶æ
ã§äžŠã¶å ŽæãäžãããããšãïŒJOI å§«ãšçµã«ãªã貎æã®èžãã®ããŸããšããŠèããããæå€§å€ãæ±ããããã°ã©ã ãäœæããïŒ å
¥å æšæºå
¥åãã以äžã®ããŒã¿ãèªã¿èŸŒãïŒ 1 è¡ç®ã«ã¯ïŒ2 åã®æŽæ° N , M ã空çœãåºåããšããŠæžãããŠããïŒããã¯èèžäŒã«è²Žæã N 人åå ãïŒåã«äžŠã¶å Žæããã§ã«æ±ºãŸã£ãŠãã貎æã M 人ããããšã衚ãïŒ ç¶ã M è¡ã®ãã¡ã® i è¡ç® (1 †i †M ) ã«ã¯ïŒ2 åã®æŽæ° D i , P i ã空çœãåºåããšããŠæžãããŠããïŒããã¯è²Žæ i ã®èžãã®ããŸãã D i ã§ïŒè²Žæ i ãåæç¶æ
ã§åã®å
é ãã P i çªç®ã«äžŠã¶ããšã衚ãïŒ ç¶ã N â M è¡ã®ãã¡ã® i è¡ç® (1 †i †N â M ) ã«ã¯ïŒæŽæ° D i+M ãæžãããŠããïŒããã¯è²Žæ ( i + M )ã®èžãã®ããŸãã D i+M ã§ããããšã衚ãïŒ åºå æšæºåºåã«ïŒJOI å§«ãšçµã«ãªã貎æã®èžãã®ããŸããšããŠèããããæå€§å€ãè¡šãæŽæ°ã 1 è¡ã§åºåããïŒ å¶é ãã¹ãŠã®å
¥åããŒã¿ã¯ä»¥äžã®æ¡ä»¶ãæºããïŒ 3 †N †99 999ïŒ N ã¯å¥æ°ã§ããïŒ 1 †M †N â 2ïŒ 1 †D i †1 000 000 000 (1 †i †N )ïŒ 1 †P i †N (1 †i †M )ïŒ P i â P j (1 †i < j †M )ïŒ å
¥åºåäŸ å
¥åäŸ 1 7 3 5 2 5 5 8 6 6 2 8 9 åºåäŸ 1 8 åæç¶æ
ã§ã¯ 3 人ã®è²Žæã®äžŠã¶å Žæããã§ã«æ±ºãŸã£ãŠããïŒ æ¬åŒ§å
ã®æ°åã¯èžãã®ããŸãã衚ãïŒå·Šç«¯ãåã®å
é ã§ããïŒ äŸãã°ïŒå
é ããé ã«è²Žæ 5ïŒè²Žæ 1ïŒè²Žæ 4ïŒè²Žæ 6ïŒè²Žæ 2ïŒè²Žæ 3ïŒè²Žæ 7 ãšããé çªã«äžŠãã å Ž åãèããïŒ ãã¹ãŠã®è²Žæã䞊ãã ããšã®é
眮 ãã®å ŽåïŒä»¥äžã®ããã«åãå€åããŠããïŒ åã®å
é ã® 3 人ã®è²Žæ (貎æ 5ïŒè²Žæ 1ïŒè²Žæ 4) äžã§ïŒæãèžãã®ããŸãã倧ãã貎æ 4 ãšæãèžãã®ããŸããå°ãã貎æ 5 ãçµã«ãªãïŒæ®ã£ã貎æ 1 ãæåŸå°Ÿã«ç§»åããïŒ æ¬¡ã«ïŒåã®å
é ã® 3 人ã®è²Žæ (貎æ 6ïŒè²Žæ 2ïŒè²Žæ 3) ã®äžã§ïŒæãèžãã®ããŸãã倧ãã貎æã¯è²Žæ 6 ãšè²Žæ 3 ã® 2 人ã§ããïŒãã®ãã¡çªå·ã®å°ãã貎æã¯è²Žæ 3 ã§ããïŒãŸãïŒåã®å
é ã® 3 人ã®è²Žæã®ãã¡æãèžãã®ããŸããå°ãã貎æã¯è²Žæ 2 ã§ããïŒè²Žæ 3 ãšè²Žæ 2 ãçµã«ãªãïŒæ®ã£ã貎æ 6 ãæåŸå°Ÿã«ç§»åããïŒ æ¬¡ã«ïŒåã®å
é ã® 3 人ã®è²Žæ (貎æ 7ïŒè²Žæ 1ïŒè²Žæ 6) ã®äžã§ïŒæãèžãã®ããŸãã倧ãã貎æ 7 ãšæãèžãã®ããŸããå°ãã貎æ 1 ãçµã«ãªãïŒæ®ã£ã貎æ 6 ãæåŸå°Ÿã«ç§»åããïŒ æçµçã«è²Žæ 6 ãæ®ãïŒJOI å§«ãšçµã«ãªãïŒè²Žæ 6 ã®èžãã®ããŸã㯠8 ã§ããïŒãã®å€ã JOI å§«ãšçµã«ãªã貎æã®èžãã®ããŸããšããŠèããããæå€§å€ã§ããïŒ åã®å€åã®æ§å å
¥åäŸ 2 3 1 5 3 5 5 åºåäŸ 2 5 ã©ã®ãããªé çªã§äžŠãã§ãïŒè²Žæ 2 ãš JOI å§«ãçµã«ãªãïŒ å
¥åäŸ 3 7 2 32 4 27 6 37 41 41 30 27 åºåäŸ 3 37 å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã | 37,280 |
J: å·ŠåŽã»å³ç· å顿 å·ŠåŽãããšå³ç·ããã¯ãé·ã $N$ ã®æ°å $a_1, a_2, \dots ,a_n$ ã䜿ã£ãã²ãŒã ã§éã¶ã®ã奜ãã§ãã ãã®ã²ãŒã ã§ã¯å·ŠåŽãããšå³ç·ããã§äº€äºã«ä»¥äžã®æäœãè¡ããŸãã å·ŠåŽããã®æçªã§ã¯ $1 \leq k \leq n$ ãæå®ãã$a_1, a_2, \dots ,a_k$ ã®å€ããããã $1$ ãã€æžããã å³ç·ããã®æçªã§ã¯ $1 \leq k \leq n$ ãæå®ãã$a_k, a_{k+1}, \dots ,a_n$ ã®å€ããããã $1$ ãã€æžããã æçªçµäºæã«æ°åã®äžã«è² ã®æ°ãååšããŠããå Žåããã®æäœããã人ã¯è² ããŸããè² ããªãã£ãæ¹ã¯åã¡ãŸããæåã«æäœãããã®ã¯å·ŠåŽããã§ãã å·ŠåŽããã¯ãã®ã²ãŒã ããã¬ã€ããããã«ã$0, 1, \dots, S$ ãããªãé·ã $N$ ã®æ°åãå
šçš®é¡ïŒ$(S+1)^N$ éãïŒè²·ã£ãŠããŸãããå·ŠåŽãããšå³ç·ããããããã®æ°åã䜿ã£ãŠ $1$ åãã€ã²ãŒã ãããŸãããå·ŠåŽãããåã£ãåæ°ã $998244353$ ã§å²ã£ãããŸããæ±ããŠãã ããããã ããäž¡è
ãšããããããåã€ããã«æé©ãªæäœããããšããŸãã å¶çŽ å
¥åã¯å
šãп޿° $2 \leq N \leq 1000$ $1 \leq S \leq 10^9$ å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããŸãã $N$ $S$ åºå å
šãŠã®æ°åã䜿ã£ãŠ $1$ åãã€ã²ãŒã ããããšãã«ãå·ŠåŽãããåã£ãåæ°ã $998244353$ ã§å²ã£ãããŸããåºåããŠãã ããã å
¥åºåäŸ å
¥åäŸ1 2 1 åºåäŸ1 2 å·ŠåŽãããè²·ã£ãŠããæ°å㯠(0, 0), (0, 1), (1, 0), (1, 1) ã® $4$ ã€ã§ãã (0, 0), (0, 1) ã䜿ã£ãã²ãŒã ã§ã¯ãå·ŠåŽããã¯æåã®æçªã§ã©ã® $k$ ãéžãã§ãè² ããŸãã (1, 0) ã䜿ã£ãã²ãŒã ã§ã¯ãå·ŠåŽãã㯠$k = 1$ ãéžã¹ã°ãæ°åã (0, 0) ãšãªããåãŠãŸãã (1, 1) ã䜿ã£ãã²ãŒã ã§ã¯ãå·ŠåŽãã㯠$k = 2$ ãéžã¹ã°ãæ°åã (0, 0) ãšãªããåãŠãŸãã å
¥åäŸ2 3 2 åºåäŸ2 12 å·ŠåŽãããåã€æ°åã¯ä»¥äžã® $12$ åã§ãã (1,0,0) (1,1,0) (1,1,1) (1,2,0) (1,2,1) (2,0,0) (2,0,1) (2,1,0) (2,1,1) (2,1,2) (2,2,0) (2,2,1) å
¥åäŸ3 1000 1000000000 åºåäŸ3 972070366 | 37,281 |
Problem C: GIGA Universe Cup Following FIFA World Cup, a larger competition called ``GIGA Universe Cup'' is taking place somewhere in our universe. Both FIFA World Cup and GIGA Universe Cup are two rounds competitions that consist of the first round, also known as ``group league,'' and the second called ``final tournament.'' In the first round, participating teams are divided into groups of four teams each. Each team in a group plays a match against each of the other teams in the same group. For example, let's say we have a group of the following four teams, ``Engband, Swedon, Argontina, and Nigerua.'' They play the following six matches: Engband - Swedon, Engband - Argontina, Engband - Nigerua, Swedon - Argontina, Swedon - Nigerua, and Argontina - Nigerua. The result of a single match is shown by the number of goals scored by each team, like ``Engband 1 - 0 Argontina,'' which says Engband scored one goal whereas Argontina zero. Based on the result of a match, points are given to the two teams as follows and used to rank teams. If a team wins a match (i.e., scores more goals than the other), three points are given to it and zero to the other. If a match draws (i.e., the two teams score the same number of goals), one point is given to each. The goal difference of a team in given matches is the total number of goals it scored minus the total number of goals its opponents scored in these matches. For example, if we have three matches ``Swedon 1 - 2 Engband,'' ``Swedon 3 - 4 Nigerua,'' and ``Swedon 5 - 6 Argontina,'' then the goal difference of Swedon in these three matches is (1 + 3 + 5) - (2 + 4+ 6) = -3. Given the results of all the six matches in a group, teams are ranked by the following criteria, listed in the order of priority (that is, we first apply (a) to determine the ranking, with ties broken by (b), with ties broken by (c), and so on). (a) greater number of points in all the group matches; (b) greater goal difference in all the group matches; (c) greater number of goals scored in all the group matches. If two or more teams are equal on the basis of the above three criteria, their place shall be determined by the following criteria, applied in this order: (d) greater number of points obtained in the group matches between the teams concerned; (e) greater goal difference resulting from the group matches between the teams concerned; (f) greater number of goals scored in the group matches between the teams concerned; If two or more teams are stiIl equal, apply (d), (e), and (f) as necessary to each such group. Repeat this until those three rules to equal teams do not make any further resolution. Finally, teams that still remain equal are ordered by: (g) drawing lots by the Organizing Committee for the GIGA Universe Cup. The two teams coming first and second in each group qualify for the second round. Your job is to write a program which, given the results of matches played so far in a group and one team specified in the group, calculates the probability that the specified team will qualify for the second round. You may assume each team has played exactly two matches and has one match to play. In total, four matches have been played and two matches are to be played. Assume the probability that any team scores (exactly) p goals in any match is: for p †8, and zero for p > 8 . Assume the lot in the step (g) is fair. Input The first line of the input is an integer, less than 1000, that indicates the number of subsequent records. The rest of the input is the indicated number of records. A single record has the following format: In the above, <_> is a single underscore (_) and < empty > a sequence of exactly four underscores (____). Each of < team > 1 , ... , < team > 4 is either an asterisk character (*) followed by exactly three uppercase letters (e.g., *ENG), or an underscore followed by exactly three uppercase letters (e.g., _SWE). The former indicates that it is the team you are asked to calculate the probability of the second round qualification for. You may assume exactly one of < team > 1 , ... , < team > 4 is marked with an asterisk. Each < m > ij (1 †i < j †4) is a match result between the < team > i and < team > j . Each match result is either __-_ (i.e., two underscores, hyphen, and another underscore) or of the form _ x - y where each of x and y is a single digit (†8) . The former indicates that the corresponding match has not been played, whereas the latter that the result of the match was x goals by < team > i and y goals by < team > j . Since each team has played exactly two matches, exactly two match results are in the former format. Output The output should consist of n lines where n is the number of records in the input. The i th line should show the probability that the designated team (marked with an asterisk) will qualify for the second round in the i th record. Numbers should be printed with exactly seven digits after the decimal point. Each number should not contain an error greater than 10 -7 . Sample Input 5 _____*AAA__BBB__CCC__DDD *AAA_______0-0__0-0___-_ _BBB_____________-___0-0 _CCC_________________0-0 _DDD____________________ ______CHN__CRC__TUR_*BRA _CHN_______0-2___-___0-4 _CRC____________1-1___-_ _TUR_________________1-2 *BRA____________________ ______CMR_*KSA__GER__IRL _CMR_______1-0___-___1-1 *KSA____________0-8___-_ _GER_________________1-1 _IRL____________________ ______TUN__JPN_*BEL__RUS _TUN________-___1-1__0-2 _JPN____________2-2__1-0 *BEL__________________-_ _RUS____________________ ______MEX__CRO_*ECU__ITA _MEX_______1-0__2-1___-_ _CRO_____________-___2-1 *ECU_________________0-2 _ITA____________________ Output for the Sample Input 0.5000000 1.0000000 0.0000000 0.3852746 0.0353304 | 37,282 |
Problem Statement We can describe detailed direction by repeating the directional names: north, south, east and west. For example, northwest is the direction halfway between north and west, and northnorthwest is between north and northwest. In this problem, we describe more detailed direction between north and west as follows. " north " means $0$ degrees. " west " means $90$ degrees. If the direction $dir$ means $a$ degrees and the sum of the occurrences of " north " and " west " in $dir$ is $n$ ($\geq$ 1), " north "$dir$ (the concatenation of " north " and $dir$) means $a - \frac{90}{2^n}$ degrees and " west "$dir$ means $a + \frac{90}{2^n}$ degrees. Your task is to calculate the angle in degrees described by the given direction. Input The input contains several datasets. The number of datasets does not exceed $100$. Each dataset is described by a single line that contains a string denoting a direction. You may assume the given string can be obtained by concatenating some " north " and " west ", the sum of the occurrences of " north " and " west " in the given string is between $1$ and $20$, inclusive, and the angle denoted by the given direction is between $0$ and $90$, inclusive. The final dataset is followed by a single line containing only a single " # ". Output For each dataset, print an integer if the angle described by the given direction can be represented as an integer, otherwise print it as an irreducible fraction. Follow the format of the sample output. Sample Input north west northwest northnorthwest westwestwestnorth # Output for the Sample Input 0 90 45 45/2 315/4 | 37,283 |
Problem C: Usagitobi m à n ãã¹ã®ç€ããã. i è¡ j åã®ãã¹ã( i , j ) (0 †i < m , 0 †j < n ) ã§è¡šã. ãããã¯( x , y ) ã«ãããšã, (( x + a ) mod m , ( y + b ) mod n ) ãŸãã¯(( x + c ) mod m , ( y + d ) mod n ) ãžè·³ã¶ããšãã§ãã. ããŸ, ãããã(0, 0) ã«ãã. äžåºŠè·³ã³ç«ã£ããã¹ãžåã³è¡ãããšã¯ã§ããªããšãããšã, ãããã¯æå€§äœåè·³ã¶ããšãã§ããã. Input å
¥åã¯äžè¡ã« m , n , a , b , c , d ãã¹ããŒã¹åºåãã§äžãããã. 1 †m , n , a , b , c , d †100 000 Output ããããè·³ã¹ãæå€§åæ°ãäžè¡ã«åºåãã. Sample Input 1 6 6 2 2 2 4 Sample Output 1 8 | 37,284 |
Score : 400 points Problem Statement There are N mountains in a circle, called Mountain 1 , Mountain 2 , ... , Mountain N in clockwise order. N is an odd number. Between these mountains, there are N dams, called Dam 1 , Dam 2 , ... , Dam N . Dam i ( 1 \leq i \leq N ) is located between Mountain i and i+1 (Mountain N+1 is Mountain 1 ). When Mountain i ( 1 \leq i \leq N ) receives 2x liters of rain, Dam i-1 and Dam i each accumulates x liters of water (Dam 0 is Dam N ). One day, each of the mountains received a non-negative even number of liters of rain. As a result, Dam i ( 1 \leq i \leq N ) accumulated a total of A_i liters of water. Find the amount of rain each of the mountains received. We can prove that the solution is unique under the constraints of this problem. Constraints All values in input are integers. 3 \leq N \leq 10^5-1 N is an odd number. 0 \leq A_i \leq 10^9 The situation represented by input can occur when each of the mountains receives a non-negative even number of liters of rain. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print N integers representing the number of liters of rain Mountain 1 , Mountain 2 , ... , Mountain N received, in this order. Sample Input 1 3 2 2 4 Sample Output 1 4 0 4 If we assume Mountain 1 , 2 , and 3 received 4 , 0 , and 4 liters of rain, respectively, it is consistent with this input, as follows: Dam 1 should have accumulated \frac{4}{2} + \frac{0}{2} = 2 liters of water. Dam 2 should have accumulated \frac{0}{2} + \frac{4}{2} = 2 liters of water. Dam 3 should have accumulated \frac{4}{2} + \frac{4}{2} = 4 liters of water. Sample Input 2 5 3 8 7 5 5 Sample Output 2 2 4 12 2 8 Sample Input 3 3 1000000000 1000000000 0 Sample Output 3 0 2000000000 0 | 37,285 |
Score : 400 points Problem Statement You are given a string S of length N consisting of ( and ) . Your task is to insert some number of ( and ) into S to obtain a correct bracket sequence . Here, a correct bracket sequence is defined as follows: () is a correct bracket sequence. If X is a correct bracket sequence, the concatenation of ( , X and ) in this order is also a correct bracket sequence. If X and Y are correct bracket sequences, the concatenation of X and Y in this order is also a correct bracket sequence. Every correct bracket sequence can be derived from the rules above. Find the shortest correct bracket sequence that can be obtained. If there is more than one such sequence, find the lexicographically smallest one. Constraints The length of S is N . 1 †N †100 S consists of ( and ) . Input Input is given from Standard Input in the following format: N S Output Print the lexicographically smallest string among the shortest correct bracket sequences that can be obtained by inserting some number of ( and ) into S . Sample Input 1 3 ()) Sample Output 1 (()) Sample Input 2 6 )))()) Sample Output 2 (((()))()) Sample Input 3 8 ))))(((( Sample Output 3 (((())))(((()))) | 37,286 |
Problem E: Hide-and-seek Hide-and-seek is a childrenâs game. Players hide here and there, and one player called it tries to find all the other players. Now you played it and found all the players, so itâs turn to hide from it . Since you have got tired of running around for finding players, you donât want to play it again. So you are going to hide yourself at the place as far as possible from it . But where is that? Your task is to find the place and calculate the maximum possible distance from it to the place to hide. Input The input contains a number of test cases. The first line of each test case contains a positive integer N ( N †1000). The following N lines give the map where hide-and-seek is played. The map consists of N corridors . Each line contains four real numbers x 1 , y 1 , x 2 , and y 2 , where ( x 1 , y 1 ) and ( x 2 , y 2 ) indicate the two end points of the corridor. All corridors are straight, and their widths are negligible. After these N lines, there is a line containing two real numbers sx and sy , indicating the position of it . You can hide at an arbitrary place of any corridor, and it always walks along corridors. Numbers in the same line are separated by a single space. It is guaranteed that its starting position ( sx , sy ) is located on some corridor and linked to all corridors directly or indirectly. The end of the input is indicated by a line containing a single zero. Output For each test case, output a line containing the distance along the corridors from âitâs starting position to the farthest position. The value may contain an error less than or equal to 0.001. You may print any number of digits below the decimal point. Sample Input 2 0 0 3 3 0 4 3 1 1 1 0 Output for the Sample Input 4.243 | 37,287 |
Score : 1000 points Problem Statement You are given a tree with N vertices. The vertices are numbered 0 through N-1 , and the edges are numbered 1 through N-1 . Edge i connects Vertex x_i and y_i , and has a value a_i . You can perform the following operation any number of times: Choose a simple path and a non-negative integer x , then for each edge e that belongs to the path, change a_e by executing a_e â a_e â x (â denotes XOR). Your objective is to have a_e = 0 for all edges e . Find the minimum number of operations required to achieve it. Constraints 2 †N †10^5 0 †x_i,y_i †N-1 0 †a_i †15 The given graph is a tree. All input values are integers. Input Input is given from Standard Input in the following format: N x_1 y_1 a_1 x_2 y_2 a_2 : x_{N-1} y_{N-1} a_{N-1} Output Find the minimum number of operations required to achieve the objective. Sample Input 1 5 0 1 1 0 2 3 0 3 6 3 4 4 Sample Output 1 3 The objective can be achieved in three operations, as follows: First, choose the path connecting Vertex 1, 2 , and x = 1 . Then, choose the path connecting Vertex 2, 3 , and x = 2 . Lastly, choose the path connecting Vertex 0, 4 , and x = 4 . Sample Input 2 2 1 0 0 Sample Output 2 0 | 37,288 |
Score : 200 points Problem Statement We have N weights indexed 1 to N . The mass of the weight indexed i is W_i . We will divide these weights into two groups: the weights with indices not greater than T , and those with indices greater than T , for some integer 1 \leq T < N . Let S_1 be the sum of the masses of the weights in the former group, and S_2 be the sum of the masses of the weights in the latter group. Consider all possible such divisions and find the minimum possible absolute difference of S_1 and S_2 . Constraints 2 \leq N \leq 100 1 \leq W_i \leq 100 All values in input are integers. Input Input is given from Standard Input in the following format: N W_1 W_2 ... W_{N-1} W_N Output Print the minimum possible absolute difference of S_1 and S_2 . Sample Input 1 3 1 2 3 Sample Output 1 0 If T = 2 , S_1 = 1 + 2 = 3 and S_2 = 3 , with the absolute difference of 0 . Sample Input 2 4 1 3 1 1 Sample Output 2 2 If T = 2 , S_1 = 1 + 3 = 4 and S_2 = 1 + 1 = 2 , with the absolute difference of 2 . We cannot have a smaller absolute difference. Sample Input 3 8 27 23 76 2 3 5 62 52 Sample Output 3 2 | 37,289 |
Problem G: Walking Ant Ants are quite diligent. They sometimes build their nests beneath flagstones. Here, an ant is walking in a rectangular area tiled with square flagstones, seeking the only hole leading to her nest. The ant takes exactly one second to move from one flagstone to another. That is, if the ant is on the flagstone with coordinates ( x , y ) at time t , she will be on one of the five flagstones with the following coordinates at time t + 1: ( x , y ), ( x + 1, y ), ( x - 1, y ), ( x , y + 1), ( x , y - 1). The ant cannot go out of the rectangular area. The ant can visit the same flagstone more than once. Insects are easy to starve. The ant has to go back to her nest without starving. Physical strength of the ant is expressed by the unit "HP". Initially, the ant has the strength of 6 HP. Every second, she loses 1 HP. When the ant arrives at a flagstone with some food on it, she eats a small piece of the food there, and recovers her strength to the maximum value, i.e., 6 HP, without taking any time. The food is plenty enough, and she can eat it as many times as she wants. When the ant's strength gets down to 0 HP, she dies and will not move anymore. If the ant's strength gets down to 0 HP at the moment she moves to a flagstone, she does not effectively reach the flagstone: even if some food is on it, she cannot eat it; even if the hole is on that stone, she has to die at the entrance of her home. If there is a puddle on a flagstone, the ant cannot move there. Your job is to write a program which computes the minimum possible time for the ant to reach the hole with positive strength from her start position, if ever possible. Input The input consists of multiple maps, each representing the size and the arrangement of the rectangular area. A map is given in the following format. w h d 11 d 12 d 13 ... d 1 w d 2 d 22 d 23 ... d 2 w ... d h 1 d h 2 d h 3 ... d h w The integers w and h are the numbers of flagstones in the x - and y -directions, respectively. w and h are less than or equal to 8. The integer d yx represents the state of the flagstone with coordinates ( x , y ) as follows. 0: There is a puddle on the flagstone, and the ant cannot move there. 1, 2: Nothing exists on the flagstone, and the ant can move there. '2' indicates where the ant initially stands. 3: The hole to the nest is on the flagstone. 4: Some food is on the flagstone. There is one and only one flagstone with a hole. Not more than five flagstones have food on them. The end of the input is indicated by a line with two zeros. Integer numbers in an input line are separated by at least one space character. Output for each map in the input, your program should output one line containing one integer representing the minimum time. If the ant cannot return to her nest, your program should output -1 instead of the minimum time. Sample Input 3 3 2 1 1 1 1 0 1 1 3 8 4 2 1 1 0 1 1 1 0 1 0 4 1 1 0 4 1 1 0 0 0 0 0 0 1 1 1 1 4 1 1 1 3 8 5 1 2 1 1 1 1 1 4 1 0 0 0 1 0 0 1 1 4 1 0 1 1 0 1 1 0 0 0 0 3 0 1 1 1 4 1 1 1 1 1 0 0 Output for the Sample Input 4 -1 13 | 37,290 |
Share the Ruins Preservation Two organizations International Community for Preservation of Constructions (ICPC) and Japanese Archaeologist Group (JAG) engage in ruins preservation. Recently, many ruins were found in a certain zone. The two organizations decided to share the preservation of the ruins by assigning some of the ruins to ICPC and the other ruins to JAG. Now, ICPC and JAG make a rule for assignment as follows: Draw a vertical straight line from the north to the south, avoiding to intersect ruins. Ruins located to the west of the line are preserved by ICPC. On the other hand, ruins located to the east of the line are preserved by JAG. (It is possible that no ruins are located to the east/west of the line; in this case, ICPC/JAG will preserve no ruins.) A problem is where to draw a straight line. For each organization, the way to preserve its assigned ruins is to make exactly one fence such that all the assigned ruins are in the region surrounded by the fence. Furthermore, they should minimize the length of such a fence for their budget. If the surrounded areas are vast, expensive costs will be needed to maintain the inside of areas. Therefore, they want to minimize the total preservation cost, i.e. the sum of the areas surrounded by two fences. Your task is to write a program computing the minimum sum of the areas surrounded by two fences, yielded by drawing an appropriate straight line. Input The input consists of a single test case. $N$ $x_1$ $y_1$ $x_2$ $y_2$ ... $x_N$ $y_N$ The first line contains an integer $N$ ($1 \leq N \leq 100,000$), which is the number of founded ruins. The following $N$ lines represent the location of the ruins. The $i$-th line of them consists of two integers $x_i$ and $y_i$, which indicate the location of the $i$-th ruin is $x_i$ east and $y_i$ north from a certain location in the zone. You can assume the following things for the ruins: $-10^9 \leq x_i, y_i \leq 10^9$ You can ignore the sizes of ruins. That is, you can assume ruins are points. No pair of ruins has the same location. Output Print the minimum total preservation cost yielded by drawing an appropriate straight line. You should round off the cost to the nearest integer. Sample Input 1 8 -10 0 -10 5 -5 5 -5 0 10 0 10 -5 5 -5 5 0 Output for the Sample Input 1 50 Sample Input 2 5 0 0 0 1 0 2 1 0 1 1 Output for the Sample Input 2 0 Sample Input 3 6 1 5 1 6 0 5 0 -5 -1 -5 -1 -6 Output for the Sample Input 3 6 Sample Input 4 10 2 5 4 6 9 5 8 8 1 3 6 4 5 9 7 3 7 7 3 9 Output for the Sample Input 4 17 | 37,291 |
Activity Selection Problem There are $n$ acitivities with start times $\{s_i\}$ and finish times $\{t_i\}$. Assuming that a person can only work on a single activity at a time, find the maximum number of activities that can be performed by a single person. Input $n$ $s_1$ $t_1$ $s_2$ $t_2$ : $s_n$ $t_n$ The first line consists of the integer $n$. In the following $n$ lines, the start time $s_i$ and the finish time $t_i$ of the activity $i$ are given. åºå Print the maximum number of activities in a line. Constraints $1 \le n \le 10^5$ $1 \le s_i \lt t_i \le 10^9 (1 \le i \le n)$ Sample Input 1 5 1 2 3 9 3 5 5 9 6 8 Sample Output 1 3 Sample Input 2 3 1 5 3 4 2 5 Sample Output 2 1 Sample Input 3 3 1 2 2 3 3 4 Sample Output 3 2 | 37,292 |
Score: 400 points Problem Statement To become a millionaire, M-kun has decided to make money by trading in the next N days. Currently, he has 1000 yen and no stocks - only one kind of stock is issued in the country where he lives. He is famous across the country for his ability to foresee the future. He already knows that the price of one stock in the next N days will be as follows: A_1 yen on the 1 -st day, A_2 yen on the 2 -nd day, ..., A_N yen on the N -th day. In the i -th day, M-kun can make the following trade any number of times (possibly zero), within the amount of money and stocks that he has at the time . Buy stock: Pay A_i yen and receive one stock. Sell stock: Sell one stock for A_i yen. What is the maximum possible amount of money that M-kun can have in the end by trading optimally? Constraints 2 \leq N \leq 80 100 \leq A_i \leq 200 All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 A_2 \cdots A_N Output Print the maximum possible amount of money that M-kun can have in the end, as an integer. Sample Input 1 7 100 130 130 130 115 115 150 Sample Output 1 1685 In this sample input, M-kun has seven days of trading. One way to have 1685 yen in the end is as follows: Initially, he has 1000 yen and no stocks. Day 1 : Buy 10 stocks for 1000 yen. Now he has 0 yen. Day 2 : Sell 7 stocks for 910 yen. Now he has 910 yen. Day 3 : Sell 3 stocks for 390 yen. Now he has 1300 yen. Day 4 : Do nothing. Day 5 : Buy 1 stock for 115 yen. Now he has 1185 yen. Day 6 : Buy 10 stocks for 1150 yen. Now he has 35 yen. Day 7 : Sell 11 stocks for 1650 yen. Now he has 1685 yen. There is no way to have 1686 yen or more in the end, so the answer is 1685 . Sample Input 2 6 200 180 160 140 120 100 Sample Output 2 1000 In this sample input, it is optimal to do nothing throughout the six days, after which we will have 1000 yen. Sample Input 3 2 157 193 Sample Output 3 1216 In this sample input, it is optimal to buy 6 stocks in Day 1 and sell them in Day 2 , after which we will have 1216 yen. | 37,293 |
Score : 400 points Problem Statement On a planet far, far away, M languages are spoken. They are conveniently numbered 1 through M . For CODE FESTIVAL 20XX held on this planet, N participants gathered from all over the planet. The i -th (1âŠiâŠN) participant can speak K_i languages numbered L_{i,1}, L_{i,2}, ..., L_{i,{}K_i} . Two participants A and B can communicate with each other if and only if one of the following conditions is satisfied: There exists a language that both A and B can speak. There exists a participant X that both A and B can communicate with. Determine whether all N participants can communicate with all other participants. Constraints 2âŠNâŠ10^5 1âŠMâŠ10^5 1âŠK_iâŠM ( The sum of all K_i)âŠ10^5 1âŠL_{i,j}âŠM L_{i,1}, L_{i,2}, ..., L_{i,{}K_i} are pairwise distinct. Partial Score 200 points will be awarded for passing the test set satisfying the following: NâŠ1000 , MâŠ1000 and ( The sum of all K_i)âŠ1000 . Additional 200 points will be awarded for passing the test set without additional constraints. Input The input is given from Standard Input in the following format: N M K_1 L_{1,1} L_{1,2} ... L_{1,{}K_1} K_2 L_{2,1} L_{2,2} ... L_{2,{}K_2} : K_N L_{N,1} L_{N,2} ... L_{N,{}K_N} Output If all N participants can communicate with all other participants, print YES . Otherwise, print NO . Sample Input 1 4 6 3 1 2 3 2 4 2 2 4 6 1 6 Sample Output 1 YES Any two participants can communicate with each other, as follows: Participants 1 and 2 : both can speak language 2 . Participants 2 and 3 : both can speak language 4 . Participants 1 and 3 : both can communicate with participant 2 . Participants 3 and 4 : both can speak language 6 . Participants 2 and 4 : both can communicate with participant 3 . Participants 1 and 4 : both can communicate with participant 2 . Note that there can be languages spoken by no participant. Sample Input 2 4 4 2 1 2 2 1 2 1 3 2 4 3 Sample Output 2 NO For example, participants 1 and 3 cannot communicate with each other. | 37,294 |
Knapsack Problem You have N kinds of items that you want to put them into a knapsack. Item i has value v i and weight w i . You want to find a subset of items to put such that: The total value of the items is as large as possible. The items have combined weight at most W , that is capacity of the knapsack. You can select as many items as possible into a knapsack for each kind. Find the maximum total value of items in the knapsack. Input N W v 1 w 1 v 2 w 2 : v N w N The first line consists of the integers N and W . In the following lines, the value and weight of the i -th item are given. Output Print the maximum total values of the items in a line. Constraints 1 †N †100 1 †v i †1000 1 †w i †1000 1 †W †10000 Sample Input 1 4 8 4 2 5 2 2 1 8 3 Sample Output 1 21 Sample Input 2 2 20 5 9 4 10 Sample Output 2 10 Sample Input 3 3 9 2 1 3 1 5 2 Sample Output 3 27 | 37,295 |
Score : 600 points Problem Statement For a non-negative integer K , we define a fractal of level K as follows: A fractal of level 0 is a grid with just one white square. When K > 0 , a fractal of level K is a 3^K \times 3^K grid. If we divide this grid into nine 3^{K-1} \times 3^{K-1} subgrids: The central subgrid consists of only black squares. Each of the other eight subgrids is a fractal of level K-1 . For example, a fractal of level 2 is as follows: In a fractal of level 30 , let (r, c) denote the square at the r -th row from the top and the c -th column from the left. You are given Q quadruples of integers (a_i, b_i, c_i, d_i) . For each quadruple, find the distance from (a_i, b_i) to (c_i, d_i) . Here the distance from (a, b) to (c, d) is the minimum integer n that satisfies the following condition: There exists a sequence of white squares (x_0, y_0), \ldots, (x_n, y_n) satisfying the following conditions: (x_0, y_0) = (a, b) (x_n, y_n) = (c, d) For every i (0 \leq i \leq n-1) , (x_i, y_i) and (x_{i+1}, y_{i+1}) share a side. Constraints 1 \leq Q \leq 10000 1 \leq a_i, b_i, c_i, d_i \leq 3^{30} (a_i, b_i) \neq (c_i, d_i) (a_i, b_i) and (c_i, d_i) are white squares. All values in input are integers. Input Input is given from Standard Input in the following format: Q a_1 \ b_1 \ c_1 \ d_1 : a_Q \ b_Q \ c_Q \ d_Q Output Print Q lines. The i -th line should contain the distance from (a_i, b_i) to (c_i, d_i) . Sample Input 1 2 4 2 7 4 9 9 1 9 Sample Output 1 5 8 | 37,296 |
E: 28 å顿 ãã©ã³ãã²ãŒã ã®å€§å¯è±ªã«ãããŠïŒã©ã³ã¯ã $2$, $8$ ã®ã«ãŒãã¯åŒ·åã§ãïŒ ããã§ïŒ$10$ 鲿°è¡šèšã§æ°åã® $2$, $8$ ã®ã¿ãããªãæŽæ°ã è¯ãæŽæ° ãšåŒã¶ããšã«ããŸãïŒ è¯ãæŽæ°ãå°ãããã®ããåæãããš $2, 8, 22, 28, 82, 88, \cdots$ ãšãªããŸãïŒ $n$ ãæ£ã®æŽæ°ãšããŸãïŒ$n$ ãè¯ãæŽæ°ã®ç©ã®åœ¢ã§è¡šçŸã§ãããšãïŒ æå€§ã§ããã€ã®ç©ã«ãªããæ±ããŠãã ããïŒã§ããªããªã $-1$ ãšåºåããŠãã ããïŒ å
¥å $n$ å¶çŽ $1 \leq n \leq 10^{18}$ åºå çãã $1$ è¡ã§åºåããŠãã ããïŒ ãµã³ãã« ãµã³ãã«å
¥å1 1 ãµã³ãã«åºå1 -1 ãµã³ãã«å
¥å2 2 ãµã³ãã«åºå2 1 ãµã³ãã«å
¥å3 88 ãµã³ãã«åºå3 3 $2 \times 2 \times 22$ ãšè¡šããŸãïŒ ãµã³ãã«å
¥å4 100 ãµã³ãã«åºå4 -1 ãµã³ãã«å
¥å5 173553147234869248 ãµã³ãã«åºå5 11 $2^6 \times 28 \times 2222^3 \times 8828$ ãšè¡šããŸãïŒ | 37,297 |
芪æ¹ã®çµŠæèšç® ã¯ã·ã¯ãã€ãã€ãªãçµåã®èŠªæ¹ãããè·äººãå·¥äºçŸå Žã«æŽŸé£ããçŸå Žã§ãã€ããã€ãªãããŠãããå»å¹Žã¯å·¥äºãå¢ããŠå€§å²ãããããšæã£ãã®ããããã¡ãã£ãšçµŠæã®åºãæ¹ããŸãããŠã®ã
ããŠããšããŠã¯å€§èµ€åã«ãªã£ãŠããŸã£ãã®ãããâŠãããã§ãä»å¹Žã¯è·äººãã¡ãžã®çµŠæã®åºãæ¹ã工倫ãããã®ããã è·äººãã¡ã®çµŠæã¯ãå·¥äºã®çš®é¡ãšããªããåæ°ã§æ±ºããŠãããã€ãŸãã è·äººã®çµŠæ ïŒ çš®é¡ 1 ã®å䟡 Ã çš®é¡ 1 ãããªããåæ° + çš®é¡ 2 ã®å䟡 Ã çš®é¡ 2 ãããªããåæ° .... + çš®é¡ M ã®å䟡 Ã çš®é¡ M ãããªããåæ° ãšãªãã®ããããããèšç®ããããã«ããŠãã§ã¯ãã©ã®è·äººãã©ã®çš®é¡ã®å·¥äºãäœåããªããããæ¬¡ã®ãããªè¡šã«èšé²ããŠããã äŸãã°ãäžã®è¡šã§ã¯ãè·äººïŒãå·¥äºïŒãïŒåãå·¥äºïŒãïŒåããªããããšã瀺ããŠããã è·äººãã¡ãããªããä»äºã®åæ°ã¯ããå€ãããããããã€ãã¯å·¥äºã®å䟡ãç¥ããã®ã§ãå䟡ããããããšå€ããªããçã®äžæºãåºã¬ãã絊æã調æŽããããšæããŠãããããããã¯ã·ããããããããã°ã©ã ãä»ãã£ãŠåããªããŠã®ã
ãã¡ãã£ãšã¿ãŠãããããã //çç¥ int i, j; for ( i = 0; i < N; i++ ){ c[i] = 0; for ( j = 0; j < M; j++ ){ c[i] = c[i] + a[i][j]*b[j]; } } //çç¥ N ã¯è·äººã®æ°ã§ M ã¯å·¥äºã®çš®é¡ã®æ°ããã倿° a[i][j] ã«è·äººiãå·¥äº j ãããªããåæ°ãã b[j] ã«å·¥äº j ã®å䟡ããããŠã c[i] ã«è·äºº i ã®çµŠæãæ ŒçŽããŠãããåã£ãŠããã¯ããªã®ã«ããããšããããšãèšããïŒããããä»å¹Žã®çµŠæãè·äººãã¡ã«æããªããšãŸããã®ãããã»ã»ã»ã»ã»ãªããšããªãããã®ã
ã ããã§ã¯ãè·äººã®ããªããä»äºã®åæ°ãšåå·¥äºã®åäŸ¡ã®æ
å ±ãäžãããããšããåè·äººã®çµŠæãèšç®ããããã°ã©ã ãäœæããŠãã ããã å
¥å å
¥åã¯1ã€ã®ããŒã¿ã»ãããããªããå
¥åããŒã¿ã¯ä»¥äžã®åœ¢åŒã§äžããããã N M s 1 t 1 e 1 s 2 t 2 e 2 : 0 0 0 L b 11 b 12 ... b 1M b 21 b 22 ... b 2M : b L1 b L2 ... b LM 1è¡ç®ã¯è·äººã®æ° N (1 †N †10000)ãšå·¥äºã®çš®é¡ã®æ° M (1 †M †10000)ã ç¶ããŠãå·¥äºã®èšé²ãšããŠãè·äººã®çªå· s i (1 †s i †N ) ãšå·¥äºã®çš®é¡ã®çªå· t i (1 †t i †M )ãããã³è·äºº s i ãå·¥äº t i ãããªããåæ° e i (1 †e i †50000) ãããªãè¡ãïŒè¡ä»¥äžäžãããããå·¥äºã®èšé²ã¯ãŒãïŒã€ã®è¡ã§çµããããã ãã e i ã®åèšã¯ 1 ä»¥äž 50000 以äžã§ããããŸããå·¥äºã®èšé²ã«ã¯ãã©ã®è·äººãšå·¥äºã®çš®é¡ã®çµãïŒåºŠä»¥äžçŸããªããå·¥äºãããªããåæ°ã 0 ã§ããè·äººãšå·¥äºã®çš®é¡ã®çµã¯äžããããªãã ç¶ã 1 è¡ã¯çµŠæã®ç®åºãè¡ãåæ° L (1 †L †100) ã ç¶ã L è¡ã¯ã i åç®ã®çµŠæã®ç®åºã«å¿
èŠãªãå·¥äº j ã®å䟡 b ij (0 †b ij †10000) ã®äžŠã³ã åºå 以äžã®åœ¢åŒã§ã i åç®ã®çµŠæã®ç®åºã«ãã£ãŠåŸãããè·äºº j ã®çµŠæ c ij ãé çªã«åºåãããå絊æã®éã¯ç©ºçœïŒã€ã§åºåãã c 11 c 12 ... c 1N c 21 c 22 ... c 2N : c L1 c L2 ... c LN å
¥åºåäŸ å
¥åäŸ 4 6 1 2 1 2 3 2 2 4 3 3 1 5 4 2 4 4 3 2 4 6 10 0 0 0 3 1 3 2 4 0 10 6 5 4 3 2 1 5 1 1 5 5 1 åºåäŸ 3 16 5 116 5 17 30 38 1 17 25 16 | 37,299 |
Score : 100 points Problem Statement In your garden, there is a long and narrow flowerbed that stretches infinitely to the east. You have decided to plant N kinds of flowers in this empty flowerbed. For convenience, we will call these N kinds of flowers Flower 1, 2, âŠ, N . Also, we will call the position that is p centimeters from the west end of the flowerbed Position p . You will plant Flower i (1 †i †N) as follows: first, plant one at Position w_i , then plant one every d_i centimeters endlessly toward the east. That is, Flower i will be planted at the positions w_i, w_i + d_i, w_i + 2 d_i, ⊠Note that more than one flower may be planted at the same position. Find the position at which the K -th flower from the west is planted. If more than one flower is planted at the same position, they are counted individually. Constraints 1 †N †10^5 1 †K †10^9 1 †w_i †10^{18} 1 †d_i †10^9 All input values are integers. Input Input is given from Standard Input in the following format: N K w_1 d_1 : w_N d_N Output When the K -th flower from the west is planted at Position X , print the value of X . (The westmost flower is counted as the 1 -st flower.) Sample Input 1 2 6 20 10 25 15 Sample Output 1 50 Two kinds of flowers are planted at the following positions: Flower 1 : Position 20, 30, 40, 50, 60, ⊠Flower 2 : Position 25, 40, 55, 70, 85, ⊠The sixth flower from the west is the Flower 1 planted at Position 50 . Note that the two flowers planted at Position 40 are counted individually. Sample Input 2 3 9 10 10 10 10 10 10 Sample Output 2 30 Three flowers are planted at each of the positions 10, 20, 30, ⊠Thus, the ninth flower from the west is planted at Position 30 . Sample Input 3 1 1000000000 1000000000000000000 1000000000 Sample Output 3 1999999999000000000 | 37,300 |
Score : 300 points Problem Statement There is a grid with H rows and W columns, where each square is painted black or white. You are given H strings S_1, S_2, ..., S_H , each of length W . If the square at the i -th row from the top and the j -th column from the left is painted black, the j -th character in the string S_i is # ; if that square is painted white, the j -th character in the string S_i is . . Find the number of pairs of a black square c_1 and a white square c_2 that satisfy the following condition: There is a path from the square c_1 to the square c_2 where we repeatedly move to a vertically or horizontally adjacent square through an alternating sequence of black and white squares: black, white, black, white... Constraints 1 \leq H, W \leq 400 |S_i| = W ( 1 \leq i \leq H ) For each i ( 1 \leq i \leq H ), the string S_i consists of characters # and . . Input Input is given from Standard Input in the following format: H W S_1 S_2 : S_H Output Print the answer. Sample Input 1 3 3 .#. ..# #.. Sample Output 1 10 Some of the pairs satisfying the condition are ((1, 2), (3, 3)) and ((3, 1), (3, 2)) , where (i, j) denotes the square at the i -th row from the top and the j -th column from the left. Sample Input 2 2 4 .... .... Sample Output 2 0 Sample Input 3 4 3 ### ### ... ### Sample Output 3 6 | 37,301 |
Problem E: HullMarathon ãããã¯ãã«ãã©ãœã³ãšããç«¶æã奜ãã§ãã. ãã®ç«¶æã¯ããŒã ã§è¡ã. ããŒã ã¡ã³ããŒã¯ç«¶æéå§åã«åç¹ã«éãŸã. ç«¶æéå§ãšåæã«èµ°ãåºã, 1 ååŸã«ç«ã¡æ¢ãŸãïŒãã®ãšãïŒããŒã ã¡ã³ããŒã®äœçœ®ã®åžå
ã®é¢ç©ãæã倧ããªããŒã ãåã¡ãšãªã. ããªã㯠$N$ å¹ã®ããããããªãããŒã ã®ç£ç£ã§ãã. $i$ å¹ç®ã®ããã㯠1 åã§ $r_i$ ç§»åããããšãã§ãã. ãã®ããŒã ãæé©ãªæŠç¥ããšã£ãå Žåã®, 1 ååŸã®åžå
ã®é¢ç©ã®æå€§å€ãæ±ãã. Constraints $N$ will be between 3 and 8, inclusive. $r_i$ will be an integer between 1 and 1,000, inclusive. Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžãããã: $N$ $r_1$ ... $r_N$ Output åžå
ã®é¢ç©ã®æå€§å€ã衚ã宿°ã 1 è¡ã«åºåãã. å°æ°ç¹ä»¥äžäœæ¡åºåããŠãããã, 絶察誀差ãŸãã¯çžå¯Ÿèª€å·®ã $10^{-6}$ 以äžã®ãšã Accepted ã«ãªã. Sample Input 1 4 5 8 58 85 Sample Output 1 2970.000000000 Sample Input 2 6 1 1 1 1 1 1 Sample Output 2 2.598076211 | 37,302 |
ããŒã åé¡ ããªãã¯ä»¥äžã®ã«ãŒã«ã§ããŒãã²ãŒã ãããããšã«ãªã£ã. ããªãã¯,ç¢ãç(ãŸãš)ã«åãã£ãŠ 4 æ¬ãŸã§æããããšãã§ãã.å¿
ããã 4 æ¬å
šãŠãæããå¿
èŠã¯ãªã,1 æ¬ãæããªããŠãããŸããªã.ç㯠N åã®éšåã«åºåãããŠããŠ,åã
ã®éšåã«ç¹æ° P 1 ,..., P N ãæžã ããŠãã.ç¢ãåºãã£ãå Žæã®ç¹æ°ã®åèš S ãããªãã®åŸç¹ã®åºç€ãšãªã.S ããããããæ±ºããããããç¹æ° M 以äžã®å Žå㯠S ããã®ãŸãŸããªãã®åŸç¹ãšãªã.ããã,S ã M ãè¶
ããå Žåã¯ããªãã®åŸç¹ã¯ 0 ç¹ãšãªã. çã«æžãããŠããç¹æ°ãš M ã®å€ãäžãããããšã,ããªããåŸãããšã®ã§ããç¹æ°ã®æå€§å€ãæ±ããããã°ã©ã ãäœæãã. å
¥å å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ 1 è¡ç®ã«ã¯,æŽæ° N (1 †N †1000) ãš M (1 †M †200000000 = 2 à 10 8 )ããã®é ã«ç©ºçœåºåãã§æžãããŠãã.2 è¡ç®ä»¥éã®ç¬¬ 1 + i è¡ç® (1 †i †N ) ã«ã¯, P i (1 †P i †100000000 = 10 8 ) ãæžãããŠãã. æ¡ç¹çšããŒã¿ã®ãã¡, é
ç¹ã® 20% å㯠N †100 ãæºãã,é
ç¹ã® 50% åã¯N †300 ãæºãã. N, M ããšãã« 0 ã®ãšãå
¥åã®çµäºã瀺ã. ããŒã¿ã»ããã®æ°ã¯ 10 ãè¶
ããªãïŒ åºå ããŒã¿ã»ããããšã«ããªããåŸãããšã®ã§ããç¹æ°ã®æå€§å€ãïŒè¡ã«åºåãã. å
¥åºåäŸ å
¥åäŸ 4 50 3 14 15 9 3 21 16 11 2 0 0 åºåäŸ 48 20 1ã€ç®ã®äŸã§ã¯,15 ç¹ã®éšåã« 3 æ¬,3 ç¹ã®éšåã« 1 æ¬ã®ç¢ãåºãã£ãå Žåã«ããªãã®åŸç¹ã¯æå€§ã«ãªã,ãã®åŸç¹ã¯ 48 ç¹ã§ãã. 2ã€ç®ã®äŸã§ã¯,16 ç¹ã®å Žæã« 1 æ¬,2 ç¹ã®å Žæã« 2 æ¬ã®ç¢ãåºãã£ãå Žåã«ããªãã®åŸç¹ã¯æå€§ã«ãªã,ãã®åŸç¹ã¯ 20 ç¹ã§ãã. äžèšå顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã | 37,303 |
Bichrome Tree Connectivity æšãäžããããŸãã ã¯ããããã¹ãŠã®é ç¹ã¯çœãã§ãã çœãé ç¹ã®è²ãå転ãããšé»ã«ãªããé»ãé ç¹ã®è²ãå転ãããšçœã«ãªããŸãã äºçš®é¡ã®ã¯ãšãªãåŠçããŠãã ããã äžçš®é¡ç®ã®ã¯ãšãªã§ã¯ãé ç¹ v ã®è²ãå転ããŸãã äºçš®é¡ç®ã®ã¯ãšãªã§ã¯ãçœãé ç¹ v ããçœãé ç¹ãšããããçµã¶èŸºã ãã䜿ã£ãŠãã©ãçããé ç¹ã®åæ°ãçããŸãã å
¥å N Q a_1 b_1 a_2 b_2 : a_{n-1} b_{n-1} t_1 v_1 t_2 v_2 : t_q v_q t_i ã 1 ã®ãšãäžçš®é¡ç®ã®ã¯ãšãªã 2 ã®ãšãäºçš®é¡ç®ã®ã¯ãšãªã§ããããšã衚ãã åºå ans_1 ans_2 : ans_k äºçš®é¡ç®ã®ã¯ãšãªã«å¯Ÿããçããé ã«åºåããã å¶çŽ 1 \leq N,Q \leq 10^5 1 \leq a_i,b_i \leq N 1 \leq t_i \leq 2 1 \leq v_i \leq N äžããããã°ã©ãã¯æšã§ããã t_i=2 ã®ãšããé ç¹ v_i ã¯å¿
ãçœã§ããã å
¥åäŸ 10 3 1 2 2 5 2 6 1 4 1 3 3 7 3 8 3 9 9 10 1 3 2 1 2 8 åºåäŸ 5 1 | 37,304 |
Digit Number Write a program which computes the digit number of sum of two integers a and b . Input There are several test cases. Each test case consists of two non-negative integers a and b which are separeted by a space in a line. The input terminates with EOF. Constraints 0 †a , b †1,000,000 The number of datasets †200 Output Print the number of digits of a + b for each data set. Sample Input 5 7 1 99 1000 999 Output for the Sample Input 2 3 4 | 37,305 |
Problem J: Castle Wall A new lord assumed the position by the death of the previous lord in a Far Eastern province. The new greedy lord hates concave polygons, because he believes they need much wasted area to be drawn on paper. He always wants to modify them to convex ones. His castle is currently surrounded by a wall forming a concave polygon, when seen from the above. Of course he hates it. He believes more area could be obtained with a wall of a convex polygon. Thus he has ordered his vassals to have new walls built so they form a convex polygon. Unfortunately, there is a limit in the budget. So it might be infeasible to have the new walls built completely. The vassals has found out that only up to r meters of walls in total can be built within the budget. In addition, the new walls must be built in such a way they connect the polygonal vertices of the present castle wall. It is impossible to build both of intersecting walls. After long persuasion of the vassals, the new lord has reluctantly accepted that the new walls might not be built completely. However, the vassals still want to maximize the area enclosed with the present and new castle walls, so they can satisfy the lord as much as possible. Your job is to write a program to calculate, for a given integer r , the maximum possible area of the castle with the new walls. Input The input file contains several test cases. Each case begins with a line containing two positive integers n and r . n is the number of vertices of the concave polygon that describes the present castle wall, satisfying 5 †n †64. r is the maximum total length of new castle walls feasible within the budget, satisfying 0 †r †400. The subsequent n lines are the x - and y -coordinates of the n vertices. The line segments ( x i , y i ) - ( x i +1 , y i +1 ) (1 †i †n - 1) and ( x n , y n ) - ( x 1 , y 1 ) form the present castle wall of the concave polygon. Those coordinates are given in meters and in the counterclockwise order of the vertices. All coordinate values are integers between 0 and 100, inclusive. You can assume that the concave polygon is simple, that is, the present castle wall never crosses or touches itself. The last test case is followed by a line containing two zeros. Output For each test case in the input, print the case number (beginning with 1) and the maximum possible area enclosed with the present and new castle walls. The area should be printed with exactly one fractional digit. Sample Input 5 4 0 0 4 0 4 4 2 2 0 4 8 80 45 41 70 31 86 61 72 64 80 79 40 80 8 94 28 22 0 0 Output for the Sample Input case 1: 16.0 case 2: 3375.0 | 37,306 |
Score : 2000 points Problem Statement For each of the K^{NM} ways to write an integer between 1 and K (inclusive) in every square in a square grid with N rows and M columns, find the value defined below, then compute the sum of all those K^{NM} values, modulo D . For each of the NM squares, find the minimum among the N+M-1 integers written in the square's row or the square's column. The value defined for the grid is the product of all these NM values. Constraints 1 \leq N,M,K \leq 100 10^8 \leq D \leq 10^9 N,M,K, and D are integers. D is prime. Input Input is given from Standard Input in the following format: N M K D Output Print the sum of the K^{NM} values, modulo D . Sample Input 1 2 2 2 998244353 Sample Output 1 35 We have 1 way to write integers such that the product of the NM values is 16 , 4 ways such that the product is 2 , and 11 ways such that the product is 1 . Sample Input 2 2 3 4 998244353 Sample Output 2 127090 Sample Input 3 31 41 59 998244353 Sample Output 3 827794103 | 37,307 |
Score : 700 points Problem Statement Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. Iroha is looking for X,Y,Z -Haiku (defined below) in integer sequences. Consider all integer sequences of length N whose elements are between 1 and 10 , inclusive. Out of those 10^N sequences, how many contain an X,Y,Z -Haiku? Here, an integer sequence a_0, a_1, ..., a_{N-1} is said to contain an X,Y,Z -Haiku if and only if there exist four indices x, y, z, w (0 ⊠x < y < z < w ⊠N) such that all of the following are satisfied: a_x + a_{x+1} + ... + a_{y-1} = X a_y + a_{y+1} + ... + a_{z-1} = Y a_z + a_{z+1} + ... + a_{w-1} = Z Since the answer can be extremely large, print the number modulo 10^9+7 . Constraints 3 ⊠N ⊠40 1 ⊠X ⊠5 1 ⊠Y ⊠7 1 ⊠Z ⊠5 Input The input is given from Standard Input in the following format: N X Y Z Output Print the number of the sequences that contain an X,Y,Z -Haiku, modulo 10^9+7 . Sample Input 1 3 5 7 5 Sample Output 1 1 Here, the only sequence that contains a 5,7,5 -Haiku is [5, 7, 5] . Sample Input 2 4 5 7 5 Sample Output 2 34 Sample Input 3 37 4 2 3 Sample Output 3 863912418 Sample Input 4 40 5 7 5 Sample Output 4 562805100 | 37,308 |
Score : 1300 points Problem Statement This is an interactive task. AtCoDeer the deer came across N people. For convenience, the people are numbered 0 through N-1 . Among them, A are honest and the remaining B(=N-A) are unkind . All of these N people know who are honest and who are unkind, but AtCoDeer only knows that there are A honest and B unkind people. He is trying to identify all of the honest people by asking questions to these N people. For one question, AtCoDeer selects a and b (0â€a,bâ€N-1) , and asks person a the following question: "Is person b honest?" An honest person will always answer correctly by "Yes" or "No". An unkind person, however, will answer by selecting "Yes" or "No" arbitrarily . That is, the algorithm used by an unkind person may not be simple one such as always lying or giving random fifty-fifty answers. AtCoDeer can ask at most 2N questions. He will ask questions one by one, and the responses to the previous questions can be used when deciding the next question to ask. Identify all of the honest people. If it is impossible (more formally, if, for any strategy of asking 2N questions, there exists a strategy for unkind people to answer the questions so that there are two or more possible sets of the honest people), report that fact. Constraints 1â€A,Bâ€2000 Input and Output First, A and B are given from Standard Input in the following format: A B If identifying the honest people is impossible, the program must immediately print the following output and terminate itself: Impossible Otherwise, the program shall ask questions. Each question must be written to Standard Output in the following format: ? a b Here, a and b must be integers between 0 and N-1 (inclusive). The response to the question will be given from Standard Input in the following format: ans Here, ans is either Y or N . Y represents "Yes"; N represents "No". Finally, the answer must be written to Standard Output in the following format: ! s_0s_1...s_{N-1} Here, s_i must be 1 if person i is honest, and 0 if person i is unkind. Judgement After each output, you must flush Standard Output. Otherwise you may get TLE . After you print the answer, the program must be terminated immediately. Otherwise, the behavior of the judge is undefined. When your output is invalid or incorrect, the behavior of the judge is undefined (it does not necessarily give WA ). Samples In the following sample, A = 2 , B = 1 , and the answer is 101 . Input Output 2 1 ? 0 1 N ? 0 2 Y ? 1 0 Y ? 2 0 Y ? 2 2 Y ! 101 In the following sample, A = 1 , B = 2 , and the answer is Impossible . Input Output 1 2 Impossible | 37,309 |
Problem H: ASCII Expression Mathematical expressions appearing in old papers and old technical articles are printed with typewriter in several lines, where a fixed-width or monospaced font is required to print characters (digits, symbols and spaces). Let us consider the following mathematical expression. It is printed in the following four lines: 4 2 ( 1 - ---- ) * - 5 + 6 2 3 where â- 5â indicates unary minus followed by 5. We call such an expression of lines âASCII expressionâ. For helping those who want to evaluate ASCII expressions obtained through optical character recognition (OCR) from old papers, your job is to write a program that recognizes the structure of ASCII expressions and computes their values. For the sake of simplicity, you may assume that ASCII expressions are constructed by the following rules. Its syntax is shown in Table H.1. (1) Terminal symbols are â 0 â, â 1 â, â 2 â, â 3 â, â 4 â, â 5 â, â 6 â, â 7 â, â 8 â, â 9 â, â + â, â - â, â * â, â ( â, â ) â, and â â. (2) Nonterminal symbols are expr , term , factor , powexpr , primary , fraction and digit . The start symbol is expr . (3) A âcellâ is a rectangular region of characters that corresponds to a terminal or nonterminal symbol (Figure H.1). In the cell, there are no redundant rows and columns that consist only of space characters. A cell corresponding to a terminal symbol consists of a single character. A cell corresponding to a nonterminal symbol contains cell(s) corresponding to its descendant(s) but never partially overlaps others. (4) Each cell has a base-line, a top-line, and a bottom-line. The base-lines of child cells of the right-hand side of rules I, II, III, and V should be aligned. Their vertical position defines the base-line position of their left-hand side cell. Table H.1: Rules for constructing ASCII expressions (similar to Backus-Naur Form) The box indicates the cell of the terminal or nonterminal symbol that corresponds to a rectan- gular region of characters. Note that each syntactically-needed space character is explicitly indicated by the period character denoted by, here. (5) powexpr consists of a primary and an optional digit . The digit is placed one line above the base-line of the primary cell. They are horizontally adjacent to each other. The base-line of a powexpr is that of the primary . (6) fraction is indicated by three or more consecutive hyphens called âvinculumâ. Its dividend expr is placed just above the vinculum, and its divisor expr is placed just beneath it. The number of the hyphens of the vinculum, denoted by w h , is equal to 2 + max( w 1 , w 2 ), where w 1 and w 2 indicate the width of the cell of the dividend and that of the divisor, respectively. These cells are centered, where there are â( w h â w k )/2â space characters to the left and â( w h â w k )/2â space characters to the right, ( k = 1, 2). The base-line of a fraction is at the position of the vinculum. (7) digit consists of one character. For example, the negative fraction is represented in three lines: 3 - --- 4 where the left-most hyphen means a unary minus operator. One space character is required between the unary minus and the vinculum of the fraction. The fraction is represented in four lines: 3 + 4 * - 2 ------------- 2 - 1 - 2 where the widths of the cells of the dividend and divisor are 11 and 8 respectively. Hence the number of hyphens of the vinculum is 2 + max(11, 8) = 13. The divisor is centered by â(13â8)/2â = 3 space characters (hyphens) to the left and â(13â8)/2â = 2 to the right. The powexpr (4 2 ) 3 is represented in two lines: 2 3 ( 4 ) where the cell for 2 is placed one line above the base-line of the cell for 4, and the cell for 3 is placed one line above the base-line of the cell for a primary (4 2 ). Input The input consists of multiple datasets, followed by a line containing a zero. Each dataset has the following format. n str 1 str 2 . . . str n n is a positive integer, which indicates the number of the following lines with the same length that represent the cell of an ASCII expression. str k is the k -th line of the cell where each space character is replaced with a period. You may assume that n †20 and that the length of the lines is no more than 80. Output For each dataset, one line containing a non-negative integer less than 2011 should be output. The integer indicates the value of the ASCII expression in modular arithmetic under modulo 2011. The output should not contain any other characters. There is no fraction with the divisor that is equal to zero or a multiple of 2011. Note that powexpr x 0 is defined as 1, and x y (y is a positive integer) is defined as the product xÃxà ...à x where the number of x 's is equal to y . A fraction is computed as the multiplication of x and the inverse of y , i.e., x à inv( y ), under y modulo 2011. The inverse of y (1 †y < 2011) is uniquely defined as the integer z (1 †z < 2011) that satisfies z à y â¡ 1 (mod 2011), since 2011 is a prime number. Sample Input 4 ........4...2.......... (.1.-.----.)..*.-.5.+.6 ........2.............. .......3............... 3 ...3. -.--- ...4. 4 .3.+.4.*.-.2. ------------- ..........2.. ...-.1.-.2... 2 ...2..3 (.4..). 1 2.+.3.*.5.-.7.+.9 1 (.2.+.3.).*.(.5.-.7.).+.9 3 .2....3. 4..+.--- ......5. 3 .2......-.-.3. 4..-.-.------- ..........5... 9 ............1............ ------------------------- ..............1.......... .1.+.-------------------. ................1........ ......1.+.-------------.. ..................1...... ...........1.+.-------... ................1.+.2.... 15 .................2...... ................---..... .......2.........5....3. .(.---------.+.-----.).. .....7...........3...... ....---.+.1............. .....4.................. ------------------------ .......2................ ......---............... .......5.......2....2... ...(.-----.+.-----.).... .......3.......3........ ..............---....... ...............4........ 2 .0....2.... 3..+.4..*.5 20 ............2............................2...................................... ...........3............................3....................................... ..........----.........................----..................................... ............4............................4...................................... .....2.+.------.+.1...............2.+.------.+.1................................ ............2............................2...................................... ...........2............................2........................2.............. ..........----.........................----.....................3............... ............2............................2.....................----............. ...........3............................3........................4.............. (.(.----------------.+.2.+.3.).*.----------------.+.2.).*.2.+.------.+.1.+.2.*.5 ............2............................2.......................2.............. ...........5............................5.......................2............... ..........----.........................----....................----............. ............6............................6.......................2.............. .........------.......................------....................3............... ............3............................3...................................... ..........----.........................----..................................... ............2............................2...................................... ...........7............................7....................................... 0 Output for the Sample Input 501 502 1 74 19 2010 821 821 1646 148 81 1933 | 37,310 |
A: Grid Mori / ã°ãªããæ£® ãšããå¯è±ªã®æ£®ãããïŒã°ãªããç¶ã«åºåããããåå°ã® n åºç»ãè²·ã£ãŠïŒ 4ã€ã®å·¥å Ž A, B, C, D ã建ãŠãããšããŠããïŒ ãŸãïŒåå°å
šäœã®å¹
w ã1ä»¥äž n 以äžã®å€ã§æ±ºå®ããïŒ ãã®åå°ã® 1 çªå·Šäžã®åºç»ã (0, 0) ãšããïŒ ãããŠïŒ (0, 0) ã®åºç»ã1çªç®ã«ïŒ (1, 0) ã®åºç»ã2çªç®ã«è³Œå
¥ããïŒ ãã®ããã«ïŒ i çªç®ã« ( x , y ) ã®åºç»ã賌å
¥ããåŸã«ïŒ i + 1 çªç®ã« ( x + 1, y ) ã®åºç»ã賌å
¥ããŠããïŒ ããïŒ ( w , y ) ã®åºç»ã賌å
¥ããããšãããšãã¯ïŒ 代ããã« (0, y + 1) ã®åºç»ã賌å
¥ããïŒ ããã«æ£®ããã¯ïŒåå°ã賌å
¥ããåã«å ãåž«ã«æ¬¡ã®ãããªããšãèšãããŠããïŒ ã a çªç®ã«è³Œå
¥ããã°ãªããã®åå°ã«å·¥å ŽAãïŒ b çªç®ã«è³Œå
¥ããã°ãªããã«å·¥å ŽBãïŒ c çªç®ã®ã°ãªããã«å·¥å ŽCãïŒ d çªç®ã®ã°ãªããã«å·¥å ŽDã建ãŠããšãããïŒã 森ããã¯ïŒéåžžã«å ã奜ãã§ããïŒå¿
ãå ãåž«ã®å©èšãå®ããããšèããŠããïŒ ãããïŒAãšBïŒCãšDã®2ã€ã®ãã¢ã¯é¢é£ã®ããå·¥å Žã§ããããïŒã§ããã ãè¿ãã«ãã£ãæ¹ãããïŒ èªåã®åå°ã®è²·ãæ¹ãšå ãåž«ã®å©èšãäž¡æ¹å®ãã€ã€ïŒé¢é£ããå·¥å Žå士ããªãã¹ãè¿ããããã®ã§ããïŒ ããã§ïŒ2ã€ã®åå°ã ( x 1 , y 1 )ïŒ( x 2 , y 2 ) ã«ãããšãïŒ è·é¢ã¯ïŒ| x 1 - x 2 |+ | y 1 - y 2 | ã§æ±ããããšãã§ããïŒ | x | ã¯ïŒ x ã®çµ¶å¯Ÿå€ã衚ããŠããïŒ ããªãã®ä»äºã¯ïŒ (å·¥å ŽAãšBã®è·é¢) ïŒ (å·¥å ŽCãšDã®è·é¢) ã®å€ãæå°ã«ãªãããã«åå°ã賌å
¥ãããšãã®è·é¢ã®åèšãæ±ããããã°ã©ã ãäœæããããšã§ããïŒ å³1ã¯ãµã³ãã«ã®1çªç®ã«ãããïŒãã¹ãŠã®å·¥å Žã®é
眮ã®çµã¿åããã§ããïŒå¹
3ã§åå°ã賌å
¥ãããšãïŒè·é¢ã®åèšãæå°ãšãªãïŒ å³1: ãµã³ãã«1ã®å·¥å Žã®é
眮 Input å
¥åã¯æ¬¡ã®åœ¢åŒã§è¡šãããïŒ n a b c d å
¥åã¯ïŒå
šãп޿°å€ã§ããïŒ n (4 ⊠n ⊠100) ã¯ãããã賌å
¥ããåå°ã®ã°ãªããæ°ã衚ãïŒ a , b , c , d (1 ⊠a , b , c , d ⊠n ) ã¯ïŒããããå·¥å ŽA, B, C, Dãäœçªç®ã«è³Œå
¥ããã°ãªããã®åå°ã«å»ºãŠããã衚ãïŒ ãã®ãšãïŒ a , b , c , d ã¯å
šãŠïŒç°ãªãæ°ãå
¥åãããïŒ Output 森ãããïŒ a, b éãš c, d éã®è·é¢ã®åèšãæå°ãšãªãããã«åå°ã賌å
¥ãããšãã®åèšå€ã1è¡ã§åºåããïŒ Sample Input 1 5 1 4 2 5 Sample Output 1 2 Sample Input 2 16 2 9 14 8 Sample Output 2 3 | 37,311 |
Problem D: åäœå€æåš åœéåäœç³»(SI)ã§ã¯ãkilo, mega, giga ãªã©ã®æ¥é èŸã䜿ã£ãŠããæ°å€ + æ¥é èŸ + åäœããšãã圢ã§ããŸããŸãªç©çéã衚èšãããããšãã°ãã3.5 kilometersã, ã5.1 milligramsã ãšãã£ãå
·åã§ããã äžæ¹ããããã®ç©çéã¯ææ°è¡šèšã䜿ã£ãŠã3.5 * 10^3 metersããã5.1 * 10^-3 gramsãã®ããã«è¡šãããšãå¯èœã§ããã ç©çéã®æž¬å®ã¯å¿
ã誀差ãå«ããããã§ã枬å®ãããç©çéãã©ãã ãã®ç²ŸåºŠãæã€ãã衚ãããã«ãæå¹æ°åãšããæŠå¿µããããæå¹æ°åãèæ
®ãã衚èšã§ã¯ãæåŸã®æ¡ã¯èª€å·®ãå«ã¿ãããããã以å€ã®æ¡ã¯ä¿¡é Œã§ãããã®ãšèãããããšãã°ãã1.23ã ãšè¡šèšããå Žåãçã®å€ã¯ 1.225 ä»¥äž 1.235 æªæºã§ãããå°æ°ç¬¬1äœä»¥äžã®æ¡ã¯ä¿¡é Œã§ããããå°æ°ç¬¬2äœã«ã¯èª€å·®ãå«ãããã®ããã«ãä¿¡é Œã§ããæ¡ + 誀差ãå«ã1æ¡ããšãã圢ã§ç©çéã衚ãããšãã®æ¡æ°ãæå¹æ¡æ°ãšåŒã¶ãããšãã°ãã1.23ãã®æå¹æ¡æ°ã¯3æ¡ã§ããã 0ã§ãªãæäžäœã®æ¡ããåã«0ãããå Žåããã®0ã¯æå¹æ¡æ°ã«ã¯å«ããªããããšãã°ãã0.45ãã®æå¹æ¡æ°ã¯2æ¡ã§ããã 0ã§ãªãæäžäœã®æ¡ããåŸã«0ãããå Žåããã®0ãæå¹æ¡æ°ã«å«ããã©ããã¯å°æ°ç¹ã®äœçœ®ã«ããç°ãªããå°æ°ç¹ããå³ãŸã§0ããããšãã¯ããã®0ã¯æå¹æ¡æ°ã«å«ãããããšãã°ãã12.300ãã®æå¹æ¡æ°ã¯5æ¡ã§ãããäžæ¹ãã12300ãã®ããã«ãå°æ°ç¹ããå³ã«0ããªããšãã¯ãå³åŽã®0ãæå¹æ¡æ°ã«å«ãããã©ããã¯æç¢ºã§ã¯ãªããããã®åé¡ã«ãããŠã¯å«ããããšãšãããããªãã¡ãã12300ãã®æå¹æ¡æ°ã¯5æ¡ã§ããã ãªã€ãã¯åŠæ ¡ã®èª²é¡ã§ç©çã®åé¡ãåºãããããã®äžã§æå¹æ°åãåäœãé¢ããèšç®ãããªããã°ãªããªãã®ã ããå°ã£ãããšã«ãªã€ãã«ã¯æå¹æ°åãåäœã®äœ¿ãæ¹ããŸã ããããã£ãŠããªããããã§ãèªåã§ãããã®èšç®ãããããã°ã©ã ãäœã£ãŠããªã€ããå©ããŠãããŠã»ããã ããªããæžãã®ã¯ãæ¥é èŸã䜿ã£ã衚èšãäžãããããšãããããæå¹æ¡æ°ãçããææ°è¡šèšã«å€æããããã°ã©ã ã§ããã䜿ãããæ¥é èŸã¯ä»¥äžã®20åã§ããã yotta = 10^24 zetta = 10^21 exa = 10^18 peta = 10^15 tera = 10^12 giga = 10^9 mega = 10^6 kilo = 10^3 hecto = 10^2 deca = 10^1 deci = 10^-1 centi = 10^-2 milli = 10^-3 micro = 10^-6 nano = 10^-9 pico = 10^-12 femto = 10^-15 ato = 10^-18 zepto = 10^-21 yocto = 10^-24 Input å
¥åã¯1è¡ã®ã¿ãããªãããã®å¯äžã®è¡ã«ã¯ãæ°å€ãïŒããããã°ïŒåäœæ¥é èŸãåäœãå«ãŸããŠãããããããã®éã¯ç©ºçœ1åã§åºåãããŠãããåäœæ¥é èŸããªãå Žåãããããã®å Žåã¯æ°å€ãšåäœã®ã¿ãè¡ã«å«ãŸãããåäœæ¥é èŸãšåãååã®åäœã¯çŸããªããå°æ°ãäžããããå Žåã®1ã®äœãé€ããæäžäœã®æ¡ã0ã«ãªãããšã¯ãªããäžããããæ°å€ã¯æ£ã§ãããäžããããæ°å€ã¯å°æ°ç¹ãå«ã1000æ¡ä»¥äžã§ãåäœã®ååã¯50æå以äžã§ããã Output a * 10^ b [åäœ] ã®åœ¢ã§ææ°è¡šèšã§è¡šçŸãããéãåºåããããã ãã1 <= a < 10 ã§ãããåäœåã®åæ°åœ¢ã»è€æ°åœ¢ã®éãã¯èæ
®ããªããå
¥åã«äžããããåäœåããã®ãŸãŸåºåããã Notes on Submission äžèšåœ¢åŒã§è€æ°ã®ããŒã¿ã»ãããäžããããŸããå
¥åããŒã¿ã® 1 è¡ç®ã«ããŒã¿ã»ããã®æ°ãäžããããŸããåããŒã¿ã»ããã«å¯Ÿããåºåãäžèšåœ¢åŒã§é çªã«åºåããããã°ã©ã ãäœæããŠäžããã Sample Input 7 12.3 kilo meters 0.45 mega watts 0.000000000000000000000001 yotta grams 1000000000000000000000000 yocto seconds 42 amperes 0.42 joules 1234.56789012345678901234567890 hecto pascals Output for the Sample Input 1.23 * 10^4 meters 4.5 * 10^5 watts 1 * 10^0 grams 1.000000000000000000000000 * 10^0 seconds 4.2 * 10^1 amperes 4.2 * 10^-1 joules 1.23456789012345678901234567890 * 10^5 pascals | 37,312 |
Score : 400 points Problem Statement The ABC number of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: 1 †i < j < k †|T| ( |T| is the length of T .) T_i = A ( T_i is the i -th character of T from the beginning.) T_j = B T_k = C For example, when T = ABCBC , there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5) . Thus, the ABC number of T is 3 . You are given a string S . Each character of S is A , B , C or ? . Let Q be the number of occurrences of ? in S . We can make 3^Q strings by replacing each occurrence of ? in S with A , B or C . Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7 . Constraints 3 †|S| †10^5 Each character of S is A , B , C or ? . Input Input is given from Standard Input in the following format: S Output Print the sum of the ABC numbers of all the 3^Q strings, modulo 10^9 + 7 . Sample Input 1 A??C Sample Output 1 8 In this case, Q = 2 , and we can make 3^Q = 9 strings by by replacing each occurrence of ? with A , B or C . The ABC number of each of these strings is as follows: AAAC : 0 AABC : 2 AACC : 0 ABAC : 1 ABBC : 2 ABCC : 2 ACAC : 0 ACBC : 1 ACCC : 0 The sum of these is 0 + 2 + 0 + 1 + 2 + 2 + 0 + 1 + 0 = 8 , so we print 8 modulo 10^9 + 7 , that is, 8 . Sample Input 2 ABCBC Sample Output 2 3 When Q = 0 , we print the ABC number of S itself, modulo 10^9 + 7 . This string is the same as the one given as an example in the problem statement, and its ABC number is 3 . Sample Input 3 ????C?????B??????A??????? Sample Output 3 979596887 In this case, the sum of the ABC numbers of all the 3^Q strings is 2291979612924 , and we should print this number modulo 10^9 + 7 , that is, 979596887 . | 37,313 |
Problem I: Shy Polygons You are given two solid polygons and their positions on the xy -plane. You can move one of the two along the x -axis (they can overlap during the move). You cannot move it in other directions. The goal is to place them as compactly as possible, subject to the following condition: the distance between any point in one polygon and any point in the other must not be smaller than a given minimum distance L . We define the width of a placement as the difference between the maximum and the minimum x -coordinates of all points in the two polygons. Your job is to write a program to calculate the minimum width of placements satisfying the above condition. Let's see an example. If the polygons in Figure 13 are placed with L = 10.0, the result will be 100. Figure 14 shows one of the optimal placements. Input The input consists of multiple datasets. Each dataset is given in the following format. L Polygon 1 Polygon 2 L is a decimal fraction, which means the required distance of two polygons. L is greater than 0.1 and less than 50.0. The format of each polygon is as follows. n x 1 y 1 x 2 y 2 . . . x n y n n is a positive integer, which represents the number of vertices of the polygon. n is greater than 2 and less than 15. Remaining lines represent the vertices of the polygon. A vertex data line has a pair of nonneg- ative integers which represent the x - and y-coordinates of a vertex. x - and y -coordinates are separated by a single space, and y -coordinate is immediately followed by a newline. x and y are less than 500. Edges of the polygon connect vertices given in two adjacent vertex data lines, and vertices given in the last and the first vertex data lines. You may assume that the vertices are given in the counterclockwise order, and the contours of polygons are simple, i.e. they do not cross nor touch themselves. Also, you may assume that the result is not sensitive to errors. In concrete terms, for a given pair of polygons, the minimum width is a function of the given minimum distance l . Let us denote the function w ( l ). Then you can assume that | w ( L ± 10 -7 ) - w ( L )| < 10 -4 . The end of the input is indicated by a line that only contains a zero. It is not a part of a dataset. Output The output should consist of a series of lines each containing a single decimal fraction. Each number should indicate the minimum width for the corresponding dataset. The answer should not have an error greater than 0.0001. You may output any number of digits after the decimal point, provided that the above accuracy condition is satisfied. Sample Input 10.5235 3 0 0 100 100 0 100 4 0 50 20 50 20 80 0 80 10.0 4 120 45 140 35 140 65 120 55 8 0 0 100 0 100 100 0 100 0 55 80 90 80 10 0 45 10.0 3 0 0 1 0 0 1 3 0 100 1 101 0 101 10.0 3 0 0 1 0 0 100 3 0 50 100 50 0 51 0 Output for the Sample Input 114.882476 100 1 110.5005 | 37,314 |
Score : 100 points Problem Statement Having learned the multiplication table, Takahashi can multiply two integers between 1 and 9 (inclusive) together. He cannot do any other calculation. Given are two integers A and B . If Takahashi can calculate A \times B , print the result; if he cannot, print -1 instead. Constraints 1 \leq A \leq 20 1 \leq B \leq 20 All values in input are integers. Input Input is given from Standard Input in the following format: A B Output If Takahashi can calculate A \times B , print the result; if he cannot, print -1 . Sample Input 1 2 5 Sample Output 1 10 2 \times 5 = 10 . Sample Input 2 5 10 Sample Output 2 -1 5\times 10 = 50 , but Takahashi cannot do this calculation, so print -1 instead. Sample Input 3 9 9 Sample Output 3 81 | 37,315 |
æåå S ãšïŒ m åã®ã¯ãšãªãäžããããïŒ i çªç®ã®ã¯ãšãªã¯äºã€ã®æåå x i , y i ã§äžããããïŒ åã¯ãšãªã«ã€ããŠïŒæåå S ã®éšåæååã§ããïŒ x i ã§å§ãŸã y i ã§çµãããã®ã®äžã§ïŒæé·ã®é·ããçããïŒ æåå S ã«ã€ããŠïŒ |S| 㯠S ã®é·ãã衚ãïŒãŸãïŒæåå T ãæåå S ã®éšåæååã§ãããšã¯ïŒããæŽæ° i ãååšããŠïŒ 1 †j †|T| ã«å¯Ÿã㊠T j = S i+j ãæºããããšãèšãïŒãã ã T j 㯠T ã® j çªç®ã®æåã衚ãïŒ Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ S m x 1 y 1 x 2 y 2 : x m y m 1 è¡ç®ã«ã¯ïŒæåå S ãäžããããïŒ 2 è¡ç®ã«ã¯ïŒã¯ãšãªã®åæ° m ãäžããããïŒ 3 è¡ç®ããã® m è¡ã®ãã¡ i è¡ç®ã«ã¯ i çªç®ã®ã¯ãšãªæåå x i , y i ã空çœåºåãã§äžããããïŒ Constraints 1 †|S| †2 à 10 5 1 †m †10 5 1 †|x i |, |y i | $\sum^m_{i=1}$ ( |x i | + |y i | ) †2 à 10 5 S åã³ x i , y i ã¯ïŒåè§ã®è±å°æåã®ã¿ãããªãïŒ Output 以äžã®åœ¢åŒã§æå€§ã®éšåæååã®é·ããçããïŒ len 1 len 2 : len m 1 è¡ç®ããã® m è¡ã®ãã¡ i è¡ç®ã«ã¯ïŒ i çªç®ã®ã¯ãšãªã«ã€ããŠïŒæ¡ä»¶ãæºããæé·ã®éšåæååã®é·ã len i ãåºåããïŒãã®ãããªéšåæååããªãå ŽåïŒ0 ãåºåããïŒ Sample Input 1 abracadabra 5 ab a a a b c ac ca z z Output for the Sample Input 1 11 11 4 3 0 æåå S ãšããŠïŒabracadabra ãäžããããïŒ "ab" ã§å§ãŸã "a" ã§çµããéšåæååã¯ïŒ"abra" ã "abraca", "abracada", "abracadabra" ã®4 çš®é¡ããããïŒæé·ã®éšåæåå㯠"abracadabra" ã§ïŒé·ã㯠11 ã§ããïŒ "a" ã§å§ãŸã "a" ã§çµããæé·ã®éšåæååãåæ§ã« "abracadabra" ã§ïŒé·ã㯠11 ã§ããïŒ "b" ã§å§ãŸã "c" ã§çµããæé·ã®éšåæåå㯠"brac" ã§ïŒé·ã㯠4 ã§ããïŒ "ac" ã§å§ãŸã "ca" ã§çµããæé·ã®éšåæåå㯠"aca" ã§ïŒé·ã㯠3 ã§ããïŒ "z" ã§å§ãŸã "z" ã§çµããéšåæååã¯ååšããªãïŒãã£ãŠ0 ãåºåããïŒ Sample Input 2 howistheprogress 4 ist prog s ss how is the progress Output for the Sample Input 2 9 12 5 11 Sample Input 3 icpcsummertraining 9 mm m icpc summer train ing summer mm i c i i g g train i summer er Output for the Sample Input 3 2 10 8 0 4 16 1 6 6 | 37,316 |
åé¡ 3: è¶
éœèгå
(Super Metropolis) åé¡ JOI åã¯ïŒIOI åœã«ããè¶
éœãšããéœåžã®èгå
ãã¢ãŒãèšç»ããããšã«ãªã£ãïŒ è¶
éœã¯ïŒååæ¹åã«ãŸã£ããã«äŒžã³ã W æ¬ã®éè·¯ãšïŒæ±è¥¿æ¹åã«ãŸã£ããã«äŒžã³ã H æ¬ã®éè·¯ã«ããïŒç¢ç€ã®ç®ã®åœ¢ã«åºåããããŠããïŒ ååæ¹åã® W æ¬ã®éè·¯ã«ã¯ïŒè¥¿ããé ã« 1, 2, ... , W ã®çªå·ãä»ããããŠããïŒãŸãïŒæ±è¥¿æ¹åã® H æ¬ã®éè·¯ã«ã¯ïŒåããé ã« 1, 2, ... , H ã®çªå·ãä»ããããŠããïŒè¥¿ãã i çªç®ã®ååæ¹åã®éè·¯ãšïŒåãã j çªç®ã®æ±è¥¿æ¹åã®éè·¯ãšã®äº€å·®ç¹ã (i, j) ã§è¡šãïŒ ããã«ïŒäžå³ã®ããã«ïŒå亀差ç¹ããã¯ïŒã€åæ±ã®äº€å·®ç¹ãžã®éãããïŒæãåã®éè·¯äžã®äº€å·®ç¹ãšæãæ±ã®éè·¯äžã®äº€å·®ç¹ãé€ãïŒïŒ ãŸãïŒïŒã€å西ã®äº€å·®ç¹ãžã®éãããïŒæãåã®éè·¯äžã®äº€å·®ç¹ãšæã西ã®éè·¯äžã®äº€å·®ç¹ãé€ãïŒïŒ ããªãã¡ïŒäº€å·®ç¹ (i, j) ããã¯ïŒããäº€å·®ç¹ (i - 1, j), (i + 1, j), (i, j - 1), (i, j + 1) ããããšãã¯ïŒãããã®äº€å·®ç¹ãžïŒæ¬ã®éã䜿ã£ãŠè¡ãããšãåºæ¥ãïŒããã«å ãïŒããäº€å·®ç¹ (i - 1, j - 1), (i + 1, j + 1) ããããšãã¯ïŒãããã®äº€å·®ç¹ãžãïŒæ¬ã®éã䜿ã£ãŠè¡ãããšãåºæ¥ãïŒ JOI åã¯ãã¢ãŒã®èšç»ãšããŠæ¢ã« N åã®èгå
ã¹ããããã©ã®ãããªé çªã§èšªããããæ±ºããŠããïŒ i çªç® (1 ⊠i ⊠N) ã«èšªãã芳å
ã¹ãããã¯äº€å·®ç¹ (X i , Y i ) ã«ããïŒ JOI åã¯ïŒãã¢ãŒã«ãããæéãã§ããã ãçãããããã«ïŒéããªããã°ãªããªãéã®æ¬æ°ãå°ãªããããïŒ èŠ³å
ã¹ããããäºåã«æ±ºããé çªã§èšªããããã«éããªããã°ãªããªãéã®æ¬æ°ã®åèšã®æå°å€ãæ±ããããã°ã©ã ãäœæããïŒ ãã ãïŒãã¢ãŒã®éå§å°ç¹ã¯äº€å·®ç¹ (X 1 , Y 1 ) ã§ããïŒãŸãïŒãã¢ãŒã®éäžã§è¶
éœã®å€ãžç§»åããŠã¯ãªããªããã®ãšããïŒ ãŸãïŒJOI åã¯ïŒèгå
ã¹ãããã®ãã亀差ç¹ãïŒèгå
ã¹ãããã蚪ããã«ééããããšãã§ããïŒ ãéã®æ¬æ°ã®åèšãã«ã€ããŠã®è£è¶³ïŒãã¢ãŒã®éäžã§åãéãïŒå以äžéãããšãã§ããïŒãã®å ŽåïŒãéã®æ¬æ°ã®åèšããšããŠã¯ïŒãã®éã«ã€ããŠã¯éã£ãåæ°ã ãéè€ããŠæ°ãããã®ãšããïŒ å
¥å å
¥å㯠1 + N è¡ãããªãïŒ 1 è¡ç®ã«ã¯ïŒç©ºçœãåºåããšã㊠3 ã€ã®æŽæ° W, H, N (2 †W †10000, 2 †H †10000, 1 †N †1000) ãæžãããŠããïŒ ç¶ã N è¡ã®ãã¡ã® i è¡ç® (1 †i †N) ã«ã¯ïŒ2 ã€ã®æŽæ° X i , Y i (1 †X i †W, 1 †Y i †H) ã空çœãåºåããšããŠæžãããŠããïŒããã¯ïŒi çªç®ã«èšªãã芳å
ã¹ãããã®ãã亀差ç¹ã (X i , Y i ) ã§ããããšã衚ãïŒ åºå 芳å
ã¹ããããé çªã«èšªããããã«éãéã®æ¬æ°ã®åèšã®æå°å€ã 1 è¡ã§åºåããïŒ å
¥åºåäŸ å
¥åäŸ 1 4 3 3 1 1 3 3 4 1 åºåäŸ 1 5 å
¥åºåäŸ 1 ã§ã¯ïŒäŸãã° (1, 1), (2, 2), (3, 3), (3, 2), (4, 2), (4, 1) ã®é ã§äº€å·®ç¹ã蚪ããã°è¯ãïŒ å
¥åäŸ 2 4 3 5 1 3 4 3 2 2 2 2 1 3 åºåäŸ 2 7 å
¥åºåäŸ 2 ã®ããã«ïŒåã亀差ç¹ã«è€æ°å蚪ããããšãããïŒ å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã | 37,317 |
çŠçžè» ãçŠçžè»ãã¯è¡åã®ã§ãã人æ°ã®ã©ãŒã¡ã³å±ã§ããã§ãæè¿ãã客ããã®éãããåŸ
ã¡æéãé·ãã®ã«ãåºã«å
¥ã£ãã空åžãããã®ã¯èš±ããªãããšãã声ãèãããããã«ãªã£ãŠããŸãããã©ãããŠãããªäžæºãåºãã®ã調ã¹ããã®ã§ããããåºãéããŠããããã ã¯å¿ãããŠãå®éã®è¡åã®æ§åã調ã¹ãããšãã§ããŸãããããããé·å¹Žã®çµéšããã客ãããæ¥ãééã人æ°ã¯åãã£ãŠããã®ã§ããããããšã«åŸ
ã¡æéã®åæãããããšã«ããŸããã åºå
ã«ã¯ã«ãŠã³ã¿ãŒã«åãã£ãŠ 17 ã®åžããããŸããéåºæéã¯æ£åã§ãã客ããã¯æ¬¡ã®ããã«ãã£ãŠããŸãã 0 çªãã 99 çªãŸã§ã® 100 çµã®ã°ã«ãŒããæ¥ãŸãã i çªç®ã®ã°ã«ãŒãã¯æ£åãã 5 i ååŸã«ãåºã«å°çããŸãã i çªç®ã®ã°ã«ãŒãã®äººæ°ã¯ i % 5 ã 1 ã®ãšã 5 人ããã以å€ã®ãšã㯠2 人ã§ãã ( x % y 㯠x ã y ã§å²ã£ããšãã®äœãã衚ãããŸãã) i çªç®ã®ã°ã«ãŒãã¯ãåžã«çããš 17( i % 2) + 3( i % 3) + 19 åéã§é£äºãæžãŸããŸãã æåã® 10 ã°ã«ãŒãã®å°çæå»ã人æ°ãé£äºæéã¯æ¬¡ã®ããã«ãªããŸãã ã°ã«ãŒãçªå· 0 1 2 3 4 5 6 7 8 9 å°çæå»(ååŸ) 0 5 10 15 20 25 30 35 40 45 人æ°(人) 2 5 2 2 2 2 5 2 2 2 é£äºæé(å) 19 39 25 36 22 42 19 39 25 36 ãŸããã客ãããåžã«æ¡å
ãããšãã«ã¯ã次ã®ããã«ããŠããŸãã åžã«ã¯ 0 ãã 16 ãŸã§ã®çªå·ãä»ããŠããŸãã x 人ã®ã°ã«ãŒãã¯é£ç¶ã㊠x åãããŠããåžããã£ãæã ãçåžã§ããŸãã ãŸãã座ããå Žæãè€æ°ãã£ãå Žåã¯ãåžã®çªå·ãæãå°ãããªããšããã«åº§ããŸããäŸãã°ã0ã1ã2ã4ã5çªã®åžã ãã空ããŠããå Žåã5 人ã®ã°ã«ãŒãã¯çåžã§ããŸããã2 人ã®ã°ã«ãŒãã§ããã° 0ã1 çªã«çåžããŸãã äžåºŠçåžããããåžãç§»åããŠãããããšã¯ããŸããã ã客ãã㯠1 ååäœã§åºå
¥ãããŸããåæå»ã«ã¯æ¬¡ã®é åºã§ã客ãããæ¡å
ããŸãã åã®ã°ã«ãŒãã®é¢åžãšåæã«æ¬¡ã®ã°ã«ãŒãã®çåžãå¯èœãšãªããŸãã ã客ãããçåžãããéã«ã¯ãè¡åã®å
é ã«ããã°ã«ãŒãããé ã«ãã§ããéãå€ãã®ã°ã«ãŒããåãæå»ã«çåžãããŸããè¡åã®é åºã远ãè¶ãããšã¯ããŸãããã€ãŸããå
é ã®ã°ã«ãŒããçåžã§ããªããã°ãè¡åå
ã®ä»ã®ã°ã«ãŒããçåžã§ãããšããŠããçåžãããŸããã ãã®æå»ã«å°çããã°ã«ãŒãã¯ãè¡åãæ®ã£ãŠããå Žåã¯è¡åã®æåŸå°Ÿã«äžŠã³ãŸããè¡åãç¡ããçåžã§ããå Žåã¯çåžããã§ããªãå Žåã¯äžŠãã§åŸ
ã¡ãŸããäŸãšããŠæåã® 10 ã°ã«ãŒããå°çãããŸã§ã®æ§åã瀺ããšä»¥äžã®ããã«ãªããŸããåè¡ã®3ã€ã®æ¬ã¯ãå·Šããæå»ã座åžã®æ§åãè¡åã®æ§åã瀺ããŠããŸãã座åžã¯ã_ãã空åžã§ãçªå·ã¯ãã®åžã«ãã®çªå·ã®ã°ã«ãŒãã座ã£ãŠããããšã瀺ããŠããŸãã æå»: åº§åž è¡å 0: 00_______________: 5: 0011111__________: 10: 001111122________: 15: 00111112233______: 18: 00111112233______: 19: __111112233______: 20: 44111112233______: 25: 4411111223355____: 30: 4411111223355____: 66666 ã°ã«ãŒã6ãå°ç 34: 4411111223355____: 66666 35: 4411111__3355____: 6666677 ã°ã«ãŒã7ãå°ç 40: 4411111__3355____: 666667788 ã°ã«ãŒã8ãå°ç 41: 4411111__3355____: 666667788 42: __11111__3355____: 666667788 43: __11111__3355____: 666667788 44: 6666677883355____: ã°ã«ãŒã6ã7ã8ãçåž 45: 666667788335599__: ã°ã«ãŒã9ãå°çãçåž äŸãã°ãæå» 40 ã§ã¯ 8 çªç®ã®ã°ã«ãŒããå°çããŸãããçåžã§ããªãã®ã§è¡åã«å ãããŸãã4 çªç®ã®ã°ã«ãŒãã¯æå» 41 ãŸã§é£äºãããŸããæå» 42 ã§ã¯ã4 çªç®ã®ã°ã«ãŒãã®åžã空ããŸãããé£ç¶ããåžæ°ãè¶³ããªãã®ã§ 6 çªç®ã®ã°ã«ãŒãã¯ãŸã çåžã§ããŸããã1 çªç®ã®ã°ã«ãŒãã¯æå» 43 ãŸã§é£äºãããŸããæå» 44 ã§ 1 çªç®ã®ã°ã«ãŒãã®åžã空ãã®ã§ã6 çªç®ã®ã°ã«ãŒããçåžããåæã« 7 çªç®ã8 çªç®ã®ã°ã«ãŒããçåžããŸãã9 çªç®ã®ã°ã«ãŒãã¯æå» 45 ã§å°çããåžã空ããŠããã®ã§ãã®ãŸãŸçåžããŸãã ãããã®æ
å ±ãåºã«ããŠã0 ä»¥äž 99 以äžã®æŽæ° n ãå
¥åãšããŠã n çªç®ã°ã«ãŒãã®ã客ãããåŸ
ã€æé(ååäœ)ãåºåããããã°ã©ã ãäœæããŠãã ããã Input è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã¯ïŒã€ã®æŽæ° n ãããªããŸãã ããŒã¿ã»ããã®æ°ã¯ 20 ãè¶
ããŸããã Output åããŒã¿ã»ããã«ã€ããŠã n çªç®ã®ã客ã®ååäœã®åŸ
ã¡æé(0 以äžã®æŽæ°)ãïŒè¡ã«åºåããŠãã ããã Sample Input 5 6 7 8 Output for the Sample Input 0 14 9 4 | 37,318 |
Problem P02: Yes, I have a number åå£«ïŒ ããŒã¿ãŒåãYes, I have a numberãã£ãŠç¥ã£ãŠãããïŒ ãºãŒã¿ãŒïŒ ãã®ãŸããã¬ãã§ãã£ãŠãŸããããæç« ã«å«ãŸããååèªã®æåæ°ã§äœããèŠãããšãããã®ã§ãããã ãYes, I have a numberã ã ãããã3.14ãšããæ°åããšããæå³ã«ãªã£ãŠååšçãèŠããããã®ããŒã¯ãŒãã«ãªã£ãŠãããã§ãããã åå£«ïŒ ããŒã¿ãŒåãããã¯éããããã ããã¯ã3.1416 ãšè§£éããã°ãªãã¬ã®ãããååšçã¯3.14159...ã ããã®ãã ããŒã¿ãŒïŒ ããããããã®çªçµã¯æ¥æ¬ãååšçã3.14ãšæããŠãããããšãã£ãŠç¡çç¢ççç¥ãããã§ããïŒïŒ åå£«ïŒ ããããå°åŠæ ¡ã§æããååšçããã£ãš3ãã3.14ã«æ»ã£ãã ãã§ããããšãããã ããŒã¿ãŒïŒ ãããããããã§æ¬åœã«èŠãããããã§ããïŒ åå£«ïŒ æ¥æ¬äººã«ã¯é£ããããããããè±èªåã®äººãã¡ã¯äœ¿ãããããããè±èªã§ãŽãåãããããã®ã¯é£ããããã®ãã ããŒã¿ãŒïŒ ããã«ããŠãããã§ãã¯ããã®ãé¢åããããã§ããã åå£«ïŒ ããã§ãããæç« ãåèªã®æåæ°ã®æ°åã«å€æããããã°ã©ã ãäœã£ãŠã»ããã®ããã ããŒã¿ãŒïŒ äºè§£ããŸããã詳ãã仿§ãæããŠãã ããå士ã åå£«ïŒ 1è¡ã®æç« ãå
¥åãšããããç°¡åã®ããã«ã¢ã«ãã¡ããããšç©ºçœã®ã¿ãå«ãæç« ã§ãããã ãã®æç« ã«ã€ããŠã空çœã»æé ã»ææ«ã«æãŸããæååã®é·ããé çªã«åºåããŠããã æååã®æåæ°ã¯9ãè¶
ããªããšéçšããŠãããã äŸãã°ã"Yes I have" ã® Yes ã¯æé ãšæåã®ç©ºçœã§åºåãããŠããããæåæ°ã¯ 3 ã I 㯠1 ã€ç®ãš 2 ã€ç®ã®ç©ºçœã«åºåãããŠããŠæåæ°ã¯ 1 ããã åå£«ïŒ ã»ã»ã»ããããã空çœãé£ç¶ããå Žåã®ãæåæ°ã 0 ã«ãªãæååãå¿ããã«ãªã Input è€æ°ã®ããŒã¿ã»ãããå
¥åãšããŠäžããããŸããåããŒã¿ã»ããã§ãã¢ã«ãã¡ããããšç©ºçœãå«ãæååãïŒè¡ã«äžããããŸãã æååã "END OF INPUT" ã®ãšããå
¥åã®çµãããšããŸãããã®å
¥åã«å¯Ÿããåºåãè¡ã£ãŠã¯ãããŸããã Output åããŒã¿ã»ããã«ã€ããŠãæååã«å¯Ÿããæåæ°ã®æ°åãïŒè¡ã«åºåããŠäžããã Sample Input Yes I have a number How I wish I could calculate an unused color for space Thank you END OF INPUT Output for the Sample Input 31416 31415926535 53 | 37,320 |
Score: 400 points Problem Statement Quickly after finishing the tutorial of the online game ATChat , you have decided to visit a particular place with N-1 players who happen to be there. These N players, including you, are numbered 1 through N , and the friendliness of Player i is A_i . The N players will arrive at the place one by one in some order. To make sure nobody gets lost, you have set the following rule: players who have already arrived there should form a circle, and a player who has just arrived there should cut into the circle somewhere. When each player, except the first one to arrive, arrives at the place, the player gets comfort equal to the smaller of the friendliness of the clockwise adjacent player and that of the counter-clockwise adjacent player. The first player to arrive there gets the comfort of 0 . What is the maximum total comfort the N players can get by optimally choosing the order of arrivals and the positions in the circle to cut into? Constraints All values in input are integers. 2 \leq N \leq 2 \times 10^5 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N A_1 A_2 \dots A_N Output Print the maximum total comfort the N players can get. Sample Input 1 4 2 2 1 3 Sample Output 1 7 By arriving at the place in the order Player 4, 2, 1, 3 , and cutting into the circle as shown in the figure, they can get the total comfort of 7 . They cannot get the total comfort greater than 7 , so the answer is 7 . Sample Input 2 7 1 1 1 1 1 1 1 Sample Output 2 6 | 37,321 |
ååŒ·äŒ ããã°ã©ããŒé€ææ ¡ã®ã¢ã«ã髿 ¡ã«ã¯ãçåŸèªèº«ã§éå¶ãããŠããŒã¯ãªå匷äŒããããŸããããã°ã©ããŒã¯æ°ããæè¡ãåžžã«åãå
¥ããããšã倧åãªã®ã§ããã®å匷äŒãéããŠèªåŠèªç¿ã®ç¿æ
£ã身ã«ã€ããããšããã®æŽ»åã®ãããã§ãã çåŸã¯å
šéšã§ N 人ããããããããå
¥åŠæã®ããã°ã©ãã³ã°ã³ã³ãã¹ãã®çµæã§åŸãããã¹ã³ã¢ãæã£ãŠããŸããå匷äŒã§ã¯ N 人ã®çåŸã®ãã¡äœäººãããªãŒããŒã«ãªããåãªãŒããŒãããããã®ã°ã«ãŒããéå¶ãããšãšãã«ãèªãã®éå¶ããã°ã«ãŒãã«åå ããŸãã ãªãŒããŒä»¥å€ã®çåŸã¯ãèªåã®ã¹ã³ã¢ãããäœãã¹ã³ã¢ã®ãªãŒããŒãéå¶ããã°ã«ãŒãã«ã¯åå ã§ããŸããããŸãã0以äžã®ããå€ r ãïŒã€æ±ºããã°ã«ãŒãã«åå ããçåŸãšãªãŒããŒã®ã¹ã³ã¢ã®å·®ã r 以å
ãšãªãããã«ããŠããŸããã€ãŸããã°ã«ãŒãã®ãªãŒããŒã®ã¹ã³ã¢ã s ã®ãšããèªåã®ã¹ã³ã¢ã s ãè¶
ããŠããããããã㯠s - r æªæºãªãã°ããã®ã°ã«ãŒãã«ã¯åå ã§ããŸããã ããªãã¯å匷äŒã®å®è¡å§å¡é·ã§ãããéå¶æºåã®ããã«ã·ãã¥ã¬ãŒã·ã§ã³ãè¡ãããšã«ããŸãããã·ãã¥ã¬ãŒã·ã§ã³ã§ã¯ããªãŒããŒã誰ãããªãç¶æ
ããå§ãã以äžã®æäœãäœåãç¹°ãè¿ããŸãã çåŸããªãŒããŒã«å ããã çåŸããªãŒããŒããå€ãã èŠæ±æç¹ã§ã®ãªãŒããŒã®çµã¿åããã«ã€ããŠãã©ã®ã°ã«ãŒãã«ãåå ã§ããªãçåŸã x 人以äžã«ãªããããªãæå°ã® r ãæ±ããã ãã®ãããªã·ãã¥ã¬ãŒã·ã§ã³ãè¡ãããã°ã©ã ãäœæããŠãã ããã å
¥å å
¥åã¯1ã€ã®ããŒã¿ã»ãããããªããå
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã N Q s 1 s 2 : s N QUERY 1 QUERY 2 : QUERY Q 1è¡ç®ã«çåŸã®æ° N (1 †N †1000000)ãåŠçèŠæ±ã®æ° Q (0 †Q †1000)ãäžããããã ç¶ã N è¡ã« i çªç®ã®çåŸã®ã¹ã³ã¢ãç€ºãæŽæ° s i (0 †s i †1,000,000,000)ãäžãããããçåŸã¯1,2,..., N ã§çªå·ä»ããããŠãããã®ãšããã ç¶ã Q è¡ã«åŠçèŠæ± QUERY i ãäžãããããåŠçèŠæ±ã¯æç³»åé ã«äžãããããåŠçèŠæ±ã¯ADD, REMOVE, CHECKã®3çš®é¡ãããå QUERY i ã¯ä»¥äžã®ããããã®åœ¢åŒã§äžããããã ADD a ãŸã㯠REMOVE a ãŸã㯠CHECK x ADD a ã¯çªå· a (1 †a †N )ã®çåŸããªãŒããŒã«å ããããšã衚ãã REMOVE a ã¯çªå· a (1 †a †N )ã®çåŸããªãŒããŒããå€ãããšã衚ãã CHECK x ã¯åºåèŠæ±ã衚ããã©ã®ã°ã«ãŒãã«ãåå ã§ããªãçåŸã®æ°ã®äžé x (0 †x †N )ãäžããããã ãªããå
¥åã¯ä»¥äžã®æ¡ä»¶ãæºãããã®ãšããã ã©ã®æç¹ã§ãããªãŒããŒã®äººæ°ã100人ãè¶
ããããšã¯ãªãã ãã®æç¹ã§ãªãŒããŒã§ããçåŸããªãŒããŒã«å ããããšã¯ãªãã ãã®æç¹ã§ãªãŒããŒã§ãªãçåŸããªãŒããŒããå€ãããšã¯ãªãã åºå æç³»åé ã«ååºåèŠæ±ã®æç¹ã§ãã©ã®ã°ã«ãŒãã«ãåå ã§ããªãçåŸãx人以äžã«ãªããããªæå°ã® r ã1è¡ã«åºåããããã ããã©ã®ãã㪠r ãéžãã§ã x 人以äžã«ããããšãäžå¯èœã§ããã°NAãšåºåããã å
¥åäŸ 1 5 8 5 10 8 7 3 ADD 1 ADD 3 CHECK 0 CHECK 1 CHECK 2 CHECK 3 CHECK 4 CHECK 5 åºåäŸ 1 NA 2 1 0 0 0 å
¥åäŸ 2 5 28 5 10 8 7 3 CHECK 0 CHECK 1 CHECK 2 CHECK 3 CHECK 4 CHECK 5 ADD 1 CHECK 0 CHECK 1 CHECK 2 CHECK 3 CHECK 4 CHECK 5 REMOVE 1 ADD 3 CHECK 0 CHECK 1 CHECK 2 CHECK 3 CHECK 4 CHECK 5 ADD 1 CHECK 0 CHECK 1 CHECK 2 CHECK 3 CHECK 4 CHECK 5 åºåäŸ 2 NA NA NA NA NA 0 NA NA NA 2 0 0 NA 5 3 1 0 0 NA 2 1 0 0 0 | 37,322 |
8 Puzzle The goal of the 8 puzzle problem is to complete pieces on $3 \times 3$ cells where one of the cells is empty space. In this problem, the space is represented by 0 and pieces are represented by integers from 1 to 8 as shown below. 1 3 0 4 2 5 7 8 6 You can move a piece toward the empty space at one step. Your goal is to make the pieces the following configuration in the shortest move (fewest steps). 1 2 3 4 5 6 7 8 0 Write a program which reads an initial state of the puzzle and prints the fewest steps to solve the puzzle. Input The $3 \times 3$ integers denoting the pieces or space are given. Output Print the fewest steps in a line. Constraints There is a solution. Sample Input 1 3 0 4 2 5 7 8 6 Sample Output 4 | 37,323 |
Non-redundant Drive The people of JAG kingdom hate redundancy. For example, the N cities in JAG kingdom are connected with just $N - 1$ bidirectional roads such that any city is reachable from any city through some roads. Under the condition, the number of paths from a city to another city is exactly one for all pairs of the cities. This is a non-redundant road network :) One day, you, a citizen of JAG kingdom, decided to travel as many cities in the kingdom as possible with a car. The car that you will use has an infinitely large tank, but initially the tank is empty. The fuel consumption of your car is 1 liter per 1 km, i.e. it consumes 1 liter of gasoline to move 1 km. Each city has exactly one gas station, and you can supply $g_x$ liters of gasoline to your car at the gas station of the city $x$. Of course, you have a choice not to visit some of the gas stations in your travel. But you will not supply gasoline twice or more at the same gas station, because it is redundant. Each road in the kingdom has a distance between two cities: the distance of $i$-th road is $d_i$ km. You will not pass the same city or the same road twice or more, of course, because it is redundant. If a quantity of stored gasoline becomes zero, the car cannot move, and hence your travel will end there. But then, you may concern about an initially empty tank. Don't worry. You can start at any gas station of the cities in the kingdom. Furthermore, each road directly connects the gas stations of the its two ends (because the spirit of non-redundancy avoids redundant moves in a city), you therefore can supply gasoline to your car even if your car tank becomes empty just when you arrive the city. Your task is to write a program computing the maximum number of cities so that you can travel under your non-redundancy policy. Input The input consists of a single test case. $N$ $g_1$ $g_2$ ... $g_N$ $a_1$ $b_1$ $d_1$ $a_2$ $b_2$ $d_2$ ... $a_{N-1}$ $b_{N-1}$ $d_{N-1}$ The first line contains an integer $N$ ($1 \leq N \leq 100,000$), which is the number of cities in JAG kingdom. The second line contains $N$ integers: the $i$-th of them is $g_i$ ($1 \leq g_i \leq 10,000$), the amount of gasoline can be supplied at the gas station of the city $i$. The following $N - 1$ lines give information of roads: the $j$-th line of them contains $a_j$ and $b_j$ , which indicates that the $j$-th road bidirectionally connects the cities $a_j$ and $b_j$ ($1 \leq a_j, b_j \leq N, a_j \ne b_j$) with distance $d_j$ ($1 \leq d_j \leq 10,000$). You can assume that all cities in the kingdom are connected by the roads. Output Print the maximum number of cities you can travel from any city under the constraint such that you can supply gasoline at most once per a gas station. Sample Input 1 5 5 8 1 3 5 1 2 4 2 3 3 2 4 3 1 5 7 Output for the Sample Input 1 4 Sample Input 2 2 10 1 1 2 10 Output for the Sample Input 2 2 Sample Input 3 5 1 3 5 1 1 1 2 5 2 3 3 2 4 3 1 5 5 Output for the Sample Input 3 3 | 37,324 |
Problem C: Mobile Phone Coverage A mobile phone company ACMICPC (Advanced Cellular, Mobile, and Internet-Connected Phone Corporation) is planning to set up a collection of antennas for mobile phones in a city called Maxnorm. The company ACMICPC has several collections for locations of antennas as their candidate plans, and now they want to know which collection is the best choice. for this purpose, they want to develop a computer program to find the coverage of a collection of antenna locations. Each antenna A i has power r i , corresponding to "radius". Usually, the coverage region of the antenna may be modeled as a disk centered at the location of the antenna ( x i , y i ) with radius r i . However, in this city Maxnorm such a coverage region becomes the square [ x i â r i , x i + r i ] à [ y i â r i , y i + r i ]. In other words, the distance between two points ( x p , y p ) and ( x q , y q ) is measured by the max norm max{ | x p â x q |, | y p â y q |}, or, the L â norm, in this city Maxnorm instead of the ordinary Euclidean norm â {( x p â x q ) 2 + ( y p â y q ) 2 }. As an example, consider the following collection of 3 antennas 4.0 4.0 3.0 5.0 6.0 3.0 5.5 4.5 1.0 depicted in the following figure where the i -th row represents x i , y i r i such that ( x i , y i ) is the position of the i -th antenna and r i is its power. The area of regions of points covered by at least one antenna is 52.00 in this case. Write a program that finds the area of coverage by a given collection of antenna locations. Input The input contains multiple data sets, each representing a collection of antenna locations. A data set is given in the following format. n x 1 y 1 r 1 x 2 y 2 r 2 . . . x n y n r n The first integer n is the number of antennas, such that 2 †n †100. The coordinate of the i -th antenna is given by ( x i , y i ), and its power is r i . x i , y i and r i are fractional numbers between 0 and 200 inclusive. The end of the input is indicated by a data set with 0 as the value of n . Output For each data set, your program should output its sequence number (1 for the first data set, 2 for the second, etc.) and the area of the coverage region. The area should be printed with two digits to the right of the decimal point, after rounding it to two decimal places. The sequence number and the area should be printed on the same line with no spaces at the beginning and end of the line. The two numbers should be separated by a space. Sample Input 3 4.0 4.0 3.0 5.0 6.0 3.0 5.5 4.5 1.0 2 3.0 3.0 3.0 1.5 1.5 1.0 0 Output for the Sample Input 1 52.00 2 36.00 | 37,325 |
Score : 600 points Problem Statement There are N points in a two-dimensional plane. The initial coordinates of the i -th point are (x_i, y_i) . Now, each point starts moving at a speed of 1 per second, in a direction parallel to the x - or y - axis. You are given a character d_i that represents the specific direction in which the i -th point moves, as follows: If d_i = R , the i -th point moves in the positive x direction; If d_i = L , the i -th point moves in the negative x direction; If d_i = U , the i -th point moves in the positive y direction; If d_i = D , the i -th point moves in the negative y direction. You can stop all the points at some moment of your choice after they start moving (including the moment they start moving). Then, let x_{max} and x_{min} be the maximum and minimum among the x -coordinates of the N points, respectively. Similarly, let y_{max} and y_{min} be the maximum and minimum among the y -coordinates of the N points, respectively. Find the minimum possible value of (x_{max} - x_{min}) \times (y_{max} - y_{min}) and print it. Constraints 1 \leq N \leq 10^5 -10^8 \leq x_i,\ y_i \leq 10^8 x_i and y_i are integers. d_i is R , L , U , or D . Input Input is given from Standard Input in the following format: N x_1 y_1 d_1 x_2 y_2 d_2 . . . x_N y_N d_N Output Print the minimum possible value of (x_{max} - x_{min}) \times (y_{max} - y_{min}) . The output will be considered correct when its absolute or relative error from the judge's output is at most 10^{-9} . Sample Input 1 2 0 3 D 3 0 L Sample Output 1 0 After three seconds, the two points will meet at the origin. The value in question will be 0 at that moment. Sample Input 2 5 -7 -10 U 7 -6 U -8 7 D -3 3 D 0 -6 R Sample Output 2 97.5 The answer may not be an integer. Sample Input 3 20 6 -10 R -4 -9 U 9 6 D -3 -2 R 0 7 D 4 5 D 10 -10 U -1 -8 U 10 -6 D 8 -5 U 6 4 D 0 3 D 7 9 R 9 -4 R 3 10 D 1 9 U 1 -6 U 9 -8 R 6 7 D 7 -3 D Sample Output 3 273 | 37,326 |
Problem C: Manhattan Warp Machine 1 Problem ãšããå®å®ã§ã¯ã1次å
ã®æŽæ°åº§æšç¹äžã«æãååšããå®å®äººéã¯ãã³ããã¿ã³ã¯ãŒãè£
眮ã䜿ããæéãç§»åããŠããã ãã®ã¯ãŒãè£
眮ã«ã¯ã N åã®ãã¿ã³ãä»ããŠããããã¿ã³ i ãæŒããšãçŸåšããæããã®ãã³ããã¿ã³è·é¢ã d i ã§ããä»»æã®æã«ã³ã¹ã c i ã§ã¯ãŒãããããšãã§ããã ä»ãç¹0ã®æã«ããããå®å®äººãç¹ x ã®æã«è¡ããããšèããŠããã ç¹ x ã®æã«èŸ¿ãçããŸã§ã®æå°ã®ã³ã¹ããçããã 蟿ãçããªãå Žåã¯-1ãåºåããã 1次å
äžã®æŽæ°åº§æšç¹ã«ã¯å¿
ãæãååšããã ç¹ x 1 ãšç¹ x 2 éã®ãã³ããã¿ã³è·é¢ã¯| x 1 - x 2 |ã§è¡šãããã Input N x d 1 c 1 ... d N c N å
¥åã¯å
šãп޿°ã§äžããããã 1è¡ç®ã« N ãšè¡ãããæã®åº§æš x ã空çœåºåãã§äžããããã ç¶ã N è¡ã«ãç§»åå¯èœãªãã³ããã¿ã³è·é¢ d i ãšã³ã¹ã c i ã1è¡ãã€ç©ºçœåºåãã§äžããããã Constraints å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã 1 †N †15 0 †x †10 5 1 †d i †10 5 1 †c i †100 äžãããããã³ããã¿ã³è·é¢ d i ã¯å
šãŠç°ãªãã Output ç¹ x ã®æã«èŸ¿ãçããŸã§ã«ãããæå°ã³ã¹ãã1è¡ã«åºåããã蟿ãçãããšãäžå¯èœãªå Žåã¯-1ãåºåããã Sample Input 1 2 5 1 1 2 1 Sample Output 1 3 Sample Input 2 2 12 9 1 3 2 Sample Output 2 3 Sample Input 3 1 3 4 1 Sample Output 3 -1 | 37,327 |
Score : 900 points Problem Statement For a positive integer n , let us define f(n) as the number of digits in base 10 . You are given an integer S . Count the number of the pairs of positive integers (l, r) ( l \leq r ) such that f(l) + f(l + 1) + ... + f(r) = S , and find the count modulo 10^9 + 7 . Constraints 1 \leq S \leq 10^8 Input Input is given from Standard Input in the following format: S Output Print the answer. Sample Input 1 1 Sample Output 1 9 There are nine pairs (l, r) that satisfies the condition: (1, 1) , (2, 2) , ... , (9, 9) . Sample Input 2 2 Sample Output 2 98 There are 98 pairs (l, r) that satisfies the condition, such as (1, 2) and (33, 33) . Sample Input 3 123 Sample Output 3 460191684 Sample Input 4 36018 Sample Output 4 966522825 Sample Input 5 1000 Sample Output 5 184984484 | 37,328 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.