å ´ååã
é¢ç½ãã£ãï¼ ã«ã¿ã©ã³æ°çãªãã®ãç»å ´ããã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ å¶ç´ èããã㨠ã¾ãããã«ããã£ããã¨ã¯ã ã®ä¸ã«ã1 ã 2 å以ä¸ãã£ã¦ã¯ãã¡ ã®ä¸ã«ã1 ãæ«å°¾ä»¥å¤ã®å ´æã«ãã£ã¦ã¯ãã¡ ã¨ãããã¨ã ã£ããããããã¨ã ã¯æ¬¡ã®ããããã®å½¢ã«ãªâ¦
è¾æ¸é æå°ã¨è¨ãããã......ï¼ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ æå 'd', 'p' ãããªãé·ã ã®æåå ãä¸ããããã ãã®æååã®ããåºéãã¨ã£ã¦ããã®åºéã 180 度å転ãããï¼reverse ããä¸ã§ã'd' 㨠'p' ãå ¥ãæ¿ããï¼ã ãããã¦ã§ããæååã®ãã¡â¦
ãã®æ代ããã®æã® Greedy ã¯ãããããã£ãã®ãï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é·ã ã®æ°å ãä¸ããããããæ°åã®è¦ç´ ã 1 ã¤é¸ã³ã+1 ãããã-1 ãããã¨ããæä½ãè¡ããã¨ã§ã次ã®ç¶æ ãéæãããããã ãã ã¨ããã ãã¹ã¦ã® ã«å¯¾ãã¦ã ã§ãã ãã¹â¦
ã¡ãã£ã¨ããç®æ°çãªèãæ¹ãå¿ è¦ã«ãªãåé¡ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ JOI åã¯ä»¥ä¸ã®è¡åãè¡å A â è¡å B â è¡å A â ⯠ã®ããã«äº¤äºã«ç¹°ãè¿ãã è¡å Aï¼3m åã«é²ã è¡å Bï¼2m å¾ãã«æ»ã è¡åãåãã㦠åè¡ãã¨ããä½mé²ããï¼ è§£æ³ ãã®ãããªåâ¦
æ´çããã®ã大å¤ãªåé¡ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 3 ã¤ã®ç¸ç°ãªãæ´æ° ãããï¼å¤ã¯ä¸ããããªãï¼ã ãããã® 3 ã¤ã®æ´æ°ã®å¤§å°é¢ä¿ã表ã 3 ã¤ã®æå ãä¸ããããããã¨ãã° ã '<' ã§ããã¨ãã ã§ãããã¨ã表ãã ã '>' ã§ããã¨ãã ã§ãããã¨ã表â¦
ã§å ´ååãããç³»ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ æ£ã®æ´æ° ãä¸ããããã次ã®æ¡ä»¶ãæºããæå°ã®æ´æ° ï¼ï¼ãæ±ããã(åå¨ããªãå ´å㯠-1ãï¼ ãæ¡ä»¶ã ã é²æ³è¡¨è¨ããã¨ãã®æ¡ã®åã ã§ãã å¶ç´ èããã㨠ãå°ããç¯å²ã¯æç´ã«èª¿ã¹ãã°ããããã ã ããâ¦
ä¸æã«å ´ååããã¦è§£ãã¦ãããã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 1 ãæ¸ãããã«ã¼ãã æã0 ãæ¸ãããã«ã¼ãã æã â1 ãæ¸ãããã«ã¼ãã æããã ãããã®ã«ã¼ããããã¡ããã© æãé¸ãã§åãã¨ããåã£ãã«ã¼ãã«æ¸ãããæ°ã®åã¨ãã¦ã ããããå¤ã®æâ¦
ããããããã©ãè½ã¡çãã¦èããã°ã§ããï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ AtCoder çå½ã®ä½æ°ã¯ æã«ãªãã¨ããç¼ãã¸ã®æãå«ã¶ãã¨ã«ãªã£ã¦ããã AtCoder çå½ã«ä½ãé«æ©åã¯æ¯æ¥ æã«å°±å¯ã æã«èµ·åºããã é«æ©åã¯ããç¼ãã¸ã®æãå«ã¶ãã¨ãã§ãã¦ããâ¦
確çãèããããã®åºç¤ã¨ãªãåé¡ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ã³ã³ãã¹ãã« 1000 人ãåå ããã ä¸ä½ ä½ã¯ã確å®ã« T ã·ã£ãããããã ä¸ä½ ä½ãã ä½ã¾ã§ã¯ããã®ä¸ããã©ã³ãã 㫠人ãé¸ã°ãã¦ãT ã·ã£ãããããã ãã以å¤ã¯ãT ã·ã£ããããããªã â¦
è½ã¡çãã¦æ´çãã¦ãããï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 以ä¸ã®æå°ã® 4 ã§å²ã£ã¦ 2 ä½ãæ´æ°ãæ±ããã å¶ç´ èããã㨠ã 4 ã§å²ã£ãä½ãã«ãã£ã¦å ´ååããã¦èãããã ã 4 ã§å²ãåããã¨ãï¼2 足ããã¨ã§ã4 ã§å²ã£ã¦ 2 ä½ãæ´æ°ãã«ãªãã®ã§ã ãçãâ¦
ãã®ãªã®ãªãèãããã¨ããèå¯ã®åºæ¬å½¢ã¨è¨ããåé¡ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ æ´æ° ãä¸ããããã®ã§ã ãæºããæ´æ° ã«ã¤ãã¦ã® ã®æ大å¤ãæ±ããã å¶ç´ èããã㨠ãã®æã®åé¡ã§èãããã¨ã¯ãã端ç¹ã®ã¿èããã°è¯ãã®ã§ã¯ããªã©ã¨çããã¨ãã¤ã¾ãâ¦
ã¡ãã£ã¨ç®æ°ããã¯ãªåé¡ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 人 1, 2, 3 ã容çè ã«æãããã¦ããã次ã®è¨¼è¨ãããã ã人 ã¯ç¯äººã§ã¯ãªãã ã人 ã¯ç¯äººã§ã¯ãªãã ç¯äººãç¹å®ã§ãããã©ãããå¤å®ããç¹å®ã§ãããªãã°ç¯äººãçããã å¶ç´ 㯠1, 2, 3 ã®ãããã â¦
æç´ã« ã ãæ±ãããã¨ããã¨ãè²ããªçç±ã§ãããããªã£ã¦ãã¾ããæ°å¦çã«ç¶ºéºã«å¦çãããï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ æ´æ° ãä¸ããããã 㨠ã®å¤§å°é¢ä¿ãæ±ãã (大ãããå°ãããçãã)ã å¶ç´ èããã㨠ã ã¯ã¾ã¨ãã«è¨ç®ããã¨ãã®ãããæ¡æ°ã«â¦
ç®æ°ç³»ã®åé¡ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ è§£æ³ å ¥åã®ä¸ã« ãå«ã¾ããããããã¯çµå±ä½¿ããªããããããå¤æ°ã«æããããªãããã«ãããã次㮠2 ã¤ã®å ´åã«åãã¦èããã ã®ã¨ã (ä¸ãã®ã¨ã) ã®ã¨ã (ä¸ãã®ã¨ã) åè ã®å ´åã¯ã"Yes" ã¨ãªãæ¡ä»¶ã¯ ã¨æ¸â¦
ä¸æã«å ´ååããããï¼ åé¡ã¸ã®ãªã³ã¯ editorial åé¡æ¦è¦ 3 åã®æ´æ° ãä¸ããããã ãããã®ãã¡ã® 1 åããæ®ãã® 2 åã®åã¨ãã¦è¡¨ããã¨ã㯠1 ãåºåããããã§ãªãã¨ã㯠0 ãåºåããã è§£æ³ ã3 åã®æ´æ° ã®ãã¡ã® 1 åããæ®ãã® 2 åã®åã¨ãâ¦
ããçµæ§é£ããã¨æãï¼ æ°å¦ IA ã®ãå ´åã®æ°ããããã¨ãããåºã¦æ¥ããã¤ã§ããã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ è±å°æåã®ã¿ãããªãé·ã 3 ã®æåå ãä¸ãããã¾ãã ã®åæåã並ã³æ¿ãã¦å¾ãããæååã¯ãä½ç¨®é¡ããã¾ããï¼ è§£æ³ ã3 åã®ãã®ã並ã³æ¿â¦
ããã¯æ´çããã®ã大å¤ï¼ï¼ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é«æ©å㯠åã®ã¢ã¡ãæã£ã¦ãã¦ãéæ¨å㯠åã®ã¢ã¡ãæã£ã¦ããã 交äºã«èªåã®ã¢ã¡ãé£ã¹ã¦ãããå ã«é£ã¹ãããªããªã£ãæ¹ãè² ãã§ããã ãªãã°é«æ©åãå æã ãªãã°éæ¨åãå¾æã ã©ã¡ããåã¤â¦
ã¡ãã£ã¨é£ããåé¡ã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 3 æåã® 'R' 㨠'S' ã®ã¿ãããªãæåå ãä¸ããããã ã«ããã¦ã'R' ãæ大ã§ä½åé£ç¶ãã¦ããããçããã è§£æ³ ããããæåå㯠éããããã¨ã«æ³¨æãããããã£ã¦ããã¹ã¦ã®æååã調ã¹ããã¨ãã§ãâ¦
ããã¯é£ããï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 2 åã®æ´æ° ãä¸ããããã ãæºãããããªæ´æ° ãåå¨ããã°ãããçãã¦ãåå¨ããªãå ´åã«ã¯ "IMPOSSIBLE" ã¨çããã è§£æ³ ããã¯é£ãããçµè«ããè¨ãã°ã ã¯æ´æ°ã§ãªãã¦ããããªãã°ã ã®å¹³åå¤ ã¨ãªããä¸å³â¦
天ææ§ç¯ã²ã¼ãããå®å ¨èªåã§ä¸çº AC ã§ãã¦å¬ããã£ãï¼ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ æ£ã®æ´æ° ãä¸ããããã次ã®æ¡ä»¶ãæºããä¸è§å½¢ãåå¨ãããã©ãããå¤å®ããåå¨ããå ´å㯠1 ã¤æ±ããã é ç¹ããã¹ã¦æ ¼åç¹ã§ããã座æ¨å¤ã¯ ä»¥ä¸ ä»¥ä¸ã§ãã ãã¹ã¦â¦
æ éã«è§£ããããã¼ããã§è§£ããã®ã¯åç©«ã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ã®ã°ãªããã«ã以ä¸ã®æ¡ä»¶ãæºããããã« åã®ã«ã¼ã¯ã¨ åã®ãã¼ã³ãé ç½®ãããã¨ãå¯è½ãã©ãããå¤å®ãã (ã«ã¼ã¯ã¨ãã¼ã³ãåããã¦é§ã¨å¼ã¶)ã ã©ã®ã«ã¼ã¯ã«ã¤ãã¦ããããã¨åãè¡ã»â¦
ããã¯é£ããï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 4 æ¡ã®æ´æ° ãä¸ããããããã®æ´æ°ããåãæ°åã 3 ã¤ä»¥ä¸é£ç¶ãã¦ãããããå¤å®ããã è§£æ³ ãæååã¨ãã¦åãåãæ¹ã楽ã ã¨æãããããã®ã¨ããåãæ°åã 3 ã¤ä»¥ä¸é£ç¶ããã®ã¯æ¬¡ã® 2 ãã¿ã¼ã³ãããã N â¦
æãã®å ´ååããã¡ãã£ã¨è¦æç³»ã ãã©ä¸çº AC ã§ãã¦ããã£ãã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é«æ©åã¯ç¾å¨ ã«ãã¦ãè·ç©ã¯ ã«ãããè·ç©ãç®çå° ã«å±ãããã é«æ©åã¯è·ç©ã®ããä½ç½®ã«å ¥ããã¨ã¯ã§ãããè·ç©ã¨é£æ¥ããç¶æ ããè·ç©ã®æ¹åã«ç§»åããã¨ãè·ç©â¦
ããããåºéåå²ã® DP ã ãã©ãããã§ãããã¨ã«æãè³ãã®ãé£ãããããããªãã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ æ²ãã£ã¦ãããããã®æ²ã®é·ã㯠ã§ããã ä»ãæå» 0 ããéå§ãã¦ãæ²ãä¸æ§ã©ã³ãã ã«æµãããããçµãã£ããã¾ãä¸æ§ã©ã³ãã ã«æ²ãé¸æãã¦â¦
ããããã¾ãã½ã¼ããã¦èããããå¹ãç³»ãã§ããããããªãã¦ã解ããã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 3 ã¤ã®æ£ã®æ´æ° ãä¸ããããã ãããã 2 ã¤ã®ã°ã«ã¼ãã«åãã¦ãåã°ã«ã¼ãã®æ°å¤ã®ç·åãçãããªãããã«ã§ãããã©ãããå¤å®ããã è§£æ³ (1)ï¼å ´ååâ¦
3 ã¤ã®æ´æ°ã«ã¤ãã¦ããããåãåé¡ã¯ãã®æ代å¤ãã£ã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 3 åã®æ´æ° ããããããã㯠1 ä»¥ä¸ 100 以ä¸ã®æ´æ°ã§ããã ãããã®æ´æ°ã®ç¨®é¡æ°ãæ±ããã ã³ã¼ã ãã®æã®åé¡ã¯ããé åã¨ãã¦åãåã£ã¦ã½ã¼ãããããã¯ããã¯ã使ãâ¦
ã³ã³ãã¹ãå¾ã«è§£ããããªãã¨ãè©°ãåã£ãã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ éè² æ´æ° ã¨æ´æ° ã«å¯¾ãã¦ãé¢æ° ã次ã®ããã«å®ç¾©ããã æ£æ´æ° ãä¸ãããã¦ã次ã®æ¡ä»¶ãæºããéè² æ´æ°å ã¨æ£ã®æ´æ° ã®çµã®åæ°ã 998244353 ã§å²ã£ãä½ããæ±ããã () å¶ç´ èãâ¦
æå¤ã¨ãããããåé¡ã ã©ã¦ã³ãç®ã®æ績ã«ãã£ã¦ã¯ãããã¾ã§ã®æ«å®ã®æ大ã¹ã³ã¢ã¨æå°ã¹ã³ã¢ãå¤ãããããããªãã¨ããç¹ã«æ³¨æï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ã©ã¦ã³ãã®è©¦é¨ãè¡ããããåã©ã¦ã³ãã®å¾ç¹ã¯ 0 ä»¥ä¸ 100 以ä¸ã®æ´æ°å¤ã§ãããå ¨ã©ã¦ã³ãã®â¦
é¤åçï¼ å¦ã³ã®å¤ãåé¡ã ã£ããSubset Convolution ã®æ¹ã¯ã¡ãã£ã¨é å¼µã£ã¦ãã®å¾å¾©ç¿ããã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é ç¹çªå·ã ã§ããã°ã©ã ããããæåã辺㯠1 æ¬ããªãã ä»¥ä¸ ä»¥ä¸ã®å¤ãããªããµã¤ãº ã® 2 ã¤ã®æ°å 㨠ãããã ä»ãããã 2 ã¤â¦
ãã®åé¡ãããã«ã±ã«æºå®å ¨äºåæ¨ã®ã©ã¤ãã©ãªãæ¡å ããï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é ç¹æ° ã®æ ¹ä»ãæ¨ãä¸ãããããé ç¹çªå·ã¯ ã§ãããåé ç¹ (> 2) ã«ã¤ãã¦ã親é ç¹ã¯ ã§ããã ãã®æ ¹ä»ãæ¨ã«ããã¦ãé ç¹ ããã®è·é¢ã ã§ãããããªé ç¹ã®åæ°ãæ±â¦