結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー ei1333333ei1333333
提出日時 2016-07-08 23:16:18
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,141 bytes
コンパイル時間 1,356 ms
コンパイル使用メモリ 161,380 KB
実行使用メモリ 36,224 KB
最終ジャッジ日時 2024-04-21 07:57:47
合計ジャッジ時間 20,877 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 163 ms
34,560 KB
testcase_01 AC 176 ms
34,560 KB
testcase_02 AC 159 ms
34,432 KB
testcase_03 AC 165 ms
34,560 KB
testcase_04 AC 167 ms
34,560 KB
testcase_05 AC 155 ms
34,432 KB
testcase_06 AC 169 ms
34,560 KB
testcase_07 AC 184 ms
34,304 KB
testcase_08 AC 190 ms
34,560 KB
testcase_09 AC 200 ms
34,688 KB
testcase_10 AC 171 ms
34,688 KB
testcase_11 AC 165 ms
34,688 KB
testcase_12 AC 163 ms
34,560 KB
testcase_13 AC 174 ms
35,200 KB
testcase_14 AC 166 ms
34,688 KB
testcase_15 AC 165 ms
34,688 KB
testcase_16 AC 163 ms
34,560 KB
testcase_17 AC 159 ms
34,688 KB
testcase_18 AC 188 ms
35,840 KB
testcase_19 AC 159 ms
34,432 KB
testcase_20 AC 157 ms
34,560 KB
testcase_21 AC 165 ms
34,560 KB
testcase_22 AC 158 ms
34,560 KB
testcase_23 AC 161 ms
34,560 KB
testcase_24 AC 164 ms
34,560 KB
testcase_25 AC 156 ms
34,560 KB
testcase_26 AC 160 ms
34,560 KB
testcase_27 AC 170 ms
34,560 KB
testcase_28 AC 161 ms
34,432 KB
testcase_29 AC 168 ms
34,304 KB
testcase_30 AC 171 ms
34,432 KB
testcase_31 AC 160 ms
34,432 KB
testcase_32 AC 161 ms
34,560 KB
testcase_33 AC 166 ms
34,432 KB
testcase_34 AC 166 ms
34,560 KB
testcase_35 AC 163 ms
34,432 KB
testcase_36 AC 164 ms
34,560 KB
testcase_37 AC 161 ms
34,560 KB
testcase_38 AC 168 ms
34,304 KB
testcase_39 AC 161 ms
34,560 KB
testcase_40 AC 168 ms
34,560 KB
testcase_41 AC 160 ms
34,560 KB
testcase_42 AC 159 ms
34,560 KB
testcase_43 AC 163 ms
34,432 KB
testcase_44 AC 168 ms
34,304 KB
testcase_45 AC 161 ms
34,560 KB
testcase_46 AC 171 ms
34,432 KB
testcase_47 AC 170 ms
34,432 KB
testcase_48 AC 170 ms
34,560 KB
testcase_49 AC 199 ms
35,712 KB
testcase_50 AC 166 ms
34,560 KB
testcase_51 AC 177 ms
34,688 KB
testcase_52 AC 172 ms
34,816 KB
testcase_53 AC 171 ms
34,688 KB
testcase_54 AC 177 ms
34,688 KB
testcase_55 AC 176 ms
34,560 KB
testcase_56 AC 168 ms
34,688 KB
testcase_57 AC 197 ms
35,072 KB
testcase_58 AC 194 ms
35,712 KB
testcase_59 AC 195 ms
35,328 KB
testcase_60 AC 171 ms
34,944 KB
testcase_61 AC 205 ms
36,224 KB
testcase_62 AC 167 ms
34,816 KB
testcase_63 AC 189 ms
35,712 KB
testcase_64 AC 176 ms
34,688 KB
testcase_65 AC 166 ms
34,816 KB
testcase_66 AC 169 ms
34,944 KB
testcase_67 AC 173 ms
34,944 KB
testcase_68 AC 161 ms
34,688 KB
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
testcase_72 WA -
testcase_73 WA -
testcase_74 WA -
testcase_75 WA -
testcase_76 WA -
testcase_77 WA -
testcase_78 WA -
testcase_79 AC 150 ms
34,432 KB
testcase_80 AC 152 ms
34,432 KB
testcase_81 AC 160 ms
34,432 KB
testcase_82 AC 161 ms
34,432 KB
testcase_83 AC 153 ms
34,432 KB
testcase_84 AC 157 ms
34,432 KB
testcase_85 AC 149 ms
34,432 KB
testcase_86 AC 155 ms
34,560 KB
testcase_87 AC 161 ms
34,560 KB
testcase_88 AC 153 ms
34,432 KB
testcase_89 AC 164 ms
35,072 KB
testcase_90 AC 172 ms
35,200 KB
testcase_91 AC 185 ms
35,712 KB
testcase_92 AC 162 ms
34,816 KB
testcase_93 AC 176 ms
35,200 KB
testcase_94 AC 153 ms
34,432 KB
testcase_95 AC 181 ms
35,200 KB
testcase_96 AC 173 ms
35,200 KB
testcase_97 AC 178 ms
35,200 KB
testcase_98 AC 170 ms
34,816 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 = 2000000) : 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[1000000];
int main()
{
  scanf("%d", &M);
  while(~scanf("%d", &H[K])) ++K;
  int ALL = accumulate(H, H + K, 0);
  CombinationMod c(MOD);
  if(K == 1 && H[K] == 0) cout << 1 << endl;
  else if(M - ALL + 1 < K) cout << "NA" << endl;
  else cout << c.nCr(M - ALL + 1, K) << endl;
}
0