Submission #731158

#TimeUsernameProblemLanguageResultExecution timeMemory
731158Alihan_8Palindromes (APIO14_palindrome)C++17
8 / 100
1065 ms131072 KiB
#include <bits/stdc++.h> using namespace std; #define all(x) x.begin(), x.end() #define pb push_back #define ln '\n' #define int long long bool chmin(int &x, int y){ bool flag = false; if ( x > y ){ x = y; flag |= true; } return flag; } bool chmax(int &x, int y){ bool flag = false; if ( x < y ){ x = y; flag |= true; } return flag; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); string s; cin >> s; int n = (int)s.size(); map <string,int> mp; for ( int i = 0; i < n; i++ ){ string c; for ( int j = i; j < n; j++ ){ c += s[j]; ++mp[c]; } } int Mx = 0; for ( int i = 0; i < n; i++ ){ string l, r; l += s[i]; chmax(Mx, mp[l + r]); for ( int j = i - 1; j >= 0; j-- ){ if ( (i - j) + i >= n ) break; if ( s[j] != s[i + (i - j)] )break; l = s[j] + l; r += s[j]; chmax(Mx, mp[l + r] * ((i - j) * 2 + 1)); } if ( i + 1 == n or s[i + 1] != s[i] ) continue; l = r = ""; l += s[i], r += s[i]; chmax(Mx, mp[l + r] * 2); for ( int j = i - 1; j >= 0; j-- ){ if ( (i - j) + (i + 1) >= n ) break; if ( s[j] != s[i + 1 + (i - j)] ) break; l = s[j] + l; r += s[j]; chmax(Mx, mp[l + r] * (i - j + 1) * 2); } } cout << Mx; cout << '\n'; }
#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...