QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#499601#6726. Turn It OffpagohiaTL 0ms3556kbC++14637b2024-07-31 16:09:172024-07-31 16:09:17

Judging History

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

  • [2024-07-31 16:09:17]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3556kb
  • [2024-07-31 16:09:17]
  • 提交

answer


#pragma GCC optimize("Ofast")
#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()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0); 
 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: 3556kb

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: