Jeremiah_

Rails - URI - UVA 514

May 28th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.67 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define forn(l, r) for(int i = l; i < (r); ++i)
  4. #define forj(l, r) for(int j = l; j < (r); ++j)
  5. #define TAM 1000100
  6. #define SYNC ios::sync_with_stdio(0);
  7. #define $ << ' ' <<
  8. #define F first
  9. #define S second
  10. #define endl '\n'
  11.  
  12.  
  13. using namespace std;
  14.  
  15. using ll = long long int;
  16. using ii = pair<int, int>;
  17. using vii = vector<ii>;
  18. using vi = vector<int>;
  19. using graph = vector<vi>;
  20. const int INF = 0x3f3f3f3f;
  21. const int MAXN = 112345;
  22. const ll mod = 1000000007;
  23.  
  24.  
  25. int main() {
  26.     //SYNC
  27.     vector<string> ans;
  28.     stack<int> ptA, stt;
  29.     queue<int> ptB;
  30.     int n, vag;
  31.     while (cin >> n && n) {
  32.         while (cin >> vag && vag) {
  33.             while(!ptA.empty()) ptA.pop();
  34.             while(!ptB.empty()) ptB.pop();
  35.             while(!stt.empty()) stt.pop();
  36.             for (int i = n; i > 0; --i) {
  37.                 ptA.push(i);
  38.             }
  39.             ptB.push(vag);
  40.             for (int i = 1; i < n; ++i) {
  41.                 int j;
  42.                 cin >> j;
  43.                 ptB.push(j);
  44.             }
  45.             while (!ptA.empty()) {
  46.                 //cout << "x\n";
  47.                 stt.push(ptA.top());
  48.                 ptA.pop();
  49.                 //cout << stt.top() << ' ' << ptB.front() << endl;
  50.                 while (!stt.empty() && stt.top() == ptB.front()) {
  51.                     stt.pop();
  52.                     ptB.pop();
  53.                 }
  54.             }
  55.            
  56.             if (stt.empty()) ans.push_back("Yes");
  57.             else ans.push_back("No");
  58.         }
  59.         if (!vag) {
  60.             ans.push_back("");
  61.         }
  62.     }
  63.     for (auto x : ans) {
  64.         cout << x << endl;
  65.     }
  66.     return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment