#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1005;
int cnt1[MAX_N];
int b[MAX_N][MAX_N];
// 1 '+' red
// 0 '-' blue
void solve(int N, int M) {
if(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';
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 i = 0; i < N; i++) {
for(int j = 0; j < M; j++) {
b[i][j] = 1;
cnt1[j]++;
}
}
int B = M, maxab = M, to = -1;
for(int i = 0; i < N; i++) {
priority_queue <pair <int, int>> pq;
for(int j = 0; j < M; j++) {
pq.emplace(cnt1[j], j);
}
int cnt = M / 2 + 1;
while(cnt--) {
auto [cn, j] = pq.top();
pq.pop();
if(cnt1[j]-- == N / 2 + 1) {
B--;
}
b[i][j] = 0;
}
if(maxab < B + i + 1) {
maxab = B + i + 1;
to = i;
}
}
cout << maxab << '\n';
for(int i = 0; i < N; i++) {
for(int j = 0; j < M; j++) {
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 |
Incorrect |
0 ms |
340 KB |
in the table A+B is not equal to 5 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
468 KB |
in the table A+B is not equal to 10 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
in the table A+B is not equal to 5 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
65 ms |
1624 KB |
in the table A+B is not equal to 80 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
66 ms |
1868 KB |
in the table A+B is not equal to 38 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
in the table A+B is not equal to 5 |
2 |
Halted |
0 ms |
0 KB |
- |