結果

問題 No.2824 Lights Up! (Grid Edition)
ユーザー chineristAC
提出日時 2024-07-26 23:41:25
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,767 bytes
コンパイル時間 613 ms
コンパイル使用メモリ 82,392 KB
実行使用メモリ 146,760 KB
最終ジャッジ日時 2024-07-26 23:41:45
合計ジャッジ時間 18,487 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 97 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from itertools import permutations
from heapq import *
from collections import deque
import random
import bisect
from math import factorial

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

def test(N):
    base = []

    def op(r,c):
        res = 0
        for x in ((r-1)%N,r):
            for y in ((c-1)%N,c):
                res |= 1<<(N*x+y)
        return res

    for r in range(1,N):
        for c in range(1,N):
            act = op(r,c) ^ op(r,0) ^ op(0,c)
            #act = op(r,c)
            for b in base:
                act = min(act,act^b)
            if act != 0:
                base.append(act)
    
    return len(base)

def solve(N,S):
    if N == 1:
        if S[0][0] == "#":
            return ("No",[])
        return ("Yes",[])
    
    tmp = [[int(S[i][j]=="#") for j in range(N)] for i in range(N)]
    op = [[0]*N for i in range(N)]

    cnt = 0
    for i in range(1,N)[::-1]:
        for j in range(1,N)[::-1]:
            if tmp[i][j] == 0:
                continue
            op[i][j] = 1
            cnt += 1
            for r in [i,(i-1)%N]:
                for c in [j,(j-1)%N]:
                    tmp[r][c] ^= 1
    
    if sum(sum(a) for a in tmp):
        return ("No",[])
    
    if N & 1:
        ccc = [op[i][:] for i in range(N)]
        for i in range(1,N):
            check = (sum(ccc[i][1:]) & 1) ^ (cnt & 1)
            if check == 1:
                for j in range(N):
                    op[i][j] ^= 1
        for j in range(1,N):
            check = (sum(ccc[i][j] for i in range(1,N)) & 1) ^ (cnt & 1)
            if check == 1:
                for i in range(N):
                    op[i][j] ^= 1
        
        
    else:
        R = [sum(op[i][1:]) & 1 for i in range(1,N)]
        C = [sum(op[i][j] for i in range(1,N)) & 1 for j in range(N)]
        same = R[0]
        if any(x!=same for x in R+C):
            return ("No",[])
        
    res = []
    for i in range(1,N):
        for j in range(1,N):
            if op[i][j]:
                res.append((i,j))
    
    return ("Yes",res)

def checker(N,S,res):
    tmp = [[int(S[i][j]=="#") for j in range(N)] for i in range(N)]

    def op(r,c):
        for x in ((r-1)%N,r):
            for y in ((c-1)%N,c):
                tmp[x][y] ^= 1
    
    def act(r,c):
        op(r,c)
        op(r,0)
        op(0,c)
    
    for x,y in res:
        act(x,y)
    
    for i in range(N):
        if sum(tmp[i]) > 0:
            return False
    return True
        




                
N = int(input())
S = [input() for i in range(N)]

ans,res = solve(N,S)
if ans == "No":
    print(-1)
else:
    print(len(res))
    for x,y in res:
        print(x,y)

    #print(checker(N,S,res))
0