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 ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>
int ans[22][22],C[22][22];
int row[22],col[22];
void calc(int r,int c){
int big = 0,cnt = 0;
for(int i = 0;i<(1<<(r*c));i++){
for(int j = 0;j<r;j++)row[j] = 0;
for(int j = 0;j<c;j++)col[j] = 0;
for(int j = 0;j<r;j++){
for(int k = 0;k<c;k++){
if(i&(1<<(j*c+k)))row[j]++,col[k]++;
}
}
int tc = 0;
for(int j = 0;j<r;j++){
tc += (row[j]>c-row[j]);
}
for(int j = 0;j<c;j++){
tc += (r-col[j]>col[j]);
}
if(tc>cnt)cnt = tc,big = i;
}
ans[r][c] = cnt;
C[r][c] = big;
}
void prep(){
for(int i = 1;i<=5;i++){
for(int j = 1;i*j<=20;j++)calc(i,j);
}
return;
}
void solve(int r,int c){
string s[r];
for(int i = 0;i<r;i++){
for(int j = 0;j<c;j++){
if(C[r][c]&(1<<(i*c+j)))s[i] += '+';
else s[i] += '-';
}
}
cout<<ans[r][c]<<'\n';
for(auto &i:s)cout<<i<<'\n';
return;
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
prep();
int t;
cin>>t;
while(t--){
int r,c;
cin>>r>>c;
solve(r,c);
}
return 0;
}
# | 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... |