結果
問題 | No.5002 stick xor |
ユーザー |
|
提出日時 | 2018-05-26 10:45:22 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 541 ms / 1,000 ms |
コード長 | 1,539 bytes |
コンパイル時間 | 16,993 ms |
実行使用メモリ | 5,380 KB |
スコア | 39,729 |
最終ジャッジ日時 | 2018-05-26 10:45:41 |
ジャッジサーバーID (参考情報) |
judge7 / |
純コード判定しない問題か言語 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 |
コンパイルメッセージ
Main.rb:56: warning: assigned but unused variable - size Syntax OK
ソースコード
DEBUG = falseN, K = gets.split.map &:to_iL = gets.split.map &:to_iLI = L.map.with_index{|l, i| [l, i]}.sort_by{|l, i| -l}board = $<.map{|s|s.chomp.chars.map &:to_i}$rows = board$cols = board.transposedef count_white$rows.map{|a|N - a.count(1)}.sumendFirstScore = count_whitedef calc_scorecount_white - FirstScoreendp FirstScore if DEBUGp calc_score() if DEBUGdef update_memo(len)max = 0res = nil$rows.each_with_index{|s, i|cusum = [sum = 0] + s.map{|c|sum += c}(0..N-len).each{|j|if cusum[j+len] - cusum[j] > maxmax = cusum[j+len] - cusum[j]res = [:r, max, i, j]return res if max >= lenend}}$cols.each_with_index{|s, i|cusum = [sum = 0] + s.map{|c|sum += c}(0..N-len).each{|j|if cusum[j+len] - cusum[j] > maxmax = cusum[j+len] - cusum[j]res = [:c, max, i, j]return res if max >= lenend}}resendans = []LI.each{|l, i|sym, size, idx, pos = update_memo(l)if sym.nil?sym = [:r, :c].sampleidx = rand(N)pos = rand(N)endpos = [N - l, pos].minif sym == :r(pos...pos+l).each{|j|$rows[idx][j] ^= 1$cols[j][idx] ^= 1}a = c = idx + 1b = pos + 1d = pos + lelse(pos...pos+l).each{|j|$cols[idx][j] ^= 1$rows[j][idx] ^= 1}b = d = idx + 1a = pos + 1c = pos + lendans[i] = [a, b, c, d]}ans.each{|a|puts a * " "}p calc_score() if DEBUG