結果
問題 |
No.496 ワープクリスタル (給料日前編)
|
ユーザー |
|
提出日時 | 2017-04-02 23:27:05 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 172 ms / 2,000 ms |
コード長 | 974 bytes |
コンパイル時間 | 3,955 ms |
コンパイル使用メモリ | 80,008 KB |
実行使用メモリ | 41,828 KB |
最終ジャッジ日時 | 2024-07-08 00:19:23 |
合計ジャッジ時間 | 7,557 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 23 |
ソースコード
import java.util.ArrayList; import java.util.Scanner; public class WarpCrystal { public static void main(String[] args) { Scanner s = new Scanner(System.in); int Gx = s.nextInt() , Gy = s.nextInt() , N = s.nextInt() , F = s.nextInt(); ArrayList<Integer> cx = new ArrayList<>(); ArrayList<Integer> cy = new ArrayList<>(); ArrayList<Integer> cc = new ArrayList<>(); for(int i = 0;i < N;i++){ int x = s.nextInt(),y = s.nextInt(),c = s.nextInt(); if(c < (x+y)*F){ cx.add(x); cy.add(y); cc.add(c); } } s.close(); int[][] mas = new int[Gx+1][Gy+1]; for(int i =0;i <= Gx;i++){ for(int j = 0;j <= Gy;j++){ mas[i][j] = (i + j) * F; } } for(int i = 0;i < cx.size();i++){ for(int j = Gx;j >= 0;j--){ for(int k = Gy;k >= 0;k--){ if(j - cx.get(i) >= 0 && k -cy.get(i) >= 0){ mas[j][k] = Math.min(mas[j][k], mas[j-cx.get(i)][k-cy.get(i)]+cc.get(i)); } } } } System.out.println(mas[Gx][Gy]); } }