#include <bits/stdc++.h>
using namespace std;
#define sz(s) (int)s.size()
#define ff first
#define ss second
#define ll long long
const int N = 2e3 + 5;
const ll M = 1e9 + 7;
int T, n, m, a[N], b[N][N], k = 0, c[N][N], k1;
void f(int x){
if(x == n*m+1){
for(int i = 1; i <= n*m; i++){
b[(i+m-1)/m][(i % m == 0 ? m : i%m)] = a[i];
}
int ans = 0;
for(int i = 1; i <= n; i++){
int a1 = 0, b1 = 0;
for(int j = 1; j <= m; j++){
if(b[i][j] == 1) a1++;
else b1++;
}
ans += (a1 > b1);
}
int ans1 = ans;
for(int j = 1; j <= m; j++){
int a1 = 0, b1 = 0;
for(int i = 1; i <= n; i++){
if(b[i][j] == 1) a1++;
else b1++;
}
ans += (b1 > a1);
}
if(ans >= k){
k = ans;
k1 = ans1;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
c[i][j] = b[i][j];
}
}
}
return;
}
for(int i = 0; i < 2; i++){
a[x] = i;
f(x+1);
}
}
int main(){
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> T;
while(T--){
cin >> n >> m;
f(1);
cout << k << '\n';
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
cout << (c[i][j] == 1 ? '+' : '-');
}
cout << '\n';
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
10 ms |
348 KB |
in the table A+B is not equal to 4 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2075 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
10 ms |
348 KB |
in the table A+B is not equal to 4 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
1116 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2088 ms |
604 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
10 ms |
348 KB |
in the table A+B is not equal to 4 |
3 |
Halted |
0 ms |
0 KB |
- |