제출 #560896

#제출 시각아이디문제언어결과실행 시간메모리
560896Yazan_AlattarPalinilap (COI16_palinilap)C++14
0 / 100
282 ms67928 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define F first #define S second #define pb push_back #define endl "\n" #define all(x) x.begin(), x.end() const int M = 5007; const ll inf = 1e18; const ll mod = 1e9 + 7; const double pi = acos(-1); const double eps = 1e-6; const int dx[] = {0, -1, 0, 1}, dy[] = {1, 0, -1, 0}; const int block = 320; string s; int cnt[M][30], dp[M][M], con[M], ans; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> s; int n = s.size(); s = '#' + s; for(int mid = 1; mid <= n; ++mid){ int l = mid, r = mid; int pos1 = 0, pos2 = 0, c1 = 0, c2 = 0; while(l && r <= n){ if(s[l] != s[r]){ if(pos1) break; pos1 = l; pos2 = r; c1 = s[r] - 'a'; c2 = s[l] - 'a'; } ++cnt[pos1][c1]; ++cnt[pos2][c2]; if(pos1 == 0) ++ans; --l; ++r; } l = mid, r = mid + 1; pos1 = 0; pos2 = 0; c1 = 0; c2 = 0; while(l && r <= n){ if(s[l] != s[r]){ if(pos1) break; pos1 = l; pos2 = r; c1 = s[r] - 'a'; c2 = s[l] - 'a'; } ++cnt[pos1][c1]; ++cnt[pos2][c2]; if(pos1 == 0) ++ans; --l; ++r; } } for(int mid = 1; mid <= n; ++mid){ int l = mid, r = mid; while(l && r <= n){ if(s[l] != s[r]) break; if(l < r) ++dp[l][r]; --l; ++r; } l = mid, r = mid + 1; while(l && r <= n){ if(s[l] != s[r]) break; ++dp[l][r]; --l; ++r; } } for(int len = n; len; --len){ for(int l = 1; l + len - 1 <= n; ++l){ int r = l + len - 1; dp[l][r] += dp[l - 1][r + 1]; con[l] += dp[l][r]; con[r] += dp[l][r]; } } int mx = 0; for(int i = 1; i <= n; ++i) for(int j = 0; j < 26; ++j) mx = max(mx, cnt[i][j] - con[i]); cout << ans + mx << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...