Submission #99173

#TimeUsernameProblemLanguageResultExecution timeMemory
99173mirbek01Palindromes (APIO14_palindrome)C++11
47 / 100
1066 ms2752 KiB
# include <bits/stdc++.h> using namespace std; const int N = 1e4 + 2; int n, bor[26][N], cnt[N * 27], cn = 1; long long ans; string s; void add(int id, int c){ int v = 1; for(int len = 0; len < min(n - id + 1, id); len ++){ if(id - len <= 0 || id + len + c > n || s[id - len] != s[id + len + c]){ break; } int now = s[id - len] - 'a'; if(!bor[now][v]){ bor[now][v] = ++ cn; } v = bor[now][v]; cnt[v] ++; } } void f(int v, int len, int c){ for(int i = 0; i < 26; i ++){ if(bor[i][v]){ ans = max(ans, (len * 2 - c) *1ll* cnt[bor[i][v]]); f(bor[i][v], len + 1, c); } } } int main(){ cin >> s; n = s.size(); s = ' ' + s; for(int i = 1; i <= n; i ++){ add(i, 0); } f(1, 1, 1); cn = 1; memset(bor, 0, sizeof(bor)); memset(cnt, 0, sizeof(cnt)); for(int i = 1; i < n; i ++){ if(s[i] == s[i + 1]) add(i, 1); } f(1, 1, 0); cout << ans << endl; }
#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...