This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
template<class T> using V = vector<T>;
using str = string;
using T = pair<int, int>;
void solve() {
int N, M; cin >> N >> M;
bool SWAP = 0;
if (N < M) { swap(N, M); SWAP = 1; }
// WLOG N > M
int have = (M - 1) / 2;
int need = (N / 2) + 1;
int can = (have * N) / need;
int ans = can + N;
V<str> A(N, str(M, '+'));
priority_queue<T, vector<T>> S;
for(int i = 0; i < N; i++) S.push(make_pair(have, i));
for(int c = 0; c < can; c++) {
V<pair<int, int>> add;
for(int t = 0; t < need; t++) {
if (size(S) == 0) assert(false);
int amt, i; tie(amt, i) = S.top(); S.pop();
A[i][c] = '-'; amt--;
if (amt > 0) add.push_back(make_pair(amt, i));
}
for(auto p : add) S.push(p);
}
if (SWAP) {
V<str> B(M, str(N, '_'));
for(int r = 0; r < N; r++) for(int c = 0; c < M; c++) {
B[c][r] = '+' + '-' - A[r][c];
}
A.swap(B);
swap(N, M);
}
cout << ans << nl;
for(auto x : A) cout << x << nl;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int T; cin >> T;
while(T--) solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |