QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#450851#1289. A + B ProblemFroranzenAC ✓25ms16868kbC++202.4kb2024-06-22 18:36:002024-06-22 18:36:01

Judging History

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

  • [2024-06-22 18:36:01]
  • 评测
  • 测评结果:AC
  • 用时:25ms
  • 内存:16868kb
  • [2024-06-22 18:36:00]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(i, f, t) for(int i(f); i <= t; ++i)
#define re(i, t) for(int i(1); i <= t; ++i)
#define per(i, t, f) for(int i(t); i >= f; --i)
#define pe(i, t) for(int i(t); i >= 1; --i) 
#define nx(i, u) for(int i(head[u]); i; i = e[i].nxt)
typedef long long ll;
typedef unsigned long long ull; 
using namespace std;
typedef pair <int, int> pii;
#define pb push_back
#define eb emplace_back 
#define fi first
#define se second
#define Ls (ix(l, mid))
#define Rs (ix(mid+1, r))
#define ix(l, r) ((l + r) | (l != r))  
#define mp(i, j) (make_pair(i, j))
//#define int long long
#define inf 0x3f3f3f3f
#define i128 __int128  
#define INF 0x3f3f3f3f3f3f3f3f
namespace IO {
char buf[1 << 21], *p1 = buf, *p2 = buf, buf1[1 << 21];
inline char gc() {return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++;}
template<class I>
inline void read(I &x) {x = 0;I f = 1;char c = gc();while (c < '0' || c > '9') {if (c == '-') {f = -1;} c = gc();}while (c >= '0' && c <= '9') {x = x * 10 + c - '0';c = gc();}x *= f;}
template<class I>
inline void write(I x) {if (x == 0) {putchar('0');return;}I tmp = x > 0 ? x : -x;if (x < 0) {putchar('-');}int cnt = 0;while (tmp > 0) {buf1[cnt++] = tmp % 10 + '0';tmp /= 10;}while (cnt > 0)putchar(buf1[--cnt]);}
#define outn(x) write(x), putchar('\n')
#define out(x) write(x), putchar(' ')
} using namespace IO;
#define look_memory cerr<<abs(&sT-&eD)/1024.0/1024<<'\n'
int sT;

const int N = 4e6 + 5;
int T, n, m;
char s[N];
int a[N], b[N];
 
int pos[N], ax[N], ay[N];

void solve () {
	if(n < m) swap(n, m);
	int len = n + m + 2; 
	int L = 0;
	int sz = 0;
	re(i, m) {
		sz += (!a[i]);
		if(a[i]) {
			pos[++L] = m-i+1;
			ay[m-i+1] = 1;
		}
	}
	rep(i, m+1, n+m) {
		if(a[i]) ax[n-(i-m)+1] = 1;
	}  
	
	rep(i, m+1, n+m) { 
		if(!a[i]) {
			++sz;
			if(sz > m) break; 
			if(pos[L] > (n-(i-m)+1)) break;
			ay[pos[L]] = 0;
			--L;
			ax[n-(i-m)+1] = 1;
		} 
	}
	re(i, len) {
		b[i] = ax[i] + ay[i];
	}
	re(i, len) {
		b[i+1] += b[i]/2;
		b[i] &= 1;
	} 
	len = 1;
	re(i, n+m+2) { 
		if(b[i]) len = i;
	} 
	pe(i, len) {
		if(b[i]) putchar('1');
		else putchar('0');
	}
	puts(""); 
	re(i, n+m+2) {
		ax[i] = ay[i] = b[i] = 0;
	}
}	 
 
int main (){ 
	scanf("%d", &T);
	while(T--) {
		scanf("%d %d %s", &n, &m, s + 1);
		re(i, n+m) a[i] = s[i] - '0';
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 25ms
memory: 16868kb

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