1694A - Creep - CodeForces Solution


greedy implementation *800

Please click on ads to support us..

Python Code:

t = int(input())
for _ in range(t):
    a, b = map(int, input().split())
    res = ""
    while a != 0 and b != 0:
        res += '10'
        a -= 1
        b -= 1
    res += '0'*a
    res += '1'*b
    print(res)

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll sol()
{
   ll a,b,c,z=1;
   cin>>a>>b;
   if(a<b)
   {
       c=b-a;
   }
   else if(b<a)
   {
       c=a-b;
   }
   else
   {
       c=1;
   }
       while(b!=0 || a!=0)
       {
            for(ll i=1;i<=c;i++)
            {
                if(z==1 && b>0)
                {
                    cout<<'1';
                    b--;
                }
                 if(b==0)
                 {
                     z=0;
                     break;
                 }
                 if(c==i)
                 {
                     z=0;
                 }
            }
            for(ll i=1;i<=c;i++)
            {
                if(z==0 && a>0)
                {
                    cout<<'0';
                    a--;
                }
                 if(a==0)
                 {
                     z=1;
                     break;
                 }
                  if(c==i)
                 {
                     z=1;
                 }
            }
            
       }
       cout<<endl;
   
   return 0;

}
int main() {
    ll t;
    cin>>t;
    while(t--)
    {
        ll a=sol();
    }
}


Comments

Submit
0 Comments
More Questions

1296B - Food Buying
133A - HQ9+
1650D - Twist the Permutation
1209A - Paint the Numbers
1234A - Equalize Prices Again
1613A - Long Comparison
1624B - Make AP
660B - Seating On Bus
405A - Gravity Flip
499B - Lecture
709A - Juicer
1358C - Celex Update
1466B - Last minute enhancements
450B - Jzzhu and Sequences
1582C - Grandma Capa Knits a Scarf
492A - Vanya and Cubes
217A - Ice Skating
270A - Fancy Fence
181A - Series of Crimes
1638A - Reverse
1654C - Alice and the Cake
369A - Valera and Plates
1626A - Equidistant Letters
977D - Divide by three multiply by two
1654B - Prefix Removals
1654A - Maximum Cake Tastiness
1649A - Game
139A - Petr and Book
1612A - Distance
520A - Pangram