結果

問題 No.2307 [Cherry 5 th Tune *] Cool 46
ユーザー ShirotsumeShirotsume
提出日時 2023-05-19 21:41:25
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,988 bytes
コンパイル時間 366 ms
コンパイル使用メモリ 86,972 KB
実行使用メモリ 174,644 KB
最終ジャッジ日時 2023-08-23 02:41:38
合計ジャッジ時間 26,906 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
72,984 KB
testcase_01 AC 115 ms
73,320 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 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 341 ms
80,816 KB
testcase_39 AC 473 ms
83,376 KB
testcase_40 AC 299 ms
81,760 KB
testcase_41 AC 309 ms
81,392 KB
testcase_42 AC 338 ms
145,352 KB
testcase_43 AC 329 ms
145,152 KB
testcase_44 AC 357 ms
174,644 KB
testcase_45 AC 346 ms
173,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import copy
import sys
from collections import deque, Counter
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
inf = 2 ** 63 - 1
mod = 998244353

def solve():
    n, m = mi()
    a = set(mi())
    b = set(mi())
    pair = []
    for v in list(a):
        if v in b:
            pair.append(v)
            a.discard(v)
            b.discard(v)
    ans1 = []
    cnt = 0
    for v in pair:
        if cnt % 2 == 0:
            ans1.append(('Red', v))
            ans1.append(('Blue', v))
        else:
            ans1.append(('Blue', v))
            ans1.append(('Red', v))
        cnt += 1

    ax = copy.copy(a)
    bx = copy.copy(b)
    cnt = 0
    while a or b:
        if b:
            ans1.append(('Blue', b.pop()))
        elif a:
            ans1.append(('Red', a.pop()))
        cnt += 1
    ans2 = []
    cnt = 0
    for v in pair:
        if cnt % 2 == 1:
            ans2.append(('Red', v))
            ans2.append(('Blue', v))
        else:
            ans2.append(('Blue', v))
            ans2.append(('Red', v))
        cnt += 1
    a = ax
    b = bx
    cnt = 0
    while a or b:
        if a:
            ans2.append(('Red', a.pop()))
        elif b:
            ans2.append(('Blue', b.pop()))
        cnt += 1

    cnt1 = 0

    for i in range(len(ans1) - 1):
        if ans1[i][0] != ans1[i + 1][0]:
            cnt1 += 1
        if ans1[i][0] != ans1[i + 1][0] and ans1[i][1] != ans1[i + 1][1]:
            cnt1 -= inf
    cnt2 = 0
    for i in range(len(ans2) - 1):
        if ans2[i][0] != ans2[i + 1][0]:
            cnt2 += 1
        if ans2[i][0] != ans2[i + 1][0] and ans2[i][1] != ans2[i + 1][1]:
            cnt2 -= inf
    if max(cnt1, cnt2) < 0:
        print('No')
        return
    print('Yes')
    if cnt1 >= cnt2:
        for x, y in ans1:
            print(x, y)
    else:
        for x, y in ans2:
            print(x, y)

for _ in range(ii()):
    solve()



    
0