結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー amesyuamesyu
提出日時 2020-06-20 10:59:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 632 ms / 2,000 ms
コード長 1,060 bytes
コンパイル時間 665 ms
コンパイル使用メモリ 75,472 KB
実行使用メモリ 238,032 KB
最終ジャッジ日時 2023-09-16 17:17:14
合計ジャッジ時間 60,748 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 563 ms
237,980 KB
testcase_01 AC 564 ms
237,712 KB
testcase_02 AC 562 ms
237,704 KB
testcase_03 AC 556 ms
237,980 KB
testcase_04 AC 557 ms
237,788 KB
testcase_05 AC 547 ms
237,932 KB
testcase_06 AC 567 ms
237,752 KB
testcase_07 AC 565 ms
237,704 KB
testcase_08 AC 533 ms
237,980 KB
testcase_09 AC 554 ms
237,896 KB
testcase_10 AC 558 ms
237,748 KB
testcase_11 AC 563 ms
237,696 KB
testcase_12 AC 559 ms
237,692 KB
testcase_13 AC 570 ms
237,844 KB
testcase_14 AC 568 ms
237,712 KB
testcase_15 AC 551 ms
237,708 KB
testcase_16 AC 560 ms
237,708 KB
testcase_17 AC 563 ms
238,032 KB
testcase_18 AC 603 ms
237,812 KB
testcase_19 AC 542 ms
237,708 KB
testcase_20 AC 550 ms
237,836 KB
testcase_21 AC 557 ms
237,784 KB
testcase_22 AC 569 ms
237,780 KB
testcase_23 AC 569 ms
237,820 KB
testcase_24 AC 556 ms
238,028 KB
testcase_25 AC 547 ms
237,812 KB
testcase_26 AC 556 ms
237,692 KB
testcase_27 AC 544 ms
237,708 KB
testcase_28 AC 555 ms
237,700 KB
testcase_29 AC 551 ms
237,712 KB
testcase_30 AC 557 ms
237,756 KB
testcase_31 AC 569 ms
238,028 KB
testcase_32 AC 550 ms
237,732 KB
testcase_33 AC 542 ms
237,748 KB
testcase_34 AC 549 ms
237,700 KB
testcase_35 AC 559 ms
237,752 KB
testcase_36 AC 566 ms
237,764 KB
testcase_37 AC 540 ms
237,820 KB
testcase_38 AC 555 ms
237,752 KB
testcase_39 AC 552 ms
237,700 KB
testcase_40 AC 569 ms
237,696 KB
testcase_41 AC 558 ms
237,760 KB
testcase_42 AC 554 ms
237,716 KB
testcase_43 AC 566 ms
237,712 KB
testcase_44 AC 547 ms
237,896 KB
testcase_45 AC 544 ms
237,980 KB
testcase_46 AC 569 ms
237,980 KB
testcase_47 AC 582 ms
237,756 KB
testcase_48 AC 573 ms
237,980 KB
testcase_49 AC 619 ms
237,784 KB
testcase_50 AC 580 ms
237,688 KB
testcase_51 AC 581 ms
237,732 KB
testcase_52 AC 577 ms
237,780 KB
testcase_53 AC 577 ms
237,784 KB
testcase_54 AC 565 ms
237,692 KB
testcase_55 AC 591 ms
237,700 KB
testcase_56 AC 575 ms
237,780 KB
testcase_57 AC 586 ms
237,896 KB
testcase_58 AC 591 ms
237,892 KB
testcase_59 AC 602 ms
237,704 KB
testcase_60 AC 595 ms
237,704 KB
testcase_61 AC 632 ms
237,712 KB
testcase_62 AC 594 ms
237,840 KB
testcase_63 AC 624 ms
237,708 KB
testcase_64 AC 593 ms
237,740 KB
testcase_65 AC 573 ms
237,820 KB
testcase_66 AC 595 ms
237,844 KB
testcase_67 AC 573 ms
237,896 KB
testcase_68 AC 583 ms
237,748 KB
testcase_69 AC 564 ms
237,764 KB
testcase_70 AC 541 ms
238,032 KB
testcase_71 AC 548 ms
237,740 KB
testcase_72 AC 550 ms
237,760 KB
testcase_73 AC 547 ms
237,836 KB
testcase_74 AC 559 ms
237,892 KB
testcase_75 AC 546 ms
237,744 KB
testcase_76 AC 554 ms
237,712 KB
testcase_77 AC 549 ms
237,820 KB
testcase_78 AC 562 ms
237,892 KB
testcase_79 AC 561 ms
237,696 KB
testcase_80 AC 565 ms
237,764 KB
testcase_81 AC 566 ms
237,784 KB
testcase_82 AC 541 ms
237,744 KB
testcase_83 AC 554 ms
237,840 KB
testcase_84 AC 530 ms
237,732 KB
testcase_85 AC 543 ms
238,020 KB
testcase_86 AC 551 ms
237,704 KB
testcase_87 AC 549 ms
237,748 KB
testcase_88 AC 561 ms
237,704 KB
testcase_89 AC 571 ms
237,752 KB
testcase_90 AC 584 ms
237,764 KB
testcase_91 AC 595 ms
237,716 KB
testcase_92 AC 570 ms
237,764 KB
testcase_93 AC 591 ms
237,752 KB
testcase_94 AC 552 ms
237,716 KB
testcase_95 AC 579 ms
237,708 KB
testcase_96 AC 572 ms
237,980 KB
testcase_97 AC 593 ms
237,712 KB
testcase_98 AC 587 ms
237,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <cmath>
using namespace std;
const long long MAX = 10000000;
const long long MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (long long i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        //そのまま計算すると負の値になるのでMODを足す
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(long long n, long long k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main() {
    COMinit();
    long long n;
    cin >> n;
    long long asize = 1;
    long long a = n;
    while(cin >> n) {
        if(n==0) continue;
        asize+=1;
        a-=n;
    }
    if(asize >= 3 && a-asize+2 < 0) cout << "NA" << endl;
    else cout << COM(a+1, a-asize+2) << endl;
} 
0