Submission #1085050

#TimeUsernameProblemLanguageResultExecution timeMemory
1085050AliyyiakbarPalindromes (APIO14_palindrome)C++17
100 / 100
36 ms69600 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/hash_policy.hpp> #include <ext/pb_ds/hash_policy.hpp> #define int long long #define $AzH_TxdmN$ ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr); #pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native") #pragma GCC optimize("Ofast") #pragma GCC optimize("no-stack-protector") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("fast-math") #define ep emplace_back #define pb push_back #define pii pair<int,int> #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() using namespace std; using namespace __gnu_pbds; template <typename T> using __indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template <typename T> using __indexed_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; const int sz = 3e5+9; const int LOG = 65; const int MOD = 1e9+7; const int INF = 1e18; struct PT { struct Node { int next[26], link, len; int occ; }; string s; vector<Node> t; int siz, last, n; int res; PT(string& _s) : s(_s), n(_s.size()), res(0) { t.resize(n + 3); t[0].len = -1; t[1].len = 0; t[0].link = t[1].link = 0; siz = 2, last = 1; for (int i = 0; i <= n; ++i) { for (int j = 0; j < 26; ++j) { t[i].next[j] = -1; } } } void extend(int i) { int cur = last, cur_len = 0, letter = s[i] - 'a'; while (true) { cur_len = t[cur].len; if (i - cur_len - 1 >= 0 && s[i] == s[i - cur_len - 1]) { break; } cur = t[cur].link; } if (t[cur].next[letter] != -1) { last = t[cur].next[letter]; t[last].occ++; return; } last = siz++; t[last].len = t[cur].len + 2; t[last].occ = 1; t[cur].next[letter] = last; if (t[last].len == 1) { t[last].link = 1; } else { while (true) { cur = t[cur].link; cur_len = t[cur].len; if (i - cur_len - 1 >= 0 && s[i] == s[i - cur_len - 1]) { t[last].link = t[cur].next[letter]; break; } } } } void build() { for (int i = siz - 1; i >= 2; --i) { t[t[i].link].occ += t[i].occ; } } void calllc() { for (int i = 2; i < siz; ++i) { res = max(res,t[i].len*t[i].occ); } } }; string s; void solve() { cin>>s; PT pt(s); for (int i = 0; i < (int)s.length(); ++i) { pt.extend(i); } pt.build(); pt.calllc(); cout<<pt.res<<'\n'; } signed main() { $AzH_TxdmN$ int t = 1; //cin >> t; while (t--) { solve(); } }
#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...