-
Notifications
You must be signed in to change notification settings - Fork 0
/
STPAR_T.py
56 lines (43 loc) · 1.04 KB
/
STPAR_T.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
44
45
46
47
48
49
50
51
52
53
54
55
56
from sys import stdin
count = 0
N = []
lsts = []
while(True):
n = int(input())
if n != 0:
N.append(n)
else:
break
lsts.append(list(map(int, stdin.readline().split())))
count += 1
for z in range(count):
lst = lsts[z]
n = N[z]
order = 1
i = 0
narrow_street = [0]
approach_street = []
while (i < n):
if lst[i] == order:
approach_street.append(lst[i])
order += 1
elif narrow_street[-1] == order:
approach_street.append(narrow_street[-1])
narrow_street.pop()
order += 1
i -= 1
else:
narrow_street.append(lst[i])
i += 1
del narrow_street[0]
if narrow_street != []:
approach_street.extend(narrow_street[::-1])
flag = False
for i in range(n):
if approach_street[i] != i+1:
flag = True
break
if flag:
print('no')
else:
print('yes')