Submission #858977

# Submission time Handle Problem Language Result Execution time Memory
858977 2023-10-09T13:52:52 Z VinhLuu Palindromic Partitions (CEOI17_palindromic) C++17
0 / 100
6 ms 10584 KB
#include <bits/stdc++.h>
//#define ll long long
#define int long long
using namespace std;

const int mod = 1e9 + 7;
const int Max = 1e6 + 5;

string s;
int dp[Max],n;
int lt[Max],hs[Max];

int get(int i,int j){
    return (hs[j]%mod + mod - (1LL * hs[i - 1]*lt[j - i + 1])%mod)%mod;
}

int dfs(int i){
    if(dp[i] != 0) return dp[i];
    dp[i] = 1;
    int l = i, r = n - i + 1;
    //cout << l << " " << r << "\n";
    int mid = (r - l + 1) / 2;
    for(int j = 1; j <= mid; j ++){
       // cout << l << " " << l + j - 1 << " " << r - j + 1 << " " << r << "u\n";
        if(get(l, l + j - 1) == get(r - j + 1, r)){
            dp[i] = max(dp[i], 2 + dfs(l + j));
        }
    }
    return dp[i];
}


void solve(){
    cin >> s;
    n = s.size();
    s = " " + s;
    for(int i = 1; i <= n; i ++) dp[i] = 0;
    for(int i = 1; i <= n; i ++) hs[i] = ((1LL * hs[i - 1] * 26)%mod + (int)(s[i] - 'a'))%mod;
    cout << dfs(1) << "\n";
}

signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    lt[0] = 1;
    for(int i = 1; i <= Max - 5; i ++) lt[i] = (1LL * lt[i-1] * 26)%mod;
    int tt; cin >> tt;
    while(tt--) solve();
}
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 10584 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 10584 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 10584 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 10584 KB Output isn't correct
2 Halted 0 ms 0 KB -