#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define PI 3.14159265359
ll n,m,t,p[1001][1001],h[1001][1001],a,b,c,d,e,f,i,j,k,mod=1000000007,mod1=998244353,MAX=1e18;
string s,u;
ll df[101];
vector<pair<ll,ll> >v;
vector<ll>dv[101];
void dfs(ll x){
df[x]=1;
for(ll i=0;i<dv[x].size();i++){
if(df[dv[x][i]]==0){
dfs(dv[x][i]);
}
}
}
ll fastPow(ll a,ll b){
ll d=1;
while(b>0){
if(b%2==1){
d=d*a%mod;
}
b/=2;
a=a*a%mod;
}
return d;
}
ll check(){
ll r=0;
ll b=0;
ll ans=0;
for(ll i=1;i<=n;i++){
r=0;
b=0;
for(ll j=1;j<=m;j++){
if(p[i][j]==1){
r++;
}
else{
b++;
}
}
if(r>b){
ans++;
}
}
for(ll i=1;i<=m;i++){
r=0;
b=0;
for(ll j=1;j<=n;j++){
if(p[j][i]==1){
r++;
}
else{
b++;
}
}
if(b>r){
ans++;
}
}
return ans;
}
int main(){
cin>>t;
while(t--){
cin>>n>>m;
if(n<=4&&m<=4){
a=fastPow(2,n*m);
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
v.pb({i,j});
}
}
ll ans=0;
for(i=0;i<a;i++){
d=i;
for(j=0;j<n*m;j++){
p[v[j].ff][v[j].ss]=d%2;
d/=2;
}
f=check();
if(ans<f){
ans=f;
for(j=1;j<=n;j++){
for(k=1;k<=m;k++){
h[j][k]=p[j][k];
}
}
}
}
cout<<ans<<endl;
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
if(h[i][j]==1){
cout<<'+';
}
else{
cout<<'-';
}
}
cout<<endl;
}
v.clear();
continue;
}
if(min(n,m)<=3){
if(n<=3){
if(n==1){
cout<<m<<endl;
for(i=1;i<=m;i++){
cout<<'-';
}
cout<<endl;
}
else if(n==2){
cout<<m<<endl;
for(i=1;i<=2;i++){
for(j=1;j<=m;j++){
cout<<'-';
}
cout<<endl;
}
}
else{
cout<<n+m-1<<endl;
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
if(i<3){
cout<<'-';
}
else{
cout<<'+';
}
}
cout<<endl;
}
}
}
else{
if(m==1){
cout<<n<<endl;
for(i=1;i<=n;i++){
cout<<'+';
}
cout<<endl;
}
else if(m==2){
cout<<m<<endl;
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
cout<<'+';
}
cout<<endl;
}
}
else{
cout<<n+m-1<<endl;
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
if(j<3){
cout<<'+';
}
else{
cout<<'-';
}
}
cout<<endl;
}
}
}
}
}
}
Compilation message
stones.cpp: In function 'void dfs(long long int)':
stones.cpp:15:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | for(ll i=0;i<dv[x].size();i++){
| ~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
13 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
332 KB |
in the table A+B is not equal to 47 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
13 ms |
332 KB |
Output is correct |
3 |
Incorrect |
6 ms |
332 KB |
in the table A+B is not equal to 47 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Wrong answer |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
332 KB |
Wrong answer |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
13 ms |
332 KB |
Output is correct |
3 |
Incorrect |
6 ms |
332 KB |
in the table A+B is not equal to 47 |