QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#307992 | #7880. Streak Manipulation | confesser | WA | 2ms | 10968kb | C++17 | 1.0kb | 2024-01-19 12:39:26 | 2024-01-19 12:39:26 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using pi=pair<int,int>;
#define F(i,a,b) for(int i=(a);i<=(b);i++)
#define G(i,a,b) for(int i=(a);i>=(b);i--)
#define ms(a,b) memset(a,b,sizeof(a))
#define si(a) ((int)(a).size())
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define pb push_back
const int N=2e5+3;
int a[N],dp[N][8],f[N],g[N];
int main(){
cin.tie(0)->ios::sync_with_stdio(0);
int n,m,k;
cin>>n>>m>>k;
F(i,1,n){
char c;
cin>>c;
a[i]=c-'0';
}
F(i,1,n){
if(!a[i]) f[i]=i;
else f[i]=f[i-1];
g[i]=g[i-1]+(!a[i]);
}
int l=1,r=n,ans=-1;
while(l<=r){
int mid=(l+r)>>1;
auto chk=[&](){
ms(dp,63);
dp[0][0]=0;
F(i,1,n){
dp[i][0]=0;
if(i>=mid){
F(j,1,k){
dp[i][j]=min(dp[i][j],dp[max(f[i-mid]-1,0)][j-1]+g[i]-g[f[i-mid]]);
}
}
}
F(i,1,n) if(dp[i][k]<=m) return 1;
return 0;
};
if(chk()){
ans=mid;
l=mid+1;
}else r=mid-1;
}
cout<<ans;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 10096kb
input:
8 3 2 10110110
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 10076kb
input:
12 3 3 100100010011
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 2ms
memory: 10232kb
input:
4 4 4 0000
output:
-1
result:
ok 1 number(s): "-1"
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 10968kb
input:
1000 200 5 0001001000101001110010011001101010110101101100010100111110111111010010001100100111100101011100011101011001110010111100100100011001010011000100011111010110100001101110101001110000001000111010000111110100111101100110011010011111000111101001010011000111010111010100101111100000100001011001010...
output:
90
result:
wrong answer 1st numbers differ - expected: '99', found: '90'