結果
| 問題 |
No.1403 調和の魔法陣
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-09 21:05:41 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,576 bytes |
| コンパイル時間 | 355 ms |
| コンパイル使用メモリ | 82,584 KB |
| 実行使用メモリ | 78,884 KB |
| 最終ジャッジ日時 | 2025-04-09 21:07:49 |
| 合計ジャッジ時間 | 2,321 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | WA * 19 |
ソースコード
import sys
MOD = 998244353
# Precompute the ways array
ways = [0] * 19
for s in range(19):
if s <= 9:
ways[s] = s + 1
else:
ways[s] = 19 - s
def solve():
input = sys.stdin.read().split()
T = int(input[0])
idx = 1
for _ in range(T):
W = int(input[idx])
H = int(input[idx+1])
X = int(input[idx+2])
idx += 3
# Check if both are >=3
if W >=3 and H >=3:
print(1 % MOD if X ==0 else 0)
continue
# Check if H or W is 2, swap to make H=2 if possible
original_H = H
if H !=2 and W ==2:
W, H = H, W
if H ==2:
S = X
a = 0 # count x mod3 ==1
b = 0 # count x mod3 ==2
for x in range(1, W+1):
mod = x %3
if mod ==1:
a +=1
elif mod ==2:
b +=1
min_c1 = max(0, S -18)
max_c1 = min(S, 18)
total =0
for c1 in range(min_c1, max_c1+1):
c2 = S - c1
if c2 <0 or c2 >18:
continue
# Calculate (ways[c1]^a * ways[c2]^b) mod MOD
pow_a = pow(ways[c1], a, MOD)
pow_b = pow(ways[c2], b, MOD)
total = (total + (pow_a * pow_b) % MOD) % MOD
print(total % MOD)
else:
# Handle other cases (H=1 or W=1 not handled here)
print(0)
if __name__ == '__main__':
solve()
lam6er