結果

問題 No.2042 RGB Caps
コンテスト
ユーザー tomerun
提出日時 2022-08-19 21:37:27
言語 Crystal
(1.19.1)
コンパイル:
crystal build -Donline_judge -o a.out --release --no-debug _filename_
実行:
./a.out
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 483 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 15,703 ms
コンパイル使用メモリ 337,928 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-05-11 05:46:39
合計ジャッジ時間 11,038 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_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