답안 #94845

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
94845 2019-01-24T12:07:45 Z Origims 회문 (APIO14_palindrome) C++14
0 / 100
1000 ms 1920 KB
// In The Name Of God
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define sqr(A) ((A) * (A))
#define X first
#define Y second
#define MP make_pair
#define bsz  __builtin_popcount
#define all(A) A.begin(), A.end()
using namespace std;
using namespace __gnu_pbds;
template < typename T >
using ordered_set = tree < T , null_type , less < T > , rb_tree_tag , tree_order_statistics_node_update >;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
const int MOD2 = 1e9 + 9;
const int PR = 727;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;

const int N = 1e4 + 20;
int hsh[N], pw[N], n;
unordered_map<int, ll> cnt, len;
string s;
ll ans;

int getHash(int l, int r) {
	if (l == 0) return hsh[r];
	return hsh[r] - hsh[l - 1] * pw[r - l + 1];
}

bool isPal(int l, int r) {
	if (r - l == 0) return 1;
	int t = r - l + 1;
	if (t % 2)
		return getHash(l, l + t / 2 - 1) == getHash(l + t / 2 + 1, r);
	else
		return getHash(l, l + t / 2 - 1) == getHash(l + t / 2, r);
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> s; n = s.size();
	pw[0] = 1;
	hsh[0] = s[0];
	for (int i = 1; i < n; i++) {
		pw[i] = pw[i - 1] * PR;
		hsh[i] = PR * hsh[i - 1] + s[i];
	}
	for (int i = 0; i < n; i++)
		for (int j = i; j < n; j++)
			if (isPal(i, j)) {
				int tmp = getHash(i, j);
				cnt[tmp]++;
				len[tmp] = j - i + 1;
			}
	for (auto x : cnt)
		ans = max(ans, x.Y * len[x.X]);
	cout << ans << endl;
}



























# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 380 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Incorrect 2 ms 376 KB Output isn't correct
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 372 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1088 ms 1400 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 1144 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 1920 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -