結果

問題 No.3430 Flip the Grid
コンテスト
ユーザー titia
提出日時 2026-01-21 02:40:32
言語 PyPy3
(8.0.1 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 229 ms / 2,000 ms
+ 713µs
コード長 496 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 83 ms
コンパイル使用メモリ 64,528 KB
実行使用メモリ 99,832 KB
最終ジャッジ日時 2026-10-23 20:20:30
合計ジャッジ時間 3,625 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 11
権限があれば一括ダウンロードができます

ソースコード

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