cf Jumbled String(思维 )

http://codeforces.com/gym/101933/problem/J

Jumbled String

time limit per test

1.0 s

memory limit per test

256 MB

input

standard input

output

standard output

Recall that a subsequence of a string is any string obtained by removing some subset of characters from the string, for instance "string", "sing", "i" and "sg" are all subsequences of "string". If the same subsequence can be obtained in exactly tt different ways, by removing different subsets of characters, we say that the subsequence occurs tt times.

Jingfei wants to create a nonempty bit string that has the following properties:

  1. the subsequence 00 occurs aa times,
  2. the subsequence 01 occurs bb times,
  3. the subsequence 10 occurs cc times, and
  4. the subsequence 11 occurs dd times.

However, Jingfei does not know how to create such a string – or whether it is even possible. Could you help her?

Input

The input consists of a single line with four integers aa, bb, cc, and dd (0≤a,b,c,d≤1090≤a,b,c,d≤109).

Output

Output a bit string that satisfies the given requirements. If there are several solutions, output any one of them. If there are no solutions, output "impossible".

Examples

input

Copy

3 4 2 1

output

Copy

01001

input

Copy

5 0 0 5

output

Copy

impossible

#include<bits/stdc++.h>
using namespace std;
using lom=long long;
lom a,b,c,d;
lom e[50000],f[100000];
lom fuck(){
	lom sum=0;
	for(lom i=2;;i++){
		sum+=i-1;
		e[i]=sum;
		if(sum>1e9) return i;
	}
}
int main(){
	lom s=fuck(),x,y;
	bool c1=0,c2=0;
	cin>>a>>b>>c>>d;
	for(lom i=1;i<s;i++){
		if(a==e[i]){
			c1=true;
			x=i;
		}
		if(d==e[i]){
			c2=true;
			y=i;
		}
	}
	lom t=0,k=0;
	if(a==0&&b==0&&c==0&&d==0){
		cout<<0<<endl;
	}
	else if(c1==0){
		cout<<"impossible"<<endl;
	}
	else if(c2==0){
		printf("impossible\n");
	}
	else if(a==0&&d==0){
		if(b==1&&c==0){
			cout<<0<<1<<endl;
		}
		else if(c==1&&b==0){
			cout<<10<<endl;
		}
		else printf("impossible\n");
	}
	else if(b==0&&c==0){
		if(a==0){
			for(lom i=1;i<=y;i++) cout<<1;
			cout<<endl;
		}else if(d==0){
			for(lom i=1; i<=x; i++) cout<<0;
			cout<<endl;
		}
		else cout<<"impossible"<<endl;
	}
	else if(c1&&c2&&(b+c==x*y)){
		for(lom i=0;i<x+y;i++){
			if(i<x) f[i]=0;
			else f[i]=1;
		}
		for(int i=x;i<x+y;i++){
			if(t==c) break;
			if(t+x<=c){
				f[k]=1;
				f[i]=0;
				k++;
				t=t+x;
			}
			else{
				f[k+x-c+t]=1;
				f[i]=0;
				break;
			}
		}
		for(lom i=0;i<x+y;i++) cout<<f[i];
		cout<<endl;
	}
	else cout<<"impossible"<<endl;
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值