QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#664064 | #7880. Streak Manipulation | B1ueqwq | WA | 1ms | 5724kb | C++14 | 1.0kb | 2024-10-21 19:06:33 | 2024-10-21 19:06:34 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int n,m,k;
string ch;
const int maxn=2e5+5;
int sum[maxn];
int nxt[maxn];
int f[maxn][10];
const int INF=maxn;
bool check(int len){
for(int i=1;i<=n;i++){
int l=i,r=l+len-1;
if(r>n)
f[i][1]=INF;
else
f[i][1]=sum[r]-sum[l-1];
}
for(int st=2;st<=k;st++){
int minn=INF;
for(int i=n;i>=1;i--){
int l=i,r=l+len-1;
int ll=nxt[r+1]+1;
if(r+1<=n&&ll<=n)
minn=min(minn,f[ll][st-1]);
if(r>n)
f[i][st]=INF;
else{
f[i][st]=minn+sum[r]-sum[l-1];
}
}
}
return f[1][k]<=m;
}
int main(){
cin>>n>>m>>k;
cin>>ch;
for(int i=1;i<=n;i++){
char tmp=ch[i-1];
if(tmp=='0')
sum[i]=1;
else
sum[i]=0;
sum[i]+=sum[i-1];
}
nxt[n+1]=n+1;
for(int i=n;i>=1;i--){
char tmp=ch[i-1];
if(tmp=='0')
nxt[i]=i;
else
nxt[i]=nxt[i+1];
}
int l=1,r=n;
int ans=-1;
while(l<=r){
int mid=(r-l>>1)+l;
if(check(mid)){
l=mid+1;
ans=mid;
}
else
r=mid-1;
}
cout<<ans<<endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3660kb
input:
8 3 2 10110110
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5588kb
input:
12 3 3 100100010011
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5724kb
input:
4 4 4 0000
output:
-1
result:
ok 1 number(s): "-1"
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3712kb
input:
1000 200 5 0001001000101001110010011001101010110101101100010100111110111111010010001100100111100101011100011101011001110010111100100100011001010011000100011111010110100001101110101001110000001000111010000111110100111101100110011010011111000111101001010011000111010111010100101111100000100001011001010...
output:
96
result:
wrong answer 1st numbers differ - expected: '99', found: '96'