跳到正文

个人记录

模拟赛代码

Zzx2013约 2 分钟
原文

这是 2026年10月10日 存档的第 3 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2026年10月5日
收录
2026年10月5日
更新
2026年11月17日
篇幅
约 2 分钟

版本

  1. v5当前
  2. v4
  3. v3
  4. v2
更早的 1 个版本
  1. v1
C++
#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

?
*/