For each string s consisting of characters '0' and '1' one can define four integers a00, a01, a10 and a11, where axy is the number of subsequences of length 2 of the string s equal to the sequence {x, y}.

In these problem you are given four integers a00, a01, a10, a11 and have to find any non-empty string s that matches them, or determine that there is no such string. One can prove that if at least one answer exists, there exists an answer of length no more than 1 000 000.

Input

The only line of the input contains four non-negative integers a00, a01, a10 and a11. Each of them doesn't exceed 109.

Output

If there exists a non-empty string that matches four integers from the input, print it in the only line of the output. Otherwise, print "Impossible". The length of your answer must not exceed 1 000 000.

Examples
Input

Copy
1 2 3 4
Output

Copy
Impossible
Input

Copy
1 2 2 1
Output

Copy
0110

首先从a00和a11可以求出0和1的数量;

假设目前为0000...001111..;

显然a01=num0*num1,a10=0;

那么我们移动一个1去左边,a10++,a01--;但总数还是不变;

那么合理的解必须是a10+a01=num0*num1;

值得注意的是:当00或11=0时,0或1可能有1个也可能没有;

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize(2)
using namespace std;
#define maxn 1000005
#define inf 0x3f3f3f3f
//#define INF 1e18
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9 + 7;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-3
typedef pair<int, int> pii;
#define pi acos(-1.0)
const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii;
inline ll rd() {
ll x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
} ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
ll sqr(ll x) { return x * x; } /*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1; y = 0; return a;
}
ans = exgcd(b, a%b, x, y);
ll t = x; x = y; y = t - a / b * y;
return ans;
}
*/
int a00, a01, a10, a11; int main()
{
//ios::sync_with_stdio(0);
rdint(a00); rdint(a01); rdint(a10); rdint(a11);
int k = 1, r = 1;
while (k*(k - 1) / 2 < a00)k++;
while (r*(r - 1) / 2 < a11)r++;
// cout << k << ' ' << r << endl;
int fg = 1;
if (k*(k - 1) / 2 != a00 || r * (r - 1) / 2 != a11) {
cout << "Impossible" << endl; return 0;
} else if (a00 == 0 && a11 == 0) {
if (a01 == 0 && a10 == 0)cout << 0 << endl;
else if (a01 == 0 && a10 == 1)cout << "10" << endl;
else if (a01 == 1 && a10 == 0)cout << "01" << endl;
else cout << "Impossible" << endl;
return 0;
}
else if (a00 == 0) {
if (a01 == 0 && a10 == 0) {
while (r--)cout << '1'; }
else if (a01 + a10 == r) {
while (a10--)cout << '1';
cout << 0;
while (a01--)cout << '1';
}
else fg = 0;
}
else if (a11 == 0) {
if (a10 == 0 && a01 == 0) {
while (k--)cout << '0';
}
else if (a10 + a01 == k) {
while (a01--)cout << 0;
cout << 1;
while (a10--)cout << 0;
}
else fg = 0;
} else {
if (a01 + a10 == k * r) {
while (a01) {
while (r > a01) {
cout << 1;
r--;
}
cout << 0;
k--; a01 -= r;
}
while (r--)cout << 1;
while (k--)cout << 0;
}
else fg = 0;
}
if (fg == 0)cout << "Impossible" << endl;
return 0;
}

