답안 #596975

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
596975 2022-07-15T10:49:35 Z 1bin Palindromic Partitions (CEOI17_palindromic) C++14
15 / 100
1 ms 324 KB
#include <bits/stdc++.h>

using namespace std;

#define all(v) v.begin(), v.end()
typedef long long ll;
const int NMAX = 1e6 + 5;
const ll m1 = 1e15 + 1, m2 = 1e15 + 3;
int tc, n, l1, l2, r1, r2, pw1, pw2;
string s;

int main(void){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    cin >> tc;
    while(tc--){
        cin >> s; n = s.size();
        
        l1 = l2 = r1 = r2 = 0; pw1 = pw2 = 1;
        int ans = 0, cnt = 0;
        for(int i = 0; i < n / 2; i++){
            l1 = (l1 * 26 + s[i] - 'a') % m1;
            l2 = (l2 * 26 + s[i] - 'a') % m2;
            r1 = (r1 + pw1 * (s[n - 1 - i] - 'a')) % m1;
            r2 = (r2 + pw2 * (s[n - 1 - i] - 'a')) % m2;
            if(l1 == r1 && l2 == r2){
                ans += 2; cnt = 0;
                l1 = l2 = r1 = r2 = 0;
                pw1 = pw2 = 1;
            }
            else {
                cnt++;
                pw1 = pw1 * 26 % m1;
                pw2 = pw2 * 26 % m2;
            }
        }
        if(n & 1 || cnt) ans++;
        cout << ans << '\n';
    }
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 324 KB Output is correct
6 Incorrect 0 ms 212 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 324 KB Output is correct
6 Incorrect 0 ms 212 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 324 KB Output is correct
6 Incorrect 0 ms 212 KB Output isn't correct
7 Halted 0 ms 0 KB -