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>
#define loop(i, a, b) for(long long i=a;i<b;i++)
#define pool(i, a, b) for(long long i=a-1;i>=b;i--)
#define fore(i, a) for(auto&& i:a)
#define fi first
#define se second
#define ps(a) push_back(a)
#define pb(a) pop_back(a)
#define sc scanf
#define vc vector
#define pa pair<ll, ll>
#define ll long long
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define llmax LLONG_MAX/2
#define llmin -LLONG_MAX/2
using namespace std;
#define mn 200100
#define pa pair<ll, ll>
#define ld long double
ll l[mn], r[mn], t[mn], b[mn];
ll solve(){
ll n;cin >> n;
loop(i, 0, n){
cin >> l[i];
if(l[i]==-1) l[i]=n;
}
loop(i, 0, n){
cin >> r[i];
if(r[i]==-1) r[i]=n;
}
loop(i, 0, n){
cin >> t[i];
if(t[i]==-1) t[i]=n;
}
loop(i, 0, n){
cin >> b[i];
if(b[i]==-1) b[i]=n;
}
loop(i, 0, n) if(l[i]+r[i]>=n and l[i]!=n and r[i]!=n){return 0;}
loop(i, 0, n) if(t[i]+b[i]>=n and t[i]!=n and b[i]!=n){return 0;}
ll cur=n;
loop(i, 0, n) if(cur>l[i]){
loop(j, l[i], cur) if(t[j]<i){return 0;}
if(t[l[i]]!=i){return 0;}
cur=l[i];
}
swap(l, r);
reverse(t, t+n);
reverse(b, b+n);
cur=n;
loop(i, 0, n) if(cur>l[i]){
loop(j, l[i], cur) if(t[j]<i){return 0;}
if(t[l[i]]!=i){return 0;}
cur=l[i];
}
swap(t, b);
reverse(l, l+n);
reverse(r, r+n);
cur=n;
loop(i, 0, n) if(cur>l[i]){
loop(j, l[i], cur) if(t[j]<i){return 0;}
if(t[l[i]]!=i){return 0;}
cur=l[i];
}
swap(l, r);
reverse(t, t+n);
reverse(b, b+n);
cur=n;
loop(i, 0, n) if(cur>l[i]){
loop(j, l[i], cur) if(t[j]<i){return 0;}
if(t[l[i]]!=i){return 0;}
cur=l[i];
}
return 1;
}
int main(){
if(solve()){
cout << "DA"<<endl;
}
else cout << "NE"<<endl;
}
# | 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... |