CF708B Recover the String 构造的更多相关文章

  1. codeforces 709D D. Recover the String(构造)

    题目链接: D. Recover the String time limit per test 1 second memory limit per test 256 megabytes input s ...

  2. AIM Tech Round 3 (Div. 1) B. Recover the String 构造

    B. Recover the String 题目连接: http://www.codeforces.com/contest/708/problem/B Description For each str ...

  3. cf708B. Recover the String---(构造法)

    题目链接:http://codeforces.com/problemset/problem/708/B 意思是给出四个参数 a00表01串中00对的数量 a01表01串中01对的数量 a10表01串中 ...

  4. 【CodeForces】708 B. Recover the String 数学构造

    [题目]B. Recover the String [题意]找到一个串s,满足其中子序列{0,0}{0,1}{1,0}{1,1}的数量分别满足给定的数a1~a4,或判断不存在.数字<=10^9, ...

  5. Recover the String

    Recover the String 题目链接:http://codeforces.com/contest/709/problem/D 构造 这题乍一看很难构造,但是如果知道了整个字符串中'0'和'1 ...

  6. AIM Tech Round 3 (Div. 2)D. Recover the String(贪心+字符串)

    D. Recover the String time limit per test 1 second memory limit per test 256 megabytes input standar ...

  7. B. Recover the String

    B. Recover the String time limit per test 1 second memory limit per test 256 megabytes input standar ...

  8. java的String构造对象的几种方法以及内存运行过程

    String类创建对象的方法可以分为以下三种 1.String a = "123"; 2.String b = new String("123"); 3.Str ...

  9. C++ string 构造的陷阱

    先看代码 #include<iostream> #include<string> using namespace std; int main(int argc, char ** ...

随机推荐

  1. 2015.12.24(圣诞节) 解决Oralce数据库将具有相同属性的多行合并为一行的简单方法多年想要wmsys.wm_concat

    用到Oralce10g以后增加的函数wmsys.wm_concat 例如这张表的有两个字段,要按airport_id合并成两行可用sql语句 select airport_id,   wmsys.wm ...

  2. java 多线程系列基础篇(十)之线程优先级和守护线程

    1. 线程优先级的介绍 java 中的线程优先级的范围是1-10,默认的优先级是5.“高优先级线程”会优先于“低优先级线程”执行. java 中有两种线程:用户线程和守护线程.可以通过isDaemon ...

  3. 类型:JQuery;问题:ajax调用ashx文件;结果:ashx文件怎么获取$.ajax()方法发送的json数据

    ashx文件怎么获取$.ajax()方法发送的json数据 作者:careful 和ajax相关     新浪微博QQ空间QQ微博百度搜藏腾讯朋友QQ收藏百度空间人人网开心网0 $.ajax({  t ...

  4. DAY9-python并发之多进程

    一 multiprocessing模块介绍 python中的多线程无法利用多核优势,如果想要充分地使用多核CPU的资源(os.cpu_count()查看),在python中大部分情况需要使用多进程.P ...

  5. GUI编程02

    1 编写一个导航栏 from tkinter import * root = Tk() root.title("测试") root.geometry("400x400+4 ...

  6. loj2436 糖果

    传送门 分析 我们知道对于一个不等式a<b可以将其转化为a+1<=b的形式,在知道这个之后我们便可以将5个关系进行差分约束了,具体的建边方式见代码.注意由于每个人都必须有糖,我们把每个人的 ...

  7. 100078D Domestic Networks

    传送门 题目大意 有两种染料,给定它们的单价和数量,每染色一米需耗费一个单位的染料,一条边只能用一种燃料,给你一张图,要求你将其中的一些边染色使得在满足图联通的情况下花费最小并输出方案. 分析 首先, ...

  8. linux设备驱动第四篇:驱动调试方法

    http://www.cnblogs.com/donghuizaixian/archive/2015/04/02/4387083.html 上一篇我们大概聊了如何写一个简单的字符设备驱动,我们不是神, ...

  9. str() 和repr()的区别

    >>> a='bbc' >>> a'bbc'>>> print abbc str()一般是将数值转成字符串:repr()是将一个对象转成字符串显示 ...

  10. 【转】链接任意目录下库文件(解决错误“/usr/bin/ld: cannot find -lxxx”

    netbeans构建项目也出现了同样的问题.猜测是netbeans内部就用的是-l 这种编译方式,所以需要把***.a手动改为lib***.a 原文地址:链接任意目录下库文件(解决错误“/usr/bi ...