█████████ ████ ███░░░░░███ ░░███ ███ ░░░ ██████ ███████ ██████ ██████ ░███ ███░░███ ███░░███ ███░░███ ███░░███ ░███ ░███ ░███░███ ░███ ░███████ ░███ ░███ ░░███ ███░███ ░███░███ ░███ ░███░░░ ░███ ░███ ░░█████████ ░░██████ ░░████████░░██████ ░░██████ ░░░░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░░

Envío 6400

Problema 0xe1 - Cuadrado mágico

  • Autor: Camilo15
  • Fecha: 2022-07-04 18:30:42 UTC (Hace casi 2 años)
Caso # Resultado Tiempo Memoria
#1
Incorrecto
0.086 s 16 KBi
#2
Incorrecto
0.075 s 16 KBi
#3
Incorrecto
0.085 s 16 KBi
#4
Incorrecto
0.108 s 13 KBi
#5
Incorrecto
0.078 s 16 KBi
#6
Incorrecto
0.09 s 16 KBi
#7
Incorrecto
0.099 s 13 KBi
#8
Incorrecto
0.081 s 16 KBi
#9
Incorrecto
0.094 s 13 KBi
#10
Incorrecto
0.078 s 16 KBi
#11
Incorrecto
0.081 s 16 KBi
#12
Incorrecto
0.088 s 16 KBi
#13
Incorrecto
0.078 s 16 KBi
#14
Incorrecto
0.108 s 13 KBi
#15
Incorrecto
0.112 s 13 KBi
#16
Incorrecto
0.229 s 24 KBi
#17
Incorrecto
0.258 s 33 KBi
#18
Incorrecto
0.249 s 25 KBi
#19
Incorrecto
0.225 s 25 KBi
#20
Incorrecto
0.233 s 24 KBi
Puntos totales: 0 / 100

Código

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";
		}
  
}