結果
問題 | No.389 ロジックパズルの組み合わせ |
ユーザー | tubo28 |
提出日時 | 2016-07-08 22:48:31 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 62 ms / 2,000 ms |
コード長 | 999 bytes |
コンパイル時間 | 1,596 ms |
コンパイル使用メモリ | 167,616 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-13 06:14:12 |
合計ジャッジ時間 | 4,343 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 99 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; #define int ll #define rep(i,n) for(int i = 0; i < (int)(n); ++i) #define all(c) begin(c), end(c) //#define fill(c,v) fill(decltype(v)*(begin(c)), decltype(v)*(end(c)), v) const ll mod = 1000000007; ll modpow(ll x, ll y, ll m){ if(y==0) return 1; ll res = modpow(x,y/2,m); return res * res % m * (y&1 ? x : 1) % m; } ll modinv(ll x, ll m){ return modpow(x, m-2, m); } decltype(0) main(){ int W; cin >> W; int x; int k = 0; int zero = 0; while(cin >> x){ W -= x; ++k; zero |= x == 0; } if(W+1 < k){ cout << "NA" << endl; } else if(k == 1 && zero){ cout << 1 << endl; } else { ll num = 1; ll den = 1; rep(i,k){ num *= W+1-i; den *= i+1; num %= mod; den %= mod; } num *= modinv(den, mod); num %= mod; cout << num << endl; } }