제출 #1294859

#제출 시각아이디문제언어결과실행 시간메모리
1294859kawhietRed-blue table (IZhO19_stones)C++20
17 / 100
2096 ms464 KiB
#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n, m;
    cin >> n >> m;
    int N = n * m;
    int mx = 0;
    vector<string> res;
    for (int s = 0; s < (1 << N); s++) {
        vector<string> a(n, string(m, ' '));
        for (int i = 0; i < N; i++) {
            int x = i / m;
            int y = i % m;
            if (s & (1 << i)) {
                a[x][y] = '+';
            } else {
                a[x][y] = '-';
            }
        }
        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;
        }
        if (cnt > mx) {
            mx = cnt;
            res = a;
        }
    }
    cout << mx << '\n';
    for (auto s : res) {
        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...