QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#278886 | #7875. Queue Sorting | Murphy_ | WA | 1ms | 3380kb | C++14 | 1.1kb | 2023-12-07 22:11:22 | 2023-12-07 22:11:22 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define re register
#define il inline
#define N 200005
using namespace std;
char str[N];
int f[N][6][2],g[N],n,m,k;
bool check(int len) {
for(int i=0;i<=n;++i) for(int j=0;j<=k;++j) f[i][j][0]=f[i][j][1]=N;
for(int i=0,s=0;i<=n&&s<len;++i) {if(str[i+1]=='0') s=0;else s++;f[i][0][0]=0;}
for(int i=1,x=0;i<=n;++i) {
for(int j=1;j<=k;++j) {
if(str[i]=='0') f[i][j][0]=min(f[i][j][0],f[i-1][j][1]);
if(str[i]=='1') f[i][j][0]=f[i-1][j][0];
if(i>=len) f[i][j][1]=min(f[i-len][j-1][0],f[i-len][j][1])+g[i]-g[i-len];
}
}
// for(int i=0;i<=n;++i) {for(int j=0;j<=k;++j) cout<<f[i][j][0]<<' ';cout<<endl;}cout<<endl;
// for(int i=0;i<=n;++i) {for(int j=0;j<=k;++j) cout<<f[i][j][1]<<' ';cout<<endl;}cout<<endl;
if(f[n][k][0]<=m||f[n][k][1]<=m) return 1;
return 0;
}
int main()
{
cin>>n>>m>>k>>(str+1);
for(int i=1;i<=n;++i) g[i]=g[i-1]+((str[i]-'0')^1);
int l=0,r=n;
while(l<r) {
int mid=ceil((l+r)/2.0);
// cout<<l<<':'<<r<<':'<<mid<<endl;
if(check(mid)) l=mid;
else r=mid-1;
}
if(!l) cout<<"-1";
else cout<<l;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3380kb
input:
4 1 1 1 1
output:
4
result:
wrong answer 1st numbers differ - expected: '14', found: '4'