結果

問題 No.269 見栄っ張りの募金活動
ユーザー nebukuro09nebukuro09
提出日時 2016-12-28 20:57:42
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 23 ms / 5,000 ms
コード長 876 bytes
コンパイル時間 591 ms
コンパイル使用メモリ 91,660 KB
実行使用メモリ 19,996 KB
最終ジャッジ日時 2023-09-03 00:17:45
合計ジャッジ時間 1,754 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 4 ms
4,380 KB
testcase_04 AC 11 ms
9,180 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 23 ms
19,996 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 12 ms
11,008 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 4 ms
4,380 KB
testcase_12 AC 9 ms
8,696 KB
testcase_13 AC 4 ms
5,304 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 9 ms
9,184 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 15 ms
13,064 KB
testcase_19 AC 5 ms
5,412 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;


void main() {
    immutable long MOD = 10^^9+7;

    int N, S, K;
    scanf("%d %d %d", &N, &S, &K);

    auto dp = new long[][](N, S+1);
    foreach (i; 0..N) foreach (j; 0..S+1) dp[i][j] = 0;

    foreach (i; 0..S+1) {
        auto s = N * i;
        if (s > S)
            break;
        dp[0][s] = 1;
    }

    foreach (i; 1..N) {
        foreach (j; 0..S+1) {
            auto plus_k = j - (N-i)*K;
            auto plus_one = j - (N-i);
            if (plus_k >= 0 && plus_k <= S)
                dp[i][j] += dp[i-1][plus_k];
            if (plus_one >= 0 && plus_one <= S)
                (dp[i][j] += dp[i][plus_one]) %= MOD;
        }
    }

    dp[N-1][S].writeln;
}
0