æ°´è²diff
é 延è©ä¾¡ã»ã°ã¡ã³ãæ¨ã¨ããã® max_right, min_left ã§æ®´ã£ãï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ãã¹ ãä¸åã«ä¸¦ãã§ãã¦ãããããè² ã§å¡ããã¦ããã次㮠åã®ã¯ã¨ãªã«çããã ã¯ã¨ãªã¿ã¤ã 1ï¼ãã¹ ã¨è² ãæå®ãããã®ã§ããã¹ ããå§ãã¦ããã¾ãããã¹ã¨åâ¦
ã主客転åã»å¯ä¸å解ãã®å ¸ååé¡ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 1 ãã 9 ã¾ã§ã®æ°åãããªã æ¡ã®æ´æ°å¤ ãä¸ããããã ãã®æ´æ°å¤ã®é£ç¶ããåºéãåãåºãã¦ã§ããæ´æ°å¤ã®ç·åãæ±ãããï¼998244353 ã§å²ããªããï¼ å¶ç´ èããã㨠ãã®æã®åé¡ã§ã¯ã â¦
ããã«ã stack ãç»å ´ããããªåé¡ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ä¸ã®å³ã®ããã«ãé«ãã ã®ä»åããçééã«ä¸¦ãã§ãã¦ããã®éã¨ä¸¡ç«¯ã® ã«æã®ã¹ãã¼ã¹ã表ãçªå·ã ã¨ããããããã¯å¹ ãçããã ä»ãã¹ãã¼ã¹ 0 ã«æ°´ãå ¥ãã¦ããã1 ååã®ã¹ãã¼ã¹ã«ã¤ãâ¦
evima ããã®å¥è§£ã§è§£ããã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é ç¹æ° ã®åç´ãªæ¨ãä¸ããããããã®æ¨ã«è¾ºã 1 æ¬è¿½å ãã¦å¾ãããã°ã©ãã®ãã¡ã次ã®æ¡ä»¶ãæºãããã®ã®åæ°ãæ±ããã åç´ã°ã©ãã§ãã ãµã¤ã¯ã«ãã¡ããã© 1 ã¤å«ã¿ããã®ãµã¤ã¯ã«ã«å«ã¾ããé ç¹â¦
ããé¢ç½ãã£ãï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ æ°å ãä¸ããããããã®æ°åã®é£ç¶ããé¨åæ°åã«ã¤ãã¦ããã®ç·åã ã§å²ã£ãä½ãããèããã é£ç¶ããé¨åæ°åããã¹ã¦èããã¨ãã®ãããã®ç·åã ã§å²ã£ãä½ããã®ç·åãæ±ããã å¶ç´ èããã㨠ãã®åé¡â¦
é¢ç½ããåå¤ã«å¯¾ããçããäºãæ´çãã¦æ±ãã¦ããææ³ã¯é »åºï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ åã®åç©ããããåç© ã¯ãéãã ã§ããã価å¤ã ã§ããã ããã¤ãã®åç©ããç·åã 以ä¸ã¨ãªãããã«é¸ã¶ã¨ããé¸ãã åç©ã®ä¾¡å¤ã®ç·åã®æ大å¤ãæ±ããã å¶ç´ â¦
ãã®æ代ããã®æã® Greedy ã¯ãããããã£ãã®ãï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é·ã ã®æ°å ãä¸ããããããæ°åã®è¦ç´ ã 1 ã¤é¸ã³ã+1 ãããã-1 ãããã¨ããæä½ãè¡ããã¨ã§ã次ã®ç¶æ ãéæãããããã ãã ã¨ããã ãã¹ã¦ã® ã«å¯¾ãã¦ã ã§ãã ãã¹â¦
æ¹éãç«ã¦ãã®ã¯é£ãããªããã©ãã¨ã«ããéããåé¡ã ã£ãã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 人 ã«å¯¾ãã¦åè¨ ç¥¨ãéã¾ã£ãããããã®äººã®ãã¡æ¡ä»¶ãèªåãããå¤ãã®ç¥¨ãéãã人ã 人æªæºããæºãã人ãå½é¸ã¨ãªãã 票ã®ãã¡éä¸ã¾ã§é票ããã¦ãå人 ã«ã¯ 票â¦
ãããã¤ãã®å¤ã決ããã¨ãæ®ãã決ã¾ã£ã¦ããã®ã§ãæå¾ã«æ´åæ§ã check ãããã¨ããã®ã¯ãé »åºã®å ¸åãã¯ããã¯ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ åç°ç¶ã«åç© ããã®é ã«ä¸¦ãã§ãããååç©ã¯ç¾ ('S') ãç¼ ('W') ã§ããããã ããååç©ããããã§ããããâ¦
ãé¢ä¿ãªããããï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é«æ©åã¯è¡ ã®é ã«è¨ªãããè¡ ã§ã¯ãããã®ä¾¡å¤ã¯ åã§ããã é«æ©åã¯è¡ 㧠åã§ãããã好ããªæ°ã ãè²·ããã¨ãã§ãã¦ã ãæºããè¡ ã§ãã®ãããã好ããªæ°ã ã åã§å£²ããã¨ãã§ããããã ããé«æ©åã¯ããâ¦
ä¸è¦ã ã® DP ã«è¦ãããããã®å¿ è¦ã¯ãªãã£ãã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ã°ã¼ã¨ãã¼ããåºããªãã¸ã£ã³ã±ã³ã åãããç¸æãååã«ä½ãåºãããäºãããã£ã¦ããããã ããã©ã®æç¹ã§ã (ããã¾ã§ã«åºããã°ã¼ã®åæ°) (ããã¾ã§ã«åºãããã¼ã®åæ°) ãæºâ¦
åé¡æã®ç解ã大å¤ãããããªã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ï¼æè¨³ï¼ 2 ã¤ã®æ£ã®æ´æ° ã次ã®ããã« åæ´æ°ãã¦ãããæåã ã§ããã åç®ã®æ´æ°ã§ã¯ 2 ã¤ã®äºãã«ç´ ãªæ£ã®æ´æ° ãä¸ããããã®ã§ã ãæºãããã㪠2 ã¤ã®æ£ã®æ´æ° ã 1 ã¤æ±ãã¦ã ããããã â¦
å ±éãã¹ãæ°å¦ IA ã«ãä¼¼ãåé¡ãåºã¦ããï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é ç¹æ°ã ã®ãµã¤ã¯ã«ã°ã©ããä¸ããããããã®ã°ã©ãã®åé ç¹ãè² ã®ããããã®è²ã§å¡ãã ã©ã®é£æ¥ããé ç¹å¯¾ãç°ãªãè²ã§å¡ãããããã«ããæ¹æ³ã®åæ°ã 998244353 ã§å²ã£ãä½ããæ±â¦
ã¨ã¦ãé¢åãªå ¨æ¢ç´¢åé¡ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ãµã¤ãºãçããã¨ã¯éããªã 3 ã¤ã®ç½é»ã®ã°ãªãã ãä¸ããããã ãã巨大ãªã°ãªããã«ã2 ã¤ã®ã°ãªãã ãéãåã㦠(é»è²é¨åã«ã¤ã㦠OR ãã¨ã)ãããããé©åã«é·æ¹å½¢é åãåãåºããã¨ã§ãã°ãªãâ¦
ä¹ ã ï¼ Functional Graph ã®ãµã¤ã¯ã«æ¤åºã¨ DP åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é ç¹æ° ã® functional graph ãä¸ãããã (åºæ¬¡æ° 1 ã®æåã°ã©ã)ã ãã®ã°ã©ãã® 2 é ç¹ ãããªãé åºå¯¾ ã§ãã£ã¦ãé ç¹ ããé ç¹ ã¸ã¨è³ãã¦ã©ã¼ã¯ãåå¨ãããã®ã®åæ°ãæ±ãã (â¦
é¢ç½ãã£ãï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ æ£ã®æ´æ°ãããªãé·ã ã®æ°å ãä¸ããããã ã®å¤ãæ±ããã å¶ç´ èããã㨠ã¾ãã ã¨ããå¶ç´ãæªããï¼ï¼ï¼ ãã£ã¨ã ã¨ã㦠ãªè¨ç®éã«ãªãã«éããªãã¨æããã ã¨ãããããæ°åãå ã®ã¾ã¾èããã®ã§ã¯ãªããâ¦
å¨ææ§ããã¾ããã¨æ´»ç¨ãã¦ãªãã¨ãããåé¡ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 座æ¨å¹³é¢ä¸ã§ä¸ã®å³ã®ãããªç½é»æ¨¡æ§ãä¸ãããã (åé¡æãã)ã å·¦ä¸ã®é ç¹ã ãå³ä¸ã®é ç¹ã ã§ãããããªé·æ¹å½¢é åå é¨ã®é»è²é¨åã®é¢ç© (ã® 2 å) ãæ±ããã å¶ç´ èããã㨠â¦
ChatGPT ãåé¡æã³ããã®ã¿ã§è§£ããã¨è©±é¡ã«ãªã£ãï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ æã®ã«ã¼ããããã表ã«ã¯ ãè£ã«ã¯ ãæ¸ããã¦ããã å æã¨å¾æã交äºã«ã²ã¼ã ããã交äºã«ã¾ã æ®ã£ã¦ããã«ã¼ãã®ãã¡ã表ã®å¤ãçããããè£ã®å¤ãçãããã㪠2 æã®ã«ã¼â¦
ã¨ããã³ã¼ãã¼ã±ã¼ã¹ã«ããããï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ æ´æ° ãä¸ããããã ã ã§å²ã£ãä½ãã®ä¸ã®ä½ã®å¤ãæ±ããã (ãã«ããã¹ãã±ã¼ã¹) å¶ç´ èããã㨠ã¾ãæåã«èããã®ã¯ãå ¨ä½ã ã§å²ã£ãä¸çãã§èããã°è¯ãã¨ãããã¨ã ãã®ãã¨ãæ£å½åâ¦
大æãã¦ãã¾ã£ãã®ã§èªæãè¾¼ãã¦ã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ æ´æ° ãä¸ããããã ã®ã°ãªããã§ãã£ã¦ã以ä¸ã®æ¡ä»¶ãæºãããã®ãæ§ç¯ããã åãã¹ã®å¤ã¯ 0 ã¾ã㯠1 ã§ãã åã®ãã¹ ã®å¤ã¯ãããã 1 ã§ãã è¡åã¯ãã¹ã¦ ã§ãã ååã¯ãã¹ã¦ ã§ãã â¦
é åãã©ãã®ããã®ããç³»ãæè¿å¤ããããããªãã åé¡ã¸ã®ãªã³ã¯ åé¡æ èããã㨠æä½ã®å 容ã解éããã®ã«å°ãè¦å´ããã é å ããèªå°ããã Functional Graph ãèããããã®ã°ã©ãä¸ã§ãé ç¹ ããåºçºãã¦é ç¹çªå·ã大ãããªãéãé²ãã§ãã£ãã¨â¦
é¢ç½ãã£ãï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 以ä¸ã®æ´æ° ã¨éè² æ´æ° ãä¸ããããã ã®æ£ã®ç´æ°ã®ç·ç©ã ã§æ大ä½åå²ãããã 998244353 ã§å²ã£ãä½ãã§æ±ããã å¶ç´ èããã㨠ä¸è¬ã«ã2 以ä¸ã®æ´æ° ã®æ£ã®ç´æ°ã®ç·ç©ã¯ã ã®ç´æ°ã®åæ°ã ã¨ãã㨠ã¨ãªãããâ¦
éã¿ä»ã Union-Find ãã®ãã®ããããã¯ãåæå¯è½ Union-Find 使ã£ã¦ãã¼ã¸ãã¯ã§ãã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ åã®æ´æ°å¤ ã«é¢ããå¶ç´æ¡ä»¶ã åä¸ããããã çªç®ã®å¶ç´æ¡ä»¶ã§ã¯ 3 ã¤ã®æ´æ°ã®çµ ãä¸ãããã ã¨ããå½¢ããã¦ãããããã§ã次ã®ã¯ã¨ãªã«â¦
å¼ããããããã¦æ¸æããã©ãDP èªä½ã¯æ¯è¼çåç´ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ åã®å¤ ãä¸ããããã ãããã®ä¸ããé åºãä¿ã£ã¦ããã¤ãé¸ã¶ãé¸ã³æ¹ã®ã¹ã³ã¢ã¯ã åã®æ´æ° ãé¸ãã ã¨ããã¨ãã ã§ä¸ããããããã®ã¹ã³ã¢ã®æ大å¤ãæ±ããã å¶ç´ èãããâ¦
ã¨ã¦ããããããã¦ããã£ã¦ãã¾ã£ã......ãã¨ã¦ãæè²ç㪠Greedy åé¡ã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ åã®ååããã«ãã³ã³ãã¢ã§éã°ãã¦ããã çªç®ã®ååã¯ãæå» ããæå» ã®é (両端å«ã) ã«ç¹åã§ããã ç¹åãã·ã³ã¯ 1 ç§ããã 1 åã®ååã«ããç¹åâ¦
ã¨ã¦ãå ¸åçãªãå¹³åå¤ã®æ大åãâãäºåæ¢ç´¢ãã®åé¡ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ åã®é£å¡©æ°´ãããã çªç®ã®é£å¡©æ°´ã¯ãéãã ã°ã©ã ã§ãããæ¿åº¦ ãã¼ã»ã³ãã§ããã ãããã®é£å¡©æ°´ãã åé¸ãã§æ··ãã¦ã§ããé£å¡©æ°´ã®æ¿åº¦ã®æ大å¤ãæ±ããã å¶ç´ èããâ¦
æãã®å ´ååããã¡ãã£ã¨è¦æç³»ã ãã©ä¸çº AC ã§ãã¦ããã£ãã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é«æ©åã¯ç¾å¨ ã«ãã¦ãè·ç©ã¯ ã«ãããè·ç©ãç®çå° ã«å±ãããã é«æ©åã¯è·ç©ã®ããä½ç½®ã«å ¥ããã¨ã¯ã§ãããè·ç©ã¨é£æ¥ããç¶æ ããè·ç©ã®æ¹åã«ç§»åããã¨ãè·ç©â¦
ããããåºéåå²ã® DP ã ãã©ãããã§ãããã¨ã«æãè³ãã®ãé£ãããããããªãã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ æ²ãã£ã¦ãããããã®æ²ã®é·ã㯠ã§ããã ä»ãæå» 0 ããéå§ãã¦ãæ²ãä¸æ§ã©ã³ãã ã«æµãããããçµãã£ããã¾ãä¸æ§ã©ã³ãã ã«æ²ãé¸æãã¦â¦
æè¿ãå®è£ éããå ¨æ¢ç´¢åé¡å¤ããï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ä¸å³ã®ãããªããªãªããã 3 åä¸ããããããããã 4 à 4 ã°ãªããã«ããã¾ããµã¤ãºã§ãããå ¥å㯠4 à 4 ã°ãªããã§ä¸ãããããæå '#' ã«å¯¾å¿ããé¨åãä¸ããããããªãªããã«å¯¾å¿ãããâ¦
æè¿è©±é¡ã® Functional Graph ã®åé¡ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 人 ããããå人 ã«ã¯ 1 人ãã¤å«ããªäºº ãããã ä»ãå½¼ãã«é çªã«ãã£ã³ãã£ã¼ãé ãããã ããå ã«ã¤ãã¦ããã人 ãããå ã« ã«ãã£ã³ãã£ã¼ãé ãã¨ãä¸æºåº¦ã ã ãå ç®ãããã ãã£ã³â¦