This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#ifdef MIKU
#define debug(x...) cout << '[' << #x << "] : ", dout(x)
void dout() { cout << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif
#define int long long
#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
typedef pair<int, int> pii;
const int MXN = 100005;
int n, l[MXN], r[MXN], u[MXN], d[MXN];
set<int> SH[MXN], SV[MXN];
void PUT(int x, int y) {
SH[x].insert(y);
SV[y].insert(x);
}
bool miku() {
cin >> n;
FOR(i, 1, n + 1) cin >> l[i];
FOR(i, 1, n + 1) cin >> r[i];
FOR(i, 1, n + 1) cin >> u[i];
FOR(i, 1, n + 1) cin >> d[i];
FOR(i, 1, n + 1) {
if (l[i] == -1 && r[i] == -1) continue;
if (l[i] == -1 || r[i] == -1) return false;
PUT(i, l[i] + 1);
PUT(i, n - r[i]);
}
FOR(i, 1, n + 1) {
if (u[i] == -1 && d[i] == -1) continue;
if (u[i] == -1 || d[i] == -1) return false;
PUT(u[i] + 1, i);
PUT(n - d[i], i);
}
FOR(i, 1, n + 1) {
if (l[i] == -1) {
if (SH[i].size()) return false;
continue;
}
if (*SH[i].begin() != l[i] + 1) return false;
if (*SH[i].rbegin() != n - r[i]) return false;
}
FOR(i, 1, n + 1) {
if (u[i] == -1) {
if (SV[i].size()) return false;
continue;
}
if (*SV[i].begin() != u[i] + 1) return false;
if (*SV[i].rbegin() != n - d[i]) return false;
}
return true;
}
int32_t main() {
cin.tie(0) -> sync_with_stdio(false);
cin.exceptions(iostream::failbit);
cout << (miku() ? "DA" : "NE") << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |