結果

問題 No.158 奇妙なお使い
ユーザー tentententen
提出日時 2023-01-26 17:15:48
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 3,492 bytes
コンパイル時間 2,696 ms
コンパイル使用メモリ 82,636 KB
実行使用メモリ 345,040 KB
最終ジャッジ日時 2023-09-09 17:36:47
合計ジャッジ時間 10,520 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 52 ms
50,032 KB
testcase_03 AC 44 ms
49,536 KB
testcase_04 AC 2,905 ms
345,040 KB
testcase_05 AC 46 ms
49,256 KB
testcase_06 AC 45 ms
49,420 KB
testcase_07 AC 45 ms
49,264 KB
testcase_08 AC 52 ms
50,204 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 51 ms
49,892 KB
testcase_13 AC 48 ms
49,744 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 207 ms
60,848 KB
testcase_17 AC 530 ms
74,020 KB
testcase_18 AC 237 ms
67,644 KB
testcase_19 AC 64 ms
52,136 KB
testcase_20 AC 125 ms
57,368 KB
testcase_21 AC 82 ms
57,244 KB
testcase_22 AC 90 ms
57,908 KB
testcase_23 AC 89 ms
55,896 KB
testcase_24 AC 79 ms
52,428 KB
testcase_25 WA -
testcase_26 AC 116 ms
56,724 KB
testcase_27 AC 52 ms
50,004 KB
testcase_28 WA -
testcase_29 AC 62 ms
52,160 KB
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
    }
    
}
0