# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1095052 | vjudge1 | Palindromic Partitions (CEOI17_palindromic) | C++17 | 11 ms | 8284 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//------------------------------------\
// ------------------------------ \
// | created by Pham Phuongg | \
// | phamvuphuong2008 | \
// | THPT CHUYEN HA TINH | \
// | HA TINH, VIET NAM | \
// | Bé Phương from TK4-CHT | \
// ------------------------------ \
//------------------------------------\
#include<bits/stdc++.h>
#define fi first
#define se second
#define int long long
#define ii pair<int ,int >
#define endl '\n'
#define iii pair<int,ii>
#define pb push_back
#define task "main"
#define base 341
using namespace std;
const int maxn = 1e6+5;
const int lim = 1e6;
int mod = 1e9+7;
int p[maxn], f[maxn];
string s;
int add(int a, int b) {
return (a + b)%mod;
}
int mul(int a, int b) {
return ((a%mod)*(b%mod))%mod;
}
int sub(int a, int b) {
return ((a-b)%mod+mod)%mod;
}
int get(int l, int r) {
return sub(f[r], mul(f[l-1], p[r-l+1]));
}
void solve(){
cin >> s;
int n = s.length();
s = " " + s;
for (int i = 1; i <= n; i++) f[i] = add(mul(f[i-1], base), s[i] - 'a' + 1);
int l = 1, r = n, cnt = 0;
if (get(3,4) == get(r,r)) cout << "YES" << endl;
while(l <= r) {
int res = -1;
for (int i = 0; i <= n; i++) {
if (get(l,l+i) == get(r-i,r)) {
res = i;
break;
}
}
// cout << res << " " << l << " " << r << endl;
if (l == r-res && l + res == r) break;
l += res + 1;
r -= (res + 1);
cnt += 2;
}
cout << cnt + 1;
}
main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
if(fopen(task".inp","r")) {
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
p[0] = 1;
for (int i = 1; i <= lim; i++) p[i] = mul(p[i-1], base);
int t=1;
cin>>t;
while(t--){
solve();
cout << endl;
}
}
Compilation message (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... |