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 int long long
#define f first
#define s second
#define endl '\n'
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int t; cin>>t;
while(t--){
int n,m; cin>>n>>m;
int BOT = n/2;
int BOT1 = m/2;
int best = 0;
int curans = 0;
for(int i = 0; i<(1<<(n*m)); i++){
vector<int> rows(n), columns(m);
for(int k = 0; k<(n*m); k++){
if(i & (1<<k)){
// RED
// cerr<<k/m<<" "<<n<<endl;
rows[k/m]++;
}
else{
columns[k%m]++;
}
}
int ans = 0;
for(int i : rows) ans+= (i>BOT1);
for(int i : columns) ans+= i>(BOT);
// cout<<ans<<endl;
// for(int msk = 0; msk<n*m; msk++){
// if((1<<msk) & i) cout<<'+';
// else cout<<'-';
// if(msk % m == (m-1)) cout<<endl;
// }
// cout<<"COLUMNS: ";
// for(int i : columns) cout<<i<<" ";
// cout<<endl<<"ROWS: ";
// for(int i : rows) cout<<i<<" "; cout<<endl;
if(ans > curans) best = i, curans = ans;
}
cout<<curans<<endl;
for(int i = 0; i<n*m; i++){
if((1<<i) & best) cout<<'+';
else cout<<'-';
if(i % m == (m-1)) cout<<endl;
}
}
}
/*
1 3 7 9 10
10 + 24
9 + 11
7 + 4
1 + 3
*/
# | 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... |