結果

問題 No.2307 [Cherry 5 th Tune *] Cool 46
ユーザー KKT89KKT89
提出日時 2023-05-19 22:46:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,094 bytes
コンパイル時間 3,236 ms
コンパイル使用メモリ 224,972 KB
実行使用メモリ 14,052 KB
最終ジャッジ日時 2024-06-01 01:30:37
合計ジャッジ時間 27,032 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 95 ms
6,940 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 157 ms
11,240 KB
testcase_19 WA -
testcase_20 AC 89 ms
6,944 KB
testcase_21 AC 89 ms
6,940 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 184 ms
12,412 KB
testcase_28 WA -
testcase_29 AC 117 ms
7,820 KB
testcase_30 WA -
testcase_31 AC 86 ms
6,944 KB
testcase_32 WA -
testcase_33 AC 196 ms
14,052 KB
testcase_34 AC 189 ms
13,532 KB
testcase_35 AC 161 ms
9,728 KB
testcase_36 WA -
testcase_37 AC 162 ms
10,632 KB
testcase_38 AC 48 ms
6,940 KB
testcase_39 AC 74 ms
5,376 KB
testcase_40 AC 50 ms
6,944 KB
testcase_41 AC 77 ms
5,376 KB
testcase_42 AC 140 ms
9,344 KB
testcase_43 AC 145 ms
9,416 KB
testcase_44 AC 52 ms
6,940 KB
testcase_45 AC 51 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

void slv() {
    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];
    }
    if (m == 0) {
        cout << "Yes" << "\n";
        for (int i = 0; i < n; ++i) {
            cout << "Red" << " " << a[i] << "\n";
        }
        return;
    }
    if (n == 0) {
        cout << "Yes" << "\n";
        for (int i = 0; i < m; ++i) {
            cout << "Blue" << " " << b[i] << "\n";
        }
        return;
    }
    vector<int> R,B,RB;
    set<int> st;
    for (int i = 0; i < n; ++i) {
        st.insert(a[i]);
    }
    for (int i = 0; i < m; ++i) {
        if (st.find(b[i]) != st.end()) {
            RB.push_back(b[i]);
            st.erase(b[i]);
        }
        else {
            B.push_back(b[i]);
        }
    }
    for (int i : st) {
        R.push_back(i);
    }

    if (RB.size() == 0) {
        cout << "No" << "\n";
        return;
    }
    else if (B.size() == 0) {
        cout << "Yes" << "\n";
        for (int i : R) {
            cout << "Red " << i << "\n";
        }
        for (int i = 0; i < RB.size(); ++i) {
            if (i%2 == 0) {
                cout << "Red " << RB[i] << "\n";
                cout << "Blue " << RB[i] << "\n";
            }
            else {
                cout << "Blue " << RB[i] << "\n";
                cout << "Red " << RB[i] << "\n";
            }
        }
        return;
    }
    else if (R.size() == 0) {
        cout << "Yes" << "\n";
        for (int i : B) {
            cout << "Blue " << i << "\n";
        }
        for (int i = 0; i < RB.size(); ++i) {
            if (i%2 == 1) {
                cout << "Red " << RB[i] << "\n";
                cout << "Blue " << RB[i] << "\n";
            }
            else {
                cout << "Blue " << RB[i] << "\n";
                cout << "Red " << RB[i] << "\n";
            }
        }
        return;
    }
    else if (RB.size() % 2 == 0) {
        auto p = RB.back(); RB.pop_back();
        R.push_back(p);
        B.push_back(p);
    }
    cout << "Yes" << "\n";
    for (int i : R) {
        cout << "Red " << i << "\n";
    }
    for (int i = 0; i < RB.size(); ++i) {
        if (i%2 == 0) {
            cout << "Red " << RB[i] << "\n";
            cout << "Blue " << RB[i] << "\n";
        }
        else {
            cout << "Blue " << RB[i] << "\n";
            cout << "Red " << RB[i] << "\n";
        }
    }
    for (int i : B) {
        cout << "Blue " << i << "\n";
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int q; cin >> q;
    while (q--) {
        slv();
    }
}
0