QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#526428#7880. Streak Manipulationmhw#WA 1ms3852kbC++231.3kb2024-08-21 15:43:282024-08-21 15:43:29

Judging History

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

  • [2024-08-21 15:43:29]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3852kb
  • [2024-08-21 15:43:28]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const i64 P = 998244353;
const int inf = 1e9;
void solve() {
    string s;
    int n, m, k;
    cin >> n >> m >> k >> s;
    n++;
    s = "00" + s;
    vector<int> sum(n + 1);
    for (int i = 2; i <= n; i++) sum[i] = sum[i - 1] + (s[i] == '1');
    auto check = [&](int x) -> bool {
        vector dp(n + 1, vector<int>(k + 1, inf));
        dp[0][0] = 0;
        for (int i = 2; i <= n; i++) {
            for (int j = 0; j < k; j++) {
                dp[i][j] = min(dp[i - 1][j], dp[i][j]);
                if (i + x - 1 <= n && s[i - 1] == '0')
                    dp[i + x - 1][j + 1] = min(dp[i + x - 1][j + 1], dp[i - 2][j] + (x - sum[i + x - 1] + sum[i - 1]));
            }
            dp[i][k] = min(dp[i - 1][k], dp[i][k]);
        }
        return dp[n][k] <= m;
    };
    int l = 1, r = n;
    while (l < r) {
        int mid = (l + r + 1) / 2;
        if (check(mid)) l = mid;
        else r = mid - 1;
    }
    if (check(l)) cout << l << '\n';
    else cout << -1 << '\n';
}
int main() {
    // ios::sync_with_stdio(0); cin.tie(0), cout.tie(0);
    int t = 1; 
    // cin >> t;
    while(t--) solve();
    return 0;
}
/*
3
8 3 2
10110110
12 3 3
100100010011
4 4 4
0000
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

8 3 2
10110110

output:

3

result:

ok 1 number(s): "3"

Test #2:

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

input:

12 3 3
100100010011

output:

2

result:

ok 1 number(s): "2"

Test #3:

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

input:

4 4 4
0000

output:

-1

result:

ok 1 number(s): "-1"

Test #4:

score: -100
Wrong Answer
time: 1ms
memory: 3852kb

input:

1000 200 5
0001001000101001110010011001101010110101101100010100111110111111010010001100100111100101011100011101011001110010111100100100011001010011000100011111010110100001101110101001110000001000111010000111110100111101100110011010011111000111101001010011000111010111010100101111100000100001011001010...

output:

96

result:

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