QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#499537#6726. Turn It OffpagohiaTL 0ms3624kbC++14543b2024-07-31 15:30:412024-07-31 15:30:41

Judging History

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

  • [2024-07-31 15:30:41]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3624kb
  • [2024-07-31 15:30:41]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

string s;
int L, k, len;

bool f(int LL)
{
 int cnt = 0;
 for(int i = 0; i < len; i++)
 if(s[i] == '1')
 {
 i += (LL - 1);
 cnt++;
 if(cnt > k)
 return 1;
 }
 return 0;
}

void F(int l, int r)
{
 int m = (l + r) / 2;
 if(f(l) && !f(l + 1))
 L = l + 1;
 else if(f(m))
 F(m, r);
 else
F(l, m - 1);
}

int main()
{
 int t;
 cin >> t;
 while(t--)
 {
cin >> len >> k;
 cin >> s;
 L = len / k + 1;
if(len % k == 0)
 L--;
 F(1, L);
 cout << L << endl;
 }
}

详细

Test #1:

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

input:

2
10 4
0101011111
3 1
010

output:

3
1

result:

ok 2 number(s): "3 1"

Test #2:

score: -100
Time Limit Exceeded

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

result: