Submission #1294978

#TimeUsernameProblemLanguageResultExecution timeMemory
1294978kawhietRed-blue table (IZhO19_stones)C++20
0 / 100
5 ms4416 KiB
#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n, m;
    cin >> n >> m;
    vector<string> a(n, string(m, ' '));
    if (n & 1) {
        int t = (n + 1) / 2;
        for (int i = t; i < n; i++) {
            fill(a[i].begin(), a[i].end(), '-');
        }
        int k = 0;
        for (int i = 0; i < (n + 1) / 2; i++) {
            fill(a[i].begin(), a[i].end(), '+');
            for (int j = k; j < m; j += t) {
                a[i][j] = '-';
            }
            k++;
        }
    } else {
        for (int i = n / 2 - 1; i < n; i++) {
            fill(a[i].begin(), a[i].end(), '-');
        }
        int t = n / 2 + 1;
        int k = 0;
        for (int i = 0; i < n / 2 - 1; i++) {
            fill(a[i].begin(), a[i].end(), '-');
            for (int j = k; j < k + t; j++) {
                a[i][j] = '+';
            }
            k++;
        }
    }
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        int red = 0, blue = 0;
        for (int j = 0; j < m; j++) {
            if (a[i][j] == '+') {
                red++;
            } else {
                blue++;
            }
        }
        cnt += red > blue;
    }
    for (int j = 0; j < m; j++) {
        int red = 0, blue = 0;
        for (int i = 0; i < n; i++) {
            if (a[i][j] == '+') {
                red++;
            } else {
                blue++;
            }
        }
        cnt += blue > red;
    }
    cout << cnt << '\n';
    for (auto s : a) {
        cout << s << '\n';
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    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...