#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define rep(X, a,b) for(int X=a;X<b;++X)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) (int)(a).size()
#define NL "\n"
using namespace std;
typedef pair<long long,long long> pll;
typedef pair<int,int> pii;
typedef long long ll;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << "," << p.second << ')'; }
template<typename A> ostream& operator<<(ostream &os, const vector<A> &p){
for(const auto &a:p)
os << a << " ";
os << "\n";
return os;
}
int val[100010][4];
int col[100010][2];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
rep(k,0,4) rep(i,0,n) cin>>val[i][k];
memset(&col[0][0], -1, sizeof(col));
rep(i,0,n){
if(val[i][0]==-1 && val[i][1]==-1) continue;
if((val[i][0]==-1 && val[i][1]!=-1) || (val[i][0]!=-1 && val[i][1]==-1)){
cout<<"NE\n";
return 0;
}
if(val[i][0]+val[i][1]<n){
if(col[val[i][0]][0]==-1) col[val[i][0]][0]=i, col[val[i][0]][1]=i;
else col[val[i][0]][1]=i;
if(col[n-1-val[i][1]][0]==-1) col[n-1-val[i][1]][0]=i, col[n-1-val[i][1]][1]=i;
else col[n-1-val[i][1]][1]=i;
}//fix
else{
cout<<"NE\n";
return 0;
}
}
rep(i,0,n){
if(val[i][2]==-1 && val[i][3]==-1){
if(col[i][0]==-1) continue;
else{
cout<<"NE\n";
return 0;
}
}
if((val[i][2]==-1 && val[i][3]!=-1) || (val[i][2]!=-1 && val[i][3]==-1)){
cout<<"NE\n";
return 0;
}
if(col[i][0]==-1){
cout<<"NE\n";
return 0;
}
if(val[i][2]+val[i][3]>=n-(col[i][1]-col[i][0])){
cout<<"NE\n";
return 0;
}
}
memset(&col[0][0], -1, sizeof(col));
rep(i,0,n){
if(val[i][2]==-1 && val[i][3]==-1) continue;
if((val[i][2]==-1 && val[i][3]!=-1) || (val[i][2]!=-1 && val[i][3]==-1)){
cout<<"NE\n";
return 0;
}
if(val[i][2]+val[i][3]<n){
if(col[val[i][2]][0]==-1) col[val[i][2]][0]=i, col[val[i][2]][1]=i;
else col[val[i][2]][1]=i;
if(col[n-1-val[i][3]][0]==-1) col[n-1-val[i][3]][0]=i, col[n-1-val[i][3]][1]=i;
else col[n-1-val[i][3]][1]=i;
}//fix
else{
cout<<"NE\n";
return 0;
}
}
rep(i,0,n){
if(val[i][0]==-1 && val[i][1]==-1){
if(col[i][0]==-1) continue;
else{
cout<<"NE\n";
return 0;
}
}
if((val[i][0]==-1 && val[i][1]!=-1) || (val[i][0]!=-1 && val[i][1]==-1)){
cout<<"NE\n";
return 0;
}
if(col[i][0]==-1){
cout<<"NE\n";
return 0;
}
if(val[i][0]+val[i][1]>=n-(col[i][1]-col[i][0])){
// cout<<val[i][0]+val[i][1]<<" "<<col[i][1]-col[i][0]<<" "<<i<<NL;
cout<<"NE\n";
return 0;
}
}
cout<<"DA\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1108 KB |
Output is correct |
2 |
Correct |
1 ms |
1108 KB |
Output is correct |
3 |
Correct |
2 ms |
1108 KB |
Output is correct |
4 |
Correct |
1 ms |
1108 KB |
Output is correct |
5 |
Correct |
1 ms |
1108 KB |
Output is correct |
6 |
Correct |
1 ms |
1108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1108 KB |
Output is correct |
2 |
Incorrect |
1 ms |
1108 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
29 ms |
2636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
29 ms |
2660 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
30 ms |
2656 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |