結果

問題 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  
実行時間 708 ms / 2,000 ms
コード長 3,557 bytes
コンパイル時間 2,680 ms
コンパイル使用メモリ 217,008 KB
実行使用メモリ 30,464 KB
最終ジャッジ日時 2024-06-01 08:28:26
合計ジャッジ時間 44,673 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 281 ms
6,944 KB
testcase_03 AC 296 ms
5,376 KB
testcase_04 AC 284 ms
5,376 KB
testcase_05 AC 276 ms
5,376 KB
testcase_06 AC 300 ms
5,376 KB
testcase_07 AC 246 ms
5,376 KB
testcase_08 AC 378 ms
12,672 KB
testcase_09 AC 374 ms
13,312 KB
testcase_10 AC 345 ms
11,996 KB
testcase_11 AC 437 ms
11,136 KB
testcase_12 AC 340 ms
12,876 KB
testcase_13 AC 497 ms
11,372 KB
testcase_14 AC 398 ms
16,000 KB
testcase_15 AC 297 ms
8,624 KB
testcase_16 AC 410 ms
7,488 KB
testcase_17 AC 362 ms
12,300 KB
testcase_18 AC 599 ms
27,012 KB
testcase_19 AC 634 ms
20,156 KB
testcase_20 AC 530 ms
20,368 KB
testcase_21 AC 570 ms
19,488 KB
testcase_22 AC 613 ms
27,760 KB
testcase_23 AC 535 ms
19,892 KB
testcase_24 AC 643 ms
26,028 KB
testcase_25 AC 642 ms
26,412 KB
testcase_26 AC 527 ms
20,628 KB
testcase_27 AC 626 ms
27,252 KB
testcase_28 AC 569 ms
21,020 KB
testcase_29 AC 556 ms
22,140 KB
testcase_30 AC 647 ms
23,076 KB
testcase_31 AC 525 ms
20,464 KB
testcase_32 AC 534 ms
20,432 KB
testcase_33 AC 708 ms
30,464 KB
testcase_34 AC 664 ms
28,544 KB
testcase_35 AC 640 ms
21,432 KB
testcase_36 AC 552 ms
19,804 KB
testcase_37 AC 595 ms
25,524 KB
testcase_38 AC 369 ms
5,376 KB
testcase_39 AC 506 ms
5,376 KB
testcase_40 AC 396 ms
5,376 KB
testcase_41 AC 426 ms
5,376 KB
testcase_42 AC 643 ms
19,572 KB
testcase_43 AC 641 ms
19,572 KB
testcase_44 AC 514 ms
18,816 KB
testcase_45 AC 523 ms
18,816 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