Submission #916132

# Submission time Handle Problem Language Result Execution time Memory
916132 2024-01-25T11:10:13 Z vjudge1 Palindromic Partitions (CEOI17_palindromic) C++17
100 / 100
148 ms 27904 KB
#include <bits/stdc++.h>
 
using namespace std;
 
/// toto -> 1
 
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define io                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define all(a) a.begin(),a.end()
#define rep(k,i,n) for(ll k=i;k<n;k++)
#define repp(k,i,n) for(ll k=n-1;k>=i;k--)
#define rech(k) for(char k='a';k<='z';k++)
#define SZ(a) (int)a.size()
#define MX(a) *max_element(all(a))
#define MN(a) *min_element(all(a))
#define SM(a) accumulate(all(a),0LL)
#define vi vector<int>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vvi vector<vector<int>>
#define fii first
#define see second
 
/// toto -> 
const long long mod = 1e9 + 7 , modd = 998244353;
 
 
typedef long long ll;
 
void F1(bool res) {
    if(res) {
        cout<<"Yes\n" ;
    }
    else {
        cout<<"No\n" ;
    }
}
 
struct mint{
    ll val;
 
    mint(int64_t v = 0) {
        v %= mod;
        if (v < 0) v += mod;
        val = v;
    }
 
    mint& operator+=(const mint& other) {
        val += other.val;
        if (val >= mod) val -= mod;
        return *this;
    }
 
    mint& operator-=(const mint& other) {
        val += mod - other.val;
        if (val >= mod) val -= mod;
        return *this;
    }
 
    mint& operator*=(const mint& other) {
        val = (int64_t)val * other.val % mod;
        return *this;
    }
 
    mint& operator/=(const mint& other) {
        return *this *= other.inv();
    }
 
    friend mint operator+(mint a, const mint& b) { return a += b; }
    friend mint operator-(mint a, const mint& b) { return a -= b; }
    friend mint operator*(mint a, const mint& b) { return a *= b; }
    friend mint operator/(mint a, const mint& b) { return a /= b; }
 
    mint pow(int64_t exp) const {
        mint a = *this, res = 1;
        while (exp > 0) {
            if (exp & 1)
                res *= a;
            a *= a;
            exp >>= 1;
        }
        return res;
    }
 
    mint inv() const {
        assert(val != 0);
        return pow(mod - 2);
    }
 
    friend ostream& operator<<(ostream& os, const mint& m) {
        return os << m.val;
    }
};
 
ll bp(ll n,ll m){
    if(m == 0){
        return 1;
    }
    if(m == 1){
        return n%mod;
    }
    if(m%2==0){
        return bp(n*n%mod,m/2)%mod;
    }
    return n*bp(n,m-1)%mod;
}
 
 
/// toto -> 3
 
const int N = 2e5 + 9, M = 1e6 + 434, inf = 1e9 + 99;
const ll inff = 1e10;
 
 
void solve() {
	string s;
	cin >> s;
	int n = s.size();
 
	ll B = 47;
	vector<ll> p(n+1 , 0), pre(n+1 , 0);
	p[0] = 1; 
	pre[0] = 0;
	
	for (int i = 0; i < n; i++) {
		p[i+1] = (p[i] * B) % mod;
		pre[i+1] = (pre[i] * B + (s[i] - 'a' + 1)) % mod;
	}
 
	int l = 0, r = n, ans = 0;
	while (l < r) {
		int k = 0;
		ll hs1 = 0, hs2 = 1;
		while (hs1 != hs2) {
			k++;
			hs1 = pre[l+k] - (pre[l] * p[k]) % mod;
			hs2 = pre[r] - (pre[r - k] * p[k]) % mod;
			hs1 = (hs1 + mod)%mod;
			hs2 = (hs2 + mod)%mod;
		}
		ans ++;
		if(r - l != k) {
			ans++;
		}
		l += k;
		r -= k;
	}
 
	cout << ans << '\n';
}
 
int32_t main() {
	
	
    io;
    
    ll t=1;
       cin >> t;
    rep(_,1,t+1) {
		///cerr << "Start of test case: " << _ << "\n";
        ///cout<<"Case #"<<_<<": ";
        solve();
        ///cerr << "\n";
        ///cerr << "\n";
    }
    return 0;
 
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 456 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 456 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 456 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 2 ms 712 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 2 ms 696 KB Output is correct
13 Correct 2 ms 668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 456 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 2 ms 712 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 2 ms 696 KB Output is correct
13 Correct 2 ms 668 KB Output is correct
14 Correct 148 ms 27904 KB Output is correct
15 Correct 85 ms 22600 KB Output is correct
16 Correct 143 ms 26156 KB Output is correct
17 Correct 76 ms 15140 KB Output is correct