CF1493F.Enchanted Matrix

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

This is an interactive problem.

There exists a matrix aa of size n×mn \times m (nn rows and mm columns), you know only numbers nn and mm. The rows of the matrix are numbered from 11 to nn from top to bottom, and columns of the matrix are numbered from 11 to mm from left to right. The cell on the intersection of the xx-th row and the yy-th column is denoted as (x,y)(x, y).

You are asked to find the number of pairs (r,c)(r, c) (1≤r≤n1 \le r \le n, 1≤c≤m1 \le c \le m, rr is a divisor of nn, cc is a divisor of mm) such that if we split the matrix into rectangles of size r×cr \times c (of height rr rows and of width cc columns, each cell belongs to exactly one rectangle), all those rectangles are pairwise equal.

You can use queries of the following type:

  • ? hh ww i1i_1 j1j_1 i2i_2 j2j_2 (1≤h≤n1 \le h \le n, 1≤w≤m1 \le w \le m, 1≤i1,i2≤n1 \le i_1, i_2 \le n, 1≤j1,j2≤m1 \le j_1, j_2 \le m) — to check if non-overlapping subrectangles of height hh rows and of width ww columns of matrix aa are equal or not. The upper left corner of the first rectangle is (i1,j1)(i_1, j_1). The upper left corner of the second rectangle is (i2,j2)(i_2, j_2). Subrectangles overlap, if they have at least one mutual cell. If the subrectangles in your query have incorrect coordinates (for example, they go beyond the boundaries of the matrix) or overlap, your solution will be considered incorrect.

You can use at most $ 3 \cdot \left \lfloor{ \log_2{(n+m)} } \right \rfloor$ queries. All elements of the matrix aa are fixed before the start of your program and do not depend on your queries.

这是一个交互式问题。

存在一个大小为 n×mn \times m 的矩阵 aa(共 nn 行、mm 列),你仅知道 nn 和 mm 这两个数。矩阵的行从上到下编号为 11 至 nn,列从左到右编号为 11 至 mm。第 xx 行与第 yy 列交叉处的单元格记作 (x,y)(x, y)。

你需要求出满足如下条件的数对 (r,c)(r, c) 的个数(其中 1≤r≤n1 \le r \le n,1≤c≤m1 \le c \le m,且 rr 是 nn 的约数、cc 是 mm 的约数):若将矩阵划分为若干个大小为 r×cr \times c 的矩形(每个矩形高 rr 行、宽 cc 列,且每个单元格恰好属于一个矩形),则所有这些矩形两两相等。

你可以使用如下类型的查询:

  • ? hh ww i1i_1 j1j_1 i2i_2 j2j_2(其中 1≤h≤n1 \le h \le n,1≤w≤m1 \le w \le m,1≤i1,i2≤n1 \le i_1, i_2 \le n,1≤j1,j2≤m1 \le j_1, j_2 \le m)—— 用于判断矩阵 aa 中两个高为 hh 行、宽为 ww 列的不重叠子矩形是否相等。第一个子矩形的左上角为 (i1,j1)(i_1, j_1),第二个子矩形的左上角为 (i2,j2)(i_2, j_2)。当两个子矩形至少有一个公共单元格时,称它们重叠。若你在查询中给出的子矩形坐标不合法(例如超出矩阵边界)或彼此重叠,则你的解法将被判为错误。

你最多可进行 $ 3 \cdot \left \lfloor{ \log_2{(n+m)} } \right \rfloor$ 次查询。矩阵 aa 的所有元素在你的程序开始运行前即已固定,且不依赖于你的任何查询。

输入格式

The first line contains two integers nn and mm (1≤n,m≤10001 \le n, m \le 1000) — the number of rows and columns, respectively.

第一行包含两个整数 nn 和 mm(1≤n,m≤10001 \le n, m \le 1000),分别表示行数和列数。

输出格式

When ready, print a line with an exclamation mark ('!') and then the answer — the number of suitable pairs (r,c)(r, c). After that your program should terminate.

准备就绪后,输出一行,包含一个感叹号('!')以及答案——即满足条件的数对 (r,c)(r, c) 的数量。之后,你的程序应终止。

输入输出样例

  • 输入#1

    3 4
    1
    1
    1
    0

    输出#1

    ? 1 2 1 1 1 3
    ? 1 2 2 1 2 3
    ? 1 2 3 1 3 3
    ? 1 1 1 1 1 2
    ! 2

说明/提示

In the example test the matrix aa of size 3×43 \times 4 is equal to:

1 2 1 2
3 3 3 3
2 1 2 1

在样例测试中,3×43 \times 4 的矩阵 aa 为:

1 2 1 2
3 3 3 3
2 1 2 1

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

首页