QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#501353 | #7880. Streak Manipulation | Decade | WA | 1ms | 5680kb | C++17 | 2.5kb | 2024-08-02 17:06:05 | 2024-08-02 17:06:05 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
// #define int long long
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
mt19937 rng;
uniform_int_distribution <ull> dist(0,1ull<<63);
//#define mp make_pair
inline void print(__int128 x){//输出模板
if(x<0){
putchar('-');
x=-x;
}
if(x>9) print(x/10);
putchar(x%10+'0');
}
inline int read()
{
int X = 0;
bool flag = 1;
char ch = getchar();
while (ch < '0' || ch > '9')
{
if (ch == '-')
flag = 0;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
{
X = (X << 1) + (X << 3) + ch - '0';
ch = getchar();
}
if (flag)
return X;
return ~(X - 1);
}
const ll mod = 1e9 + 7,INF = 0x3f3f3f3f;
ll qpow(ll a, ll b)
{
ll res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1)
{
if (b & 1)
res = res * a % mod;
a = a * a % mod;
}
return res;
}
inline int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
inline int lcm(int a, int b) { return a / gcd(a, b) * b; }
const int N = 200010,M = 1000010;
string s;
int f[N][10][2],sum[N];
int n,m,k;
bool check(int x)
{
for(int i=0;i<=n;i++)for(int j=0;j<=k;j++) f[i][j][1] = f[i][j][0] = INF;
f[0][0][0] = 0;
for(int i=1;i<=n;i++)
{
if(s[i]=='1') f[i][0][1] = 0;
else f[i][0][0] = 0,f[i][0][1] = 1;
}
int tmp[10];
for(int i=0;i<=k;i++) tmp[i] = INF;
int res = INF;
for(int i=x;i<=n;i++)
{
for(int j=1;j<=k;j++)
{
tmp[j-1] = min(tmp[j-1],f[i-x][j-1][0]-sum[i-x]);
if(s[i]=='1') f[i][j][1] = min(f[i][j][1],sum[i]+tmp[j-1]);
else
{
f[i][j][1] = min(f[i][j][1],sum[i]+tmp[j-1]);
f[i][j][0] = min(f[i-1][j][0],f[i-1][j][1]);
}
}
res = min({res,f[i][k][0],f[i][k][1]});
}
return res<=m;
}
void solve()
{
cin>>n>>m>>k;
cin>>s;
s = ' '+s;
for(int i=1;i<=n;i++) sum[i] = sum[i-1]+(s[i]=='0');
int l = 0,r = n;
while(r>l)
{
int mid = l+r+1>>1;
if(check(mid)) l = mid;
else r = mid-1;
}
if(!l) cout<<-1<<'\n';
else cout<<l<<'\n';
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
//cin>>t;
while (t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5680kb
input:
8 3 2 10110110
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5656kb
input:
12 3 3 100100010011
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
4 4 4 0000
output:
-1
result:
ok 1 number(s): "-1"
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 3924kb
input:
1000 200 5 0001001000101001110010011001101010110101101100010100111110111111010010001100100111100101011100011101011001110010111100100100011001010011000100011111010110100001101110101001110000001000111010000111110100111101100110011010011111000111101001010011000111010111010100101111100000100001011001010...
output:
90
result:
wrong answer 1st numbers differ - expected: '99', found: '90'