結果
問題 | No.584 赤、緑、青の色塗り |
ユーザー | maspy |
提出日時 | 2020-04-23 18:22:08 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 568 ms / 2,000 ms |
コード長 | 1,793 bytes |
コンパイル時間 | 149 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 44,588 KB |
最終ジャッジ日時 | 2024-10-13 18:53:24 |
合計ジャッジ時間 | 12,529 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 509 ms
43,944 KB |
testcase_01 | AC | 513 ms
43,944 KB |
testcase_02 | AC | 515 ms
44,200 KB |
testcase_03 | AC | 516 ms
43,816 KB |
testcase_04 | AC | 517 ms
44,328 KB |
testcase_05 | AC | 514 ms
44,072 KB |
testcase_06 | AC | 511 ms
43,812 KB |
testcase_07 | AC | 516 ms
43,948 KB |
testcase_08 | AC | 515 ms
44,076 KB |
testcase_09 | AC | 514 ms
44,456 KB |
testcase_10 | AC | 516 ms
43,940 KB |
testcase_11 | AC | 517 ms
44,588 KB |
testcase_12 | AC | 514 ms
43,944 KB |
testcase_13 | AC | 514 ms
43,948 KB |
testcase_14 | AC | 528 ms
44,200 KB |
testcase_15 | AC | 517 ms
43,948 KB |
testcase_16 | AC | 523 ms
43,948 KB |
testcase_17 | AC | 525 ms
43,816 KB |
testcase_18 | AC | 522 ms
44,200 KB |
testcase_19 | AC | 568 ms
43,952 KB |
ソースコード
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np MOD = 10 ** 9 + 7 N, R, G, B = map(int, read().split()) def cumprod(A, MOD=MOD): L = len(A) Lsq = int(L**.5 + 1) A = np.resize(A, Lsq**2).reshape(Lsq, Lsq) for n in range(1, Lsq): A[:, n] *= A[:, n - 1] A[:, n] %= MOD for n in range(1, Lsq): A[n] *= A[n - 1, -1] A[n] %= MOD return A.ravel()[:L] def make_fact(U, MOD=MOD): x = np.arange(U, dtype=np.int64) x[0] = 1 fact = cumprod(x, MOD) x = np.arange(U, 0, -1, dtype=np.int64) x[0] = pow(int(fact[-1]), MOD - 2, MOD) fact_inv = cumprod(x, MOD)[::-1] fact.flags.writeable = False fact_inv.flags.writeable = False return fact, fact_inv fact, fact_inv = make_fact(10 ** 4) answer = 0 for N2 in range(N + 1): N1 = R + G + B - 2 * N2 if N1 < 0: break tile = N1 + N2 space = N - (R + G + B) space -= (tile - 1) if space < 0: continue coef = fact[N1 + N2] * fact_inv[N1] % MOD * fact_inv[N2] % MOD coef *= fact[space + tile] * fact_inv[space] % MOD * fact_inv[tile] % MOD coef %= MOD lo = max(0, N2 - R) hi = min(N2, B, G, N1 + N2 - R) if lo > hi: continue x = fact[N2] * fact_inv[lo: hi + 1] % MOD * fact_inv[N2 - hi: N2 - lo + 1][::-1] % MOD x = x * pow(2, N2, MOD) % MOD x *= fact[N1] * fact_inv[R - N2 + lo: R - N2 + hi + 1] % MOD * fact_inv[N1 + N2 - R - hi: N1 + N2 - R - lo + 1][::-1] % MOD x %= MOD x *= fact[B + G - 2 * hi: B + G - 2 * lo + 2:2][::-1] * fact_inv[B - hi: B - lo + 1][::-1] % MOD * fact_inv[G - hi: G - lo + 1][::-1] % MOD x %= MOD answer += x.sum() % MOD * coef % MOD print(answer % MOD)