This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//we all are lost trying to be someone
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
#define sz(x) ll(x.size())
#define all(x) x.begin(),x.end()
#define pb push_back
#define ff first
#define ss second
using namespace std;
typedef unsigned long long ll;
const ll MAX=1000000;
const int inf=1e7;
vector<int> A[5];
int n;
set<int> comodin;
bool check(){
comodin.clear();
vector<int>U=A[2];
vector<int>L=A[0];
vector<pair<int,int>> first;
for(int i=0; i<n; i++){
first.pb({L[i],i});
}
sort(all(first));
/*
for(auto it:first){
cout<<'('<<it.ff<<','<<it.ss<<')'<<' ';
}
cout<<'\n';
*/
int j=0;
for(int i=0; i<n; i++){
int primer = inf;
while(j<n and first[j].ff<=i){
primer = min(primer, first[j].ss);
comodin.insert(first[j].ss);
j++;
}
if(primer>U[i]){
if(!comodin.count(U[i])) return false;
}
else if(primer < U[i]) return false;
}
return true;
}
void turnleft(){
vector<int> x=A[0];
vector<int> y=A[1];
A[0]=A[2];
reverse(all(A[0]));
A[1]=A[3];
reverse(all(A[1]));
A[2]=y;
A[3]=x;
/*
for(int i=0; i<4; i++){
for(int j=0; j<n; j++){
cout<<A[i][j]<<' ';
}
cout<<'\n';
}
*/
return;
}
bool die(){
for(int i=0; i<n; i++){
if(A[0][i]==inf and A[1][i]==inf) continue;
if(A[0][i]+A[1][i]>=n)return false;
}
for(int i=0; i<n; i++){
if(A[2][i]==inf and A[3][i]==inf) continue;
if(A[2][i]+A[3][i]>=n)return false;
}
return true;
}
void solve(){
int a;
cin>>n;
for(int i=0; i<4; i++){
for(int j=0; j<n; j++){
cin>>a;
if(a == -1) a=inf;
A[i].pb(a);
}
}
if(!die()){
cout<<"NE"<<'\n';
return;
}
for(int i=0; i<4; i++){
if(!check()){
cout<<"NE"<<'\n';
return;
}
turnleft();
}
cout<<"DA"<<'\n';
return;
}
int main(){
solve();
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... |