結果

問題 No.2307 [Cherry 5 th Tune *] Cool 46
ユーザー gyozasukisukigyozasukisuki
提出日時 2023-05-19 22:45:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 539 ms / 2,000 ms
コード長 2,418 bytes
コンパイル時間 1,995 ms
コンパイル使用メモリ 174,884 KB
実行使用メモリ 13,016 KB
最終ジャッジ日時 2023-08-23 03:55:04
合計ジャッジ時間 43,345 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 257 ms
4,380 KB
testcase_03 AC 263 ms
4,380 KB
testcase_04 AC 259 ms
4,376 KB
testcase_05 AC 249 ms
4,376 KB
testcase_06 AC 261 ms
4,380 KB
testcase_07 AC 215 ms
4,380 KB
testcase_08 AC 329 ms
6,776 KB
testcase_09 AC 329 ms
7,400 KB
testcase_10 AC 283 ms
7,356 KB
testcase_11 AC 382 ms
6,992 KB
testcase_12 AC 276 ms
6,740 KB
testcase_13 AC 459 ms
7,604 KB
testcase_14 AC 331 ms
7,728 KB
testcase_15 AC 256 ms
5,856 KB
testcase_16 AC 372 ms
5,912 KB
testcase_17 AC 322 ms
7,288 KB
testcase_18 AC 503 ms
12,856 KB
testcase_19 AC 531 ms
12,704 KB
testcase_20 AC 506 ms
12,856 KB
testcase_21 AC 516 ms
12,864 KB
testcase_22 AC 509 ms
12,860 KB
testcase_23 AC 512 ms
12,784 KB
testcase_24 AC 537 ms
13,016 KB
testcase_25 AC 524 ms
13,016 KB
testcase_26 AC 501 ms
12,748 KB
testcase_27 AC 515 ms
12,748 KB
testcase_28 AC 511 ms
12,820 KB
testcase_29 AC 502 ms
12,788 KB
testcase_30 AC 537 ms
12,892 KB
testcase_31 AC 508 ms
12,748 KB
testcase_32 AC 494 ms
12,704 KB
testcase_33 AC 539 ms
12,736 KB
testcase_34 AC 534 ms
12,768 KB
testcase_35 AC 524 ms
12,796 KB
testcase_36 AC 517 ms
12,976 KB
testcase_37 AC 502 ms
12,764 KB
testcase_38 AC 355 ms
4,380 KB
testcase_39 AC 495 ms
4,376 KB
testcase_40 AC 380 ms
4,376 KB
testcase_41 AC 403 ms
4,376 KB
testcase_42 AC 521 ms
12,884 KB
testcase_43 AC 516 ms
12,748 KB
testcase_44 AC 510 ms
12,864 KB
testcase_45 AC 507 ms
12,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
using namespace std;
const int INF = 1e9;
using ll = long long;
using inv = vector<int>;
using stv = vector<string>;
using pint = pair<int,int>;
#define FOR(i,l,r) for(int i=(l); i<(r); i++)
#define rep(i,r) for(int i=0; i<(r); i++)
#define repl(i,r) for(long long i=0; i<(r); i++)
#define FORl(i,l,r) for(long long i=(l); i<(r); i++)
#define INFL ((1LL<<62)-(1LL<<31))
#define pb(x) push_back(x)
#define CIN(x) cin >> x

int main(){
  int T;
  cin >> T;

  rep(q,T){
    int N,M;
    cin >> N >> M;

    set<ll> A,B;
    rep(i,N){
      ll c;
      cin >> c;
      A.insert(c);
    } 
    rep(i,M){
      ll c;
      cin >> c;
      B.insert(c);
    }

    if(!N || !M){
      if(!N){
        cout << "Yes" << endl;
        for(auto b: B){
          cout << "Blue " << b << endl;

        }
        continue;
      }else{
        cout << "Yes" << endl;
        for(auto a: A){
          cout << "Red " << a << endl;
        }
        continue;
      }

    }

    set<ll> S; // 共通のやつ

    for(auto C:A){
      if(B.find(C) != B.end()){
        S.insert(C);
        B.erase(C);
        
      }
    }
    for(auto s:S) A.erase(s);

    if(S.empty() && !A.empty() && !B.empty()){
      cout << "No" << endl;
      continue;
    }
    
    cout << "Yes" << endl;

    bool nowA = true;

    if(A.empty()){      
      nowA = false;
    }
    if(B.empty()){
      nowA = true;
    }

    if(!nowA){
      for(auto b:B){
        cout << "Blue " << b << endl;
      }
      for(auto s:S){
        cout << (nowA ? "Red ":"Blue ") << s << endl;
        cout << (!nowA ? "Red ":"Blue ") << s << endl;
        nowA = !nowA;
      }
      continue;
    }
    else if(B.empty()){
      for(auto a:A){
        cout << "Red " << a << endl;
      }
      for(auto s:S){
        cout << (nowA ? "Red ":"Blue ") << s << endl;
        cout << (!nowA ? "Red ":"Blue ") << s << endl;
        nowA = !nowA;
      }
      continue;
    }else{
      bool first = true;
      for(auto a:A){
        cout << "Red " << a << endl;
      }
      for(auto s:S){
        cout << (nowA ? "Red ":"Blue ") << s << endl;
        cout << (!nowA ? "Red ":"Blue ") << s << endl;
        if(first){
          for(auto b: B){
            cout << "Blue " << b << endl;
          }
        }
        nowA = !nowA;

        first = false;
      }
    }


  }
  return 0;
}
0