結果

問題 No.2307 [Cherry 5 th Tune *] Cool 46
ユーザー hiro71687k
提出日時 2023-05-21 00:55:51
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 688 ms / 2,000 ms
コード長 3,557 bytes
コンパイル時間 2,262 ms
コンパイル使用メモリ 209,264 KB
最終ジャッジ日時 2025-02-13 03:53:14
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
ld pie=3.141592653589793;
ll inf=300000000;
ll mod=998244353;
int main(){
    ll t;
    cin >> t;
    for (ll o = 0; o < t; o++)
    {
        ll n,m;
        cin >> n >> m;
        vector<ll>a(n),b(m);
        map<ll,ll>memo;
        for (ll i = 0; i < n; i++)
        {
            cin >> a[i];
            memo[a[i]]+=1;
        }
        map<ll,ll>mm;
        vector<ll>aa(n,0),bb(m,0);
        ll now=0;
        for (ll i = 0; i < m; i++)
        {
            cin >> b[i];
            if (memo[b[i]]>=1)
            {
                now++;
                bb.push_back(i);
                memo[b[i]]--;
                mm[b[i]]+=1;
                bb[i]=1;
            }
        }
        if (n==0)
        {
            cout << "Yes" << endl;
            for (ll i = 0; i < m; i++)
            {
                cout << "Blue " << b[i] << endl;
            }
            continue;
        }
        if (m==0)
        {
            cout << "Yes" << endl;
            for (ll i = 0; i < n; i++)
            {
                cout << "Red " << a[i] << endl;
            }
            continue;
        }
        
        for (ll i = 0; i < n; i++)
        {
            if (mm[a[i]]>=1)
            {
                mm[a[i]]--;
                aa[i]=1;
            }
        }
        if (now==0)
        {
            cout << "No" << endl;
            continue;
        }
        if (now%2)
        {
            cout << "Yes" << endl;
            for (ll i = 0; i < n; i++)
            {
                if (aa[i]==0)
                {
                    cout << "Red " << a[i] << endl;
                }
            }
            ll x=0;
            for (ll i = 0; i < n; i++)
            {
                if (aa[i]==1)
                {
                    if (x%2==0)
                    {
                        cout << "Red " << a[i]<< endl;
                        cout << "Blue " << a[i] << endl;
                    }else{
                        cout << "Blue " << a[i] << endl;
                        cout << "Red " << a[i]<< endl;
                    }
                    x++;
                }
            }
            for (ll i = 0; i < m; i++)
            {
                if (bb[i]==0)
                {
                    cout << "Blue " << b[i] << endl;
                }
            }
        }else{
            cout << "Yes" << endl;
            ll saisyo=inf;
            for (ll i = 0; i < n; i++)
            {
                if (aa[i]==0)
                {
                    cout << "Red " << a[i] << endl;
                }else{
                    saisyo=min(saisyo,i);
                }
            }
            cout << "Red " << a[saisyo] << endl;
            cout << "Blue " << a[saisyo] << endl;
            ll x=1;
            for (ll i = 0; i < m; i++)
            {
                if (bb[i]==0)
                {
                    cout << "Blue " << b[i] << endl;
                }
            }
            for (ll i = 0; i < n; i++)
            {
                if (aa[i]==1&&i!=saisyo)
                {
                    if (x%2==0)
                    {
                        cout << "Red " << a[i]<< endl;
                        cout << "Blue " << a[i] << endl;
                    }else{
                        cout << "Blue " << a[i] << endl;
                        cout << "Red " << a[i]<< endl;
                    }
                    x++;
                }
            }
        }
    }
    
}
0