結果
問題 | No.2837 Flip Triomino |
ユーザー |
|
提出日時 | 2024-07-26 17:19:26 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 71 ms / 2,000 ms |
コード長 | 757 bytes |
コンパイル時間 | 299 ms |
コンパイル使用メモリ | 82,324 KB |
実行使用メモリ | 69,824 KB |
最終ジャッジ日時 | 2024-07-26 17:19:30 |
合計ジャッジ時間 | 3,922 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 34 |
ソースコード
h, w = map(int, input().split()) s = [input() for i in range(h)] assert 3 <= h <= 500 and 3 <= w <= 500 for i in range(h): for j in range(w): assert s[i][j] in ["W", "B", "?"] q_cnt = [0] * 3 b_cnt = [0] * 3 mod = 998244353 for i in range(h): for j in range(w): if s[i][j] == "B": b_cnt[(i + j) % 3] += 1 if s[i][j] == "?": q_cnt[(i + j) % 3] += 1 ans_o = 1 ans_e = 1 for b, q in zip(b_cnt, q_cnt): if b & 1: ans_e *= 0 if not q else pow(2, q - 1, mod) ans_o *= 1 if not q else pow(2, q - 1, mod) else: ans_e *= 1 if not q else pow(2, q - 1, mod) ans_o *= 0 if not q else pow(2, q - 1, mod) ans_e %= mod ans_o %= mod print((ans_e + ans_o) % mod)