답안 #579344

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
579344 2022-06-19T01:34:55 Z KoD Red-blue table (IZhO19_stones) C++17
100 / 100
34 ms 2288 KB
#include <bits/stdc++.h>

using std::vector;
using std::array;
using std::pair;
using std::tuple;

using ll = long long;

template <class T>
constexpr T infty = std::numeric_limits<T>::max() / 2;

void solve(const int N, const int M) {
    const int Nh = N / 2 + 1;
    const int Mh = M / 2 + 1;
    int best_r = N, best_c = 0;
    for (int r = 0; r <= N; ++r) {
        for (int c = 1; c <= M; ++c) {
            const int a = std::max(Mh - (M - c), 0);
            if (N - (a * r + c - 1) / c >= Nh) {
                if (best_r + best_c < r + c) {
                    best_r = r;
                    best_c = c;
                }
            }
        }
    }
    vector ans(N, vector(M, '-'));
    const int a = std::max(Mh - (M - best_c), 0);
    for (int i = 0; i < best_r; ++i) {
        for (int j = a * i; j < a * (i + 1); ++j) {
            ans[i][j % best_c] = '+';
        }
        for (int j = best_c; j < M; ++j) {
            ans[i][j] = '+';
        }
    }
    std::cout << best_r + best_c << std::endl;
    for (const auto& v : ans) {
        for (const char c : v) {
            std::cout << c;
        }
        std::cout << '\n';
    }
}

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);    
    int test;
    std::cin >> test;
    while (test--) {
        int n, m;
        std::cin >> n >> m;
        solve(n, m);
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 1316 KB Output is correct
2 Correct 27 ms 1604 KB Output is correct
3 Correct 31 ms 1896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 1264 KB Output is correct
2 Correct 27 ms 1476 KB Output is correct
3 Correct 25 ms 1244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 32 ms 1316 KB Output is correct
6 Correct 27 ms 1604 KB Output is correct
7 Correct 31 ms 1896 KB Output is correct
8 Correct 34 ms 1264 KB Output is correct
9 Correct 27 ms 1476 KB Output is correct
10 Correct 25 ms 1244 KB Output is correct
11 Correct 9 ms 488 KB Output is correct
12 Correct 23 ms 1528 KB Output is correct
13 Correct 25 ms 1236 KB Output is correct
14 Correct 19 ms 992 KB Output is correct
15 Correct 30 ms 2288 KB Output is correct
16 Correct 21 ms 1740 KB Output is correct
17 Correct 10 ms 980 KB Output is correct