結果

問題 No.2824 Lights Up! (Grid Edition)
ユーザー chineristACchineristAC
提出日時 2024-07-26 23:47:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 628 ms / 2,000 ms
コード長 3,822 bytes
コンパイル時間 371 ms
コンパイル使用メモリ 82,120 KB
実行使用メモリ 146,680 KB
最終ジャッジ日時 2024-07-26 23:48:17
合計ジャッジ時間 18,254 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
58,500 KB
testcase_01 AC 48 ms
57,368 KB
testcase_02 AC 49 ms
57,012 KB
testcase_03 AC 48 ms
57,632 KB
testcase_04 AC 211 ms
93,964 KB
testcase_05 AC 254 ms
94,128 KB
testcase_06 AC 217 ms
94,196 KB
testcase_07 AC 497 ms
133,648 KB
testcase_08 AC 206 ms
94,192 KB
testcase_09 AC 245 ms
94,424 KB
testcase_10 AC 196 ms
94,412 KB
testcase_11 AC 502 ms
133,652 KB
testcase_12 AC 208 ms
94,188 KB
testcase_13 AC 549 ms
140,208 KB
testcase_14 AC 218 ms
94,156 KB
testcase_15 AC 606 ms
146,680 KB
testcase_16 AC 204 ms
94,272 KB
testcase_17 AC 560 ms
140,440 KB
testcase_18 AC 195 ms
94,152 KB
testcase_19 AC 628 ms
139,996 KB
testcase_20 AC 114 ms
82,696 KB
testcase_21 AC 210 ms
88,728 KB
testcase_22 AC 76 ms
77,324 KB
testcase_23 AC 441 ms
129,656 KB
testcase_24 AC 63 ms
70,968 KB
testcase_25 AC 112 ms
79,156 KB
testcase_26 AC 124 ms
83,576 KB
testcase_27 AC 488 ms
131,500 KB
testcase_28 AC 68 ms
73,324 KB
testcase_29 AC 138 ms
82,616 KB
testcase_30 AC 83 ms
78,172 KB
testcase_31 AC 49 ms
58,060 KB
testcase_32 AC 94 ms
78,600 KB
testcase_33 AC 78 ms
77,236 KB
testcase_34 AC 67 ms
69,656 KB
testcase_35 AC 61 ms
68,632 KB
testcase_36 AC 47 ms
57,472 KB
testcase_37 AC 71 ms
71,112 KB
testcase_38 AC 65 ms
70,148 KB
testcase_39 AC 58 ms
65,152 KB
testcase_40 AC 54 ms
64,824 KB
testcase_41 AC 48 ms
57,856 KB
testcase_42 AC 49 ms
57,408 KB
testcase_43 AC 49 ms
57,512 KB
testcase_44 AC 48 ms
57,492 KB
testcase_45 AC 49 ms
57,628 KB
testcase_46 AC 49 ms
58,048 KB
testcase_47 AC 50 ms
57,236 KB
testcase_48 AC 48 ms
57,124 KB
testcase_49 AC 48 ms
57,672 KB
testcase_50 AC 48 ms
56,824 KB
testcase_51 AC 48 ms
57,504 KB
testcase_52 AC 50 ms
57,300 KB
testcase_53 AC 49 ms
56,828 KB
testcase_54 AC 49 ms
58,220 KB
testcase_55 AC 50 ms
58,096 KB
testcase_56 AC 49 ms
57,076 KB
testcase_57 AC 49 ms
57,936 KB
testcase_58 AC 49 ms
57,432 KB
testcase_59 AC 50 ms
57,816 KB
testcase_60 AC 48 ms
57,668 KB
testcase_61 AC 48 ms
57,200 KB
testcase_62 AC 48 ms
57,576 KB
testcase_63 AC 47 ms
57,040 KB
testcase_64 AC 49 ms
57,224 KB
testcase_65 AC 48 ms
58,420 KB
testcase_66 AC 49 ms
57,204 KB
testcase_67 AC 49 ms
57,156 KB
testcase_68 AC 49 ms
57,688 KB
testcase_69 AC 48 ms
57,148 KB
testcase_70 AC 49 ms
56,892 KB
testcase_71 AC 49 ms
58,140 KB
testcase_72 AC 49 ms
57,188 KB
testcase_73 AC 48 ms
57,608 KB
testcase_74 AC 47 ms
58,172 KB
testcase_75 AC 49 ms
57,424 KB
testcase_76 AC 48 ms
58,476 KB
testcase_77 AC 48 ms
56,916 KB
testcase_78 AC 47 ms
58,444 KB
testcase_79 AC 48 ms
58,064 KB
testcase_80 AC 48 ms
57,780 KB
testcase_81 AC 49 ms
58,352 KB
testcase_82 AC 49 ms
57,652 KB
testcase_83 AC 48 ms
58,004 KB
testcase_84 AC 48 ms
57,488 KB
testcase_85 AC 49 ms
57,940 KB
testcase_86 AC 49 ms
57,436 KB
testcase_87 AC 48 ms
57,324 KB
testcase_88 AC 49 ms
57,152 KB
testcase_89 AC 51 ms
57,536 KB
testcase_90 AC 47 ms
57,348 KB
testcase_91 AC 48 ms
57,112 KB
testcase_92 AC 49 ms
58,648 KB
testcase_93 AC 49 ms
57,352 KB
testcase_94 AC 49 ms
58,232 KB
testcase_95 AC 48 ms
58,544 KB
testcase_96 AC 48 ms
57,068 KB
testcase_97 AC 48 ms
57,188 KB
testcase_98 AC 48 ms
56,992 KB
testcase_99 AC 47 ms
57,364 KB
testcase_100 AC 49 ms
57,892 KB
testcase_101 AC 48 ms
58,360 KB
testcase_102 AC 48 ms
56,700 KB
testcase_103 AC 48 ms
56,892 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",[])

    if N == 2:
        c = S[0][0]
        if c == S[0][1] and c == S[1][0] and c == S[1][1]:
            res = [] if c == "." else [(0,0)]
            return ("Yes",res)
        return ("No",[])
    
    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(1,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
        

def make_test(N):
    tmp = [[0]*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 r in range(N):
        for c in range(N):
            if random.randint(0,99) & 1:
                act(r,c)
    
    S = []
    for i in range(N):
        S.append("".join([".#"[tmp[i][j]] for j in range(N)]))
    return S
    

while False:
    N = random.randint(2,5)
    S = make_test(N)

    

    

    ans,res = solve(N,S)
    if ans == "No":
        print("WA")
        print(N)
        for s in S:
            print(s)
        exit()
    
    if not checker(N,S,res):
        print("WA:construction")
        print(N)
        for s in S:
            print(s)
        exit()
    
    print("AC",N)

    


                
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