結果
| 問題 | No.5002 stick xor | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2018-05-26 03:10:06 | 
| 言語 | Ruby (3.4.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 42 ms / 1,000 ms | 
| コード長 | 1,437 bytes | 
| コンパイル時間 | 2,530 ms | 
| 実行使用メモリ | 4,848 KB | 
| スコア | 18,195 | 
| 最終ジャッジ日時 | 2018-05-26 03:10:11 | 
| ジャッジサーバーID (参考情報) | judge10 / | 
| 純コード判定しない問題か言語 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 32 | 
コンパイルメッセージ
Main.rb:42: warning: assigned but unused variable - size Syntax OK
ソースコード
N, K = gets.split.map &:to_i
L = gets.split.map &:to_i
LI = L.map.with_index{|l, i| [l, i]}.sort_by{|l, i| -l}
board = $<.map{|s|
  s.chomp.chars
}
$rows = board.map{|a| a*"" }
$cols = board.transpose.map{|a| a*"" }
def count_white
  $rows.map{|a|
    N - a.count(?1)
  }.sum
end
FirstScore = count_white
def calc_score
  count_white - FirstScore
end
# p FirstScore
# p calc_score()
$memo = []
def update_memo(re = /1{5,}/)
  $memo.clear()
  $rows.map.with_index{|s, i|
    s.scan(re){
      $memo << [:r, $&.size, i, $`.size]
    }
  }
  $cols.map.with_index{|s, i|
    s.scan(re){
      $memo << [:c, $&.size, i, $`.size]
    }
  }
  $memo.sort_by!{|sym, size, idx, pos| -size}
end
ans = []
LI.each{|l, i|
  update_memo(/1{#{l},}/) if $memo.empty?
  sym, size, idx, pos = $memo.shift
  if sym.nil?
    sym = [:r, :c].sample
    idx = rand(N)
    pos = rand(N)
  end
  pos = [N - l, pos].min
  if sym == :r
    t = $rows[idx][pos, l]
    $rows[idx][pos, l] = t.tr("01", "10")
    (pos...pos+l).each{|j|
      c = $cols[j][idx]
      $cols[j][idx] = c == ?1 ? ?0 : ?1
    }
    a = c = idx + 1
    b = pos + 1
    d = pos + l
  else
    t = $cols[idx][pos, l]
    $cols[idx][pos, l] = t.tr("01", "10")
    (pos...pos+l).each{|j|
      c = $rows[j][idx]
      $rows[j][idx] = c == ?1 ? ?0 : ?1
    }
    b = d = idx + 1
    a = pos + 1
    c = pos + l
  end
  ans[i] = [a, b, c, d]
}
ans.each{|a|
  puts a * " "
}
# p calc_score()
            
            
            
        