結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー tktk_snsntktk_snsn
提出日時 2021-03-20 12:50:57
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 570 ms / 2,000 ms
コード長 1,560 bytes
コンパイル時間 298 ms
コンパイル使用メモリ 10,916 KB
実行使用メモリ 94,664 KB
最終ジャッジ日時 2023-08-13 05:11:27
合計ジャッジ時間 48,558 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 410 ms
87,028 KB
testcase_01 AC 410 ms
86,712 KB
testcase_02 AC 412 ms
86,880 KB
testcase_03 AC 413 ms
86,832 KB
testcase_04 AC 412 ms
86,624 KB
testcase_05 AC 412 ms
86,920 KB
testcase_06 AC 409 ms
86,940 KB
testcase_07 AC 412 ms
86,768 KB
testcase_08 AC 407 ms
86,816 KB
testcase_09 AC 426 ms
87,604 KB
testcase_10 AC 419 ms
87,508 KB
testcase_11 AC 429 ms
87,720 KB
testcase_12 AC 421 ms
87,456 KB
testcase_13 AC 471 ms
89,956 KB
testcase_14 AC 434 ms
87,852 KB
testcase_15 AC 416 ms
87,360 KB
testcase_16 AC 421 ms
87,448 KB
testcase_17 AC 429 ms
87,672 KB
testcase_18 AC 524 ms
92,552 KB
testcase_19 AC 410 ms
86,676 KB
testcase_20 AC 412 ms
86,828 KB
testcase_21 AC 410 ms
86,716 KB
testcase_22 AC 413 ms
86,672 KB
testcase_23 AC 410 ms
86,728 KB
testcase_24 AC 412 ms
86,672 KB
testcase_25 AC 412 ms
86,680 KB
testcase_26 AC 410 ms
86,604 KB
testcase_27 AC 413 ms
86,796 KB
testcase_28 AC 411 ms
86,828 KB
testcase_29 AC 412 ms
86,700 KB
testcase_30 AC 412 ms
86,740 KB
testcase_31 AC 412 ms
87,020 KB
testcase_32 AC 414 ms
86,888 KB
testcase_33 AC 414 ms
86,772 KB
testcase_34 AC 413 ms
86,656 KB
testcase_35 AC 411 ms
86,768 KB
testcase_36 AC 411 ms
86,744 KB
testcase_37 AC 415 ms
86,780 KB
testcase_38 AC 411 ms
86,828 KB
testcase_39 AC 413 ms
86,876 KB
testcase_40 AC 415 ms
86,844 KB
testcase_41 AC 413 ms
86,668 KB
testcase_42 AC 413 ms
86,696 KB
testcase_43 AC 413 ms
86,792 KB
testcase_44 AC 414 ms
86,840 KB
testcase_45 AC 410 ms
86,740 KB
testcase_46 AC 409 ms
86,852 KB
testcase_47 AC 413 ms
86,700 KB
testcase_48 AC 416 ms
86,880 KB
testcase_49 AC 524 ms
92,876 KB
testcase_50 AC 421 ms
87,868 KB
testcase_51 AC 421 ms
87,408 KB
testcase_52 AC 437 ms
90,340 KB
testcase_53 AC 423 ms
87,692 KB
testcase_54 AC 439 ms
90,920 KB
testcase_55 AC 414 ms
86,872 KB
testcase_56 AC 422 ms
87,404 KB
testcase_57 AC 462 ms
89,444 KB
testcase_58 AC 513 ms
91,976 KB
testcase_59 AC 487 ms
90,380 KB
testcase_60 AC 444 ms
88,328 KB
testcase_61 AC 570 ms
94,664 KB
testcase_62 AC 447 ms
88,652 KB
testcase_63 AC 517 ms
92,108 KB
testcase_64 AC 437 ms
90,820 KB
testcase_65 AC 427 ms
87,784 KB
testcase_66 AC 445 ms
88,384 KB
testcase_67 AC 444 ms
88,680 KB
testcase_68 AC 446 ms
90,952 KB
testcase_69 AC 409 ms
86,880 KB
testcase_70 AC 415 ms
86,872 KB
testcase_71 AC 413 ms
86,772 KB
testcase_72 AC 412 ms
86,864 KB
testcase_73 AC 414 ms
86,904 KB
testcase_74 AC 416 ms
86,820 KB
testcase_75 AC 417 ms
86,892 KB
testcase_76 AC 414 ms
86,924 KB
testcase_77 AC 415 ms
86,724 KB
testcase_78 AC 414 ms
86,952 KB
testcase_79 AC 413 ms
86,916 KB
testcase_80 AC 417 ms
86,696 KB
testcase_81 AC 414 ms
86,800 KB
testcase_82 AC 415 ms
86,892 KB
testcase_83 AC 415 ms
86,632 KB
testcase_84 AC 415 ms
86,684 KB
testcase_85 AC 412 ms
86,636 KB
testcase_86 AC 412 ms
86,824 KB
testcase_87 AC 416 ms
86,772 KB
testcase_88 AC 414 ms
86,780 KB
testcase_89 AC 454 ms
88,952 KB
testcase_90 AC 478 ms
90,232 KB
testcase_91 AC 526 ms
92,540 KB
testcase_92 AC 431 ms
87,808 KB
testcase_93 AC 483 ms
90,344 KB
testcase_94 AC 413 ms
87,152 KB
testcase_95 AC 486 ms
90,240 KB
testcase_96 AC 469 ms
89,888 KB
testcase_97 AC 470 ms
89,776 KB
testcase_98 AC 441 ms
90,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
mod = 10 ** 9 + 7


class Combination:
    """
    SIZEが10**6程度以下の二項係数を何回も呼び出したいときに使う
    使い方:
    comb = Combination(SIZE, MOD)
    comb(10, 3) => 120
    """

    def __init__(self, N=10**6, MOD=10 ** 9 + 7):
        self.MOD = MOD
        self.__make_factorial_list(N)

    def __call__(self, n, k):
        if k < 0 or k > n:
            return 0
        res = self.fact[n] * self.inv[k] % self.MOD
        res = res * self.inv[n - k] % self.MOD
        return res

    def nPk(self, n, k):
        if k < 0 or k > n:
            return 0
        return self.fact[n] * self.inv[n - k] % self.MOD

    def nHk(self, n, k):
        if k == 0:
            return 1
        return self.__call__(n + k - 1, k)

    def __make_factorial_list(self, N):
        self.fact = [1] * (N + 1)
        self.inv = [1] * (N + 1)
        MOD = self.MOD
        for i in range(1, N + 1):
            self.fact[i] = (self.fact[i - 1] * i) % MOD
        self.inv[N] = pow(self.fact[N], MOD - 2, MOD)
        for i in range(N, 0, -1):
            self.inv[i - 1] = (self.inv[i] * i) % MOD
        return


comb = Combination(10**6+100, mod)
M = int(input())
H = []
sumH = 0
for h in map(int, input().split()):
    if h:
        H.append(h)
        sumH += h

if not H:
    print(1)
    exit()

white = M - sumH - (len(H) - 1)
if white < 0:
    print("NA")
    exit()

ans = comb(white + len(H), len(H))
print(ans)
0