1694A. Creep

#Implementation

้กŒ็›ฎ

Codeforces: 1694A: Creep

Define the score of some binary string ๐‘‡ as the absolute difference between the number of zeroes and ones in it. (for example, ๐‘‡= 010001 contains 4 zeroes and 2 ones, so the score of ๐‘‡ is $|4โˆ’2|=2$).

Define the creepiness of some binary string ๐‘† as the maximum score among all of its prefixes (for example, the creepiness of ๐‘†= 01001 is equal to 2 because the score of the prefix ๐‘†[1โ€ฆ4] is 2 and the rest of the prefixes have a score of 2 or less).

Given two integers ๐‘Ž and ๐‘, construct a binary string consisting of ๐‘Ž zeroes and ๐‘ ones with the minimum possible creepiness.

Input

The first line contains a single integer ๐‘ก (1โ‰ค๐‘กโ‰ค1000) ย โ€” the number of test cases. The description of the test cases follows.

The only line of each test case contains two integers ๐‘Ž and ๐‘ (1โ‰ค๐‘Ž,๐‘โ‰ค100) ย โ€” the numbers of zeroes and ones correspondingly.

่ชชๆ˜Ž

้€™้กŒๅฏไปฅ็›ดๆŽฅๆŠŠๆ•ธๅญธๅผๅˆ—ๅ‡บไพ†ใ€‚

Code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <string>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    for (int lt = 0; lt < T; ++lt) {
        int zeros, ones;
        cin >> zeros >> ones;
        for (int lx = 0; lx < min(zeros, ones); ++lx) {
            cout << "01";
        }
        if (zeros < ones) {
            cout << string(ones - zeros, '1');
        } else { // if (zeros > ones) {
            cout << string(zeros - ones, '0');
        }
        cout << "\n";
    }
    return 0;
}