Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.107 s | 13 KBi |
#2 |
Correcto
|
0.086 s | 16 KBi |
#3 |
Correcto
|
0.085 s | 16 KBi |
#4 |
Correcto
|
0.082 s | 16 KBi |
#5 |
Correcto
|
0.089 s | 13 KBi |
#6 |
Correcto
|
0.09 s | 16 KBi |
#7 |
Correcto
|
0.083 s | 16 KBi |
#8 |
Correcto
|
0.111 s | 13 KBi |
#9 |
Incorrecto
|
0.082 s | 16 KBi |
#10 |
Incorrecto
|
0.082 s | 16 KBi |
#11 |
Correcto
|
0.082 s | 16 KBi |
#12 |
Correcto
|
0.083 s | 16 KBi |
#13 |
Correcto
|
0.084 s | 16 KBi |
#14 |
Correcto
|
0.118 s | 13 KBi |
#15 |
Correcto
|
0.097 s | 16 KBi |
#16 |
Correcto
|
0.23 s | 25 KBi |
#17 |
Correcto
|
0.239 s | 24 KBi |
#18 |
Correcto
|
0.27 s | 25 KBi |
#19 |
Correcto
|
0.221 s | 25 KBi |
#20 |
Incorrecto
|
0.258 s | 25 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"; } }