# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
47557 | JohnTitor | Luxury burrow (IZhO13_burrow) | C++11 | 632 ms | 12488 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=(j); i<=(k); i++)
#define FFOR(i, j, k) for(int i=(j); i<(k); i++)
#define DFOR(i, j, k) for(int i=(j); i>=(k); i--)
#define bug(x) cerr<<#x<<" = "<<(x)<<'\n'
#define pb push_back
#define mp make_pair
#define setbit(s, i) (s|=(1LL<<(i)))
#define bit(s, i) (((s)>>(i))&1LL)
#define mask(i) ((1LL<<(i)))
#define builtin_popcount __builtin_popcountll
typedef long long ll;
typedef long double ld;
template <typename T> inline void read(T &x){
char c;
bool nega=0;
while((!isdigit(c=getchar()))&&(c!='-'));
if(c=='-'){
nega=1;
c=getchar();
}
x=c-48;
while(isdigit(c=getchar())) x=x*10+c-48;
if(nega) x=-x;
}
template <typename T> inline void writep(T x){
if(x>9) writep(x/10);
putchar(x%10+48);
}
template <typename T> inline void write(T x){
if(x<0){
putchar('-');
x=-x;
}
writep(x);
}
template <typename T> inline void writeln(T x){
write(x);
putchar('\n');
}
#define taskname "F"
int n, m, k;
int a[1001][1001];
int h[1001][1001];
int l[1001];
int r[1001];
vector <int> v;
int make(int c){
FOR(i, 1, n) FOR(j, 1, m) if(a[i][j]>=c) h[i][j]=h[i-1][j]+1; else h[i][j]=0;
int maxs=0;
deque <int> d;
FOR(i, 1, n){
d.clear();
FOR(j, 1, m){
while((!d.empty())&&(h[i][j]<=h[i][d.back()])) d.pop_back();
l[j]=(d.empty())?1:d.back()+1;
d.pb(j);
}
d.clear();
DFOR(j, m, 1){
while((!d.empty())&&(h[i][j]<=h[i][d.back()])) d.pop_back();
r[j]=(d.empty())?m:d.back()-1;
d.pb(j);
}
FOR(j, 1, m) maxs=max(maxs, h[i][j]*(r[j]-l[j]+1));
}
return maxs;
}
int main(){
#ifdef Kanikou
if(fopen(taskname".inp", "r"))
freopen(taskname".inp", "r", stdin);
#endif // Kanikou
read(n);
read(m);
read(k);
FOR(i, 1, n) FOR(j, 1, m){
read(a[i][j]);
v.pb(a[i][j]);
}
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
int low=0, high=v.size()-1, mid, ans, best, res;
while(low<=high){
mid=(low+high)/2;
res=make(v[mid]);
if(res>=k){
ans=v[mid];
best=res;
low=mid+1;
}
else high=mid-1;
}
write(ans);
putchar(' ');
write(best);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |