Submission #227710

#TimeUsernameProblemLanguageResultExecution timeMemory
227710emil_physmathLuxury burrow (IZhO13_burrow)C++17
0 / 100
2016 ms5996 KiB
#include <algorithm> #include <iostream> #include <cstdio> #include <vector> #include <queue> #include <set> using namespace std; int n, m, k; int price[1000][1000], a[1000][1000]; pair<int, int> t[4000]; void Build(int v, int vl, int vr, vector<int>& a) { if (vl == vr) { t[v] = {a[vr], vr}; return; } int vm = (vl + vr) / 2; Build(v * 2, vl, vm, a); Build(v * 2 + 1, vm + 1, vr, a); t[v] = min(t[v * 2], t[v * 2 + 1]); } pair<int, int> Min(int v, int vl, int vr, int l, int r) { if (l > vr || vl > r) return {10000, 0}; if (l <= vl && vr <= r) return t[v]; int vm = (vl + vr) / 2; return min(Min(v * 2, vl, vm, l, r), Min(v * 2 + 1, vm + 1, vr, l, r)); } int Solve(int l, int r) { queue<pair<int, int>> q; q.push({l, r}); int ans = 0; while (q.size()) { l = q.front().first, r = q.front().second; q.pop(); if (l > r) continue; pair<int, int> p = Min(1, 0, m - 1, l, r); int hei = p.first, i = p.second; ans = max(ans, (r - l + 1) * hei); q.push({l, i - 1}); q.push({i + 1, r}); } return ans; } int Solve() { vector<int> up(m); int ans = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) if (a[i][j]) ++up[j]; else up[j] = 0; Build(1, 0, m - 1, up); ans = max(Solve(0, m - 1), ans); } return ans; } int main() { cin >> n >> m >> k; for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) scanf("%d", price[i] + j); pair<int, int> ans = {0, n * m}; int ans_l = 1, ans_r = 1000'000'000; while (ans_l <= ans_r) { int ans_m = (ans_l + ans_r) / 2; for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) a[i][j] = (price[i][j] >= ans_m); int x = Solve(); if (x >= k) { ans = {ans_m, x}; ans_l = ans_m + 1; } else ans_r = ans_m - 1; } cout << ans.first << ' ' << ans.second; }

Compilation message (stderr)

burrow.cpp: In function 'int main()':
burrow.cpp:74:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", price[i] + j);
             ~~~~~^~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...