結果

問題 No.2307 [Cherry 5 th Tune *] Cool 46
ユーザー first_vilfirst_vil
提出日時 2023-05-20 09:47:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 683 ms / 2,000 ms
コード長 1,844 bytes
コンパイル時間 238 ms
コンパイル使用メモリ 82,300 KB
実行使用メモリ 172,360 KB
最終ジャッジ日時 2024-06-01 05:19:10
合計ジャッジ時間 38,369 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,088 KB
testcase_01 AC 42 ms
53,504 KB
testcase_02 AC 513 ms
79,644 KB
testcase_03 AC 322 ms
83,092 KB
testcase_04 AC 285 ms
83,012 KB
testcase_05 AC 268 ms
82,448 KB
testcase_06 AC 286 ms
83,800 KB
testcase_07 AC 234 ms
81,492 KB
testcase_08 AC 302 ms
102,212 KB
testcase_09 AC 295 ms
96,096 KB
testcase_10 AC 290 ms
106,500 KB
testcase_11 AC 339 ms
103,260 KB
testcase_12 AC 273 ms
114,800 KB
testcase_13 AC 450 ms
125,580 KB
testcase_14 AC 336 ms
119,316 KB
testcase_15 AC 251 ms
99,560 KB
testcase_16 AC 375 ms
101,500 KB
testcase_17 AC 363 ms
110,552 KB
testcase_18 AC 419 ms
157,292 KB
testcase_19 AC 425 ms
149,052 KB
testcase_20 AC 482 ms
172,360 KB
testcase_21 AC 467 ms
168,268 KB
testcase_22 AC 438 ms
155,620 KB
testcase_23 AC 463 ms
172,328 KB
testcase_24 AC 458 ms
146,740 KB
testcase_25 AC 447 ms
154,592 KB
testcase_26 AC 440 ms
170,472 KB
testcase_27 AC 460 ms
154,896 KB
testcase_28 AC 453 ms
167,600 KB
testcase_29 AC 450 ms
165,948 KB
testcase_30 AC 430 ms
148,640 KB
testcase_31 AC 437 ms
172,212 KB
testcase_32 AC 437 ms
171,992 KB
testcase_33 AC 431 ms
168,112 KB
testcase_34 AC 447 ms
146,500 KB
testcase_35 AC 437 ms
149,116 KB
testcase_36 AC 444 ms
160,640 KB
testcase_37 AC 450 ms
163,232 KB
testcase_38 AC 522 ms
77,476 KB
testcase_39 AC 683 ms
78,628 KB
testcase_40 AC 202 ms
76,940 KB
testcase_41 AC 364 ms
79,024 KB
testcase_42 AC 386 ms
143,340 KB
testcase_43 AC 385 ms
143,220 KB
testcase_44 AC 177 ms
99,900 KB
testcase_45 AC 180 ms
99,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left

mi=lambda: map(int,input().split())
mi1=lambda: map(lambda x: int(x)-1,input().split())
li=lambda: list(mi())
li1=lambda: list(mi1())
ii=lambda: int(input())

def buildCompressedElementsList(a,comp=[]):
	return sorted(set(a+comp))

def compress(a,comp):
	for i in range(len(a)):
		a[i]=bisect_left(comp,a[i])

def countListElements(a,n):
	# assert all(0 <= x < n for x in a)
	res=[0]*n
	for x in a:
		res[x]+=1
	return res


printRed=lambda x: print("Red", x+1)
printBlue=lambda x: print("Blue", x+1)
def printPair(x,redFirst=True):
	if redFirst:
		printRed(x)
		printBlue(x)
	else:
		printBlue(x)
		printRed(x)

def solve():
	n,m=mi()
	a=li1()
	b=li1()
	
	if n==0:
		print("Yes")
		for x in b:
			printBlue(x)
		return
	if m==0:
		print("Yes")
		for x in a:
			printRed(x)
		return
	
	setB=set(b)
	checkAnyPair=lambda: any(x in setB for x in a)
	if not checkAnyPair():
		print("No")
		return
	
	comp=buildCompressedElementsList(a)
	comp=buildCompressedElementsList(b,comp)
	
	compress(a,comp)
	compress(b,comp)
	s=len(comp)
	cntA=countListElements(a,s)
	cntB=countListElements(b,s)
	
	red=[]
	blue=[]
	pair=[]
	for i in range(s):
		mn=min(cntA[i],cntB[i])
		pair+=[i for _ in range(mn)]
		if cntA[i]>cntB[i]:
			red+=[i for _ in range(cntA[i]-cntB[i])]
		else:
			blue+=[i for _ in range(cntB[i]-cntA[i])]
	
	
	print("Yes")
	# step 1: eat red cards which doesn't has partner
	for x in red:
		printRed(comp[x])
	
	# step 2.1: eat a pair of cards (it's guaranteed that there is at least one pair of cards, and this changes previous color to blue)
	printPair(comp[pair[0]], True)
	
	# step 2.2: eat blue cards which doesn't has partner
	for x in blue:
		printBlue(comp[x])
	
	# step 2.3: eat the other pairs of cards
	for i in range(1,len(pair)):
		printPair(comp[pair[i]],(i&1)==0)

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