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;
void solve(){
int n, m;
cin>>n>>m;
if (n==1){
cout<<m<<"\n";
for (int i=1;i<=m;i++)cout<<"-";
cout<<"\n";
return;
}
if (m==1){
cout<<n<<"\n";
for (int i=1;i<=n;i++)cout<<"+\n";
return;
}
if (n==2){
cout<<m<<"\n";
for (int i=1;i<=2;i++){
for (int j=1;j<=m;j++){
cout<<"-";
}
cout<<"\n";
}
return;
}
if (m==2){
cout<<n<<"\n";
for (int i=1;i<=n;i++){
for (int j=1;j<=2;j++){
cout<<"+";
}
cout<<"\n";
}
return;
}
if (n%2==1 && m%2==1){
cout<<n+m-2<<"\n";
for (int i=1;i<=n;i++){
for (int j=1;j<=m;j++){
if (i!=n && j!=m){
if ((i+j)%2==1)cout<<"-";
else cout<<"+";
continue;
}
if (i==n)cout<<"-";
else cout<<"+";
}
cout<<"\n";
}
return;
}
if (n%2==0 && m%2==0){
if (n/2>=m-3){
cout<<n+m-3<<"\n";
int l=m/2-2, x, y, z;
for (int i=1;i<=n;i++){
for (int j=1;j<=m-3;j++){
if (l==0){
cout<<"-";
continue;
}
x=i%(m-3);
if (x==0)x+=(m-3);
y=(x*l)%(m-3);
z=((x-1)*l)%(m-3);
if (y>z){
if (y>=j && z<j)cout<<"+";
else cout<<"-";
}
else{
if (y>=j || z<j)cout<<"+";
else cout<<"-";
}
}
cout<<"+++\n";
}
return;
}
if (m/2>=n-3){
cout<<n+m-3<<"\n";
int l=n/2-2, x, y, z;
for (int i=1;i<=n-3;i++){
for (int j=1;j<=m;j++){
if (l==0){
cout<<"+";
continue;
}
x=j%(n-3);
if (x==0)x+=(n-3);
y=(x*l)%(n-3);
z=((x-1)*l)%(n-3);
if (y>z){
if (y>=i && z<i)cout<<"-";
else cout<<"+";
}
else{
if (y>=i || z<i)cout<<"-";
else cout<<"+";
}
}
cout<<"\n";
}
for (int i=1;i<=3;i++){
for (int j=1;j<=m;j++){
cout<<"-";
}
cout<<"\n";
}
return;
}
else{
cout<<n+m-4<<"\n";
for (int i=1;i<=n;i++){
for (int j=1;j<=m;j++){
if (i<n-1 && j<m-1){
if ((i+j)%2==0)cout<<"+";
else cout<<"-";
continue;
}
if (i>n-2)cout<<"-";
else cout<<"+";
}
cout<<"\n";
}
}
return;
}
if (n%2==0){
if (n>=2*(m-2)){
cout<<n+m-2<<"\n";
int l=m/2-1, x, y, z;
for (int i=1;i<=n;i++){
for (int j=1;j<=m-2;j++){
if (l==0){
cout<<"-";
continue;
}
x=i%(m-2);
if (x==0)x+=(m-2);
y=(x*l)%(m-2);
z=((x-1)*l)%(m-2);
if (y>z){
if (y>=j && z<j)cout<<"+";
else cout<<"-";
}
else{
if (y>=j || z<j)cout<<"+";
else cout<<"-";
}
}
cout<<"++\n";
}
return;
}
else{
cout<<n+m-3<<"\n";
for (int i=1;i<=n;i++){
for (int j=1;j<=m;j++){
if (i<=n-2 && j<=m-1){
if ((i+j)%2==0)cout<<"+";
else cout<<"-";
continue;
}
if (i>n-2)cout<<"-";
else cout<<"+";
}
cout<<"\n";
}
return;
}
}
else{
if (m>=2*(n-2)){
cout<<n+m-2<<"\n";
int l=n/2-1, x, y, z;
for (int i=1;i<=n-2;i++){
for (int j=1;j<=m;j++){
if (l==0){
cout<<"+";
continue;
}
x=j%(n-2);
if (x==0)x+=(n-2);
y=(x*l)%(n-2);
z=((x-1)*l)%(n-2);
if (y>z){
if (y>=i && z<i)cout<<"-";
else cout<<"+";
}
else{
if (y>=i || z<i)cout<<"-";
else cout<<"+";
}
}
cout<<"\n";
}
for (int i=1;i<=2;i++){
for (int j=1;j<=m;j++){
cout<<"-";
}
cout<<"\n";
}
return;
}
else{
cout<<n+m-3<<"\n";
for (int i=1;i<=n;i++){
for (int j=1;j<=m;j++){
if (i<=n-1 && j<=m-2){
if ((i+j)%2==0)cout<<"+";
else cout<<"-";
continue;
}
if (j>m-2)cout<<"+";
else cout<<"-";
}
cout<<"\n";
}
return;
}
}
}
int main(){
int t;
cin>>t;
while(t--){
solve();
}
}
# | 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... |