1492D - Genius's Gambit - CodeForces Solution


bitmasks constructive algorithms greedy math *1900

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i, a, n) for (int i = a; i < n; i++)
#define loope(i, b, n) for (int i = b; i <= n; i++)
#define loopit(a) for (auto it = a.begin(); it != a.end(); it++)
#define bloop(i, a, b) for (int i = a; i > b; i--)
#define bloope(i, a, b) for (int i = a; i >= b; i--)
#define ms(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define MP make_pair
#define pi pair<int, int>
#define ff first
#define ss second
#define PQ priority_queue<int> pq;
#define vi vector<int>
#define vii vector<vector<int>>
#define vil vector<ll>
#define viil vector<vector<ll>>
#define si set<int>
#define NO cout << "NO\n";
#define YES cout << "YES\n";
#define MPQ priority_queue<pi, vector<int>, greater<pi>> mpq;
#define io                        \
    ios_base::sync_with_stdio(0); \
    cin.tie(NULL);
const int inf = 0x3f3f3f3f;

void __print(int x) {
    cerr << x;
}
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T &x) {
    int f = 0;
    cerr << '{';
    for (auto &i : x)
        cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
    __print(t);
    if (sizeof...(v))
        cerr << ", ";
    _print(v...);
}

#ifdef MURTAZAS_BUILD
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif

void solve(int testCase) {
    int a, b, c; cin >> a >> b >> c;

    string ansa, ansb;

    b--;
    ansa.pb('1');
    ansb.pb('1');

    // use 0

    if (b >= 1 && a >= 1 && c) {
        ansa.pb('1');
        ansb.pb('0');

        a--, b--, c--;

        int mn = min(a, c);

        ansa = ansa + string(mn, '0');
        ansb = ansb + string(mn, '0');
        a -= mn;
        c -= mn;

        mn = min(b, c);

        ansa = ansa + string(mn, '1');
        ansb = ansb + string(mn, '1');
        c -= mn;
        b -= mn;

        ansa.pb('0');
        ansb.pb('1');

    }
    debug(ansa, ansb);

    if (c) {
        cout << "No\n";
        return;
    }

    cout << "Yes\n";

    loop(i, 0, a)ansa.pb('0'), ansb.pb('0');
    loop(i, 0, b)ansa.pb('1'), ansb.pb('1');

    cout << ansa << "\n" << ansb << "\n";
}

int main() {
    io;
#ifdef MURTAZAS_BUILD
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif

    int testCase = 1, i = 0;
    // cin >> testCase;
    while (i++ != testCase) {
        // cout<<"Case #"<<i<<": ";
        debug(testCase, i);
        solve(i);
    }

#ifdef MURTAZAS_BUILD
    cerr << "Time Taken : " << (float)clock() / CLOCKS_PER_SEC << " seconds" << endl;
#endif

    return 0;
}


Comments

Submit
0 Comments
More Questions

72. Edit Distance
563. Binary Tree Tilt
1306. Jump Game III
236. Lowest Common Ancestor of a Binary Tree
790. Domino and Tromino Tiling
878. Nth Magical Number
2099. Find Subsequence of Length K With the Largest Sum
1608A - Find Array
416. Partition Equal Subset Sum
1446. Consecutive Characters
1618A - Polycarp and Sums of Subsequences
1618B - Missing Bigram
938. Range Sum of BST
147. Insertion Sort List
310. Minimum Height Trees
2110. Number of Smooth Descent Periods of a Stock
2109. Adding Spaces to a String
2108. Find First Palindromic String in the Array
394. Decode String
902. Numbers At Most N Given Digit Set
221. Maximal Square
1200. Minimum Absolute Difference
1619B - Squares and Cubes
1619A - Square String
1629B - GCD Arrays
1629A - Download More RAM
1629C - Meximum Array
1629D - Peculiar Movie Preferences
1629E - Grid Xor
1629F1 - Game on Sum (Easy Version)