結果

問題 No.2162 Copy and Paste 2
ユーザー akakimidoriakakimidori
提出日時 2021-12-22 07:15:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 784 ms / 7,000 ms
コード長 1,120 bytes
コンパイル時間 2,012 ms
コンパイル使用メモリ 110,164 KB
実行使用メモリ 15,388 KB
最終ジャッジ日時 2024-04-24 13:02:21
合計ジャッジ時間 11,627 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 79 ms
10,140 KB
testcase_07 AC 108 ms
12,220 KB
testcase_08 AC 266 ms
15,132 KB
testcase_09 AC 82 ms
9,748 KB
testcase_10 AC 80 ms
9,744 KB
testcase_11 AC 188 ms
13,600 KB
testcase_12 AC 150 ms
12,316 KB
testcase_13 AC 334 ms
15,004 KB
testcase_14 AC 118 ms
10,140 KB
testcase_15 AC 112 ms
10,252 KB
testcase_16 AC 113 ms
10,256 KB
testcase_17 AC 591 ms
15,260 KB
testcase_18 AC 701 ms
15,388 KB
testcase_19 AC 649 ms
15,136 KB
testcase_20 AC 619 ms
15,132 KB
testcase_21 AC 332 ms
15,260 KB
testcase_22 AC 315 ms
15,260 KB
testcase_23 AC 117 ms
15,256 KB
testcase_24 AC 770 ms
15,388 KB
testcase_25 AC 780 ms
15,136 KB
testcase_26 AC 731 ms
15,132 KB
testcase_27 AC 784 ms
15,264 KB
testcase_28 AC 422 ms
10,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// https://yukicoder.me/submissions/692208
// 上をベースに書き換え

#include <atcoder/string>
#include <iostream>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace atcoder;
using namespace std;

int main(void) {
    string s;
    cin >> s;
    const int n = s.size();
    const vector<int> z = z_algorithm(s);
    vector<int> ord;
    set<int> st;
    for (int i = 1; i < n; ++i) {
        if (z[i] >= 1) {
            ord.push_back(i);
            st.emplace(i);
        }
    }
    st.emplace(n);
    sort(ord.begin(), ord.end(), [&](int a, int b) { return z[a] < z[b]; });
    vector<int> dp(n + 1, 0);
    for (int i = 1, x = 0; i < n; ++i) {
        int d = dp[i];
        dp[i + 1] = max(dp[i + 1], d);
        d -= 1;
        int pos = *st.lower_bound(i);
        while (pos < n) {
            d += i - 1;
            dp[pos + i] = max(dp[pos + i], d);
            pos = *st.lower_bound(pos + i);
        }
        for (; x < (int)ord.size() && z[ord[x]] == i; ++x) {
            st.erase(ord[x]);
        }
    }
    int ans = n - dp[n];
    cout << ans << endl;
}
0