結果
| 問題 | 
                            No.2307 [Cherry 5 th Tune *] Cool 46
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2023-05-19 22:17:37 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 366 ms / 2,000 ms | 
| コード長 | 1,279 bytes | 
| コンパイル時間 | 655 ms | 
| コンパイル使用メモリ | 82,444 KB | 
| 実行使用メモリ | 125,164 KB | 
| 最終ジャッジ日時 | 2024-12-21 03:01:37 | 
| 合計ジャッジ時間 | 33,776 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 46 | 
ソースコード
import sys
input = sys.stdin.readline
def main():
    T = int(input())
    for _ in range(T):
        N, M = map(int, input().split())
        A = set(map(int, input().split()))
        B = set(map(int, input().split()))
        pair = []
        ans = []
        while A:
            n = A.pop()
            if n in B:
                pair.append(n)
                B.discard(n)
            else:
                ans.append(f'Red {n}')
        if not pair:
            if M == 0:
                print('Yes')
                print(*ans, sep='\n')
            elif N == 0:
                print('Yes')
                while B:
                    print(f'Blue {B.pop()}')
            else:
                print('No')
            continue
        n = pair.pop()
        ans.append(f'Red {n}')
        ans.append(f'Blue {n}')
        while B:
            ans.append(f'Blue {B.pop()}')
        cur = 'Blue'
        while pair:
            n = pair.pop()
            if cur == 'Blue':
                ans.append(f'Blue {n}')
                ans.append(f'Red {n}')
                cur = 'Red'
            else:
                ans.append(f'Red {n}')
                ans.append(f'Blue {n}')
                cur = 'Blue'
        print('Yes')
        print(*ans, sep='\n')
main()