//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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
504 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
444 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
169 ms |
8372 KB |
Output is correct |
2 |
Correct |
78 ms |
4492 KB |
Output is correct |
3 |
Correct |
86 ms |
4536 KB |
Output is correct |
4 |
Correct |
74 ms |
5672 KB |
Output is correct |
5 |
Correct |
78 ms |
4548 KB |
Output is correct |
6 |
Correct |
87 ms |
4564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
243 ms |
10676 KB |
Output is correct |
2 |
Correct |
86 ms |
5696 KB |
Output is correct |
3 |
Correct |
79 ms |
4560 KB |
Output is correct |
4 |
Correct |
209 ms |
9536 KB |
Output is correct |
5 |
Correct |
78 ms |
4556 KB |
Output is correct |
6 |
Correct |
241 ms |
10420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
170 ms |
8540 KB |
Output is correct |
2 |
Correct |
70 ms |
5680 KB |
Output is correct |
3 |
Correct |
79 ms |
4660 KB |
Output is correct |
4 |
Correct |
79 ms |
4560 KB |
Output is correct |
5 |
Correct |
82 ms |
4536 KB |
Output is correct |
6 |
Correct |
79 ms |
5812 KB |
Output is correct |