QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#720710#9566. Topologyucup-team902#WA 0ms3684kbC++202.4kb2024-11-07 13:45:252024-11-07 13:45:27

Judging History

你现在查看的是最新测评结果

  • [2024-11-07 13:45:27]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3684kb
  • [2024-11-07 13:45:25]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define cs const
#define re register
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define fi first
#define se second
#define bg begin
cs int RLEN=1<<22|1;
char ibuf[RLEN],*ib,*ob;
inline char gc(){
    (ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
    return (ib==ob)?EOF:*ib++;
}
inline int read(){
	char ch=gc();
	int res=0;bool f=1;
	while(!isdigit(ch))f^=ch=='-',ch=gc();
	while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
	return f?res:-res;
}
inline ll readll(){
	char ch=gc();
	ll res=0;bool f=1;
	while(!isdigit(ch))f^=ch=='-',ch=gc();
	while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
	return f?res:-res;
}
inline int readstring(char *s){
	int top=0;char ch=gc();
	while(isspace(ch))ch=gc();
	while(!isspace(ch)&&ch!=EOF)s[++top]=ch,ch=gc();
	s[top+1]='\0';return top;
}

template<typename tp>inline void chemx(tp &a,tp b){(a<b)?(a=b):0;}
template<typename tp>inline void chemn(tp &a,tp b){(a>b)?(a=b):0;}


cs int N=200005;

int n;
char s[N];

pii f[N][2];

pii merge(pii x,pii y){
	if(y.se<0)y.se+=2;
	if(x.fi>x.se)return y;
	if(y.fi>y.se)return x;
	return pii(min(x.fi,y.fi),max(x.se,y.se));
}

void solve(){
	n=readstring(s);
	//cout<<n<<'\n';
	for(int i=1;i<=n;i++)
	for(int k=0;k<2;k++)f[i][k]=pii(1e9,0);
	if(s[1]=='1')f[1][1]=pii(1,1);
	if(s[1]=='0')f[1][0]=pii(1,1);
	if(s[1]=='2')f[1][0]=f[1][1]=pii(1,1);
	for(int i=2;i<=n;i++){
	for(int k=0;k<2;k++)if(f[i-1][k].fi<=f[i-1][k].se){
		pii x=f[i-1][k];
		if(s[i]=='0'||s[i]=='2'){
			if(k==0){
				f[i][k^1]=merge(f[i][k^1],pii(x.fi-1,x.se-1));
			}
			else {
				f[i][k^1]=merge(f[i][k^1],pii(x.fi+1,x.se+1));
			}
		}
		if(s[i]=='1'||s[i]=='2'){
			if(k==1){
				f[i][k^1]=merge(f[i][k^1],pii(x.fi-1,x.se-1));
			}
			else {
				f[i][k^1]=merge(f[i][k^1],pii(x.fi+1,x.se+1));
			}			
		}
	}
	if(f[i][0].fi==f[i][0].se&&f[i][0].fi==0){
		f[i][1]=merge(f[i][1],f[i][0]);
	}
	if(f[i][1].fi==f[i][1].se&&f[i][1].fi==0){
		f[i][0]=merge(f[i][0],f[i][1]);
	}
	cout<<i<<'\n';
	cout<<f[i][0].fi<<" "<<f[i][0].se<<'\n';
	cout<<f[i][1].fi<<" "<<f[i][1].se<<'\n';
	}
	int ans=1e9;
	for(int i=0;i<2;i++){
		if(f[n][i].fi<=f[n][i].se){
			ans=min(ans,f[n][i].fi);
		}
	}
	cout<<ans<<'\n';
}

int main(){
	#ifdef Stargazer
	freopen("1.in","r",stdin);
	#endif
	int T=read();
	while(T--)solve();

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3684kb

input:

4
1 1 2

output:

1
1
1
0

result:

wrong answer 1st numbers differ - expected: '3', found: '1'