1881B - Three Threadlets - CodeForces Solution


math

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

// using namespace __gnu_pbds;
using namespace std;

#define ff first
#define ss second
#define ll long long int
#define fo(i, a, n) for (ll i = a; i < n; i++)
#define rfo(i, a, n) for (ll i = n - 1; i >= a; i--)
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
#define vll vector<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll>
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define ri reverse_iterator
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ite(a) for (auto &x : a)
#define read(a) ite(a) cin >> x;
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cout.tie(NULL);                   \
    cin.tie(NULL);
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define what_is(x) cerr << #x << " is " << x << endl;
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // *A.find_by_order, A.order_of_key

#ifdef Rishabh
#define deb(x)         \
    cerr << #x << " "; \
    _print(x);         \
    cerr << endl;
#else
#define deb(x) ;
#endif

// function
//  ll expo(ll a, ll b, ll mod) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
//  void google(int t) {cout << "Case #" << t << ": ";}
//  vector<ll> sieve(int n) {int*arr = new int[n + 1](); vector<ll> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;}
//  ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
//  ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
//  ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}
//  ll ceiling(ll n,ll m) {if(n%m==0)return n/m; else return n/m+1;}
//  ll fact(ll n){ll res = 1;for (ll i = 2; i <= n; i++)res = res * i;return res;}
//  ll modInv(ll a) {return expo(a, mod-2, mod);}
//  ll nCr(ll n, ll r){return fact(n) / (fact(r) * fact(n - r));}
//  bool isprime(ll n){for(ll i = 2; i * i <= n; i++){if(n % i == 0){return 0;}}return 1;}

struct Point
{
    int x = 0;
    int y = 0;
};

double dist(const Point &a, const Point &b)
{
    return std::hypot(a.x - b.x, a.y - b.y);
}

void solve()
{
    vector<ll> p;
    for (int i = 0; i < 3; i++)
    {
        ll a;
        cin >> a;
        p.pb(a);
    }
    sort(all(p));
    int rounds = 0;
    while (rounds < 3)
    {
        ll x = p[p.size() - 1] - p[0];
        if (x == 0)
        {
            cout << "YES" << endl;
            return;
        }
        else
        {
            p[p.size() - 1] = p[0];
            p.pb(x);
        }
        rounds++;
        sort(all(p));
    }
    if (p[p.size() - 1] == p[0])
    {
        cout << "YES" << endl;
        return;
    }
    cout << "NO" << endl;
}
int32_t main()
{
    fast;
    clock_t z = clock();
    ll TC;
    cin >> TC;
    for (ll i = 1; i <= TC; i++)
    {
        solve();
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

415. Add Strings
22. Generate Parentheses
13. Roman to Integer
2. Add Two Numbers
515. Find Largest Value in Each Tree Row
345. Reverse Vowels of a String
628. Maximum Product of Three Numbers
1526A - Mean Inequality
1526B - I Hate 1111
1881. Maximum Value after Insertion
237. Delete Node in a Linked List
27. Remove Element
39. Combination Sum
378. Kth Smallest Element in a Sorted Matrix
162. Find Peak Element
1529A - Eshag Loves Big Arrays
19. Remove Nth Node From End of List
925. Long Pressed Name
1051. Height Checker
695. Max Area of Island
402. Remove K Digits
97. Interleaving String
543. Diameter of Binary Tree
124. Binary Tree Maximum Path Sum
1465. Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts
501A - Contest
160A- Twins
752. Open the Lock
1535A - Fair Playoff
1538F - Interesting Function