結果
| 問題 |
No.2042 RGB Caps
|
| コンテスト | |
| ユーザー |
judgelaw
|
| 提出日時 | 2022-08-19 22:59:24 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,126 bytes |
| コンパイル時間 | 278 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 51,272 KB |
| 最終ジャッジ日時 | 2024-10-08 10:19:01 |
| 合計ジャッジ時間 | 8,798 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 3 WA * 13 |
ソースコード
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import defaultdict as dd
# aまでcが最多となる条件を考える
# ⇒c>a//3は必要
# ⇒c>a//2あれば十分
# 必要条件をチェックして大丈夫そうなら適当に構成する
# indexをRGBに変換
i2c=["R","G","B"]
# R,G,Bをindexに変換
c2i=dd(int)
c2i["R"]=0
c2i["G"]=1
c2i["B"]=2
N,K=map(int,input().split())
AC=[]
for _ in range(K):
a,c=input().split()
a=int(a)
AC.append((a,c))
AC=sorted(AC)
# 必要条件チェック
RGB=[0,0,0]
for a,c in AC:
# 今確認したい色以外の必要数をチェック
othermax=0
for i in range(3):
if c2i[c]==i:continue
othermax=max(othermax,RGB[i])
# cはc>a//3かそれまでの最多数を更新する必要がある
RGB[c2i[c]]=max((a+2)//3,othermax)
# RGBの総和がaを上回ればNG
if a<sum(RGB):
print(-1)
exit(0)
# print(RGB)
# 達成可能ならば適当に構成する
res=[]
i=0
resRGB=[0,0,0]
for a,c in AC:
# まずはaまで目的の色が最多となるようにする
othermax=0
for i in range(3):
if c2i[c]==i:continue
othermax=max(othermax,resRGB[i])
target=max((a+2)//3,othermax)
# print(a,c,target)
while target-resRGB[i]>0:
res.append(c)
resRGB[c2i[c]]+=1
RGB[c2i[c]]-=1
target-=1
# 他の色が残っている場合は最多条件を破らないようにいい感じに埋める
for i in range(3):
if c2i[c]==i:continue
while RGB[i] and resRGB[i]<resRGB[c2i[c]] and len(res)<a:
res.append(i2c[i])
resRGB[i]+=1
RGB[i]-=1
# まだ足りない場合は最小のものを埋め続ける
while len(res)<a:
for i in range(3):
if min(resRGB)==resRGB[i]:
res.append(i2c[i])
resRGB[i]+=1
break
# print(resRGB,RGB,res)
#全クエリを見ても残っている場合は適当にRを埋める
while len(res)<N:res.append("R")
print(*res,sep="")
judgelaw