답안 #1085027

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1085027 2024-09-07T10:27:59 Z makrav Red-blue table (IZhO19_stones) C++14
100 / 100
23 ms 2416 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ff first
#define sc second

void solve() {
    int n, m; cin >> n >> m;
    if (n == 1) {
        cout << m << '\n';
        for (int i = 0; i < m; i++) cout << '-';
        cout << '\n';
        return;
    }
    if (m == 1) {
        cout << n << '\n';
        for (int i = 0; i < n; i++) {
            cout << "+\n";
        }
        return;
    }
    pair<int, int> b = {0, 0};
    for (int r = 0; r <= n; r++) {
        for (int c = 0; c <= m; c++) {
            int needr = max(0, m / 2 + 1 - (m - c)), needc = max(0, n / 2 + 1 - (n - r));
            if (needc * c + needr * r <= r * c) {
                if (b.first + b.second < r + c) {
                    b = {r, c};
                }
            }
        }
    }
    cout << b.first + b.second << '\n';
    vector<vector<char>> ans(n, vector<char>(m, '+'));
    for (int j = b.second; j < m; j++) {
        for (int i = 0; i < n; i++) ans[i][j] = '+';
    }
    for (int i = b.first; i < n; i++) {
        for (int j = 0; j < b.second; j++) ans[i][j] = '-';
    }
    int r = b.first, c = b.second;
    int needr = max(0, m / 2 + 1 - (m - c)), needc = max(0, n / 2 + 1 - (n - r));
    int cur = 0;
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c - needr; j++) {
            ans[i][cur] = '-';
            cur = (cur + 1) % c;
        }
    }
    for (auto &u : ans) {
        for (auto v : u) cout << v;
        cout << '\n';
    }
}

signed main() {
    int tt = 1;
    #ifdef LOCAL 
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #else
        ios::sync_with_stdio(false); 
        cin.tie(0); cout.tie(0);
    #endif
    cin >> tt;

    while (tt--) {
        solve();
    }

    return 0;
}

Compilation message

stones.cpp: In function 'void solve()':
stones.cpp:47:46: warning: unused variable 'needc' [-Wunused-variable]
   47 |     int needr = max(0, m / 2 + 1 - (m - c)), needc = max(0, n / 2 + 1 - (n - r));
      |                                              ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 1368 KB Output is correct
2 Correct 18 ms 1748 KB Output is correct
3 Correct 16 ms 1832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 1372 KB Output is correct
2 Correct 16 ms 1604 KB Output is correct
3 Correct 15 ms 1256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 21 ms 1368 KB Output is correct
6 Correct 18 ms 1748 KB Output is correct
7 Correct 16 ms 1832 KB Output is correct
8 Correct 23 ms 1372 KB Output is correct
9 Correct 16 ms 1604 KB Output is correct
10 Correct 15 ms 1256 KB Output is correct
11 Correct 6 ms 604 KB Output is correct
12 Correct 21 ms 1456 KB Output is correct
13 Correct 16 ms 1368 KB Output is correct
14 Correct 12 ms 1024 KB Output is correct
15 Correct 21 ms 2416 KB Output is correct
16 Correct 14 ms 1880 KB Output is correct
17 Correct 6 ms 1368 KB Output is correct