結果

問題 No.2042 RGB Caps
ユーザー baLoon8128baLoon8128
提出日時 2022-08-19 21:49:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 1,403 bytes
コンパイル時間 4,039 ms
コンパイル使用メモリ 234,008 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-27 20:32:54
合計ジャッジ時間 4,598 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 3 ms
6,944 KB
testcase_07 AC 14 ms
6,944 KB
testcase_08 AC 27 ms
6,940 KB
testcase_09 AC 6 ms
6,940 KB
testcase_10 AC 41 ms
6,940 KB
testcase_11 AC 4 ms
6,940 KB
testcase_12 AC 45 ms
6,944 KB
testcase_13 AC 43 ms
6,940 KB
testcase_14 AC 45 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 11 ms
6,940 KB
testcase_17 AC 4 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repr(i, n) for (int i = (int)(n - 1); i >= 0; --i)

int main() {
    const string str = "BRG";
    int n, K;
    cin >> n >> K;
    vector<pii> p(K);
    rep(i, K) {
        int k;
        char c;
        cin >> k >> c, k--;
        p[i] = pii(k, (int)c % 3);
    }
    sort(p.begin(), p.end());

    string ret = "";
    vector<bool> mx(3, false);
    for (int i = 0, k = 0; i < n; i++) {
        if (i % 3 == 0) {
            rep(j, 3) mx[j] = false;
        }
        if (k < K && p[k].first == i) {
            int c = p[k].second;
            if (!mx[c]) {
                mx[c] = true;
                ret += str[c];
            } else {
                rep(j, 3) {
                    if (!mx[j]) {
                        mx[j] = true;
                        ret += str[j];
                        break;
                    }
                }
            }
            k++;
        } else {
            rep(j, 3) {
                if (!mx[j]) {
                    mx[j] = true;
                    ret += str[j];
                    break;
                }
            }
        }
    }
    cout << ret << endl;
    return 0;
}
0