-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueriesForTheArray.cpp
More file actions
54 lines (51 loc) · 1.27 KB
/
QueriesForTheArray.cpp
File metadata and controls
54 lines (51 loc) · 1.27 KB
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
// https://codeforces.com/problemset/problem/1861/C
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
void solveCase() {
string s;
cin >> s;
int sorted = 0, unsorted = 0;
vector<bool> bad;
bad.reserve(s.size());
bool ans = true;
for (int i = 0; i < s.size(); ++i) {
char ch = s[i];
if (ch == '+') {
bad.push_back(false);
} else if (ch == '-') {
if (bad.back()) {
--unsorted;
}
bad.pop_back();
sorted = min(sorted, (int)bad.size());
} else if (ch == '1') {
if (unsorted) {
ans = false;
break;
}
sorted = bad.size();
} else if (ch == '0') {
if (sorted == bad.size() || bad.size() <= 1) {
ans = false;
break;
}
if (!bad.back()) {
bad[bad.size()-1] = true;
++unsorted;
}
}
}
cout << ((ans) ? "YES" : "NO") << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int nC = 1;
cin >> nC;
for (int i = 1; i <= nC; i++) {
// cout << "\nTEST #" << i << ":\n";
solveCase();
}
return 0;
}