2020-02-01ãã1ã¶æéã®è¨äºä¸è¦§
ãããé¢ç½ãã£ãï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ åã®è¢ããã£ã¦ãããããã«ã¯ æ¿è¾ãããã æ¬ ç¾å³ãããããã æ¬ ããããå æã¨å¾æã以ä¸ã®ãã¨ã交äºã«è¡ãã æ¿è¾ãããã 0 æ¬ã¾ã㯠1 æ¬åãåºã ç¾å³ãããããã好ããªæ¬æ°ã ãåãåºã ãã ããæ¿â¦
ããªã¼ä¸ã®ãã¹ã¯ã¨ãªã«ã¤ãã¦ã®æè²çå ¸åé¡ã ã£ã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ (æ訳) é ç¹ã®éã¿ä»ãããªã¼ãä¸ããããã以ä¸ã® åã®ã¯ã¨ãªã«çããã åã¯ã¨ãªã¯ 2 é ç¹ , ã¨å¤ ãæå®ãããããªã¼ä¸ã® 㨠ã¨ãçµã¶ãã¹ä¸ã®è¾ºã®éã¿ã®ç©ãæ±ãããã㨠ãâ¦
å¾ãããè¦ããããã£ã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ã®é å ã§ãã£ã¦ã以ä¸ã®æ¡ä»¶ãæºãããã®ã®åæ°ã 1000000007 ã§å²ã£ããã¾ããæ±ããã ä»»æ㮠以ä¸ã®å¥æ° ã«å¯¾ãã¦ã ã®ã¡ãã£ã¢ã³ã¯ ã§ãã å¶ç´ èããã㨠簡åã®ããã ãå¥æ°ã¨ãã¦èãã¦ã¿ãããã®â¦
é·ç§»å ãçµãã系㮠DP åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é·ã ã®æåå ãä¸ãããããããã以ä¸ã®æ¡ä»¶ãæºããããã«æå°åæ°ã®åºéã«åå²ããããæå°åæ°ãæ±ããã ã©ã®åºéã«ã¤ãã¦ããåºéå ã®æåãé©åã«ä¸¦ã³æ¿ããã¨åæã«ãªã å¶ç´ èããã㨠ã¾ããæâ¦
æä½ãè¨ãæããã¨ããã¯æ¥½ãããã©ãBinaryTrie ãå¿ è¦ã¨ãããã¨ã§ãå¿ æ»ã«æ´åããã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ è¦ç´ ã®éè² æ´æ°å ãä¸ããããã以ä¸ã®æä½ã好ããªåæ°ã ãè¡ãããè¡ãªã£ãçµæå¾ãããæ°åã®ãã¡ãè¾æ¸é æå°ã®ãã®ãæ±ããã index â¦
BinaryTrie ã確èªããï¼ï¼ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ æ°ã®éå S ã«å¯¾ãã以ä¸ã®ã¯ã¨ãª ( å) ãå¦çãã¦ãã ããã S ã«æ° X ã追å ãã S ã«å«ã¾ããæ°ã®ãã¡ X çªç®ã«å°ããæ°ãçãããã®æ°ã S ããåé¤ãã å¶ç´ èããã㨠BIT ã priority_queueãâ¦
æä½ã åè¡ã£ãçµæãæ±ããç³»ãè¦ææèãããã©å æãããï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ã¨çªå·ã®æ¯ããã åã®ãã¼ã«ããã£ã¦ãåæç¶æ ã§ã¯ãããã ã®ä½ç½®ã«ããã以ä¸ã®æä½ã åè¡ããæçµçãªåãã¼ã«ã®åº§æ¨ã®æå¾ å¤ãããããæ±ããã åæä½ã¯ åã®â¦
å°ãã§ãå®è£ ã楽ã«ããã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ è±å°æåã®ã¿ãããªãé·ã ã®æåå ãä¸ããããã以ä¸ã®æä½ãæå°åæ°è¡ã£ã¦åæã«ãããããã®æå°åæ°ãæ±ãããä¸å¯è½ãªå ´å㯠-1 ãåºåããã ã®ã©ããã« 'x' ãæ¿å ¥ãã å¶ç´ èããã㨠ã¾ãå¯â¦
æå¾ å¤ã®ç·å½¢æ§ï¼ï¼ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ åã®ãµã¤ã³ããå·¦ããå³ã«ä¸åã«ä¸¦ã¹ã¦ããã çªç®ã®ãµã¤ã³ãã¯ç®ã ã¨ãªã£ã¦ãã¦ãããããå½ç¢ºçã«åºãã é£æ¥ãã åã®ãµã¤ã³ããé¸ãã§ããããç¬ç«ã«æ¯ã£ãã¨ããåºãç®ã®åè¨ã®æå¾ å¤ã®æ大å¤ãæ±ãããâ¦
ãããããã©ã®å¤ãä½åããã¾ãããçãªå¦çæ¹æ³ã¯å ¸åãã¿ã¼ã³ã 2 ã¤ããã¨æã std::set ã std::map ãªã©ã®é£æ³é åãç¨ãã¦ç®¡çãã ã½ã¼ããã¦ã½ã¼ãé ã«å¦çãã¦ãã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ åã®æ´æ° ãä¸ããããããã®æ´æ°åã®ã©ã® 2 ã¤ã®è¦ç´ ãâ¦
DP ããªãã¦ãéã«åããã©ãæ¡ DP çãªèãæ¹ãå½¹ã«ç«ã¤ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 100 æ¡ä»¥ä¸ã®æ´æ° ãä¸ããããã ä»¥ä¸ ä»¥ä¸ã®æ´æ°ã§ãã£ã¦ãåé²æ³è¡¨è¨ã§ 0 以å¤ã®æ°å¤ãã¡ããã© åã§ãããããªãã®ãä½åããã®ããæ±ããã å¶ç´ ã®æ¡æ° èããã㨠â¦
ãã£ããè²ããªæ¹æ³ãããããï¼ï¼ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ æ£ã®æ´æ° ãä¸ããããã, ãæºãããã¹ã¦ã®æ´æ° ã«ã¤ãã¦ã® ã®ç·åã 1000000007 ã§å²ã£ããã¾ããæ±ããã å¶ç´ èããã㨠ã¨ããããäºé ä¿æ°ã®è¨ç®èªä½ã¯ãé©åã«åå¦çããã¦ããã°ã ã§â¦
é¢ç½ãã£ããã©ãå®éã«å®è£ ããã®ã¯è¾ãã£ãã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ã®ã°ãªãããä¸ãããããåãã¹ã 2 ã¾ã㯠5 ã§åãããããã ã以ä¸ã®æ¡ä»¶ãæºããããã«ãããã 2 ãæ¸ããããã¹ã ãã«çç®ããä¸ä¸å·¦å³æã ã«é£æ¥ãããã¹å士ã«è¾ºãå¼µã£ãã°â¦
é¢ç½ãã£ã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ã®ç¤é¢ã®åãã¹ã 0 ã 1 ãã§åãããããã§ã« åã®ãã¹ã«ã¤ãã¦ã¯æ°åãåã¾ã£ã¦ããã以ä¸ã®æ¡ä»¶ãæºããããã«æ®ã ãã¹ãåããæ¹æ³ã¯ä½éããããã998244353 ã§å²ã£ããã¾ãã§æ±ããã ä¸è¾ºã®é·ãã 2 以ä¸ãªé¨åâ¦
ããããã®ã確å®ã«... åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 1 以ä¸ã®æ´æ°ãããªãé·ã ã®æ°å ãä¸ããããããã®æ°åã«å¯¾ãã¦ã以ä¸ã®æä½ã好ããªåæ°ã ã好ããªé åºã§è¡ããã¨ã§åºç¾©å調å¢å ã¨ãªãããã«ããããæå°åæ°ãæ±ããã åã®æ´æ°ãã 1 ã¤é¸ã㧠-2 åâ¦
ä»ã® RUPC / AUPC ã®å é§ãã¨ãªã£ãå宿ã®å大ã»ããã®åé¡ï¼ï¼ï¼ ãã®ã»ããã¯ãå ¨åé¡ã®ã¿ã¤ãã«ã®é æåã 'D' ã¨ããã»ããã ã£ã ã»ããã¸ã®ãªã³ã¯ å大ã¢ã¼ã«ã¤ãã¸ã®ãªã³ã¯ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é·ã ã®é å ãä¸ããããããããã並ã³æ¿ãã¦å®â¦
é¢ç½ãã£ãï¼ï¼ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é ç¹ã®æ¨ãä¸ãããããæ¨ã®å辺ã«å¯¾ãã¦ã以ä¸ã®æ¡ä»¶ãæºããããã« 1 ä»¥ä¸ 1000000 以ä¸ã®æ´æ°å¤ãå²ãæ¯ãããã æ¡ä»¶ã¯ åãã çªç®ã®æ¡ä»¶ã¯ã2 é ç¹ ã¨æ´æ°å¤ ãæå®ããã¦ã ãçµã¶ãã¹ä¸ã®è¾ºã®å¤ã®æå°å¤ãâ¦
ããã¨åãã§ã¯ï¼ï¼ atcoder.jp åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é·ã ã®æåå ãä¸ããããã ãã¾ãæååã®å index ã«è²ãå¡ããã¨ãèãããè²ãå¡ã£ããã¨ãé£æ¥ããç°ãªãè²ãã㤠2 æåã swap ãããã¨ãã§ãããswap ããçµæå¾ãããæååãã½ã¼ããâ¦
Union-Find ã使ãããªãï¼ï¼ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ (æ訳) åã® 0-1 å¤æ° ãä¸ãããã¦ãã¦ãæåã¯ãããã®å¤ã«ã¤ãã¦ç¹ã«å¶ç´ã¯ãªãããã¾ã åã®å¶ç´ãé ã«ä¸ãããããåå¶ç´ã¯ãããã 1 ã¤ã®å¤æ° 㨠0 ã 1 ã®å¤ w ãæå®ãã¦ã ã¨ãã 2 ã¤ã®å¤â¦
æ¨ DP ã·ãªã¼ãºï¼ï¼ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ åºéã°ã©ãã¨ã¯ã åã®åºéãä¸ããããã¨ãã«ãååºéãåé ç¹ã«å¯¾å¿ãããintersection ãããåºéå士ã«è¾ºãå¼µããããããªã°ã©ãã®ãã¨ã§ããã ãã¦ã é ç¹ã®æ¨ãä¸ããããããã®æ¨ã®é£çµãªé¨åã°ã©ã (â¦
ãã¡ããã¡ãç°¡åãªå®è£ ã§è¯ããã¨ãããã£ãã®ã§ã ãªãããDFS 2 åããå ¨æ¹ä½ããããªã®ãã¨æã£ã¦ããã©ãã¨ã¦ãç°¡åãªæ¨DPã§ç´å¾ãæ±ãããããã¨ãç¥ã£ãã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é ç¹ã®éã¿ä»ãæ¨ãä¸ããããã®ã§ããã®ç´å¾ã®é·ããæ±ããã å¶ç´â¦
ããããã®ãç´ æ©ãå¦çã§ããããã«ãªããã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é·ã 㮠種é¡ã®æåãããªãæåå ãä¸ããããããã¾ã 種é¡ã®æåã®é å ã¨ãã¦èãããã éãã®ä¸¦ã³ã®ãã¡æé©ãªãã®ãæ±ãããã é åã®ã¹ã³ã¢ã¯ã ä¸ã®ãã¹ã¦ã®é£ç¶ãã 2 æåâ¦
é¢ç½ãã£ã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ æåå ã good ã§ããã¨ã¯ã ã®é£ç¶é¨åæååã§ãã£ã¦åæã§ãããããªåºéããã¹ã¦ã¨ã£ã¦ããã¨ãã«ããããã«ãã£ã¦ ã被è¦ããããã¨ãããããã¨ãã° "aaba" ã¯ã"aa" 㨠"aba" ã«ãã£ã¦è¢«è¦ãããã®ã§ good ã§ãâ¦
ãæä½ã«ãã£ã¦åºæ¥ä¸ãããã®ãä½éããããï¼ãã¨ããåé¡ã§ã¯ãã¾ãå¤å®åé¡ãèããï¼(ç´ æ¯ã) åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ã®ã°ãªããããã£ã¦ãåãã¹ã¯ç½ã¾ãã¯é»ã«å¡ããã¦ããã以ä¸ã®æä½ã好ããªé åºã§å¥½ããªåæ°ã ãè¡ã£ãçµæå¾ãããç¤é¢ãä½éãâ¦
åã¨å¤è§å½¢ã®å ±éé¨åã®é¢ç©ãæ±ããã©ã¤ãã©ãªãä¸å¿µçºèµ·ãã¦æ´åããï¼ï¼ï¼ ãµãã«ã¼ãã³ã¨ãã¦ãå㨠"ç·å" ã®äº¤ç¹ãæ±ãããã¨ããã©ã¤ãã©ãªãå¿ è¦ã¨ãªãã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ åç¹ãä¸å¿ã¨ããåå¾ ã®åã¨ã é ç¹ã®å¤è§å½¢ãä¸ããããããããâ¦
ãã¼ã¸ãã¯ç«¥è²ãåæ¥ããï¼ï¼ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é ç¹ã®æ ¹ä»ãæ¨ãä¸ãããã (æ ¹ã®çªå·ã¯ 1)ãã¾ãåé ç¹ ã«ã¯è² ãå¡ããã¦ãããè²ã¯æ´æ°å¤ã§è¡¨ããããåé ç¹ ã«ã¤ãã¦ã以ä¸ã®åãã«çããã ãã®é ç¹ãæ ¹ã¨ããé¨åæ¨ãèãã ãã®é¨åæ¨ã§ãâ¦
åã¨åã®å ±éé¨åã®é¢ç©ï¼ï¼ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ åã 2 ã¤ä¸ããããããããã®å ±éé¨åã®é¢ç©ãæ±ããã å¶ç´ 座æ¨ã®çµ¶å¯¾å¤ã ä»¥ä¸ è§£æ³ ãæ¥ããå ´åããé¤ãã¨ã以ä¸ã® 3 ãã¿ã¼ã³ã«ãããã å®å ¨ã« disjoint (é¢ç©ã¯ 0) 2 ç¹ã§äº¤ãã ä¸æ¹ãä»æ¹â¦
ãããé¢ç½ãã£ãï¼ï¼ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ æ´æ° ãä¸ããããã¨ãã«ã漸åå¼ ãæºããæ°å ãä¸ãããããããã«å¯¾ãã¦ä»¥ä¸ã® åã®ã¯ã¨ãªã«çãã: 1 ã¤ã®ã¯ã¨ãªã¯ 2 以ä¸ã®æ´æ° ãæå®ããã ãæºãããããªæ£ã®æ´æ° ã«å¯¾ãã¦ã ã®ç·åãæ±ãã10000â¦
LIS ã®äºç¨®ã ãã©ãé°å²æ°éã£ã¦é¢ç½ãï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é·ã ã®æ£ã®æ´æ°å ãä¸ããããããã®é¨ååã§ãã£ã¦ ç義å調å¢å å¾ã® index ã«åºã¦ãããã¤ã¯åã® index ã«ã§ã¦ãããã¤ã®åæ°ã«ãªã£ã¦ãã ã¨ããæ¡ä»¶ãæºãããã®ã®æé·ã®é·ããæ±ãâ¦