• C. Team


    Problem - C - Codeforces

    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的数组,排序满足条件:

    1.两个相邻的零不能在一起

    2.三个1不能在一起

    1. #include
    2. #include
    3. #include
    4. #include
    5. #include
    6. #include
    7. #include
    8. #include
    9. #include
    10. #include
    11. using namespace std;
    12. // ctrl+shift+C 注释
    13. //ctrl+shift+x 取消
    14. #define int long long
    15. #define YES cout<<"YES"<
    16. #define NO cout<<"NO"<
    17. #define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    18. typedef long long ll;
    19. typedef pair<int,int> PII;
    20. const int N=2e5+10;
    21. const ll M=1e18+10;
    22. const int mod=1e9+7;
    23. int a[N],sum[N];
    24. priority_queue<int,vector<int>,greater<int> >pq;
    25. set<int>se;
    26. map<int,int>mp;
    27. queue<int>qu;
    28. vector<int>v;
    29. deque<int>de;
    30. int n,m;
    31. void solve()
    32. {
    33. cin>>n>>m;
    34. if(m>n*2+2||n>m+1)
    35. {
    36. cout<<-1<
    37. return;
    38. }
    39. int f=0;
    40. if(m==n)// 010101
    41. {
    42. for(int i=0;i
    43. {
    44. cout<<"10";
    45. }
    46. }
    47. else if(m-n<=2&&m>n)// n=2 m=3 10101
    48. {
    49. for(int i=1;i<=n;i++)
    50. {
    51. cout<<"10";
    52. }
    53. for(int i=1;i<=m-n;i++)
    54. cout<<"1";
    55. }
    56. else if(n-1==m)// n=3 m=2 01010
    57. {
    58. for(int i=1;i<=m;i++)
    59. {
    60. cout<<"01";
    61. }
    62. cout<<0;
    63. }
    64. else if(m2)// 0多 n=4 m=7 11011011010
    65. {
    66. int res=n*2-m;
    67. for(int i=1;i<=n-res;i++)
    68. {
    69. cout<<"110";
    70. }
    71. for(int i=1;i<=res;i++)
    72. {
    73. cout<<"10";
    74. }
    75. }
    76. else if(m==n*2)
    77. {
    78. for(int i=0;i
    79. {
    80. cout<<"110";
    81. }
    82. }
    83. else if(m>n*2&&m<=n*2+2)//1多 n=4 m=9 1101101101101
    84. {
    85. for(int i=0;i
    86. {
    87. cout<<"110";
    88. }
    89. int res=m-n*2;
    90. for(int i=1;i<=res;i++)
    91. {
    92. cout<<1;
    93. }
    94. }
    95. cout<
    96. }
    97. signed main()
    98. {
    99. int t=1;
    100. //cin>>t;
    101. while(t--)
    102. {
    103. solve();
    104. }
    105. }

  • 相关阅读:
    Servlet的生命周期
    【Go 基础篇】Windows 开发常用 Dos 命令
    Docker最新超详细教程——入门简介
    JSTL 标签库
    文生视频Sora模型发布,是否引爆AI芯片热潮
    MySQL——表的插入
    Apache Paimon 使用之 Querying Tables
    Elasticsearch:ES|QL 查询语言简介
    vim绝对常用命令
    【Exception】 Java Lambda List转换Map报错 触发异常 IllegalStateException: Duplicate key
  • 原文地址:https://blog.csdn.net/qq_62079079/article/details/127562101