S1_H_Team

Team

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Now it’s time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They’ve been best friends ever since primary school and hopefully, that can somehow help them in teamwork.

For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that:

  • there wouldn’t be a pair of any side-adjacent cards with zeroes in a row;
  • there wouldn’t be a group of three consecutive cards containing numbers one.

Today Vanya brought n cards with zeroes and m cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a way.

Input

The first line contains two integers: n (1 ≤ n ≤ 106) — the number of cards containing number 0; m (1 ≤ m ≤ 106) — the number of cards containing number 1.

Output

In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1.

Examples

input

Copy

1 2

output

Copy

101

input

Copy

4 8

output

Copy

110110110101

input

Copy

4 10

output

Copy

11011011011011

input

Copy

1 5

output

Copy

-1

题目大意

给定0与1的个数,输出满足以下条件的一个序列(任意一个即可)

  • 不能有连续的两个0
  • 不能有连续的三个1

题目分析

注意到 n n 的取值范围是 1 0 6 10 ^ 6 ,最后应该用输出挂优化,不然会超时(实际上训练的时候完全没有留意到,递交C++是没有事情的,队内有人用C说超时了)

分类既可以。我们先考虑一个简单的情况,就是0与1的个数是相等的。那么,我们可以这样排:

010101……

0与1交错排列。然后我们再继续分类考虑复杂的情况。

0比1多的情况:

我们观察到,当两者相等的情况,当0比1的个数多一个的时候,只要把0插到后面就行。而拥有更多的0的时候,找不到合适的序列满足这种情况。

1比0多的情况

由于我们条件限制是3个1不能相邻,所以两个1是可以相邻的。我们考虑,当:

  1. 1是0的两倍以内的时候

    排列成011011011……这样的形式就可以了

  2. 当1比0的两倍还多的时候

    由于第一个是0,所以我们还可以往前面两个位置插入1。所以,$num(1) \le 2 \times num(0) +2 num(n)$是数字n的跟个数

至此,我们已经分类了所有的情况,所以按照以上的分析写就行了。

参考代码

#include <cstdio>
#include <algorithm>
using namespace std;
int main(int argc, char const *argv[]) {
  int n, m;
  while(~scanf("%d%d", &n, &m)){
    int k = min(n, m), t = m - k;
    n -= k; m -= k;
    if(n != 0 && n != 1){
      printf("%d\n", -1);
      break;
    }else{
      if(t > k + 2){
        printf("%d\n", -1);
        break;
      }
      if(t - k > 0){
        for(int i = 0; i < t - k; i++)
          printf("1");
        t -= t - k;
      }
    }
    for(int i = 0; i < k; i++){
      printf("01");
      if(t-- > 0) printf("1");
    }
    if(n == 1)
      printf("0");
    printf("\n");
  }
  return 0;
}

猜你喜欢

转载自blog.csdn.net/IT_w_TI/article/details/88323086