Submission #681551

#TimeUsernameProblemLanguageResultExecution timeMemory
681551Matteo_VerzRed-blue table (IZhO19_stones)C++17
100 / 100
43 ms3312 KiB
#include <bits/stdc++.h>

using namespace std;

auto solve(int x, int y) {
    char ch, replacech;
    if (x >= y) {
        swap(x, y);
        ch = '+';
        replacech = '-';
    } else {
        ch = '-';
        replacech = '+';
    }

    vector <vector <char>> a(x, vector <char>(y, ch));
    int ans = y;
    vector <int> freq(y);
    int pos = 0, line = 0;
    while (true) {
        if (freq[(pos + y / 2) % y] < (x - 1) / 2) {
            for (int i = pos; i <= pos + y / 2; i++) {
                freq[i % y]++;
                a[line][i % y] = replacech;
            }
            pos = (pos + y / 2 + 1) % y;
        } else break;
        line++;
        ans++;
    }

    if (replacech == '-') { // have been swapped
        vector <vector <char>> b(y, vector <char>(x));
        for (int i = 0; i < x; i++)
            for (int j = 0; j < y; j++)
                b[j][i] = a[i][j];
        a = b;
    }
    cout << ans << '\n';
    return a;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        int x, y;
        cin >> x >> y;
        auto a = solve(x, y);

        for (int i = 0; i < x; i++, cout << '\n')
            for (int j = 0; j < y; j++)
                cout << a[i][j];
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...