結果
| 問題 |
No.2307 [Cherry 5 th Tune *] Cool 46
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-05-20 09:47:25 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 619 ms / 2,000 ms |
| コード長 | 1,844 bytes |
| コンパイル時間 | 1,055 ms |
| コンパイル使用メモリ | 81,920 KB |
| 実行使用メモリ | 172,064 KB |
| 最終ジャッジ日時 | 2024-12-21 08:19:44 |
| 合計ジャッジ時間 | 36,483 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 46 |
ソースコード
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()