Submission #703679

# Submission time Handle Problem Language Result Execution time Memory
703679 2023-02-28T06:07:09 Z mychecksedad Palindromic Partitions (CEOI17_palindromic) C++17
100 / 100
231 ms 34556 KB
/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define PI 3.1415926535
#define pb push_back
#define all(x) x.begin(), x.end()
const int N = 1e6+100, M = 1e5+10, K = 20;

int n;
string s;
ll h[N], p[N], rp[N];
ll po(ll a, ll b){ll res = 1; while(b){if(b&1) (res*=a)%=MOD; b>>=1; (a*=a)%=MOD;} return res;}

ll mod(ll x){
  x %= MOD;
  x = (x+MOD)%MOD;
  return x;
}

void solve(){
  cin >> s;
  n = s.length();
  h[0] = 0;
  for(int i = 1; i <= n; ++i){
    h[i] = (h[i - 1] + p[i] * (s[i - 1] - 'a' + 1)) % MOD;
  }
  int ans = 1, last = 1;
  for(int i = 1; i <= n/2; ++i){
    if(mod((h[n - last + 1] - h[n - i]) * rp[n - i]) == mod((h[i] - h[last - 1]) * rp[last - 1])){
      ans += 2;
      last = i + 1;
    }
  }
  if(n % 2 == 0 && last == n/2 + 1) ans--;
  cout << ans;
}


int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int T = 1, aa;
  cin >> T;aa=T;
  p[0] = 1;
  for(int i = 1; i < N; ++i) p[i] = (p[i - 1] * 37) % MOD;
  for(int i = 0; i < N; ++i) rp[i] = po(p[i], MOD-2);
  while(T--){
    // cout << "Case #" << aa-T << ": ";
    solve();
    cout << '\n';
  }
  return 0;
 
}

Compilation message

palindromic.cpp: In function 'int main()':
palindromic.cpp:44:14: warning: variable 'aa' set but not used [-Wunused-but-set-variable]
   44 |   int T = 1, aa;
      |              ^~
# Verdict Execution time Memory Grader output
1 Correct 136 ms 15912 KB Output is correct
2 Correct 138 ms 15964 KB Output is correct
3 Correct 138 ms 15944 KB Output is correct
4 Correct 149 ms 15916 KB Output is correct
5 Correct 144 ms 15868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 136 ms 15912 KB Output is correct
2 Correct 138 ms 15964 KB Output is correct
3 Correct 138 ms 15944 KB Output is correct
4 Correct 149 ms 15916 KB Output is correct
5 Correct 144 ms 15868 KB Output is correct
6 Correct 137 ms 15944 KB Output is correct
7 Correct 141 ms 15912 KB Output is correct
8 Correct 141 ms 15912 KB Output is correct
9 Correct 138 ms 15900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 136 ms 15912 KB Output is correct
2 Correct 138 ms 15964 KB Output is correct
3 Correct 138 ms 15944 KB Output is correct
4 Correct 149 ms 15916 KB Output is correct
5 Correct 144 ms 15868 KB Output is correct
6 Correct 137 ms 15944 KB Output is correct
7 Correct 141 ms 15912 KB Output is correct
8 Correct 141 ms 15912 KB Output is correct
9 Correct 138 ms 15900 KB Output is correct
10 Correct 140 ms 16112 KB Output is correct
11 Correct 139 ms 16076 KB Output is correct
12 Correct 142 ms 16076 KB Output is correct
13 Correct 136 ms 16108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 136 ms 15912 KB Output is correct
2 Correct 138 ms 15964 KB Output is correct
3 Correct 138 ms 15944 KB Output is correct
4 Correct 149 ms 15916 KB Output is correct
5 Correct 144 ms 15868 KB Output is correct
6 Correct 137 ms 15944 KB Output is correct
7 Correct 141 ms 15912 KB Output is correct
8 Correct 141 ms 15912 KB Output is correct
9 Correct 138 ms 15900 KB Output is correct
10 Correct 140 ms 16112 KB Output is correct
11 Correct 139 ms 16076 KB Output is correct
12 Correct 142 ms 16076 KB Output is correct
13 Correct 136 ms 16108 KB Output is correct
14 Correct 231 ms 34556 KB Output is correct
15 Correct 195 ms 30016 KB Output is correct
16 Correct 223 ms 34016 KB Output is correct
17 Correct 192 ms 25832 KB Output is correct