/* #pragma GCC optimize("O3")
#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops") */
#include <bits/stdc++.h>
#define int long long
using namespace std;
int tc;
signed main () {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> tc;
while (tc--) {
int n, m;
cin >> n >> m;
if (n <= 4 && m <= 4) {
char a[n+1][m+1];
int k = n*m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
a[i][j] = '.';
}
}
int mx = -1, mxi = -1;
for (int mask = 0; mask <= (1 << k); mask++) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (mask & (1 << (i*m+m))) {
a[i][j] = '+';
} else {
a[i][j] = '-';
}
}
}
int cnt = 0;
for (int i = 1; i <= n; i++) {
int r = 0, b = 0;
for (int j = 1; j <= m; j++) {
if (a[i][j] == '+') {
r++;
} else {
b++;
}
}
if (r > b) cnt++;
}
for (int j = 1; j <= m; j++) {
int r = 0, b = 0;
for (int i = 1; i <= n; i++) {
if (a[i][j] == '+') {
r++;
} else {
b++;
}
}
if (r > b) cnt++;
}
if (cnt > mx) {
mx = cnt;
mxi = mask;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
a[i][j] = '.';
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (mxi & (1 << (i*m+m))) {
a[i+1][j+1] = '+';
} else {
a[i+1][j+1] = '-';
}
}
}
int cnt = 0;
for (int i = 1; i <= n; i++) {
int r = 0, b = 0;
for (int j = 1; j <= m; j++) {
if (a[i][j] == '+') {
r++;
} else {
b++;
}
}
if (r > b) cnt++;
}
for (int j = 1; j <= m; j++) {
int r = 0, b = 0;
for (int i = 1; i <= n; i++) {
if (a[i][j] == '+') {
r++;
} else {
b++;
}
}
if (r < b) cnt++;
}
cout << cnt << '\n';
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cout << a[i][j];
}
cout << '\n';
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
5 ms |
212 KB |
Wrong answer in test 2 1: 1 < 2 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
216 KB |
Wrong answer |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
5 ms |
212 KB |
Wrong answer in test 2 1: 1 < 2 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Wrong answer |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
316 KB |
Wrong answer |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
5 ms |
212 KB |
Wrong answer in test 2 1: 1 < 2 |
3 |
Halted |
0 ms |
0 KB |
- |