제출 #399080

#제출 시각아이디문제언어결과실행 시간메모리
399080BERNARB01회문 (APIO14_palindrome)C++17
8 / 100
1089 ms2516 KiB
#include <bits/stdc++.h>

using namespace std;

vector<int> Z(const string& s) {
    int n = s.size();
    vector<int> z(n);
    int x = 0, y = 0;
    for (int i = 1; i < n; i++) {
        z[i] = max(0, min(z[i-x], y-i+1));
        while (i+z[i] < n && s[z[i]] == s[i+z[i]]) {
            x = i; y = i+z[i]; z[i]++;
        }
    }
    return z;
}

bool pal(const string& s) {
	string t = s;
	reverse(t.begin(), t.end());
	return s == t;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//freopen("palindrome.in", "r", stdin);
	//freopen("palindrome.out", "w", stdout);
	string s;
	cin >> s;
	int n = s.length();
	long long res = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i; j < n; j++) {
			long long len = j - i + 1;
			string t = s.substr(i, len);
			if (!pal(t)) {
				continue;
			}
			t += '#';
			t += s;
			vector<int> z = Z(t);
			long long ans = 0;
			for (int c : z) {
				if (c == len) {
					ans++;
				}
			}
			ans *= len;
			res = max(res, ans);
		}
	}
	cout << res << '\n';
	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...