結果

問題 No.2042 RGB Caps
ユーザー tomerun
提出日時 2022-08-19 21:37:27
言語 Crystal
(1.14.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 483 bytes
コンパイル時間 14,991 ms
コンパイル使用メモリ 295,456 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-16 01:54:46
合計ジャッジ時間 16,317 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

n, k = read_line.split.map(&.to_i)
cs = Array.new(n, -1)
k.times do
  a, c = read_line.split
  cs[a.to_i - 1] = "RGB".index(c).not_nil!
end
ans = [] of Int32
cnt = [0, 0, 0]
n.times do |i|
  min = 3.times.min_by { |i| cnt[i] }
  case i % 3
  when 0
    ans << (cs[i] == -1 ? 0 : cs[i])
  when 1
    if cs[i] == -1
      ans << min
    else
      ans << (ans[-1] == cs[i] ? min : cs[i])
    end
  when 2
    ans << min
  end
  cnt[ans[-1]] += 1
end
puts ans.map { |i| "RGB"[i] }.join
0