This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
k = 0;
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';
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |