結果

問題 No.2042 RGB Caps
ユーザー t98slidert98slider
提出日時 2022-09-04 15:12:01
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 1,182 bytes
コンパイル時間 2,203 ms
コンパイル使用メモリ 177,076 KB
実行使用メモリ 4,464 KB
最終ジャッジ日時 2023-08-12 00:51:03
合計ジャッジ時間 5,056 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 7 ms
4,380 KB
testcase_07 AC 13 ms
4,380 KB
testcase_08 AC 26 ms
4,380 KB
testcase_09 AC 6 ms
4,384 KB
testcase_10 AC 37 ms
4,380 KB
testcase_11 AC 5 ms
4,380 KB
testcase_12 AC 41 ms
4,384 KB
testcase_13 AC 40 ms
4,464 KB
testcase_14 AC 40 ms
4,380 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 12 ms
4,380 KB
testcase_17 AC 5 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    int n, k, p;
    char c;
    cin >> n >> k;
    vector<vector<pair<int,char>>> tb(3);
    for(int i = 0; i < k; i++){
        cin >> p >> c;
        p--;
        tb[p % 3].emplace_back(p, c);
    }
    string ans(n, '?');
    for(int i = 0; i < tb[0].size(); i++){
        tie(p, c) = tb[0][i];
        if(ans[p] != '?'){
            cout << -1 << '\n';
            continue;
        }
        ans[p] = c;
    }
    for(int i = 0; i < tb[1].size(); i++){
        tie(p, c) = tb[1][i];
        if(ans[p - 1] == c)continue;
        if(ans[p] == c)continue;
        if(ans[p - 1] == '?')ans[p - 1] = c;
        else if(ans[p] == '?')ans[p] = c;
        else{
            cout << -1 << '\n';
            return 0;
        }
    }
    for(int i = 0; i < n; i += 3){
        set<char> S{'R','G','B'};
        for(int j = 0; j < 2; j++){
            if(ans[i + j] != '?')S.erase(ans[i + j]);
        }
        int j = i + 2;
        while(!S.empty()){
            if(j < ans.size())ans[j--] = *S.rbegin();
            else j--;
            S.erase(*S.rbegin());
        }
    }
    cout << ans << endl;
}
0