QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#391904#7880. Streak ManipulationFiatiustitiaWA 1ms3616kbC++201.5kb2024-04-16 21:40:082024-04-16 21:40:09

Judging History

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

  • [2024-04-16 21:40:09]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3616kb
  • [2024-04-16 21:40:08]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
int f[N][6][2];
void solve()
{
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> cnts0(n + 1);
    string s;
    cin >> s;
    s = '!' + s;
    for (int i = 1; i <= n; i++)
        cnts0[i] = cnts0[i - 1] + (s[i] == '0');
    f[0][1][0] = f[0][2][0] = f[0][3][0] = f[0][4][0] = f[0][5][0] = INT32_MAX / 2;
    auto check = [&](int x)
    {
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= k; j++)
            {
                f[i][j][0] = f[i][j][1] = INT32_MAX / 2;
                if (i != 1 && s[i] == '0')
                {
                    f[i][j][0] = min(f[i - 1][j][0], f[i - 1][j][1]);
                    f[i][j][1] = min(f[i - 1][j][1] + 1,f[i - 1][j][0] + 1);
                }
                else
                    f[i][j][1] = min(f[i - 1][j][1],f[i - 1][j][0]);
                if (i - x >= 0)
                    f[i][j][1] = f[i - x][j - 1][0] + cnts0[i] - cnts0[i - x];
            }
        }
        return min(f[n][k][0], f[n][k][1]) <= m;
    };
    int l = 1, r = n, res = -1;
    while (l <= r)
    {
        int mid = (l + r) >> 1;
        if (check(mid))
        {
            res = mid;
            l = mid + 1;
        }
        else
            r = mid - 1;
    }
    cout << res << '\n';
}

int main()
{
#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3616kb

input:

8 3 2
10110110

output:

3

result:

ok 1 number(s): "3"

Test #2:

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

input:

12 3 3
100100010011

output:

6

result:

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