제출 #1137721

#제출 시각아이디문제언어결과실행 시간메모리
1137721RafiullahText editor (CEOI24_editor)C++20
16 / 100
250 ms8148 KiB
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
#define int long long
int up(int x1, int y1, int x2, int y2){
    return abs(x2 - x1) + abs (y2 - y1);
}

int arr[N];
signed main(){
    int n; cin >> n;
    int x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    for(int i = 0; i < n; i++)
        cin >> arr[i];
    if(n == 1)cout << 0 <<endl;
    else{
        int X = up(x1,y1,x2,y2);
        int Y = 1e9;
        if(x1 != n)
            Y = (arr[0] + 2) - y1 + up(x1 + 1, 1, x2, y2);
        int T = 1e9;
        if(x1!=1)T=y1+up(x1-1,arr[0]+1,x2,y2);
        else T=1+y1+up(1,arr[0]+1,x2,y2);
        int Z = n - x1;
        Z = Z + 1 + min(up(n - 1, 1, x2, y2), up(n - 1, arr[0] + 1, x2, y2));
        X = min({X,Y,T,Z});
        cout << X << '\n';
    }
    
}
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...