結果

問題 No.5002 stick xor
ユーザー letrangerjpletrangerjp
提出日時 2018-05-26 02:45:33
言語 Ruby
(3.3.0)
結果
AC  
実行時間 270 ms / 1,000 ms
コード長 1,412 bytes
コンパイル時間 9,037 ms
実行使用メモリ 5,048 KB
スコア 27,829
最終ジャッジ日時 2018-05-26 02:45:44
ジャッジサーバーID
(参考情報)
judge9 /
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 212 ms
5,024 KB
testcase_01 AC 200 ms
5,016 KB
testcase_02 AC 253 ms
4,996 KB
testcase_03 AC 223 ms
4,988 KB
testcase_04 AC 201 ms
5,028 KB
testcase_05 AC 215 ms
5,008 KB
testcase_06 AC 234 ms
5,036 KB
testcase_07 AC 253 ms
4,952 KB
testcase_08 AC 258 ms
5,004 KB
testcase_09 AC 215 ms
5,020 KB
testcase_10 AC 220 ms
5,008 KB
testcase_11 AC 223 ms
5,000 KB
testcase_12 AC 245 ms
4,948 KB
testcase_13 AC 217 ms
4,976 KB
testcase_14 AC 220 ms
5,048 KB
testcase_15 AC 219 ms
4,996 KB
testcase_16 AC 187 ms
5,016 KB
testcase_17 AC 232 ms
4,996 KB
testcase_18 AC 214 ms
4,924 KB
testcase_19 AC 235 ms
5,032 KB
testcase_20 AC 226 ms
5,024 KB
testcase_21 AC 243 ms
4,996 KB
testcase_22 AC 220 ms
5,020 KB
testcase_23 AC 254 ms
4,980 KB
testcase_24 AC 254 ms
5,000 KB
testcase_25 AC 246 ms
5,024 KB
testcase_26 AC 270 ms
4,936 KB
testcase_27 AC 255 ms
5,004 KB
testcase_28 AC 229 ms
5,008 KB
testcase_29 AC 258 ms
5,016 KB
testcase_30 AC 258 ms
4,932 KB
testcase_31 AC 240 ms
5,012 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:43: warning: assigned but unused variable - size
Syntax OK

ソースコード

diff #

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
  $memo.clear()
  re = /1{3,}/
  $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()
  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()
0