結果

問題 No.2042 RGB Caps
ユーザー erbowlerbowl
提出日時 2022-08-20 08:02:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 1,354 bytes
コンパイル時間 2,178 ms
コンパイル使用メモリ 209,456 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-27 20:37:03
合計ジャッジ時間 2,836 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
    ll n,k;
    std::cin >> n>>k;
    vector<vector<pair<ll,char>>> ama(2);
    for (int i = 0; i < k; i++) {
        ll a;
        char c;
        std::cin >> a>>c;
        if(a%3==1){
            ama[0].push_back({a,c});
        }else if(a%3==2){
            ama[1].push_back({a,c});
        }
    }
    string ans = "";
    for (int i = 0; i < n; i++) {
        ans.push_back('.');
    }
    for (auto e : ama[0]) {
        auto [a,c] = e;
        ans[a-1] = c;
    }
    for (auto e : ama[1]) {
        auto [a,c] = e;
        if(ans[a-2]==c)continue;
        if(ans[a-2]=='.'){
            ans[a-2]=c;
        }else{
            ans[a-1]=c;
        }
    }
    vector<ll> cnt(3);

    for (int i = 0; i < n; i++) {
        if(ans[i]=='.'){
            if(cnt[0]<=cnt[1]&&cnt[0]<=cnt[2]){
                ans[i] = 'R';
                cnt[0]++;
            }else if(cnt[1]<=cnt[0]&&cnt[1]<=cnt[2]){
                ans[i]= 'G';
                cnt[1]++;
            }else{
                ans[i]='B';
                cnt[2]++;
            }
        }else{
            if(ans[i]=='R')cnt[0]++;
            if(ans[i]=='G')cnt[1]++;
            if(ans[i]=='B')cnt[2]++;
        }
    }
    std::cout << ans << std::endl;
}
0