結果

問題 No.2307 [Cherry 5 th Tune *] Cool 46
ユーザー koarakko5555koarakko5555
提出日時 2023-05-20 00:09:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 762 ms / 2,000 ms
コード長 1,750 bytes
コンパイル時間 300 ms
コンパイル使用メモリ 87,128 KB
実行使用メモリ 149,408 KB
最終ジャッジ日時 2023-08-23 04:17:26
合計ジャッジ時間 35,638 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
71,608 KB
testcase_01 AC 88 ms
71,604 KB
testcase_02 AC 392 ms
81,616 KB
testcase_03 AC 260 ms
83,932 KB
testcase_04 AC 248 ms
84,720 KB
testcase_05 AC 283 ms
85,960 KB
testcase_06 AC 277 ms
85,592 KB
testcase_07 AC 234 ms
83,796 KB
testcase_08 AC 298 ms
107,032 KB
testcase_09 AC 279 ms
106,080 KB
testcase_10 AC 254 ms
113,220 KB
testcase_11 AC 312 ms
104,864 KB
testcase_12 AC 278 ms
112,064 KB
testcase_13 AC 339 ms
114,232 KB
testcase_14 AC 294 ms
108,304 KB
testcase_15 AC 255 ms
110,940 KB
testcase_16 AC 302 ms
99,384 KB
testcase_17 AC 309 ms
103,796 KB
testcase_18 AC 318 ms
127,156 KB
testcase_19 AC 344 ms
123,704 KB
testcase_20 AC 344 ms
125,480 KB
testcase_21 AC 338 ms
120,840 KB
testcase_22 AC 320 ms
127,552 KB
testcase_23 AC 358 ms
120,944 KB
testcase_24 AC 347 ms
127,360 KB
testcase_25 AC 343 ms
126,580 KB
testcase_26 AC 317 ms
127,836 KB
testcase_27 AC 336 ms
127,504 KB
testcase_28 AC 341 ms
122,216 KB
testcase_29 AC 330 ms
121,536 KB
testcase_30 AC 344 ms
128,388 KB
testcase_31 AC 325 ms
127,508 KB
testcase_32 AC 320 ms
127,188 KB
testcase_33 AC 325 ms
127,668 KB
testcase_34 AC 359 ms
129,128 KB
testcase_35 AC 341 ms
129,040 KB
testcase_36 AC 335 ms
120,240 KB
testcase_37 AC 362 ms
129,980 KB
testcase_38 AC 671 ms
80,964 KB
testcase_39 AC 762 ms
83,024 KB
testcase_40 AC 287 ms
79,464 KB
testcase_41 AC 327 ms
80,024 KB
testcase_42 AC 332 ms
125,604 KB
testcase_43 AC 319 ms
125,676 KB
testcase_44 AC 272 ms
149,288 KB
testcase_45 AC 263 ms
149,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections

T = int(input())
for _ in range(T):
    N, M = map(int, input().split())
    try:
        A = list(map(int, input().split()))
        B = list(map(int, input().split()))
    except:
        if N==0:
            A = []
        if M==0:
            B = []

    #辞書型の生成
    AB = collections.Counter(A+B)
    AB_keys = list(AB.keys())
    AB_values = list(AB.values())

    #何もない
    if N==0 and M==0:
        print("Yes")
        continue

    #Noのパターン
    if max(AB_values)==1 and N>0 and M>0:
        print("No")
        continue

    #Yesのパターン
    print("Yes")
    #Redのみ
    if M==0:
        for i in range(N):
            print("Red", A[i])
    
    #Blueのみ
    if N==0:
        for i in range(M):
            print("Blue", B[i])

    #大本命
    if N>0 and M>0:
        #Redで1つしかないやつを表示する。
        for i in range(N):
            if AB[A[i]]==1:
                print("Red", A[i])
        #1回目の共通項を表示する
        cnt = 0
        for i in range(N):
            if AB[A[i]]>1:
                print("Red", A[i])
                print("Blue", A[i])
                cnt += 1
                save_point = i
                break
            
        #Blueで1つしかないやつを表示する。
        for i in range(M):
            if AB[B[i]]==1:
                print("Blue", B[i])

        #2回目の共通項
        for i in range(save_point+1, N):
            if AB[A[i]]>1 and cnt%2==0:
                print("Red", A[i])
                print("Blue", A[i])
                cnt += 1
            elif AB[A[i]]>1 and cnt%2==1:
                print("Blue", A[i])
                print("Red", A[i])
                cnt += 1
0