답안 #203622

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
203622 2020-02-21T16:13:18 Z thebes Palindromic Partitions (CEOI17_palindromic) C++14
100 / 100
629 ms 19048 KB
#include <bits/stdc++.h>
#define DEBUG 1
using namespace std;

namespace output{
    void __(short x){cout<<x;}
    void __(unsigned x){cout<<x;}
    void __(int x){cout<<x;}
    void __(long long x){cout<<x;}
    void __(unsigned long long x){cout<<x;}
    void __(double x){cout<<x;}
    void __(long double x){cout<<x;}
    void __(char x){cout<<x;}
    void __(const char*x){cout<<x;}
    void __(const string&x){cout<<x;}
    void __(bool x){cout<<(x?"true":"false");}
    template<class S,class T>
    void __(const pair<S,T>&x){__(DEBUG?"(":""),__(x.first),__(DEBUG?", ":" "),__(x.second),__(DEBUG?")":"");}
    template<class T>
    void __(const vector<T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
    template<class T>
    void __(const set<T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
    template<class T>
    void __(const multiset<T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
    template<class S,class T>
    void __(const map<S,T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
    void pr(){cout<<"\n";}
    template<class S,class... T>
    void pr(const S&a,const T&...b){__(a);if(sizeof...(b))__(' ');pr(b...);}
}

using namespace output;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef pair<ld,ld> pld;
typedef vector<int> vi;
typedef vector<ll> vl;

#define pb push_back
#define fox(i,x,y) for(int i=(x);i<=(y);i++)
#define foxr(i,x,y) for(int i=(y);i>=(x);i--)

const int MN = 1e6+6, mod = 1e9+3;
int t, n, i, j, k, hsh[MN], pw[MN]={1}, ans;
string s;

int get(int x,int y){
    int res = (hsh[y]-1LL*hsh[x-1]*pw[y-x+1]%mod)%mod;
    while(res>=mod) res-=mod;
    while(res<0) res+=mod;
    return res;
}

int main(){
    for(i=1;i<MN;i++) pw[i]=pw[i-1]*133LL%mod;
    scanf("%d",&t);
    for(;t;t--){
        cin >> s; n = s.size();
        for(i=1;i<=n;i++){
            hsh[i]=(hsh[i-1]*133LL+s[i-1]-'a'+1)%mod;
        }
        ans = 0;
        for(i=1;i<=n-i+1;i=j+1){
            for(j=i;j<=n;j++){
                if(get(i,j)==get(n-j+1,n-i+1)) break;
            }
            if(i==n-j+1) ans++;
            else ans+=2;
        }
        printf("%d\n",ans);
    }
    return 0;
}

Compilation message

palindromic.cpp: In function 'int main()':
palindromic.cpp:60:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&t);
     ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 4216 KB Output is correct
2 Correct 16 ms 4216 KB Output is correct
3 Correct 16 ms 4348 KB Output is correct
4 Correct 16 ms 4216 KB Output is correct
5 Correct 16 ms 4216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 4216 KB Output is correct
2 Correct 16 ms 4216 KB Output is correct
3 Correct 16 ms 4348 KB Output is correct
4 Correct 16 ms 4216 KB Output is correct
5 Correct 16 ms 4216 KB Output is correct
6 Correct 16 ms 4216 KB Output is correct
7 Correct 16 ms 4216 KB Output is correct
8 Correct 16 ms 4216 KB Output is correct
9 Correct 17 ms 4216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 4216 KB Output is correct
2 Correct 16 ms 4216 KB Output is correct
3 Correct 16 ms 4348 KB Output is correct
4 Correct 16 ms 4216 KB Output is correct
5 Correct 16 ms 4216 KB Output is correct
6 Correct 16 ms 4216 KB Output is correct
7 Correct 16 ms 4216 KB Output is correct
8 Correct 16 ms 4216 KB Output is correct
9 Correct 17 ms 4216 KB Output is correct
10 Correct 22 ms 4472 KB Output is correct
11 Correct 19 ms 4344 KB Output is correct
12 Correct 23 ms 4344 KB Output is correct
13 Correct 21 ms 4472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 4216 KB Output is correct
2 Correct 16 ms 4216 KB Output is correct
3 Correct 16 ms 4348 KB Output is correct
4 Correct 16 ms 4216 KB Output is correct
5 Correct 16 ms 4216 KB Output is correct
6 Correct 16 ms 4216 KB Output is correct
7 Correct 16 ms 4216 KB Output is correct
8 Correct 16 ms 4216 KB Output is correct
9 Correct 17 ms 4216 KB Output is correct
10 Correct 22 ms 4472 KB Output is correct
11 Correct 19 ms 4344 KB Output is correct
12 Correct 23 ms 4344 KB Output is correct
13 Correct 21 ms 4472 KB Output is correct
14 Correct 629 ms 19048 KB Output is correct
15 Correct 344 ms 14440 KB Output is correct
16 Correct 599 ms 18536 KB Output is correct
17 Correct 343 ms 12332 KB Output is correct