結果
| 問題 |
No.389 ロジックパズルの組み合わせ
|
| コンテスト | |
| ユーザー |
wing3196
|
| 提出日時 | 2016-07-08 22:59:53 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 712 bytes |
| コンパイル時間 | 1,414 ms |
| コンパイル使用メモリ | 159,316 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-13 06:26:22 |
| 合計ジャッジ時間 | 4,168 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 94 WA * 5 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000000 + 7;
int Factorial(int n)
{
int res = 1;
while (n) (res *= n--) %= MOD;
return res;
}
int Pow(int x, int n)
{
if (n == 0) return 1;
int res = Pow(x*x % MOD, n/2);
if (n&1) res *= x;
return res % MOD;
}
int Inverse(int n)
{
return Pow(n, MOD - 2);
}
int H(int ball, int stick)
{
return Factorial(ball + stick) * Inverse(Factorial(ball) * Factorial(stick) % MOD) % MOD;
}
int M;
signed main()
{
cin >> M;
int h, sum = 0, N = 0;
while (cin >> h)
{
sum += h;
N++;
}
if (sum + N - 1 > M)
{
puts("NA");
return 0;
}
int n = M - (sum + N - 1), k = N;
printf("%lld\n", H(n, k));
return 0;
}
wing3196