제출 #1171955

#제출 시각아이디문제언어결과실행 시간메모리
1171955qrnRed-blue table (IZhO19_stones)C++20
0 / 100
14 ms2424 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;
    bool is = false;
    if(n > m) {
        swap(n,m); is = true;
    }
    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);
            // cout << i << ": ";
            // for(intt j : jler) cout << j << " ";
            // cout << endl;
            for(intt j = 0; j < jler.size(); j++) {
                intt curj = jler[j];
                cnt[curj]++;
                g[i][curj] = '+';
                if((j + 1) * 2 > m) break;
            }
            ans++;
            } else {
                break;
            }
        // for(intt j = 1; j <= n; j++) {
        //     for(intt k = 1; k <= m; k++) {
        //         cout << g[j][k];
        //     }
        //     cout << endl;
        // }
    }
    cout << ans + m << endl;
    if(is) swap(n, m);
    // cout << g[7][1] << endl;
    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...