QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 64 MB Total points: 100

#13174. 购买地块

Statistics

Byteasar 打算购买一块工业用地。他的资产估计为 $k$ 拜塔勒(bythalers),这也是 Byteasar 想要花费的金额。然而,找到一块价值正好为 $k$ 拜塔勒的地块并非易事。因此,Byteasar 准备购买一块更贵的地块。他考虑申请贷款。Byteotian 信贷银行最多可以向他提供 $k$ 拜塔勒的贷款。因此,Byteasar 在地块上的花费不能超过 $2k$ 拜塔勒,且他希望花费不少于 $k$ 拜塔勒。

Byteasar 想要购买地块的区域是一个边长为 $n$ 米的正方形。目前的土地所有者设定了不同的每平方米价格。Byteasar 与他们每个人都谈过,并准备了一份该区域的价格地图。地图描绘了每一个 $1 \times 1$ 米小方格的价格。显然,共有 $n^2$ 个这样的小方格。现在是寻找理想地块的时候了。它必须是矩形的,且由完整的单位小方格组成。Byteasar 已经在地图上寻找地块,但在花费了许多小时后,他仍然无法找到合适的地块。请帮帮他!

编写一个程序:

  • 从标准输入读取 $k$ 和 $n$,以及该区域的价格地图,
  • 确定一个价格在区间 $[k, 2k]$ 内的地块,或者指出不存在这样的地块,
  • 将结果输出到标准输出。

输入格式

第一行包含两个整数 $k$ 和 $n$,由一个空格分隔,$1 \le k \le 1\,000\,000\,000$,$1 \le n \le 2\,000$。接下来的 $n$ 行,每行包含 $n$ 个非负整数,由空格分隔。第 $j+1$ 行的第 $i$ 个数字表示坐标为 $(i, j)$ 的单位小方格的价格。每个单位小方格的价格不超过 $2\,000\,000\,000$ 拜塔勒。

输出格式

如果不存在价格在区间 $[k, 2k]$ 内的地块,程序应输出一行,内容为 NIE(波兰语中的“不”)。否则,输出一行,包含四个正整数 $x_1, y_1, x_2, y_2$,由空格分隔,表示矩形的坐标。$(x_1, y_1)$ 表示矩形的左上角坐标,$(x_2, y_2)$ 表示右下角坐标。该矩形由满足 $\{(x, y) \mid x_1 \le x \le x_2 \text{ 且 } y_1 \le y \le y_2\}$ 的小方格组成。构成该矩形的小方格价格总和 $c$ 应满足不等式 $k \le c \le 2k$。如果存在多个满足条件的矩形地块,任选一个即可。

样例

样例输入 1

4 3
1 1 1
1 9 1
1 1 1

样例输出 1

NIE

样例输入 2

8 4
1 2 1 3
25 1 2 1
4 20 3 3
3 30 12 2

样例输出 2

2 1 4 2

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.