CF846D.Monitor

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Recently Luba bought a monitor. Monitor is a rectangular matrix of size n × m. But then she started to notice that some pixels cease to work properly. Luba thinks that the monitor will become broken the first moment when it contains a square k × k consisting entirely of broken pixels. She knows that q pixels are already broken, and for each of them she knows the moment when it stopped working. Help Luba to determine when the monitor became broken (or tell that it's still not broken even after all q pixels stopped working).

最近,Luba 购买了一台显示器。该显示器是一个大小为 n×mn \times m 的矩形矩阵。但随后她开始注意到,某些像素点逐渐无法正常工作。Luba 认为:当显示器中首次出现一个完全由坏点组成的 k×kk \times k 正方形区域时,显示器即宣告损坏。她已知共有 qq 个像素点已经损坏,并且对每个坏点,她都知晓其失效的具体时刻。请帮助 Luba 判断显示器在何时损坏(或者说明:即使全部 qq 个像素点均已失效,显示器仍未损坏)。

输入格式

The first line contains four integer numbers n, m, k, q (1 ≤ n, m ≤ 500, 1 ≤ k ≤ min(n, m), 0 ≤ q ≤ n·m) — the length and width of the monitor, the size of a rectangle such that the monitor is broken if there is a broken rectangle with this size, and the number of broken pixels.

Each of next q lines contain three integer numbers x__i, y__i, t__i (1 ≤ x__i ≤ n, 1 ≤ y__i ≤ m, 0 ≤ t ≤ 109) — coordinates of i-th broken pixel (its row and column in matrix) and the moment it stopped working. Each pixel is listed at most once.

We consider that pixel is already broken at moment t__i.

第一行包含四个整数 nn、mm、kk、qq(1≤n,m≤5001 \le n, m \le 500,1≤k≤min⁡(n,m)1 \le k \le \min(n, m),0≤q≤n⋅m0 \le q \le n \cdot m)—— 分别表示显示器的长与宽、导致显示器损坏的破损矩形的尺寸(即若存在一个大小为 k×kk \times k 的全破损矩形,则显示器损坏),以及破损像素的数量。

接下来的 qq 行,每行包含三个整数 xix_i、yiy_i、tit_i(1≤xi≤n1 \le x_i \le n,1≤yi≤m1 \le y_i \le m,0≤ti≤1090 \le t_i \le 10^9)—— 表示第 ii 个破损像素的坐标(其在矩阵中的行号与列号)及其失效时刻。每个像素至多被列出一次。

我们认为像素在时刻 tit_i 已经处于破损状态。

输出格式

Print one number — the minimum moment the monitor became broken, or "-1" if it's still not broken after these q pixels stopped working.

输出一个数字——显示器发生故障的最早时刻;如果在这些 qq 个像素停止工作后显示器仍未损坏,则输出 "-1"。

输入输出样例

  • 输入#1

    2 3 2 5
    2 1 8
    2 2 8
    1 2 1
    1 3 4
    2 3 2

    输出#1

    8
  • 输入#2

    3 3 2 5
    1 2 2
    2 2 1
    2 3 5
    3 2 10
    2 1 100

    输出#2

    -1

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

首页