This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
 * author: NotLinux
 * created: 03.09.2022 ~ 14:26:36
**/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#ifdef LOCAL
    #include "/home/notlinux/debug.h"
#else
    #define debug(x...) void(37)
#endif
int n;
const int inf = -(1e9 + 7);
int md(int v , int e){
    int ss = v+e;
    if(ss < 0)ss += (n+1);
    else if(ss >= (n+1))ss-=(n+1);
    return ss;
}
void solve(){
    cin >> n;
    vector < vector < int > > sq(4 , vector < int > (n));
    for(auto &inp : sq[0])cin >> inp;
    for(auto &inp : sq[2])cin >> inp;
    for(auto &inp : sq[1])cin >> inp;
    for(auto &inp : sq[3])cin >> inp;
    for(int i = 0;i<4;i++){
        for(int j = 0;j<n;j++){
            if(sq[i][j] == -1)sq[i][j] = inf;
            int me = sq[i][j];
            int other = sq[md(i,2)][j];
            debug(i,j);
            debug(me,other);
            if((me + other) >= n){
                cout << "NE" << endl;
                return;
            }
            if(me == inf)continue;
            int left , right;
            if(i==0 or i == 1 ){
                        left = sq[md(i,1)][me];
                        right = sq[md(i,-1)][me];
                        }
            else {
                        left = sq[md(i,1)][n-me-1];
                        right = sq[md(i,-1)][n-me-1];
            }
            if(left == -1)left = inf;
            if(right == -1)right = inf;
            debug(left,right);
            if(i==0 or i == 3){
                        if(left > j or left==inf){
                            cout << "NE" << endl;
                            return;
                        }
                        else if(right > (n-j-1) or right == inf){
                            cout << "NE" << endl;
                            return;
                        }
                    }
            else {
                        if(left > (n-j-1) or left==inf){
                            cout << "NE" << endl;
                            return;
                        }
                        else if(right > j or right == inf){
                            cout << "NE" << endl;
                            return;
                        }
            }
        }
    }
    cout << "DA" << endl;
}
int32_t main(){
    ios_base::sync_with_stdio(0);cin.tie(nullptr);
    int tt=1;
//    cin >> tt;
    while(tt--)solve();
}
| # | 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... |