結果

問題 No.503 配列コレクション
ユーザー kimiyukikimiyuki
提出日時 2017-04-08 02:40:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 605 ms / 2,000 ms
コード長 1,218 bytes
コンパイル時間 421 ms
コンパイル使用メモリ 51,348 KB
実行使用メモリ 57,108 KB
最終ジャッジ日時 2023-09-23 03:36:51
合計ジャッジ時間 2,811 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,500 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 7 ms
4,556 KB
testcase_12 AC 105 ms
9,188 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 27 ms
16,816 KB
testcase_15 AC 605 ms
8,476 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 125 ms
10,540 KB
testcase_19 AC 25 ms
21,948 KB
testcase_20 AC 93 ms
57,108 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 67 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <vector>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
using ll = long long;
using namespace std;
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

const int mod = 1e9+7;
int solve(int n, int k, int d) {
    int r = 0; while (n >= k) { n -= k-1; r += 1; }
    if (d == 1) return n;
    auto dp  = vectors(n+1, r+1, 0);
    auto cnt = vectors(n+1, r+1, 0);
    dp[0][0] = 1;
    cnt[0][0] = 1;
    repeat (x,r) {
        dp[0][x+1] = dp[0][x] *(ll) d % mod;
        cnt[0][x+1] = 1;
    }
    repeat (y,n-1) {
        repeat (x,r+1) {
            ll acc = 0;
            ll cntacc = 0;
            repeat (z,x+1) {
                acc += dp[y][x-z] + cnt[y][x-z] *(ll) dp[0][z] % mod;
                cntacc += cnt[y][x-z];
            }
            dp[y+1][x] = acc % mod;
            cnt[y+1][x] = cntacc % mod;
        }
    }
    return dp[n-1][r];
}

int main() {
    int n, k, d; scanf("%d%d%d", &n, &k, &d);
    printf("%d\n", solve(n, k, d));
    return 0;
}
0