QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#526473#7876. Cyclic Substringsrxzfn639RE 0ms0kbC++231.2kb2024-08-21 16:38:182024-08-21 16:38:18

Judging History

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

  • [2024-08-21 16:38:18]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-08-21 16:38:18]
  • 提交

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;
}

详细

Test #1:

score: 0
Runtime Error

input:

5
01010

output:


result: