【Codeforces 708B】Recover the String

题目传送门:http://codeforces.com/problemset/problem/708/B

《论何为血wa》

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#define LL long long
#define abs(x) ((x)>0?(x):-(x))
using namespace std;

const int MAXN = 1000000+9;

LL a00,a01,a10,a11,tag,n;
char pat[MAXN];

inline LL read(){
	char c=getchar(); LL ret=0,f=1;
	while (c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}
	while (c<='9'&&c>='0') ret=ret*10+c-'0',c=getchar();
	return ret*f;
}

inline int solve(LL w) {
	w *= 2; LL tmp = sqrt(w);
	if (tmp*(tmp+1) != w) {tag++;return 0;}
	else return tmp+1;
}

int main(){
	a00 = read(); a01 = read(); a10 = read(); a11 = read();
	if (!a00 && !a11 && !a01 && !a10) cout<<0<<endl, exit(0);
	else if (a11 && !a00 && !a10 && !a01) {
		if(solve(a11)) {
			a11 = solve(a11);
			for (LL i=1;i<=a11;i++) pat[i] = '1'; 
			cout<<pat+1;
		} else cout<<"Impossible";
	} else if (!a11 && a00 && !a10 && !a01) {
		if(solve(a00)){
			a00 = solve(a00);
			for (LL i=1;i<=a00;i++) pat[i] = '0'; 
			cout<<pat+1;
		} else cout<<"Impossible";
	} else {
		a00 = solve(a00); a11 = solve(a11);
		if (tag) cout<<"Impossible";
		else if (a00*a11 != a01 + a10) cout<<"Impossible";
		else {
			n = a00+a11; int l1 = a10/a00, l2 = a01/a00;
			if (l1*a00 < a10) pat[n-l2-(a10-l1*a00)] = '1';
			if (l2*a00 < a01) pat[l1+(a01-l2*a00)+1] = '1'; 
			for (int i=1;i<=l1;i++) pat[i] = '1';
			for (int i=1;i<=l2;i++) pat[n-i+1] = '1';
			for (int i=1;i<=n;i++) if (!pat[i]) pat[i] = '0';
			printf("%s",pat+1);
		}
	}
	return 0;
}

34 thoughts to “【Codeforces 708B】Recover the String”

  1. Somebody necessarily help to make significantly posts
    I would state. This is the first time I frequented your website page
    and up to now? I surprised with the research you made to create this actual submit incredible.

    Magnificent job!

  2. Having read this I believed it was rather informative.
    I appreciate you finding the time and energy to put this information together.
    I once again find myself personally spending a lot
    of time both reading and leaving comments. But so what, it was still worth it!

  3. Oh my goodness! Impressive article dude! Many thanks, However I am
    having issues with your RSS. I don’t understand why I can’t subscribe to it.
    Is there anybody having similar RSS problems? Anyone who knows the solution will you
    kindly respond? Thanks!!

  4. This is very interesting, You’re a very skilled blogger.
    I have joined your feed and look forward to seeking more
    of your great post. Also, I’ve shared your site in my social networks!

  5. I do believe all of the ideas you have offered on your post.

    They are very convincing and can certainly work.

    Still, the posts are too quick for newbies. Could you please lengthen them a little from subsequent time?
    Thank you for the post.

  6. Hey There. I discovered your blog using msn. This is a very neatly written article.
    I will be sure to bookmark it and return to learn more of your useful information. Thank you for the post.

    I will certainly return.

  7. Thanks for one’s marvelous posting! I really enjoyed
    reading it, you are a great author.I will be sure to
    bookmark your blog and will eventually come back in the future.
    I want to encourage you to definitely continue your great posts, have a nice
    morning!

  8. It is perfect time to make some plans for the future and it
    is time to be happy. I’ve learn this submit and if I may I
    desire to recommend you some fascinating
    things or suggestions. Perhaps you could write subsequent articles relating to this article.
    I want to read more things approximately it!

  9. I haven?¦t checked in here for a while as I thought it was getting boring, but the last few posts are great quality so I guess I will add you back to my daily bloglist. You deserve it my friend 🙂

  10. Hello! Do you know if they make any plugins to safeguard against hackers?
    I’m kinda paranoid about losing everything I’ve worked hard
    on. Any recommendations?

  11. Hi there, You have done a fantastic job. I’ll definitely digg it and
    personally recommend to my friends. I’m confident
    they will be benefited from this site.

  12. Currently it looks like Drupal is the top blogging platform available right now.

    (from what I’ve read) Is that what you’re using on your blog?

  13. I was suggested this website by my cousin. I am not sure whether this post is written by
    him as no one else know such detailed about my problem. You’re wonderful!
    Thanks!

  14. Fantastic blog! Do you have any hints for aspiring writers? I’m planning to start my own site soon but I’m a little lost on everything. Would you advise starting with a free platform like WordPress or go for a paid option? There are so many options out there that I’m completely confused .. Any ideas? Bless you!

  15. This is the perfect webpage for everyone who hopes to find out about this
    topic. You realize so much its almost tough to argue with you (not that I really will need
    to…HaHa). You definitely put a brand new spin on a subject
    that’s been discussed for years. Excellent stuff, just great!

Leave a Reply

Your email address will not be published. Required fields are marked *