結果

問題 No.2332 Make a Sequence
ユーザー dyktr_06dyktr_06
提出日時 2023-04-18 20:25:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,371 bytes
コンパイル時間 2,539 ms
コンパイル使用メモリ 199,736 KB
実行使用メモリ 13,884 KB
最終ジャッジ日時 2024-04-21 21:43:01
合計ジャッジ時間 15,532 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,884 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 7 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 63 ms
9,472 KB
testcase_08 AC 27 ms
5,504 KB
testcase_09 AC 58 ms
8,448 KB
testcase_10 AC 51 ms
8,448 KB
testcase_11 AC 39 ms
6,528 KB
testcase_12 AC 77 ms
11,008 KB
testcase_13 AC 80 ms
11,136 KB
testcase_14 AC 80 ms
11,008 KB
testcase_15 AC 84 ms
11,008 KB
testcase_16 AC 87 ms
11,136 KB
testcase_17 AC 87 ms
10,880 KB
testcase_18 AC 79 ms
11,008 KB
testcase_19 AC 79 ms
10,880 KB
testcase_20 AC 79 ms
10,880 KB
testcase_21 AC 83 ms
11,008 KB
testcase_22 AC 80 ms
11,008 KB
testcase_23 AC 83 ms
11,008 KB
testcase_24 AC 79 ms
11,008 KB
testcase_25 AC 81 ms
11,008 KB
testcase_26 AC 81 ms
11,008 KB
testcase_27 AC 81 ms
11,008 KB
testcase_28 AC 81 ms
11,008 KB
testcase_29 AC 79 ms
10,880 KB
testcase_30 AC 82 ms
11,136 KB
testcase_31 AC 83 ms
10,880 KB
testcase_32 AC 86 ms
10,880 KB
testcase_33 AC 85 ms
11,008 KB
testcase_34 AC 86 ms
11,008 KB
testcase_35 AC 87 ms
11,008 KB
testcase_36 AC 86 ms
11,136 KB
testcase_37 AC 86 ms
11,136 KB
testcase_38 AC 87 ms
11,008 KB
testcase_39 AC 86 ms
10,880 KB
testcase_40 AC 76 ms
11,008 KB
testcase_41 AC 88 ms
11,008 KB
testcase_42 AC 87 ms
10,880 KB
testcase_43 AC 80 ms
11,008 KB
testcase_44 AC 79 ms
11,008 KB
testcase_45 AC 83 ms
11,008 KB
testcase_46 AC 81 ms
11,008 KB
testcase_47 TLE -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

template <typename T>
vector<int> z_algorithm(const T &s) {
    int n = s.size();
    vector<int> res(n, 0);
    for(int i = 1, j = 0; i < n; ++i){
        if(i + res[i - j] < j + res[j]){
            res[i] = res[i - j];
        }else{
            res[i] = max(j + res[j] - i, 0);
            while(i + res[i] < n && s[i + res[i]] == s[res[i]]) ++res[i];
            j = i;
        }
    }
    res[0] = n;
    return res;
}

const long long INF = 1LL << 60;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m; cin >> n >> m;
    vector<int> a(n), b(m);
    vector<long long> c(m);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < m; i++){
        cin >> b[i];
    }
    for(int i = 0; i < m; i++){
        cin >> c[i];
    }

    vector<int> d(n + m);
    for(int i = 0; i < n; i++){
        d[i] = a[i];
    }
    for(int i = 0; i < m; i++){
        d[i + n] = b[i];
    }
    vector<int> z = z_algorithm(d);

    vector<long long> dp(m + 1, INF);
    dp[0] = 0;
    for(int i = 0; i < m; i++){
        int add = min(n, z[i + n]);
        for(int j = i + 1; j < i + add + 1; j++){
            dp[j] = min(dp[j], dp[i] + c[i] * (j - i));
        }
    }
    
    if(dp[m] == INF){
        cout << -1 << endl;
    }else{
        cout << dp[m] << endl;
    }
}
0