結果
問題 | No.226 0-1パズル |
ユーザー |
![]() |
提出日時 | 2024-03-13 22:08:26 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 33 ms / 5,000 ms |
コード長 | 1,254 bytes |
コンパイル時間 | 829 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 10,880 KB |
最終ジャッジ日時 | 2024-09-29 23:36:55 |
合計ジャッジ時間 | 1,847 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 |
ソースコード
H, W = map(int, input().split()) table = {} for i in range(H): for j, v in enumerate(list(input())): if v != '?': if i not in table: table[i] = {} table[i][j] = int(v) exp1= H exp2= W v_chk = {} for i, row in table.items(): h_chk = -1 for j, v in row.items(): if exp1 != -1: if h_chk == -1: h_chk = (j + v) % 2 exp1 -= 1 else: if h_chk != (j + v) % 2: exp1 = -1 if exp2 != -1: if j not in v_chk: v_chk[j] = (i + v) % 2 exp2 -=1 else: if v_chk[j] != (i + v) % 2: exp2 = -1 if exp1 == -1 and exp2 == -2: break MOD = 1000000007 ans = 0 if exp1 != -1: ans += pow(2, exp1, MOD) if exp2 != -1: if exp1 == -1: dup = 0 elif exp2 == W: dup = 2 else: dup = 1 h_chk = -1 for j, v in v_chk.items(): if h_chk == -1: h_chk = (j + v) % 2 else: if h_chk != (j + v) % 2: dup = 0 break ans += pow(2, exp2, MOD) - dup ans %= MOD print(ans)