我也我不知道我到底写了些什么(′д` )…彡…彡反正很暴力
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 1000;
int T;//T组用例
int main () {
cin >> T;
for (int k = 1;k <= T;k++) {
int n;
cin >> n;
int map[N][N];
int square = n * n;
int t = 1,m = 1;
int cell[N],col[N];
for (int i = 1;i <= square;i++)
for (int j = 1;j <= square;j++)
cin >> map[i][j];
for (int i = 1;i <= square;i++) {
memset(col,0,sizeof(int) * (square + 5));
for (int j = 1;j <= square;j++) {
if (col[map[i][j]] == 1 || map[i][j] <= 0 || map[i][j] > square) {
cout << "Case #" << k << ": " << "No" << endl;
goto mark;
}
col[map[i][j]]++;
}
}
for (int j = 1;j <= square;j++) {
memset(col,0,sizeof(int) * (square + 5));
for (int i = 1;i <= square;i++) {
if (col[map[i][j]] == 1 || map[i][j] <= 0 || map[i][j] > square) {
cout << "Case #" << k << ": " << "No" << endl;
goto mark;
}
col[map[i][j]]++;
}
}
//
memset(cell,0,sizeof(int) * (square + 5));
while (t <= square - n + 1) {
for (int i = t;i < t + n;i++) {
for (int j = m;j < m + n;j++) {
if (cell[map[i][j]] == 1) {
cout << "Case #" << k << ": " << "No" << endl;
goto mark;
}
cell[map[i][j]]++;
}
}
if (m == square - n + 1) {
t += n;
m = 1;
} else {
m += n;
}
memset(cell,0,sizeof(int) * (square + 5));
}
cout << "Case #" << k << ": " << "Yes" << endl;
mark: ;
}
return 0;
}