Submission #1171963

#TimeUsernameProblemLanguageResultExecution timeMemory
1171963qrnRed-blue table (IZhO19_stones)C++20
100 / 100
91 ms100676 KiB
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
using namespace std;
// using namespace __gnu_pbds;

#define SPEED                     \
    ios_base::sync_with_stdio(0); \
    cin.tie(NULL);                \
    cout.tie(NULL);

#define pb push_back
#define ins insert
#define fi first
#define se second

#define endl "\n"
#define ALL(x) x.begin(), x.end()
#define sz(x) x.size()
#define intt long long

const intt mod = 1e9 + 7;
const intt base = 31;
const intt inf = 1e9;
const intt mxN = 1e3 + 5;
const intt L = 21;

vector<intt> cnt(mxN);
vector<vector<char>> g(mxN, vector<char>(mxN, '-'));

bool cmp(intt &a, intt &b) {
    if(cnt[a] == cnt[b]) return a < b;
    return cnt[a] < cnt[b];
}

void solve() {
    intt n, m;
    cin >> n >> m;
    cnt.assign(20* m + 1, 0ll);
    bool is = false;
    if(n > m) {
        swap(n,m); is = true;
    }
    g.assign(10 * n + 1, vector<char>(10 * m + 1, '-'));
    intt ans = 0;
    for(intt i = 1; i <= n; i++) {
        vector<intt> jler;
        intt fort = 0;
        for(intt j = 1; j <= m; j++) {
            if((cnt[j] + 1) * 2 >= n) continue;
            jler.pb(j);
            fort++;
        }
        if(fort * 2 > m) {
            sort(ALL(jler), cmp);
            intt fortt = 0;
            for(intt curj : jler) {
                g[i][curj] = '+';
                cnt[curj]++;
                if((fortt + 1) * 2 > m) break;
                fortt++;
            }
            ans++;
        } else {
            break;
        }
    }
    cout << ans + m << endl;
    if(is) swap(n, m);
    if(is) {
        for(intt i = 1; i <= n; i++) {
            for(intt j = 1; j <= m; j++) {
                if(g[j][i] == '+') {
                    cout << '-';
                } else {
                    cout << '+';
                }
            }
            cout << endl;
        }
    } else {
        for(intt i = 1; i <= n; i++) {
            for(intt j = 1; j <= m; j++) {
                cout << g[i][j];
            }
            cout << endl;
        }
    }
}

signed main() {
    SPEED;
    intt tst = 1;
    cin >> tst;
    while (tst--) {
        solve();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...