답안 #332370

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
332370 2020-12-02T06:32:45 Z KWang31 Red-blue table (IZhO19_stones) Java 11
26 / 100
321 ms 21904 KB
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; int d;
        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
                if(M%2==1 && N%2==1){
                    sb.append(M+N-2).append("\n");
                    sb.append('+');
                    for (int i = 0; i < M-1; i++) {
                        sb.append('-');
                    }
                    sb.append("\n");
                    for (int i = 0; i < N-1; i++) {
                        sb.append('+');
                        for (int j = 0; j < M-1; j++) {
                            if((i+j)%2==0){
                                sb.append('+');
                            }else{
                                sb.append('-');
                            }
                        }
                        sb.append("\n");
                    }
                }else if(N%2==1){
                    if(M/2 >= N-2){
                        sb.append(M+N-2).append("\n");   
                        for (int i = 0; i < N-2; i++) {
                            for (int j = 0; j < 2*(N-2); j++) {
                                d=(j-(N-3)*i+2000*(N-2))%(2*N-4); 
                                if(d<N-3)sb.append('-');
                                else sb.append('+');
                            }
                            for (int j = 2*(N-2); j < M; j++) {
                                if((i+j)%2==0)sb.append('+');
                                else sb.append('-');
                            }
                            sb.append("\n");
                        }
                        for (int i = 0; i < 2; i++) {
                            for (int j = 0; j < M; j++) {sb.append('-');}
                            sb.append("\n");
                        }
                    }else{
                        sb.append(M+N-3).append("\n");
                       
                        for (int j = 0; j < M; j++) {sb.append('-');}
                        sb.append("\n");
                        
                        for (int i = 0; i < N-1; i++) {
                            sb.append("++");
                            for (int j = 0; j < M-2; j++) {
                                if((i+j)%2==0)sb.append('-');
                                else sb.append('+');
                            }
                            sb.append("\n");
                        }
                    }
                }else if(M%2==1){
                    if(N/2 < M-2){
                        sb.append((M+N-3)+"\n");
                        for(int i=0;i<M;i++)sb.append('-');
                        sb.append("\n");
                        for(int i=0;i<M;i++)sb.append('-');
                        sb.append("\n");
                        for (int i = 0; i < N-2; i++) {
                            sb.append('+');
                            for (int j = 0; j < M-1; j++) {
                                if((i+j)%2==0)sb.append('-');
                                else sb.append('+');
                            }
                            sb.append("\n");
                        }
                    }else{
                        sb.append((M+N-2)+"\n");
                        for (int i = 0; i < 2*(M-2); i++) {
                            sb.append("++");
                            for (int j = 0; j < M-2; j++) {
                                d=(i-(M-3)*j+2000*(M-2))%(2*M-4); 
                                if(d<M-3)sb.append('-');
                                else sb.append('+');
                            }
                            sb.append("\n");
                        }
                        for (int i = 2*(M-2); i < N; i++) {
                            for (int j = 0; j < M; j++) {
                                if((i+j)%2==0)sb.append('-');
                                else sb.append('+');
                            }
                            sb.append("\n");
                        }
                    }
                }else{
                    //M,N are both even
                    if(M/2 > N-4){
                        sb.append(M+N-3).append("\n");
                        for (int i = 0; i < 3; i++) {
                            for (int j = 0; j < M; j++) {
                                sb.append('-');
                            }
                            sb.append("\n");
                        }
                        for (int i = 0; i < N-3; i++) {
                            for (int j = 0; j < 2*(N-3); j++) {
                                d=(j-(N-4)*i+2000*(N-3))%(2*N-6); 
                                if(d<N-4)sb.append('-');
                                else sb.append('+');
                            }
                            
                            for (int j = 2*(N-3); j < M; j++) {
                                if((i+j)%2==0)sb.append('-');
                                else sb.append('+');
                            }
                            sb.append("\n");
                        }
                    }else if(N/2 > M-4){
                        sb.append(M+N-3+"\n");
                        for (int i = 0; i < 2*(M-3); i++) {
                            sb.append("+++");
                            for (int j = 0; j < M-3; j++) {
                                d=(i-(M-4)*j+2000*(M-3))%(2*M-6); 
                                if(d<M-4)sb.append('-');
                                else sb.append('+');
                            }
                        }
                        for (int i = 2*(M-3); i < N; i++) {
                            sb.append("+++");
                            for (int j = 0; j < M; j++) {
                                if((i+j)%2==0)sb.append('-');
                                else sb.append('+');
                            }
                        }
                    }else{
                        sb.append((M+N-4)+"\n");
                        for(int i=0;i<M;i++)sb.append('-');
                        sb.append("\n");
                        for(int i=0;i<M;i++)sb.append('-');
                        sb.append("\n");
                        for (int i = 0; i < N-2; i++) {
                            sb.append("++");
                            for (int j = 0; j < M-2; j++) {
                                if((i+j)%2==0)sb.append('-');
                                else sb.append('+');
                            }
                            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 75 ms 8936 KB Output is correct
2 Incorrect 129 ms 9708 KB in the table A+B is not equal to 5
# 결과 실행 시간 메모리 Grader output
1 Incorrect 187 ms 10856 KB in the table A+B is not equal to 5
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 8936 KB Output is correct
2 Incorrect 129 ms 9708 KB in the table A+B is not equal to 5
# 결과 실행 시간 메모리 Grader output
1 Correct 253 ms 18144 KB Output is correct
2 Correct 203 ms 18224 KB Output is correct
3 Correct 203 ms 18716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 321 ms 21904 KB Output is correct
2 Correct 281 ms 20512 KB Output is correct
3 Correct 254 ms 19564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 8936 KB Output is correct
2 Incorrect 129 ms 9708 KB in the table A+B is not equal to 5