結果

問題 No.2042 RGB Caps
ユーザー HIcoderHIcoder
提出日時 2023-07-18 22:23:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 1,618 bytes
コンパイル時間 1,239 ms
コンパイル使用メモリ 117,424 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 01:47:53
合計ジャッジ時間 2,560 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<queue>
#include<cmath>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<int,int> P;
typedef pair<int,P> PP;
const ll MOD=998244353;
const double PI=acos(-1);


int main(){
    int N,K;
    cin>>N>>K;
    vector<int> A(K);
    vector<char> c(K);
    
    vector<char> color(N,'R');
    for(int i=0;i<K;i++){
        cin>>A[i]>>c[i];
        A[i]--;
        color[A[i]]=c[i];
    }



    map<char,int> idxcolor;
    vector<char> cvec={'R','G','B'};
    for(int i=0;i<3;i++){
        idxcolor[cvec[i]]=i;
    }

    vector<char> ans(N);

    for(int i=0;i<N;i++){
        if(i%3==0){
            //解説では3でわったあまりが1
            ans[i]=color[i];
        }else if(i%3==1){
            //解説では3でわったあまりが2
            //必ずi-1>=0
            if(ans[i-1]!=color[i]){
                ans[i]=color[i];
            }else{
                //ans[i-1]==color[i]のとき
                //R->G->B->R->G->B となるように, ans[i-1]がどの値かにより,次を決める
                
                ans[i]=cvec[(idxcolor[ans[i-1]]+1)%3];

            }
            
        }else{
            set<char> st={'R','G','B'};

            //i%3==2
            st.erase(ans[i-1]);
            st.erase(ans[i-2]);
            char c=*st.begin();
            //i-1番目,i-2番目とも被らない色
            ans[i]=c;
        }
    }
   
    for(char c:ans){
        cout<<c;
    }
    cout<<endl;




}
0