-
Notifications
You must be signed in to change notification settings - Fork 3
/
CCC14S3.cpp
63 lines (53 loc) · 1.02 KB
/
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
51
52
53
54
55
56
57
58
59
60
61
62
63
// Problem: CCC '14 S3 - The Geneva Confection
// Contest: DMOJ
// URL: https://dmoj.ca/problem/ccc14s3
// Memory Limit: 64 MB
// Time Limit: 3000 ms
// Ryan Liu
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
deque<ll> m, b;
ll n, temp, cur;
bool pos = true;
void solve() {
// Initialize each variable for a new test case
m.clear();
b.clear();
pos = true;
cur = 1;
cin >> n;
for (ll j = 0; j < n; j++) {
cin >> temp;
m.pb(temp);
}
while (cur != n) {
if (m.empty() && (cur != b.back())) {
pos = false;
break;
}
if (!(m.empty()) && m.back() == cur) {
m.pop_back();
cur++;
} else if (!(b.empty()) && (b.back() == cur)) {
b.pop_back();
cur++;
}
else if (!m.empty()) {
b.pb(m.back());
m.pop_back();
}
}
cout << ((pos) ? "Y" : "N") << "\n";
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tc;
cin >> tc;
for (int t = 1; t <= tc; t++) {
solve();
}
}