結果
| 問題 |
No.1403 調和の魔法陣
|
| コンテスト | |
| ユーザー |
qwewe
|
| 提出日時 | 2025-05-14 12:51:02 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,534 bytes |
| コンパイル時間 | 184 ms |
| コンパイル使用メモリ | 82,312 KB |
| 実行使用メモリ | 77,928 KB |
| 最終ジャッジ日時 | 2025-05-14 12:51:34 |
| 合計ジャッジ時間 | 3,162 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | WA * 19 |
ソースコード
MOD = 998244353
# Precompute ways for H=2, W>=3 case
ways = [0] * (18 + 1)
for c in range(19):
if c <= 9:
ways[c] = c + 1
else:
ways[c] = 19 - c
def compute_case(W, H, X):
if H == 1 and W == 1:
return 1 if 0 <= X <= 9 else 0
elif (H == 1 and W == 2) or (W == 1 and H == 2):
if X < 0 or X > 18:
return 0
if X <= 9:
return (X + 1) % MOD
else:
return (19 - X) % MOD
elif (H == 1 and W >= 3) or (W == 1 and H >= 3):
return 1 if 0 <= X <= 9 else 0
elif H == 2 and W == 2:
def comb(n):
if n < 0:
return 0
return n * (n-1) * (n-2) // 6 if n >= 3 else 0
total = comb(X + 3)
total -= 4 * comb(X + 3 - 10)
total += 6 * comb(X + 3 - 20)
total -= 4 * comb(X + 3 - 30)
total += comb(X + 3 - 40)
return total % MOD
elif H == 2 or W == 2:
if H != 2:
W, H = H, W
if H != 2:
return 0
if X < 0 or X > 36:
return 0
res = 0
start = max(0, X - 18)
end = min(18, X)
for C1 in range(start, end + 1):
C2 = X - C1
if C2 < 0 or C2 > 18:
continue
res = (res + (ways[C1] ** 2) * (ways[C2] ** 2)) % MOD
return res
else:
return 1 if X == 0 else 0
T = int(input())
for _ in range(T):
W, H, X = map(int, input().split())
result = compute_case(W, H, X)
print(result % MOD)
qwewe