#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#define N 1010
#define ff first
#define ss second
#define ll long long
#define pb push_back
#define mod 1000000007
#define pii pair <int, int>
using namespace std;
int n, m, k;
int v[N][N];
int H[N][N];
pii p[N][N];
int main()
{
cin >> n >> m >> k;
for(int i = 1; i <= n; i++)
for(int h = 1; h <= m; h++)
cin >> v[i][h];
int l = 1, md, r = 1e9, ans, sz;
while(l <= r) {
md = (l+r)/2;
char c[N][N];
for(int i = 1; i <= n; i++)
for(int h = 1; h <= m; h++) {
c[i][h] = '0';
if(v[i][h] >= md) c[i][h] = '1';
}
for(int i = n; i >= 1; i--) {
memset(H[i], 0, sizeof(H[i]));
for(int h = 1; h <= m; h++) if(c[i][h] == '1') H[i][h] = H[i+1][h] + 1;
}
for(int i = 1; i <= n; i++) {
vector <int> E;
for(int h = 1; h <= m; h++) {
p[i][h] = {0, m};
while(!E.empty() && H[i][E.back()] > H[i][h]) {
p[i][E.back()].ss = h-1;
E.pop_back();
}
if(E.empty()) p[i][h].ff = 1;
else {
if(H[i][E.back()] == H[i][h]) p[i][h].ff = p[i][E.back()].ff;
else p[i][h].ff = E.back()+1;
}
E.pb(h);
}
}
int now = 0;
for(int i = 1; i <= n; i++)
for(int h = 1; h <= m; h++)
now = max(now, H[i][h] * (p[i][h].ss - p[i][h].ff + 1));
if(now >= k) {
ans = md, sz = now;
l = md+1;
} else r = md-1;
}
cout << ans << " " << sz;
}
/*
3 3 3
1 1 1
1 2 2
1 2 2
1 10 5
4 3 2 5 10 7 6 5 1 100
3 5 2
5 7 5 5 5
8 5 5 7 5
8 5 8 8 8
*/
Compilation message
burrow.cpp: In function 'int main()':
burrow.cpp:84:24: warning: 'sz' may be used uninitialized in this function [-Wmaybe-uninitialized]
84 | cout << ans << " " << sz;
| ^~
burrow.cpp:84:17: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
84 | cout << ans << " " << sz;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
640 KB |
Output is correct |
5 |
Correct |
2 ms |
768 KB |
Output is correct |
6 |
Correct |
3 ms |
896 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
11 ms |
1792 KB |
Output is correct |
9 |
Correct |
24 ms |
3200 KB |
Output is correct |
10 |
Correct |
58 ms |
3576 KB |
Output is correct |
11 |
Correct |
92 ms |
4600 KB |
Output is correct |
12 |
Correct |
52 ms |
7288 KB |
Output is correct |
13 |
Correct |
71 ms |
2552 KB |
Output is correct |
14 |
Correct |
148 ms |
7288 KB |
Output is correct |
15 |
Correct |
147 ms |
7400 KB |
Output is correct |
16 |
Correct |
184 ms |
7892 KB |
Output is correct |
17 |
Correct |
172 ms |
9208 KB |
Output is correct |
18 |
Correct |
454 ms |
13304 KB |
Output is correct |
19 |
Correct |
437 ms |
13944 KB |
Output is correct |
20 |
Correct |
917 ms |
19552 KB |
Output is correct |
21 |
Correct |
972 ms |
21752 KB |
Output is correct |
22 |
Correct |
1310 ms |
26876 KB |
Output is correct |
23 |
Correct |
1347 ms |
26836 KB |
Output is correct |
24 |
Correct |
682 ms |
19320 KB |
Output is correct |
25 |
Correct |
719 ms |
20088 KB |
Output is correct |