【題解】Codeforces 1492D. Genius’s Gambit

【題目敘述】http://codeforces.com/contest/1492/problem/D

#include <iostream>
#include <vector>
using namespace std;
 
int a, b, k;
vector <int> x, y;
 
void f(int t){
    if (t == 0) a--;
    else b--;
    x.push_back(t);
    y.push_back(t);
}
 
int main() {
    cin >> a >> b >> k;
    f(1);
    if (k == 0){
        while (a) f(0);
        while (b) f(1);
    }
    else if (!a || !b || k > (a+b-1)){
        cout << "No\n";
        return 0;
    }
    else{
        a--;
        b--;
        x.push_back(1);
        y.push_back(0);
        for (int i = 0; i < k-1; i++){
            if (a) f(0);
            else f(1);
        }
        x.push_back(0);
        y.push_back(1);
        while (a) f(0);
        while (b) f(1);
    }
    cout << "Yes\n";
    for (auto i:x){
        cout << i;
    }
    cout << "\n";
    for (auto i:y){
        cout << i;
    }
    cout << "\n";
}

分享本文 Share with friends