Submission #1294919

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

void solve() {
    int n, m;
    cin >> n >> m;
    bool rev = 0;
    if (n > m) {
        rev = 1;
        swap(n, m);
    }
    int t = (n + 1) / 2;
    vector<string> a(n, string(m, '+'));
    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++;
    }
    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';
    if (rev) {
        for (int j = 0; j < m; j++) {
            for (int i = 0; i < n; i++) {
                cout << (a[i][j] == '+' ? '-' : '+');
            }
            cout << '\n';
        }
    } else {
        for (auto s : a) {
            cout << s << '\n';
        }
    }
}

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