task stringlengths 0 154k | __index_level_0__ int64 0 39.2k |
|---|---|
Problem C: Unhappy Class Problem å±±ä¹åŸ¡è¹åŠåã®1幎Gçµã¯ãäžå¹žãèè² ã£ã女åçåŸãã¡ãéãŸãã¯ã©ã¹ã§ããã 圌女ãã¡ã¯ã幞çŠã«ãªãããšãç®æšã«ãæ¥ã
æ§ã
ãªè©Šç·Žã«ç«ã¡åããã 圌女ãã¡ã®ã¯ã©ã¹ã§ã¯ã幞çŠã«ãªãããã®è©Šç·Žã®äžç°ãšããŠã幞çŠå®æç§ç®ãåè¬ããããšãã§ããã ææããéæã®ãããã1éãã N éãŸã§ã«ææ¥ç§ç®ã®æ ãããã M åã®åè¬å¯èœãªç§ç®ãããã ç§ç® i ã¯ãææ¥ d i ( d i = 0, 1, 2, 3, 4ããããããææãç«æãæ°Žæãæšæãéæã«å¯Ÿå¿ãã)ã® a i éç®ããå§ãŸããé£ç¶ãã k i ã³ãã§è¡ããããããåè¬ãããšãã«åŸããã幞çŠåºŠã¯ t i ã§ããã åçåŸã¯ãæå€§ L åã®ç§ç®ãäºãã«éãªããªãããã«èªç±ã«éžã¶ããšãã§ãããã©ã®ããã«ç§ç®ãéžã¹ã°ãæãé«ã幞çŠåºŠãåŸãããã ããããäžããããç§ç®ã®æ
å ±ãããåŸããã幞çŠåºŠã®æå€§å€ãæ±ããŠã»ããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã N M L d 1 a 1 k 1 t 1 d 2 a 2 k 2 t 2 ... d M a M k M t M 1è¡ç®ã«3ã€ã®æŽæ° N , M , L ã空çœåºåãã§äžããããã 2è¡ç®ãã M +1è¡ç®ã«4ã€ã®æŽæ° d i , a i , k i , t i ã空çœåºåãã§äžããããã Constraints 2 †N †8 0 †M †300 0 †L †min( N Ã5, M ) 0 †d i †4 1 †a i †N 1 †k i a i + k i - 1 †N 1 †t i †100 Output 幞çŠåºŠã®åã®æå€§å€ã1è¡ã«åºåããã Sample Input 1 3 7 3 0 1 1 1 0 1 1 2 1 1 3 4 1 1 1 1 1 2 1 2 2 1 1 3 2 2 2 1 Sample Output 1 9 Sample Input 2 5 10 5 0 1 1 2 0 2 1 2 0 1 2 3 1 2 1 2 1 4 2 3 2 1 1 1 2 1 1 2 3 3 2 3 4 1 1 2 4 2 1 2 Sample Output 2 13 | 37,544 |
ãµãŒãžã§ã³ãã»ã©ã€ã¢ã³ ãã©ã€ã¢ã³è»æ¹ãæãããšããæä»€ã®ããšãã¢ã€ã
è»ã®æåºéšéã¯ãã€ããªãŒã®æ°Žäžéœåžã§æµè»ãšæ¿ããæŠéãç¹°ãåºããŠããŸããã圌ãã¯ç¡äºã«è»æ¹ãšåæµããŸããããæµã®æŠè»ãå€ããæåºããªãåŒã¹ãã«ããŸãããããã§ã圌ãã¯æµã®æŠè»ãæ··ä¹±ããããããéœåžã«ããæ©ãå
šãŠçç ŽãããšããäœæŠãå®è¡ããããšã«ããŸããã äœæŠã¯ããã«åžä»€éšã«äŒããããæåºããªã®æºåãé²ããããŸãããæåºããªãé£ã°ãããã«ã¯ããã€æ©ãå
šãŠçç Žãããããäºæž¬ããªããã°ãªããŸãããè»ã®ããã°ã©ãã§ããããªãã®ä»»åã¯ãæåºéšéãå
šãŠã®æ©ã®çç Žã«å¿
èŠãªæéãèšç®ããããšã§ãã æ°Žäžéœåžã¯ N åã®å³¶ã§æ§æãããŠãããå³¶ãšå³¶ãšã®éã«ã¯æ©ãããã£ãŠããŸãããã¹ãŠã®å³¶ã¯ããªãŒç¶ã«ç¹ãã£ãŠããŸã(äžå³åç
§) ãããå³¶ããããå³¶ãžã®çµè·¯ã¯ãäžéãã ãååšããŸããåæ©ãæž¡ãã«ã¯ãæ©ããšã«æ±ºããããæéãããããã©ã¡ãã®æ¹åã«ããã®æéã§æ©ãæž¡ãããšãå¯èœã§ãã æåºéšéã¯ããŒããªã©æ°Žäžãç§»åããææ®µãæã£ãŠããªãã®ã§å³¶ãšå³¶ã®éãç§»åããã«ã¯æ©ãéãä»ãããŸãããæåºéšéã¯ããã®æããå³¶ã«é£æ¥ããŠããæ©ã®ãã¡ãå¿
èŠãªãã®ãäžç¬ã§çç Žããããšãã§ããŸããæåºéšéãå
šãŠã®æ©ãçç Žããã®ã«å¿
èŠãªæå°ã®æéã¯ãããã§ããããããã ããå³¶ã®äžã§ã®ç§»åæéã¯èããŸããã å³¶ã®æ°ãããããã®æ©æ
å ±ãå
¥åãšããæ©ãå
šãŠçç Žããã®ã«å¿
èŠãªæå°ã®æéãåºåããããã°ã©ã ãäœæããŠãã ãããå³¶ã¯ãããã 1 ãã N ã®çªå·ã§è¡šãããŸããæ©ã¯ N -1 æ¬ãããŸããæ©æ
å ±ã¯ããã®æ©ã飿¥ããŠããäºã€ã®å³¶ã®çªå·( a , b )ãšããã®æ©ãæž¡ãã®ã«å¿
èŠãªæé t ã§æ§æãããŸããæåºéšéã¯å³¶çªå· 1 ã®å³¶ããã¹ã¿ãŒããããã®ãšããŸãã Input è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžãããããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºããããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããã N a 1 b 1 t 1 a 2 b 2 t 2 : a N-1 b N-1 t N-1 å
¥åã¯ãã¹ãп޿°ã§äžããããã1 è¡ç®ã«å³¶ã®æ° N (2 †N †20) ãäžããããã ç¶ã N -1 è¡ã« i çªç®ã®æ©ã®æ
å ±ãäžããããã a i , b i , t i (1 †t i †500) ã¯ã i çªç®ã®æ©ãéã£ãŠå³¶ a i ãšå³¶ b i ã®éãæé t i ã§ç§»åã§ããããšã衚ãã ããŒã¿ã»ããã®æ°ã¯ 100 ãè¶
ããªãã Output ããŒã¿ã»ããããšã«ãæ©ãå
šãŠçç Žããã®ã«å¿
èŠãªæå°ã®æéã1è¡ã«åºåããã Sample Input 7 1 2 5 2 3 2 3 4 3 2 5 3 5 6 3 5 7 8 0 Output for the Sample Input 12 | 37,545 |
ã«ããµã³ã (Cutlet Sandwich) ããäžçã«ã¯ã $X$ çš®é¡ã®ããµã³ããã $Y$ çš®é¡ã®ãã«ããã $Z$ çš®é¡ã®ãã«ã¬ãŒããšããé£ã¹ç©ããããŸãã ãã®äžçã«ã¯ $N$ çš®é¡ã®ãã«ããµã³ãããšããé£ã¹ç©ãããã $i$ çš®é¡ç®ã®ã«ããµã³ã㯠$A_i$ çš®é¡ç®ã®ãµã³ããš $B_i$ çš®é¡ç®ã®ã«ããåæã§ãã ãŸãã $M$ çš®é¡ã®ãã«ãã«ã¬ãŒããšããé£ã¹ç©ãããã $i$ çš®é¡ç®ã®ã«ãã«ã¬ãŒã¯ $C_i$ çš®é¡ç®ã®ã«ããš $D_i$ çš®é¡ç®ã®ã«ã¬ãŒãåæã§ãã Segtree åã¯ãããã«ããµã³ããŸãã¯ã«ãã«ã¬ãŒãæã£ãŠãããšããåæã®ãã¡å°ãªããšã $1$ ã€ãå
±éããŠãããããªã«ããµã³ããŸãã¯ã«ãã«ã¬ãŒãšäº€æããããšãã§ããŸãã äŸãã°ã$a$ çš®é¡ç®ã®ãµã³ããš $b$ çš®é¡ç®ã®ã«ããåæã§ããã«ããµã³ããæã£ãŠãããšãã $a$ çš®é¡ç®ã®ãµã³ããŸã㯠$b$ çš®é¡ç®ã®ã«ããåæã«æã€ä»»æã®ã«ããµã³ãããŸãã¯ã $b$ çš®é¡ç®ã®ã«ããåæã«å«ãä»»æã®ã«ãã«ã¬ãŒãšäº€æã§ããŸãã ä»ã Segtree å㯠$S$ çš®é¡ç®ã®ã«ããµã³ããæã£ãŠããŸãããé£ã¹ããã®ã¯ $T$ çš®é¡ç®ã®ã«ãã«ã¬ãŒã§ãã $T$ çš®é¡ç®ã®ã«ãã«ã¬ãŒãæã«å
¥ããããšãã§ãããå€å®ããŠãã ãããããå¯èœãªãã°ãæå°äœåã®äº€æã§ç®çã®ã«ãã«ã¬ãŒãæã«ããããããæ±ããŠãã ããã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããã $X$ $Y$ $Z$ $N$ $M$ $S$ $T$ $A_1$ $B_1$ $A_2$ $B_2$ $\ldots$ $A_N$ $B_N$ $C_1$ $D_1$ $C_2$ $D_2$ $\ldots$ $C_M$ $D_M$ åºå $T$ çš®é¡ç®ã®ã«ãã«ã¬ãŒãæã«å
¥ããããã«å¿
èŠãªæå°ã®äº€æåæ°ãåºåããŠãã ãããæã«å
¥ããããšãäžå¯èœãªãã°ã代ããã«ã $-1$ ããåºåããŠãã ããã ãã ããæåŸã«ã¯æ¹è¡ãå
¥ããããšã å¶çŽ $1 \leq X,Y,Z,N,M \leq 10^5$ $1 \leq S \leq N$ $1 \leq T \leq M$ $1 \leq A_i \leq X$ $1 \leq B_i \leq Y$ $1 \leq C_i \leq Y$ $1 \leq D_i \leq Z$ å
¥åã¯å
šãп޿°ã§ããã å
¥åäŸ1 1 1 1 1 1 1 1 1 1 1 1 åºåäŸ1 1 å
¥åäŸ2 2 3 4 3 5 1 5 1 1 1 2 2 2 2 1 3 1 3 2 3 3 3 4 åºåäŸ2 4 å
¥åäŸ3 1 2 2 1 2 1 1 1 2 1 2 2 1 åºåäŸ3 -1 | 37,546 |
Problem G : Everything Starts With Your Vote ãã¥ãŒãªã¹ãã£ã¯ã¹ãšããèšèãããã確å®ã«ããŸããããšããä¿èšŒã¯ãªãããã©ã倧æµã®å Žåã¯ããŸããããæ¯èŒçåçŽãªã¢ãããŒãã®ããšã ãåçŽã«ããŠåŒ·åã§ãããããã«ããã®äžã®äžã¯å€ãã®ãã¥ãŒãªã¹ãã£ã¯ã¹ã§æºã¡æº¢ããŠããã ãã¥ãŒãªã¹ãã£ã¯ã¹ã®äžäŸãšããŠããããªãã®ãæãããããã¢ãã¡çªçµã«ãããŠããããã£ã©ã¯ã¿ãŒã®äººæ°åºŠã¯ããã®ã¢ãã¡æ¬ç·šäžã«ãããç»å Žæéã®ç·åã«æ¯äŸããã確ãã«ããã¯å€ãã®å Žåã«æãç«ã£ãŠããããã ãããããã©ãããåã¯å°æ°æŽŸã«å±ãããããã圱ã®èããã£ã©ãèæ¯ã«ã¡ãããšæ ãã¢ããã£ã©ãªããã«éã£ãŠå¯æãèŠãããããã®ã ã èªåã®å¥œããªãã£ã©ã®ããšããä»äººãã©ãæã£ãŠãããããããããªããããšã¯èšã£ãŠãããªãäºæ
ããæ®å¿µãªãããããé¢é£ååããã£ã®ã¥ã¢ããã£ã©ã¯ã¿ãŒãœã³ã°CDãªã©ã¯ã人æ°ã®ãããã£ã©ã®ãã®ããåªå
çã«çºå£²ãããåŸåã«ããã®ã ã忥çã«ã¯åœç¶ã®éžæã ãšã¯ãããäžäººæ°ãã£ã©ã®ãã¡ã³ã®è©èº«ã¯çãã ããã§éèŠãšãªã£ãŠããã®ããã¢ãã¡çªçµã®å¶äœäŒç€Ÿã«ãã£ãŠè¡ãããäººæ°æç¥šã§ãããå®éã®äººæ°ãã©ãã§ãããããã§å€ãã®ç¥šãç²åŸããã°ãé¢é£ååãžã®éãéãããã®ã ãã©ããªææ®µã䜿ã£ãŠã祚ãéããã°ãªããŸãã 峿£ãªãæç¥šã®ããã«ãããé¢é£ååã1ã€è³Œå
¥ãããã³ã«1ç¥šã®æç¥šæš©ãäžããããããã®ä»çµã峿£ãšåŒã¶ã¹ããã©ããã¯ä»å€§ããè°è«ãããŠãããããšã«ããå㯠L ç¥šã®æç¥šæš©ãåŸããæç¥šã®å¯Ÿè±¡ãšãªããã£ã©ã¯å
šéšã§ N 人ããŠãããå€ãã®ç¥šãç²åŸãã K 人ã®ãã£ã© (å祚ã®å Žåã¯ååã®èŸæžé ) ã®é¢é£ååãäŒç»ãããããšã«ãªããåã®å¥œããªãã£ã©ã¯å
šéšã§ M 人ããŠããã®äžããã§ããã ãå€ãã®ãã£ã©ãäžäœ K 人ã«å
¥ããããšæã£ãŠããã åã¯ãŸããããããã®ãã£ã©ãã©ãã ãã®ç¥šãç²åŸããããäºæž¬ãã(é£ããããšã§ã¯ãªãããããã£ã©ã¯ã¿ãŒã®äººæ°åºŠã¯ããã®ç»å Žæéã®ç·åã«æ¯äŸãããšä»®å®ããã ãã )ããã®äºæž¬ãæ£ãããšããŠãããå€ãã®åã®å¥œããªãã£ã©ã®é¢é£ååãçºå£²ãããããã«ããããã«ã¯ãåã¯ãã® L 祚ã誰ã«ã©ãã ãæããã°ããã ãããã Input å
¥åã¯è€æ°ã®ã±ãŒã¹ãããªãã åã±ãŒã¹ã¯ä»¥äžã®ãã©ãŒãããã§äžããããã N M K L name 0 x 0 . . . name N-1 x N-1 fav 0 . . . fav M-1 N ã M ã K ã L ã®æå³ã¯å顿ã«èšãããŠãããšããã§ããã name i ã¯ãã£ã©ã¯ã¿ãŒã®ååã x i 㯠i çªç®ã®ãã£ã©ã¯ã¿ãŒã®ç¥šã®ç·æ°ã衚ãã fav i ã¯ããªããã²ããããŠãããã£ã©ã¯ã¿ãŒã®ååã衚ãããããã®ååã¯å¿
ãç°ãªãããŸãå¿
ããã£ã©ã¯ã¿ãŒã®ååã®å
¥åã®äžã«å«ãŸããã å
¥åã®çµãã㯠N = 0 ã〠M = 0 ã〠K = 0 ã〠L = 0ãããªãè¡ã«ãã£ãŠäžãããã ãŸãåå€ã¯ä»¥äžã®æ¡ä»¶ãæºãã 1 †N †100,000 1 †M †N 1 †K †N 1 †L †100,000,000 0 †x i †100,000,000 name i ã¯ã¢ã«ãã¡ãããã®ã¿ãå«ã¿ãé·ãã¯10æå以äžã§ããã ãã¹ãã±ãŒã¹ã®æ°ã¯150ãè¶
ããªãã ãŸã20,000 †N ãšãªãã±ãŒã¹ã®æ°ã¯20ãè¶
ããªãããšãä¿èšŒãããŠããã ãžã£ããžããŒã¿ã¯å€§ããã®ã§ãéãå
¥åã䜿ãããšãæšå¥šããã Output M 人ã®ãã£ã©ã®äžããæå€§ã§äœäººãäžäœ K 人ã«å
¥ããããšãåºæ¥ããã1è¡ã§åºåããã Sample input 4 1 3 4 yskwcnt 16 akzakr 7 tsnukk 12 fnmyi 13 akzakr 4 1 3 5 akzakr 7 tsnukk 12 fnmyi 13 yskwcnt 16 akzakr 4 2 2 1 akzakr 4 tsnukk 6 yskwcnt 6 fnmyi 12 akzakr fnmyi 5 2 3 28 knmmdk 6 skrkyk 14 tmemm 14 akmhmr 15 mksyk 25 knmmdk skrkyk 5 2 3 11 tmemm 12 skrkyk 18 knmmdk 21 mksyk 23 akmhmr 42 skrkyk tmemm 14 5 10 38 iormns 19 hbkgnh 23 yyitktk 31 rtkakzk 36 mmftm 43 ykhhgwr 65 hrkamm 66 ktrotns 67 mktkkc 68 mkhsi 69 azsmur 73 tknsj 73 amftm 81 chyksrg 88 mkhsi hbkgnh mktkkc yyitktk tknsj 14 5 10 38 mktkkc 24 rtkakzk 25 ykhhgwr 25 hrkamm 27 amftm 37 iormns 38 tknsj 38 yyitktk 39 hbkgnh 53 mmftm 53 chyksrg 63 ktrotns 63 azsmur 65 mkhsi 76 mkhsi hbkgnh mktkkc yyitktk tknsj 0 0 0 0 Sample output 0 1 1 2 1 4 5 The University of Aizu Programming Contest 2011 Summer åæ¡: Tomoya Sakai å顿: Takashi Tayama | 37,547 |
Score : 200 points Problem Statement Given N integers A_1, ..., A_N , compute A_1 \times ... \times A_N . However, if the result exceeds 10^{18} , print -1 instead. Constraints 2 \leq N \leq 10^5 0 \leq A_i \leq 10^{18} 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 value A_1 \times ... \times A_N as an integer, or -1 if the value exceeds 10^{18} . Sample Input 1 2 1000000000 1000000000 Sample Output 1 1000000000000000000 We have 1000000000 \times 1000000000 = 1000000000000000000 . Sample Input 2 3 101 9901 999999000001 Sample Output 2 -1 We have 101 \times 9901 \times 999999000001 = 1000000000000000001 , which exceeds 10^{18} , so we should print -1 instead. Sample Input 3 31 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 0 Sample Output 3 0 | 37,548 |
D: æ°Žæ§œ åé¡ AORã€ã«ã¡ããã¯çžŠ $1$ 暪 $N$ ã®å€§ããã®æ°Žæ§œãããã£ããæ°Žæ§œã¯æ°Žãå
¥ããã®ã«ååãªé«ããããã æ°Žæ§œã«ã¯ $N-1$ åã®ä»åãããã $N$ åã®åºç»ã«çééã«åºåãããŠããã ããã«æ°Žã泚ãã ãšãããååºç»ã®æ°Žã®é«ã㯠$a_i$ ã«ãªã£ãã AORã€ã«ã¡ããã¯ããã€ãä»åããåãé€ããåºç»ã®æ°ã $M$ å以äžã«ããããšã«ããã ä»åããåãé€ãçµãã£ãæãååºç»ã®æ°Žã®é«ãã®ç·åã®æå€§å€ãæ±ããã ãªããä»åãã®åãã¯ç¡èŠã§ãããã®ãšããã å¶çŽ $1 \le N \le 500$ $1 \le M \le N$ $1 \le a_i \le 10^9$ å
¥åã¯å
šãп޿° å
¥å $N \ M$ $a_1 \cdots a_N$ åºå ååºç»ã®æ°Žã®é«ãã®ç·åã®æå€§å€ãäžè¡ã§åºåããããŸãæ«å°Ÿã«æ¹è¡ãåºåããã çžå¯Ÿèª€å·®ãŸãã¯çµ¶å¯Ÿèª€å·®ã $10^{-6}$ 以äžã§ããã°èš±å®¹ãããã ãµã³ãã« ãµã³ãã«å
¥å 1 5 3 9 1 2 3 9 ãµã³ãã«åºå 1 20.000000 $a_2$ ãš $a_3$ ã$a_3$ ãš $a_4$ ã®éã®ä»åãããšããšããã®åºç»ã®æ°Žã®é«ã㯠$\frac{(1 + 2 + 3)}{3} = 2$ ãšãªãã ååºç»ã®æ°Žã®é«ã㯠$9 \ 2 \ 9$ ãšãªããããæå€§ã§ããã ãµã³ãã«å
¥å 2 4 1 14 4 9 7 ãµã³ãã«åºå 2 8.500000 ãµã³ãã«å
¥å 3 8 3 11 18 9 20 4 18 12 14 ãµã³ãã«åºå 3 44.666667 | 37,549 |
Lake Survery The Onogawa Expedition is planning to conduct a survey of the Aizu nature reserve. The expedition planner wants to take the shortest possible route from the start to end point of the survey, while the expedition has to go around the coast of the Lake of Onogawa en route. The expedition walks along the coast of the lake, but can not wade across the lake. Based on the base information including the start and end point of the survey and the area of Lake Onogawa as convex polygon data, make a program to find the shortest possible route for the expedition and calculate its distance. Note that the expedition can move along the polygonal lines passing through the nodes, but never enter within the area enclosed by the polygon. Input The input is given in the following format. x_s y_s x_g y_g N x_1 y_1 x_2 y_2 : x_N y_N The first line provides the start point of the survey x_s,y_s (0†x_s,y_s â€10 4 ), and the second line provides the end point x_g,y_g (0 †x_g,y_g †10 4 ) all in integers. The third line provides the number of apexes N (3 †N †100) of the polygon that represents the lake, and each of the subsequent N lines provides the coordinate of the i -th apex x_i,y_i (0 †x_i,y_i †10 4 ) in counter-clockwise order. These data satisfy the following criteria: Start and end points of the expedition are not within the area enclosed by the polygon nor on boundaries. Start and end points of the expedition are not identical, i.e., x_s â x_g or y_s â y_g . No duplicate coordinates are given, i.e., if i â j then x_i â x_r or y_i â y_j . The area enclosed by the polygon has a positive value. Any three coordinates that define an area are not aligned on a line. Output Output the distance of the shortest possible expedition route. Any number of decimal places can be selected as long as the error does not exceed ± 10 -3 . Sample Input 1 0 0 4 0 4 1 1 2 1 3 3 1 2 Sample Output 1 4.472136 Sample Input 2 4 4 0 0 4 1 1 3 1 3 3 1 3 Sample Output 2 6.32455 | 37,550 |
C: çŽ æ° åé¡ ããæ¥ãçŽ æ°ã倧奜ããªããããå㯠$p + q$ ãçŽ æ°ãšãªãã㢠$(p, q)$ ã§éãã§ããã ããããåã¯çªç¶ããã®ãã¢ã®ãã¡ã $p$ ãš $q$ ããšãã« $N$ 以äžã®çŽ æ°ã§ãããã¢ãããã€ãããæ°ã«ãªãã ããã ããããåã«ä»£ãã£ãŠåæ°ãæ±ããã å¶çŽ å
¥åå€ã¯å
šãп޿°ã§ããã $1 \leq N \leq 10^7$ å
¥ååœ¢åŒ å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã $N$ åºå ãã¢ã®åæ°ãåºåããããŸããæ«å°Ÿã«æ¹è¡ãåºåããã ãµã³ãã« ãµã³ãã«å
¥å 1 3 ãµã³ãã«åºå 1 2 ãã¢ã¯ $(2, 3), (3, 2)$ ã®äºã€ã§ããã ãµã³ãã«å
¥å 2 20 ãµã³ãã«åºå 2 8 | 37,551 |
Problem E: Earth Observation with a Mobile Robot Team A new type of mobile robot has been developed for environmental earth observation. It moves around on the ground, acquiring and recording various sorts of observational data using high precision sensors. Robots of this type have short range wireless communication devices and can exchange observational data with ones nearby. They also have large capacity memory units, on which they record data observed by themselves and those received from others. Figure 1 illustrates the current positions of three robots A, B, and C and the geographic coverage of their wireless devices. Each circle represents the wireless coverage of a robot, with its center representing the position of the robot. In this figure, two robots A and B are in the positions where A can transmit data to B, and vice versa. In contrast, C cannot communicate with A or B, since it is too remote from them. Still, however, once B moves towards C as in Figure 2, B and C can start communicating with each other. In this manner, B can relay observational data from A to C. Figure 3 shows another example, in which data propagate among several robots instantaneously. Figure 1: The initial configuration of three robots Figure 2: Mobile relaying Figure 3: Instantaneous relaying among multiple robots As you may notice from these examples, if a team of robots move properly, observational data quickly spread over a large number of them. Your mission is to write a program that simulates how information spreads among robots. Suppose that, regardless of data size, the time necessary for communication is negligible. Input The input consists of multiple datasets, each in the following format. N T R nickname and travel route of the first robot nickname and travel route of the second robot ... nickname and travel route of the N-th robot The first line contains three integers N , T , and R that are the number of robots, the length of the simulation period, and the maximum distance wireless signals can reach, respectively, and satisfy that 1 <= N <= 100, 1 <= T <= 1000, and 1 <= R <= 10. The nickname and travel route of each robot are given in the following format. nickname t 0 x 0 y 0 t 1 vx 1 vy 1 t 2 vx 2 vy 2 ... t k vx k vy k Nickname is a character string of length between one and eight that only contains lowercase letters. No two robots in a dataset may have the same nickname. Each of the lines following nickname contains three integers, satisfying the following conditions. 0 = t 0 < t 1 < ... < t k = T -10 <= vx 1 , vy 1 , ..., vx k , vy k <= 10 A robot moves around on a two dimensional plane. ( x 0 , y 0 ) is the location of the robot at time 0. From time t i -1 to t i (0 < i <= k ), the velocities in the x and y directions are vx i and vy i , respectively. Therefore, the travel route of a robot is piecewise linear. Note that it may self-overlap or self-intersect. You may assume that each dataset satisfies the following conditions. The distance between any two robots at time 0 is not exactly R. The x - and y -coordinates of each robot are always between -500 and 500, inclusive. Once any robot approaches within R + 10 -6 of any other, the distance between them will become smaller than R - 10 -6 while maintaining the velocities. Once any robot moves away up to R - 10 -6 of any other, the distance between them will become larger than R + 10 -6 while maintaining the velocities. If any pair of robots mutually enter the wireless area of the opposite ones at time t and any pair, which may share one or two members with the aforementioned pair, mutually leave the wireless area of the opposite ones at time t' , the difference between t and t' is no smaller than 10 -6 time unit, that is, | t - t' | >= 10 -6 . A dataset may include two or more robots that share the same location at the same time. However, you should still consider that they can move with the designated velocities. The end of the input is indicated by a line containing three zeros. Output For each dataset in the input, your program should print the nickname of each robot that have got until time T the observational data originally acquired by the first robot at time 0. Each nickname should be written in a separate line in dictionary order without any superfluous characters such as leading or trailing spaces. Sample Input 3 5 10 red 0 0 0 5 0 0 green 0 5 5 5 6 1 blue 0 40 5 5 0 0 3 10 5 atom 0 47 32 5 -10 -7 10 1 0 pluto 0 0 0 7 0 0 10 3 3 gesicht 0 25 7 5 -7 -2 10 -1 10 4 100 7 impulse 0 -500 0 100 10 1 freedom 0 -491 0 100 9 2 destiny 0 -472 0 100 7 4 strike 0 -482 0 100 8 3 0 0 0 Output for the Sample Input blue green red atom gesicht pluto freedom impulse strike | 37,552 |
Shifting a Matrix You are given $N \times N$ matrix $A$ initialized with $A_{i,j} = (i - 1)N + j$, where $A_{i,j}$ is the entry of the $i$-th row and the $j$-th column of $A$. Note that $i$ and $j$ are 1-based. You are also given an operation sequence which consists of the four types of shift operations: left, right, up, and down shifts. More precisely, these operations are defined as follows: Left shift with $i$: circular shift of the $i$-th row to the left, i.e., setting previous $A_{i,k}$ to new $A_{i,k-1}$ for $2 \leq k \leq N$, and previous $A_{i,1}$ to new $A_{i,N}$. Right shift with $i$: circular shift of the $i$-th row to the right, i.e., setting previous $A_{i,k}$ to new $A_{i,k+1}$ for $1 \leq k \leq N - 1$, and previous $A_{i,N}$ to new $A_{i,1}$. Up shift with $j$: circular shift of the $j$-th column to the above, i.e., setting previous $A_{k,j}$ to new $A_{k-1,j}$ for $2 \leq k \leq N$, and previous $A_{1,j}$ to new $A_{N,j}$. Down shift with $j$: circular shift of the $j$-th column to the below, i.e., setting previous $A_{k,j}$ to new $A_{k+1,j}$ for $1 \leq k \leq N - 1$, and previous $A_{N,j}$ to new $A_{1,j}$. An operation sequence is given as a string. You have to apply operations to a given matrix from left to right in a given string. Left, right, up, and down shifts are referred as 'L', 'R', 'U', and 'D' respectively in a string, and the following number indicates the row/column to be shifted. For example, "R25" means we should perform right shift with 25. In addition, the notion supports repetition of operation sequences. An operation sequence surrounded by a pair of parentheses must be repeated exactly $m$ times, where $m$ is the number following the close parenthesis. For example, "(L1R2)10" means we should repeat exactly 10 times the set of the two operations: left shift with 1 and right shift with 2 in this order. Given operation sequences are guaranteed to follow the following BNF: <sequence> := <sequence><repetition> | <sequence><operation> | <repetition> | <operation> <repetition> := '('<sequence>')'<number> <operation> := <shift><number> <shift> := 'L' | 'R' | 'U' | 'D' <number> := <nonzero_digit> |<number><digit> <digit> := '0' | <nonzero_digit> <nonzero_digit> := '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' Given $N$ and an operation sequence as a string, make a program to compute the $N \times N$ matrix after operations indicated by the operation sequence. Input The input consists of a single test case. The test case is formatted as follows. $N$ $L$ $S$ The first line contains two integers $N$ and $L$, where $N$ ($1 \leq N \leq 100$) is the size of the given matrix and $L$ ($2 \leq L \leq 1,000$) is the length of the following string. The second line contains a string $S$ representing the given operation sequence. You can assume that $S$ follows the above BNF. You can also assume numbers representing rows and columns are no less than 1 and no more than $N$, and the number of each repetition is no less than 1 and no more than $10^9$ in the given string. Output Output the matrix after the operations in $N$ lines, where the $i$-th line contains single-space separated $N$ integers representing the $i$-th row of $A$ after the operations. Sample Input 1 3 2 R1 Output for the Sample Input 1 3 1 2 4 5 6 7 8 9 Sample Input 2 3 7 (U2)300 Output for the Sample Input 2 1 2 3 4 5 6 7 8 9 Sample Input 3 3 7 (R1D1)3 Output for the Sample Input 3 3 4 7 1 5 6 2 8 9 | 37,553 |
A Two Floors Dungeon It was the last day of the summer camp you strayed into the labyrinth on the way to Komaba Campus, the University of Tokyo. The contest has just begun. Your teammates must impatiently wait for you. So you have to escape from this labyrinth as soon as possible. The labyrinth is represented by a grid map. Initially, each grid except for walls and stairs is either on the first floor or on the second floor. Some grids have a switch which can move up or down some of the grids (the grids on the first floor move to the second floor, and the grids on the second floor to the first floor). In each step, you can take one of the following actions: Move to an adjacent grid (includes stairs) on the same floor you are now in. Move to another floor (if you are in the stairs grid). Operate the switch (if you are in a grid with a switch). Luckily, you have just found a map of the labyrinth for some unknown reason. Let's calculate the minimum step to escape from the labyrinth, and go to the place your teammates are waiting! Input The format of the input is as follows. W H M 11 M 12 M 13 ...M 1W M 21 M 22 M 23 ...M 2W ........ M H1 M H2 M H3 ...M HW S MS 111 MS 112 MS 113 ...MS 11W MS 121 MS 122 MS 123 ...MS 12W ........ MS 1H1 MS 1H2 MS 1H3 ...MS 1HW MS 211 MS 212 MS 213 ...MS 21W MS 221 MS 222 MS 223 ...MS 22W ........ MS 2H1 MS 2H2 MS 2H3 ...MS 2HW MS S11 MS S12 MS S13 ...MS S1W MS S21 MS S22 MS S23 ...MS S2W ........ MS SH1 MS SH2 MS SH3 ...MS SHW The first line contains two integers W ( 3 †W †50 ) and H ( 3 †H †50 ). They represent the width and height of the labyrinth, respectively. The following H lines represent the initial state of the labyrinth. Each of M ij is one of the following symbols: '#' representing a wall, '|' representing stairs, '_' representing a grid which is initially on the first floor, '^' representing a grid which is initially on the second floor, a lowercase letter from 'a' to 'j' representing a switch the grid has, and the grid is initially on the first floor, an uppercase letter from 'A' to 'J' representing a switch the grid has, and the grid is initially on the second floor, '%' representing the grid you are initially in (which is initially on the first floor) or '&' representing the exit of the labyrinth (which is initially on the first floor). The next line contains one integer S ( 0 †S †10 ), and then the following SH lines represent the information of the switches. Each of MS kij is one of: '#' if M ij is a '#', '|' if M ij is a '|', '*' if the grid is moved by the switch represented by the k -th alphabet letter, or '.' otherwise. Note that the grid which contains a switch may be moved by operating the switch. In this case, you will move together with the grid. You may assume each of the '%' (start) and '&' (goal) appears exacyly once, that the map is surround by walls, and that each alphabet in the map is any of the letters from 'A' (or 'a') to S -th alphabet letter. Output Print the minimum step to reach the goal in one line. If there is no solution, print "-1". Sample Input 1 6 6 ###### #_|A%# #B#_|# #^BBa# #B&A## ###### 2 ###### #*|*.# #.#.|# #*.**# #...## ###### ###### #*|*.# #*#.|# #..**# #..*## ###### Output for the Sample Input 1 21 Sample Input 2 8 3 ######## #%||Aa&# ######## 2 ######## #*||*..# ######## ######## #.||*.*# ######## Output for the Sample Input 2 7 Sample Input 3 3 4 ### #%# #&# ### 0 Output for the Sample Input 3 1 Sample Input 4 3 5 ### #%# #^# #&# ### 0 Output for the Sample Input 4 -1 | 37,554 |
Problem A: Keitai Message Alice ãã㯠Miku ããã«æºåž¯é»è©±ã§ã¡ãŒã«ãéãããšããŠããã æºåž¯é»è©±ã«ã¯å
¥åã«äœ¿ãããã¿ã³ã¯æ°åã®ãã¿ã³ãããªãã ããã§ãæåã®å
¥åãããããã«æ°åãã¿ã³ãäœåºŠãæŒããŠæåã®å
¥åãè¡ããæºåž¯é»è©±ã®æ°åãã¿ã³ã«ã¯ãæ¬¡ã®æåãå²ãåœãŠãããŠããããã¿ã³ 0 ã¯ç¢ºå®ãã¿ã³ãå²ãåœãŠãããŠããããã®æºåž¯é»è©±ã§ã¯ 1 æåã®å
¥åãçµãã£ããå¿
ã確å®ãã¿ã³ãæŒãããšã«ãªã£ãŠããã 1: . , ! ? (ã¹ããŒã¹) 2: a b c 3: d e f 4: g h i 5: j k l 6: m n o 7: p q r s 8: t u v 9: w x y z 0: 確å®ãã¿ã³ äŸãã°ããã¿ã³ 2ããã¿ã³ 2ããã¿ã³ 0 ãšæŒããšãæåã 'a' â 'b' ãšå€åããããã§ç¢ºå®ãã¿ã³ãæŒãããã®ã§ãæå b ãåºåãããã åãæ°åãç¶ããŠå
¥åãããšå€åããæåã¯ã«ãŒããããããªãã¡ããã¿ã³ 2 ã 5 åæŒããŠã次ã«ãã¿ã³ 0 ãæŒããšãæåã 'a' â 'b' â 'c' â 'a' â 'b' ãšå€åããããã§ç¢ºå®ãã¿ã³ãæŒããããã 'b' ãåºåãããã äœããã¿ã³ãæŒãããŠããªããšãã«ç¢ºå®ãã¿ã³ãæŒãããšã¯ã§ãããããã®å Žåã«ã¯äœãæåã¯åºåãããªãã ããªãã®ä»äºã¯ãAlice ãããæŒãããã¿ã³ã®åãããAlice ãããäœã£ãã¡ãã»ãŒãžãåçŸããããšã§ããã Input æåã®è¡ã«ãã¹ãã±ãŒã¹ã®æ°ãäžããããã ç¶ããŠåãã¹ãã±ãŒã¹ã«ã€ããŠãæå€§ã§é·ã 1024 ã®æ°ååã1è¡ã§äžããããã Output Alice ãããäœã£ãã¡ãã»ãŒãžã®æååãããããã®ãã¹ãã±ãŒã¹ã«ã€ã㊠1 è¡ããšã«åºåããã ãã ããåºå㯠1 æåä»¥äž 76 æåæªæºã§ãããšä»®å®ããŠããã Sample Input 5 20 220 222220 44033055505550666011011111090666077705550301110 000555555550000330000444000080000200004440000 Output for the Sample Input a b b hello, world! keitai | 37,555 |
Score: 600 points Problem Statement AtCoder's head office consists of N rooms numbered 1 to N . For any two rooms, there is a direct passage connecting these rooms. For security reasons, Takahashi the president asked you to set a level for every passage, which is a positive integer and must satisfy the following condition: For each room i\ (1 \leq i \leq N) , if we leave Room i , pass through some passages whose levels are all equal and get back to Room i , the number of times we pass through a passage is always even. Your task is to set levels to the passages so that the highest level of a passage is minimized. Constraints N is an integer between 2 and 500 (inclusive). Input Input is given from Standard Input in the following format: N Output Print one way to set levels to the passages so that the objective is achieved, as follows: a_{1,2} a_{1,3} ... a_{1,N} a_{2,3} ... a_{2,N} . . . a_{N-1,N} Here a_{i,j} is the level of the passage connecting Room i and Room j . If there are multiple solutions, any of them will be accepted. Sample Input 1 3 Sample Output 1 1 2 1 The following image describes this output: For example, if we leave Room 2 , traverse the path 2 \to 3 \to 2 \to 3 \to 2 \to 1 \to 2 while only passing passages of level 1 and get back to Room 2 , we pass through a passage six times. | 37,556 |
Score : 2000 points Problem Statement You are participating in a quiz with N + M questions and Yes/No answers. It's known in advance that there are N questions with answer Yes and M questions with answer No, but the questions are given to you in random order. You have no idea about correct answers to any of the questions. You answer questions one by one, and for each question you answer, you get to know the correct answer immediately after answering. Suppose you follow a strategy maximizing the expected number of correct answers you give. Let this expected number be P/Q , an irreducible fraction. Let M = 998244353 . It can be proven that a unique integer R between 0 and M - 1 exists such that P = Q \times R modulo M , and it is equal to P \times Q^{-1} modulo M , where Q^{-1} is the modular inverse of Q . Find R . Constraints 1 \leq N, M \leq 500,000 Both N and M are integers. Partial Score 1500 points will be awarded for passing the testset satisfying N = M and 1 \leq N, M \leq 10^5 . Input Input is given from Standard Input in the following format: N M Output Let P/Q be the expected number of correct answers you give if you follow an optimal strategy, represented as an irreducible fraction. Print P \times Q^{-1} modulo 998244353 . Sample Input 1 1 1 Sample Output 1 499122178 There are two questions. You may answer randomly to the first question, and you'll succeed with 50% probability. Then, since you know the second answer is different from the first one, you'll succeed with 100% probability. The expected number of your correct answers is 3 / 2 . Thus, P = 3 , Q = 2 , Q^{-1} = 499122177 (modulo 998244353 ), and P \times Q^{-1} = 499122178 (again, modulo 998244353 ). Sample Input 2 2 2 Sample Output 2 831870297 The expected number of your correct answers is 17 / 6 . Sample Input 3 3 4 Sample Output 3 770074220 The expected number of your correct answers is 169 / 35 . Sample Input 4 10 10 Sample Output 4 208827570 Sample Input 5 42 23 Sample Output 5 362936761 | 37,557 |
Score : 900 points Problem Statement Takahashi has a lot of peculiar devices. These cylindrical devices receive balls from left and right. Each device is in one of the two states A and B, and for each state, the device operates as follows: When a device in state A receives a ball from either side (left or right), the device throws out the ball from the same side, then immediately goes into state B. When a device in state B receives a ball from either side, the device throws out the ball from the other side, then immediately goes into state A. The transition of the state of a device happens momentarily and always completes before it receives another ball. Takahashi built a contraption by concatenating N of these devices. In this contraption, A ball that was thrown out from the right side of the i -th device from the left ( 1 \leq i \leq N-1 ) immediately enters the (i+1) -th device from the left side. A ball that was thrown out from the left side of the i -th device from the left ( 2 \leq i \leq N ) immediately enters the (i-1) -th device from the right side. The initial state of the i -th device from the left is represented by the i -th character in a string S . From this situation, Takahashi performed the following K times: put a ball into the leftmost device from the left side, then wait until the ball comes out of the contraption from either end. Here, it can be proved that the ball always comes out of the contraption after a finite time. Find the state of each device after K balls are processed. Constraints 1 \leq N \leq 200,000 1 \leq K \leq 10^9 |S|=N Each character in S is either A or B . Input The input is given from Standard Input in the following format: N K S Output Print a string that represents the state of each device after K balls are processed. The string must be N characters long, and the i -th character must correspond to the state of the i -th device from the left. Sample Input 1 5 1 ABAAA Sample Output 1 BBAAA In this input, we put a ball into the leftmost device from the left side, then it is returned from the same place. Sample Input 2 5 2 ABAAA Sample Output 2 ABBBA Sample Input 3 4 123456789 AABB Sample Output 3 BABA | 37,558 |
Score : 100 points Problem Statement There is an N -car train. You are given an integer i . Find the value of j such that the following statement is true: "the i -th car from the front of the train is the j -th car from the back." Constraints 1 \leq N \leq 100 1 \leq i \leq N Input Input is given from Standard Input in the following format: N i Output Print the answer. Sample Input 1 4 2 Sample Output 1 3 The second car from the front of a 4 -car train is the third car from the back. Sample Input 2 1 1 Sample Output 2 1 Sample Input 3 15 11 Sample Output 3 5 | 37,559 |
D: ç¢ / Arrow åé¡ rodea å㯠1 次å
座æšç³»ã®äžã«ããã x = 0 ã®å Žæã«ç«ã£ãŠããããã®äœçœ®ããã x = N ã®äœçœ®ã«ããçãç®ãããŠã åžžã«éã 1 ã§ç§»åããæ£ã®æŽæ°ã®é·ãã®ç¢ãæãããããããrodea åã¯éåãªããã åºé 0 \leq x \leq N ã®äžã«åèš M åã®é颚æ©ã眮ãããšã«ããŠããã ããã§ãç¢ã®å
端ããæ ¹å
ãŸã§ã®äœçœ®ã« 1 ã€ã®é颚æ©ãå«ãŸããªãå Žåããæå€±ããšå®çŸ©ãããæå€±ã®å€å®ã¯ãç¢ã®å
端ã x = 1, 2, 3, $\ldots$ , N ã«å°éããéã«è¡ãïŒã€ãŸããåèš N åè¡ãïŒã ãã®ãšãã以äžã®ã¯ãšãªã Q ååŠçããã ãæå€±ã蚱容å¯èœãªåæ° l_i ãäžãããããããªãã¡ã N åã®å€å®ã«ãããŠããæå€±ããåèš l_i å以äžãªãç¢ãçã«å±ããããšãå¯èœã§ããããã®ãšãã®ãç¢ãçã«å±ããããã«å¿
èŠãªæçã®ç¢ã®é·ããæ±ããã å
¥ååœ¢åŒ N M m_1 m_2 $\ldots$ m_M Q l_1 l_2 $\ldots$ l_Q 1 è¡ç®ã«è·é¢ N ãšé颚æ©ã®åæ° M ã空çœåºåãã§äžããããã 2 è¡ç®ã«ã M åã®é颚æ©ããããã®äœçœ®ãäžããããã m_i=j ã®ãšãã i çªç®ã®é颚æ©ã¯ x=j-1 ãš x=j ã®äžåºŠäžéã«äœçœ®ããŠããã 3 è¡ç®ã«ã¯ãšãªã®åæ° Q ãäžãããã 4 è¡ç®ã«ãæå€±ã蚱容å¯èœãªåæ° l_i ã Q åäžããããã å¶çŽ 1 \leq N \leq 10^5 1 \leq M \leq N 1 \leq m_1 < m_2 < $\ldots$ < m_M \leq N 1 \leq Q \leq 10^5 0 \leq l_i \leq 10^5 ( 1 \leq i \leq Q ) åºååœ¢åŒ äžãããã Q åã® l_i ã«å¯ŸããŠèããããæçã®ç¢ã®é·ãããé ã«æ¹è¡ããŠåºåããã ãã ããæ¡ä»¶ãæºããæ£ã®æŽæ°ã®é·ãã®ç¢ãååšããªãå Žå㯠-1 ãåºåãããã®ãšããã å
¥åäŸ1 5 1 2 1 3 åºåäŸ1 2 ç¢ã®å
端ã x = 1 ã«å°éãããšããå
端ããæ ¹å
ãŸã§ã«é颚æ©ã¯å«ãŸããªãã®ã§ããæå€±ãåæ°ã¯ 1 ã«ãªãã ç¢ã®å
端ã x = 2 ã«å°éãããšããå
端ããæ ¹å
ãŸã§ã«é颚æ©ã¯å«ãŸããã®ã§ããæå€±ãåæ°ã¯ 1 ã®ãŸãŸã§ããã ç¢ã®å
端ã x = 3 ã«å°éãããšããå
端ããæ ¹å
ãŸã§ã«é颚æ©ã¯å«ãŸããã®ã§ããæå€±ãåæ°ã¯ 1 ã®ãŸãŸã§ããã ç¢ã®å
端ã x = 4 ã«å°éãããšããå
端ããæ ¹å
ãŸã§ã«é颚æ©ã¯å«ãŸããªãã®ã§ããæå€±ãåæ°ã¯ 2 ã«ãªãã ç¢ã®å
端ã x = 5 ã«å°éãããšããå
端ããæ ¹å
ãŸã§ã«é颚æ©ã¯å«ãŸããªãã®ã§ããæå€±ãåæ°ã¯ 3 ã«ãªãã é·ã 2 ããçãç¢ãæããå Žåããæå€±ãåæ°ã 3 ãããå€ããªããããé·ã 2 ã®ç¢ãæãããšããæ¡ä»¶ãæºããæçã®ç¢ã®é·ãã§ããã å
¥åäŸ2 11 3 2 5 9 3 1 4 8 åºåäŸ2 4 3 1 | 37,560 |
èµ°ãåå (Run, Twins) E869120åã¯ãå®¶ããåŠæ ¡ãžåãã£ãŠåé $P$ ã¡ãŒãã«ã§èµ°ãåºããŸããã square1001åã¯ãE869120åãå®¶ãåºçºããŠãã $A$ ååŸã«E869120åã®å¿ãç©ã«æ°ãä»ããåé $Q$ ã¡ãŒãã«ã§è¿œããããŸããã ãã®åŸãE869120åã¯ãE869120åãå®¶ãåºçºããŠãã $B$ ååŸã«å¿ããã®ã«æ°ãä»ããåé $R$ ã¡ãŒãã«ã§éãåŒãè¿ããŸããã E869120åãå®¶ãåºçºããŠããäœååŸã«ååã¯åºäŒãã§ããããïŒ ãã ãã$B$ ååŸãŸã§ã«E869120åãšsquare1001åãåºäŒãããšã¯ãããŸããã ãŸããE869120åãšsquare1001åã®å®¶ããåŠæ ¡ãŸã§ã¯äžæ¬éã§ãããè¿éãå¥ã®éã¯ãªããã®ãšããŸãã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããã $A$ $B$ $P$ $Q$ $R$ åºå E869120åãå®¶ãåºçºããŠããE869120åãšsquare1001åãåºäŒããŸã§ã®æéãåºåããã ãã ããæåŸã«ã¯æ¹è¡ãå
¥ããããšã ãªããæ³å®è§£çãšã®çµ¶å¯Ÿèª€å·®åã¯çžå¯Ÿèª€å·®ã $10^{-3}$ 以å
ã§ããã°æ£è§£ãšããŠæ±ãããã å¶çŽ $1 \leq A \leq B \leq 100$ $1 \leq Q \leq P \leq 100$ $1 \leq R \leq 100$ å
¥åã¯å
šãп޿°ã§ããã å
¥åäŸ1 14 86 9 1 20 åºåäŸ1 119.428571428571 å
¥åäŸ2 1 4 15 9 2 åºåäŸ2 7.000000000000 å
¥åäŸ3 67 87 7 4 51 åºåäŸ3 96.618181818182 | 37,561 |
Set Union Find the union of two sets $A = \{a_0, a_1, ..., a_{n-1}\}$ and $B = \{b_0, b_1, ..., b_{m-1}\}$. Input The input is given in the following format. $n$ $a_0 \; a_1 \; ... \; a_{n-1}$ $m$ $b_0 \; b_1 \; ... \; b_{m-1}$ Elements of $A$ and $B$ are given in ascending order respectively. There are no duplicate elements in each set. Output Print elements in the union in ascending order. Print an element in a line. Constraints $1 \leq n, m \leq 200,000$ $0 \leq a_0 < a_1 < ... < a_{n-1} \leq 10^9$ $0 \leq b_0 < b_1 < ... < b_{m-1} \leq 10^9$ Sample Input 1 3 1 5 8 2 5 9 Sample Output 1 1 5 8 9 | 37,562 |
B: Shortest Crypt åé¡ xryuseixããã®åŠæ ¡ã§ã¯æå·ãæµè¡ããŠãã. æ Œåç¶ã®è¡ã«äœãã§ããxryuseixããã¯éåå Žæã決ããæ°ããæå·ãèãã. æå·æã¯ $N$ æåã®æåå $S$ ãããªã, $S_i$ ã®æåã«ãã£ãŠçŸåšå°ããã®ç§»åæ¹åãæ±ºãã. ç§»åæ¹åã«é¢ããŠã¯ä»¥äžã®éãã§ãã. A ~ M : åã«ïŒãã¹é²ã. N ~ Z : åã«ïŒãã¹é²ã. a ~ m : æ±ã«ïŒãã¹é²ã. n ~ z : 西ã«ïŒãã¹é²ã. ããŠ,ããã§xryuseixããã¯, yryuseiyã¡ããã«ããŒãã®éåå Žæãæå·æã§æããããšæã£ãã®ã ã, æå·æãåé·ãªããšã«æ°ã¥ãã. äŸãã°,ãANAããšããæå·æããã£ããšããã. ããã¯åã« $1$ ãã¹é²ã¿, åãž $1$ ãã¹é²ãã ã®ã¡åãž $1$ ãã¹é²ã. ããã¯åã« $1$ ãã¹é²ãæå·æãšç䟡ãªã®ã§,ãANAãïŒãAããš, ç°¡æœã«ã§ãã. xryuseixããã¯yryuseiyã¡ããã«é åãããããªããã,æå·æãç°¡æœã«ããããšæã£ã. ããã§ããªãã¯xryuseixããã«å€ãã£ãŠ, æå·æãç°¡æœã«ããããã°ã©ã ãæžãããšã«ãªã£ã. ãªã, ãæå·æãç°¡æœã«ããããšã¯,ãå
ã®æå·æãšåãç®çå°ãžè¡ãæãçãæå·æãäœãããšããããšã§ãã. å¶çŽ $N$ ã¯æŽæ°ã§ãã, $S_i$ ã¯å€§æåãŸãã¯å°æåã®ã¢ã«ãã¡ãããã§ãã. $1 \leq N \leq 10^{5}$ å
¥ååœ¢åŒ å
¥åã¯ä»¥äžã®åœ¢åŒã§äžãããã. $N$ $S$ åºå $1$ è¡ç®ã«ç°¡æœã«ããåŸã®æå·æã®é·ã, $2$ è¡ç®ã«ãã®æå·æãåºåãã. çããšããŠããããæå·æãè€æ°ååšããå Žå, ã©ããåºåããŠããã. ãŸãåè¡ã®æ«å°Ÿã«æ¹è¡ãåºåãã. ãµã³ãã« ãµã³ãã«å
¥å 1 5 ANazA ãµã³ãã«åºå 1 1 A ãµã³ãã«å
¥å 2 7 ACMICPC ãµã³ãã«åºå 2 5 HIJKL ãµã³ãã«å
¥å 3 4 AIZU ãµã³ãã«åºå 3 0 ç°¡æœã«ããæå·æ(ç©ºã®æåå)ã®ããšã«æ¹è¡ãå¿
èŠãªããšã«æ³šæ. | 37,563 |
Score : 800 points Problem Statement Given is a positive even number N . Find the number of strings s of length N consisting of A , B , and C that satisfy the following condition: s can be converted to the empty string by repeating the following operation: Choose two consecutive characters in s and erase them. However, choosing AB or BA is not allowed. For example, ABBC satisfies the condition for N=4 , because we can convert it as follows: ABBC â (erase BB ) â AC â (erase AC ) â (empty) . The answer can be enormous, so compute the count modulo 998244353 . Constraints 2 \leq N \leq 10^7 N is an even number. Input Input is given from Standard Input in the following format: N Output Print the number of strings that satisfy the conditions, modulo 998244353 . Sample Input 1 2 Sample Output 1 7 Except AB and BA , all possible strings satisfy the conditions. Sample Input 2 10 Sample Output 2 50007 Sample Input 3 1000000 Sample Output 3 210055358 | 37,564 |
Problem D: Sum of Different Primes A positive integer may be expressed as a sum of different prime numbers (primes), in one way or another. Given two positive integers n and k , you should count the number of ways to express n as a sum of k different primes. Here, two ways are considered to be the same if they sum up the same set of the primes. For example, 8 can be expressed as 3 + 5 and 5+ 3 but they are not distinguished. When n and k are 24 and 3 respectively, the answer is two because there are two sets {2, 3, 19} and {2, 5, 17} whose sums are equal to 24. There are no other sets of three primes that sum up to 24. For n = 24 and k = 2, the answer is three, because there are three sets {5, 19}, {7,17} and {11, 13}. For n = 2 and k = 1, the answer is one, because there is only one set {2} whose sum is 2. For n = 1 and k = 1, the answer is zero. As 1 is not a prime, you shouldn't count {1}. For n = 4 and k = 2, the answer is zero, because there are no sets of two diffrent primes whose sums are 4. Your job is to write a program that reports the number of such ways for the given n and k . Input The input is a sequence of datasets followed by a line containing two zeros separated by a space. A dataset is a line containing two positive integers n and k separated by a space. You may assume that n †1120 and k †14. Output The output should be composed of lines, each corresponding to an input dataset. An output line should contain one non-negative integer indicating the number of ways for n and k specified in the corresponding dataset. You may assume that it is less than 2 31 . Sample Input 24 3 24 2 2 1 1 1 4 2 18 3 17 1 17 3 17 4 100 5 1000 10 1120 14 0 0 Output for the Sample Input 2 3 1 0 0 2 1 0 1 55 200102899 2079324314 | 37,565 |
Score : 300 points Problem Statement There are 3N participants in AtCoder Group Contest . The strength of the i -th participant is represented by an integer a_i . They will form N teams, each consisting of three participants. No participant may belong to multiple teams. The strength of a team is defined as the second largest strength among its members. For example, a team of participants of strength 1 , 5 , 2 has a strength 2 , and a team of three participants of strength 3 , 2 , 3 has a strength 3 . Find the maximum possible sum of the strengths of N teams. Constraints 1 †N †10^5 1 †a_i †10^{9} a_i are integers. Input Input is given from Standard Input in the following format: N a_1 a_2 ... a_{3N} Output Print the answer. Sample Input 1 2 5 2 8 5 1 5 Sample Output 1 10 The following is one formation of teams that maximizes the sum of the strengths of teams: Team 1 : consists of the first, fourth and fifth participants. Team 2 : consists of the second, third and sixth participants. Sample Input 2 10 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 Sample Output 2 10000000000 The sum of the strengths can be quite large. | 37,566 |
Score : 100 points Problem Statement You are given two integers A and B . Find the largest value among A+B , A-B and A \times B . Constraints -1000 \leq A,B \leq 1000 All values in input are integers. Input Input is given from Standard Input in the following format: A B Output Print the largest value among A+B , A-B and A \times B . Sample Input 1 3 1 Sample Output 1 4 3+1=4 , 3-1=2 and 3 \times 1=3 . The largest among them is 4 . Sample Input 2 4 -2 Sample Output 2 6 The largest is 4 - (-2) = 6 . Sample Input 3 0 0 Sample Output 3 0 | 37,567 |
Problem 06: Ghost Buster! äžè¬äººã«ã¯ç¥ãç±ãç¡ãããšã ãããã®è¡ã¯å¹œéã§æº¢ããŠããããã®ã»ãšãã©ã¯ç¡å®³ãªã®ã ããå°ã£ãããšã«ã人ãåªãæªéãå°ãªãããããã®ã ã ãããšããã«ããããªæªéãšæŠãå°å¥³ããããåœŒå¥³ã¯æŒéã¯äœé£ãã¬é¡ã§é«æ ¡ã«éããªããããå€ã«ãªããšè¡äžãæ©ãåãã圷埚ããéãèŠä»ããŠã¯æä»ãããã®ã ã 幜éãæä»ãããããã«ã¯ãŸããã®å¹œéã«æ¥è¿ããå¿
èŠãããã®ã ããããã¯ç°¡åãªããšã§ã¯ãªãã幜éã¯ç©ãããæããããããã ã幜éã¯æ°å®¶ã«å£ãã䟵å
¥ããŠåæå£ããåºãŠè¡ã£ãããä¿¡å·ã®ç¡ã倧éããæ ã
ãšæšªæãããããã人éã§ãã圌女ã«ã¯ãããªããšã¯ã§ããªãã®ã§ã幜éã远跡ããã®ã¯ãšãŠãé£ããã®ã ã 圌女ã¯çµéšäžã幜éãèŠåçãªåããããããšãç¥ã£ãŠãããããã§åœŒå¥³ã¯ããã®æ
å ±ãæŽ»çšããŠå¹œéã远跡ããããšãèããã 圌女ã®ããè¡ã¯ã( H à W )ãã¹ã®ã°ãªãããšããŠè¡šãããã圌女ã幜éãã1åéã«1åãæ¬¡ã®5ã€ã®è¡å æ±ãž1ãã¹é²ã 西ãž1ãã¹é²ã åãž1ãã¹é²ã åãž1ãã¹é²ã ãã®å Žã«çãŸã ã®ãã¡ã©ãã1ã€ãè¡ãããšãã§ããããã ãã圌女ã¯è¡ã®åšå²ã«çµçã匵ã£ãã®ã§ã圌女ã幜éãè¡ã®å€ã«åºãããšã¯ã§ããªãããŸãããã®ãããªè¡åãããããšããå Žåã代ããã«ãã®å Žã«çãŸãã ããããã®ãã¹ã¯ ' # ' ãŸã㯠' . ' ãšããæåã«ãã£ãŠè¡šãããåè
ã¯å¹œéã ããé²å
¥ã§ãããã¹ããåŸè
ã¯äž¡è
ãé²å
¥ã§ãããã¹ã衚ãã 幜éã®è¡åãã¿ãŒã³ã¯ãLåã®è¡åã®åãšããŠäžããããã幜éã¯ãããã®è¡åãæåããé çªã«å®è¡ããŠãããå
šãŠã®è¡åãå®è¡ãçµãããšãŸãæåã®è¡åã«æ»ããé ã«å®è¡ãç¶ããã 圌女ãšå¹œéã N ååŸã«åããã¹ã«ãããªãã°ã圌女ãšå¹œéã¯æå» N ã§ééãããšèšãããšãåºæ¥ãã幜éã¯æŸã£ãŠãããšã©ããªè¢«å®³ããããããåãããªãã®ã§ã圌女ã¯åºæ¥ãã ãæ©ãæå»ã«å¹œéãæãŸãããããªã®ã§ã圌女ã¯é Œããå
茩ã§ããããªãã«ã圌女ãšå¹œéãééã§ããæãæ©ãæå»ãšãã®ééå Žæãæ±ããããã°ã©ã ãæžããŠã»ãããšæã£ãŠããã ããã圌女ãå©ããŠã圌女ã®ãããããèšèã§åœ·åŸšããéãæ¥µæ¥œæµåãžãšå°ãã®ã ïŒ Input è€æ°ã®ããŒã¿ã»ãããäžããããã åããŒã¿ã»ããã®åœ¢åŒã以äžã«ç€ºãã H W ïŒã°ãªããã®ååæ¹åã®ãã¹ã®æ°ãã°ãªããã®æ±è¥¿æ¹åã®ãã¹ã®æ°ïŒ 空çœåºåãã®ïŒã€ã®æŽæ°ïŒ H à W ã®æå ïŒãã¹ã®çš®é¡ïŒ' . ', ' # ', ' A ', ãŸã㯠' B 'ïŒ pattern ïŒå¹œéã®è¡åãã¿ã³ïŒæååïŒ ' A ' ã¯å°å¥³ã®åæäœçœ®ã' B ' ã¯å¹œéã®åæäœçœ®ã瀺ããäž¡è
ã®åæäœçœ®ã¯ã ' . ' ã®ãã¹ã®äžã«ããã pattern 㯠' 5 ', ' 2 ', ' 4 ', ' 6 ', ' 8 ' ããæãæååã§ãåæåã®æå³ã¯ä»¥äžã®éãã§ããïŒ ' 5 ' ãã®å Žã«çãŸã ' 8 ' åã«1ãã¹é²ã ' 6 ' æ±ã«1ãã¹é²ã ' 4 ' 西ã«1ãã¹é²ã ' 2 ' åã«1ãã¹é²ã äŸãã°ã pattern ã " 8544 " ã®å Žåã幜éã¯ãåã«1ãã¹é²ããããã®å Žã«çãŸããã西ã«1ãã¹é²ããã西ã«1ãã¹é²ããã®è¡åãã¿ã³ãç¹°ãè¿ãã H , W 㯠1 ä»¥äž 20 以äžã§ããã pattern ã®é·ã㯠10 以äžã§ããã H , W ããšãã« 0 ã®ãšããå
¥åã¯çµäºããã Output ããå°å¥³ã幜éãšééã§ãããªãã°ãæãæ©ãééæå»ãšããã®ééå Žæã®ååæ¹åã®åº§æšãæ±è¥¿æ¹åã®åº§æšã空çœã§åºåã£ãŠ1è¡ã«åºåãããã°ãªããã®æå西ã座æš(0, 0)ãšããæåæ±ã座æš( H -1, W -1) ãšããã ã©ã®ããã«è¡åããŠã絶察ã«ééã§ããªãå Žåã¯ã " impossible " ãšåºåããã Sample Input 4 7 A#...#B .#.#.#. .#.#.#. ...#... 5 4 7 A#...#B .#.#.#. .#.#.#. ...#... 2 4 7 A#...#B .#.#.#. .#.#.#. ...#... 4 4 7 A#...#B .#.#.#. .#.#.#. ...#... 442668 1 10 A#.......B 55555554 1 10 A#.......B 55555555 0 0 Output for the Sample Input 18 0 6 15 3 6 6 0 0 14 0 4 72 0 0 impossible | 37,568 |
EïŒãã€ããªå - Binary Sequence - ç©èª ããã¯ãã€ããªå€§å¥œãBonald.Brvin.BnuthããïŒ ãªããã¥ã³ãã©ãŒã倧åŠã§ãã€ããªåã®æ§è³ªãç ç©¶ããŠãã£ãŠã®ããBnuthãããããšåŒã°ããŠã芪ããŸããŠããããïŒ ã¡ãªã¿ã«ãããã®ååãBonald.Brvin.BnuthããASCIIã³ãŒããããã€ããªåãããšã1000010 1101111 1101110 1100001 1101100 1100100 101110 1000010 1110010 1110110 1101001 1101110 101110 1000010 1101110 1110101 1110100 1101000ãã«ãªãããïŒ æ¥œããã®ãïŒ ä»æ¥ã¯ãåŒåãäœããé¢çœãããªå®éšããããšèšãããã®ããæããæ¥œãã¿ãªãããïŒ ã©ãã©ããã©ããªããšããããããã®ïŒ ãªããšïŒãã€ããªåãæžãæãç¶ããããšã§ãäœããã®æ§è³ªãèŠåºããããšãªïŒ ãµãïŒããã¯ãéèŠãªçºèŠã®åããã·ãã·ãããããïŒ ããããããå®éšãå§ãããã§ã¯ãªããïŒ ãã詳现ãªèšå®ãæç« ãšããŠãŸãšããŠããããïŒ åé¡ é·ã n ã®ãã€ããªå x = (x_1, ..., x_n) ( x_i \in \{0,1\} , i = 1,...,n ) ãäžããããããã€ããªå x ã«å¯ŸããŠ2ã€ã®é¢æ° f(x) ãš g(x) ã以äžã®ããã«å®çŸ©ããã f(x) = Σ_{i=1}^{n} x_i = x_1 + x_2 + ... + x_n g(x) = Σ_{i=1}^{n-1} x_i x_{i+1} = x_1 x_2 + x_2 x_3 + ... x_{n-1} x_n ä»ããã€ããªå x ã«å¯ŸããŠä»¥äžã®ãããªå€æŽæäœã q åè¡ãã j åç®ã®å€æŽæäœã¯ l_j, r_j, b_j ( 1 \leq l_j \leq r_j \leq n , b_j \in \{0,1\} , j = 1,...,q ) ã§äžããããããã¯ãã€ããªå x ã® l_j çªç®ãã r_j çªç®ã b_j ã«çœ®ãæããæäœã«å¯Ÿå¿ãããå倿޿äœã®åŸã§ f(x) - g(x) ãæ±ããã å
¥ååœ¢åŒ n x q l_1 r_1 b_1 ... l_q r_q b_q 1è¡ç®ã«ã¯ãã€ããªåã®é·ããè¡šãæŽæ° n ãäžããããã 2è¡ç®ã«ã¯ãã€ããªå x ã衚ããæååãäžããããã 3è¡ç®ã«ã¯ã¯ãšãªã®åæ°ãè¡šãæŽæ° q ãäžããããã ç¶ã q è¡ã®ãã¡ i è¡ç®ã«ã¯ã i åç®ã®ã¯ãšãªã«é¢ããæ
å ± l_i, r_i, b_i ããã®é ã§ç©ºçœåºåãã§äžããããã å¶çŽ 2 \leq n \leq 100000 x ã¯â0âãâ1âãããªãæåå |x| = n 1 \leq q \leq 100000 1 \leq l_j \leq r_j \leq n , b_j \in \{0,1\} , j = 1,...,q åºååœ¢åŒ å i=1,...,q ã«ã€ããŠã i è¡ç®ã« i åç®ã®ã¯ãšãªãåŠçããåŸã® f(x) - g(x) ã®å€ãåºåããã å
¥åäŸ1 10 0101100110 3 3 3 1 1 6 0 2 5 1 åºåäŸ1 2 1 2 å
¥åäŸ2 8 00111100 3 8 8 1 4 5 0 7 8 1 åºåäŸ2 2 3 2 | 37,569 |
ãããã¯ã®äžè§åœ¢ å³a ã®ããã«ç©ãŸãããããã¯ã«å¯Ÿãã以äžã®äžŠã¹æ¿ãæäœãç¹°ãè¿ãã äžçªäžã®ãããã¯å
šãŠïŒå³a äžã®çœã®ãããã¯ïŒãå³ç«¯ã«æ°ããç©ã¿äžããïŒæ®ãã®ãããã¯ã¯èªåçã«ïŒæ®µäžã«èœã¡ãå³b ã®ããã«ãªãïŒã ãããã¯ã®éã«ééãã§ããããå·Šã«è©°ããŠééããªããïŒå³ b ããå³c ã®ããã«ãªãïŒã 1 以äžã®æŽæ° k ã«å¯ŸããŠãkÃ(kïŒ1)/2 ã§è¡šãããæ° (äŸ:1, 3, 6, 10, ...)ãäžè§æ°ãšããããããã¯ã®ç·æ°ãäžè§æ°ã®å Žåãäžèšã®äžŠã¹æ¿ããç¹°ãè¿ããšã巊端ã®é«ãã1 ã§å³ã«åãã£ãŠïŒã€ãã€é«ããªã£ãŠãããããªäžè§åœ¢ã«ãªããšäºæ³ãããŠããïŒå³d ã¯ç·æ°ã15 åã®å ŽåïŒã ãããã¯ã®æåã®äžŠã³ãäžãããããšãããããããæ±ºãããã忰以äžã®æäœã§ãäžã§èª¬æãããããªãããã¯ã®äžè§åœ¢ãã§ãããšããäžè§åœ¢ãåŸããããŸã§ã®æå°ã®æäœåæ°ãåºåããããã°ã©ã ãäœæããŠãã ããã å
¥å å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªããå
¥åã®çµããã¯ãŒãïŒã€ã®è¡ã§ç€ºããããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããã N b 1 b 2 ... b N åããŒã¿ã»ããã¯ïŒè¡ã§ããããããã¯ã®æåã®äžŠã³ã衚ããN (1 †N †100)ã¯ãäžçªäžã®æ®µã«ãããããã¯ã®æ°ã瀺ããb i (1 †bi †10000) ã¯å·Šãã i çªç®ã®äœçœ®ã«ç©ãŸããŠãããããã¯ã®æ°ã瀺ããb i ãš b i+1 ã¯ïŒã€ã®ç©ºçœã§åºåãããŠããããããã¯ã®ç·æ°ã¯ 3 以äžã§ããã ããŒã¿ã»ããã®æ°ã¯ 20 ãè¶
ããªãã åºå ããŒã¿ã»ããããšã«ãäžè§åœ¢ãã§ãããŸã§ã«è¡ã£ãäžŠã¹æ¿ãæäœã®åæ°ãïŒè¡ã«åºåããããã ããäžè§åœ¢ãäœããªãå Žåããæäœåæ°ã 10000 åãè¶
ããå Žå㯠-1 ãåºåããã å
¥åäŸ 6 1 4 1 3 2 4 5 1 2 3 4 5 10 1 1 1 1 1 1 1 1 1 1 9 1 1 1 1 1 1 1 1 1 12 1 4 1 3 2 4 3 3 2 1 2 2 1 5050 3 10000 10000 100 0 åºåäŸ 24 0 10 -1 48 5049 -1 æåã®ããŒã¿ã»ããããå³ã«ç€ºããå Žåã«å¯Ÿå¿ããã ïŒã€ç®ã®ããŒã¿ã»ãããããããã¯ã®ç·æ°ãäžè§æ°ã§ãªããããäžè§åœ¢ãäœããªãå Žåã«å¯Ÿå¿ããã æåŸã®ããŒã¿ã»ãããããããã¯ã®ç·æ°ã¯äžè§æ°ã ããæäœåæ°ã 10000 åãè¶
ããå Žåã«å¯Ÿå¿ããã | 37,570 |
Problem C: Push!! Mr. Schwarz was a famous powerful pro wrestler. He starts a part time job as a warehouseman. His task is to move a cargo to a goal by repeatedly pushing the cargo in the warehouse, of course, without breaking the walls and the pillars of the warehouse. There may be some pillars in the warehouse. Except for the locations of the pillars, the floor of the warehouse is paved with square tiles whose size fits with the cargo. Each pillar occupies the same area as a tile. Initially, the cargo is on the center of a tile. With one push, he can move the cargo onto the center of an adjacent tile if he is in proper position. The tile onto which he will move the cargo must be one of (at most) four tiles (i.e., east, west, north or south) adjacent to the tile where the cargo is present. To push, he must also be on the tile adjacent to the present tile. He can only push the cargo in the same direction as he faces to it and he cannot pull it. So, when the cargo is on the tile next to a wall (or a pillar), he can only move it along the wall (or the pillar). Furthermore, once he places it on a corner tile, he cannot move it anymore. He can change his position, if there is a path to the position without obstacles (such as the cargo and pillars) in the way. The goal is not an obstacle. In addition, he can move only in the four directions (i.e., east, west, north or south) and change his direction only at the center of a tile. As he is not so young, he wants to save his energy by keeping the number of required pushes as small as possible. But he does not mind the count of his pedometer, because walking is very light exercise for him. Your job is to write a program that outputs the minimum number of pushes required to move the cargo to the goal, if ever possible. Input The input consists of multiple maps, each representing the size and the arrangement of the warehouse. A map is given in the following format. w h d 11 d 12 d 13 ... d 1 w d 21 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 lengths of the two sides of the floor of the warehouse in terms of widths of floor tiles. w and h are less than or equal to 7. The integer d ij represents what is initially on the corresponding floor area in the following way. 0: nothing (simply a floor tile) 1: a pillar 2: the cargo 3: the goal 4: the warehouseman (Mr. Schwarz) Each of the integers 2, 3 and 4 appears exactly once as d ij in the map. Integer numbers in an input line are separated by at least one space character. The end of the input is indicated by a line containing two zeros. Output For each map, your program should output a line containing the minimum number of pushes. If the cargo cannot be moved to the goal, -1 should be output instead. Sample Input 5 5 0 0 0 0 0 4 2 0 1 1 0 1 0 0 0 1 0 0 0 3 1 0 0 0 0 5 3 4 0 0 0 0 2 0 0 0 0 0 0 0 0 3 7 5 1 1 4 1 0 0 0 1 1 2 1 0 0 0 3 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 0 0 6 6 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 4 0 0 0 0 0 0 0 Output for the Sample Input 5 -1 11 8 | 37,571 |
Problem H: Caterpillar ãšãã倩空éœåžã«äœã倧åŠçã®Gã¯ãèè«ã®ãã倪éã飌ã£ãŠããã 圌ã¯ããã倪éã«æçæ©æ°ã§å
šãŠã®ãããé çªã«é£ã¹ãããã«èºŸããããã圌ã®å人ã§ããããªãã¯ã圌ãããã倪éãæ¬åœã«èºŸããããŠãããã©ããã調ã¹ãŠæ¬²ãããšäŸé Œãããã®ã§ãããã°ã©ã ãæžãããšã«ããã Problem è€æ°ã®é害ç©ãšãšãµãã°ãªããç¶ã®ãšãªã¢å
ã«ååšãããé ãš 5 ã€ã®èŽäœãæã€èè«ããã®ãšãªã¢ãæ¢çŽ¢ãããèè«ãé çªã«æåŸãŸã§ãšãµãé£ã¹ããšãã®æå°ã®æ©æ°ãæ±ããã ãã ãå
šãŠã®ãšãµãé£ã¹ãããšãäžå¯èœãªå Žå㯠-1 ãåºåããããšããªãããšãµã®äžã«èè«ã®é ãéãªã£ããšãããšãµãé£ã¹ãããšãã§ããã ãšãªã¢ã¯ä»¥äžã®æåã§æ§æãããã äœããªããã¹ -> â.â éå®³ç© -> â#â ãšãµ -> â1â, â2â, ..., â9â èè«ã®åæäœçœ® -> é âSâ, èŽäœ âaâ, âbâ, âcâ, âdâ, âeâ èè«ã¯é âSâ ãã 5 ã€ã®èŽäœ âaâ, âbâ, âcâ, âdâ, âeâ ãš é ã«äžäžå·Šå³ã® 4 æ¹åã«é£æ¥ããŠãããããé£ãªã£ãŠæ§æãããã äŸãã°ãèè«ã®æ§æã衚ãããšãã以äžã® (1) ã¯æ£ããèè«ã®æ§æã§ãããã (2) ã (3) ã®ãããªæ§æã¯ããããªãã (1) æ£ãã .bc Sad ..e (2) eãååšããªã Sab .dc (3) "Sab" ãš "cde" ãšã§èè«ãåæãããŠãã Sab cde (1) ã®ãããªæ£ããèè«ã®æ§æã¯ãå
¥åã§äžããããç¶æ
ããä»»æã®åæ°ã®èè«ã®ç§»åã®éãäžè²«ããŠä¿ãããã ã€ãŸããèè«ã®é ãã飿¥ããŠãã 4 ã€ã®ãã¹ã®ãã¡ã®ããããã®ç©ºããŠãããã¹ã«äžæ©é²ããšããã®åŸã«ç¶ã㊠1 çªç®ã®èŽäœã¯é ãå
ãã£ããã¹ãžåãã2 çªç®ã®èŽäœã¯ 1 çªç®ã®èŽäœãå
ãã£ããã¹ãžã 3 çªç®ã¯ 2 çªç®ã®å
ãžâ¥âŠ ãšããããã«é ã®è»è·¡ããã©ãããã«èŽäœãåãã以äžã¯ãïŒãã¹å·Šãžåããšãã®äŸã§ããã ç§»åå ç§»ååŸ ...... ...... ...bc. ...cd. ..Sad. .Sabe. ....e. ...... èè«ã®ç§»åã§ããå Žæã¯ä»¥äžã®ããã«å®ããããŠããã èè«ã¯èªåã®èŽäœãé害ç©ããšãªã¢å€ãç§»åããããšã¯åºæ¥ãªãããã ããšãµã®äžãããã®ãšãµãé£ã¹ãã«ç§»åããããšã¯åºæ¥ãã ç§»ååã«èŽäœãé²ãå
ã«ãã£ãå Žåã§ããç§»ååŸã«é ãšèŽäœãéãªããªããªãã°ç§»åã§ããã Input H W N area å
¥å㯠H + 1 è¡ã§äžããããã1è¡ç®ã«ã¯ 3ã€ã®æŽæ° H , W , N ( 2 †H †10, 2 †W †10, 1 †N †9 ) ãæžãããŠããã H ã¯ãšãªã¢ã®é«ãã W ã¯å¹
ã N ããšãµã®åæ°ã衚ã ( ãã®ãšã 6 + N †H à W ãå¿
ãæç«ãã ) ã 2 è¡ç®ãã H + 1 è¡ç®ãŸã§ã®åè¡ã«ã¯ ÂŽSÂŽ,ÂŽ1ÂŽ, 2ÂŽ , ⊠Ž9ÂŽ,ÂŽaÂŽ,ÂŽbÂŽ,ÂŽcÂŽ,ÂŽdÂŽ,ÂŽeÂŽ,ÂŽ#ÂŽ,ÂŽ.ÂŽ ãããªã W æåã®æååãæžãããŠããïŒåã
ããšãªã¢ã®ååºç»ã®ç¶æ
ã衚ããŠããããŸã ÂŽSÂŽ,ÂŽaÂŽ,ÂŽbÂŽ,ÂŽcÂŽ,ÂŽdÂŽ,ÂŽeÂŽ ã¯èè«ã®åæç¶æ
ã衚ããŠãããåæç¶æ
ã®èè«ã«èŠãããããã«ããŠãšãµãé害ç©ã¯ååšããªãããŸããèè«ã®åæäœçœ®ããã³ãšãµã®äœçœ®ã¯æ£ããå
¥åãããããšãä¿èšŒãããŠããã Output èè«ããšãµãé çªéãã«é£ã¹ããšãã®æå°ã®æ©æ°ããŸããããäžå¯èœãªã -1 ãåºåããã Sample Input1 5 8 3 #....... #.####2# #.#.3..# #.###### .1Sabcde Sample Output1 14 Sample Input2 2 6 2 .1.baS .2.cde Sample Output2 7 Sample Input3 2 6 2 .1#baS .2.cde Sample Output3 -1 | 37,572 |
å顿 æåå $S$ ãäžããããã$S$ ã®ãã¹ãŠã®ã¢ãã°ã©ã ã®ãã¡ãåæã«ãªã£ãŠãããã®ã®åæ°ãæ±ããã æåå $X$ ã $Y$ ã®ã¢ãã°ã©ã ã§ãããšã¯ã$X$ ã $Y$ ãšçãããã$X$ ã®æåãäžŠã³æ¿ããã $Y$ ã«çãããªãããšããããäŸãã°æååabcdã«å¯ŸããŠãabcdãcbdaãªã©ã¯ã¢ãã°ã©ã ã§ããããabedãcabãabcddãªã©ã¯ã¢ãã°ã©ã ã§ãªãã æåå $X$ ãåæã§ãããšã¯ã$X$ ãéããèªãã ãã®ã $X$ èªèº«ãšçãããªãããšããããäŸãã°abcãabã¯åæã§ãªããaãabccbaãªã©ã¯åæã§ããã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã«åŸãã $S$ å¶çŽ $1 \leq |S| \leq 40$ ( $|S|$ ã¯æåå $S$ ã®é·ã) $S$ ã¯å°æåã®è±åã®ã¿ãå«ãã ç㯠$2^{63}$ æªæºã§ããããšãä¿èšŒãããã åºå åæ°ã1è¡ã«åºåããã Sample Input 1 ab Output for the Sample Input 1 0 abã®ã¢ãã°ã©ã ã¯abãšbaã®äºã€ãããããã©ã¡ããåæã«ãªã£ãŠããªãã Sample Input 2 abba Output for the Sample Input 2 2 abbaãšbaabã®äºã€ã®æååãåæãã€ã¢ãã°ã©ã ã«ãªã£ãŠããã | 37,573 |
Problem I: Roads in a City Roads in a city play important roles in development of the city. Once a road is built, people start their living around the road. A broader road has a bigger capacity, that is, people can live on a wider area around the road. Interstellar Conglomerate of Plantation and Colonization (ICPC) is now planning to develop roads on a new territory. The new territory is a square and is completely clear. ICPC has already made several plans, but there are some difficulties in judging which plan is the best. Therefore, ICPC has collected several great programmers including you, and asked them to write programs that compute several metrics for each plan. Fortunately your task is a rather simple one. You are asked to compute the area where people can live from the given information about the locations and the capacities of the roads. The following figure shows the first plan given as the sample input. Figure 1: The first plan given as the sample input Input The input consists of a number of plans. The first line of each plan denotes the number n of roads ( n †50), and the following n lines provide five integers x 1 , y 1 , x 2 , y 2 , and r , separated by a space. ( x 1 , y 1 ) and ( x 2 , y 2 ) denote the two endpoints of a road (-15 †x 1 , y 1 , x 2 , y 2 †15), and the value r denotes the capacity that is represented by the maximum distance from the road where people can live ( r †10). The end of the input is indicated by a line that contains only a single zero. The territory is located at -5 †x , y †5. You may assume that each road forms a straight line segment and that any lines do not degenerate. Output Print the area where people can live in one line for each plan. You may print an arbitrary number of digits after the decimal points, provided that difference from the exact answer is not greater than 0.01. Sample Input 2 0 -12 0 0 2 0 0 12 0 2 0 Output for the Sample Input 39.14159 | 37,574 |
Problem D: So Sleepy You have an appointment to meet a friend of yours today, but you are so sleepy because you didnât sleep well last night. As you will go by trains to the station for the rendezvous, you can have a sleep on a train. You can start to sleep as soon as you get on a train and keep asleep just until you get off. However, because of your habitude, you can sleep only on one train on your way to the destination. Given the time schedule of trains as well as your departure time and your appointed time, your task is to write a program which outputs the longest possible time duration of your sleep in a train, under the condition that you can reach the destination by the appointed time. Input The input consists of multiple datasets. Each dataset looks like below: S T D Time D A Time A N 1 K 1,1 Time 1,1 ... K 1, N 1 Time 1, N 1 N 2 K 2,1 Time 2,1 ... K 2, N 2 Time 2, N 2 ... N T K T ,1 Time T ,1 ... K T , N T Time T , N T The first line of each dataset contains S (1 †S †1000) and T (0 †T †100), which denote the numbers of stations and trains respectively. The second line contains the departure station ( D ), the departure time ( Time D ), the appointed station ( A ), and the appointed time ( Time A ), in this order. Then T sets of time schedule for trains follow. On the first line of the i -th set, there will be N i which indicates the number of stations the i -th train stops at. Then N i lines follow, each of which contains the station identifier ( K i,j ) followed by the time when the train stops at (i.e. arrives at and/or departs from) that station ( Time i,j ). Each station has a unique identifier, which is an integer between 1 and S . Each time is given in the format hh : mm , where hh represents the two-digit hour ranging from â00â to â23â, and mm represents the two-digit minute from â00â to â59â. The input is terminated by a line that contains two zeros. You may assume the following: each train stops at two stations or more; each train never stops at the same station more than once; a train takes at least one minute from one station to the next; all the times that appear in each dataset are those of the same day; and as being an expert in transfer, you can catch other trains that depart at the time just you arrive the station. Output For each dataset, your program must output the maximum time in minutes you can sleep if you can reach to the destination station in time, or âimpossibleâ (without the quotes) otherwise. Sample Input 3 1 1 09:00 3 10:00 3 1 09:10 2 09:30 3 09:40 3 2 1 09:00 1 10:00 3 1 09:10 2 09:30 3 09:40 3 3 09:20 2 09:30 1 10:00 1 0 1 09:00 1 10:00 1 0 1 10:00 1 09:00 3 1 1 09:00 3 09:35 3 1 09:10 2 09:30 3 09:40 4 3 1 09:00 4 11:00 3 1 09:10 2 09:20 4 09:40 3 1 10:30 3 10:40 4 10:50 4 1 08:50 2 09:30 3 10:30 4 11:10 0 0 Output for the Sample Input 30 30 0 impossible impossible 60 | 37,575 |
Transparent Mahjong F: éæãªéº»éç ããªãã¯ïŒéã«èãéãã倩çœãšåãããã®ã£ã³ãã©ãŒã®é·¹å·£ãããšéº»éã§å¯Ÿå±ããããšã«ãªã£ãïŒ é·¹å·£ããã¯å€©çœãšåãããã ããã£ãŠïŒé·¹å·£çãšãã奿ªãªéº»éçãçšãã察å±ãææ¡ããŠããïŒ éº»éãšã¯ïŒãã¬ã€ã€ãŒãäºãã«æçãšããè€æ°æã®çãæã¡åãïŒèªåã®æçãçžæãããã¯ããïŒã¢ã¬ãªã®åœ¢ã«ããããšã§åå©ã確å®ããã²ãŒã ã§ããïŒ éº»éã®çã®è¡šåŽã«ã¯ïŒãã®çãäœã§ããããæãããŠããïŒçã®è£åŽã«ã¯ïŒäœãæãããŠããªãïŒ ãã£ãŠïŒããªãã麻éã§å¯Ÿå±ãããšãã¯ïŒããªãã®æçã®è¡šåŽãããªãã®åŽã«ïŒè£åŽã察å±è
ã®åŽã«åãããšããïŒ ããããããšã§ïŒããªãã®æçãäœã§ãããã¯ïŒããªãã®ã¿ãç¥ãããšãã§ããïŒ éº»éã®ééå³ã¯ïŒãã¬ã€ã€ãŒãäºã®æé
ãèªã¿åãïŒãããæ¥œããããšã«ããïŒ ããããªããïŒé·¹å·£çã¯éæãªéº»éçã§ããïŒ é·¹å·£çã¯éæã§ããããïŒãã¬ã€ã€ãŒã¯äºãã«çžæã®æçãç¥ãããšãã§ããïŒ ããã§ã¯ïŒæé
ã®èªã¿åããæ¥œããããšãã§ããªãïŒ ããã¯ãïŒããã¯éº»éã§ã¯ãªãïŒããšïŒé·¹å·£çãçšããããšã«çŽåŸã§ããªãããªãã¯ïŒé·¹å·£ãããšã®çŽäœæ²æãçµãåè°ã®çµæïŒé·¹å·£çãšæ®éã®éº»éçãæ··ããŠå¯Ÿå±ããããšã«ãªã£ãïŒ æå§ãã«ïŒããªãã¯ïŒé·¹å·£ããã®æçã®ã¢ã¬ãªçãäœã§ããããäºæ³ããããšã«ããïŒ é·¹å·£ããã®æçã¯ïŒé·¹å·£çãšæ®éã®çããæ§æãããïŒ åé¡ã®ç°¡åã®ããïŒé·¹å·£çãšæ®éã®çã¯ïŒ1ãã12ã®12çš®é¡å4æãããªããã®ãšããïŒ 3 n +2æã®çãããªãæçã«ã€ããŠïŒæ¬¡ã®3ã€ã®æ¡ä»¶ãæºãããããšãïŒãã®æçã¯ã¢ã¬ãªã§ããïŒ åãæ°åãçµã¿åãããçã®çµã1ã€ååšãã æ®ãã®3 n æã®çã¯ïŒ3åã®æ°åã®çµåãã® n ã°ã«ãŒãã«ãªã ããããã®ã°ã«ãŒãã¯ïŒåãæ°åã3ã€çµã¿åããããã®ãïŒ3ã€ã®é£ç¶ããæ°åãçµã¿åããããã®ã§ãã äŸãã°ïŒ 1 1 1 3 3 3 5 5 5 7 7 7 8 9 ã®ãããª14æã®çã¯ïŒå
šãŠé·¹å·£çã§æ§æãããŠããïŒ ãã®å ŽåïŒæ¬¡ã®ããã«2ã€ã®çã®çµåã1ã€ãš4ã€ã®ã°ã«ãŒããäœãããšãã§ãïŒã¢ã¬ãªã§ããïŒ (1 1 1) (3 3 3) (5 5 5) (7 7) (7 8 9) 次ã«ïŒæ®éã®çãšé·¹å·£çãæ··ãã£ãæçã®äŸãæããïŒ 1 1 1 3 3 3 5 5 5 7 7 7 * * ã®ãããª14æã®çã¯ïŒ12æã®é·¹å·£çãš2æã®æ®éã®ç(*)ã§æ§æãããŠããïŒ ãã®å ŽåïŒæ¬¡ã®ããã«2ã€ã®æ®éã®çã8ãš9ã§ãããããããªãã®ã§ïŒ2ã€ã®çã®çµåã1ã€ãš4ã€ã®ã°ã«ãŒããäœãããšãã§ãïŒã¢ã¬ãªã§ãããããããªãïŒ (1 1 1) (3 3 3) (5 5 5) (7 7) (7 [8] [9]) åãäŸã«ã€ããŠïŒæ¬¡ã®ããã«2ã€ã®æ®éã®çã8ãš8ã§ãããããããªãã®ã§ïŒä»¥äžã®ãããªåœ¢ã®ã¢ã¬ãªã§ãããããããªãïŒ (1 1 1) (3 3 3) (5 5 5) (7 7 7) ([8] [8]) ãããïŒ7ãšããåãçã¯4æãŸã§ãã䜿ããªãã®ã§ïŒä»¥äžã®ãããªåœ¢ã®ã¢ã¬ãªã§ããããšã¯ãªãïŒ (1 1 1) (3 3 3) (5 5 5) (7 7 7) ([7] [7]) 鷹巣ããã®3 n +1æã®æçãå
¥åãšããŠäžãããããšãã«ïŒ 鷹巣ããã®æçã«1æã®çãå ããŠïŒ3 n +2æã®æçãäœãããšãèããïŒ ãã®ãšãã«ïŒ3 n +2æã®æçãã¢ã¬ãªã«ãªãåŸããããªå ãã1æã®ç(ã¢ã¬ãªç)ãå
šãŠæ±ããïŒ Input å
¥åã¯ïŒæ¬¡ã®åœ¢åŒã§äžããããïŒ n ç 1 ç 2 ... ç 3n+1 å
¥åããŒã¿ã¯æ¬¡ã®æ¡ä»¶ãæºãã n ã¯ïŒ0 <= n <= 15ãæºããïŒ åçã¯ïŒé·¹å·£çãæ®éã®çã§ããïŒé·¹å·£çã®å Žåã¯ïŒ1以äž12以äžã®æŽæ°ã§è¡šããïŒæ®éã®çã®å Žåã¯ïŒæå*ã§è¡šãããïŒ Output ã¢ã¬ãªçã®äžèЧãæé ã«åºåããïŒã¢ã¬ãªçã1ã€åºåããåºŠã«æ¹è¡ãåºåããïŒ ãããçããªãå Žåã¯ïŒ-1ã1è¡ã«è¡šç€ºããïŒ Sample Input 1 4 1 1 1 3 3 3 5 5 5 7 7 7 9 Sample Output 1 8 9 Sample Input 2 4 1 2 2 3 3 4 5 6 7 8 8 8 9 Sample Output 2 1 4 7 9 10 Sample Input 3 4 1 1 1 4 4 4 7 7 7 8 8 9 * Sample Output 3 6 7 8 9 10 11 Sample Input 4 4 1 * * * * * * * * * * * * Sample Output 4 1 2 3 4 5 6 7 8 9 10 11 12 Sample Input 5 1 3 * 1 4 Sample Output 5 1 2 4 5 | 37,576 |
Bridge Removal ICPC islands once had been a popular tourist destination. For nature preservation, however, the government decided to prohibit entrance to the islands, and to remove all the man-made structures there. The hardest part of the project is to remove all the bridges connecting the islands. There are n islands and n -1 bridges. The bridges are built so that all the islands are reachable from all the other islands by crossing one or more bridges. The bridge removal team can choose any island as the starting point, and can repeat either of the following steps. Move to another island by crossing a bridge that is connected to the current island. Remove one bridge that is connected to the current island, and stay at the same island after the removal. Of course, a bridge, once removed, cannot be crossed in either direction. Crossing or removing a bridge both takes time proportional to the length of the bridge. Your task is to compute the shortest time necessary for removing all the bridges. Note that the island where the team starts can differ from where the team finishes the work. Input The input consists of at most 100 datasets. Each dataset is formatted as follows. n p 2 p 3 ... p n d 2 d 3 ... d n The first integer n (3 †n †800) is the number of the islands. The islands are numbered from 1 to n . The second line contains n -1 island numbers p i (1 †p i < i ), and tells that for each i from 2 to n the island i and the island p i are connected by a bridge. The third line contains n -1 integers d i (1 †d i †100,000) each denoting the length of the corresponding bridge. That is, the length of the bridge connecting the island i and p i is d i . It takes d i units of time to cross the bridge, and also the same units of time to remove it. Note that, with this input format, it is assured that all the islands are reachable each other by crossing one or more bridges. The input ends with a line with a single zero. Output For each dataset, print the minimum time units required to remove all the bridges in a single line. Each line should not have any character other than this number. Sample Input 4 1 2 3 10 20 30 10 1 2 2 1 5 5 1 8 8 10 1 1 20 1 1 30 1 1 3 1 1 1 1 0 Output for the Sample Input 80 136 2 | 37,577 |
Score : 900 points Problem Statement There are N pinholes on the xy -plane. The i -th pinhole is located at (x_i,y_i) . We will denote the Manhattan distance between the i -th and j -th pinholes as d(i,j)(=|x_i-x_j|+|y_i-y_j|) . You have a peculiar pair of compasses, called Manhattan Compass . This instrument always points at two of the pinholes. The two legs of the compass are indistinguishable, thus we do not distinguish the following two states: the state where the compass points at the p -th and q -th pinholes, and the state where it points at the q -th and p -th pinholes. When the compass points at the p -th and q -th pinholes and d(p,q)=d(p,r) , one of the legs can be moved so that the compass will point at the p -th and r -th pinholes. Initially, the compass points at the a -th and b -th pinholes. Find the number of the pairs of pinholes that can be pointed by the compass. Constraints 2âŠNâŠ10^5 1âŠx_i, y_iâŠ10^9 1âŠa < bâŠN When i â j , (x_i, y_i) â (x_j, y_j) x_i and y_i are integers. Input The input is given from Standard Input in the following format: N a b x_1 y_1 : x_N y_N Output Print the number of the pairs of pinholes that can be pointed by the compass. Sample Input 1 5 1 2 1 1 4 3 6 1 5 5 4 8 Sample Output 1 4 Initially, the compass points at the first and second pinholes. Since d(1,2) = d(1,3) , the compass can be moved so that it will point at the first and third pinholes. Since d(1,3) = d(3,4) , the compass can also point at the third and fourth pinholes. Since d(1,2) = d(2,5) , the compass can also point at the second and fifth pinholes. No other pairs of pinholes can be pointed by the compass, thus the answer is 4 . Sample Input 2 6 2 3 1 3 5 3 3 5 8 4 4 7 2 5 Sample Output 2 4 Sample Input 3 8 1 2 1 5 4 3 8 2 4 7 8 8 3 3 6 6 4 8 Sample Output 3 7 | 37,578 |
A: ç§€ / Steelyard å顿 æ
倪ããã¯é·ã $2L$ ã®æ£ã䜿ã£ãŠäžã®å³ã®ãããªç§€ãäœã£ãïŒ æ£ã«ã¯çééã« $2L+1$ åã®ç©ŽãããããïŒå·Šããé ã« $-L, -L+1, \cdots, -1, 0, 1, \cdots, L-1, L$ ãšããçªå·ãä»ããããŠããïŒãã㊠$0$ çªã®ç©Žã®å Žæã倩äºããçŽã§åãããŠããïŒ æ
倪ããã¯ïŒç§€ã®ç©Žã« $N$ åã®ããããåãããïŒ$i$ çªç®ã®ããããåããã穎ã®çªå·ã¯ $x_i$ ã§ïŒãããã®éã㯠$w_i$ ã§ããïŒãããã $1$ ã€ãåããããªã穎ãïŒè€æ°ã®ããããåãããã穎ãååšãããïŒ æ
倪ãããåããããããã«ãã£ãŠã¯ïŒç§€ãåŸããŠãããããããªãïŒå§ã®ç«åããã¯ïŒè¿œå ã§ããã€ãã®éããåããããšã§ç§€ãæ°Žå¹³ã«ããã (ãããã®åº§æšãšéãç©ã®ç·åã $0$ ã«ãªããšãç§€ã¯æ°Žå¹³ã«ãªã)ïŒæ¡ä»¶ãæºãããããã®åããæ¹ã $1$ ã€åºåããªããïŒåè£ãè€æ°ããå Žåã¯ã©ããåºåããŠãããïŒ å
¥å $L$ $N$ $x_1 \ w_1$ $\vdots$ $x_N \ w_N$ å
¥åã®å¶çŽ $1 \leq L \leq 30$ $1 \leq N \leq 30$ $|x_i| \leq L$ $1 \leq w_i \leq 30$ å
šãп޿° åºå çãã¯æ¬¡ã®ãããªåœ¢åŒã§åºåããïŒ $1$ è¡ç®ã® $Nâ$ ã¯ç«åãããåããããããã®æ°ã§ããïŒ $1+i$ è¡ç®ã® $x_iâ, w_iâ$ ã¯ïŒããããç«åãããåããããããã®äœçœ®ãšéãã§ããïŒ $N'$ $x_1' \ w_1'$ $\vdots$ $x_N' \ w_N'$ åºåã®å¶çŽ ç«åããã远å ã§åãäžãããããã¯ïŒä»¥äžã®æ¡ä»¶ãæºããå¿
èŠããã. $0 \leq N' \leq 50000$ $|x_i'| \leq L$ $1 \leq w_i' \leq 50000$ å
šãп޿° ãµã³ãã« ãµã³ãã«å
¥å1 3 3 1 1 2 1 3 1 ãµã³ãã«åºå1 1 -3 2 ä»ã«ãïŒäŸãã°ä»¥äžã®ãããªåºåãæ£è§£ãšããŠæ±ããã. 2 -3 1 -3 1 ããããå³ç€ºãããšæ¬¡ã®ããã«ãªãïŒ ãµã³ãã«å
¥å2 3 3 1 1 0 2 -1 3 ãµã³ãã«åºå2 1 2 1 ãµã³ãã«å
¥å3 10 4 1 2 2 3 -7 1 -1 1 ãµã³ãã«åºå3 0 ç§€ã¯æåããé£ãåã£ãŠããããšãããïŒ | 37,579 |
æ¶ããæ°åãæ¶ããªãæ°å ãã ãåã¯é ã®äœæãããããã«ãæ°åã䜿ã£ãã²ãŒã ãããŠããŸãããã®ã²ãŒã ã§ã¯ãã¯ããã«ãïŒããïŒãŸã§ã®æ°åãã©ã³ãã ã«äžŠãã åãäžããããŸãããã ãåã¯ãæ°åãããã®äžéšåãæ¶ããŠãããŸããã«ãŒã«ã¯ã以äžã®éãã§ãã æ°åãããåãæ°åãïŒã€ä»¥äžäžŠãã§ããéšåãé©åœã«éžã¶ããã®éšåãå«ã¿ãé£ç¶ããŠçŸããŠããåãæ°åããã¹ãŠæ¶ãã æ¶ããéšåã®å³åŽã«æ°åãæ®ã£ãŠããå Žåã¯ããããå·Šã«è©°ããŠãæ°åãïŒã€ã«ãŸãšããã äžã®ïŒã€ã®æäœãç¹°ãè¿ããçµæããã¹ãŠã®æ°åãæ¶ããã°ã²ãŒã ã¯ãªã¢ãšãªãã äŸãã°ãäžã®å³ã®ãã㪠1,2,3,3,2,2,1,2,2 ãšããæ°åã®å Žåã å·Šããæ°ããŠãïŒçªç®ãïŒçªç®ã®ïŒãæ¶ããš 1,2,2,2,1,2,2 å·Šããæ°ããŠãïŒçªç®ããïŒçªç®ã®ïŒãæ¶ããš 1,1,2,2 å·Šããæ°ããŠãïŒçªç®ãšïŒçªç®ã®ïŒãæ¶ããš 2,2 å·Šããæ°ããŠãïŒçªç®ãšïŒçªç®ã®ïŒãæ¶ããšãã²ãŒã ã¯ãªã¢ãšãªããŸãã ãã ããã©ã®ããã«æ°åãæ¶ããŠãã¯ãªã¢ã§ããªãæ°åããããŸããããšãã°ã1,2,3,3,1,2 ã 1,2,3,1,2,3 ãªã©ã®æ°åã§ããçãæ°åã§ããã°ããã ãåã§ãã¯ãªã¢ã§ãããã©ãããããã«åãããã¯ãªã¢ã§ããªããšåããã°éãæ°åã«ãã£ã¬ã³ãžã§ããŸãããé·ãæ°åã«ãªããšããç°¡åã«ã¯ãããŸããã äžããããæ°åãäžã®ã²ãŒã ãã¯ãªã¢ã§ãããã©ããå€å®ããããã°ã©ã ãäœæããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã N c 1 c 2 ... c N ïŒè¡ç®ã® N (1 †N †100) ã¯ãæ°åã®é·ããè¡šãæŽæ°ã§ãããïŒè¡ç®ã«ã¯ïŒã€ã®ç©ºçœã§åºåããã N åã®æŽæ° c i (1 †c i †9) ãäžããããã c i ã¯æ°åã® i çªç®ã®æ°åã瀺ãã Output äžã«ç€ºãããã«ãŒã«ã§æ°åãæ¶ãããšãã§ããå Žåã¯ãyesããã§ããªãå Žåã¯ãnoããåºåããã Sample Input 1 8 1 2 3 3 2 1 2 2 Sample Output 1 yes Sample Input 2 7 1 2 2 1 1 3 3 Sample Output 2 yes Sample Input 3 16 9 8 8 7 7 6 5 4 4 5 1 1 2 2 3 3 Sample Output 3 no Sample Input 4 5 1 1 2 2 1 Sample Output 4 yes | 37,580 |
ãããã¹ã åé¡ IOI補èã§ã¯ïŒåµæ¥ä»¥æ¥ã®äŒçµ±ã®è£œæ³ã§ç
é€
ïŒããã¹ãïŒãçŒããŠããïŒãã®äŒçµ±ã®è£œæ³ã¯ïŒçç«ã§äžå®æé衚åŽãçŒãïŒè¡šåŽãçŒãããšè£è¿ããŠïŒçç«ã§äžå®æéè£åŽãçŒããšãããã®ã§ããïŒãã®äŒçµ±ãå®ãã€ã€ïŒç
é€
ãæ©æ¢°ã§çŒããŠããïŒãã®æ©æ¢°ã¯çžŠ R (1 †R †10) è¡, 暪 C (1 †C †10000) åã®é·æ¹åœ¢ç¶ã«ç
é€
ã䞊ã¹ãŠçŒãïŒéåžžã¯èªåé転ã§ïŒè¡šåŽãçŒãããäžæã«ç
é€
ãè£è¿ãè£åŽãçŒãïŒ ããæ¥ïŒç
é€
ãçŒããŠãããšïŒç
é€
ãè£è¿ãçŽåã«å°éãèµ·ããäœæãã®ç
é€
ãè£è¿ã£ãŠããŸã£ãïŒå¹žããªããšã«çç«ã®ç¶æ
ã¯é©åãªãŸãŸã§ãã£ããïŒãã以äžè¡šåŽãçŒããšåµæ¥ä»¥æ¥ã®äŒçµ±ã§å®ããããŠããçŒãæéãè¶
ããŠããŸãïŒç
é€
ã®è¡šåŽãçŒããããŠååãšããŠåºè·ã§ããªããªãïŒããã§ïŒæ¥ãã§æ©æ¢°ãããã¥ã¢ã«æäœã«å€æŽãïŒãŸã è£è¿ã£ãŠããªãç
é€
ã ããè£è¿ãããšããïŒãã®æ©æ¢°ã¯ïŒæšªã®è¡ãäœè¡ãåæã«è£è¿ããã瞊ã®åãäœåãåæã«è£è¿ãããããããšã¯ã§ãããïŒæ®å¿µãªããšã«ïŒç
é€
ãïŒæããšè£è¿ãããšã¯ã§ããªãïŒ è£è¿ãã®ã«æéãããããšïŒå°éã§è£è¿ããªãã£ãç
é€
ã®è¡šåŽãçŒããããŠååãšããŠåºè·ã§ããªããªãã®ã§ïŒæšªã®äœè¡ããåæã«ïŒåè£è¿ãïŒåŒãç¶ãïŒçžŠã®äœåããåæã«ïŒåè£è¿ããŠïŒè¡šåŽãçŒããããã«äž¡é¢ãçŒãããšã®ã§ããç
é€
ïŒã€ãŸãïŒãåºè·ã§ããç
é€
ãã®ææ°ããªãã¹ãå€ãããããšã«ããïŒæšªã®è¡ãïŒè¡ãè£è¿ããªãïŒãããã¯ïŒçžŠã®åãïŒåãè£è¿ããªãå Žåãèããããšã«ããïŒåºè·ã§ããç
é€
ã®ææ°ã®æå€§å€ãåºåããããã°ã©ã ãæžããªããïŒ å°éã®çŽåŸã«ïŒç
é€
ãæ¬¡ã®å³ã®ãããªç¶æ
ã«ãªã£ããšããïŒé»ãäžžã衚åŽãçŒããç¶æ
ãïŒçœãäžžãè£åŽãçŒããç¶æ
ã衚ããŠããïŒ 1è¡ç®ãè£è¿ããšæ¬¡ã®å³ã®ãããªç¶æ
ã«ãªãïŒ ããã«ïŒ 1åç®ãš5åç®ãè£è¿ããšæ¬¡ã®å³ã®ãããªç¶æ
ã«ãªãïŒãã®ç¶æ
ã§ã¯ïŒåºè·ã§ããç
é€
ã¯9æã§ããïŒ ãã³ã R ã®äžé 10 㯠C ã®äžé 10000 ã«æ¯ã¹ãŠå°ããããšã«æ³šæããïŒ å
¥å å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ å
¥åã®1è¡ç®ã«ã¯2ã€ã®æŽæ° R, C (1 †R †10, 1 †C †10 000) ã空çœãåºåããšããŠæžãããŠããïŒç¶ã R è¡ã¯å°éçŽåŸã®ç
é€
ã®ç¶æ
ã衚ãïŒ (i+1) è¡ç® (1 †i †R) ã«ã¯ïŒ C åã®æŽæ° a i,1 , a i,2 , âŠâŠ, a i,C ã空çœãåºåããšããŠæžãããŠããïŒ a i,j 㯠i è¡ j å ã®ç
é€
ã®ç¶æ
ã衚ããŠãã. a i,j ã 1 ãªã衚åŽãçŒããããšãïŒ 0 ãªãè£åŽãçŒããããšã衚ãïŒ C, R ããšãã« 0 ã®ãšãå
¥åã®çµäºã瀺ã. ããŒã¿ã»ããã®æ°ã¯ 5 ãè¶
ããªãïŒ åºå ããŒã¿ã»ããããšã«ïŒåºè·ã§ããç
é€
ã®æå€§ææ°ã1è¡ã«åºåããïŒ å
¥åºåäŸ å
¥åäŸ 2 5 0 1 0 1 0 1 0 0 0 1 3 6 1 0 0 0 1 0 1 1 1 0 1 0 1 0 1 1 0 1 0 0 åºåäŸ 9 15 äžèšå顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã | 37,581 |
Division of Big Integers Given two integers $A$ and $B$, compute the quotient, $\frac{A}{B}$. Round down to the nearest decimal. Input Two integers $A$ and $B$ separated by a space character are given in a line. Output Print the quotient in a line. Constraints $-1 \times 10^{1000} \leq A, B \leq 10^{1000}$ $B \ne 0$ Sample Input 1 5 8 Sample Output 1 0 Sample Input 2 100 25 Sample Output 2 4 Sample Input 3 -1 3 Sample Output 3 0 Sample Input 4 12 -3 Sample Output 4 -4 | 37,582 |
Sorting Five Numbers Write a program which reads five numbers and sorts them in descending order. Input Input consists of five numbers a , b , c , d and e (-100000 †a , b , c , d , e †100000). The five numbers are separeted by a space. Output Print the ordered numbers in a line. Adjacent numbers should be separated by a space. Sample Input 3 6 9 7 5 Output for the Sample Input 9 7 6 5 3 | 37,583 |
K: ææž (Angel Relief) 倩䜿ã®å€©çããã¯ãããè¡ãæãããšã«ããã ãã®è¡ã¯åå $H$ åºç» à æ±è¥¿ $W$ åºç»ã«åããããé·æ¹åœ¢ã®åœ¢ãããŠãããååºç»ã«å®¶ãããã åããæ°ã㊠$X$ çªç®ã西ããæ°ã㊠$Y$ çªç®ã®åºç»ã $(X, Y)$ ã§è¡šãã åºç» $(i, j)$ ã«ããå®¶ã«ã¯ $A_{i, j}$ 人ã®äººãäœãã§ããã 倩çããã¯ã蟺ãååãŸãã¯æ±è¥¿ã«å¹³è¡ãŸãã¯åçŽãªé·æ¹åœ¢ã®ãšãªã¢ãéžã³ããã®äžã«äœãã§ãã人å
šå¡ã ã²ãšããã€ ææžããã 倩çããã¯ãèãããããã¹ãŠã®é·æ¹åœ¢ã§ãã®æäœãè¡ãã 倩çãããäººãææžããåæ°ã®åèšãæ±ããã å
¥å 1 è¡ç®ã«ãæŽæ° $H, W$ ã空çœåºåãã§äžããããã ç¶ã $H$ è¡ã®ãã¡ $i$ è¡ç®ã«ã¯ãæŽæ° $A_{i, 1}, A_{i, 2}, A_{i, 3}, \dots, A_{i, W}$ ã空çœåºåãã§äžããããã åºå 倩çãããäººãææžããåæ°ã®åèšãåºåããã å¶çŽ $H, W$ 㯠$1$ ä»¥äž $500$ 以äžã®æŽæ° $A_{i, j}$ ã¯ãã¹ãŠ $1$ ä»¥äž $9$ 以äžã®æŽæ°ã§ããã å
¥åäŸ1 2 2 1 2 4 8 åºåäŸ1 60 äŸãã°ãå·Šäžã $(1, 1)$ãå³äžã $(2, 2)$ ãšãªãããã«é·æ¹åœ¢ã®ãšãªã¢ãéžã¶ãšãããã«ãã $15$ 人ãã²ãšããã€ææžããã®ã§ãåèš $15$ åã®ææžãè¡ãã $9$ éãã®é·æ¹åœ¢ã®ãšãªã¢ã«å¯ŸããŠããããã $1, 2, 3, 4, 5, 8, 10, 12, 15$ åã®ææžãè¡ãã®ã§ãåèšã§ $60$ åã§ããã å
¥åäŸ2 2 3 1 2 3 4 5 6 åºåäŸ2 140 | 37,584 |
Score : 100 points Problem Statement Find the number of ways to choose a pair of an even number and an odd number from the positive integers between 1 and K (inclusive). The order does not matter. Constraints 2\leq K\leq 100 K is an integer. Input Input is given from Standard Input in the following format: K Output Print the number of ways to choose a pair of an even number and an odd number from the positive integers between 1 and K (inclusive). Sample Input 1 3 Sample Output 1 2 Two pairs can be chosen: (2,1) and (2,3) . Sample Input 2 6 Sample Output 2 9 Sample Input 3 11 Sample Output 3 30 Sample Input 4 50 Sample Output 4 625 | 37,585 |
Problem J: Tile Puzzle You are visiting Ancient and Contemporary Museum. Today there is held an exhibition on the history of natural science. You have seen many interesting exhibits about ancient, medieval, and modern science and mathematics, and you are in a resting space now. You have found a number of panels there. Each of them is equipped with N à N electric tiles arranged in a square grid. Each tile is lit in one of the following colors: black (unlit), red, green, yellow, blue, magenta, and cyan. Initially all the tiles are in black. When a tile is touched on, that tile and the eight adjacent tiles will change their colors as follows: black -> red, red -> green, green -> yellow, yellow -> blue, blue -> magenta, magenta -> cyan, and cyan -> black. Here, the leftmost and rightmost columns are considered adjacent, and so as the uppermost and lowermost rows. There is a goal pattern for each panel, and you are to change the colors of the tiles as presented in the goal pattern. For example, if you are given the goal pattern shown in the figure below for a panel of 4 à 4, you will touch on the upper-left tile once and then on the lower-right tile twice (note that this might not be the only way). Since you are good at programming, you guess you can find the solution using your computer. So your job in this problem is to write a program for it. Figure 1: Example Goal Pattern Input The input contains a series of datasets. Each dataset is given in the following format: N Row 1 ... Row N N indicates the size (i.e. the number of rows and columns) of the electrical panel (3 †N †15). Row i describes the goal pattern of the i -th row and contains exactly N numbers separated by a space. The j -th number indicates the color of the j -th column, and it is one of the following: 0 (denoting black), 1 (red), 2 (green), 3 (yellow), 4 (blue), 5 (magenta), and 6 (cyan). The input is terminated by a line containing a single zero. This line is not part of any datasets. Output For each dataset, your program should produce the output of N lines. The i -th line should correspond to the i -th row and contain exactly N numbers separated by a space, where the j -th number should be the number of touches on the tile of the j -th column. The number should be in the range from 0 to 6 inclusive. If there is more than one solution, your program may output any of them. If it is impossible to make the goal pattern, your program should output a single line containing â -1 â (without quotes) instead of the N lines. A blank line should follow the output for every dataset (including the last one). Sample Input 4 3 1 2 3 1 1 0 1 2 0 2 2 3 1 2 3 5 3 3 3 0 0 3 3 3 0 0 3 3 0 4 4 0 0 4 4 4 0 0 4 4 4 0 Output for the Sample Input 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 0 4 0 0 0 0 0 0 | 37,586 |
Score : 400 points Problem Statement You are given a tree with N vertices. Here, a tree is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i -th edge (1â€iâ€N-1) connects Vertices a_i and b_i , and has a length of c_i . You are also given Q queries and an integer K . In the j -th query (1â€jâ€Q) : find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K . Constraints 3â€Nâ€10^5 1â€a_i,b_iâ€N (1â€iâ€N-1) 1â€c_iâ€10^9 (1â€iâ€N-1) The given graph is a tree. 1â€Qâ€10^5 1â€Kâ€N 1â€x_j,y_jâ€N (1â€jâ€Q) x_jâ y_j (1â€jâ€Q) x_jâ K,y_jâ K (1â€jâ€Q) Input Input is given from Standard Input in the following format: N a_1 b_1 c_1 : a_{N-1} b_{N-1} c_{N-1} Q K x_1 y_1 : x_{Q} y_{Q} Output Print the responses to the queries in Q lines. In the j -th line j(1â€jâ€Q) , print the response to the j -th query. Sample Input 1 5 1 2 1 1 3 1 2 4 1 3 5 1 3 1 2 4 2 3 4 5 Sample Output 1 3 2 4 The shortest paths for the three queries are as follows: Query 1 : Vertex 2 â Vertex 1 â Vertex 2 â Vertex 4 : Length 1+1+1=3 Query 2 : Vertex 2 â Vertex 1 â Vertex 3 : Length 1+1=2 Query 3 : Vertex 4 â Vertex 2 â Vertex 1 â Vertex 3 â Vertex 5 : Length 1+1+1+1=4 Sample Input 2 7 1 2 1 1 3 3 1 4 5 1 5 7 1 6 9 1 7 11 3 2 1 3 4 5 6 7 Sample Output 2 5 14 22 The path for each query must pass Vertex K=2 . Sample Input 3 10 1 2 1000000000 2 3 1000000000 3 4 1000000000 4 5 1000000000 5 6 1000000000 6 7 1000000000 7 8 1000000000 8 9 1000000000 9 10 1000000000 1 1 9 10 Sample Output 3 17000000000 | 37,587 |
One Problem Statement é»è»ã®çªããçŸãã山䞊ã¿ãèŠããïŒ çªã¯ïŒå·Šäžé
ã®åº§æšã (0, 0) ïŒå³äžé
ã®åº§æšã (W, H) ã®é·æ¹åœ¢ã§ããïŒ çªãã㯠N ã€ã®å±±ãèŠããŠããïŒ i çªç®ã®å±±ã¯äžã«åžãªæŸç©ç· y = a_i (x-p_i)^2 + q_i ã®åœ¢ãããŠããïŒ å±±ãšç©ºãšã®å¢çç·ã®é·ããæ±ããïŒ æ¬¡ã®äžã€ã®å³ã¯ Sample Input ã«å¯Ÿå¿ããŠããïŒå€ªç·ã§ç€ºãããŠããéšåãå±±ãšç©ºãšã®å¢çç·ã§ããïŒ Input å
¥åã¯ä»¥äžã®åœ¢åŒã«åŸãïŒäžããããæ°ã¯å
šãп޿°ã§ããïŒ W H N a_1 p_1 q_1 ... a_N p_N q_N Constraints 1 ⊠W, H ⊠100 1 ⊠N ⊠50 -100 ⊠a_i ⊠-1 0 ⊠p_i ⊠W 1 ⊠q_i ⊠H i \neq j ãªãã° (a_i, p_i, q_i) \neq (a_j, p_j, q_j) Output å±±ãšç©ºãšã®å¢çç·ã®é·ãã 1 è¡ã«åºåããïŒ åºåããå€ã¯ïŒçã®å€ãšã®çµ¶å¯Ÿèª€å·®ãŸãã¯çžå¯Ÿèª€å·®ã 10^{-6} æªæºã§ãªããã°ãªããªãïŒ Sample Input 1 20 20 1 -1 10 10 Output for the Sample Input 1 21.520346288593280 Sample Input 2 20 20 2 -1 10 10 -2 10 5 Output for the Sample Input 2 21.520346288593280 Sample Input 3 15 100 2 -2 5 100 -2 10 100 Output for the Sample Input 3 126.921542730127873 | 37,588 |
Score: 600 points Problem Statement E869120 is initially standing at the origin (0, 0) in a two-dimensional plane. He has N engines, which can be used as follows: When E869120 uses the i -th engine, his X - and Y -coordinate change by x_i and y_i , respectively. In other words, if E869120 uses the i -th engine from coordinates (X, Y) , he will move to the coordinates (X + x_i, Y + y_i) . E869120 can use these engines in any order, but each engine can be used at most once. He may also choose not to use some of the engines. He wants to go as far as possible from the origin. Let (X, Y) be his final coordinates. Find the maximum possible value of \sqrt{X^2 + Y^2} , the distance from the origin. Constraints 1 \leq N \leq 100 -1 \ 000 \ 000 \leq x_i \leq 1 \ 000 \ 000 -1 \ 000 \ 000 \leq y_i \leq 1 \ 000 \ 000 All values in input are integers. Input Input is given from Standard Input in the following format: N x_1 y_1 x_2 y_2 : : x_N y_N Output Print the maximum possible final distance from the origin, as a real value. Your output is considered correct when the relative or absolute error from the true answer is at most 10^{-10} . Sample Input 1 3 0 10 5 -5 -5 -5 Sample Output 1 10.000000000000000000000000000000000000000000000000 The final distance from the origin can be 10 if we use the engines in one of the following three ways: Use Engine 1 to move to (0, 10) . Use Engine 2 to move to (5, -5) , and then use Engine 3 to move to (0, -10) . Use Engine 3 to move to (-5, -5) , and then use Engine 2 to move to (0, -10) . The distance cannot be greater than 10 , so the maximum possible distance is 10 . Sample Input 2 5 1 1 1 0 0 1 -1 0 0 -1 Sample Output 2 2.828427124746190097603377448419396157139343750753 The maximum possible final distance is 2 \sqrt{2} = 2.82842... . One of the ways to achieve it is: Use Engine 1 to move to (1, 1) , and then use Engine 2 to move to (2, 1) , and finally use Engine 3 to move to (2, 2) . Sample Input 3 5 1 1 2 2 3 3 4 4 5 5 Sample Output 3 21.213203435596425732025330863145471178545078130654 If we use all the engines in the order 1 \rightarrow 2 \rightarrow 3 \rightarrow 4 \rightarrow 5 , we will end up at (15, 15) , with the distance 15 \sqrt{2} = 21.2132... from the origin. Sample Input 4 3 0 0 0 1 1 0 Sample Output 4 1.414213562373095048801688724209698078569671875376 There can be useless engines with (x_i, y_i) = (0, 0) . Sample Input 5 1 90447 91000 Sample Output 5 128303.000000000000000000000000000000000000000000000000 Note that there can be only one engine. Sample Input 6 2 96000 -72000 -72000 54000 Sample Output 6 120000.000000000000000000000000000000000000000000000000 There can be only two engines, too. Sample Input 7 10 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Sample Output 7 148.660687473185055226120082139313966514489855137208 | 37,589 |
Score : 700 points Problem Statement In the State of Takahashi in AtCoderian Federation, there are N cities, numbered 1, 2, ..., N . M bidirectional roads connect these cities. The i -th road connects City A_i and City B_i . Every road connects two distinct cities. Also, for any two cities, there is at most one road that directly connects them. One day, it was decided that the State of Takahashi would be divided into two states, Taka and Hashi. After the division, each city in Takahashi would belong to either Taka or Hashi. It is acceptable for all the cities to belong Taka, or for all the cities to belong Hashi. Here, the following condition should be satisfied: Any two cities in the same state, Taka or Hashi, are directly connected by a road. Find the minimum possible number of roads whose endpoint cities belong to the same state. If it is impossible to divide the cities into Taka and Hashi so that the condition is satisfied, print -1 . Constraints 2 \leq N \leq 700 0 \leq M \leq N(N-1)/2 1 \leq A_i \leq N 1 \leq B_i \leq N A_i \neq B_i If i \neq j , at least one of the following holds: A_i \neq A_j and B_i \neq B_j . If i \neq j , at least one of the following holds: A_i \neq B_j and B_i \neq A_j . Input Input is given from Standard Input in the following format: N M A_1 B_1 A_2 B_2 : A_M B_M Output Print the answer. Sample Input 1 5 5 1 2 1 3 3 4 3 5 4 5 Sample Output 1 4 For example, if the cities 1, 2 belong to Taka and the cities 3, 4, 5 belong to Hashi, the condition is satisfied. Here, the number of roads whose endpoint cities belong to the same state, is 4 . Sample Input 2 5 1 1 2 Sample Output 2 -1 In this sample, the condition cannot be satisfied regardless of which cities belong to each state. Sample Input 3 4 3 1 2 1 3 2 3 Sample Output 3 3 Sample Input 4 10 39 7 2 7 1 5 6 5 8 9 10 2 8 8 7 3 10 10 1 8 10 2 3 7 4 3 9 4 10 3 4 6 1 6 7 9 5 9 7 6 9 9 4 4 6 7 5 8 3 2 5 9 2 10 7 8 6 8 9 7 3 5 3 4 5 6 3 2 10 5 10 4 2 6 2 8 4 10 6 Sample Output 4 21 | 37,590 |
Score : 1000 points Problem Statement There are N oases on a number line. The coordinate of the i -th oases from the left is x_i . Camel hopes to visit all these oases. Initially, the volume of the hump on his back is V . When the volume of the hump is v , water of volume at most v can be stored. Water is only supplied at oases. He can get as much water as he can store at a oasis, and the same oasis can be used any number of times. Camel can travel on the line by either walking or jumping: Walking over a distance of d costs water of volume d from the hump. A walk that leads to a negative amount of stored water cannot be done. Let v be the amount of water stored at the moment. When v>0 , Camel can jump to any point on the line of his choice. After this move, the volume of the hump becomes v/2 (rounded down to the nearest integer), and the amount of stored water becomes 0 . For each of the oases, determine whether it is possible to start from that oasis and visit all the oases. Constraints 2 †N,V †2 à 10^5 -10^9 †x_1 < x_2 < ... < x_N †10^9 V and x_i are all integers. Input Input is given from Standard Input in the following format: N V x_1 x_2 ... x_{N} Output Print N lines. The i -th line should contain Possible if it is possible to start from the i -th oasis and visit all the oases, and Impossible otherwise. Sample Input 1 3 2 1 3 6 Sample Output 1 Possible Possible Possible It is possible to start from the first oasis and visit all the oases, as follows: Walk from the first oasis to the second oasis. The amount of stored water becomes 0 . Get water at the second oasis. The amount of stored water becomes 2 . Jump from the second oasis to the third oasis. The amount of stored water becomes 0 , and the volume of the hump becomes 1 . Sample Input 2 7 2 -10 -4 -2 0 2 4 10 Sample Output 2 Impossible Possible Possible Possible Possible Possible Impossible A oasis may be visited any number of times. Sample Input 3 16 19 -49 -48 -33 -30 -21 -14 0 15 19 23 44 52 80 81 82 84 Sample Output 3 Possible Possible Possible Possible Possible Possible Possible Possible Possible Possible Possible Possible Impossible Impossible Impossible Impossible | 37,591 |
Score : 500 points Problem Statement Takahashi is at an all-you-can-eat restaurant. The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i -th dish, whose deliciousness is B_i . The restaurant has the following rules: You can only order one dish at a time. The dish ordered will be immediately served and ready to eat. You cannot order the same kind of dish more than once. Until you finish eating the dish already served, you cannot order a new dish. After T-0.5 minutes from the first order, you can no longer place a new order, but you can continue eating the dish already served. Let Takahashi's happiness be the sum of the deliciousness of the dishes he eats in this restaurant. What is the maximum possible happiness achieved by making optimal choices? Constraints 2 \leq N \leq 3000 1 \leq T \leq 3000 1 \leq A_i \leq 3000 1 \leq B_i \leq 3000 All values in input are integers. Input Input is given from Standard Input in the following format: N T A_1 B_1 : A_N B_N Output Print the maximum possible happiness Takahashi can achieve. Sample Input 1 2 60 10 10 100 100 Sample Output 1 110 By ordering the first and second dishes in this order, Takahashi's happiness will be 110 . Note that, if we manage to order a dish in time, we can spend any amount of time to eat it. Sample Input 2 3 60 10 10 10 20 10 30 Sample Output 2 60 Takahashi can eat all the dishes within 60 minutes. Sample Input 3 3 60 30 10 30 20 30 30 Sample Output 3 50 By ordering the second and third dishes in this order, Takahashi's happiness will be 50 . We cannot order three dishes, in whatever order we place them. Sample Input 4 10 100 15 23 20 18 13 17 24 12 18 29 19 27 23 21 18 20 27 15 22 25 Sample Output 4 145 | 37,592 |
Problem L: Product Problem äŒæŽ¥åã¯ãçŽ æ°$P$ãèªç¶æ°ãããªãéå$G$ãèªç¶æ°$A$ã䜿ã£ãŠã²ãŒã ãããããšã«ããŸããã ãŸããäŒæŽ¥åã¯æå
ã®çŽã«$1$ãæžããŸãããã®åŸã以äžã®äžé£ã®æäœãä»»æã®åæ°è¡ããŸãã $G$ããèŠçŽ ãäžã€éžã¶ãããã$g$ãšããã æå
ã®çŽã«æžãããæ°ãš$g$ãšã®ç©ãæ°ããçŽã«æžãã å
ã
çŽã«æžãããŠããæ°ãæ¶ãã æå
ã®çŽã«æžãããæ°ã$P$ã§å²ã£ãããŸããš$A$ãçãããã°äŒæŽ¥åã®åã¡ã§ãããã§ãªããã°è² ãã§ãã$P$ã$G$ã$A$ãäžãããããšãã«äŒæŽ¥åãåã€ããšãã§ãããå€å®ããŠãã ããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã $P$ $T$ $Test_1$ $\vdots$ $Test_{T}$ å
¥åã¯è€æ°ã®ãã¹ãã±ãŒã¹ãããªãããŸã$1$è¡ã«çŽ æ°$P$ãšãã¹ãã±ãŒã¹ã®æ°$T$ãäžããããã$P$ã¯å
šãŠã®ãã¹ãã±ãŒã¹ã§å
±éã§ãããç¶ã$T$è¡ã«åãã¹ãã±ãŒã¹ãäžããããã åãã¹ãã±ãŒã¹ã¯ä»¥äžã®ããã«äžããããã $|G|$ $G_1$ $\dots$ $G_{|G|}$ $A$ åãã¹ãã±ãŒã¹ã§ã¯ã$G$ã®èŠçŽ æ°ã$G$ã®åèŠçŽ ã$A$ãé çªã«ç©ºçœã§åºåãããŠäžããããã Constraints å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã å
¥åã¯ãã¹ãŠã¯æŽæ°ã§ããã $2 \le P \le 2^{31}-1$ $1 \le T,|G| \le 10^5$ $1 \le G_i,A \le P-1$ $G_i \ne G_j,$ if $i \ne j$ å
šãŠã®ãã¹ãã±ãŒã¹ã®$|G|$ã®ç·åã¯$10^5$ãè¶
ããªãã Output åãã¹ãã±ãŒã¹ã«å¯ŸããŠãäŒæŽ¥åãåã€ããšãã§ãããªãã°$1$ããããã§ãªããã°$0$ãäžè¡ã«åºåããã Sample Input 1 7 3 1 1 2 1 2 1 3 1 2 4 5 Sample Output 1 0 1 0 Sample Input 2 1000000007 8 3 2 9 7 5 3 2 9 5 1000001 3 39 1002 65537 12 2 1000000006 518012930 793649232 10 459268180 313723762 835892239 612038995 90424474 366392946 38051435 854115735 5132833 320534710 421820264 1 1 1 1 1 1000000006 1 1000000006 1 Sample Output 2 0 1 1 1 0 1 0 1 | 37,593 |
Testing Circuits A Boolean expression is given. In the expression, each variable appears exactly once. Calculate the number of variable assignments that make the expression evaluate to true. Input A data set consists of only one line. The Boolean expression is given by a string which consists of digits, x, (, ), |, &, and ~. Other characters such as spaces are not contained. The expression never exceeds 1,000,000 characters. The grammar of the expressions is given by the following BNF. <expression> ::= <term> | <expression> "|" <term> <term> ::= <factor> | <term> "&" <factor> <factor> ::= <variable> | "~" <factor> | "(" <expression> ")" <variable> ::= "x" <number> <number> ::= "1" | "2" |... | "999999" | "1000000" The expression obeys this syntax and thus you do not have to care about grammatical errors. When the expression contains N variables, each variable in {x1, x2,..., xN} appears exactly once. Output Output a line containing the number of variable assignments that make the expression evaluate to true in modulo 1,000,000,007. Sample Input 1 (x1&x2) Output for the Sample Input 1 1 Sample Input 2 (x1&x2)|(x3&x4)|(~(x5|x6)&(x7&x8)) Output for the Sample Input 2 121 | 37,594 |
Problem I: Hard Beans Problem 倧接倧åŠã§ã¯è±ãçãã§ãã N åã®è±ãäžçŽç·äžã«äžŠãã§ããŸãã ãããã0ããé ã« N â1ãŸã§çªå·ããµãããŠããã i çªç®ã®è±ã®ç¡¬ãã a i ãšããŸãã ã·ã¢ã³åã¯çæ³ã®è±ã®ç¡¬ãã D ã ãšèããŠããŸããããããã·ã¢ã³åã¯é¢åãããããªã®ã§ããŸãé ãã«ããè±ãåãã«è¡ããããããŸããããããã£ãŠãã·ã¢ã³å㯠l çªç®ã®è±ãã r çªç®ã®è±ã®äžã§ç¡¬ãã D ã«æãè¿ãè±ãç¥ããããšæã£ãŠããŸãã ã·ã¢ã³å㯠Q åã®è³ªåãããŠããã®ã§ãããããã®è³ªåã«å¯Ÿãéåºé[ l , r ]çªç®ã«ãã | è±ã®ç¡¬ã â D | ã®æå°å€ãæ±ããããã°ã©ã ãäœæããŠãã ããã(ãã ãã| a | 㯠a ã®çµ¶å¯Ÿå€ã衚ããŸãã) Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã N a 0 a 1 ... a Nâ1 Q l 0 r 0 D 0 l 1 r 1 D 1 . . . l Qâ1 r Qâ1 D Qâ1 1è¡ç®ã«ã1ã€ã®æŽæ° N ãäžããããã2è¡ç®ã«ã N ã€ã®æŽæ°ã空çœåºåãã§äžããããã3è¡ç®ã«ãã¯ãšãªã®æ°ãïŒã€ã®æŽæ° Q ãšããŠäžãããããç¶ã4è¡ãã3+ Q è¡ãŸã§ã«ã¯ãšãªã®å€ l , r , D ãäžããããã Constraints å
¥åã¯ä»¥äžã®å¶çŽãæºããã 1 †N †10 5 0 †|a i | †10 6 (0 †i †N â1) 1 †Q †10 5 0 †D i †10 6 0 †l i †r i †N â1 Output åã¯ãšãªã«å¯Ÿãã D ãš[ l , r ]çªç®ã®è±ã®äžã§ç¡¬ã D ã«æãè¿ãè±ã®ç¡¬ããšã®å·®ã®çµ¶å¯Ÿå€ã1è¡ã«åºåããã Sample Input1 3 1 2 3 3 0 2 2 0 2 4 0 0 2 Sample Output1 0 1 1 Sample Input2 10 4 5 0 21 9 100 12 9 0 8 5 0 3 20 2 5 100 8 9 9 5 5 10 0 9 20 Sample Output2 1 0 1 90 1 | 37,596 |
Score : 600 points Problem Statement The squirrel Chokudai has N acorns. One day, he decides to do some trades in multiple precious metal exchanges to make more acorns. His plan is as follows: Get out of the nest with N acorns in his hands. Go to Exchange A and do some trades. Go to Exchange B and do some trades. Go to Exchange A and do some trades. Go back to the nest. In Exchange X (X = A, B) , he can perform the following operations any integer number of times (possibly zero) in any order: Lose g_{X} acorns and gain 1 gram of gold. Gain g_{X} acorns and lose 1 gram of gold. Lose s_{X} acorns and gain 1 gram of silver. Gain s_{X} acorns and lose 1 gram of silver. Lose b_{X} acorns and gain 1 gram of bronze. Gain b_{X} acorns and lose 1 gram of bronze. Naturally, he cannot perform an operation that would leave him with a negative amount of acorns, gold, silver, or bronze. What is the maximum number of acorns that he can bring to the nest? Note that gold, silver, or bronze brought to the nest would be worthless because he is just a squirrel. Constraints 1 \leq N \leq 5000 1 \leq g_{X} \leq 5000 1 \leq s_{X} \leq 5000 1 \leq b_{X} \leq 5000 All values in input are integers. Input Input is given from Standard Input in the following format: N g_A s_A b_A g_B s_B b_B Output Print the maximum number of acorns that Chokudai can bring to the nest. Sample Input 1 23 1 1 1 2 1 1 Sample Output 1 46 He can bring 46 acorns to the nest, as follows: In Exchange A , trade 23 acorns for 23 grams of gold. {acorns, gold, silver, bronze}={ 0,23,0,0 } In Exchange B , trade 23 grams of gold for 46 acorns. {acorns, gold, silver, bronze}={ 46,0,0,0 } In Exchange A , trade nothing. {acorns, gold, silver, bronze}={ 46,0,0,0 } He cannot have 47 or more acorns, so the answer is 46 . | 37,597 |
Pattern Search Find places where a R à C pattern is found within a H à W region. Print top-left coordinates ( i , j ) of sub-regions where the pattern found. The top-left and bottom-right coordinates of the region is (0, 0) and ( H -1, W -1) respectively. Input In the first line, two integers H and W are given. In the following H lines, i -th lines of the region are given. In the next line, two integers R and C are given. In the following R lines, i -th lines of the pattern are given. output For each sub-region found, print a coordinate i and j separated by a space character in a line. Print the coordinates in ascending order of the row numbers ( i ), or the column numbers ( j ) in case of a tie. Constraints 1 †H, W †1000 1 †R, C †1000 The input consists of alphabetical characters and digits Sample Input 1 4 5 00010 00101 00010 00100 3 2 10 01 10 Sample Output 1 0 3 1 2 | 37,598 |
ããããã®æ¯å ãžã§ãŠåãšã€ãšããã¯ä»²ã®è¯ãã«ããã«ã§ãããžã§ãŠåã¯ã«ãã»ã«ç©å
·èªè²©æ©(ã¬ãã£ãã³)ã®æ¯åãéããŠãããäºäººã§åºããããšãããã¬ãã£ãã³ãèŠã€ãããšäœåºŠããã£ãŠã¿ãã»ã©ã®ç±ã®å
¥ãããã§ããã€ãšããã¯æ¥œããããªãžã§ãŠåããã°ã§èŠãŠããã ãã§ãããããžã§ãŠåã®ä»åºŠã®èªçæ¥ãã¬ãŒã³ãã«ã¬ãã£ãã³ã®æ¯åãã²ãšã€ãããããšã«ããŸãããã€ãšããã¯ã¬ãã£ãã³èªäœã«ã¯ããŸãèå³ããããŸããã§ããããã§ããã°ãžã§ãŠåãšããããã®æ¯åãæ¬²ãããšæã£ãŠããŸãã ã€ãšããããã£ãŠã¿ãããšæãã¬ãã£ãã³ã¯ãïŒåã®ãã£ã¬ã³ãžã§æ¯åãã²ãšã€åºãŸããååãã®ãã®ãå«ãæ¯åãäœçš®é¡ããã®ããšãããããã®æ¯åãããã€æ®ã£ãŠããã®ãã¯ããããŸãããããã1åã®ãã£ã¬ã³ãžã§ã©ã®æ¯åãåºããã¯ããããŸãããããã§ãæ¯åãåºãé çªã«ããããããã€ãšãããåãæ¯åãå¿
ãïŒã€åŸãããã«æäœéå¿
èŠãªãã£ã¬ã³ãžã®åæ°ãåºåããããã°ã©ã ãäœæããŠãã ããã å
¥å å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªããå
¥åã®çµããã¯ãŒã1ã€ã®è¡ã§ç€ºããããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããã N k 1 k 2 ... k N åããŒã¿ã»ããã¯2è¡ã§ããã1è¡ç®ã«æ¯åãäœçš®é¡ããããè¡šãæŽæ° N (1 †N †10000)ãäžãããããç¶ã1è¡ã«åæ¯åãããã€æ®ã£ãŠããã®ããè¡šãæŽæ° k i (0 †k i †10000)ãäžããããã ããŒã¿ã»ããã®æ°ã¯100ãè¶
ããªãã åºå ããŒã¿ã»ããããšã«ãåãæ¯åãå¿
ãïŒã€åŸãããã«æäœéå¿
èŠãªãã£ã¬ã³ãžã®åæ°ãåºåããããã ããäžå¯èœãªå Žåã¯NAãšåºåããã å
¥åäŸ 2 3 2 3 0 1 1 1 1000 0 åºåäŸ 3 NA 2 ïŒã€ç®ã®ããŒã¿ã»ããã§ã¯ãéè¯ãïŒçš®é¡ç®ãïŒçš®é¡ç®ã®æ¯åãé£ç¶ã§åºãŠïŒåã§æžãå¯èœæ§ã¯ããããåãçš®é¡ã®æ¯åãå¿
ãïŒã€åŸãããã«ã¯ïŒåãã£ã¬ã³ãžããå¿
èŠãããã ïŒã€ç®ã®ããŒã¿ã»ããã§ã¯ãïŒã€ä»¥äžæ®ã£ãŠããæ¯åãããšããšç¡ãã®ã§äžå¯èœã§ããã ïŒã€ç®ã®ããŒã¿ã»ããã§ã¯ãæ¯åã¯ïŒçš®é¡ã ããªã®ã§ïŒåã®ãã£ã¬ã³ãžã§ãã®æ¯åãå¿
ãïŒã€åŸãããã | 37,599 |
F: Steps åé¡ AORã€ã«ã¡ããã¯æ ªåŒäŒç€ŸAORã®èŠå¯ã«èšªããã æ ªåŒäŒç€ŸAOR㯠$N$ é建ãŠã®ãã«ã§ãããå°äžéã¯ååšããªãã AORã€ã«ã¡ãã㯠$1$ éããèŠå¯ãéå§ããã¡ããã© $M$ åç§»åããããšã«ããã $1$ åã®ç§»åã§ $i$ éãã $i + 1$ éãããã㯠$i - 1$ éã«ç§»åããããšãã§ããã ãã ãã ç§»åå
ã $0$ éã $N + 1$ éãšãªãããã«ç§»åããããšã¯ã§ããªãã AORã€ã«ã¡ãããå
šãŠã®éã«äžåºŠä»¥äžèšªããç§»åæ¹æ³ã®éãæ°ã $1000000007 (= 10^9 + 7)$ ã§å²ã£ãäœããæ±ããã ãªãã $1$ éã«ã¯ãã§ã«èšªãããã®ãšããã å¶çŽ $2 \leq N \leq 10^5$ $1 \leq M \leq 10^5$ å
¥åã¯å
šãп޿°ã§äžããããã å
¥ååœ¢åŒ å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã $N \ M$ åºå ç§»åæ¹æ³ã®éãæ°ã $1000000007 (= 10 ^ 9 + 7)$ ã§å²ã£ãäœããåºåããããŸããæ«å°Ÿã«æ¹è¡ãåºåããã ãµã³ãã« ãµã³ãã«å
¥å 1 3 5 ãµã³ãã«åºå 1 3 ãµã³ãã«å
¥å 2 3 1 ãµã³ãã«åºå 2 0 ãµã³ãã«å
¥å 3 4883 5989 ãµã³ãã«åºå 3 956662807 | 37,600 |
(Please read problem A first. The maximum score you can get by solving this problem B is 1, which will have almost no effect on your ranking.) Beginner's Guide Let's first write a program to calculate the score from a pair of input and output. You can know the total score by submitting your solution, or an official program to calculate a score is often provided for local evaluation as in this contest. Nevertheless, writing a score calculator by yourself is still useful to check your understanding of the problem specification. Moreover, the source code of the score calculator can often be reused for solving the problem or debugging your solution. So it is worthwhile to write a score calculator unless it is very complicated. Problem Statement You will be given a contest schedule for D days. For each d=1,2,\ldots,D , calculate the satisfaction at the end of day d . Input Input is given from Standard Input in the form of the input of Problem A followed by the output of Problem A. D c_1 c_2 \cdots c_{26} s_{1,1} s_{1,2} \cdots s_{1,26} \vdots s_{D,1} s_{D,2} \cdots s_{D,26} t_1 t_2 \vdots t_D The constraints and generation methods for the input part are the same as those for Problem A. For each d , t_d is an integer satisfying 1\leq t_d \leq 26 , and your program is expected to work correctly for any value that meets the constraints. Output Let v_d be the satisfaction at the end of day d . Print D integers v_d to Standard Output in the following format: v_1 v_2 \vdots v_D Sample Input 1 5 86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82 19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424 6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570 6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256 8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452 19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192 1 17 13 14 13 Sample Output 1 18398 35037 51140 65837 79325 Note that this example is a small one for checking the problem specification. It does not satisfy the constraint D=365 and is never actually given as a test case. Next Step We can build a solution (schedule) for this problem in the order of day 1, day 2, and so on. And for every partial solution we have built, we can calculate the goodness (satisfaction) by using the above score calculator. So we can construct the following algorithm: for each d=1,2,\ldots,D , we select the contest type that maximizes the satisfaction at the end of day d . You may have already encountered this kind of "greedy algorithms" in algorithm contests such as ABC. Greedy algorithms can guarantee the optimality for several problems, but unfortunately, it doesn't ensure optimality for this problem. However, even if it does not ensure optimality, we can still obtain a reasonable solution in many cases. Let's go back to Problem A and implement the greedy algorithm by utilizing the score calculator you just implemented! Greedy methods can be applied to a variety of problems, are easy to implement, and often run relatively fast compared to other methods. Greedy is often the most powerful method when we need to process huge inputs. We can further improve the score by changing the greedy selection criteria (evaluation function), keeping multiple candidates instead of focusing on one best partial solution (beam search), or using the output of greedy algorithms as an initial solution of other methods. For more information, please refer to the editorial that will be published after the contest. | 37,601 |
Problem D: Dr. Nakamura's Lab. Dr.äžæã¯å倧ãªçºæè
ã§ãã, 仿¥ã垞人ã«ã¯çºæ³åºæ¥ãªãæ°ããªçºæã«åãæãã£ãŠãã. ä»çºæããŠããã®ã¯æ°ããªé²ç¯ã·ã¹ãã ãšã³ã³ããã§ãã. é²ç¯ã·ã¹ãã ã®æ¹ã¯äžã«ä¹ã£ãè
ãèå¥ããŠæãããã客ã ã£ãå Žå, 黿µãæµããŠæ°çµ¶ãããããã«ã§ãã. ãã®ããã«ã¯èžãŸãªãããã«äžãééããŠãç¡é§ã§, 空äžã®ãã®ã«å¯ŸãæŸé»ãã. ããã, ãŸã 宿ã«ã¯çšé ã, 黿µã¯åŒ·ãããŠèª¿ç¯ãäžå¯èœã§, äžåºŠæŸé»ãããšå
é»ããªãéã䜿ããªã. ãŸã, 人ãšç©äœã®åºå¥ãã§ãã, ãããã人èªäœåºå¥ã§ããªãçæ¬ ç¹ããããã°ããªããªã. ã³ã³ããã®æ¹ã¯è¬ã®åã«ãã£ãŠåžžæå°é¢ããæµ®ããŠãã, éã¶ã®ã«äŸ¿å©ã«äœã£ãŠãã. ããã, ããã宿ã«ã¯é ã, äžåºŠæŒããšäœãã«ã¶ã€ãããŸã§æ¢ãŸããªã. Dr.äžæã¯äžæ¥ã®äœæ¥ãçµã, åž°å®
ããããšãããæªå®æã®ããã«ãèšçœ®ãããŸãŸã ãšããããšã«æ°ã¥ãã. ãããåãå€ãã®ã¯é²ç¯äžéåžžã«å°é£ã«äœã£ãŠããäžã«, ãããéããªããã°åž°ããªããããªäœçœ®ã«èšçœ®ããŠããŸã£ãã®ã§Dr.äžæã¯éæ¹ã«æ®ãã. ããã, çŽ æŽãããé è³ãæã€Dr.äžæã¯è§£æ±ºæ¡ãããã«æãã€ãã. ããã«ã¯äžåºŠæŸé»ãããã°éããããã«ãªããã, ã³ã³ãããééãããã°ããã«ã®äžãéããããã«ãªã, ããèãã. å®é, ããã«ã®äžã«ã³ã³ãããééããããš, ã³ã³ããã¯é»æµã«ãã£ãŠæ¶æ»
ããŠããŸãäžæ¹ã§ããã«ã¯æŸé»ã, éããããã«ãªã. ããã, ç 究宀ã®äžã¯å
¥ãçµãã§ãã, ããŸãã³ã³ãããåãããªããšããã«ãééãããããªã. Dr.äžæã¯å©æã§ããããªãã«ã¡ãŒã«ã§å©ããæ±ãã. ããªãã®ä»äºã¯ç ç©¶å®€ã®æ
å ±ãäžããããæã«Dr.äžæãåºå£ãŸã§ãã©ãçãããã®ããã°ã©ã ãäœæããããšã§ãã. ç 究宀ã¯äºæ¬¡å
ã°ãªããã§äžããã, Dr.äžæã¯äžåºŠã®ç§»åã§äžäžå·Šå³ã«é£æ¥ããã»ã«ã«ç§»åããããšãåºæ¥ã.ãã ã, é害ç©, ã³ã³ãã, æŸé»ããŠããªãããã«ã®ã»ã«ã«ã¯ç§»åã§ããªã. Dr.äžæã¯äžäžå·Šå³ã«é£æ¥ããã»ã«ã«ããã³ã³ãããæŒãããšãã§ã, ã³ã³ããã¯Dr.äžæãããæ¹åãšéã®æ¹åã«å¥ã®ã³ã³ãããé害ç©ã«ã¶ã€ãã, ãããã¯æŸé»ãããŠããªãããã«ã®äžãééãããŸã§åã. ãŸã, äœãã«ã¶ã€ããæ¢ãŸã£ãå Žå, ã¶ã€ããçŽåã®ã»ã«ã§éæ¢ãã. åºå£ã¯ã³ã³ãããDr.äžæã䟵å
¥å¯èœã§ãã. ã³ã³ããã¯åºå£ãéã£ãŠãæ¶æ»
ããããã®ãŸãŸééãã. å£ã«ã¶ã€ãã£ãŠåºå£ããµããããšã¯ãã. ãã®å Žåã¯åºå£ã«é²å
¥ã§ããªã. ããªãã®ããã°ã©ã ãèŠæ±ãããŠããããšã¯, Dr.äžæã¯æå°äœåã®ç§»åã§ç 究宀ãè±åºã§ããããåºåããããšã®ã¿ã§ãã. ãªããªã, Dr.äžæã¯çŽ æŽãããé è³ã®æã¡äž»ãªã®ã§ãããããããã°èªåã§è±åºããããã§ãã. Input å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªã, äžè¡ç®ã«ç 究宀ã®çžŠã®é·ã H ãšæšªã®é·ã W ãäžãããã. 2è¡ç®ä»¥éã§ã¯ç 究宀ã®ç¶æ
ã H à W åã®æåã§è¡šãããã. åæåã衚ããã®ã¯ä»¥äžã®ãšããã§ãã: â # âé害ç©ã衚ã. â @ âDr.äžæã®åæäœçœ®ã衚ã. â w âããã«ã衚ã. â c âã³ã³ããã衚ã. â . âäœã眮ãããŠããªã空çœã®ã»ã«ã衚ã. â E âè±åºå£ã衚ã. çžŠãšæšªã®é·ãããšãã« 0 ã®ãšãå
¥åã®çµäºã衚ã. ããã«ã€ããŠåŠçãããå¿
èŠã¯ãªã. 以äžã®ããšãä»®å®ããŠãã. 3 †H, W †10 ç 究宀ã®åšå²ã¯é害ç©ã§å²ãŸããŠãã. ããã«ãšã³ã³ããã®æ°ã¯ãããã 3 ãè¶ããªã. ç 究宀ã«ã¯ãã ïŒã€ã®åºå£ããã. Output åããŒã¿ã»ããã«ã€ããŠæå°ã®ç§»ååæ°ãïŒè¡ã«åºåãã. ãªããDr.äžæãè±åºã§ããªãå Žåãâ -1 âãšåºåãã. Sample Input 5 5 ##### ##@## #wc.# #Ew.# ##### 5 5 ##### ##@.# #wc.# #E#.# ##### 3 6 ###### #@.wE# ###### 0 0 Output for the Sample Input 3 5 -1 | 37,602 |
æ¥ã®åºãšæ¥ã®å
¥ã 倪éœãçŸããããšããæ¥ã®åºããé ããããšããæ¥ã®å
¥ãããšåŒã³ãŸããããã®å³å¯ãªæå»ã¯å€ªéœãå°å¹³ç·ã«å¯ŸããŠã©ã®ãããªäœçœ®ã«ããæã§ããããã äžã®å³ã®ããã«ã倪éœãåãå°å¹³ç·ãçŽç·ã§è¡šãããšã«ããŸãããã®ãšãã倪éœã®ãæ¥ã®åºããæ¥ã®å
¥ããã®æå»ã¯ã倪éœã衚ãåã®äžç«¯ãå°å¹³ç·ã衚ãçŽç·ãšäžèŽããç¬éãšãããŠããŸããæ¥ã®åºã®æå»ãéããåã®äžç«¯ãçŽç·ããäžã«ããæéåž¯ãæŒéãåãçŽç·ã®äžãžå®å
šã«é ããŠããæé垯ãå€éãšãªããŸãã ããæå»ã®å°å¹³ç·ãã倪éœã®äžå¿ãŸã§ã®é«ããšã倪éœã®ååŸãå
¥åãšãããã®æå»ããæŒéããããæ¥ã®åºãŸãã¯æ¥ã®å
¥ãããããå€éãããåºåããããã°ã©ã ãäœæããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã H R å
¥åã¯ïŒè¡ãããªããããæå»ã®å°å¹³ç·ãã倪éœã®äžå¿ãŸã§ã®é«ããè¡šãæŽæ° H (-1000 †H †1000) ãšååŸãè¡šãæŽæ° R (1 †R †1000) ãäžããããããã ãã H ã¯å€ªéœã®äžå¿ãå°å¹³ç·äžã«ãããšãã 0 ãšããŠãããããäžã«ãããšãã¯æ£ãäžã«ãããšãã¯è² ãšããã Output æŒéã®ãšãã1ããæ¥ã®åºãŸãã¯æ¥ã®å
¥ãã®ãšãã0ããå€éã®ãšãã-1ããïŒè¡ã«åºåããã Sample Input 1 -3 3 Sample Output 1 0 Sample Input 2 3 3 Sample Output 2 1 Sample Input 3 -4 3 Sample Output 3 -1 | 37,603 |
B: åšææ°å - Periodic Sequence - åé¡ H倧åŠã®ææãåããŠããPeriodå士ã¯ãäžç©ã«æœããšãããåšæãšåŒã°ããæ§è³ªãç ç©¶ããŠãããäžè¬çã«ç¥ãããŠããåºæ¬çãªåšæãšããŠã¯ãæ°åã«æœãåšæãèããããã ãããããªãã¡ãé·ã N ã®æ°å S = S_1, S_2, ... , S_N ã以äžã®æ§è³ªãæºãããªãã°ãåšæ t ( t \†N ) ãæã€ãšããäºå®ã§ããã 1 \†i \†N â t ã«ã€ããŠã S_i=S_{i+t} ã§ããã ä»ãPeriodå士ãçç®ããŠããã®ã¯ãåšæãçšããŠããç°¡æãªèšè¿°ãã§ããæ°åã§ãããäŸãã°ãé·ã N ã®æ°åãåšæ t ( \†N ) ãæã€ãšããããæŽæ° k ãçšã㊠N=kt ãšæžãããªãã°ããã®æ°åã¯é·ã t ã®æ°å S_1, ... , S_t ã k åé£ç¶ãããã®ã§ããããšèšè¿°ã§ãããPeriodåå£«ã¯æ°åãäŸã®ããã«èšè¿°ã§ãããšãããã®æ°å㯠k -partã§ãããšèšãããšã«ããã Periodå士ã¯ã k ãæã倧ãã k -partã«èå³ã瀺ããŠãããããã§å©æã§ããããªãã¯ãå
¥åãšããŠæ°åãåãåããããã k -partã§ãããšãæã倧ãã k ãåºåããããã°ã©ã ã®äœæãä»»ãããããšãšãªã£ããPeriodå士ã®èŠæ±ã«æ£ç¢ºã«å¿ããããã°ã©ã ãäœæãããã å
¥ååœ¢åŒ N S_1 ... S_N 1è¡ç®ã«ã¯ãæ°åã®é·ããè¡šãæŽæ° N ãäžããããã2è¡ç®ã«ã¯ãé·ã N ã®æ°åã®åèŠçŽ ãè¡šãæŽæ° S_i ( 1 \†i \†N ) ã空çœåºåãã§äžããããããŸããå
¥å㯠1 \†N \†200,000 ãš 1 \†S_i \†100,000 ( 1 \†i \†N ) ãæºããã åºååœ¢åŒ äžããããæ°åã«å¯ŸããŠã k -partã§ãããšãã® k ã®æå€§å€ã1è¡ã«åºåããã å
¥åäŸ1 6 1 2 3 1 2 3 åºåäŸ1 2 å
¥åäŸ2 12 1 2 1 2 1 2 1 2 1 2 1 2 åºåäŸ2 6 å
¥åäŸ3 6 1 2 3 4 5 6 åºåäŸ3 1 | 37,604 |
Recurring Decimals A decimal representation of an integer can be transformed to another integer by rearranging the order of digits. Let us make a sequence using this fact. A non-negative integer a 0 and the number of digits L are given first. Applying the following rules, we obtain a i +1 from a i . Express the integer a i in decimal notation with L digits. Leading zeros are added if necessary. For example, the decimal notation with six digits of the number 2012 is 002012. Rearranging the digits, find the largest possible integer and the smallest possible integer; In the example above, the largest possible integer is 221000 and the smallest is 000122 = 122. A new integer a i +1 is obtained by subtracting the smallest possible integer from the largest. In the example above, we obtain 220878 subtracting 122 from 221000. When you repeat this calculation, you will get a sequence of integers a 0 , a 1 , a 2 , ... . For example, starting with the integer 83268 and with the number of digits 6, you will get the following sequence of integers a 0 , a 1 , a 2 , ... . a 0 = 083268 a 1 = 886320 â 023688 = 862632 a 2 = 866322 â 223668 = 642654 a 3 = 665442 â 244566 = 420876 a 4 = 876420 â 024678 = 851742 a 5 = 875421 â 124578 = 750843 a 6 = 875430 â 034578 = 840852 a 7 = 885420 â 024588 = 860832 a 8 = 886320 â 023688 = 862632 ⊠Because the number of digits to express integers is fixed, you will encounter occurrences of the same integer in the sequence a 0 , a 1 , a 2 , ... eventually. Therefore you can always find a pair of i and j that satisfies the condition a i = a j ( i > j ). In the example above, the pair ( i = 8, j = 1) satisfies the condition because a 8 = a 1 = 862632. Write a program that, given an initial integer a 0 and a number of digits L , finds the smallest i that satisfies the condition a i = a j ( i > j ). Input The input consists of multiple datasets. A dataset is a line containing two integers a 0 and L separated by a space. a 0 and L represent the initial integer of the sequence and the number of digits, respectively, where 1 †L †6 and 0 †a 0 < 10 L . The end of the input is indicated by a line containing two zeros; it is not a dataset. Output For each dataset, find the smallest number i that satisfies the condition a i = a j ( i > j ) and print a line containing three integers, j , a i and i â j . Numbers should be separated by a space. Leading zeros should be suppressed. Output lines should not contain extra characters. You can assume that the above i is not greater than 20. Sample Input 2012 4 83268 6 1112 4 0 1 99 2 0 0 Output for the Sample Input 3 6174 1 1 862632 7 5 6174 1 0 0 1 1 0 1 | 37,605 |
A - ã¢ã«ãã³ã å顿 ãããã¯è¿æã®ã¹ãŒããŒã§åããŠã¹ãã²ããã£ãšãããã®ã賌å
¥ããïŒããã±ãŒãžã®æ
å ±ã«ãããšïŒãã®ã¹ãã²ããã£ã¯ T ç§è¹ã§ããšæãçæ³çãªç¶æ
ã«è¹ã§äžãããããïŒ ãšããã§ãããã¯é»æ°ãå«ããªäººéã§ããïŒå®¶ã«ã¯ãã¬ããããœã³ã³ã¯ãããïŒæèšããç¡ãïŒ ãã®ããã¹ãã²ããã£ãè¹ã§ããã«ãïŒæéãæž¬ãããšãã§ããªãïŒ é»æ± åŒã®æèšã¯å«ãªã®ã§ïŒãããã¯ä»£ããã«ç æèšãè²·ãããšèãïŒã¹ãŒããŒã®ç æèšå£²ãå Žãžãšåãã£ãïŒ å£²ãå Žã«ã¯ N åã®ç æèšããã£ãïŒ i çªç®ã®ç æèšã¯ã¡ããã© x i ç§ã ãæž¬ãããšãã§ããããã§ãã£ãïŒ ãããããã£ãŠæ©ãŸãããïŒã¹ãã²ããã£ã®ããã«ç æèšãäœåãè²·ãã®ã¯éŠ¬é¹¿ãããã®ã§ãã®äžããã¡ããã© 1 åã ãè²·ãããšæãïŒ ãããçãããåç¥ã®éãïŒç æèšãšããã®ã¯äžåºŠæž¬ãå§ãããšïŒããããæž¬ãçµãããŸã§ã¯éäžã®æå»ãšããã®ã¯ãŸã£ããåãããªãïŒ ãã®ããïŒããç§ã i çªç®ã®ç æèšãè²·ã£ãŠäœ¿ã£ããšãããšïŒæèšãé£ç¶ããŠäœ¿ãããšã§ x i ç§ïŒ 2x i ç§ïŒ 3x i ç§ïŒ... ãšããæéãæž¬ãããšãã§ãããïŒéã«ãã以å€ã®æéã¯æž¬ãããšãã§ããªãïŒ çæ³çãªè¹ã§äžããã«å¿
èŠãªæé㯠T ç§ããããïŒããã§ã¯åŠ¥åã㊠E (< T) ç§ä»¥å
ã®èª€å·®ãèš±ããïŒ ããªãã¡ïŒã©ãã 1 ã€ã®ç æèšãçšããŠïŒ TâE ç§ïŒ TâE+1 ç§ïŒ TâE+2 ç§ïŒ... ïŒ T+Eâ2 ç§ïŒ T+Eâ1 ç§ïŒ T+E ç§ã®ãã¡ã®ã©ããã®æéãèšæž¬ãããïŒ ç§ã¯äœçªç®ã®ç æèšã賌å
¥ããŠäœ¿ãã°ããã ããã? å
¥ååœ¢åŒ å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ N T E x 1 ... x N N ã¯ç æèšã®åæ°ã§ããïŒ T ã¯ã¹ãã²ããã£ãçæ³çã«è¹ã§äžããã®ã«å¿
èŠãªæé(ç§)ïŒ E ã¯è¹ã§äžãã«èš±å®¹ããèª€å·®ã®æé(ç§)ã§ããïŒ x i 㯠i çªç®ã®ç æèšã 1 åã§æž¬ãããšã§ããã®æé(ç§)ã§ããïŒ åºååœ¢åŒ äœçªç®ã®ç æèšã䜿ãã°ãããåºåããïŒãã®ãããªç æèšãè€æ°åããå ŽåïŒãããã®äžããã©ãã 1 ã€ãåºåããïŒ ã©ã®ç æèšã䜿ã£ãŠãæéãæž¬ããªãå Žå㯠-1 ãåºåããïŒ å¶çŽ 1 †N †100 1 †T †1,440 0 †E < T 1 †x i †10^4 å
¥åå€ã¯ãã¹ãп޿°ã§ããïŒ å
¥åºåäŸ å
¥åäŸ 1 2 10 2 3 4 åºåäŸ 1 2 8ç§ïŒ9ç§ïŒ10ç§ïŒ11ç§ïŒ12ç§ ã®ãã¡ã®ããããã®æéãèšæž¬ã§ããã°ããïŒ 1 çªç®ã®ç æèšã§æž¬ãããšã®ã§ããæé㯠3ç§ïŒ6ç§ïŒ9ç§ïŒ12ç§ïŒ... ã§ããïŒ 2 çªç®ã®ç æèšã§æž¬ãããšã®ã§ããæé㯠4ç§ïŒ8ç§ïŒ12ç§ïŒ16ç§ïŒ... ã§ããã®ã§ïŒã©ã¡ãã®ç æèšãçšããŠãç®çã®æéãèšæž¬ã§ããïŒ åºåäŸ 1 ã§ã¯ 2 ãçããšããŠãããïŒ1 ãçãã«ããŠãæ£è§£ã§ããïŒ å
¥åäŸ 2 3 10 5 16 17 18 åºåäŸ 2 -1 ã©ã®ç æèšã䜿ã£ãŠãç®çã®æéã¯èšæž¬ã§ããªãïŒ Writer: è±ç°è£äžæ Tester: å°æµç¿å€ªé | 37,606 |
Problem H: Robot's Crash Prof. Jenifer A. Gibson is carrying out experiments with many robots. Since those robots are expensive, she wants to avoid their crashes during her experiments at her all effort. So she asked you, her assistant, as follows. âSuppose that we have n (2 †n †100000) robots of the circular shape with the radius of r , and that they are placed on the xy -plane without overlaps. Each robot starts to move straight with a velocity of either v or - v simultaneously, say, at the time of zero. The robots keep their moving infinitely unless I stop them. Iâd like to know in advance if some robots will crash each other. The robots crash when their centers get closer than the distance of 2 r . Iâd also like to know the time of the first crash, if any, so I can stop the robots before the crash. Well, could you please write a program for this purpose?â Input The input consists of multiple datasets. Each dataset has the following format: n vx vy r rx 1 ry 1 u 1 rx 2 ry 2 u 2 ... rx n ry n u n n is the number of robots. ( vx , vy ) denotes the vector of the velocity v . r is the radius of the robots. ( rx i , ry i ) denotes the coordinates of the center of the i -th robot. u i denotes the moving direction of the i -th robot, where 1 indicates the i -th robot moves with the velocity ( vx , vy ), and -1 indicates (- vx , - vy ). All the coordinates range from -1200 to 1200. Both vx and vy range from -1 to 1. You may assume all the following hold for any pair of robots: they must not be placed closer than the distance of (2 r + 10 -8 ) at the initial state; they must get closer than the distance of (2 r - 10 -8 ) if they crash each other at some point of time; and they must not get closer than the distance of (2 r + 10 -8 ) if they donât crash. The input is terminated by a line that contains a zero. This should not be processed. Output For each dataset, print the first crash time in a line, or âSAFEâ if no pair of robots crashes each other. Each crash time should be given as a decimal with an arbitrary number of fractional digits, and with an absolute error of at most 10 -4 . Sample Input 2 1.0 0.0 0.5 0.0 0.0 1 2.0 0.0 -1 2 1.0 0.0 0.5 0.0 0.0 -1 2.0 0.0 1 0 Output for the Sample Input 0.500000 SAFE | 37,607 |
Score : 100 points Problem Statement You planned a trip using trains and buses. The train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket. Similarly, the bus fare will be C yen if you buy ordinary tickets along the way, and D yen if you buy an unlimited ticket. Find the minimum total fare when the optimal choices are made for trains and buses. Constraints 1 \leq A \leq 1 000 1 \leq B \leq 1 000 1 \leq C \leq 1 000 1 \leq D \leq 1 000 All input values are integers. Input Input is given from Standard Input in the following format: A B C D Output Print the minimum total fare. Sample Input 1 600 300 220 420 Sample Output 1 520 The train fare will be 600 yen if you buy ordinary tickets, and 300 yen if you buy an unlimited ticket. Thus, the optimal choice for trains is to buy an unlimited ticket for 300 yen. On the other hand, the optimal choice for buses is to buy ordinary tickets for 220 yen. Therefore, the minimum total fare is 300 + 220 = 520 yen. Sample Input 2 555 555 400 200 Sample Output 2 755 Sample Input 3 549 817 715 603 Sample Output 3 1152 | 37,608 |
Score : 800 points Problem Statement This is an interactive task. Snuke has a favorite positive integer, N . You can ask him the following type of question at most 64 times: "Is n your favorite integer?" Identify N . Snuke is twisted, and when asked "Is n your favorite integer?", he answers "Yes" if one of the two conditions below is satisfied, and answers "No" otherwise: Both n \leq N and str(n) \leq str(N) hold. Both n > N and str(n) > str(N) hold. Here, str(x) is the decimal representation of x (without leading zeros) as a string. For example, str(123) = 123 and str(2000) = 2000 . Strings are compared lexicographically. For example, 11111 < 123 and 123456789 < 9 . Constraints 1 \leq N \leq 10^{9} Input and Output Write your question to Standard Output in the following format: ? n Here, n must be an integer between 1 and 10^{18} (inclusive). Then, the response to the question shall be given from Standard Input in the following format: ans Here, ans is either Y or N . Y represents "Yes"; N represents "No". Finally, write your answer in the following format: ! n Here, n=N must hold. Judging 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 ). Sample Below is a sample communication for the case N=123 : Input Output ? 1 Y ? 32 N ? 1010 N ? 999 Y ! 123 Since 1 \leq 123 and str(1) \leq str(123) , the first response is "Yes". Since 32 \leq 123 but str(32) > str(123) , the second response is "No". Since 1010 > 123 but str(1010) \leq str(123) , the third response is "No". Since 999 \geq 123 and str(999) > str(123) , the fourth response is "Yes". The program successfully identifies N=123 in four questions, and thus passes the case. | 37,609 |
Score : 300 points Problem Statement You are given a sequence of length N : A_1, A_2, ..., A_N . For each integer i between 1 and N (inclusive), answer the following question: Find the maximum value among the N-1 elements other than A_i in the sequence. Constraints 2 \leq N \leq 200000 1 \leq A_i \leq 200000 All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 : A_N Output Print N lines. The i -th line ( 1 \leq i \leq N ) should contain the maximum value among the N-1 elements other than A_i in the sequence. Sample Input 1 3 1 4 3 Sample Output 1 4 3 4 The maximum value among the two elements other than A_1 , that is, A_2 = 4 and A_3 = 3 , is 4 . The maximum value among the two elements other than A_2 , that is, A_1 = 1 and A_3 = 3 , is 3 . The maximum value among the two elements other than A_3 , that is, A_1 = 1 and A_2 = 4 , is 4 . Sample Input 2 2 5 5 Sample Output 2 5 5 | 37,610 |
Score : 700 points Problem Statement We have a directed weighted graph with N vertices. Each vertex has two integers written on it, and the integers written on Vertex i are A_i and B_i . In this graph, there is an edge from Vertex x to Vertex y for all pairs 1 \leq x,y \leq N , and its weight is {\rm min}(A_x,B_y) . We will consider a directed cycle in this graph that visits every vertex exactly once. Find the minimum total weight of the edges in such a cycle. Constraints 2 \leq N \leq 10^5 1 \leq A_i \leq 10^9 1 \leq B_i \leq 10^9 All values in input are integers. Input Input is given from Standard Input in the following format: N A_1 B_1 A_2 B_2 : A_N B_N Output Print the minimum total weight of the edges in such a cycle. Sample Input 1 3 1 5 4 2 6 3 Sample Output 1 7 Consider the cycle 1â3â2â1 . The weights of those edges are {\rm min}(A_1,B_3)=1 , {\rm min}(A_3,B_2)=2 and {\rm min}(A_2,B_1)=4 , for a total of 7 . As there is no cycle with a total weight of less than 7 , the answer is 7 . Sample Input 2 4 1 5 2 6 3 7 4 8 Sample Output 2 10 Sample Input 3 6 19 92 64 64 78 48 57 33 73 6 95 73 Sample Output 3 227 | 37,611 |
Score : 300 points Problem Statement You are given N real values A_1, A_2, \ldots, A_N . Compute the number of pairs of indices (i, j) such that i < j and the product A_i \cdot A_j is integer. Constraints 2 \leq N \leq 200\,000 0 < A_i < 10^4 A_i is given with at most 9 digits after the decimal. Input Input is given from Standard Input in the following format. N A_1 A_2 \vdots A_N Output Print the number of pairs with integer product A_i \cdot A_j (and i < j ). Sample Input 1 5 7.5 2.4 17.000000001 17 16.000000000 Sample Output 1 3 There are 3 pairs with integer product: 7.5 \cdot 2.4 = 18 7.5 \cdot 16 = 120 17 \cdot 16 = 272 Sample Input 2 11 0.9 1 1 1.25 2.30000 5 70 0.000000001 9999.999999999 0.999999999 1.000000001 Sample Output 2 8 | 37,612 |
Problem Statement In A.D. 2101, war was beginning. The enemy has taken over all of our bases. To recapture the bases, we decided to set up a headquarters. We need to define the location of the headquarters so that all bases are not so far away from the headquarters. Therefore, we decided to choose the location to minimize the sum of the distances from the headquarters to the furthest $K$ bases. The bases are on the 2-D plane, and we can set up the headquarters in any place on this plane even if it is not on a grid point. Your task is to determine the optimal headquarters location from the given base positions. Input The input consists of a single test case in the format below. $N$ $K$ $x_{1}$ $y_{1}$ $\vdots$ $x_{N}$ $y_{N}$ The first line contains two integers $N$ and $K$. The integer $N$ is the number of the bases ($1 \le N \le 200$). The integer $K$ gives how many bases are considered for calculation ($1 \le K \le N$). Each of the following $N$ lines gives the x and y coordinates of each base. All of the absolute values of given coordinates are less than or equal to $1000$, i.e., $-1000 \le x_{i}, y_{i} \le 1000$ is satisfied. Output Output the minimum sum of the distances from the headquarters to the furthest $K$ bases. The output can contain an absolute or a relative error no more than $10^{-3}$. Examples Input Output 3 1 0 1 1 0 1 1 0.70711 6 3 1 1 2 1 3 2 5 3 8 5 13 8 17.50426 9 3 573 -50 -256 158 -751 14 314 207 293 567 59 -340 -243 -22 -268 432 -91 -192 1841.20904 | 37,613 |
Transformation Write a program which performs a sequence of commands to a given string $str$. The command is one of: print a b : print from the a -th character to the b -th character of $str$ reverse a b : reverse from the a -th character to the b -th character of $str$ replace a b p : replace from the a -th character to the b -th character of $str$ with p Note that the indices of $str$ start with 0. Input In the first line, a string $str$ is given. $str$ consists of lowercase letters. In the second line, the number of commands q is given. In the next q lines, each command is given in the above mentioned format. Output For each print command, print a string in a line. Constraints $1 \leq $ length of $str \leq 1000$ $1 \leq q \leq 100$ $0 \leq a \leq b < $ length of $str$ for replace command, $b - a + 1 = $ length of $p$ Sample Input 1 abcde 3 replace 1 3 xyz reverse 0 2 print 1 4 Sample Output 1 xaze Sample Input 2 xyz 3 print 0 2 replace 0 2 abc print 0 2 Sample Output 2 xyz abc | 37,614 |
Problem A: Special Chat Problem 人æ°åç»æçš¿ãµã€ããZouTubeãã¯ä»ã空åã®ãããŒãã£ã«ZouTuberãããŒã ã®çã£åªäžã«ããããã®äžã§ããæè¿ç¹ã«æ³šç®ãéããŠããã®ã¯ãåŸèŒ©ç³»ããŒãã£ã«ZouTuberãã¢ã€ã
ããªã ïŒéç§°ïŒã¢ã
ãªã ïŒãã ã ã¢ã
ãªã ã®å€§ãã¡ã³ã§ããããªãã¯ãæ¬æ¥ã®ã¢ã
ãªã ã®ã©ã€ãé
ä¿¡ã§ã圌女ã«ãã¹ãã·ã£ã«ãã£ããããéãã€ããã ã ãã¹ãã·ã£ã«ãã£ããããšã¯ãZouTubeã®æäŸãããèŠèŽè
ãé
ä¿¡è
ã«ãã€ã³ãããã¬ãŒã³ãããæ©èœã ã ãèŠèŽè
ã¯ã¹ãã·ã£ã«ãã£ãã$1$åã«ã€ãã$500$, $1000$, $5000$, $10000$ã®ããããã ããã€ã³ããæ¶è²»ããŠãæ¶è²»ããéãšåãéã ããã€ã³ããé
ä¿¡è
ã«ãã¬ãŒã³ãã§ããã ä»ããªããä¿æããŠãããã€ã³ãã®ç·éãäžãããããšãããã®ãã€ã³ããæ¶è²»ããŠãããªããã¢ã
ãªã ã«ãã¬ãŒã³ãã§ãããã€ã³ãã®ç·éã®æå€§å€ãæ±ãããä¿æããŠãããã€ã³ãã®éãæ¶è²»ãããã€ã³ãã®éãäžåããªãéããã¹ãã·ã£ã«ãã£ããã¯äœåºŠã§ãè¡ãããšãã§ããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã $P$ ä»ããªããä¿æããŠãããã€ã³ãã®ç·éãè¡šãæŽæ°$P$ã$1$è¡ã«äžããããã Constraints å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã $1 \le P \le 10^5$ Output ã¢ã
ãªã ã«ãã¬ãŒã³ãã§ãããã€ã³ãã®ç·éã®æå€§å€ã$1$è¡ã«åºåããã Sample Input 1 5700 Sample Output 1 5500 Sample Input 2 1333 Sample Output 2 1000 Sample Input 3 100000 Sample Output 3 100000 | 37,615 |
Score : 100 points Problem Statement You are given an array a_0, a_1, ..., a_{N-1} of length N . Process Q queries of the following types. The type of i -th query is represented by T_i . T_i=1 : You are given two integers X_i,V_i . Replace the value of A_{X_i} with V_i . T_i=2 : You are given two integers L_i,R_i . Calculate the maximum value among A_{L_i},A_{L_i+1},\cdots,A_{R_i} . T_i=3 : You are given two integers X_i,V_i . Calculate the minimum j such that X_i \leq j \leq N, V_i \leq A_j . If there is no such j , answer j=N+1 instead. Constraints 1 \leq N \leq 2 \times 10^5 0 \leq A_i \leq 10^9 1 \leq Q \leq 2 \times 10^5 1 \leq T_i \leq 3 1 \leq X_i \leq N , 0 \leq V_i \leq 10^9 ( T_i=1,3 ) 1 \leq L_i \leq R_i \leq N ( T_i=2 ) All values in Input are integer. Input Input is given from Standard Input in the following format: N Q A_1 A_2 \cdots A_N First query Second query \vdots Q -th query Each query is given in the following format: If T_i=1,3 , T_i X_i V_i If T_i=2 , T_i L_i R_i Output For each query with T_i=2, 3 , print the answer. Sample Input 1 5 5 1 2 3 2 1 2 1 5 3 2 3 1 3 1 2 2 4 3 1 3 Sample Output 1 3 3 2 6 First query: Print 3 , which is the maximum of (A_1,A_2,A_3,A_4,A_5)=(1,2,3,2,1) . Second query: Since 3>A_2 , j=2 does not satisfy the conditionïŒSince 3 \leq A_3 , print j=3 . Third query: Replace the value of A_3 with 1 . It becomes A=(1,2,1,2,1) . Fourth query: Print 2 , which is the maximum of (A_2,A_3,A_4)=(2,1,2) . Fifth query: Since there is no j that satisfies the condition, print j=N+1=6 . | 37,616 |
Score : 900 points Problem Statement There is a tree with N vertices numbered 1 through N . The i -th of the N-1 edges connects vertices a_i and b_i . Initially, each vertex is uncolored. Takahashi and Aoki is playing a game by painting the vertices. In this game, they alternately perform the following operation, starting from Takahashi: Select a vertex that is not painted yet. If it is Takahashi who is performing this operation, paint the vertex white; paint it black if it is Aoki. Then, after all the vertices are colored, the following procedure takes place: Repaint every white vertex that is adjacent to a black vertex, in black. Note that all such white vertices are repainted simultaneously, not one at a time. If there are still one or more white vertices remaining, Takahashi wins; if all the vertices are now black, Aoki wins. Determine the winner of the game, assuming that both persons play optimally. Constraints 2 †N †10^5 1 †a_i,b_i †N a_i â b_i The input graph is a tree. Input Input is given from Standard Input in the following format: N a_1 b_1 : a_{N-1} b_{N-1} Output Print First if Takahashi wins; print Second if Aoki wins. Sample Input 1 3 1 2 2 3 Sample Output 1 First Below is a possible progress of the game: First, Takahashi paint vertex 2 white. Then, Aoki paint vertex 1 black. Lastly, Takahashi paint vertex 3 white. In this case, the colors of vertices 1 , 2 and 3 after the final procedure are black, black and white, resulting in Takahashi's victory. Sample Input 2 4 1 2 2 3 2 4 Sample Output 2 First Sample Input 3 6 1 2 2 3 3 4 2 5 5 6 Sample Output 3 Second | 37,617 |
Problem G: Nim Let's play a traditional game Nim. You and I are seated across a table and we have a hundred stones on the table (we know the number of stones exactly). We play in turn and at each turn, you or I can remove one to four stones from the heap. You play first and the one who removed the last stone loses. In this game, you have a winning strategy. To see this, you first remove four stones and leave 96 stones. No matter how I play, I will end up with leaving 92-95 stones. Then you will in turn leave 91 stones for me (verify this is always possible). This way, you can always leave 5 k + 1 stones for me and finally I get the last stone, sigh. If we initially had 101 stones, on the other hand, I have a winning strategy and you are doomed to lose. Let's generalize the game a little bit. First, let's make it a team game. Each team has n players and the 2 n players are seated around the table, with each player having opponents at both sides. Turns round the table so the two teams play alternately. Second, let's vary the maximum number ofstones each player can take. That is, each player has his/her own maximum number ofstones he/she can take at each turn (The minimum is always one). So the game is asymmetric and may even be unfair. In general, when played between two teams of experts, the outcome of a game is completely determined by the initial number ofstones and the minimum number of stones each player can take at each turn. In other words, either team has a winning strategy. You are the head-coach of a team. In each game, the umpire shows both teams the initial number of stones and the maximum number of stones each player can take at each turn. Your team plays first. Your job is, given those numbers, to instantaneously judge whether your team has a winning strategy. Incidentally, there is a rumor that Captain Future and her officers of Hakodate-maru love this game, and they are killing their time playing it during their missions. You wonder where the stones are?. Well, they do not have stones but do have plenty of balls in the fuel containers!. Input The input is a sequence of lines, followed by the last line containing a zero. Each line except the last is a sequence of integers and has the following format. n S M 1 M 2 ... M 2 n where n is the number of players in a team, S the initial number of stones, and M i the maximum number of stones i th player can take. 1st, 3rd, 5th, ... players are your team's players and 2nd, 4th, 6th, ... the opponents. Numbers are separated by a single space character. You may assume 1 †n †10, 1 †M i †16, and 1 †S †2 13 . Output The out put should consist of lines each containing either a one, meaning your team has a winning strategy, or a zero otherwise. Sample Input 1 101 4 4 1 100 4 4 3 97 8 7 6 5 4 3 0 Output for the Sample Input 0 1 1 | 37,618 |
Score : 600 points Problem Statement We have a tree with N vertices. The i -th edge connects Vertex A_i and B_i bidirectionally. Takahashi is standing at Vertex u , and Aoki is standing at Vertex v . Now, they will play a game of tag as follows: 1 . If Takahashi and Aoki are standing at the same vertex, the game ends. Otherwise, Takahashi moves to a vertex of his choice that is adjacent to his current vertex. 2 . If Takahashi and Aoki are standing at the same vertex, the game ends. Otherwise, Aoki moves to a vertex of his choice that is adjacent to his current vertex. 3 . Go back to step 1 . Takahashi performs his moves so that the game ends as late as possible, while Aoki performs his moves so that the game ends as early as possible. Find the number of moves Aoki will perform before the end of the game if both Takahashi and Aoki know each other's position and strategy. It can be proved that the game is bound to end. Constraints 2 \leq N \leq 10^5 1 \leq u,v \leq N u \neq v 1 \leq A_i,B_i \leq N The given graph is a tree. Input Input is given from Standard Input in the following format: N u v A_1 B_1 : A_{N-1} B_{N-1} Output Print the number of moves Aoki will perform before the end of the game. Sample Input 1 5 4 1 1 2 2 3 3 4 3 5 Sample Output 1 2 If both players play optimally, the game will progress as follows: Takahashi moves to Vertex 3 . Aoki moves to Vertex 2 . Takahashi moves to Vertex 5 . Aoki moves to Vertex 3 . Takahashi moves to Vertex 3 . Here, Aoki performs two moves. Note that, in each move, it is prohibited to stay at the current vertex. Sample Input 2 5 4 5 1 2 1 3 1 4 1 5 Sample Output 2 1 Sample Input 3 2 1 2 1 2 Sample Output 3 0 Sample Input 4 9 6 1 1 2 2 3 3 4 4 5 5 6 4 7 7 8 8 9 Sample Output 4 5 | 37,619 |
Score : 900 points Problem Statement Akaki, a patissier, can make N kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1 , Doughnut 2 , ..., Doughnut N . In order to make one Doughnut i (1 †i †N) , she needs to consume m_i grams of Moto. She cannot make a non-integer number of doughnuts, such as 0.5 doughnuts. The recipes of these doughnuts are developed by repeated modifications from the recipe of Doughnut 1 . Specifically, the recipe of Doughnut i (2 †i †N) is a direct modification of the recipe of Doughnut p_i (1 †p_i < i) . Now, she has X grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition: Let c_i be the number of Doughnut i (1 †i †N) that she makes. For each integer i such that 2 †i †N , c_{p_i} †c_i †c_{p_i} + D must hold. Here, D is a predetermined value. At most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto. Constraints 2 †N †50 1 †X †10^9 0 †D †10^9 1 †m_i †10^9 (1 †i †N) 1 †p_i < i (2 †i †N) All values in input are integers. Input Input is given from Standard Input in the following format: N X D m_1 m_2 p_2 : m_N p_N Output Print the maximum number of doughnuts that can be made under the condition. Sample Input 1 3 100 1 15 10 1 20 1 Sample Output 1 7 She has 100 grams of Moto, can make three kinds of doughnuts, and the conditions that must hold are c_1 †c_2 †c_1 + 1 and c_1 †c_3 †c_1 + 1 . It is optimal to make two Doughnuts 1 , three Doughnuts 2 and two Doughnuts 3 . Sample Input 2 3 100 10 15 10 1 20 1 Sample Output 2 10 The amount of Moto and the recipes of the doughnuts are not changed from Sample Input 1, but the last conditions are relaxed. In this case, it is optimal to make just ten Doughnuts 2 . As seen here, she does not necessarily need to make all kinds of doughnuts. Sample Input 3 5 1000000000 1000000 123 159 1 111 1 135 3 147 3 Sample Output 3 7496296 | 37,620 |
RPG Maker You are planning to create a map of an RPG. This map is represented by a grid whose size is $H \times W$. Each cell in this grid is either ' @ ', ' * ', ' # ', or ' . '. The meanings of the symbols are as follows. ' @ ': The start cell. The story should start from this cell. ' * ': A city cell. The story goes through or ends with this cell. ' # ': A road cell. ' . ': An empty cell. You have already located the start cell and all city cells under some constraints described in the input section, but no road cells have been located yet. Then, you should decide which cells to set as road cells. Here, you want a "journey" exists on this map. Because you want to remove the branch of the story, the journey has to be unforked. More formally, the journey is a sequence of cells and must satisfy the following conditions: The journey must contain as many city cells as possible. The journey must consist of distinct non-empty cells in this map. The journey must begin with the start cell. The journey must end with one of the city cells. The journey must contain all road cells. That is, road cells not included in the journey must not exist. The journey must be unforked. In more detail, all road cells and city cells except for a cell at the end of the journey must share edges with the other two cells both of which are also contained in the journey. Then, each of the start cell and a cell at the end of the journey must share an edge with another cell contained in the journey. You do not have to consider the order of the cities to visit during the journey. Initially, the map contains no road cells. You can change any empty cells to road cells to make a journey satisfying the conditions above. Your task is to print a map which maximizes the number of cities in the journey. Input The input consists of a single test case of the following form. $H$ $W$ $S_1$ $S_2$ : $S_H$ The first line consists of two integers $N$ and $W$. $H$ and $W$ are guaranteed to satisfy $H = 4n - 1$ and $W = 4m -1$ for some positive integers $n$ and $m$ ($1 \leq n, m \leq 10$). The following $H$ lines represent a map without road cells. The ($i+1$)-th line consists of a string $S_i$ of length $W$. The $j$-th character of $S_i$ is either ' * ', ' @ ' or ' . ' if both $i$ and $j$ are odd, otherwise ' . '. The number of occurrences of ' @ ' in the grid is exactly one. It is guaranteed that there are one or more city cells on the grid. Output Print a map indicating a journey. If several maps satisfy the condition, you can print any of them. Sample Input 1 11 7 ....... ....... *.....* ....... ..@.... ....... *...... ....... ....*.. ....... ....... Output for Sample Input 1 ....... ....... *#####* ......# ..@...# ..#.### *##.#.. #...#.. ####*.. ....... ....... Sample Input 2 7 11 ........*.. ........... ........... ........... ....*...*.. ........... ..*.@...*.. Output for Sample Input 2 ........*.. ........#.. ........#.. ........#.. ..##*##.*.. ..#...#.#.. ..*#@.##*.. | 37,621 |
Problem E: School Excursion æ¥ãããã¯ä¿®åŠæ
è¡ã®ææã§ããã äŒæŽ¥å€§åŠéå±å°åŠæ ¡ïŒäŒæŽ¥å€§å°ïŒã§ããæ¥å¹ŽåºŠã®ä¿®åŠæ
è¡ã®èšç»ã建ãŠãããŠããã ä¿®åŠæ
è¡ã¯é»è»ã§ç§»åããããšãäŒçµ±ã«ãªã£ãŠããã äŒæŽ¥è¥æŸåžå
ã§ã¯é»è»ãå©çšããæ©äŒãå°ãªãããã ã ããããåŠæ ¡ã«å±ããããèŠæ
ã«ããæå¡ãã¡ã¯é ãæ©ãŸããŠããã ããã¯ããããé§
ã§å€§äººæ°ã§ä¹ãæããè¡ã£ãŠããã®ã§ããã®é§
ãå©çšããä»ã®ä¹å®¢ã«è¿·æã§ãã£ãããšããå
容ã ã£ãã ãšãã«ãé»è»ãéããããšããŒã ããã®éè·¯ã§å€§æ··éããŠããŸã£ããšããã ããã¯è¿å¹ŽãäŒæŽ¥å€§å°ã®çåŸæ°ãæ¥äžæããŠããããã§ãã£ãã ãã®åå ã¯æ¥æ¬ã«ãããŠç«¶æããã°ã©ãã³ã°ã倧æµè¡ãã å°åŠæ ¡ããç«¶æããã°ã©ããŒã逿ããããã®èšç·Žãè¡ã£ãŠããäŒæŽ¥å€§å°ã«çåŸãéãŸã£ãããã§ããã äŒæŽ¥å€§å°ç«¶æããã°ã©ãã³ã°éšé·ã§ããããªãã¯ãä¿®åŠæ
è¡ã楜ãã¿ã«ããŠããã ä¿®åŠæ
è¡ãæåããããããªãã¯æå¡ãã¡ã«ææ¡ãããã ãã¯ã©ã¹ããšã«è¡åããŠãåãé§
ã«åæã«å°çããªãããã«ããŸãããïŒïŒ ç«¶æããã°ã©ãã³ã°ã®ç¥èãå¿çšããã°ç°¡åã§ãïŒïŒã è€æ°ã®ã¯ã©ã¹ãåæã«åãé§
ã«å°çããããšããªãããã«ç§»åãããšãïŒåãé§
ã«è€æ°ã®ã¯ã©ã¹ãæ»åšããããšã¯å¯èœïŒã åºçºããé§
ããç®çå°ãŸã§å°éã§ããæå€§ã®ã¯ã©ã¹æ°ãæ±ãããã®ãšãã®æå°ã®éè³ãæ±ããããã°ã©ã ãã€ãããªããã ãã ããããé§
ã§åæã«å°çããé»è»ãšçºè»ããé»è»ãååšããå Žåãä¹ãç¶ããå¯èœã§ãããã€ãŸããä¹ãç¶ãã«èŠããæéã¯ç¡èŠããŠè¯ãã Input å
¥åã¯è€æ°ã®ããŒã¿ã»ããããæ§æãããã ããŒã¿ã»ããã®æ°ã¯20å以äžã§ããã åããŒã¿ã»ããã®åœ¢åŒã¯æ¬¡ã«ç€ºãéãã§ããã n m 1 x 1,1 y 1,1 c 1,1 x 1,2 y 1,2 c 1,2 ... x 1,m1 y 1,m1 c 1,m1 m 2 x 2,1 y 2,1 c 2,1 x 2,2 y 2,2 c 2,2 ... x 2,m2 y 2,m2 c 2,m2 ... m n-1 x n-1,1 y n-1,1 c n-1,1 x n-1,2 y n-1,2 c n-1,2 ... x n-1,m2 y n-1,m2 c n-1,m2 g n( 2 †n †100)ã¯é§
ã®æ°ã衚ãã é§
ã®æ°ã¯åºçºããé§
ãšç®çå°ã®é§
ãä¹ãæãããé§
ãå«ãã é§
ã¯åºçºããé§
ã1çªç®ãæåã«ä¹ãæããé§
ã2çªç®ã®é§
ãšæ°ããç®çå°ãnçªç®ã®é§
ãšããã m i ã¯içªç®ã®é§
ããi+1çªç®ã®é§
ãžã®é»è»ã®æ°ã衚ãã m i (1 †m †20)åã®é»è»ã®æ
å ±ãç¶ãã x i,j y i,j c i,j ã¯içªç®ã®é§
ããi+1çªç®ã®é§
ã«åããé»è»ã®åºçºæå»(x i,j )å°çæå»(y i,j )éè³(c i,j )ã衚ãã (0 †x i,j , y i,j †200000 ã〠x i,j †y i,j ) (1 †c i,j †1000) ãã®åŸg(1†g †10)ãç¶ãã gã¯ä¿®åŠæ
è¡ã«åå ããã¯ã©ã¹æ°ã衚ãã äžããããæ°ïŒn,m,x,y,c,g)ã¯ãã¹ãп޿°ã§ããã å
¥åã®çµäºã¯ã²ãšã€ã®0ãå«ãïŒè¡ã§ç€ºãããã Output äžè¡ã«å°çå¯èœãªã¯ã©ã¹æ°ãšãã®ãšãã®æå°éè³ããã®é ã«åºåããã ããããã äžã€ã®ã¯ã©ã¹ãå°çã§ããªãå Žåã¯0 0ãåºåããã Sample Input 2 4 1 2 10 2 2 5 1 3 20 2 3 10 10 3 2 1 2 5 0 3 4 3 10 11 100 2 12 2 12 12 3 10 0 Sample Output 2 15 2 111 | 37,622 |
Pilling Blocks We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing. We have to build the tower abiding by the following conditions: Every stage of the tower has one or more blocks on it. Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage. Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed. Input The input is given in the following format. $N$ $K$ The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$). Output Output the maximum possible number of stages. Sample Input 1 4 2 Sample Output 1 3 Sample Input 2 5 2 Sample Output 2 4 | 37,623 |
è¿·åã®åå ããããåãšããããåã¯ä»²è¯ãã®ååã§ãããè¡åãçéã§ãã äŸãã°ãããããåã西ã«è¡ãã°ãããããåã¯æ±ãžè¡ããããããåãåãžè¡ãã°ãããããåã¯åãžè¡ããŸãã çŸåš 2 人ã¯ãããŒãã«æ¥ãŠãããå¥ã
ã®å Žæã«ããŸããçéã«ç§»åããŠããŸã 2 人ãã§ããã ãæ©ãåºäŒãããã«ã¯ã©ããããããã§ãããã? ãããŒãã¯æšª W å à 瞊 H åã®ãã¹ã§æ§æãããã°ãªããã§è¡šããã2 人ã¯åäœæéã«æ±è¥¿ååã« 1 ãã¹åç§»åããããšãã§ããŸãããã ããã°ãªããã®ç¯å²å€ãé害ç©ã®ãããã¹ã«ç§»åããããšã¯ã§ããŸããã å³ã®ããã«ãã°ãªããã®ãã¹ã®äœçœ®ã¯åº§æš ( x , y ) ã§è¡šãããŸãã ã°ãªããã®æ
å ±ãš 2 人ã®åæäœçœ®ãå
¥åãšãã2 人ãåºäŒããŸã§ã®æçã®æéãåºåããããã°ã©ã ãäœæããŠãã ãããåºäŒãããšãã§ããªãå ŽåããåºäŒãã®ã« 100 以äžã®æéãèŠããå Žåã¯ãNA ãšåºåããŠãã ãããã°ãªããã®æ
å ±ã¯ã H è¡ W åã®æ°åã2 人ã®äœçœ®æ
å ±ã¯åº§æšã«ãã£ãŠäžããããŸãã ç§»ååŸã«ããããåãããããåã®ãã¡ãã©ã¡ããäžæ¹ãé害ç©ãã°ãªããã®ç¯å²å€ã«äœçœ®ããŠããŸããšãã«ã¯ãç§»åãã§ããªãã®ã§ãé害ç©ãã°ãªããã®ç¯å²å€ã«äœçœ®ããæ¹ã¯å
ã®å Žæã«æ»ããŸãããããã§ãªãæ¹ã¯å
ã®å Žæã«æ»ãããšãªãåãããšãã§ããŸãã ãªãã2 人ãåºäŒããšã¯ãç§»ååŸã« 2 人ãåããã¹ã«æ¢ãŸãããšãèšããŸãã2 人ãããéã£ãŠããåºäŒã£ãããšã«ã¯ãªããŸããã Input è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒããµãã€ã®è¡ã§ç€ºãããŸãã åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã W H tx ty kx ky d 11 d 21 ... d W1 d 12 d 22 ... d W2 : d 1H d 2H ... d WH 1 è¡ç®ã«ãããŒãã®å€§ãã W , H (1 †W, H †50) ãäžããããŸãã2 è¡ç®ã«ããããåã®åæäœçœ® tx, ty ã3 è¡ç®ã«ããããåã®åæäœçœ® kx, ky ãäžããããŸãã ç¶ã H è¡ã«ãããŒãã®æ
å ±ãäžããããŸãã d i,j ã¯ãã¹ ( i, j ) ã®çš®é¡ã衚ãã0 ã®ãšãç§»åå¯èœãªãã¹ã1 ã®ãšãé害ç©ããããã¹ã衚ããŸãã ããŒã¿ã»ããã®æ°ã¯ 100 ãè¶
ããŸããã Output å
¥åããŒã¿ã»ããããšã«ãæçã®æéãïŒè¡ã«åºåããŸãã Sample Input 6 6 2 4 6 2 0 0 0 0 1 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 3 3 1 1 3 3 0 0 0 0 1 0 0 0 0 0 0 Output for the Sample Input 3 NA | 37,624 |
Courage Test Pã仿¥ã¯è詊ãäŒç»ã®çªçµã®åé²ã ãã Oåæºçµµéãããããã ããâŠâŠã åæããªåãæºçµµéã¡ãã倧äžå€«ïŒã æéèããããPããïŒäžè¡ã§ç¶æ³ãææ°å€æã«ãããçŽ æŽããã解説ã§ãïŒããïŒç«ã®çã«åãã£ãŠèµ°ããŸãããïŒã Pãã«ãŒã«ã¯ç°¡åãã¿ããªã§ååããŠãã®ãšãªã¢ã®ãã¹ãŠã®ç¥ç€Ÿã«ãåãããŠããã ãã ãã èããªãŒãœããã¯ã¹ã§ããïŒæ©éç¥ç€Ÿã«åãã£ãŠèµ°ããŸãããïŒã ããªåãã§ããããæ¥æ¬ææ°ã®ç¥ç€Ÿå¯åºŠã§è¡ããªãã¡ããããªãç¥ç€Ÿãããããããããããªãã£ãã£ãâŠâŠã ããªåãã§ãèã¡ãããããã°å¿åŒ·ããïŒã Pãã¡ãªã¿ã«ã¹ã¿ãŒãã¯å
šå¡éãç¥ç€Ÿããã¹ã¿ãŒããåæµãçŠæ¢ã ããããããæºçµµéãšããªåã¯åæäœçœ®ã«ã€ããŠããã æºçµµéããã
âŠâŠã ããªåããããèåãæã£ãŠããã°å€§äžå€«ïŒã æºçµµéãé 匵ãâŠâŠã èããããã¥ãŒãµãŒïŒç§ã¯ã©ãããã°ïŒã Pããåã¯è³ãããã ã èããã£ã Pã座ã£ãŠãã èãã Problem ãããã1~ n ã®çªå·ãä»ãããã n åã®ç¥ç€Ÿãš n -1æ¬ã®éããããåéã¯ç¥ç€Ÿ a i ãšç¥ç€Ÿ b i ãç¹ããåæ¹åã«ç§»åããããšãã§ãããããããã®ç¥ç€Ÿã¯ãä»»æã®ç¥ç€Ÿãã1æ¬ä»¥äžã®éãçµç±ããŠå°éããããšãã§ããããŸããä»»æã®2ã€ã®ç¥ç€Ÿã®éã®(è¿åããªã)çµè·¯ã¯äžæã«å®ãŸãã Oåæºçµµéã¡ãããšåæããªåã¡ãããããããç¥ç€Ÿ u ãšç¥ç€Ÿ v ã«ããã ä»ã2人ãä»»æã«ç§»åãããããšãèãããç§»åãšã¯ãããç¥ç€Ÿãã1æ¬ã®éãçµç±ããŠå¥ã®ç¥ç€Ÿã«é²ãããšã§ããã ãã®éã以äžã®ã«ãŒã«ãæºããããã 2人åãããŠå
šãŠã®ç¥ç€Ÿã蚪åããã 2人ã®ç§»åæ°ãåãã«ããã 1ã€ã®ç¥ç€Ÿ, éã¯1人ããéãããããã«1床ããéãããšãã§ããªãã ç¥ç€Ÿ u , v ã¯æ¢ã«èšªããŠãããã®ãšããéãããšã¯ã§ããªãã ãããã®ã«ãŒã«ãæºããããšãã§ãããã©ãããå€å®ããã§ããå Žåã¯"Yes"ããã§ããªãå Žåã¯"No"ãåºåããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã n u v a 1 b 1 a 2 b 2 ... a nâ1 b nâ1 1è¡ç®ã«3ã€ã®æŽæ° n , u , v ã空çœåºåãã§äžããããã 2è¡ç®ãã n è¡ç®ãŸã§ã«ã2ã€ã®æŽæ° a i , b i ã空çœåºåãã§äžããããã Constraints 2 †n †10 5 1 †a i , b i , u , v †n u â v a i < b i ( a i , b i ) â ( a j , b j ) ( i â j ) Output ã«ãŒã«ãæºããããšãã§ããå Žåã¯"Yes"ããã§ããªãå Žåã¯"No"ã1è¡ã«åºåããã Sample Input 1 4 1 4 1 2 2 3 3 4 Sample Output 1 Yes Sample Input 2 8 3 6 1 2 2 4 3 4 4 5 5 6 6 7 7 8 Sample Output 2 No Sample Input 3 4 2 3 1 2 2 3 3 4 Sample Output 3 Yes Sample Input 4 6 1 5 1 2 1 4 2 3 4 5 3 6 Sample Output 4 No | 37,625 |
Problem H: Testing Sorting Networks A N sorting network is a circuit that accepts N numbers as its input, outputs them sorted. Mr. Smith is an engineer of a company that sells various sizes of the circuit. One day, the company got an order of N sorting networks. Unfortunately, they didn't have the circuit for N numbers at the time. The clerk once declined the order for being out of stock, but the client was so urgent that he offered much money if he could get the circuit in a week. The deal escalated to a manager, and she asked Mr. Smith for a solution to produce the N sorting networks by the deadline. He came up with an idea to combine several N/2 sorting networks, because he noticed that they have many stocks of the circuits for N/2 numbers. He designed a new circuit using the N/2 sorting networks, but he was not sure if it would really work as an N sorting network. So, he asked a colleague, you, to check if it was actually an N sorting network. The circuit he designed consists of multiple stages. Each stage of the circuit consists of two N/2 sorting networks, which makes each stage accept a sequence of N numbers as inputs and output a sequence of N numbers. From the 1st to the N/2 -th input numbers of a stage goes to one of those N/2 sorting networks, and from the (N/2+1) -th to the N -th input numbers goes to the other. Similarly, the first half of the output numbers of a stage is the output of the former sorting network and the second half is the output of the latter, both of which are sorted in ascending order. Each output of a stage is connected to exactly one input of the next stage, and no two inputs are connected to the same output line. The input of the last stage is the input of the whole circuit and the output of the first stage is the output of the whole circuit. Input The input begins with a line containing a positive even integer N (4 <= N <= 100) and a positive integer D (1 <= D <= 10). N indicates the number of the input and output of the circuit and D indicates the number of the stages of the circuit. The i -th line of the following D-1 lines contains N integers w i 1 , w i 2 ,..., w i N (1 <= w i j <= N ), which describes the wiring between the i -th and (i+1) -th stages. w i j indicates the j -th input of the i -th stage and the w i j -th output of the (i+1) -th stage are wired. You can assume w i 1 , w i 2 ,..., w i N are unique for each i . Output Print a line containing "Yes" if the circuit works as an N sorting network. Print "No" otherwise. Sample Input 1 4 4 1 3 4 2 1 4 2 3 1 3 2 4 Output for the Sample Input 1 Yes Sample Input 2 4 3 3 1 2 4 1 3 2 4 Output for the Sample Input 2 No | 37,626 |
å顿 圱ã®é女 ELSAMARIA ã¯ãã¹ãŠã®ãã®ã«å¯ŸããŠç¥ããç¶ããé女ã§ããïŒåœ±ã«æãŸã£ãããããåœã¯ãã®é女ã®äžã«åŒããã蟌ãŸããŠããŸãïŒ åœ±ã¯è§Šæã®ããã«åã çŸæš¹ããã ãåŒããã蟌ãããšçã£ãŠããïŒ çŸæš¹ããã ã¯ãã®éå¥³ã«æãŸãããšãªãæ»æããããã«ïŒé女ã«ãšã£ãŠäºæž¬ã®é£ããã§ããããªåããããããšãèããïŒå
·äœçã«ã¯ïŒãŸãé ã®äžã§ 1 ãã N ãŸã§ã®æŽæ°ãäžæ§ãªç¢ºçã§ K åäœãïŒãã®åèšå€ã®è·é¢ã ãä»ã®äœçœ®ããéå¥³ã®æ¹åãžãžã£ã³ãããïŒãšããããšãç¹°ãè¿ãã®ã§ããïŒãããŠé女ã®äœçœ®ã«å°éããæã«æ»æããã®ã§ããïŒ ããã ãšé女ã¯ããäžçŽç·äžã«ãããšãïŒæåé女ã¯åº§æš 0 ïŒ ããã ã¯åº§æš S ã®äœçœ®ã«ãããã®ãšããïŒãŸãé女ã¯åããªããã®ãšããïŒäœåºŠãžã£ã³ãããåŸã«éå¥³ã«æåã®æ»æãäžããããšãã§ããã ãããïŒæåŸ
å€ãæ±ããïŒ å
¥ååœ¢åŒ å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããïŒ S\ N\ K S ã¯æåã« ããã ããã座æšã§ããïŒ N 㯠ããã ãé ã®äžã§äœãæŽæ°ã®ç¯å²ã®äžéïŒ K 㯠ããã ã 1 åã®ãžã£ã³ãã«çšããæŽæ°ã®åæ°ã§ããïŒ åºååœ¢åŒ ããã ãé女ã®äœçœ®ã«å°éããããã«å¿
èŠãªãžã£ã³ãã®åæ°ã®æåŸ
å€ã 1 è¡ã«åºåããïŒããäœåºŠãžã£ã³ãããŠãé女ã®äœçœ®ãžå°éã§ããªãïŒãããã¯æåŸ
å€ãæéå€ã«åãŸããªãå Žå㯠-1 ãšåºåããïŒ å°æ°ç¹ä»¥äžäœæ¡ã§ãåºåããŠæ§ããªããïŒçžå¯Ÿèª€å·®ãããã¯çµ¶å¯Ÿèª€å·®ã 10 -6 æªæºã«ãªã£ãŠããªããã°ãªããªãïŒ å¶çŽ -10 9 †S †10 9 1 †N †10 1 †K †10 å
¥åå€ã¯å
šãп޿°ã§ããïŒ å
¥åºåäŸ å
¥åäŸ 1 6 6 1 åºåäŸ1 6.00000000 å
¥åäŸ 2 -100 7 5 åºåäŸ 2 43.60343043 å
¥åäŸ 3 756434182 9 10 åºåäŸ 3 15128783.80867078 Problem Setter: Flat35 | 37,627 |
X-Ray Screening System ãã㯠20XX 幎ã®è©±ã§ããïŒåççºé»ç¶²ã«ããå®å®ãããšãã«ã®ãŒäŸçµŠïŒããã³æ¶²ååæçæã®çºæã«ãã£ãŠèªç©ºæ
客æ°ã¯é°»ç»ãã«å¢å ããïŒãããïŒèªç©ºæ©ã«ãããããªãºã ã®è
åšã¯äŸç¶ãšããŠååšããããïŒé«éã§ãã€é«ãä¿¡é Œæ§ããã€èªåæè·ç©æ€æ»ã·ã¹ãã ã®éèŠæ§ãé«ãŸã£ãŠããïŒæ€æ»å®ãå
šéšã®è·ç©ã調ã¹ãããšã¯å®éåé¡ãšããŠå°é£ã§ããããšããïŒèªåæ€æ»ã«ãããŠçããããšå€æãããæè·ç©ã ããæ€æ»å®ã§æ¹ããŠèª¿ã¹ããšããä»çµã¿ãæŽãããããã§ããïŒ èªç©ºæ©æ¥çããã®èŠè«ãåãïŒåœé客宀ä¿è·äŒç€ŸïŒInternational Cabin Protection CompanyïŒã§ã¯ïŒæ°ããªèªåæ€æ»ã·ã¹ãã ãéçºããããïŒæè¿ã®æ
å®¢ã®æè·ç©ã«ã€ããŠèª¿æ»ããïŒèª¿æ»ã®çµæïŒæè¿ã®æ
å®¢ã®æè·ç©ã«ã¯æ¬¡ã®ãããªåŸåãããããšã倿ããïŒ æè·ç©ã¯ 1 蟺ã ããçãçŽæ¹äœã®ãããªåœ¢ç¶ãããŠããïŒ äžè¬ã®ä¹å®¢ãæè·ç©ã«è©°ããŠèªç©ºæ©ã«æã¡èŸŒãåç©ãšããŠã¯ããŒãããœã³ã³ïŒé³æ¥œãã¬ã€ã€ãŒïŒæºåž¯ã²ãŒã æ©ïŒãã©ã³ããªã©ãããïŒãããã¯ããããé·æ¹åœ¢ã§ããïŒ åã
ã®åç©ã¯ïŒãã®é·æ¹åœ¢ã®èŸºãæè·ç©ã®èŸºãšå¹³è¡ã«ãªãããã«è©°ãããŸããïŒ äžæ¹ïŒãããªãºã ã«çšãããããããªæŠåšã¯ïŒé·æ¹åœ¢ãšã¯éåžžã«ç°ãªã圢ç¶ããã€ïŒ äžèšã®èª¿æ»çµæããµãŸããŠïŒä»¥äžã®ãããªæè·ç©æ€æ»ã®ããã®ã¢ãã«ãèæ¡ããïŒããããã®æè·ç©ã¯ X ç·ã«å¯ŸããŠéæã§ããçŽæ¹äœã®å®¹åšã ãšã¿ãªãïŒãã®äžã«ã¯ X ç·ã«å¯ŸããŠäžéæã§ããè€æ°ã®åç©ãå
¥ã£ãŠããïŒããã§ïŒçŽæ¹äœã® 3 蟺ã x 軞ïŒy 軞ïŒz 軞ãšãã座æšç³»ãèãïŒx 軞ãšå¹³è¡ãªæ¹åã« X ç·ãç
§å°ããŠïŒy-z å¹³é¢ã«æåœ±ãããç»åãæ®åœ±ããïŒæ®åœ±ãããç»åã¯é©åœãªå€§ããã®æ Œåã«åå²ããïŒç»åè§£æã«ãã£ãŠïŒããããã®æ Œåé åã«æ ã£ãŠããåç©ã®æè³ªãæšå®ãããïŒãã®äŒç€Ÿã«ã¯éåžžã«é«åºŠã®è§£ææè¡ãããïŒæè³ªã®è©³çްãªéããããè§£æããããšãå¯èœã§ããããšããïŒåç©ã®æè³ªã¯äºãã«ç°ãªããšèããããšãã§ããïŒãªãïŒè€æ°ã®åç©ã x 軞æ¹åã«é¢ããŠéãªã£ãŠãããšãã¯ïŒããããã®æ Œåé åã«ã€ããŠæãæåã«ããïŒããªãã¡ x 座æšãæå°ã§ããåç©ã®æè³ªãåŸãããïŒãŸãïŒ2 ã€ä»¥äžã®åç©ã® x 座æšãçããããšã¯ãªããšä»®å®ããïŒ ããªãã®ä»äºã¯ïŒç»åè§£æã®çµæãäžãããããšãã«ïŒé·æ¹åœ¢ã§ã¯ãªãïŒæŠåšã§ãããããããªãïŒåç©ãå
¥ã£ãŠããããšãæèšã§ãããïŒãããã¯ãã®æè·ç©ã«ã¯é·æ¹åœ¢ã®åç©ä»¥å€ã®ãã®ã¯å
¥ã£ãŠããªããšæšæž¬ãããããå€å®ããããã°ã©ã ãäœæããããšã§ããïŒ Input å
¥åã®å
é è¡ã«ã¯åäžã®æ£ã®æŽæ°ãå«ãŸãïŒããã¯ããŒã¿ã»ããã®åæ°ã衚ãïŒããããã®ããŒã¿ã»ããã¯æ¬¡ã®åœ¢åŒã§äžããããïŒ H W è§£æçµæãã®1 è§£æçµæãã®2 ... è§£æçµæãã® H H ã¯ç»åã®çžŠã®å€§ããïŒ W ã¯æšªã®å€§ãããè¡šãæŽæ°ã§ãã (1 <= h , w <= 50)ïŒè§£æçµæã®åè¡ã¯ W æåã§æ§æãããŠããïŒ i çªç®ã®æåã¯ïŒè¡ã®å·Šãã i çªç®ã«ããæ Œåé åã«ãããè§£æçµæã衚ãïŒç©è³ªãæ€åºãããæ Œåé åã«ã€ããŠã¯ïŒãã®æè³ªãè±å€§æåïŒAãZïŒã«ãã£ãŠè¡šãããïŒãã®ãšãïŒåãæè³ªã§ããã°åãæåãïŒãŸãç°ãªãæè³ªã§ããã°ç°ãªãæåãçšããããïŒç©è³ªãæ€åºãããªãã£ãæ Œåé åã«ã€ããŠã¯ãããïŒ.ïŒã§è¡šãããïŒ ãã¹ãŠã®ããŒã¿ã»ããã«ã€ããŠïŒæè³ªã®çš®é¡ã¯ 7 çš®é¡ãè¶
ããªãããšãä¿èšŒãããŠããïŒ Output ããããã®ããŒã¿ã»ããã«å¯ŸããŠïŒé·æ¹åœ¢ä»¥å€ã®åç©ã確å®ã«å
¥ã£ãŠãããšãã¯ãSUSPICIOUSããïŒããã§ãªããšãã¯ãSAFEãããããã 1 è¡ã«åºåããªããïŒ Sample Input 6 1 1 . 3 3 ... .W. ... 10 10 .......... .DDDDCCC.. .DDDDCCC.. .DDDDCCC.. ADDDDCCC.. AAA..CCC.. AAABBBBC.. AAABBBB... ..BBBBB... .......... 10 10 .......... .DDDDDD... .DDDDCCC.. .DDDDCCC.. ADDDDCCC.. AAA..CCC.. AAABBBBC.. AAABBBB... ..BBBBB... .......... 10 10 R..E..C.T. R.EEE.C.T. .EEEEE.... EEEEEEE... .EEEEEEE.. ..EEEEEEE. ...EEEEEEE ....EEEEE. .....EEE.. ......E... 16 50 .................................................. .........AAAAAAAAAAAAAAAA......................... ....PPP...AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA..... ....PPP...AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA..... ....PPP...AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.... ....PPP..............AAAAA.AAAAAAAAAAAAAAAA....... ....PPP................A....AAA.AAAAAAAAAA........ ....PPP...........IIIIIAAIIAIII.AAAAAAAAAA........ ..CCCCCCCCCCCCC...IIIIIIAAAAAAAAAAAAAAAAAA........ ..CCCCCCCCCCCCC...IIIIIIIIIIIII...AAAAAAAAAA...... ....PPP............................AAAAAAAAAA..... MMMMPPPMMMMMMMMMMMMMMM.............AAAAAAAAAAA.... MMMMPPPMMMMMMMMMMMMMMM..............AAAAAAAAAAA... MMMMMMMMMMMMMMMMMMMMMM...............AAAAAAAAAA... MMMMMMMMMMMMMMMMMMMMMM...............AAAAAAAAAA... MMMMMMMMMMMMMMMMMMMMMM............................ Output for the Sample Input SAFE SAFE SAFE SUSPICIOUS SUSPICIOUS SUSPICIOUS | 37,628 |
Problem H: Magic Walls You are a magician and have a large farm to grow magical fruits. One day, you saw a horde of monsters, approaching your farm. They would ruin your magical farm once they reached your farm. Unfortunately, you are not strong enough to fight against those monsters. To protect your farm against them, you decided to build magic walls around your land. You have four magic orbs to build the walls, namely, the orbs of Aquamarine (A), Bloodstone (B), Citrine (C) and Diamond (D). When you place them correctly and then cast a spell, there will be magic walls between the orbs A and B, between B and C, between C and D, and between D and A. The walls are built on the line segments connecting two orbs, and form a quadrangle as a whole. As the monsters cannot cross the magic walls, the inside of the magic walls is protected. Nonetheless, you can protect only a part of your land, since there are a couple of restrictions on building the magic walls. There are N hills in your farm, where the orbs can receive rich power of magic. Each orb should be set on the top of one of the hills. Also, to avoid interference between the orbs, you may not place two or more orbs at the same hill. Now, you want to maximize the area protected by the magic walls. Please figure it out. Input The input begins with an integer N (4 †N †1500), the number of the hills. Then N line follow. Each of them has two integers x (0 †x †50000) and y (0 †y †50000), the x - and y -coordinates of the location of a hill. It is guaranteed that no two hills have the same location and that no three hills lie on a single line. Output Output the maximum area you can protect. The output value should be printed with one digit after the decimal point, and should be exact. Sample Input 1 5 2 0 0 1 1 3 4 2 3 4 Output for the Sample Input 1 7.5 Sample Input 2 4 0 0 0 3 1 1 3 0 Output for the Sample Input 2 3.0 | 37,629 |
Problem G: Surface Area of Cubes Taro likes a single player game "Surface Area of Cubes". In this game, he initially has an $A \times B \times C$ rectangular solid formed by $A \times B \times C$ unit cubes (which are all 1 by 1 by 1 cubes). The center of each unit cube is placed at 3-dimentional coordinates $(x, y, z)$ where $x$, $y$, $z$ are all integers ($0 \leq x \leq A-1, 0 \leq y \leq B -1, 0 \leq z \leq C - 1$). Then, $N$ distinct unit cubes are removed from the rectangular solid by the game master. After the $N$ cubes are removed, he must precisely tell the total surface area of this object in order to win the game. Note that the removing operation does not change the positions of the cubes which are not removed. Also, not only the cubes on the surface of the rectangular solid but also the cubes at the inside can be removed. Moreover, the object can be divided into multiple parts by the removal of the cubes. Notice that a player of this game also has to count up the surface areas which are not accessible from the outside. Taro knows how many and which cubes were removed but this game is very difficult for him, so he wants to win this game by cheating! You are Taro's friend, and your job is to make a program to calculate the total surface area of the object on behalf of Taro when you are given the size of the rectangular solid and the coordinates of the removed cubes. Input The input is formatted as follows. The first line of a test case contains four integers $A$, $B$, $C$, and $N$ ($1 \leq A, B, C \leq 10^8, 0 \leq N \leq $ min{$1,000, A \times B \times C - 1$}). Each of the next $N$ lines contains non-negative integers $x$, $y$, and $z$ which represent the coordinate of a removed cube. You may assume that these coordinates are distinct. Output Output the total surface area of the object from which the $N$ cubes were removed. Sample Input 2 2 2 1 0 0 0 Output for the Sample Input 24 Sample Input 1 1 5 2 0 0 1 0 0 3 Output for the Sample Input 18 Sample Input 3 3 3 1 1 1 1 Output for the Sample Input 60 | 37,630 |
Score : 700 points Problem Statement Snuke has decided to play a game, where the player runs a railway company. There are M+1 stations on Snuke Line, numbered 0 through M . A train on Snuke Line stops at station 0 and every d -th station thereafter, where d is a predetermined constant for each train. For example, if d = 3 , the train stops at station 0 , 3 , 6 , 9 , and so forth. There are N kinds of souvenirs sold in areas around Snuke Line. The i -th kind of souvenirs can be purchased when the train stops at one of the following stations: stations l_i , l_i+1 , l_i+2 , ... , r_i . There are M values of d , the interval between two stops, for trains on Snuke Line: 1 , 2 , 3 , ... , M . For each of these M values, find the number of the kinds of souvenirs that can be purchased if one takes a train with that value of d at station 0 . Here, assume that it is not allowed to change trains. Constraints 1 ⊠N ⊠3 à 10^{5} 1 ⊠M ⊠10^{5} 1 ⊠l_i ⊠r_i ⊠M Input The input is given from Standard Input in the following format: N M l_1 r_1 : l_{N} r_{N} Output Print the answer in M lines. The i -th line should contain the maximum number of the kinds of souvenirs that can be purchased if one takes a train stopping every i -th station. Sample Input 1 3 3 1 2 2 3 3 3 Sample Output 1 3 2 2 If one takes a train stopping every station, three kinds of souvenirs can be purchased: kind 1 , 2 and 3 . If one takes a train stopping every second station, two kinds of souvenirs can be purchased: kind 1 and 2 . If one takes a train stopping every third station, two kinds of souvenirs can be purchased: kind 2 and 3 . Sample Input 2 7 9 1 7 5 9 5 7 5 9 1 1 6 8 3 4 Sample Output 2 7 6 6 5 4 5 5 3 2 | 37,631 |
Problem C: How can I satisfy thee? Let me count the ways... Three-valued logic is a logic system that has, in addition to "true" and "false", "unknown" as a valid value. In the following, logical values "false", "unknown" and "true" are represented by 0, 1 and 2 respectively. Let "-" be a unary operator (i.e. a symbol representing one argument function) and let both "*" and "+" be binary operators (i.e. symbols representing two argument functions). These operators represent negation (NOT), conjunction (AND) and disjunction (OR) respectively. These operators in three-valued logic can be defined in Table C-1. Table C-1: Truth tables of three-valued logic operators -X (X*Y) (X+Y) Let P, Q and R be variables ranging over three-valued logic values. For a given formula, you are asked to answer the number of triples (P,Q,R) that satisfy the formula, that is, those which make the value of the given formula 2. A formula is one of the following form (X and Y represent formulas). Constants: 0, 1 or 2 Variables: P, Q or R Negations: -X Conjunctions: (X*Y) Disjunctions: (X+Y) Note that conjunctions and disjunctions of two formulas are always parenthesized. For example, when formula (P*Q) is given as an input, the value of this formula is 2 when and only when (P,Q,R) is (2,2,0), (2,2,1) or (2,2,2). Therefore, you should output 3. Input The input consists of one or more lines. Each line contains a formula. A formula is a string which consists of 0, 1, 2, P, Q, R, -, *, +, (, ). Other characters such as spaces are not contained. The grammar of formulas is given by the following BNF. <formula> ::= 0 | 1 | 2 | P | Q | R | -<formula> | (<formula>*<formula>) | (<formula>+<formula>) All the formulas obey this syntax and thus you do not have to care about grammatical errors. Input lines never exceed 80 characters. Finally, a line which contains only a "." (period) comes, indicating the end of the input. Output You should answer the number (in decimal) of triples (P,Q,R) that make the value of the given formula 2. One line containing the number should be output for each of the formulas, and no other characters should be output. Sample Input (P*Q) (--R+(P*Q)) (P*-P) 2 1 (-1+(((---P+Q)*(--Q+---R))*(-R+-P))) . Output for the Sample Input 3 11 0 27 0 7 | 37,632 |
Electric Metronome A boy PCK is playing with N electric metronomes. The i -th metronome is set to tick every t_i seconds. He started all of them simultaneously. He noticed that, even though each metronome has its own ticking interval, all of them tick simultaneously from time to time in certain intervals. To explore this interesting phenomenon more fully, he is now trying to shorten the interval of ticking in unison by adjusting some of the metronomesâ interval settings. Note, however, that the metronomes do not allow any shortening of the intervals. Given the number of metronomes and their preset intervals t_i (sec), write a program to make the tick-in-unison interval shortest by adding a non-negative integer d_i to the current interval setting of the i -th metronome, and report the minimum value of the sum of all d_i . Input The input is given in the following format. N t_1 t_2 : t_N The first line provides the number of metronomes N (1 †N †10 5 ). Each of the subsequent N lines provides the preset ticking interval t_i (1 †t_i †10 4 ) of the i -th metronome. Output Output the minimum value. Sample Input 1 3 3 6 8 Sample Output 1 3 If we have three metronomes each with a ticking interval of 3, 6, and 8 seconds, respectively, simultaneous activation of these will produce a tick in unison every 24 seconds. By extending the interval by 1 second for the first, and 2 seconds for the second metronome, the interval of ticking in unison will be reduced to 8 seconds, which is the shortest possible for the system. Sample Input 2 2 10 10 Sample Output 2 0 If two metronomes are both set to 10 seconds, then simultaneous activation will produce a tick in unison every 10 seconds, which is the shortest possible for this system. | 37,633 |
ãµã€ã³ãããºã« åé¢ã«ã¢ã«ãã¡ãããäžæå(a ã zãA ã Z)ãæããããµã€ã³ãããããŸãã ãã®ãããªãµã€ã³ãã8ã€çµã¿åãã㊠2 à 2 à 2 ã®ç«æ¹äœãäœãããšãèããŸãã çµã¿åããæ¹ã«ã¯æ¡ä»¶ããããåãµã€ã³ãã®åãåãé¢ã¯åãã¢ã«ãã¡ãããã§ãã€äžæ¹ãå°æåãã ãäžæ¹ã倧æåã§ãªããã°ãªããŸãããäŸãã°ãa ãšæãããé¢ã«æ¥ããããšãã§ããã®ã¯ A ãšæã ããé¢ã§ãããã ããæ¥ãããšãã®æåã®åãã¯åããŸããã ãã®ã«ãŒã«ã«åŸããïŒã€ã®ãµã€ã³ãã®æ
å ±ãå
¥åãšããç«æ¹äœãäœãããåŠããå€å®ããããã°ã©ã ãäœæããŠãã ãããç«æ¹äœãäœããå Žå㯠YESïŒåè§è±å€§æåïŒãäœããªãå Žå㯠NOïŒåè§è±å€§æåïŒãšåºåããŠãã ããã ãªãããµã€ã³ãã®åé¢ã®æåãæ¬¡ã®å³ã«ããããã« c1 ã c6 ãšè¡šãããšã«ããŸãã ãŸãã1ã€ã®ãµã€ã³ãã«åãæåãè€æ°åæãããŠããããšã¯ç¡ããã®ãšããŸãïŒåãã¢ã«ãã¡ãããã®å€§æåãšå°æåã¯ãã®éãã§ã¯ãããŸããïŒã Input è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸãã åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã s 1 s 2 : s 8 i è¡ç®ã« i åç®ã®ãµã€ã³ãã®æ
å ± s i ãäžããããŸãã s i ã¯é·ã 6 ã®æååã§ãã j æåç®ããµã€ã³ãã®åé¢ cj ã«å¯Ÿå¿ããŸãã ããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã Output ããŒã¿ã»ããããšã«å€å®çµæïŒåè§è±å€§æåïŒãïŒè¡ã«åºåããŸãã Sample Input zabZNq BCxmAi ZcbBCj aizXCm QgmABC JHzMop ImoXGz MZTOhp zabZnQ BCxmAi ZcbBCj aizXCm QgmABC JHzMop ImoXGz MZTOhp abcdef ABDCFE FBDCAE abcdef BEACDF bfcaed fabcde DEABCF UnivOf AizuaH zTXZYW piglIt GRULNP higGtH uAzIXZ FizmKZ UnivOf AizuaH piglIt higGtH GRULNP uAzIXZ FizmKZ ZTXzYW 0 Output for the Sample Input YES NO YES YES NO | 37,634 |
JOI çŽç« (JOI Emblem) æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒã§ã¯ïŒå°æ¹Ÿå€§äŒã«åããéžæãå¿æŽããããã«æ°ããJOI æãäœæããããšã«ããïŒ JOI æã¯ïŒæ£æ¹åœ¢ã瞊㫠$M$ è¡ïŒæšªã« $N$ å䞊ãã 圢ãããŠããïŒåæ£æ¹åœ¢ã«ã¯ JïŒOïŒI ã®ããããã®æåã1 ã€ãã€æžãããŠããïŒ æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒã¯JOI æãšã¯å¥ã«JOI çŽç« ãšãããã®ã決ããŠããïŒJOI çŽç« ã¯ïŒæ£æ¹åœ¢ã瞊ã«2 è¡ïŒæšªã«2 å䞊ãã 圢ãããŠããïŒåæ£æ¹åœ¢ã«ã¯JïŒOïŒI ã®ããããã®æåã1 ã€ãã€æžãããŠããïŒ JOI æã«å«ãŸããJOI çŽç« ã®åæ°ãšã¯ïŒJOI æã«å«ãŸãã瞊2 è¡ïŒæšª2 åã®é åã®ãã¡ïŒãã®é åã®JïŒOïŒI ã®é
眮ãJOI çŽç« ãš(å転ãè£è¿ããããã«) äžèŽããŠãããã®ã®åæ°ã®ããšã§ããïŒæ¡ä»¶ãæºãã瞊2 è¡ïŒæšª2 åã®é åå士ãéãªã£ãŠããŠãããããå¥ã
ã«æ°ãããã®ãšããïŒ æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒã¯å€ãJOI æãš1 æã®çœçŽãæã£ãŠããïŒçœçŽã¯JOI æãæ§æããæ£æ¹åœ¢1 ååã®å€§ããã§ïŒJïŒOïŒI ã®ãã¡å¥œããª1 æåãæžã蟌ãããšãã§ããïŒæ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒã¯ä»¥äžã®ãããã1 ã€ã®æäœãããŠïŒæ°ããJOI æãäœæããããšã«ããïŒ å€ãJOI æã«å¯ŸããŠäœãæäœããïŒãã®ãŸãŸæ°ããJOI æãšããïŒçœçŽã¯äœ¿çšããªãïŒ çœçŽã«1 æåæžã蟌ã¿ïŒå€ãJOI æã®ããããã®æ£æ¹åœ¢ã«éããŠè²Œãä»ããããšã§å€ãJOI æã®ãã¡1 ç®æã倿ŽããïŒå€æŽåŸã®JOI æãæ°ããJOI æãšããïŒ æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒã¯æ°ããJOI æã«å«ãŸããJOI çŽç« ã®åæ°ãã§ããã ãå€ãããããšæã£ãŠããïŒããªãã¯æ°ããJOI æã«å«ãŸããJOI çŽç« ã®åæ°ã®æå€§å€ãæ±ããããšã«ãªã£ãïŒ èª²é¡ å€ãJOI æãšJOI çŽç« ã®æ
å ±ãäžãããããšãïŒæ°ããJOI æã«å«ãŸããJOI çŽç« ã®åæ°ã®æå€§å€ãæ±ããããã°ã©ã ãäœæããïŒ å
¥å æšæºå
¥åãã以äžã®ããŒã¿ãèªã¿èŸŒãïŒ 1 è¡ç®ã«ã¯2 åã®æŽæ° $M, N$ ã空çœãåºåããšããŠæžãããŠããïŒããã¯JOI æãæ£æ¹åœ¢ã瞊ã«$M$è¡ïŒæšªã«$N$ å䞊ãã 圢ã§ããããšã衚ããŠããïŒ ç¶ã$M$ è¡ã®åè¡ã«ã¯ïŒãããã$N$ æåãããªãæååãæžãããŠããïŒåæåã¯JïŒOïŒI ã®ããããã§ããïŒ$M$ è¡ã®ãã¡äžãã$i$ è¡ç®$(1 \leq i \leq M)$ ã«æžãããŠããæååã®å·Šãã$j$ æåç®$(1 \leq j \leq N)$ã¯å€ãJOI æã®äžãã$i$ è¡ç®ïŒå·Šãã$j$ åç®ã®æ£æ¹åœ¢ã«æžãããŠããæåã衚ãïŒ ç¶ã2 è¡ã®åè¡ã«ã¯ïŒãããã2 æåãããªãæååãæžãããŠããïŒåæåã¯JïŒOïŒI ã®ããããã§ããïŒ2 è¡ã®ãã¡äžãã$i$ è¡ç®$(1 \leq i \leq 2)$ ã«æžãããŠããæååã®å·Šãã$j$ æåç®$(1 \leq j \leq 2)$ ã¯JOI çŽç« ã®äžãã$i$ è¡ç®ïŒå·Šãã$j$ åç®ã®æ£æ¹åœ¢ã«æžãããŠããæåã衚ãïŒ åºå æšæºåºåã«ïŒæ°ããJOI æã«å«ãŸããJOI çŽç« ã®åæ°ã®æå€§å€ãè¡šãæŽæ°ã1 è¡ã§åºåããïŒ å¶çŽ ãã¹ãŠã®å
¥åããŒã¿ã¯ä»¥äžã®æ¡ä»¶ãæºããïŒ $2 \leq M \leq 1000$ $2 \leq N \leq 1000$ å
¥åºåäŸ å
¥åäŸ 1 3 5 JOIJO IJOOO IIJIJ JO IJ åºåäŸ 1 3 å€ãJOI æãšJOI çŽç« ã¯å顿äžã®äŸã®éãã§ããïŒäžãã2 è¡ç®ïŒå·Šãã4 åç®ã®æ£æ¹åœ¢ãçœçŽãçšããŠJ ã«å€æŽãããšïŒæ¬¡ã®ãããªåœ¢ã«ãªãïŒ ãã®ããã«å€æŽããåŸã®JOI æã«ã¯æ¬¡ã«ç€ºã3 ç®æã«JOI çŽç« ãšåãé
眮ã®é åãããïŒ JOI çŽç« ãšåãé
眮ã®é åã4 ç®æä»¥äžãšãªãæ°ããJOI æã¯ååšããªãã®ã§ïŒæ°ããJOI æã«å«ãŸããJOI çŽç« ã®åæ°ã®æå€§å€ã¯3 ã§ããïŒ å
¥åäŸ 2 2 6 JOJOJO OJOJOJ OJ JO åºåäŸ 2 2 çœçŽã䜿çšããªããŠãæå€§å€ãåŸãããå Žåãããããšã«æ³šæããïŒ å
¥åäŸ 3 2 2 JI IJ JJ JJ åºåäŸ 3 0 ãã®å
¥åºåäŸã®å ŽåïŒèããããã©ã®æ°ããJOI æã«ãããŠãïŒJOI çŽç« ã1 ã€ãå«ãŸããªãïŒ å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã | 37,635 |
A : Taps / èå£ Problem ããã¥åã®å®¶ã®æµŽæ§œã«ã¯2ã€ã®èå£ A , B ãã€ããŠããã ã²ãããšã²ãã£ãè§åºŠã«æ¯äŸããéã®æ°ŽãåºãŠããã åºãŠããæ°Žã®æž©åºŠã¯ A 㯠t A [â]ã B 㯠t B [â]ã§äžå®ã§ããã 颚åã«å
¥ããšãã«ã¯ãããã®éã調ç¯ããŠæ··ãããããããšã§é©åºŠãªæž©åºŠã«ãªãããã«ããŠããã t A [â] ã®æ°Ž v A [L] ãš t B [â]ã®æ°Ž v B [L] ãæ··ãåãããåŸã®æž©åºŠã¯ã( t A à v A + t B à v B ) / ( v A + v B ) ã«ãªãã äŸãã°ã t A = 80â, t B = 20â ã§ 40â ã®ã湯ã匵ããããšãã«ã¯ã A ãã 100mL/s ã B ãã 200mL/s ãã€åºãããã«èå£ã調ç¯ããã°ããã ãšãããããã®ããèå£ãèæœåããŠãããã A 㯠d A [mL/s] ã B 㯠d B [mL/s] åäœã§ãã åºãæ°Žã®éã調ç¯ã§ããªããªã£ãŠããŸã£ãã ããªãã¡ã A ããåºãæ°Žã®éã 0, d A , 2à d A , 3à d A , ...[mL/s] ãšãã é£ã³é£ã³ã®å€ã«ããèšå®ã§ããªããªã£ãŠããŸã£ãã®ã§ãã( B ãåæ§)ã ããã¥åã¯é·å¹Žå¹ã£ãŠããåã«ãã£ãŠçã£ã枩床ãŽã£ãã㫠調ç¯ã§ããã®ã ãããããéçšããªããªã£ãã å°ã£ãããã¥åã¯ãèªåçã«ç®çã®æž©åºŠ T [â] ã«æãè¿ã枩床ã«ãªããããªæ°Žã®åºãæ¹ã«èª¿ç¯ããããã°ã©ã ãæžãããšã«ããã ãã ããæ¯ç§åºããæ°Žã®éã«ã¯äžéãããã A ãš B ã®æ°Žã®éã®å㯠D [mL/s] 以äžã§ãªããã°ãªããªãã ãŸããæ°Žãåºããªãããšã«ã¯ã颚åã«å
¥ããªããããæ¯ç§åºãæ°Žã®éã¯æäœã§ã 1mL/s 以äžã§ãªããã°ãªããªãã ã€ãŸãã 1 ⊠A ããåºãæ°Žã®é + B ããåºãæ°Žã®é ⊠D ãæºããå¿
èŠãããã Input å
¥åã¯æ¬¡ã®ãããªåœ¢åŒã§äžããããïŒ T D t A t B d A d B 1è¡ç®ã® T , D ã¯ãããããç®çã®æž©åºŠãæ°Žã®éã®äžéã衚ãã 2è¡ç®ã® t A , t B ã¯ããããã A ã®æž©åºŠã B ã®æž©åºŠã衚ãã 3è¡ç®ã® d A , d B ã¯ããããã A ããåºãæ°Žã®éã®åäœã B ããåºãæ°Žã®éã®åäœã衚ãã Constraints å
¥åã¯å
šãп޿°ã§ããã 1 ⊠T , t A , t B ⊠99 1 ⊠D ⊠1000 1 ⊠d A , d B ⊠D Output T ã«æãè¿ããªãããã«æ°Žãæ··ãããããåŸã®æž©åºŠãš T ãšã®å·®ã®å€§ããã®æå°å€ã1è¡ã§åºåããããã ãã10 -4 以äžã®èª€å·®ã¯èš±å®¹ãããã Samples Sample Input 1 40 1000 80 20 100 100 Sample Output 1 0.0000000000 å顿ã®äŸã§ããã Sample Input 2 38 1000 80 20 100 95 Sample Output 2 0.2222222222 Aã®èå£ãã 200mL/sãBã®èå£ãã 475mL/s ã®éã®æ°Žãåºãããšãã37.7777...â ãšãªããããã38â ã«æãè¿ããªãã | 37,636 |
Problem I: Common Polynomial Math teacher Mr. Matsudaira is teaching expansion and factoring of polynomials to his students. Last week he instructed the students to write two polynomials (with a single variable x), and to report GCM (greatest common measure) of them as a homework, but he found it boring to check their answers manually. So you are asked to write a program to check the answers. Hereinafter, only those polynomials with integral coefficients, called integral polynomials, are considered. When two integral polynomials A and B are given, an integral polynomial C is a common factor of A and B if there are some integral polynomials X and Y such that A = CX and B = CY . GCM of two integral polynomials is a common factor which has the highest degree (for x , here); you have to write a program which calculates the GCM of two polynomials. It is known that GCM of given two polynomials is unique when constant multiplication factor is ignored. That is, when C and D are both GCM of some two polynomials A and B , p à C = q à D for some nonzero integers p and q . Input The input consists of multiple datasets. Each dataset constitutes a pair of input lines, each representing a polynomial as an expression defined below. A primary is a variable x, a sequence of digits 0 - 9, or an expression enclosed within ( ... ). Examples: x, 99, (x+1) A factor is a primary by itself or a primary followed by an exponent. An exponent consists of a symbol ^ followed by a sequence of digits 0 - 9. Examples: x^05, 1^15, (x+1)^3 A term consists of one or more adjoining factors. Examples: 4x, (x+1)(x-2), 3(x+1)^2 An expression is one or more terms connected by either + or -. Additionally, the first term of an expression may optionally be preceded with a minus sign -. Examples: -x+1, 3(x+1)^2-x(x-1)^2 Integer constants, exponents, multiplications (adjoining), additions (+) and subtractions/negations (-) have their ordinary meanings. A sequence of digits is always interpreted as an integer con- stant. For example, 99 means 99, not 9 à 9. Any subexpressions of the input, when fully expanded normalized, have coefficients less than 100 and degrees of x less than 10. Digit sequences in exponents represent non-zero values. All the datasets are designed so that a standard algorithm with 32-bit twoâs complement integers can solve the problem without overflows. The end of the input is indicated by a line containing a period. Output For each of the dataset, output GCM polynomial expression in a line, in the format below. c 0 x^ p 0 ± c 1 x^ p 1 ... ± c n x^ p n Where c i and p i ( i = 0, . . . , n ) are positive integers with p 0 > p 1 > . . . > p n , and the greatest common divisor of { c i | i = 0, . . . , n } is 1. Additionally: When c i is equal to 1, it should be omitted unless corresponding p i is 0, x^0 should be omitted as a whole, and x^1 should be written as x. Sample Input -(x^3-3x^2+3x-1) (x-1)^2 x^2+10x+25 x^2+6x+5 x^3+1 x-1 . Output for the Sample Input x^2-2x+1 x+5 1 | 37,637 |
Problem J: å€é
åŒã®è§£ã®åæ° ãããŸãåã¯å€§åŠã§ããŸããŸãªå€æã«ã€ããŠç ç©¶ããŠãããæè¿ããããŸãåãèå³ãæã£ãŠããå€æã¯æ¬¡ã®ãããªãã®ã§ããã N+1åã®æŽæ° a 0 , ..., a N ãåºå®ããæŽæ° z ãå
¥åãšããããŸã P ãçŽ æ°ãšããã t = ( a N z N + a N-1 z N-1 + ... + a 2 z 2 + a 1 z + a 0 ) mod P ãããŸãåã¯ãã®å€æã«ãã£ãŠ t = 0 ã«ãªã£ãŠããŸã z ãããã€ãããããšã«æ°ãã€ããã ããã§ããããŸãåã¯å人ã§ããã¹ãŒããŒããã°ã©ããŒã§ãããããªãã«ã倿åŸã« t = 0 ã«ãªã z ã 0ãP-1 ã«ããã€ããããèšç®ããŠãããããšã«ããã Input å
¥åã¯æ¬¡ã®åœ¢åŒã§äžããããã N P a 0 a 1 ... a N å
¥åã®1è¡ç®ã«ã¯æŽæ°NãšçŽ æ°Pãã¹ããŒã¹æåã§åºåãããŠäžããããããããã¯ãå顿ã§äžãããããšããã§ããã 0 †N †100, 2 †P †10 9 ãæºããã æ¬¡ã®1è¡ã«ã¯ a 0 ãa N ãã¹ããŒã¹æåã§åºåãããŠäžãããããããã㯠|a i | †10 9 ãæºããæŽæ°ã§ããããŸã a N â 0 ã§ããã Output 倿åŸã«0ã«ãªããã㪠z (0 †z < P) ã®åæ°ãåºåããã Notes on Test Cases äžèšå
¥å圢åŒã§è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã«å¯ŸããŠäžèšåºå圢åŒã§åºåãè¡ãããã°ã©ã ãäœæããŠäžããã N, P ããšãã« 0 ã®ãšãå
¥åã®çµããã瀺ããŸãã Sample Input 2 3 1 2 1 2 3 1 2 6 0 0 Output for Sample Input 1 1 | 37,638 |
Score : 500 points Problem Statement You have a string A = A_1 A_2 ... A_n consisting of lowercase English letters. You can choose any two indices i and j such that 1 \leq i \leq j \leq n and reverse substring A_i A_{i+1} ... A_j . You can perform this operation at most once. How many different strings can you obtain? Constraints 1 \leq |A| \leq 200,000 A consists of lowercase English letters. Input Input is given from Standard Input in the following format: A Output Print the number of different strings you can obtain by reversing any substring in A at most once. Sample Input 1 aatt Sample Output 1 5 You can obtain aatt (don't do anything), atat (reverse A[2..3] ), atta (reverse A[2..4] ), ttaa (reverse A[1..4] ) and taat (reverse A[1..3] ). Sample Input 2 xxxxxxxxxx Sample Output 2 1 Whatever substring you reverse, you'll always get xxxxxxxxxx . Sample Input 3 abracadabra Sample Output 3 44 | 37,639 |
ããã©å§«ã®ããºã« ãã¬ã¹çåœã®ããã©å§«ã¯ç¡é¡ã®ããºã«å¥œããšããŠç¥ãããŠããïŒæè¿ã¯èªèº«ãèæ¡ãããããã©ããºã«ãã«ç±äžããŠããïŒ ããã¯ïŒæ£äžè§åœ¢ã®ãã¹ãæ·ãè©°ããããŒããšïŒããã©ãããã¯ãšåŒã°ãã 4 æã®æ£äžè§åœ¢ã®ããã«ãããªãæ£åé¢äœã®ãããã¯ã䜿ã£ãããºã«ã§ããïŒ ããºã«ã®ç®çã¯ïŒããŒãäžã®ãã¹ãŠã®ããã©ãããã¯ã以äžã®æ¡ä»¶ãã¿ããããã«å±éããããšã§ããïŒ å±éãããããã©ãããã¯ãïŒçœ®ãããŠãããã¹ããã³ïŒããããã«æå®ãããç°ãªã 2 ã€ã®ãã¹ãèŠã£ãŠãã ã©ã®ãã¹ãïŒ2 ã€ä»¥äžã®ããã«ã§èŠãããŠããªã å³F-1ã¯ããã©ããºã«ã®åé¡äŸããã³ïŒãã®è§£çäŸã§ããïŒ â
ã®ãã¹ãšâã®ãã¹ã«ããã©ãããã¯ã眮ãããŠããïŒãããããâã®ãã¹ãšâã®ãã¹ãèŠãããã«æå®ãããŠããïŒ è§£çäŸã«ãããŠïŒæšªç·ãåŒããããã¹ã¯â
ã®ãã¹ã«çœ®ãããŠããããã©ãããã¯ãå±éããŠèŠã£ããã¹ïŒçžŠç·ã®ãã¹ã¯âã®ãã¹ã«çœ®ãããããã©ãããã¯ã§èŠã£ããã¹ã§ããïŒ å³ F-1: ããã©ããºã«ã®åé¡äŸ(å·Š)ããã³è§£çäŸ(å³) å³F-2ã¯ïŒäžå³ã®åé¡äŸã«ãããç¡å¹ãªè§£çäŸã§ããïŒ å·Šã®äŸã§ã¯â
ã®ãã¹ã®çäžã®ãã¹ã2ã€ã®ããã«ã§èŠãããŠããïŒå³ã®äŸã§ã¯ãããããããã©ãããã¯ãå±éããŠåŸããã圢ç¶ã§ãªãããïŒçããšããŠã¯èªããããªãïŒ å³ F-2: ç¡å¹ãªè§£çäŸ ããã©å§«ã¯ããºã«ã®é¢çœããå€ãã®äººã«ç¥ã£ãŠãããã¹ãïŒæ¥ããå€ã®ç¥å
žã«åããŠããºã«ã®åé¡éãäœã£ãïŒ ãããŠïŒçåœã§äºçªç®ã®ããºã«å¥œããšããŠå§«ããä¿¡é Œã眮ãããŠããããªãã¯ïŒåé¡éã®ãã§ãã¯æ
åœã«ä»»åœãããïŒ ããŠïŒãã§ãã¯äœæ¥ãé²ããŠããããªãã¯å°ã£ãäºã«æ°ãä»ããïŒ åé¡éã«ã¯è§£ãååšããªãããºã«ãå«ãŸããŠãããããªã®ã ïŒ ãªãã¹ãå§«ã®äœã£ãããºã«ãå°éããããšèããããªãã¯ïŒè§£ãååšããªãããºã«ã«ã€ããŠïŒã©ãã 1 åã®ããã©ãããã¯ããã®ããã©ãããã¯ãèŠãã¹ããã¹ã®æ
å ±ããšåé€ããããšã§ïŒããºã«ãè§£ãããã®ã«å€ããããšã«ããïŒ å§«ããèšãæž¡ããããã§ãã¯ã®ç· åããŸã§ã¯ããš3æéãããªãïŒ åé¡éãèŠãªãããŠïŒææ©ãä¿®æ£ãæžãŸããŠããŸããïŒ Input å
¥åã¯è€æ°ã®ããŒã¿ã»ããããæ§æãããïŒ åããŒã¿ã»ããã®åœ¢åŒã¯æ¬¡ã®éãã§ããïŒ n x 1a y 1a x 1b y 1b x 1c y 1c x 2a y 2a x 2b y 2b x 2c y 2c ... x na y na x nb y nb x nc y nc n (2 †n †5,000) ã¯ããŒãã«çœ®ãããããã©ãããã¯ã®æ°ãè¡šãæŽæ°ã§ããïŒ åããã©ãããã¯ã«ã¯ 1 ãã n ã®çªå·ãå²ãåœãŠãããŠããïŒ ç¶ã n è¡ã¯ïŒãããã 1 åã®ã¹ããŒã¹ã§åºåããã 6 åã®æŽæ°ãããªãïŒ (x ia , y ia ) 㯠i çªç®ã®ããã©ãããã¯ã眮ãããŠãããã¹ã®åº§æšã衚ãïŒ(x ib , y ib ) ããã³ïŒ(x ic , y ic ) ã¯ïŒãããã i çªç®ã®ããã©ãããã¯ãå±éããæã«èŠãã¹ããã¹ã®åº§æšã衚ãïŒ äžãããã x 座æšããã³ y 座æšã®çµ¶å¯Ÿå€ã¯ 20,000 以äžãšä»®å®ããŠè¯ãïŒ ãŸãïŒäžãããã座æšã¯å
šãŠäºãã«ç°ãªããšä»®å®ããŠè¯ãïŒ ããªãã¡ïŒåããã¹ã« 2 å以äžã®ããã©ãããã¯ã眮ãããäºãïŒããã©ãããã¯ã眮ãããŠãããã¹ãèŠãã¹ããã¹ãšããŠæå®ãããäºãïŒèŠãã¹ããã¹ãéè€ããŠæå®ãããäºã¯ãªãïŒ åãã¹ã«ã¯å³F-3ã®ããã«åº§æšãå²ãåœãŠãããŠããïŒ å³ F-3: ãã¹ã«å²ãåœãŠãããåº§æš n=0 ã¯å
¥åã®çµããã瀺ãïŒããã¯ããŒã¿ã»ããã«ã¯å«ããªãïŒ Output åããŒã¿ã»ããã«ã€ããŠïŒããã©ãããã¯ãé€ãããšãªãããºã«ãè§£ããå Žå㯠Valid ããããã 1 è¡ã«åºåããªããïŒ ããã©ãããã¯ã 1 åã ãé€ãããšã§ããºã«ãè§£ããããã«ãªãå Žå㯠Remove ã 1 è¡ã«åºåãïŒç¶ããŠé€ãããšã§ããºã«ãè§£ããããã«ãªãããã©ãããã¯ã®çªå·ãå°ãããã®ããé ã«ãããã 1 è¡ã«åºåããªããïŒ 2 å以äžã®ããã©ãããã¯ãé€ããªããšããºã«ãè§£ããããã«ãªããªãå Žå㯠Invalid ã1è¡ã«åºåããªããïŒ Sample Input 3 2 3 2 2 2 1 2 0 1 -1 2 -1 -2 -1 -1 -1 -2 0 6 -1 0 1 0 0 -1 -2 -1 -3 -2 -4 -2 2 -1 2 0 1 -1 4 -2 3 -2 3 -1 1 1 0 1 -1 1 -3 -1 -1 -1 -2 0 5 -1 2 0 2 1 2 -3 1 -2 1 -2 2 -2 0 -2 -1 -3 0 1 -1 0 -1 -1 -1 1 0 2 0 2 -1 4 -2 0 -2 -1 -3 -1 -1 -1 0 -1 1 -1 2 -1 2 0 3 -1 -1 0 0 0 1 0 5 -2 1 3 -1 2 1 -5 2 -5 3 -4 2 -2 -1 0 -1 -3 -1 4 2 5 2 5 3 1 -1 2 -1 -1 -1 0 以äžã®å³ã¯ãããããµã³ãã«ã®é
眮ã瀺ããŠããïŒ å³ F-4: 1çªç®ã®ãµã³ãã« å³ F-5: 2çªç®ã®ãµã³ãã« å³ F-6: 3çªç®ã®ãµã³ãã« å³ F-7: 4çªç®ã®ãµã³ãã« å³ F-8: 5çªç®ã®ãµã³ãã« Output for Sample Input Remove 1 Remove 2 6 Valid Remove 1 2 3 4 Invalid | 37,640 |
Problem C Sibling Rivalry You are playing a game with your elder brother. First, a number of circles and arrows connecting some pairs of the circles are drawn on the ground. Two of the circles are marked as the start circle and the goal circle . At the start of the game, you are on the start circle. In each turn of the game, your brother tells you a number, and you have to take that number of steps . At each step, you choose one of the arrows outgoing from the circle you are on, and move to the circle the arrow is heading to. You can visit the same circle or use the same arrow any number of times. Your aim is to stop on the goal circle after the fewest possible turns, while your brother's aim is to prevent it as long as possible. Note that, in each single turn, you must take the exact number of steps your brother tells you. Even when you visit the goal circle during a turn, you have to leave it if more steps are to be taken. If you reach a circle with no outgoing arrows before completing all the steps, then you lose the game. You also have to note that, your brother may be able to repeat turns forever, not allowing you to stop after any of them. Your brother, mean but not too selfish, thought that being allowed to choose arbitrary numbers is not fair. So, he decided to declare three numbers at the start of the game and to use only those numbers. Your task now is, given the configuration of circles and arrows, and the three numbers declared, to compute the smallest possible number of turns within which you can always nish the game, no matter how your brother chooses the numbers. Input The input consists of a single test case, formatted as follows. $n$ $m$ $a$ $b$ $c$ $u_1$ $v_1$ ... $u_m$ $v_m$ All numbers in a test case are integers. $n$ is the number of circles $(2 \leq n \leq 50)$. Circles are numbered 1 through $n$. The start and goal circles are numbered 1 and $n$, respectively. $m$ is the number of arrows $(0 \leq m \leq n(n - 1))$. $a$, $b$, and $c$ are the three numbers your brother declared $(1 \leq a, b, c \leq 100)$. The pair, $u_i$ and $v_i$, means that there is an arrow from the circle $u_i$ to the circle $v_i$. It is ensured that $u_i \ne v_i$ for all $i$, and $u_i \ne u_j$ or $v_i \ne v_j$ if $i \ne j$. Output Print the smallest possible number of turns within which you can always finish the game. Print IMPOSSIBLE if your brother can prevent you from reaching the goal, by either making you repeat the turns forever or leading you to a circle without outgoing arrows. Sample Input 1 3 3 1 2 4 1 2 2 3 3 1 Sample Output 1 IMPOSSIBLE Sample Input 2 8 12 1 2 3 1 2 2 3 1 4 2 4 3 4 1 5 5 8 4 6 6 7 4 8 6 8 7 8 Sample Output 2 2 For Sample Input 1, your brother may choose 1 first, then 2, and repeat these forever. Then you can never finish. For Sample Input 2 (Figure C.1), if your brother chooses 2 or 3, you can finish with a single turn. If he chooses 1, you will have three options. Move to the circle 5. This is a bad idea: Your brother may then choose 2 or 3 and make you lose. Move to the circle 4. This is the best choice: From the circle 4, no matter any of 1, 2, or 3 your brother chooses in the next turn, you can finish immediately. Move to the circle 2. This is not optimal for you. If your brother chooses 1 in the next turn, you cannot finish yet. It will take three or more turns in total. In summary, no matter how your brother acts, you can finish within two turns. Thus the answer is 2. Figure C.1. Sample Input 2 | 37,641 |
Score : 700 points Problem Statement You are given a string s of length n . Does a tree with n vertices that satisfies the following conditions exist? The vertices are numbered 1,2,..., n . The edges are numbered 1,2,..., n-1 , and Edge i connects Vertex u_i and v_i . If the i -th character in s is 1 , we can have a connected component of size i by removing one edge from the tree. If the i -th character in s is 0 , we cannot have a connected component of size i by removing any one edge from the tree. If such a tree exists, construct one such tree. Constraints 2 \leq n \leq 10^5 s is a string of length n consisting of 0 and 1 . Input Input is given from Standard Input in the following format: s Output If a tree with n vertices that satisfies the conditions does not exist, print -1 . If a tree with n vertices that satisfies the conditions exist, print n-1 lines. The i -th line should contain u_i and v_i with a space in between. If there are multiple trees that satisfy the conditions, any such tree will be accepted. Sample Input 1 1111 Sample Output 1 -1 It is impossible to have a connected component of size n after removing one edge from a tree with n vertices. Sample Input 2 1110 Sample Output 2 1 2 2 3 3 4 If Edge 1 or Edge 3 is removed, we will have a connected component of size 1 and another of size 3 . If Edge 2 is removed, we will have two connected components, each of size 2 . Sample Input 3 1010 Sample Output 3 1 2 1 3 1 4 Removing any edge will result in a connected component of size 1 and another of size 3 . | 37,642 |
Problem C: Dial Lock A dial lock is a kind of lock which has some dials with printed numbers. It has a special sequence of numbers, namely an unlocking sequence, to be opened. You are working at a manufacturer of dial locks. Your job is to verify that every manufactured lock is unlocked by its unlocking sequence. In other words, you have to rotate many dials of many many locks. Itâs a very hard and boring task. You want to reduce time to open the locks. Itâs a good idea to rotate multiple dials at one time. It is, however, a difficult problem to find steps to open a given lock with the fewest rotations. So you decided to write a program to find such steps for given initial and unlocking sequences. Your companyâs dial locks are composed of vertically stacked k (1 †k †10) cylindrical dials. Every dial has 10 numbers, from 0 to 9, along the side of the cylindrical shape from the left to the right in sequence. The neighbor on the right of 9 is 0. A dial points one number at a certain position. If you rotate a dial to the left by i digits, the dial newly points the i -th right number. In contrast, if you rotate a dial to the right by i digits, it points the i -th left number. For example, if you rotate a dial pointing 8 to the left by 3 digits, the dial newly points 1. You can rotate more than one adjacent dial at one time. For example, consider a lock with 5 dials. You can rotate just the 2nd dial. You can rotate the 3rd, 4th and 5th dials at the same time. But you cannot rotate the 1st and 3rd dials at one time without rotating the 2nd dial. When you rotate multiple dials, you have to rotate them to the same direction by the same digits. Your program is to calculate the fewest number of rotations to unlock, for given initial and unlocking sequences. Rotating one or more adjacent dials to the same direction by the same digits is counted as one rotation. Input The input consists of multiple datasets. Each datset consists of two lines. The first line contains an integer k. The second lines contain two strings, separated by a space, which indicate the initial and unlocking sequences. 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 the minimum number of rotations in one line. Sample Input 4 1357 4680 6 777777 003330 0 Output for the Sample Input 1 2 | 37,643 |
ééè·¯ç· è€ç·ïŒäžããšäžããå¥ã®ç·è·¯ã«ãªã£ãŠããŠã©ãã§ã§ãããéããïŒã®ééè·¯ç·ããããŸãããã®è·¯ç·ã«ã¯çµç«¯é§
ãå«ããŠ11 ã®é§
ããããããããã®é§
ãšé§
ã®éã¯å³ã§ç€ºãåºéçªå·ã§åŒã°ããŠããŸãã ãã®è·¯ç·ã®äž¡æ¹ã®çµç«¯é§
ããåè»ãåæã«åºçºããŠãéäžã§åãŸããã«èµ°ããŸããååºéã®é·ããš2 æ¬ã®åè»ã®é床ãèªã¿èŸŒãã§ãããããã®å Žåã«ã€ããŠåè»ãããéãåºéã®çªå·ãåºåããããã°ã©ã ãäœæããŠãã ããããã ããã¡ããã©é§
ã®ãšããã§ããéãå Žåã¯ãäž¡åŽã®åºéçªå·ã®ãã¡å°ããã»ãã®æ°åãåºåããŸãããŸããåè»ã®é·ããé§
ã®é·ãã¯ç¡èŠã§ãããã®ãšããŸãã Input è€æ°ã®ããŒã¿ã»ãããäžãããããåããŒã¿ã»ããã¯ä»¥äžã®ãããªåœ¢åŒã§äžããããã l 1 , l 2 , l 3 , l 4 , l 5 , l 6 , l 7 , l 8 , l 9 , l 10 , v 1 , v 2 l i (1 †l i †2,000) ã¯åºé i ã®é·ã(km)ãè¡šãæŽæ°ã§ããã v 1 ã¯åºé 1 åŽã®çµç«¯é§
ãåºçºããåè»ã®é床(km/h)ã v 2 ã¯åºé 10 åŽã®çµç«¯é§
ãåºçºããåè»ã®é床(km/h)ãè¡šãæŽæ°ã§ãã (1 †v 1 , v 2 †2,000)ã ããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããªãã Output ããŒã¿ã»ããããšã«ãåè»ãããã¡ããåºéã®çªå·ãïŒè¡ã«åºåããã Sample Input 1,1,1,1,1,1,1,1,1,1,40,60 1,1,1,1,1,3,3,3,3,3,50,50 10,10,10,10,10,10,10,10,10,10,50,49 Output for the Sample Input 4 7 6 | 37,644 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.