結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 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 27 ms
4,348 KB
testcase_09 AC 6 ms
4,348 KB
testcase_10 AC 40 ms
4,348 KB
testcase_11 AC 6 ms
4,348 KB
testcase_12 AC 44 ms
4,348 KB
testcase_13 AC 44 ms
4,348 KB
testcase_14 AC 44 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 12 ms
4,348 KB
testcase_17 AC 5 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> mp;
    mp['R']=1<<0;
    mp['G']=1<<1;
    mp['B']=1<<2;
    map<int,char> revmp;
    for(auto [c,val]:mp){
        revmp[val]=c;
    }

    //vector<char> ans;

    auto without=[&](char c){

        if(c=='R'){ return 'G';}
        else if(c=='G'){ return 'B';}
        else return 'R';
    };

    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]のとき
                
                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(int i=1;i<=N;i++){
        if(i%3==1){
            //iを3で割ったあまりが1のケース
            ans.push_back(color[i-1]);
        }else if(i%3==2){
            if(ans.back()!=color[i-1]){
                ans.push_back(color[i-1]);
            }else{
                //color[i-1]以外
                ans.push_back(without(color[i-1]));
            }
        }else{
            int S=0;
            if(ans.size()>=2){
                S|=mp[ans[ans.size()-2]];
            }
            if(ans.size()>=1){
                S|=mp[ans[ans.back()]];
            }
            char c;
            for(int i=0;i<3;i++){
                if(((S>>i)&1)==0){
                    c=revmp[1<<i];
                }
            }
            ans.push_back(c);
        }
    }
    */

    for(char c:ans){
        cout<<c;
    }
    cout<<endl;




}
0