Advertisement
Saleh127

UVA 514 / Stack

Oct 28th, 2021
841
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. /***
  2.  created: 2021-10-28-23.44.07
  3. ***/
  4.  
  5. #include <bits/stdc++.h>
  6. using namespace std;
  7. #define ll long long
  8. #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
  9. #define get_lost_idiot return 0
  10. #define nl '\n'
  11.  
  12. int main()
  13. {
  14.    ios_base::sync_with_stdio(0);
  15.    cin.tie(0);cout.tie(0);
  16.  
  17.  
  18.    ll n,m,i,j,k,l;
  19.  
  20.    while(cin>>n && n)
  21.    {
  22.         ll a[n+4];
  23.  
  24.         while(cin>>a[0] && a[0])
  25.         {
  26.              for(i=1;i<n;i++)
  27.              {
  28.                   cin>>a[i];
  29.              }
  30.  
  31.              k=0;
  32.  
  33.              stack<ll>x;
  34.  
  35.              for(i=1;i<=n;i++)
  36.              {
  37.                   x.push(i);
  38.  
  39.                   while(x.empty()==false && a[k]==x.top())
  40.                   {
  41.                        k++;
  42.                        x.pop();
  43.                   }
  44.              }
  45.  
  46.              if(x.size()==0) cout<<"Yes"<<endl;
  47.              else cout<<"No"<<endl;
  48.         }
  49.  
  50.         cout<<endl;
  51.    }
  52.  
  53.  
  54.    get_lost_idiot;
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement