답안 #94847

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
94847 2019-01-24T12:17:39 Z Origims 회문 (APIO14_palindrome) C++14
0 / 100
1000 ms 1784 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 PR2 = 23;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;

const int N = 1e4 + 20;
int hsh[N], hsh2[N], pw[N], pw2[N], n;
map<pii, 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];
}

int getHash2(int l, int r) {
	if (l == 0) return hsh2[r];
	return hsh2[r] - hsh2[l - 1] * pw2[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)) & (getHash2(l, l + t / 2 - 1) == getHash2(l + t / 2 + 1, r));
	else
		return (getHash(l, l + t / 2 - 1) == getHash(l + t / 2, r)) & (getHash2(l, l + t / 2 - 1) == getHash2(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; pw2[0] = 1;
	hsh[0] = s[0]; hsh2[0] = s[0];
	for (int i = 1; i < n; i++) {
		pw[i] = pw[i - 1] * PR;
		hsh[i] = PR * hsh[i - 1] + s[i];
		pw2[i] = pw2[i - 1] * PR2;
		hsh2[i] = PR2 * hsh2[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);
				int tmp2 = getHash2(i, j);
				cnt[MP(tmp, tmp2)]++;
				len[MP(tmp, tmp2)] = 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 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 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 43 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1075 ms 1784 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 1272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 1664 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -