제출 #965443

#제출 시각아이디문제언어결과실행 시간메모리
965443PringGarden (JOI23_garden)C++17
30 / 100
3035 ms1116 KiB
#include <bits/stdc++.h>
#pragma GCC optimize("O3","unroll-loops")
#pragma GCC target("avx2","popcnt","sse4","abm")
using namespace std;

#ifdef MIKU
string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m";
#define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x)
void dout() { cout << dbrs << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif

#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
using ll = long long;
typedef pair<int, int> pii;

const int MXN = 5005;
int n, m, d, p[MXN], q[MXN];
multiset<int> MS;
vector<int> bck[MXN * 2];
int c[MXN * 2];
int ori;

int CALC_ORI() {
    vector<int> v;
    FOR(i, 0, n + m) v.push_back(q[i]);
    sort(v.begin(), v.end());
    int ans = 0;
    FOR(i, 1, n + m) ans = max(ans, v[i] - v[i - 1]);
    ans = max(ans, d - v.back() + v.front());
    return ans;
}

int calc(int sr) {
    if (bck[sr].empty() && c[sr] == 0) return INT_MAX;
    int big = ori, cnt = 0, ans = INT_MAX;
    FOR(i, 0, d) {
        cnt += c[sr + i];
        for (auto &j : bck[sr + i]) {
            auto it = MS.find(q[j]);
            int l = (it == MS.begin() ? *MS.rbegin() - d : *prev(it));
            int r = (next(it) == MS.end() ? *MS.begin() + d : *next(it));
            big = max(big, r - l);
            MS.erase(MS.find(q[j]));
        }
        if (cnt == n) ans = min(ans, (i + 1) * (d - big + 1));
    }
    FOR(i, n, n + m) {
        MS.insert(q[i]);
    }
    return ans;
}

void miku() {
    cin >> n >> m >> d;
    FOR(i, 0, n) {
        cin >> p[i] >> q[i];
        c[p[i]]++;
        c[p[i] + d]++;
    }
    FOR(i, n, n + m) {
        cin >> p[i] >> q[i];
        bck[p[i]].push_back(i);
        bck[p[i] + d].push_back(i);
    }
    ori = CALC_ORI();
    FOR(i, 0, n + m) {
        MS.insert(q[i]);
    }
    int ans = INT_MAX;
    FOR(i, 0, d) ans = min(ans, calc(i));
    cout << ans << '\n';
}

int32_t main() {
    cin.tie(0) -> sync_with_stdio(false);
    cin.exceptions(cin.failbit);
    miku();
    return 0;
}
#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...