結果
| 問題 | No.389 ロジックパズルの組み合わせ |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-06-18 14:29:39 |
| 言語 | C++11(old_compat) (gcc 12.4.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 44 ms / 2,000 ms |
| コード長 | 1,133 bytes |
| 記録 | |
| コンパイル時間 | 1,369 ms |
| コンパイル使用メモリ | 176,328 KB |
| 実行使用メモリ | 9,332 KB |
| 最終ジャッジ日時 | 2026-03-08 01:31:24 |
| 合計ジャッジ時間 | 4,542 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 99 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:38:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
38 | i64 m; scanf("%lld", &m);
| ~~~~~^~~~~~~~~~~~
ソースコード
#include <iostream>
#include <algorithm>
#include <tuple>
using namespace std;
using i64 = long long;
constexpr i64 mod = i64(powl(10, 9)) + 7;
tuple<i64, i64, i64> extgcd(i64 x, i64 y) {
if(y == 0) { return make_tuple(1, 0, x); }
i64 a, b, d; tie(a, b, d) = extgcd(y, x%y);
return make_tuple(b, a-x/y*b, d);
}
i64 mod_inv(const i64 &a, const i64 &m) {
i64 x, _, d; tie(x, _, d) = extgcd(a, m);
if(d == 1) { return (x % m + m) % m; }
throw;
}
i64 nCr(i64 n, i64 r, i64 mod) {
vector<i64> fact(n+1, 1);
for(i64 i=2; i<=n; ++i) {
fact[i] = fact[i-1] * i;
fact[i] %= mod;
}
i64 inv1 = mod_inv(fact[r], mod),
inv2 = mod_inv(fact[n-r], mod);
i64 res = fact[n];
res *= inv1;
res %= mod;
res *= inv2;
res %= mod;
return res;
}
int main(void) {
i64 m; scanf("%lld", &m);
vector<i64> a;
for(i64 x; ~scanf("%lld", &x); a.push_back(x)) ;
i64 n = a.size();
i64 acc = accumulate(begin(a), end(a), 0);
if(a[0] == 0) {
puts("1");
return 0;
}
if(acc + n - 1 > m) {
puts("NA");
return 0;
}
i64 res = nCr(m-acc+1, n, mod);
printf("%lld\n", res);
return 0;
}