結果

問題 No.2307 [Cherry 5 th Tune *] Cool 46
ユーザー CoCo_Japan_panCoCo_Japan_pan
提出日時 2023-05-19 22:22:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 2,741 bytes
コンパイル時間 3,865 ms
コンパイル使用メモリ 227,836 KB
実行使用メモリ 7,316 KB
最終ジャッジ日時 2023-08-23 03:38:48
合計ジャッジ時間 27,929 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 50 ms
4,376 KB
testcase_03 AC 52 ms
4,376 KB
testcase_04 AC 52 ms
4,376 KB
testcase_05 AC 52 ms
4,376 KB
testcase_06 AC 51 ms
4,376 KB
testcase_07 AC 48 ms
4,380 KB
testcase_08 AC 56 ms
4,896 KB
testcase_09 AC 55 ms
4,696 KB
testcase_10 AC 55 ms
4,984 KB
testcase_11 AC 61 ms
4,996 KB
testcase_12 AC 53 ms
4,912 KB
testcase_13 AC 67 ms
5,264 KB
testcase_14 AC 56 ms
4,932 KB
testcase_15 AC 52 ms
4,380 KB
testcase_16 AC 60 ms
4,424 KB
testcase_17 AC 56 ms
4,940 KB
testcase_18 AC 69 ms
6,724 KB
testcase_19 AC 70 ms
6,132 KB
testcase_20 AC 68 ms
7,316 KB
testcase_21 AC 69 ms
7,052 KB
testcase_22 AC 69 ms
6,928 KB
testcase_23 AC 69 ms
6,980 KB
testcase_24 AC 69 ms
6,456 KB
testcase_25 AC 70 ms
6,524 KB
testcase_26 AC 69 ms
7,256 KB
testcase_27 AC 70 ms
6,920 KB
testcase_28 AC 70 ms
6,916 KB
testcase_29 AC 70 ms
7,176 KB
testcase_30 AC 70 ms
6,384 KB
testcase_31 AC 69 ms
7,312 KB
testcase_32 AC 68 ms
7,264 KB
testcase_33 AC 69 ms
7,292 KB
testcase_34 AC 69 ms
6,932 KB
testcase_35 AC 70 ms
6,392 KB
testcase_36 AC 69 ms
6,980 KB
testcase_37 AC 70 ms
6,652 KB
testcase_38 AC 41 ms
4,376 KB
testcase_39 AC 66 ms
4,376 KB
testcase_40 AC 45 ms
4,380 KB
testcase_41 AC 59 ms
4,380 KB
testcase_42 AC 69 ms
6,200 KB
testcase_43 AC 69 ms
6,132 KB
testcase_44 AC 45 ms
4,380 KB
testcase_45 AC 45 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 2 "/home/cocojapanpan/Procon_CPP/proconLibrary/lib/template/procon.hpp"

#ifndef DEBUG
// 提出時にassertはオフ
#ifndef NDEBUG
#define NDEBUG
#endif
// 定数倍高速化
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif

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

#define ALL(x) (x).begin(), (x).end()
template <class T>
using vec = vector<T>;
template <class T, class S>
inline bool chmax(T &a, const S &b) {
    return (a < b ? a = b, 1 : 0);
}
template <class T, class S>
inline bool chmin(T &a, const S &b) {
    return (a > b ? a = b, 1 : 0);
}
template <class T>
constexpr T INF = 1'000'000'000;
template <>
constexpr int INF<int> = 1'000'000'000;
template <>
constexpr ll INF<ll> = ll(INF<int>) * INF<int> * 2;
#line 2 "main.cpp"

void solve() {
    int N, M;
    cin >> N >> M;
    vec<int> A(N), B(M);
    for(int &a : A) cin >> a;
    for(int &b : B) cin >> b;
    if(M == 0) {
        cout << "Yes\n";
        for(int a : A) {
            cout << "Red " << a << "\n";
        }
        return;
    }
    if(N == 0) {
        cout << "Yes\n";
        for(int b : B) {
            cout << "Blue " << b << "\n";
        }
        return;
    }
    // 赤だけ、青だけ、共通の分離
    vec<int> RedOnly, BlueOnly, Common;
    {
        vec<pair<int, bool>> concat;
        for(int a : A) concat.push_back({a, true});
        for(int b : B) concat.push_back({b, false});
        sort(ALL(concat));
        for(int i = 0; i < N + M; i++) {
            if(i < N + M - 1 && concat[i].first == concat[i + 1].first) {
                Common.push_back(concat[i].first);
                i++;
            }
            else {
                if(concat[i].second) RedOnly.push_back(concat[i].first);
                else BlueOnly.push_back(concat[i].first);
            }
        }
    }
    if(Common.empty()) {
        cout << "No\n";
        return;
    }
    cout << "Yes\n";
    for(int red : RedOnly) {
        cout << "Red ";
        cout << red << "\n";
    }
    cout << "Red " << Common[0] << "\n";
    cout << "Blue " << Common[0] << "\n"; 
    for(int blue : BlueOnly) {
        cout << "Blue ";
        cout << blue << "\n";
    }
    for(int i = 1; i < (int)Common.size(); i++) {
        if(i % 2 == 0) {
            cout << "Red ";
        } else {
            cout << "Blue ";
        }
        cout << Common[i] << "\n";
        if(i % 2 == 0) {
            cout << "Blue ";
        } else {
            cout << "Red ";
        }
        cout << Common[i] << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    for(int i = 0; i < T; i++) {
        solve();
    }
}
0