QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#463052#1289. A + B ProblemTaoRanAC ✓9ms6120kbC++141.5kb2024-07-04 12:22:082024-07-04 12:22:08

Judging History

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

  • [2024-07-04 12:22:08]
  • 评测
  • 测评结果:AC
  • 用时:9ms
  • 内存:6120kb
  • [2024-07-04 12:22:08]
  • 提交

answer

#include<bits/stdc++.h>
#define pt putchar
using namespace std;
typedef long long ll;
int read();void write(int);
const int N=1e6+5;
int n,m;
int a[N*2];
int ans[N*2];

void solve(){
	n=read();m=read();
	if(n<m)swap(n,m);
	int lim=n+1;
	for(int i=0;i<=lim;i++)
		ans[i]=0;
	char c=getchar();
	while(c!='0'&&c!='1')c=getchar();
	for(int i=1;i<=n+m;i++){
		a[i]=c-'0';
		c=getchar();
	}
	int la=m;
	while(la>=1&&!a[la])la--;
	for(int p=m;p<n+m;p++){
		if(!la)break;
		if(a[p+1]==0){
			if(m-la>=n+m-p-1){
				break;
			}
			ans[m-la]--;
			ans[n+m-p-1]++;
			//printf("%d:%d %d\n",p,m-la,n+m-p-1);
			
			la--;
			while(la>=1&&!a[la])la--;
			if(!la)break;
		}
	}
	for(int i=1;i<=m;i++){
		ans[m-i]+=a[i];
	}
	for(int i=1;i<=n;i++){
		ans[n-i]+=a[i+m];
	}
	for(int i=0;i<=lim;i++){
		int ji=ans[i]/2;
		if(ans[i]<=-1)ji++;
		ans[i]=(ans[i]%2+2)%2;
		ans[i+1]+=ji;
	}
	int i=lim;
	while(i>=1&&!ans[i])i--;
	for(;i>=0;i--){
		pt(ans[i]+'0');
	}pt('\n');
}

int main(){//fc partition.out example2.out
	//freopen("example2.in","r",stdin);freopen("partition.out","w",stdout);
	int T=read();
	while(T--){
		solve();
	}
	return 0;
}
/*
7 4
10111011111

1
7 6
0001010011011

*/

int read(){
	int x=0,f=1;
	char c='A';
	while(c<'0'||c>'9'){
		c=getchar();
		if(c=='-')f=-f;
	}
	while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
	return x*f;
}
void write(int x){
	if(x<0){
		pt('-');
		x=-x;
	}
	if(x>9){
		write(x/10);
	}
	pt(x%10+'0');
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5640kb

input:

3
4 3
1000101
2 2
1111
1 1
00

output:

1101
110
0

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 9ms
memory: 6120kb

input:

11110
10 8
111011010011100100
3 5
01011000
7 6
1110101010000
9 1
0110100101
1 9
0100001110
8 10
000101101011111000
9 6
011111111000111
1 9
1011101101
10 7
00100011000100000
4 9
1000101101010
8 4
100100110000
8 9
00101111011000101
8 9
11000000101011110
7 6
1111010100110
2 9
01001110101
4 5
100010100
...

output:

10011010100
11100
10101000
110100101
100001110
10000001100
1000010111
111101101
1110100000
111101010
11110000
1000011101
1001011110
10101110
101110101
11100
1111010
1000010
1011100010
10010101001
10010001
1001010
1000000010
1110
111
1111110001
10110111
1100010101
10000000
111000011
110
11111
1100101...

result:

ok 11110 lines