結果

問題 No.2332 Make a Sequence
ユーザー KKT89KKT89
提出日時 2023-05-28 15:43:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,116 bytes
コンパイル時間 3,577 ms
コンパイル使用メモリ 226,704 KB
実行使用メモリ 24,832 KB
最終ジャッジ日時 2023-08-27 12:49:18
合計ジャッジ時間 20,108 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 181 ms
20,092 KB
testcase_08 AC 25 ms
5,360 KB
testcase_09 AC 124 ms
15,688 KB
testcase_10 AC 186 ms
18,972 KB
testcase_11 AC 110 ms
13,368 KB
testcase_12 AC 237 ms
23,704 KB
testcase_13 AC 205 ms
24,052 KB
testcase_14 AC 244 ms
24,188 KB
testcase_15 AC 253 ms
23,396 KB
testcase_16 AC 205 ms
23,904 KB
testcase_17 AC 235 ms
24,284 KB
testcase_18 AC 243 ms
23,756 KB
testcase_19 AC 219 ms
24,108 KB
testcase_20 AC 222 ms
23,980 KB
testcase_21 AC 244 ms
23,720 KB
testcase_22 AC 217 ms
23,336 KB
testcase_23 AC 230 ms
24,084 KB
testcase_24 AC 226 ms
24,488 KB
testcase_25 AC 232 ms
24,024 KB
testcase_26 AC 229 ms
23,664 KB
testcase_27 AC 242 ms
23,664 KB
testcase_28 AC 238 ms
23,664 KB
testcase_29 AC 238 ms
24,020 KB
testcase_30 AC 238 ms
24,052 KB
testcase_31 AC 243 ms
24,240 KB
testcase_32 AC 261 ms
24,300 KB
testcase_33 AC 274 ms
23,696 KB
testcase_34 AC 275 ms
23,636 KB
testcase_35 AC 271 ms
24,072 KB
testcase_36 AC 269 ms
24,504 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 174 ms
24,268 KB
testcase_48 AC 172 ms
23,936 KB
testcase_49 AC 172 ms
23,956 KB
testcase_50 AC 173 ms
23,576 KB
testcase_51 AC 173 ms
24,640 KB
testcase_52 WA -
testcase_53 WA -
testcase_54 AC 237 ms
23,660 KB
testcase_55 WA -
testcase_56 WA -
testcase_57 AC 230 ms
24,832 KB
testcase_58 AC 233 ms
23,580 KB
testcase_59 AC 233 ms
24,036 KB
testcase_60 AC 233 ms
24,040 KB
testcase_61 AC 233 ms
23,756 KB
testcase_62 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(
            chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

vector<int> Zalgo(vector<int> s){
    int n=s.size();
    vector<int> a(n,0);
    int from=-1,last=-1;
    for(int i=1;i<n;i++){
        int &same=a[i];
        if(from!=-1){
            same=min(a[i-from],last-i);
            same=max(0,same);
        }
        while(i+same<n&&s[same]==s[i+same]){
            same++;
        }
        if(last<i+same){
            last=i+same;
            from=i;
        }
    }
    a[0]=n;
    return a;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m; cin >> n >> m;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    a.push_back(-1);
    for (int i = 0; i < m; ++i) {
        int x; cin >> x;
        a.push_back(x);
    }
    vector<ll> c(m);
    for (int i = 0; i < m; ++i) {
        cin >> c[i];
    }
    vector<pair<ll,int>> v;
    for (int i = 0; i < m; ++i) {
        v.push_back({c[i], i});
    }
    sort(v.begin(), v.end());
    vector<ll> uo(m,-1);
    set<int> st;
    for (int i = 0; i < m; ++i) {
        st.insert(i);
    }
    auto Z = Zalgo(a);
    for (auto p:v) {
        int i = p.second;
        int len = Z[n+1+i];
        while (true) {
            auto it = st.lower_bound(i+len);
            if (it == st.begin()) break;
            it--;
            if (*it < i) break;
            assert(uo[*it] == -1);
            uo[*it] = p.first; st.erase(it);
        }
    }
    if (st.size()) {
        cout << -1 << endl;
        return 0;
    }
    ll cost = 0;
    for (int i = 0; i < m; ++i) {
        ll u = uo[i];
        if (u == -1) {
            cost = -1;
            break;
        }
        cost += u;
    }
    cout << cost << endl;
}
0