Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.006 s | 7 KBi |
#2 |
Correcto
|
0.006 s | 2 KBi |
#3 |
Correcto
|
0.008 s | 1 KBi |
#4 |
Correcto
|
0.005 s | 17 KBi |
#5 |
Correcto
|
0.006 s | 2 KBi |
#6 |
Correcto
|
0.007 s | 2 KBi |
#7 |
Correcto
|
0.006 s | 1 KBi |
#8 |
Correcto
|
0.005 s | 1 KBi |
#9 |
Correcto
|
0.007 s | 30 KBi |
#10 |
Correcto
|
0.008 s | 1 KBi |
#11 |
Correcto
|
0.008 s | 1 KBi |
#12 |
Correcto
|
0.005 s | 1 KBi |
#13 |
Correcto
|
0.006 s | 7 KBi |
#14 |
Correcto
|
0.006 s | 2 KBi |
#15 |
Correcto
|
0.008 s | 1 KBi |
#16 |
Correcto
|
0.008 s | 1 KBi |
#17 |
Correcto
|
0.007 s | 16 KBi |
#18 |
Correcto
|
0.009 s | 17 KBi |
#19 |
Correcto
|
0.011 s | 17 KBi |
#20 |
Correcto
|
0.008 s | 4 KBi |
#include<iostream> #include<vector> using namespace std; pair<int,int> sumRowCol(vector<vector<int>> &matrix, int p){ int col =0, row = 0; for(int i=0;i<matrix.size();i++){ row+=matrix[p][i]; col+=matrix[i][p]; } return {col,row}; } pair<int,int> sumDiagonals(vector<vector<int>> &matrix){ int firstDiagonal = 0, secondDiagonal = 0; for(int i=0;i<matrix.size();i++){ firstDiagonal+=matrix[i][i]; secondDiagonal+=matrix[i][matrix.size()-1-i]; } return {firstDiagonal,secondDiagonal}; } int main(){ int n; cin>>n; vector<vector<int>> matrix; matrix.resize(n,vector<int>(n,0)); for(int i=0;i<n;i++){ for(int j=0; j<n;j++){ int val; cin>>val; matrix[i][j] = val; } } int target = 0; for(int i=0;i<matrix[0].size();i++){ target+=matrix[0][i]; } for(int i=0;i<n;i++){ pair<int,int> current = sumRowCol(matrix,i); if(current.first!=target || current.second!=target){ cout<<"No\n"; return 0; } } pair<int,int> diagonals = sumDiagonals(matrix); if(diagonals.first!=target || diagonals.second!=target){ cout<<"No\n"; } else{ cout<<"Yes\n"; } return 0; }