제출 #331834

#제출 시각아이디문제언어결과실행 시간메모리
331834keko37Red-blue table (IZhO19_stones)C++14
100 / 100
44 ms2284 KiB
#include<bits/stdc++.h>

using namespace std;

const int MAXN = 1005;

typedef pair <int, int> pi;

int t, n, m, a, b;
char c[MAXN][MAXN];

bool moze (int x, int y) {
    if (x == 0 || y == 0) return 1;
    int ost = x * y - max(a - (m - y), 0) * x;
    return ost / y + n - x >= b;
}

void build (int x, int y) {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (i >= x) c[i][j] = '-';
            if (j >= y) c[i][j] = '+';
        }
    }
    if (y == 0) return;
    int br = max(a - (m - y), 0), curr = 0;
    for (int i = 0; i < x; i++) {
        for (int j = 0; j < y; j++) {
            c[i][(curr + j) % y] = j < br ? '+' : '-';
        }
        curr = (curr + br) % y;
    }
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> t;
    while (t--) {
        cin >> n >> m;
        a = m / 2 + 1;
        b = n / 2 + 1;
        int sol = 0;
        pi best = {0, 0};
        for (int x = 0; x <= n; x++) {
            for (int y = 0; y <= m; y++) {
                if (x + y > sol && moze(x, y)) {
                    sol = x + y;
                    best = {x, y};
                }
            }
        }
        build(best.first, best.second);
        cout << sol << '\n';
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                cout << c[i][j];
            }
            cout << '\n';
        }
    }
    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...