結果

問題 No.2307 [Cherry 5 th Tune *] Cool 46
ユーザー shobonvipshobonvip
提出日時 2023-05-19 21:38:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 1,976 bytes
コンパイル時間 4,901 ms
コンパイル使用メモリ 264,072 KB
実行使用メモリ 4,972 KB
最終ジャッジ日時 2023-08-23 02:39:27
合計ジャッジ時間 28,789 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 44 ms
4,376 KB
testcase_03 AC 49 ms
4,376 KB
testcase_04 AC 48 ms
4,380 KB
testcase_05 AC 47 ms
4,376 KB
testcase_06 AC 48 ms
4,380 KB
testcase_07 AC 45 ms
4,376 KB
testcase_08 AC 52 ms
4,380 KB
testcase_09 AC 52 ms
4,376 KB
testcase_10 AC 49 ms
4,380 KB
testcase_11 AC 57 ms
4,376 KB
testcase_12 AC 48 ms
4,380 KB
testcase_13 AC 61 ms
4,376 KB
testcase_14 AC 51 ms
4,380 KB
testcase_15 AC 47 ms
4,380 KB
testcase_16 AC 56 ms
4,380 KB
testcase_17 AC 52 ms
4,380 KB
testcase_18 AC 64 ms
4,376 KB
testcase_19 AC 66 ms
4,924 KB
testcase_20 AC 61 ms
4,380 KB
testcase_21 AC 63 ms
4,392 KB
testcase_22 AC 64 ms
4,376 KB
testcase_23 AC 62 ms
4,380 KB
testcase_24 AC 66 ms
4,556 KB
testcase_25 AC 66 ms
4,448 KB
testcase_26 AC 61 ms
4,380 KB
testcase_27 AC 65 ms
4,380 KB
testcase_28 AC 62 ms
4,380 KB
testcase_29 AC 62 ms
4,376 KB
testcase_30 AC 68 ms
4,932 KB
testcase_31 AC 61 ms
4,376 KB
testcase_32 AC 61 ms
4,380 KB
testcase_33 AC 63 ms
4,376 KB
testcase_34 AC 64 ms
4,432 KB
testcase_35 AC 67 ms
4,972 KB
testcase_36 AC 63 ms
4,376 KB
testcase_37 AC 64 ms
4,380 KB
testcase_38 AC 42 ms
4,376 KB
testcase_39 AC 67 ms
4,380 KB
testcase_40 AC 53 ms
4,376 KB
testcase_41 AC 58 ms
4,380 KB
testcase_42 AC 66 ms
4,852 KB
testcase_43 AC 66 ms
4,884 KB
testcase_44 AC 59 ms
4,376 KB
testcase_45 AC 60 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef modint998244353 mint;
typedef long long ll;

// importbisect
template <typename T>
int bisect_left(vector<T> &X, T v){
	return lower_bound(X.begin(), X.end(), v) - X.begin();
}

template <typename T>
int bisect_right(vector<T> &X, T v){
	return upper_bound(X.begin(), X.end(), v) - X.begin();
}
// -----


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

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());

	if (n == 0){
		cout << "Yes\n";
		for (int i=0; i<m; i++){
			cout << "Blue " << b[i] << "\n";
		}
		return;
	}

	if (m == 0){
		cout << "Yes\n";
		for (int i=0; i<n; i++){
			cout << "Red " << a[i] << "\n";
		}
		return;
	}
	
	vector<pair<int,int>> goodpair;
	vector<bool> usered(n), useblue(m);
	bool can = false;

	for (int i=0; i<n; i++){
		int tmp = bisect_left(b, a[i]);
		if (tmp < m && b[tmp] == a[i]){
			usered[i] = true;
			useblue[tmp] = true;
			goodpair.push_back(pair(i, tmp));
			can = true;
		}
	}

	if (!can){
		cout << "No\n";
		return;
	}

	cout << "Yes\n";

	for (int i=0; i<n; i++){
		if (!usered[i]){
			cout << "Red " << a[i] << "\n";
		}
	}

	int x = goodpair.back().first;
	int y = goodpair.back().second;

	goodpair.pop_back();

	cout << "Red " << a[x] << "\n";
	cout << "Blue " << b[y] << "\n";
	
	for (int i=0; i<m; i++){
		if (!useblue[i]){
			cout << "Blue " << b[i] << "\n";
		}
	}

	bool mode = true;
	while(!goodpair.empty()){
		x = goodpair.back().first;
		y = goodpair.back().second;

		goodpair.pop_back();
		if (mode){
			cout << "Blue " << b[y] << "\n";
			cout << "Red " << a[x] << "\n";
			mode = false;
		}else{
			cout << "Red " << a[x] << "\n";
			cout << "Blue " << b[y] << "\n";
			mode = true;
		}
	}
	
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int t; cin >> t;
	while(t--) solve();
}
0