QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#153243#6860. Binary Numberneko_nyaaAC ✓8ms3808kbC++231.0kb2023-08-29 19:15:472023-08-29 19:15:49

Judging History

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

  • [2023-08-29 19:15:49]
  • 评测
  • 测评结果:AC
  • 用时:8ms
  • 内存:3808kb
  • [2023-08-29 19:15:47]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define int long long
const int M = 998244353;
int modpow(int n, int k) {
	int ans = 1;
	while (k) {
		if (k % 2) ans = (ans*n) % M;
		n = (n*n) % M; k /= 2;
	}
	return ans;
}

bool allOne(string s) {
	for (char c: s) {
		if (c == '0') return 0;
	}
	return 1;
}

void solve() {
	int n, k; cin >> n >> k;
	string s; cin >> s;
	if (n == 1) {
		if (k % 2) {
			if (s[0] == '0') {
				s[0] = '1';
			} else {
				s[0] = '0';
			}
		}
		cout << s << '\n';
		return;
	}
	if (allOne(s)) {
		if (k == 1) {
			s.back() = '0';
		}
		cout << s << '\n';
		return;
	}

	for (int i = 0; i < n; i++) {
		if (s[i] == '0') {
			if (k > 0) {
				k--;
				int j = i;
				while (j < n && s[j] == '0') j++;
				j--;
				for (int ff = i; ff <= j; ff++) {
					s[ff] = '1';
				}
				i = j;
			}
		}
	}
	cout << s << '\n';
}

signed main() {
	ios::sync_with_stdio(0); cin.tie(0);

	int t; cin >> t;
	while (t--) {
		solve();
	}

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 8ms
memory: 3808kb

input:

59471
11 523478562876
11011111010
10 1000
1110101110
11 13333
10101000011
11 9
10000001001
11 1000
10110100100
11 4
11000010111
11 1000
11100100011
11 100
10000000001
11 23333
10111101110
9 233
110110010
11 648953764538
10011110011
9 233333
101010111
11 9
10001011001
11 8
10100001100
10 77777777
100...

output:

11111111111
1111111111
11111111111
11111111111
11111111111
11111111111
11111111111
11111111111
11111111111
111111111
11111111111
111111111
11111111111
11111111111
1111111111
11111111111
11111111111
11111111010
11111111111
11111111111
11111111111
11111111111
11111111000
11111111111
1111010
1111111111...

result:

ok 59471 lines