結果

問題 No.2204 Palindrome Splitting (No Rearrangement ver.)
ユーザー umimelumimel
提出日時 2023-02-03 22:22:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,705 ms / 2,000 ms
コード長 1,719 bytes
コンパイル時間 1,562 ms
コンパイル使用メモリ 170,152 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-15 18:25:58
合計ジャッジ時間 5,115 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 29 ms
4,376 KB
testcase_04 AC 8 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 6 ms
4,376 KB
testcase_07 AC 10 ms
4,376 KB
testcase_08 AC 9 ms
4,380 KB
testcase_09 AC 20 ms
4,380 KB
testcase_10 AC 17 ms
4,376 KB
testcase_11 AC 11 ms
4,376 KB
testcase_12 AC 21 ms
4,380 KB
testcase_13 AC 10 ms
4,380 KB
testcase_14 AC 11 ms
4,380 KB
testcase_15 AC 14 ms
4,380 KB
testcase_16 AC 4 ms
4,380 KB
testcase_17 AC 6 ms
4,376 KB
testcase_18 AC 16 ms
4,376 KB
testcase_19 AC 8 ms
4,376 KB
testcase_20 AC 11 ms
4,376 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 4 ms
4,376 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 24 ms
4,380 KB
testcase_25 AC 40 ms
4,376 KB
testcase_26 AC 62 ms
4,380 KB
testcase_27 AC 195 ms
4,380 KB
testcase_28 AC 8 ms
4,380 KB
testcase_29 AC 3 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 48 ms
4,376 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 1,705 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i)
#define rep(i, n) drep(i, 0, n - 1)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second

const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll INF = 1LL << 60;
const ll MAX_N = 2e5;

struct ZAlgorithm{
    ZAlgorithm(){}

    vector<int> query(string S){
        int N = (int)S.size();
        vector<int> Z(N);
        Z[0] = N;
        int i=1, j=0;
        while(i < N){
            while(i+j<N && S[j]==S[i+j]) j++;
            Z[i] = j;

            if(j == 0){
                i++;
                continue;
            }

            int k=1;
            while(k < j && k+Z[k]<j){
                Z[i+k] = Z[k];
                k++;
            }
            i += k;
            j -= k;
        }

        return Z;
    }
};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    string s;
    cin >> s;

    int n = (int)s.size();

    ZAlgorithm za;
    int lw = 1;
    int hi = n+1;
    int mid;
    while(hi-lw>1){
        mid = (lw+hi)/2;

        vector<bool> check(n+1, false);
        check[0]=true;
        for(int i=0; i<n; i++){
            if(!check[i]) continue;
            string t = "";
            for(int j=i; j<n; j++) t+=s[j];
            for(int j=n-1; j>=i; j--) t+=s[j];

            vector<int> z = za.query(t);
            for(int j=mid-1; j<n-i; j++){
                if(z[2*(n-i)-1-j]==j+1){
                    check[i+j+1] = true;
                }
            }
        }

        if(check[n]) lw = mid;
        else hi = mid;
    }

    cout << lw << endl;
}
0