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;
int const N = 1e5 + 5;
int l[N], r[N], top[N], bottom[N];
set<int> x[N], y[N];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for(int i = 1; i <= n; i++){
cin >> l[i];
if(l[i] >= 0){
x[i].insert(l[i] + 1);
y[l[i] + 1].insert(i);
}
}
for(int i = 1; i <= n; i++){
cin >> r[i];
if(r[i] >= 0){
x[i].insert(n - r[i]);
y[n - r[i]].insert(i);
}
}
for(int i = 1; i <= n; i++){
cin >> top[i];
if(top[i] >= 0){
x[top[i] + 1].insert(i);
y[i].insert(top[i] + 1);
}
}
for(int i = 1; i <= n; i++){
cin >> bottom[i];
if(bottom[i] >= 0){
x[n - bottom[i]].insert(i);
y[i].insert(n - bottom[i]);
}
}
bool can = 1;
for(int i = 1; i <= n; i++){
if(l[i] == -1 && !x[i].empty())
can = 0;
if(r[i] == -1 && !x[i].empty())
can = 0;
if(top[i] == -1 && !y[i].empty())
can = 0;
if(bottom[i]== -1 && !y[i].empty())
can = 0;
if(!can)
break;
if((l[i] >= 0 && *x[i].begin() != l[i] + 1) || (r[i] >= 0 && *prev(x[i].end()) != n - r[i]) || (top[i] >= 0 && *y[i].begin() != top[i] + 1) || (bottom[i] >= 0 && *prev(y[i].end()) != n - bottom[i])){
can = 0;
break;
}
}
if(can){
cout << "DA\n";
}else{
cout << "NE\n";
}
}
# | 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... |