#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int Maxn=3e6+5;
int l,L,n,a[Maxn],Last,Next[Maxn],x,ans;
string s;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
freopen("toy.in","r",stdin);
freopen("toy.out","w",stdout);
cin>>l>>L>>n;
cin>>s;
s='c'+s;
if(L==n){
for(int i=1; i<=n; i++){
if(s[i]=='1')x++;
}
if(x==l)cout<<0;
else cout<<l;
return 0;
}
Last=1;
for(int i=2; i<=n; i++){
if(s[i]=='1'){
Next[Last]=i;
Last=i;
}
}
a[l]=1;
for(int i=l+1; i<=n; i++){
a[i]=a[i-1];
if(s[i]=='1'){
a[i]=Next[a[i]];
}
}
x=L;
while(true){
ans+=l;
if(x==n)break;
Last=a[x];
x=min(a[x]+L-1,n);
if(Last==a[x]&&x!=n){
cout<<"IMPOSSIBLE";
exit(0);
}
}
cout<<ans+n-L;
return 0;
}
/*
longlong
?
*/模拟赛代码
这是 2026年10月10日 存档的第 3 版,不是当前版本。查看当前版本