#include <bits/stdc++.h>
using namespace std;
const int mxn = 1010;
int a[mxn][mxn], n, m;
int b[mxn][mxn];
int sus() {
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
a[i][j] = 0;
int mn_r = (m / 2) + 1, mx_b = m - mn_r;
int mx_r = (n - 1) / 2, mn_b = n - mx_r;
int i = 0, t = 0;
if(mx_b != 0)
for(int j = 0; j < m; j++) {
if(n - i >= mn_b) {
for(int cnt = 0; cnt < mn_b; cnt++, i++) {
a[i][j] = 1;
}
continue;
}
if(t == mx_b - 1) break;
t++;
for(int cnt = 0; cnt < mn_b; cnt++, i++) {
i %= n;
a[i][j] = 1;
}
}
int ans = 0;
for(int i = 0; i < n; i++) {
int sum = 0;
for(int j = 0; j < m; j++)
if(a[i][j] == 0) sum++;
if(sum > m / 2) ans++;
}
for(int j = 0; j < m; j++) {
int sum = 0;
for(int i = 0; i < n; i++)
if(a[i][j]) sum++;
if(sum > n / 2) ans++;
}
return ans;
}
void go() {
cin >> n >> m;
int t1 = sus();
swap(n, m);
int t2 = sus();
bool rev = true;
if(t1 > t2) {
swap(n, m);
sus();
rev = false;
}
cout << max(t1, t2) << '\n';
if(rev)
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
b[j][i] = 1 - a[i][j];
else
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
b[i][j] = a[i][j];
if(rev) swap(n, m);
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++)
if(b[i][j]) cout << '-';
else cout << '+';
cout << '\n';
}
}
int main() {
int T;
cin >> T;
while(T--)
go();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
2 ms |
4712 KB |
Output is correct |
4 |
Correct |
3 ms |
4696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
7708 KB |
Output is correct |
2 |
Correct |
26 ms |
8788 KB |
Output is correct |
3 |
Correct |
26 ms |
8888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
7768 KB |
Output is correct |
2 |
Correct |
23 ms |
8084 KB |
Output is correct |
3 |
Correct |
25 ms |
7456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
2 ms |
4712 KB |
Output is correct |
4 |
Correct |
3 ms |
4696 KB |
Output is correct |
5 |
Correct |
34 ms |
7708 KB |
Output is correct |
6 |
Correct |
26 ms |
8788 KB |
Output is correct |
7 |
Correct |
26 ms |
8888 KB |
Output is correct |
8 |
Correct |
30 ms |
7768 KB |
Output is correct |
9 |
Correct |
23 ms |
8084 KB |
Output is correct |
10 |
Correct |
25 ms |
7456 KB |
Output is correct |
11 |
Correct |
10 ms |
2652 KB |
Output is correct |
12 |
Correct |
25 ms |
8276 KB |
Output is correct |
13 |
Correct |
24 ms |
8796 KB |
Output is correct |
14 |
Correct |
19 ms |
8028 KB |
Output is correct |
15 |
Correct |
28 ms |
9308 KB |
Output is correct |
16 |
Correct |
21 ms |
8728 KB |
Output is correct |
17 |
Correct |
16 ms |
7260 KB |
Output is correct |