QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#283973#7880. Streak ManipulationContrisElikemouthing#WA 5ms11612kbC++171.4kb2023-12-15 19:51:182023-12-15 19:51:18

Judging History

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

  • [2023-12-15 19:51:18]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:11612kb
  • [2023-12-15 19:51:18]
  • 提交

answer

#include <bits/stdc++.h>
#define eb emplace_back
#define pb pop_back
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef tuple<int, int, int> tu;
bool Mbe;

const int N = 2e5 + 200;
int n, m, k, s[N], pr[N], f[N][10];
char c[N];

bool chk(int x) {
	memset(f, 0x3f, sizeof(f));
	f[0][0] = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= k; j++)
			f[i][j] = min(f[i][j], f[i - 1][j]);
		if (i - x - 1 >= 0) {
			for (int j = 1; j <= k; j++) {
				f[i][j] = min(f[i][j], f[i - x - 1][j - 1] + x - (s[i] - s[i - x]));
			}
		}
	}
	return f[n][k] <= m;
}

void solve() {
	cin >> n >> m >> k >> (c + 1);
	for (int i = 1; i <= n; i++)
		s[i] = s[i - 1] + (c[i] - '0');
	// for (int i = 1; i <= n; i++) 
		// pr[i] = (c[i] == '0') ? i : pr[i - 1];
	// cout << chk(3) << '\n';
	int l = 1, r = n / k, res = -1;
	while (l <= r) {
		int mid = (l + r) >> 1;
		if (chk(mid)) res = mid, l = mid + 1;
		else r = mid - 1;
	}
	cout << res << '\n';
}

bool Med;
int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cerr << (&Mbe - &Med) / 1048576.0 << " MB\n";
	#ifdef FILE
		freopen("1.in", "r", stdin);s
		freopen("1.out", "w", stdout);
	#endif
	int T = 1;
	// cin >> T;
	while (T--) solve();
	cerr << (int)(1e3 * clock() / CLOCKS_PER_SEC) << " ms\n";
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

8 3 2
10110110

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 4ms
memory: 11600kb

input:

12 3 3
100100010011

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 0
Accepted
time: 4ms
memory: 11604kb

input:

4 4 4
0000

output:

-1

result:

ok 1 number(s): "-1"

Test #4:

score: 0
Accepted
time: 2ms
memory: 11612kb

input:

1000 200 5
0001001000101001110010011001101010110101101100010100111110111111010010001100100111100101011100011101011001110010111100100100011001010011000100011111010110100001101110101001110000001000111010000111110100111101100110011010011111000111101001010011000111010111010100101111100000100001011001010...

output:

99

result:

ok 1 number(s): "99"

Test #5:

score: 0
Accepted
time: 5ms
memory: 11604kb

input:

1000 200 5
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

40

result:

ok 1 number(s): "40"

Test #6:

score: -100
Wrong Answer
time: 5ms
memory: 11608kb

input:

1000 200 5
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

199

result:

wrong answer 1st numbers differ - expected: '-1', found: '199'