제출 #847336

#제출 시각아이디문제언어결과실행 시간메모리
847336LucppSoccer Stadium (IOI23_soccer)C++17
100 / 100
370 ms62376 KiB
#include <bits/stdc++.h>
#include "soccer.h"
using namespace std;

int biggest_stadium(int N, vector<vector<int>> F){
    vector<int> H(N), oldDp(N);
    vector<vector<int>> byH(N+1);
    int ans = 0;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(F[i][j]) H[j] = 0;
            else H[j]++;
            byH[H[j]].push_back(j);
        }
        stack<pair<int, int>> s;
        s.emplace(-1, -1);
        vector<int> L(N), R(N, N), dp(N);
        for(int k = 0; k < N; k++){
            while(s.top().first > H[k]){
                R[s.top().second] = k;
                s.pop();
            }
            if(s.top().first == H[k]) L[k] = L[s.top().second];
            else L[k] = s.top().second+1;
            s.emplace(H[k], k);
        }
        for(int h = 1; h <= i+1; h++){
            for(int j : byH[h]){
                int w = R[j]-L[j];
                dp[j] = w+oldDp[j];
                if(int k = L[j]-1; k >= 0) dp[j] = max(dp[j], w*(H[j]-H[k]) + dp[k]);
                if(int k = R[j]; k < N) dp[j] = max(dp[j], w*(H[j]-H[k]) + dp[k]);
                ans = max(ans, dp[j]);
            }
            byH[h].clear();
        }
        swap(dp, oldDp);
    }
    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...