QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#339585 | #7880. Streak Manipulation | 275307894a# | WA | 1ms | 6164kb | C++14 | 1.7kb | 2024-02-27 16:05:34 | 2024-02-27 16:05:34 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=2e5+5,M=N*10+5,K=1000+5,mod=998244353,Mod=+-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(263082);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
#ifdef LOCAL
#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
#else
#define gdb(...) void()
#endif
}using namespace Debug;
int n,m,k,sum[N];char s[N];
int f[N],g[N];
int check(int mid){gdb(mid);
for(int i=0;i<=n+1;i++) if(s[i]=='0') f[i]=0;else f[i]=INF;
for(int i=1;i<=k;i++){
Mc(g,f);Me(f,0x3f);
int mi=INF;
for(int j=1;j<=n+1;j++)if(s[j]=='0'){
f[j]=f[j-1];
if(j-mid-1>=0) mi=min(mi,g[j-mid-1]-sum[j-mid-1]);
f[j]=min(f[j],mi+sum[j-1]);
// for(int h=0;h<=j-mid-1;h++) f[j]=min(f[j],g[h]+sum[j-1]-sum[h]);
}
}
return f[n+1]<=m;
}
void Solve(){
int i,j;scanf("%d%d%d",&n,&m,&k);
scanf("%s",s+1);s[0]='0';s[n+1]='0';
for(i=1;i<=n;i++) sum[i]=sum[i-1]+(s[i]=='0');
int l=0,r=n+1,mid;
while(l+1<r) mid=l+r>>1,(check(mid)?l:r)=mid;
printf("%d\n",l?l:-1);
}
int main(){
int t=1;
// scanf("%d",&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 6164kb
input:
8 3 2 10110110
output:
2
result:
wrong answer 1st numbers differ - expected: '3', found: '2'