結果

問題 No.37 遊園地のアトラクション
ユーザー tentententen
提出日時 2023-06-12 16:07:35
言語 Java21
(openjdk 21)
結果
AC  
実行時間 104 ms / 5,000 ms
コード長 2,459 bytes
コンパイル時間 5,710 ms
コンパイル使用メモリ 92,872 KB
実行使用メモリ 57,588 KB
最終ジャッジ日時 2023-09-02 10:37:45
合計ジャッジ時間 7,693 ms
ジャッジサーバーID
(参考情報)
judge14 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
49,400 KB
testcase_01 AC 51 ms
49,400 KB
testcase_02 AC 74 ms
52,388 KB
testcase_03 AC 63 ms
51,244 KB
testcase_04 AC 60 ms
51,176 KB
testcase_05 AC 73 ms
51,900 KB
testcase_06 AC 49 ms
49,760 KB
testcase_07 AC 95 ms
56,888 KB
testcase_08 AC 49 ms
49,484 KB
testcase_09 AC 44 ms
49,528 KB
testcase_10 AC 89 ms
55,020 KB
testcase_11 AC 79 ms
54,364 KB
testcase_12 AC 71 ms
51,768 KB
testcase_13 AC 69 ms
52,168 KB
testcase_14 AC 49 ms
49,396 KB
testcase_15 AC 65 ms
52,116 KB
testcase_16 AC 74 ms
52,368 KB
testcase_17 AC 60 ms
51,564 KB
testcase_18 AC 104 ms
57,588 KB
testcase_19 AC 45 ms
49,308 KB
testcase_20 AC 74 ms
51,436 KB
testcase_21 AC 48 ms
49,500 KB
testcase_22 AC 67 ms
55,380 KB
testcase_23 AC 46 ms
49,832 KB
testcase_24 AC 45 ms
49,408 KB
testcase_25 AC 45 ms
49,356 KB
testcase_26 AC 45 ms
49,308 KB
testcase_27 AC 73 ms
52,792 KB
testcase_28 AC 46 ms
49,396 KB
testcase_29 AC 60 ms
51,388 KB
testcase_30 AC 46 ms
49,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    static ArrayList<Integer> times = new ArrayList<>();
    static ArrayList<Integer> values = new ArrayList<>();
    static int[][] dp;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int t = sc.nextInt();
        int n = sc.nextInt();
        int[] tmps = new int[n];
        for (int i = 0; i < n; i++) {
            tmps[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            while (x > 0) {
                times.add(tmps[i]);
                values.add(x);
                x /= 2;
            }
        }
        dp = new int[times.size()][t + 1];
        for (int[] arr : dp) {
            Arrays.fill(arr, -1);
        }
        System.out.println(dfw(times.size() - 1, t));
    }
    
    static int dfw(int idx, int v) {
        if (v < 0) {
            return Integer.MIN_VALUE;
        }
        if (idx < 0) {
            return 0;
        }
        if (dp[idx][v] < 0) {
            dp[idx][v] = Math.max(dfw(idx - 1, v), dfw(idx - 1, v - times.get(idx)) + values.get(idx));
        }
        return dp[idx][v];
    }
}
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