-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2_4.cpp
42 lines (41 loc) · 948 Bytes
/
2_4.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
using namespace std;
int main(){
int m,n,k;
cin>>m>>n>>k;
for(int i=0;i<k;i++){
int seq[n];
for(int j=0;j<n;j++){
cin>>seq[j];
}
int sstack[m];
int top=-1;
int count=0;
int ppop=0,ppush=0;
while(ppop<=n&&ppush<=n&&ppop<=ppush&&top<m&&count<n){
if(top==-1){
top++;
ppush++;
sstack[top]=ppush;
}
if(sstack[top]==seq[count]){
ppop++;
top--;
count++;
}
else if(sstack[top]<seq[count]){
top++;
ppush++;
sstack[top]=ppush;
}
else {
break;
}
}
if(ppop==ppush&&ppop==n&&count==n){
printf("YES\n");
}
else printf("NO\n");
}
return 0;
}