QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#496430#1289. A + B ProblemrollerZWA 95ms7296kbC++231.6kb2024-07-28 10:06:182024-07-28 10:06:19

Judging History

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

  • [2024-07-28 10:06:19]
  • 评测
  • 测评结果:WA
  • 用时:95ms
  • 内存:7296kb
  • [2024-07-28 10:06:18]
  • 提交

answer

#include <bits/stdc++.h>
#define pii pair<int, int>
#define fi first
#define se second
#define MP make_pair
#define ep emplace
#define eb emplace_back
//#define int long long
#define rep(i, j, k) for (int i = j; i <= k; i++)
#define per(i, j, k) for (int i = j; i >= k; i--)
typedef double db;
typedef long double ldb;
typedef long long ll;
typedef __int128 lll;
typedef unsigned long long ull;
typedef unsigned int ui;
using namespace std;

int read() {
	int s = 0, f = 1;
	char c = getchar();
	while (c < '0' || c > '9') f ^= (c == '-'), c = getchar();
	while (c >= '0' && c <= '9') s = s * 10 + c - '0', c = getchar();
	return f ? s : -s;
}

int n,m,s[200005],a[100005],b[100005],pos[200005],id[200005],ans[100005],tot;

signed main() {
	for(int T=read();T--;){
		n=read(),m=read();
		int nn=n,mm=m,top=0;tot=0;
		rep(i,1,n+m)scanf("%1d",&s[i]);
		rep(i,1,max(n,m))a[i]=b[i]=0;
		rep(i,1,n+m)if(s[i])++top,id[pos[top]=i]=top;
		rep(i,1,nn+mm){
			if(!n||!m){
				if(!n)a[m--]=s[i];
				if(!m)a[n--]=s[i];
				continue;
			}
			if(s[i]){
				if(n<m){
					if(pos[id[i]+m-n]&&nn+mm-pos[id[i]+m-n]+m-n>=m)a[n--]=1;
					else b[m--]=1;
				}else{
					if(pos[id[i]+n-m]&&nn+mm-pos[id[i]+n-m]+n-m>=n)b[m--]=1;
					else a[n--]=1;
				}
			}else{
				if(n<m)n--;
				else m--;
			}
		}
		n=nn,m=mm;
		int j=0;
		rep(i,1,max(n,m)){
			ans[++tot]=(a[i]^b[i]^j)&1;
			j=(a[i]+b[i]+j)>>1;
		}
		if(j)ans[++tot]=1;
		bool flag=1;
		per(i,tot,1){
			flag&=!ans[i];
			if(!flag)putchar(ans[i]+'0');
		}
		if(flag)putchar('0');
		putchar('\n');
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3844kb

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: 95ms
memory: 7296kb

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
11000
10101000
110100101
100001110
1111111000
1000010111
111101101
1000110001
111101010
10110010
1000000101
101011110
10101110
101110101
10100
1101100
1000010
1011011110
10010011011
10001001
111100
111011010
1110
111
111010111
110111
1100010101
1110000
111000011
110
11111
11001010
111111...

result:

wrong answer 2nd lines differ - expected: '11100', found: '11000'