結果

問題 No.606 カラフルタイル
ユーザー YosukeKawadaYosukeKawada
提出日時 2017-12-18 15:09:24
言語 Ruby
(3.3.0)
結果
AC  
実行時間 595 ms / 2,000 ms
コード長 908 bytes
コンパイル時間 71 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 64,000 KB
最終ジャッジ日時 2024-05-09 11:21:54
合計ジャッジ時間 9,130 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 102 ms
12,160 KB
testcase_01 AC 95 ms
12,288 KB
testcase_02 AC 95 ms
12,288 KB
testcase_03 AC 95 ms
12,160 KB
testcase_04 AC 94 ms
12,160 KB
testcase_05 AC 95 ms
12,288 KB
testcase_06 AC 97 ms
12,032 KB
testcase_07 AC 93 ms
12,160 KB
testcase_08 AC 94 ms
12,288 KB
testcase_09 AC 95 ms
12,160 KB
testcase_10 AC 94 ms
12,160 KB
testcase_11 AC 93 ms
12,288 KB
testcase_12 AC 94 ms
12,160 KB
testcase_13 AC 123 ms
15,872 KB
testcase_14 AC 94 ms
12,288 KB
testcase_15 AC 96 ms
12,416 KB
testcase_16 AC 436 ms
53,120 KB
testcase_17 AC 572 ms
62,976 KB
testcase_18 AC 481 ms
59,264 KB
testcase_19 AC 455 ms
58,112 KB
testcase_20 AC 595 ms
61,312 KB
testcase_21 AC 473 ms
58,752 KB
testcase_22 AC 475 ms
58,880 KB
testcase_23 AC 474 ms
57,856 KB
testcase_24 AC 541 ms
59,264 KB
testcase_25 AC 515 ms
54,784 KB
testcase_26 AC 573 ms
64,000 KB
testcase_27 AC 570 ms
62,848 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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

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

rows = []
rd = {}
cols = []
cd = {}

#p rows
#p cols

(0...Q).map{ |i| [i, *(readl)] }.reverse.each{ |l|
  i,a,b,c = l
  b = b.to_i
  c = c.to_i
  colorpair = [i,c]
  case a
  when "R"
    next if rd.key?(b)
    rows << colorpair
    rd[b] = 1
  when "C"
    next if cd.key?(b)
    cols << colorpair
    cd[b] = 1
  end
}

rows.reverse!
cols.reverse!

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

BR = N - rows.size
BC = N - cols.size

color_count[0] += BR*BC

i,j = 0,0
while i < rows.size || j < cols.size
  if i == rows.size
    color_count[cols[j][1]-1] += BR+i
    j += 1
    next
  end
  
  if j == cols.size
    color_count[rows[i][1]-1] += BC+j
    i += 1
    next
  end
  
  r = rows[i]
  c = cols[j]
  if r[0] < c[0]
    color_count[r[1]-1] += BC+j
    i += 1
  else
    color_count[c[1]-1] += BR+i
    j += 1
  end
end

puts color_count
0