結果

問題 No.269 見栄っ張りの募金活動
ユーザー tentententen
提出日時 2023-06-13 15:15:09
言語 Java21
(openjdk 21)
結果
AC  
実行時間 117 ms / 5,000 ms
コード長 2,247 bytes
コンパイル時間 2,589 ms
コンパイル使用メモリ 85,932 KB
実行使用メモリ 61,540 KB
最終ジャッジ日時 2023-09-04 00:01:18
合計ジャッジ時間 6,314 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,448 KB
testcase_01 AC 44 ms
49,672 KB
testcase_02 AC 44 ms
49,476 KB
testcase_03 AC 58 ms
51,416 KB
testcase_04 AC 79 ms
54,296 KB
testcase_05 AC 45 ms
49,336 KB
testcase_06 AC 44 ms
49,396 KB
testcase_07 AC 117 ms
61,540 KB
testcase_08 AC 46 ms
49,492 KB
testcase_09 AC 45 ms
49,396 KB
testcase_10 AC 43 ms
47,848 KB
testcase_11 AC 62 ms
54,920 KB
testcase_12 AC 45 ms
49,428 KB
testcase_13 AC 63 ms
52,392 KB
testcase_14 AC 57 ms
54,608 KB
testcase_15 AC 63 ms
52,040 KB
testcase_16 AC 43 ms
49,540 KB
testcase_17 AC 44 ms
49,892 KB
testcase_18 AC 77 ms
53,860 KB
testcase_19 AC 61 ms
51,720 KB
testcase_20 AC 57 ms
52,008 KB
testcase_21 AC 56 ms
54,112 KB
testcase_22 AC 61 ms
52,052 KB
testcase_23 AC 48 ms
49,464 KB
testcase_24 AC 57 ms
52,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static final int MOD = 1000000007;
    static int[][] dp;
    static int n;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        n = sc.nextInt();
        int s = sc.nextInt();
        int k = sc.nextInt();
        for (int i = 1; i < n; i++) {
            s -= k * (n - i);
        }
        if (s < 0) {
            System.out.println(0);
            return;
        }
        dp = new int[n][s + 1];
        for (int[] arr : dp) {
            Arrays.fill(arr, -1);
        }
        System.out.println(dfw(n - 1, s));
    }
    
    static int dfw(int idx, int v) {
        if (v < 0) {
            return 0;
        }
        if (v == 0) {
            return 1;
        }
        if (idx < 0) {
            return 0;
        }
        if (dp[idx][v] < 0) {
            dp[idx][v] = (dfw(idx - 1, v) + dfw(idx, v - (n - idx))) % MOD;
        }
        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