QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#661910 | #7880. Streak Manipulation | sdnuwy | WA | 1ms | 3808kb | C++17 | 1.7kb | 2024-10-20 18:58:35 | 2024-10-20 18:58:35 |
Judging History
answer
//Think twice,code once.
#include<bits/stdc++.h>
#define endl '\n'
#define INF 0x3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define ff first
#define ss second
#define int long long
#define pii pair<int,int>
#define mem(i,n) memset(i,n,sizeof i)
#define dg(a) std::cout << #a << " = " << a << endl
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
void solve()
{
int n,m,k;
cin >> n >> m >> k;
vector<char>c(n+2);
vector<int>sum(n+2);
vector<int>b(n+1);
for(int i=1;i<=n;i++)
{
cin >> c[i];
if(c[i]=='1')
{
sum[i]++;
}
sum[i]+=sum[i-1];
}
sum[n+1]=sum[n];
int cnt=0;
for(int i=1;i<=n;i++)
{
b[i]=cnt;
if(c[i]=='0') cnt=i;
}
auto check=[&](int x){
if(x==0) return true;
vector<vector<int>>f(n+2,vector<int>(6,inf));
for(int i=0;i<=n+1;i++)
{
f[i][0]=0;
}
for(int i=x;i<=n+1;i++)
{
if(c[i]=='1') continue;
for(int j=1;j<=k;j++)
{
int pre=b[i-x];
f[i][j]=min(f[i-1][j],f[pre][j-1]+(i-pre-1)-(sum[i]-sum[pre]));
}
}
return f[n+1][k]<=m;
};
int l=0,r=n;
while(l<r)
{
int mid=l+r+1>>1;
if(check(mid)) l=mid;
else r=mid-1;
}
if(l==0)
{
cout << -1 << endl;
}
else
{
cout << l << endl;
}
}
int32_t main()
{
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
int t = 1;
// std::cin >> t;
while(t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3636kb
input:
8 3 2 10110110
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3808kb
input:
12 3 3 100100010011
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
4 4 4 0000
output:
-1
result:
ok 1 number(s): "-1"
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 3696kb
input:
1000 200 5 0001001000101001110010011001101010110101101100010100111110111111010010001100100111100101011100011101011001110010111100100100011001010011000100011111010110100001101110101001110000001000111010000111110100111101100110011010011111000111101001010011000111010111010100101111100000100001011001010...
output:
85
result:
wrong answer 1st numbers differ - expected: '99', found: '85'