QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#339583 | #7880. Streak Manipulation | 275307894a# | WA | 3ms | 5524kb | C++14 | 1.7kb | 2024-02-27 16:04:54 | 2024-02-27 16:04:54 |
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);
Me(f,0);
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: 100
Accepted
time: 2ms
memory: 5476kb
input:
8 3 2 10110110
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 2ms
memory: 5480kb
input:
12 3 3 100100010011
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 0ms
memory: 5516kb
input:
4 4 4 0000
output:
-1
result:
ok 1 number(s): "-1"
Test #4:
score: -100
Wrong Answer
time: 3ms
memory: 5524kb
input:
1000 200 5 0001001000101001110010011001101010110101101100010100111110111111010010001100100111100101011100011101011001110010111100100100011001010011000100011111010110100001101110101001110000001000111010000111110100111101100110011010011111000111101001010011000111010111010100101111100000100001011001010...
output:
84
result:
wrong answer 1st numbers differ - expected: '99', found: '84'