結果
問題 | No.389 ロジックパズルの組み合わせ |
ユーザー |
![]() |
提出日時 | 2016-07-08 22:39:55 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 379 ms / 2,000 ms |
コード長 | 1,614 bytes |
コンパイル時間 | 896 ms |
コンパイル使用メモリ | 98,576 KB |
実行使用メモリ | 36,568 KB |
最終ジャッジ日時 | 2024-10-13 04:41:31 |
合計ジャッジ時間 | 38,143 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 99 |
ソースコード
#include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> //#include<cctype> #include<climits> #include<iostream> #include<string> #include<vector> #include<map> //#include<list> #include<queue> #include<deque> #include<algorithm> //#include<numeric> #include<utility> //#include<memory> #include<functional> #include<cassert> #include<set> #include<stack> #include<random> const int dx[] = {1, 0, -1, 0}; const int dy[] = {0, -1, 0, 1}; using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<int, int> pii; ll mod_pow(ll x, ll p, ll MOD) { ll a = 1; while (p) { if (p%2) a = a*x%MOD; x = x*x%MOD; p/=2; } return a; } // mod_inverse ll mod_inverse(ll a, ll m) { return mod_pow(a, m-2, m); } const int MAXM = 1001000; const int MOD = 1e9+7; int H[MAXM]; ll fact[2*MAXM], rfact[2*MAXM]; int M, K; ll nCr(int n, int r) { ll ret = fact[n]; (ret *= rfact[r]) %= MOD; (ret *= rfact[n-r]) %= MOD; return ret; } int main() { cin.tie(0); ios::sync_with_stdio(false); fact[0] = rfact[0] = 1; for (int i = 1; i < 2*MAXM; i++) { fact[i] = (fact[i-1]*i)%MOD; rfact[i] = mod_inverse(fact[i], MOD); } cin >> M; int sum = 0; while (cin >> H[K]) { sum += H[K++]; } int rest = M-sum; rest -= K-1; if (rest < 0) { cout << "NA" << endl; return 0; } if (K == 1 && H[0] == 0) { cout << 1 << endl; return 0; } cout << nCr(rest+K, K) << endl; return 0; }