#pragma GCC optimize("O3")
#pragma GCC target("popcnt")
#include <bits/stdc++.h>
using namespace std;
#define IShowSpeed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define popcnt __builtin_popcount
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define mii map<int,int>
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define pb push_back
#define vt vector
#define endl '\n'
#define X first
#define Y second
typedef long double ld;
typedef long long ll;
const int dx[4]={1,-1,0,0},dy[4]={0,0,1,-1},N=6e5;
const ll mod=1e9+7,inf=1e18;
int n,m;
void solve(){
cin>>n>>m;
int all=n*m;
vt<char>ans;
int ans1=0;
for(int mask=0; mask<(1<<all); ++mask){
vt<char>var;
int col[5]={0,0,0,0,0};
int row[5]={0,0,0,0,0},cnt=0;
for(int i=0; i<all; ++i){
if((mask>>i)&1) var.pb('+');
else var.pb('-');
}
int h=0;
for(int i=0; i<n; ++i)for(int j=0; j<m; ++j){
if(var[h]=='+'){row[i]++;}
if(var[h]=='-'){col[j]++;}
++h;
}
for(int i=0; i<n; ++i) {if(row[i]>=(m+1)/2)++cnt;}
for(int i=0; i<m; ++i) {if(col[i]>=(n+1)/2)++cnt;}
if(ans1<cnt){
ans1=cnt;
ans=var;
}
}
cout<<ans1<<endl;
for(int i=0; i<n; ++i){
for(int j=0; j<m; ++j){
cout<<ans[(i*n)+j];
}
cout<<endl;
}
}
int main() {
IShowSpeed;
int tt=1;
cin>>tt;
while(tt--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
20 ms |
204 KB |
invalid character |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
460 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
20 ms |
204 KB |
invalid character |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2060 ms |
204 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
20 ms |
204 KB |
invalid character |
3 |
Halted |
0 ms |
0 KB |
- |