結果

問題 No.2824 Lights Up! (Grid Edition)
ユーザー chineristACchineristAC
提出日時 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
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
56,448 KB
testcase_01 AC 54 ms
56,576 KB
testcase_02 AC 51 ms
56,576 KB
testcase_03 AC 53 ms
56,448 KB
testcase_04 AC 233 ms
94,464 KB
testcase_05 AC 259 ms
94,084 KB
testcase_06 AC 224 ms
94,104 KB
testcase_07 WA -
testcase_08 AC 208 ms
94,080 KB
testcase_09 AC 257 ms
94,052 KB
testcase_10 AC 206 ms
94,464 KB
testcase_11 AC 515 ms
133,864 KB
testcase_12 AC 226 ms
94,080 KB
testcase_13 AC 583 ms
140,344 KB
testcase_14 AC 237 ms
94,336 KB
testcase_15 AC 609 ms
146,760 KB
testcase_16 AC 218 ms
94,136 KB
testcase_17 AC 603 ms
140,516 KB
testcase_18 AC 206 ms
94,208 KB
testcase_19 AC 625 ms
140,288 KB
testcase_20 AC 122 ms
82,812 KB
testcase_21 AC 219 ms
88,832 KB
testcase_22 AC 77 ms
74,624 KB
testcase_23 AC 458 ms
129,792 KB
testcase_24 AC 68 ms
69,376 KB
testcase_25 AC 121 ms
79,048 KB
testcase_26 AC 138 ms
83,176 KB
testcase_27 AC 456 ms
131,596 KB
testcase_28 AC 75 ms
72,576 KB
testcase_29 AC 154 ms
82,688 KB
testcase_30 AC 92 ms
78,608 KB
testcase_31 AC 54 ms
56,704 KB
testcase_32 AC 97 ms
78,464 KB
testcase_33 AC 75 ms
75,008 KB
testcase_34 AC 66 ms
68,992 KB
testcase_35 AC 71 ms
66,688 KB
testcase_36 AC 54 ms
56,832 KB
testcase_37 AC 75 ms
70,400 KB
testcase_38 AC 68 ms
68,480 KB
testcase_39 AC 60 ms
64,512 KB
testcase_40 AC 60 ms
63,360 KB
testcase_41 AC 50 ms
56,704 KB
testcase_42 AC 53 ms
56,576 KB
testcase_43 AC 52 ms
56,960 KB
testcase_44 AC 53 ms
56,448 KB
testcase_45 AC 53 ms
56,704 KB
testcase_46 AC 53 ms
56,576 KB
testcase_47 AC 53 ms
56,704 KB
testcase_48 AC 52 ms
56,704 KB
testcase_49 WA -
testcase_50 AC 53 ms
56,704 KB
testcase_51 AC 51 ms
56,576 KB
testcase_52 AC 50 ms
56,832 KB
testcase_53 AC 51 ms
56,576 KB
testcase_54 AC 52 ms
56,704 KB
testcase_55 AC 54 ms
56,448 KB
testcase_56 AC 52 ms
56,704 KB
testcase_57 AC 53 ms
56,704 KB
testcase_58 AC 51 ms
56,448 KB
testcase_59 AC 51 ms
56,448 KB
testcase_60 AC 53 ms
56,832 KB
testcase_61 AC 51 ms
56,448 KB
testcase_62 AC 54 ms
56,704 KB
testcase_63 AC 54 ms
56,704 KB
testcase_64 AC 52 ms
56,832 KB
testcase_65 AC 54 ms
56,448 KB
testcase_66 AC 53 ms
56,576 KB
testcase_67 AC 52 ms
56,576 KB
testcase_68 AC 50 ms
56,320 KB
testcase_69 AC 53 ms
56,576 KB
testcase_70 AC 52 ms
56,576 KB
testcase_71 AC 54 ms
56,448 KB
testcase_72 AC 50 ms
56,832 KB
testcase_73 AC 53 ms
56,704 KB
testcase_74 AC 53 ms
56,576 KB
testcase_75 AC 50 ms
56,448 KB
testcase_76 AC 50 ms
56,320 KB
testcase_77 AC 54 ms
56,832 KB
testcase_78 AC 54 ms
56,704 KB
testcase_79 AC 53 ms
56,704 KB
testcase_80 AC 51 ms
56,448 KB
testcase_81 AC 53 ms
56,448 KB
testcase_82 AC 53 ms
56,704 KB
testcase_83 WA -
testcase_84 AC 54 ms
56,448 KB
testcase_85 AC 51 ms
56,576 KB
testcase_86 AC 52 ms
56,448 KB
testcase_87 AC 52 ms
56,832 KB
testcase_88 AC 53 ms
56,576 KB
testcase_89 AC 59 ms
56,320 KB
testcase_90 AC 54 ms
56,704 KB
testcase_91 AC 53 ms
56,576 KB
testcase_92 AC 51 ms
56,448 KB
testcase_93 AC 52 ms
56,832 KB
testcase_94 AC 52 ms
56,704 KB
testcase_95 AC 50 ms
56,448 KB
testcase_96 AC 53 ms
56,704 KB
testcase_97 AC 54 ms
56,704 KB
testcase_98 AC 54 ms
56,448 KB
testcase_99 AC 54 ms
56,704 KB
testcase_100 AC 55 ms
56,704 KB
testcase_101 AC 55 ms
56,704 KB
testcase_102 AC 53 ms
56,704 KB
testcase_103 AC 54 ms
56,704 KB
権限があれば一括ダウンロードができます

ソースコード

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