#include <bits/stdc++.h>
using namespace std;
vector <pair <int, int>> v;
int git, n, m, jogap;
char vis[5][5], jog[5][5];
void solve (int x) {
if (x == git + 1) {
int ans = 0;
for (int i = 1; i <= n; ++i) {
int r = 0;
for (int j = 1; j <= m; ++j) {
if (vis[i][j] == '+') {
r++;
}
else r--;
}
if (r > 0) ans++;
}
for (int i = 1; i <= m; ++i) {
int b = 0;
for (int j = 1; j <= n; ++j) {
if (vis[j][i] == '-') b++;
else b--;
}
if (b > 0) ans++;
}
if (jogap < ans) {
jogap = ans;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
jog[i][j] = vis[i][j];
}
}
}
return;
}
for (int i = 0; i < 2; ++i) {
char c;
if (!i) c = '-';
else c = '+';
vis[v[x].first][v[x].second] = c;
solve (x + 1);
}
}
int main () {
int t;
cin >> t;
while ( t-- ) {
cin >> n >> m;
git = n * m;
v.clear();
v.push_back ({0, 0});
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
v.push_back ({i, j});
}
}
solve (1);
cout << jogap << "\n";
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
cout << jog[i][j];
}
cout << "\n";
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
8 ms |
348 KB |
in the table A+B is not equal to 4 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
344 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
8 ms |
348 KB |
in the table A+B is not equal to 4 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
8 ms |
348 KB |
in the table A+B is not equal to 4 |
3 |
Halted |
0 ms |
0 KB |
- |