Problem:
Warehouse Robot
Aizu Transport is developing a warehouse guard robot. In our warehouse, points in the warehouse are managed by coordinates (x,y) as shown in the floor plan below. In the warehouse, shelves with square bottoms are arranged in a regular pattern to facilitate the management of cargo. If we represent the positions of the southwest and northeast corners of the shelves by pairs of coordinates of points in the warehouse, the shelves are (0,0) and (1,1), (2,0) and (3,1), ..., (0,2) and (1,3), (2,2) and (3,3), ..., and so on, from one end of the warehouse to the other, they are placed in such a way that they occupy a square area represented by (2i,2j) and (2i+1,2j+1) using zero or more integers i and j.
The warehouseman robot can move freely when there are no shelves. It cannot pass through the area where shelves are placed, but it can pass over the boundary of the shelf area because of its small size. For example, to go from point (0,0) to point (4,3) in the shortest distance, you can move as follows.
You, the warehouseman robot development department, are planning to add a function to the robot to calculate the shortest distance to the target point.
Given the point where the warehouse guard robot is currently located and the target point, write a program that outputs the shortest distance that the robot will travel to reach the target point.
Input
The input is given in the following form.
$x_0$ $y_0$ $x_1$ $y_1$
In one line, the coordinates $x_0$,$y_0$ ($0 \leq x_0,y_0 \leq 300$) of the point where the warehouse guard robot is currently located and the coordinates $x_1$,$y_1$ ($0 \leq x_1,y_1 \leq 300$) of the target point are all given as integers. The warehouse can be thought of as a rectangle of such a size that all points with the given coordinates exist. The coordinates of the point where the robot is currently located and the target point are different ($x_0 \ne x_1$ or $y_0 \ne y_1$).
Output
Output the shortest distance for the robot to reach the target point as a real number on one line. The error must not exceed plus or minus 0.00001.
Sample Input and Output
Sample Input 1
0 0 4 3
Sample Output 1
5.24264069
Sample Input 2
7 1 1 6
Sample Output 2
7.89292223
Sample Input 3
0 2 5 2
Sample Output 3
5

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ld=long double;
#define fi first
#define se second
#define i128 __int128_t
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define si(a) (long)(a.size())
template<typename T>bool chmin(T&a,T b){return b<a?(a=b,1):0;}
template<typename T>bool chmax(T&a,T b){return b>a?(a=b,1):0;}
const int INF=1e9+100;
const long INFL=3e18+100;
struct _ {
   _() { cin.tie(0)->sync_with_stdio(0), cout.tie(0); }
} __;

int main(){
    int sx,sy,gx,gy;
    cin>>sx>>sy>>gx>>gy;
    vector<pair<int,int>> V;
    int L=301;
    rep(i,L)rep(j,L) V.push_back({i,j});
    sort(all(V), [&](auto a, auto b){return abs(a.fi-sy)+abs(a.se-sx)<abs(b.fi-sy)+abs(b.se-sx);});
    
    vector dp(L,vector<ld>(L,1e9));
    dp[sy][sx]=0;
    vector<ld> X(L,0);
    rep(i,L)X[i]=hypotf64(1, i);
    for(auto [y,x]: V){

        vector<int> dd={0,1,0,-1,0};
        rep(i,4){
            int ny=y+dd[i];
            int nx=x+dd[i+1];
            if(ny<0||L<=ny||nx<0||L<=nx) continue;
            chmin(dp[ny][nx], dp[y][x]+1);
        }
        rep(_,1){
            int ny=y+(y%2)*2-1;
            if(ny<0||L<=ny) continue;
            rep(nx,L){
                chmin(dp[ny][nx], dp[y][x]+X[abs(x-nx)]);
            }
        }
        rep(_,1){
            int nx=x+(x%2)*2-1;
            if(nx<0||L<=nx) continue;
            rep(ny,L){
                chmin(dp[ny][nx], dp[y][x]+X[abs(y-ny)]);
            }
        }
    }
    cout<<fixed<<setprecision(15);
    cout<<dp[gy][gx]<<"\n";

}
accuracy: 1
time_ms: 130
memory_kb: 5860
final_rank: 5

code_snippet: #include <bits/stdc++.h>
#include <random>
using namespace std;
#define all(a) a.begin(),a.end()
#define vc_rotate(a) rotate(a.begin(),a.begin() + 1,a.end());
typedef long long ll;typedef long double ld;
#define INF (ll)2e18
const int inf = (1 << 30);
using pii = pair<int,int>;
using dat = pair<ld,pair<int,int>>;
using pq = priority_queue<dat,vector<dat>,greater<dat>>;//{cost,node}
vector<pii> dir = {{0,1},{1,0},{-1,0},{0,-1}};

template<typename T> bool chmin(T &a, T b) { if (a > b){a = b;return true;}else return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b){a = b;return true;}else return false; }
template<typename T> void vec_out(vector<T> a){for (int i = 0;i < a.size();i++)cout << a[i] << ' ';cout << endl;}
template<typename T> void vvout(vector<vector<T>> a){for (int i =0;i <a.size();i++){vec_out(a[i]);}}
template<typename T> void set_out(T a){for (auto it = a.begin();it != a.end();it++)cout << *it << ' ';cout << endl;}
template<typename T> void map_out(T a){for (auto it = a.begin();it != a.end();it++)cout << "key = " << it->first << " val = " << it->second << endl;}
template<typename T,typename U> T div_ceil(T a,U b){assert(b != 0);return (a + b - 1) / b;}
void debug(){cout << "No Runtime Error" << endl;}
int popcount(ll t){return __builtin_popcountll(t);}

