সোমবার, ২৩ জানুয়ারী, ২০১৭

UVA 514 Rails

#include<bits/stdc++.h>
using namespace std;
main()
{
    long  n;
    while(cin>>n)
    {
        long ar[100010]={0},i,cnt,pos;
        if(n==0)
                break;
            while(1)
            {
                cin>>ar[0];
                if(ar[0]==0)
                    {
                        cout<<endl;
                        break;
                    }
                for(i=1;i<n;i++)
                    {
                        cin>>ar[i];
                    }
               cnt=1,pos=0;
                stack<long>st;
               while(cnt<=n)
                {
                    st.push(cnt);
                    while(!st.empty()&&st.top()==ar[pos])
                    {
                        st.pop();
                        pos++;
                       if(pos>=n)
                        break;
                    }
                    cnt++;
                }
        if(st.empty())
            cout << "Yes" << endl;
        else
cout << "No" << endl;
        }
    }
}

কোন মন্তব্য নেই:

একটি মন্তব্য পোস্ট করুন

Factorization with prime Sieve

vector <int> prime; char sieve[1000009]; int N=1000009; void primeSieve ( ) { sieve[0] = sieve[1] = 1; prime.push_back(2); ...