CF492E.Vanya and Field

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Vanya decided to walk in the field of size n × n cells. The field contains m apple trees, the i-th apple tree is at the cell with coordinates (x__i, y__i). Vanya moves towards vector (dx, dy). That means that if Vanya is now at the cell (x, y), then in a second he will be at cell . The following condition is satisfied for the vector: , where is the largest integer that divides both a and b. Vanya ends his path when he reaches the square he has already visited.

Vanya wonders, from what square of the field he should start his path to see as many apple trees as possible.

万尼亚决定在一块大小为 n×nn \times n 的方格场上行走。场上有 mm 棵苹果树,其中第 ii 棵苹果树位于坐标为 (xi, yi)(x_i,\, y_i) 的方格内。万尼亚沿向量 (dx, dy)(dx,\, dy) 移动。也就是说,若万尼亚当前位于方格 (x, y)(x,\, y),则一秒后他将到达方格
。
该向量满足如下条件:
,
其中 表示能同时整除 aa 和 bb 的最大整数(即 gcd⁡(a,b)\gcd(a,b))。
当万尼亚抵达一个他此前已访问过的方格时,其路径终止。

万尼亚想知道:他应从场上的哪一个方格出发,才能经过尽可能多的苹果树?

输入格式

The first line contains integers n, m, dx, dy(1 ≤ n ≤ 106, 1 ≤ m ≤ 105, 1 ≤ dx, dy ≤ n) — the size of the field, the number of apple trees and the vector of Vanya's movement. Next m lines contain integers x__i, y__i (0 ≤ x__i, y__i ≤ n - 1) — the coordinates of apples. One cell may contain multiple apple trees.

第一行包含整数 nn、mm、dxdx、dydy(1 ≤ n ≤ 1061 \le n \le 10^6,1 ≤ m ≤ 1051 \le m \le 10^5,1 ≤ dx, dy ≤ n1 \le dx, dy \le n)—— 分别表示场地的大小、苹果树的数量以及万尼亚移动的向量。接下来的 mm 行每行包含整数 xix_i、yiy_i(0 ≤ xi, yi ≤ n − 10 \le x_i, y_i \le n - 1)—— 表示苹果的坐标。一个格子中可能有多个苹果树。

输出格式

Print two space-separated numbers — the coordinates of the cell from which you should start your path. If there are several answers you are allowed to print any of them.

输出两个用空格分隔的数字——即你应从其中开始路径的单元格的坐标。如果存在多个答案,你可以输出其中任意一个。

输入输出样例

  • 输入#1

    5 5 2 3
    0 0
    1 2
    1 3
    2 4
    3 1

    输出#1

    1 3
  • 输入#2

    2 3 1 1
    0 0
    0 1
    1 1

    输出#2

    0 0

说明/提示

In the first sample Vanya's path will look like: (1, 3) - (3, 1) - (0, 4) - (2, 2) - (4, 0) - (1, 3)

In the second sample: (0, 0) - (1, 1) - (0, 0)

在第一个样例中,万尼亚的路径如下:(1, 3) − (3, 1) − (0, 4) − (2, 2) − (4, 0) − (1, 3)(1,\,3)\,-\,(3,\,1)\,-\,(0,\,4)\,-\,(2,\,2)\,-\,(4,\,0)\,-\,(1,\,3)

在第二个样例中:(0, 0) − (1, 1) − (0, 0)(0,\,0)\,-\,(1,\,1)\,-\,(0,\,0)

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

首页