ld dist(int a,int b,int c,int d){
    return sqrt(ld(c - a) * ld(c - a) + ld(d - b) * ld(d - b));
};

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >>d;
    vector<vector<ld>> dp(301,vector<ld> (301,ld(1000)));
    dp[a][b] = 0;
    pq q;
    q.push(make_pair(0,make_pair(a,b)));
    int cnt= 0;
    while(!q.empty()){
        auto [val,w] = q.top();
        auto[x,y] = w;
        q.pop();
        cnt++;
        if (cnt >= 100000) break;
        if (x % 2 == 1){
            if (x + 1 <= 300){
                for (int i = 0;i < 301;i++){
                    if (chmin(dp[x + 1][i],val + dist(x,y,x + 1,i))){
                        q.push(make_pair(dp[x + 1][i],make_pair(x + 1,i)));
                    }
                }
            }
            if (y - 1 >= 0 && dp[x][y - 1] > dp[x][y] + 1){
                dp[x][y - 1] = dp[x][y] + 1;
                q.push(make_pair(dp[x][y - 1],make_pair(x,y - 1)));
            }
        }
        else{
            if (x - 1 >= 0){
                for (int i = 0;i < 301;i++){
                    if (chmin(dp[x - 1][i],val + dist(x,y,x - 1,i))){
                        q.push(make_pair(dp[x - 1][i],make_pair(x - 1,i)));
                    }
                }
            }
            if (y + 1 <= 300 && dp[x][y + 1] > dp[x][y] + 1){
                dp[x][y + 1] = dp[x][y] + 1;
                q.push(make_pair(dp[x][y + 1],make_pair(x,y + 1)));
            }
        }
        if (y % 2 == 1){
            if (y + 1 <= 300){
                for (int i = 0;i < 301;i++){
                    if (chmin(dp[i][y + 1],val + dist(x,y,i,y + 1))){
                        q.push(make_pair(dp[i][y + 1],make_pair(i,y + 1)));
                    }
                }
            }
            if (x - 1 >= 0 && dp[x - 1][y] > dp[x][y] + 1){
                dp[x - 1][y] = dp[x][y] + 1;
                q.push(make_pair(dp[x - 1][y],make_pair(x - 1,y)));
            }
        }
        else{
            if (y - 1 >= 0){
                for (int i = 0;i < 301;i++){
                    if (chmin(dp[i][y - 1],val + dist(x,y,i,y - 1))){
                        q.push(make_pair(dp[i][y - 1],make_pair(i,y - 1)));
                    }
                }
            }
            if (x + 1 <= 300 && dp[x +1][y] > dp[x][y] + 1){
                dp[x + 1][y] = dp[x][y] + 1;
                q.push(make_pair(dp[x +1][y],make_pair(x + 1,y)));
            }
        }
    }
    cout << fixed << setprecision(8);
    cout << dp[c][d] << endl;
}
accuracy: 0.10416666666666667
time_ms: 200
memory_kb: 71504
final_rank: 20

code_snippet: #include<bits/stdc++.h>
#include <iomanip>
#pragma GCC optimize("O2")
using namespace std;
#define ll long long 
#define ld long double
#define rep(i,N) for(int i=0;i<(int)N;i++)
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define pb push_back
vector<int>dx={0,0,1,-1},dy={1,-1,0,0};
bool out(int x,int y){
    return (x<0||301<x||y<0||301<y);
}
int main(){
    int sx,sy,tx,ty;cin>>sx>>sy>>tx>>ty;
    vector<vector<ld>>dist(302,vector<ld>(302,1000.0));
    dist[sx][sy]=0;
    int dlim = max(302-sx,sx)+max(302-sy,sy);
    vector<vector<bool>>seen(302,vector<bool>(302,false));
    rep(k,dlim+1)for(int i = -k;i<=k;i++)for(int kk=1;kk>=-1;kk-=2){
        int x = sx+i,y = sy+((k-abs(i))*kk);
        if(x<0||301<x||y<0||301<y)continue;
        if(seen[x][y]){
            continue;
        }
        seen[x][y]=true;
        rep(t,4){
            int nx = x+dx[t],ny=y+dy[t];
            if(out(nx,ny))continue;
            dist[nx][ny]=min(dist[nx][ny],dist[x][y]+1);
        }
        if(x%2!=0||y%2!=0){
            int nx = x+1,ny=y+1;
            if(out(nx,ny))continue;
            dist[nx][ny]=min(dist[nx][ny],dist[x][y]+sqrtl(2));
        }
        if(x%2!=1||y%2!=0){
            int nx = x-1,ny=y+1;
            if(out(nx,ny))continue;
            dist[nx][ny]=min(dist[nx][ny],dist[x][y]+sqrtl(2));
        }
        if(x%2!=0||y%2!=1){
            int nx = x+1,ny=y-1;
            if(out(nx,ny))continue;
            dist[nx][ny]=min(dist[nx][ny],dist[x][y]+sqrtl(2));
        }
        if(x%2!=1||y%2!=1){
            int nx = x-1,ny=y-1;
            if(out(nx,ny))continue;
            dist[nx][ny]=min(dist[nx][ny],dist[x][y]+sqrtl(2));
        }
        int ddx = 1;
        if(x%2==0)ddx=-1;
        rep(ny,302){
            int nx = x+ddx;
            if(out(nx,ny))continue;
            dist[nx][ny]=min(dist[nx][ny],dist[x][y]+sqrtl(1+(y-ny)*(y-ny)));
        }
        int ddy = 1;
        if(y%2==0)ddy=-1;
        rep(nx,302){
            int ny = y+ddy;
            if(out(nx,ny))continue;
            dist[nx][ny]=min(dist[nx][ny],dist[x][y]+sqrtl(1+(x-nx)*(x-nx)));
        }
    }
    cout<<fixed<<setprecision(10)<<dist[tx][ty]<<endl;
}
accuracy: 1
time_ms: 200
memory_kb: 5012
final_rank: 6

