QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#26516#1289. A + B ProblemWu_RenWA 183ms7300kbC++17968b2022-04-07 16:17:082022-04-29 03:53:48

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-04-29 03:53:48]
  • 评测
  • 测评结果:WA
  • 用时:183ms
  • 内存:7300kb
  • [2022-04-07 16:17:08]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
int T,n,m,a[100010],b[100010],p[200010],pos[200010];
char s[2000010];
void sol(){
	scanf("%d%d%s",&n,&m,s+1);
	for(int i=1;i<=max(n,m)+1;i++) a[i]=b[i]=0;
	int l=n,r=m,t=0;
	for(int i=1;i<=n+m;i++){
		p[i]=p[i-1]+(s[i]=='1');
		if(s[i]=='1') pos[++t]=i;
	}
	assert(p[n+m]==t);
	for(int i=1;i<=n+m;i++){
		if(l>r) swap(a,b),swap(l,r),swap(n,m);
		if(s[i]=='1'){
			if(!l) b[r--]=1;
			else{
				if(p[i]+r-l+1<=p[n+m]&&pos[p[i]+r-l+1]-pos[p[i]]-(r-l)<l) a[l--]=1;
				else b[r--]=1;
			}
		}
		else{
			if(l) a[l--]=0;
			else b[r--]=0;
		}
//		for(int j=l+1;j<=n;j++) cout<<a[j];puts("");
//		for(int j=r+1;j<=m;j++) cout<<b[j];puts("");
	}
	n=max(n,m); 
	for(int i=1;i<=n;i++) a[i]=a[i]+b[i];
	for(int i=1;i<=n;i++) a[i+1]+=a[i]/2,a[i]&=1;
	if(a[n+1]) n++;
	while(!a[n]&&n>1) n--;
	for(int i=n;i>=1;i--) printf("%d",a[i]);puts("");
}
int main(){
	scanf("%d",&T);
	while(T--) sol();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
4 3
1000101
2 2
1111
1 1
00

output:

1101
110
0

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 183ms
memory: 7300kb

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
1011011111
10010101001
10001101
1001010
111111110
1110
111
1111110001
10110111
1100010101
1111000
111000011
110
11111
11001010
...

result:

wrong answer 19th lines differ - expected: '1011100010', found: '1011011111'