Submission #312053

#TimeUsernameProblemLanguageResultExecution timeMemory
312053FatihSolakPalinilap (COI16_palinilap)C++14
17 / 100
1087 ms512 KiB
#include <bits/stdc++.h> using namespace std; string s; long long solve(){ long long tot = 0; for (int i = 0; i < s.length(); i++) { int odd = 1; while (i - odd >= 0 && odd + i < s.length() && s[i - odd] == s[i + odd]) { odd++; } int even = 0; int l = i - 1; int r = i; while (l >= 0 && r < s.length() && s[l] == s[r]) { even++; l--; r++; } tot += odd + even; } return tot; } int main(){ cin >> s; long long maxi=0; int l=s.length(); for(int i=0;i<l;i++){ char now=s[i]; for(int j=0;j<26;j++){ s[i] = j+'a'; maxi = max(maxi, solve()); } s[i] = now; } cout << maxi; /* long long arr[l][26]; long long brr[l]; for(int i=0;i<l;i++){ for(int j=0;j<26;j++){ arr[i][j]=1; } brr[i]=0; } for(int i=0;i<l;i++){ for(int j=i;j<l;j++){ string a=""; for(int c=i;c<=j;c++){ a +=s[c]; } string b=a; reverse(a.begin(),a.end()); if(j-i%2 == 0){ for(int c=0;c<26;c++){ if(c!=s[(i+j)/2]-'a'){ arr[(i+j)/2][c]++; } } } if(b == a){ ans++; for(int c=i;c<=j;c++){ brr[c]++; } } else{ for(int h=0;h<(j-i+1)/2;h++){ if(b[h] != a[h]){ string d =""; for(int c=i;c<=j;c++){ if(c == i+h || c == j-h){ continue; } d+=s[c]; } string e=d; reverse(d.begin(),d.end()); if(d==e){ arr[i+h][a[h]-'a']++; arr[j-h][b[h]-'a']++; //cout << i<< " " << j << " "<< i+h <<" " << a[h] << " " << j-h << " " << b[h]<< endl; } } } } } } //cout <<endl; long long maxi=0; for(int i=0;i<l;i++){ for(int j=0;j<26;j++){ if(brr[i] <=arr[i][j]){ maxi = max(maxi,arr[i][j]-brr[i]); } cout << arr[i][j] <<" "; } cout <<endl; } cout << maxi +ans;*/ }

Compilation message (stderr)

palinilap.cpp: In function 'long long int solve()':
palinilap.cpp:6:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 |     for (int i = 0; i < s.length(); i++) {
      |                     ~~^~~~~~~~~~~~
palinilap.cpp:8:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |         while (i - odd >= 0 && odd + i < s.length() && s[i - odd] == s[i + odd]) {
      |                                ~~~~~~~~^~~~~~~~~~~~
palinilap.cpp:14:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |         while (l >= 0 && r < s.length() && s[l] == s[r]) {
      |                          ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...