답안 #532534

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
532534 2022-03-03T05:48:33 Z syl123456 Red-blue table (IZhO19_stones) C++17
100 / 100
10 ms 2252 KB
#include <bits/stdc++.h>
#define all(i) (i).begin(), (i).end()
using namespace std;
void Debug(bool _split) {}
template<typename T1, typename ...T2>
void Debug(bool _split, T1 i, T2 ...j) {
    if (_split)
        cerr << ", ";
    cerr << i;
    Debug(true, j...);
}
#define debug(args...) cerr << "Line(" << __LINE__ << ") : [" << #args << "] is [", Debug(false, args), cerr << "]" << endl
template<typename T1, typename T2>
ostream& operator << (ostream& i, pair<T1, T2> j) {
    return i << '(' << j.first << ", " << j.second << ')';
}
 
typedef long long ll;
typedef pair<int, int> pi;
const int inf = 0x3f3f3f3f, lg = 20;
const ll mod = 1e9 + 7, INF = 0x3f3f3f3f3f3f3f3f;
 
signed main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        int n, m;
        cin >> n >> m;
        pi ans(n, 0);
        if (m > n)
            ans = pi(0, m);
        for (int i = n; i; --i)
            for (int j = m; j; --j) {
                if (i + j <= ans.first + ans.second)
                    break;
                int x = n + 2 >> 1, y = m + 2 >> 1;
                x = max(0, x - n + i);
                if (!x) {
                    ans = pi(i, j);
                    continue;
                }
                if (m == y) {
                    continue;
                }
                int tmp = 0, rem = 0;
                for (int _i = 0; _i < x && tmp <= i; ++_i)
                    for (int _j = 0; _j < j && tmp <= i; ++_j) {
                        if (!rem)
                            ++tmp, rem = min(j, m - y);
                        --rem;
                    }
                if (tmp <= i)
                    ans = pi(i, j);
            }
        cout << ans.first + ans.second << '\n';
        int x = n + 2 >> 1, y = m + 2 >> 1;
        x = max(0, x - n + ans.first);
        vector<string> s(ans.first, string(m, '+'));
        int tmp = -1, rem = 0;
        for (int i = 0; i < x; ++i)
            for (int j = m - ans.second; j < m; ++j) {
                if (!rem)
                    ++tmp, rem = min(ans.second, m - y);
                s[tmp][j] = '-', --rem;
            }
        for (auto i : s)
            cout << i << '\n';
        for (int i = ans.first; i < n; ++i)
            cout << string(m, '-') << '\n';
    }
}

Compilation message

stones.cpp: In function 'int main()':
stones.cpp:37:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   37 |                 int x = n + 2 >> 1, y = m + 2 >> 1;
      |                         ~~^~~
stones.cpp:37:43: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   37 |                 int x = n + 2 >> 1, y = m + 2 >> 1;
      |                                         ~~^~~
stones.cpp:57:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   57 |         int x = n + 2 >> 1, y = m + 2 >> 1;
      |                 ~~^~~
stones.cpp:57:35: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   57 |         int x = n + 2 >> 1, y = m + 2 >> 1;
      |                                 ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 1356 KB Output is correct
2 Correct 4 ms 1612 KB Output is correct
3 Correct 5 ms 1844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1372 KB Output is correct
2 Correct 5 ms 1356 KB Output is correct
3 Correct 4 ms 1192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 8 ms 1356 KB Output is correct
6 Correct 4 ms 1612 KB Output is correct
7 Correct 5 ms 1844 KB Output is correct
8 Correct 10 ms 1372 KB Output is correct
9 Correct 5 ms 1356 KB Output is correct
10 Correct 4 ms 1192 KB Output is correct
11 Correct 4 ms 460 KB Output is correct
12 Correct 4 ms 1552 KB Output is correct
13 Correct 5 ms 1224 KB Output is correct
14 Correct 4 ms 1012 KB Output is correct
15 Correct 7 ms 2252 KB Output is correct
16 Correct 7 ms 1740 KB Output is correct
17 Correct 2 ms 952 KB Output is correct