#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;
for (int i=1;i<=n;i++){
for (int j=1;j<=m-3;j++){
x=j-i;
while(x<0)x+=(m-3);
if (x<l)cout<<"+";
else cout<<"-";
}
cout<<"+++\n";
}
return;
}
if (m/2>=n-3){
cout<<n+m-3<<"\n";
int l=n/2-2, x;
for (int i=1;i<=n-3;i++){
for (int j=1;j<=m;j++){
x=i-j;
while(x<0)x+=(n-3);
if (x<l)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;
for (int i=1;i<=n;i++){
for (int j=1;j<=m-2;j++){
x=j-i;
while(x<0)x+=(m-2);
if (x<l)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 x, l=n-2;
if (n==3)l=0;
for (int i=1;i<=n-2;i++){
for (int j=1;j<=m;j++){
x=j-i;
if (l==0){
cout<<"+";
continue;
}
if (x%l==0)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 (i>=n-1)cout<<"-";
else cout<<"+";
}
cout<<"\n";
}
return;
}
}
}
int main(){
int t;
cin>>t;
while(t--){
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
292 KB |
Output is correct |
3 |
Correct |
1 ms |
292 KB |
Output is correct |
4 |
Incorrect |
2 ms |
332 KB |
in the table A+B is not equal to 50 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
1232 KB |
Output is correct |
2 |
Correct |
27 ms |
1080 KB |
Output is correct |
3 |
Correct |
28 ms |
1120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
29 ms |
1220 KB |
in the table A+B is not equal to 44 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
292 KB |
Output is correct |
3 |
Correct |
1 ms |
292 KB |
Output is correct |
4 |
Incorrect |
2 ms |
332 KB |
in the table A+B is not equal to 50 |