답안 #332378

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
332378 2020-12-02T06:48:26 Z KWang31 Red-blue table (IZhO19_stones) Java 11
53 / 100
410 ms 23440 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(M==3){
                        sb.append(N+1+"\n");
                        for (int i = 0; i < N; i++) {
                            sb.append("++- \n");
                        }
                    }else 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==4){
                        sb.append(N+1+"\n");
                        for (int i = 0; i < N; i++) {
                            sb.append("+++- \n");
                        }
                    }else if(N==4){
                        sb.append(M+1+"\n");
                        for (int i = 0; i < 3; i++) {
                            for (int j = 0; j < M; j++) {
                                sb.append('-');
                            }
                            sb.append("\n");
                        }
                        for (int j = 0; j < M; j++) {
                            sb.append('+');
                        }
                    }else 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('-');
                            }
                            sb.append("\n");
                        }
                        for (int i = 2*(M-3); i < N; i++) {
                            sb.append("+++");
                            for (int j = 0; j < M-3; j++) {
                                if((i+j)%2==0)sb.append('-');
                                else sb.append('+');
                            }
                            sb.append("\n");
                        }
                    }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 77 ms 8808 KB Output is correct
2 Correct 113 ms 9680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 190 ms 10856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 8808 KB Output is correct
2 Correct 113 ms 9680 KB Output is correct
3 Correct 190 ms 10856 KB Output is correct
4 Incorrect 219 ms 10880 KB in the table A+B is not equal to 41
# 결과 실행 시간 메모리 Grader output
1 Correct 261 ms 18008 KB Output is correct
2 Correct 211 ms 18252 KB Output is correct
3 Correct 207 ms 18776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 410 ms 23440 KB Output is correct
2 Correct 287 ms 20484 KB Output is correct
3 Correct 274 ms 19676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 8808 KB Output is correct
2 Correct 113 ms 9680 KB Output is correct
3 Correct 190 ms 10856 KB Output is correct
4 Incorrect 219 ms 10880 KB in the table A+B is not equal to 41