結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー ei1333333ei1333333
提出日時 2016-07-08 23:21:04
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,238 ms / 2,000 ms
コード長 1,153 bytes
コンパイル時間 1,489 ms
コンパイル使用メモリ 161,408 KB
実行使用メモリ 161,280 KB
最終ジャッジ日時 2024-04-21 08:18:26
合計ジャッジ時間 105,116 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,009 ms
159,580 KB
testcase_01 AC 988 ms
159,440 KB
testcase_02 AC 997 ms
159,472 KB
testcase_03 AC 995 ms
159,568 KB
testcase_04 AC 1,001 ms
159,488 KB
testcase_05 AC 993 ms
159,616 KB
testcase_06 AC 1,004 ms
159,572 KB
testcase_07 AC 999 ms
159,408 KB
testcase_08 AC 987 ms
159,412 KB
testcase_09 AC 996 ms
159,744 KB
testcase_10 AC 1,030 ms
159,616 KB
testcase_11 AC 1,019 ms
159,676 KB
testcase_12 AC 1,022 ms
159,708 KB
testcase_13 AC 990 ms
160,128 KB
testcase_14 AC 993 ms
159,828 KB
testcase_15 AC 982 ms
159,744 KB
testcase_16 AC 1,018 ms
159,736 KB
testcase_17 AC 997 ms
159,744 KB
testcase_18 AC 1,018 ms
160,768 KB
testcase_19 AC 992 ms
159,508 KB
testcase_20 AC 1,015 ms
159,608 KB
testcase_21 AC 999 ms
159,608 KB
testcase_22 AC 999 ms
159,504 KB
testcase_23 AC 1,023 ms
159,616 KB
testcase_24 AC 990 ms
159,488 KB
testcase_25 AC 1,003 ms
159,552 KB
testcase_26 AC 1,008 ms
159,616 KB
testcase_27 AC 1,012 ms
159,488 KB
testcase_28 AC 1,009 ms
159,412 KB
testcase_29 AC 1,015 ms
159,488 KB
testcase_30 AC 1,012 ms
159,572 KB
testcase_31 AC 1,013 ms
159,572 KB
testcase_32 AC 1,024 ms
159,500 KB
testcase_33 AC 1,006 ms
159,448 KB
testcase_34 AC 1,007 ms
159,476 KB
testcase_35 AC 1,054 ms
159,556 KB
testcase_36 AC 1,023 ms
159,488 KB
testcase_37 AC 1,029 ms
159,556 KB
testcase_38 AC 1,014 ms
159,508 KB
testcase_39 AC 1,008 ms
159,444 KB
testcase_40 AC 1,012 ms
159,612 KB
testcase_41 AC 1,016 ms
159,616 KB
testcase_42 AC 1,016 ms
159,528 KB
testcase_43 AC 999 ms
159,544 KB
testcase_44 AC 993 ms
159,576 KB
testcase_45 AC 999 ms
159,508 KB
testcase_46 AC 990 ms
159,488 KB
testcase_47 AC 986 ms
159,404 KB
testcase_48 AC 994 ms
159,560 KB
testcase_49 AC 998 ms
160,896 KB
testcase_50 AC 1,012 ms
159,616 KB
testcase_51 AC 1,043 ms
159,508 KB
testcase_52 AC 1,031 ms
159,744 KB
testcase_53 AC 995 ms
159,616 KB
testcase_54 AC 997 ms
159,744 KB
testcase_55 AC 987 ms
159,488 KB
testcase_56 AC 992 ms
159,700 KB
testcase_57 AC 1,013 ms
160,000 KB
testcase_58 AC 999 ms
160,640 KB
testcase_59 AC 993 ms
160,384 KB
testcase_60 AC 990 ms
159,872 KB
testcase_61 AC 1,040 ms
161,280 KB
testcase_62 AC 988 ms
159,992 KB
testcase_63 AC 1,002 ms
160,512 KB
testcase_64 AC 966 ms
159,856 KB
testcase_65 AC 992 ms
159,632 KB
testcase_66 AC 974 ms
159,872 KB
testcase_67 AC 997 ms
159,840 KB
testcase_68 AC 987 ms
159,744 KB
testcase_69 AC 1,004 ms
159,616 KB
testcase_70 AC 990 ms
159,616 KB
testcase_71 AC 1,009 ms
159,488 KB
testcase_72 AC 991 ms
159,488 KB
testcase_73 AC 964 ms
159,464 KB
testcase_74 AC 975 ms
159,556 KB
testcase_75 AC 987 ms
159,412 KB
testcase_76 AC 967 ms
159,532 KB
testcase_77 AC 967 ms
159,504 KB
testcase_78 AC 968 ms
159,744 KB
testcase_79 AC 972 ms
159,448 KB
testcase_80 AC 976 ms
159,460 KB
testcase_81 AC 1,067 ms
159,616 KB
testcase_82 AC 1,041 ms
159,488 KB
testcase_83 AC 1,141 ms
159,608 KB
testcase_84 AC 1,136 ms
159,612 KB
testcase_85 AC 995 ms
159,472 KB
testcase_86 AC 985 ms
159,488 KB
testcase_87 AC 1,031 ms
159,476 KB
testcase_88 AC 996 ms
159,604 KB
testcase_89 AC 1,021 ms
159,964 KB
testcase_90 AC 1,021 ms
160,256 KB
testcase_91 AC 1,011 ms
160,896 KB
testcase_92 AC 1,011 ms
159,744 KB
testcase_93 AC 1,008 ms
160,256 KB
testcase_94 AC 1,003 ms
159,488 KB
testcase_95 AC 1,013 ms
160,320 KB
testcase_96 AC 1,082 ms
160,128 KB
testcase_97 AC 1,008 ms
160,060 KB
testcase_98 AC 1,238 ms
159,724 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:48:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   48 |   scanf("%d", &M);
      |   ~~~~~^~~~~~~~~~

ソースコード

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