제출 #1324929

#제출 시각아이디문제언어결과실행 시간메모리
1324929vladiliusGarden (JOI23_garden)C++20
0 / 100
1187 ms14744 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n, m, d; cin>>n>>m>>d;
    vector<pii> M[2 * d];
    vector<int> f(d + 2); f[0] = f[d + 1] = 1;
    int L1 = 1e9, R1 = 0;
    for (int i = 1; i <= n; i++){
        int x, y; cin>>x>>y;
        y++;
        f[y]++;
        M[x].pb({y, 1});
        M[x + d].pb({y, 1});
        
        L1 = min(L1, y); R1 = max(R1, y);
    }
    
    vector<int> D[2 * d];
    vector<pii> all;
    for (int i = 1; i <= m; i++){
        int x, y; cin>>x>>y;
        y++;
        M[x].pb({y, 0});
        M[x + d].pb({y, 0});
        all.pb({x, y});
    }
    
    vector<int> L(d), R(d);
    
    ll out = 1e18;
    for (int i = 0; i < d; i++){
        for (auto [x, y]: all){
            f[y]++;
        }

        auto get = [&](){
            int pre = 1e9, mx = 0;
            for (int j = 1; j <= d; j++){
                if (f[j]){
                    mx = max(mx, j - pre);
                    pre = j;
                }
            }
            if (!mx) return d;
            return mx;
        };
        
        for (int j = d - 2; j >= 0; j--){
            L[j] = L[j + 1]; R[j] = R[j + 1];
            for (auto [y, b]: M[i + j + 1]){
                if (!b){
                    L[j] = min(L[j], y);
                    R[j] = max(R[j], y);
                }
            }
        }
        
        int cc = 0;
        for (int j = i; j < i + d; j++){
            for (auto [y, b]: M[j]){
                if (b){
                    cc++;
                }
                else {
                    f[y]--;
                }
            }
            if (cc == n){
                out = min(out, 1LL * (j - i + 1) * min((d + 1) - get(), max(R1, R[j - i]) - min(L1, L[j - i]) + 1));
            }
        }
    }
    
    cout<<out<<"\n";
}
#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...