結果

問題 No.158 奇妙なお使い
ユーザー htensaihtensai
提出日時 2020-05-14 15:56:18
言語 Java19
(openjdk 21)
結果
AC  
実行時間 292 ms / 5,000 ms
コード長 1,474 bytes
コンパイル時間 2,062 ms
コンパイル使用メモリ 75,044 KB
実行使用メモリ 59,816 KB
最終ジャッジ日時 2023-10-13 11:20:47
合計ジャッジ時間 8,119 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,764 KB
testcase_01 AC 128 ms
55,904 KB
testcase_02 AC 128 ms
55,780 KB
testcase_03 AC 123 ms
55,464 KB
testcase_04 AC 292 ms
59,816 KB
testcase_05 AC 123 ms
55,696 KB
testcase_06 AC 125 ms
55,820 KB
testcase_07 AC 125 ms
56,172 KB
testcase_08 AC 126 ms
56,040 KB
testcase_09 AC 126 ms
55,600 KB
testcase_10 AC 128 ms
55,728 KB
testcase_11 AC 126 ms
55,724 KB
testcase_12 AC 123 ms
55,860 KB
testcase_13 AC 123 ms
55,896 KB
testcase_14 AC 126 ms
55,848 KB
testcase_15 AC 158 ms
56,816 KB
testcase_16 AC 131 ms
56,468 KB
testcase_17 AC 170 ms
56,496 KB
testcase_18 AC 208 ms
59,124 KB
testcase_19 AC 127 ms
55,628 KB
testcase_20 AC 154 ms
57,124 KB
testcase_21 AC 154 ms
57,884 KB
testcase_22 AC 155 ms
58,324 KB
testcase_23 AC 125 ms
55,696 KB
testcase_24 AC 127 ms
55,856 KB
testcase_25 AC 125 ms
55,712 KB
testcase_26 AC 129 ms
55,668 KB
testcase_27 AC 126 ms
55,728 KB
testcase_28 AC 127 ms
55,940 KB
testcase_29 AC 128 ms
55,892 KB
testcase_30 AC 144 ms
56,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int[] aArr = new int[4];
		int[] bArr = new int[4];
		for (int i = 0; i < 4; i++) {
		    aArr[i] = sc.nextInt();
		}
		for (int i = 0; i < 4; i++) {
		    bArr[i] = sc.nextInt();
		}
		HashMap<Integer, Integer> dp = new HashMap<>();
		dp.put(a * 1000 + b, c);
		int count = -1;
		while (dp.size() > 0) {
		    HashMap<Integer, Integer> next = new HashMap<>();
		    for (Map.Entry<Integer, Integer> entry : dp.entrySet()) {
		        int x = entry.getKey() / 1000;
		        int y = entry.getKey() % 1000;
		        int z = entry.getValue();
		        setDP(x, y, z, aArr, next);
		        setDP(x, y, z, bArr, next);
		    }
		    dp = next;
		    count++;
		}
		System.out.println(count);
	}
	
	static boolean setDP(int a, int b, int c, int[] arr, HashMap<Integer, Integer> dp) {
	    if (a * 1000 + b * 100 + c < arr[0]) {
	        return false;
	    }
	    int x = arr[0];
	    while (x >= 1000 && a > 0) {
	        x -= 1000;
	        a--;
	    }
	    while (x >= 100 && b > 0) {
	        x -= 100;
	        b--;
	    }
	    c -= x;
	    if (c < 0) {
	        return false;
	    }
	    a += arr[1];
	    b += arr[2];
	    c += arr[3];
	    int key = a * 1000 + b;
	    if (!dp.containsKey(key) || dp.get(key) < c) {
	        dp.put(key, c);
	    }
	    return true;
	}
}
0