Submission #338898

#TimeUsernameProblemLanguageResultExecution timeMemory
338898IZhO_2021_I_want_SilverLuxury burrow (IZhO13_burrow)C++14
100 / 100
796 ms14076 KiB
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <stack>
#include <queue>
#include <deque>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>-

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

// template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//  order_of_key (k) : Number of items strictly smaller than k .
//  find_by_order(k) : K-th element in a set (counting from zero).
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define show(a) cerr << #a <<" -> "<< a <<" "
#define nl cerr <<"\n"
//#define int ll

const int N = 1005;
const int oo = 1e9 + 5;

int n, m, k, a[N][N], h[N], l[N];
stack <int> st;

int check(int x) {
    for (int j = 1; j <= m; ++j) {  h[j] = 0; }

    int mx = 0;
    for (int i = 1; i <= n; ++i) {
        // l[j]
        while (sz(st)) { st.pop(); }
        st.push(0); h[0] = 0;
        for (int j = 1; j <= m; ++j) {
            if (a[i][j] >= x) { h[j] = h[j] + 1; }
            else { h[j] = 0; }

            while (sz(st) && h[st.top()] >= h[j]) { st.pop(); }
            if (sz(st)) { l[j] = st.top()+1; }
            st.push(j);
        }
        // r
        while (sz(st)) { st.pop(); }
        st.push(m+1); h[m+1] = 0;
        for (int j = m; j >= 1; --j) {
            while (sz(st) && h[st.top()] >= h[j]) { st.pop(); }
            if (sz(st)) {
                int r = st.top()-1;
                mx = max(mx, (r - l[j] + 1) * h[j]);
            }
            st.push(j);
        }
    }
    if (mx >= k) { return mx; }
    return 0;
}

void solve() {
    cin >> n >> m >> k;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            cin >> a[i][j];
        }
    }
    int l = 1, r = oo;
    while (l < r) {
        int mid = (l + r + 1) / 2;
        if (check(mid)) l = mid;
        else r = mid - 1;
    }
    cout << l <<" "<< check(l) <<"\n";

}

 main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int tests = 1;
	//cin >> tests;
	while (tests --) {
		solve();
	}
	return 0;
}
/*
    Just Chalish!
3 3 3
1 1 1
1 2 2
1 2 2
*/

Compilation message (stderr)

burrow.cpp:93:8: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   93 |  main () {
      |        ^
#Verdict Execution timeMemoryGrader output
Fetching results...