답안 #116321

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
116321 2019-06-12T08:16:42 Z JohnTitor Palindromic Partitions (CEOI17_palindromic) C++11
100 / 100
417 ms 22564 KB
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=(j); i<=(k); i++)
#define FFOR(i, j, k) for(int i=(j); i<(k); i++)
#define DFOR(i, j, k) for(int i=(j); i>=(k); i--)
#define bug(x) cerr<<#x<<" = "<<(x)<<'\n'
#define pb push_back
#define mp make_pair
#define bit(s, i) (((s)>>(i))&1LL)
#define mask(i) ((1LL<<(i)))
#define builtin_popcount __builtin_popcountll
#define __builtin_popcount __builtin_popcountll
using ll=long long; using ld=long double;
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); const ld pi=acos(0)*2;
template <typename T> inline void read(T &x){char c; bool nega=0; while((!isdigit(c=getchar()))&&(c!='-')); if(c=='-'){nega=1; c=getchar();} x=c-48; while(isdigit(c=getchar())) x=x*10+c-48; if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10); putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){ putchar('-'); x=-x;} writep(x);}
template <typename T> inline void writeln(T x){write(x); putchar('\n');}
#define taskname "Palindromic"
const ll base=999727999;
string s;
ll h[1000002];
ll p[1000002];
ll get_hash(int l, int r){
    return ((h[r]-h[l-1]*p[r-l+1])%base+base)%base;
}
void solve(){
    cin>>s;
    int n=s.size();
    s='0'+s;
    FOR(i, 1, n) h[i]=(h[i-1]*131+s[i])%base;
    int ans=0;
    int l=1, r=n;
    int nl=1, nr=n;
    while(nl<nr){
        if(get_hash(l, nl)==get_hash(nr, r)){
            ans+=2;
            l=nl+1;
            r=nr-1;
            nl=l;
            nr=r;
        }
        else{
            nl++;
            nr--;
        }
    }
    if(l<=r) ans++;
    writeln(ans);
}
int main(){
    #ifdef Aria
        if(fopen(taskname".in", "r"))
            freopen(taskname".in", "r", stdin);
    #endif // Aria
    p[0]=1;
    FOR(i, 1, 1000000) p[i]=(p[i-1]*131)%base;
    int t;
    read(t);
    while(t--) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 8192 KB Output is correct
2 Correct 12 ms 8192 KB Output is correct
3 Correct 13 ms 8192 KB Output is correct
4 Correct 12 ms 8192 KB Output is correct
5 Correct 12 ms 8192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 8192 KB Output is correct
2 Correct 12 ms 8192 KB Output is correct
3 Correct 13 ms 8192 KB Output is correct
4 Correct 12 ms 8192 KB Output is correct
5 Correct 12 ms 8192 KB Output is correct
6 Correct 13 ms 8164 KB Output is correct
7 Correct 13 ms 8192 KB Output is correct
8 Correct 13 ms 8192 KB Output is correct
9 Correct 12 ms 8192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 8192 KB Output is correct
2 Correct 12 ms 8192 KB Output is correct
3 Correct 13 ms 8192 KB Output is correct
4 Correct 12 ms 8192 KB Output is correct
5 Correct 12 ms 8192 KB Output is correct
6 Correct 13 ms 8164 KB Output is correct
7 Correct 13 ms 8192 KB Output is correct
8 Correct 13 ms 8192 KB Output is correct
9 Correct 12 ms 8192 KB Output is correct
10 Correct 18 ms 8320 KB Output is correct
11 Correct 17 ms 8320 KB Output is correct
12 Correct 17 ms 8320 KB Output is correct
13 Correct 17 ms 8312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 8192 KB Output is correct
2 Correct 12 ms 8192 KB Output is correct
3 Correct 13 ms 8192 KB Output is correct
4 Correct 12 ms 8192 KB Output is correct
5 Correct 12 ms 8192 KB Output is correct
6 Correct 13 ms 8164 KB Output is correct
7 Correct 13 ms 8192 KB Output is correct
8 Correct 13 ms 8192 KB Output is correct
9 Correct 12 ms 8192 KB Output is correct
10 Correct 18 ms 8320 KB Output is correct
11 Correct 17 ms 8320 KB Output is correct
12 Correct 17 ms 8320 KB Output is correct
13 Correct 17 ms 8312 KB Output is correct
14 Correct 417 ms 22152 KB Output is correct
15 Correct 227 ms 21044 KB Output is correct
16 Correct 394 ms 22564 KB Output is correct
17 Correct 230 ms 16276 KB Output is correct