Submission #170824

# Submission time Handle Problem Language Result Execution time Memory
170824 2019-12-26T13:03:49 Z davitmarg Luxury burrow (IZhO13_burrow) C++17
100 / 100
788 ms 18164 KB
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;

const int N = 1005;

int n, m, k, a[N][N], d[N][N];
int l, r, mid, ans;

int solve(int x)
{
    int res = 0;
    //cout << x << endl;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            if (a[i][j] >= x)
                d[i][j] = d[i - 1][j] + 1;
            else
                d[i][j] = 0;
            //cout << i << " : " << j << " = " << d[i][j] << endl;
        }
        vector<int> v, nxt(m + 5, m + 1), lst(m + 1, 0);
        for (int j = 1; j <= m; j++)
        {
            while (!v.empty() && d[i][v.back()] >= d[i][j])
                v.pop_back();
            if (!v.empty())
                lst[j] = v.back();
            lst[j]++;
            v.PB(j);
        }
        v.clear();
        for (int j = m; j >= 1; j--)
        {
            while (!v.empty() && d[i][v.back()] >= d[i][j])
                v.pop_back();
            if (!v.empty())
                nxt[j] = v.back();
            nxt[j]--;
            v.PB(j);
        }
        for (int j = 1; j <= m; j++)
        {
            res = max(d[i][j] * (nxt[j] - lst[j] + 1), res);
            //cout << i << " : " << j << " = " << lst[j] << " : " << nxt[j] << endl;
        }
    }
    return res;
}

int main()
{
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            scanf("%d", a[i] + j);
    l = 0;
    r = mod;
    while (l <= r)
    {
        mid = (l + r) / 2;
        if (solve(mid) >= k)
        {
            ans = mid;
            l = mid + 1;
        }
        else
        {
            r = mid - 1;
        }
    }
    cout << ans << " " << solve(ans) << endl;
    return 0;
}

/*

2 
2 0
3



*/

Compilation message

burrow.cpp: In function 'int main()':
burrow.cpp:79:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", a[i] + j);
             ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 4 ms 504 KB Output is correct
6 Correct 3 ms 636 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 10 ms 1144 KB Output is correct
9 Correct 16 ms 2040 KB Output is correct
10 Correct 46 ms 2296 KB Output is correct
11 Correct 63 ms 2936 KB Output is correct
12 Correct 39 ms 4472 KB Output is correct
13 Correct 48 ms 1528 KB Output is correct
14 Correct 108 ms 4088 KB Output is correct
15 Correct 111 ms 4088 KB Output is correct
16 Correct 120 ms 4600 KB Output is correct
17 Correct 135 ms 4956 KB Output is correct
18 Correct 293 ms 8032 KB Output is correct
19 Correct 337 ms 7672 KB Output is correct
20 Correct 683 ms 12280 KB Output is correct
21 Correct 615 ms 13724 KB Output is correct
22 Correct 761 ms 18164 KB Output is correct
23 Correct 788 ms 17912 KB Output is correct
24 Correct 536 ms 10872 KB Output is correct
25 Correct 576 ms 11128 KB Output is correct