結果

問題 No.2386 Udon Coupon (Easy)
ユーザー tentententen
提出日時 2023-07-24 10:50:29
言語 Java21
(openjdk 21)
結果
AC  
実行時間 352 ms / 2,000 ms
コード長 2,083 bytes
コンパイル時間 3,105 ms
コンパイル使用メモリ 90,636 KB
実行使用メモリ 67,916 KB
最終ジャッジ日時 2024-04-08 12:48:45
合計ジャッジ時間 9,666 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
53,992 KB
testcase_01 AC 59 ms
53,952 KB
testcase_02 AC 61 ms
53,972 KB
testcase_03 AC 58 ms
53,972 KB
testcase_04 AC 59 ms
54,000 KB
testcase_05 AC 59 ms
53,984 KB
testcase_06 AC 60 ms
54,024 KB
testcase_07 AC 121 ms
67,900 KB
testcase_08 AC 60 ms
54,000 KB
testcase_09 AC 60 ms
53,972 KB
testcase_10 AC 83 ms
58,304 KB
testcase_11 AC 66 ms
54,896 KB
testcase_12 AC 109 ms
65,548 KB
testcase_13 AC 119 ms
67,744 KB
testcase_14 AC 352 ms
65,468 KB
testcase_15 AC 119 ms
67,916 KB
testcase_16 AC 108 ms
63,476 KB
testcase_17 AC 121 ms
65,492 KB
testcase_18 AC 90 ms
58,680 KB
testcase_19 AC 69 ms
54,528 KB
testcase_20 AC 95 ms
61,408 KB
testcase_21 AC 115 ms
65,860 KB
testcase_22 AC 82 ms
60,816 KB
testcase_23 AC 92 ms
60,856 KB
testcase_24 AC 69 ms
55,536 KB
testcase_25 AC 85 ms
61,332 KB
testcase_26 AC 239 ms
65,460 KB
testcase_27 AC 166 ms
67,764 KB
testcase_28 AC 79 ms
60,944 KB
testcase_29 AC 84 ms
58,580 KB
testcase_30 AC 63 ms
54,496 KB
testcase_31 AC 82 ms
60,868 KB
testcase_32 AC 64 ms
54,656 KB
testcase_33 AC 119 ms
67,740 KB
testcase_34 AC 85 ms
60,952 KB
testcase_35 AC 102 ms
63,604 KB
testcase_36 AC 118 ms
67,792 KB
testcase_37 AC 104 ms
65,708 KB
testcase_38 AC 85 ms
61,328 KB
testcase_39 AC 90 ms
58,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static int[] base = new int[]{3, 5, 10};
    static int[] values;
    static int[][] dp;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        values = new int[]{sc.nextInt(), sc.nextInt(), sc.nextInt()};
        dp = new int[3][n + 1];
        for (int[] arr : dp) {
            Arrays.fill(arr, -1);
        }
        System.out.println(dfw(2, n));
    }
    
    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, v - base[idx]) + values[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