Submission #930087

#TimeUsernameProblemLanguageResultExecution timeMemory
930087abcvuitunggioSoccer Stadium (IOI23_soccer)C++17
100 / 100
799 ms161876 KiB
#include "soccer.h" #include <bits/stdc++.h> using namespace std; const int mxn=2006; int ans,dp[mxn][mxn],l[mxn][mxn],u[mxn][mxn],d[mxn][mxn],r[mxn][mxn],L[mxn],R[mxn],h[mxn][mxn],w[mxn][mxn],a[mxn][mxn]; vector <int> ve[mxn]; int biggest_stadium(int n, vector <vector <int>> F){ for (int i=0;i<n;i++) for (int j=0;j<n;j++){ l[i][j]=(j&&!F[i][j-1]?l[i][j-1]:j); r[i][j]=(j<n-1&&!F[i][j+1]); d[i][j]=n-1; } for (int j=n-1;j>=0;j--){ stack <int> st; for (int i=0;i<n;i++){ if (!F[i][j]) ve[l[i][j]].push_back(i); while (!st.empty()&&(F[i][j]||l[i][j]>l[st.top()][j])){ d[st.top()][j]=i-1; st.pop(); } L[i]=(st.empty()?-1:st.top()); if (!F[i][j]) st.push(i); } while (!st.empty()) st.pop(); for (int i=n-1;i>=0;i--){ while (!st.empty()&&(F[i][j]||l[i][j]>l[st.top()][j])){ u[st.top()][j]=i+1; st.pop(); } R[i]=(st.empty()?-1:st.top()); if (!F[i][j]) st.push(i); } for (int i=0;i<n;i++){ h[i][j]=d[i][j]-u[i][j]+1; w[i][j]=j-l[i][j]+1; a[i][j]=w[i][j]*h[i][j]; if (r[i][j]) dp[i][j]=max(dp[i][j+1]-w[i][j]*h[i][j+1],0); dp[i][j]+=a[i][j]; } for (int k=0;k<=j;k++) for (int it=0;it<2;it++){ reverse(ve[k].begin(),ve[k].end()); for (int i:ve[k]) if (L[i]>=0) dp[L[i]][j]=max(dp[L[i]][j],dp[i][j]-w[L[i]][j]*h[i][j]+a[L[i]][j]); reverse(ve[k].begin(),ve[k].end()); for (int i:ve[k]) if (R[i]>=0) dp[R[i]][j]=max(dp[R[i]][j],dp[i][j]-w[R[i]][j]*h[i][j]+a[R[i]][j]); } for (int i=0;i<n;i++) ve[l[i][j]].clear(); } for (int i=0;i<n;i++) for (int j=0;j<n;j++) if (!F[i][j]) ans=max(ans,dp[i][j]); return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...