fork download
  1. import java.util.*;
  2. import java.io.*;
  3. import java.math.*;
  4.  
  5. class Solver {
  6. public static void main(String args[]) throws IOException{
  7. new Solver().run();
  8. }
  9.  
  10.  
  11. int nextInt() throws IOException{
  12. in.nextToken();
  13. return (int)in.nval;
  14. }
  15. void run() throws IOException{
  16. out = new PrintWriter(new OutputStreamWriter(System.out));
  17. solve();
  18. out.flush();
  19. }
  20. void solve() throws IOException{
  21. int n = nextInt();
  22. int[][] G = new int[n][n];
  23. if(n == 4)
  24. out.println("-1");
  25. else{
  26. for(int i = 0; i < n; i++)
  27. G[i][(i+1)%n] = 1;
  28. for(int y = 0; y < n; y++){
  29. for(int x = 0; x < n; x++){
  30. if(G[y][x] + G[x][y] == 0 && x != y){
  31. if(y % 2 == x % 2) G[y][x] = 1;
  32. else G[x][y] = 1;
  33. }
  34. }
  35. }
  36. for(int y = 0; y < n; y++){
  37. for(int x = 0; x < n-1; x++){
  38. out.print(G[y][x]);
  39. out.print(" ");
  40. }
  41. out.println(G[y][n-1]);
  42. }
  43. }
  44. }
  45. }
Success #stdin #stdout 0.1s 320512KB
stdin
5
stdout
0 1 1 0 0
0 0 1 1 0
0 0 0 1 1
1 0 0 0 1
1 1 0 0 0