結果

問題 No.2042 RGB Caps
ユーザー simansiman
提出日時 2022-08-20 18:32:11
言語 Ruby
(3.3.0)
結果
AC  
実行時間 358 ms / 2,000 ms
コード長 2,311 bytes
コンパイル時間 62 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 30,208 KB
最終ジャッジ日時 2024-04-27 20:37:36
合計ジャッジ時間 3,892 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
12,032 KB
testcase_01 AC 81 ms
12,160 KB
testcase_02 AC 72 ms
12,160 KB
testcase_03 AC 73 ms
12,288 KB
testcase_04 AC 71 ms
12,288 KB
testcase_05 AC 71 ms
12,288 KB
testcase_06 AC 135 ms
18,432 KB
testcase_07 AC 159 ms
17,024 KB
testcase_08 AC 250 ms
23,168 KB
testcase_09 AC 105 ms
13,824 KB
testcase_10 AC 314 ms
28,288 KB
testcase_11 AC 115 ms
14,080 KB
testcase_12 AC 350 ms
30,208 KB
testcase_13 AC 348 ms
29,824 KB
testcase_14 AC 358 ms
29,952 KB
testcase_15 AC 79 ms
12,288 KB
testcase_16 AC 152 ms
17,024 KB
testcase_17 AC 97 ms
13,056 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:11: warning: assigned but unused variable - a
Syntax OK

ソースコード

diff #

N, K = gets.split.map(&:to_i)
Q = K.times.map { a, c = gets.chomp.split; [a.to_i, c] }
Q.sort_by! { |a, c| a }

ans = []
counter = Hash.new(0)

1.upto(N) do |n|
  if Q.size > 0
    if n == Q[0][0]
      a, c = Q.shift

      case c
      when 'R'
        if counter['R'] == counter['G'] && counter['G'] == counter['B']
          ans << 'R'
          counter['R'] += 1
        else
          if counter['G'] < counter['R']
            ans << 'G'
            counter['G'] += 1
          elsif counter['B'] < counter['R']
            ans << 'B'
            counter['B'] += 1
          else
            ans << 'R'
            counter['R'] += 1
          end
        end
      when 'G'
        if counter['R'] == counter['G'] && counter['G'] == counter['B']
          ans << 'G'
          counter['G'] += 1
        else
          if counter['R'] < counter['G']
            ans << 'R'
            counter['R'] += 1
          elsif counter['B'] < counter['G']
            ans << 'B'
            counter['B'] += 1
          else
            ans << 'G'
            counter['G'] += 1
          end
        end
      when 'B'
        if counter['R'] == counter['G'] && counter['G'] == counter['B']
          ans << 'B'
          counter['B'] += 1
        else
          if counter['R'] < counter['B']
            ans << 'R'
            counter['R'] += 1
          elsif counter['G'] < counter['B']
            ans << 'G'
            counter['G'] += 1
          else
            ans << 'B'
            counter['B'] += 1
          end
        end
      end
    else
      if counter['R'] < counter['G'] && counter['R'] < counter['B']
        ans << 'R'
        counter['R'] += 1
      elsif counter['G'] < counter['R'] && counter['G'] < counter['B']
        ans << 'G'
        counter['G'] += 1
      elsif counter['B'] < counter['R'] && counter['B'] < counter['G']
        ans << 'B'
        counter['B'] += 1
      else
        if counter['R'] < counter['G'] || counter['R'] < counter['B']
          ans << 'R'
          counter['R'] += 1
        elsif counter['G'] < counter['R'] || counter['G'] < counter['B']
          ans << 'G'
          counter['G'] += 1
        else
          ans << 'B'
          counter['B'] += 1
        end
      end
    end
  else
    ans << 'R'
    counter['R'] += 1
  end
end

puts ans.join
0