結果

問題 No.2162 Copy and Paste 2
ユーザー 👑 NachiaNachia
提出日時 2024-04-26 02:04:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 138 ms / 7,000 ms
コード長 1,082 bytes
コンパイル時間 1,639 ms
コンパイル使用メモリ 112,080 KB
実行使用メモリ 7,984 KB
最終ジャッジ日時 2024-04-26 02:04:51
合計ジャッジ時間 4,318 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 30 ms
7,860 KB
testcase_07 AC 29 ms
7,736 KB
testcase_08 AC 43 ms
7,860 KB
testcase_09 AC 100 ms
7,856 KB
testcase_10 AC 122 ms
7,640 KB
testcase_11 AC 113 ms
7,860 KB
testcase_12 AC 138 ms
7,736 KB
testcase_13 AC 120 ms
7,856 KB
testcase_14 AC 49 ms
7,728 KB
testcase_15 AC 60 ms
7,720 KB
testcase_16 AC 61 ms
7,864 KB
testcase_17 AC 34 ms
7,732 KB
testcase_18 AC 56 ms
7,736 KB
testcase_19 AC 48 ms
7,860 KB
testcase_20 AC 52 ms
7,732 KB
testcase_21 AC 39 ms
7,984 KB
testcase_22 AC 50 ms
7,728 KB
testcase_23 AC 24 ms
7,732 KB
testcase_24 AC 43 ms
7,732 KB
testcase_25 AC 43 ms
7,732 KB
testcase_26 AC 53 ms
7,860 KB
testcase_27 AC 47 ms
7,984 KB
testcase_28 AC 49 ms
7,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <atcoder/modint>
#include <atcoder/string>
#include <atcoder/segtree>

using namespace std;
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using Modint = atcoder::static_modint<998244353>;


namespace RMQ{
    using S = int;
    S op(S l, S r){ return max(l, r); }
    S e(){ return -1; }
    using Segtree = atcoder::segtree<S, op, e>;
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string S; cin >> S;
    auto Z = atcoder::z_algorithm(S);
    int n = S.size();

    RMQ::Segtree segtree(atcoder::z_algorithm(S));
    
    vector<int> dp(n+1);
    rep(i,n+1) dp[i] = i;

    for(int x=1; x<=n; x++){
        dp[x] = min(dp[x], dp[x-1] + 1);
        int p = x, t = dp[x] + 1;
        while(p < n){
            int nx = segtree.max_right(p, [x](int v){ return v<x; });
            if(nx >= n) break;
            t += nx - p + 1;
            p = nx + x;
            dp[p] = min(dp[p], t);
        }
    }

    cout << dp[n] << '\n';
    return 0;
}
0