| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1303513 | thuhienne | Palindromic Partitions (CEOI17_palindromic) | C++20 | 80 ms | 19500 KiB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define thuhien ""
#define re exit(0);
#define hash __hash__
const int maxn = 1000009;
const ll mod = 1e9 + 7,base = 31;
string s;
int n;
ll hash[maxn],power[maxn];
void createhash() {
power[0] = 1;
for (int i = 1;i <= n;i++) {
hash[i] = (hash[i - 1] * base + s[i] - 'a' + 1) % mod;
power[i] = power[i - 1] * base % mod;
}
}
int gethash(int l,int r) {
return (hash[r] - hash[l - 1] * power[r - l + 1] + mod * mod) % mod;
}
void solve() {
cin >> s;
n = s.length();s = " " + s;
createhash();
int cnt = 0;
int l = 1,r = n;
for (int i = 1;i <= n;i++) {
if (i - l + 1 > r - i + 1 || l > r) {
cnt += l <= r;
break;
}
if (l == r) {
cnt++;
break;
}
int len = i - l + 1;
if (gethash(l,l + len - 1) == gethash(r - len + 1,r)) {
cnt += 2;
l += len;
r -= len;
// cout << i << "\n";
}
}
cout << cnt << '\n';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
if (fopen(thuhien".inp","r")) {
freopen(thuhien".inp","r",stdin);
freopen(thuhien".out","w",stdout);
}
int test;cin >> test;while (test--) 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... | ||||
