結果
問題 | No.1474 かさまJ |
ユーザー | gorugo30 |
提出日時 | 2021-03-02 17:19:06 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 339 ms / 2,500 ms |
コード長 | 2,067 bytes |
コンパイル時間 | 7,856 ms |
コンパイル使用メモリ | 294,836 KB |
実行使用メモリ | 10,496 KB |
最終ジャッジ日時 | 2024-04-14 04:44:38 |
合計ジャッジ時間 | 11,029 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 3 ms
6,816 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 263 ms
8,064 KB |
testcase_06 | AC | 21 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | AC | 3 ms
6,940 KB |
testcase_09 | AC | 339 ms
8,192 KB |
testcase_10 | AC | 35 ms
6,944 KB |
testcase_11 | AC | 11 ms
6,940 KB |
testcase_12 | AC | 7 ms
6,940 KB |
testcase_13 | AC | 228 ms
8,704 KB |
testcase_14 | AC | 107 ms
6,944 KB |
testcase_15 | AC | 36 ms
6,944 KB |
testcase_16 | AC | 37 ms
6,940 KB |
testcase_17 | AC | 139 ms
6,944 KB |
testcase_18 | AC | 260 ms
9,856 KB |
testcase_19 | AC | 299 ms
10,496 KB |
testcase_20 | AC | 316 ms
10,496 KB |
ソースコード
#include <bits/stdc++.h> #include "testlib.h" using namespace std; #define MOD 1000000007 const int MIN_N = 1; const int MAX_N = 40; const int MIN_MP = 1; const int MAX_MP = 20000; const int MIN_Mq = 0; const int MAX_Mq = 20000; const int MIN_L = 1; const int MAX_L = 10000; const int MIN_S = 0; const int MAX_S = MAX_L - 1; vector<long> fac(50000, 1); long modpow(long x, long p, long mod){ long ret = 1; while (p > 0){ if (p & 1) ret = (ret * x) % mod; x = (x * x) % mod; p >>= 1; } return ret; } long nCr(long n, long r){ if (n < r) return 0; return (((fac[n] * modpow(fac[n - r], MOD - 2, MOD)) % MOD) * modpow(fac[r], MOD - 2, MOD)) % MOD; } int main(int argc, char *argv[]){ registerValidation(argc, argv); int N = inf.readInt(MIN_N, MAX_N, "N"); inf.readSpace(); int MP = inf.readInt(MIN_MP, MAX_MP, "MP"); inf.readSpace(); int Mq = inf.readInt(MIN_Mq, MAX_Mq, "Mq"); inf.readSpace(); int L = inf.readInt(MIN_L, MAX_L, "L"); inf.readEoln(); vector<int> S(N); for (int i = 0; i < N; i++){ if (i != 0){ inf.readSpace(); } S[i] = inf.readInt(MIN_S, L - 1, "S[i]"); } inf.readEoln(); inf.readEof(); vector<vector<long>> dp(N + 1, vector<long>(Mq + 1, 0)); dp[0][Mq] = 1; for (int i = 1; i <= min(S[0], Mq); i++){ dp[1][Mq - i] = 1; } for (int i = 1; i < N; i++){ for (int k = N; k >= 1; k--){ long sum = 0; for (int r = Mq; r >= 0; r--){ dp[k][r] = (dp[k][r] + sum) % MOD; sum = (sum + dp[k - 1][r]) % MOD; if (r + S[i] <= Mq) sum = (sum - dp[k - 1][r + S[i]] + MOD) % MOD; } } } for (int i = 1; i < 50000; i++){ fac[i] = (fac[i - 1] * i) % MOD; } long ans = 0; for (int m = 0; m <= Mq; m++){ for (int x = 0; x <= N; x++){ ans = (ans + dp[x][Mq - m] * nCr(MP + m - L * x + N - 1, N - 1)) % MOD; } } cout << ans << endl; }