Submission #868328

# Submission time Handle Problem Language Result Execution time Memory
868328 2023-10-31T05:37:53 Z The_Samurai Red-blue table (IZhO19_stones) C++17
100 / 100
35 ms 2228 KB
// I stand with PALESTINE




//#pragma GCC optimize("Ofast,O3")
//#pragma GCC target("avx,avx2")
#include "bits/stdc++.h"

using namespace std;
using ll = long long;

void out(int n, int m, vector<vector<char>> &a) {
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int cnt = 0;
        for (int j = 0; j < m; j++) cnt += a[i][j] == '+';
        ans += cnt > m - cnt;
    }
    for (int j = 0; j < m; j++) {
        int cnt = 0;
        for (int i = 0; i < n; i++) cnt += a[i][j] == '-';
        ans += cnt > n - cnt;
    }
    cout << ans << '\n';
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) cout << a[i][j];
        cout << '\n';
    }
}

void solve() {
    int n, m;
    cin >> n >> m;
    if (n >= m) {
        vector a(n, vector(m, '+'));
        vector<pair<int, int>> b(n);
        for (int i = 0; i < n; i++) b[i] = make_pair(m, i);
        for (int j = 0; j < m; j++) {
            sort(b.rbegin(), b.rend());
            int need = n - (n - 1) / 2;
            if (b[need - 1].first <= m - (m - 1) / 2) break;
            for (int i = 0; i < need; i++) {
                a[b[i].second][j] = '-';
                b[i].first--;
            }
        }
        out(n, m, a);
    } else {
        vector a(n, vector(m, '-'));
        vector<pair<int, int>> b(m);
        for (int j = 0; j < m; j++) b[j] = make_pair(n, j);
        for (int i = 0; i < n; i++) {
            sort(b.rbegin(), b.rend());
            int need = m - (m - 1) / 2;
            if (b[need - 1].first <= n - (n - 1) / 2) break;
            for (int j = 0; j < need; j++) {
                a[i][b[j].second] = '+';
                b[j].first--;
            }
        }
        out(n, m, a);
    }
}

int main() {
    cin.tie(0)->sync_with_stdio(false);
#ifdef sunnatov
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int q = 1;
    cin >> q;
    while (q--) {
        solve();
//        cout << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 1372 KB Output is correct
2 Correct 27 ms 1620 KB Output is correct
3 Correct 29 ms 1932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 1360 KB Output is correct
2 Correct 24 ms 1440 KB Output is correct
3 Correct 26 ms 1240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 344 KB Output is correct
5 Correct 28 ms 1372 KB Output is correct
6 Correct 27 ms 1620 KB Output is correct
7 Correct 29 ms 1932 KB Output is correct
8 Correct 35 ms 1360 KB Output is correct
9 Correct 24 ms 1440 KB Output is correct
10 Correct 26 ms 1240 KB Output is correct
11 Correct 7 ms 600 KB Output is correct
12 Correct 23 ms 1620 KB Output is correct
13 Correct 24 ms 1356 KB Output is correct
14 Correct 19 ms 1060 KB Output is correct
15 Correct 34 ms 2228 KB Output is correct
16 Correct 21 ms 1876 KB Output is correct
17 Correct 10 ms 1368 KB Output is correct