Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.005 s | 3 KBi |
#2 |
Correcto
|
0.004 s | 1 KBi |
#3 |
Correcto
|
0.005 s | 1 KBi |
#4 |
Correcto
|
0.005 s | 1 KBi |
#5 |
Correcto
|
0.006 s | 1 KBi |
#6 |
Correcto
|
0.006 s | 2 KBi |
#7 |
Correcto
|
0.005 s | 1 KBi |
#8 |
Correcto
|
0.005 s | 1 KBi |
#9 |
Correcto
|
0.005 s | 1 KBi |
#10 |
Correcto
|
0.005 s | 1 KBi |
#11 |
Correcto
|
0.004 s | 1 KBi |
#12 |
Correcto
|
0.004 s | 1 KBi |
#13 |
Correcto
|
0.005 s | 1 KBi |
#14 |
Correcto
|
0.006 s | 4 KBi |
#15 |
Correcto
|
0.005 s | 1 KBi |
#16 |
Correcto
|
0.008 s | 1 KBi |
#17 |
Correcto
|
0.006 s | 1 KBi |
#18 |
Correcto
|
0.006 s | 1 KBi |
#19 |
Correcto
|
0.007 s | 1 KBi |
#20 |
Correcto
|
0.007 s | 1 KBi |
#include <iostream> #include <cassert> using namespace std; const int MAXN = 100; int matrix[MAXN][MAXN]; // Retorna true si la matriz es cuadrado mágico. bool is_magic_square(int n) { assert(n >= 2); int want = 0; for (int c = 0; c < n; c++) { want += matrix[0][c]; } // Revisar la suma de todas las filas. for (int r = 0; r < n; r++) { int sum = 0; // sum es la suma de la fila r for (int c = 0; c < n; c++) { sum += matrix[r][c]; } if (sum != want) { return false; } } // Revisar la suma de todas las columnas. for (int c = 0; c < n; c++) { int sum = 0; // sum es la suma de la columna c for (int r = 0; r < n; r++) { sum += matrix[r][c]; } if (sum != want) { return false; } } // Diagonal 1 int sum = 0; for (int i = 0; i < n; i++) { sum += matrix[i][i]; } if (sum != want) { return false; } // Diagonal 2 sum = 0; for (int i = 0; i < n; i++) { sum += matrix[i][n-1-i]; } if (sum != want) { return false; } return true; } int main() { int n; cin >> n; for (int r = 0; r < n; r++) { for (int c = 0; c < n; c++) { cin >> matrix[r][c]; } } if (is_magic_square(n)) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; }