#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] = N;
}
}
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 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
3 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
1660 KB |
Output is correct |
2 |
Correct |
56 ms |
4060 KB |
Output is correct |
3 |
Correct |
59 ms |
4888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
1760 KB |
Output is correct |
2 |
Correct |
49 ms |
3916 KB |
Output is correct |
3 |
Correct |
49 ms |
3272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
3 ms |
468 KB |
Output is correct |
5 |
Correct |
60 ms |
1660 KB |
Output is correct |
6 |
Correct |
56 ms |
4060 KB |
Output is correct |
7 |
Correct |
59 ms |
4888 KB |
Output is correct |
8 |
Correct |
56 ms |
1760 KB |
Output is correct |
9 |
Correct |
49 ms |
3916 KB |
Output is correct |
10 |
Correct |
49 ms |
3272 KB |
Output is correct |
11 |
Correct |
12 ms |
596 KB |
Output is correct |
12 |
Correct |
50 ms |
4176 KB |
Output is correct |
13 |
Correct |
54 ms |
4712 KB |
Output is correct |
14 |
Correct |
39 ms |
3904 KB |
Output is correct |
15 |
Correct |
65 ms |
5160 KB |
Output is correct |
16 |
Correct |
46 ms |
4304 KB |
Output is correct |
17 |
Correct |
21 ms |
3260 KB |
Output is correct |