#include #include #include using namespace std; struct Point { int x; int y; }; Point start = { 0, 0 }; Point goal; Point obst; int main(int argc, char *argv[]) { std::ios::sync_with_stdio(false); std::cin.tie(0); int cnt = 0; cin >> goal.x >> goal.y >> obst.x >> obst.y; /* 斜めに進んで残った分を真っすぐ進む */ if (goal.x >= goal.y) { cnt += goal.y + (goal.x - goal.y); } else { cnt += goal.x + (goal.y - goal.x); } /*斜めに進んで障害物にぶつかる場合はコスト+1(真っすぐ進む場合は変わらない)*/ if ((obst.x < goal.x) && (obst.y < goal.y)) { if (obst.x == obst.y) { cnt++; } } cout << cnt << endl; }