#include <bits/stdc++.h>
using namespace std;
int t, n, m;
void rotate(vector<vector<bool>> &v) {
int nv = v.size(), mv = v[0].size();
vector<vector<bool>> vp(mv, vector<bool>(nv));
for (int i = 0; i < nv; i++) {
for (int j = 0; j < mv; j++) {
vp[j][i] = v[i][j];
}
}
v = vp;
}
int solve(int nv, int mv, vector<vector<bool>> &v) {
auto ok = [nv, mv, &v](int save) {
vector<int> cnt(save, nv);
priority_queue<pair<int, int>> pq;
for (int i = 0; i < save; i++) {
pq.push(make_pair(0, i));
}
int plus = (nv / 2) + (nv % 2) - (mv - save);
for (int i = 0; i < nv; i++) {
for (int j = 0; j < mv; j++) {
v[i][j] = (j >= save);
}
for (int _ = 1; _ <= plus; _++) {
auto [__, j] = pq.top();
pq.pop();
v[i][j] = 1;
pq.push(make_pair(-(--cnt[j]), j));
}
}
bool ret = 1;
for (int x : cnt) {
ret &= (x >= (nv / 2) + (nv % 2));
}
return ret;
};
int lo = 0, hi = mv;
while (hi - lo > 1) {
int mid = (lo + hi) / 2;
if (ok(mid)) lo = mid;
else hi = mid - 1;
}
if (ok(hi)) return nv + hi;
return nv + lo;
}
int main() {
cin >> t;
while (t--) {
cin >> n >> m;
vector<vector<bool>> org(n, vector<bool>(m));
int goodA = solve(n, m, org);
vector<vector<bool>> alt(m, vector<bool>(n));
int goodB = solve(m, n, alt);
if (goodA < goodB) {
swap(goodA, goodB);
rotate(alt);
swap(alt, org);
}
cout << goodA << '\n';
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cout << (org[i][j] ? '+' : '-');
}
cout << '\n';
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
in the table A+B is not equal to 3 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
in the table A+B is not equal to 3 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
81 ms |
1252 KB |
in the table A+B is not equal to 37 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
in the table A+B is not equal to 3 |
2 |
Halted |
0 ms |
0 KB |
- |