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

Envío 5023

Problema 0xe1 - Cuadrado mágico

  • Autor: cams2692
  • Fecha: 2021-10-06 21:04:47 UTC (Hace alrededor de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.005 s 4 KBi
#2
Correcto
0.012 s 5 KBi
#3
Correcto
0.005 s 4 KBi
#4
Correcto
0.008 s 3 KBi
#5
Correcto
0.003 s 3 KBi
#6
Correcto
0.006 s 5 KBi
#7
Correcto
0.006 s 9 KBi
#8
Correcto
0.006 s 6 KBi
#9
Correcto
0.009 s 6 KBi
#10
Correcto
0.006 s 6 KBi
#11
Correcto
0.005 s 6 KBi
#12
Correcto
0.014 s 7 KBi
#13
Correcto
0.005 s 5 KBi
#14
Correcto
0.011 s 5 KBi
#15
Correcto
0.005 s 3 KBi
#16
Correcto
0.006 s 4 KBi
#17
Correcto
0.005 s 4 KBi
#18
Correcto
0.006 s 4 KBi
#19
Correcto
0.006 s 4 KBi
#20
Correcto
0.003 s 3 KBi
Puntos totales: 100 / 100

Código

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	n, _ := reader.ReadString('\n')
	n = strings.ReplaceAll(n, "\n", "")
	nInt, _ := strconv.ParseInt(n, 10, 64)
	var diagonal1 int64 = 0
	var diagonal2 int64 = 0
	var sumValue int64 = 0
	isInit := true
	for i := 0; i < int(nInt); i++ {
		row, _ := reader.ReadString('\n')
		row = strings.ReplaceAll(row, "\n", "")
		rowSplits := strings.Split(row, " ")
		var rowSum int64 = 0
		for index, v := range rowSplits {
			vInt, _ := strconv.ParseInt(v, 10, 64)

			if index == i {
				diagonal1 += vInt
			}
			if int(nInt-1)-i == index {
				diagonal2 += vInt
			}
			rowSum += vInt

		}
		if isInit {
			sumValue = rowSum
			isInit = false
		}

		if sumValue != rowSum {
			fmt.Println("No")
			return
		}

	}

	if sumValue != diagonal1 || sumValue != diagonal2 {

		fmt.Println("No")
		return
	}

	fmt.Println("Yes")

}