Submission #915928

#TimeUsernameProblemLanguageResultExecution timeMemory
915928biankSoccer Stadium (IOI23_soccer)C++17
0 / 100
2 ms4952 KiB
#include <bits/stdc++.h> using namespace std; #define ALL(x) x.begin(),x.end() #define SIZE(x) (int)x.size() #define forsn(i,s,n) for(int i=int(s);i<int(n);i++) #define forn(i,n) for(int i=0;i<int(n);i++) #define dforsn(i,s,n) for(int i=int(n)-1;i>=int(s);i--) #define dforn(i,n) for(int i=int(n)-1;i>=0;i--) #define fst first #define snd second typedef pair<int,int> ii; const int MAXN = 500; int f[MAXN][MAXN]; int dp[MAXN][MAXN]; ii ran[MAXN][MAXN]; int L[MAXN][MAXN], R[MAXN][MAXN]; int n; pair<int,ii> solve(int l, int r, int p) { if(l>r) return {0LL,{-1,n}}; if(dp[l][r]!=-1) return {dp[l][r],ran[l][r]}; auto calculate = [&](pair<int,ii> prev, int i) { auto [val,range] = prev; int mini = max(range.fst, L[i][p]), maxi = min(range.snd, R[i][p]); return (pair<int,ii>){val+max(maxi-mini-1,0),{mini,maxi}}; }; pair<int,ii> res = max(calculate(solve(l+1,r,p),l), calculate(solve(l,r-1,p),r)); dp[l][r]=res.fst, ran[l][r]=res.snd; return res; } int only_check(vector<vector<int>> f) { vector<int> l(n,n), r(n,-1); forn(i,n) forn(j,n) { if(f[i][j]==0) { l[i]=min(l[i],j); r[i]=max(r[i],j); } } forn(i,n) forsn(j,l[i],r[i]+1) { if(f[i][j]==1) return -1; } forn(i,n) forn(j,n) { if(l[i]>l[j] && r[i]>r[j]) return -1; } vector<int> c(n); forn(i,n) c[i]=max(r[i]-l[i]+1,0); int maxi = int(max_element(ALL(c)) - c.begin()); forsn(i,maxi,n-1) { if(c[i]<c[i+1]) return -1; } forn(i,maxi) { if(c[i]>c[i+1]) return -1; } int count=0; forn(i,n) forn(j,n) { count += f[i][j]==0; } return count; } int subtask1(vector<vector<int>> f) { ii pos={-1,-1}; forn(i,n) forn(j,n) { if(f[i][j]==1) pos={i,j}; } auto calculate = [](int i, int j) { return n*n-(i+1)*(j+1); }; auto [i,j] = pos; return max({calculate(i,j),calculate(n-i-1,j),calculate(i,n-j-1),calculate(n-i-1,n-j-i)}); } int biggest_stadium(int N, vector<vector<int>> F) { n=N; int count=0; forn(i,n) forn(j,n) { count += F[i][j]==1; } if(count<=1) return subtask1(F); if(n>500) return only_check(F); forn(i,n) forn(j,n) { f[i][j]=F[i][j]; } forn(i,n) { int k=-1; forn(j,n) { if(f[i][j]==1) k=j; L[i][j]=k; } } forn(i,n) { int k=n; dforn(j,n) { if(f[i][j]==1) k=j; R[i][j]=k; } } int ans=0; forn(i,n) { memset(dp,-1,sizeof dp); ans=max(ans,solve(0,n-1,i).fst); } 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...