#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1005;
int cnt1[MAX_N];
int b[MAX_N][MAX_N];
void solve(int N, int M) {
bool is_swap = false;
if(N < M) {
is_swap = true;
swap(N, M);
}
for(int i = 0; i < N; i++) {
for(int j = 0; j < M; j++) {
b[i][j] = 1;
}
cnt1[i] = M;
}
int A = N, maxab = N, to = -1;
for(int j = 0; j < M; j++) {
priority_queue <pair <int, int>> pq;
for(int i = 0; i < N; i++) {
pq.emplace(cnt1[i], i);
}
int cnt = N / 2 + 1;
while(cnt--) {
auto [cn, i] = pq.top();
pq.pop();
if(cnt1[i]-- == M / 2 + 1) {
A--;
}
b[i][j] = 0;
}
if(maxab < A + j + 1) {
maxab = A + j + 1;
to = j;
}
}
cout << maxab << '\n';
if(is_swap == false) {
for(int i = 0; i < N; i++) {
for(int j = 0; j < M; j++) {
if(j <= to) {
cout << (b[i][j] == 1 ? '+' : '-');
}
else {
cout << '+';
}
}
cout << '\n';
}
}
else {
for(int j = 0; j < M; j++) {
for(int i = 0; i < N; i++) {
if(i <= to) {
cout << (b[i][j] == 1 ? '-' : '+');
}
else {
cout << '-';
}
}
cout << '\n';
}
}
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int T;
cin >> T;
while(T--) {
int N, M;
cin >> N >> M;
solve(N, M);
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
0 ms |
340 KB |
in the table A+B is not equal to 5 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
468 KB |
in the table A+B is not equal to 46 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
0 ms |
340 KB |
in the table A+B is not equal to 5 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
56 ms |
1720 KB |
in the table A+B is not equal to 78 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
1880 KB |
Output is correct |
2 |
Correct |
62 ms |
3940 KB |
Output is correct |
3 |
Correct |
55 ms |
3260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
0 ms |
340 KB |
in the table A+B is not equal to 5 |
3 |
Halted |
0 ms |
0 KB |
- |