code_snippet: #include<bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define ll long long 
#define ld long double
#define rep(i,N) for(int i=0;i<(int)N;i++)
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define pb push_back
vector<int>dx={0,0,1,-1},dy={1,-1,0,0};
bool out(int x,int y){
    return (x<0||301<x||y<0||301<y);
}
int main(){
    int sx,sy,tx,ty;cin>>sx>>sy>>tx>>ty;
    vector<vector<ld>>dist(302,vector<ld>(302,1000.0));
    dist[sx][sy]=0;
    int dlim = max(302-sx,sx)+max(302-sy,sy);
    vector<vector<bool>>seen(302,vector<bool>(302,false));
    rep(k,dlim+1)for(int i = -k;i<=k;i++)for(int kk=1;kk>=-1;kk-=2){
        int x = sx+i,y = sy+((k-abs(i))*kk);
        if(x<0||301<x||y<0||301<y)continue;
        if(seen[x][y]){
            continue;
        }
        seen[x][y]=true;
        rep(t,4){
            int nx = x+dx[t],ny=y+dy[t];
            if(out(nx,ny))continue;
            dist[nx][ny]=min(dist[nx][ny],dist[x][y]+1);
        }
        if(x%2!=0||y%2!=0){
            int nx = x+1,ny=y+1;
            if(out(nx,ny))continue;
            dist[nx][ny]=min(dist[nx][ny],dist[x][y]+sqrtl(2));
        }
        if(x%2!=1||y%2!=0){
            int nx = x-1,ny=y+1;
            if(out(nx,ny))continue;
            dist[nx][ny]=min(dist[nx][ny],dist[x][y]+sqrtl(2));
        }
        if(x%2!=0||y%2!=1){
            int nx = x+1,ny=y-1;
            if(out(nx,ny))continue;
            dist[nx][ny]=min(dist[nx][ny],dist[x][y]+sqrtl(2));
        }
        if(x%2!=1||y%2!=1){
            int nx = x-1,ny=y-1;
            if(out(nx,ny))continue;
            dist[nx][ny]=min(dist[nx][ny],dist[x][y]+sqrtl(2));
        }
        int ddx = 1;
        if(x%2==0)ddx=-1;
        rep(ny,302){
            int nx = x+ddx;
            if(out(nx,ny))continue;
            dist[nx][ny]=min(dist[nx][ny],dist[x][y]+sqrtl(1+(y-ny)*(y-ny)));
        }
        int ddy = 1;
        if(y%2==0)ddy=-1;
        rep(nx,302){
            int ny = y+ddy;
            if(out(nx,ny))continue;
            dist[nx][ny]=min(dist[nx][ny],dist[x][y]+sqrtl(1+(x-nx)*(x-nx)));
        }
    }
    cout<<dist[tx][ty]<<endl;
}
accuracy: 0.22916666666666666
time_ms: 220
memory_kb: 5012
final_rank: 19

