結果

問題 No.389 ロジックパズルの組み合わせ
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-11-08 17:50:26
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 206 ms / 2,000 ms
コード長 1,319 bytes
コンパイル時間 1,415 ms
コンパイル使用メモリ 148,880 KB
実行使用メモリ 12,984 KB
最終ジャッジ日時 2023-09-02 22:47:27
合計ジャッジ時間 8,898 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,368 KB
testcase_01 AC 2 ms
4,368 KB
testcase_02 AC 1 ms
4,372 KB
testcase_03 AC 2 ms
4,372 KB
testcase_04 AC 193 ms
4,372 KB
testcase_05 AC 1 ms
4,368 KB
testcase_06 AC 2 ms
4,368 KB
testcase_07 AC 1 ms
4,372 KB
testcase_08 AC 1 ms
4,372 KB
testcase_09 AC 200 ms
4,368 KB
testcase_10 AC 25 ms
4,368 KB
testcase_11 AC 206 ms
4,376 KB
testcase_12 AC 10 ms
4,368 KB
testcase_13 AC 60 ms
8,144 KB
testcase_14 AC 23 ms
4,372 KB
testcase_15 AC 29 ms
4,372 KB
testcase_16 AC 86 ms
4,368 KB
testcase_17 AC 135 ms
4,496 KB
testcase_18 AC 111 ms
9,888 KB
testcase_19 AC 2 ms
4,368 KB
testcase_20 AC 2 ms
4,372 KB
testcase_21 AC 1 ms
4,368 KB
testcase_22 AC 2 ms
4,368 KB
testcase_23 AC 1 ms
4,368 KB
testcase_24 AC 2 ms
4,368 KB
testcase_25 AC 1 ms
4,372 KB
testcase_26 AC 1 ms
4,372 KB
testcase_27 AC 1 ms
4,372 KB
testcase_28 AC 2 ms
4,372 KB
testcase_29 AC 1 ms
4,372 KB
testcase_30 AC 1 ms
4,368 KB
testcase_31 AC 1 ms
4,368 KB
testcase_32 AC 1 ms
4,368 KB
testcase_33 AC 1 ms
4,372 KB
testcase_34 AC 1 ms
4,372 KB
testcase_35 AC 1 ms
4,368 KB
testcase_36 AC 1 ms
4,372 KB
testcase_37 AC 1 ms
4,368 KB
testcase_38 AC 1 ms
4,372 KB
testcase_39 AC 1 ms
4,372 KB
testcase_40 AC 1 ms
4,368 KB
testcase_41 AC 2 ms
4,368 KB
testcase_42 AC 1 ms
4,368 KB
testcase_43 AC 1 ms
4,372 KB
testcase_44 AC 2 ms
4,372 KB
testcase_45 AC 2 ms
4,368 KB
testcase_46 AC 1 ms
4,368 KB
testcase_47 AC 1 ms
4,372 KB
testcase_48 AC 2 ms
4,372 KB
testcase_49 AC 27 ms
12,352 KB
testcase_50 AC 3 ms
4,368 KB
testcase_51 AC 3 ms
4,368 KB
testcase_52 AC 6 ms
4,368 KB
testcase_53 AC 3 ms
4,368 KB
testcase_54 AC 7 ms
6,480 KB
testcase_55 AC 1 ms
4,368 KB
testcase_56 AC 3 ms
4,368 KB
testcase_57 AC 11 ms
8,072 KB
testcase_58 AC 21 ms
10,100 KB
testcase_59 AC 17 ms
9,084 KB
testcase_60 AC 9 ms
7,276 KB
testcase_61 AC 36 ms
12,984 KB
testcase_62 AC 9 ms
6,272 KB
testcase_63 AC 21 ms
9,908 KB
testcase_64 AC 7 ms
5,224 KB
testcase_65 AC 5 ms
4,368 KB
testcase_66 AC 9 ms
6,996 KB
testcase_67 AC 8 ms
6,244 KB
testcase_68 AC 8 ms
7,012 KB
testcase_69 AC 100 ms
4,368 KB
testcase_70 AC 46 ms
4,368 KB
testcase_71 AC 74 ms
4,368 KB
testcase_72 AC 29 ms
4,368 KB
testcase_73 AC 54 ms
4,372 KB
testcase_74 AC 78 ms
4,368 KB
testcase_75 AC 67 ms
4,372 KB
testcase_76 AC 23 ms
4,368 KB
testcase_77 AC 139 ms
4,368 KB
testcase_78 AC 7 ms
4,372 KB
testcase_79 AC 2 ms
4,372 KB
testcase_80 AC 1 ms
4,372 KB
testcase_81 AC 1 ms
4,368 KB
testcase_82 AC 1 ms
4,368 KB
testcase_83 AC 2 ms
4,372 KB
testcase_84 AC 1 ms
4,368 KB
testcase_85 AC 1 ms
4,368 KB
testcase_86 AC 1 ms
4,372 KB
testcase_87 AC 1 ms
4,368 KB
testcase_88 AC 2 ms
4,368 KB
testcase_89 AC 39 ms
6,756 KB
testcase_90 AC 64 ms
8,136 KB
testcase_91 AC 118 ms
11,612 KB
testcase_92 AC 16 ms
4,368 KB
testcase_93 AC 71 ms
9,236 KB
testcase_94 AC 2 ms
4,372 KB
testcase_95 AC 73 ms
9,308 KB
testcase_96 AC 57 ms
9,696 KB
testcase_97 AC 53 ms
7,140 KB
testcase_98 AC 25 ms
6,252 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void log(A...)(A arg) {
    stderr.writeln(arg);
}
int size(T)(in T s) {
    return cast(int)s.length;
}

const long mod = cast(long)(1e9 + 7);

long extgcd(long a, long b, ref long x, ref long y) {
    long g = a; x = 1; y = 0;
    if (b != 0) {
        g = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    }
    return g;
}
long inverse(long mod, long v) {
    long x, y;
    if (extgcd(v, mod, x, y) == 1) return (x + mod) % mod;
    return 0;
}

void main() {
    int M; readf("%d\n", &M);
    auto H = readln.chomp.split(" ").map!(to!int).array;

    int k = H.size;

    if (k == 1 && H[0] == 0) {
        writeln(1);
        return;
    }

    int Y = M - (k - 1);
    foreach (h; H) {
        Y -= h;
    }

    if (Y < 0) {
        writeln("NA");
        return;
    }

    auto inv = delegate(long x) => inverse(mod, x);
    long ans = 1;
    for (long i = 1; i <= Y + k; i++) {
        ans = (ans * i) % mod;
    }
    for (long i = 1; i <= k; i++) {
        ans = (ans * inv(i)) % mod;
    }
    for (long i = 1; i <= Y; i++) {
        ans = (ans * inv(i)) % mod;
    }
    writeln(ans);

}
0