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

Envío 4620

Problema 0xe1 - Cuadrado mágico

  • Autor: 7yrionLannister
  • Fecha: 2021-08-03 21:28:43 UTC (Hace más de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.08 s 11 KBi
#2
Correcto
0.079 s 12 KBi
#3
Correcto
0.079 s 12 KBi
#4
Correcto
0.089 s 10 KBi
#5
Correcto
0.086 s 12 KBi
#6
Correcto
0.096 s 13 KBi
#7
Correcto
0.099 s 12 KBi
#8
Correcto
0.082 s 12 KBi
#9
Correcto
0.094 s 11 KBi
#10
Correcto
0.092 s 12 KBi
#11
Correcto
0.08 s 12 KBi
#12
Correcto
0.081 s 12 KBi
#13
Correcto
0.098 s 11 KBi
#14
Correcto
0.095 s 13 KBi
#15
Correcto
0.108 s 12 KBi
#16
Correcto
0.157 s 15 KBi
#17
Correcto
0.125 s 14 KBi
#18
Correcto
0.128 s 14 KBi
#19
Correcto
0.153 s 14 KBi
#20
Correcto
0.087 s 12 KBi
Puntos totales: 100 / 100

Código

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        int N = Integer.parseInt(br.readLine());
        int SUM = 0;
        int[][] matrix = new int[N][N];
        String[] line = br.readLine().split(" ");
        int[] colSum = new int[N];
        for (int i = 0; i < N; i++) {
            int num = Integer.parseInt(line[i]);
            matrix[0][i] = num;
            colSum[i] = num;
            SUM += num;
        }
        boolean diff = false;
        int N1 = N - 1;
        int[] Dsum = new int[2];
        Dsum[0] += matrix[0][0];
        Dsum[1] += matrix[0][N1];
        for (int i = 1; i < N1 && !diff; i++) {
            line = br.readLine().split(" ");
            int rowSum = 0;
            for (int j = 0; j < N && !diff; j++) {
                int num = Integer.parseInt(line[j]);
                matrix[i][j] = num;
                rowSum += num;
                colSum[j] += num;
            }
            Dsum[0] += matrix[i][i];
            Dsum[1] += matrix[i][N1 - i];
            diff = (rowSum != SUM);
        }
        line = br.readLine().split(" ");
        int num1 = Integer.parseInt(line[0]);
        int rowSum = num1;
        matrix[N1][0] = num1;
        Dsum[1] += num1;
        diff |= (Dsum[1] != SUM);
        colSum[0] += num1;
        for (int j = 1; j < N && !diff; j++) {
            int num = Integer.parseInt(line[j]);
            matrix[N1][j] = num;
            rowSum += num;
            colSum[j] += num;
            diff = (colSum[j] != colSum[j - 1]);
        }
        Dsum[0] += matrix[N1][N1];
        diff |= (rowSum != SUM || Dsum[0] != SUM);
        bw.write((diff ? "No" : "Yes") + "\n");
        bw.close();
        br.close();
    }
}