結果

問題 No.2307 [Cherry 5 th Tune *] Cool 46
ユーザー first_vilfirst_vil
提出日時 2023-05-20 09:37:22
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,822 bytes
コンパイル時間 401 ms
コンパイル使用メモリ 82,532 KB
実行使用メモリ 172,536 KB
最終ジャッジ日時 2024-12-21 08:11:40
合計ジャッジ時間 33,742 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
52,608 KB
testcase_01 AC 49 ms
53,120 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 593 ms
77,220 KB
testcase_39 WA -
testcase_40 AC 250 ms
76,928 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 212 ms
99,776 KB
testcase_45 AC 271 ms
130,312 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()
	
	setB=set(b)
	
	if n==0:
		print("Yes")
		for x in b:
			printBlue(x)
		return
	if m==0:
		print("Yes")
		for x in a:
			printRed(x)
		return
	
	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(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(pair[0], True)
	
	# step 2.2: eat blue cards which doesn't has partner
	for x in blue:
		printBlue(x)
	
	# step 2.3: eat the other pairs of cards
	for i in range(1,len(pair)):
		printPair(pair[i],(i&1)==0)

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