QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#275867#7880. Streak ManipulationSGColin#WA 0ms3912kbC++141.2kb2023-12-05 10:20:382023-12-05 10:20:39

Judging History

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

  • [2023-12-05 10:20:39]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3912kb
  • [2023-12-05 10:20:38]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

inline int rd() {
    int x = 0;
    bool f = 0;
    char c = getchar();
    for (; !isdigit(c); c = getchar()) f |= (c == '-');
    for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
    return f ? -x : x;
}

#define eb emplace_back
#define all(s) (s).begin(), (s).end()
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)

#define N 200007

char s[N];

int n, m, k, pre[N], sum[N], dp[N][6];

int main() {
	n = rd(); m = rd(); k = rd();
	scanf("%s", s + 1);
	int lst = 0;
	rep(i, 1, n) {
		pre[i] = lst;
		sum[i] = sum[i - 1];
		if (s[i] == '0') {lst = i; ++sum[i];}
	} 
	auto valid = [&](int l) {
		rep(i, 0, n) rep(j, 1, k) dp[i][j] = 1e9;
		rep(i, 1, n)
			if (i >= l && (i == n || s[i + 1] == '0')) {
				rep(j, 1, k) 
					dp[i][j] = min(dp[i][j], dp[max(0, pre[i - l + 1] - 1)][j - 1] + sum[i] - sum[i - l]);
				if (dp[i][k] <= m) return true;
			}
		return false;
		
	};
	if (!valid(1)) {puts("-1"); return 0;}
	int l = 1, r = n / k;
	while (l < r) {
		int mid = (l + r + 1) / 2;
		valid(mid) ? l = mid : r = mid - 1;
	}
	printf("%d\n", l);
	return 0;
}

详细

Test #1:

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

input:

8 3 2
10110110

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3788kb

input:

12 3 3
100100010011

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

4 4 4
0000

output:

-1

result:

ok 1 number(s): "-1"

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3816kb

input:

1000 200 5
0001001000101001110010011001101010110101101100010100111110111111010010001100100111100101011100011101011001110010111100100100011001010011000100011111010110100001101110101001110000001000111010000111110100111101100110011010011111000111101001010011000111010111010100101111100000100001011001010...

output:

90

result:

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