# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
673579 | 2022-12-21T07:40:31 Z | Baytoro | Luxury burrow (IZhO13_burrow) | C++17 | 1036 ms | 25760 KB |
#include <bits/stdc++.h> using namespace std; #define ios ios::sync_with_stdio(false); cin.tie(NULL); #define pb push_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define fr first #define sc second #define int long long #define endl '\n' void fopn(string name){ freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout); } const int INF=1e18,mod=998244353; int n,m,k; int h[1005][1005],a[1005][1005]; int area=0; int get_area(vector<int> vec){ int N=vec.size(); vec.resize(N+2); vector<int> l(N+2),r(N+2); vec[0]=vec[N+1]=-INF; stack<int> st; st.push(0); for(int i=1;i<=N;i++){ while(vec[st.top()]>vec[i]) st.pop(); l[i]=st.top(); st.push(i); } while(!st.empty()) st.pop(); st.push(N+1); for(int i=N;i>0;i--){ while(vec[st.top()]>=vec[i]) st.pop(); r[i]=st.top()-1; st.push(i); } int res=0; for(int i=1;i<=N;i++) res=max(res,(r[i]-l[i])*vec[i]); return res; } bool check(int md){ for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(h[i][j]>=md) a[i][j]=1; else a[i][j]=0; } } for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++) if(a[i][j]) a[i][j]+=a[i-1][j]; } area=0; for(int i=1;i<=n;i++){ vector<int> v; v.pb(0); for(int j=1;j<=m+1;j++){ v.pb(a[i][j]); } area=max(area,get_area(v)); } if(area>=k) return 1; return 0; } void solve(){ cin>>n>>m>>k; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) cin>>h[i][j]; int l=0,r=1e9; int ar=0,ans=0; while(r-l>1){ //cout<<l<<' '<<r<<' '; int md=(l+r)/2; if(check(md)){ l=md; ans=md,ar=area; } else r=md; //cout<<area<<endl; } cout<<ans<<' '<<ar<<endl; } main(){ //fopn("newbarn"); //ios; int T=1; //cin>>T; while(T--){ solve(); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 468 KB | Output is correct |
5 | Correct | 2 ms | 468 KB | Output is correct |
6 | Correct | 2 ms | 596 KB | Output is correct |
7 | Correct | 1 ms | 316 KB | Output is correct |
8 | Correct | 9 ms | 1236 KB | Output is correct |
9 | Correct | 17 ms | 2388 KB | Output is correct |
10 | Correct | 42 ms | 2772 KB | Output is correct |
11 | Correct | 81 ms | 3772 KB | Output is correct |
12 | Correct | 41 ms | 5260 KB | Output is correct |
13 | Correct | 52 ms | 2340 KB | Output is correct |
14 | Correct | 116 ms | 6620 KB | Output is correct |
15 | Correct | 119 ms | 6584 KB | Output is correct |
16 | Correct | 149 ms | 7056 KB | Output is correct |
17 | Correct | 149 ms | 8700 KB | Output is correct |
18 | Correct | 334 ms | 12552 KB | Output is correct |
19 | Correct | 382 ms | 13200 KB | Output is correct |
20 | Correct | 745 ms | 18488 KB | Output is correct |
21 | Correct | 702 ms | 20748 KB | Output is correct |
22 | Correct | 1036 ms | 25760 KB | Output is correct |
23 | Correct | 910 ms | 25664 KB | Output is correct |
24 | Correct | 580 ms | 18180 KB | Output is correct |
25 | Correct | 641 ms | 18916 KB | Output is correct |