/*
И пусть меня погубит, то к чему я
Бегу, не жалея ног.
И если мне суждено сгореть на восходе,
Я буду идти вперёд.
*/
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x).size()
#define S second
#define F first
#define all(x) (x).begin(), (x).end()
using namespace std;
const bool dbg_flg = 0;
#define debug(x) if (dbg_flg) cerr << #x << ' ' << x << '\n'
#define debug_pair(x) if (dbg_flg) cerr << #x << ' ' << x.F << ' ' << x.S << '\n'
const int inf = 1e9 + 7;
const int MAXN = 1e5 + 5;
int n, m;
char x[1005][1005];
int res;
char y[1005][1005];
void rec(int i, int j) {
if (i > n) {
int a = 0, b = 0;
for (int i = 1; i <= n; i++) {
int red = 0;
int blue = 0;
for (int j = 1; j <= m; j++) {
if (x[i][j] == '+') red++;
else blue++;
}
if (red > blue) a++;
}
for (int i = 1; i <= m; i++) {
int red = 0;
int blue = 0;
for (int j = 1; j <= n; j++) {
if (x[j][i] == '+') red++;
else blue++;
}
if (red < blue) b++;
}
if (res < a + b) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
y[i][j] = x[i][j];
}
}
res = a + b;
}
return;
}
x[i][j] = '-';
if (j < m) rec(i, j + 1);
else rec(i + 1, 1);
x[i][j] = '+';
if (j < m) rec(i, j + 1);
else rec(i + 1, 1);
}
void solve() {
cin >> n >> m;
res = 0;
rec(1, 1);
cout << res << '\n';
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cout << y[i][j] << ' ';
}
cout << '\n';
}
}
int main() {
//~ freopen(".in", "r", stdin);
//~ freopen(".out", "w", stdout);
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
cout.tie(NULL);
int tt = 1;
cin >> tt;
while (tt--) {
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
376 KB |
Wrong answer |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2083 ms |
376 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
376 KB |
Wrong answer |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2078 ms |
632 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2090 ms |
376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
376 KB |
Wrong answer |
2 |
Halted |
0 ms |
0 KB |
- |