結果

問題 No.2549 Paint Eggs
ユーザー InTheBloomInTheBloom
提出日時 2023-11-20 19:53:53
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 1,136 bytes
コンパイル時間 1,778 ms
コンパイル使用メモリ 165,856 KB
実行使用メモリ 28,456 KB
最終ジャッジ日時 2023-11-20 19:54:01
合計ジャッジ時間 7,214 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 1 ms
6,676 KB
testcase_07 AC 1 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 91 ms
25,960 KB
testcase_11 AC 70 ms
15,240 KB
testcase_12 AC 67 ms
15,428 KB
testcase_13 AC 80 ms
15,748 KB
testcase_14 AC 48 ms
14,292 KB
testcase_15 AC 6 ms
6,676 KB
testcase_16 AC 77 ms
15,660 KB
testcase_17 AC 50 ms
10,864 KB
testcase_18 AC 41 ms
10,648 KB
testcase_19 AC 61 ms
11,512 KB
testcase_20 AC 113 ms
28,332 KB
testcase_21 AC 110 ms
28,324 KB
testcase_22 AC 115 ms
28,348 KB
testcase_23 AC 115 ms
28,284 KB
testcase_24 AC 128 ms
28,352 KB
testcase_25 AC 104 ms
28,404 KB
testcase_26 AC 106 ms
28,192 KB
testcase_27 AC 109 ms
28,332 KB
testcase_28 AC 118 ms
28,224 KB
testcase_29 AC 110 ms
28,252 KB
testcase_30 AC 112 ms
28,332 KB
testcase_31 AC 106 ms
28,372 KB
testcase_32 AC 112 ms
28,456 KB
testcase_33 AC 109 ms
28,380 KB
testcase_34 AC 119 ms
28,208 KB
testcase_35 AC 118 ms
28,412 KB
testcase_36 AC 114 ms
28,332 KB
testcase_37 AC 108 ms
28,384 KB
testcase_38 AC 106 ms
28,292 KB
testcase_39 AC 111 ms
28,356 KB
testcase_40 AC 115 ms
28,368 KB
testcase_41 AC 115 ms
28,316 KB
testcase_42 AC 115 ms
28,260 KB
testcase_43 AC 116 ms
28,320 KB
testcase_44 AC 129 ms
28,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

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

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

void solve (int N, int M, int K, int[] C, int[] A) {
    /* スライドしていけば良さそう */
    int[int] mp;
    // 最初の一回
    foreach (i; 0..K) mp[C[i]]++;

    long ans = long.max;

    foreach (key, val; mp) {
        ans = min(ans, 1L*(K-val)*A[key]);
    }

    int left = 0, right = K;
    while (right < N) {
        // [left, right)を保持している
        // leftを除去してrightを加入させる

        mp[C[left]]--;
        mp[C[right]]++;
        ans = min(ans, 1L*(K-mp[C[right]])*A[C[right]]);

        left++, right++;

        //dbg
        //writeln("[", left, ", ", right, ") ", mp);
    }

    // ハマった。単に全部塗り替えるのが最適な場合がある
    foreach (a; A) {
        ans = min(ans, 1L*K*a);
    }

    writeln(ans);
}

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