-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathccc14s3.cpp
50 lines (38 loc) · 885 Bytes
/
ccc14s3.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
#include <vector>
#include <algorithm>
#include <iostream>
#include <stack>
using namespace std;
void solve() {
int n; cin >> n;
stack<int> mountain, branch;
for (int i = 0; i < n; i++) {
int a; cin >> a;
mountain.push(a);
}
int ans = 0;
while (ans != n) {
if (!mountain.empty() && mountain.top() == ans + 1) {
mountain.pop();
ans++;
}
else if (!branch.empty() && branch.top() == ans+1) {
branch.pop();
ans++;
}
else if (mountain.empty()) {
cout << "N" << "\n";
return;
}
else {
branch.push(mountain.top());
mountain.pop();
}
}
cout << "Y" << "\n";
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int t; cin >> t;
while (t--) solve();
}