-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstpar.cpp
More file actions
51 lines (49 loc) · 841 Bytes
/
stpar.cpp
File metadata and controls
51 lines (49 loc) · 841 Bytes
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
#include <iostream>
#include <cstring> //memset
#include <algorithm>
#include <bitset>
#include <string>
#include <vector>
#include <utility>
#include <cstdio>
#include <queue>
#include <stack>
#include <cmath>
#include <list>
#include <set>
#include <map>
using namespace std;
int main() {
freopen("input.txt", "r", stdin);
int len, i, temp, index;
bool flagged;
while (cin >> len && len != 0) {
flagged = false;
index = 1;
stack <int> S;
while (len--) {
cin >> temp;
if (temp == index) {
index++;
continue;
}
while (!S.empty() && (S.top() == index)) {
S.pop();
index++;
}
if (temp != index)
S.push(temp);
}
while (!S.empty()) {
if (S.top() != index)
break;
S.pop();
index++;
}
if (!S.empty())
cout << "no" << endl;
else
cout << "yes" << endl;
}
return 0;
}