結果

問題 No.2329 Nafmo、イカサマをする
ユーザー tentententen
提出日時 2023-12-12 09:33:33
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,322 bytes
コンパイル時間 3,047 ms
コンパイル使用メモリ 85,292 KB
実行使用メモリ 363,080 KB
最終ジャッジ日時 2023-12-12 09:33:45
合計ジャッジ時間 12,790 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
60,768 KB
testcase_01 AC 58 ms
53,992 KB
testcase_02 AC 57 ms
53,996 KB
testcase_03 AC 55 ms
53,984 KB
testcase_04 AC 57 ms
53,996 KB
testcase_05 AC 61 ms
53,996 KB
testcase_06 AC 55 ms
54,000 KB
testcase_07 AC 55 ms
53,984 KB
testcase_08 AC 183 ms
65,552 KB
testcase_09 AC 55 ms
53,996 KB
testcase_10 AC 57 ms
53,992 KB
testcase_11 AC 58 ms
53,980 KB
testcase_12 AC 58 ms
53,980 KB
testcase_13 AC 59 ms
52,048 KB
testcase_14 AC 56 ms
53,980 KB
testcase_15 AC 57 ms
53,996 KB
testcase_16 AC 78 ms
54,516 KB
testcase_17 AC 55 ms
53,984 KB
testcase_18 AC 58 ms
53,976 KB
testcase_19 AC 327 ms
82,612 KB
testcase_20 AC 64 ms
54,260 KB
testcase_21 AC 92 ms
55,280 KB
testcase_22 AC 78 ms
55,272 KB
testcase_23 AC 59 ms
53,992 KB
testcase_24 AC 56 ms
53,992 KB
testcase_25 AC 84 ms
55,156 KB
testcase_26 AC 55 ms
53,980 KB
testcase_27 AC 58 ms
53,996 KB
testcase_28 AC 58 ms
53,992 KB
testcase_29 AC 822 ms
114,532 KB
testcase_30 AC 82 ms
54,644 KB
testcase_31 AC 56 ms
53,992 KB
testcase_32 AC 55 ms
54,000 KB
testcase_33 AC 59 ms
52,052 KB
testcase_34 AC 59 ms
53,996 KB
testcase_35 AC 99 ms
55,400 KB
testcase_36 TLE -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static ArrayList<ArrayList<HashMap<Long, Long>>> dp = new ArrayList<>();
    static int[] values;
    static long m;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        m = sc.nextLong();
        int k = sc.nextInt();
        values = new int[n];
        for (int i = 0; i < n; i++) {
            dp.add(new ArrayList<>());
            for (int j = 0; j < k; j++) {
                dp.get(i).add(new HashMap<>());
            }
            values[i] = sc.nextInt();
        }
        System.out.println(dfw(n - 1, k - 1, 0));
    }
    
    static long dfw(int idx, int v, long w) {
        if (w > m) {
            return Long.MIN_VALUE;
        }
        if (idx < 0 || v < 0) {
            return w;
        }
        if (!dp.get(idx).get(v).containsKey(w)) {
            dp.get(idx).get(v).put(w, Math.max(dfw(idx - 1, v, w), dfw(idx, v - 1, w + values[idx])));
        }
        return dp.get(idx).get(v).get(w);
    }
}
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