結果

問題 No.2307 [Cherry 5 th Tune *] Cool 46
ユーザー hongrock
提出日時 2023-05-19 21:44:44
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 1,901 bytes
コンパイル時間 1,981 ms
コンパイル使用メモリ 209,644 KB
最終ジャッジ日時 2025-02-13 01:41:40
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define rep(i, a, n) for(int i=(a); i<(n); ++i)
#define per(i, a, n) for(int i=(a); i>(n); --i)
#define pb emplace_back
#define mp make_pair
#define clr(a, b) memset(a, b, sizeof(a))
#define all(x) (x).begin(),(x).end()
#define lowbit(x) (x & -x)
#define fi first
#define se second
#define lson o<<1
#define rson o<<1|1
#define gmid l[o]+r[o]>>1
 
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll, ll>;
using ui = unsigned int;
 
constexpr int mod = 998244353;
constexpr int inf = 0x3f3f3f3f;
constexpr double EPS = 1e-8;
const double PI = acos(-1.0);

constexpr int N = 2e5 + 10;

int T, n, m, a[N], b[N];
set<int> st;
vector<pair<string,int>> ans;

bool ok(){
  st.clear();
  ans.clear();
  rep(i, 1, n + 1)  st.insert(a[i]);
  vector<int> same, x;
  rep(i, 1, m + 1){
    if(st.count(b[i])){
      same.pb(b[i]);
      st.erase(b[i]);
    } else {
      x.pb(b[i]);
    }
  }
  if(n && m && !same.size()){
    return 0;
  }
  if(!n){
    rep(i, 1, m + 1)  ans.pb("Blue", b[i]);
    return 1;
  }
  if(!m){
    rep(i, 1, n + 1)  ans.pb("Red", a[i]);
    return 1;
  }
  for(int v : st) ans.pb("Red", v);
  ans.pb("Red", same[0]);
  ans.pb("Blue", same[0]);
  for(int v : x)  ans.pb("Blue", v);
  rep(i, 1, same.size()){
    if(i & 1){
      ans.pb("Blue", same[i]);
      ans.pb("Red", same[i]);
    } else {
      ans.pb("Red", same[i]);
      ans.pb("Blue", same[i]);
    }
  }
  return 1;
}

void _main(){
  cin >> T;
  while(T--){
    cin >> n >> m;
    rep(i, 1, n + 1){
      cin >> a[i];
    }
    rep(i, 1, m + 1){
      cin >> b[i];
    }
    if(ok()){
      cout << "Yes\n";
      for(auto [s, v] : ans){
        cout << s << ' ' << v << '\n';
      }
    } else {
      cout << "No\n";
    }
  }
}

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  _main();
  return 0;
}
0