結果

問題 No.1328 alligachi-problem
ユーザー tktk_snsntktk_snsn
提出日時 2020-12-25 16:40:59
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,355 bytes
コンパイル時間 132 ms
コンパイル使用メモリ 12,016 KB
実行使用メモリ 250,248 KB
最終ジャッジ日時 2023-10-22 08:20:17
合計ジャッジ時間 19,644 ms
ジャッジサーバーID
(参考情報)
judge10 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
14,624 KB
testcase_01 AC 29 ms
10,276 KB
testcase_02 AC 32 ms
10,276 KB
testcase_03 AC 29 ms
10,276 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 34 ms
11,008 KB
testcase_07 WA -
testcase_08 AC 32 ms
10,544 KB
testcase_09 WA -
testcase_10 AC 822 ms
78,408 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 832 ms
78,408 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 841 ms
78,408 KB
testcase_24 TLE -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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 = []


@lru_cache(maxsize=True)
def rec(R, B):
    if R + B == N:
        return True

    if red_red[R]:
        ans.append(red_red[R].pop())
        if rec(R + 1, B):
            return True
        red_red[R].append(ans.pop())

    if red_blue[B]:
        ans.append(red_blue[B].pop())
        if rec(R + 1, B):
            return True
        red_blue[B].append(ans.pop())

    if blue_red[R]:
        ans.append(blue_red[R].pop())
        if rec(R, B + 1):
            return True
        blue_red[R].append(ans.pop())

    if blue_blue[B]:
        ans.append(blue_blue[B].pop())
        if rec(R, B + 1):
            return True
        blue_blue[B].append(ans.pop())

    return False


if not rec(0, 0):
    print("No")
else:
    print("Yes")
    print(*ans)
0