結果

問題 No.2332 Make a Sequence
ユーザー firiexpfiriexp
提出日時 2023-05-01 14:06:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,628 bytes
コンパイル時間 963 ms
コンパイル使用メモリ 107,488 KB
実行使用メモリ 12,032 KB
最終ジャッジ日時 2024-04-30 16:39:15
合計ジャッジ時間 9,410 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 61 ms
10,368 KB
testcase_08 AC 24 ms
5,504 KB
testcase_09 AC 53 ms
8,960 KB
testcase_10 AC 47 ms
8,960 KB
testcase_11 AC 33 ms
7,296 KB
testcase_12 AC 75 ms
12,032 KB
testcase_13 AC 74 ms
11,904 KB
testcase_14 AC 77 ms
12,032 KB
testcase_15 AC 76 ms
11,904 KB
testcase_16 AC 75 ms
12,032 KB
testcase_17 AC 75 ms
11,904 KB
testcase_18 AC 76 ms
11,904 KB
testcase_19 AC 78 ms
11,904 KB
testcase_20 AC 75 ms
11,904 KB
testcase_21 AC 77 ms
11,904 KB
testcase_22 AC 77 ms
12,032 KB
testcase_23 AC 75 ms
11,904 KB
testcase_24 AC 76 ms
12,032 KB
testcase_25 AC 76 ms
11,776 KB
testcase_26 AC 76 ms
11,904 KB
testcase_27 AC 77 ms
12,032 KB
testcase_28 AC 79 ms
12,032 KB
testcase_29 AC 83 ms
11,776 KB
testcase_30 AC 79 ms
12,032 KB
testcase_31 AC 76 ms
12,032 KB
testcase_32 AC 77 ms
11,904 KB
testcase_33 AC 77 ms
11,904 KB
testcase_34 AC 76 ms
11,776 KB
testcase_35 AC 76 ms
11,904 KB
testcase_36 AC 76 ms
12,032 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 AC 78 ms
12,032 KB
testcase_48 AC 79 ms
11,904 KB
testcase_49 AC 80 ms
11,904 KB
testcase_50 AC 77 ms
12,032 KB
testcase_51 AC 81 ms
11,776 KB
testcase_52 WA -
testcase_53 WA -
testcase_54 AC 80 ms
11,904 KB
testcase_55 WA -
testcase_56 WA -
testcase_57 AC 79 ms
11,904 KB
testcase_58 AC 77 ms
11,904 KB
testcase_59 AC 76 ms
11,904 KB
testcase_60 AC 78 ms
11,904 KB
testcase_61 AC 76 ms
11,904 KB
testcase_62 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>
#include <limits>

static const int MOD = 998244353;
using ll = long long;
using uint = unsigned;
using ull = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;


vector<int> Z_algorithm(const vector<int> &s){
    vector<int> res(s.size());
    for (int i = 1, j = 0; i < s.size(); ++i) {
        if(i + res[i-j] < j + res[j]) res[i] = res[i-j];
        else {
            int k = max(0, j + res[j]-i);
            while(i + k < s.size() && s[k] == s[i+k]) ++k;
            res[i] = k;
            j = i;
        }
    }
    res.front() = s.size();
    return res;
}


int main() {
    int n, m;
    cin >> n >> m;
    vector<int> A(n);
    for (auto &&i : A) scanf("%d", &i);
    vector<int> B(m);
    for (auto &&i : B) scanf("%d", &i);
    vector<int> C(m);
    for (auto &&i : C) scanf("%d", &i);
    vector<ll> idx(m+2);
    iota(idx.begin(),idx.end(), 0);

    vector<int> AB(n+m+1);
    for (int i = 0; i < n; ++i) {
        AB[i] = A[i];
    }
    for (int i = 0; i < m; ++i) {
        AB[i+n] = B[i];
    }
    auto Z = Z_algorithm(AB);
    vector<ll> dp(m+1, INF<ll>);
    dp[0] = 0;
    for (int i = 0; i < m; ++i) {
        for (int j = i+1; j <= i+Z[n+i]; ++j) {
            if(dp[j] >= dp[i] + (ll)C[i]*(j-i)){
                dp[j] = dp[i] + (ll)C[i]*(j-i);
            }else break;
        }
    }
    if(dp[m] == INF<ll>) puts("-1");
    else cout << dp[m] << "\n";
    return 0;
}
0