#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N, M, K;
cin >> N >> M >> K;
vector<vector<int>> A(N, vector<int>(M));
vector<int> sorted_vals(N * M);
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
cin >> A[i][j];
sorted_vals[i * M + j] = A[i][j];
}
}
sort(sorted_vals.begin(), sorted_vals.end());
vector<vector<int>> up(N, vector<int>(M));
vector<int> prv(M), nxt(M);
int L = -1, R = (int)sorted_vals.size();
int area;
while (R - L > 1) {
int mid = (L + R) / 2;
int pivot = sorted_vals[mid];
int max_area = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
up[i][j] = (A[i][j] >= pivot ? (i > 0 ? up[i - 1][j] : 0) + 1 : 0);
}
for (int j = 0; j < M; j++) {
prv[j] = j - 1;
while (prv[j] >= 0 && up[i][prv[j]] > up[i][j]) {
prv[j] = prv[prv[j]];
}
}
for (int j = M - 1; j >= 0; j--) {
nxt[j] = j + 1;
while (nxt[j] < M && up[i][nxt[j]] >= up[i][j]) {
nxt[j] = nxt[nxt[j]];
}
max_area = max(max_area, (nxt[j] - prv[j] - 1) * up[i][j]);
}
}
if (max_area >= K) {
L = mid;
area = max_area;
} else {
R = mid;
}
}
cout << sorted_vals[L] << " " << area << "\n";
}
Compilation message
burrow.cpp: In function 'int main()':
burrow.cpp:50:44: warning: 'area' may be used uninitialized in this function [-Wmaybe-uninitialized]
50 | cout << sorted_vals[L] << " " << area << "\n";
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
3 ms |
604 KB |
Output is correct |
9 |
Correct |
5 ms |
604 KB |
Output is correct |
10 |
Correct |
12 ms |
1104 KB |
Output is correct |
11 |
Correct |
19 ms |
1588 KB |
Output is correct |
12 |
Correct |
14 ms |
1116 KB |
Output is correct |
13 |
Correct |
19 ms |
1372 KB |
Output is correct |
14 |
Correct |
41 ms |
2952 KB |
Output is correct |
15 |
Correct |
50 ms |
2908 KB |
Output is correct |
16 |
Correct |
46 ms |
3420 KB |
Output is correct |
17 |
Correct |
49 ms |
3932 KB |
Output is correct |
18 |
Correct |
110 ms |
7508 KB |
Output is correct |
19 |
Correct |
172 ms |
8020 KB |
Output is correct |
20 |
Correct |
237 ms |
13396 KB |
Output is correct |
21 |
Correct |
248 ms |
16212 KB |
Output is correct |
22 |
Correct |
309 ms |
21884 KB |
Output is correct |
23 |
Correct |
317 ms |
21724 KB |
Output is correct |
24 |
Correct |
238 ms |
12116 KB |
Output is correct |
25 |
Correct |
264 ms |
15080 KB |
Output is correct |