結果
問題 |
No.1328 alligachi-problem
|
ユーザー |
![]() |
提出日時 | 2020-12-25 16:40:59 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,355 bytes |
コンパイル時間 | 91 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 86,812 KB |
最終ジャッジ日時 | 2024-09-22 09:19:50 |
合計ジャッジ時間 | 20,260 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 6 WA * 15 RE * 1 TLE * 1 -- * 2 |
ソースコード
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)