답안 #217865

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
217865 2020-03-31T05:05:45 Z aloo123 Palindromic Partitions (CEOI17_palindromic) C++14
100 / 100
57 ms 11708 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define all(x) (x).begin() , (x).end()
#define f first
#define s second
using namespace std;
 
const ll N =(2e5+5);
const ll MOD = 998244353;
const ll INF = 1e16;
const ll LOG = 29;

long long binpow(long long a, long long b) {
     a %= MOD;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a)%MOD ;
        a = (a * a)%MOD ;
        b >>= 1;
    }
    res%=MOD;
    return res;
}
ll pp[1000005];

void solve(){
    string s;
    cin>>s;
    ll n = (ll)s.size();
    //cout<<n<<endl;
    ll l= 0,r= n -1;
    ll a=0;
    ll b=0;
    ll ans = 0;
    ll x=-1,y=n;
    ll lol = 0,gg=n-1;

    while(l < r){
        a = (a * LOG + (s[l]-'a'+1))%MOD; // 4
        b = ( b + pp[gg-r] * (s[r] - 'a' + 1))%MOD;//  
       // cout<<l<<" "<<r<<" --> " << a<< " "<<b<<endl;
        if(b == a){
            ans += 2;
            a=0;
            b=0;
            x = l,y =r;
            lol = l-1,gg = r-1;
            
        }

        l++,r--;
    }
    if((x+1)<=(y-1))
    ans++;
    cout<<ans<<endl;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    pp[0] = 1;
    for(int i =1;i<=1000000;i++)pp[i] = (pp[i-1] * LOG)%MOD;
    ll t;cin>>t;

    

    while(t--){
        solve();
    }



    return 0;     
    
        
}

Compilation message

palindromic.cpp: In function 'void solve()':
palindromic.cpp:43:8: warning: variable 'lol' set but not used [-Wunused-but-set-variable]
     ll lol = 0,gg=n-1;
        ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 8204 KB Output is correct
2 Correct 14 ms 8192 KB Output is correct
3 Correct 14 ms 8192 KB Output is correct
4 Correct 13 ms 8192 KB Output is correct
5 Correct 16 ms 8248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 8204 KB Output is correct
2 Correct 14 ms 8192 KB Output is correct
3 Correct 14 ms 8192 KB Output is correct
4 Correct 13 ms 8192 KB Output is correct
5 Correct 16 ms 8248 KB Output is correct
6 Correct 13 ms 8192 KB Output is correct
7 Correct 13 ms 8192 KB Output is correct
8 Correct 13 ms 8212 KB Output is correct
9 Correct 14 ms 8192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 8204 KB Output is correct
2 Correct 14 ms 8192 KB Output is correct
3 Correct 14 ms 8192 KB Output is correct
4 Correct 13 ms 8192 KB Output is correct
5 Correct 16 ms 8248 KB Output is correct
6 Correct 13 ms 8192 KB Output is correct
7 Correct 13 ms 8192 KB Output is correct
8 Correct 13 ms 8212 KB Output is correct
9 Correct 14 ms 8192 KB Output is correct
10 Correct 14 ms 8320 KB Output is correct
11 Correct 14 ms 8192 KB Output is correct
12 Correct 17 ms 8320 KB Output is correct
13 Correct 14 ms 8320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 8204 KB Output is correct
2 Correct 14 ms 8192 KB Output is correct
3 Correct 14 ms 8192 KB Output is correct
4 Correct 13 ms 8192 KB Output is correct
5 Correct 16 ms 8248 KB Output is correct
6 Correct 13 ms 8192 KB Output is correct
7 Correct 13 ms 8192 KB Output is correct
8 Correct 13 ms 8212 KB Output is correct
9 Correct 14 ms 8192 KB Output is correct
10 Correct 14 ms 8320 KB Output is correct
11 Correct 14 ms 8192 KB Output is correct
12 Correct 17 ms 8320 KB Output is correct
13 Correct 14 ms 8320 KB Output is correct
14 Correct 57 ms 11708 KB Output is correct
15 Correct 37 ms 11256 KB Output is correct
16 Correct 57 ms 11512 KB Output is correct
17 Correct 41 ms 10112 KB Output is correct