Submission #134998

#TimeUsernameProblemLanguageResultExecution timeMemory
134998qrnoPalindromes (APIO14_palindrome)C++14
8 / 100
1087 ms99384 KiB
#include <iostream> #include <string> #include <cstring> #include <map> using namespace std; map <string, int> M; inline bool isPalindrome(string s) { for (int i = 0; i < s.size(); i++) { if (s[i] != s[s.size()-i-1]) return false; } return true; } const int MAXN = 101010; int n[MAXN]; int l[MAXN]; int main() { cin.tie(0); ios_base::sync_with_stdio(false); memset(l, -1, sizeof(l)); memset(n, -1, sizeof(n)); string a; cin >> a; for (int i = 0; i < a.size(); i++) { if (l[a[i]] != -1) { n[l[a[i]]] = i; } l[a[i]] = i; } int ans = 0; for (int i = 0; i < a.size(); i++) { for (int j = i; j != -1; j = n[j]) { string s = ""; for (int m = i; m <= j; m++) { s += a[m]; } if (isPalindrome(s)) { M[s]++; int m = s.size(); ans = max(ans, m*M[s]); } } } cout << ans << '\n'; return 0; }

Compilation message (stderr)

palindrome.cpp: In function 'bool isPalindrome(std::__cxx11::string)':
palindrome.cpp:10:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < s.size(); i++) {
                     ~~^~~~~~~~~~
palindrome.cpp: In function 'int main()':
palindrome.cpp:34:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < a.size(); i++) {
                     ~~^~~~~~~~~~
palindrome.cpp:35:19: warning: array subscript has type 'char' [-Wchar-subscripts]
         if (l[a[i]] != -1) {
                   ^
palindrome.cpp:36:21: warning: array subscript has type 'char' [-Wchar-subscripts]
             n[l[a[i]]] = i;
                     ^
palindrome.cpp:38:15: warning: array subscript has type 'char' [-Wchar-subscripts]
         l[a[i]] = i;
               ^
palindrome.cpp:43:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < a.size(); 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...