#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
int n,m,k,ans2;
int inp[1010][1010];
int tmp[1010][1010];
typedef pair<int,int> Pi;
#define X first
#define Y second
vector <Pi> v;
bool check(int x)
{
if(x==5){
x++;
x--;
}
int i,j;
for(i=0;i<n;i++){
tmp[i][0]=0;
for(j=1;j<m;j++)
if(inp[i][j]>=x)tmp[i][j]=tmp[i][j-1]+1;
else tmp[i][j]=0;
}
int mx = 0;
for(j=0;j<m;j++){
v.clear();
for(i=0;i<=n;i++){
int a = i;
while(!v.empty() && v.back().Y >= tmp[i][j]){
a=v.back().X;
mx = max(mx,v.back().Y * (i - a));
v.pop_back();
}
v.push_back(Pi(a,tmp[i][j]));
}
}
if(mx>=k){ans2=mx;return true;}
return false;
}
int main(){
scanf("%d%d%d",&n,&m,&k);
int i,j;
for(i=0;i<n;i++){
for(j=0;j<m;j++)scanf("%d",inp[i]+j);
}
int st=1,en=1e9,mi,ans;
while(st<=en){
mi = (st+en)>>1;
if(check(mi))st=mi+1,ans=mi;
else en=mi-1;
}
printf("%d %d",ans,ans2);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
9176 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
9176 KB |
Output isn't correct |
3 |
Correct |
0 ms |
9176 KB |
Output is correct |
4 |
Correct |
0 ms |
9176 KB |
Output is correct |
5 |
Correct |
0 ms |
9176 KB |
Output is correct |
6 |
Correct |
0 ms |
9176 KB |
Output is correct |
7 |
Correct |
0 ms |
9176 KB |
Output is correct |
8 |
Correct |
4 ms |
9176 KB |
Output is correct |
9 |
Correct |
8 ms |
9176 KB |
Output is correct |
10 |
Correct |
28 ms |
9176 KB |
Output is correct |
11 |
Correct |
56 ms |
9176 KB |
Output is correct |
12 |
Correct |
36 ms |
9176 KB |
Output is correct |
13 |
Correct |
40 ms |
9176 KB |
Output is correct |
14 |
Correct |
108 ms |
9176 KB |
Output is correct |
15 |
Correct |
112 ms |
9176 KB |
Output is correct |
16 |
Correct |
116 ms |
9176 KB |
Output is correct |
17 |
Correct |
148 ms |
9176 KB |
Output is correct |
18 |
Correct |
288 ms |
9176 KB |
Output is correct |
19 |
Correct |
380 ms |
9176 KB |
Output is correct |
20 |
Correct |
620 ms |
9176 KB |
Output is correct |
21 |
Correct |
664 ms |
9176 KB |
Output is correct |
22 |
Incorrect |
860 ms |
9176 KB |
Output isn't correct |
23 |
Correct |
916 ms |
9176 KB |
Output is correct |
24 |
Correct |
636 ms |
9176 KB |
Output is correct |
25 |
Correct |
792 ms |
9176 KB |
Output is correct |