QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#664806 | #7880. Streak Manipulation | 111111qqqqqq | WA | 1ms | 5760kb | C++23 | 1.7kb | 2024-10-21 22:27:29 | 2024-10-21 22:27:30 |
Judging History
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<=k;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<=k;j++) {
f[i][j]=f[i-1][j];
if(c[i] && !is[i]) continue;
int x=i-mid+1;
if(c[x]) x=fly[x];
else if(c[x-1]) x=fly[x-1];
if(x==1) {
if(j==1) {
f[i][j]=min(f[i][j],max(0,mid-(cnt[i])));
}
}
else {
f[i][j]=min(f[i][j],f[x-2][j-1]+max(0,mid-(cnt[i]-cnt[x-1])));
}
}
}
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;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 5644kb
input:
8 3 2 10110110
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 5760kb
input:
12 3 3 100100010011
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5696kb
input:
4 4 4 0000
output:
-1
result:
ok 1 number(s): "-1"
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 5720kb
input:
1000 200 5 0001001000101001110010011001101010110101101100010100111110111111010010001100100111100101011100011101011001110010111100100100011001010011000100011111010110100001101110101001110000001000111010000111110100111101100110011010011111000111101001010011000111010111010100101111100000100001011001010...
output:
101
result:
wrong answer 1st numbers differ - expected: '99', found: '101'