0pts,能过样例
查看原帖
0pts,能过样例
169594
Heart_Of_Iron_4楼主2023/9/10 19:32
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define FOR(qw,we,er) for(int qw=we;qw<=er;++qw)
//#define sum(qwer,wert) (a[wert]-a[qwer-1])
#define ok() cout<<s<<endl;goto ccf;
int a[1145],n,m,t1,t2,t3,t4,cnt,sum;
string s;
signed main()
{
	scanf("%lld",&n);
	while(cin>>s)
	{
		m=s.size();
		if(s.size()>n+1||s.size()<n-1){cout<<-1<<endl;goto ccf;}
		t2=t3=t4=0;
		cnt=sum=0;
		memset(a,0,sizeof(a));
		FOR(j,0,m-1)
		{
			if(s[j]=='1')
			{
			//	cout<<j<<endl;
				sum+=j+1;cnt++;a[j]=1;
			}
			else a[j]=0;
		}
		//cout<<sum<<endl;
		FOR(i,1,m-1)a[i]+=a[i-1];
		t1=cnt%(n+1);
		if(m==n)
		{
			if(t1==0){ok();}
			if(t1!=0)
			{
				if(s[t1-1]=='1')s[t1-1]='0';
				ok();
			}
		}
		if(m==n-1)
		{
			FOR(i,0,m-1)//insert after
			{//cout<<s[i]<<" "<<sum<<" "<<cnt<<" "<<a[i]<<endl;
				if((sum+(cnt-a[i]))%(n+1)==0)
				{s.insert(i+1,"0");ok();}
				if((sum+(cnt-a[i])+i+1)%(n+1)==0)
				{s.insert(i+1,"1");ok();}
			}
		}
		if(m==n+1)
		{
			FOR(i,0,m-1)//delete
			{
				if(s[i]=='0'&&(sum-(cnt-a[i]))%(n+1)==0)
				{s.erase(i,1);ok();}
				if(s[i]=='1'&&(sum-(cnt-a[i])-i-1)%(n+1)==0)
				{s.erase(i,1);ok();}
			}
		}
		cout<<-1<<endl;
		ccf:114514==1919810;
	}
	return 0;
}
2023/9/10 19:32
加载中...