625 {
626 const unsigned int n = matrix.size();
627 for(int i = 0; i < n; i++) {
628 auto *const row = new bool[n + 1];
629 memset(row, 1, (n + 1) * sizeof(bool));
630 for(int j = 0; j < n; j++) {
631 if(!row[matrix[i][j]]) {
632 delete[] row;
633 return false;
634 }
635 row[matrix[i][j]] = false;
636 }
637 delete[] row;
638 }
639
640 for(int j = 0; j < n; j++) {
641 auto *const column = new bool[n + 1];
642 memset(column, 1, (n + 1) * sizeof(bool));
643 for(int i = 0; i < n; i++) {
644 if(!column[matrix[i][j]]) {
645 delete[] column;
646 return false;
647 }
648 column[matrix[i][j]] = false;
649 }
650 delete[] column;
651 }
652 return true;
653 }