結果

問題 No.3430 Flip the Grid
コンテスト
ユーザー tomerun
提出日時 2026-01-11 15:01:38
言語 Crystal
(1.18.2)
結果
WA  
実行時間 -
コード長 379 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 14,065 ms
コンパイル使用メモリ 336,176 KB
実行使用メモリ 29,424 KB
最終ジャッジ日時 2026-01-11 15:03:46
合計ジャッジ時間 16,762 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 3 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

h, w = read_line.split.map(&.to_i)
a = Array.new(h) { read_line.split.map(&.to_i) }
ans = 0
(h - 1).times do |y|
  ps = w.times.select { |i| a[y][i] == 1 }.to_a
  0.step(to: ps.size - 2, by: 2) do |i|
    a[y + 1][ps[i]] ^= 1
    a[y + 1][ps[i + 1]] ^= 1
  end
  ans += ps.size % 2
end
last = a[h - 1].sum
if last >= 2 && ans > 0
  puts ans + last - 2
else
  puts ans + last
end
0