結果

問題 No.2566 美しい整数列
ユーザー InTheBloomInTheBloom
提出日時 2023-12-02 16:57:12
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 288 ms / 2,000 ms
コード長 1,491 bytes
コンパイル時間 3,163 ms
コンパイル使用メモリ 164,064 KB
実行使用メモリ 63,272 KB
最終ジャッジ日時 2023-12-02 16:57:24
合計ジャッジ時間 9,267 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 255 ms
63,156 KB
testcase_05 AC 288 ms
60,884 KB
testcase_06 AC 136 ms
22,444 KB
testcase_07 AC 162 ms
21,728 KB
testcase_08 AC 134 ms
22,364 KB
testcase_09 AC 139 ms
21,900 KB
testcase_10 AC 138 ms
21,932 KB
testcase_11 AC 177 ms
47,776 KB
testcase_12 AC 182 ms
47,952 KB
testcase_13 AC 175 ms
47,776 KB
testcase_14 AC 182 ms
48,616 KB
testcase_15 AC 201 ms
48,724 KB
testcase_16 AC 229 ms
60,108 KB
testcase_17 AC 223 ms
60,828 KB
testcase_18 AC 229 ms
63,272 KB
testcase_19 AC 151 ms
50,712 KB
testcase_20 AC 214 ms
60,084 KB
testcase_21 AC 236 ms
60,484 KB
testcase_22 AC 139 ms
53,660 KB
testcase_23 AC 188 ms
52,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

void main () {
    int N, M; readln.read(N, M);
    int[] A = readln.split.to!(int[]);
    int[] B = readln.split.to!(int[]);
    int[] C = readln.split.to!(int[]);

    solve(N, M, A, B, C);
}

void solve (int N, int M, int[] A, int[] B, int[] C) {
    /*
       すでに関係が出来上がっている列はそのままor一挙変更であることがわかる。
       つなぎ目をいい感じに選ぶ問題に帰着する
       -> 連想配列でいい感じに
     */

    // 分割
    int[] sp;
    sp ~= 0;
    foreach (i; 0..N-1) {
        if (A[i+1]-A[i] == B[i%M]) {
            continue;
        }
        sp ~= i+1;
    }
    sp ~= N;

    bool[int] spmp;
    foreach (s; sp) spmp[s] = true;

    long[] cum = new long[](N+1);
    // cum[i] := [0, i)
    cum[0] = 0;
    foreach (i; 1..N+1) {
        cum[i] = cum[i-1] + C[i-1];
    }

    long[int] cost;
    foreach (i; 0..sp.length-1) {
        cost[sp[i]] = cum[sp[i+1]] - cum[sp[i]];
    }

    // 初項が0であったときの美しい数列をトレス
    long[long] mp;
    long b = 0;
    foreach (i; 0..N) {
        if (i in spmp) {
            mp[A[i]-b] += cost[i];
        }
        b += B[i%M];
    }

    long ans = cum[N];
    long sub = -long.max;
    foreach (key, val; mp) {
        sub = max(sub, val);
    }
    writeln(ans - sub);
}

void read (T...) (string S, ref T args) {
    auto buf = S.split;
    foreach (i, ref arg; args) {
        arg = buf[i].to!(typeof(arg));
    }
}
0