제출 #1203183

#제출 시각아이디문제언어결과실행 시간메모리
1203183loomPalindromic Partitions (CEOI17_palindromic)C++20
100 / 100
117 ms11132 KiB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define inf 5e18
#define nl '\n'

const int p = 131, mod = 1e9+7;

inline void solve(){
   string s;
   cin>>s;
   int n = s.size();

   int powp[n];
   powp[0] = 1;
   for(int i=1; i<n; i++) powp[i] = powp[i-1] * p % mod;

   int l = 0, r = n-1;
   deque<char> sl, sr;

   int ans = 0, hl = 0, hr = 0;
   while(l < r){
      sl.push_back(s[l]);
      hl = (hl*p + (s[l] - 'a')) % mod;
      
      hr = (hr + powp[sr.size()] * (s[r] - 'a')) % mod;
      sr.push_front(s[r]);

      if(hl == hr and sl == sr){
         ans += 2;
         sl.clear();
         hl = 0;
         sr.clear();
         hr = 0;
      }

      l++, r--;
   }

   cout<<ans + (l == r or sl != sr)<<nl;
}

signed main(){
   ios_base::sync_with_stdio(0);
   cin.tie(NULL);cout.tie(NULL);

   int t = 1;
   cin>>t;
   while(t--) solve();

   return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...