QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#278384 | #7880. Streak Manipulation | daredsakura# | WA | 1ms | 3592kb | C++14 | 2.0kb | 2023-12-07 15:26:57 | 2023-12-07 15:26:58 |
Judging History
answer
#include <iostream>
#include <array>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long ll;
//#define int long long
const int inf = 0x3f3f3f3f;
void solve() {
int n, m, k;
cin >> n >> m >> k;
string s;
cin >> s;
s = " " + s;
vector<int> pre(n + 1);
for (int i = 1; i <= n; ++i) {
pre[i] = pre[i - 1] + (s[i] == '1');
}
auto check = [&](int x) -> bool {
vector<vector<array<int, 2>>> dp(n + 1, vector<array<int, 2>>(k + 1, {inf, inf}));
for (int i = 0; i <= 0; i++) {
dp[i][0][0] = 0;
}
for (int i = 1; i <= n; ++i) {
for (int j = 0; j <= k; ++j) {
if (s[i] == '1') {
dp[i][j][1] = dp[i - 1][j][1];
// dp[i][j][0] = dp[i - 1][j][0];
} else {
dp[i][j][0] = min(dp[i - 1][j][1], dp[i - 1][j][0]);
}
// dp[i][j][1] = dp[i - 1][j][1];
if (i >= x && j >= 1)
dp[i][j][1] = min({dp[i][j][1], dp[i - x][j - 1][0] + x - (pre[i] - pre[i - x]),
dp[i - x][j][1] + x - (pre[i] - pre[i - x])});
}
}
cout << "mid: " << x << endl;
for (int i = 1; i <= n; ++i) {
for (int j = 0; j <= k; ++j) {
cout << "i, j: " << i << ',' << j << ": " << dp[i][j][0] << ' ' << dp[i][j][1] << endl;
}
}
cout << endl;
return min(dp[n][k][0], dp[n][k][1]) <= m;
};
int l = 0, r = n + 1;
while (l + 1 < r) {
int mid = l + (r - l) / 2;
if (check(mid))
l = mid;
else
r = mid;
}
cout << (l ? l : -1) << '\n';
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3592kb
input:
8 3 2 10110110
output:
mid: 4 i, j: 1,0: 1061109567 1061109567 i, j: 1,1: 1061109567 1061109567 i, j: 1,2: 1061109567 1061109567 i, j: 2,0: 1061109567 1061109567 i, j: 2,1: 1061109567 1061109567 i, j: 2,2: 1061109567 1061109567 i, j: 3,0: 1061109567 1061109567 i, j: 3,1: 1061109567 1061109567 i, j: 3,2: 1061109567 1061109...
result:
wrong output format Expected integer, but "mid:" found