# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1125466 | ducanh0811 | Palindromic Partitions (CEOI17_palindromic) | C++20 | 14 ms | 15936 KiB |
//
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
#define eb emplace_back
#define MASK(i) (1ll << (i))
#define FOR(i,a,b) for (int i = (a); i <= (b); ++i)
#define REV(i,a,b) for (int i = (a); i >= (b); --i)
using namespace std;
const int MOD[] = {1000000007, 998244353};
const int base = 727;
int n;
string s;
#define MAXN 1000005
int p[2][MAXN];
int f[MAXN];
int g[MAXN];
pair<int,int> get(int l, int r){
int f1 = ((f[r] - f[l - 1] * p[0][r - l + 1]) % MOD[0] + MOD[0]) % MOD[0];
int f2 = ((g[r] - g[l - 1] * p[1][r - l + 1]) % MOD[1] + MOD[1]) % MOD[1];
return make_pair(f1, f2);
}
bool bang(pair<int,int> A, pair<int,int> B){
return (A.first == B.first && A.second == B.second);
}
void solve(){
cin >> s;
n = s.size();
s = '#' + s;
FOR(i,1,n){
f[i] = (f[i - 1] * base + s[i] - 'a' + 1) % MOD[0];
g[i] = (g[i - 1] * base + s[i] - 'a' + 1) % MOD[1];
}
int res = 1;
int last_left = 1;
int last_right = n;
for (int i = 1, j = n; i < j;){
if (bang(get(last_left, i), get(j, last_right))){
res += 2;
last_left = i + 1;
last_right = j - 1;
}
i++;
j--;
}
cout << res << '\n';
}
#define task ""
int32_t main(){
if (fopen(task".inp","r")){
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
p[0][0] = 1;
p[1][0] = 1;
FOR(i,1,1000000){
p[0][i] = (p[0][i - 1] * base) % MOD[0];
p[1][i] = (p[1][i - 1] * base) % MOD[1];
}
int test; cin >> test; while (test--)
solve();
return 0;
}
컴파일 시 표준 에러 (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... |