82分求助

P3952 [NOIP2017 提高组] 时间复杂度

@[MithrilSword_XIV](/user/387037) 和我的问题一样 ```cpp #include<bits/stdc++.h> using namespace std; int read(){ int x=0; bool flag=false; char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-'){ flag=true; } ch=getchar(); } while(ch>='0'&&ch<='9'){ x=(x<<1)+(x<<3)+(ch-'0'); ch=getchar(); } return flag?-x:x; } char readc(){ char ch=getchar(); while(ch!='F'&&ch!='E'&&(ch<'a'||ch>'z')){ ch=getchar(); } return ch; } int readf(){ int x=0; char ch=getchar(); while(!((ch>='0'&&ch<='9')||ch=='n')){ ch=getchar(); } while(ch>='0'&&ch<='9'){ x=(x<<1)+(x<<3)+(ch-'0'); ch=getchar(); } if(ch=='n'){ return -1; } return x; } int reado(){ int x=0; bool flag=false; char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='n'){ flag=true; } ch=getchar(); } while(ch>='0'&&ch<='9'){ x=(x<<1)+(x<<3)+(ch-'0'); ch=getchar(); } return flag?x:0; } int T,L,t; bool mk[30]; stack<char>stk; void solve(){ for(int i=0;i<30;i++){ mk[i]=false; } while(!stk.empty()){ stk.pop(); } char ch,x; string s1,s2; int f=0,ans=0,l,r; bool flag=false,flag1=false; if(L&1){ flag=true; } while(L--){ ch=readc(); if(ch=='F'){ x=readc(); if(mk[x-97]){ flag=true; } mk[x-97]=true; stk.push(x); l=readf(),r=readf(); if(flag==true||flag1==true){ continue; } if(l!=-1&&r!=-1){ if(l>r){ flag1=true; } continue; }else if(r!=-1){ flag1=true; }else if(l==-1&&r==-1){ continue; }else{ f+=1; } }else{ if(stk.empty()){ flag=true; continue; } mk[stk.top()-97]=false; stk.pop(); if(stk.empty()){ ans=max(ans,f); flag1=false; f=0; } } } if(flag){ cout<<"ERR\n"; }else if(ans==t){ cout<<"Yes\n"; }else{ cout<<"No\n"; } return; } int main(){ T=read(); string str; while(T--){ L=read(); t=reado(); solve(); } return 0; } ```
by xxxalq @ 2024-01-18 22:58:10


|