結果

問題 No.3430 Flip the Grid
コンテスト
ユーザー るるまるふぁんくらぶ
提出日時 2026-01-11 15:15:50
言語 PyPy3
(7.3.17)
結果
TLE  
実行時間 -
コード長 2,154 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 356 ms
コンパイル使用メモリ 82,608 KB
実行使用メモリ 120,280 KB
最終ジャッジ日時 2026-01-11 15:15:55
合計ジャッジ時間 4,395 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 3 TLE * 1 -- * 6
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

h, w = map(int, input().split())
mp = [list(map(int, input().split())) for _ in range(h)]
while True:
    g = True
    while True:
        f = True
        for i in range(h-1):
            for j in range(w-1):
                arr = [mp[i][j], mp[i][j+1], mp[i+1][j], mp[i+1][j+1]]
                if arr.count(1) == 4:
                    mp[i][j] = 0
                    mp[i][j+1] = 0
                    mp[i+1][j] = 0
                    mp[i+1][j+1] = 0
                    f = False
                    g = False
        if f:
            break
    while True:
        f = True
        for i in range(h-1):
            for j in range(w-1):
                arr = [mp[i][j], mp[i][j+1], mp[i+1][j], mp[i+1][j+1]]
                if arr.count(1) == 3:
                    mp[i][j] = int(not mp[i][j])
                    mp[i][j+1] = int(not mp[i][j+1])
                    mp[i+1][j] = int(not mp[i+1][j])
                    mp[i+1][j+1] = int(not mp[i+1][j+1])
                    f = False
                    g = False
        if f:
            break
    while True:
        f = True
        for i in range(h-1):
            for j in range(w-1):
                arr = [mp[i][j], mp[i][j+1], mp[i+1][j], mp[i+1][j+1]]
                if arr == [0, 0, 1, 1]:
                    mp[i][j] = int(not mp[i][j])
                    mp[i][j+1] = int(not mp[i][j+1])
                    mp[i+1][j] = int(not mp[i+1][j])
                    mp[i+1][j+1] = int(not mp[i+1][j+1])
                    f = False
                    g = False
        if f:
            break
    while True:
        f = True
        for i in range(h-1):
            for j in range(w-1):
                arr = [mp[i][j], mp[i][j+1], mp[i+1][j], mp[i+1][j+1]]
                if arr == [0, 1, 0, 1]:
                    mp[i][j] = int(not mp[i][j])
                    mp[i][j+1] = int(not mp[i][j+1])
                    mp[i+1][j] = int(not mp[i+1][j])
                    mp[i+1][j+1] = int(not mp[i+1][j+1])
                    f = False
                    g = False
        if f:
            break
    if g:
        break

ans = 0
for x in mp:
    ans += sum(x)
print(ans)
0