#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))
template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }
void bad(){
cout << "NE" << endl;
exit(0);
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
//freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
int n;
cin >> n;
vi l(n), r(n), u(n), d(n);
rep(i, n) cin >> l[i];
rep(i, n) cin >> r[i];
rep(i, n) cin >> u[i];
rep(i, n) cin >> d[i];
vector<pi> c(n);
rep(i, n) c[i] = mp(1e9, 0);
//so first work with l and r
rep(i, n){
if(l[i] == -1 && r[i] != -1) bad();
if((l[i] + 1 + r[i]) > n) bad();
if(l[i] != -1 && r[i] != -1){
c[l[i]].fi = min(c[l[i]].fi, i);
c[l[i]].se = max(c[l[i]].se, i);
c[n - r[i] - 1].fi = min(c[n - r[i] - 1].fi, i);
c[n - r[i] - 1].se = max(c[n - r[i] - 1].se, i);
}
}
rep(i, n){
if(u[i] == -1 && d[i] != -1) bad();
if((u[i] + 1 + d[i]) > n) bad();
if(u[i] != -1 && d[i] != -1){
if(c[i].fi < u[i]) bad();
if(c[i].se > (n - d[i] - 1)) bad();
}
}
cout << "DA" << endl;
return 0;
}
/*
Things to look out for:
- Integer overflows
- Array bounds
- Special cases
Be careful!
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
3064 KB |
Output is correct |
2 |
Correct |
47 ms |
3068 KB |
Output is correct |
3 |
Correct |
44 ms |
3192 KB |
Output is correct |
4 |
Correct |
35 ms |
3192 KB |
Output is correct |
5 |
Correct |
47 ms |
3192 KB |
Output is correct |
6 |
Correct |
47 ms |
3320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
2812 KB |
Output is correct |
2 |
Correct |
33 ms |
3064 KB |
Output is correct |
3 |
Correct |
45 ms |
3064 KB |
Output is correct |
4 |
Correct |
36 ms |
3192 KB |
Output is correct |
5 |
Correct |
45 ms |
3192 KB |
Output is correct |
6 |
Correct |
42 ms |
3192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
3064 KB |
Output is correct |
2 |
Correct |
32 ms |
3064 KB |
Output is correct |
3 |
Correct |
46 ms |
3064 KB |
Output is correct |
4 |
Correct |
47 ms |
3192 KB |
Output is correct |
5 |
Correct |
43 ms |
3192 KB |
Output is correct |
6 |
Correct |
34 ms |
3192 KB |
Output is correct |