結果

問題 No.2307 [Cherry 5 th Tune *] Cool 46
ユーザー HIcoderHIcoder
提出日時 2023-07-08 14:50:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,315 bytes
コンパイル時間 2,629 ms
コンパイル使用メモリ 116,656 KB
実行使用メモリ 21,996 KB
最終ジャッジ日時 2023-09-29 16:09:45
合計ジャッジ時間 39,776 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
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 -
testcase_18 WA -
testcase_19 RE -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 RE -
testcase_29 RE -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 RE -
testcase_37 WA -
testcase_38 AC 371 ms
4,380 KB
testcase_39 AC 508 ms
4,380 KB
testcase_40 AC 388 ms
4,376 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 476 ms
21,616 KB
testcase_45 AC 466 ms
21,300 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<ll,ll> P;
typedef pair<int,P> PP;
const ll MOD=998244353;
const double PI=acos(-1);

void solve(){
    int N,M;
    cin>>N>>M;
    vector<int> A(N),B(M);
    set<int> stA,stB;
    
    deque<pair<string,int>> deq;

    for(int i=0;i<N;i++){
        cin>>A[i];
        stA.insert(A[i]);
    }
    for(int i=0;i<M;i++){
        cin>>B[i];
        stB.insert(B[i]);
    }

    bool flag=false;
    int s=0;

    for(int i=0;i<M;i++){
        
        if(stA.count(B[i])){//Aに B[i]が含まれる場合

            flag=true;
            if(s==0){
                deq.emplace_back("Red",A[i]);
                deq.emplace_back("Blue",B[i]);
                s^=1;
            }else{
                //s==1
                deq.emplace_back("Blue",B[i]);
                deq.emplace_back("Red",A[i]);
                s^=1;
            }
            stA.erase(A[i]);
            stB.erase(B[i]);
        }
    }

    if(s==0){
        //最初にredをfrontで全部いれて
        //最後にbackで全部入れる
        for(int v:stA){
            deq.emplace_front("Red",v);
        }

        for(int v:stB){
            deq.emplace_front("Blue",v);
        }

    }else{
        //最初にblueをfrontで全部いれて
        //最後にredで全部入れる

        for(int v:stB){
            deq.emplace_front("Blue",v);
        }

        for(int v:stA){
            deq.emplace_front("Red",v);
        }


    }

    if(!flag){
        if(N>0 && M>0){
            cout<<"No"<<endl;
        }else{
             cout<<"Yes"<<endl;

            if(N>0){
                for(int i=0;i<N;i++){
                    cout<<"Red"<<' '<<A[i]<<endl;
                }
            }else{
                //M>0
                for(int i=0;i<M;i++){
                    cout<<"Blue"<<' '<<B[i]<<endl;
                }

            }
        }
    }else{
        cout<<"Yes"<<endl;

        for(auto [str,v]:deq){
            cout<<str<<' '<<v<<endl;
        }

    }
    



    
}


int main(){
    int T;
    cin>>T;
    for(int t=0;t<T;t++){
        solve();

    }
}
0