Codeforces Round 730 Solutions

Video Solutions are also given!!

Join Telegram for discussion regarding contest problems: Click Here to join

Problem A: Exciting Bets

#include <iostream>
#include <vector>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
//Code by Abhinav Awasthi
//Language C++
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t,a,b,s,s1,m,n;
    cin>>t;
    while(t--)
    {
        cin>>a>>b;
        if(a>b)
        s=a-b;
        else 
        s=b-a;
        if(a==b)
        cout<<"0 0\n";
        else if(a==0)
        cout<<s<<" "<<"0"<<"\n";
        else if(s==1)
        cout<<"1 0\n";
        else{
            s1=a%s;
            if(s1==0)
            cout<<s<<" "<<s1<<"\n";
            else
            {
                m=s1;
                n=s-s1;
                    if(m>n)
                    s1=n;
                    else
                    s1=m;
                cout<<s<<" "<<s1<<"\n";
            }
        }
    }
    return 0;
}

Problem B: Customising the Track

#include <iostream>
#include <vector>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
//Code by Abhinav Awasthi
//Language C++
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t,n,s,a;
    cin>>t;
    while(t--)
    {
        s=0;
        cin>>n;
       ll arr[n];
       for(int i=0;i<n;i++)
       {
           cin>>arr[i];
           s+=arr[i];
       } 
       if(s%n==0)
       cout<<"0\n";
       else
       {
           a=s%n;
           a*=(n-a);
           cout<<a<<"\n";
       }
    }
    return 0;
}

Problem C: Need for Pink Slips

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define pb push_back
#define pii pair < int, int >
#define F first
#define S second

double ans = 0;
int dd = 0;

void rec(double a, double b, double c, double d, int kl, double x)
{
    double y = (kl + 1) * x * c;
    ans += y;
    if (a > 0 && (int)(a * 10000000) <= dd)
    {
        double a1 = 0, b1 = b, c1 = c;
        if (b == 0)
            c1 += a;
        else
        {
            b1 += a / 2;
            c1 += a / 2;
        }
        rec(a1, b1, c1, d, kl + 1, x * a);
    }
    else if (a > 0)
    {
        double a1 = a - d, b1 = b, c1 = c;
        if (b == 0)
            c1 += d;
        else
        {
            b1 += d / 2;
            c1 += d / 2;
        }
        rec(a1, b1, c1, d, kl + 1, x * a);
    }
    if (b > 0 && (int)(b * 10000000) <= dd)
    {
        double a1 = a, b1 = 0, c1 = c;
        if (a == 0)
            c1 += b;
        else
        {
            a1 += b / 2;
            c1 += b / 2;
        }
        rec(a1, b1, c1, d, kl + 1, x * b);
    }
    else if (b > 0)
    {
        double a1 = a, b1 = b - d, c1 = c;
        if (a == 0)
            c1 += d;
        else
        {
            a1 += d / 2;
            c1 += d / 2;
        }
        rec(a1, b1, c1, d, kl + 1, x * b);
    }
}

int32_t main()
{
    int t;
    cin >> t;
    for (int zzz = 0;zzz < t;zzz++)
    {
        ans = 0;
        double a, b, c, d;
        cin >> a >> b >> c >> d;
        dd = d * 10000000.0;
        rec(a, b, c, d, 0, 1);
        cout << fixed << setprecision(12) << ans << endl;
    }
}

Published by Abhinav Awasthi

Entrepreneur | Coder | Harcourtian'24

Leave a comment

Design a site like this with WordPress.com
Get started