結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー btkbtk
提出日時 2017-03-28 15:22:57
言語 Java21
(openjdk 21)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 4,082 bytes
コンパイル時間 2,138 ms
コンパイル使用メモリ 76,444 KB
実行使用メモリ 51,996 KB
最終ジャッジ日時 2023-09-20 18:28:52
合計ジャッジ時間 4,536 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,336 KB
testcase_01 AC 43 ms
49,360 KB
testcase_02 AC 44 ms
49,292 KB
testcase_03 AC 43 ms
49,292 KB
testcase_04 AC 43 ms
49,372 KB
testcase_05 AC 43 ms
49,500 KB
testcase_06 AC 44 ms
49,364 KB
testcase_07 AC 43 ms
49,396 KB
testcase_08 AC 77 ms
51,956 KB
testcase_09 AC 74 ms
51,996 KB
testcase_10 AC 44 ms
49,352 KB
testcase_11 AC 44 ms
49,300 KB
testcase_12 AC 44 ms
49,348 KB
testcase_13 AC 45 ms
49,236 KB
testcase_14 AC 46 ms
49,392 KB
testcase_15 AC 45 ms
49,404 KB
testcase_16 AC 46 ms
49,320 KB
testcase_17 AC 47 ms
49,464 KB
testcase_18 AC 46 ms
49,512 KB
testcase_19 AC 46 ms
49,224 KB
testcase_20 AC 45 ms
49,488 KB
testcase_21 AC 44 ms
49,184 KB
testcase_22 AC 55 ms
50,084 KB
testcase_23 AC 55 ms
51,064 KB
testcase_24 AC 54 ms
50,028 KB
testcase_25 AC 54 ms
50,492 KB
testcase_26 AC 55 ms
50,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.math.BigInteger;
import java.util.*;

/**
 * Created by btk on 2017/03/16.
 */
public class Main {

    static FastScanner in;
    static PrintWriter out;

    static void solve() {
        int Gr = in.nextInt();
        int Gc = in.nextInt();
        int N = in.nextInt();
        int F = in.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] = in.nextInt();
            y[i] = in.nextInt();
            c[i] = in.nextInt();
        }
        int[][] d=new int[212][212];
        for (int i = 0; i < 212; i++) {
            Arrays.fill(d[i],11234567);
        }
        d[0][0] = 0;
        for (int i = 0; i <= Gr; i++) {
            for (int j = 0; j <= Gc; j++) {
                d[i+1][j] = Math.min(d[i+1][j],d[i][j]+F);
                d[i][j+1] = Math.min(d[i][j+1],d[i][j]+F);
            }
        }
        for (int k = 0; k < N; k++) {
            for (int i = Gr; i >= x[k]; i--) {
                for (int j = Gc; j >= y[k]; j--) {
                    d[i][j] = Math.min(d[i][j],d[i-x[k]][j-y[k]]+c[k]);
                }
            }
        }

        out.println(d[Gr][Gc]);


    }
    public static void main(String[] args){
        in = new FastScanner();
        out = new PrintWriter(System.out);
        solve();
        out.flush();
        out.close();
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
class Pair implements Comparable<Pair> {
    BigInteger a;
    int b;

    public Pair(BigInteger a, int b) {
        this.a = a;
        this.b = b;
    }

    //(a,b)が一致
    @Override
    public boolean equals(Object o) {
        if (o instanceof Pair) {
            Pair p = (Pair) o;
            return a == p.a && b == p.b;
        }
        return super.equals(o);
    }

    //辞書順比較
    @Override
    public int compareTo(Pair o) {
        if (!a.equals(o.a)) {
            return a.compareTo(o.a);
        }
        return Integer.compare(b,o.b);
    }
}
0