Submission #332371

# Submission time Handle Problem Language Result Execution time Memory
332371 2020-12-02T06:37:31 Z KWang31 Red-blue table (IZhO19_stones) Java 11
11 / 100
304 ms 22568 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==4){
                        for (int i = 0; i < N; i++) {
                            sb.append("+++- \n");
                        }
                    }else if(N==4){
                        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('+');
                            }
                        }
                        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!
# Verdict Execution time Memory Grader output
1 Correct 76 ms 8668 KB Output is correct
2 Incorrect 109 ms 9580 KB Expected integer, but "+++-" found
# Verdict Execution time Memory Grader output
1 Incorrect 189 ms 10844 KB in the table A+B is not equal to 5
# Verdict Execution time Memory Grader output
1 Correct 76 ms 8668 KB Output is correct
2 Incorrect 109 ms 9580 KB Expected integer, but "+++-" found
# Verdict Execution time Memory Grader output
1 Correct 255 ms 18296 KB Output is correct
2 Correct 217 ms 18432 KB Output is correct
3 Correct 203 ms 19108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 304 ms 22568 KB Expected integer, but "+++-" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 76 ms 8668 KB Output is correct
2 Incorrect 109 ms 9580 KB Expected integer, but "+++-" found