Submission #42860

#TimeUsernameProblemLanguageResultExecution timeMemory
42860ToMoClonePalindromes (APIO14_palindrome)C++14
Compilation error
0 ms0 KiB
/*input www a aba abacaba acaba ba bacaba caba */ #include <bits/stdc++.h> using namespace std; const int N = 300005; namespace SuffixArray { int pos[N], sa[N], tmp[N], lcp[N], gap, n; string s; bool SuffixCmp(int i, int j) { if(pos[i] != pos[j]) return pos[i] < pos[j]; i += gap, j += gap; return (i < n && j < n) ? (pos[i] < pos[j]) : (i > j); } void buildSA(string x) { n = (int)x.size(), s = x; for(int i = 0; i < n; ++i) pos[i] = s[i], sa[i] = i; for(gap = 1; ; gap *= 2) { sort(sa, sa + n, SuffixCmp); for(int i = 1; i < n; ++i) tmp[i] = tmp[i - 1] + SuffixCmp(sa[i - 1], sa[i]); for(int i = 0; i < n; ++i) pos[sa[i]] = tmp[i]; if(tmp[n - 1] == n - 1) break; } } void Kasai() { for(int i = 0, k = 0; i < n; ++i) if(pos[i] != n - 1) { for(int j = sa[pos[i] + 1]; s[i + k] == s[j + k]; ++k); lcp[pos[i]] = k; if(k != 0) --k; } } } namespace MaxRange { int lef[N], rig[N], mn[18][N]; int get(int l, int r) { int dist = log2(r - l + 1); return min(mn[dist][l], mn[dist][r - (1 << dist) + 1]); } long long Solve(vector<int> &x, vector<int> &val) { int n = x.size(); for(int i = 1; i < n - 1; ++i) mn[0][i] = x[i]; for(int i = 1; (1 << i) < n - 1; ++i) for(int j = 1; j + (1 << i) < n; ++j) mn[i][j] = min(mn[i - 1][j], mn[i - 1][j + (1 << (i - 1))]); long long Ans = 0; for(int i = 1; i < n - 1; ++i) { int le = 1, ri = i - 1, l, r; if(i == 1) l = 1; else if(x[i - 1] < val[i]) l = i; else { while(le < ri) { int mid = (le + ri) >> 1; if(get(mid, i - 1) < val[i]) le = mid + 1; else ri = mid; } l = le; } if(i == n - 2) r = i; else if(x[i] < val[i]) r = i; else { le = i, ri = n - 2; while(le < ri) { int mid = (le + ri + 1) >> 1; if(get(i, mid) < val[i]) ri = mid - 1; else le = mid; } r = le + 1; } Ans = max(Ans, 1ll * (r - l + 1) * val[i]); } return Ans; } } int main(){ string s; cin >> s; int n = (int)s.size(); SuffixArray::buildSA(s); SuffixArray::Kasai(); vector<int> v, val; v.reserve(n + 2), val.reserve(n + 2); v.emplace_back(- 1), val.emplace_back(0); for(int i = 0; i < n; ++i) { v.emplace_back(SuffixArray::lcp[i]); val.emplace_back(n - SuffixArray::sa[i]); } v.emplace_back(- 1), val.emplace_back(0); printf("%lld", MaxRange::Solve(v, val)) // cerr << fixed << setprecision(6) << (double)clock() / CLOCKS_PER_SEC << endl; }

Compilation message (stderr)

palindrome.cpp: In function 'int main()':
palindrome.cpp:114:1: error: expected ';' before '}' token
 }
 ^