QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#282455#7880. Streak ManipulationhelcsnewsxdWA 172ms21728kbC++142.2kb2023-12-12 05:36:492023-12-12 05:36:51

Judging History

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

  • [2023-12-12 05:36:51]
  • 评测
  • 测评结果:WA
  • 用时:172ms
  • 内存:21728kb
  • [2023-12-12 05:36:49]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define fore(i, a, b) for(int i = a, bella = b; i < bella; i++)
#define mset(a, b) memset(a, b, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define SZ(a) int(a.size())
#define fst first
#define snd second
#define pb push_back
#define FIO ios::sync_with_stdio(0); cin.tie(0)

typedef long double ld;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;

const int MAXN = 2e5 + 7;
const int MAXK = 5;
const int INF = 1e6;

// Input global values
string s;
int n, m, k;
bool dbg = false;

// DP Aux functions
int izq[MAXN];
void izq_init() {
    int pos = 0;
    fore(i, 0, n) {
        izq[i] = pos;
        if(i+1 != n && (s[i] == '0' || s[i+1] == '0'))
            pos = i+1;
    }
    
    fore(i, 0, n)
        assert(s[izq[i]] == s[i] && (izq[i] == 0 || s[i] == '0' || s[izq[i] - 1] == '0'));
}

int cnt_arr[MAXN];
void cnt_init() {
    fore(i, 0, n) {
        cnt_arr[i] = (i ? cnt_arr[i-1] : 0) + (s[i] == '0');
    }
}
int cnt(int i, int j) {
    assert(i <= j);
    return cnt_arr[j] - (i ? cnt_arr[i-1] : 0);
}

// DP
int dp[MAXN][MAXK];
void dp_init() {
    mset(dp, -1);
}
int dp_do(int pos, int act_k, const int &act_val) {
    if(act_k == 0)
        return 0;

    if(pos < 0)
        return INF;

    int &res = dp[pos][act_k];
    if(res != -1)
        return res;

    res = dp_do((s[pos] == '1' ? izq[pos] - 2 : pos - 1), act_k, act_val);
    if(pos - act_val + 1 >= 0) {
        assert(act_val >= cnt(izq[pos - act_val + 1], pos));

        res = min(
            res,
            cnt(izq[pos - act_val + 1], pos) +
                dp_do(izq[pos - act_val + 1] - 2, act_k - 1, act_val)
        );
    }

    return res;
}

bool check(int bm) {
    dp_init();

    int dp_val = dp_do(n-1, k, bm);

    return dp_val <= m;
}

int main() {
    FIO;

    cin >> n >> m >> k;
    cin >> s;

    izq_init();
    cnt_init();

    int bs = 1, be = n + 1;
    while(bs + 1 < be) {
        int bm = (bs + be)/2;
        
        if(check(bm))
            bs = bm;
        else be = bm;
    }
    if(check(be))
        bs = be;

    cout << (check(bs) ? bs : -1) << '\n';

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 7536kb

input:

8 3 2
10110110

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 2ms
memory: 8984kb

input:

12 3 3
100100010011

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 0
Accepted
time: 2ms
memory: 8396kb

input:

4 4 4
0000

output:

-1

result:

ok 1 number(s): "-1"

Test #4:

score: 0
Accepted
time: 3ms
memory: 8124kb

input:

1000 200 5
0001001000101001110010011001101010110101101100010100111110111111010010001100100111100101011100011101011001110010111100100100011001010011000100011111010110100001101110101001110000001000111010000111110100111101100110011010011111000111101001010011000111010111010100101111100000100001011001010...

output:

99

result:

ok 1 number(s): "99"

Test #5:

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

input:

1000 200 5
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

40

result:

ok 1 number(s): "40"

Test #6:

score: 0
Accepted
time: 2ms
memory: 8060kb

input:

1000 200 5
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

-1

result:

ok 1 number(s): "-1"

Test #7:

score: 0
Accepted
time: 108ms
memory: 21672kb

input:

200000 5 3
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

2

result:

ok 1 number(s): "2"

Test #8:

score: 0
Accepted
time: 81ms
memory: 18524kb

input:

200000 5 2
0001010000000000000000010011000001000000000000000001100000000001000000000000010011000010000000000110000010000010000100000000001001010000011000100000000001001000000000011110000100000011000000100110100110001011000000000000000000000000110001000000100000011100010011010001010010010100000000000...

output:

13

result:

ok 1 number(s): "13"

Test #9:

score: 0
Accepted
time: 172ms
memory: 15508kb

input:

200000 5 5
0001100001100000001011100010111101100100110001000011001011111101110100000000000111101001110100010101010100110100100011001100000010110111110010111011110100100101011001100101001010110100011101011001000101011110110010001011111101011101011010101101010001111110101001001110000000000010101001001...

output:

17

result:

ok 1 number(s): "17"

Test #10:

score: 0
Accepted
time: 90ms
memory: 12368kb

input:

200000 5 5
1011101011100110010111011011101110111111101111110111101111011110110111111101111011110101101110001100111110010101111011111101111111111111110110111111111011111111111111111111111111011100101111001110011100111100001111111111110101111011110010111001101111111111110110010101100111111111111111011...

output:

45

result:

ok 1 number(s): "45"

Test #11:

score: 0
Accepted
time: 5ms
memory: 9224kb

input:

200000 5 4
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

24879

result:

ok 1 number(s): "24879"

Test #12:

score: 0
Accepted
time: 163ms
memory: 15424kb

input:

200000 5 5
1010101010010101001010100101011010110010100101000010100101010101001010110101010101010101101010110101010101010101011001010101010101010101011001010101010100010101010010101000101001010101010110010101010110101101010111101010110101010101010010101010110111010010110111011010101010101110111001101...

output:

9

result:

ok 1 number(s): "9"

Test #13:

score: 0
Accepted
time: 35ms
memory: 15500kb

input:

200000 5 1
1001001011010101010101010101110101010100101001001010101101110101011010110101010110101010101011010101010101010010101010101000100110111110101101010101101011010101010101011010101010101010101010010101010101010110101001010101010101010110101010101010101011011010001010101011010101010101010101001...

output:

20

result:

ok 1 number(s): "20"

Test #14:

score: 0
Accepted
time: 122ms
memory: 15484kb

input:

200000 5 5
0001000000001111111100001000000000111100000111111100000000000011111000011110000000111001111100110000000000000000110000000000000000000011111111100000000111001111111111100000000011100000000010000111100111110000000111111110001111110111001100111111111001011111110111000111111111111111111111111...

output:

50

result:

ok 1 number(s): "50"

Test #15:

score: 0
Accepted
time: 71ms
memory: 12320kb

input:

200000 5 4
0111111111111111111101100000111111100101011111110000000111111110010011111111111101111111110000001001111111111111111110001111111111111111111111111111111111111111111101110110000000000111111111111001101111111111010000111111110000011000111100001111111110101111111101100000011101000111111111111...

output:

90

result:

ok 1 number(s): "90"

Test #16:

score: 0
Accepted
time: 133ms
memory: 18608kb

input:

200000 5 4
0000100000110000000111100000000000111111100011111110001001110000000000001000000001100000011110000000010000000000011110000111111111101110000000100000000111100000011000011111001001000000000011000100000000000000001110000001000010000000000011111000000000000000000100000000011000000000000000000...

output:

22

result:

ok 1 number(s): "22"

Test #17:

score: 0
Accepted
time: 110ms
memory: 21728kb

input:

200000 170 3
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

57

result:

ok 1 number(s): "57"

Test #18:

score: 0
Accepted
time: 78ms
memory: 18604kb

input:

200000 170 2
00000000000000011000001010110010100000001010100001010010100011010110101100010100100010000001010000010000001000001010111100000101000110010000000010100000000100100010000000000110001000000001000101000010100000000000010100101100100011000100100000000010000101001010000000010000110000000000000...

output:

143

result:

ok 1 number(s): "143"

Test #19:

score: 0
Accepted
time: 165ms
memory: 15424kb

input:

200000 170 5
00000000110010110001010110100010110110100111110011111010101001111011101011111011101010100000001100110100000011000110001100000111011111001011001101011111111011101010100111001100011010100100001100010000001010010101011100001010111100011100101110111001110101011011100011100010010011001000100...

output:

107

result:

ok 1 number(s): "107"

Test #20:

score: 0
Accepted
time: 86ms
memory: 12380kb

input:

200000 170 5
10110010111110111011101101110111110111111011111110011111010111111111010100111001010111111111111001111011011011111111101011111011111111111010111111100111001001111100010111111001111011111011101100101110010101111101101011111101110011111110010001111101101101011110110111011111101010010111111...

output:

225

result:

ok 1 number(s): "225"

Test #21:

score: -100
Wrong Answer
time: 5ms
memory: 9176kb

input:

200000 170 4
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

44640

result:

wrong answer 1st numbers differ - expected: '44639', found: '44640'