結果

問題 No.2042 RGB Caps
ユーザー HIcoderHIcoder
提出日時 2023-07-18 22:12:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,714 bytes
コンパイル時間 1,332 ms
コンパイル使用メモリ 123,672 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 01:36:21
合計ジャッジ時間 5,879 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
権限があれば一括ダウンロードができます

ソースコード

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';
    };

    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