답안 #852183

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
852183 2023-09-21T11:55:11 Z c2zi6 Palindromic Partitions (CEOI17_palindromic) C++14
0 / 100
0 ms 344 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

vector<ll> Bpow;
ll B = 31;
ll P = 1e9 + 9;

struct HASHED {
    vector<ll> pref;
    HASHED(string s) {
        if (Bpow.empty()) Bpow.push_back(1);
        while (Bpow.size() <= s.size()) Bpow.push_back(Bpow.back() * B % P);
        pref = vector<ll>(s.size()+1);
        pref[0] = 0;
        for (int i = 1; i <= s.size(); i++) {
            pref[i] = pref[i-1] * B + (s[i-1] - 'a' + 1) % P;
        }
    }
    ll subst(ll l, ll r) {
        ll a = pref[l] * Bpow[r-l+1] % P;
        ll b = pref[r+1];
        return (b + P - a) % P;
    }
};

void solve() {
    string s;
    cin >> s;
    int n = s.size()/2;
    string a, b;
    for (int i = 0; i < n; i++) {
        a.push_back(s[i]);
        b.push_back(s[i+n+s.size()%2]);
    }
    HASHED A(a), B(b);
    int l = 0, r = 0;

    int ans = 0;
    while (true) {
        while (A.subst(l, r) != B.subst(n-r-1, n-l-1)) {
            r++;
            if (r == n) {
                cout << ans + 1 << endl;
                return;
            }
        }
        l = r = r+1;
        ans += 2;
        if (r == n) {
            cout << ans + n%2 << endl;
            return;
        }
    }
}

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

Compilation message

palindromic.cpp: In constructor 'HASHED::HASHED(std::string)':
palindromic.cpp:18:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |         for (int i = 1; i <= s.size(); i++) {
      |                         ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -