結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー a
提出日時 2016-07-08 23:23:31
言語 C++14
(gcc 8.2.0)
結果
AC  
実行時間 53 ms
コード長 925 Byte
コンパイル時間 445 ms
使用メモリ 4,996 KB
最終ジャッジ日時 2019-07-10 04:27:41

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
test01.txt AC 3 ms
1,544 KB
test02.txt AC 3 ms
1,512 KB
test03.txt AC 2 ms
1,544 KB
test04.txt AC 3 ms
1,524 KB
test05.txt AC 9 ms
1,556 KB
test06.txt AC 3 ms
1,512 KB
test07.txt AC 3 ms
1,512 KB
test08.txt AC 3 ms
1,508 KB
test09.txt AC 3 ms
1,508 KB
test10.txt AC 14 ms
1,824 KB
test11.txt AC 8 ms
1,776 KB
test12.txt AC 16 ms
1,892 KB
test13.txt AC 7 ms
1,768 KB
test14.txt AC 24 ms
2,908 KB
test15.txt AC 11 ms
1,904 KB
test16.txt AC 6 ms
1,720 KB
test17.txt AC 9 ms
1,772 KB
test18.txt AC 15 ms
1,868 KB
test19.txt AC 42 ms
3,940 KB
test20.txt AC 3 ms
1,560 KB
test21.txt AC 3 ms
1,552 KB
test22.txt AC 3 ms
1,552 KB
test23.txt AC 2 ms
1,556 KB
test24.txt AC 2 ms
1,540 KB
test25.txt AC 3 ms
1,552 KB
test26.txt AC 3 ms
1,560 KB
test27.txt AC 3 ms
1,556 KB
test28.txt AC 3 ms
1,564 KB
test29.txt AC 3 ms
1,552 KB
test30.txt AC 3 ms
1,552 KB
test31.txt AC 3 ms
1,544 KB
test32.txt AC 3 ms
1,552 KB
test33.txt AC 2 ms
1,552 KB
test34.txt AC 3 ms
1,544 KB
test35.txt AC 3 ms
1,556 KB
test36.txt AC 2 ms
1,560 KB
test37.txt AC 3 ms
1,548 KB
test38.txt AC 3 ms
1,552 KB
test39.txt AC 3 ms
1,552 KB
test40.txt AC 3 ms
1,560 KB
test41.txt AC 2 ms
1,548 KB
test42.txt AC 3 ms
1,548 KB
test43.txt AC 3 ms
1,556 KB
test44.txt AC 3 ms
1,552 KB
test45.txt AC 2 ms
1,544 KB
test46.txt AC 3 ms
1,540 KB
test47.txt AC 2 ms
1,552 KB
test48.txt AC 3 ms
1,552 KB
test49.txt AC 3 ms
1,552 KB
test50.txt AC 40 ms
4,204 KB
test51.txt AC 6 ms
1,708 KB
test52.txt AC 4 ms
1,696 KB
test53.txt AC 12 ms
2,000 KB
test54.txt AC 6 ms
1,764 KB
test55.txt AC 13 ms
2,068 KB
test56.txt AC 4 ms
1,560 KB
test57.txt AC 6 ms
1,736 KB
test58.txt AC 20 ms
2,644 KB
test59.txt AC 34 ms
3,676 KB
test60.txt AC 26 ms
3,172 KB
test61.txt AC 14 ms
2,264 KB
test62.txt AC 53 ms
4,996 KB
test63.txt AC 14 ms
2,260 KB
test64.txt AC 37 ms
3,680 KB
test65.txt AC 13 ms
2,052 KB
test66.txt AC 8 ms
1,832 KB
test67.txt AC 13 ms
2,260 KB
test68.txt AC 13 ms
2,080 KB
test69.txt AC 13 ms
2,260 KB
test70.txt AC 7 ms
1,544 KB
test71.txt AC 5 ms
1,540 KB
test72.txt AC 6 ms
1,544 KB
test73.txt AC 5 ms
1,540 KB
test74.txt AC 4 ms
1,540 KB
test75.txt AC 6 ms
1,540 KB
test76.txt AC 6 ms
1,544 KB
test77.txt AC 4 ms
1,540 KB
test78.txt AC 8 ms
1,544 KB
test79.txt AC 3 ms
1,544 KB
test80.txt AC 3 ms
1,540 KB
test81.txt AC 2 ms
1,544 KB
test82.txt AC 3 ms
1,544 KB
test83.txt AC 3 ms
1,540 KB
test84.txt AC 3 ms
1,544 KB
test85.txt AC 3 ms
1,540 KB
test86.txt AC 2 ms
1,540 KB
test87.txt AC 3 ms
1,540 KB
test88.txt AC 3 ms
1,544 KB
test89.txt AC 3 ms
1,544 KB
test90.txt AC 17 ms
2,288 KB
test91.txt AC 26 ms
2,912 KB
test92.txt AC 43 ms
3,940 KB
test93.txt AC 9 ms
1,864 KB
test94.txt AC 28 ms
3,172 KB
test95.txt AC 4 ms
1,600 KB
test96.txt AC 29 ms
3,176 KB
test97.txt AC 23 ms
2,904 KB
test98.txt AC 22 ms
2,644 KB
test99.txt AC 14 ms
2,264 KB
テストケース一括ダウンロード

ソースコード

diff #
#include <cstdio>
#include <string>
#include <iostream>
#include <sstream>
#include <cstdlib>

using namespace std;

typedef long long ll;

const ll mod = 1e9+7;

int m;
int h[1111111], s=0;

ll modpow(ll a, ll b) {
  if (b == 0) return 1;
  ll ret = modpow(a*a%mod, b/2);
  if (b%2 == 1) ret = (ret*a)%mod;
  return ret;
}

ll C(ll n, ll k) {
  ll p = 1, q = 1;
  for (int i = n; i >= 1; i--) p = (p*i)%mod;
  for (int i = k; i >= 1; i--) q = (q*i)%mod;
  for (int i = n-k; i >= 1; i--) q = (q*i)%mod;
  return (p * modpow(q, mod-2))%mod;
}

int main(void) {
  cin >> m;
  string buf;
  getchar();
  getline(cin, buf);
  stringstream ss(buf);
  int a;
  int sum = 0;
  while (ss >> a) {
    h[s++] = a;
    sum += a;
    if (s > 1) sum += 1;
  }
  m -= sum;
  if (m < 0) {
    puts("NA");
  } else if (h[0] == 0) {
    puts("1");
  } else {
    // printf("%d %d %d\n", s, sum, m);
    printf("%lld\n", C(s+1+m-1, m));
  }
}
0