답안 #624339

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
624339 2022-08-08T01:05:23 Z dqhungdl Red-blue table (IZhO19_stones) C++17
100 / 100
34 ms 2208 KB
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
#include "debug.hpp"
#define debug(x...) cerr << "[" << #x << "] = [", _print(x)
#else
#define debug(x...)
#endif

typedef pair<int, int> ii;
const int MAX = 1005;
int T, m, n;
ii C[MAX];
char a[MAX][MAX];

void solve() {
    cin >> m >> n;
    bool flipped = false;
    if (m < n) {
        flipped = true;
        swap(m, n);
    }
    for (int i = 1; i <= m; i++) {
        C[i] = {n, i};
        for (int j = 1; j <= n; j++)
            a[i][j] = '+';
    }
    int rs = m;
    for (int j = 1; j <= n; j++) {
        sort(C + 1, C + m + 1, greater<>());
        bool valid = true;
        for (int i = 1; i <= m / 2 + 1 && valid; i++)
            if (C[i].first - 1 > n / 2) {
                a[C[i].second][j] = '-';
                C[i].first--;
            } else
                valid = false;
        rs += valid;
    }
    cout << rs << '\n';
    if (flipped) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++)
                cout << (a[j][i] == '+' ? '-' : '+');
            cout << '\n';
        }
    } else {
        for (int i = 1; i <= m; i++) {
            for (int j = 1; j <= n; j++)
                cout << a[i][j];
            cout << '\n';
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef DEBUG
    freopen("../_input", "r", stdin);
#endif
    cin >> T;
    while (T--)
        solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 1444 KB Output is correct
2 Correct 31 ms 2004 KB Output is correct
3 Correct 32 ms 2080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 1364 KB Output is correct
2 Correct 29 ms 1796 KB Output is correct
3 Correct 29 ms 1612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 33 ms 1444 KB Output is correct
6 Correct 31 ms 2004 KB Output is correct
7 Correct 32 ms 2080 KB Output is correct
8 Correct 32 ms 1364 KB Output is correct
9 Correct 29 ms 1796 KB Output is correct
10 Correct 29 ms 1612 KB Output is correct
11 Correct 8 ms 596 KB Output is correct
12 Correct 26 ms 1824 KB Output is correct
13 Correct 27 ms 1996 KB Output is correct
14 Correct 23 ms 1624 KB Output is correct
15 Correct 34 ms 2208 KB Output is correct
16 Correct 25 ms 1932 KB Output is correct
17 Correct 12 ms 1236 KB Output is correct