結果

問題 No.2042 RGB Caps
ユーザー hitonanode
提出日時 2022-08-09 20:49:10
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 820 bytes
コンパイル時間 1,046 ms
コンパイル使用メモリ 90,016 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-16 01:52:06
合計ジャッジ時間 1,853 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;


int main() {
    cin.tie(nullptr), ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    const string RGB = "RGB";
    string target(N, '_');

    while (K--) {
        int i;
        char c;
        cin >> i >> c;
        target[i - 1] = c;
    }

    string ret;

    string rem;
    for (int i = 0; i < N; ++i) {
        if (i % 3 == 0) rem = RGB;

        auto addchar = [&](char c) -> void {
            ret += c;
            auto itr = std::find(rem.begin(), rem.end(), c);
            rem.erase(itr);
        };

        if (count(rem.begin(), rem.end(), target[i])) {
            addchar(target[i]);
        } else {
            char c = rem.front();
            addchar(c);
        }
    }
    cout << ret << endl;
}
0