結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー takeya_okinotakeya_okino
提出日時 2017-06-17 10:49:48
言語 Java21
(openjdk 21)
結果
AC  
実行時間 193 ms / 2,000 ms
コード長 1,132 bytes
コンパイル時間 2,203 ms
コンパイル使用メモリ 76,800 KB
実行使用メモリ 60,200 KB
最終ジャッジ日時 2024-04-08 17:23:16
合計ジャッジ時間 7,383 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 137 ms
57,836 KB
testcase_01 AC 135 ms
57,944 KB
testcase_02 AC 133 ms
57,836 KB
testcase_03 AC 134 ms
57,956 KB
testcase_04 AC 140 ms
57,836 KB
testcase_05 AC 141 ms
57,588 KB
testcase_06 AC 141 ms
57,936 KB
testcase_07 AC 135 ms
57,940 KB
testcase_08 AC 193 ms
60,196 KB
testcase_09 AC 192 ms
59,932 KB
testcase_10 AC 157 ms
57,684 KB
testcase_11 AC 153 ms
57,976 KB
testcase_12 AC 152 ms
57,804 KB
testcase_13 AC 149 ms
57,968 KB
testcase_14 AC 152 ms
57,844 KB
testcase_15 AC 144 ms
57,812 KB
testcase_16 AC 143 ms
57,960 KB
testcase_17 AC 164 ms
58,348 KB
testcase_18 AC 146 ms
57,972 KB
testcase_19 AC 148 ms
57,960 KB
testcase_20 AC 144 ms
57,844 KB
testcase_21 AC 141 ms
57,964 KB
testcase_22 AC 169 ms
60,084 KB
testcase_23 AC 168 ms
60,092 KB
testcase_24 AC 174 ms
60,080 KB
testcase_25 AC 172 ms
60,072 KB
testcase_26 AC 172 ms
60,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int Gx = sc.nextInt();
    int Gy = sc.nextInt();
    int N = sc.nextInt();
    int F = sc.nextInt();
    int[] x = new int[N];
    int[] y = new int[N];
    int[] c = new int[N];
    for(int i = 0; i < N; i++) {
      x[i] = sc.nextInt();
      y[i] = sc.nextInt();
      c[i] = sc.nextInt();
    }
    // dp[i][j][k]はクリスタル0~i-1(i個)までを使って(j,k)だけ移動する際の最小コスト
    int[][][] dp = new int[N + 1][Gx + 1][Gy + 1];
    for(int j = 0; j < Gx + 1; j++) {
      for(int k = 0; k < Gy + 1; k++) {
        dp[0][j][k] = (j + k) * F; 
      }
    }
    for(int i = 1; i < N + 1; i++) {
      for(int j = 0; j < Gx + 1; j++) {
        for(int k = 0; k < Gy + 1; k++) {
          if(x[i - 1] <= j && y[i - 1] <= k) {
            dp[i][j][k] = Math.min(dp[i - 1][j][k], c[i - 1] + dp[i - 1][j - x[i - 1]][k - y[i - 1]]);
          } else {
            dp[i][j][k] = dp[i - 1][j][k]; 
          }
        }
      }
    }
    System.out.println(dp[N][Gx][Gy]);
  }
}
0