Submission #959056

#TimeUsernameProblemLanguageResultExecution timeMemory
959056KasymKPalindromes (APIO14_palindrome)C++17
8 / 100
1063 ms1564 KiB
#include <bits/stdc++.h> using namespace std; bool pal(string a) { int l = 0, r = a.size() - 1; while (l < r) { if (a[l] != a[r]) return false; l++, r--; } return true; } int occ(string a, string s){ int n = (int)s.size(); int k = (int)a.size(); string window = ""; int ret = 0; for(int i = 0; i < k; ++i) window += s[i]; if(window == a) ret++; // time complexity if erase is O(n + m) for(int i = k; i < n; ++i){ window += s[i]; window.erase(0, 1); if(window == a) ret++; } return ret; } int main(){ string s; cin >> s; int n = (int)s.size(); int mx = INT_MIN; for (int i = 0; i < n; ++i) for (int j = 1; j <= n - i; ++j) { string a = s.substr(i, j); if (pal(a)){ int ret = a.size() * occ(a, s); mx = max(mx, ret); } } cout << mx << "\n"; return 0; }
#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...