제출 #635319

#제출 시각아이디문제언어결과실행 시간메모리
635319tvladm2009회문 (APIO14_palindrome)C++14
0 / 100
26 ms36336 KiB
#include <iostream> using namespace std; const int MAX_N = 3 * 1e5; const int SIGMA = 26; string s; struct Node { int next[SIGMA]; int sufflink; int len; int num; int occ = 0; }; Node tree[MAX_N + 3]; int cnt = 2, suffix = 2; void addletter(int pos) { int let = s[pos] - 'a'; int cur = suffix, curlen = 0; while (true) { curlen = tree[cur].len; if (pos - curlen - 1 >= 0 && s[pos - curlen - 1] == s[pos]) { break; } cur = tree[cur].sufflink; } if (tree[cur].next[let]) { suffix = tree[cur].next[let]; return; } cnt++; suffix = cnt; tree[cnt].len = tree[cur].len + 2; tree[cur].next[let] = cnt; if (tree[cnt].len == 1) { tree[cnt].sufflink = 2; tree[cnt].num = 1; return; } while (true) { cur = tree[cur].sufflink; curlen = tree[cur].len; if (pos - curlen - 1 >= 0 && s[pos - curlen - 1] == s[pos]) { tree[cnt].sufflink = tree[cur].next[let]; break; } } tree[cnt].num = tree[tree[cnt].sufflink].num + 1; } void init() { tree[1].len = -1; tree[1].sufflink = 1; tree[2].len = 0; tree[2].sufflink = 1; } int main() { cin >> s; int n = s.size(); init(); for (int i = 0; i < n; i++) { addletter(i); } int answer = 0; for (int i = cnt; i >= 1; i--) { tree[i].occ++; answer = max(answer, tree[i].occ * tree[i].len); tree[tree[i].sufflink].occ += tree[i].occ; } cout << answer; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...