結果

問題 No.2307 [Cherry 5 th Tune *] Cool 46
ユーザー KKT89KKT89
提出日時 2023-05-19 22:11:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 6,699 bytes
コンパイル時間 4,652 ms
コンパイル使用メモリ 234,032 KB
実行使用メモリ 24,164 KB
最終ジャッジ日時 2023-08-23 03:25:39
合計ジャッジ時間 32,251 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 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 178 ms
9,776 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 266 ms
24,156 KB
testcase_19 WA -
testcase_20 AC 272 ms
24,020 KB
testcase_21 AC 267 ms
22,696 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 264 ms
23,560 KB
testcase_28 WA -
testcase_29 AC 268 ms
23,764 KB
testcase_30 WA -
testcase_31 AC 284 ms
24,028 KB
testcase_32 WA -
testcase_33 AC 290 ms
24,092 KB
testcase_34 AC 269 ms
22,248 KB
testcase_35 AC 216 ms
17,816 KB
testcase_36 WA -
testcase_37 AC 257 ms
22,968 KB
testcase_38 AC 46 ms
4,376 KB
testcase_39 AC 75 ms
4,376 KB
testcase_40 AC 48 ms
4,376 KB
testcase_41 AC 100 ms
4,376 KB
testcase_42 AC 186 ms
15,760 KB
testcase_43 AC 182 ms
15,644 KB
testcase_44 AC 49 ms
4,376 KB
testcase_45 AC 49 ms
4,380 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;
    vector<pair<int,int>> rr,bb,rb;
    {
        map<int,int> mp1,mp2;
        vector<int> z;
        for (int i = 0; i < n; ++i) {
            mp1[a[i]]++;
            z.push_back(a[i]);
        }
        for (int i = 0; i < m; ++i) {
            mp2[b[i]]++;
            z.push_back(b[i]);
        }
        sort(z.begin(), z.end());
        z.erase(unique(z.begin(), z.end()), z.end());
        for (int i : z) {
            int u = mp1[i], uu = mp2[i];
            while (abs(u-uu) > 1) {
                if (u > uu) {
                    R.push_back(i);
                    u--;
                }
                else {
                    B.push_back(i);
                    uu--;
                }
            }
            if (min(u,uu) == 0) {
                if (uu > 0) B.push_back(i);
                else if (u > 0) R.push_back(i);
            }
            else {
                if (u == uu) rb.push_back({u, i});
                else if (u < uu) bb.push_back({u, i});
                else rr.push_back({uu, i});
            }
        }
    }
    if (rr.size() + rb.size() + bb.size() == 0) {
        cout << "No" << "\n";
        return;
    }
    cout << "Yes" << "\n";

    if (rb.size() % 2 == 1) {
        for (int i : R) {
            cout << "Red " << i << "\n";
        }
        for (auto p: rr) {
            cout << "Red " << p.second << "\n";
            for (int j = 0; j < p.first; ++j) {
                cout << "Blue " << p.second << "\n";
                cout << "Red " << p.second << "\n";
            }
        }
        int t = 0;
        for (auto p: rb) {
            for (int j = 0; j < p.first; ++j) {
                if (t == 0) {
                    cout << "Red " << p.second << "\n";
                    cout << "Blue " << p.second << "\n";
                }
                else {
                    cout << "Blue " << p.second << "\n";
                    cout << "Red " << p.second << "\n";
                }
            }
            t ^= 1;
        }
        for (auto p: bb) {
            cout << "Blue " << p.second << "\n";
            for (int j = 0; j < p.first; ++j) {
                cout << "Red " << p.second << "\n";
                cout << "Blue " << p.second << "\n";
            }
        }
        for (int i : B) {
            cout << "Blue " << i << "\n";
        }
    }
    else if (rr.size() + R.size() == 0) {
        for (int i : B) {
            cout << "Blue " << i << "\n";
        }
        for (auto p: bb) {
            cout << "Blue " << p.second << "\n";
            for (int j = 0; j < p.first; ++j) {
                cout << "Red " << p.second << "\n";
                cout << "Blue " << p.second << "\n";
            }
        }
        int t = 1;
        for (auto p: rb) {
            for (int j = 0; j < p.first; ++j) {
                if (t == 0) {
                    cout << "Red " << p.second << "\n";
                    cout << "Blue " << p.second << "\n";
                }
                else {
                    cout << "Blue " << p.second << "\n";
                    cout << "Red " << p.second << "\n";
                }
            }
            t ^= 1;
        }
    }
    else if (B.size() + bb.size() == 0) {
        for (int i : R) {
            cout << "Red " << i << "\n";
        }
        for (auto p: rr) {
            cout << "Red " << p.second << "\n";
            for (int j = 0; j < p.first; ++j) {
                cout << "Blue " << p.second << "\n";
                cout << "Red " << p.second << "\n";
            }
        }
        int t = 0;
        for (auto p: rb) {
            for (int j = 0; j < p.first; ++j) {
                if (t == 0) {
                    cout << "Red " << p.second << "\n";
                    cout << "Blue " << p.second << "\n";
                }
                else {
                    cout << "Blue " << p.second << "\n";
                    cout << "Red " << p.second << "\n";
                }
            }
            t ^= 1;
        }
    }
    else {
        if (rb.size()) {
            auto p = rb.back(); rb.pop_back();
            p.first--;
            B.push_back(p.second);
            rr.push_back(p);
        }
        else if (rr.size()) {
            auto p = rr.back(); rr.pop_back();
            rb.push_back(p);
            R.push_back(p.second);
        }
        else {
            auto p = bb.back(); bb.pop_back();
            rb.push_back(p);
            B.push_back(p.second);
        }

        for (int i : R) {
            cout << "Red " << i << "\n";
        }
        for (auto p: rr) {
            cout << "Red " << p.second << "\n";
            for (int j = 0; j < p.first; ++j) {
                cout << "Blue " << p.second << "\n";
                cout << "Red " << p.second << "\n";
            }
        }
        int t = 0;
        for (auto p: rb) {
            for (int j = 0; j < p.first; ++j) {
                if (t == 0) {
                    cout << "Red " << p.second << "\n";
                    cout << "Blue " << p.second << "\n";
                }
                else {
                    cout << "Blue " << p.second << "\n";
                    cout << "Red " << p.second << "\n";
                }
            }
            t ^= 1;
        }
        for (auto p: bb) {
            cout << "Blue " << p.second << "\n";
            for (int j = 0; j < p.first; ++j) {
                cout << "Red " << p.second << "\n";
                cout << "Blue " << p.second << "\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