Submission #490059

# Submission time Handle Problem Language Result Execution time Memory
490059 2021-11-25T11:15:03 Z Valera_Grinenko Luxury burrow (IZhO13_burrow) C++17
100 / 100
286 ms 13852 KB
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <cmath>
#include <queue>
#include <bitset>
#include <numeric>
#include <array>
#include <cstring>
#include <random>
#include <chrono>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template<class T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int main() {

  ios::sync_with_stdio(0); cin.tie(0);

  int n, m, k;

  cin >> n >> m >> k;

  vector<vector<int> > a(n, vector<int>(m));

  for(auto& x : a)
    for(auto& y : x)
      cin >> y;

  int l = 1, r = 1e9 + 42;

  while(l < r) {
    int mb = (l + r + 1) / 2;
    vector<int> cur(m);
    int mx = 0;
    for(int i = 0; i < n; i++) {
      for(int j = 0; j < m; j++) {
        if(a[i][j] >= mb) cur[j]++;
        else cur[j] = 0;
      }
      stack<int> st;
      int top = 0, ar = 0;
      int in = 0;
      while(in < m) {
        if(st.empty() || cur[st.top()] <= cur[in]) st.push(in++);
        else {
          top = cur[st.top()];
          st.pop();
          ar = top * in;
          if(!st.empty()) ar = top * (in - st.top() - 1);
          mx = max(mx, ar);
        }
      }
      while(!st.empty()) {
        top = cur[st.top()];
        st.pop();
        ar = top * in;
        if(!st.empty()) ar = top * (in - st.top() - 1);
        mx = max(mx, ar);
      }
    }
    if(mx >= k) l = mb;
    else r = mb - 1;
  }

  cout << l << ' ';

  vector<int> cur(m);

  int mx = 0;

  for(int i = 0; i < n; i++) {
    for(int j = 0; j < m; j++) {
      if(a[i][j] >= l) cur[j]++;
      else cur[j] = 0;
    }
    stack<int> st;
    int top = 0, ar = 0;
    int in = 0;
    while(in < m) {
      if(st.empty() || cur[st.top()] <= cur[in]) st.push(in++);
      else {
        top = cur[st.top()];
        st.pop();
        ar = top * in;
        if(!st.empty()) ar = top * (in - st.top() - 1);
        mx = max(mx, ar);
      }
    }
    while(!st.empty()) {
      top = cur[st.top()];
      st.pop();
      ar = top * in;
      if(!st.empty()) ar = top * (in - st.top() - 1);
      mx = max(mx, ar);
    }
  }

  cout << mx << '\n';

  return 0;
}
/*

*/

Compilation message

burrow.cpp:3: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    3 | #pragma GCC optimization ("unroll-loops")
      |
# Verdict Execution time Memory Grader output
1 Correct 1 ms 260 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 3 ms 336 KB Output is correct
9 Correct 5 ms 464 KB Output is correct
10 Correct 12 ms 720 KB Output is correct
11 Correct 23 ms 1180 KB Output is correct
12 Correct 11 ms 592 KB Output is correct
13 Correct 16 ms 964 KB Output is correct
14 Correct 40 ms 1488 KB Output is correct
15 Correct 41 ms 1532 KB Output is correct
16 Correct 43 ms 1972 KB Output is correct
17 Correct 43 ms 1816 KB Output is correct
18 Correct 118 ms 4524 KB Output is correct
19 Correct 119 ms 4096 KB Output is correct
20 Correct 243 ms 8412 KB Output is correct
21 Correct 219 ms 9768 KB Output is correct
22 Correct 272 ms 13852 KB Output is correct
23 Correct 286 ms 13768 KB Output is correct
24 Correct 184 ms 6124 KB Output is correct
25 Correct 199 ms 7112 KB Output is correct