Created
May 28, 2015 06:01
-
-
Save sukeesh/e407dbc9b35b8b9cd6e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<stdio.h> | |
#include<vector> | |
using namespace std; | |
int main() | |
{ | |
while(1) | |
{ | |
int t,n=1; | |
scanf("%d",&t); | |
if(t==0) | |
{ | |
return 0; | |
} | |
int a[t],i; | |
for(i=0;i<t;i++) | |
{ | |
scanf("%d",&a[i]); | |
} | |
vector <int> dest(0); | |
vector <int> side(0); | |
for(i=0;i<t;i++) | |
{ | |
if(a[i]==n) | |
{ | |
dest.push_back(n); | |
n++; | |
a[i]=0; | |
} | |
else if(side.size()>0 && side.back()==n) | |
{ | |
dest.push_back(n); | |
side.pop_back(); | |
n++; | |
i--; | |
} | |
else if(a[i]!=0) | |
{ | |
if(side.size()>0) | |
{ | |
if(a[i]>side.back()) | |
{ | |
printf("no\n"); | |
goto s; | |
} | |
} | |
side.push_back(a[i]); | |
a[i]=0; | |
} | |
} | |
printf("yes\n"); | |
s:{} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment