UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#206882#3718. 古神审判Matthew1001ms1252kbC++417b2024-07-25 19:59:002024-07-25 20:26:09

answer

#include <bits/stdc++.h>
using namespace std;
string str;
int n,m;
int dp[114];
int main(){
    cin >> n >> m >> str;
    str = ' ' + str;
    memset(dp,0x3f3f3f,sizeof dp);
    dp[1]=0;
    for(int i = 2;i<=n;i++){
        for(int j = i-1;j >= max(i-m,1);j--){
            if(str[i]!='0')dp[i]=min(dp[i],dp[j]+1);
        }
    }
    cout << (dp[n] >= 114514 ? -1 : dp[n]) << endl;
    return 0;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1244kb

input:

93 12
111011110011011101101001001010000110101011011010100010100001010100100000000110111000100001011

output:

9

result:

ok 1 number(s): "9"

Test #2:

score: 10
Accepted
time: 1ms
memory: 1244kb

input:

93 25
110010011101100001011111000110000011110110100011011100001101111110000100000001011100101111001

output:

4

result:

ok 1 number(s): "4"

Test #3:

score: 10
Accepted
time: 0ms
memory: 1244kb

input:

26 3
11010011111101000000001111

output:

-1

result:

ok 1 number(s): "-1"

Test #4:

score: 10
Accepted
time: 0ms
memory: 1244kb

input:

13 4
1100011011001

output:

4

result:

ok 1 number(s): "4"

Test #5:

score: 10
Accepted
time: 0ms
memory: 1248kb

input:

11 4
11100010111

output:

3

result:

ok 1 number(s): "3"

Test #6:

score: 10
Accepted
time: 0ms
memory: 1244kb

input:

18 4
111011101000110101

output:

5

result:

ok 1 number(s): "5"

Test #7:

score: 10
Accepted
time: 0ms
memory: 1244kb

input:

50 18
11100110101000001111111001110101111110010000001101

output:

3

result:

ok 1 number(s): "3"

Test #8:

score: 10
Accepted
time: 0ms
memory: 1252kb

input:

98 12
1100111000010000010001110010101100100011111110101010001100111011011111000000101000101110111011...

output:

9

result:

ok 1 number(s): "9"

Test #9:

score: 10
Accepted
time: 0ms
memory: 1244kb

input:

87 32
110000101001110001010110110110011110110010000100101011101010000010111011001110110110111

output:

3

result:

ok 1 number(s): "3"

Test #10:

score: 10
Accepted
time: 0ms
memory: 1244kb

input:

47 20
11011010100101010010011000000001100011111110101

output:

3

result:

ok 1 number(s): "3"