#include "bits/stdc++.h"
#define mxN 1003
using namespace std;
int a[mxN][mxN];
int cn[mxN];
int solve(int N, int M){
int res = M;
memset(a, 0, sizeof(a));
memset(cn, 0, sizeof(cn));
for (int i = 1; i <= N; i ++){
vector<pair<int,int>> vp;
for (int j = 1; j <= M; j ++)
if ((cn[j] + 1) * 2 < N)
vp.emplace_back(cn[j], j);
if (vp.size() * 2 <= M) break;
sort(begin(vp), end(vp));
for (int j = 0; ; j ++){
a[i][vp[j].second] = 1;
cn[vp[j].second] ++;
if ((j + 1) * 2 > M) break;
}
res ++;
}
return res;
}
int main(){
int T;
cin >> T;
while (T --){
int N, M;
cin >> N >> M;
int f = 0;
if (N > M) swap(N, M), f = 1;
int loc = solve(N, M);
cout << loc << endl;
if (f) swap(N, M);
for (int i = 1; i <= N; i ++){
for (int j = 1; j <= M; j ++)
if (f) cout << (a[j][i] ? '-' : '+');
else cout << (a[i][j] ? '+' : '-');
cout << endl;
}
}
}
# | 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... |