結果

問題 No.1954 CHECKER×CHECKER(2)
ユーザー chineristACchineristAC
提出日時 2022-05-20 23:24:41
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,791 bytes
コンパイル時間 890 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 71,112 KB
最終ジャッジ日時 2023-10-20 14:16:40
合計ジャッジ時間 3,962 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
56,104 KB
testcase_01 AC 39 ms
56,104 KB
testcase_02 AC 40 ms
56,104 KB
testcase_03 AC 40 ms
56,104 KB
testcase_04 WA -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 39 ms
56,104 KB
testcase_11 WA -
testcase_12 RE -
testcase_13 RE -
testcase_14 WA -
testcase_15 AC 39 ms
58,152 KB
testcase_16 AC 39 ms
58,152 KB
testcase_17 AC 39 ms
58,152 KB
testcase_18 WA -
testcase_19 AC 40 ms
58,152 KB
testcase_20 WA -
testcase_21 RE -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 46 ms
64,316 KB
testcase_25 AC 45 ms
64,320 KB
testcase_26 WA -
testcase_27 AC 46 ms
64,316 KB
testcase_28 AC 46 ms
64,320 KB
testcase_29 AC 39 ms
58,152 KB
testcase_30 WA -
testcase_31 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,random,bisect
from collections import deque,defaultdict
import heapq
from itertools import permutations
from math import gcd

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

def calc(h,w,A,f):
    if not f:
        if A[-1][-1]!=0:
            return False
        c = [A[h-1][j] for j in range(w-1)]
        r = [A[i][w-1] for i in range(h-1)]
        for i in range(h-1):
            for j in range(w-1):
                if A[i][j]!=r[i]^c[j]:
                    return False
        return True
    
    else:
        B = [[A[i][j] for j in range(w)] for i in range(h)]
        if calc(h,w,B,False):
            return True
        for j in range(w):
            B[h-1][w] ^= 1
        if calc(h,w,B,False):
            return True
        return False

H,W = mi()
A = [[(i+j)&1 for j in range(W)] for i in range(H)]
for i in range(H):
    S = input()
    for j in range(W):
        if S[j]=="#":
            A[i][j] ^= 1

M = int(input())
row = [H]
column = [W]
for _ in range(M):
    t,n = mi()
    if t==1:
        row.append(n-1)
    else:
        column.append(n-1)

row.sort()
column.sort()
f = True
if H-1 not in row:
    f = False

if W-1 not in column:
    f = False

h = len(row)-1
w = len(column)-1

new_A = [[0]*w for i in range(h)]
for i in range(h):
    for j in range(w):
        rl,rr = row[i],row[i+1]-1
        cl,cr = column[i],column[i+1]-1

        t = A[rl][cl]
        for p in range(rl,rr+1):
            for q in range(cl,cr+1):
                if t!=A[p][q]:
                    exit(print("No"))
        new_A[i][j] = t

if calc(h,w,new_A,f):
    exit(print("Yes"))
new_A = [[new_A[i][j]^1 for j in range(w)] for i in range(h)]
if calc(h,w,new_A,f):
    exit(print("Yes"))
print("No")



0