#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] << ' ';
}
cout << '\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Wrong answer |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2019 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Wrong answer |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
1368 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2067 ms |
604 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Wrong answer |
2 |
Halted |
0 ms |
0 KB |
- |