結果

問題 No.158 奇妙なお使い
ユーザー htensaihtensai
提出日時 2020-05-14 15:10:29
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,476 bytes
コンパイル時間 2,312 ms
コンパイル使用メモリ 76,044 KB
実行使用メモリ 84,368 KB
最終ジャッジ日時 2023-10-13 10:19:27
合計ジャッジ時間 10,040 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
56,224 KB
testcase_01 AC 646 ms
78,476 KB
testcase_02 AC 173 ms
59,244 KB
testcase_03 AC 124 ms
55,628 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static int[] aArr = new int[4];
    static int[] bArr = new int[4];
    static HashMap<Integer, HashMap<Integer, HashMap<Integer, Integer>>> dp = new HashMap<>();
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		for (int i = 0; i < 4; i++) {
		    aArr[i] = sc.nextInt();
		}
		for (int i = 0; i < 4; i++) {
		    bArr[i] = sc.nextInt();
		}
		System.out.println(func(a, b, c));
	}
	
	static int func(int a, int b, int c) {
	    int max = Math.max(func(a, b, c, aArr), func(a, b, c, bArr));
	    if (dp.containsKey(a)) {
	        if (dp.get(a).containsKey(b)) {
	            if (dp.get(a).get(b).containsKey(c)) {
	                return dp.get(a).get(b).get(c);
	            }
	        } else {
	            dp.get(a).put(b, new HashMap<>());
	        }
	    } else {
	        dp.put(a, new HashMap<>());
	        dp.get(a).put(b, new HashMap<>());
	    }
	    dp.get(a).get(b).put(c, max);
	    return max;
	}
	
	static int func(int a, int b, int c, int[] arr) {
	    if (a * 1000 + b * 100 + c < arr[0]) {
	        return 0;
	    }
	    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 0;
	    }
	    return func(a + arr[1], b + arr[2], c + arr[3]) + 1;
	}
}
0