-
Notifications
You must be signed in to change notification settings - Fork 6
/
dream.py
43 lines (39 loc) · 1.12 KB
/
dream.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import sys
def push(event):
event_map[event] = len(event_stack)
event_stack.append(event)
def pop():
if event_stack:
e = event_stack.pop()
del event_map[e]
return e
input()
event_stack = []
event_map = {}
for line in sys.stdin:
line = line.strip().split()
if line[0] == 'E':
push(line[1])
elif line[0] == 'D':
for _ in range(int(line[1])):
pop()
else: # scenario
consistent = True
mn, mx = 0, len(event_stack)
for event in line[2:]:
if event[0] != '!':
if event in event_map:
mx = min(mx, len(event_stack) - event_map[event] - 1)
else:
consistent = False
break
else:
if event[1:] in event_map:
mn = max(mn, len(event_stack) - event_map[event[1:]])
if consistent and mn <= mx:
if mn == 0:
print('Yes')
else:
print(mn, 'Just A Dream')
else:
print('Plot Error')