QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#893950#1289. A + B ProblemlinanchenWA 24ms8120kbC++141.4kb2025-02-11 08:43:452025-02-11 08:43:45

Judging History

This is the latest submission verdict.

  • [2025-02-11 08:43:45]
  • Judged
  • Verdict: WA
  • Time: 24ms
  • Memory: 8120kb
  • [2025-02-11 08:43:45]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#ifdef Anson
	#define debug
#else
	#ifdef debug
		#undef debug
	#endif
#endif
const int N=1e6+5;
char s[N<<1];int n,m,sum0;
bool book[N<<1],a[N],b[N],ans[N];
int main() {
#ifdef Anson
	#ifdef debug
		puts("function main");
	#endif
	freopen("C:\\Users\\Administrator\\Documents\\input.txt","r",stdin);
//	freopen("output.txt","w",stdout); 
#else
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
#endif
	int T;scanf("%d",&T);
	for(;T--;) {
		scanf("%d %d %s",&n,&m,s+1);bool flag=false;int t=max(n,m)+1;
		for(int i=1;i<=n+m;i++){book[i]=false;sum0=sum0+(s[i]=='0');}
		for(int i=1;i<=t;i++){ans[i]=a[i]=b[i]=false;}
		for(int i=1,x=n,y=m;i<=n+m;i++) {
			if(s[i]=='0') {
				if((x<=y||!y)&&x){book[i]=true;x--;}
				else	y--;
			}
			else {
				if((x<y||!x)&&y)y--;
				else{book[i]=true;x--;}
			}
		}
		for(int i=1,x=n,y=m;i<=n+m;i++) {
			if(book[i])	a[x--]=(s[i]=='1');
			else		b[y--]=(s[i]=='1');
		}
		flag=false;
		for(int i=1;i<=t;i++) {
			if((flag&&a[i])||(flag&&b[i])||(a[i]&&b[i])) {
				ans[i]=(flag&&a[i]&&b[i]);flag=true;
			}
			else{ans[i]=(flag||a[i]||b[i]);flag=false;}
		}
		flag=false;
		for(int i=t;i>=1;i--)
			if(flag||ans[i]) {
				flag=true;putchar(ans[i]?'1':'0');
			}
		if(!flag)putchar('0');putchar('\n');
	}
	return 0;
}
#ifdef Anson
	#undef Anson
#endif
#ifdef debug
	#undef debug
#endif

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 24ms
memory: 8120kb

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:

10010000000
11100
10011100
110100101
100001110
1111111110
1000010111
111101101
1110100000
111101010
11110000
1000001101
1001011110
10101110
101110101
11100
1111010
1000010
1010001011
10001000101
10000101
1001000
111111110
1110
111
1111110001
10110111
1011010101
1111000
111000011
110
11111
11001010
1...

result:

wrong answer 1st lines differ - expected: '10011010100', found: '10010000000'