結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー ei1333333ei1333333
提出日時 2016-07-08 23:21:04
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,188 ms / 2,000 ms
コード長 1,153 bytes
コンパイル時間 2,415 ms
コンパイル使用メモリ 147,268 KB
実行使用メモリ 160,920 KB
最終ジャッジ日時 2023-08-03 09:40:41
合計ジャッジ時間 111,500 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,043 ms
159,404 KB
testcase_01 AC 1,024 ms
159,300 KB
testcase_02 AC 1,048 ms
159,460 KB
testcase_03 AC 1,058 ms
159,392 KB
testcase_04 AC 1,078 ms
159,284 KB
testcase_05 AC 1,033 ms
159,528 KB
testcase_06 AC 1,060 ms
159,316 KB
testcase_07 AC 1,179 ms
159,320 KB
testcase_08 AC 1,058 ms
159,268 KB
testcase_09 AC 1,066 ms
159,460 KB
testcase_10 AC 1,058 ms
159,392 KB
testcase_11 AC 1,081 ms
159,868 KB
testcase_12 AC 1,069 ms
159,596 KB
testcase_13 AC 1,062 ms
160,120 KB
testcase_14 AC 1,062 ms
159,612 KB
testcase_15 AC 1,065 ms
159,600 KB
testcase_16 AC 1,066 ms
159,432 KB
testcase_17 AC 1,046 ms
159,364 KB
testcase_18 AC 1,068 ms
160,576 KB
testcase_19 AC 1,040 ms
159,456 KB
testcase_20 AC 1,057 ms
159,412 KB
testcase_21 AC 1,042 ms
159,460 KB
testcase_22 AC 1,045 ms
159,264 KB
testcase_23 AC 1,020 ms
159,368 KB
testcase_24 AC 1,053 ms
159,416 KB
testcase_25 AC 1,042 ms
159,264 KB
testcase_26 AC 1,074 ms
159,392 KB
testcase_27 AC 1,060 ms
159,360 KB
testcase_28 AC 1,084 ms
159,356 KB
testcase_29 AC 1,066 ms
159,320 KB
testcase_30 AC 1,065 ms
159,440 KB
testcase_31 AC 1,072 ms
159,440 KB
testcase_32 AC 1,074 ms
159,388 KB
testcase_33 AC 1,056 ms
159,440 KB
testcase_34 AC 1,068 ms
159,276 KB
testcase_35 AC 1,079 ms
159,416 KB
testcase_36 AC 1,071 ms
159,416 KB
testcase_37 AC 1,058 ms
159,388 KB
testcase_38 AC 1,057 ms
159,336 KB
testcase_39 AC 1,065 ms
159,200 KB
testcase_40 AC 1,083 ms
159,268 KB
testcase_41 AC 1,064 ms
159,452 KB
testcase_42 AC 1,065 ms
159,428 KB
testcase_43 AC 1,057 ms
159,436 KB
testcase_44 AC 1,077 ms
159,356 KB
testcase_45 AC 1,063 ms
159,384 KB
testcase_46 AC 1,062 ms
159,516 KB
testcase_47 AC 1,073 ms
159,328 KB
testcase_48 AC 1,088 ms
159,388 KB
testcase_49 AC 1,115 ms
160,776 KB
testcase_50 AC 1,061 ms
159,352 KB
testcase_51 AC 1,060 ms
159,396 KB
testcase_52 AC 1,068 ms
159,708 KB
testcase_53 AC 1,188 ms
159,648 KB
testcase_54 AC 1,069 ms
159,668 KB
testcase_55 AC 1,048 ms
159,520 KB
testcase_56 AC 1,074 ms
159,388 KB
testcase_57 AC 1,074 ms
159,944 KB
testcase_58 AC 1,098 ms
160,464 KB
testcase_59 AC 1,071 ms
160,108 KB
testcase_60 AC 1,061 ms
159,892 KB
testcase_61 AC 1,110 ms
160,920 KB
testcase_62 AC 1,070 ms
159,724 KB
testcase_63 AC 1,069 ms
160,324 KB
testcase_64 AC 1,031 ms
159,704 KB
testcase_65 AC 1,026 ms
159,616 KB
testcase_66 AC 1,000 ms
159,536 KB
testcase_67 AC 1,011 ms
159,788 KB
testcase_68 AC 1,031 ms
159,672 KB
testcase_69 AC 1,029 ms
159,340 KB
testcase_70 AC 1,041 ms
159,596 KB
testcase_71 AC 1,042 ms
159,340 KB
testcase_72 AC 1,017 ms
159,384 KB
testcase_73 AC 1,035 ms
159,444 KB
testcase_74 AC 1,032 ms
159,400 KB
testcase_75 AC 1,018 ms
159,400 KB
testcase_76 AC 1,008 ms
159,648 KB
testcase_77 AC 1,017 ms
159,432 KB
testcase_78 AC 1,014 ms
159,324 KB
testcase_79 AC 1,030 ms
159,428 KB
testcase_80 AC 1,046 ms
159,496 KB
testcase_81 AC 1,065 ms
159,256 KB
testcase_82 AC 1,053 ms
159,616 KB
testcase_83 AC 1,015 ms
159,340 KB
testcase_84 AC 1,022 ms
159,308 KB
testcase_85 AC 1,047 ms
159,240 KB
testcase_86 AC 1,054 ms
159,444 KB
testcase_87 AC 1,028 ms
159,500 KB
testcase_88 AC 1,077 ms
159,404 KB
testcase_89 AC 1,004 ms
159,892 KB
testcase_90 AC 1,028 ms
160,108 KB
testcase_91 AC 1,035 ms
160,432 KB
testcase_92 AC 1,015 ms
159,676 KB
testcase_93 AC 1,034 ms
160,220 KB
testcase_94 AC 990 ms
159,272 KB
testcase_95 AC 992 ms
160,128 KB
testcase_96 AC 983 ms
159,896 KB
testcase_97 AC 978 ms
159,836 KB
testcase_98 AC 988 ms
159,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
struct CombinationMod
{
  long long mod, size;
  vector< long long > fact;
  vector< long long > inv;
 
  void make_fact()
  {
    fact[0] = 1;
    for(int  i = 1; i < size; i++){
      fact[i] = fact[i-1] * i % mod;
    }
  }
 
  void make_inv()
  {
    inv[0] = inv[1] = 1;
    for(int i = 2; i < size; i++){
      inv[i] = inv[mod % i] * (mod - mod / i) % mod;
    }
    for(int i = 2; i < size; i++){
      inv[i] = inv[i-1] * inv[i] % mod;
    }
  }
  
  CombinationMod(int mod, int size = 10000000) : mod(mod), size(size+1)
  {
    fact.resize(size);
    inv.resize(size);
    make_fact();
    make_inv();
  }
  long long nCr(long long n, long long k)
  {
    if(k==0 || n==k) return 1;
    long long ret = fact[n] * inv[k] % mod * inv[n-k] % mod;
    return ret;
  }
};

int M, K;
int H[10000000];
int main()
{
  scanf("%d", &M);
  while(~scanf("%d", &H[K])) ++K;
  long long ALL = accumulate(H, H + K, 0LL);
  CombinationMod c(MOD);
  if(K == 1 && H[0] == 0) cout << 1 << endl;
  else if(M - ALL + 1 < K) cout << "NA" << endl;
  else cout << c.nCr(M - ALL + 1, K) << endl;
}
0