結果

問題 No.1328 alligachi-problem
ユーザー persimmon_t01persimmon_t01
提出日時 2021-01-08 20:52:05
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,909 bytes
コンパイル時間 284 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 260,864 KB
最終ジャッジ日時 2024-04-28 00:55:07
合計ジャッジ時間 42,777 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
11,008 KB
testcase_01 AC 26 ms
10,880 KB
testcase_02 AC 25 ms
10,880 KB
testcase_03 AC 25 ms
10,880 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 37 ms
13,312 KB
testcase_07 WA -
testcase_08 AC 31 ms
12,032 KB
testcase_09 WA -
testcase_10 AC 1,875 ms
259,712 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1,869 ms
259,584 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 1,891 ms
259,584 KB
testcase_24 AC 1,914 ms
260,864 KB
testcase_25 AC 1,857 ms
259,456 KB
testcase_26 AC 1,999 ms
260,156 KB
testcase_27 AC 1,984 ms
260,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main(n,cxy):
  # xで分類
  bary=[[set(),set()] for _ in range(n+1)]
  rary=[[set(),set()] for _ in range(n+1)]
  dc={'B':0,'R':1}
  B=0
  R=1
  for i,(c,x,y) in enumerate(cxy):
    if x=='B':
      bary[int(y)][dc[c]].add(i+1)
    else:
      rary[int(y)][dc[c]].add(i+1)
  # bart[i][B]:青がi個の状態で列に加えないといけない青ボール。
  # bart[i][R]:青がi個の状態で列に加えないといけない赤ボール。
  # rart[i][B]:赤がi個の状態で列に加えないといけない青ボール。
  # rart[i][R]:赤がi個の状態で列に加えないといけない赤ボール。
  numb=0
  numr=0
  ret=[]
  while len(ret)<n:
    if bary[numb][R] and rary[numr][B]:return [-1]
    elif bary[numb][R] and rary[numr][R]:
      ret.append(rary[numr][R].pop())
      numr+=1
    elif rary[numr][B] and bary[numb][B]:
      ret.append(bary[numb][B].pop())
      numb+=1
    elif bary[numb][B] and rary[numr][B]:
      ret.append(bary[numb][B].pop())
      numb+=1
    elif bary[numb][R] and rary[numr][R]:
      ret.append(rary[numr][R].pop())
      numr+=1
    elif bary[numb][B]:
      ret.append(bary[numb][B].pop())
      numb+=1
    elif bary[numb][R]:
      ret.append(bary[numb][R].pop())
      numr+=1
    elif rary[numr][B]:
      ret.append(rary[numr][B].pop())
      numb+=1
    elif rary[numr][R]:
      ret.append(rary[numr][R].pop())
      numr+=1
    else:
      return [-1]
  return ret

def chk(n,cxy,ret):
  numb=0
  numr=0
  for i in ret:
    i-=1
    c,x,y=cxy[i]
    y=int(y)
    if x=='R':
      if numr!=y:return False
    elif x=='B':
      if numb!=y:return False
    if c=='R':
      numr+=1
    else:
      numb+=1
  return True

if __name__ == "__main__":
  n=int(input())
  cxy=[list(input().split()) for _ in range(n)]
  ret=main(n,cxy)
  if ret[0]==-1:
    print('No')
  else:
    print('Yes')
    print(*ret)
    #print(chk(n,cxy,ret))


0