Submission #681548

#TimeUsernameProblemLanguageResultExecution timeMemory
681548Matteo_VerzRed-blue table (IZhO19_stones)C++17
100 / 100
48 ms2204 KiB
#include <bits/stdc++.h>

using namespace std;

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

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

    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...