Submission #1366558
Source Code Expand
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <vector> #define REP(i, n) for(int i = 0; i < (int)(n); ++i) using namespace std; typedef long long ll; const int MOD = 1000000007; ll cmb[1010][1010]; long long inv(int a, int p) { return a==1 ? 1 : (1-p*inv(p%a,a))/a+p; } ll facmemo[1010]; ll fac(int n) { ll& res = facmemo[n]; if(res == 0) { res = 1; for(int i = 1; i <= n; ++i) { res = (res * i) % MOD; } } return res; } ll calc(int rest, int mini, int here) { ll x = inv(fac(here), MOD); REP(i, here) { x = (x * cmb[rest][mini]) % MOD; rest -= mini; } return x; } int A, B, C, D; ll memo[1010][1010]; int solve(int rest, int mini) { ll& res = memo[rest][mini]; if(res < 0) { if(rest == 0) { res = 1; } else if(mini > B) { res = 0; } else { res = solve(rest, mini+1); for(int here = C; here <= D && here*mini <= rest; ++here) { ll x = calc(rest, mini, here); // ここの割当方法 ll y = solve(rest-here*mini, mini+1); res = (res + x*y%MOD) % MOD; } } } return res; } int main(void) { int N; cin >> N >> A >> B >> C >> D; REP(i, 1010) { cmb[i][0] = 1; for(int j = 1; j <= i; ++j) { cmb[i][j] = (cmb[i-1][j-1] + cmb[i-1][j]) % MOD; } } memset(memo, -1, sizeof memo); ll res = solve(N, A); printf("%lld\n", res); return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Grouping |
User | ush |
Language | C++14 (GCC 5.4.1) |
Score | 600 |
Code Size | 1511 Byte |
Status | AC |
Exec Time | 1144 ms |
Memory | 16256 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 600 / 600 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt |
All | sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, subtask_1_many_01.txt, subtask_1_many_02.txt, subtask_1_many_03.txt, subtask_1_many_04.txt, subtask_1_max_01.txt, subtask_1_max_02.txt, subtask_1_min_01.txt, subtask_1_randa_01.txt, subtask_1_randa_02.txt, subtask_1_randb_01.txt, subtask_1_randb_02.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
sample_01.txt | AC | 7 ms | 16128 KB |
sample_02.txt | AC | 7 ms | 16128 KB |
sample_03.txt | AC | 1144 ms | 16256 KB |
sample_04.txt | AC | 7 ms | 16128 KB |
subtask_1_many_01.txt | AC | 1088 ms | 16128 KB |
subtask_1_many_02.txt | AC | 1054 ms | 16256 KB |
subtask_1_many_03.txt | AC | 1095 ms | 16256 KB |
subtask_1_many_04.txt | AC | 1107 ms | 16256 KB |
subtask_1_max_01.txt | AC | 7 ms | 16256 KB |
subtask_1_max_02.txt | AC | 7 ms | 16256 KB |
subtask_1_min_01.txt | AC | 7 ms | 16128 KB |
subtask_1_randa_01.txt | AC | 7 ms | 16256 KB |
subtask_1_randa_02.txt | AC | 7 ms | 16128 KB |
subtask_1_randb_01.txt | AC | 7 ms | 16256 KB |
subtask_1_randb_02.txt | AC | 7 ms | 16256 KB |