제출 #561400

#제출 시각아이디문제언어결과실행 시간메모리
561400Ooops_sorry회문 (APIO14_palindrome)C++14
8 / 100
1104 ms131072 KiB
#include<bits/stdc++.h> using namespace std; #define pb push_back #define ld long double #define ll long long mt19937 rnd(51); const int INF = 1e9; bool is_palindrome(string s) { return s == (string){s.rbegin(), s.rend()}; } int solve1(string s) { int n = s.size(), ans = -INF; map<string, int> cnt; for (int i = 0; i < n; i++) { for (int j = 1; j + i <= n; j++) { cnt[s.substr(i, j)]++; } } for (int i = 0; i < n; i++) { for (int j = n - i; j >= 1; j--) { if (is_palindrome(s.substr(i, j))) { ans = max(ans, cnt[s.substr(i, j)] * j); break; } } } return ans; } int solve2(string s) { int n = s.size(), ans = -INF; map<string, int> cnt; for (int i = 0; i < n; i++) { for (int j = 1; j + i <= n; j++) { cnt[s.substr(i, j)]++; } } for (int i = 0; i < n; i++) { for (int j = 1; j + i <= n; j++) { if (is_palindrome(s.substr(i, j))) { ans = max(ans, cnt[s.substr(i, j)] * j); } } } return ans; } signed main() { #ifdef LOCAL freopen("input.txt", "r", stdin); #endif // LCOAL ios_base::sync_with_stdio(0); cin.tie(0); string s; cin >> s; cout << solve1(s) << endl; return 0; }
#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...