結果

問題 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,016 ms
コンパイル使用メモリ 221,460 KB
実行使用メモリ 13,708 KB
最終ジャッジ日時 2023-08-23 03:49:59
合計ジャッジ時間 26,904 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 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 89 ms
6,212 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 148 ms
11,056 KB
testcase_19 WA -
testcase_20 AC 86 ms
6,036 KB
testcase_21 AC 82 ms
5,940 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 155 ms
12,304 KB
testcase_28 WA -
testcase_29 AC 102 ms
7,624 KB
testcase_30 WA -
testcase_31 AC 81 ms
6,172 KB
testcase_32 WA -
testcase_33 AC 176 ms
13,708 KB
testcase_34 AC 172 ms
13,132 KB
testcase_35 AC 131 ms
9,340 KB
testcase_36 WA -
testcase_37 AC 134 ms
10,476 KB
testcase_38 AC 47 ms
4,380 KB
testcase_39 AC 72 ms
4,380 KB
testcase_40 AC 49 ms
4,380 KB
testcase_41 AC 74 ms
4,380 KB
testcase_42 AC 128 ms
9,192 KB
testcase_43 AC 125 ms
9,236 KB
testcase_44 AC 50 ms
4,376 KB
testcase_45 AC 49 ms
4,376 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