Submission #1161145

#TimeUsernameProblemLanguageResultExecution timeMemory
1161145MisterReaperRed-blue table (IZhO19_stones)C++20
100 / 100
7 ms3396 KiB
#include <bits/stdc++.h>

using i64 = long long;

#ifdef DEBUG 
    #include "/home/ahmetalp/Desktop/Workplace/debug.h"
#else
    #define debug(...) void(23)
#endif

int calc(int n, int m, std::vector<std::string> v) {
    int res = 0;
    for (int i = 0; i < n; ++i) {
        int bal = 0;
        for (int j = 0; j < m; ++j) {
            bal += (v[i][j] == '+' ? +1 : -1);
        }
        res += bal > 0;
    }
    for (int j = 0; j < m; ++j) {
        int bal = 0;
        for (int i = 0; i < n; ++i) {
            bal += (v[i][j] == '+' ? +1 : -1);
        }
        res += bal < 0;
    }
    return res;
}

void solve() {
    int N, M;
    std::cin >> N >> M;

    std::array<int, 3> ans = {0, 0, 0};
    for (int r = 0; r <= N; ++r) {
        int need = std::max(0, N / 2 + 1 - (N - r));
        int have = r * (M - (M / 2 + 1));
        int c = (need ? std::min(M, have / need) : M);
        if (r + c > ans[0]) {
            ans = {r + c, r, c};
        }
    }

    std::cout << ans[0] << '\n';

    std::vector<std::string> out(N);

    int r = ans[1], c = ans[2];
    for (int i = 0; i < r; ++i) {
        out[i] = std::string(M, '+');
    }
    for (int i = r; i < N; ++i) {
        out[i] = std::string(M, '-');
    }

    if (c != 0) {
        int put = M - (M / 2 + 1);
        assert(put <= c);

        int p = 0;
        for (int i = 0; i < r; ++i) {
            for (int j = 0; j < put; ++j) {
                out[i][p] = '-';
                p = (p + 1) % c;
            }
        }
    }

    for (int i = 0; i < N; ++i) {
        std::cout << out[i] << '\n';
    }

    debug(ans);
    assert(calc(N, M, out) == ans[0]);
    
    return;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int TT = 1; std::cin >> TT;
    for (int i = 1; i <= TT; ++i) {
        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...