結果

問題 No.2042 RGB Caps
コンテスト
ユーザー tomerun
提出日時 2022-08-19 21:37:27
言語 Crystal
(1.21.0 + ACL)
コンパイル:
crystal build -Donline_judge -o a.out --release --no-debug _filename_
実行:
./a.out
結果
AC  
実行時間 18 ms / 2,000 ms
+ 479µs
コード長 483 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 11,195 ms
コンパイル使用メモリ 329,496 KB
実行使用メモリ 9,904 KB
最終ジャッジ日時 2026-09-23 22:54:06
合計ジャッジ時間 13,457 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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