結果

問題 No.2162 Copy and Paste 2
ユーザー suisensuisen
提出日時 2022-12-19 19:00:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 147 ms / 7,000 ms
コード長 805 bytes
コンパイル時間 1,424 ms
コンパイル使用メモリ 97,248 KB
実行使用メモリ 7,216 KB
最終ジャッジ日時 2023-08-11 09:52:22
合計ジャッジ時間 6,066 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 35 ms
7,044 KB
testcase_07 AC 35 ms
7,040 KB
testcase_08 AC 44 ms
6,940 KB
testcase_09 AC 116 ms
6,900 KB
testcase_10 AC 129 ms
6,948 KB
testcase_11 AC 123 ms
6,928 KB
testcase_12 AC 147 ms
7,216 KB
testcase_13 AC 135 ms
6,964 KB
testcase_14 AC 59 ms
6,940 KB
testcase_15 AC 70 ms
6,960 KB
testcase_16 AC 69 ms
7,040 KB
testcase_17 AC 36 ms
6,984 KB
testcase_18 AC 59 ms
7,048 KB
testcase_19 AC 50 ms
6,928 KB
testcase_20 AC 58 ms
7,048 KB
testcase_21 AC 42 ms
6,932 KB
testcase_22 AC 54 ms
6,928 KB
testcase_23 AC 27 ms
6,896 KB
testcase_24 AC 47 ms
7,036 KB
testcase_25 AC 47 ms
6,956 KB
testcase_26 AC 53 ms
6,964 KB
testcase_27 AC 47 ms
7,004 KB
testcase_28 AC 52 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

#include <atcoder/string>
#include <atcoder/segtree>

int op(int x, int y) {
    return std::max(x, y);
}
int e() {
    return 0;
}

int main() {
    std::string s;
    std::cin >> s;
    const int n = s.size();

    std::vector<int> z = atcoder::z_algorithm(s);

    atcoder::segtree<int, op, e> seg(z);

    std::vector<int> dp(n + 1, n);
    dp[1] = 1;

    for (int i = 1; i < n; ++i) {
        dp[i + 1] = std::min(dp[i + 1], dp[i] + 1);

        int c = dp[i] + 1;
        for (int j = i; j < n;) {
            int nj = seg.max_right(j, [&](int v) { return v < i; });
            if (nj == n) break;
            c += (nj - j) + 1;
            dp[nj + i] = std::min(dp[nj + i], c);
            j = nj + i;
        }
    }

    std::cout << dp[n] << std::endl;
}
0