Submission #241552

# Submission time Handle Problem Language Result Execution time Memory
241552 2020-06-24T12:24:49 Z valerikk Red-blue table (IZhO19_stones) C++17
100 / 100
48 ms 2304 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld; // typedef double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<ld> vd;
typedef vector<vd> vvd;
typedef complex<ld> cd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef string str;
#define int ll

template<class A, class B>
inline bool mmin(A& a, B b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

template<class A, class B>
inline bool mmax(A& a, B b) {
    if (b > a) {
        a = b;
        return 1;
    }
    return 0;
}

ld nxt_ld() {
    string s;
    cin >> s;
    return stold(s);
}

#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define pf push_front
#define ef emplace_front
#define ppb pop_back
#define ppf pop_front
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

signed main() {
    /*freopen("cbarn.in", "r", stdin);
    freopen("cbran.out", "w", stdout);*/
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        int n, m;
        cin >> n >> m;
        int mn = m / 2 + 1, q = n / 2 + 1;
        int ansr = n, ansc = 0;
        for (int i = 0; i <= n; i++) {
            int l = 0, r = m + 1;
            while (r - l > 1) {
                int md = (l + r) / 2;
                vector<int> cur(md, 0);
                int zz = max(0LL, mn - m + md);
                // w*ansc>=zz*i
                // w>=zz*i/ansc
                int w = (zz * i + md - 1) / md;
                if (n - w >= q) l = md; else r = md;
            }
            if (i + l > ansr + ansc) {
                ansr = i;
                ansc = l;
            }
        }
        cout << ansr + ansc << '\n';
        vvc ans(n, vc(m, '-'));
        int now = 0;
        for (int i = 0; i < ansr; i++) {
            int zz = mn;
            for (int j = m - 1; zz > 0 && j >= ansc; j--) {
                ans[i][j] = '+';
                zz--;
            }
            while (zz--) {
                ans[i][now] = '+';
                now++;
                now %= ansc;
            }
        }
        for (auto x : ans) {
            for (auto y : x) cout << y;
            cout << '\n';
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 8 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 1400 KB Output is correct
2 Correct 35 ms 1656 KB Output is correct
3 Correct 36 ms 1912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 1400 KB Output is correct
2 Correct 33 ms 1504 KB Output is correct
3 Correct 30 ms 1356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 8 ms 384 KB Output is correct
5 Correct 48 ms 1400 KB Output is correct
6 Correct 35 ms 1656 KB Output is correct
7 Correct 36 ms 1912 KB Output is correct
8 Correct 47 ms 1400 KB Output is correct
9 Correct 33 ms 1504 KB Output is correct
10 Correct 30 ms 1356 KB Output is correct
11 Correct 16 ms 640 KB Output is correct
12 Correct 34 ms 1548 KB Output is correct
13 Correct 32 ms 1348 KB Output is correct
14 Correct 25 ms 1152 KB Output is correct
15 Correct 36 ms 2304 KB Output is correct
16 Correct 28 ms 1784 KB Output is correct
17 Correct 15 ms 1024 KB Output is correct