# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
895255 | Andrey | Luxury burrow (IZhO13_burrow) | C++14 | 877 ms | 18168 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;
int n,m;
int table[1001][1001];
int wow[1001][1001];
int solve(int col) {
long long big = 0,a;
vector<long long> haha(m);
vector<long long> ans(m,1);
for(long long i = 0; i < m; i++) {
haha[i] = table[col][i];
}
stack<pair<long long,long long>> idk;
idk.push({-1,-1});
for(long long i = 0; i < m; i++) {
a = haha[i];
while(a <= idk.top().first) {
idk.pop();
}
ans[i]+=i-idk.top().second-1;
idk.push({a,i});
}
while(!idk.empty()) {
idk.pop();
}
idk.push({-1,m});
for(long long i = m-1; i >= 0; i--) {
a = haha[i];
while(a <= idk.top().first) {
idk.pop();
}
ans[i]+=idk.top().second-i-1;
idk.push({a,i});
}
for(long long i = 0; i < m; i++) {
big = max(big,haha[i]*ans[i]);
}
return big;
}
int calc(int a) {
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
if(wow[i][j] >= a) {
table[i][j] = 1;
}
else {
table[i][j] = 0;
}
}
}
for(int i = 1; i < n; i++) {
for(int j = 0; j < m; j++) {
if(table[i][j] == 1) {
table[i][j] = table[i-1][j]+1;
}
}
}
int ans = 0;
for(int i = 0; i < n; i++) {
ans = max(ans,solve(i));
}
return ans;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int k;
cin >> n >> m >> k;
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
cin >> wow[i][j];
}
}
int l = 0,r = 1e9;
while(l < r) {
int mid = (l+r+1)/2;
if(calc(mid) >= k) {
l = mid;
}
else {
r = mid-1;
}
}
cout << l << " " << calc(l);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |