Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.098 s | 16 KBi |
#2 |
Correcto
|
0.08 s | 16 KBi |
#3 |
Correcto
|
0.098 s | 16 KBi |
#4 |
Correcto
|
0.079 s | 16 KBi |
#5 |
Correcto
|
0.098 s | 17 KBi |
#6 |
Correcto
|
0.09 s | 16 KBi |
#7 |
Correcto
|
0.101 s | 16 KBi |
#8 |
Correcto
|
0.1 s | 17 KBi |
#9 |
Correcto
|
0.082 s | 16 KBi |
#10 |
Correcto
|
0.094 s | 16 KBi |
#11 |
Correcto
|
0.096 s | 16 KBi |
#12 |
Correcto
|
0.093 s | 16 KBi |
#13 |
Correcto
|
0.09 s | 16 KBi |
#14 |
Correcto
|
0.088 s | 16 KBi |
#15 |
Correcto
|
0.117 s | 17 KBi |
#16 |
Correcto
|
0.3 s | 36 KBi |
#17 |
Correcto
|
0.272 s | 35 KBi |
#18 |
Correcto
|
0.25 s | 31 KBi |
#19 |
Correcto
|
0.297 s | 35 KBi |
#20 |
Correcto
|
0.302 s | 35 KBi |
import java.util.HashMap; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int[][] matrix = new int[n][n]; HashMap <Integer, Integer> rows = new HashMap<>(); HashMap <Integer, Integer> columns = new HashMap<>(); int diagonalLefRight = 0; int diagonalRightLeft = 0; int magicNumber = 0; boolean flag = true; int lastIndex = n-1; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if(!rows.containsKey(i)){ rows.put(i, 0); } if(!columns.containsKey(j)){ columns.put(j, 0); } int x = scanner.nextInt(); rows.put(i, rows.get(i) + x); columns.put(j, columns.get(j) + x); if(i == 0 && j == lastIndex){ magicNumber = rows.get(i); } if(j == lastIndex){ int count = rows.get(i); if(count != magicNumber){ flag = false; } } if(i == lastIndex){ int count = columns.get(j); if(count != magicNumber){ flag = false; } } if(i == j){ diagonalLefRight += x; } if(j+i == n-1){ diagonalRightLeft +=x; } } } if (magicNumber != diagonalLefRight || magicNumber != diagonalRightLeft){ flag = false; } if(flag){ System.out.println("Yes"); } else { System.out.println("No"); } } }