제출 #827984

#제출 시각아이디문제언어결과실행 시간메모리
827984LoboGarden (JOI23_garden)C++17
45 / 100
3082 ms7692 KiB
#include<bits/stdc++.h>
using namespace std;
const long long inf = (int) 1e9 + 10;
// #define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
const int maxn = 1e4+10;

int n, m, d, hasp[maxn], hasq[maxn];
deque<int> vals[maxn];
vector<int> endhere[maxn];

void solve() {
    cin >> n >> m >> d;

    for(int i = 1; i <= n; i++) {
        int x,y; cin >> x >> y;
        hasp[x]++; hasp[x+d]++;
        hasq[y]++; hasq[y+d]++;
    }

    for(int i = 1; i <= m; i++) {
        int x,y; cin >> x >> y;
        if(hasp[x]) continue;
        vals[x].pb(y);
    }
    for(int x = 0; x < d; x++) sort(all(vals[x]));

    int ans = inf;
    for(int y0 = 0; y0 < d; y0++) {
        set<int> pos;
        for(int y = 0; y < 2*d; y++) endhere[y].clear();
        for(int x = 0; x < d; x++) {
            while(vals[x].size() && vals[x].front() == y0-1) {
                vals[x].pop_front();
                vals[x].pb(y0-1+d);
            }

            if(hasp[x]) pos.insert(x);
            else if(vals[x].size()) {
                endhere[vals[x].back()].pb(x);
                pos.insert(x);
            }
        }

        int qtdq = 0;
        int deltax = inf;
        for(auto it = pos.begin(); next(it) != pos.end(); it++) {
            deltax = min(deltax,d+1-*next(it)+*it);
        }
        for(int y1 = y0; y1 < y0+d; y1++) {
            qtdq+= hasq[y1];
            for(auto x : endhere[y1]) {
                pos.erase(x);
                auto it = pos.lower_bound(x);
                if(it == pos.end() || it == pos.begin()) continue;
                deltax = min(deltax,d+1+*prev(it)-*it);
            }
            if(qtdq != n) continue;

            deltax = min(deltax,*pos.rbegin()-*pos.begin()+1);
            // for(auto it = pos.begin(); next(it) != pos.end(); it++) {
            //     deltax = min(deltax,d+1-*next(it)+*it);
            // }
            ans = min(ans,deltax*(y1-y0+1));
        }
    }

    cout << ans << endl;
}
    
int32_t main() {
    ios::sync_with_stdio(false); cin.tie(0);

    // freopen("in.in", "r", stdin);
    // freopen("out.out", "w", stdout);
    int tt = 1;
    // cin >> tt;
    while(tt--) {
        solve();
    }

}
#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...