結果

問題 No.2307 [Cherry 5 th Tune *] Cool 46
ユーザー hiro71687khiro71687k
提出日時 2023-05-21 00:55:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 735 ms / 2,000 ms
コード長 3,557 bytes
コンパイル時間 3,070 ms
コンパイル使用メモリ 213,484 KB
実行使用メモリ 30,164 KB
最終ジャッジ日時 2023-08-23 10:50:29
合計ジャッジ時間 46,972 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 265 ms
4,376 KB
testcase_03 AC 290 ms
4,556 KB
testcase_04 AC 279 ms
4,376 KB
testcase_05 AC 270 ms
4,444 KB
testcase_06 AC 287 ms
4,640 KB
testcase_07 AC 238 ms
4,880 KB
testcase_08 AC 387 ms
12,532 KB
testcase_09 AC 379 ms
13,120 KB
testcase_10 AC 347 ms
11,840 KB
testcase_11 AC 444 ms
10,956 KB
testcase_12 AC 353 ms
12,764 KB
testcase_13 AC 491 ms
11,384 KB
testcase_14 AC 406 ms
15,668 KB
testcase_15 AC 294 ms
8,520 KB
testcase_16 AC 404 ms
7,380 KB
testcase_17 AC 368 ms
11,900 KB
testcase_18 AC 599 ms
26,652 KB
testcase_19 AC 630 ms
19,908 KB
testcase_20 AC 527 ms
20,140 KB
testcase_21 AC 548 ms
19,328 KB
testcase_22 AC 639 ms
27,556 KB
testcase_23 AC 538 ms
19,724 KB
testcase_24 AC 649 ms
25,640 KB
testcase_25 AC 635 ms
26,164 KB
testcase_26 AC 534 ms
20,264 KB
testcase_27 AC 633 ms
27,148 KB
testcase_28 AC 549 ms
20,704 KB
testcase_29 AC 548 ms
22,100 KB
testcase_30 AC 651 ms
22,752 KB
testcase_31 AC 541 ms
21,208 KB
testcase_32 AC 537 ms
20,396 KB
testcase_33 AC 735 ms
30,164 KB
testcase_34 AC 660 ms
28,228 KB
testcase_35 AC 644 ms
21,136 KB
testcase_36 AC 571 ms
19,460 KB
testcase_37 AC 613 ms
25,200 KB
testcase_38 AC 359 ms
4,380 KB
testcase_39 AC 491 ms
4,376 KB
testcase_40 AC 387 ms
4,380 KB
testcase_41 AC 417 ms
4,376 KB
testcase_42 AC 647 ms
19,376 KB
testcase_43 AC 628 ms
19,296 KB
testcase_44 AC 501 ms
18,628 KB
testcase_45 AC 513 ms
18,520 KB
権限があれば一括ダウンロードができます

ソースコード

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