結果
| 問題 |
No.1403 調和の魔法陣
|
| コンテスト | |
| ユーザー |
qwewe
|
| 提出日時 | 2025-05-14 12:51:02 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,621 bytes |
| コンパイル時間 | 315 ms |
| コンパイル使用メモリ | 82,444 KB |
| 実行使用メモリ | 79,008 KB |
| 最終ジャッジ日時 | 2025-05-14 12:51:37 |
| 合計ジャッジ時間 | 3,234 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | WA * 19 |
ソースコード
MOD = 998244353
max_fact = 10**5 + 10
# Precompute factorial and inverse factorial modulo MOD
fact = [1] * (max_fact)
for i in range(1, max_fact):
fact[i] = fact[i-1] * i % MOD
inv_fact = [1] * (max_fact)
inv_fact[max_fact-1] = pow(fact[max_fact-1], MOD-2, MOD)
for i in range(max_fact-2, -1, -1):
inv_fact[i] = inv_fact[i+1] * (i+1) % MOD
def comb(n, k):
if n < 0 or k < 0 or n < k:
return 0
return fact[n] * inv_fact[k] % MOD * inv_fact[n - k] % MOD
# Precompute f[X] for X from 0 to 18
f = [0] * 19
for x in range(19):
a = max(x - 9, 0)
b = min(x, 9)
if a > b:
f[x] = 0
else:
f[x] = b - a + 1
T = int(input())
for _ in range(T):
W, H, X = map(int, input().split())
# Ensure W <= H for easier handling
if W > H:
W, H = H, W
if W <= 2 and H <= 2:
K = W * H
if X < 0 or X > 9 * K:
print(0)
continue
ans = 0
for k in range(0, K+1):
rem = X - 10 * k
if rem < 0:
break
term = comb(K, k) * comb(rem + K - 1, K - 1) % MOD
if k % 2 == 0:
ans = (ans + term) % MOD
else:
ans = (ans - term) % MOD
print(ans % MOD)
elif W >= 3 and H >= 3:
print(1 if X == 0 else 0)
else:
# W <= 2, H >= 3
m = (H - 1) // 2
res = 0
for B in range(0, X + 1):
if B > 18 or (X - B) > 18:
continue
product = (f[B] * f[X - B]) % MOD
res = (res + pow(product, m, MOD)) % MOD
print(res % MOD)
qwewe