Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.135 s | 13 KBi |
#2 |
Correcto
|
0.144 s | 13 KBi |
#3 |
Correcto
|
0.134 s | 13 KBi |
#4 |
Correcto
|
0.132 s | 13 KBi |
#5 |
Correcto
|
0.144 s | 13 KBi |
#6 |
Correcto
|
0.119 s | 13 KBi |
#7 |
Correcto
|
0.14 s | 13 KBi |
#8 |
Correcto
|
0.15 s | 13 KBi |
#9 |
Correcto
|
0.14 s | 13 KBi |
#10 |
Correcto
|
0.132 s | 13 KBi |
#11 |
Correcto
|
0.152 s | 13 KBi |
#12 |
Correcto
|
0.133 s | 13 KBi |
#13 |
Correcto
|
0.118 s | 13 KBi |
#14 |
Correcto
|
0.151 s | 13 KBi |
#15 |
Correcto
|
0.151 s | 13 KBi |
#16 |
Correcto
|
0.346 s | 26 KBi |
#17 |
Correcto
|
0.296 s | 25 KBi |
#18 |
Correcto
|
0.275 s | 25 KBi |
#19 |
Correcto
|
0.389 s | 26 KBi |
#20 |
Correcto
|
0.386 s | 25 KBi |
import java.util.Scanner; public class Main { public boolean isMagic(int n, int[][] matrix) { int want = 0; for ( int r = 0; r < n; r++ ) { want += matrix[0][r]; } // ROW for ( int r = 0; r < n; r++) { int sum = 0; for (int c = 0; c < n; c++) { sum += matrix[r][c]; } if (sum != want) { return false; } } // COLUMN for (int c = 0; c < n; c++) { int sum = 0; for (int r = 0; r < n; r++) { sum += matrix[r][c]; } if (sum != want) { return false; } } int sum = 0; for (int i = 0; i < n; i++) { sum += matrix[i][i]; } if (sum != want) { return false; } sum = 0; for (int i = 0; i < n; i++) { sum += matrix[i][n-1-i]; } if (sum != want) { return false; } return true; } public static void main(String[] args) { final int MAXN = 100; int[][] matrix = new int[MAXN][MAXN]; Scanner in = new Scanner(System.in); int n = in.nextInt(); for ( int r = 0; r < n; r++) { for ( int c = 0; c < n; c++) { matrix[r][c] = in.nextInt(); } } Main solve = new Main(); boolean isMagic = solve.isMagic(n, matrix); if (isMagic == true) { System.out.println("Yes"); } else { System.out.println("No"); } } }