結果

問題 No.2307 [Cherry 5 th Tune *] Cool 46
ユーザー HIcoderHIcoder
提出日時 2023-07-08 15:09:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 546 ms / 2,000 ms
コード長 3,107 bytes
コンパイル時間 2,260 ms
コンパイル使用メモリ 117,056 KB
実行使用メモリ 21,564 KB
最終ジャッジ日時 2023-09-29 16:31:41
合計ジャッジ時間 42,063 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 253 ms
4,380 KB
testcase_03 AC 256 ms
4,376 KB
testcase_04 AC 258 ms
4,384 KB
testcase_05 AC 251 ms
4,376 KB
testcase_06 AC 256 ms
4,380 KB
testcase_07 AC 211 ms
4,376 KB
testcase_08 AC 295 ms
9,364 KB
testcase_09 AC 297 ms
7,376 KB
testcase_10 AC 274 ms
8,740 KB
testcase_11 AC 363 ms
9,448 KB
testcase_12 AC 261 ms
9,720 KB
testcase_13 AC 456 ms
10,920 KB
testcase_14 AC 301 ms
11,496 KB
testcase_15 AC 246 ms
8,040 KB
testcase_16 AC 360 ms
6,368 KB
testcase_17 AC 316 ms
10,128 KB
testcase_18 AC 470 ms
21,448 KB
testcase_19 AC 544 ms
17,972 KB
testcase_20 AC 503 ms
21,340 KB
testcase_21 AC 519 ms
21,320 KB
testcase_22 AC 466 ms
19,092 KB
testcase_23 AC 520 ms
14,376 KB
testcase_24 AC 505 ms
20,772 KB
testcase_25 AC 498 ms
19,648 KB
testcase_26 AC 513 ms
14,448 KB
testcase_27 AC 493 ms
21,564 KB
testcase_28 AC 505 ms
15,332 KB
testcase_29 AC 494 ms
21,332 KB
testcase_30 AC 532 ms
19,076 KB
testcase_31 AC 505 ms
21,348 KB
testcase_32 AC 502 ms
14,112 KB
testcase_33 AC 467 ms
21,396 KB
testcase_34 AC 491 ms
20,932 KB
testcase_35 AC 538 ms
20,704 KB
testcase_36 AC 512 ms
15,636 KB
testcase_37 AC 493 ms
21,528 KB
testcase_38 AC 357 ms
4,380 KB
testcase_39 AC 487 ms
4,376 KB
testcase_40 AC 369 ms
4,380 KB
testcase_41 AC 406 ms
4,376 KB
testcase_42 AC 546 ms
15,756 KB
testcase_43 AC 535 ms
15,924 KB
testcase_44 AC 443 ms
13,000 KB
testcase_45 AC 440 ms
13,056 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);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    for(int i=0;i<M;i++){
        cin>>B[i];
    }

    set<int> stA,stB;
    
    deque<pair<string,int>> deq;

    for(int i=0;i<N;i++){
        stA.insert(A[i]);
    }
    for(int i=0;i<M;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",B[i]);
                deq.emplace_back("Blue",B[i]);
                s^=1;
            }else{
                //s==1
                deq.emplace_back("Blue",B[i]);
                deq.emplace_back("Red",B[i]);
                s^=1;
            }

            stA.erase(B[i]);
            stB.erase(B[i]);
        }
    }

    if(flag){

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

        if(s==1){
            for(int v:stB){
                deq.emplace_back("Blue",v);
            }


            cout<<"Yes"<<endl;

            for(auto [str,v]:deq){
                cout<<str<<' '<<v<<endl;
            }
        }else{
            //s==0
            bool is= true;
            
            cout<<"Yes"<<endl;



            for(auto [str,v]:deq){

                cout<<str<<' '<<v<<endl;

                if(str=="Blue" && is){
                    is=false;
                    for(int v:stB){
                        cout<<"Blue"<<' '<<v<<endl;
                    }
                }
            }

        }


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

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

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

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

            for(int v:stA){
                deq.emplace_back("Red",v);
            }
        }
        */

    }else{

        //flag=false;
        
        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;
                }

            }
        }
    }



    
}


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