Submission #615465

#TimeUsernameProblemLanguageResultExecution timeMemory
615465abc864197532Palindromes (APIO14_palindrome)C++17
73 / 100
46 ms48172 KiB
#include <bits/stdc++.h> using namespace std; #define lli long long int #define mp make_pair #define pb push_back #define eb emplace_back #define pii pair <int, int> #define X first #define Y second #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() void abc() {cout << endl;} template <typename T, typename ...U> void abc(T a, U ...b) { cout << a << ' ', abc(b...); } template <typename T> void printv(T l, T r) { for (; l != r; ++l) cout << *l << " \n"[l + 1 == r]; } template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) { return o >> a.X >> a.Y; } template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) { return o << '(' << a.X << ", " << a.Y << ')'; } template <typename T> ostream& operator << (ostream& o, vector<T> a) { bool is = false; if (a.empty()) return o << "{}"; for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;} return o << '}'; } template <typename T> struct vv : vector <vector <T>> { vv (int n, int m, T v) : vector <vector <T>> (n, vector <T>(m, v)) {} vv (int n, int m) : vector <vector <T>> (n, vector <T>(m)) {} vv () {} }; template <typename T> struct vvv : vector <vv <T>> { vvv (int n, int m, int k, T v) : vector <vv <T>> (n, vv <T>(m, k, v)) {} vvv (int n, int m, int k) : vector <vv <T>> (n, vv <T>(m, k)) {} vvv () {} }; #ifdef Doludu #define test(args...) abc("[" + string(#args) + "]", args) #define owo freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout) #else #define test(args...) void(0) #define owo ios::sync_with_stdio(false); cin.tie(0) #endif const int mod = 998244353, N = 200005, logN = 18, G = 3; struct PAM { int ch[N][26], cnt[N], fail[N], len[N], sz; string s; // 0 -> even root, 1 -> odd root PAM (string _s) : s(_s) { sz = 0; extend(), extend(); len[0] = 0, fail[0] = 1, len[1] = -1; int lst = 1; for (int i = 0; i < s.length(); ++i) { while (s[i - len[lst] - 1] != s[i]) lst = fail[lst]; if (!ch[lst][s[i] - 'a']) { int idx = extend(); len[idx] = len[lst] + 2; int now = fail[lst]; while (s[i - len[now] - 1] != s[i]) now = fail[now]; fail[idx] = ch[now][s[i] - 'a']; ch[lst][s[i] - 'a'] = idx; } lst = ch[lst][s[i] - 'a'], cnt[lst]++; } } int extend() { fill(ch[sz], ch[sz] + 26, 0), sz++; return sz - 1; } lli solve() { for (int i = sz - 1; i > 1; --i) { cnt[fail[i]] += cnt[i]; } lli ans = 0; for (int i = 2; i < sz; ++i) { ans = max(ans, 1ll * len[i] * cnt[i]); } return ans; } }; int main () { owo; string s; cin >> s; PAM solver(s); cout << solver.solve() << '\n'; }

Compilation message (stderr)

palindrome.cpp: In constructor 'PAM::PAM(std::string)':
palindrome.cpp:59:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |         for (int i = 0; i < s.length(); ++i) {
      |                         ~~^~~~~~~~~~~~
#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...