Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <cstdio>
- #include <iostream>
- using namespace std;
- #define ABS(a) ((a) < 0 ? -(a) : (a))
- int main () {
- int n, x1, y1, x2, y2;
- scanf ("%d %d %d %d %d", &n, &x1, &y1, &x2, &y2);
- if (y1 == 0 && y2 == n || y1 == n && y2 == 0) {
- printf ("%d", n + min (x1 + x2, n - x1 + n - x2));
- } else if (x1 == 0 && x2 == n || x1 == n && x2 == 0) {
- printf ("%d", n + min (y1 + y2, n - y1 + n - y2));
- } else {
- printf ("%d", ABS(x1-x2) + ABS(y1-y2));
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement