結果

問題 No.2042 RGB Caps
ユーザー 👑 hitonanodehitonanode
提出日時 2022-08-09 20:50:00
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 848 bytes
コンパイル時間 956 ms
コンパイル使用メモリ 89,824 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 05:37:15
合計ジャッジ時間 3,035 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,348 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 4 ms
4,348 KB
testcase_07 WA -
testcase_08 AC 10 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 13 ms
4,348 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 WA -
testcase_13 AC 14 ms
4,348 KB
testcase_14 AC 15 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 5 ms
4,348 KB
testcase_17 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

// WA
#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);
        }
    }
    ret.back() = 'G';
    cout << ret << endl;
}
0