# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
861958 | anhphant | Palindromic Partitions (CEOI17_palindromic) | C++14 | 118 ms | 28756 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
const ll mod = 1e9 + 9;
const ll base = 9973;
string S;
int N;
ll basepow[1000007], pre[1000007];
ll getHash(int i, int j) {
ll r = pre[j];
ll l = (pre[i - 1] * basepow[j - i + 1]) % mod;
return (r - l + mod) % mod;
}
ll DP[1000007];
void solve() {
cin >> S;
int N = S.size();
S = " " + S;
for(int i = 1; i <= N; ++i) {
pre[i] = (pre[i - 1] * base + S[i] - 'a' + 1) % mod;
}
ll L = 1, R = N;
ll ans = 0;
while(L <= R) {
//cerr << L << " " << R << endl;
if (L == R) {
ans++;
break;
}
for(int i = L; i <= N / 2; ++i) {
//cerr << "i = " << i << endl;
if (getHash(L, i) == getHash(N - i + 1, R)) {
ans += 2;
L = i + 1;
R = N - i;
goto GT;
}
}
//cerr << "end : " << L << " " << R << endl;
ans += (L < R);
break;
GT:;
if (L == R) {
ans++;
break;
}
}
cout << ans << endl;
}
int main() {
ios_base :: sync_with_stdio(0);
cin.tie(0); cout.tie(0); cerr.tie(0);
if (fopen("FILE.INP", "r")) {
freopen("FILE.INP", "r", stdin);
freopen("FILE.OUT", "w", stdout);
}
basepow[0] = 1;
for(int i = 1; i <= 1000000; ++i) basepow[i] = (basepow[i - 1] * base) % mod;
int Tc;
cin >> Tc;
for(int _ = 1; _ <= Tc; ++_) {
//cerr << " _ = " << _ << endl;
solve();
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |