QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#278087 | #7880. Streak Manipulation | Vegetable_Dog# | WA | 5ms | 13188kb | C++23 | 914b | 2023-12-07 11:50:30 | 2023-12-07 11:50:32 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define MEM(a,x) memset(a,x,sizeof(a));
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define Rep(i,a,b) for(int i=a;i>=(b);i--)
typedef vector<int> vi;
const int N=2e5+5,inf=1e9;
int n,m,k;
string s;
int dp[6][N];
bool check(int x){
MEM(dp,0x3f);
dp[0][0]=0;
int p=0,cnt=0;
vi mn(6,inf);mn[0]=0;
rep(i,1,x+1)cnt+=s[i]=='0';
rep(i,x+1,n+2){
rep(j,1,k+1)dp[j][i]=min(dp[j][i],mn[j-1]+cnt+(s[i]=='1'));
cnt-=(s[p++]=='0'),cnt+=(s[i]=='0');
rep(j,0,k+1)mn[j]=min(dp[j][p],mn[j]);
}
return *min_element(dp[k]+1,dp[k]+n+2)<=m;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>n>>m>>k>>s;
s='0'+s+'0';
int l=0,r=n;
while(l<r){
int md=(l+r+1)/2;
if(check(md))l=md;
else r=md-1;
}
cout<<(!l?-1:l)<<endl;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 12928kb
input:
8 3 2 10110110
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 3ms
memory: 13004kb
input:
12 3 3 100100010011
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 3ms
memory: 13188kb
input:
4 4 4 0000
output:
-1
result:
ok 1 number(s): "-1"
Test #4:
score: -100
Wrong Answer
time: 5ms
memory: 12932kb
input:
1000 200 5 0001001000101001110010011001101010110101101100010100111110111111010010001100100111100101011100011101011001110010111100100100011001010011000100011111010110100001101110101001110000001000111010000111110100111101100110011010011111000111101001010011000111010111010100101111100000100001011001010...
output:
100
result:
wrong answer 1st numbers differ - expected: '99', found: '100'