結果
| 問題 |
No.389 ロジックパズルの組み合わせ
|
| コンテスト | |
| ユーザー |
h_noson
|
| 提出日時 | 2016-07-08 22:53:24 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,112 bytes |
| コンパイル時間 | 593 ms |
| コンパイル使用メモリ | 65,364 KB |
| 実行使用メモリ | 19,080 KB |
| 最終ジャッジ日時 | 2024-10-13 06:19:41 |
| 合計ジャッジ時間 | 7,160 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | TLE * 1 -- * 98 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:37:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
37 | scanf("%d",&m);
| ~~~~~^~~~~~~~~
ソースコード
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
#define REP(i,s,e) for (i = s; i <= e; i++)
#define rep(i,n) REP (i,0,(int)(n)-1)
#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP (i,(int)(n)-1,0)
const int INF = 1e8;
const int MOD = 1e9+7;
typedef long long ll;
int h[500000];
ll frac[1000001];
int modinv(ll x) {
int n = MOD-2;
ll ret = 1;
while (n) {
if (n%2) {
ret *= x;
ret %= MOD;
}
x *= x;
x %= MOD;
n /= 2;
}
return ret;
}
int main(void) {
int i, m, n;
scanf("%d",&m);
n = 0;
while (scanf("%d",&h[n++]));
n--;
frac[0] = 1;
rep (i,1000000) frac[i+1] = frac[i] * (i+1) % MOD;
m -= n - 1;
rep (i,n) if (h[i] > 0)
m -= h[i] - 1;
cout << n << " " << m << endl;
int ans;
if (m < n) {
cout << "NA" << endl;
return 0;
}
if (h[0] != 0)
ans = frac[m] * modinv(frac[n]) % MOD * modinv(frac[m-n]) % MOD;
else
ans = 1;
cout << ans << endl;
return 0;
}
h_noson