結果

問題 No.2042 RGB Caps
コンテスト
ユーザー Hydrogen332
提出日時 2026-07-01 14:22:37
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 971 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,928 ms
コンパイル使用メモリ 340,408 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2026-07-01 14:23:56
合計ジャッジ時間 4,168 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  
  const vector<char> col = {'R', 'G', 'B'};
  
  int N, K;
  cin >> N >> K;
  vector<pair<int, int>> P(K);
  for (int i = 0; i < K; i++) {
    char A;
    cin >> P[i].first >> A;
    P[i].first--;
    
    if (A == 'R') P[i].second = 0;
    else if (A == 'G') P[i].second = 1;
    else P[i].second = 2;
  }
  
  sort(P.begin(), P.end());
  
  vector<int> ans(N, -1);
  int idx = 0;
  for (int i = 0; i < N; i++) {
    int c = 0;
    
    if (idx < K && P[idx].first == i) {
      c = P[idx].second;
      idx++;
    }
    
    if (i % 3 == 1) {
      if (ans[i - 1] == c) c = (c + 1) % 3;
    } else if (i % 3 == 2) {
      while (true) {
        if (ans[i - 1] != c && ans[i - 2] != c) break;
        c = (c + 1) % 3;
      }
    }
    
    ans[i] = c;
  }
  
  for (int i = 0; i < N; i++) cout << col[ans[i]];
  cout << '\n';
}
0