æ¨æ¥ã®è¨äºã®ç¶ãã§ãã Manacher æååãä¸ããããæãå i ã«ã¤ãã¦ãæå i ãä¸å¿ã¨ããæé·ã®åæã®åå¾ããè¨é²ããé å R ã O(|S|) ã§æ§ç¯ããã¢ã«ã´ãªãºã ã§ããåå¾ã¨ããã®ã¯ã(å ¨é·+1)/2ã§ãã ä¾ãã°ã abaaababa 121412321 ãããªæãã§ãã çµè«ããè¨ãã¨ãManacherã®ã³ã¼ãã¯ä»¥ä¸ã®ããã«ãªãã¾ãã int i = 0, j = 0; while (i < S.size()) { while (i-j >= 0 && i+j < S.size() && S[i-j] == S[i+j]) ++j; R[i] = j; int k = 1; while (i-k >= 0 && k+R[i-k] < j) R[i+k] = R[i-k], ++k; i += k; j -= k; } ãã®ã³ã¼ããä½ããã¦ããã®ããè¦ã¦ããã¾ãã ã¨
{{#tags}}- {{label}}
{{/tags}}