求卡常
查看原帖
求卡常
639198
Steve_xh楼主2024/6/25 13:19

最后一个点 WA,因为我是用时限判 -1 的,但我程序跑太久会导致本来没 -1 的他以为是 -1 了

#include<bits/stdc++.h>
#define pass
using namespace std;
#define int long long
struct LineOfCommand{
	int l;
	string c;
	const bool operator<(const LineOfCommand& o) const{return this->l<o.l;}
}c[1005];
int tl1,tl2,ans=0,mtol[30005],lines=0,vars[26];
char v;
 clock_t st_time;
inline void end_program(int t){
	cout<<t;
	exit(0);
}
inline int atoi(string x,int beg){
	int reans=0;
	for(int i=beg;i<x.size()&&'0'<=x[i]&&x[i]<='9';++i)
		reans=(reans<<1)+(reans<<3)+(x[i]^48);
	return reans;
}
int run(int now){
	stringstream ststr;
	if(now>lines)
		end_program(ans);
	++ans;
	if(ans>=10000000
 	||clock()-st_time>=199800ll
	)
		end_program(-1);
//	cerr<<"now command:"<<c[now].c<<'\n';
//	cerr<<"now vars:";
//	for(int i=0;i<26;i++)
//		cerr<<vars[i]<<' ';
//	cerr<<'\n';
	if(c[now].c[c[now].c.size()-1]=='?')
		pass;
	else if(c[now].c==" END")
		end_program(ans);
	else if(c[now].c[1]=='G'&&c[now].c[2]=='O'){
//		cerr<<"GO to line "<<atoi(c[now].c,3)<<'\n';
		return mtol[atoi(c[now].c,4)];
	}
	else if(c[now].c[1]=='I'&&c[now].c[2]=='F'){
		sscanf(c[now].c.c_str()," IF %c=%lld GO %lld",&v,&tl1,&tl2);
		if(vars[v-'A']==tl1)
			return mtol[tl2];
	}
	else
//		cerr<<"assignment\n",
		vars[c[now].c[1]-'A']+=atoi(c[now].c,3);
// 	ststr.flush();
	return now+1;
}
signed main(){
//	freopen("P5756_10.in","r",stdin);
	for(int t;cin>>t;){
		c[++lines].l=t;
		getline(cin,c[lines].c);
	}
	sort(c+1,c+lines+1);
	for(int i=1;i<=lines;++i)
		mtol[c[i].l]=i;
 	st_time=clock();
	for(int last=1;;)
		last=run(last);
	end_program(ans);
	return 0;
}
/*

10 A+1
20 IF A=5 GO 60
60 END
30 A+2
40 A?
50 GO 20

*/ 
2024/6/25 13:19
加载中...