結果

問題 No.2307 [Cherry 5 th Tune *] Cool 46
ユーザー AnchorBluesAnchorBlues
提出日時 2023-09-29 14:58:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 536 ms / 2,000 ms
コード長 2,735 bytes
コンパイル時間 3,873 ms
コンパイル使用メモリ 209,796 KB
実行使用メモリ 26,820 KB
最終ジャッジ日時 2023-09-29 14:59:07
合計ジャッジ時間 45,893 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 203 ms
4,384 KB
testcase_03 AC 212 ms
4,376 KB
testcase_04 AC 208 ms
4,380 KB
testcase_05 AC 199 ms
4,376 KB
testcase_06 AC 207 ms
4,376 KB
testcase_07 AC 167 ms
4,380 KB
testcase_08 AC 289 ms
9,488 KB
testcase_09 AC 260 ms
7,244 KB
testcase_10 AC 217 ms
7,260 KB
testcase_11 AC 335 ms
10,804 KB
testcase_12 AC 214 ms
6,852 KB
testcase_13 AC 396 ms
8,116 KB
testcase_14 AC 264 ms
7,828 KB
testcase_15 AC 189 ms
5,900 KB
testcase_16 AC 314 ms
6,008 KB
testcase_17 AC 263 ms
9,496 KB
testcase_18 AC 436 ms
12,844 KB
testcase_19 AC 520 ms
24,216 KB
testcase_20 AC 417 ms
12,736 KB
testcase_21 AC 465 ms
15,084 KB
testcase_22 AC 420 ms
12,776 KB
testcase_23 AC 446 ms
14,152 KB
testcase_24 AC 493 ms
18,000 KB
testcase_25 AC 460 ms
15,264 KB
testcase_26 AC 421 ms
12,776 KB
testcase_27 AC 449 ms
14,404 KB
testcase_28 AC 453 ms
14,520 KB
testcase_29 AC 432 ms
13,168 KB
testcase_30 AC 509 ms
22,352 KB
testcase_31 AC 432 ms
12,708 KB
testcase_32 AC 423 ms
12,752 KB
testcase_33 AC 451 ms
12,692 KB
testcase_34 AC 499 ms
16,012 KB
testcase_35 AC 523 ms
22,712 KB
testcase_36 AC 473 ms
16,712 KB
testcase_37 AC 436 ms
14,412 KB
testcase_38 AC 179 ms
4,376 KB
testcase_39 AC 287 ms
4,380 KB
testcase_40 AC 320 ms
4,376 KB
testcase_41 AC 379 ms
4,376 KB
testcase_42 AC 531 ms
26,772 KB
testcase_43 AC 536 ms
26,820 KB
testcase_44 AC 471 ms
12,700 KB
testcase_45 AC 430 ms
12,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;

const ll INF = 1LL << 60;

template <class T>
void chmax(T& a, T b) {
    if (b > a) a = b;
}
template <class T>
void chmin(T& a, T b) {
    if (b < a) a = b;
}

template <typename T, typename S>
std::ostream& operator<<(std::ostream& os, const pair<T, S>& x) noexcept {
    return os << "(" << x.first << ", " << x.second << ")";
}

template <typename T>
void print_vector(vector<T> a) {
    cout << '[';
    for (int i = 0; i < a.size(); i++) {
        cout << a[i];
        if (i != a.size() - 1) {
            cout << ", ";
        }
    }
    cout << ']' << endl;
}

void solve() {
    ll N, M;
    cin >> N >> M;
    set<ll> A, B, AB;
    for (int i = 0; i < N; i++) {
        ll a;
        cin >> a;
        A.insert(a);
    }
    for (int j = 0; j < M; j++) {
        ll b;
        cin >> b;
        B.insert(b);
    }
    for (auto& v : A) {
        if (B.count(v)) AB.insert(v);
    }
    // std::cout << N << ' ' << M << "\n";
    // std::cout << A.size() << ' ' << B.size() << endl;
    // std::cout << AB.size() << "\n";
    if (AB.size() == 0 && A.size() > 0 && B.size() > 0) {
        std::cout << "No"
                  << "\n";
        return;
    }
    set<ll> to_be_removed_A, to_be_removed_B;
    for (auto& v : A) {
        if (AB.count(v)) {
            to_be_removed_A.insert(v);
        }
    }
    for (auto& v : B) {
        if (AB.count(v)) {
            to_be_removed_B.insert(v);
        }
    }
    for (auto& v : to_be_removed_A) {
        A.erase(v);
    }
    for (auto& v : to_be_removed_B) {
        B.erase(v);
    }
    // ここから答え出力
    std::cout << "Yes"
              << "\n";
    for (auto& v : A) {
        std::cout << "Red" << ' ' << v << endl;
    }
    if (AB.size() > 0) {
        auto it = AB.begin();
        auto u = *it;
        std::cout << "Red" << ' ' << u << endl;
        std::cout << "Blue" << ' ' << u << endl;
        AB.erase(it);
    }
    for (auto& v : B) {
        std::cout << "Blue" << ' ' << v << endl;
    }
    bool blue = true;
    for (auto& v : AB) {
        if (blue) {
            std::cout << "Blue" << ' ' << v << endl;
            std::cout << "Red" << ' ' << v << endl;
        } else {
            std::cout << "Red" << ' ' << v << endl;
            std::cout << "Blue" << ' ' << v << endl;
        }
        blue = blue ^ true;
    }
}

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int T;
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}
0