結果

問題 No.2162 Copy and Paste 2
ユーザー 👑 rin204rin204
提出日時 2022-12-13 01:02:45
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 227 ms / 7,000 ms
コード長 1,574 bytes
コンパイル時間 2,209 ms
コンパイル使用メモリ 201,000 KB
実行使用メモリ 36,444 KB
最終ジャッジ日時 2024-04-24 14:12:57
合計ジャッジ時間 6,664 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 47 ms
36,316 KB
testcase_07 AC 49 ms
36,320 KB
testcase_08 AC 98 ms
36,320 KB
testcase_09 AC 154 ms
36,104 KB
testcase_10 AC 163 ms
36,444 KB
testcase_11 AC 168 ms
36,440 KB
testcase_12 AC 191 ms
36,312 KB
testcase_13 AC 199 ms
36,444 KB
testcase_14 AC 157 ms
36,444 KB
testcase_15 AC 169 ms
35,712 KB
testcase_16 AC 170 ms
36,444 KB
testcase_17 AC 156 ms
36,316 KB
testcase_18 AC 187 ms
36,440 KB
testcase_19 AC 179 ms
36,392 KB
testcase_20 AC 178 ms
36,444 KB
testcase_21 AC 107 ms
36,320 KB
testcase_22 AC 122 ms
36,316 KB
testcase_23 AC 35 ms
36,316 KB
testcase_24 AC 194 ms
36,444 KB
testcase_25 AC 189 ms
36,316 KB
testcase_26 AC 186 ms
36,320 KB
testcase_27 AC 189 ms
36,440 KB
testcase_28 AC 227 ms
36,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define endl '\n'

vector<int> Z_algo(string S){
    int l = S.size();
    vector<int> Z(l, 0);
    Z[0] = l;
    int i = 1;
    int j = 0;
    while(i < l){
        while (i + j < l && S[j] == S[i + j]) j++;
        Z[i] = j;
        if(j == 0){
            i++;
            continue;
        }
        int k = 1;
        while(i + k < l && k + Z[k] < j){
            Z[i + k] = Z[k];
            k++;
        }
        i += k;
        j -= k;
    }
    return Z;
}

int main(){
    string S;
    cin >> S;
    int n = S.size(); 
    auto Z = Z_algo(S);

    vector<vector<int>> ma(20, vector<int>(n, 0));
    vector<vector<int>> nex(20, vector<int>(n, 0));
    ma[0] = Z;
    for(int j = 0; j < n; j++){
        if(j == n - 1) nex[0][j] = j; 
        else nex[0][j] = j + 1;
    }
    for(int i = 1; i < 20; i++){
        for(int j = 0; j < n; j++){
            int k = nex[i - 1][j];
            nex[i][j] = nex[i - 1][k];
            ma[i][j] = max(ma[i - 1][j], ma[i - 1][k]);
        }
    }

    vector<int> mi(n, 0);
    for(int i = 1; i < n; i++){
        mi[i] = min(mi[i], mi[i - 1]);
        int x = mi[i] + 1;
        int j = i + 1;
        int z = i + 1;
        while(j < n){
            if(ma[19][j] < z) break;
            int d = 0;
            for(int k = 19; k >= 0; k--){
                if(ma[k][j] < z) j = nex[k][j];
            }
            j += z - 1;
            x -= z - 1;
            mi[j] = min(mi[j], x);
            j++;
        }
    }
    cout << n + mi[n - 1] << endl;
}
0