제출 #1331750

#제출 시각아이디문제언어결과실행 시간메모리
1331750benjaminshihKocka (COCI18_kocka)C++20
70 / 70
27 ms1860 KiB
#include <bits/stdc++.h>
using namespace std;

int main(){
    // 優化輸入輸出速度
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n; 
    if(!(cin >> n)) return 0;
    vector<int> l(n), r(n), u(n), d(n);

    for(auto &x : l) cin >> x;
    for(auto &x : r) cin >> x;
    for(auto &x : u) cin >> x;
    for(auto &x : d) cin >> x;
    
    bool possible = true;

    for(int i = 0 ; i < n ; i++){
        if(l[i] == -1){
            if(r[i] != -1) possible = false;
        } else {
            if(r[i] == -1) possible = false;
            else if(l[i] + r[i] >= n) possible = false;
            else {
                int c1 = l[i];
                if(u[c1] == -1 || d[c1] == -1 || i < u[c1] || i > n - 1 - d[c1]) {
                    possible = false;
                }
                
                int c2 = n - 1 - r[i];
                if(u[c2] == -1 || d[c2] == -1 || i < u[c2] || i > n - 1 - d[c2]) {
                    possible = false;
                }
            }
        }
    }

    for(int j = 0 ; j < n ; j++){
        if(u[j] == -1){
            if(d[j] != -1) possible = false;
        } else {
            if(d[j] == -1) possible = false;
            else if(u[j] + d[j] >= n) possible = false;
            else {
                int r1 = u[j];
                if(l[r1] == -1 || r[r1] == -1 || j < l[r1] || j > n - 1 - r[r1]) {
                    possible = false;
                }
                
                int r2 = n - 1 - d[j];
                if(l[r2] == -1 || r[r2] == -1 || j < l[r2] || j > n - 1 - r[r2]) {
                    possible = false;
                }
            }
        }
    }

    if(possible) cout << "DA\n";
    else cout << "NE\n";

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...