社区讨论
求助
P3952[NOIP 2017 提高组] 时间复杂度参与者 2已保存回复 4
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 3 条
- 当前快照
- 1 份
- 快照标识符
- @mm4x0vls
- 此快照首次捕获于
- 2026/02/27 21:15 2 周前
- 此快照最后确认于
- 2026/03/01 17:55 上周
对于第一个测试点:
in:
CPP4
4 O(n^2)
F a 32 n
F b 69 n
E
E
2 O(n^2)
F a 60 n
E
4 O(n^4)
F a 67 n
F b 36 n
E
E
10 O(n^4)
F a 78 81
F b 73 98
F c 7 n
F d 46 n
F e 35 n
E
E
E
E
E
out
CPPYes
No
No
No
代码运行结果和测试点一样,但还是被判WA是怎么回事?
CPP#include<bits/stdc++.h>
using namespace std;
int isdigit1(string s){
for(int i=0;i<s.length();++i)
if(!isdigit(s[i])) return 0;
return 1;
}
stack<int> p;
int t,L,cnt1,chon[300],ff[110],k,q[110],ss[110];
string ch,f,ii,x,y;
int main(){
cin>>t;
while(t--){
cin>>L>>ch;
if(ch[2]=='1') k=0;
else k=ch[4]-'0';
int tem=0,maxx=0,cnt=1,ww=0;
for(int i=1;i<=L;++i){
cin>>f;int w=0;
if(f[0]=='F'){
cin>>ii>>x>>y;
q[i]=ii[0];
if(chon[ii[0]]) tem=1;
chon[ii[0]]=1;
p.push(i);
if(cnt1){
cnt++;
continue;
}
if(isdigit1(x)&&y[0]=='n') w=1;
else if(isdigit1(x)&&isdigit1(y)){
w=0;
if(atoi(x.c_str())>atoi(y.c_str())) ss[++cnt1]=i;
}
else if(x[0]=='n'&&y[0]=='n') w=0;
else if(x[0]=='n'&&isdigit1(y)) w=0,ss[++cnt1]=i;
ff[++cnt]=ff[cnt-1]+w;
maxx=max(maxx,ff[cnt]);
}
else{
if(p.empty()){
tem=1;
break;
}
if(ss[cnt1]==p.top()) ss[cnt1--]=0;
chon[q[p.top()]]=0;
cnt--;
p.pop();
}
}
if(!p.empty()) cout<<"ERR\n";
else if(!tem){
if(maxx==k) cout<<"Yes\n";
else cout<<"No\n";
}
else if(tem)
cout<<"ERR\n";
while(!p.empty()) p.pop();
memset(ff,0,sizeof(ff));
memset(chon,0,sizeof(chon));
memset(q,0,sizeof(q));
}
return 0;
}
回复
共 4 条回复,欢迎继续交流。
正在加载回复...