Guest User

Untitled

a guest
Oct 14th, 2019
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.68 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. import java.text.*;
  4. public class Main{
  5.     //SOLUTION BEGIN
  6.     //Into the Hardware Mode
  7.     void pre() throws Exception{}
  8.     void solve(int TC)throws Exception{
  9.         int n = ni();
  10.         if(n%2 == 0)pn("NO");
  11.         else{
  12.             pn("YES");
  13.             boolean[][] win = new boolean[n][n];
  14.             for(int i = 0; i< n; i++)
  15.                 for(int j = i+1; j< i+1+(n-1)/2; j++)
  16.                     win[i][j%n] = true;
  17.             for(int i = 0; i< n; i++)
  18.                 for(int j = i+1; j< n; j++)
  19.                     hold(win[i][j] != win[j][i]);
  20.             for(int i = 0; i< n; i++){
  21.                 for(int j = 0; j< n; j++)p(win[i][j]?1:0);pn("");
  22.             }
  23.         }
  24.     }
  25.     //SOLUTION END
  26.     void hold(boolean b)throws Exception{if(!b)throw new Exception("Hold right there, Sparky!");}
  27.     void exit(boolean b){if(!b)System.exit(0);}
  28.     long IINF = (long)1e18, mod = (long)1e9+7;
  29.     final int INF = (int)1e9, MX = (int)2e6+5;
  30.     DecimalFormat df = new DecimalFormat("0.0000000");
  31.     double PI = 3.141592653589793238462643383279502884197169399, eps = 1e-7;
  32.     static boolean multipleTC = true, memory = false, fileIO = false;
  33.     FastReader in;PrintWriter out;
  34.     void run() throws Exception{
  35.         if(fileIO){
  36.             in = new FastReader("C:/users/user/desktop/inp.in");
  37.             out = new PrintWriter("C:/users/user/desktop/out.out");
  38.         }else {
  39.             in = new FastReader();
  40.             out = new PrintWriter(System.out);
  41.         }
  42.         //Solution Credits: Taranpreet Singh
  43.         int T = (multipleTC)?ni():1;
  44.         pre();
  45.         for(int t = 1; t<= T; t++)solve(t);
  46.         out.flush();
  47.         out.close();
  48.     }
  49.     public static void main(String[] args) throws Exception{
  50.         if(memory)new Thread(null, new Runnable() {public void run(){try{new Main().run();}catch(Exception e){e.printStackTrace();}}}, "1", 1 << 28).start();
  51.         else new Main().run();
  52.     }
  53.     int find(int[] set, int u){return set[u] = (set[u] == u?u:find(set, set[u]));}
  54.     int digit(long s){int ans = 0;while(s>0){s/=10;ans++;}return ans;}
  55.     long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
  56.     int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
  57.     int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}
  58.     void p(Object o){out.print(o);}
  59.     void pn(Object o){out.println(o);}
  60.     void pni(Object o){out.println(o);out.flush();}
  61.     String n()throws Exception{return in.next();}
  62.     String nln()throws Exception{return in.nextLine();}
  63.     int ni()throws Exception{return Integer.parseInt(in.next());}
  64.     long nl()throws Exception{return Long.parseLong(in.next());}
  65.     double nd()throws Exception{return Double.parseDouble(in.next());}
  66.  
  67.     class FastReader{
  68.         BufferedReader br;
  69.         StringTokenizer st;
  70.         public FastReader(){
  71.             br = new BufferedReader(new InputStreamReader(System.in));
  72.         }
  73.  
  74.         public FastReader(String s) throws Exception{
  75.             br = new BufferedReader(new FileReader(s));
  76.         }
  77.  
  78.         String next() throws Exception{
  79.             while (st == null || !st.hasMoreElements()){
  80.                 try{
  81.                     st = new StringTokenizer(br.readLine());
  82.                 }catch (IOException  e){
  83.                     throw new Exception(e.toString());
  84.                 }
  85.             }
  86.             return st.nextToken();
  87.         }
  88.  
  89.         String nextLine() throws Exception{
  90.             String str = "";
  91.             try{  
  92.                 str = br.readLine();
  93.             }catch (IOException e){
  94.                 throw new Exception(e.toString());
  95.             }  
  96.             return str;
  97.         }
  98.     }  
  99. }
Add Comment
Please, Sign In to add comment