結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー tentententen
提出日時 2023-01-06 12:53:03
言語 Java21
(openjdk 21)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 2,337 bytes
コンパイル時間 4,803 ms
コンパイル使用メモリ 85,924 KB
実行使用メモリ 35,916 KB
最終ジャッジ日時 2023-08-20 07:05:22
合計ジャッジ時間 7,633 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
33,356 KB
testcase_01 AC 41 ms
33,492 KB
testcase_02 AC 41 ms
33,436 KB
testcase_03 AC 41 ms
33,316 KB
testcase_04 AC 40 ms
33,456 KB
testcase_05 AC 40 ms
33,424 KB
testcase_06 AC 40 ms
33,748 KB
testcase_07 AC 39 ms
33,292 KB
testcase_08 AC 45 ms
35,520 KB
testcase_09 AC 45 ms
35,608 KB
testcase_10 AC 43 ms
33,596 KB
testcase_11 AC 44 ms
33,448 KB
testcase_12 AC 46 ms
34,116 KB
testcase_13 AC 47 ms
34,112 KB
testcase_14 AC 48 ms
34,016 KB
testcase_15 AC 48 ms
33,588 KB
testcase_16 AC 45 ms
33,832 KB
testcase_17 AC 44 ms
34,364 KB
testcase_18 AC 41 ms
33,888 KB
testcase_19 AC 43 ms
33,768 KB
testcase_20 AC 42 ms
33,716 KB
testcase_21 AC 42 ms
33,824 KB
testcase_22 AC 47 ms
35,696 KB
testcase_23 AC 49 ms
35,916 KB
testcase_24 AC 48 ms
35,700 KB
testcase_25 AC 46 ms
35,440 KB
testcase_26 AC 47 ms
35,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static int f;
    static int[][][] dp;
    static int[] xs;
    static int[] ys;
    static int[] cs;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int gx = sc.nextInt();
        int gy = sc.nextInt();
        int n = sc.nextInt();
        f = sc.nextInt();
        xs = new int[n];
        ys = new int[n];
        cs = new int[n];
        for (int i = 0; i < n; i++) {
            xs[i] = sc.nextInt();
            ys[i] = sc.nextInt();
            cs[i] = sc.nextInt();
        }
        dp = new int[n][gx + 1][gy + 1];
        System.out.println(dfw(n - 1, gx, gy));
    }
    
    static int dfw(int idx, int x, int y) {
        if (x < 0 || y < 0) {
            return Integer.MAX_VALUE / 2;
        }
        if (idx < 0) {
            return (x + y) * f;
        }
        if (dp[idx][x][y] == 0) {
            dp[idx][x][y] = Math.min(dfw(idx - 1, x, y), dfw(idx - 1, x - xs[idx], y - ys[idx]) + cs[idx]);
        }
        return dp[idx][x][y];
    }
}

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