結果

問題 No.269 見栄っ張りの募金活動
ユーザー tentententen
提出日時 2023-04-04 14:23:57
言語 Java21
(openjdk 21)
結果
AC  
実行時間 118 ms / 5,000 ms
コード長 2,193 bytes
コンパイル時間 2,695 ms
コンパイル使用メモリ 90,632 KB
実行使用メモリ 65,376 KB
最終ジャッジ日時 2024-04-08 14:02:35
合計ジャッジ時間 5,710 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
53,988 KB
testcase_01 AC 52 ms
53,984 KB
testcase_02 AC 53 ms
53,960 KB
testcase_03 AC 63 ms
54,116 KB
testcase_04 AC 82 ms
58,116 KB
testcase_05 AC 59 ms
54,028 KB
testcase_06 AC 56 ms
53,972 KB
testcase_07 AC 118 ms
65,376 KB
testcase_08 AC 55 ms
53,988 KB
testcase_09 AC 54 ms
53,948 KB
testcase_10 AC 53 ms
54,004 KB
testcase_11 AC 83 ms
58,688 KB
testcase_12 AC 59 ms
53,988 KB
testcase_13 AC 77 ms
56,296 KB
testcase_14 AC 65 ms
57,636 KB
testcase_15 AC 82 ms
56,160 KB
testcase_16 AC 55 ms
53,952 KB
testcase_17 AC 57 ms
53,968 KB
testcase_18 AC 93 ms
58,004 KB
testcase_19 AC 82 ms
55,516 KB
testcase_20 AC 63 ms
54,776 KB
testcase_21 AC 63 ms
57,640 KB
testcase_22 AC 79 ms
55,528 KB
testcase_23 AC 58 ms
54,116 KB
testcase_24 AC 67 ms
55,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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