結果
| 問題 | No.1328 alligachi-problem |
| コンテスト | |
| ユーザー |
tktk_snsn
|
| 提出日時 | 2020-12-25 16:55:14 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,442 bytes |
| コンパイル時間 | 134 ms |
| コンパイル使用メモリ | 12,928 KB |
| 実行使用メモリ | 100,768 KB |
| 最終ジャッジ日時 | 2024-09-22 09:32:47 |
| 合計ジャッジ時間 | 4,719 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 6 TLE * 1 -- * 18 |
ソースコード
from functools import lru_cache
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
N = int(input())
red_red = [[] for _ in range(N + 1)]
red_blue = [[] for _ in range(N + 1)]
blue_blue = [[] for _ in range(N + 1)]
blue_red = [[] for _ in range(N + 1)]
for i in range(1, N+1):
c, x, y = input().rstrip().split()
y = int(y)
if c == "R":
if x == "R":
red_red[y].append(i)
else:
red_blue[y].append(i)
else:
if x == "R":
blue_red[y].append(i)
else:
blue_blue[y].append(i)
ans = []
def rec(R, B, now):
if R + B == N:
ans.append(now)
return True
if red_red[R]:
x = red_red[R].pop()
if rec(R + 1, B, x):
ans.append(now)
return True
red_red[R].append(x)
if red_blue[B]:
x = red_blue[B].pop()
if rec(R + 1, B, x):
ans.append(now)
return True
red_blue[B].append(x)
if blue_red[R]:
x = blue_red[R].pop()
if rec(R, B + 1, x):
ans.append(now)
return True
blue_red[R].append(x)
if blue_blue[B]:
x = blue_blue[B].pop()
if rec(R, B + 1, x):
ans.append(now)
return True
blue_blue[B].append(x)
return False
if not rec(0, 0, 0):
print("No")
else:
print("Yes")
ans.pop()
print(*ans[::-1])
tktk_snsn