Submission #868894

#TimeUsernameProblemLanguageResultExecution timeMemory
868894sleepntsheep회문 (APIO14_palindrome)C++17
100 / 100
18 ms34908 KiB
#include <iostream> #include <cstring> #include <vector> #include <algorithm> #include <deque> #include <set> #include <utility> #include <array> using namespace std; #define ALL(x) x.begin(), x.end() #define ShinLena cin.tie(nullptr)->sync_with_stdio(false); using ll = long long; #define N 300005 char s[N]; int lz[N], len[N], link[N], nxt[N][26], n = 2, t = 2; ll ans; void init() { n = t = 2; len[1] = -1, link[1] = 1; len[2] = 0, link[2] = 1; } void append(int pos) { int la, l, c = s[pos] - 'a'; for (l = t; !(pos-1>=len[l] && s[pos-1-len[l]] == s[pos]); l = link[l]); if (nxt[l][c]) { ++lz[t = nxt[l][c]]; return; } t = ++n; len[n] = len[l] + 2; ++lz[n]; nxt[l][c] = n; if (len[n] == 1) { link[n] = 2; return; } for (la = link[l]; !(pos-1>=len[la] && s[pos-1-len[la]] == s[pos]); la=link[la]); link[n] = nxt[la][c]; } void pushlazy() { for (int i = n; i >= 3; --i) { lz[link[i]] += lz[i]; ans = max(ans, 1ll*lz[i]*len[i]); } } int main() { ShinLena; cin >> s; init(); for (int i = 0; s[i]; ++i) append(i); pushlazy(); cout << ans; 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...