code_snippet: #include <bits/stdc++.h>
#include <iomanip>
#include <numbers>
#include <cassert>
#include <numeric>
#ifdef _MSC_VER
#include <intrin.h>
#endif
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pint = pair<int, int>;
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
template<typename T>
bool chmax(T & a, const T & b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T & a, const T & b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9;
const ll linf = 1e18;
const int dy[] = { 0,0,1,-1 }, dx[] = { 1,-1,0,0 };
int main() {
    int x0, y0, x1, y1; cin >> x0 >> y0 >> x1 >> y1;
    if (x0 > x1) { x0 = 301 - x0; x1 = 301 - x1; }
    if (y0 > y1) { y0 = 301 - y0; y1 = 301 - y1; }
    int n = 302;
    vector dp(n, vector<double>(n, inf));
    dp[y0][x0] = 0;
    rep(y, n)rep(x, n) {
        if (x + 1 >= n || y + 1 >= n)continue;
        chmin(dp[y][x + 1], dp[y][x] + 1);
        chmin(dp[y + 1][x], dp[y][x] + 1);
        if (x % 2)rep(yy, n) chmin(dp[yy][x + 1], dp[y][x] + sqrt((yy - y) * (yy - y) + 1));
        if (y % 2)rep(xx, n) chmin(dp[y + 1][xx], dp[y][x] + sqrt((xx - x) * (xx - x) + 1));
    }
    printf("%.10f\n", dp[y1][x1]);
}
accuracy: 1
time_ms: 40
memory_kb: 4480
final_rank: 2

code_snippet: #include <bits/stdc++.h>
#include <iomanip>
#include <numbers>
#include <cassert>
#include <numeric>
#ifdef _MSC_VER
#include <intrin.h>
#endif
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pint = pair<int, int>;
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
template<typename T>
bool chmax(T & a, const T & b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T & a, const T & b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9;
const ll linf = 1e18;
const int dy[] = { 0,0,1,-1 }, dx[] = { 1,-1,0,0 };
int main() {
    int x0, y0, x1, y1; cin >> x0 >> y0 >> x1 >> y1;
    if (x0 > x1) swap(x0, x1);
    if (y0 > y1) swap(y0, y1);
    int n = 302;
    vector dp(n, vector<double>(n, inf));
    dp[y0][x0] = 0;
    rep(y, n)rep(x, n) {
        if (x + 1 >= n || y + 1 >= n)continue;
        chmin(dp[y][x + 1], dp[y][x] + 1);
        chmin(dp[y + 1][x], dp[y][x] + 1);
        if (x % 2)rep(yy, n) chmin(dp[yy][x + 1], dp[y][x] + sqrt((yy - y) * (yy - y) + 1));
        if (y % 2)rep(xx, n) chmin(dp[y + 1][xx], dp[y][x] + sqrt((xx - x) * (xx - x) + 1));
    }
    printf("%.10f\n", dp[y1][x1]);
}
accuracy: 0.5625
time_ms: 40
memory_kb: 4480
final_rank: 15

code_snippet: #include <bits/stdc++.h>
#include <iomanip>
#include <numbers>
#include <cassert>
#include <numeric>
#ifdef _MSC_VER
#include <intrin.h>
#endif
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pint = pair<int, int>;
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
template<typename T>
bool chmax(T & a, const T & b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T & a, const T & b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9;
const ll linf = 1e18;
const int dy[] = { 0,0,1,-1 }, dx[] = { 1,-1,0,0 };
int main() {
    int x0, y0, x1, y1; cin >> x0 >> y0 >> x1 >> y1;
    if (x0 > x1) { x0 = 301 - x0; x1 = 301 - x1; }
    if (y0 > y1) { y0 = 301 - y0; y1 = 301 - y1; }
    int n = 301;
    vector dp(n, vector<double>(n, inf));
    dp[y0][x0] = 0;
    rep(y, n)rep(x, n) {
        if (x + 1 < n)chmin(dp[y][x + 1], dp[y][x] + 1);
        if (y + 1 < n)chmin(dp[y + 1][x], dp[y][x] + 1);
        if (x % 2)rep(yy, n) chmin(dp[yy][x + 1], dp[y][x] + sqrt((yy - y) * (yy - y) + 1));
        if (y % 2)rep(xx, n) chmin(dp[y + 1][xx], dp[y][x] + sqrt((xx - x) * (xx - x) + 1));
    }
    printf("%.10f\n", dp[y1][x1]);
}
accuracy: 0.5625
time_ms: 40
memory_kb: 4480
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double INF_D = 1e100;

int main() {
    int x0, y0, x1, y1;
    if (!(cin >> x0 >> y0 >> x1 >> y1)) return 0;

    // mirror as in reference
    if (x0 > x1) swap(x0, x1);
    if (y0 > y1) swap(y0, y1);

    const int LIM = 302; // indices 0..301 inclusive
    vector<vector<double>> dp(LIM, vector<double>(LIM, INF_D));
    dp[y0][x0] = 0.0;

    for (int x = 0; x < LIM; ++x) {         // 列を外側に
        for (int y = 0; y < LIM; ++y) {     // 行を内側に
            double cur = dp[y][x];
            if (cur >= INF_D/2) continue;

            // right (x+1, y)
            if (x + 1 < LIM) dp[y][x+1] = min(dp[y][x+1], cur + 1.0);
            // down (x, y+1)
            if (y + 1 < LIM) dp[y+1][x] = min(dp[y+1][x], cur + 1.0);

            // x-warp: if x is odd -> (x+1, yy) for yy > y
            if ((x % 2) == 1 && x + 1 < LIM) {
                for (int yy = y + 1; yy < LIM; ++yy) {
                    double cost = sqrt((double)(yy - y) * (yy - y) + 1.0);
                    dp[yy][x+1] = min(dp[yy][x+1], cur + cost);
                }
            }
            // y-warp: if y is odd -> (xx, y+1) for xx > x
            if ((y % 2) == 1 && y + 1 < LIM) {
                for (int xx = x + 1; xx < LIM; ++xx) {
                    double cost = sqrt((double)(xx - x) * (xx - x) + 1.0);
                    dp[y+1][xx] = min(dp[y+1][xx], cur + cost);
                }
            }
        }
    }

    cout.setf(std::ios::fixed);
    cout << setprecision(10) << dp[y1][x1] << "\n";
    return 0;
}
accuracy: 0.5625
time_ms: 10
memory_kb: 4608
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double INF_D = 1e100;

int main() {
    int x0, y0, x1, y1;
    if (!(cin >> x0 >> y0 >> x1 >> y1)) return 0;

    // mirror as in reference
    if (x0 > x1) { x0 = 301 - x0; x1 = 301 - x1; }
    if (y0 > y1) { y0 = 301 - y0; y1 = 301 - y1; }

    const int LIM = 302; // indices 0..301 inclusive
    vector<vector<double>> dp(LIM, vector<double>(LIM, INF_D));
    dp[y0][x0] = 0.0;

    for (int x = 0; x < LIM; ++x) {         // 列を外側に
        for (int y = 0; y < LIM; ++y) {     // 行を内側に
            double cur = dp[y][x];
            if (cur >= INF_D/2) continue;

            // right (x+1, y)
            if (x + 1 < LIM) dp[y][x+1] = min(dp[y][x+1], cur + 1.0);
            // down (x, y+1)
            if (y + 1 < LIM) dp[y+1][x] = min(dp[y+1][x], cur + 1.0);

            // x-warp: if x is odd -> (x+1, yy) for yy > y
            if ((x % 2) == 1 && x + 1 < LIM) {
                for (int yy = y + 1; yy < LIM; ++yy) {
                    double cost = sqrt((double)(yy - y) * (yy - y) + 1.0);
                    dp[yy][x+1] = min(dp[yy][x+1], cur + cost);
                }
            }
            // y-warp: if y is odd -> (xx, y+1) for xx > x
            if ((y % 2) == 1 && y + 1 < LIM) {
                for (int xx = x + 1; xx < LIM; ++xx) {
                    double cost = sqrt((double)(xx - x) * (xx - x) + 1.0);
                    dp[y+1][xx] = min(dp[y+1][xx], cur + cost);
                }
            }
        }
    }

    cout.setf(std::ios::fixed);
    cout << setprecision(10) << dp[y1][x1] << "\n";
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4608
final_rank: 1

code_snippet: #include <bits/stdc++.h>
#include <iomanip>
#include <numbers>
#include <cassert>
#include <numeric>
#ifdef _MSC_VER
#include <intrin.h>
#endif
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pint = pair<int, int>;
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
template<typename T>
bool chmax(T & a, const T & b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T & a, const T & b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9;
const ll linf = 1e18;
const int dy[] = { 0,0,1,-1 }, dx[] = { 1,-1,0,0 };
int main() {
    int x0, y0, x1, y1; cin >> x0 >> y0 >> x1 >> y1;
    if (x0 > x1) { x0 = 301 - x0; x1 = 301 - x1; }
    if (y0 > y1) { y0 = 301 - y0; y1 = 301 - y1; }
    int n = 301;
    vector dp(n + 1, vector<double>(n + 1, inf));
    dp[y0][x0] = 0;
    rep(y, n)rep(x, n) {
        if (x + 1 < n)chmin(dp[y][x + 1], dp[y][x] + 1);
        if (y + 1 < n)chmin(dp[y + 1][x], dp[y][x] + 1);
        if (x % 2)rep(yy, n) chmin(dp[yy][x + 1], dp[y][x] + sqrt((yy - y) * (yy - y) + 1));
        if (y % 2)rep(xx, n) chmin(dp[y + 1][xx], dp[y][x] + sqrt((xx - x) * (xx - x) + 1));
    }
    printf("%.10f\n", dp[y1][x1]);
}
accuracy: 0.5625
time_ms: 30
memory_kb: 4480
final_rank: 10

code_snippet: #include <bits/stdc++.h>
#include <iomanip>
#include <numbers>
using namespace std;
using ll = long long;
const int NMAX = 301;
const int dy[] = { 0,0,1,-1 }, dx[] = { 1,-1,0,0 };

int main() {
    int x0, y0, x1, y1;
    if (!(cin >> x0 >> y0 >> x1 >> y1)) return 0;
    if (x0 > x1) swap(x0, x1);
    if (y0 > y1) swap(y0, y1);

    int n = 301;
    const double INF = 1e100;
    vector<vector<double>> dp(n, vector<double>(n, INF));
    dp[y0][x0] = 0.0;

    // 修正：列 (x) を外側ループにする
    for (int x = x0; x < n; ++x) {
        for (int y = 0; y < n; ++y) {
            double cur = dp[y][x];
            if (cur >= INF/2) continue;
            // 右に1
            if (x + 1 < n) dp[y][x + 1] = min(dp[y][x + 1], cur + 1.0);
            // 下に1
            if (y + 1 < n) dp[y + 1][x] = min(dp[y + 1][x], cur + 1.0);
            // xが奇数のとき、任意の行 yy にワープして x+1 列へ
            if (x % 2 == 1 && x + 1 < n) {
                for (int yy = 0; yy < n; ++yy) {
                    double cost = sqrt((double)(yy - y) * (yy - y) + 1.0);
                    dp[yy][x + 1] = min(dp[yy][x + 1], cur + cost);
                }
            }
            // yが奇数のとき、任意の列 xx にワープして y+1 行へ
            if (y % 2 == 1 && y + 1 < n) {
                for (int xx = 0; xx < n; ++xx) {
                    double cost = sqrt((double)(xx - x) * (xx - x) + 1.0);
                    dp[y + 1][xx] = min(dp[y + 1][xx], cur + cost);
                }
            }
        }
    }

    printf("%.10f\n", dp[y1][x1]);
    return 0;
}
accuracy: 0.5625
time_ms: 30
memory_kb: 4480
final_rank: 10

code_snippet: #include <bits/stdc++.h>
#include <iomanip>
#include <numbers>
#include <cassert>
#include <numeric>
#ifdef _MSC_VER
#include <intrin.h>
#endif
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pint = pair<int, int>;
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
template<typename T>
bool chmax(T & a, const T & b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T & a, const T & b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9;
const ll linf = 1e18;
const int dy[] = { 0,0,1,-1 }, dx[] = { 1,-1,0,0 };
int main() {
    int x0, y0, x1, y1; cin >> x0 >> y0 >> x1 >> y1;
    if (x0 > x1)swap(x0, x1);
    if (y0 > y1)swap(y0, y1);
    int n = 301;
    vector dp(n, vector<double>(n, inf));
    dp[y0][x0] = 0;
    rep(y, y1 + 1)rep(x, x1 + 1) {
        if (x + 1 < n)chmin(dp[y][x + 1], dp[y][x] + 1);
        if (y + 1 < n)chmin(dp[y + 1][x], dp[y][x] + 1);
        if (x % 2)rep(yy, y1 + 1) chmin(dp[yy][x + 1], dp[y][x] + sqrt((yy - y) * (yy - y) + 1));
        if (y % 2)rep(xx, x1 + 1) chmin(dp[y + 1][xx], dp[y][x] + sqrt((xx - x) * (xx - x) + 1));
    }
    printf("%.10f\n", dp[y1][x1]);
}
accuracy: 0.5625
time_ms: 30
memory_kb: 4480
final_rank: 10

code_snippet: #include <bits/stdc++.h>
#include <iomanip>
#include <numbers>
#include <cassert>
#include <numeric>
#ifdef _MSC_VER
#include <intrin.h>
#endif
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pint = pair<int, int>;
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
template<typename T>
bool chmax(T & a, const T & b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T & a, const T & b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9;
const ll linf = 1e18;
const int dy[] = { 0,0,1,-1 }, dx[] = { 1,-1,0,0 };
int main() {
    int x0, y0, x1, y1; cin >> x0 >> y0 >> x1 >> y1;
    if (x0 > x1)swap(x0, x1);
    if (y0 > y1)swap(y0, y1);
    int n = 301;
    vector dp(n, vector<double>(n, inf));
    dp[y0][x0] = 0;
    rep(y, y1 + 1)rep(x, x1 + 1) {
        if (x + 1 < n)chmin(dp[y][x + 1], dp[y][x] + 1);
        if (y + 1 < n)chmin(dp[y + 1][x], dp[y][x] + 1);
        if (x % 2)rep(yy, n) chmin(dp[yy][x + 1], dp[y][x] + sqrt((yy - y) * (yy - y) + 1));
        if (y % 2)rep(xx, n) chmin(dp[y + 1][xx], dp[y][x] + sqrt((xx - x) * (xx - x) + 1));
    }
    printf("%.10f\n", dp[y1][x1]);
}
accuracy: 0.5625
time_ms: 30
memory_kb: 4480
final_rank: 10

code_snippet: #include <bits/stdc++.h>
#include <iomanip>
#include <numbers>
#include <cassert>
#include <numeric>
#ifdef _MSC_VER
#include <intrin.h>
#endif
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pint = pair<int, int>;
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
template<typename T>
bool chmax(T & a, const T & b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T & a, const T & b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9;
const ll linf = 1e18;
const int dy[] = { 0,0,1,-1 }, dx[] = { 1,-1,0,0 };
int main() {
    int x0, y0, x1, y1; cin >> x0 >> y0 >> x1 >> y1;
    /*if (x0 > x1)swap(x0, x1);
    if (y0 > y1)swap(y0, y1);*/
    if (x0 > x1) x0 = -x0 + 301, x1 = -x1 + 301;
    if (y0 > y1) y0 = -y0 + 301, y1 = -y1 + 301;
    int n = 301;
    vector dp(n, vector<double>(n, inf));
    dp[y0][x0] = 0;
    rep(y, n)rep(x, n) {
        if (x + 1 < n)chmin(dp[y][x + 1], dp[y][x] + 1);
        if (y + 1 < n)chmin(dp[y + 1][x], dp[y][x] + 1);
        if (x % 2)rep(yy, n) chmin(dp[yy][x + 1], dp[y][x] + sqrt((yy - y) * (yy - y) + 1));
        if (y % 2)rep(xx, n) chmin(dp[y + 1][xx], dp[y][x] + sqrt((xx - x) * (xx - x) + 1));
    }
    printf("%.10f\n", dp[y1][x1]);
}
accuracy: 0.5625
time_ms: 40
memory_kb: 4480
final_rank: 15

code_snippet: #include <bits/stdc++.h>
#include <iomanip>
#include <numbers>
#include <cassert>
#include <numeric>
#ifdef _MSC_VER
#include <intrin.h>
#endif
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pint = pair<int, int>;
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
template<typename T>
bool chmax(T & a, const T & b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T & a, const T & b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9;
const ll linf = 1e18;
const int dy[] = { 0,0,1,-1 }, dx[] = { 1,-1,0,0 };
int main() {
    int x0, y0, x1, y1; cin >> x0 >> y0 >> x1 >> y1;
    if (x0 > x1)swap(x0, x1);
    if (y0 > y1)swap(y0, y1);
    int n = 301;
    vector dp(n, vector<double>(n, inf));
    dp[y0][x0] = 0;
    rep(y, n)rep(x, n) {
        if (x + 1 < n)chmin(dp[y][x + 1], dp[y][x] + 1);
        if (y + 1 < n)chmin(dp[y + 1][x], dp[y][x] + 1);
        if (x % 2)rep(yy, n) chmin(dp[yy][x + 1], dp[y][x] + sqrt((yy - y) * (yy - y) + 1));
        if (y % 2)rep(xx, n) chmin(dp[y + 1][xx], dp[y][x] + sqrt((xx - x) * (xx - x) + 1));
    }
    printf("%.10f\n", dp[y1][x1]);
}
accuracy: 0.5625
time_ms: 30
memory_kb: 4480
final_rank: 10

code_snippet: #include<bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

int main(){
	int x0,y0,x1,y1;
	cin >> x0 >> y0 >> x1 >> y1;
	int dx=x1-x0;
	int dy=y1-y0;
	if(dx<0 && dy<0){
		swap(x0,x1);
		swap(y0,y1);
	}
	else if(dx<0){
		x0++;
		x1=x0-dx;
	}
	else if(dy<0){
		y0++;
		y1=y0-dy;
	}
	x1-=x0/2*2;
	y1-=y0/2*2;
	x0%=2;
	y0%=2;
	vector<double> dist(110000,8000000000.0);
	dist[x0*320+y0]=0.0;
	for(int t=0;t<320*320;t++){
		pair<int,int> pos=make_pair(t/320,t%320);
		int hash=pos.first%2+pos.second%2*2;
		for(int i=0;i<=300;i++){
			if(hash==0 && i!=0 && i!=-1) continue;
			if(hash==2 && i!=0 && i!=1) continue;
			pair<int,int> nv=make_pair(pos.first+1,pos.second+i);
			if(nv.first<0 || nv.first>=320 || nv.second<0 || nv.second>=320) continue;
			if(dist[nv.first*320+nv.second]>dist[pos.first*320+pos.second]+hypot(1.0,(double)i)){
				dist[nv.first*320+nv.second]=dist[pos.first*320+pos.second]+hypot(1.0,(double)i);
			}
		}
		for(int i=0;i<=300;i++){
			if(hash==1 && i!=0 && i!=-1) continue;
			if(hash==3 && i!=0 && i!=1) continue;
			pair<int,int> nv=make_pair(pos.first-1,pos.second+i);
			if(nv.first<0 || nv.first>=320 || nv.second<0 || nv.second>=320) continue;
			if(dist[nv.first*320+nv.second]>dist[pos.first*320+pos.second]+hypot(1.0,(double)i)){
				dist[nv.first*320+nv.second]=dist[pos.first*320+pos.second]+hypot(1.0,(double)i);
			}
		}
		for(int i=0;i<=300;i++){
			if(hash==0 && i!=0 && i!=-1) continue;
			if(hash==1 && i!=0 && i!=1) continue;
			pair<int,int> nv=make_pair(pos.first+i,pos.second+1);
			if(nv.first<0 || nv.first>=320 || nv.second<0 || nv.second>=320) continue;
			if(dist[nv.first*320+nv.second]>dist[pos.first*320+pos.second]+hypot(1.0,(double)i)){
				dist[nv.first*320+nv.second]=dist[pos.first*320+pos.second]+hypot(1.0,(double)i);
			}
		}
		for(int i=0;i<=300;i++){
			if(hash==2 && i!=0 && i!=-1) continue;
			if(hash==3 && i!=0 && i!=1) continue;
			pair<int,int> nv=make_pair(pos.first+i,pos.second-1);
			if(nv.first<0 || nv.first>=320 || nv.second<0 || nv.second>=320) continue;
			if(dist[nv.first*320+nv.second]>dist[pos.first*320+pos.second]+hypot(1.0,(double)i)){
				dist[nv.first*320+nv.second]=dist[pos.first*320+pos.second]+hypot(1.0,(double)i);
			}
		}
		/*
		for(int i=-300;i<=300;i++){
			if(hash==0 && i!=0 && i!=-1) continue;
			if(hash==2 && i!=0 && i!=1) continue;
			pair<int,int> nv=make_pair(pos.first+1,pos.second+i);
			if(nv.first<0 || nv.first>=320 || nv.second<0 || nv.second>=320) continue;
			if(conf[nv.first*320+nv.second]) continue;
			if(cur[nv.first*320+nv.second]>cur[pos.first*320+pos.second]+hypot(1.0,(double)i)){
				cur[nv.first*320+nv.second]=cur[pos.first*320+pos.second]+hypot(1.0,(double)i);
				que.push(make_pair(cur[nv.first*320+nv.second],nv));
			}
		}
		for(int i=-300;i<=300;i++){
			if(hash==1 && i!=0 && i!=-1) continue;
			if(hash==3 && i!=0 && i!=1) continue;
			pair<int,int> nv=make_pair(pos.first-1,pos.second+i);
			if(nv.first<0 || nv.first>=320 || nv.second<0 || nv.second>=320) continue;
			if(conf[nv.first*320+nv.second]) continue;
			if(cur[nv.first*320+nv.second]>cur[pos.first*320+pos.second]+hypot(1.0,(double)i)){
				cur[nv.first*320+nv.second]=cur[pos.first*320+pos.second]+hypot(1.0,(double)i);
				que.push(make_pair(cur[nv.first*320+nv.second],nv));
			}
		}
		for(int i=-300;i<=300;i++){
			if(hash==0 && i!=0 && i!=-1) continue;
			if(hash==1 && i!=0 && i!=1) continue;
			pair<int,int> nv=make_pair(pos.first+i,pos.second+1);
			if(nv.first<0 || nv.first>=320 || nv.second<0 || nv.second>=320) continue;
			if(conf[nv.first*320+nv.second]) continue;
			if(cur[nv.first*320+nv.second]>cur[pos.first*320+pos.second]+hypot(1.0,(double)i)){
				cur[nv.first*320+nv.second]=cur[pos.first*320+pos.second]+hypot(1.0,(double)i);
				que.push(make_pair(cur[nv.first*320+nv.second],nv));
			}
		}
		for(int i=-300;i<=300;i++){
			if(hash==2 && i!=0 && i!=-1) continue;
			if(hash==3 && i!=0 && i!=1) continue;
			pair<int,int> nv=make_pair(pos.first+i,pos.second-1);
			if(nv.first<0 || nv.first>=320 || nv.second<0 || nv.second>=320) continue;
			if(conf[nv.first*320+nv.second]) continue;
			if(cur[nv.first*320+nv.second]>cur[pos.first*320+pos.second]+hypot(1.0,(double)i)){
				cur[nv.first*320+nv.second]=cur[pos.first*320+pos.second]+hypot(1.0,(double)i);
				que.push(make_pair(cur[nv.first*320+nv.second],nv));
			}
		}
		*/
	}
	cout << fixed << setprecision(20);
	cout << dist[x1*320+y1] << '\n';
}
accuracy: 1
time_ms: 500
memory_kb: 3904
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...)
#endif

const int M = 305;
template <class T, class U>
T ceil(T x, U y) {
    return (x > 0 ? (x + y - 1) / y : x / y);
}

template <class T, class U>
T floor(T x, U y) {
    return (x > 0 ? x / y : (x - y + 1) / y);
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int x0, y0, x1, y1;
    cin >> x0 >> y0 >> x1 >> y1;
    // x0 <= x1 かつ y0 <= y1 になるように変数変換
    if (x0 > x1) {
        // x = -0.5 の軸中心に対称移動
        x0 = -(x0 + 1), x1 = -(x1 + 1);
        // 両方正になるように平行移動
        while (x0 < 0) x0 += 2, x1 += 2;
    }
    if (y0 > y1) {
        // y = -0.5 の軸中心に対称移動
        y0 = -(y0 + 1), y1 = -(y1 + 1);
        // 両方正になるように平行移動
        while (y0 < 0) y0 += 2, y1 += 2;
    }
    // 偶数長の平行移動を行う
    debug(x0, y0, x1, y1);
    array<array<double, M>, M> dist;
    for (int i = 0; i < M; i++) {
        for (int j = 0; j < M; j++) dist[i][j] = M * M;
    }
    dist[x0][y0] = 0;
    for (int i = 0; i < M; i++) {
        for (int j = 0; j < M; j++) {
            if (i + 1 < M) {
                dist[i + 1][j] = min(dist[i + 1][j], dist[i][j] + 1);
            }
            if (j + 1 < M) {
                dist[i][j + 1] = min(dist[i][j + 1], dist[i][j] + 1);
            }
            // 斜め
            if (i & 1) {
                // (i, j) -> (i + 1, k)
                for (int k = j + 1; k < M; k++) {
                    dist[i + 1][k] = min(dist[i + 1][k], dist[i][j] + hypot(1, k - j));
                }
            }
            if (j & 1) {
                // (i, j) -> (k, j + 1)
                for (int k = i + 1; k < M; k++) {
                    dist[k][j + 1] = min(dist[k][j + 1], dist[i][j] + hypot(k - i, 1));
                }
            }
        }
    }

    cout << dist[x1][y1] << '\n';
}
accuracy: 1
time_ms: 70
memory_kb: 4608
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...)
#endif

const int M = 305;
template <class T, class U>
T ceil(T x, U y) {
    return (x > 0 ? (x + y - 1) / y : x / y);
}

template <class T, class U>
T floor(T x, U y) {
    return (x > 0 ? x / y : (x - y + 1) / y);
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int x0, y0, x1, y1;
    cin >> x0 >> y0 >> x1 >> y1;
    // x0 <= x1 かつ y0 <= y1 になるように変数変換
    if (x0 > x1) {
        // 反転させる
        x0 *= -1, x1 *= -1;
        // 両方正になるように平行移動
        while (x0 < 0) x0 += 2, x1 += 2;
    }
    if (y0 > y1) {
        // 反転させる
        y0 *= -1, y1 *= -1;
        // 両方正になるように平行移動
        while (y0 < 0) y0 += 2, y1 += 2;
    }
    // 偶数長の平行移動を行う
    debug(x0, y0, x1, y1);
    array<array<double, M>, M> dist;
    for (int i = 0; i < M; i++) {
        for (int j = 0; j < M; j++) dist[i][j] = M * M;
    }
    dist[x0][y0] = 0;
    for (int i = 0; i < M; i++) {
        for (int j = 0; j < M; j++) {
            if (i + 1 < M) {
                dist[i + 1][j] = min(dist[i + 1][j], dist[i][j] + 1);
            }
            if (j + 1 < M) {
                dist[i][j + 1] = min(dist[i][j + 1], dist[i][j] + 1);
            }
            // 斜め
            if (i & 1) {
                // (i, j) -> (i + 1, k)
                for (int k = j + 1; k < M; k++) {
                    dist[i + 1][k] = min(dist[i + 1][k], dist[i][j] + hypot(1, k - j));
                }
            }
            if (j & 1) {
                // (i, j) -> (k, j + 1)
                for (int k = i + 1; k < M; k++) {
                    dist[k][j + 1] = min(dist[k][j + 1], dist[i][j] + hypot(k - i, 1));
                }
            }
        }
    }

    cout << dist[x1][y1] << '\n';
}
accuracy: 0.5625
time_ms: 60
memory_kb: 4608
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...)
#endif

const int M = 305;
template <class T, class U>
T ceil(T x, U y) {
    return (x > 0 ? (x + y - 1) / y : x / y);
}

template <class T, class U>
T floor(T x, U y) {
    return (x > 0 ? x / y : (x - y + 1) / y);
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int x0, y0, x1, y1;
    cin >> x0 >> y0 >> x1 >> y1;
    // x0 <= x1 かつ y0 <= y1 になるように変数変換
    // (-0.5, -0.5) が対称軸
    // 2 倍に拡大 -> -1 移動 -> 2 倍縮小 (負の方向に丸める)
    if (x0 > x1) {
        x0 = -(x0 * 2 + 2), x1 = -(x1 * 2 + 2);
        x0 = floor(x0, 2), x1 = floor(x1, 2);
        x1 -= x0 - (x0 & 1), x0 = x0 & 1;
    }
    if (y0 > y1) {
        y0 = -(y0 * 2 + 2), y1 = -(y1 * 2 + 2);
        y0 = floor(y0, 2), y1 = floor(y1, 2);
        y1 -= y0 - (y0 & 1), y0 = y0 & 1;
    }
    // 偶数長の平行移動を行う
    debug(x0, y0, x1, y1);
    array<array<double, M>, M> dist;
    for (int i = 0; i < M; i++) {
        for (int j = 0; j < M; j++) dist[i][j] = M * M;
    }
    dist[x0][y0] = 0;
    for (int i = 0; i < M; i++) {
        for (int j = 0; j < M; j++) {
            if (i + 1 < M) {
                dist[i + 1][j] = min(dist[i + 1][j], dist[i][j] + 1);
            }
            if (j + 1 < M) {
                dist[i][j + 1] = min(dist[i][j + 1], dist[i][j] + 1);
            }
            // 斜め
            if (i & 1) {
                // (i, j) -> (i + 1, k)
                for (int k = j + 1; k < M; k++) {
                    dist[i + 1][k] = min(dist[i + 1][k], dist[i][j] + hypot(1, k - j));
                }
            }
            if (j & 1) {
                // (i, j) -> (k, j + 1)
                for (int k = i + 1; k < M; k++) {
                    dist[k][j + 1] = min(dist[k][j + 1], dist[i][j] + hypot(k - i, 1));
                }
            }
        }
    }

    cout << dist[x1][y1] << '\n';
}
accuracy: 1
time_ms: 60
memory_kb: 4608
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...)
#endif

const int M = 305;
template <class T, class U>
T ceil(T x, U y) {
    return (x > 0 ? (x + y - 1) / y : x / y);
}

template <class T, class U>
T floor(T x, U y) {
    return (x > 0 ? x / y : (x - y + 1) / y);
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int x0, y0, x1, y1;
    cin >> x0 >> y0 >> x1 >> y1;
    // x0 <= x1 かつ y0 <= y1 になるように変数変換
    // (-0.5, -0.5) が対称軸
    // 2 倍に拡大 -> -1 移動 -> 2 倍縮小 (負の方向に丸める)
    if (x0 > x1) {
        x0 = -(x0 * 2 + 2), x1 = -(x1 * 2 + 2);
        x0 = floor(x0, 2), x1 = floor(x1, 2);
    }
    if (y0 > y1) {
        swap(x0, x1);
        swap(y0, y1);
    }
    // 偶数長の平行移動を行う
    x1 -= x0 - (x0 & 1), x0 = x0 & 1, y1 -= y0 - (y0 & 1), y0 = y0 & 1;
    debug(x0, y0, x1, y1);
    array<array<double, M>, M> dist;
    for (int i = 0; i < M; i++) {
        for (int j = 0; j < M; j++) dist[i][j] = M * M;
    }
    dist[x0][y0] = 0;
    for (int i = 0; i < M; i++) {
        for (int j = 0; j < M; j++) {
            if (i + 1 < M) {
                dist[i + 1][j] = min(dist[i + 1][j], dist[i][j] + 1);
            }
            if (j + 1 < M) {
                dist[i][j + 1] = min(dist[i][j + 1], dist[i][j] + 1);
            }
            // 斜め
            if (i & 1) {
                // (i, j) -> (i + 1, k)
                for (int k = j + 1; k < M; k++) {
                    dist[i + 1][k] = min(dist[i + 1][k], dist[i][j] + hypot(1, k - j));
                }
            }
            if (j & 1) {
                // (i, j) -> (k, j + 1)
                for (int k = i + 1; k < M; k++) {
                    dist[k][j + 1] = min(dist[k][j + 1], dist[i][j] + hypot(k - i, 1));
                }
            }
        }
    }

    cout << dist[x1][y1] << '\n';
}
accuracy: 0.9375
time_ms: 60
memory_kb: 4608
final_rank: 8