Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.086 s | 16 KBi |
#2 |
Correcto
|
0.086 s | 17 KBi |
#3 |
Correcto
|
0.083 s | 16 KBi |
#4 |
Correcto
|
0.102 s | 13 KBi |
#5 |
Correcto
|
0.107 s | 13 KBi |
#6 |
Correcto
|
0.079 s | 16 KBi |
#7 |
Correcto
|
0.107 s | 13 KBi |
#8 |
Correcto
|
0.082 s | 16 KBi |
#9 |
Correcto
|
0.084 s | 13 KBi |
#10 |
Correcto
|
0.077 s | 16 KBi |
#11 |
Correcto
|
0.087 s | 13 KBi |
#12 |
Correcto
|
0.083 s | 13 KBi |
#13 |
Correcto
|
0.077 s | 16 KBi |
#14 |
Correcto
|
0.094 s | 16 KBi |
#15 |
Correcto
|
0.085 s | 16 KBi |
#16 |
Correcto
|
0.244 s | 25 KBi |
#17 |
Correcto
|
0.267 s | 35 KBi |
#18 |
Correcto
|
0.177 s | 24 KBi |
#19 |
Correcto
|
0.178 s | 24 KBi |
#20 |
Correcto
|
0.226 s | 33 KBi |
import java.util.*; public class Main { public static void main(String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int [][] m = new int [n][n]; for(int i =0; i<n; i++){ for(int j =0; j<n; j++){ m[i][j]= sc.nextInt(); } } System.out.println(isMagicSquare(m)); } public static String isMagicSquare(int [][] m){ int lastRow=0; int row=0; int col=0; int lastColumn=0; int upperDiag = 0; int lowerDiag = 0; for(int i =0, z=m.length-1; i<m.length; i++,z--){ if((row!=lastRow && i>1) || (col!=lastColumn && i>1)) return "No"; lastRow = row; row=0; lastColumn = col; col=0; upperDiag+=m[i][i]; lowerDiag += m[i][z]; for(int j =0; j<m.length; j++){ row += m[i][j]; col += m[j][i]; } } return col==row && col==upperDiag && col==lowerDiag ? "Yes": "No"; } }