結果

問題 No.606 カラフルタイル
ユーザー YosukeKawadaYosukeKawada
提出日時 2017-12-18 11:18:44
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,114 ms / 2,000 ms
コード長 883 bytes
コンパイル時間 296 ms
コンパイル使用メモリ 11,324 KB
実行使用メモリ 35,008 KB
最終ジャッジ日時 2023-08-22 05:22:46
合計ジャッジ時間 16,148 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
15,308 KB
testcase_01 AC 84 ms
15,156 KB
testcase_02 AC 582 ms
27,096 KB
testcase_03 AC 85 ms
15,116 KB
testcase_04 AC 86 ms
15,084 KB
testcase_05 AC 86 ms
15,328 KB
testcase_06 AC 85 ms
15,080 KB
testcase_07 AC 87 ms
15,032 KB
testcase_08 AC 84 ms
15,152 KB
testcase_09 AC 85 ms
15,080 KB
testcase_10 AC 86 ms
15,076 KB
testcase_11 AC 128 ms
16,100 KB
testcase_12 AC 85 ms
15,224 KB
testcase_13 AC 98 ms
15,348 KB
testcase_14 AC 598 ms
27,088 KB
testcase_15 AC 90 ms
15,468 KB
testcase_16 AC 217 ms
15,320 KB
testcase_17 AC 670 ms
24,312 KB
testcase_18 AC 575 ms
23,260 KB
testcase_19 AC 524 ms
22,804 KB
testcase_20 AC 1,114 ms
34,744 KB
testcase_21 AC 1,052 ms
34,052 KB
testcase_22 AC 1,031 ms
34,004 KB
testcase_23 AC 971 ms
30,232 KB
testcase_24 AC 964 ms
34,004 KB
testcase_25 AC 806 ms
31,064 KB
testcase_26 AC 869 ms
35,008 KB
testcase_27 AC 918 ms
34,848 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:37: warning: assigned but unused variable - color
Syntax OK

ソースコード

diff #

def readl
  $stdin.gets.split(" ")
end

N,K,Q = readl.map{ |r| r.to_i }

rows = (0...N).map{ [-1,1] }
cols = (0...N).map{ [-2,1] }

#p rows
#p cols

Q.times do |i|
  a,b,c = readl
  b = b.to_i
  c = c.to_i
  colorpair = [i,c]
  case a
  when "R"
    rows[b-1] = colorpair
  when "C"
    cols[b-1] = colorpair
  end
end

#p rows
#p cols

rows = rows.sort{ |a,b| a[0] <=> b[0] }
cols = cols.sort{ |a,b| a[0] <=> b[0] }

#p rows
#p cols

def count_wins(item, arr)
  i = item[0]
  color = item[1]

  # b-search

  mi,ma = 0,arr.size-1

  j = (mi+ma)/2
  if i <arr[j][0]
    ma = i
  else
    mi = i
  end

  #p [item, arr]
  if j = arr.bsearch_index{ |b| i < b[0] }
    j
  else
    arr.size
  end
end

color_count = (0...K).map{ 0 }

rows.each do |s|
  color_count[s[1]-1] += count_wins(s, cols)
end

cols.each do |s|
  color_count[s[1]-1] += count_wins(s, rows)
end


puts color_count
0