Submission #901626

#TimeUsernameProblemLanguageResultExecution timeMemory
901626alexandru_onutPalindromes (APIO14_palindrome)C++14
23 / 100
1049 ms5164 KiB
#include <bits/stdc++.h> using namespace std; string A; int zF (const string &str) { string aux = str + "#" + A; int N = aux.size(); vector <int> z (N , 0); int L = 0 , R = 0 , ans = 0; for(int i = 0; i < N; ++i) { if(i < R) z[i] = min(z[i - L] , R - i); while(i + z[i] < N && aux[z[i]] == aux[i + z[i]]) ++z[i]; if(i + z[i] > R) { R = i + z[i]; L = i; } ans += (z[i] == str.size()); } return ans; } long long Manacher (const string &str) { string S; vector <int> dp; S.push_back('#'); for(int i = 0; i < (int) str.size(); ++i) { S.push_back(str[i]); S.push_back('#'); } int N = S.size(); dp = vector <int> (N , 0); int C = 0 , R = 0; for(int i = 0; i < N; ++i) { int M = 2 * C - i; if(i < R) dp[i] = min(dp[M] , R - i); int a = i + (dp[i] + 1); int b = i - (dp[i] + 1); while(b >= 0 && a < N && S[a] == S[b]) ++dp[i] , ++a , --b; if(i + dp[i] > R) { C = i; R = i + dp[i]; } } int p = 0; string ans; unordered_map <string , bool> use; long long rasp = 0; for(int i = 1; i < (int) S.size(); ++i) { string ans; for(int j = i - dp[i]; j <= i + dp[i]; ++j) if(S[j] != '#') ans.push_back(S[j]); if(!use[ans]) { long long nrAp = zF (ans) * ans.size(); rasp = max(rasp , 1LL * nrAp) , use[ans] = 1; } } return rasp; } int main() { ios_base :: sync_with_stdio(false); cin.tie(nullptr); cin >> A; cout << Manacher(A); }

Compilation message (stderr)

palindrome.cpp: In function 'int zF(const string&)':
palindrome.cpp:24:22: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |         ans += (z[i] == str.size());
palindrome.cpp: In function 'long long int Manacher(const string&)':
palindrome.cpp:57:9: warning: unused variable 'p' [-Wunused-variable]
   57 |     int p = 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...