Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define endl '\n'
- #define sz(x) int(x.size())
- #define all(x) x.begin(), x.end()
- int main() {
- ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
- int n;
- while (cin >> n, n) {
- vector<int> nums(n);
- while (cin >> nums[0], nums[0]) {
- for (int i = 1; i < n; i++) cin >> nums[i];
- stack<int> stk, station;
- for (int i = n; i >= 1; i--) stk.push(i);
- int idx = 0;
- bool done = true;
- while (done) {
- done = false;
- while (sz(station) && station.top() == nums[idx]) {
- idx++;
- done = true;
- station.pop();
- }
- while (sz(stk) && stk.top() != nums[idx]) station.push(stk.top()), stk.pop();
- if (sz(stk)) {
- done = true;
- idx++;
- stk.pop();
- }
- }
- cout << (idx == n ? "Yes" : "No") << endl;
- }
- cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement