-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path514 - Rails.cpp
128 lines (111 loc) · 1.45 KB
/
514 - Rails.cpp
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*input
5
1 2 3 4 5
5 4 1 2 3
1 4 3 2 5
3 4 2 5 1
3 4 2 1 5
4 3 5 2 1
0
3
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
0
4
1 2 3 4
1 2 4 3
1 3 2 4
1 3 4 2
1 4 2 3
1 4 3 2
2 1 3 4
2 1 4 3
2 3 1 4
2 3 4 1
2 4 1 3
2 4 3 1
3 1 2 4
3 1 4 2
3 2 1 4
3 2 4 1
3 4 1 2
3 4 2 1
4 1 2 3
4 1 3 2
4 2 1 3
4 2 3 1
4 3 1 2
4 3 2 1
0
10
5 7 10 9 8 6 4 3 2 1
5 6 4 8 7 3 2 9 1 10
0
0
*/
#include <stdio.h>
#include <cmath>
#include <set>
#include <vector>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stack>
using namespace std;
#define SSTR( x ) dynamic_cast< std::ostringstream & >( \
( std::ostringstream() << std::dec << x ) ).str()
#define FOR(a , b) for ( int i = a ; i < b ; i++ )
#define FOR2(a , b) for ( int j = 0 ; j < b ; j++)
#define INF 1000000000
typedef long long ll;
typedef std::pair<int,int> ii;
int n;
stack<int> station;
int arr[1005];
int main()
{
cin >> n;
while ( n != 0)
{
cin >> arr[0];
while (arr[0] != 0)
{
while(!station.empty())
station.pop();
FOR(1 , n)
cin >> arr[i];
int j = 1;
int i = 0;
while ( j <= n && i < n)
{
station.push(j);
while(!station.empty() && station.top() == arr[i])
{
station.pop();
i++;
}
j++;
}
for(;i < n; i++)
{
if(arr[i] == station.top())
station.pop();
}
if (!station.empty())
{
cout << "No"<< endl;
}
else
{
cout << "Yes" << endl;
}
cin >> arr[0];
}
cout << endl;
cin >> n;
}
}