Submission #42049

#TimeUsernameProblemLanguageResultExecution timeMemory
42049cmasterPalindromes (APIO14_palindrome)C++14
0 / 100
1077 ms4296 KiB
#include <bits/stdc++.h> /*#include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/detail/standard_policies.hpp>*/ #define pb push_back #define mp make_pair #define sz(s) ((int)(s.size())) #define all(s) s.begin(), s.end() #define rep(i, a, n) for (int i = a; i <= n; ++i) #define per(i, n, a) for (int i = n; i >= a; --i) #define onlycin ios_base::sync_with_stdio(false); cin.tie(0) using namespace std; // using namespace __gnu_pbds; typedef long long ll; typedef unsigned long long ull; /*typedef tree< pair < int, int >, null_type, less< pair < int, int > >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;*/ // find_by_order() order_of_key() const int MAXN = (int)1e5+228; const char nxtl = '\n'; const int mod = (int)1e9+7; const double eps = (double)1e-7; template<typename T> inline bool updmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;} template<typename T> inline bool updmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;} int n, suff[MAXN], c[MAXN], nc[MAXN], tmp[MAXN], cnt[MAXN], timer; char s[MAXN]; int lcp[MAXN], pos[MAXN]; inline void calc() { rep(i, 1, max(n, 256)) cnt[i] += cnt[i - 1]; per(i, max(n, 256), 0) cnt[i + 1] = cnt[i]; cnt[0] = 0; } inline void SA() { memset(cnt, 0, sizeof cnt); s[n++] = (char)0; rep(i, 0, n - 1) cnt[s[i]]++; calc(); rep(i, 0, n - 1) { suff[cnt[s[i]]++] = i; } c[suff[0]] = 0; rep(i, 1, n - 1) { if(s[suff[i]] == s[suff[i - 1]]) c[suff[i]] = c[suff[i - 1]]; else c[suff[i]] = c[suff[i - 1]] + 1; } for(int len = 1; len <= n; len += len) { rep(i, 0, n - 1) tmp[i] = (suff[i] - len + n) % n; memset(cnt, 0, sizeof cnt); rep(i, 0, n - 1) cnt[c[suff[i]]]++; calc(); rep(i, 0, n - 1) suff[cnt[c[tmp[i]]]++] = tmp[i]; nc[suff[0]] = 0; rep(i, 1, n - 1) { pair < int, int > cur = { c[suff[i]], c[(suff[i] + len) % n] }; pair < int, int > last = { c[suff[i - 1]], c[(suff[i - 1] + len) % n] }; if(cur == last) nc[suff[i]] = nc[suff[i - 1]]; else nc[suff[i]] = nc[suff[i - 1]] + 1; } rep(i, 0, n - 1) c[i] = nc[i]; } n--; rep(i, 0, n - 1) suff[i] = suff[i + 1]; } void build() { rep(i, 0, n - 1) pos[suff[i]] = i; int k = 0; rep(i, 0, n - 1) { if(k > 0) k--; if(pos[i] == n - 1) { k = 0; lcp[n - 1] = 0; } else { int j = suff[pos[i] + 1]; while(k <= n && max(i + k, j + k) < n && s[(i + k) % n] == s[(j + k) % n]) k++; lcp[pos[i]] = k; } } } bool ok(int l, int r) { if(l > r) return 1; if(s[l] != s[r]) return 0; return ok(l+1, r-1); } int sv[MAXN]; int main() { #ifdef accepted freopen(".in", "r", stdin); freopen(".out", "w", stdout); #endif // onlycin; scanf("%s", s); n = strlen(s); SA(); build(); ll res = 0ll; rep(i, 0, n-1) cerr << suff[i] << ' '; cerr << nxtl; rep(i, 0, n-1) { int len = n-suff[i]; while(!ok(suff[i], suff[i]+len-1)) len--; sv[i] = len; cerr << lcp[i] << ' '; } cerr << nxtl; rep(i, 0, n-1) { int l = i, kol = 1, r = i+1; while(l >= 0 && lcp[l] >= sv[i]) l--; while(r <= n-2 && lcp[r] >= sv[i]) r++; l++, r--; kol += r - l + 1; cerr << sv[i] << ' '<< l << ' '<< r << nxtl; updmax(res, sv[i] * 1ll * kol); } cout << res << nxtl; return 0; }

Compilation message (stderr)

palindrome.cpp: In function 'void SA()':
palindrome.cpp:45:27: warning: array subscript has type 'char' [-Wchar-subscripts]
  rep(i, 0, n - 1) cnt[s[i]]++;
                           ^
palindrome.cpp:48:16: warning: array subscript has type 'char' [-Wchar-subscripts]
   suff[cnt[s[i]]++] = i;
                ^
palindrome.cpp: In function 'int main()':
palindrome.cpp:103:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s", s);
                ^
#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...