結果

問題 No.2162 Copy and Paste 2
ユーザー hotman78hotman78
提出日時 2022-12-13 14:24:16
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,169 ms / 7,000 ms
コード長 1,686 bytes
コンパイル時間 4,596 ms
コンパイル使用メモリ 251,048 KB
実行使用メモリ 26,768 KB
最終ジャッジ日時 2024-04-25 00:22:01
合計ジャッジ時間 18,183 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 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 105 ms
16,912 KB
testcase_07 AC 139 ms
18,832 KB
testcase_08 AC 366 ms
21,448 KB
testcase_09 AC 153 ms
16,528 KB
testcase_10 AC 147 ms
16,524 KB
testcase_11 AC 282 ms
19,984 KB
testcase_12 AC 260 ms
18,496 KB
testcase_13 AC 513 ms
21,140 KB
testcase_14 AC 205 ms
17,040 KB
testcase_15 AC 220 ms
16,916 KB
testcase_16 AC 211 ms
16,916 KB
testcase_17 AC 832 ms
22,160 KB
testcase_18 AC 986 ms
22,416 KB
testcase_19 AC 951 ms
22,028 KB
testcase_20 AC 863 ms
22,288 KB
testcase_21 AC 463 ms
22,164 KB
testcase_22 AC 436 ms
21,392 KB
testcase_23 AC 133 ms
22,284 KB
testcase_24 AC 1,169 ms
26,636 KB
testcase_25 AC 1,150 ms
26,640 KB
testcase_26 AC 1,056 ms
23,440 KB
testcase_27 AC 1,138 ms
26,768 KB
testcase_28 AC 821 ms
19,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/string>
#include<atcoder/segtree>
using namespace std;
using namespace atcoder;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
template<typename T>using pbds=__gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T>using pbds_map=__gnu_pbds::tree<T,T,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T,typename E>using hash_map=__gnu_pbds::gp_hash_table<T,E>;
template<typename T>using pqueue =__gnu_pbds::priority_queue<T, greater<T>,__gnu_pbds::rc_binomial_heap_tag>;

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

int op(int a, int b) {
    return max(a, b);
}

int e() {
    return (int)(0);
}

int main(){
    string s;
    cin>>s;
    int n=s.size();
    segtree<int, op, e> seg(n+1);
    pbds<int> st;
    vector<vector<int>>v(n+1);
    auto z=z_algorithm(s);
    for(int i=0;i<n;++i){if(z[i]!=0)st.insert(i);}
    for(int i=0;i<n;++i){
        v[z[i]].emplace_back(i);
    }

    for(int i=2;i<n+1;++i){
        // cerr<<"i:"<<i<<endl;
        for(auto e:v[i-1]){
            st.erase(e);
        }
        int now=i,cnt=0;
        int fst=seg.prod(0,now+1);
        while(1){
            ++cnt;
            int itr=st.order_of_key(now);
            if(itr==st.size())break;
            int to=*st.find_by_order(itr)+i;
            assert(to<=n);
            seg.set(to,max(seg.get(to),fst+cnt*(i-1)-1));
            now=to;
        }
    }
    cout<<n-seg.all_prod()<<endl;
}
0