結果

問題 No.2329 Nafmo、イカサマをする
ユーザー tentententen
提出日時 2023-05-30 15:08:48
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,358 bytes
コンパイル時間 2,613 ms
コンパイル使用メモリ 82,932 KB
実行使用メモリ 374,304 KB
最終ジャッジ日時 2023-08-28 00:38:29
合計ジャッジ時間 10,482 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
374,304 KB
testcase_01 AC 45 ms
49,396 KB
testcase_02 AC 44 ms
49,216 KB
testcase_03 AC 45 ms
49,384 KB
testcase_04 AC 45 ms
49,448 KB
testcase_05 AC 45 ms
49,292 KB
testcase_06 AC 44 ms
49,388 KB
testcase_07 AC 45 ms
49,216 KB
testcase_08 AC 178 ms
65,676 KB
testcase_09 AC 46 ms
49,516 KB
testcase_10 AC 45 ms
49,352 KB
testcase_11 AC 49 ms
51,340 KB
testcase_12 AC 47 ms
49,452 KB
testcase_13 AC 52 ms
50,224 KB
testcase_14 AC 45 ms
49,492 KB
testcase_15 AC 45 ms
49,384 KB
testcase_16 AC 62 ms
51,732 KB
testcase_17 AC 45 ms
49,276 KB
testcase_18 AC 47 ms
49,416 KB
testcase_19 AC 379 ms
84,776 KB
testcase_20 AC 57 ms
50,140 KB
testcase_21 AC 69 ms
51,836 KB
testcase_22 AC 65 ms
51,416 KB
testcase_23 AC 53 ms
50,152 KB
testcase_24 AC 47 ms
49,324 KB
testcase_25 AC 64 ms
51,804 KB
testcase_26 AC 46 ms
49,316 KB
testcase_27 AC 50 ms
50,156 KB
testcase_28 AC 50 ms
49,488 KB
testcase_29 AC 500 ms
102,692 KB
testcase_30 AC 63 ms
51,728 KB
testcase_31 AC 45 ms
49,464 KB
testcase_32 AC 45 ms
49,488 KB
testcase_33 AC 50 ms
49,264 KB
testcase_34 AC 50 ms
50,248 KB
testcase_35 AC 80 ms
52,240 KB
testcase_36 TLE -
testcase_37 AC 138 ms
53,428 KB
testcase_38 AC 81 ms
52,384 KB
testcase_39 TLE -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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