QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#123206#6726. Turn It OfflhzawaAC ✓13ms3824kbC++141001b2023-07-11 21:11:082023-07-11 21:11:09

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-11 21:11:09]
  • 评测
  • 测评结果:AC
  • 用时:13ms
  • 内存:3824kb
  • [2023-07-11 21:11:08]
  • 提交

answer

// lhzawa(https://www.cnblogs.com/lhzawa/)
// Problem: E. Turn It Off
// Contest: QOJ - The 2019 ICPC China Shaanxi Provincial Programming Contest
// URL: https://qoj.ac/contest/1285/problem/6726
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
char s[N];
int main() {
	function<void ()> solve = []() -> void {
		int n, k;
		scanf("%d%d%s", &n, &k, s + 1);
		int l = 1, r = n, ans = n;
		function<int (int)> check = [&n, &k](int l) -> int {
			int c = 0;
			for (int i = 1; i <= n; ) {
				if (s[i] == '1') {
					i += l, c++;
				}
				else {
					i++;
				}
			}
			return c <= k;
		};
		for (; l <= r; ) {
			int mid = (l + r) >> 1;
			if (check(mid)) {
				ans = mid, r = mid - 1;
			}
			else {
				l = mid + 1;
			}
		}
		printf("%d\n", ans);
		return ;
	};
	int _;
	scanf("%d", &_);
	for (; _; _--) {
		solve();
	}
	return 0;
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

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

input:

2
10 4
0101011111
3 1
010

output:

3
1

result:

ok 2 number(s): "3 1"

Test #2:

score: 0
Accepted
time: 13ms
memory: 3824kb

input:

1109
47 36
11101110101001111110101101100001000011101001011
6 5
100010
35 26
00011111000000101010011010100101111
71 45
11101001000111011101101000000000010001100100110000001000011011001011000
32 23
00000100011110010101000110010110
36 30
110110000000000011010001100011111100
21 8
010000011010011101100
9...

output:

1
1
1
1
1
1
2
4
10
2
2
3
3
1
2
1
1
1
1
2
2
2
6
7
1
1
1
1
1
1
1
3
1
1
2
3
1
1
3
1
1
6
1
1
5
1
1
3
10
19
1
1
1
4
1
1
2
1
2
1
1
2
1
1
60
17
3
3
2
2
1
1
4
1
1
1
1
1
2
2
1
3
5
2
1
1
4
2
1
1
3
1
1
1
1
1
5
2
3
1
2
1
1
1
1
2
1
1
2
1
1
81
1
4
1
1
1
2
1
44
1
5
2
3
1
1
1
2
1
8
1
1
3
1
1
2
1
46
1
1
1
1
1
1
1
1
...

result:

ok 1109 numbers