結果
問題 | No.158 奇妙なお使い |
ユーザー | tenten |
提出日時 | 2023-01-26 17:15:48 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,492 bytes |
コンパイル時間 | 2,855 ms |
コンパイル使用メモリ | 89,860 KB |
実行使用メモリ | 336,448 KB |
最終ジャッジ日時 | 2024-06-27 10:17:15 |
合計ジャッジ時間 | 10,572 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | AC | 53 ms
37,104 KB |
testcase_03 | AC | 50 ms
37,088 KB |
testcase_04 | AC | 2,973 ms
336,448 KB |
testcase_05 | AC | 50 ms
37,084 KB |
testcase_06 | AC | 50 ms
36,972 KB |
testcase_07 | AC | 50 ms
36,632 KB |
testcase_08 | AC | 52 ms
36,756 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 52 ms
37,168 KB |
testcase_13 | AC | 50 ms
36,892 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 234 ms
49,852 KB |
testcase_17 | AC | 558 ms
61,524 KB |
testcase_18 | AC | 246 ms
56,948 KB |
testcase_19 | AC | 78 ms
38,408 KB |
testcase_20 | AC | 130 ms
47,084 KB |
testcase_21 | AC | 90 ms
42,376 KB |
testcase_22 | AC | 93 ms
44,156 KB |
testcase_23 | AC | 96 ms
42,040 KB |
testcase_24 | AC | 87 ms
40,120 KB |
testcase_25 | WA | - |
testcase_26 | AC | 124 ms
46,012 KB |
testcase_27 | AC | 54 ms
36,888 KB |
testcase_28 | WA | - |
testcase_29 | AC | 56 ms
37,260 KB |
testcase_30 | WA | - |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { static int db; static int b1000; static int b100; static int b1; static int dc; static int c1000; static int c100; static int c1; static HashMap<Long, Integer> dpb = new HashMap<>(); static HashMap<Long, Integer> dpc = new HashMap<>(); public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int a1000 = sc.nextInt(); int a100 = sc.nextInt(); int a1 = sc.nextInt(); db = sc.nextInt(); b1000 = sc.nextInt(); b100 = sc.nextInt(); b1 = sc.nextInt(); dc = sc.nextInt(); c1000 = sc.nextInt(); c100 = sc.nextInt(); c1 = sc.nextInt(); System.out.println(dfwb(a1000, a100, a1)); } static int dfwb(int x1000, int x100, int x1) { long key = getKey(x1000, x100, x1); if (!dpb.containsKey(key)) { int ans = dfwc(x1000, x100, x1); for (int i = 0; i <= x1000 && i * 1000 <= db; i++) { for (int j = 0; j <= x100 && j * 100 <= db - i * 1000; j++) { int value = db - i * 1000 - j * 100; if (x1 >= value) { ans = Math.max(ans, dfwb(x1000 - i + b1000, x100 - j + b100, x1 - value + b1) + 1); } } } dpb.put(key, ans); } return dpb.get(key); } static int dfwc(int x1000, int x100, int x1) { long key = getKey(x1000, x100, x1); if (!dpc.containsKey(key)) { int ans = 0; for (int i = 0; i <= x1000 && i * 1000 <= dc; i++) { for (int j = 0; j <= x100 && j * 100 <= dc - i * 1000; j++) { int value = dc - i * 1000 - j * 100; if (x1 >= value) { ans = Math.max(ans, dfwc(x1000 - i + c1000, x100 - j + c100, x1 - value + c1) + 1); } } } dpc.put(key, ans); } return dpc.get(key); } static long getKey(int x1000, int x100, int x1) { return x1000 * 100000000L + x100 * 100000L + x1; } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }