結果

問題 No.2549 Paint Eggs
ユーザー tentententen
提出日時 2023-11-27 10:42:16
言語 Java21
(openjdk 21)
結果
AC  
実行時間 548 ms / 2,000 ms
コード長 2,308 bytes
コンパイル時間 2,932 ms
コンパイル使用メモリ 91,216 KB
実行使用メモリ 77,780 KB
最終ジャッジ日時 2023-11-27 10:42:38
合計ジャッジ時間 19,056 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
55,040 KB
testcase_01 AC 60 ms
54,672 KB
testcase_02 AC 77 ms
54,912 KB
testcase_03 AC 76 ms
54,800 KB
testcase_04 AC 67 ms
55,028 KB
testcase_05 AC 71 ms
54,804 KB
testcase_06 AC 65 ms
55,048 KB
testcase_07 AC 73 ms
55,048 KB
testcase_08 AC 53 ms
54,008 KB
testcase_09 AC 78 ms
54,820 KB
testcase_10 AC 300 ms
69,928 KB
testcase_11 AC 361 ms
70,380 KB
testcase_12 AC 305 ms
62,448 KB
testcase_13 AC 279 ms
69,776 KB
testcase_14 AC 340 ms
65,028 KB
testcase_15 AC 122 ms
57,884 KB
testcase_16 AC 285 ms
66,356 KB
testcase_17 AC 262 ms
61,788 KB
testcase_18 AC 266 ms
62,176 KB
testcase_19 AC 305 ms
64,060 KB
testcase_20 AC 393 ms
77,780 KB
testcase_21 AC 384 ms
73,256 KB
testcase_22 AC 547 ms
75,252 KB
testcase_23 AC 378 ms
72,836 KB
testcase_24 AC 391 ms
74,036 KB
testcase_25 AC 411 ms
73,860 KB
testcase_26 AC 361 ms
72,608 KB
testcase_27 AC 521 ms
74,176 KB
testcase_28 AC 407 ms
72,032 KB
testcase_29 AC 375 ms
72,828 KB
testcase_30 AC 462 ms
73,756 KB
testcase_31 AC 371 ms
73,876 KB
testcase_32 AC 373 ms
73,888 KB
testcase_33 AC 438 ms
74,880 KB
testcase_34 AC 370 ms
72,680 KB
testcase_35 AC 391 ms
73,948 KB
testcase_36 AC 548 ms
73,860 KB
testcase_37 AC 395 ms
73,900 KB
testcase_38 AC 390 ms
72,820 KB
testcase_39 AC 399 ms
73,796 KB
testcase_40 AC 372 ms
73,916 KB
testcase_41 AC 413 ms
73,348 KB
testcase_42 AC 395 ms
72,228 KB
testcase_43 AC 379 ms
72,836 KB
testcase_44 AC 420 ms
72,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();
        int[] colors = new int[n];
        for (int i = 0; i < n; i++) {
            colors[i] = sc.nextInt() - 1;
        }
        long[] costs = new long[m];
        long[] colorCosts = new long[m];
        for (int i = 0; i < m; i++) {
            costs[i] = sc.nextInt();
            colorCosts[i] = costs[i] * k;
        }
        for (int i = 0; i < k; i++) {
            colorCosts[colors[i]] -= costs[colors[i]];
        }
        long ans = Long.MAX_VALUE;
        for (long x : colorCosts) {
            ans = Math.min(ans, x);
        }
        for (int i = k; i < n; i++) {
            colorCosts[colors[i - k]] += costs[colors[i - k]];
            colorCosts[colors[i]] -= costs[colors[i]];
            ans = Math.min(ans, colorCosts[colors[i]]);
        }
        System.out.println(ans);
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0