Submission #441223

#TimeUsernameProblemLanguageResultExecution timeMemory
441223parsabahramiLuxury burrow (IZhO13_burrow)C++17
100 / 100
566 ms17952 KiB
#include <bits/stdc++.h>
 
using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
 
#define SZ(x)                       (int) x.size()
#define F                           first
#define S                           second

const int N = 1e3 + 10, MOD = 1e9 + 7;
int A[N][N], L[N], R[N], up[N][N], n, k, m;

int get(int x) {
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (A[i][j] < x) { up[i][j] = 0; continue; }
            if (A[i - 1][j] >= x) up[i][j] = up[i - 1][j] + 1;
            else up[i][j] = 1;
        }
    }
    int ret = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            for (L[j] = j - 1; L[j] && up[i][L[j]] >= up[i][j]; L[j] = L[L[j]]);
        }
        for (int j = m; j; j--) {
            for (R[j] = j + 1; R[j] <= m && up[i][R[j]] >= up[i][j]; R[j] = R[R[j]]);
        }
        for (int j = 1; j <= m; j++) {
            ret = max(ret, up[i][j] * (R[j] - L[j] - 1));
        }
    }
    return ret;
}

int main() {
    scanf("%d%d%d", &n, &m, &k);
    for (int i = 1; i <= n; i++) 
        for (int j = 1; j <= m; j++) 
            scanf("%d", &A[i][j]);
    int l = 0, r = MOD;
    while (r - l > 1) {
        int md = (l + r) >> 1;
        if (get(md) < k) r = md;
        else l = md;
    }
    printf("%d %d\n", l, get(l));
    return 0;
}

Compilation message (stderr)

burrow.cpp: In function 'int main()':
burrow.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |     scanf("%d%d%d", &n, &m, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
burrow.cpp:42:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |             scanf("%d", &A[i][j]);
      |             ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...