Submission #158173

# Submission time Handle Problem Language Result Execution time Memory
158173 2019-10-15T08:21:07 Z koste4ka Red-blue table (IZhO19_stones) C++14
27 / 100
34 ms 1656 KB
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define pb push_back
#define F first
#define S second
#define lll long long
#define lld long double

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree <T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

const int N = 3e5 + 229;
const int M = 1e9 + 7;
const lll M2 = 1e9 + 9;
const lll mod = 998244353;
const int rx[8] = {1, 1, -1, -1, -2, -2, 2, 2};
const int ry[8] = {-2, 2, -2, 2, 1, -1, 1, -1};
const lld eps = 1e-7;
const double pi = acos(-1.0);

bool a[2000][2000];

int k[2000];

void solve() {
    int n, m;
    cin >> n >> m;
    int ans = max(n, m);
    for (int i = 0; i < max(n, m); ++i) {
        k[i] = 0;
    }
    if (m > n) {
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                a[i][j] = 1;
            }
        }
        int now;
        for (int i = 0; i < n; ++i) {
            now = 0;
            for (int j = 0; j < m; ++j) {
                if (k[j] + 1 < (n + 1) / 2) {
                    ++now;
                    ++k[j];
                    a[i][j] = 0;
                    if (now >= m / 2 + 1) {
                        break;
                    }
                }
            }
            if (now >= m / 2 + 1) {
                ++ans;
            }
        }
    } else {
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                a[i][j] = 0;
            }
        }
        int now;
        for (int j = 0; j < m; ++j) {
            now = 0;
            for (int i = 0; i < n; ++i) {
                if (k[i] + 1 < (m + 1) / 2) {
                    ++now;
                    ++k[i];
                    a[i][j] = 1;
                    if (now >= n / 2 + 1) {
                        break;
                    }
                }
            }
            if (now >= n / 2 + 1) {
                ++ans;
            }
        }
    }
    cout << ans << '\n';
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (a[i][j]) {
                cout << '-';
            } else {
                cout << '+';
            }
        }
        cout << '\n';
    }
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    srand(time(0));
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Incorrect 4 ms 424 KB Wrong answer in test 5 29: 31 < 32
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 1552 KB Wrong answer in test 97 21: 107 < 116
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 34 ms 1656 KB Wrong answer in test 24 24: 35 < 44
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Incorrect 4 ms 424 KB Wrong answer in test 5 29: 31 < 32