import java.io.*; import java.util.*;
public class stones{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
}
static int MOD=998244353;
static int[] rk, p;
public static void main(String[] args){
FastReader br=new FastReader();
int T=br.nextInt();
StringBuilder sb;
while(T>0){
T--; sb=new StringBuilder();
int N=br.nextInt(); int M=br.nextInt();
if(N==1){
System.out.println(M);
for (int i = 0; i < M; i++) {
sb.append('-');
}
}else if(M==1){
System.out.println(N);
for (int i = 0; i < N; i++) {
sb.append('+').append("\n");
}
}else if(N==2){
System.out.println(M);
for (int i = 0; i < M; i++) {
sb.append('-');
}
sb.append("\n");
for (int i = 0; i < M; i++) {
sb.append('-');
}
}else if(M==2){
System.out.println(N);
for (int i = 0; i < N; i++) {
sb.append('+').append('+').append("\n");
}
}else{//M,N>2
System.out.println(N+M-4+(N&1)+(M&1));
for (int i = 0; i < M; i++) {
sb.append('-');
}
sb.append("\n");
if(N%2==0){
for (int i = 0; i < M; i++) {
sb.append('-');
}
sb.append("\n");
}
for (int i = 2-(N&1); i < N; i++) {
sb.append('+');
if(N%2==0){
sb.append('+');
}
boolean prev=((i-N)%2==0);
for (int j = 2-(M&1); j < M; j++) {
if(prev){
sb.append('+');
}else{
sb.append('-');
}
prev=!prev;
}
sb.append("\n");
}
}
System.out.println(sb.toString());
}
}
}
//Debugging:
//Are you sure your algorithm is correct?
//Bounds: long
//Special cases: n=0,1?
//Make sure you remove your debugging code before you submit!
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
81 ms |
8800 KB |
Output is correct |
2 |
Incorrect |
78 ms |
8556 KB |
Wrong answer in test 4 4: 4 < 5 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
153 ms |
9688 KB |
Wrong answer |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
81 ms |
8800 KB |
Output is correct |
2 |
Incorrect |
78 ms |
8556 KB |
Wrong answer in test 4 4: 4 < 5 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
252 ms |
15484 KB |
Output is correct |
2 |
Correct |
195 ms |
15268 KB |
Output is correct |
3 |
Correct |
176 ms |
16196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
200 ms |
15960 KB |
Wrong answer in test 4 4: 4 < 5 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
81 ms |
8800 KB |
Output is correct |
2 |
Incorrect |
78 ms |
8556 KB |
Wrong answer in test 4 4: 4 < 5 |