結果

問題 No.2307 [Cherry 5 th Tune *] Cool 46
ユーザー norikamenorikame
提出日時 2023-05-19 22:04:55
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 515 ms / 2,000 ms
コード長 1,985 bytes
コンパイル時間 5,714 ms
コンパイル使用メモリ 318,592 KB
実行使用メモリ 17,080 KB
最終ジャッジ日時 2023-08-23 03:16:39
合計ジャッジ時間 43,078 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 247 ms
4,380 KB
testcase_03 AC 240 ms
4,376 KB
testcase_04 AC 241 ms
4,376 KB
testcase_05 AC 228 ms
4,376 KB
testcase_06 AC 243 ms
4,376 KB
testcase_07 AC 198 ms
4,384 KB
testcase_08 AC 261 ms
8,232 KB
testcase_09 AC 262 ms
7,220 KB
testcase_10 AC 232 ms
8,516 KB
testcase_11 AC 319 ms
8,500 KB
testcase_12 AC 230 ms
7,764 KB
testcase_13 AC 386 ms
8,492 KB
testcase_14 AC 270 ms
9,464 KB
testcase_15 AC 211 ms
6,448 KB
testcase_16 AC 323 ms
6,336 KB
testcase_17 AC 270 ms
8,692 KB
testcase_18 AC 427 ms
15,268 KB
testcase_19 AC 436 ms
16,188 KB
testcase_20 AC 439 ms
17,080 KB
testcase_21 AC 455 ms
17,032 KB
testcase_22 AC 432 ms
15,092 KB
testcase_23 AC 436 ms
16,824 KB
testcase_24 AC 428 ms
15,404 KB
testcase_25 AC 425 ms
15,496 KB
testcase_26 AC 418 ms
15,024 KB
testcase_27 AC 429 ms
15,268 KB
testcase_28 AC 415 ms
15,408 KB
testcase_29 AC 420 ms
15,460 KB
testcase_30 AC 444 ms
15,344 KB
testcase_31 AC 449 ms
16,916 KB
testcase_32 AC 443 ms
16,888 KB
testcase_33 AC 446 ms
16,556 KB
testcase_34 AC 464 ms
17,012 KB
testcase_35 AC 438 ms
16,188 KB
testcase_36 AC 425 ms
15,136 KB
testcase_37 AC 411 ms
15,168 KB
testcase_38 AC 371 ms
4,380 KB
testcase_39 AC 515 ms
4,376 KB
testcase_40 AC 377 ms
4,380 KB
testcase_41 AC 387 ms
4,376 KB
testcase_42 AC 435 ms
13,912 KB
testcase_43 AC 427 ms
15,324 KB
testcase_44 AC 446 ms
16,360 KB
testcase_45 AC 430 ms
16,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 

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

using ll = long long;

#define rep(i, n) for (int i=0; i<(int)(n); ++(i))
#define rep3(i, m, n) for (int i=(m); (i)<(int)(n); ++(i))
#define repr(i, n) for (int i=(int)(n)-1; (i)>=0; --(i))
#define rep3r(i, m, n) for (int i=(int)(n)-1; (i)>=(int)(m); --(i))
#define all(x) (x).begin(), (x).end()

const int INF = (int)(1e9);

int main() {
	int t0;
	cin >> t0;
	rep(i0, t0) {
		int n, m;
		cin >> n >> m;
		vector<int> a(n), b(m);
		rep(i, n) cin >> a[i];
		rep(i, m) cin >> b[i];
		unordered_set<int> ast(all(a)), bst(all(b));
		vector<int> clst;
		for (auto itr=ast.begin(); itr!=ast.end(); ) {
			if (bst.find(*itr) != bst.end()) {
				clst.push_back(*itr);
				bst.erase(*itr);
				itr = ast.erase(itr);
			}
			else ++itr;
		}
		vector<pair<bool, int>> res;
		if (clst.empty()) {
			if (!ast.empty() && !bst.empty()) {
				cout << "No" << endl;
				continue;
			}
			else if (ast.empty()) {
				for (const int& vi : bst) res.emplace_back(true, vi);
			}
			else {
				for (const int& vi : ast) res.emplace_back(false, vi);
			}
		}
		else {
			for (const int& vi : clst) {
				if ((int)(res.size())/2%2 == 0) {
					res.emplace_back(false, vi);
					res.emplace_back(true, vi);
				}
				else {
					res.emplace_back(true, vi);
					res.emplace_back(false, vi);
				}
			}
			auto tmp2 = res.back();
			res.pop_back();
			auto tmp1 = res.back();
			res.pop_back();
			if (!tmp1.first) {
				for (const int& vi : ast) res.emplace_back(false, vi);
				res.push_back(tmp1);
				res.push_back(tmp2);
				for (const int& vi : bst) res.emplace_back(true, vi);
			}
			else {
				for (const int& vi : bst) res.emplace_back(true, vi);
				res.push_back(tmp1);
				res.push_back(tmp2);
				for (const int& vi : ast) res.emplace_back(false, vi);
			}
		}
		cout << "Yes" << endl;
		for (const auto& pi : res) cout << (!pi.first ? "Red" : "Blue") << ' ' << pi.second << endl;
	}
	return 0;
}
0