#include <bits/stdc++.h> using namespace std; char a[225]; int top = 0; int id=0; void push(int x) { top++; a[top] = x; return; } void pop() { top--; return; } int gettop() { int t = a[top]; return t; } void clear() { top = 0; return; } int main() { int n; int b[1001]; cin>>n; for(int i=1;i<=n;i++){ cin>>b[i]; } int j=1; int mx; push(1); for(int i=1;i<=n;i++){ mx=max(mx,top); if(b[i]>gettop()){ while(b[i]<=gettop()){ push(j); j++; } } else if(b[i]==gettop()){ pop(); } else if(b[i]<1){ cout<<"no"; return 0; } } if(top==0){ cout<<"yes"<<endl; cout<<mx; } else{ cout<<"no"; } return 0; }
共 1 条回复
把
cin >> n
放到freopen
后面试试