Untitled
#include <bits/stdc++.h> using namespace std; /***********************************************/ /* Dear online judge: * I've read the problem, and tried to solve it. * Even if you don't accept my solution, you should respect my effort. * I hope my code compiles and gets accepted. * ___ __ _______ _______ * |\ \|\ \ |\ ___ \ |\ ___ \ * \ \ \/ /|_\ \ __/| \ \ __/| * \ \ ___ \\ \ \_|/__\ \ \_|/__ * \ \ \\ \ \\ \ \_|\ \\ \ \_|\ \ * \ \__\\ \__\\ \_______\\ \_______\ * \|__| \|__| \|_______| \|_______| */ const long long mod = 1000000007; #define ll long long #undef ll const int mxN = 2510; int get(int x){ for(int i = 0;i*(i-1)/2 <= x;i++) if(i * (i - 1) / 2 == x)return i; return -1; } int main(int argc, char** argv) { #ifdef ONLINE_JUDGE ios_base::sync_with_stdio(0); cin.tie(0); #endif int a[4] = {}; for(int i = 0; i < 4; i++)cin >> a[i]; if(*max_element(a,a+4) == 0){ cout << 1 << '\n'; return 0; } int zeros = get(a[0]); int ones = get(a[3]); if(a[1]||a[2]){ zeros = max(zeros,1); ones = max(ones,1); } if(zeros * (zeros - 1) / 2 != a[0] || ones * (ones - 1) / 2 != a[3]){ cout << "impossible\n"; return 0; } string ans = ""; while(zeros || ones){ if(zeros > 0 && a[1] >= ones) a[1] -= ones, zeros--, ans.push_back('0'); else if(ones > 0 && a[2] >= zeros) a[2] -= zeros, ones--, ans.push_back('1'); else{ cout << "impossible\n"; return 0; } } if(a[1] || a[2]){ cout << "impossible\n"; return 0; } cout << ans << '\n'; return 0; }
Leave a Comment