結果

問題 No.3430 Flip the Grid
コンテスト
ユーザー titia
提出日時 2026-01-21 02:40:32
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 272 ms / 2,000 ms
+ 180µs
コード長 496 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 234 ms
コンパイル使用メモリ 96,108 KB
実行使用メモリ 118,400 KB
最終ジャッジ日時 2026-07-20 12:57:33
合計ジャッジ時間 4,282 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
input = sys.stdin.readline

H,W=list(map(int,input().split()))
A=[list(map(int,input().split())) for i in range(H)]

CH=[0]*H
CW=[0]*W

for i in range(H):
    for j in range(W):
        if A[i][j]==1:
            CH[i]+=1
            CW[j]+=1

CH.sort(reverse=True)
CW.sort(reverse=True)

i=0
j=0

while i<len(CH) and j<len(CW):
    if CH[i]>=2 and CW[j]>=2:
        CH[i]-=2
        CW[j]-=2
        continue

    if CH[i]<2:
        i+=1
    if CW[j]<2:
        j+=1

print(sum(CH))
0