#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define F first
#define S second
using namespace std;
const ll N=1000006;
int n, m, q, o, u, e, l, M;
string x, y, a[1010];
int main(){ios_base::sync_with_stdio(false), cin.tie(0);
cin>>q;
for (int i=0; i<1001; i++)for (int j=0; j<1001; j++)a[i]+='-';
while(q--){x="";o=u=0;
cin>>n>>m;
if(n==1){cout<<m<<endl;while(m--)cout<<'-';cout<<'\n';continue;}
if(m==1){cout<<n<<endl;while(n--)cout<<"+\n";continue;}
if(n==2){cout<<m<<endl;M=m;while(m--)cout<<'-';cout<<'\n';m=M;while(m--)cout<<'-';cout<<'\n';continue;}
if(m==2){cout<<n<<endl;while(n--)cout<<"++\n";continue;}
if(n==3){cout<<m+1<<endl;M=m;while(m--)cout<<'-';cout<<'\n';m=M;while(m--)cout<<'-';cout<<'\n';m=M;while(m--)cout<<'+';cout<<'\n';continue;}
if(m==3){cout<<n+1<<endl;while(n--)cout<<"++-\n";continue;}
if(n==4){cout<<m+1<<endl;M=m;while(m--)cout<<'-';cout<<'\n';m=M;while(m--)cout<<'-';cout<<'\n';m=M;while(m--)cout<<'-';cout<<'\n';m=M;while(m--)cout<<'+';cout<<'\n';continue;}
if(m==4){cout<<n+1<<endl;while(n--)cout<<"+++-\n";continue;}
if(n%2==1&&m%2==1){
if(n==1){cout<<m<<endl;while(m--)cout<<'-';cout<<'\n';continue;}
if(m==1){cout<<n<<endl;while(n--)cout<<"+\n";continue;}
cout<<n+m-2<<'\n';
for (int i=1; i<=m/2; i++)x+='-';
for (int i=1; i<=m/2+1; i++)x+='+';
for (int i=1; i<=n/2; i++)cout<<x<<'\n';
for (int i=0; i<m-1; i++)x[i]='-'; x[m-1]='+';
cout<<x<<'\n';
x="";
for (int i=1; i<=m/2; i++)x+='+';
for (int i=1; i<=m/2; i++)x+='-';
x+='+';
for (int i=1; i<=n/2; i++)cout<<x<<'\n';
continue;
}
if(n%2==0&&m%2==0){if(n<m)n--,o=1; else m--,u=1;}
if(n%2==1){e=n/2;
for(int i=0; i<n; i++)for(int j=0; j<m; j++)a[i][j]='-';
if(m+4-2*n>=0){l=n-2; for (int i=0; i<m; i++)for (int j=i; j<i+2*e; j+=2)a[min(j%l, n-1)][i]='+';}
else{
for (int i=0; i<n/2; i++)for (int j=0; j<m/2-1; j++)a[i][j]='+';
for (int i=n/2+1; i<n; i++)for (int j=m/2-1; j<m-2; j++)a[i][j]='+';
for (int i=0; i<n; i++)a[i][m-1]='+';
for (int i=0; i<n; i++)a[i][m-2]='+';
l=n-3;
}
}else{e=m/2;
for(int i=0; i<n; i++)for(int j=0; j<m; j++)a[i][j]='+';
if(n+4-2*m>=0){l=m-2;for (int i=0; i<n; i++)for (int j=i; j<i+2*e; j+=2)a[i][min(j%l, m-1)]='-';}
else{
for (int i=0; i<m/2; i++)for (int j=0; j<n/2; j++)a[j][i]='-';
for (int i=m/2+1; i<m; i++)for (int j=n/2-1; j<n; j++)a[j][i]='-';
for (int i=0; i<m; i++)a[n-1][i]='-';
l=m-3;
}
}
cout<<n*(m%2)+m*(n%2)+l<<endl;
for(int i=0; i<n; i++){for(int j=0; j<m; j++)cout<<a[i][j];if(u)cout<<'+';cout<<'\n';}
if(o)while(m--)cout<<'-';cout<<'\n';
}
}
Compilation message
stones.cpp: In function 'int main()':
stones.cpp:35:4: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
35 | for (int i=0; i<m-1; i++)x[i]='-'; x[m-1]='+';
| ^~~
stones.cpp:35:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
35 | for (int i=0; i<m-1; i++)x[i]='-'; x[m-1]='+';
| ^
stones.cpp:70:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
70 | if(o)while(m--)cout<<'-';cout<<'\n';
| ^~
stones.cpp:70:28: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
70 | if(o)while(m--)cout<<'-';cout<<'\n';
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
2284 KB |
Output is correct |
2 |
Correct |
9 ms |
2284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
2284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
2284 KB |
Output is correct |
2 |
Correct |
9 ms |
2284 KB |
Output is correct |
3 |
Correct |
10 ms |
2284 KB |
Output is correct |
4 |
Correct |
11 ms |
2284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
3308 KB |
Output is correct |
2 |
Correct |
10 ms |
3180 KB |
Output is correct |
3 |
Correct |
10 ms |
3112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
3308 KB |
Output is correct |
2 |
Correct |
20 ms |
3052 KB |
Output is correct |
3 |
Correct |
20 ms |
3052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
2284 KB |
Output is correct |
2 |
Correct |
9 ms |
2284 KB |
Output is correct |
3 |
Correct |
10 ms |
2284 KB |
Output is correct |
4 |
Correct |
11 ms |
2284 KB |
Output is correct |
5 |
Correct |
12 ms |
3308 KB |
Output is correct |
6 |
Correct |
10 ms |
3180 KB |
Output is correct |
7 |
Correct |
10 ms |
3112 KB |
Output is correct |
8 |
Correct |
29 ms |
3308 KB |
Output is correct |
9 |
Correct |
20 ms |
3052 KB |
Output is correct |
10 |
Correct |
20 ms |
3052 KB |
Output is correct |
11 |
Correct |
18 ms |
2500 KB |
Output is correct |
12 |
Correct |
11 ms |
3052 KB |
Output is correct |
13 |
Correct |
28 ms |
3052 KB |
Output is correct |
14 |
Correct |
29 ms |
2924 KB |
Output is correct |
15 |
Correct |
46 ms |
3308 KB |
Output is correct |
16 |
Correct |
37 ms |
3052 KB |
Output is correct |
17 |
Correct |
22 ms |
2540 KB |
Output is correct |