結果

問題 No.584 赤、緑、青の色塗り
ユーザー nebukuro09nebukuro09
提出日時 2018-01-16 13:10:53
言語 D
(dmd 2.107.1)
結果
WA  
実行時間 -
コード長 1,715 bytes
コンパイル時間 801 ms
コンパイル使用メモリ 101,500 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-03 18:10:30
合計ジャッジ時間 2,010 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 WA -
testcase_11 AC 1 ms
4,380 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1 ms
4,380 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;


void main() {
    immutable int MAX = 4000;
    immutable long MOD = 10^^9+7;

    auto modinv = new long[](MAX);
    modinv[0] = modinv[1] = 1;
    foreach(i; 2..MAX) {
        modinv[i] = modinv[MOD % i] * (MOD - MOD / i) % MOD;
    }

    auto f_mod = new long[](MAX);
    auto f_modinv = new long[](MAX);
    f_mod[0] = f_mod[1] = 1;
    f_modinv[0] = f_modinv[1] = 1;

    foreach(i; 2..MAX) {
        f_mod[i] = (i * f_mod[i-1]) % MOD;
        f_modinv[i] = (modinv[i] * f_modinv[i-1]) % MOD;
    }

    long comb(int n, int k) {
        if (n < k) return 0;
        return f_mod[n] * f_modinv[n-k] % MOD * f_modinv[k] % MOD;
    }

    
    auto s = readln.split.map!(to!int);
    auto N = s[0], R = s[1], G = s[2], B = s[3];
    auto M = max(R, G, B);
    auto RGB = R + G + B;
    long ans = 0;

    foreach (two; 0..RGB/2+1) {
        auto one = RGB - two * 2;
        auto emp = N - two * 2 - one;
        if (M > two + one) continue;
        if (emp + 1 < one + two) continue;
        long tmp1 = comb(emp+1, one) * comb(emp+1-one, two) % MOD;
        foreach (i; max(0, R-one)..min(R, two)+1) {
            long tmp2 = tmp1 * comb(two, i) % MOD * comb(one, R-i) % MOD;
            tmp2 = tmp2 * comb(one+two-(R-i), G) % MOD;
            tmp2 = tmp2 * powmod(2, two, MOD);
            ans = (ans + tmp2) % MOD;
        }
    }

    ans.writeln;
}


long powmod(long a, long x, long m) {
    long ret = 1;
    while (x) {
        if (x % 2) ret = ret * a % m;
        a = a * a % m;
        x /= 2;
    }
    return ret;
}
0