QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#467327#1289. A + B ProblemNephren_SakuraRE 0ms0kbC++141.2kb2024-07-08 15:48:242024-07-08 15:48:24

Judging History

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

  • [2024-07-08 15:48:24]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-07-08 15:48:24]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
int t,n,m,a[2000005];
int b[1000005],c[1000005];
int ans[1000005];
stack<int> stk;
signed main(){
	freopen("partition.in","r",stdin);
	freopen("partition.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>t;
	while(t--){
		cin>>n>>m;
		int s=0;
		for(int i=1; i<=n+m; i++){
			char c;
			cin>>c;
			a[i]=c-'0';
			s+=a[i];
		}
		if(n>m) swap(n,m);
		int nwb=n,nwc=m;
		for(int i=1; i<=n; i++){
			b[--nwb]=a[i];
			if(a[i]) stk.push(nwb);
		}
		for(int i=1; i<=m; i++){
			if(a[n+i]==1) c[--nwc]=a[n+i];
			else if(stk.empty()==false&&nwc-1>stk.top()){
				c[--nwc]=1;
				b[stk.top()]=0;
				stk.pop();
			}
			else
				c[--nwc]=0;
		}
		while(!stk.empty()) stk.pop();
		for(int i=0; i<max(n,m)+1; i++){
			ans[i]+=b[i]+c[i];
			ans[i+1]+=ans[i]/2;
			ans[i]%=2;
		}
		for(int i=0; i<n; i++)
			b[i]=0;
		for(int i=0; i<m; i++)
			c[i]=0;
		bool f=false;
		for(int i=max(n,m); i>=0; i--){
			if(ans[i]){
				cout<<ans[i];
				f=true;
			}
			else if(f)
				cout<<ans[i];
			ans[i]=0;
		}
		if(!f) cout<<0;
		cout<<'\n';
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

input:

3
4 3
1000101
2 2
1111
1 1
00

output:


result: