task stringlengths 0 154k | __index_level_0__ int64 0 39.2k |
|---|---|
ååŠç©è³ªã¢ã«ãã¡ ã¢ã€ã
補è¬ã§ã¯æ¥ã
ååŠç©è³ªã®ç ç©¶ããªãããŠããŸããããŸç ç©¶ãããŠããã®ã¯ã$1$çªãã$N$çªã®ååã巊端ããå³ç«¯ãžçŽç·ç¶ã«ãªããã æ§é ãããŠããååŠç©è³ªãã³ãŒãããŒã ãã¢ã«ãã¡ãã§ãã ã¢ã€ã
補è¬ã®éçºããæè¡ã䜿ãã°ãã¢ã«ãã¡ãæ§æããååã®äœçœ®ãå
¥ãæ¿ããããšãã§ããŸããå
¥ãæ¿ãã¯æ±ºãŸã£ãæé ã§ããè¡ãããšãã§ããŸãããããã®æé ã®éäžããå§ããŠéäžã§çµããããšãã§ããŸãã巊端ãã$a$çªç®ãš$b$çªç®ã®ååãå
¥ãæ¿ããæäœã$(a,b)$ãšæžããšããŸããããšãã°ã$N=5$ã§æ±ºãŸã£ãæé ã$(1,3),(2,5),(4,3),(1,5)$ã®ãšãã$1$çªç®ã®æäœ$(1,3)$ããå§ããŠ$3$çªç®ã®æäœ$(4,3)$ã§çµããããšãã$2$çªç®ã®æäœ$(2,5)$ããå§ããŠ$4$çªç®ã®æäœ$(1,5)$ã§çµããããšãã§ããŸãã ããªãã¯ãã¢ã«ãã¡ã®ååã®å
¥ãæ¿ãæé ã®äžã®éå§äœçœ®ãšçµäºäœçœ®ãéžãã§ã·ãã¥ã¬ãŒã·ã§ã³ãè¡ããå
¥ãæ¿ãåŸã®ååã®ç¶æ
ã調ã¹ãããšã«ããŸããã ã¢ã«ãã¡ã®ååã®å
¥ãæ¿ãæé ãäžãããããã·ãã¥ã¬ãŒã·ã§ã³ãäœåºŠãè¡ã£ããšããåã·ãã¥ã¬ãŒã·ã§ã³ã§ã®ååã®äœçœ®ã«ã€ããŠè³ªåã«çããããã°ã©ã ãäœæããã質åã¯æ¬¡ã®1.ãŸãã¯2.ã®åœ¢ãããŠããã çµäºåŸã«å·Šç«¯ãã$i$çªç®ã«äœçœ®ããŠããååã¯ãæåã¯äœçªç®ã«äœçœ®ããŠãããã æåã«$i$ çªç®ã«äœçœ®ããŠããååãçµäºåŸã«ã©ã®äœçœ®ã«æ¥ãŠãããã ãã ããåã·ãã¥ã¬ãŒã·ã§ã³ã¯ãã¢ã«ãã¡ã®åæç¶æ
ïŒ$1$çªãã$N$çªã®ååã巊端ããå³ç«¯ãžçŽç·ç¶ã«ãªããã ç¶æ
ïŒããå§ãããã®ãšããã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã $N$ $K$ $Q$ $a_1$ $b_1$ $a_2$ $b_2$ : $a_K$ $b_K$ $query_1$ $query_2$ : $query_Q$ ïŒè¡ç®ã«ã¢ã«ãã¡ãæ§æããååã®æ°$N$ ($2 \leq N \leq 100,000$)ãå
¥ãæ¿ãæé ã®é·ã$K$ ($1 \leq K \leq 100,000$)ãå
¥ãæ¿ãåŸã®ååã®ç¶æ
ã調ã¹ãåæ°$Q$ ($1 \leq Q \leq 100,000$)ãäžãããããç¶ã$K$è¡ã«å
¥ãæ¿ãæé ã®äžã®åæäœ$a_i,b_i$ ($1 \leq a_i,b_i \leq N$, $a_i \ne b_i$)ãäžããããã$i$çªç®ã®æäœã¯ã巊端ãã$a_i$çªç®ãš$b_i$çªç®ã®ååãå
¥ãæ¿ããæäœã衚ããç¶ã$Q$è¡ã«ãå
¥ãæ¿ãçµäºåŸã®ååã®ç¶æ
ãå°ãã質åãäžãããããå$query_i$ã¯ä»¥äžã®ããããã®åœ¢åŒã§äžããããã 1 $s$ $t$ $x$ ãŸã㯠2 $s$ $t$ $x$ æåã®æ°åã1ã®å Žåãå
¥ãæ¿ãæé ã®äžã®å
¥ãæ¿ãã$s$çªãã$t$çª($1 \leq s \leq t \leq K$)ãŸã§è¡ã£ãåŸã«ãå·ŠåŽãã$x$çªç®($1 \leq x \leq N$)ã®ååã®çªå·ãäœçªãå°ãã質åã衚ããæåã®æ°åã2ã®å Žåãå
¥ãæ¿ãæé ã®äžã®å
¥ãæ¿ãã$s$çªãã$t$çª($1 \leq s \leq t \leq K$)ãŸã§è¡ã£ãåŸã«ã$x$çª($1 \leq x \leq N$)ã®ååãå·Šããæ°ããŠäœçªç®ã«ãããå°ãã質åã衚ãã åºå å質åã«å¯ŸããŠãçããïŒè¡ã«åºåããã å
¥åºåäŸ å
¥åäŸ 6 5 8 1 3 2 5 3 4 2 4 2 5 1 1 5 1 1 1 5 2 1 1 5 3 1 1 5 4 1 1 5 5 1 1 5 6 2 3 4 2 1 1 1 1 åºåäŸ 3 2 4 5 1 6 4 3 å
¥ãæ¿ãæé ã¯$(1,3),(2,5),(3,4),(2,4),(2,5)$ã§ããã $1$çªç®ãã$6$çªç®ã®è³ªåã§ã¯ãæé ã®$1$çªç®($s=1$)ãã$5$çªç®($t=5$)ãŸã§ãã¹ãŠè¡ã£ãå Žåãªã®ã§ãå
¥ãæ¿ãåŸã®ç¶æ
ã¯ãã¹ãŠå
±éã§ä»¥äžã®ããã«ãªãã åæç¶æ
1 2 3 4 5 6 $(1,3)$ã®åŸ 3 2 1 4 5 6 $(2,5)$ã®åŸ 3 5 1 4 2 6 $(3,4)$ã®åŸ 3 5 4 1 2 6 $(2,4)$ã®åŸ 3 1 4 5 2 6 $(2,5)$ã®åŸ 3 2 4 5 1 6 $7$çªç®ã®è³ªåã§ã¯$s=3,t=4$ãªã®ã§ãå
¥ãæ¿ãåŸã®ç¶æ
ã¯ä»¥äžã®ããã«ãªããååçªå·$2$çªã¯å·Šããæ°ããŠ$4$çªç®ã«ããã®ã§ãçãã¯4ã«ãªãã åæç¶æ
1 2 3 4 5 $(3,4)$ã®åŸ 1 2 4 3 5 $(2,4)$ã®åŸ 1 3 4 2 5 $8$çªç®ã®è³ªåã§ã¯$s=1,t=1$ãªã®ã§ãå
¥ãæ¿ãåŸã®ç¶æ
ã¯ä»¥äžã®ããã«ãªãã åæç¶æ
1 2 3 4 5 $(1,3)$ã®åŸ 3 2 1 4 5 | 36,201 |
æèšã®çãéãšé·ãé åå§ã¹ããŒã©ã€ã䞻矩çµç¹ãã¢ã«ã«ã€ãããããããããã®äºåç¶ãå±ããŸãããã¢ã«ã«ã€ããšããã°ãèŠäººã®é¡é¢ã«ãã€ãæãã€ãããããããããã§æåã§ãããæè¿ã§ã¯ç«è¬ãçšããŠã¬ã»ãã·ã§ã³äŒå Žã«ããºãè±ç«ããŸãæ£ãããªã©ãããéæ¿åããŠããŸãããäºåç¶ã¯æ¬¡ã®æé¢ã§ãã ---ããœã³ã³ ããã®æéã奪ããè¯ããªãã æèšã®çãéãšé·ãé åºäŒããããã¢ã«ã«ã€ã æ£çŸ©è¡ãã ã¹ããŒã©ã€ã å倧ãªãã ãã©ãã©ãããŠããè§£ããªãã®ã§ãããæèšã®çéãšé·éãšãéãªã£ãããã«ãããããæ±ºè¡ãããšããæå³ã®ããã§ãã ãã®ãããããèŠæãããããæå»ãå
¥åãšããŠãçéãšé·éãè¿ãå Žå㯠"alert"ãé ãå Žå㯠"safe"ããã以å€ã®å Žå㯠"warning" ãšåºåããããã°ã©ã ãäœæããŠãã ããããã ãããè¿ãããšã¯çéãšé·éã®è§åºŠã 0° ä»¥äž 30° æªæºã®å Žåãããããé ãããšã¯ 90° ä»¥äž 180° 以äžã®å ŽåããããŸãããªããæå»ã¯ 00:00 ä»¥äž 11:59 以äžãšããŸãã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã n hh 1 : mm 1 hh 2 : mm 2 : hh n : mm n 1 è¡ç®ã«å€å®ããæå»ã®åæ° n ïŒ1 †n †10000ïŒã2 è¡ç®ä»¥éã« i çªç®ã®æå» hh i : mm i ãããããïŒè¡ã«äžããããŸãã Output i çªç®ã®æå»ã®å€å®çµæ safeãwarningããŸã㯠alert ãé çªã«ããããïŒè¡ã«åºåããŠãã ããã Sample Input 4 02:15 06:01 11:55 10:40 Output for the Sample Input alert safe alert warning | 36,202 |
Problem K: Donuts Purchase Problem ã©ãã€ã¯äŒæã®éããããšããªãæã§ããªããšãªãããŒãããé£ã¹ãããªã£ãã®ã§ãåºãå·¡ãããŒããã賌å
¥ããŠããããšã«ããã åè¡ã«ã¯1è»ã®ããŒããåºãããããã¹ãŠã®ããŒããåºã¯å¥æ°æ¥ãå®äŒæ¥ãšãªã£ãŠããã ã©ãã€ã«ã¯ããŒããã®å¥œã¿ãããã®ã§ãåºã«ãã£ãŠåŸãããæºè¶³åºŠãéãã ããã§ã©ãã€ã¯æé©ã«è¡åããããšã§ãã§ããã ãå€ãã®æºè¶³åºŠãåŸãããšã«ããã ã©ãã€ãäœãã§ããäžçã«ã¯ããããã0ãã n -1ã®çªå·ãå²ãåœãŠããã n åã®è¡ããããããã㯠m æ¬ã®éã§ç¹ãããŠããã ããããã®éã¯äžæ¹éè¡ã«ãªã£ãŠãããã©ãã€ã¯è¡ a i ããè¡ b i ãžç§»åããããšãã§ããã æåã©ãã€ã¯å¶æ°æ¥ã«è¡0ã«ããã ã©ãã€ã¯è¡ã«ã¯çãŸããã«ã1æ¥ã«éã1æ¬æž¡ãå¥ã®è¡ã«ç§»åããã ã©ãã€ã¯è¡ i ã«å°çããæ¥ã«ãåºãå¶æ¥ããŠããã°1ã€ããŒããã賌å
¥ããæºè¶³åºŠ c i ãåŸãã åãè¡ã¯äœåºŠã§ã蚪ããããšãã§ãããã1ã€ã®åºã§ã¯1床ãã賌å
¥ããªãã ã©ãã€ãããä»¥äžæºè¶³åºŠãåŸãããªãç¶æ
ã«ãªããŸã§æé©ã«è¡åããæã®æºè¶³åºŠã®åèšã®æå€§ãæ±ããã Input n m c 0 ... c nâ1 a 0 b 0 ... a mâ1 b mâ1 å
¥åã¯ãã¹ãп޿°ã§äžããããã 1è¡ç®ã«è¡ã®æ° n ãšéã®æ° m ã空çœåºåãã§äžããããã 2è¡ç®ã«è¡ i ã®åºã§ããŒããã賌å
¥ããéã«åŸãããæºè¶³åºŠ c i ã空çœåºåãã§äžããããã ç¶ã m è¡ã«éã®æ
å ±ã衚ã a i ãš b i ã空çœåºåãã§äžããããã Constraints å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã 1 †n †10 5 0 †m †min( n Ã( n â1),10 5 ) 0 †c i †1000 0 †a i , b i †n â 1 èªå·±ã«ãŒããå€é蟺ã¯ååšããªã Output æºè¶³åºŠã®åèšã®æå€§å€ã1è¡ã«åºåããã Sample Input 1 2 1 1 2 0 1 Sample Output 1 1 Sample Input 2 5 5 1 1 1 1 1 0 1 1 2 2 3 3 0 3 4 Sample Output 2 3 Sample Input 3 4 4 1 1 1 1 0 1 1 2 2 0 2 3 Sample Output 3 4 | 36,203 |
åå
(Sugoroku) å顿 JOI åã¯ããããã®å®¶ã§åå
ãèŠã€ããïŒåå
ã¯çŽç·ç¶ã«äžŠãã N+2 åã®ãã¹ãããªãïŒ 1 çªç®ã®ãã¹ã¯ã¹ã¿ãŒãïŒ N+2 çªç®ã®ãã¹ã¯ãŽãŒã«ã§ããïŒãã®ä»ã®åãã¹ã«ã¯ 0 ãŸã㯠1 ãæžãããŠããŠïŒå i ( 1âŠiâŠN ) ã«ã€ããŠïŒ i+1 çªç®ã®ãã¹ã«æžãããæ°å㯠A_i ã§ããïŒ åå
ã§ã¯ïŒæåã«ã¹ã¿ãŒãã®ãã¹ã«ã³ãã眮ãïŒãµã€ã³ããæ¯ã£ãŠïŒåºãç®ã®æ°ã ãã³ããé²ããããšãç¹°ãè¿ãïŒãã ãïŒ 1 ã®æžããããã¹ã«æ¢ãŸã£ãå Žåã¯ïŒã²ãŒã ãªãŒããŒã§ããïŒã²ãŒã ãªãŒããŒã«ãªããã«ãŽãŒã«ã®ãã¹ã«æ¢ãŸããïŒãŽãŒã«ã®ãã¹ãéãéãããïŒã²ãŒã ã¯ãªã¢ã§ããïŒ JOI åã¯åå
ãéã¶ããã®ãµã€ã³ããããã¡ãå±ããã«è²·ãã«è¡ãããšã«ããïŒããã¡ãå±ããã«ã¯ N+1 åã®ãµã€ã³ãã売ã£ãŠããïŒ j çªç® ( 1âŠjâŠN+1 ) ã®ãµã€ã³ã㯠j åã®é¢ãæã¡ïŒ 1,2,...,j ã 1 ã€ãã€æžãããŠããïŒ JOI åã¯ã²ãŒã ã¯ãªã¢ã§ãããããªãµã€ã³ãã®ãã¡ïŒæãé¢ã®æ°ãå°ãªããµã€ã³ãã 1 åè²·ãããšã«ããïŒJOI åã¯ã©ã®ãµã€ã³ããè²·ãã°ããã ãããïŒ å¶çŽ 1 \leq N \leq100 0 \leq A_i \leq 1 ( 1 \leq i \leq N ) å
¥åã»åºå å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããïŒ N A_1 A_2 ... A_N åºå JOI åã賌å
¥ãã¹ããµã€ã³ãã®é¢ã®æ°ãçããïŒ å
¥åºåäŸ å
¥åäŸ 1 5 0 1 0 0 0 åºåäŸ 1 2 åå
㯠7 ãã¹ãããªãïŒ 3 ãã¹ç®ã®ã¿ã« 1 ãæžãããŠããïŒé¢ã®æ°ã 2 åã®ãµã€ã³ãã䜿ã£ãå ŽåïŒäŸãã°åºãç®ã 1,2,1,1,1 ãšãªã£ããšãã«ã²ãŒã ã¯ãªã¢ããããšãã§ããïŒãããæå°ãªã®ã§ 2 ãåºåããïŒ å
¥åäŸ 2 5 1 1 1 1 1 åºåäŸ 2 6 åå
㯠7 ãã¹ãããªãïŒã¹ã¿ãŒããšãŽãŒã«ä»¥å€ã®ãã¹å
šãŠã« 1 ãæžãããŠããïŒãã®ãšãïŒé¢ã®æ°ã 6 åã®ãµã€ã³ããå¿
èŠã§ããïŒãããæå°ãªã®ã§ 6 ãåºåããïŒ å
¥åäŸ 3 7 0 0 1 0 1 1 0 åºåäŸ 3 3 æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒäœ ã第 17 åæ¥æ¬æ
å ±ãªãªã³ãã㯠JOI 2017/2018 äºéžç«¶æèª²é¡ã | 36,204 |
Score : 100 points Problem Statement You are given an undirected graph with N vertices and 0 edges. Process Q queries of the following types. 0 u v : Add an edge (u, v) . 1 u v : Print 1 if u and v are in the same connected component, 0 otherwise. Constraints 1 \leq N \leq 200,000 1 \leq Q \leq 200,000 0 \leq u_i, v_i \lt N Input Input is given from Standard Input in the following format: N Q t_1 u_1 v_1 t_2 u_2 v_2 : t_Q u_Q v_Q åºå For each query of the latter type, print the answer. Sample Input 1 4 7 1 0 1 0 0 1 0 2 3 1 0 1 1 1 2 0 0 2 1 1 3 Sample Output 1 0 1 0 1 | 36,205 |
Score : 100 points Problem Statement You are given three integers A , B and C . Determine whether C is not less than A and not greater than B . Constraints -100â€A,B,Câ€100 A , B and C are all integers. Input Input is given from Standard Input in the following format: A B C Output If the condition is satisfied, print Yes ; otherwise, print No . Sample Input 1 1 3 2 Sample Output 1 Yes C=2 is not less than A=1 and not greater than B=3 , and thus the output should be Yes . Sample Input 2 6 5 4 Sample Output 2 No C=4 is less than A=6 , and thus the output should be No . Sample Input 3 2 2 2 Sample Output 3 Yes | 36,206 |
è² ããå«ãã®ã€ã¯ã¿åã¯ãæè¿å²ç¢ç€ã䜿ã£ãŠéã¶ã²ãŒã ã«ç±äžããŠããã ããããå²ç¢ãäºç®äžŠã¹ãå人ã«å
šãåãŠãªãã®ã§ãããŸãæåã§ãªã Phutball ãšããã²ãŒã ã®ç¹èšãããããšã«ããã ãã®ã²ãŒã ã¯é£ããã²ãŒã ãªã®ã§ãæå§ãã«èªåã®ã¿ãŒã³ã«åã£ãŠçµå±ã§ããããå€å®ã§ããããã«ç¹èšããããšã«ããã ã²ãŒã ã®å婿¡ä»¶ã¯ä»¥äžã®ãããªãã®ã§ããã çœç³ã¯é»ç³ã®çœ®ãããŠããå Žæã«ãžã£ã³ãããããšã¯åºæ¥ãªãã ç¢ç€ã®äžå€®ã® 19 à 15 ã®éšåãçšããã å婿¡ä»¶ãå€å®ãããç¢ç€ã¯çœç³ã1ã€ãšé»ç³ãããã€ã眮ãããç¶æ
ã§äžããããã ãŽãŒã«å°ç¹ãšããã®ã¯ç¢ç€ã®äžç«¯ãããã®äžåŽãæããïŒäžå³ãåç
§ãããïŒ ãŽãŒã«å°ç¹ã«çœç³ãéã¹ã°åå©ããã åå©ããããã«ä»¥äžã®ãããªããšãè¡ãã çœç³ã¯1å以äžãžã£ã³ããè¡ãããšãã§ããã ãžã£ã³ãã¯çœç³ã«é£æ¥ãã8æ¹åïŒäžäžå·Šå³ãšæãäžãæãäžïŒã®é»ç³ã®ã©ãããé£ã³è¶ããããšã§è¡ããã é»ç³ã飿¥ããŠããªãæ¹åãžãžã£ã³ãããããšã¯åºæ¥ãªãã é£ã³è¶ããããé»ç³ã¯ã1åã®ãžã£ã³ãããšã«ç¢ç€ã®äžããåãé€ãããã ãžã£ã³ãããããšã®çœç³ã¯ãŽãŒã«å°ç¹ãã²ãŒã ç€ã®äžã«ååšããªããã°ãããªãã é»ç³ã2å以äžé£ç¶ããŠããŠããã¡ããã©ããããŸããããã«ãžã£ã³ãã§ããã çœç³ã¯é»ç³ã®çœ®ãããŠããå Žæã«ãžã£ã³ãããããšã¯åºæ¥ãªãã(ãžã£ã³ãããæ¹åã«é£ç¶ããŠããé»ç³ã¯å¿
ãé£ã³è¶ããªããŠã¯ãªããªãã) å³ã®äžžå°ãã€ããŠããå Žæãžã¯ãžã£ã³ãããããšãå¯èœã§ãããå
šãŠãŽãŒã«å°ç¹ã§ããããããå°ã®å Žæã¯ãŽãŒã«å°ç¹ã§ããªããç¢ç€ã®å
åŽã§ããªãã®ã§ããžã£ã³ãããããšã¯åºæ¥ãªãã ããªãã®ä»äºã¯ã€ã¯ã¿åã®ç¹èšãæå©ãããããã«ããŽãŒã«ã§ãããã©ããã®å€å®ãšããŽãŒã«ããããã®æå°ã®ãžã£ã³ãåæ°ãæ±ããããã°ã©ã ãæžããŠãããäºã§ããã Input .OX ã§æ§æããã 19 à 15 ã®ç€é¢ã19è¡ã§äžããããã åè¡ã¯å¿
ã15æåãããªããåæåã¯æ¬¡ã衚ãã "."ã¯ç©ºçœã衚ãã "O"ã¯çœç³ã衚ãã "X"ã¯é»ç³ã衚ãã Constraints é»ç³ã®æ°ã20以äžã çœç³ã¯å¿
ã1ã€ã ãååšããã ãã§ã«ãŽãŒã«ããç¶æ
ãå
¥åãããããšã¯ãªãã Output ãŽãŒã«å¯èœãªãæçã®ææ°ã1è¡ã«åºåããããŽãŒã«ããããšãäžå¯èœãªå Žåã¯-1ãåºåããã Sample Input 1 ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ......O........ ......X........ Output for the Sample Input 1 1 çœç³ã¯é»ç³ã1åãžã£ã³ãããŠãŽãŒã«ããããšãã§ããã Sample Input 2 ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ......O........ ............... Output for the Sample Input 2 -1 çœç³ã¯ç§»åã§ããªãã®ã§ãŽãŒã«ã§ããªãã Sample Input 3 ............... ............... ............... ............... ............... ............... ............... ............... ...........O... ............X.. .............X. .............X. .............X. ............... ..............X .........X..... .............X. ......X....X..X .....X.X.XX.X.. Output for the Sample Input 3 6 ã¡ããã©6åã§ãŽãŒã«ã§ããã ãžã£ã³ãæ¯ã«åè§£ããç»åã以äžã«ç€ºãã Sample Input 4 ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... ............... .....XX........ .....XXXO...... ......X........ Output for the Sample Input 4 4 | 36,207 |
Problem A: Sum of Consecutive Prime Numbers Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representations does a given positive integer have? For example, the integer 53 has two representations 5 + 7 + 11 + 13 + 17 and 53. The integer 41 has three representations 2 + 3 + 5 + 7 + 11 + 13, 11 + 13 + 17, and 41. The integer 3 has only one representation, which is 3. The integer 20 has no such representations. Note that summands must be consecutive prime numbers, so neither 7 + 13 nor 3 + 5 + 5 + 7 is a valid representation for the integer 20. Your mission is to write a program that reports the number of representations for the given positive integer. Input The input is a sequence of positive integers each in a separate line. The integers are between 2 and 10 000, inclusive. The end of the input is indicated by a zero. Output The output should be composed of lines each corresponding to an input line except the last zero. An output line includes the number of representations for the input integer as the sum of one or more consecutive prime numbers. No other characters should be inserted in the output. Sample Input 2 3 17 41 20 666 12 53 0 Output for the Sample Input 1 1 2 3 0 0 1 2 | 36,208 |
Score : 1200 points Problem Statement Find the number of the possible tuples of sequences (A_0,A_1,...,A_N) that satisfy all of the following conditions, modulo M : For every i (0\leq i\leq N) , A_i is a sequence of length i consisting of integers between 1 and K (inclusive); For every i (1\leq i\leq N) , A_{i-1} is a subsequence of A_i , that is, there exists 1\leq x_i\leq i such that the removal of the x_i -th element of A_i would result in a sequence equal to A_{i-1} ; For every i (1\leq i\leq N) , A_i is lexicographically larger than A_{i-1} . Constraints 1 \leq N,K \leq 300 2 \leq M \leq 10^9 N , K and M are integers. Input Input is given from Standard Input in the following format: N K M Output Print the number of the possible tuples of sequences (A_0,A_1,...,A_N) , modulo M . Sample Input 1 2 2 100 Sample Output 1 5 Five tuples below satisfy the conditions: (),(1),(1,1) (),(1),(1,2) (),(1),(2,1) (),(2),(2,1) (),(2),(2,2) Sample Input 2 4 3 999999999 Sample Output 2 358 Sample Input 3 150 150 998244353 Sample Output 3 186248260 | 36,209 |
æ¡è©© é¡ã¯ãã¯è±ã®äžã«ãŠæ¥æ»ãªã English text is not available in this practice contest. Nathan O. Davis ã¯éç©åè·¯ã³ãŒã¹ã®åŠçã§ããïŒ Nathan ã¯è¶³ããªãåäœãè£å
ããããã«ïŒæ¥æ¬æåã«é¢ããææ¥ã履修ããŠããïŒä»æ¥ã®èª²é¡ã¯è©©ã®äœæã§ããïŒ Nathan ã¯å匷äžè¶³ã§æ¥æ¬èªãäžåŸæãªããïŒããã°ã©ã ã«è©©ãèªåçæãããããšèããïŒæå§ãã«åœŒã¯ïŒæ¥æ¬èªã®åèªã®æ¥ç¶èŸæžãå
¥æããïŒ ããšã¯åèªã®æ¥ç¶ã«ãããã£ãŠã©ã³ãã ãªæç« ãçæããã ãã§ããïŒ ããããªããïŒã©ã³ãã ã«çæãããå
šãŠã®æååãè©©ãšããŠèªããããããã§ã¯ãªãïŒ è©©ã«ã¯ïŒããã€ãã®å£èªã®ãã¡1ã€ãïŒäžåºŠã ãçŸããŠããªããã°ãªããªãïŒããå£èªã2å以äžåºçŸããããšãïŒ2çš®é¡ä»¥äžã®å£èªã1åãã€åºçŸããããšã¯èš±ãããªãïŒ ãŸãïŒå£èªã¯åèªã®æ¥ç¶ã®å¢çããŸããã§åºçŸããŠãããïŒ ããªãã®ä»äºã¯ïŒå
¥åã§äžããããåèªã®æ¥ç¶èŸæžãšå£èªã®ãªã¹ãããïŒæå®ãããé·ãã®è©©ãäœéãã«äœãããããæ±ããããã°ã©ã ãäœæããããšã§ããïŒ éãåèªãç¹ããŠè©©ãšãªãåãæååãåŸãããå ŽåïŒãããã¯éè€ããŠæ°ãäžãããã®ãšããïŒçãã¯éåžžã«å€§ãããªãããã®ã§ïŒ 1,000,000,007 ã§å²ã£ãäœããåºåããïŒ Input å
¥åã¯è€æ°ã®ãã¹ãã±ãŒã¹ãå«ãã§ããïŒ1ã€ã®ãã¹ãã±ãŒã¹ã¯ïŒä»¥äžã®åœ¢åŒã§äžããããïŒ N M K from 1 to 1 from 2 to 2 : from N to N seasonword 1 seasonword 2 : seasonword K å
¥åã®æåã®è¡ã«ã¯3ã€ã®æŽæ° N (1 †N †250), M (1 †M †500), K (1 †K †30) ãå«ãŸãïŒããããåèªã®æ¥ç¶èŸæžã®å€§ããïŒäœæãã¹ãè©©ã®é·ãïŒå£èªã®æ°ã衚ãïŒ ç¶ã N è¡ã¯åèªã®æ¥ç¶èŸæžã®æ
å ±ã衚ãïŒ åè¡ã¯2ã€ã®æåå from i , to i ãå«ã¿ïŒåèª from i ã®åŸã«ç¶ããŠåèª to i ãåºçŸããŠããããšããããšã衚ãïŒ to i ã®åŸã«ç¶ã㊠from i ãåºçŸããŠããããšããããšã衚ããã®ã§ã¯ãªãããšã«æ³šæããïŒãŸãïŒ from i ã§çµãããããªä»ã®æååã®åŸã«ç¶ã㊠to i ãåºçŸããŠããããšããããšã衚ããã®ã§ããªãïŒè©©ã¯ïŒæ¥ç¶èŸæžã«å«ãŸããã©ã®åèªããå§ããŠãããïŒ ç¶ã K è¡ã¯1ã€ã®æåå seasonword i ãããªãïŒããããå£èªã衚ãïŒ å
¥åäžã«çŸããæååã¯å
šãŠå°æåã®ã¢ã«ãã¡ããããããªãïŒãã®é·ã㯠1 ä»¥äž 20 以äžã§ããïŒ æ¥ç¶èŸæžã®åé
ç®ïŒããã³å£èªã¯äºãã«ç°ãªãïŒ ããªãã¡ïŒ i â j ã«å¯Ÿã㊠from i â from j ãŸã㯠to i â to j ãæãç«ã€ïŒ åæ§ã«ïŒ i â j ã«å¯Ÿã㊠seasonword i â seasonword j ãæãç«ã€ïŒ å
¥åã®æ«å°Ÿã«ã¯ïŒå
¥åã®çµäºã衚ã 3 ã€ã® 0 ãããïŒ Output çæãããç°ãªãè©©ã®æ°ã 1,000,000,007 ã§å²ã£ãäœãã1è¡ã«åºåããïŒ å
ã«èšåããããã«ïŒéãåèªãç¹ããŠè©©ãšãªãåãæååãåŸãããå ŽåïŒãããã¯éè€ããŠæ°ãäžãããã®ãšããïŒ å³å¯ã«èšãã°ïŒ2ã€ã®è©© s , t ãããïŒããããåèªã®å [ a 1 , a 2 , ..., a n ], [ b 1 , b 2 , ..., b m ] ãé ã«é£çµããŠåŸããããã®ã§ãããšãïŒ n = m ãã€ãã¹ãŠã® 1 †i †n ã«å¯Ÿã㊠a i = b i ã§ãããšãïŒãŸããã®ãšãã«éã£ãŠïŒ2ã€ã®è©© s , t ã¯åäžã®è©©ãšã¿ãªãããïŒ Sample Input 4 64 2 negawakuha hananoshitanite hananoshitanite harushinan harushinan sonokisaragino sonokisaragino mochizukinokoro sakura hana 2 15 2 naha naha naha gachoon sakura hana 3 7 2 asakur a a sakura asa kura sakura hana 9 100 2 a a a h a n h a h h h n n a n h n n sakura hana 4 2 2 a a a b b a b b ab b 4 7 4 i cpc mi cp ac mi cp c ac wa tle re 0 0 0 Output for the Sample Input 1 1 3 715991824 1 1 | 36,210 |
Score : 200 points Problem Statement There are N balls placed in a row. AtCoDeer the deer is painting each of these in one of the K colors of his paint cans. For aesthetic reasons, any two adjacent balls must be painted in different colors. Find the number of the possible ways to paint the balls. Constraints 1âŠNâŠ1000 2âŠKâŠ1000 The correct answer is at most 2^{31}-1 . Input The input is given from Standard Input in the following format: N K Output Print the number of the possible ways to paint the balls. Sample Input 1 2 2 Sample Output 1 2 We will denote the colors by 0 and 1 . There are two possible ways: we can either paint the left ball in color 0 and the right ball in color 1 , or paint the left in color 1 and the right in color 0 . Sample Input 2 1 10 Sample Output 2 10 Since there is only one ball, we can use any of the ten colors to paint it. Thus, the answer is ten. | 36,211 |
Score : 1000 points Problem Statement There are 3^N people dancing in circle. We denote with 0,1,\dots, 3^{N}-1 the positions in the circle, starting from an arbitrary position and going around clockwise. Initially each position in the circle is occupied by one person. The people are going to dance on two kinds of songs: salsa and rumba. When a salsa is played, the person in position i goes to position j , where j is the number obtained replacing all digits 1 with 2 and all digits 2 with 1 when reading i in base 3 (e.g., the person in position 46 goes to position 65 ). When a rumba is played, the person in position i moves to position i+1 (with the identification 3^N = 0 ). You are given a string T=T_1T_2\cdots T_{|T|} such that T_i= S if the i -th song is a salsa and T_i= R if it is a rumba. After all the songs have been played, the person that initially was in position i is in position P_i . Compute the array P_0,P_1,\dots, P_{3^N-1} . Constraints 1 \le N \le 12 1 \le |T| \le 200,000 T contains only the characters S and R . Input Input is given from Standard Input in the following format: N T Output You should print on Standard Output: P_0 P_1 \cdots P_{3^N-1} Sample Input 1 1 SRS Sample Output 1 2 0 1 Before any song is played, the positions are: 0 , 1 , 2 . When we say "person i ", we mean "the person that was initially in position i ". After the first salsa, the positions are: 0 , 2 , 1 . After the rumba, the positions are: 1 , 0 , 2 (so, person 0 is in position 1 , person 1 is in position 0 and person 2 is in position 2 ). After the second salsa, the positions are 2 , 0 , 1 (so, person 0 is in position 2 , person 1 is in position 0 and person 2 is in position 1 ). Sample Input 2 2 RRSRSSSSR Sample Output 2 3 8 1 0 5 7 6 2 4 Sample Input 3 3 SRSRRSRRRSRRRR Sample Output 3 23 9 22 8 3 7 20 24 19 5 18 4 17 12 16 2 6 1 14 0 13 26 21 25 11 15 10 | 36,212 |
K: ããŒãã¡ã³ã å顿 京éœå€§åŠã¯ã¹ããåã«ãŠã$2$ 人çšå¯ŸæŠã²ãŒã ã®ããŒãã¡ã³ããè¡ãããããšããŠããŸãã ãã®ããŒãã¡ã³ãã®åå è
㯠$2^N$ 人ããŠã $1$ ãã $2^N$ ãŸã§ã®çªå·ãã€ããŠããŸãã åå è
ã®ãã¡ã® $2$ äººãæŠã£ãæã®åæã¯ã$0$ ãš $1$ ãããªãé·ã $2^N-1$ ã®æåå $S$ ã«ãã£ãŠè¡šãããŸãã 人 $x$ ãšäºº $y$ $(1 \le x < y \le 2^N)$ ãæŠã£ããšãã $S_{y-x} = 0$ ã®ãšãã人 $x$ ãåã¡ã $S_{y-x} = 1$ ã®ãšãã人 $y$ ãå〠ããšãåãã£ãŠããŸãã ããŒãã¡ã³ãã¯åå è
ãäžåã«äžŠã¶ããšã§å§ãŸãã以äžã®éãã«é²è¡ããŸãã åã®å
é ãã $2$ 人ãã€ãã¢ãäœãããã¹ãŠã®ãã¢ã«ã€ããŠããã¢å
ã® $2$ äººãæŠãã 1 ã®å¯ŸæŠã§åã£ã人ã¯åã«æ®ããè² ãã人ã¯åããæããã æ®ã£ãŠãã人ã $2$ 人以äžãããšãã¯ãåãè©°ã㊠1 ã«æ»ãã æ®ã£ãŠãã人ã $1$ 人ãšãªã£ããããã®äººãåªåè
ãšãªãã ããŸãåå è
ã¯åæç¶æ
ãšããŠãå
é ãã $i$ çªç® $(1 \le i \le 2^N)$ ã人 $P_i$ ãšãªãããã«äžŠãã§ããŸãã $0 \le k \le 2^N-1$ ãæºãããã¹ãŠã®æŽæ° $k$ ã«ã€ããŠã以äžã®åé¡ãè§£ããŠãã ããã åæç¶æ
ããå
é $k$ 人ãããã®é çªãå€ããã«åã®æ«å°Ÿã«ç§»åããã ã€ãŸããç§»ååŸã®åã«ãããåå è
ã®çªå·ãå
é ããæããŠãããšã $P_{k+1}, P_{k+2}, ..., P_{2^N}, P_1, P_2, ..., P_k$ ãšãªãã ç§»ååŸã®åããããŒãã¡ã³ããå§ãããšãã®ãåªåè
ã®çªå·ãæ±ããã å¶çŽ $1 \leq N \leq 18$ $N$ ã¯æŽæ°ã§ããã $S$ 㯠$0$ ãš $1$ ãããªãé·ã $2^N-1$ ã®æååã§ããã $P$ 㯠$1$ ãã $2^N$ ãŸã§ã®æŽæ°ãäžŠã¹æ¿ããé åã§ããã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããã $N$ $S_1S_2 \ldots S_{2^N-1}$ $P_1$ $P_2$ $\ldots$ $P_{2^N}$ åºå $2^N$ è¡åºåããã $i$ è¡ç® $(1 \le i \le 2^N)$ ã«ã¯ã$k = i-1$ ãšãããšãã®äžèšã®åé¡ã®çããåºåããã å
¥åäŸ1 2 100 1 4 2 3 åºåäŸ1 1 2 1 2 äŸãã° $k = 2$ ãšãããšããç§»ååŸã®åã«ãããåå è
ã®çªå·ãå
é ããæããŠãããšã $2, 3, 1, 4$ ãšãªããŸãã 人 $2$ 㚠人 $3$ ãæŠããšã $S_1 = 1$ ãã人 $3$ ãåã¡ãŸãã 人 $1$ 㚠人 $4$ ãæŠããšã $S_3 = 0$ ãã人 $1$ ãåã¡ãŸãã 人 $3$ 㚠人 $1$ ãæŠããšã $S_2 = 0$ ãã人 $1$ ãåã¡ãŸãã ãããã£ãŠã $k = 2$ ã®å Žåã®åªåè
ã¯ã人 $1$ ãšãªããŸãã å
¥åäŸ2 4 101011100101000 8 15 2 9 12 5 1 7 14 10 11 3 4 6 16 13 åºåäŸ2 16 1 16 2 16 12 10 14 16 1 16 2 16 12 10 14 å
¥åäŸ3 1 0 1 2 åºåäŸ3 1 1 | 36,213 |
Score : 200 points Problem Statement There are N gems. The value of the i -th gem is V_i . You will choose some of these gems, possibly all or none, and get them. However, you need to pay a cost of C_i to get the i -th gem. Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid. Find the maximum possible value of X-Y . Constraints All values in input are integers. 1 \leq N \leq 20 1 \leq C_i, V_i \leq 50 Input Input is given from Standard Input in the following format: N V_1 V_2 ... V_N C_1 C_2 ... C_N Output Print the maximum possible value of X-Y . Sample Input 1 3 10 2 5 6 3 4 Sample Output 1 5 If we choose the first and third gems, X = 10 + 5 = 15 and Y = 6 + 4 = 10 . We have X-Y = 5 here, which is the maximum possible value. Sample Input 2 4 13 21 6 19 11 30 6 15 Sample Output 2 6 Sample Input 3 1 1 50 Sample Output 3 0 | 36,214 |
Score : 900 points Problem Statement Takahashi has decided to give a string to his mother. The value of a string T is the length of the longest common subsequence of T and T' , where T' is the string obtained by reversing T . That is, the value is the longest length of the following two strings that are equal: a subsequence of T (possibly non-contiguous), and a subsequence of T' (possibly non-contiguous). Takahashi has a string S . He wants to give her mother a string of the highest possible value, so he would like to change at most K characters in S to any other characters in order to obtain a string of the highest possible value. Find the highest possible value achievable. Constraints 1 \leq |S| \leq 300 0 \leq K \leq |S| S consists of lowercase English letters. K is an integer. Input Input is given from Standard Input in the following format: S K Output Print the highest possible value achievable. Sample Input 1 abcabcabc 1 Sample Output 1 7 Changing the first character to c results in cbcabcabc . Let this tring be T , then one longest common subsequence of T and T' is cbabcbc , whose length is 7 . Sample Input 2 atcodergrandcontest 3 Sample Output 2 15 | 36,215 |
On-Screen Keyboard You are to input a string with an OSK (on-screen keyboard). A remote control with five buttons, four arrows and an OK (Fig. B-1), is used for the OSK. Find the minimum number of button presses required to input a given string with the given OSK. Fig. B-1 Remote control Fig. B-2 An on-screen keyboard Character to input Move of highlighted cells Button presses I â,â,â,â,â,â,â,â,OK (9 presses) C â,â,â,â,â,â,OK (7 presses) P â,â,â,â,â,OK (6 presses) C â,â,â,â,â,OK (6 presses) Fig. B-3 The minimum steps to input â ICPC â with the OSK in Fig. B-2 The OSK has cells arranged in a grid, each of which has a character in it or is empty. No two of the cells have the same character. One of the cells of the OSK is highlighted, and pressing the OK button will input the character in that cell, if the cell is not empty. Initially, the cell at the top-left corner is highlighted. Pressing one of the arrow buttons will change the highlighted cell to one of the adjacent cells in the direction of the arrow. When the highlighted cell is on an edge of the OSK, pushing the arrow button with the direction to go out of the edge will have no effect. For example, using the OSK with its arrangement shown in Fig. B-2, a string â ICPC â can be input with 28 button presses as shown in Fig. B-3, which is the minimum number of presses. Characters in cells of the OSKs are any of a lowercase letter (â a â, â b â, ..., â z â), an uppercase letter (â A â, â B â, ..., â Z â), a digit (â 0 â, â 1 â, ..., â 9 â), a comma (â , â), a hyphen (â - â), a dot (â . â), a slash (â / â), a colon (â : â), a semicolon (â ; â), or an at sign (â @ â). Input The input consists of at most 100 datasets, each in the following format. h w r 1 ... r h s The two integers h and w in the first line are the height and the width of the OSK, respectively. They are separated by a space, and satisfy 1 †h †50 and 1 †w †50. Each of the next h lines gives a row of the OSK. The i -th row, r i is a string of length w . The characters in the string corresponds to the characters in the cells of the i -th row of the OSK or an underscore (â _ â) indicating an empty cell, from left to right. The given OSK satisfies the conditions stated above. The next line is a string s to be input. Its length is between 1 and 1000, inclusive. All the characters in s appear in the given OSK. Note that s does not contain underscores. The end of the input is indicated by a line containing two zeros. Output For each dataset, output a single line containing an integer indicating the minimum number of button presses required to input the given string with the given OSK. Sample Input 3 9 ABCDEFGHI JKLMNOPQR STUVWXYZ_ ICPC 5 11 ___________ ____A______ ________M__ ___________ _C_________ ACM 4 21 1_2_3_4_5_6_7_8_9_0_- QqWwEeRrTtYyUuIiOoPp@ AaSsDdFfGgHhJjKkLl;_: ZzXxCcVvBbNnMm,_._/__ ICPC2019,AsiaYokohamaRegional,QualificationRound 0 0 Output for the Sample Input 28 23 493 | 36,216 |
Score : 100 points Problem Statement You are given positive integers A and B . If A is a divisor of B , print A + B ; otherwise, print B - A . Constraints All values in input are integers. 1 \leq A \leq B \leq 20 Input Input is given from Standard Input in the following format: A B Output If A is a divisor of B , print A + B ; otherwise, print B - A . Sample Input 1 4 12 Sample Output 1 16 As 4 is a divisor of 12 , 4 + 12 = 16 should be printed. Sample Input 2 8 20 Sample Output 2 12 Sample Input 3 1 1 Sample Output 3 2 1 is a divisor of 1 . | 36,217 |
åé¡å Audition ã¢ã€ãã«---ããã¯å¥³ã®åéã®æ°žé ã®æ§ããããããé ç¹ã«ç«ãŠãã®ã¯ã»ãã®äžæ¡ãããããªãµãã€ãã«ãªäžçã«ãããªãã¯ã¢ã€ãã«ãããã¥ãŒãµãŒãšããŠè¶³ãèžã¿å
¥ããããšã«ãªããŸããããããŠã仿¥ã¯ããªãã®æ
åœã¢ã€ãã«ãé£ããŠå€§äºãªãªãŒãã£ã·ã§ã³ã«æãããšã«ãªããŸããã ãªãŒãã£ã·ã§ã³ã®æ±ºãæã«ãªãã®ã¯ããžã¥ã¢ã«ããã³ã¹ãããŒã«ã«ã® 3 èŠçŽ ã§ãããªãŒãã£ã·ã§ã³äžã«ã¯ m åã®ã¢ããŒã«ã¿ã€ã ãããã 1 åã®ã¢ããŒã«ã¿ã€ã ããšã«åã¢ã€ãã«ã¯ããžã¥ã¢ã«ã¢ããŒã«ããã³ã¹ã¢ããŒã«ãããŒã«ã«ã¢ããŒã«ã®ãããããè¡ãããšãåºæ¥ãŸããããžã¥ã¢ã«ã¢ããŒã«ãè¡ããšãã®ã¢ã€ãã«ã®ããžã¥ã¢ã«ãã€ã³ãã¯åœŒå¥³ã®æã£ãŠãããžã¥ã¢ã«å€ã ãããã³ã¹ã¢ããŒã«ãè¡ããšãã³ã¹ãã€ã³ãã¯åœŒå¥³ã®æã£ãŠããã³ã¹å€ã ããããŒã«ã«ã¢ããŒã«ãè¡ããšããŒã«ã«ãã€ã³ãã¯åœŒå¥³ã®æã£ãŠãããŒã«ã«å€ã ãäžæããŸãã m åã®ã¢ããŒã«ãçµäºããåŸã N 人ã®ã¢ã€ãã«ã®ãã¡ããžã¥ã¢ã«ãã€ã³ãã®é«ãã»ããã 3 人㯠5 ãªãŒãã£ã·ã§ã³ãã€ã³ãããã³ã¹ãã€ã³ãã®é«ãã»ããã 3 人㯠3 ãªãŒãã£ã·ã§ã³ãã€ã³ããããŒã«ã«ãã€ã³ãã®é«ãã»ããã 3 人㯠2 ãªãŒãã£ã·ã§ã³ãã€ã³ããç²åŸããŸããäžæ¹ãããžã¥ã¢ã«ãã€ã³ããæäžäœã ãšãªãŒãã£ã·ã§ã³ãã€ã³ã㯠1 ç¹æžç¹ããã³ã¹ãã€ã³ããæäžäœã ãšãªãŒãã£ã·ã§ã³ãã€ã³ã㯠1 ç¹æžç¹ãããŒã«ã«ãã€ã³ããæäžäœã ãšãªãŒãã£ã·ã§ã³ãã€ã³ã㯠1 ç¹æžç¹ãšãªããŸããïŒãªãŒãã£ã·ã§ã³ãã€ã³ãã1以äžã§ããããã 1 ç¹æžç¹ïŒã ãªãŒãã£ã·ã§ã³ã®å§ãã«ãåã¢ã€ãã«ã®ããžã¥ã¢ã«ãã€ã³ãããã³ã¹ãã€ã³ããããŒã«ã«ãã€ã³ãã¯ãããã 0 ã§ããããªãã¯ã¢ã€ãã« 1 ã®ãããã¥ãŒãµãŒã§ãã¢ããŒã«ã¿ã€ã ããšã«ã©ã®ã¢ããŒã«ãè¡ããæç€ºããããšãåºæ¥ãŸããã¢ã€ãã« 1 以å€ã®ã¢ã€ãã«ã¯ã¢ããŒã«ã¿ã€ã ããšã«ã©ã³ãã ã«ç確çã«ã©ããã®ã¢ããŒã«ãè¡ããŸãïŒã€ãŸããããã 3 åã® 1 ã®ç¢ºçã§è¡ãããïŒãã¢ã€ãã« 1 ã®ããžã¥ã¢ã«ããã³ã¹ãããŒã«ã«ã®ãã€ã³ããä»ã®ã¢ã€ãã«ãšçããå Žåãã¢ã€ãã« 1 ã¯åžžã«äžäœãšããŸããã¢ã€ãã« 1 ã®ç²åŸãããªãŒãã£ã·ã§ã³ãã€ã³ãã®æåŸ
å€ãæå€§ã«ãªãããã«æç€ºãããšãã®æåŸ
å€ãæ±ããŠäžãããã¢ã€ãã«ã®éåœã¯ãããªãã®æç€ºã«ããã£ãŠããŸãïŒ ã¡ãªã¿ã«ãæç€ºã¯ãªãŒãã£ã·ã§ã³ãå§ãŸãåã«å
šãŠè¡ã£ãŠããã®åŸãªãŒãã£ã·ã§ã³äžã®æç€ºã®å€æŽã¯åºæ¥ãªããã®ãšããŸããã€ãŸããä»ã®ã¢ã€ãã«ãããªãŒãã£ã·ã§ã³ãå§ãŸã£ãŠããã®ã¢ããŒã«ã§ã©ã®ã¢ããŒã«ãããããèŠãŠããããã®å Žåã«ãããŠã®æåŸ
å€ãæå€§ãšãªããããªæç€ºãåºãããšããããšã¯åºæ¥ãªããã®ãšããŸãã Input å
¥åã¯ä»¥äžã®åœ¢ã§äžããããŸãã n m vi 1 da 1 vo 1 vi 2 da 2 vo 2 ... vi n da n vo n 1è¡ç®ã«ã¯ãªãŒãã£ã·ã§ã³ã«åºå Žããã¢ã€ãã«ã®æ° n ( 4 †n †2000 ) ãšããã®ãªãŒãã£ã·ã§ã³ã«ãããã¢ããŒã«ã¿ã€ã ã®æ° m ( 1 †m †2000 ) ãæžããŠãããŸããæ¬¡ã® n è¡ã«ã¯ããããã¢ã€ãã«iã®ããžã¥ã¢ã«å€ vi i ããã³ã¹å€ da i ãããŒã«ã«å€ vo i ( 1 †vi i , da i , vo i †10,000 )ãæžããŠãããŸãã Output ã¢ã€ãã« 1 ã®ç²åŸãããªãŒãã£ã·ã§ã³ãã€ã³ãã®æåŸ
å€ã®æå€§å€ã 1 è¡ã§åºåããªããã Sample Input 1 4 1 1 1 1 1 1 1 1 1 1 1 1 1 Output for the Sample Input 1 2.777777777778 ã©ã®ã¢ããŒã«ãè¡ã£ãŠãããã®ãžã£ã³ã«ã§ 3 äœä»¥å
ã«å
¥ãã確çã¯çããã§ããã 3 äœä»¥å
ã«å
¥ã£ãæã«è²°ãããªãŒãã£ã·ã§ã³ãã€ã³ããæãå€ãããžã¥ã¢ã«ã®ã¢ããŒã«ãè¡ãã®ããã£ãšãæåŸ
å€ãè¯ããªããŸãã Sample Input 2 4 10 1 1 1 10 10 10 10 10 10 10 10 10 Output for the Sample Input 2 -2.335340954780 éåžžã«å³ãããªãŒãã£ã·ã§ã³ãšãªãã§ãããã Sample Input 3 9 9 13 5 19 19 21 37 15 1 7 7 11 15 21 23 25 33 29 19 13 19 11 21 5 15 7 13 1 Output for the Sample Input 3 4.678837855075 | 36,218 |
Score : 300 points Problem Statement You are given an undirected connected graph with N vertices and M edges that does not contain self-loops and double edges. The i -th edge (1 \leq i \leq M) connects Vertex a_i and Vertex b_i . An edge whose removal disconnects the graph is called a bridge . Find the number of the edges that are bridges among the M edges. Notes A self-loop is an edge i such that a_i=b_i (1 \leq i \leq M) . Double edges are a pair of edges i,j such that a_i=a_j and b_i=b_j (1 \leq i<j \leq M) . An undirected graph is said to be connected when there exists a path between every pair of vertices. Constraints 2 \leq N \leq 50 N-1 \leq M \leq min(N(Nâ1)â2,50) 1 \leq a_i<b_i \leq N The given graph does not contain self-loops and double edges. The given graph is connected. 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 number of the edges that are bridges among the M edges. Sample Input 1 7 7 1 3 2 7 3 4 4 5 4 6 5 6 6 7 Sample Output 1 4 The figure below shows the given graph: The edges shown in red are bridges. There are four of them. Sample Input 2 3 3 1 2 1 3 2 3 Sample Output 2 0 It is possible that there is no bridge. Sample Input 3 6 5 1 2 2 3 3 4 4 5 5 6 Sample Output 3 5 It is possible that every edge is a bridge. | 36,219 |
Score : 100 points Problem Statement There are two rectangles. The lengths of the vertical sides of the first rectangle are A , and the lengths of the horizontal sides of the first rectangle are B . The lengths of the vertical sides of the second rectangle are C , and the lengths of the horizontal sides of the second rectangle are D . Print the area of the rectangle with the larger area. If the two rectangles have equal areas, print that area. Constraints All input values are integers. 1â€Aâ€10^4 1â€Bâ€10^4 1â€Câ€10^4 1â€Dâ€10^4 Input The input is given from Standard Input in the following format: A B C D Output Print the area of the rectangle with the larger area. If the two rectangles have equal areas, print that area. Sample Input 1 3 5 2 7 Sample Output 1 15 The first rectangle has an area of 3Ã5=15 , and the second rectangle has an area of 2Ã7=14 . Thus, the output should be 15 , the larger area. Sample Input 2 100 600 200 300 Sample Output 2 60000 | 36,220 |
Score : 600 points Problem Statement Given are a sequence of N integers A_1 , A_2 , \ldots , A_N and a positive integer S . For a pair of integers (L, R) such that 1\leq L \leq R \leq N , let us define f(L, R) as follows: f(L, R) is the number of sequences of integers (x_1, x_2, \ldots , x_k) such that L \leq x_1 < x_2 < \cdots < x_k \leq R and A_{x_1}+A_{x_2}+\cdots +A_{x_k} = S . Find the sum of f(L, R) over all pairs of integers (L, R) such that 1\leq L \leq R\leq N . Since this sum can be enormous, print it modulo 998244353 . Constraints All values in input are integers. 1 \leq N \leq 3000 1 \leq S \leq 3000 1 \leq A_i \leq 3000 Input Input is given from Standard Input in the following format: N S A_1 A_2 ... A_N Output Print the sum of f(L, R) , modulo 998244353 . Sample Input 1 3 4 2 2 4 Sample Output 1 5 The value of f(L, R) for each pair is as follows, for a total of 5 . f(1,1) = 0 f(1,2) = 1 (for the sequence (1, 2) ) f(1,3) = 2 (for (1, 2) and (3) ) f(2,2) = 0 f(2,3) = 1 (for (3) ) f(3,3) = 1 (for (3) ) Sample Input 2 5 8 9 9 9 9 9 Sample Output 2 0 Sample Input 3 10 10 3 1 4 1 5 9 2 6 5 3 Sample Output 3 152 | 36,221 |
Square Carpets Mr. Frugal bought a new house. He feels deeply in love with his new house because it has a comfortable living room in which he can put himself completely at ease. He thinks his new house is a really good buy. But, to his disappointment, the floor of its living room has some scratches on it. The floor has a rectangle shape, covered with square panels. He wants to replace all the scratched panels with flawless panels, but he cannot afford to do so. Then, he decides to cover all the scratched panels with carpets. The features of the carpets he can use are as follows. Carpets are square-shaped. Carpets may overlap each other. Carpets cannot be folded. Different sizes of carpets are available. Lengths of sides of carpets are multiples of that of the panels. The carpets must cover all the scratched panels, but must not cover any of the flawless ones. For example, if the scratched panels are as shown in Figure 1, at least 6 carpets are needed. Figure 1: Example Covering As carpets cost the same irrespective of their sizes, Mr. Frugal would like to use as few number of carpets as possible. Your job is to write a program which tells the minimum number of the carpets to cover all the scratched panels. Input The input consists of multiple data sets. As in the following, the end of the input is indicated by a line containing two zeros. DataSet 1 DataSet 2 ... DataSet n 0 0 Each data set ( DataSet i ) represents the state of a floor. The format of a data set is as follows. W H P 11 P 12 P 13 ... P 1 W P 21 P 22 P 23 ... P 2 W ... P H 1 P H 2 P H 3 ... P HW The positive integers W and H are the numbers of panels on the living room in the x- and y- direction, respectively. The values of W and H are no more than 10. The integer P yx represents the state of the panel. The value of P yx means, 0 : flawless panel (must not be covered), 1 : scratched panel (must be covered). Output For each data set, your program should output a line containing one integer which represents the minimum number of the carpets to cover all of the scratched panels. Sample Input 4 3 0 1 1 1 1 1 1 1 1 1 1 1 8 5 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 0 1 1 1 0 1 1 1 8 8 0 1 1 0 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 0 1 1 0 10 10 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 0 0 Output for the Sample Input 2 6 14 29 | 36,222 |
Minimum Spanning Tree Find the sum of weights of edges of the Minimum Spanning Tree for a given weighted undirected graph G = ( V , E ). Input |V| |E| s 0 t 0 w 0 s 1 t 1 w 1 : s |E|-1 t |E|-1 w |E|-1 , where |V| is the number of vertices and |E| is the number of edges in the graph. The graph vertices are named with the numbers 0, 1,..., |V| -1 respectively. s i and t i represent source and target verticess of i -th edge (undirected) and w i represents the weight of the i -th edge. Output Print the sum of the weights of the Minimum Spanning Tree. Constraints 1 †|V| †10,000 0 †|E| †100,000 0 †w i †10,000 The graph is connected There are no parallel edges There are no self-loops Sample Input 1 4 6 0 1 2 1 2 1 2 3 1 3 0 1 0 2 3 1 3 5 Sample Output 1 3 Sample Input 2 6 9 0 1 1 0 2 3 1 2 1 1 3 7 2 4 1 1 4 3 3 4 1 3 5 1 4 5 6 Sample Output 2 5 | 36,223 |
Dungeon Bob is playing a popular game called "Dungeon". The game is played on a rectangular board consisting of W à H squares. Each square is identified with its column and row number, thus the square located in the x -th column and the y -th row is represented as ( x , y ). The left-most square in the top row is (0, 0) and the right-most square in the bottom row is ( W -1, H -1). Bob moves a character "BomBom" to clear the game. BomBom is initially located at (0, 0). The game is won if Bob successfully destroys all the enemy characters on the board by manipulating BomBom cleverly. The enemy characters are fixed on specific squares, and Bob can manipulate BomBom using the following two operations any number of times. One-square movement in the up, down, left, or right direction within the board Using a bomb, eliminate all the enemy characters that are located in the same column and row as that of BomBom BomBom consumes a Cost when it moves from one square to another. BomBom can use a bomb any number of times without consuming a Cost. Use of a bomb has no effect on BomBomâs behavior and it can move even to a square where an enemy character is located. Given the board size and enemy information, make a program to evaluate the minimum Cost BomBom consumes before it destroys all enemy characters. Input The input is given in the following format. W H N x_1 y_1 x_2 y_2 : x_N y_N The first line provides the number of squares in the horizontal direction W (1 †W †10 5 ), in the vertical direction H (1 †H †10 5 ), and the number of enemy characters N (1 †N †10 5 ). Each of the subsequent N lines provides location information of the i -th enemy, column x_i (0 †x_i †W -1) and row y_i (0 †y_i †H -1). The number of enemy characters in a specific square can be either one or zero. Output Output the minimum Cost in a line. Sample Input 1 5 4 4 0 3 1 1 2 2 2 3 Sample Output 1 2 Sample Input 2 6 6 5 2 1 5 2 3 3 1 4 1 5 Sample Output 2 4 Sample Input 3 8 8 4 6 0 7 0 0 6 0 7 Sample Output 3 0 | 36,224 |
åèšæé (Total Time) åé¡ å€ªéå㯠3 ã«æã®åºã蚪ããããšãæ¥èª²ã«ããŠããïŒå®¶ãåºçºãïŒæ±ºãŸã£ãé çªã§ 3 ã«æã®åºãåã£ãåŸïŒå®¶ã«åž°ãïŒãšãã©ãïŒã¹ããããŠã©ããã䜿ã£ãŠïŒååºéãç§»åããã®ã«äœç§ããã£ãããèšãïŒãã®ç§æ°ãèšé²ããïŒ ããæ¥ã®èšæž¬çµæãäžãããããšãïŒãã®æ¥ã®ç§»åæéã®åèšãäœåäœç§ããæ±ããããã°ã©ã ãäœæããïŒ å
¥å å
¥å㯠4 è¡ãããªãïŒ 1 è¡ã« 1 ã€ãã€æ£ã®æŽæ°ãæžãããŠããïŒ 1 è¡ç®ã®æŽæ°ã¯å®¶ãã 1 ã€ç®ã®åºãŸã§ã®ç§»åæéã衚ãç§æ°ã§ããïŒ 2 è¡ç®ã®æŽæ°ã¯ 1 ã€ç®ã®åºãã 2 ã€ç®ã®åºãŸã§ã®ç§»åæéã衚ãç§æ°ã§ããïŒ 3 è¡ç®ã®æŽæ°ã¯ 2 ã€ç®ã®åºãã 3 ã€ç®ã®åºãŸã§ã®ç§»åæéã衚ãç§æ°ã§ããïŒ 4 è¡ç®ã®æŽæ°ã¯ 3 ã€ç®ã®åºããå®¶ãŸã§ã®ç§»åæéã衚ãç§æ°ã§ããïŒãã ãïŒäžããããå
¥åããŒã¿ã«ãããŠã¯åèšç§»åæé㯠1 å 0 ç§ä»¥äžã§ 59 å 59 ç§ä»¥äžã§ããããšãä¿èšŒãããŠããïŒ åºå åºå㯠2 è¡ãããªãïŒx å y ç§ (1 †x †59 , 0 †y †59 )ã®ãšãïŒ 1è¡ç®ã« x ãïŒ2è¡ç®ã« y ãåºåããïŒ å
¥åºåäŸ å
¥åäŸ 1 31 34 7 151 åºåäŸ 1 3 43 å
¥åäŸ 2 316 430 643 1253 åºåäŸ 2 44 2 å
¥åäŸ 3 5 10 15 30 åºåäŸ 3 1 0 å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã | 36,225 |
What day is today? Your task is to write a program which reads a date (from 2004/1/1 to 2004/12/31) and prints the day of the date. Jan. 1, 2004, is Thursday. Note that 2004 is a leap year and we have Feb. 29. Input The input is a sequence of datasets. The end of the input is indicated by a line containing one zero. Each dataset consists of two integers m and d separated by a single space in a line. These integers respectively represent the month and the day. The number of datasets is less than or equal to 50. Output For each dataset, print the day (please see the following words) in a line. Monday Tuesday Wednesday Thursday Friday Saturday Sunday Sample Input 1 1 2 29 0 0 Output for the Sample Input Thursday Sunday | 36,226 |
Problem H: Robot Communication In the year 21xx, human beings are proliferating across the galaxy. Since the end of the last century, thousands of pioneer spaceships have been launched in order to discover new habitation planets. The Presitener is one of those spaceships, heading toward the Andromeda galaxy. After a long, long cruise in the hyperspace, the crew have finally found a very hopeful candidate planet. The next thing to do is to investigate the planet whether it is really suitable for a new resident or not. For that purpose, the ship is taking some unattended landers. The captain Juclean Dripac decided to drop them to the planet and collect data about it. But unfortunately, these robots are a bit old and not so clever that the operator has to program what to do on the planet beforehand of the landing. Many staffs including you are called for making this important plan. The most complicated phase in the mission is to gather and integrate all the data collected independently by many robots. The robots need to establish all-to-all communication channels to exchange the data, once during the mission. That is, all the robots activate their communication channels all together at the predetermined time, and they exchange the data with each other at that time. They use wireless channels to communicate with each other, so the distance between robots does not limit the connectivity. But the farther two robots goes, the more power they have to use for communication. Due to the limitation of the battery capacity, you want to save the transmission power as much as possible. For a good thing, communication units of the robots also have the routing functionality, each robot only has to talk with the nearest robot. Suppose a graph whose vertices represent robots and edges represent communication channels established between them. If the graph is connected, all-to-all communication can be established. Your task is to write the program to calculate the minimum total transmission power required for all- to-all communication among the robots. Each robot moves linearly on the planet surface. Each pair of robots which communicate each other must occupy one channel, but you can assume enough number of channels are available. The transmission power required for two robots is proportional to the distance between them, so the cost here is exactly the sum of the distances between each pair of robots which establish a communication channel. You may also regard the planet surface as a two-dimensional surface, as it is huge enough. The time required for communicating data among robots are also negligible. Input The input contains multiple datasets. Each dataset has the format below. N T x 1 y 1 vx 1 vy 1 ... x N y N vx N vy N The first line of each dataset contains two integers; N is the number of robots used for gathering data (2 †N †16), and T is the time limit of the mission (1 †T < 1000). Each of the following N lines describes the motion of a robot. ( x i , y i ) and ( vx i , vy i ) are the initial landing position and the velocity of the i -th robot, respectively (| x i |, | y i | < 100000, | vx i |, | vy i | < 1000). The last dataset is followed by a line containing two zeros. This line is not a part of any dataset and should not be processed. Output For each dataset, output in a line the minimum communication cost required for all-to-all communication. Your program may output an arbitrary number of digits after the decimal point. The absolute error should be less than or equal to 0.001. Sample Input 4 2 2 0 0 1 0 4 1 0 4 6 0 -1 6 2 -1 0 4 6 2 0 0 1 0 4 1 0 4 6 0 -1 6 2 -1 0 0 0 Output for the Sample Input 6.00000000 4.24264069 | 36,227 |
Problem C: Mysterious Operator ã±ãŒæ°ããã€ãã®ããã«æSNSãé²èЧããŠãããšã ãè§£ãã人ã¯IQ150以äžããããšããåé¡ãã¿ã€ã ã©ã€ã³ã«æµããŠããã ã±ãŒæ°ã¯IQã150以äžããã®ã§ãèŠããŸã§ããªããã®åé¡ãäžç¬ã§è§£ããŠããŸã£ãã 圌ã«ããŠã¿ãã°ããã®ãããªåé¡ãªãã«é ãåãããå¿
èŠã¯ç¡ãã ã³ã³ãã¥ãŒã¿ã«ä»»ããã°å
åãªã®ã§ããã åé¡ åé¡ã«ã¯ä»¥äžã®ãããªè¬ã®æ°åŒãæžãããŠããã \( 5 + 3 = 28 \) \( 9 + 1 = 810 \) \(8 + 6 = 214 \) \( 5 + 4 = 19 \) \( 2 + 2 = 4 \) \( 15 + 8 = 723 \) \( 7 + 9 = -216 \) \( 3 + 0 = 33 \) äžèšã®æŒç®å\( + \)ã«ã€ããŠèããæãããæ£æŽæ°\( a \)ã«ã€ããŠ\( x \geq 0, y \geq 0 \)ãã€\( x + y = a \)ã«ãªããããªæŽæ°ã®ãã¢\( x,y \)ã®åæ°ãæ±ããã å
¥å æ£æŽæ°\(a\)ãäžè¡ã§äžããããã åºå \( a = x + y, x \geq 0, y \geq 0\)ãæºãããã¢\((x,y)\)ã®åæ°ãäžè¡ã«åºåããã å¶çŽ \( 1 \leq a \leq 10^9(= 1000000000) \) å
¥åºåäŸ å
¥å1 19 åºå1 1 \( 5 + 4 \)ã®1éãã§ããã å
¥å2 22 åºå2 2 \( 11 + 11 \)ãšã\( 2 + 0 \)ã®2éããååšããã å
¥å3 1 åºå3 0 \( 1 + 0 = 11 , 0 + 1 = -11 \)ã§ããã\( 1 \)ã¯çæããããšãã§ããªãã å
¥å4 101 åºå4 0 \( 1 - 0 \)ã¯\( 101 \)ã§ã¯ãªãããšã«æ³šæããããšã å
¥å5 660233276 åºå5 4 | 36,228 |
Problem A: Bit String Reordering You have to reorder a given bit string as specified. The only operation allowed is swapping adjacent bit pairs. Please write a program that calculates the minimum number of swaps required. The initial bit string is simply represented by a sequence of bits, while the target is specified by a run-length code . The run-length code of a bit string is a sequence of the lengths of maximal consecutive sequences of zeros or ones in the bit string. For example, the run-length code of "011100" is "1 3 2". Note that there are two different bit strings with the same run-length code, one starting with zero and the other starting with one. The target is either of these two. In Sample Input 1, bit string "100101" should be reordered so that its run-length code is "1 3 2", which means either "100011" or "011100". At least four swaps are required to obtain "011100". On the other hand, only one swap is required to make "100011". Thus, in this example, 1 is the answer. Input The input consists of a single test case. The test case is formatted as follows. $N$ $M$ $b_1$ $b_2$ . . . $b_N$ $p_1$ $p_2$ . . . $p_M$ The first line contains two integers $N$ ($1 \leq N \leq 15$) and $M$ ($1 \leq M \leq N$). The second line specifies the initial bit string by $N$ integers. Each integer $b_i$ is either 0 or 1. The third line contains the run-length code, consisting of $M$ integers. Integers $p_1$ through $p_M$ represent the lengths of consecutive sequences of zeros or ones in the bit string, from left to right. Here, $1 \leq p_j$ for $1 \leq j \leq M$ and $\sum^{M}_{j=1} p_j = N$ hold. It is guaranteed that the initial bit string can be reordered into a bit string with its run-length code $p_1, . . . , p_M$. Output Output the minimum number of swaps required Sample Input 1 6 3 1 0 0 1 0 1 1 3 2 Sample Output 1 1 Sample Input 2 7 2 1 1 1 0 0 0 0 4 3 Sample Output 2 12 Sample Input 3 15 14 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 Sample Output 3 7 Sample Input 4 1 1 0 1 Sample Output 4 0 | 36,229 |
Score: 500 points Problem Statement Given is a permutation P of \{1, 2, \ldots, N\} . For a pair (L, R) (1 \le L \lt R \le N) , let X_{L, R} be the second largest value among P_L, P_{L+1}, \ldots, P_R . Find \displaystyle \sum_{L=1}^{N-1} \sum_{R=L+1}^{N} X_{L,R} . Constraints 2 \le N \le 10^5 1 \le P_i \le N P_i \neq P_j (i \neq j) All values in input are integers. Input Input is given from Standard Input in the following format: N P_1 P_2 \ldots P_N Output Print \displaystyle \sum_{L=1}^{N-1} \sum_{R=L+1}^{N} X_{L,R} . Sample Input 1 3 2 3 1 Sample Output 1 5 X_{1, 2} = 2, X_{1, 3} = 2 , and X_{2, 3} = 1 , so the sum is 2 + 2 + 1 = 5 . Sample Input 2 5 1 2 3 4 5 Sample Output 2 30 Sample Input 3 8 8 2 7 3 4 5 6 1 Sample Output 3 136 | 36,230 |
Problem C: ã³ã³ãã€ã« æ±äº¬å€§åŠã«å
¥åŠãããããŸãåã¯TSG(æ±å€§ã¹ãŒããŒã²ãŒããŒãº)ãšãããµãŒã¯ã«ã«å
¥ã£ãã ãã®ãµãŒã¯ã«ã¯æ¯å¹Žãé§å Žç¥ã§ã²ãŒã ãå±ç€ºããŠããããããŸãåãã²ãŒã ãäœæããŠå±ç€ºããããšã«ããã ãããŸãåã®äœæããã²ãŒã ã¯æ¬¡ã®ãããªãããããèœã¡ç©ããºã«ã²ãŒã ã§ããã æšª6ãã¹Ã瞊12ãã¹ã®æ Œåç¶ã®ãã£ãŒã«ãããããåãã¹ã«ã€ã1åã®ãããã¯ã眮ãããšãã§ããã äžãããããã¯ã2ã€1çµã§èœäžããŠããããããã¯ã«ã¯èµ€ã»ç·ã»éã»é»ã»çŽ«ã®5è²ã®åºæ¬ãããã¯ãšãéªéãããã¯ã®èš6çš®é¡ãããããã¬ã€ã€ãŒã¯ãããã¯ãåè»¢ãæšªç§»åã«ããæäœããèœäžäœçœ®ã倿Žããããšãã§ããã èœäžããŠãããããã¯ããã£ãŒã«ãã®åºãã»ãã®ãããã¯ã«è¡çªãããšããã®äœçœ®ã«ãããã¯ãåºå®ãããã åºå®ããããããã¯ãšåè²ã®ãããã¯ãåšå²4æ¹åã«ããå Žåããããã¯äºãã«ãã£ã€ãããã ãããéªéãããã¯ã¯äºãã«ãã£ã€ããªãã ãããã¯ã4å以äžãã£ã€ããšæ¶æ»
ãåŸç¹ãšãªãããéªéãããã¯ã®åšå²4æ¹åã«ååšããåºæ¬ãããã¯ãæ¶æ»
ãããšããã®ãéªéãããã¯ãäžç·ã«æ¶æ»
ããããããã¯ã®æ¶æ»
ã¯ãå
šãŠã®ãããã¯ã®èœäžãçµäºããã¿ã€ãã³ã°ã§åæã«èµ·ããã ãããã¯ã®æ¶æ»
ã«ããããã®äžã«ãã£ããããã¯ãèœäžããããã®ãããã¯ã®èœäžã¯ãã¬ã€ã€ãŒãæäœã§ããªãããã®ãšãåã³ãããã¯ã4å以äžãã£ã€ããšæ¶æ»
ããé£éãèµ·ããããã ããè€æ°è²ãåæã«æ¶ããå Žåã§ãã1é£éæ±ããšãªãã ãããŸãåã¯ãã®ã²ãŒã ã®å€§éšåã®ããã°ã©ã ãæžãçµããããã©ãããŠããããã¯ããã£ã€ããŠæ¶æ»
ãããšãã®åŠçãæžãããšãåºæ¥ãªãã£ããããã§ãµãŒã¯ã«ã®å人ã§ããããªãã«ãã®éšåã®ããã°ã©ã ãæžããŠãããããšã«ããã Input å
¥åã¯12è¡ãããªãã å
¥åã® i è¡ç®ã¯é·ã6ã®æååãããªãããã® j æåç®ã¯ãã£ãŒã«ãã®äžãã i è¡ç®ãå·Šãã j åç®ã®ãã¹ã®ç¶æ
ã衚ããŠããã ãã¹ã®ç¶æ
ã衚ãæåã¯ä»¥äžã®7ã€ã®ãã¡ã®ããããã§ããã æå çš®é¡ R èµ€ G ç· B é Y é» P 玫 O ãéªé . 空ããã¹ ãŸããå
¥åã«å«ãŸããå
šãŠã®ãããã¯ã¯åºã®äžãä»ã®ãããã¯ã®äžã«ä¹ã£ãŠããã Output å
¥åã®ç¶æ
ãããã«ãŒã«ã«åŸã£ãŠãããã¯ãæ¶ããŠãã£ãæã®é£éæ°ãèšç®ããäžè¡ã§åºåããã ãããã¯ãäžã€ãæ¶ããªãå Žåã¯0ãšåºåããã Notes on Test Cases äžèšå
¥å圢åŒã§è€æ°ã®ããŒã¿ã»ãããäžããããŸãã å
¥åã®1è¡ç®ã«ããŒã¿ã»ããã®æ°TãäžããããŸãã åããŒã¿ã»ããã«å¯ŸããŠäžèšåºå圢åŒã§åºåãè¡ãããã°ã©ã ãäœæããŠäžããã Sample Input 3 ...... ...... ...... ...... ...... ...... ...... ...... .RGB.. RGOP.. RGBPB. RGBPP. GBRGYP GBRRYP BGGRBB BPRGYY GGPRRY BYPPRB YGGGPB GYYYPR YRBRBR YBRBRB BRBRBR BRBRBR ...... ...... ...... ...... ...... ...... ...... ...... ...... ...... ..OO.. ..OO.. Output for Sample Input 3 18 0 | 36,231 |
B: Cram School Schedule / å¡Ÿã®æéå² ç©èª ããªãã¯å¡Ÿã®çµå¶è
ã§ããïŒããªãã®å¡Ÿã¯åäººææ¥å¶ã§1人ã®çåŸãš1人ã®å
çã§ææ¥ãè¡ãïŒãã®å¡Ÿã®å
çã¯éåžžã«åªç§ã§ç§ç®ã«ããããããã¹ãŠã®ææ¥ãè¡ãããšãã§ããïŒãŸãïŒå
çãšçåŸã¯éåžžã«ã¿ããªã®ã§ïŒåºåžã§ããææ¥ã«ã¯ä»ã®ææ¥ã®åºåžç¶æ³ã«ãããããïŒãã¹ãŠåºåžããããšãå¯èœã§ããïŒäŸãã°ïŒåãæéåž¯ã®ææ¥ã«åºåžã§ãã2人ã®çåŸãš4人ã®å
çãããå Žåã¯ïŒãã®æé垯ã«2ã€ã®ææ¥ãè¡ããïŒ ããªãã¯æ¥æã®ææ¥äºå®ãç«ãŠãªããŠã¯ãããªããïŒå
çãšçåŸã®äººæ°ãå€ãããäºå®ãç«ãŠãã®ãéåžžã«å€§å€ã§ããïŒãŸãïŒããªãã¯ã§ããã ãå€ãã®ææ¥ãè¡ããããšèããŠããïŒãã®ããïŒããªãã¯è¡ããæå€§ã®ææ¥æ°ãæ±ããããã°ã©ã ãäœãããšã«ããïŒ åé¡ å
çã®äººæ°ãšïŒçåŸã®äººæ°ïŒããããã®å
çãšçåŸã®äºå®ããªãæéåž¯ïŒææ¥ãè¡ããæé垯ãäžããããïŒããããã®å
çïŒãŸãã¯çåŸã«ã€ããŠïŒäºå®ããªãæéåž¯ãææ¥ãè¡ããæé垯ãå®å
šã«è¢«èŠããŠãããšãïŒãã®å
çïŒãŸãã¯çåŸã¯ãã®ææ¥ã«åºåžã§ããïŒããããã®ææ¥ãè¡ããæé垯ã§ã¯ïŒåºåžã§ããå
çãšçåŸãããªããã¢ãè€æ°äœãïŒäœã£ããã¢ã®æ°ã ãã®ææ¥ãåæã«è¡ãããšãã§ããïŒãã®ãšãã«è¡ããæå€§ã®ææ¥æ°ãæ±ããïŒ å
¥ååœ¢åŒ å
¥åããŒã¿ã®åœ¢åŒã¯ä»¥äžã®ããã«äžããããïŒ ææ¥ãè¡ããæéåž¯ã®æ
å ± n å
ç 1 ã®æéåž¯ã®æ
å ± ... å
ç n ã®æéåž¯ã®æ
å ± m çåŸ 1 ã®æéåž¯ã®æ
å ± ... çåŸ m ã®æéåž¯ã®æ
å ± æåã®1è¡ã«ã¯ææ¥ãè¡ããæéåž¯ã®æ
å ±ãäžããããïŒ ç¶ã1è¡ã«ã¯å
çã®äººæ° n ( 1 †n †100 ) ãäžããããïŒç¶ã n è¡ã® i è¡ç®ã«ã¯ i çªç®ã®å
çã®äºå®ããªãæéåž¯ã®æ
å ±ãäžããããïŒ ç¶ã1è¡ã«ã¯çåŸã®äººæ° m ( 1 †m †100 ) ãäžããããïŒç¶ã m è¡ã® i è¡ç®ã«ã¯ i çªç®ã®çåŸã®äºå®ããªãæéåž¯ã®æ
å ±ãäžããããïŒ åã
ã®æéåž¯ã®æ
å ±ã¯æ¬¡ã®åœ¢åŒã§äžããããïŒ k ah_1 : am_1 - bh_1 : bm_1 . . . ah_k : am_k - bh_k : bm_k ã¯ããã«æéåž¯ã®æ° k ( 1 †k †100 ) ãäžãããïŒç©ºçœåºåãã§ k åã®æé垯ãäžããããïŒ i çªç®ã®æé垯㯠ah_i : am_i - bh_i : bm_i ã®åœ¢åŒã§äžãããïŒ ah_i : am_i ãéå§æå»ã衚ãïŒ bh_i : bm_i ãçµäºæå»ã衚ãïŒ ah_i , am_i , bh_i , bm_i ã¯ãããã0è©°ã2æ¡ã§ 0 †ah_i, bh_i †23 , 0 †am_i, bm_i †59 ãæºããæŽæ°ã§ããïŒ äžãããããã¹ãŠã®æé垯ã«ã€ããŠïŒéå§æå»ã¯çµäºæå»ããçã«æ©ãïŒãŸãïŒããããã®æéåž¯ã®æ
å ±ã«ãããŠïŒæéåž¯ã¯æ©ãæå»é ã«äžŠãã§ããïŒã©ã®çµäºæå»ã1ã€åŸã®æé垯ã®éå§æå»ããçã«æ©ãïŒ åºååœ¢åŒ è¡ããææ¥ã®æå€§æ°ã1è¡ã§åºåããïŒ å
¥åäŸ1 2 10:00-11:30 12:00-13:00 2 1 10:00-15:00 2 09:00-12:00 18:10-18:55 2 2 10:00-13:00 15:30-16:40 3 06:00-08:00 12:00-13:10 15:00-17:00 åºåäŸ1 2 1ã€ç®ã®æé垯ãš2ã€ç®ã®æé垯ã§1ã€ãã€ææ¥ãè¡ãããšã§ïŒ2åã®ææ¥ãè¡ãããšãã§ããïŒ å
¥åäŸ2 2 07:00-08:30 10:00-12:00 3 3 08:30-09:00 11:05-15:05 23:10-23:55 2 09:00-12:00 17:45-18:55 1 08:00-10:00 2 2 07:20-11:00 12:30-17:05 3 07:48-08:51 11:22-16:15 17:02-17:59 åºåäŸ2 0 äºå®ããªãæé垯ã§07:00ããã®ææ¥ã«éã«åãå
çãšçåŸã®ãã¢ãååšããªãã®ã§1ã€ç®ã®æéåž¯ã¯ææ¥ãè¡ãããšãã§ããªãïŒãŸãïŒ2ã€ç®ã®æé垯ã¯2人ç®ã®å
çãåºåžã§ãããïŒçåŸã¯èª°ãåºåžã§ããªãïŒãã£ãŠïŒ2ã€ç®ã®æéåž¯ãææ¥ãè¡ãããšãã§ããªãïŒãããã£ãŠïŒè¡ããæå€§ã®ææ¥æ°ã¯0ã§ããïŒ | 36,232 |
Problem H: Bug Hunt In this problem, we consider a simple programming language that has only declarations of one- dimensional integer arrays and assignment statements. The problem is to find a bug in the given program. The syntax of this language is given in BNF as follows: where < new line > denotes a new line character (LF). Characters used in a program are alphabetical letters, decimal digits, = , [ , ] and new line characters. No other characters appear in a program. A declaration declares an array and specifies its length. Valid indices of an array of length n are integers between 0 and n - 1, inclusive. Note that the array names are case sensitive, i.e. array a and array A are different arrays. The initial value of each element in the declared array is undefined. For example, array a of length 10 and array b of length 5 are declared respectively as follows. a[10] b[5] An expression evaluates to a non-negative integer. A < number > is interpreted as a decimal integer. An < array_name > [< expression >] evaluates to the value of the < expression > -th element of the array. An assignment assigns the value denoted by the right hand side to the array element specified by the left hand side. Examples of assignments are as follows. a[0]=3 a[1]=0 a[2]=a[a[1]] a[a[0]]=a[1] A program is executed from the first line, line by line. You can assume that an array is declared once and only once before any of its element is assigned or referred to. Given a program, you are requested to find the following bugs. An index of an array is invalid. An array element that has not been assigned before is referred to in an assignment as an index of array or as the value to be assigned. You can assume that other bugs, such as syntax errors, do not appear. You can also assume that integers represented by < number > s are between 0 and 2 31 - 1 (= 2147483647), inclusive. Input The input consists of multiple datasets followed by a line which contains only a single ' . ' (period). Each dataset consists of a program also followed by a line which contains only a single ' . ' (period). A program does not exceed 1000 lines. Any line does not exceed 80 characters excluding a new line character. Output For each program in the input, you should answer the line number of the assignment in which the first bug appears. The line numbers start with 1 for each program. If the program does not have a bug, you should answer zero. The output should not contain extra characters such as spaces. Sample Input a[3] a[0]=a[1] . x[1] x[0]=x[0] . a[0] a[0]=1 . b[2] b[0]=2 b[1]=b[b[0]] b[0]=b[1] . g[2] G[10] g[0]=0 g[1]=G[0] . a[2147483647] a[0]=1 B[2] B[a[0]]=2 a[B[a[0]]]=3 a[2147483646]=a[2] . . Output for the Sample Input 2 2 2 3 4 0 | 36,233 |
Problem G: Strange Couple Alice and Bob are going to drive from their home to a theater for a date. They are very challenging - they have no maps with them even though they donât know the route at all (since they have just moved to their new home). Yes, they will be going just by their feeling. The town they drive can be considered as an undirected graph with a number of intersections (vertices) and roads (edges). Each intersection may or may not have a sign. On intersections with signs, Alice and Bob will enter the road for the shortest route. When there is more than one such roads, they will go into one of them at random. On intersections without signs, they will just make a random choice. Each random selection is made with equal probabilities. They can even choose to go back to the road they have just come along, on a random selection. Calculate the expected distance Alice and Bob will drive before reaching the theater. Input The input consists of multiple datasets. Each dataset has the following format: n s t q 1 q 2 ... q n a 11 a 12 ... a 1 n a 21 a 22 ... a 2 n . . . a n 1 a n 2 ... a nn n is the number of intersections ( n †100). s and t are the intersections the home and the theater are located respectively (1 †s , t †n , s â t ); q i (for 1 †i †n ) is either 1 or 0, where 1 denotes there is a sign at the i -th intersection and 0 denotes there is not; a ij (for 1 †i , j †n ) is a positive integer denoting the distance of the road connecting the i -th and j -th intersections, or 0 indicating there is no road directly connecting the intersections. The distance of each road does not exceed 10. Since the graph is undirectional, it holds a ij = a ji for any 1 †i , j †n . There can be roads connecting the same intersection, that is, it does not always hold a ii = 0. Also, note that the graph is not always planar. The last dataset is followed by a line containing three zeros. This line is not a part of any dataset and should not be processed. Output For each dataset, print the expected distance accurate to 10 -8 , or " impossible " (without quotes) if there is no route to get to the theater. The distance may be printed with any number of digits after the decimal point. Sample Input 5 1 5 1 0 1 0 0 0 2 1 0 0 2 0 0 1 0 1 0 0 1 0 0 1 1 0 1 0 0 0 1 0 0 0 0 Output for the Sample Input 8.50000000 | 36,234 |
ã¯ãªã¹ãã¹ããŒãã£ãŒ (Christmas Party) åé¡ JOI åã¯åé 1 ããåé N ãŸã§ã® N 人ã®åéãæããŠã¯ãªã¹ãã¹ããŒãã£ãŒãè¡ã£ãïŒã¯ãªã¹ãã¹ããŒãã£ãŒãçãäžãã£ãŠãããšããã§ïŒåéãšäžç·ã«æ¬¡ã®ãããªã²ãŒã ãè¡ãããšã«ãªã£ãïŒ æåã« JOI å㯠N 人ã®åéã®äžãã 1 人ãéžã¶ïŒä»¥éã¯ãã®åéãã¿ãŒã²ãããšåŒã¶ããšã«ããïŒ JOI åã¯ïŒã¿ãŒã²ãããšããŠéžãã åéã«ïŒãã®äººãã¿ãŒã²ããã§ããããšããã£ããäŒããïŒã¿ãŒã²ãã以å€ã®åéã¯ïŒèª°ãã¿ãŒã²ããããç¥ãããšã¯ã§ããªãïŒ ã¿ãŒã²ãã以å€ã®åéã¯ããããïŒã¿ãŒã²ããã誰ããäºæ³ããŠïŒãã®äººã®ååãçŽã«èšå
¥ããïŒã¿ãŒã²ããã¯èªåèªèº«ã®ååãçŽã«èšå
¥ããïŒ ãã¹ãŠã®äººã®èšå
¥ãçµãã£ãåŸïŒJOI åã¯ã¿ãŒã²ããã®ååãçºè¡šããïŒ äºæ³ãåœãã£ã人㯠1 ç¹ãåŸãïŒãªãïŒã¿ãŒã²ããã¯èªåèªèº«ã®ååãçŽã«èšå
¥ããŠããã®ã§ïŒå¿
ã 1 ç¹ãåŸãïŒäºæ³ãå€ãã人ã«ã¯åŸç¹ã¯äžããããªãïŒ ããã«å ããŠïŒäºæ³ãå€ãã人ã®äººæ°ã X 人ãšãããšãïŒã¿ãŒã²ããã¯è¿œå ã§ X ç¹ãåŸãïŒ JOI åãã¡ã¯ãã®ã²ãŒã ã M åè¡ã£ãïŒããããã®åéã«å¯ŸããŠïŒM åã®ã²ãŒã ã«ãããåèšåŸç¹ãæ±ããïŒ å
¥å å
¥å㯠3 + M è¡ãããªãïŒ 1 è¡ç®ã«ã¯ïŒåéã®äººæ° N (3 †N †100) ãæžãããŠããïŒ 2 è¡ç®ã«ã¯ïŒJOI åãã¡ãè¡ã£ãã²ãŒã ã®åæ° M (3 †M †100) ãæžãããŠããïŒ 3 è¡ç®ã«ã¯ïŒM åã®æŽæ° A 1 , A 2 , ..., A M ã空çœãåºåããšããŠæžãããŠããïŒããã¯ïŒi åç® (1 ⊠i ⊠M) ã®ã²ãŒã ã®ã¿ãŒã²ãããåé A i (1 †A i †N) ã§ããããšã衚ãïŒ ç¶ã M è¡ã®ãã¡ã® i è¡ç® (1 ⊠i ⊠M) ã«ã¯ïŒN åã®æŽæ° B i,1 , B i,2 , ..., B i,N ã空çœãåºåããšããŠæžãããŠããïŒããã¯ïŒi åç®ã®ã²ãŒã ã«ãããŠåé j (1 †j †N) ãåé B i,j (1 †B i,j †N) ã®ååãçŽã«èšå
¥ããããšã衚ãïŒã¿ãŒã²ããã¯èªåèªèº«ã®ååãçŽã«èšå
¥ããã®ã§ïŒj = A i ã®ãšãïŒåžžã« B i,j = j ã§ããïŒ åºå ããããã®åéã«å¯ŸããŠïŒM åã®ã²ãŒã ã«ãããåèšåŸç¹ãåºåããïŒåºå㯠N è¡ãããªãïŒj è¡ç® (1 †j †N) ã«åé j ã®åèšåŸç¹ãåºåããïŒ å
¥åºåäŸ å
¥åäŸ 1 3 4 1 2 3 2 1 1 2 3 2 2 1 1 3 2 2 2 åºåäŸ 1 3 4 5 å
¥åäŸ 2 5 3 3 3 1 2 4 3 3 3 4 3 3 3 1 1 3 4 1 1 åºåäŸ 1 3 1 6 3 2 å
¥åºåäŸ 1 ã§ã¯ 3 人ã®åéã 4 åã®ã²ãŒã ãè¡ãïŒ 1 åç®ã®ã²ãŒã ã®ã¿ãŒã²ããã¯åé 1 ã§ããïŒåé 1 㯠2 ç¹ïŒåé 2 㯠1 ç¹ïŒåé 3 㯠0 ç¹ãåŸãïŒ 2 åç®ã®ã²ãŒã ã®ã¿ãŒã²ããã¯åé 2 ã§ããïŒåé 1 㯠0 ç¹ïŒåé 2 㯠2 ç¹ïŒåé 3 㯠1 ç¹ãåŸãïŒ 3 åç®ã®ã²ãŒã ã®ã¿ãŒã²ããã¯åé 3 ã§ããïŒåé 1 㯠0 ç¹ïŒåé 2 㯠0 ç¹ïŒåé 3 㯠3 ç¹ãåŸãïŒ 4 åç®ã®ã²ãŒã ã®ã¿ãŒã²ããã¯åé 2 ã§ããïŒåé 1 㯠1 ç¹ïŒåé 2 㯠1 ç¹ïŒåé 3 㯠1 ç¹ãåŸãïŒ 4 åã®ã²ãŒã çµäºåŸã®åèšåŸç¹ã¯ïŒåé 1 㯠3 ç¹ïŒåé 2 㯠4 ç¹ïŒåé 3 㯠5 ç¹ã§ããïŒ å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã | 36,235 |
ããã³ã°æ° 1 ã« 2, 3, 5 ãäœåã (0 å以äž) ããç®ããŠåŸãããæ°ãããã³ã°æ° (Hamming numbers) ãšåŒã³ãŸããäŸãã°ã 1 1 à 2 à 2 = 4 1 à 2 à 2 à 3 à 5 à 5 = 300 ãªã©ã¯ããã³ã°æ°ã§ããã11, 13, 14 ãªã©ã¯ããã³ã°æ°ã§ã¯ãããŸããã ããã³ã°æ°ã¯ã©ãã 60 ã®ã¹ãä¹ãå²ãåã(äŸãã°ã54 㯠60 3 = 21600 ãå²ãåã) ã®ã§ãæå»ãªã© 60 鲿³ã®èšç®ã«ã¯éœåã®è¯ãæ°ãšããŠæããç¥ãããŠããŸããããŸããæ¥œåšã®èª¿åŸã«çšããé³éã®äžã€ã§ããçŽæ£åŸã§ã¯ãé³ã®åšæ³¢æ°ã®æ¯ã 24, 27, 30, 32, 36, 40, 45, 48 ãšããããã³ã°æ°ãããªãæ°åã«ãªããŸãã æŽæ° m ã n ãå
¥åãšãã m ä»¥äž n 以äžã®ããã³ã°æ°ã®åæ°ãåºåããããã°ã©ã ãäœæããŠãã ããã Input è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸãã åããŒã¿ã»ãããšããŠãïŒã€ã®æŽæ° m ãš n (1 †m , n †1000000, m †n ) ã空çœåºåãã§ïŒè¡ã«äžããããŸãã ããŒã¿ã»ããã®æ°ã¯ 20 ãè¶
ããŸããã Output ããŒã¿ã»ããããšã« m ä»¥äž n 以äžã®ããã³ã°æ°ã®åæ°ãïŒè¡ã«åºåããŸãã Sample Input 3 8 1 27 1 86 0 Output for the Sample Input 5 17 31 | 36,236 |
JOI åœã®ãç¥ãäºæ
(Festivals in JOI Kingdom) JOI åœã«ã¯N åã®è¡ãããïŒãããã®é㯠M æ¬ã®åæ¹åã«éè¡å¯èœãªéè·¯ã§çµã°ããŠããïŒåœæ°ã¯éè·¯ãéã£ãŠãããã®è¡ãç§»åããïŒ JOI åœã®åœæ°ã«ã¯ïŒãç¥ãã奜ããªäººãå€ãïŒçŸåšïŒ K åã®è¡ã§ãç¥ããéå¬ãããŠããïŒéåžžã«è³ãã£ãŠããïŒäžæ¹ã§ïŒäžéšã®åœæ°ã¯ãç¥ããéšããããšããŠå«ãïŒãç¥ãã«ã§ããã ãè¿ã¥ããããªããšæã£ãŠããïŒ ããã§åœçã¯ïŒåªç§ãªããã°ã©ããŒã§ããããªãã«ïŒãã®ãããªãç¥ããå«ãåœæ°ã®ããïŒããè¡ããããè¡ã«ç§»åããããã«ïŒãç¥ããéå¬ãããŠããè¡ã«ã©ãã ãè¿ã¥ããã«ç§»åããããšãã§ããããé«éã«èª¿ã¹ãããšã®ã§ããããã°ã©ã ã®äœæãäŸé ŒããïŒ èª²é¡ éè·¯ã®æ
å ±ãšãç¥ããéå¬ãããŠããè¡ã®æ
å ±ïŒããã³ Q åã®ã¯ãšãªïŒåºçºããè¡ S i ãšè¡ãããè¡ T i ã®çµïŒãäžããããïŒåã¯ãšãª i ã«å¯ŸãïŒè¡ S i ããè¡ T i ãžã®ãã¹ãŠã®çµè·¯ã®ãã¡ïŒãç¥ããŸã§ã®è·é¢ãæå€§ãšãªãçµè·¯ã®ïŒãç¥ããŸã§ã®è·é¢ãæ±ããããã°ã©ã ãäœæããïŒãã ãïŒããçµè·¯ã®ãç¥ããŸã§ã®è·é¢ãšã¯ïŒçµè·¯äžã®è¡ãããç¥ããéå¬ãããŠããè¡ãŸã§ã®ç§»åè·é¢ã®æå°å€ã®ããšã§ããïŒ å¶é 2 †N †100000 (= 10 5 ) JOI åœã®è¡ã®åæ° 1 †M †200000 (= 2 à 10 5 ) JOI åœã®éè·¯ã®æ¬æ° 1 †K †N ãç¥ããéå¬ãããŠããè¡ã®åæ° 1 †Q †100000 (= 10 5 ) ã¯ãšãªã®åæ° 1 †L i †1000 i çªç®ã®éè·¯ã®é·ã å
¥å æšæºå
¥åãã以äžã®ããŒã¿ãèªã¿èŸŒãïŒ 1 è¡ç®ã«ã¯æŽæ° N , M , K , Q ã空çœãåºåããšããŠæžãããŠããïŒ N ã¯JOI åœã®è¡ã®åæ°ãïŒ M ã¯JOIåœã®éè·¯ã®æ¬æ°ãïŒ K ã¯ãç¥ããéå¬ãããŠããè¡ã®åæ°ãïŒ Q ã¯ã¯ãšãªã®åæ°ããããã衚ãïŒè¡ã«ã¯1, 2, ... , N ã®çªå·ãã€ããããŠããïŒ ç¶ã M è¡ã¯éè·¯ã®æ
å ±ã衚ãïŒ i + 1 è¡ç®(1 †i †M ) ã«ã¯æŽæ° A i , B i , L i (1 †A i †N , 1 †B i †N ) ã空çœãåºåããšããŠæžãããŠããïŒããã¯ïŒ i çªç®ã®éè·¯ãè¡ A i ãšè¡ B i ãçµãã§ããïŒé·ãã L i ã§ããããšã衚ãïŒéè·¯ã®äž¡ç«¯ãåãè¡ã§ããããšã¯ãªãïŒãŸãïŒä»»æã®2 ã€ã®è¡ p , q ã«å¯ŸãïŒ p ãš q ãçµã¶éè·¯ã¯2 æ¬ä»¥äžååšããªãïŒã©ã®è¡ããã©ã®è¡ãžãããã€ãã®éè·¯ããã©ã£ãŠè¡ãããšãã§ããïŒ ç¶ã K è¡ã¯ãç¥ããéå¬ãããŠããè¡ã®æ
å ±ã衚ãïŒ i + M + 1 è¡ç®(1 †i †K ) ã«ã¯1 ã€ã®æŽæ° F i (1 †F i †N ) ãæžãããŠããïŒããã¯è¡ F i ã§ãç¥ããéå¬ãããŠããããšã衚ãïŒ F 1 , ..., F K ã®äžã«åãå€ã2 å以äžçŸããããšã¯ãªãïŒ ç¶ã Q è¡ã¯ã¯ãšãªã衚ãïŒ i + M + K + 1 è¡ç®(1 †i †Q ) ã«ã¯2 ã€ã®æŽæ° S i , T i (1 †S i †N , 1 †T i †N , S i â T i ) ã空çœãåºåããšããŠæžãããŠããïŒãã㯠i çªç®ã®ã¯ãšãªã®åºçºããè¡ã S i ã§ããè¡ãããè¡ã T i ã§ããããšã衚ãïŒ åºå æšæºåºåã«ïŒå
šã¯ãšãªãžã®çãã Q è¡ã§åºåããïŒããªãã¡ïŒ i è¡ç®ã«ïŒè¡ S i ããè¡ T i ãžã®ãã¹ãŠã®çµè·¯ã®ãã¡ïŒãç¥ããŸã§ã®è·é¢ãæå€§ãšãªãçµè·¯ã®ïŒãç¥ããŸã§ã®è·é¢ãè¡šãæŽæ°ãåºåããïŒ æ¡ç¹åºæº æ¡ç¹çšããŒã¿ã®ãã¡ïŒ é
ç¹ã®10% åã«ã€ããŠã¯ïŒ Q = 1 ãæºããïŒ é
ç¹ã®20% åã«ã€ããŠã¯ïŒ N †5000, Q †5000 ãæºããïŒ é
ç¹ã®30% åã«ã€ããŠã¯ïŒããã2 ã€ã®æ¡ä»¶ã®å°ãªããšãäžæ¹ãæºããïŒãŸãïŒããã2 ã€ã®æ¡ä»¶ã®äž¡æ¹ãæºãããããªæ¡ç¹çšããŒã¿ã¯ãªãïŒ å
¥åºåäŸ å
¥åäŸ 1 6 6 2 3 1 2 5 2 3 4 2 4 6 3 5 9 4 5 3 5 6 7 1 6 3 4 5 2 1 4 åºåäŸ 1 7 5 0 6 ã€ã®è¡ã6 æ¬ã®éè·¯ã§çµã°ããŠããïŒãç¥ãã¯è¡1, 6 ã®2 ã€ã®è¡ã§éå¬ãããŠããïŒã¯ãšãªã¯ä»¥äžã®3 ã€ã§ããïŒ 1 ã€ç®ã®ã¯ãšãªã¯è¡3 ããè¡4 ãžè¡ããšãããã®ã§ããïŒè¡2 ãçµç±ããçµè·¯ã§ã¯ãç¥ããŸã§ã®è·é¢ã¯5ïŒè¡5 ãçµç±ããçµè·¯ã§ã¯ãç¥ããŸã§ã®è·é¢ã¯7 ãšãªãããïŒçãã¯7 ã§ããïŒ 2 ã€ç®ã®ã¯ãšãªã¯è¡5 ããè¡2 ãžè¡ããšãããã®ã§ããïŒè¡3 ãšè¡4 ã®ã©ã¡ããçµç±ããŠãïŒè¡2 ã§ãç¥ããŸã§ã®è·é¢ãæå°ãšãªãïŒçãã¯5 ã§ããïŒ 3 ã€ç®ã®ã¯ãšãªã¯è¡1 ããè¡4 ãžè¡ããšãããã®ã§ããïŒè¡1 ã¯ãç¥ããéå¬ãããŠããè¡ã§ããããïŒçãã¯0 ãšãªãïŒ å³1: å
¥åäŸ1 å
¥åäŸ 2 12 17 2 5 1 3 6 1 6 7 2 3 8 2 4 4 2 8 11 2 12 2 3 6 3 3 7 8 3 11 2 4 12 2 5 10 3 6 10 5 8 9 6 8 12 7 9 10 6 11 9 10 12 9 5 8 7 2 6 5 2 1 10 8 9 9 4 åºåäŸ 2 8 8 11 0 6 å³1: å
¥åäŸ2 å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã | 36,237 |
Score : 1400 points Problem Statement Consider the following set of rules for encoding strings consisting of 0 and 1 : Strings 0 and 1 can be encoded as 0 and 1 , respectively. If strings A and B can be encoded as P and Q , respectively, then string AB can be encoded as PQ . If string A can be encoded as P and K \geq 2 is a positive integer, then string AA...A ( A repeated K times) can be encoded as ( P x K ) . For example, string 001001001 , among other possibilities, can be encoded as 001001001 , 00(1(0x2)x2)1 and (001x3) . Let's call string A a subset of string B if: A and B are equal in length and consist of 0 and 1 ; for all indices i such that A_i = 1 , it's also true that B_i = 1 . You are given string S consisting of 0 and 1 . Find the total number of distinct encodings of all subsets of S , modulo 998244353 . Constraints 1 \leq |S| \leq 100 S consists of 0 and 1 . Input Input is given from Standard Input in the following format: S Output Print the total number of distinct encodings of all subsets of S modulo 998244353 . Sample Input 1 011 Sample Output 1 9 There are four subsets of S : 011 can be encoded as 011 and 0(1x2) ; 010 can be encoded as 010 ; 001 can be encoded as 001 and (0x2)1 ; 000 can be encoded as 000 , 0(0x2) , (0x2)0 and (0x3) . Thus, the total number of encodings of all subsets of S is 2 + 1 + 2 + 4 = 9 . Sample Input 2 0000 Sample Output 2 10 This time S has only one subset, but it can be encoded in 10 different ways. Sample Input 3 101110 Sample Output 3 156 Sample Input 4 001110111010110001100000100111 Sample Output 4 363383189 Don't forget to take the result modulo 998244353 . | 36,238 |
Score : 300 points Problem Statement We have N ID cards, and there are M gates. We can pass the i -th gate if we have one of the following ID cards: the L_i -th, (L_i+1) -th, ..., and R_i -th ID cards. How many of the ID cards allow us to pass all the gates alone? Constraints All values in input are integers. 1 \leq N \leq 10^5 1 \leq M \leq 10^5 1 \leq L_i \leq R_i \leq N Input Input is given from Standard Input in the following format: N M L_1 R_1 L_2 R_2 \vdots L_M R_M Output Print the number of ID cards that allow us to pass all the gates alone. Sample Input 1 4 2 1 3 2 4 Sample Output 1 2 Two ID cards allow us to pass all the gates alone, as follows: The first ID card does not allow us to pass the second gate. The second ID card allows us to pass all the gates. The third ID card allows us to pass all the gates. The fourth ID card does not allow us to pass the first gate. Sample Input 2 10 3 3 6 5 7 6 9 Sample Output 2 1 Sample Input 3 100000 1 1 100000 Sample Output 3 100000 | 36,239 |
Partition Quick sort is based on the Divide-and-conquer approach. In QuickSort(A, p, r), first, a procedure Partition(A, p, r) divides an array A[p..r] into two subarrays A[p..q-1] and A[q+1..r] such that each element of A[p..q-1] is less than or equal to A[q], which is, inturn, less than or equal to each element of A[q+1..r]. It also computes the index q. In the conquer processes, the two subarrays A[p..q-1] and A[q+1..r] are sorted by recursive calls of QuickSort(A, p, q-1) and QuickSort(A, q+1, r). Your task is to read a sequence A and perform the Partition based on the following pseudocode: Partition(A, p, r) 1 x = A[r] 2 i = p-1 3 for j = p to r-1 4 do if A[j] <= x 5 then i = i+1 6 exchange A[i] and A[j] 7 exchange A[i+1] and A[r] 8 return i+1 Note that, in this algorithm, Partition always selects an element A[r] as a pivot element around which to partition the array A[p..r]. Input The first line of the input includes an integer n , the number of elements in the sequence A. In the second line, A i ( i = 1,2,..., n ), elements of the sequence are given separated by space characters. Output Print the sorted sequence. Two contiguous elements of the sequence should be separated by a space character. The element which is selected as the pivot of the partition should be indicated by [ ] . Constraints 1 †n †100,000 0 †A i †100,000 Sample Input 1 12 13 19 9 5 12 8 7 4 21 2 6 11 Sample Output 1 9 5 8 7 4 2 6 [11] 21 13 19 12 | 36,240 |
E: åæ¥åŒ èæ¯ ããæ¥ Y ããã¯ããã°ã©ãã³ã°ã³ã³ãã¹ãã«åå ããããïŒäŒå Žããã倧åŠã«åãããŸããïŒ ãšããã倧åŠã«çããšäººãããããïŒãªããšä»æ¥ã¯åæ¥åŒã ã£ãã®ã§ãïŒ äŒå Žã«åãããã«ãäººã«æŒãæµãããŠããŸãïŒèªåã®é²ã¿ããæ¹åã«é²ãããšããã§ããŸããïŒ äººæ··ã¿ããæãåºãããã«ïŒY ããã¯ä»ããå Žæããå°ãã§ãé ãã«è¡ããããšèããŸããïŒ ããã§ Y ããã¯ç¶æ³ã以äžã®ãããªåé¡ãšããŠå®åŒåãïŒç«¶æããã°ã©ãã³ã°ã圹ã«ç«ãŠãããšã«ããŸããïŒ ãªãïŒä»¥äžã®å顿ã§ã¯ Y ããã¯ç¹ $P$ ãšããŠã¢ãã«åãããŠããŸãïŒ åé¡ åº§æšå¹³é¢äžã®åç¹ã«ç¹ $P$ ã眮ãããŠããïŒ ç¹ $P$ ãåããïŒã§ããã ãåç¹ããã®ãã³ããã¿ã³è·é¢ãé ãäœçœ®ã«ç§»åããããïŒ ã¯ããã«ïŒæåå $S = s_1s_2 \cdots s_{|S|}$ ($|S|$ 㯠$S$ ã®æåæ°) ãäžããããïŒ ç¹ $P$ ã®ç§»åã¯ïŒæåå $S$ ã®å
é ããæåã 1 æåãã€èªã¿èŸŒãããšã§è¡ãïŒ æåå $S$ ã¯æå 'U', 'L', 'D', 'R' ãããªãïŒ ããããã®æåãèªã¿èŸŒãã ãšãïŒç¹ $P$ ã®ç§»ååã®åº§æšã $(x, y)$ ãšãããšïŒ ç§»ååŸã®ç¹ $P$ ã®åº§æšã¯ãããã $(x, y+1),\ (x-1, y),\ (x, y-1),\ (x+1, y)$ ãšãªãïŒ åæåãèªã¿èŸŒãçŽåã«ïŒéæ³ãããããåŠããéžæããããšãã§ããïŒ éæ³ã«ã¯éæ³ 1 ãšéæ³ 2 ã®äºçš®é¡ãããïŒæåå $S$ ã® $i$ çªç®ã®æåã $s_i$ ãšãããšïŒ $s_i$ ãèªã¿èŸŒãçŽåã«éæ³ãããããšãã®å€åã¯ä»¥äžã®éãã§ããïŒ éæ³ 1 ãããããšã: å
šãŠã® $s_j \ (i \le j \le |S|)$ ã«å¯ŸãïŒ'U' ã 'D' ã«ïŒ'D' ã 'U' ã«çœ®æããïŒ éæ³ 2 ãããããšã: å
šãŠã® $s_j \ (i \le j \le |S|)$ ã«å¯ŸãïŒ'L' ã 'R' ã«ïŒ'R' ã 'L' ã«çœ®æããïŒ çŽæçã«ã¯ïŒéæ³ 1 ã§ã¯ãã®åŸã®äžäžã®æ±ããå転ãããããšãã§ãïŒéæ³ 2 ã§ã¯å·Šå³ã®æ±ããå転ãããããšãã§ããïŒ ããæåãèªã¿èŸŒãåã«ãããéæ³ã®åæ°ã¯è€æ°åã§ãæ§ããªãïŒãŸãïŒäž¡æ¹ã®éæ³ãç¶ããŠãããŠãããŸããªãïŒ ãã ãïŒæåå $S$ ã®æåããã¹ãŠèªã¿çµãããŸã§ã«éæ³ããããããåæ°ã¯ïŒåèš $K$ åãŸã§ã§ããïŒ è©³çŽ°ã¯ãµã³ãã«ãåç
§ããããïŒ æåå $S$ ã®æåããã¹ãŠèªã¿çµããåŸã®ç¹ $P$ ã®åº§æšã $(x',y')$ ãšãããšãïŒ$|x'| + |y'|$ ã®æå€§å€ãæ±ããïŒ å¶çŽ $1 \le |S| \le 2000$ $1 \le K \le 2000$ å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããïŒ $S$ $K$ åºå $|x'| + |y'|$ ã®æå€§å€ã 1 è¡ã§åºåããïŒãŸããæ«å°Ÿã«æ¹è¡ãåºåãã. ãµã³ãã« ãµã³ãã«å
¥å 1 RRLUDDD 2 ãµã³ãã«åºå 1 7 3 æåç®ãèªã¿èŸŒãçŽåã«éæ³ 2 ãããããšïŒæåå $S$ 㯠"RRRUDDD" ãšãªãïŒ ç¶ã㊠5 æåç®ãèªã¿èŸŒãçŽåã«éæ³ 1 ãããããšïŒæåå $S$ 㯠"RRRUUUU" ãšãªãïŒ ãã¹ãŠã®æåãèªã¿çµããåŸã®ç¹ $P$ ã®åº§æšã¯ $(3, 4)$ ãšãªãïŒ åç¹ããã®ãã³ããã¿ã³è·é¢ã¯ 7 ã§ããïŒããã¯ãã®äŸã®æå€§å€ã§ããïŒ ãµã³ãã«å
¥å 2 LULLLUULLU 1984 ãµã³ãã«åºå 2 10 1 åãéæ³ããããªãã£ãå ŽåïŒ$xâ = -6, \ yâ = 4$ ãšãªãïŒ$|xâ| + |yâ| = 10$ ã§ããïŒ ãµã³ãã«å
¥å 3 DRDLUDD 1 ãµã³ãã«åºå 3 5 ãµã³ãã«å
¥å 4 LURRRLUDLL 1 ãµã³ãã«åºå 4 6 | 36,241 |
Max Score: $1200$ Points Problem statement There are $N$ customers in a restaurant. Each customer is numbered $1$ through $N$. A sushi chef carried out $Q$ operations for customers. The $i$-th operation is follows: The sushi chef chooses a customer whose number of dishes of sushi eaten is minimum, in customer $1, 2, 3, \dots, a_i$. If there are multiple customers who are minimum numbers of dishes, he selects the minimum-numbered customers. He puts a dish of sushi on the selected seats. A customer who have selected for professional eats this sushi. Repeat 1-3, $b_i$ times. Please calculate the number of dishes of sushi that have been eaten by each customer. Input The input is given from Standard Input in the following format: $N \ Q$ $a_1 \ b_1$ $a_2 \ b_2$ $ ïŒ \ ïŒ $ $a_Q \ b_Q$ Output You have to print $N$ lines. The $i$-th line should contain the number of dishes of sushi had eaten for customer $i (1 \le i \le N)$. Constraints $3 \le N, Q \le 100,000$ $1 \le a_i \le N$ $1 \le b_i \le 10^{12}$ Any final results do not exceed $2 \times 10^{13}$. Subtasks Subtask 1 [ $60$ points ] $N, Q \le 100$ $b_i = 1$ Subtask 2 [ $400$ points ] $N, Q \le 100$ $b_i \le 10^{12}$ Subtask 3 [ $240$ points ] $N, Q \le 100,000$ $b_i = 1$ Subtask 4 [ $500$ points ] There are no additional constraints. Sample Input 1 9 3 5 11 8 4 4 7 Sample Output 1 4 4 4 4 2 2 1 1 0 The change of the number of dishes of sushi have eaten is following: Customer 1 Customer 2 Customer 3 Customer 4 Customer 5 Customer 6 Customer 7 Customer 8 Customer 9 1st Operation 3 2 2 2 2 0 0 0 0 2nd Operation 3 2 2 2 2 2 1 1 0 3rd Operation 4 4 4 4 2 2 1 1 0 Sample Input 2 6 6 3 5 6 11 1 6 4 7 5 2 2 5 Sample Output 2 10 10 5 5 4 2 Sample Input 3 5 6 1 1 2 1 3 1 1 1 5 1 3 1 Sample Output 3 2 2 1 1 0 Sample Input 4 10 10 10 10 9 20 8 30 7 40 6 50 5 60 4 70 3 80 2 90 1 100 Sample Output 4 223 123 77 50 33 21 12 7 3 1 Writer: E869120 | 36,242 |
Score : 600 points Problem Statement There are N piles of stones. The i -th pile has A_i stones. Aoki and Takahashi are about to use them to play the following game: Starting with Aoki, the two players alternately do the following operation: Operation: Choose one pile of stones, and remove one or more stones from it. When a player is unable to do the operation, he loses, and the other player wins. When the two players play optimally, there are two possibilities in this game: the player who moves first always wins, or the player who moves second always wins, only depending on the initial number of stones in each pile. In such a situation, Takahashi, the second player to act, is trying to guarantee his win by moving at least zero and at most (A_1 - 1) stones from the 1 -st pile to the 2 -nd pile before the game begins. If this is possible, print the minimum number of stones to move to guarantee his victory; otherwise, print -1 instead. Constraints 2 \leq N \leq 300 1 \leq A_i \leq 10^{12} Input Input is given from Standard Input in the following format: N A_1 \ldots A_N Output Print the minimum number of stones to move to guarantee Takahashi's win; otherwise, print -1 instead. Sample Input 1 2 5 3 Sample Output 1 1 Without moving stones, if Aoki first removes 2 stones from the 1 -st pile, Takahashi cannot win in any way. If Takahashi moves 1 stone from the 1 -st pile to the 2 -nd before the game begins so that both piles have 4 stones, Takahashi can always win by properly choosing his actions. Sample Input 2 2 3 5 Sample Output 2 -1 It is not allowed to move stones from the 2 -nd pile to the 1 -st. Sample Input 3 3 1 1 2 Sample Output 3 -1 It is not allowed to move all stones from the 1 -st pile. Sample Input 4 8 10 9 8 7 6 5 4 3 Sample Output 4 3 Sample Input 5 3 4294967297 8589934593 12884901890 Sample Output 5 1 Watch out for overflows. | 36,243 |
Balls and Boxes 3 Balls Boxes Any way At most one ball At least one ball Distinguishable Distinguishable 1 2 3 Indistinguishable Distinguishable 4 5 6 Distinguishable Indistinguishable 7 8 9 Indistinguishable Indistinguishable 10 11 12 Problem You have $n$ balls and $k$ boxes. You want to put these balls into the boxes. Find the number of ways to put the balls under the following conditions: Each ball is distinguished from the other. Each box is distinguished from the other. Each ball can go into only one box and no one remains outside of the boxes. Each box must contain at least one ball. Note that you must print this count modulo $10^9+7$. Input $n$ $k$ The first line will contain two integers $n$ and $k$. Output Print the number of ways modulo $10^9+7$ in a line. Constraints $1 \le n \le 1000$ $1 \le k \le 1000$ Sample Input 1 4 3 Sample Output 1 36 Sample Input 2 10 3 Sample Output 2 55980 Sample Input 3 100 100 Sample Output 3 437918130 | 36,244 |
Polygon-Point-Containment For a given polygon g and target points t , print "2" if g contains t , "1" if t is on a segment of g , "0" otherwise. g is represented by a sequence of points p 1 , p 2 ,..., p n where line segments connecting p i and p i+1 (1 †i †n-1 ) are sides of the polygon. The line segment connecting p n and p 1 is also a side of the polygon. Note that the polygon is not necessarily convex. Input The entire input looks like: g (the sequence of the points of the polygon) q (the number of queris = the number of target points) 1st query 2nd query : q th query g is given by coordinates of the points p 1 ,..., p n in the following format: n x 1 y 1 x 2 y 2 : x n y n The first integer n is the number of points. The coordinate of a point p i is given by two integers x i and y i . The coordinates of points are given in the order of counter-clockwise visit of them. Each query consists of the coordinate of a target point t . The coordinate is given by two intgers x and y . Output For each query, print "2", "1" or "0". Constraints 3 †n †100 1 †q †1000 -10000 †x i , y i †10000 No point of the polygon will occur more than once. Two sides of the polygon can intersect only at a common endpoint. Sample Input 4 0 0 3 1 2 3 0 3 3 2 1 0 2 3 2 Sample Output 2 1 0 | 36,245 |
Score : 1000 points Problem Statement There are two (6-sided) dice: a red die and a blue die. When a red die is rolled, it shows i with probability p_i percents, and when a blue die is rolled, it shows j with probability q_j percents. Petr and tourist are playing the following game. Both players know the probabilistic distributions of the two dice. First, Petr chooses a die in his will (without showing it to tourist), rolls it, and tells tourist the number it shows. Then, tourist guesses the color of the chosen die. If he guesses the color correctly, tourist wins. Otherwise Petr wins. If both players play optimally, what is the probability that tourist wins the game? Constraints 0 †p_i, q_i †100 p_1 + ... + p_6 = q_1 + ... + q_6 = 100 All values in the input are integers. Input The input is given from Standard Input in the following format: p_1 p_2 p_3 p_4 p_5 p_6 q_1 q_2 q_3 q_4 q_5 q_6 Output Print the probability that tourist wins. The absolute error or the relative error must be at most 10^{-9} . Sample Input 1 25 25 25 25 0 0 0 0 0 0 50 50 Sample Output 1 1.000000000000 tourist can always win the game: If the number is at most 4 , the color is definitely red. Otherwise the color is definitely blue. Sample Input 2 10 20 20 10 20 20 20 20 20 10 10 20 Sample Output 2 0.550000000000 | 36,246 |
Score : 500 points Problem Statement You are given a string S of length N consisting of lowercase English letters. Process Q queries of the following two types: Type 1 : change the i_q -th character of S to c_q . (Do nothing if the i_q -th character is already c_q .) Type 2 : answer the number of different characters occurring in the substring of S between the l_q -th and r_q -th characters (inclusive). Constraints N , Q , i_q , l_q , and r_q are integers. S is a string consisting of lowercase English letters. c_q is a lowercase English letter. 1 \leq N \leq 500000 1 \leq Q \leq 20000 |S| = N 1 \leq i_q \leq N 1 \leq l_q \leq r_q \leq N There is at least one query of type 2 in each testcase. Input Input is given from Standard Input in the following format: N S Q Query_1 \vdots Query_Q Here, Query_i in the 4 -th through (Q+3) -th lines is one of the following: 1 i_q c_q 2 l_q r_q Output For each query of type 2 , print a line containing the answer. Sample Input 1 7 abcdbbd 6 2 3 6 1 5 z 2 1 1 1 4 a 1 7 d 2 1 7 Sample Output 1 3 1 5 In the first query, cdbb contains three kinds of letters: b , c , and d , so we print 3 . In the second query, S is modified to abcdzbd . In the third query, a contains one kind of letter: a , so we print 1 . In the fourth query, S is modified to abcazbd . In the fifth query, S does not change and is still abcazbd . In the sixth query, abcazbd contains five kinds of letters: a , b , c , d , and z , so we print 5 . | 36,247 |
Score : 1500 points Problem Statement We have a sequence A of length N . On this sequence, we can perform the following two kinds of operations: Swap two adjacent elements. Select one element, and increment it by 1 . We will repeatedly perform these operations so that A will be a non-decreasing sequence. Find the minimum required number of operations. Constraints 1 †N †200000 1 †A_i †10^9 A_i is an integer. Input Input is given from Standard Input in the following format: N A_1 A_2 : A_N Output Print the minimum number of operations required to turn A into a non-decreasing sequence. Sample Input 1 5 4 1 8 8 7 Sample Output 1 2 We can turn A into a non-decreasing sequence in two operations: Initially, A = \{4, 1, 8, 8, 7\} . Swap the first two elements. Now, A = \{1, 4, 8, 8, 7\} . Increment the last element by 1 . Now, A = \{1, 4, 8, 8, 8\} . Sample Input 2 20 8 2 9 7 4 6 7 9 7 4 7 4 4 3 6 2 3 4 4 9 Sample Output 2 62 | 36,248 |
Score : 500 points Problem Statement A robot is put at the origin in a two-dimensional plane. Initially, the robot is facing in the positive x -axis direction. This robot will be given an instruction sequence s . s consists of the following two kinds of letters, and will be executed in order from front to back. F : Move in the current direction by distance 1 . T : Turn 90 degrees, either clockwise or counterclockwise. The objective of the robot is to be at coordinates (x, y) after all the instructions are executed. Determine whether this objective is achievable. Constraints s consists of F and T . 1 \leq |s| \leq 8 000 x and y are integers. |x|, |y| \leq |s| Input Input is given from Standard Input in the following format: s x y Output If the objective is achievable, print Yes ; if it is not, print No . Sample Input 1 FTFFTFFF 4 2 Sample Output 1 Yes The objective can be achieved by, for example, turning counterclockwise in the first T and turning clockwise in the second T . Sample Input 2 FTFFTFFF -2 -2 Sample Output 2 Yes The objective can be achieved by, for example, turning clockwise in the first T and turning clockwise in the second T . Sample Input 3 FF 1 0 Sample Output 3 No Sample Input 4 TF 1 0 Sample Output 4 No Sample Input 5 FFTTFF 0 0 Sample Output 5 Yes The objective can be achieved by, for example, turning counterclockwise in the first T and turning counterclockwise in the second T . Sample Input 6 TTTT 1 0 Sample Output 6 No | 36,249 |
Score : 100 points Problem Statement There are N children, numbered 1, 2, \ldots, N . They have decided to share K candies among themselves. Here, for each i ( 1 \leq i \leq N ), Child i must receive between 0 and a_i candies (inclusive). Also, no candies should be left over. Find the number of ways for them to share candies, modulo 10^9 + 7 . Here, two ways are said to be different when there exists a child who receives a different number of candies. Constraints All values in input are integers. 1 \leq N \leq 100 0 \leq K \leq 10^5 0 \leq a_i \leq K Input Input is given from Standard Input in the following format: N K a_1 a_2 \ldots a_N Output Print the number of ways for the children to share candies, modulo 10^9 + 7 . Sample Input 1 3 4 1 2 3 Sample Output 1 5 There are five ways for the children to share candies, as follows: (0, 1, 3) (0, 2, 2) (1, 0, 3) (1, 1, 2) (1, 2, 1) Here, in each sequence, the i -th element represents the number of candies that Child i receives. Sample Input 2 1 10 9 Sample Output 2 0 There may be no ways for the children to share candies. Sample Input 3 2 0 0 0 Sample Output 3 1 There is one way for the children to share candies, as follows: (0, 0) Sample Input 4 4 100000 100000 100000 100000 100000 Sample Output 4 665683269 Be sure to print the answer modulo 10^9 + 7 . | 36,250 |
Problem H. Enlarge Circles You are given $N$ distinct points on the 2-D plane. For each point, you are going to make a single circle whose center is located at the point. Your task is to maximize the sum of perimeters of these $N$ circles so that circles do not overlap each other. Here, "overlap" means that two circles have a common point which is not on the circumference of at least either of them. Therefore, the circumferences can be touched. Note that you are allowed to make a circle with radius $0$. Input The input consists of a single test case in the following format. $N$ $x_1$ $y_1$ $\vdots$ $x_N$ $y_N$ The first line contains an integer $N$, which is the number of points ($2 \leq N \leq 200$). Each of the following $N$ lines gives the coordinates of a point. Integers $x_i$ and $y_i$ ($-100 \leq x_i, y_i \leq 100$) in the $i$-th line of them give the $x$- and $y$-coordinates, respectively, of the $i$-th point. These points are distinct, in other words, $(x_i,y_i) \ne (x_j, y_j)$ is satisfied if $i$ and $j$ are different. Output Output the maximized sum of perimeters. The output can contain an absolute or a relative error no more than $10^{-6}$. Examples Sample Input 1 3 0 0 3 0 5 0 Output for Sample Input 1 31.415926535 Sample Input 2 3 0 0 5 0 0 5 Output for Sample Input 2 53.630341225 Sample Input 3 9 91 -18 13 93 73 -34 15 2 -46 0 69 -42 -23 -13 -87 41 38 68 Output for Sample Input 3 1049.191683488 | 36,251 |
äŒæŽ¥å°é¶ 2008 幎 4 æã«ãäŒæŽ¥è¥æŸåžã¯é·ã20 m 85 cm ã®ãããšãäœãã«ææŠããŠæåããŸããããã®ãšã䜿ãããé¶èããäŒæŽ¥ç¹ç£ã®äŒæŽ¥å°é¶ã§ããäŒæŽ¥å°é¶ã¯ãšãŠãããããã®ã§ããã飌è²ããããããã®ã§çç£éãå°ãªãã倿®µãé«ãã®ãé£ç¹ã§ãã 仿¥ã¯äžéåã®å®¶ã«ãé ããã芪æãéã³ã«æ¥ãŸãããæ¯ããã¯é¶èã®æ°Žçããäœã£ãŠèŠªæãããŠãªãããšã«ããŸãããè¿ãã®ãèå±ããã§ã¯äŒæŽ¥å°é¶ãšãµã€ãã®é¶èã® 2 çš®é¡ã®é¶èã売ã£ãŠããŸãããæ¯ããã¯ã以äžã®ãããªæç€ºãäžéåã«äžããŠããèå±ããã«è¡ã£ãŠé¶èãè²·ã£ãŠããããã« é Œã¿ãŸããã é¶èãè¶³ããªããªããšå°ãã®ã§ã決ããããé以äžã®é¶èãè²·ãã äºç®ã®èš±ãç¯å²ã§äŒæŽ¥å°é¶ãã§ããã ãå€ãè²·ã(äŒæŽ¥å°é¶ã¯å¿
ãè²·ãããš)ã äŒæŽ¥å°é¶ãè²·ã£ãæ®ãã§ãµã€ãã®é¶èãã§ããã ãå€ãè²·ã(äºç®ãè¶³ããªããã°è²·ããªã)ã äžéåããèå±ããã«è¡ããšãäŒæŽ¥å°é¶ãåèã®ããäžäººãè²·ããéãå¶éããŠããŸãããäžéåãããæ¯ããããäžãããããã¹ãŠã®æç€ºãå®ã£ãŠè²·ãç©ããããšããäžéåãè²·ãäŒæŽ¥å°é¶ãšæ®éã®é¶èã®éã¯ããããäœã°ã©ã ã«ãªãã§ããã? è²·ãã¹ãé¶èã®éã®äžé q 1 ãäºç® b ããã®ãèå±ããã§ã®äŒæŽ¥å°é¶ 100 ã°ã©ã ã®å€æ®µ c 1 ããµã€ãã®é¶è 100 ã°ã©ã ã®å€æ®µ c 2 ãäŒæŽ¥å°é¶ãäžäººãè²·ããéã®äžé q 2 ãå
¥åãšããäžéåãè²·ãäŒæŽ¥å°é¶ãšãµã€ãã®é¶èã®éã 100 ã°ã©ã åäœã§åºåããããã°ã©ã ãäœæããŠãã ããããã ãããã®ãèå±ããã§ã¯ãæ¯ããã®æç€ºéãã«è²·ããªãå Žåã«ã¯ããNAããšåºåããŠãã ããã Input è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸãã åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã q 1 b c 1 c 2 q 2 é¶èã®éã衚ãããŒã¿ q 1 ãš q 2 ã¯100 ã°ã©ã åäœã§æå®ãããŸãããŸãã b ã c 1 ã c 2 ã q 1 ã q 2 㯠1 ä»¥äž 1,000,000 以äžã®æŽæ°ãšããŸãã ããŒã¿ã»ããã®æ°ã¯ 50 ãè¶
ããŸããã Output ããŒã¿ã»ããæ¯ã«ãäžéåã賌å
¥ããäŒæŽ¥å°é¶ã®éãšãµã€ãã®é¶èã®é(åè§ç©ºçœåºåã) ãŸãã¯ãNAããïŒè¡ã«åºåããŸãã Sample Input 48 9297 240 126 32 20 3010 157 141 7 30 117002 5680 962 15 8 1673 1712 190 22 64 8478 87 54 307 23 5477 117 92 12 50 7558 1396 187 17 279 88677 4522 514 14 0 Output for the Sample Input 28 20 7 13 15 33 NA 97 0 12 44 NA NA | 36,252 |
Count For a given sequence of integers $A = \{a_0, a_1, ..., a_{n-1}\}$, perform the following operations. count($b, e, k$): print the number of the specific values $k$ in $a_b, a_{b+1}, ..., a_{e-1}$. Input The input is given in the following format. $n$ $a_0 \; a_1, ..., \; a_{n-1}$ $q$ $b_1 \; e_1 \; k_1$ $b_2 \; e_2 \; k_2$ : $b_q \; e_q \; k_q$ The number of elements $n$ and each element $a_i$ are given in the first line and the second line respectively. In the third line, the number of queries $q$ is given and the following $q$ lines, $q$ integers $b_i \; b_e \; k_i$ are given as queries. Output For each query, print the number of specified values. Constraints $1 \leq n \leq 1,000$ $-1,000,000,000 \leq a_i, k_i \leq 1,000,000,000$ $1 \leq q \leq 1,000$ $0 \leq b < e \leq n$ Sample Input 1 9 1 4 1 4 2 1 3 5 6 3 0 9 1 1 6 1 3 7 5 Sample Output 1 3 2 0 | 36,253 |
Score : 500 points Problem Statement In Takahashi Kingdom, which once existed, there are N cities, and some pairs of cities are connected bidirectionally by roads. The following are known about the road network: People traveled between cities only through roads. It was possible to reach any city from any other city, via intermediate cities if necessary. Different roads may have had different lengths, but all the lengths were positive integers. Snuke the archeologist found a table with N rows and N columns, A , in the ruin of Takahashi Kingdom. He thought that it represented the shortest distances between the cities along the roads in the kingdom. Determine whether there exists a road network such that for each u and v , the integer A_{u, v} at the u -th row and v -th column of A is equal to the length of the shortest path from City u to City v . If such a network exist, find the shortest possible total length of the roads. Constraints 1 \leq N \leq 300 If i â j , 1 \leq A_{i, j} = A_{j, i} \leq 10^9 . A_{i, i} = 0 Inputs Input is given from Standard Input in the following format: N A_{1, 1} A_{1, 2} ... A_{1, N} A_{2, 1} A_{2, 2} ... A_{2, N} ... A_{N, 1} A_{N, 2} ... A_{N, N} Outputs If there exists no network that satisfies the condition, print -1 . If it exists, print the shortest possible total length of the roads. Sample Input 1 3 0 1 3 1 0 2 3 2 0 Sample Output 1 3 The network below satisfies the condition: City 1 and City 2 is connected by a road of length 1 . City 2 and City 3 is connected by a road of length 2 . City 3 and City 1 is not connected by a road. Sample Input 2 3 0 1 3 1 0 1 3 1 0 Sample Output 2 -1 As there is a path of length 1 from City 1 to City 2 and City 2 to City 3 , there is a path of length 2 from City 1 to City 3 . However, according to the table, the shortest distance between City 1 and City 3 must be 3 . Thus, we conclude that there exists no network that satisfies the condition. Sample Input 3 5 0 21 18 11 28 21 0 13 10 26 18 13 0 23 13 11 10 23 0 17 28 26 13 17 0 Sample Output 3 82 Sample Input 4 3 0 1000000000 1000000000 1000000000 0 1000000000 1000000000 1000000000 0 Sample Output 4 3000000000 | 36,254 |
Score : 400 points Problem Statement Takahashi is going to buy N items one by one. The price of the i -th item he buys is A_i yen (the currency of Japan). He has M discount tickets, and he can use any number of them when buying an item. If Y tickets are used when buying an item priced X yen, he can get the item for \frac{X}{2^Y} (rounded down to the nearest integer) yen. What is the minimum amount of money required to buy all the items? Constraints All values in input are integers. 1 \leq N, M \leq 10^5 1 \leq A_i \leq 10^9 Input Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N Output Print the minimum amount of money required to buy all the items. Sample Input 1 3 3 2 13 8 Sample Output 1 9 We can buy all the items for 9 yen, as follows: Buy the 1 -st item for 2 yen without tickets. Buy the 2 -nd item for 3 yen with 2 tickets. Buy the 3 -rd item for 4 yen with 1 ticket. Sample Input 2 4 4 1 9 3 5 Sample Output 2 6 Sample Input 3 1 100000 1000000000 Sample Output 3 0 We can buy the item priced 1000000000 yen for 0 yen with 100000 tickets. Sample Input 4 10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 Sample Output 4 9500000000 | 36,255 |
Problem H Kimagure Cleaner Ichiro won the newest model cleaner as a prize of a programming contest. This cleaner automatically moves around in a house for cleaning. Because Ichiro's house is very large, it can be modeled as an infinite two-dimensional Cartesian plane, whose axes are called $X$ and $Y$. The positive direction of the $Y$-axis is to the left if you face the positive direction of the $X$-axis. The cleaner performs a sequence of actions for cleaning. Each action consists of a turn and a run. In an action, first the cleaner turns right or left by 90 degrees, and then runs straight by an integer length to the direction that the cleaner faces. At the end of a day, the cleaner reports the log of its actions in the day to Ichiro, in order to inform him where it has cleaned and where it hasn't. Unlike common cleaners, this cleaner has human-like artificial intelligence. Therefore, the cleaner is very forgetful (like humans) and it is possible that the cleaner forgets the direction of a turn, or the cleaner only remembers the length of a run as a very rough range. However, in order to pretend to be operating correctly, the cleaner has to recover the complete log of actions after finishing the cleaning. The cleaner was initially at the point $(0, 0)$, facing the positive direction of $X$-axis. You are given the cleaner's location after cleaning, $(X, Y)$, and an incomplete log of the cleaner's actions that the cleaner remembered. Please recover a complete log from the given incomplete log. The actions in the recovered log must satisfy the following constraints: The number of actions must be the same as that in the incomplete log. The direction of the $i$-th turn must be the same as that in the incomplete log if it is recorded in the incomplete log. The length of the $i$-th run must be within the range of the length specified in the incomplete log. The cleaner must be at $(X, Y)$ after finishing all actions. The direction of the cleaner after cleaning is not important and you do not have to care about it, because the cleaner can turn freely after cleaning, though it cannot run after cleaning. You are not required to recover the actual path, because Ichiro only checks the format of the log and the location of the cleaner after cleaning. Input The input consists of a single test case. The first line contains three integers $N$ $(1 \leq N \leq 50)$, $X$, and $Y$ $(-10^9 \leq X, Y \leq 10^9)$. $N$ represents the number of actions in the incomplete log. $X$ and $Y$ represent the cleaner's location $(X, Y)$ after cleaning. The $i$-th line of the following $N$ lines contains a character $D_i$ and two integers $LL_i$ and $LU_i$. $D_i$ represents the direction of the $i$-th turn: ' L ', ' R ', and ' ? ' represents left, right, and not recorded respectively. $LL_i$ and $LU_i$ represent a lower and upper bound of the length of the $i$-th run, respectively. You can assume $1 \leq LL_i \leq LU_i \leq 55,555,555$. Output Display the recovered log. In the first line, display N, the number of actions in the log. In the $i$-th line of the following $N$ lines, display the direction of the $i$-th turn in a character and the length of the $i$-th run separated by a single space. Represent a right turn by a single character ' R ', and a left turn by a single character ' L '. The recovered log must satisfy the constraints in the problem. If there are multiple logs that satisfy the constraints, you can display any of them. Display $-1$ in a line if there is no log that satisfies the constraints. Sample Input 1 2 -3 4 L 2 5 ? 3 5 Output for the Sample Input 1 2 L 4 L 3 Sample Input 2 5 3 -4 ? 1 5 ? 1 5 ? 1 5 ? 1 5 ? 1 5 Output for the Sample Input 2 5 L 1 R 2 R 4 L 1 R 1 | 36,256 |
Problem B: Balloon Collecting "Balloons should be captured efficiently", the game designer says. He is designing an oldfashioned game with two dimensional graphics. In the game, balloons fall onto the ground one after another, and the player manipulates a robot vehicle on the ground to capture the balloons. The player can control the vehicle to move left or right, or simply stay. When one of the balloons reaches the ground, the vehicle and the balloon must reside at the same position, otherwise the balloon will burst and the game ends. Figure B.1: Robot vehicle and falling balloons The goal of the game is to store all the balloons into the house at the left end on the game field. The vehicle can carry at most three balloons at a time, but its speed changes according to the number of the carrying balloons. When the vehicle carries k balloons ( k = 0, 1, 2, 3), it takes k +1 units of time to move one unit distance. The player will get higher score when the total moving distance of the vehicle is shorter. Your mission is to help the game designer check game data consisting of a set of balloons. Given a landing position (as the distance from the house) and a landing time of each balloon, you must judge whether a player can capture all the balloons, and answer the minimum moving distance needed to capture and store all the balloons. The vehicle starts from the house. If the player cannot capture all the balloons, you must identify the first balloon that the player cannot capture. Input The input is a sequence of datasets. Each dataset is formatted as follows. n p 1 t 1 . . . p n t n The first line contains an integer n, which represents the number of balloons (0 < n †40). Each of the following n lines contains two integers p i and t i (1 †i †n ) separated by a space. p i and t i represent the position and the time when the i -th balloon reaches the ground (0 < p i †100, 0 < t i †50000). You can assume t i < t j for i < j . The position of the house is 0, and the game starts from the time 0. The sizes of the vehicle, the house, and the balloons are small enough, and should be ignored. The vehicle needs 0 time for catching the balloons or storing them into the house. The vehicle can start moving immediately after these operations. The end of the input is indicated by a line containing a zero. Output For each dataset, output one word and one integer in a line separated by a space. No extra characters should occur in the output. If the player can capture all the balloons, output "OK" and an integer that represents the minimum moving distance of the vehicle to capture and store all the balloons. If it is impossible for the player to capture all the balloons, output "NG" and an integer k such that the k -th balloon in the dataset is the first balloon that the player cannot capture. Sample Input 2 10 100 100 270 2 10 100 100 280 3 100 150 10 360 40 450 3 100 150 10 360 40 440 2 100 10 50 200 2 100 100 50 110 1 15 10 4 1 10 2 20 3 100 90 200 0 Output for the Sample Input OK 220 OK 200 OK 260 OK 280 NG 1 NG 2 NG 1 OK 188 | 36,257 |
Score : 100 points Problem Statement You have decided to give an allowance to your child depending on the outcome of the game that he will play now. The game is played as follows: There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a + printed on it. The player should construct a formula of the form X + Y , by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.) Then, the amount of the allowance will be equal to the resulting value of the formula. Given the values A, B and C printed on the integer panels used in the game, find the maximum possible amount of the allowance. Constraints All values in input are integers. 1 \leq A, B, C \leq 9 Input Input is given from Standard Input in the following format: A B C Output Print the maximum possible amount of the allowance. Sample Input 1 1 5 2 Sample Output 1 53 The amount of the allowance will be 53 when the panels are arranged as 52+1 , and this is the maximum possible amount. Sample Input 2 9 9 9 Sample Output 2 108 Sample Input 3 6 6 7 Sample Output 3 82 | 36,258 |
G: Dungeon of Cards / ã«ãŒãã®è¿·å®® ç©èª ããã¯äžæè°ã®åœãããµããïŒãããµãã蟺å¢ã®å°ã«äœçœ®ããã«ãŒãã®è¿·å®®ã«ã¯ïŒéé財å®ãç ããšäŒããããŠããïŒå¥œå¥å¿æºçãªãããã«ããã¯ïŒãã®èšãäŒããèããããªãïŒå人ã®ãŠã£ãé£ããŠã«ãŒãã®è¿·å®®ãç®æãæ
ã«åºãããšã«ããïŒ ç¿æ¥ïŒæ
ã®èšç»ãç«ãŠãããã«ãããã«ããããŠã£ã®å®¶ã蚪ãããšïŒãŠã£ã¯äœããèã蟌ãã§ããããã ã£ãïŒã©ãããçšæåšå°ãªãŠã£ã¯ã«ãŒãã®è¿·å®®ã«é¢ããéèŠãªæ
å ±ãå
¥æããããã ïŒããã¯ïŒã«ãŒãã®è¿·å®®ã«ã¯ N æã®æãããïŒããããã®æãéããããã«ã«ãŒããå¿
èŠã«ãªããšããããšã ïŒ ã«ãŒãã®è¿·å®®ãžã®éäžã«ã¯ïŒæãéãããã®ã«ãŒããæ±ãåºãããïŒãŠã£ã¯ããã§ã«ãŒãã調éããããšèããŠããããããïŒåé¡ãªã®ã¯äºç®ã§ããïŒãããã«ãããšãŠã£ã¯æ±ºããŠãéæã¡ã§ã¯ãªãã®ã§ïŒã«ãŒãã«ãéããããããŠããŸããšéäžã®é£æãååã«ç¢ºä¿ã§ããªãå¯èœæ§ãããã®ã ïŒ å¹žã N æã®æã®æ
å ±ã¯ïŒãããŸã§è¿·å®®ã«æãã 人ã
ã®èšé²ããç¥ãããšãã§ããïŒãããªãå¹çã®è¯ãã«ãŒãã®è²·ãæ¹ãèšç®ã§ãããããããªãïŒãããïŒïŒäººã§èããã«ã¯å°ãé£ããïŒããã§ãããã«ãããšãŠã£ã¯ïŒãããµããã«äœãåªç§ãªããã°ã©ãã§ããããªãã«äŸé Œãããããšã«ããïŒ åé¡ N æã®æãš M æã®ã«ãŒããããïŒæã»ã«ãŒããšãã«ïŒæã«ã€ãè±å€§æåã¢ã«ãã¡ããã ('A'-'Z') 1ã€ãš1æ¡ã®æ°å ('0'-'9') ãæãããŠããïŒæã«ã«ãŒããããããšïŒã«ãŒãã«æãããã¢ã«ãã¡ãããïŒãããã¯æ°åã®ã©ã¡ããäžæ¹ã§ãæã®ãã®ãšäžèŽããŠããã°ïŒãã®æãéããããšãã§ããïŒãã®ãšãã«ãŒãã¯ãªããªããªãããïŒåãã«ãŒããäœåºŠã§ã䜿ããŸããããšãã§ããïŒãŸãïŒã«ãŒãã«ã¯ãããã倿®µãä»ããŠããïŒ N æã®æãš M æã®ã«ãŒãã®æ
å ±ãå
ã«ïŒãã¹ãŠã®æãéããããšãã§ããã«ãŒãã®è²·ãæ¹ã®ãã¡ïŒèŠããéé¡ãæå°ãšãªãå Žåã®éé¡ãèšç®ããããã°ã©ã ãäœæããïŒ å
¥ååœ¢åŒ å
¥åã¯ä»¥äžã®åœ¢åŒãããªãïŒ N a_1 b_1 ... a_N b_N M c_1 d_1 e_1 ... c_M d_M e_M 1è¡ç®ã§ã¯æã®ææ°ãè¡šãæŽæ° N ãäžããããïŒç¶ã N è¡ã®ãã¡ïŒ i è¡ç®ã§ã¯ i çªç®ã®æã«æžãããè±å€§æåã¢ã«ãã¡ããã a_i ãš1æ¡ã®æ°å b_i ãäžããããïŒ ç¶ã1è¡ã§ã¯ïŒåºã§æ±ãããŠããã«ãŒãã®ææ° M ãäžããããïŒç¶ã M è¡ã®ãã¡ïŒ j è¡ç®ã§ã¯ j çªç®ã®ã«ãŒãã«æžãããè±å€§æåã¢ã«ãã¡ããã c_j ãš1æ¡ã®æ°å d_j ïŒäŸ¡æ Œ e_j ãäžããããïŒ å
¥åã¯ä»¥äžã®å¶çŽãæºããïŒ 1 †N, M †10{,}000 a_i, c_j ã¯ã¢ã«ãã¡ããã倧æå ('A'-'Z') 1æå b_i, d_j ã¯1æ¡ã®æ°å ('0'-'9') 1æå 1 †e_j †1{,}000 N, M, e_j ã¯ãã¹ãп޿° åºååœ¢åŒ è¿·å®®ã®æããã¹ãŠéããããã«å¿
èŠãªã«ãŒããæããããã®æå°äºç®ã1è¡ã«åºåããïŒã©ã®ããã«ã«ãŒããè²·ã£ãŠãå
šãŠã®æãéããããªãå ŽåïŒ-1ã1è¡ã«åºåããïŒ å
¥åäŸïŒ 4 D 1 D 2 A 3 D 4 4 A 1 7 D 4 5 D 3 6 B 3 3 åºåäŸïŒ 6 å
¥åäŸ2 4 D 1 D 2 A 3 D 4 4 A 1 7 D 4 5 D 3 10 B 3 3 åºåäŸ2 8 å
¥åäŸ3 5 D 1 D 2 A 3 Z 0 D 4 4 A 1 7 D 4 5 D 3 6 B 3 3 åºåäŸ3 -1 | 36,259 |
Score : 300 points Problem Statement You are given an array A of length N . Your task is to divide it into several contiguous subarrays. Here, all subarrays obtained must be sorted in either non-decreasing or non-increasing order. At least how many subarrays do you need to divide A into? Constraints 1 \leq N \leq 10^5 1 \leq A_i \leq 10^9 Each A_i is an integer. Input Input is given from Standard Input in the following format: N A_1 A_2 ... A_N Output Print the minimum possible number of subarrays after division of A . Sample Input 1 6 1 2 3 2 2 1 Sample Output 1 2 One optimal solution is to divide the array into [1,2,3] and [2,2,1] . Sample Input 2 9 1 2 1 2 1 2 1 2 1 Sample Output 2 5 Sample Input 3 7 1 2 3 2 1 999999999 1000000000 Sample Output 3 3 | 36,260 |
Score: 800 points Problem Statement This is an interactive task. We have 2N balls arranged in a row, numbered 1, 2, 3, ..., 2N from left to right, where N is an odd number. Among them, there are N red balls and N blue balls. While blindfolded, you are challenged to guess the color of every ball correctly, by asking at most 210 questions of the following form: You choose any N of the 2N balls and ask whether there are more red balls than blue balls or not among those N balls. Now, let us begin. Constraints 1 \leq N \leq 99 N is an odd number. Input and Output First, receive the number of balls of each color, N , from Standard Input: N Then, ask questions until you find out the color of every ball. A question should be printed to Standard Output in the following format: ? A_1 A_2 A_3 ... A_N This means that you are asking about the N balls A_1, A_2, A_3, ..., A_N , where 1 \leq A_i \leq 2N and A_i \neq A_j (i \neq j) must hold. The response T to this question will be given from Standard Input in the following format: T Here T is one of the following strings: Red : Among the N balls chosen, there are more red balls than blue balls. Blue : Among the N balls chosen, there are more blue balls than red balls. -1 : You printed an invalid question (including the case you asked more than 210 questions), or something else that was invalid. If the judge returns -1 , your submission is already judged as incorrect. The program should immediately quit in this case. When you find out the color of every ball, print your guess to Standard Output in the following format: ! c_1 c_2 c_3 ... c_{2N} Here c_i should be the character representing the color of Ball i ; use R for red and B for blue. Notice Flush Standard Output each time you print something. Failure to do so may result in TLE . Immediately terminate your program after printing your guess (or receiving the -1 response). Otherwise, the verdict will be indeterminate. If your program prints something invalid, the verdict will be indeterminate. Sample Input and Output Input Output 3 ? 1 2 3 Red ? 2 4 6 Blue ! RRBBRB In this sample, N = 3 , and the colors of Ball 1, 2, 3, 4, 5, 6 are red, red, blue, blue, red, blue, respectively. In the first question, there are two red balls and one blue ball among the balls 1, 2, 3 , so the judge returns Red . In the second question, there are one red ball and two blue balls among the balls 2, 4, 6 , so the judge returns Blue . | 36,261 |
Problem J: Revenge of the Round Table Two contries A and B have decided to make a meeting to get acquainted with each other. n ambassadors from A and B will attend the meeting in total. A round table is prepared for in the meeting. The ambassadors are getting seated at the round table, but they have agreed that more than k ambassadors from the same country does not sit down at the round table in a row for deeper exchange. Your task is to write a program that reports the number of possible arrangements when rotations are not counted. Your program should report the number modulo M = 1000003. Let us provide an example. Suppose n = 4 and k = 2. When rotations are counted as different arrangements, the following six arrangements are possible. AABB ABBA BBAA BAAB ABAB BABA However, when rotations are regarded as same, the following two arrangements are possible. AABB ABAB Therefore the program should report 2. Input The input consists of multiple datasets. Each dataset consists of two integers n (1 †n †1000) and k (1 †k †1000) in one line. It does not always hold k < n . This means the program should consider cases in which the ambassadors from only one country attend the meeting. The last dataset is followed by a line containing two zeros. This line is not a part of any dataset and should not be processed. Output For each dataset, print the number of possible arrangements modulo M = 1000003 in one line. Sample Input 3 1 3 2 3 3 4 2 10 5 1000 500 0 0 Output for the Sample Input 0 2 4 2 90 570682 | 36,262 |
Problem H: è¿·ãç«ãèµ°ã£ã æŽèåå°éåºã¹ãã¬ã€ãã£ããã§ã¯ããããã®ç«ã飌ãããŠãããç«ã®æ°ãããŸãã«ãå€ãããããã®åºã®ã¹ã¿ããã§ããåžã¯é€ããã«å°ã£ãŠããã ããã€ãã®å Žæã«é€ã眮ããŠããç«ã¯è²ªæ¬²ãªã®ã§æãè¿ãé€ã«åãã£ãŠããŸããäžã€ã®é€å
¥ãã«ããããã®ç«ãéäžããŠããŸãã ããªãã¯åžã®ããã«ãã§ããã ãç«ãéäžããªãé€ã®é
çœ®ãæ±ããåé¡ãè§£ãããšã«ããã åé¡ãç°¡åã«ãããããç«ã¯å¹³é¢äžã® y>0 ã®éšåã«ããŠé€ã眮ããŸã§åããªããšããã ç«ã¯ N åã®éå£ã«åãããŠããŠãäžç®æã«äœå¹ããããããããªãã é€å
¥ã㯠y=0 äžã® M ç¹ã«åºå®ããŠããããã®äžããããã€ãéžãã§é€ãå
¥ããããšã«ãªãã é€ãå
¥ãããšãç«ã¯(ãŠãŒã¯ãªããè·é¢ã§)äžçªè¿ãé€ã®å
¥ã£ãé€å
¥ãã«åããããåãè·é¢ã«äºã€ãããšãã¯x座æšãå°ããã»ãã«åãããã®ãšããã ãã®æ¡ä»¶ã®äžã§ãæãç«ãéãŸã£ãŠããé€å
¥ãã®ç«ã®æ°ãæå°åããªããã Input å
¥åã¯ä»¥äžã®ãããªåœ¢åŒã§äžããããã N M x 1 y 1 C 1 ... x N y N C N x 1 ... x M å
¥åã®1è¡ç®ã«ã¯ã2ã€ã®æŽæ° N, M ãã¹ããŒã¹æåã§åºåãããŠäžããããããããã¯ãåé¡æã§æå®ãããšããã§ããã0 †N †1000 ããã³ 1 †M †1000 ãæºããã ç¶ã N è¡ã«ã¯ãããããã®ç«ã®éå£ã«ã€ããŠ1è¡ã«1ã€ãã€ãéå£ã®äœçœ®ã® x, y 座æšãè¡šãæŽæ°ã®çµ (-10000 †x †10000, 0 < y †10000)ãšäœå¹éãŸã£ãŠããããè¡šãæŽæ°C(1 †C †100000)ãäžããããã ãã®åŸã®Mè¡ã«ã¯ãããããã®é€å
¥ãã«ã€ããŠ1è¡ã«1ã€ãã€ãé€å
¥ãã®äœçœ®ã®x座æšãè¡šãæŽæ°(-10000 †x †10000)ãäžããããã åãç¹ã«ãäºã€ä»¥äžã®é€å
¥ããååšããããšã¯ãªãã Output æãç«ãéãŸã£ãŠããé€å
¥ãã®ç«ã®æ°ã®æå°å€ãåºåããã Notes on Test Cases äžèšå
¥å圢åŒã§è€æ°ã®ããŒã¿ã»ãããäžããããŸããåããŒã¿ã»ããã«å¯ŸããŠäžèšåºå圢åŒã§åºåãè¡ãããã°ã©ã ãäœæããŠäžããã N, M ããšãã« 0 ã®ãšãå
¥åã®çµããã瀺ããŸãã Sample Input 3 3 -1 1 1 0 1 1 1 1 1 -3 0 3 5 5 7 3 5 -9 2 7 4 9 6 10 5 9 -9 7 9 0 -1 -2 -9 -8 0 0 Output for Sample Input 2 20 | 36,263 |
Score : 100 points Problem Statement There is always an integer in Takahashi's mind. Initially, the integer in Takahashi's mind is 0 . Takahashi is now going to eat four symbols, each of which is + or - . When he eats + , the integer in his mind increases by 1 ; when he eats - , the integer in his mind decreases by 1 . The symbols Takahashi is going to eat are given to you as a string S . The i -th character in S is the i -th symbol for him to eat. Find the integer in Takahashi's mind after he eats all the symbols. Constraints The length of S is 4 . Each character in S is + or - . Input Input is given from Standard Input in the following format: S Output Print the integer in Takahashi's mind after he eats all the symbols. Sample Input 1 +-++ Sample Output 1 2 Initially, the integer in Takahashi's mind is 0 . The first integer for him to eat is + . After eating it, the integer in his mind becomes 1 . The second integer to eat is - . After eating it, the integer in his mind becomes 0 . The third integer to eat is + . After eating it, the integer in his mind becomes 1 . The fourth integer to eat is + . After eating it, the integer in his mind becomes 2 . Thus, the integer in Takahashi's mind after he eats all the symbols is 2 . Sample Input 2 -+-- Sample Output 2 -2 Sample Input 3 ---- Sample Output 3 -4 | 36,264 |
Problem F: Equilateral Triangle Problem $N$åã®é ç¹ãããªãåžå€è§åœ¢ãäžããããã ãã®åžå€è§åœ¢ã®å
šãŠã®é ç¹ãå«ãæ£äžè§åœ¢ãèãããšãããã®æ£äžè§åœ¢ã®äžèŸºã®é·ãã®æå°å€ãæ±ããã Input å
¥åã¯ä»¥äžã®åœ¢åŒã§ãã¹ãп޿°ã§äžããããã $N$ $px_1$ $py_1$ $px_2$ $py_2$ $\vdots$ $px_N$ $py_N$ $1$è¡ç®ã«ã¯åžå€è§åœ¢ã®é ç¹æ°ãè¡šãæŽæ°$N$ãäžããããã ç¶ã$N$è¡ã«ã¯åžå€è§åœ¢ã®åé ç¹ã®æ
å ±ãåæèšåšãã®é ã§äžããããã $1+i$è¡ç®ã«ã¯$i$çªç®ã®é ç¹ã®åº§æšã衚ã$px_i$,$py_i$ã空çœåºåãã§äžããããã Constraints å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã $3 \le N \le 10000$ $-10^9 \le px_i, py_i \le 10^9$ åžå€è§åœ¢ã®é ç¹ã®ãã¡ã©ã®3ç¹ãéžãã§ããåäžçŽç·äžã«ã¯ååšããªã Output æ¡ä»¶ãæºããæ£äžè§åœ¢ã®äžèŸºã®é·ãã®æå°å€ãåºåããã ãã ãã$10^{-5}$ ãŸã§ã®çµ¶å¯Ÿèª€å·®ãŸãã¯çžå¯Ÿèª€å·®ã¯èš±å®¹ãããã Sample Input 1 4 2 3 1 2 2 1 3 2 Sample Output 1 3.04720672 Sample Input 2 7 -96469 25422 -55204 -45592 -29140 -72981 98837 -86795 92303 63297 19059 96012 -67980 70342 Sample Output 2 310622.35426197 | 36,265 |
ãã©ãã¯ãžã£ã㯠ãã©ãã¯ãžã£ãã¯ã¯ã«ãžãã§è¡ãããã«ãŒãã²ãŒã ã®äžçš®ã§ã1 ã 13 ãŸã§ã®æ°ãæžãããã«ãŒãã䜿ã£ãŠã²ãŒã ãè¡ãããŸããåã«ãŒãã®ç¹æ°ã¯æ¬¡ã®ããã«æ±ºãŸã£ãŠããŸãã 1 㯠1 ç¹ããã㯠11 ç¹ 2 ãã 9 ãŸã§ã¯ãæžãããŠããæ°ã®éãã®ç¹æ° 10 ãã 13 ãŸã§ã¯ã10 ç¹ ãã®ã²ãŒã ã«ã¯èŠªãå«ããäœäººãã®åå è
ãããããããããäœæãã®ã«ãŒãã®çµãæã£ãŠããŸãããã®ã«ãŒãã®çµã®ããšãæãšåŒã³ãŸããæã®ç¹æ°ã¯ã«ãŒãã®ç¹æ°ã®åèšã§ãããã®èšç®ã¯æ¬¡ã®ããã«è¡ããã®ãšããŸãã ã«ãŒãã®ç¹æ°ã®åèšã 21 ãã倧ãããªããšãã¯ãæã®ç¹æ°ã 0 ç¹ãšãã ã«ãŒãã®ç¹æ°ãšããŠã1 㯠1 ç¹ãšèšç®ããŠã 11 ç¹ãšèšç®ããŠãããããæã®ç¹æ°ãæå€§ãšãªãæ¹ãéžã¶ããšãšãã é
ãããã«ãŒãã®æ
å ±ãå
¥åãšããæã®ç¹æ°ãåºåããããã°ã©ã ãäœæããŠãã ããã Input è€æ°ã®ããŒã¿ã»ããã®äžŠã³ãå
¥åãšããŠäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã®è¡ã§ç€ºãããŸãã åããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã c 1 c 2 ... c n ïŒè¡ã« i çªç®ã®ã«ãŒãã«æžãããŠããæŽæ° c i (1 †c i †13) ã空çœåºåãã§ïŒè¡ã«äžããããŸããã«ãŒãã®æ° n 㯠100 ãè¶
ããŸããã ããŒã¿ã»ããã®æ°ã¯ 200 ãè¶
ããŸããã Output ããŒã¿ã»ããããšã«æã®ç¹æ°ãïŒè¡ã«åºåããŸãã Sample Input 1 7 7 7 7 7 8 12 1 10 1 1 0 Output for the Sample Input 11 21 0 21 12 | 36,266 |
ãžã°ã¶ã°æ° (Zig-Zag Numbers) åé¡ æ£ã®æŽæ°ã (å
é ã« 0 ãã€ããã«) 10 鲿³ã§æžããŠæ¡ã®æ°åãé çªã«èŠãŠãããšå¢å ãšæžå°ã亀äºã«ç¹°ãè¿ããŠãããšãïŒãã®æ°ã¯ããžã°ã¶ã°æ°ãã§ãããšåŒã¶ããšã«ãããïŒããšãã°ïŒ2947 ã¯æ¡ã®æ°åã 2 â 9 â 4 â 7 ãšïŒå¢å â æžå° â å¢å ã®é ã«ãªã£ãŠããã®ã§ãžã°ã¶ã°æ°ã§ããïŒãŸãïŒ71946 㯠æžå° â å¢å â æžå° â å¢å ã®é ãªã®ã§ãžã°ã¶ã°æ°ã§ããïŒäžæ¹ïŒ123 ã 71446 ã 71442 ã 88 ã¯ãžã°ã¶ã°æ°ã§ã¯ãªãïŒãªãïŒ1 æ¡ã®æ£ã®æŽæ°ã¯ãžã°ã¶ã°æ°ã§ãããšèããããšãšããïŒ A ä»¥äž B 以äžã® M ã®åæ°ã®ãã¡ïŒãžã°ã¶ã°æ°ã®åæ°ã 10000 ã§å²ã£ãäœããæ±ããããã°ã©ã ãäœæããïŒ å
¥å å
¥å㯠3 è¡ãããªãïŒ1 è¡ã« 1 ã€ãã€æ£ã®æŽæ°ãæžãããŠããïŒ 1 è¡ç®ã®æŽæ°ã¯ A ãïŒ2 è¡ç®ã®æŽæ°ã¯ B ãïŒ3 è¡ç®ã®æŽæ°ã¯ M ã衚ãïŒããã㯠1 ⊠A ⊠B ⊠10 500 ïŒ1 ⊠M ⊠500 ãæºããïŒ â» A ã B ã®å€ã¯ïŒéåžžã®æŽæ°ã衚ãããŒã¿åã«ã¯åãŸããªãå¯èœæ§ãããããšã«æ³šæããïŒ åºå A ä»¥äž B 以äžã® M ã®åæ°ã®ãã¡ïŒãžã°ã¶ã°æ°ã®åæ°ã 10000 ã§å²ã£ãäœãã 1 è¡ã§åºåããïŒ å
¥åºåäŸ å
¥åäŸ 1 100 200 5 åºåäŸ 1 13 å
¥åºåäŸ 1 ã«ãããŠïŒ100 ä»¥äž 200 以äžã® 5 ã®åæ°ã§ãããžã°ã¶ã°æ°ã¯ïŒ105, 120, 130, 140, 150, 160, 165, 170, 175, 180, 185, 190, 195 ã® 13 åã§ããïŒ å
¥åäŸ 2 6 1234567 3 åºåäŸ 2 246 å
¥åºåäŸ 2 ã«ãããŠïŒ6 ä»¥äž 1234567 以äžã® 3 ã®åæ°ã§ãããžã°ã¶ã°æ°ã¯ 50246 åããã®ã§ïŒããã 10000 ã§å²ã£ãäœãã§ãã 246 ãåºåããïŒ å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã | 36,267 |
JOI å
¬å (JOI Park) 20XX 幎㫠IOI åœã§è¡ããããªãªã³ããã¯ã«åãïŒIOI åœã«ãã JOI å
¬åãæŽåããããšã«ãªã£ãïŒJOIå
¬åã«ã¯ N åã®åºå ŽãããïŒåºå Žã«ã¯ 1 ãã N ã®çªå·ãã€ããŠããïŒåºå Žãç¹ã M æ¬ã®éãããïŒéã«ã¯ 1 ãã M ã®çªå·ãã€ããŠããïŒé i (1 †i †M ) ã¯åºå Ž A i ãšåºå Ž B i ãåæ¹åã«ç¹ãã§ããïŒé·ã㯠D i ã§ããïŒã©ã®åºå Žããã©ã®åºå Žãžãããã€ãã®éã蟿ã£ãŠè¡ãããšãã§ããïŒ æŽåèšç»ã§ã¯ïŒãŸãïŒ0 以äžã®æŽæ° X ãéžã³ïŒåºå Ž 1 ããã®è·é¢ã X 以äžã§ãããããªåºå Ž (åºå Ž 1 ãå«ã) ã©ããããã¹ãŠçžäºã«å°äžéã§çµã¶ïŒãã ãïŒåºå Ž i ãšåºå Ž j ã®è·é¢ãšã¯ïŒåºå Ž i ããåºå Ž j ã«è¡ããšãã«éãéã®é·ãã®åã®æå°å€ã§ããïŒæŽåèšç»ã§ã¯å°äžéã®æŽåã³ã¹ãã«é¢ããæŽæ° C ãå®ãŸã£ãŠããïŒå°äžéã®æŽåã«ãããã³ã¹ã㯠C à X ã§ããïŒ æ¬¡ã«ïŒå°äžéã§çµã°ããåºå Žã©ãããçµã¶éããã¹ãŠæ€å»ããïŒéã®æ€å»ã«ã³ã¹ãã¯ããããªãïŒæåŸã«ïŒæ€å»ãããã«æ®ã£ãéããã¹ãŠè£ä¿®ããïŒé·ã d ã®éãè£ä¿®ããããã«ãããã³ã¹ã㯠d ã§ããïŒæŽåèšç»å®æœåã® JOI å
¬åã«ã¯å°äžéã¯ãªãïŒJOI å
¬åã®æŽåã«ãããã³ã¹ãã®åã®æå°å€ãæ±ããïŒ èª²é¡ JOI å
¬åã®åºå Žã®æ
å ±ãšïŒå°äžéã®æŽåã³ã¹ãã«é¢ããæŽæ°ãäžãããããšãïŒJOI å
¬åã®æŽåã«ããã ã³ã¹ãã®åã®æå°å€ãæ±ããããã°ã©ã ãäœæããïŒ å
¥å æšæºå
¥åãã以äžã®ããŒã¿ãèªã¿èŸŒãïŒ 1 è¡ç®ã«ã¯ïŒæŽæ° N , M , C ã空çœãåºåããšããŠæžãããŠããïŒããã¯ïŒåºå Žã N åïŒéã M æ¬ããïŒå°äžéã®æŽåã³ã¹ãã«é¢ããæŽæ°ã C ã§ããããšã衚ãïŒ ç¶ã M è¡ã®ãã¡ã® i è¡ç® (1 †i †M ) ã«ã¯ïŒæŽæ° A i , B i , D i ã空çœãåºåããšããŠæžãããŠããïŒããã¯ïŒé i ãåºå Ž A i ãšåºå Ž B i ãç¹ãïŒé·ãã D i ã§ããããšã衚ãïŒ åºå æšæºåºåã«ïŒJOI å
¬åã®æŽåã«ãããã³ã¹ãã®åã®æå°å€ãè¡šãæŽæ°ã 1 è¡ã§åºåããïŒ å¶é ãã¹ãŠã®å
¥åããŒã¿ã¯ä»¥äžã®æ¡ä»¶ãæºããïŒ 2 †N †100 000ïŒ 1 †M †200 000ïŒ 1 †C †100 000ïŒ 1 †A i †N (1 †i †M )ïŒ 1 †B i †N (1 †i †M )ïŒ A i â B i (1 †i †M )ïŒ ( A i , B i ) â ( A j , B j ) ããã³ ( A i , B i ) â ( B j , A j ) (1 †i < j †M )ïŒ 1 †D i †100 000 (1 †i †M )ïŒ äžããããå
¥åããŒã¿ã«ãããŠã¯ïŒã©ã®åºå Žããã©ã®åºå Žãžãããã€ãã®éã蟿ãããšã«ããè¡ããããšãä¿èšŒãããŠããïŒ å
¥åºåäŸ å
¥åäŸ 1 5 5 2 2 3 1 3 1 2 2 4 3 1 2 4 2 5 5 åºåäŸ 1 14 ãã®å
¥åäŸã§ã¯ïŒ X = 3 ãšããŠïŒåºå Ž 1 ããã®è·é¢ã 3 以äžã§ãããããªåºå Ž (åºå Ž 1, åºå Ž 2, åºå Ž 3) ã©ããããã¹ãŠçžäºã«å°äžéã§çµãã ãšãïŒæŽåã«ãããã³ã¹ãã®å㯠2 à 3 + 3 + 5 = 14 ãšãªãïŒãããæå°å€ã§ããïŒ å
¥åäŸ 2 5 4 10 1 2 3 2 3 4 3 4 3 4 5 5 åºåäŸ 2 15 ãã®å
¥åäŸã§ã¯ïŒX = 0 ã®ãšãæŽåã«ãããã³ã¹ãã®åãæå°ã«ãªãïŒ å
¥åäŸ 3 6 5 2 1 2 2 1 3 4 1 4 3 1 5 1 1 6 5 åºåäŸ 3 10 ãã®å
¥åäŸã§ã¯ïŒ X = 5 ãšããŠãã¹ãŠã®åºå Žãçžäºã«å°äžéã§çµãã ãšãïŒæŽåã«ãããã³ã¹ãã®åãæå°ã«ãªãïŒ å顿ãšèªå審å€ã«äœ¿ãããããŒã¿ã¯ã æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒ ãäœæãå
¬éããŠããåé¡æãšæ¡ç¹çšãã¹ãããŒã¿ã§ãã | 36,268 |
Problem C: General of Taiko Problem ãšããã²ãŒã ã»ã³ã¿ãŒã«ã¯ãæ²ã«åãããŠæµããŠããèé¢éãã«å倪éŒãå©ãã²ãŒã ããããŸãã èé¢ã¯é·ã L ã®ã»ã«ãããªããåã»ã«ã«ã¯äœããªãããŸãã¯ããŒããšåŒã°ãããã¬ã€ã€ãŒããšãã¹ãè¡åã衚ããèšå·ããããŸãã ããŒãã¯2çš®é¡ãããããããå倪éŒã®é¢ãå©ãããã³ããå倪éŒã®çžãå©ããã³ããããããŸãã ãããã®ããŒãã«åãããŠå倪éŒãå©ããšåŸç¹ãåŸãããšãã§ããŸãã ãã®åŸç¹ã®åèšã10000ç¹ä»¥äžã§ããã°ã¯ãªã¢ãšãªããŸãã ãã®ãšãããã¬ã€ã€ãŒãæ²ãã¯ãªã¢ã§ãã確çãæ±ããªããããã ãããã¬ã€ã€ãŒã¯åžžã«æé©ãªè¡åããšãããšã«ããŸãã ãã¬ã€ã€ãŒãèé¢éãã«å倪éŒãå©ã粟床ã¯11段éãããããããã 0%, 10%, 20%, ..., 90%, 100%ã®ç¢ºçã§èé¢éãã«å倪éŒãå©ãããšãã§ããŸãã äžèšã®äºçš®é¡ã®åäœã¯å³è
ãšå·Šè
ã©ã¡ãã§ã§ãè¡ãããšãã§ããŸãã ãã¬ã€ã€ãŒã®æ
å ±ãšããŠãããããã®è
ã§è¡ã£ãå Žåã®ç²ŸåºŠã®å®å®çã衚ãå€ã16çš®é¡ãäžèšã®ããã«äžããããŸãã lt _ lt lt _ rt lt _ lk lt _ rk rt _ lt rt _ rt rt _ lk rt _ rk lk _ lt lk _ rt lk _ lk lk _ rk rk _ lt rk _ rt rk _ lk rk _ rk ãã ãã lt ã¯å·Šè
ã§ãã³, rt ã¯å³è
ã§ãã³, lk ã¯å·Šè
ã§ã³ã, rk ã¯å³è
ã§ã³ãã®åäœã衚ããŸãã äŸãã°ã lt _ rk ã¯å·Šè
ã§ãã³ã®ããšã«å³è
ã§ã³ããè¡ã£ãæã®ç²ŸåºŠã®å®å®ã®åºŠåãã衚ãããã®å€ã«ãã£ãŠå·Šè
ã§ãã³ã®ããšã«å³è
ã§ã³ããè¡ããšãã®ç²ŸåºŠããäžèšã®ããã«å€åããŸãã ãã¬ã€ã€ãŒã®ç²ŸåºŠ = max(0, (粟床ã®å®å®ç - 10) * 10 + äžã€åã®ç²ŸåºŠ) (%) æ²ã®æ
å ±ã¯ä»¥äžã®ãšããã§ãã æ²ã®é·ãã衚ã L ãèé¢ã衚ã L åã®æ°å s i (0 †i < L )ã§ç€ºããããèé¢ã®å
é 㯠s 0 ã§ããã s i ã®å€ã¯ä»¥äžã®3ã€ã§ãã 0 ... ããŒããªã 1 ... ãã³ 2 ... ã³ã ãã¬ã€ã€ãŒãæåã«å倪éŒãå©ããšãã®ç²ŸåºŠã¯100%ã§ãã ãŸãããã¬ã€ã€ãŒã¯èé¢ãç¡èŠããããšãã§ããŸãã ããŒãããªãã£ãããããŒããç¡èŠããå Žåããã¬ã€ã€ãŒã®ç²ŸåºŠã¯100%ã«ãªããŸãã åããŒãã«åãããŠå倪éŒãå©ãããšãã®åŸç¹ã¯äžèšã®ããã«ãªããŸãã åŸç¹ = A + B * min(ã³ã³ãæ°, 10) ãã®åé¡ã«ãããã³ã³ãæ°ãšã¯ãé£ç¶ããŠããŒãã«åãããŠå倪éŒãå©ããæ°ã§ãã ãã¬ã€ã€ãŒãããŒãã«åãããŠå©ããå Žåãäžèšã®åŒãå
ã«åŸç¹ãå
¥ãããã®åŸã«ã³ã³ãæ°ã1å¢ããŸãã ããŒãã«åãããŠå倪éŒãå©ããªãã£ãå Žåãã³ã³ããéåããã³ã³ãæ°ã0ã«ãªããŸãã Input å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªããŸãã åããŒã¿ã»ããã¯ä»¥äžã®ãšããã§ãã lt _ lt lt _ rt lt _ lk lt _ rk rt _ lt rt _ rt rt _ lk rt _ rk lk _ lt lk _ rt lk _ lk lk _ rk rk _ lt rk _ rt rk _ lk rk _ rk L s 0 s 1 s 2 ⊠s L - 1 A B å
¥åã®çµããã¯è² ã®æŽæ°4ã€ãããªããŸãã Constraints å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºãããŸãã 0 < L †100 0 †粟床ã®å®å®ç †10 粟床ã®å®å®çã¯æŽæ° 0 < A , B †10000 A ãš B ã¯ãšãã«100ã®åæ° ããŒã¿ã»ããã®æ°ã¯100åä»¥äž Output åå
¥åã«å¯ŸããŠãã¯ãªã¢ã§ãã確çã1è¡ã§åºåããªããã ãã ããåºåã¯0.001以äžã®èª€å·®ãå«ãã§ãè¯ãã§ãã Sample Input 9 0 0 0 0 9 0 0 0 0 0 0 0 0 0 0 5 1 1 1 1 1 1000 500 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 5 1 0 2 0 1 1000 2000 3 8 6 10 0 1 6 8 10 2 4 7 8 6 6 8 19 2 2 0 2 2 0 2 1 0 1 2 0 1 2 0 1 0 2 2 200 100 -1 -1 -1 -1 Sample Output 0.3024000000 0.0000000000 0.5120000000 | 36,269 |
Problem E: è¡ãé§ããé ããŒãŽã¡çåœã«ã¯ããã¿ã¿æãšãããæãïŒçš®é¡ã®æ°æãæ®ãããŠããããã¿ã¿æã®æå€§ã®ç¹åŸŽã¯ã é
¢è±ã«ãã€ãããã«ãå
¥ããŠé£ã¹ãããšã§ãããã ããããæã¯ããã€ãããã«ã«é
¢è±ãå
¥ããŠé£ã¹ ãããããªïŒã€ã®æ°æããäºãã«ä»²è¯ããã£ãŠãããã¯ãããªãããã¿ã¿æãšãããæã¯ãäœçŸå¹Žã ã®æãããã£ãšããã¿åããç¶ããŠããã ãããªããæ¥ãããŒãŽã¡çã®ããšã«ãïŒã€ã®æ°æããå顿žãå±ãããããã«ãããšãã¿ã¿æã¯ãèª åãã¡ãæ®ããè¡ïŒ¡ãšè¡ïŒ¢ã®ããã ãçµã¶éã建èšããŠã»ããããããäžæ¹ã§ãããæããèªåãã¡ ãæ®ããè¡ïŒ£ãšè¡ïŒ€ã®ããã ãçµã¶éã建èšããŠã»ãããããã ïŒã€ã®æ°æãè¡çªããã®ãé²ãããããã¿ã¿æãéãéãšãããæãéãéã亀差ãããããšã¯ã§ã ãªãããŸããæè¡çãªå¶çŽã«ãããïŒã€ã®è¡ã®ããã ãäžçŽç·ã«çµã¶ãããªéãã建èšããããšã¯ã§ ããªããã€ãŸããå¿
èŠãªãã°è¡ïŒ¡ãšè¡ïŒ¢ãçŽæ¥éã§çµã°ãã«ãããã€ãã®ãã¿ã¿æã®è¡ãçµç±ããŠè¡ ãšè¡ïŒ¢ã鿥çã«çµã¶ããšã«ãªãã ããïŒãã¡ããããããæã®è¡ãçµç±ããŠã¯ãªããªãïŒããã® éããã¿ã¿æã®è¡ãçµã¶éã©ããã¯äº€å·®ããŠããŠããããè¡ïŒ£ãšè¡ïŒ€ã«ã€ããŠãåæ§ã§ããã éã建èšããã«ã¯ããã®é·ãã«æ¯äŸããã³ã¹ãããããããªã®ã§ãæ¡ä»¶ãã¿ããã€ã€ãã§ããã ã建 èšããéã®é·ãã®åèšãçããªãããã«ããããããŠãé·ãã®æå°å€ã¯ããã€ã«ãªãã ãããã Input N A N B x A ,1 y A ,1 x A ,2 y A ,2 . . . x A , N A y A , N A x B ,1 y B ,1 x B ,2 y B ,2 . . . x B , N B y B , N B å
¥åã®ïŒè¡ç®ã«ã¯ãæŽæ° N A ïŒ2 †N A †1,000ïŒãšæŽæ° N B ïŒ2 †N B †1,000ïŒãã空çœåºåãã§æžãããŠãããããã¯ãããŒãŽã¡çåœã«ã¯ãã¿ã¿æãæ®ããè¡ãNA åããããæãæ®ããè¡ãNB åããããšããããããåæç¶æ
ã§ã¯ãã©ãã«ãéã¯å»ºèšãããŠããªãã ç¶ã N A è¡ã«ã¯ãæŽæ° x A,i ïŒ-10,000 †x A,i †10,000ïŒãšæŽæ° y A,i ïŒ-10,000 †y A,i †10,000ïŒãã空çœåºåãã§æžãããŠãããããŒãŽã¡çåœã®å°çã¯ïŒæ¬¡å
çŽäº€åº§æšå¹³é¢ã§ããããããïŒïŒ i è¡ç®ã«æžãããæŽæ° x A,i ãš y A,i ã¯ããã¿ã¿æãæ®ããi çªç®ã®è¡ã®äœçœ®åº§æšã( x A,i , y A,i ) ã§ããããšãããããã( x A,1 , y A,1 ) ãš( x A,2 , y A,2 ) ããçµã¶ã¹ãïŒã€ã®è¡ã®åº§æšã§ããã ç¶ã N B è¡ã«ã¯ãæŽæ° x B,i ïŒ-10,000 †x B,i †10,000ïŒãšæŽæ° y B,i ïŒ-10,000 †y B,i †10,000ïŒãã空çœåºåãã§æžãããŠãããïŒïŒ N A ïŒ i è¡ç®ã«æžãããæŽæ° x B,i ãš y B,i ã¯ããããæãæ®ããi çªç®ã®è¡ã®äœçœ®åº§æšã( x B,i , y B,i ) ã§ããããšãããããã( x B,1 , y B,1 ) ãš( x B,2 , y B,2 ) ããçµã¶ã¹ãïŒã€ã®è¡ã®åº§æšã§ããã ã©ã®ïŒã€ã®è¡ã®åº§æšãç°ãªã£ãŠãããã©ã®ïŒã€ã®è¡ãåäžçŽç·äžã«ãªããšä»®å®ããŠããã Output åé¡æã®æ¡ä»¶ãã¿ããããã«éã建èšãããšããéã®é·ãã®åèšã®æå°å€ãåºåãããããã§èšã ãé·ãããšã¯ããŠãŒã¯ãªããè·é¢ã®ããšã§ããããã ããã©ããã£ãŠãæ¡ä»¶ãã¿ããéã建èšã§ã㪠ããšãã¯ã代ããã«-1 ãåºåãããåºåã¯èª€å·®ãå«ãã§ããŠãããããçã®å€ãšã®çžå¯Ÿèª€å·®ã10 -9 æªæºã§ãªããã°ãªããªãã Sample Input 1 2 2 0 0 1 1 2 0 2 -1 Sample Output 1 2.414213562373 Sample Input 2 2 3 4 0 0 0 2 3 2 -2 3 1 Sample Output 2 -1 Sample Input 3 5 2 -2 1 1 2 -1 3 -1 5 1 4 0 4 0 0 Sample Output 3 12.359173603117 | 36,270 |
Score : 300 points Problem Statement There are N integers a_1, a_2, ..., a_N not less than 1 . The values of a_1, a_2, ..., a_N are not known, but it is known that a_1 \times a_2 \times ... \times a_N = P . Find the maximum possible greatest common divisor of a_1, a_2, ..., a_N . Constraints 1 \leq N \leq 10^{12} 1 \leq P \leq 10^{12} Input Input is given from Standard Input in the following format: N P Output Print the answer. Sample Input 1 3 24 Sample Output 1 2 The greatest common divisor would be 2 when, for example, a_1=2, a_2=6 and a_3=2 . Sample Input 2 5 1 Sample Output 2 1 As a_i are positive integers, the only possible case is a_1 = a_2 = a_3 = a_4 = a_5 = 1 . Sample Input 3 1 111 Sample Output 3 111 Sample Input 4 4 972439611840 Sample Output 4 206 | 36,271 |
E: 鬌çããæã - Unbalanced Old Maid - ç©èª é«åãããšåç°ãããšåããã¯åäŸã®é ããã®ä»²è¯ã3人çµã ã3äººã¯æ²çžã«ä¿®åŠæ
è¡ã«è¡ãããå°é¢šãæ¥ãŠããŸããæµ·ã§éã¶ããšãã§ããªãã®ã§ããæããããããšã«ããã åç°ããã¯åè² äºã«ã¯åŒ·ãããããŒã«ãŒãã§ã€ã¹ãèŠæãªãããèªåã®ã«ãŒããåŒããããšãã«ç¡æèã«ããããããé¡èžãæ«é²ããŠããŸããåç°ãããæããŠæ¢ãŸãªãé«åãããšåããã¯ãåç°ããã®é¡èžãèŠãã ãã§åç°ããã®ææãåãã£ãŠããŸããããåç°ããã®ã«ãŒããåŒããšãã¯ãèªåãæå©ã«ãªãããã«åŒãããšãã§ããã äžæ¹ãé«åãããšåããã¯ç¹ã«é¡èžããããã¯ããªãã®ã§ãææãã°ããããšã¯ãªãã ãã£ãŠãé«åãããšåããã®ã«ãŒããåŒã人ã¯ãããããé«åãããšåãããæã£ãŠããã«ãŒãã®äžããç確çã§1æåŒãã ã©ãèããŠãäžå©ãªåç°ããã¯ãããæãã§ãªããªãåãŠãªãããšã«éåæãèŠããŠããã 䜿çšããã«ãŒãã®çš®é¡æ° n ãšåæã®ææãäžãããããšããåç°ãããè² ããšãªããªã確çãæ±ããŠããããã å顿 é«åãããåç°ãããåããã®3人ã¯ã以äžã®ç¶æ³ã§ããæããè¡ãã 䜿çšããã«ãŒãã¯ã1ãã n ãŸã§ã®æŽæ°ãæžããã n çš®é¡ã®ã«ãŒããããã4æãã€ãšãžã§ãŒã«ãŒ1æã®åèš 4n+1 æã§ããã æåã®ææãäžãããããšãã3人ã¯ããããèªåã®ææã«åäžã®æŽæ°ãæžãããã«ãŒãã®ãã¢ïŒ2æçµïŒããããªãã°ããã®ãããªãã¢ãå
šãŠæšãŠãã 3人ã¯ãé«åãããåããã®ææããã«ãŒããåŒããããåç°ãããé«åããã®ææããã«ãŒããåŒãããåãããåç°ããã®ææããã«ãŒããåŒãããšããé çªïŒã¿ãŒã³ïŒã§ä»¥äžã®æäœãç¹°ãè¿ããïŒãã®ããæãã§ã¯ãã«ãŒããåŒãã人ããæ¬¡ã«åŒããããšããã«ãŒã«ã§ããããšã«æ³šæãããïŒ äžäººããžã§ãŒã«ãŒã®ã¿ãæã¡ããã®äººä»¥å€ã®2äººã®ææã空ã®ãšããããæãã¯çµäºãããžã§ãŒã«ãŒãæã£ãŠãã人ãè² ããšãªãã ã«ãŒããåŒãé çªã®äººã®ææã空ã®ãšããã¿ãŒã³ã次ã®äººãšãã1.ã«æ»ãã ããã§ãªããã°ãã«ãŒããåŒãé çªã®äººã¯æ±ºããããçžæããã«ãŒãã1æåŒãããã ããçžæã®ææã空ã®ãšãããŸã æ®ã£ãŠãããã1人ããã«ãŒããåŒãã åŒããã«ãŒããšåãæŽæ°ãæžãããã«ãŒããã«ãŒããåŒããäººã®ææã«ããã°ããã®2æãæšãŠãã ã¿ãŒã³ã次ã®äººãšãã1.ãžæ»ãã ãã ããåç°ããã®ã«ãŒããåŒã人ïŒåãããé«åããïŒã¯ã以äžã®æŠç¥ã§ã«ãŒãåŒãã ããèªåã®ã«ãŒããšåç°ããã®ã«ãŒãã§åãæŽæ°ãæžãããã«ãŒããããã°ããããã®ãã¡æå°ã®æŽæ°ãæžãããã«ãŒããåŒã ããã§ãªããšããåç°ããããžã§ãŒã«ãŒã§ãªãã«ãŒããæã£ãŠããã°ããããã®ãã¡æå°ã®æŽæ°ãæžãããã«ãŒããåŒã ããã§ãªããªããåç°ããã¯ãžã§ãŒã«ãŒããæã£ãŠããªãã®ã§ããžã§ãŒã«ãŒãåŒã é«åãããšåããã®ã«ãŒããåŒã人ã¯ãããããé«åãããšåãããæã£ãŠããã«ãŒãã®äžããç確çã§1æåŒãã 䜿çšããã«ãŒãã®çš®é¡æ° n ãš3人ã®åæã®ææãäžãããããšããåç°ãããè² ããšãªããªã確çãæ±ããŠããããã å
¥ååœ¢åŒ å
¥åã¯4è¡ãããªãã以äžã®åœ¢åŒã§äžããããã n m_1 c_{1,1} ... c_{1,m_1} m_2 c_{2,1} ... c_{2,m_2} m_3 c_{3,1} ... c_{3,m_3} 1è¡ç®ã«ãžã§ãŒã«ãŒä»¥å€ã®ã«ãŒãã®çš®é¡æ° n ãäžããããã ç¶ãå
¥åã¯3è¡ãããªãã2è¡ç®ã«é«åããã®ææã3è¡ç®ã«åç°ããã®ææã4è¡ç®ã«åããã®ææã®æ
å ±ãäžããããã i+1 (1 †i †3) è¡ç®ã§ã¯è¡é ã«ææã¡ã®ææ° m_i ãç¶ããŠææã¡ã®ã«ãŒãã衚ã m_i åã®æŽæ° c_{i,j} (1 †j †m_i) ã空çœåºåãã§äžããããã 0 ã¯ãžã§ãŒã«ãŒã 1 ãã n ã¯ã«ãŒãã«æžãããæŽæ°ã衚ãã å¶çŽ 1 †n †100 m_1+m_2+m_3 = 4n+1 3äººã®ææã§0ã¯ã¡ããã©1ã€ã 1 ãã n ã¯ã¡ããã©4åãã€çŸãã 0 †c_{i,j} †n ( 1 †i †3 , 1 †j †m_i ) åºååœ¢åŒ åç°ãããè² ããšãªããªã確çã1è¡ã«åºåãããçãã«ã¯ 10^{â6} ãè¶
ãã絶察誀差ããã£ãŠã¯ãªããªãã å
¥åäŸ1 1 1 1 3 0 1 1 1 1 åºåäŸ1 0.0 é«åãããåããã®ã«ãŒã1ãåŒããé«åãããšåããã¯ææã空ã«ãªãã åç°ããã¯ã©ãããŠãåã€ããšã¯ã§ããªãã å
¥åäŸ2 1 2 1 1 1 1 2 0 1 åºåäŸ2 0.5 ã¯ããã®é«åããã®ã¿ãŒã³ã¯ãé«åããã®ææãæ¢ã«ç©ºãªã®ã§äœãããªããæ¬¡ã®åç°ããã®ã¿ãŒã³ã§ã¯ãåç°ããã¯åããã®ææã®ãã¡ãããã0.5ã®ç¢ºçã§ã«ãŒã1ããžã§ãŒã«ãŒãåŒããã«ãŒã1ãåŒãããšããåç°ããã®ææã¯ç©ºãšãªãåå©ãããäžæ¹ãžã§ãŒã«ãŒãåŒãããšãã¯ã次ã®åããã®ã¿ãŒã³ã§ãåããã¯ç¢ºå®ã«ã«ãŒã1ãåŒãã®ã§åç°ãããè² ããšãªãã å
¥åäŸ3 2 3 0 1 2 3 1 2 2 3 1 1 2 åºåäŸ3 0.5 å
¥åäŸ4 2 2 0 1 6 2 2 2 1 1 1 1 2 åºåäŸ4 0.6666666667 | 36,272 |
Problem F: Cleaning Robot 2.0 Dr. Asimov, a robotics researcher, released cleaning robots he developed (see Problem B). His robots soon became very popular and he got much income. Now he is pretty rich. Wonderful. First, he renovated his house. Once his house had 9 rooms that were arranged in a square, but now his house has N à N rooms arranged in a square likewise. Then he laid either black or white carpet on each room. Since still enough money remained, he decided to spend them for development of a new robot. And finally he completed. The new robot operates as follows: The robot is set on any of N à N rooms, with directing any of north, east, west and south. The robot detects color of carpets of lefthand, righthand, and forehand adjacent rooms if exists. If there is exactly one room that its carpet has the same color as carpet of room where it is, the robot changes direction to and moves to and then cleans the room. Otherwise, it halts. Note that halted robot doesn't clean any longer. Following is some examples of robot's movement. Figure 1. An example of the room In Figure 1, robot that is on room (1,1) and directing north directs east and goes to (1,2). robot that is on room (0,2) and directing north directs west and goes to (0,1). robot that is on room (0,0) and directing west halts. Since the robot powered by contactless battery chargers that are installed in every rooms, unlike the previous robot, it never stops because of running down of its battery. It keeps working until it halts. Doctor's house has become larger by the renovation. Therefore, it is not efficient to let only one robot clean. Fortunately, he still has enough budget. So he decided to make a number of same robots and let them clean simultaneously. The robots interacts as follows: No two robots can be set on same room. It is still possible for a robot to detect a color of carpet of a room even if the room is occupied by another robot. All robots go ahead simultaneously. When robots collide (namely, two or more robots are in a single room, or two robots exchange their position after movement), they all halt. Working robots can take such halted robot away. On every room dust stacks slowly but constantly. To keep his house pure, he wants his robots to work so that dust that stacked on any room at any time will eventually be cleaned. After thinking deeply, he realized that there exists a carpet layout such that no matter how initial placements of robots are, this condition never can be satisfied. Your task is to output carpet layout that there exists at least one initial placements of robots that meets above condition. Since there may be two or more such layouts, please output the K -th one lexicographically. Input Input file contains several data sets. One data set is given in following format: N K Here, N and K are integers that are explained in the problem description. The end of input is described by a case where N = K = 0. You should output nothing for this case. Output Print the K -th carpet layout if exists, " No " (without quotes) otherwise. The carpet layout is denoted by N lines of string that each has exactly N letters. A room with black carpet and a room with white carpet is denoted by a letter ' E ' and ' . ' respectively. Lexicographically order of carpet layout is defined as that of a string that is obtained by concatenating the first row, the second row, ..., and the N -th row in this order. Output a blank line after each data set. Constraints Judge data consists of at most 100 data sets. 1 †N < 64 1 †K < 2 63 Sample Input 2 1 2 3 6 4 0 0 Output for the Sample Input .. .. No ..EEEE ..E..E EEE..E E..EEE E..E.. EEEE.. | 36,273 |
éå©èšç® éå©ã¯éè¡ã«é ããŠãããéã«ä»ãããã®èšç®æ¹æ³ãå©çã¯éè¡ã«ãã£ãŠæ§ã
ã§ãã婿¯ãšå
éãåããããã®ãå
å©ãšåŒã³ãŸãããå
å©ã®èšç®æ¹æ³ãšããŠã婿¯ãå
éã«çµã¿å
¥ããã«èšç®ãããåå©ããšå©æ¯ãå
éã«çµã¿å
¥ããŠèšç®ãããè€å©ããšãããã®ããããããå€ãã®å
å©ãåŸãããã«ã¯ãã®å·®ç°ãçè§£ããŠããªããã°ãªããŸãããå
å©ã®èšç®æ¹æ³ã¯ä»¥äžã®ããã«ãªããŸãã éè¡ã®æ°ããéãé ãã幎æ°ãåéè¡ã®æ
å ±ïŒéè¡çªå·ãéå©ã®çš®é¡ã幎å©çïŒããŒã»ã³ãïŒïŒãå
¥åãšããæãå
å©ãé«ããªãéè¡çªå·ãåºåããããã°ã©ã ãäœæããŠãã ããããã ããæãå
å©ãé«ããªãéè¡ã¯äžã€ã ãã§ãã å
¥å è€æ°ã®ããŒã¿ã»ãããäžããããŸããå
¥åã®çµããã¯ãŒãã²ãšã€ã§ç€ºãããŸããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããŸãã n y b 1 r 1 t 1 b 2 r 2 t 2 : b n r n t n 1è¡ç®ã«éè¡ã®æ° n (1 †n †50)ã2è¡ç®ã«ãéãé ããå¹Žæ° y (1 †y †30)ãäžããããŸããç¶ã n è¡ã« i çªç®ã®éè¡ã®éè¡çªå· b i ã幎å©çãè¡šãæŽæ° r i (1 †r i †100)ã éå©ã®çš®é¡ t i (1 ãŸã㯠2) ãäžããããŸããéå©ã®çš®é¡ t i ã¯ãåå©ã®å Žåã¯1ãè€å©ã®å Žåã¯2ã§äžããããŸãã ããŒã¿ã»ããã®æ°ã¯ 100 ãè¶
ããŸããã åºå ããŒã¿ã»ããããšã«ãæãå
å©ãé«ããªãéè¡çªå·ãïŒè¡ã«åºåããŸãã å
¥åäŸ 2 8 1 5 2 2 6 1 2 9 1 5 2 2 6 1 0 åºåäŸ 2 1 | 36,274 |
Score : 100 points Problem Statement Takahashi recorded his daily life for the last few days as a integer sequence of length 2N , as follows: a_1, b_1, a_2, b_2, ... , a_N, b_N This means that, starting from a certain time T , he was: sleeping for exactly a_1 seconds then awake for exactly b_1 seconds then sleeping for exactly a_2 seconds : then sleeping for exactly a_N seconds then awake for exactly b_N seconds In this record, he waked up N times. Takahashi is wondering how many times he waked up early during the recorded period. Here, he is said to wake up early if he wakes up between 4:00 AM and 7:00 AM, inclusive. If he wakes up more than once during this period, each of these awakenings is counted as waking up early. Unfortunately, he forgot the time T . Find the maximum possible number of times he waked up early during the recorded period. For your information, a day consists of 86400 seconds, and the length of the period between 4:00 AM and 7:00 AM is 10800 seconds. Constraints 1 \leq N \leq 10^5 1 \leq a_i, b_i \leq 10^5 a_i and b_i are integers. Input The 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 maximum possible number of times he waked up early during the recorded period. Sample Input 1 3 28800 57600 28800 57600 57600 28800 Sample Output 1 2 Sample Input 2 10 28800 57600 4800 9600 6000 1200 600 600 300 600 5400 600 6000 5760 6760 2880 6000 12000 9000 600 Sample Output 2 5 | 36,275 |
Score : 500 points Problem Statement Ibis is fighting with a monster. The health of the monster is H . Ibis can cast N kinds of spells. Casting the i -th spell decreases the monster's health by A_i , at the cost of B_i Magic Points. The same spell can be cast multiple times. There is no way other than spells to decrease the monster's health. Ibis wins when the health of the monster becomes 0 or below. Find the minimum total Magic Points that have to be consumed before winning. Constraints 1 \leq H \leq 10^4 1 \leq N \leq 10^3 1 \leq A_i \leq 10^4 1 \leq B_i \leq 10^4 All values in input are integers. Input Input is given from Standard Input in the following format: H N A_1 B_1 : A_N B_N Output Print the minimum total Magic Points that have to be consumed before winning. Sample Input 1 9 3 8 3 4 2 2 1 Sample Output 1 4 First, let us cast the first spell to decrease the monster's health by 8 , at the cost of 3 Magic Points. The monster's health is now 1 . Then, cast the third spell to decrease the monster's health by 2 , at the cost of 1 Magic Point. The monster's health is now -1 . In this way, we can win at the total cost of 4 Magic Points. Sample Input 2 100 6 1 1 2 3 3 9 4 27 5 81 6 243 Sample Output 2 100 It is optimal to cast the first spell 100 times. Sample Input 3 9999 10 540 7550 691 9680 700 9790 510 7150 415 5818 551 7712 587 8227 619 8671 588 8228 176 2461 Sample Output 3 139815 | 36,276 |
Counter-Clockwise For given three points p0, p1, p2 , print COUNTER_CLOCKWISE if p0, p1, p2 make a counterclockwise turn (1), CLOCKWISE if p0, p1, p2 make a clockwise turn (2), ONLINE_BACK if p2 is on a line p2, p0, p1 in this order (3), ONLINE_FRONT if p2 is on a line p0, p1, p2 in this order (4), ON_SEGMENT if p2 is on a segment p0p1 (5). Input x p0 y p0 x p1 y p1 q x p2 0 y p2 0 x p2 1 y p2 1 ... x p2 q-1 y p2 q-1 In the first line, integer coordinates of p0 and p1 are given. Then, q queries are given for integer coordinates of p2 . Output For each query, print the above mentioned status. Constraints 1 †q †1000 -10000 †x i , y i †10000 p0 and p1 are not identical. Sample Input 1 0 0 2 0 2 -1 1 -1 -1 Sample Output 1 COUNTER_CLOCKWISE CLOCKWISE Sample Input 2 0 0 2 0 3 -1 0 0 0 3 0 Sample Output 2 ONLINE_BACK ON_SEGMENT ONLINE_FRONT | 36,277 |
ã«ãŒãã³ ããããå€ããã£ãŠããïŒããªãã¯å€ã«åããŠéšå±ã®æš¡æ§æ¿ããããããšã«ããïŒä»å¹Žã®å€ã¯ãšãŠãæ¥å·®ãã匷ãããšãäºæ³ãããŠããïŒãŸã¶ããã®ãèŠæãªããªãã«ã¯èŸãå£ç¯ã«ãªãããã ïŒããã§ïŒããªãã¯éšå±ã®æããã調ç¯ããããã«ïŒéšå±ã®çªã«ã«ãŒãã³ãåãä»ããããšèããïŒ åãä»ããã«ãŒãã³ã¯é·æ¹åœ¢ã§ããïŒèŸºãå°é¢ã«å¯ŸããŠåçŽïŒãããã¯å¹³è¡ã§ããããã«åãä»ããïŒãŸãïŒããªãã®éšå±ã®çªã¯éåžžã«ç¹æ®ãªåœ¢ãããŠããïŒå蟺ãå°é¢ã«å¹³è¡ãŸãã¯åçŽã§ãããã㪠N è§åœ¢ã§è¡šãããïŒãã®ããïŒã«ãŒãã³ãåãä»ãããšãã«ã«ãŒãã³ã«èŠãããŠããªãçªã®é¢ç©ãã©ã®ãããã«ãªãã®ããæ±ããã®ã¯é£ããïŒéšå±ã®æããã調ç¯ããããã«ãïŒã«ãŒãã³ãåãä»ããäœçœ®ã決ããæã«ã©ã®ãããçªãèŠããããç¥ãããšã¯éèŠã§ããïŒããã§ïŒããªãã¯çªãšã«ãŒãã³ã®èšçœ®äœçœ®ãšåœ¢ç¶ãäžãããããšãã«ïŒã«ãŒãã³ã«èŠãããŠããªãçªã®é¢ç©ãæ±ããããã°ã©ã ãäœãããšã«ããïŒ äŸãšããŠæ¬¡ã®ãããªçªãšã«ãŒãã³ã®èšçœ®ã®ä»æ¹ãèããïŒãã®å Žåã¯ã«ãŒãã³ã«é ããŠããªãçªã®é¢ç©ã¯ 8 ãšãªãïŒãã®äŸã¯ãµã³ãã«å
¥åã® 3 ã±ãŒã¹ç®ã«å¯Ÿå¿ããïŒ Input å
¥åã¯è€æ°ããŒã¿ã»ãããããªãïŒ åããŒã¿ã»ããã¯æ¬¡ã®åœ¢åŒã§äžããããïŒ N x 1 y 1 : : x N y N a 1 b 1 a 2 b 2 a 3 b 3 a 4 b 4 æåã®è¡ã«ã¯çªã®æã€é ç¹æ°ãè¡šãæŽæ° N ãäžãããã ( 4 †N †100 )ïŒç¶ã N è¡ã«ã¯çªã®çžç°ãªãé ç¹ã®x座æšãè¡šãæŽæ° x i ãšy座æšãè¡šãæŽæ° y i ãäžãããã ( -20,000 †x i , y i †20,000, 1 †i †N )ïŒããã§ïŒyè»žã®æ£ã®åãã¯xè»žã®æ£ã®åããã90床ååæèšåãã«å転ãããæ¹åãšããïŒããã«ïŒç¶ã 4 è¡ã«ã¯ã«ãŒãã³ã®çžç°ãªãé ç¹ã®x座æšãè¡šãæŽæ° a j ãš y座æšãè¡šãæŽæ° b j ãäžãããã ( -20,000 †a j , b j †20,000, 1 †j †4 )ïŒçªïŒã«ãŒãã³ãšãã«ïŒããããã®é ç¹ã¯åæèšåãé ã«äžããããïŒãŸãïŒçªïŒã«ãŒãã³ã衚ãå³åœ¢ã¯ããããèªå·±äº€å·®ããªãå³åœ¢ã§ããïŒ å
¥åã®çµããã¯1ã€ã® 0 ãããªãè¡ã§ç€ºãïŒ Output åããŒã¿ã»ããã«ã€ããŠïŒã«ãŒãã³ã«èŠãããŠããªãçªã®é¢ç©ã 1 è¡ã«åºåããïŒãã ãïŒé¢ç©ã¯å¿
ãæŽæ°å€ã«ãªãããšã«æ³šæããïŒ Sample Input 4 0 0 10 0 10 10 0 10 0 0 5 0 5 10 0 10 6 0 0 10 0 10 5 5 5 5 10 0 10 2 0 8 0 8 10 2 10 12 1 1 1 3 -1 3 -1 1 -3 1 -3 -1 -1 -1 -1 -3 1 -3 1 -1 3 -1 3 1 2 2 -2 2 -2 -2 2 -2 4 20000 20000 -20000 20000 -20000 -20000 20000 -20000 1000 1000 -1000 1000 -1000 -1000 1000 -1000 4 1000 1000 -1000 1000 -1000 -1000 1000 -1000 20000 20000 -20000 20000 -20000 -20000 20000 -20000 4 0 0 10 0 10 10 0 10 20 0 30 0 30 10 20 10 0 Output for Sample Input 50 30 8 1596000000 0 100 | 36,278 |
Identically Colored Panels Connection Dr. Fukuoka has invented fancy panels. Each panel has a square shape of a unit size and has one of the six colors, namely, yellow, pink, red, purple, green and blue. The panel has two remarkable properties. One property is that, when two or more panels with the same color are placed adjacently, their touching edges melt a little and they are fused each other. The fused panels are united into a polygonally shaped panel. The other property is that the color of a panel can be changed to one of six colors by giving an electrical shock. The resulting color can be controlled by its waveform. The electrical shock to an already united panel changes the color of the whole to a specified single color. Since he wants to investigate the strength with respect to the color and the size of a united panel compared to unit panels, he tries to unite panels into a polygonal panel with a specified color. Figure C-1: panels and their initial colors Since many panels are simultaneously synthesized and generated on a base plate through some complex chemical processes, the fabricated panels are randomly colored and they are arranged in a rectangular shape on the base plate (Figure C-1). Note that the two purple (color 4) panels in Figure C-1 are already united at the initial state since they are adjacent to each other. Installing electrodes to a panel, and changing its color several times by giving electrical shocks according to an appropriate sequence for a specified target color, he can make a united panel merge the adjacent panels to unite them step by step and can obtain a larger panel with the target color. Unfortunately, panels will be broken when they are struck by the sixth electrical shock. That is, he can change the color of a panel or a united panel only five times. Let us consider a case where the panel at the upper left corner of the panel configuration (Figure C-1) is attached with the electrodes. First, changing the color of the panel from yellow to blue, the two adjacent panels are fused into a united panel (Figure C-2). Figure C-2: Change of the color of the panel at the upper left corner, from yellow (color 1) to blue (color 6). Second, changing the color of the upper left united panel from blue to red, a united red panel that consists of three unit panels is newly formed (Figure C-3). Then, changing the color of the united panel from red to purple, panels are united again to form a united panel of five unit panels (Figure C-4). Figure C-3: Change of the color of the panel at the upper left corner, from blue (color 6) to red (color 3). Figure C-4: Change of the color of the panel at the upper left corner, from red (color 3) to purple (color 4). Furthermore, through making a pink united panel in Figure C-5 by changing the color from purple to pink, then, the green united panel in Figure C-6 is obtained by changing the color from pink to green. The green united panel consists of ten unit panels. Figure C-5: Change of the color of the panel at the upper left corner, from purple (color 4) to pink (color 2). Figure C-6: Change of the color of the panel at the upper left corner, from pink (color 2) to green (color 5). In order to check the strength of united panels with various sizes and colors, he needs to unite as many panels as possible with the target color. Your job is to write a program that finds a sequence to change the colors five times in order to get the largest united panel with the target color. Note that the electrodes are fixed to the panel at the upper left corner. Input The input consists of multiple datasets, each being in the following format. h w c p 1,1 p 1,2 ... p 1, w p 2,1 p 2,2 ... p 2, w ... p h ,1 p h ,2 ... p h , w h and w are positive integers no more than 8 that represent the height and the width of the given rectangle. c is a positive integer no more than 6 that represents the target color of the finally united panel. p i , j is a positive integer no more than 6 that represents the initial color of the panel at the position ( i , j ). The end of the input is indicated by a line that consists of three zeros separated by single spaces. Output For each dataset, output the largest possible number of unit panels in the united panel at the upper left corner with the target color after five times of color changes of the panel at the upper left corner. No extra characters should occur in the output. Sample Input 3 5 5 1 6 3 2 5 2 5 4 6 1 1 2 4 1 5 4 5 6 1 5 6 1 2 1 4 6 3 2 1 5 2 3 2 1 1 2 3 2 1 1 5 1 1 8 6 1 2 3 4 5 1 2 3 8 1 1 1 2 3 4 5 1 2 3 8 8 6 5 2 5 2 6 5 4 2 4 2 2 2 5 2 2 2 4 4 4 2 5 2 2 2 6 4 5 2 2 2 6 6 6 6 5 5 2 2 6 6 6 2 5 4 2 2 6 6 2 4 4 4 6 2 2 6 2 2 2 5 5 2 2 2 8 8 2 3 3 5 4 1 6 2 3 2 3 6 4 3 6 2 2 4 1 6 6 6 4 4 4 2 5 3 6 3 6 3 5 3 1 3 4 1 5 6 3 1 6 6 3 5 1 5 3 2 4 2 2 2 6 5 3 4 1 3 6 1 5 5 4 0 0 0 Output for the Sample Input 10 18 1 5 6 64 33 | 36,279 |
Score : 400 points Problem Statement Akari has n kinds of flowers, one of each kind. She is going to choose one or more of these flowers to make a bouquet. However, she hates two numbers a and b , so the number of flowers in the bouquet cannot be a or b . How many different bouquets are there that Akari can make? Find the count modulo (10^9 + 7) . Here, two bouquets are considered different when there is a flower that is used in one of the bouquets but not in the other bouquet. Constraints All values in input are integers. 2 \leq n \leq 10^9 1 \leq a < b \leq \textrm{min}(n, 2 \times 10^5) Input Input is given from Standard Input in the following format: n a b Output Print the number of bouquets that Akari can make, modulo (10^9 + 7) . (If there are no such bouquets, print 0 .) Sample Input 1 4 1 3 Sample Output 1 7 In this case, Akari can choose 2 or 4 flowers to make the bouquet. There are 6 ways to choose 2 out of the 4 flowers, and 1 way to choose 4 , so there are a total of 7 different bouquets that Akari can make. Sample Input 2 1000000000 141421 173205 Sample Output 2 34076506 Print the count modulo (10^9 + 7) . | 36,280 |
æ ç»åã®äžããæçãªæ
å ±ãæœåºããç»åèªèã¯ã³ã³ãã¥ãŒã¿ãµã€ãšã³ã¹ã®äžã§ãéèŠãªç ç©¶ããŒãã®ã²ãšã€ã§ããããžã¿ã«ã«ã¡ã©ãéè»¢æ¯æŽã·ã¹ãã ãé²ç¯ã·ã¹ãã ãªã©ã«å¹
åºãå¿çšãããŠããŸãã ãã®ãããªç ç©¶ã®ãããã§ãç§ãã¡ã¯ç»åè§£æãè¡ãããã®å€ãã®ãœãããŠã§ã¢ãããã°ã©ã éãäœ¿ãæ§ã
ãªåŠçãè¡ãããšãã§ããŸããäžæ¹ãèªåã§ããã°ã©ã ãæžããŠè§£æããããšã§ããã®ä»çµã¿ãç¥ããæ¥œããæéãéããããšãã§ããŸããããã§ã¯ãäžé¢šå€ãã£ãç»åèªèãããŠã¿ãŸãããã ç»åãšããŠæ¬¡ã®ãããªåãã¯ã»ã«ãæŽæ°ã®å€ãæã€ N à N ã®ãã¯ã»ã«ãå
¥åãšããŠäžããããŸãããã®ç»åã®äžãããç·ã®å€ªããïŒãã¯ã»ã«ã®é·æ¹åœ¢ã®æ ïŒããïŒãïŒã€æœåºããŸãã æ ãèŠããã¯ã»ã«ã®å€ã®åãæå€§ãšãªããããªæ ãæœåºããŠããã®åãå ±åããããã°ã©ã ãäœæã㊠äžããããã ããäžã®å³ã®ããã«ãçžŠãæšªã®ãã¯ã»ã«æ°ãïŒã€ãïŒã€ã®å Žåãæ ãšã¿ãªããã®ãšããŸãã å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§äžããããã N p 1,1 p 1,2 ... p 1,N p 2,1 p 2,2 ... p 2,N : p N,1 p N,2 ... p N,N ïŒè¡ç®ã«çžŠãšæšªã®ãã¯ã»ã«æ° N (1 †N †300) ãäžãããããç¶ã N è¡ã«ã i è¡ j åç®ã®ãã¯ã»ã«ã®å€ãè¡šãæŽæ° p i,j (-1000 †p i,j †1000)ãäžããããã åºå ãã¯ã»ã«å€ã®åãæå€§ãšãªããããªæ ã®ããã¯ã»ã«å€ã®åãïŒè¡ã«åºåããã å
¥åºåäŸ å
¥åäŸïŒ 5 2 0 0 2 0 0 1 0 2 0 0 0 0 -1 0 0 4 0 3 0 -1 0 0 1 0 åºåäŸïŒ 12 å
¥åäŸïŒ 3 0 0 0 0 -1 0 0 0 0 åºåäŸïŒ 0 | 36,281 |
Balls and Boxes 8 Balls Boxes Any way At most one ball At least one ball Distinguishable Distinguishable 1 2 3 Indistinguishable Distinguishable 4 5 6 Distinguishable Indistinguishable 7 8 9 Indistinguishable Indistinguishable 10 11 12 Problem You have $n$ balls and $k$ boxes. You want to put these balls into the boxes. Find the number of ways to put the balls under the following conditions: Each ball is distinguished from the other. Each box is not distinguished from the other. Each ball can go into only one box and no one remains outside of the boxes. Each box can contain at most one ball. Note that you must print this count modulo $10^9+7$. Input $n$ $k$ The first line will contain two integers $n$ and $k$. Output Print the number of ways modulo $10^9+7$ in a line. Constraints $1 \le n \le 1000$ $1 \le k \le 1000$ Sample Input 1 5 10 Sample Output 1 1 Sample Input 2 200 100 Sample Output 2 0 | 36,282 |
Score : 800 points Problem Statement You are given a string S consisting of lowercase English letters. Determine whether we can turn S into a palindrome by repeating the operation of swapping two adjacent characters. If it is possible, find the minimum required number of operations. Constraints 1 \leq |S| \leq 2 Ã 10^5 S consists of lowercase English letters. Input Input is given from Standard Input in the following format: S Output If we cannot turn S into a palindrome, print -1 . Otherwise, print the minimum required number of operations. Sample Input 1 eel Sample Output 1 1 We can turn S into a palindrome by the following operation: Swap the 2 -nd and 3 -rd characters. S is now ele . Sample Input 2 ataatmma Sample Output 2 4 We can turn S into a palindrome by the following operation: Swap the 5 -th and 6 -th characters. S is now ataamtma . Swap the 4 -th and 5 -th characters. S is now atamatma . Swap the 3 -rd and 4 -th characters. S is now atmaatma . Swap the 2 -nd and 3 -rd characters. S is now amtaatma . Sample Input 3 snuke Sample Output 3 -1 We cannot turn S into a palindrome. | 36,283 |
Score : 100 points Problem Statement Let N be a positive integer. You are given a string s of length N - 1 , consisting of < and > . Find the number of permutations (p_1, p_2, \ldots, p_N) of (1, 2, \ldots, N) that satisfy the following condition, modulo 10^9 + 7 : For each i ( 1 \leq i \leq N - 1 ), p_i < p_{i + 1} if the i -th character in s is < , and p_i > p_{i + 1} if the i -th character in s is > . Constraints N is an integer. 2 \leq N \leq 3000 s is a string of length N - 1 . s consists of < and > . Input Input is given from Standard Input in the following format: N s Output Print the number of permutations that satisfy the condition, modulo 10^9 + 7 . Sample Input 1 4 <>< Sample Output 1 5 There are five permutations that satisfy the condition, as follows: (1, 3, 2, 4) (1, 4, 2, 3) (2, 3, 1, 4) (2, 4, 1, 3) (3, 4, 1, 2) Sample Input 2 5 <<<< Sample Output 2 1 There is one permutation that satisfies the condition, as follows: (1, 2, 3, 4, 5) Sample Input 3 20 >>>><>>><>><>>><<>> Sample Output 3 217136290 Be sure to print the number modulo 10^9 + 7 . | 36,284 |
Princess' Marriage ãå§«æ§ã®å«å
¥ã English text is not available in this practice contest. ããè²§ä¹ãªåœã®ããŠãã°ã§åæ¢ãªãå§«æ§ã¯ïŒã®ã£ã³ãã«ã®é
åœãããªãã¥ãã¥ãšã«æ¹åŒã§æ±ºå®ãããäºãç¥ãããšã«ããïŒã®ã£ã³ãã«ã«ã€ããŠè©³ãããªã£ãæ°ãããŠã®ã£ã³ãã«ã§ã®åå©ã確信ããïŒãã®çµæïŒä»ãŸã§ãããæŽã«å€é¡ã®ãéãã€ã蟌ã¿ïŒåœæ°ãçŽããçšéããã¹ãŠå€±ãã»ã©ã®è² ããå«ããŠããŸã£ãïŒãã®äºæ
ãéãåãæ¢ããçæ§ã¯ïŒãå§«æ§ãé£ã®åœãžå«ãããããšã«ããïŒããããããšã«ããïŒãå§«æ§ãæ¥é ã®è¡ããåçããïŒåæã«é£åœãšã®äº€åãæ·±ããŠè²¡æ¿æŽå©ãããŠãããããšèããããã§ããïŒ ãå§«æ§ãšé£åœã®çåæ§ã¯ãäºãã®äºãæ°ã«å
¥ãïŒãŸãäž¡åœã®çæ§éã§ãæ¿ç¥çµå©ã«é¢ããåæããªãããïŒãå§«æ§ã¯ãªããªãã®ãéãæã«ææ°æã
ãšé£ã®åœãžåºãããïŒäžæ¹ã§ïŒãå§«æ§ãå«ãåæ©ã¯çæ§ã®äžæ¹çãªå©ç远åã®ããã§ããïŒå¿«ããªããšèããé£åœã®çåæ§ã®åŽè¿ã¯ïŒãå§«æ§ã亡ãè
ã«ããããã«éã®éäžã«ç¡æ°ã®åºå®¢éãæŸã£ãïŒ ãå§«æ§ãéãéã¯ãã§ã«æ±ºããããŠããïŒãå§«æ§ã®éãéã«ã¯åèš L åã®å®¿å ŽãããïŒäŸ¿å®äžïŒåºçºå°ç¹ããã³å°çå°ç¹ãå®¿å ŽãšãïŒåå®¿å Žã S 1 , S 2 , ... S L ãšåŒã¶ããšã«ããïŒãå§«æ§ã¯æåã« S 1 ã«ããïŒæé ã« ( S 2 , S 3 ... ãšããé çªã§) å®¿å Žã蚪ããŠïŒæçµçã« S L ãžè¡ããã®ãšããïŒå®¿å Žã§ã¯ééãæã£ãŠè·è¡ãéãããšãã§ãïŒãéãããéã奜ããªè·é¢ã ãå¥çŽããŠãå§«æ§ãå®ãããããšãã§ããïŒè·è¡ãéãè²»çšã¯ïŒè·é¢1ã«ã€ãé1ã§ããïŒãå§«æ§ã¯éãåºéå
ãéšåçã«å®ã£ãŠãããããšãåºæ¥ãããšã«æ³šæããïŒ S i ãš S i+1 éã®è·é¢ã¯ D i ïŒ S i ãš S i+1 éã§è·é¢1ã«ã€ãåºå®¢ã«è¥²ãããåæ°ã®æåŸ
å€ã¯ P i ã§äžããããŠããïŒ ãå§«æ§ãäºç® M ãæã£ãŠããŠïŒåºå®¢ã«è¥²ãããåæ°ã®æåŸ
å€ãæå°ã«ãªãããã«è·è¡ãéã£ããšãã®ïŒç®çå°ãŸã§ã«åºå®¢ã«è¥²ãããåæ°ã®æåŸ
å€ãæ±ããïŒ Input å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒåããŒã¿ã»ããã¯ä»¥äžã®ãããªåœ¢åŒããšãïŒ N M D 1 P 1 D 2 P 2 ... D N P N åããŒã¿ã»ããã®æåã®è¡ã«ã¯äºã€ã®æŽæ°ãäžãããïŒããããåºéã®æ° N (1⊠N âŠ10,000) ãšïŒãå§«å·®ãæã€äºç® M (0⊠M âŠ1,000,000,000) ã衚ãïŒæ¬¡ã® N è¡ã¯ãå§«æ§ãéãéã®æ
å ±ã衚ãïŒåè¡ã¯äºã€ã®æŽæ°ãå«ãŸããŠããïŒ i è¡ç®ã¯åºéã®è·é¢ D i (1⊠D i âŠ10,000) ãšãã®éãïŒåäœè·é¢ç§»åãããšãã«è¥²ãããåæ°ã®æåŸ
å€ P i (0⊠P i <=10) ãããªãïŒ å
¥åã®çµç«¯ã¯ N =0, M =0 ãšãªãããŒã¿ã»ããã§ããããããïŒãã®ããŒã¿ã»ããã«å¯ŸããŠã¯èšç®çµæãåºåããŠã¯ãªããªãïŒ Output åããŒã¿ã»ããæ¯ã«ïŒãå§«æ§ãç®çå°ãŸã§ã«åºå®¢ã«è¥²ãããåæ°ã®æåŸ
å€ãåºåããïŒ Sample Input 2 8 5 6 4 5 3 1 5 10 5 10 5 10 0 0 Output for the Sample Input 5 140 | 36,285 |
You Are the Judge 審å€ã¯åã ïŒ English text is not available in this practice contest. ããªãã¯ããã°ã©ãã³ã°ã³ã³ãã¹ã iCPC ã®å¯©å€ã ã仿¥ãäœäºããªã詊åãçµãããåŸã¯çµæãåºåããã ãã ãšæããããçªç¶ã·ã¹ãã ã忢ããŠããŸã£ãïŒ ããã§ã¯çµæãåºåã§ããªãïŒ ã§ãã倧äžå€«ãæã
ã«ã¯ãã°ãããã ããªãã¯åªããããã°ã©ããŒã§ããããã€ãŠ iCPC ã§èŒãããæçžŸãæ®ããããšãããã ããã§ããªãã¯ã·ã¹ãã ãã°ããåããŒã ã®æçžŸãå²ãåºããããŒã ã®é äœè¡šãåºåããããã°ã©ã ãäœæããããšã«ããã å
¥åãšããŠããŒã ã®æ°ãåé¡ã®æ°ãã·ã¹ãã ãã°ãäžããããã ã·ã ãã ãã°ã¯ä»¥äžã® 2 çš®é¡ã®ã¬ã³ãŒããããªãã ã¬ã³ãŒã å
容 广 tID pID time CORRECT æå» time ã«ãããŒã tID ã åé¡ pID ã«æ£è§£ããããã°ã©ã ãéä¿¡ã ããŒã tID ã®æ£è§£æ°ã«1ãå ç®ãããã ããŒã tID ã®ããã«ãã£ã«ã(ããŒã tID ã®åé¡ pID ã«å¯Ÿããèª€çæ°*1200+time)ãå ç®ãããã 以åŸ, ããŒã tID ã®åé¡ pID ã«å¯Ÿããè§£çã¯æ£åŽãããã·ã¹ãã ãã°ã«ãéä¿¡å±¥æŽãæ®ããªãã tID pID time WRONG æå» time ã«ãããŒã tID ã åé¡ pID ã«èª€çããããã°ã©ã ãéä¿¡ã ããŒã tID ã® åé¡ pID ã«å¯Ÿããèª€çæ°ã«1ãå ç®ãããã â»äžèšã®ã·ã¹ãã ãã°ã¯ãã®åé¡ã®ããã«ç°¡ç¥åããããã®ã§ãããæ¬çªã®ICPCã§èŠãããã·ã¹ãã ãã°ãšç°ãªãããšã«çæãã iCPCã«ãããé äœä»ãã®ã«ãŒã«ã¯ä»¥äžã®éãã§ããã ããå€ãã®åé¡ãè§£ããããŒã ã¯é äœãäžã«ãªã è§£ããåé¡ãåãå Žåãããã«ãã£ã®å°ãªãããŒã ã®ã»ããé äœãäžã«ãªã è§£ããåé¡ãããã«ãã£ãåãå ŽåãããŒã çªå·ãå°ããã»ãã®ããŒã ãé äœãäžã«ãªã å
¥åããäžããããã³ã³ãã¹ãã®æ
å ±ã»ã·ã¹ãã ãã°ããåããŒã ã®æçžŸãå²ãåºããããŒã ã®é äœè¡šãåºåããã Input å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªããåããŒã¿ã»ããã¯ä»¥äžã®åœ¢åŒã§äžããããã T P R tID 1 pID 1 time 1 message 1 tID 2 pID 2 time 2 message 2 ... tID R pID R time R message R ããŒã¿ã»ããã®1è¡ç®ã«ã¯ åå ããŒã æ° T ãå顿° Pãã·ã¹ãã ãã°ã®ã¬ã³ãŒãæ° R ãå«ãŸããã ç¶ãRè¡ã«ã¯ã·ã¹ãã ãã°ã®åã¬ã³ãŒããå«ãŸããã ã·ã¹ãã ãã°ã®ã¬ã³ãŒããšããŠãããŒã çªå· tID i ãåé¡çªå· pID i ã詊åéå§ããã®çµéæé time i ãã¡ãã»ãŒãžã®çš®é¡ message i ãå«ãŸããã å
¥åã¯ä»¥äžã®å¶çŽãæºããã 1 †T †50 1 †P †10 1 †R †500 1 †tID i †T 1 †pID i †P 1 †time i †10800 message i 㯠CORRECT, WRONGã®ãããã ã·ã¹ãã ãã°ã®ã¬ã³ãŒãã¯ãæå»ã®å°ãããã®ããé ã«äžããããè€æ°ã®ã¬ã³ãŒãã®æå»ãåãã«ãªãããšã¯ãªã å
¥åã®çµããã¯ã¹ããŒã¹ã§åºåããã3åã®0ã§äžããããã Output äžããããã·ã¹ãã ãã°ããåããŒã ã®æçžŸã»é äœãå²ãåºããé äœãäžã®ããŒã ããé ã«ãããŒã çªå·ãæ£è§£æ°ãããã«ã㣠ãåºåããã Sample Input 3 3 5 3 1 800 WRONG 1 1 1200 CORRECT 3 1 1400 CORRECT 1 2 2400 CORRECT 1 3 3600 CORRECT 5 2 5 3 1 1000 WRONG 5 2 2000 CORRECT 3 1 2800 CORRECT 4 1 4000 CORRECT 5 1 5000 CORRECT 6 3 15 2 1 10 WRONG 3 3 15 WRONG 3 3 20 CORRECT 1 1 50 CORRECT 4 2 60 WRONG 1 2 70 WRONG 4 1 80 CORRECT 1 2 90 WRONG 1 2 150 CORRECT 3 1 160 WRONG 3 1 180 CORRECT 3 2 210 WRONG 5 3 500 CORRECT 4 2 720 CORRECT 5 1 1500 CORRECT 0 0 0 Output for Sample Input 1 3 7200 3 1 2600 2 0 0 5 2 7000 3 1 4000 4 1 4000 1 0 0 2 0 0 4 2 2000 5 2 2000 1 2 2600 3 2 2600 2 0 0 6 0 0 | 36,287 |
Score : 200 points Problem Statement In some other world, today is the day before Christmas Eve. Mr. Takaha is buying N items at a department store. The regular price of the i -th item (1 \leq i \leq N) is p_i yen (the currency of Japan). He has a discount coupon, and can buy one item with the highest price for half the regular price. The remaining N-1 items cost their regular prices. What is the total amount he will pay? Constraints 2 \leq N \leq 10 100 \leq p_i \leq 10000 p_i is an even number. Input Input is given from Standard Input in the following format: N p_1 p_2 : p_N Output Print the total amount Mr. Takaha will pay. Sample Input 1 3 4980 7980 6980 Sample Output 1 15950 The 7980 -yen item gets the discount and the total is 4980 + 7980 / 2 + 6980 = 15950 yen. Note that outputs such as 15950.0 will be judged as Wrong Answer. Sample Input 2 4 4320 4320 4320 4320 Sample Output 2 15120 Only one of the four items gets the discount and the total is 4320 / 2 + 4320 + 4320 + 4320 = 15120 yen. | 36,288 |
Problem Statement Snuke loves colorful balls. He has a total of NÃK balls, K in each of his favorite N colors. The colors are numbered 1 through N . He will arrange all of the balls in a row from left to right, in arbitrary order. Then, for each of the N colors, he will paint the leftmost ball of that color into color 0 , a color different from any of the N original colors. After painting, how many sequences of the colors of the balls are possible? Find this number modulo 10^9+7 . Constraints 1â€N,Kâ€2,000 Input The input is given from Standard Input in the following format: N K Output Print the number of the possible sequences of the colors of the balls after painting, modulo 10^9+7 . Sample Input 1 2 2 Sample Output 1 4 The following 4 sequences are possible: (0,1,0,2) (0,0,1,2) (0,2,0,1) (0,0,2,1) Sample Input 2 3 1 Sample Output 2 1 The following 1 sequence is possible: (0,0,0) Sample Input 3 2 3 Sample Output 3 14 Sample Input 4 2000 2000 Sample Output 4 546381702 | 36,289 |
Score : 100 points Problem Statement Snuke is giving cookies to his three goats. He has two cookie tins. One contains A cookies, and the other contains B cookies. He can thus give A cookies, B cookies or A+B cookies to his goats (he cannot open the tins). Your task is to determine whether Snuke can give cookies to his three goats so that each of them can have the same number of cookies. Constraints 1 \leq A,B \leq 100 Both A and B are integers. Input Input is given from Standard Input in the following format: A B Output If it is possible to give cookies so that each of the three goats can have the same number of cookies, print Possible ; otherwise, print Impossible . Sample Input 1 4 5 Sample Output 1 Possible If Snuke gives nine cookies, each of the three goats can have three cookies. Sample Input 2 1 1 Sample Output 2 Impossible Since there are only two cookies, the three goats cannot have the same number of cookies no matter what Snuke gives to them. | 36,290 |
Score : 100 points Problem Statement We have two integers: A and B . Print the largest number among A + B , A - B , and A \times B . Constraints All values in input are integers. -100 \leq A,\ B \leq 100 Input Input is given from Standard Input in the following format: A B Output Print the largest number among A + B , A - B , and A \times B . Sample Input 1 -13 3 Sample Output 1 -10 The largest number among A + B = -10 , A - B = -16 , and A \times B = -39 is -10 . Sample Input 2 1 -33 Sample Output 2 34 The largest number among A + B = -32 , A - B = 34 , and A \times B = -33 is 34 . Sample Input 3 13 3 Sample Output 3 39 The largest number among A + B = 16 , A - B = 10 , and A \times B = 39 is 39 . | 36,291 |
Sixth Sense Ms. Future is gifted with precognition. Naturally, she is excellent at some card games since she can correctly foresee every player's actions, except her own. Today, she accepted a challenge from a reckless gambler Mr. Past. They agreed to play a simple two-player trick-taking card game. Cards for the game have a number printed on one side, leaving the other side blank making indistinguishable from other cards. A game starts with the same number, say $n$, of cards being handed out to both players, without revealing the printed number to the opponent. A game consists of $n$ tricks. In each trick, both players pull one card out of her/his hand. The player pulling out the card with the larger number takes this trick. Because Ms. Future is extremely good at this game, they have agreed to give tricks to Mr. Past when both pull out cards with the same number. Once a card is used, it can never be used later in the same game. The game continues until all the cards in the hands are used up. The objective of the game is to take as many tricks as possible. Your mission of this problem is to help Ms. Future by providing a computer program to determine the best playing order of the cards in her hand. Since she has the sixth sense, your program can utilize information that is not available to ordinary people before the game. Input The input consists of a single test case of the following format. $n$ $p_1$ ... $p_n$ $f_1$ ... $f_n$ $n$ in the first line is the number of tricks, which is an integer between 2 and 5000, inclusive. The second line represents the Mr. Past's playing order of the cards in his hand. In the $i$-th trick, he will pull out a card with the number $p_i$ ($1 \leq i \leq n$). The third line represents the Ms. Future's hand. $f_i$ ($1 \leq i \leq n$) is the number that she will see on the $i$-th received card from the dealer. Every number in the second or third line is an integer between 1 and 10 000, inclusive. These lines may have duplicate numbers. Output The output should be a single line containing $n$ integers $a_1 ... a_n$ separated by a space, where $a_i$ ($1 \leq i \leq n$) is the number on the card she should play at the $i$-th trick for maximizing the number of taken tricks. If there are two or more such sequences of numbers, output the lexicographically greatest one among them. Sample Input 1 5 1 2 3 4 5 1 2 3 4 5 Sample Output 1 2 3 4 5 1 Sample Input 2 5 3 4 5 6 7 1 3 5 7 9 Sample Output 2 9 5 7 3 1 Sample Input 3 5 3 2 2 1 1 1 1 2 2 3 Sample Output 3 1 3 1 2 2 Sample Input 4 5 3 4 10 4 9 2 7 3 6 9 Sample Output 4 9 7 3 6 2 | 36,292 |
åé¡ C ãããšã å顿 ãªããšãªãæã ã£ãã®ã§ãããšãã® AI ãäœã£ãŠ AI ãšãããšããããããšã«ããïŒãããšããšã¯ 2 人ã§éã¶ã²ãŒã ã§ïŒäž¡è
ã®éã§ãŸã äžåºŠãçºèšãããŠãããïŒ(æåã®æçªãé€ããŠ) å
é ã®æåãçŽåã®åèªã®æåŸã®æåãšãªã£ãŠããåèªã亀äºã«èšãåãã²ãŒã ã§ããïŒ ä»å AI ã«åèªã®å€å®ãå®è£
ããã®ãé¢åã ã£ãã®ã§ïŒåèªã®å®çŸ©ã¯ã¢ã«ãã¡ãããã®å°æåãããªãæååå
šãŠãšããïŒ ããã AI ã宿ãããããã§ãããšããããã®ã¯é¢åããããªã£ãŠããã®ã§ïŒããã°ã©ã ãæžããŠèªåã®ä»£ããã« AI ãšå¯ŸæŠãããããšã«ããïŒããã°ã©ã ãæžãã®ã¯è¯ãã®ã ãç®æšãç¡ãã®ã¯ã€ãŸããªãã®ã§ïŒãªãã¹ãæ©ã AI ã«åã€ããã°ã©ã ãæžãããšã«ããïŒããªãã¡ïŒãªãã¹ãå°ãªããããšãã§ AI ã«äžæ£ãªå¿çããããããã°ã©ã ãæžãã®ã§ããïŒ ãªãããã°ã©ã ãå
æã§ AI ãåŸæã§ããïŒ å
¥åºå ããã°ã©ã ã¯ãããšãã®åèªãçºèšãããšïŒAI ã®è¿çãèãããšãã§ããïŒ äŸãã° C/C++ ã§ abc ãšåèªãçºèšããã«ã¯ printf("?abc\n"); fflush(stdout); ãšããïŒæ¬¡ã«ïŒ scanf("%s", str); ãšãããš str ã« AI ã®è¿çãå
¥ãïŒ æçµçã« AI ã®èª€ããææããã«ã¯ !OUT ãšåºåããããšïŒèª€ããææããã®ã¯ïŒééã£ãçºèšã®çŽåŸã§ãªããã°ãªããªãïŒèª€ããææããæç¹ã§ããã°ã©ã ãçµäºããïŒäžèŠãªåºåã¯äžåè¡ã£ãŠã¯ãããªãïŒèª€ãã®ææãæ£ãããã°ããã°ã©ã ã¯æ£è§£ ( Accepted ) ãšå€å®ãããïŒåèªã®å¿çãäžé©åã§ãã£ããïŒAI ãžã®èª€ãã®ææãæ£ãããªãå ŽåïŒAI ã®èª€ããææããªãã£ãå Žåã¯èª€ç ( Wrong Answer ) ãšå€å®ãããïŒ å¶çŽ ããã°ã©ã ã®äœ¿ã£ãŠè¯ãåèªã®é·ã㯠1 æåä»¥äž 10 æå以äžã§ããïŒ AI ã®äœ¿ãåèªã®é·ã㯠1 æåä»¥äž 2 æå以äžã§ããïŒ ããã°ã©ã ã¯æå€§ã§ 50 åãŸã§çºèšããããšãåºæ¥ãïŒãããè¶
ãããšèª€ç ( Query Limit Exceeded ) ãšãªãïŒ AIïŒããã°ã©ã äž¡è
ãšãåèªã«äœ¿ã£ãŠè¯ãæåã¯ã¢ã«ãã¡ãããã®å°æåã®ã¿ã§ããïŒ AI ã®è¿çã¯ã¢ã«ãã¡ãããã®å°æåã®ã¿ãããªãïŒ æåã®æçªã§ã¯ïŒããã°ã©ã ã¯ã©ã®ã¢ã«ãã¡ããããããããšããéå§ããŠãè¯ãïŒ å
¥åºåäŸ å
¥åäŸ 1 以äžã®äŸã¯ããã°ã©ã ã®å
¥åºåã®äŸã§ããïŒå·Šã®åãããã°ã©ã ã®åºåïŒå³ã®åãããã°ã©ã ãžã®å
¥å (AI ã®çºèš) ã衚ãïŒæåã«ããã°ã©ã 㯠abcdefghij ãšããåèªãèšã£ãŠããïŒãã®å¿çãšã㊠AI 㯠jk ãšè¿ããŠãïŒ 3 åç®ã®å¿çã®éã« AI ã¯ãã§ã«äœ¿ãããŠãã jk ãšããåèªãçºããŠããã®ã§ããã«å¯ŸããŠããã°ã©ã 㯠!OUT ãšèšã£ãŠ AI ã®èª€ããææããŠããïŒ ããã°ã©ã ã®åºå ããã°ã©ã ãžã®å
¥å ?abcdefghij jk ?kkkk kl ?lj jk !OUT å
¥åäŸ 2 以äžã®äŸã§ã¯ïŒAI ã aaa ãšããåèªã«å¯Ÿã㊠bb ãšãããšãã«ãªããªãè¿çãããŠãããã !OUT ãšè¿ããŠããïŒ ããã°ã©ã ã®åºå ããã°ã©ã ãžã®å
¥å ?aaa bb !OUT | 36,293 |
Sum of Numbers Write a program which reads an integer and prints sum of its digits. Input The input consists of multiple datasets. For each dataset, an integer x is given in a line. The number of digits in x does not exceed 1000. The input ends with a line including single zero. Your program should not process for this terminal symbol. Output For each dataset, print the sum of digits in x . Sample Input 123 55 1000 0 Sample Output 6 10 1 | 36,294 |
é¿ããã¹ã ããªãã¯ããŸïŒäžäžå·Šå³ã«åºå€§ã«åºãããã¹ç®ã®åç¹ã«åœããäœçœ® (0, 0) ã«ããïŒãã¹ã®äœçœ®ã¯ x 座æšãš y 座æšã§è¡šããïŒå³ã«1ãã¹åãããšã x 座æšã1ã€å¢ããããšã«å¯Ÿå¿ãïŒäžã«1ãã¹åãããšã y 座æšã1ã€å¢ããããšã«å¯Ÿå¿ããïŒããªãã¯ããããç®çå°ã§ãããã¹ (x, y) ãç®æããŠåºçºãããšããã ïŒããªã㯠1 æ©ã§äžäžå·Šå³æãã® 8 æ¹åã«é£æ¥ãããã¹ã«ç§»åããããšãã§ããïŒ ããïŒç®çå°ã«åãã£ãŠç§»åéå§ã ïŒãšããªãã¯ææ°èŸŒãã§ãããšãããããããªããïŒã¡ãã£ãšåŸ
ã£ãŠã»ããïŒäžã€ã ãå
ã«å¿ åããŠããããšãããïŒããã¯ãã®ãã¹ç®ã«æœãè¬ã®äººç©ïŒåã蟌ã¿ã®ããã»å»»å°å®®ã®ååšã ïŒå»»å°å®®ã¯ããªãã 1 æ©ç§»åããã®ã確èªãããšïŒããªããé²ãã æ¹åã®ããã« 1 æ©å
ã®ãã¹ã«ç¬æã«ç§»åãïŒéªéãããŠããïŒããæ£ç¢ºã«èšãã°ïŒããªãããã¹ (x s , y s ) ãã (x t , y t ) ã«ç§»åãããšãïŒå»»å°å®®ã¯ (x t + (x t - x s ), y t + (y t - y s )) ã«ç§»åããïŒæããã«ç°æ§ãªé°å²æ°ãéžãåºãå»»å°å®®ïŒã€ãã®éåãã«å
¥ã蟌ãã®ã¯å±éºã ïŒåã蟌ãŸããçŽåŸã¯ä»æ¹ãªããšããŠïŒæ¬¡ã«ç§»åããå
ã®ãã¹ïŒãããã¯ãã® 8 æ¹åã«é£æ¥ãããã¹ã®ã©ããã«å»»å°å®®ããã§ã«ãããšïŒã€ãã®éåãã«å
¥ã蟌ãã§ããŸãããšã«ãªãã®ã§ïŒããã¯ã©ãããŠãé¿ãããïŒ äžèšã®ããã«å»»å°å®®ã®éåããé¿ãã€ã€ïŒç®çå°ã«èŸ¿ãçãããã«ã¯æå°ã§äœæ©å¿
èŠã ãããïŒããªãã®ä»äºã¯ãã®æå°æ©æ°ãæ±ããããã°ã©ã ãæžãããšã ïŒãã ãïŒå»»å°å®®ã¯åæç¶æ
ã§ã¯ã©ã®ãã¹ã«ãååšããïŒæåã® 1 æ©ç®ä»¥éããäžèšã®ã«ãŒã«ã«åŸã£ããã¹ã«çŸãããã®ãšããïŒ æåã®ãµã³ãã«ã§ã¯ïŒããªã㯠(2, 0) ãç®æãïŒäŸãã°æåã«å³æšªã®ãã¹ (1, 0) ã«ç§»åããŠããŸããšïŒå»»å°å®®ã (2, 0) ã«åã蟌ãã§ããããïŒæ¬¡ã«ãã®ãã¹ãžãšç§»åããããšãã§ããªãïŒäžæ¹ïŒæåã«å³æãäžã® (1, 1) ã«ç§»åãããšïŒå»»å°å®®ã®äœçœ®ã¯ (2, 2) ãšãªã (2, 0) ãå»»å°å®®ã®éåãã§ã¯ãªãããïŒæ¬¡ã® 1 æ©ã§ (2, 0) ã«ç§»åããããšãã§ããïŒ Input å
¥åã¯è€æ°ã®ããŒã¿ã»ãããããªãïŒ åããŒã¿ã»ãã㯠2 ã€ã®æŽæ° x , y ãããªã 1 è¡ã§è¡šãããïŒããã¯ç®çå°ã®ãã¹ãäœçœ® (x, y) ã§ããããšã衚ãïŒ |x|, |y| †10 9 ãæºããïŒ å
¥åã®çµãã㯠EOF (ãã¡ã€ã«ã®çµç«¯) ã§è¡šãããïŒ å
šããŒã¿ã»ããã®ç·æ°ã¯ 50 ãè¶
ããªãïŒ Output æ¡ä»¶ãæºããããã«ç§»åãç¹°ãè¿ããšãïŒãã¹ (0, 0) ãããã¹ (x, y) ã«ç§»åããããã«å¿
èŠãªæå°æ©æ°ã 1 è¡ã«åºåããïŒ Sample Input 2 0 2 2 1 -1 0 0 0 -5 173 207 Output for the Sample Input 2 4 1 0 6 379 | 36,295 |
åè
ã倪é(Bitaro the Brave) åè
ã®ã倪éã¯ïŒéçãšå¯Ÿå³ããããšãšãªã£ãïŒ ã倪éã¯ïŒçžŠ$H$ è¡ïŒæšª$W$ åã®ãã¹ç®äžã«å®ç³(Jewel)ïŒãªãŒã(Orb)ïŒéå¡(Ingot) ãé
眮ãïŒéæ³ãçºåããããšã«ãã£ãŠéçã«æ»æãããããšããŠããïŒä»¥äžïŒãã¹ç®ã®ãã¡äžãã$i$ è¡ç®($1 \leq i \leq H$)ïŒå·Šãã$j$ åç®($1 \leq j \leq W$) ã®ãã¹ãïŒãã¹($i, j$) ãšè¡šãïŒ ã倪éã¯ä»ïŒããããã®ãã¹ã«ããã3 çš®é¡ã®ãã¡1 åãé
眮ããïŒä»ããéæ³ãçºåããããšããŠãããïŒãã®éæ³ã®åšåã¯ãã¹ç®äžã®å®ç³ïŒãªãŒãïŒéå¡ã®é
眮ã«ãã£ãŠæ±ºãŸãïŒå
·äœçã«ã¯ïŒæ¬¡ã®æ¡ä»¶ãæºããæŽæ°($i, j, k, l$) ($1 \leq i < k \leq H, 1 \leq j < l \leq W$) ã®çµã®åæ°ãïŒéæ³ã®åšåã§ããïŒ æ¡ä»¶ïŒãã¹($i, j$) ã«ã¯å®ç³ãïŒãã¹($i, l$) ã«ã¯ãªãŒããïŒãã¹($k, j$) ã«ã¯éå¡ã眮ãããŠããïŒ ã倪éã¯ïŒãã®éæ³ã®åšåãæ°ã«ãªã£ãŠããïŒ ãã¹ç®äžã®å®ç³ïŒãªãŒãïŒéå¡ã®é
眮ãäžãããããšãïŒã倪éãçºåããéæ³ã®åšåãæ±ããããã°ã©ã ãäœæããïŒ å
¥å å
¥åã¯ä»¥äžã®åœ¢åŒã§æšæºå
¥åããäžããããïŒ $H$ $W$ $S_1$ : $S_H$ $S_i$ ($1 \leq i \leq H$) ã¯é·ã$W$ ã®æååã§ïŒãã®$j$ æåç®($1 \leq j \leq W$) ãJ ã®ãšãã¯ãã¹($i, j$) ã«å®ç³ãïŒO ã® ãšãã¯ãã¹($i, j$) ã«ãªãŒããïŒI ã®ãšãã¯ãã¹($i, j$) ã«éå¡ã眮ãããŠããããšã衚ãïŒ åºå æšæºåºåã«ïŒéæ³ã®åšåãè¡šãæŽæ°ã1 è¡ã§åºåããïŒ å¶çŽ $2 \leq H \leq 3 000$ïŒ $2 \leq W \leq 3 000$ïŒ $S_i$ ã¯é·ã$W$ ã®æååã§ãã($1 \leq i \leq H$)ïŒ $S_i$ ã®åæåã¯JïŒOïŒI ã®ããããã§ãã($1 \leq i \leq H$)ïŒ å
¥åºåäŸ å
¥åäŸ1 3 4 JOIJ JIOO IIII åºåäŸ1 3 ãã®å
¥åäŸã§ã¯ïŒ($i, j, k, l$) = (1, 1, 3, 2), (2, 1, 3, 3), (2, 1, 3, 4) ã®3 åã®çµãæ¡ä»¶ãæºããã®ã§ïŒçãã¯3 ã§ããïŒ å
¥åäŸ2 4 4 JJOO JJOO IIJO IIIJ åºåäŸ2 17 æ
å ±ãªãªã³ããã¯æ¥æ¬å§å¡äŒäœ ã第18 åæ¥æ¬æ
å ±ãªãªã³ããã¯(JOI 2018/2019) æ¬éžã | 36,296 |
åªé¢ç©ã®èšç® åå°ã®é¢ç©ã衚çŸãããââåªããšããåäœãèããããšã¯ãªãã§ããããïŒ å€æ¥ãïŒäººã®æŠå£«ãïŒæ¥ã«é£ã¹ããç±³ãäœãé¢ç©ãèšããŸããã a mà b mã®åå°ããããŸãã a ãš b ãå
¥åãããã®åå°ã®åªé¢ç© S åªïŒœãåºåããããã°ã©ã ãäœæããŠãã ããã 1 åª = 3.305785 [m 2 ] ãšãã a ãš b 㯠100 以äžã®æŽæ°ãšããŸãã å
¥å a b ïŒã€ã®ç©ºçœã§åºåããã a ãš b ãïŒè¡ã«äžããããã åºå åªé¢ç© S ãïŒè¡ã«åºåããã0.0001 以äžã®èª€å·®ãèš±ãããã å
¥åäŸ1 15 25 åºåäŸ1 113.437508 | 36,297 |
Score : 200 points Problem Statement Given are integers a,b,c and d . If x and y are integers and a \leq x \leq b and c\leq y \leq d hold, what is the maximum possible value of x \times y ? Constraints -10^9 \leq a \leq b \leq 10^9 -10^9 \leq c \leq d \leq 10^9 All values in input are integers. Input Input is given from Standard Input in the following format: a b c d Output Print the answer. Sample Input 1 1 2 1 1 Sample Output 1 2 If x = 1 and y = 1 then x \times y = 1 . If x = 2 and y = 1 then x \times y = 2 . Therefore, the answer is 2 . Sample Input 2 3 5 -4 -2 Sample Output 2 -6 The answer can be negative. Sample Input 3 -1000000000 0 -1000000000 0 Sample Output 3 1000000000000000000 | 36,298 |
Problem F: Great Devil Sakanikia Problem 倧æªéãµã«ãŒãã£ã¯ä»æ¥ã倩æµã®ç«ã«è¥²ãããŠããã ãã€ãããããŠããèš³ã«ã¯ãããªãã®ã§ãç§å¯å
µåšã賌å
¥ããã ãã®ç§å¯å
µåšã¯ã巚倧ãªå²©ãçæããããšã§ç«ã®ç§»åçµè·¯ãå¡ããç«ããã¡ãã«è¿ã¥ããªãããã«ããããšãã§ããã ä»ããµã«ãŒãã£ãšäžå¹ã®ç«ããã¹(0,0),( n â1,0),( n â1, m â1),(0, m â1)ã§å²ãŸããé·æ¹åœ¢ã®éåºéå
ã«ããã ãã¹(0,0)ã«ç«ããã¹( n â1, m â1)ã«ãµã«ãŒãã£ãããã ç«ã¯äžäžå·Šå³ã®é£æ¥ãããã¹ã«ç§»åããããšãã§ããããåºéå€ã«åºãããšã¯ã§ããªãã ããã€ãã®ãã¹ã¯ã穎ãé害ç©ã®åœ±é¿ã§äŸµå
¥ããããšãã§ããªãã ãµã«ãŒãã£ã¯ããããã¹ã«1ã€å²©ãçæããããšã§ãã®ãã¹ã«ç«ã䟵å
¥ã§ããªãããããšãã§ããã ãã ãããã¹(0,0)ãšãã¹( n â1, m â1)ã«å²©ãçæããããšã¯ã§ããªãã ãã¹(0,0)ãããã¹( n â1, m â1)ãŸã§ã®ç§»åçµè·¯ãå¡ãããã«å¿
èŠãªãçæããå²©ã®æ°ã®æå°å€ãæ±ããã Input n m k x 1 y 1 ... x k y k å
¥åã¯ãã¹ãп޿°ã§äžããããã 1è¡ç®ã«ãã¹ã®å€§ããã衚ãïŒã€ã®æŽæ° n ãš m ã䟵å
¥ã§ããªããã¹ã®æ° k ã空çœåºåãã§äžããããã 2è¡ç®ãã k è¡ã«äŸµå
¥ã§ããªããã¹ã®åº§æšãäžããããã Constraints å
¥åã¯ä»¥äžã®æ¡ä»¶ãæºããã 2 †n , m †10 5 0 †k †min( n à m â2,10 5 ) 0 †x i †n â 1 0 †y i †m â 1 ( x i , y i ) â ( x j , y j ) ( i â j ) ( x i , y i ) â (0,0) â ( n â1, m â1) Output ãã¹(0,0)ãããã¹( n â1, m â1)ãŸã§ã®ç§»åçµè·¯ãå¡ãããã«å¿
èŠãªãçæããå²©ã®æ°ã®æå°å€ã1è¡ã«åºåããã Sample Input 1 3 5 2 0 2 2 2 Sample Output 1 1 Sample Input 2 5 5 3 0 2 2 2 4 1 Sample Output 2 2 | 36,299 |
Problem Statement You have a rectangular board with square cells arranged in $H$ rows and $W$ columns. The rows are numbered $1$ through $H$ from top to bottom, and the columns are numbered $1$ through $W$ from left to right. The cell at the row $i$ and the column $j$ is denoted by $(i, j)$. Each cell on the board is colored in either Black or White. You will paint the board as follows: Choose a cell $(i, j)$ and a color $c$, each uniformly at random, where $1 \le i \le H$, $1 \le j \le W$, and $c \in \{{\rm Black}, {\rm White}\}$. Paint the cells $(i', j')$ with the color $c$ for any $1 \le i' \le i$ and $1 \le j' \le j$. Here's an example of the painting operation. You have a $3 \times 4$ board with the coloring depicted in the left side of the figure below. If your random choice is the cell $(2, 3)$ and the color Black, the board will become as shown in the right side of the figure. $6$ cells will be painted with Black as the result of this operation. Note that we count the cells "painted" even if the color is not actually changed by the operation, like the cell $(1, 2)$ in this example. Fig: An example of the painting operation Given the initial coloring of the board and the desired coloring, you are supposed to perform the painting operations repeatedly until the board turns into the desired coloring. Write a program to calculate the expected total number of painted cells in the sequence of operations. Input The input consists of several datasets. The number of datasets is at most $100$. The first line of each dataset contains two integers $H$ and $W$ ($1 \le H, W \le 5$), the numbers of rows and columns of the board respectively. Then given are two coloring configurations of the board, where the former is the initial coloring and the latter is the desired coloring. A coloring configuration is described in $H$ lines, each of which consists of $W$ characters. Each character is either B or W, denoting a Black cell or a White cell, respectively. There is one blank line between two configurations, and also after each dataset. You can assume that the resulting expected value for each dataset will not exceed $10^9$. The input is terminated by a line with two zeros, and your program should not process this as a dataset. Output For each dataset, your program should output the expected value in a line. The absolute error or the relative error in your answer must be less than $10^{-6}$. Sample Input 1 2 BB WW 2 1 B W B W 2 2 BW BW WW WW 3 4 BBBB BBBB BBBB WWWW WWWW WWWW 5 5 BBBBB BBBBB BBBBB BBBBB BBBBB BBBBB BBBWB BBBBB BWBBB BBBBB 0 0 Output for the Sample Input 6.0000000000 0.0000000000 12.8571428571 120.0000000000 23795493.8449918639 | 36,300 |
Problem H : Dungeon (II) ããªãã¯ãšããã²ãŒã ã®éçºã«æºãã£ãŠããã ãã®ã²ãŒã ã¯ã©ã³ãã ã«çæããããã³ãžã§ã³ããã¬ã€ã€ãŒãæ¢çŽ¢ãããšãããã®ã§ããã ã²ãŒã ã®ä»æ§ãšããŠããã¬ã€ã€ãŒã«äºããã³ãžã§ã³ã®å±éºåºŠãæç€ºããçæããããã³ãžã§ã³ãæ¢çŽ¢ããã®ãããããšãæ°ãããã³ãžã§ã³ãçæããªãããããéžæã§ããããã«ãããã ãã®ã²ãŒã ã§çæããããã³ãžã§ã³ã«ã¯ n åã®éšå±ãååšããŠããã0ãã n-1 ãŸã§ã®çªå·ãå²ãæ¯ãããŠããã éšå±ãšéšå±ã¯éè·¯ã§çµã°ããŠãããéšå±ãšéšå±ãçµã¶éè·¯ã¯ãåèšã§ n-1 æ¬ååšããŠããã éè·¯ã¯ã©ã¡ãã®æ¹åãžãé²ãããšãã§ããã ãŸããéšå±ãšéšå±ã®éã«ã¯è·é¢ãèšå®ãããŠããã çæããããã³ãžã§ã³ã§ã¯ããã€ãã®éè·¯ãçµç±ããŠãããéšå±ããä»ã®ãã¹ãŠã®éšå±ãžè¡ãããšãå¯èœã§ããã ãããŠããã¬ã€ã€ãŒãã²ãŒã ãè¡ãéã«ãïŒã€ã®ç°ãªãéšå±ãã¹ã¿ãŒãå°ç¹ãšãŽãŒã«å°ç¹ãšããŠéžã°ããã ããªãã¯ãã³ãžã§ã³ã®è©äŸ¡ãè¡ãããã«ãå±éºåºŠã®è©äŸ¡æ¹æ³ã決ããããšã«ããã ãŸããããéšå±ããå¥ã®éšå±ãŸã§ã«ç§»åããéã®å±éºåºŠããéšå±éãæçã§ç§»åããããã«äœ¿ãéè·¯ã®äžã§ãæãã³ã¹ãé«ãéè·¯ã®å€ãšããã ãããŠããã³ãžã§ã³ã®å±éºåºŠãã i < j ãšãªãéšå±ã®ãã¢ã®éãç§»åããéã®å±éºåºŠã®ç·åãšããããšã«ããã ã©ã³ãã ã«çæããããã³ãžã§ã³ã®ãå
¥åãšããŠäžããããã ãŸãã i < j ãšãªããã¹ãŠã®éšå±ã®ãã¢ã«ã€ããŠãç§»åããéã®å±éºåºŠãèšç®ããŠæ¬²ããã ãããŠããã®ç·åãåé¡ã®çããšããŠåºåããã Input å
¥åã¯ä»¥äžã®ãã©ãŒãããã§äžããããã n a 1 b 1 c 1 . . . a n-1 b n-1 c n-1 a i b i c i 㯠éšå± a i ãš b i ãçµã¶éè·¯ã®è·é¢ã c i ã§ããããšã衚ãã å
¥åã¯ä»¥äžã®å¶çŽãæºãã 2 †n †200,000 0 †a i , b i < n 0 †c i †100,000 Output çãã®å€ã1è¡ã«åºåãã Sample Input 1 4 0 1 3 1 2 5 1 3 2 Sample Output 1 23 Sample Input 2 6 0 2 5 2 1 1 2 3 10 3 5 4 3 4 2 Sample Output 2 111 | 36,301 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.