# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
320682 | phathnv | Palindromic Partitions (CEOI17_palindromic) | C++11 | 57 ms | 15076 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define mp make_pair
#define X first
#define Y second
using namespace std;
typedef long long ll;
typedef pair <int, int> ii;
const int N = 1e6 + 1;
const int base = 163;
int t, n;
char s[N];
ll pw[N];
void prepare(){
pw[0] = 1;
for(int i = 1; i < N; i++)
pw[i] = pw[i - 1] * base;
}
void readInput(){
scanf("%s", s + 1);
n = strlen(s + 1);
}
void solve(){
int res = 0;
int l = 1, r = n, len = 0;
ll hashedL = 0, hashedR = 0;
while (l < r){
hashedL = hashedL * base + s[l++];
hashedR = hashedR + s[r--] * pw[len++];
if (hashedL == hashedR){
hashedL = hashedR = 0;
res += 2;
len = 0;
}
}
if (hashedL || l <= r)
res++;
printf("%d\n", res);
}
int main(){
scanf("%d", &t);
prepare();
while (t--){
readInput();
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... |