CF123B.Squares

普及+/提高

通过率:0%

时间限制:0.50s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an infinite checkered field. You should get from a square (_x_1; _y_1) to a square (_x_2; _y_2). Using the shortest path is not necessary. You can move on the field squares in four directions. That is, when you are positioned in any square, you can move to any other side-neighboring one.

A square (x; y) is considered bad, if at least one of the two conditions is fulfilled:

  • |x + y| ≡ 0 (mod 2_a_),
  • |x - y| ≡ 0 (mod 2_b_).

Your task is to find the minimum number of bad cells one will have to visit on the way from (_x_1; _y_1) to (_x_2; _y_2).

你被给定一个无限的方格网格。你需要从方格 (x1,y1)(x_1, y_1) 到达方格 (x2,y2)(x_2, y_2)。不必走最短路径。你可以在网格上沿四个方向(上、下、左、右)移动,即:当你位于任意一个方格时,你可以移动到与其任意一条边相邻的方格。

若方格 (x,y)(x, y) 满足以下两个条件中的至少一个,则称其为坏方格:

  • ∣x+y∣≡0(mod2a)|x + y| \equiv 0 \pmod{2^a},
  • ∣x−y∣≡0(mod2b)|x - y| \equiv 0 \pmod{2^b}.

你的任务是:求出从 (x1,y1)(x_1, y_1) 到 (x2,y2)(x_2, y_2) 的某条路径中,必须经过的坏方格的最少数量。

输入格式

The only line contains integers a, b, _x_1, _y_1, _x_2 and _y_2 — the parameters of the bad squares, the coordinates of the initial and the final squares correspondingly (2 ≤ a, b ≤ 109 and |_x_1|,|_y_1|,|_x_2|,|_y_2| ≤ 109). It is guaranteed that the initial and the final square aren't bad.

唯一一行包含整数 aa、bb、x1x_1、y1y_1、x2x_2 和 y2y_2 —— 分别为坏格子的参数,以及起点格子和终点格子的坐标(满足 2 ≤ a, b ≤ 1092 \le a, b \le 10^9 且 ∣x1∣,∣y1∣,∣x2∣,∣y2∣ ≤ 109|x_1|,|y_1|,|x_2|,|y_2| \le 10^9)。保证起点格子和终点格子均非坏格子。

输出格式

Print a single number — the minimum number of bad cells that one will have to visit in order to travel from square (_x_1; _y_1) to square (_x_2; _y_2).

输出一个整数——从方格 (x1,y1)(x_1, y_1) 到方格 (x2,y2)(x_2, y_2) 的路径中必须经过的坏方格的最小数量。

输入输出样例

  • 输入#1

    2 2 1 0 0 1

    输出#1

    1
  • 输入#2

    2 2 10 11 0 1

    输出#2

    5
  • 输入#3

    2 4 3 -1 3 7

    输出#3

    2

说明/提示

In the third sample one of the possible paths in (3;-1)->(3;0)->(3;1)->(3;2)->(4;2)->(4;3)->(4;4)->(4;5)->(4;6)->(4;7)->(3;7). Squares (3;1) and (4;4) are bad.

在第三个样例中,一条可能的路径为 (3;−1)→(3;0)→(3;1)→(3;2)→(4;2)→(4;3)→(4;4)→(4;5)→(4;6)→(4;7)→(3;7)(3;-1)\to(3;0)\to(3;1)\to(3;2)\to(4;2)\to(4;3)\to(4;4)\to(4;5)\to(4;6)\to(4;7)\to(3;7)。格子 (3;1)(3;1) 和 (4;4)(4;4) 是坏格子。

输入解题思路,AI测评打分。不知道怎么写?

首页