結果

問題 No.1011 Infinite Stairs
ユーザー noriocnorioc
提出日時 2020-03-20 23:51:00
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 273 ms / 2,000 ms
コード長 1,191 bytes
コンパイル時間 3,040 ms
コンパイル使用メモリ 161,172 KB
実行使用メモリ 109,820 KB
最終ジャッジ日時 2023-09-04 06:23:21
合計ジャッジ時間 5,648 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 6 ms
6,552 KB
testcase_03 AC 181 ms
73,560 KB
testcase_04 AC 35 ms
15,528 KB
testcase_05 AC 273 ms
109,820 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 4 ms
4,576 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 39 ms
18,992 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 24 ms
12,352 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 32 ms
15,432 KB
testcase_16 AC 127 ms
52,900 KB
testcase_17 AC 13 ms
7,952 KB
testcase_18 AC 74 ms
32,152 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 32 ms
15,252 KB
testcase_22 AC 62 ms
27,320 KB
testcase_23 AC 38 ms
18,604 KB
testcase_24 AC 41 ms
20,092 KB
testcase_25 AC 64 ms
29,328 KB
testcase_26 AC 15 ms
9,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

int tle(int n, int d, int k) {
    const MOD = 10^^9 + 7;

    auto dp = new int[][](n + 1, k + 1);
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < k; j++) {
            for (int m = 1; m <= d; m++) {
                if (j + m > k) break;

                dp[i][j+m] = (dp[i][j+m] + dp[i-1][j]) % MOD;
            }
        }
    }
    return dp[n][k];
}

int calc(int n, int d, int k) {
    const MOD = 10^^9 + 7;

    auto dp = new int[][](n + 1, k + 1);
    dp[0][0] = 1;

    auto acc = new int[k + 1];
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= k; j++) {
            acc[j] = (acc[j-1] + dp[i-1][j-1]) % MOD;
        }

        for (int j = 1; j <= k; j++) {
            dp[i][j] += acc[j] - acc[max(j - d, 0)];
            dp[i][j] %= MOD;
        }
    }
    return (dp[n][k] + MOD) % MOD;
}

void main() {
    int n, d, k; scan(n, d, k);
    writeln(calc(n, d, k));
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;
0