ABC-C
ãããé¢ç½ãåé¡ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ åã®æåå ãä¸ããããã ãããã®æååããç°ãªã 2 ã¤ã®æååãé¸ã¶æ¹æ³ã§ãã£ã¦ããããã®æååãäºãã«ã¢ãã°ã©ã ã¨ãªã£ã¦ãããã®ã®åæ°ãæ±ããã å¶ç´ èããã㨠ã¾ãã¯ãåé¡ã®æ¡ä»¶ãããããããâ¦
é£æ³é åã®è¯ãç·´ç¿åé¡ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ æ£ã®æ´æ°ãããªãæ°åãè¯ãæ°åã§ããã¨ã¯ãæ°åã«å«ã¾ããä»»æã®æ´æ°å¤ ã«ã¤ãã¦ãæ°åä¸ã« ãã¡ããã© åå«ã¾ãã¦ãããã¨ãããã ä¸ããããæ°å ã«å¯¾ãã¦ãããã¤ãã®è¦ç´ ãåé¤ãããã¨ã§ãããæ°â¦
ããå®ã¯ãã¢ã«ãã¡ãããæåã®å¤æãã¼ãã«ãæç´ã«ä½ããã¨ããç´ æ´ãªæ¹æ³ã解ãããã©ãæå¤ã¨ç²ç¹ã«ãªãããã ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ è±å°æåã®ã¿ãããªãé·ã ã®æåå ãä¸ããããã次㮠åã®æä½ãå®è¡å¾ã®æååãåºåããã ãæä½ã æå â¦
ã©ã³ã¬ã³ã°ã¹å§ç¸®ã§è§£ãã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 0 㨠1 ãããªãé·ã ã®æåå ãä¸ããããããã®æååã®ä¸ã§ã®ã1 ã®å¡ãã®ãã¡ãå·¦ãã çªç®ã®ãã®ãã çªç®ã®ãã®ã®å³ã«ç§»åãããã ä¾ï¼"010011100011001" â "010011111000001" å¶ç´ èããã㨠ã¾â¦
ããã¯ãããããï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ãã¹ ãä¸åã«ä¸¦ãã§ãããæåã åã®ãã¹ã«ç³ãå ¥ã£ã¦ããããã¹ ã«ã¯ åã®ç³ãå ¥ã£ã¦ãããããªãã¯ä»¥ä¸ã®æä½ã好ããªåæ°è¡ããã¨ãã§ããã ããã¹ ã«ç³ãããã¨ãããã¹ ãããã¹ ã¸ã¨ç³ã 1 ã¤ç§»åããâ¦
座æ¨ãã¨ã«æ å ±ãæ´çããã®ã¯é »åºï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ x-y 座æ¨å¹³é¢ä¸ã« 人ããããããããåº§æ¨ ã®ä½ç½®ã«ãã¦ãå·¦å³ãããããåãã¦ããï¼å人ãå·¦å³ã©ã¡ããåãã¦ãããã¯æåå ã§ä¸ããããï¼ã å人ãããã®ä½ç½®ãããåãã¦ããæ¹åã«åãã£â¦
æå¤ã¨æ´çããã®ã大å¤ã ã¨æããmap ã使ã£ã¦æ´çãããã¨ããã®ãèªç¶ã ããããã¡ãã£ã¨ç°¡åã«è§£ããã¨ãèãããã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ æååãæ稿ããã¨å¾ç¹ãä¸ããããã³ã³ãã¹ãã«ã åã®æåå ããã®é ã«æ稿ããããããã ç¹ãä¸ãããâ¦
SNS ãé¡æã«ãã set ã®ç·´ç¿åé¡ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 人ãã SNS ã«ã¤ãã¦ã次㮠åã®ã¯ã¨ãªã«çããï¼åæç¶æ ã§ã¯å ¨å¡ã誰ããã©ãã¼ãã¦ããªãï¼ã ã¯ã¨ãªã¿ã¤ã 1ï¼äºº ã人 ããã©ãã¼ããï¼ãã©ãã¼æ¸ã¿ã®å ´åã¯ä½ãããªãï¼ ã¯ã¨ãªã¿ã¤ã 2ï¼äºº â¦
ã¡ãã£ã¨ããèå¯ãå¿ è¦ã«ãªãåé¡ã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ æ´æ°ãããªãæ°å ãä¸ãããããæ°åã®åè¦ç´ ã«å¯¾ãã¦ãä½ãããªããã1 ã足ããã1 ãå¼ããããã¦ããã æä½å¾ã«ãæ´æ°å¤ ãé¸ã¶ã ã¨ãªã ã®åæ°ã®æ大å¤ãæ±ããã å¶ç´ èããã㨠åé¡â¦
åºéã伸ã°ããã縮ãããããªãããããã«ä¼´ããæ¿å ¥ãããåé¤ãã«å¯¾å¦ãããã¼ã¿æ§é ãèããç³»ã®åé¡ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ æ°å ã«ã¤ãã¦ãé£ç¶ãã åã®è¦ç´ ã®ç¨®é¡æ°ã®æ大å¤ãçããã å¶ç´ èããã㨠æ°åã®å¹ ã®åºéããã¹ã¦èª¿ã¹ãã«ã¯ã次ã®â¦
é£æ³é åã®ç·´ç¿åé¡ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é·ã ã®æ´æ°å ãä¸ããããããã®æ°åã«å¯¾ãã¦ã次㮠åã®ã¯ã¨ãªã«çããã ãã¯ã¨ãªã æ´æ° ãä¸ããããã®ã§ãæ´æ°åãé ã«è¦ã¦ãã£ãã¨ãã®ã åç®ã®å¤ ã®è¦ç´ ãã® index ãçããï¼åå¨ããªãå ´å㯠-1ï¼â¦
é£æ³é åãæå¹æ´»ç¨ã§ããåé¡ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ åã®æåå ãããã ç»å ´åæ°ã®æãå¤ãæååããè¾æ¸é ã«åºåããã å¶ç´ èããã㨠åæååãããããä½åããã®ããæ±ããããããã§ã次ã®ãããªé åãä½ãããã nums[str]ï¼æåå str ã®ç»â¦
set ã®ç·´ç¿ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ äºæ¬¡å å¹³é¢ä¸ã«é«æ©åããããé«æ©åã¯åç¹ãã移åã åè¡ã£ãã åã®ç§»åã¯é·ã ã®æååã§è¡¨ããããåæå㯠Lï¼å·¦ã¸ç§»åï¼ãRï¼å³ã¸ç§»åï¼ãUï¼ä¸ã¸ç§»åï¼ãDï¼ä¸ã¸ç§»åï¼ã®ããããã§ããã é«æ©åãåã座æ¨ã«â¦
é£æ³é åï¼è¾æ¸ï¼ã®ç·´ç¿åé¡ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ æåå ãä¸ããããã å ã«å¯¾ãã¦ã ã¨ãªã ãåå¨ããªãå ´å㯠ããã®ã¾ã¾åºåãã ã¨ãªã ãåå¨ããå ´åã¯ããã®åæ°ã ã¨ããã¨ãã ã« "(k)" ãä»ãã¦åºåãã å¶ç´ èããã㨠åé¡æã§è¨ããâ¦
é£æ³é åã§éè¨ããã¨ããæãã«è§£ããï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ æã®é´ä¸ããã£ã¦ãé´ä¸ ã®è²ã¯ ã¨ããæ´æ°å¤ã§è¡¨ãããã è²ã®çããé´ä¸ããã¢ã«ããã¨ããæ大ã§ä½ãã¢ä½ãããï¼ å¶ç´ èããã㨠次ã®ããã«èãããã è²ãã¨ã«é´ä¸ãä½åããããæ´â¦
ãããæ°å¦çãªåé¡ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 縦ã横ãé«ãã®ç·åã ã§ãããããªç´æ¹ä½ã®ä½ç©ã®æ大å¤ãæ±ããã å¶ç´ èããã㨠縦ã横ãé«ãã®é·ãã ã¨ãããããã®ã¨ãã次ã®åé¡ã«ãªãã ã®ã¨ãã ã®æ大å¤ãæ±ãã ãã®æã®åé¡ã§ã¯ã ã®ã¨ãæ大ã«â¦
map ã®ç·´ç¿åé¡ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é·ã ã®æ°å ãä¸ããããã å ã«ã¤ãã¦ã ã㤠ãæºããæ大ã®æ´æ° ãæ±ããï¼åå¨ããªãå ´å㯠-1ï¼ã å¶ç´ èããã㨠åºæ¬çã«ã¯æ¬¡ã®æ å ±ã管çã§ããé åã欲ããã last[v]ï¼ãã®æç¹ã§ã ãæºããæ大㮠â¦
ãµã³ãã«ãè¦ãã°ä¸éãåããç³»ã®åé¡ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ åæ¡ã®å¤ã 1 ã§ããæ°ãã¬ãã¦ãããæ°ã¨ããã ã¬ãã¦ãããæ° 3 åã®åã¨ãã¦èããããæ°ã®ãã¡ã çªç®ã«å°ããæ°ãæ±ããã å¶ç´ èããã㨠ã¾ããåé¡æã®æ¡ä»¶ãæºããæ°ãããªã¬ãâ¦
æç´ã·ãã¥ã¬ã¼ã·ã§ã³ãããåé¡ããã ãããç¨åº¦ã¯è¨ç®éãç¥ããªãã¨ãããã«ãããå¯è½æ§ãããã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ããã·ã£ã¯ã¼ã¯ãã¹ã¤ãããæ¼ãã¨ãã®å¾ ç§éã湯ãåºã (延é·ããããã§ã¯ãªã)ã æå» (å調å¢å ) ã«ã¹ã¤ãããæ¼ããã¨ããâ¦
ãã®æ代ããã®æã® Greedy ã¯ãããããã£ãã®ãï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é·ã ã®æ°å ãä¸ããããããæ°åã®è¦ç´ ã 1 ã¤é¸ã³ã+1 ãããã-1 ãããã¨ããæä½ãè¡ããã¨ã§ã次ã®ç¶æ ãéæãããããã ãã ã¨ããã ãã¹ã¦ã® ã«å¯¾ãã¦ã ã§ãã ãã¹â¦
éè¨å¦çã®å¿ç¨åé¡ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ä¸è¬ã«ãæåå ããããã¤ãã®æåãæãåºãã¦ãããã並ã³æ¿ãããã¨ã«ãã£ã¦æåå ãä½ããã¨ãã ãã ãä½ããã¨ããã è±å°æåãããªã åã®æåå ãä¸ããããã ã®ããããããä½ããæåå ã®ãã¡â¦
bit å ¨æ¢ç´¢ãæå¤ã¨æãæµ®ãã³ã¥ãããããããªãã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ åã®æ£ã®æ´æ° ãä¸ããããããããã®æ´æ°ã A, B ã® 2 ã°ã«ã¼ãã«åããã ã®æ大å¤ãæ±ããã å¶ç´ èããã㨠bit å ¨æ¢ç´¢ã使ãã¨ã åã®ãã®ã«å¯¾ãã¦ã0ãã1ãã®å¤ãå²ãå½â¦
å°ãèå¯ãå¿ è¦ã«ãªãåé¡ãçµå±ééãªãä½ããã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ æåãé»æ¿ã« 0 ã¨ããæ°ãæ¸ããã¦ããã ç§å¾ã«ã¯ãé»æ¿ã«æ¸ãããæ° ã以ä¸ã®ããããã«ç½®ãæãããã¨ãã§ããã é»æ¿ã«æ¸ãããæ°ã ã«ã§ããã®ã¯æçã§ä½ç§å¾ãï¼ å¶ç´ èãâ¦
è¨ç®éæ¹åã®ãã¨ãæ¬å½ã«ç¥ããªãã¨ãTLE ã«æ©ããããããªãã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é·ã ã® 2 ã¤ã®æ°å ã ãä¸ããããã 1 ä»¥ä¸ ä»¥ä¸ã®æ´æ° ãé¸ãã§ã ã®æ大å¤ãæ±ããã å¶ç´ èããã㨠æãç´ ç´ã«èããã¨ã次ã®ããã«äºé for æãç¨ãã¦è§£ãâ¦
ã¹ã¿ãã¯ã®ããç·´ç¿åé¡ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 空ã®å㨠åã®ãã¼ã«ãããã çªç®ã®ãã¼ã«ã®å¤§ãã㯠ã§ããããããã åã®æä½ãè¡ãã åç®ã®æä½ã§ã¯ã åç®ã®ãã¼ã«ãåã®ä¸çªå³ã«ä»ãå ããå¾ã次ã®æé ãç¹°ãè¿ãã åã«ãããã¼ã«ã 1 ã¤ä»¥ä¸ãªâ¦
ãã®æ代å¤ãè¦ããããã°ã«ã¼ãã³ã°ãã®åé¡ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ S åãã¼ã¹ 1 å㨠c åãã¼ã¹ 2 åã使ã£ã¦ãä¸å³ã®ããã« Scc ã 1 åä½ããã¨ãã§ããã ã¾ããc åãã¼ã¹ 2 åã使ã£ã¦ S åãã¼ã¹ 1 åãä½ããã¨ãã§ããã ä»ãS åãã¼ã¹ã â¦
å·®åã®ã¿æ´æ°ãã¦ããç³»ã®å ¸ååé¡ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ é·ã ã®æåå ãä¸ããããã次㮠åã®ã¯ã¨ãªã«çããã ãã¯ã¨ãªã æ´æ° ã¨æå ãä¸ããããã®ã§ã ã ã«å¤æ´ããããã®å¾ã®æåå ã®ä¸ã«ã"ABC" ãä½åå«ã¾ããããçããã å¶ç´ èãããã¨â¦
ã¡ãã£ã¨ããç®æ°ã®åé¡ï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ãµã¤ã³ãã転ããã¦ããããµã¤ã³ãã®ä¸ã®ç®ã®å¤ã足ãã¦ããã ãã®ç·åã 以ä¸ã¨ãªãã¾ã§ã®æå°åæ°ãæ±ããã å¶ç´ èããã㨠6, 5, 6, 5, ... ã¨ç¹°ãè¿ãã¦ããã®ãæé©ã§ããããããæ±ããããã«ãâ¦
ä»ã®æ代ã ã¨ãã¾ãè¦ãããªãã¿ã¤ãã®æ°å¦ã²ã¼åé¡ã åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ 人 ãä¸åã«ä¸¦ã¹ãæ¹æ³ã®ãã¡ã次ã®æ¡ä»¶ããã¹ã¦æºãããã®ã®åæ°ã 1000000007 ã§å²ã£ãä½ããæ±ããã 人 ã«ã¤ãã¦ãå·¦å´ã«ãã人æ°ã¨å³å´ã«ãã人æ°ã®å·®ã ã«çãã å¶ç´ èâ¦
綺éºãªè¨èã§æ¡ä»¶ãè¨ãæãããï¼ åé¡ã¸ã®ãªã³ã¯ åé¡æ¦è¦ ä¸åã«ç½è²ç¢ç³ã¨é»è²ç¢ç³ãåè¨ å並ãã§ããã å·¦å³ã®ããããã«ç½è²ç¢ç³ã¨é»è²ç¢ç³ãç½®ãã¦ããããã®ã¨ãããªã»ãã®ã«ã¼ã«ã«åºã¥ãã¦ç³ã®è²ãã²ã£ããè¿ãã ãã¹ã¦ã®è²ãåè²ã«ããã®ã«å¿ è¦â¦