#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>
#include <deque>
#include <utility>
#include <bitset>
#include <limits.h>
#include <time.h>
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef double lf;
typedef unsigned int uint;
typedef long double llf;
typedef pair<int, int> pii;
const int N_ = 1005, M_ = 1005;
int N, M, K;
int A[N_][M_];
int P[N_*M_], PN;
int res1, res2;
int H[M_];
struct state {
int x, h;
state(int x = 0, int h = 0): x(x), h(h) { }
};
state Stk[M_];
int tp;
int get (int h) {
int ret = 0;
for(int j = 1; j <= M; j++) H[j] = 0;
for(int i = 1; i <= N; i++) {
for(int j = 1; j <= M; j++) if(A[i][j] >= h) ++H[j]; else H[j] = 0;
tp = 0;
for(int j = 1; j <= M+1; j++) {
int x = j;
while(tp > 0 && Stk[tp].h > H[j]) {
x = Stk[tp].x;
ret = max(ret, Stk[tp].h * (j - x));
--tp;
}
if(j <= M && H[j] > 0) {
Stk[++tp] = state(x, H[j]);
ret = max(ret, H[j]);
}
}
}
return ret;
}
int main() {
int i, j, k;
scanf("%d%d%d", &N, &M, &K);
for(i = 1; i <= N; i++) {
for(j = 1; j <= M; j++) {
scanf("%d", &A[i][j]);
P[++PN] = A[i][j];
}
}
sort(P+1, P+PN+1);
PN = unique(P+1, P+PN+1) - (P+1);
int low = 1, high = PN;
while(low <= high) {
int mid = (low + high) >> 1;
int area = get(P[mid]);
if(area >= K) {
res1 = P[mid]; res2 = area;
low = mid + 1;
}else {
high = mid - 1;
}
}
printf("%d %d\n", res1, res2);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
8988 KB |
Output is correct |
2 |
Correct |
0 ms |
8988 KB |
Output is correct |
3 |
Correct |
0 ms |
8988 KB |
Output is correct |
4 |
Correct |
0 ms |
8988 KB |
Output is correct |
5 |
Correct |
0 ms |
8988 KB |
Output is correct |
6 |
Correct |
0 ms |
8988 KB |
Output is correct |
7 |
Correct |
0 ms |
8988 KB |
Output is correct |
8 |
Correct |
0 ms |
8988 KB |
Output is correct |
9 |
Correct |
4 ms |
8988 KB |
Output is correct |
10 |
Correct |
12 ms |
8988 KB |
Output is correct |
11 |
Correct |
28 ms |
8988 KB |
Output is correct |
12 |
Correct |
12 ms |
8988 KB |
Output is correct |
13 |
Correct |
16 ms |
8988 KB |
Output is correct |
14 |
Correct |
44 ms |
8988 KB |
Output is correct |
15 |
Correct |
48 ms |
8988 KB |
Output is correct |
16 |
Correct |
68 ms |
8988 KB |
Output is correct |
17 |
Correct |
48 ms |
8988 KB |
Output is correct |
18 |
Correct |
148 ms |
8988 KB |
Output is correct |
19 |
Correct |
168 ms |
8988 KB |
Output is correct |
20 |
Correct |
328 ms |
8988 KB |
Output is correct |
21 |
Correct |
368 ms |
8988 KB |
Output is correct |
22 |
Correct |
468 ms |
8988 KB |
Output is correct |
23 |
Correct |
480 ms |
8988 KB |
Output is correct |
24 |
Correct |
244 ms |
8988 KB |
Output is correct |
25 |
Correct |
228 ms |
8988 KB |
Output is correct |