题解 | 明日DISCO
明日DISCO
https://www.nowcoder.com/practice/5f28e16c1c934fa9bfd78d80292e99d5?channelPut=tracker2
#include <bits/stdc++.h>
using namespace std;
using ll = long long ;
int main() {
int n;
cin >> n;
vector<vector<ll>>a(n + 10, vector<ll>(n + 10, 0));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> a[i][j];
}
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= n; j++) {
if (a[i][j] == 0) {
continue;
}
if (a[i - 1][j] >= 0 && a[i][j - 1] >= 0 && a[i + 1][j] >= 0 && a[i][j + 1] >= 0 &&
a[i][j] < 0) {
a[i][j] = 0;
}
if (a[i - 1][j] <= 0 && a[i][j - 1] <= 0 && a[i + 1][j] <= 0 && a[i][j + 1] <= 0 &&
a[i][j] > 0) {
a[i][j] = 0;
}
}
}
for(int i = 1; i<=n;i++){
for(int j = 1;j<=n;j++){
if(a[i][j]!=0){
cout<<"NO";
return 0;
}
}
}
cout<<"YES";
return 0;
}


