QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#664758#7880. Streak Manipulation111111qqqqqqWA 1ms7776kbC++231.7kb2024-10-21 22:11:112024-10-21 22:11:16

Judging History

你现在查看的是最新测评结果

  • [2024-10-21 22:11:16]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7776kb
  • [2024-10-21 22:11:11]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define modd(a,b) a=a%b
#define pb push_back
#define db double
#define lowbit(x) x&(-x)
#define cerr(x) cout<<#x<<"="<<x<<endl
const ll mod=1e9+7;
ll ksm(ll a,ll b) {ll ans=1,bs=a;while(b) {if(b&1) ans=ans*bs%mod;bs=bs*bs%mod;b>>=1;}return ans;}
#define fi first
#define se second
#define N 200010
int n,m,k;
int c[N],f[N][6],cnt[N];
bool is[N];
int fly[N];
bool ck(int mid) {
    for(int i=0;i<=n;i++) for(int j=0;j<=5;j++) f[i][j]=0x3f3f3f3f;
    for(int i=0;i<=n;i++) f[i][0]=0;
    for(int i=mid;i<=n;i++) {
        for(int j=1;j<=min(5,k);j++) {
            f[i][j]=f[i-1][j];
            if(c[i] && !is[i]) continue;
            if(i-mid+1==1 || !c[i-mid]) f[i][j]=min(f[i][j],f[max(0,i-mid-1)][j-1]+mid-(cnt[i]-cnt[max(0,i-mid-1)]));
            if(c[i-mid]) {
                f[i][j]=min(f[i][j],f[max(0,fly[i-mid]-2)][j-1]+max(0,mid-(cnt[i]-cnt[max(0,fly[i-mid]-2)])));
            }
        }
    }
    return f[n][k]<=m;
}
void solve() {
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++) {char x;cin>>x;c[i]=x-'0';cnt[i]=cnt[i-1]+(c[i]==1);}
    for(int i=1;i<=n;i++) {
        if(c[i] && (i==n || c[i+1]==0)) is[i]=1;
    }
    for(int i=1;i<=n;i++) {
        if(!c[i]) continue;
        fly[i]=i;
        if(i>1 && c[i-1]) fly[i]=fly[i-1];
    }
    int l=1,r=n,mid,ans=-1;
    while(l<=r ) {
        mid=l+r>>1;
        if(ck(mid)) ans=mid,l=mid+1;
        else r=mid-1;
    }
    cout<<ans<<endl;
}
int main() {
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    // int T;
    // 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: 7776kb

input:

8 3 2
10110110

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

12 3 3
100100010011

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 0
Accepted
time: 1ms
memory: 5800kb

input:

4 4 4
0000

output:

-1

result:

ok 1 number(s): "-1"

Test #4:

score: -100
Wrong Answer
time: 1ms
memory: 3748kb

input:

1000 200 5
0001001000101001110010011001101010110101101100010100111110111111010010001100100111100101011100011101011001110010111100100100011001010011000100011111010110100001101110101001110000001000111010000111110100111101100110011010011111000111101001010011000111010111010100101111100000100001011001010...

output:

101

result:

wrong answer 1st numbers differ - expected: '99', found: '101'