結果

問題 No.307 最近色塗る問題多くない?
ユーザー chocoruskchocorusk
提出日時 2020-09-23 16:01:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,069 ms / 4,000 ms
コード長 1,082 bytes
コンパイル時間 477 ms
コンパイル使用メモリ 86,996 KB
実行使用メモリ 146,384 KB
最終ジャッジ日時 2023-09-10 07:15:11
合計ジャッジ時間 10,710 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,416 KB
testcase_01 AC 71 ms
71,516 KB
testcase_02 AC 70 ms
71,160 KB
testcase_03 AC 72 ms
71,508 KB
testcase_04 AC 87 ms
76,776 KB
testcase_05 AC 70 ms
71,316 KB
testcase_06 AC 80 ms
75,732 KB
testcase_07 AC 105 ms
77,612 KB
testcase_08 AC 150 ms
84,692 KB
testcase_09 AC 119 ms
79,340 KB
testcase_10 AC 97 ms
76,956 KB
testcase_11 AC 100 ms
77,364 KB
testcase_12 AC 71 ms
71,216 KB
testcase_13 AC 97 ms
77,200 KB
testcase_14 AC 89 ms
76,916 KB
testcase_15 AC 91 ms
76,820 KB
testcase_16 AC 92 ms
76,740 KB
testcase_17 AC 134 ms
78,684 KB
testcase_18 AC 243 ms
87,428 KB
testcase_19 AC 216 ms
87,132 KB
testcase_20 AC 81 ms
76,808 KB
testcase_21 AC 191 ms
84,720 KB
testcase_22 AC 175 ms
87,488 KB
testcase_23 AC 986 ms
137,900 KB
testcase_24 AC 401 ms
88,260 KB
testcase_25 AC 547 ms
108,048 KB
testcase_26 AC 1,069 ms
143,788 KB
testcase_27 AC 97 ms
77,564 KB
testcase_28 AC 155 ms
84,916 KB
testcase_29 AC 85 ms
76,296 KB
testcase_30 AC 1,062 ms
146,384 KB
testcase_31 AC 114 ms
77,856 KB
testcase_32 AC 103 ms
77,476 KB
testcase_33 AC 98 ms
78,576 KB
testcase_34 AC 98 ms
77,256 KB
testcase_35 AC 110 ms
77,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
readlines=sys.stdin.buffer.readlines

h, w=map(int, readline().split())
a=[]
cnt1=0
for i in range(h):
    ai=list(map(int, readline().split()))
    a.append(ai)
    cnt1+=sum(ai)
a0=-1
if cnt1==0 or cnt1==h*w:
    a0=0
q=int(readline())
for _ in range(q):
    r, c, x=map(int, readline().split())
    r-=1
    c-=1
    if a0!=-1:
        if (a[r][c]^a0)!=x:
            a0^=1
        continue
    if a[r][c]==x:
        continue
    que=[(r, c)]
    a[r][c]=x
    if x==1:
        cnt1+=1
    else:
        cnt1-=1
    for p in que:
        r0, c0=p[0], p[1]
        for dx, dy in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
            r1, c1=r0+dx, c0+dy
            if r1<0 or r1>=h or c1<0 or c1>=w or a[r1][c1]==x:
                continue
            a[r1][c1]=x
            if x==1:
                cnt1+=1
            else:
                cnt1-=1
            que.append((r1, c1))
    if cnt1==0 or cnt1==h*w:
        a0=0
if a0==-1:a0=0
for i in range(h):
    print(' '.join(map(str, [x^a0 for x in a[i]])))
0