Submission #47505

#TimeUsernameProblemLanguageResultExecution timeMemory
47505WaschbarPalindromes (APIO14_palindrome)C++17
8 / 100
1090 ms3968 KiB
///©Waschbar #include <bits/stdc++.h> #define tmm first #define uu second.first #define vv second.second using namespace std; const int MAXN = 1e5; const int LOG = 20; const int INF = 1e9; const int MOD = 1e9+7; int ans; string s; vector < int > pfunc(string str) { vector < int > p(str.size(),0); int j = 0; for(int i = 1; i < str.size(); i++) { while( j > 0 && str[j] != str[i]) j = p[j-1]; if(str[i] == str[j]) j++; p[i] = j; } return p; } void check(string t) { vector < int > p; string tt = t + "#" + s; p = pfunc(tt); int cnt = 0; for(int i = 0; i < p.size(); i++) if(p[i] == t.size()) cnt++; //cout << t << " " << cnt << endl; ans = max(ans,(int)(t.size()*cnt)); } int main() { //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); ans = 0; cin >> s; string t; for(int i = 0; i < s.size(); i++) { t = ""; t = s[i]; int j = 1; while(i-j >= 0 && i+j < s.size() && s[i-j]==s[i+j]) { check(t); t = s[i-j] + t + s[i+j]; j++; } check(t); } for(int i = 0; i < s.size()-1; i++) { t = ""; t = s[i]; t = t + s[i+1]; if(s[i] != s[i+1]) continue; int j = 1; while(i-j >= 0 && i+j+1 < s.size() && s[i-j]==s[i+j+1]) { check(t); t = s[i-j] + t + s[i+j+1]; j++; } check(t); } cout << ans; return 0; }

Compilation message (stderr)

palindrome.cpp: In function 'std::vector<int> pfunc(std::__cxx11::string)':
palindrome.cpp:19:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 1; i < str.size(); i++) {
                        ~~^~~~~~~~~~~~
palindrome.cpp: In function 'void check(std::__cxx11::string)':
palindrome.cpp:34:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
      for(int i = 0; i < p.size(); i++)
                     ~~^~~~~~~~~~
palindrome.cpp:35:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(p[i] == t.size()) cnt++;
palindrome.cpp: In function 'int main()':
palindrome.cpp:49:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < s.size(); i++) {
                    ~~^~~~~~~~~~
palindrome.cpp:52:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(i-j >= 0 && i+j < s.size() && s[i-j]==s[i+j]) {
                           ~~~~^~~~~~~~~~
palindrome.cpp:59:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < s.size()-1; i++) {
                    ~~^~~~~~~~~~~~
palindrome.cpp:63:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(i-j >= 0 && i+j+1 < s.size() && s[i-j]==s[i+j+1]) {
                           ~~~~~~^~~~~~~~~~
#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...