結果
| 問題 |
No.389 ロジックパズルの組み合わせ
|
| コンテスト | |
| ユーザー |
treeone
|
| 提出日時 | 2016-07-09 19:59:49 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 966 bytes |
| コンパイル時間 | 2,128 ms |
| コンパイル使用メモリ | 160,104 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-13 09:40:18 |
| 合計ジャッジ時間 | 4,816 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 86 WA * 13 |
ソースコード
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repp(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1e9 + 7;
int n;
typedef long long ll;
ll mod_pow(ll x,ll n){
if(n==0) return 1;
ll res=mod_pow(x*x%mod,n/2);
if(n&1) res=res*x%mod;
return res;
}
ll fact[2000010];
ll get_nCk(ll n,ll k,ll mpd){
fact[0]=1;
for(int i=1;i<200010;i++) fact[i]=fact[i-1]*i%mod;
return fact[n]*mod_pow(fact[k],mod-2)%mod*mod_pow(fact[n-k],mod-2)%mod;
}
signed main(){
cin >> n;
vector<int> h;
int a, sum = 0, cnt = 0;
while(cin >> a){
sum += a;
cnt++;
}
int ans = 0;
int r = n - (sum + cnt - 1);
if(sum == 0) cout << 1 << endl;
else if(r < 0) cout << "NA" << endl;
else{
ans = get_nCk(r + cnt, cnt, mod);
cout << ans << endl;
}
}
treeone