QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#109838#360. Cultivationbashkort#0 1ms3840kbC++204.6kb2023-05-30 18:59:492024-05-31 13:51:46

Judging History

你现在查看的是最新测评结果

  • [2024-05-31 13:51:46]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3840kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-30 18:59:49]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

constexpr int inf = 1e9 + 7;

array<int, 3> operator+(const array<int, 3> &a, const array<int, 3> &b) {
    return {max(a[0], b[0]), max(a[1], b[1]), max(a[2], b[2])};
}

constexpr array<int, 3> neut = {inf, inf, 2 * inf};

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int R, C, n;
    cin >> R >> C >> n;

    vector<pair<int, int>> pt(n);
    vector<int> x(n), y(n);

    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i];
        --x[i], --y[i];
        pt[i] = {x[i], y[i]};
    }

    sort(pt.begin(), pt.end());

    for (int i = 0; i < n; ++i) {
        x[i] = pt[i].first;
        y[i] = pt[i].second;
    }

    vector mx(n + 1, vector<array<int, 3>>(n + 1, neut));

    for (int i = 0; i < n; ++i) {
        multiset<int> sy, diff;
        sy.insert(-1), sy.insert(C);
        diff.insert(C);

        auto ins = [&](int i) {
            if (i == n) {
                return;
            }
            auto it = sy.lower_bound(y[i]);
            int nxt = *it, prv = *prev(it);
            diff.extract(nxt - prv - 1);
            diff.insert(y[i] - prv - 1);
            diff.insert(nxt - y[i] - 1);
            sy.insert(y[i]);
        };

        for (int j = i; j < n; ++j) {
            ins(j);
            int fi = *next(sy.begin());
            int la = *next(sy.rbegin());
            mx[i][j] = {fi, C - la - 1, *diff.rbegin()};
        }
    }

    int ans = R + C;

    auto upd = [&](const array<int, 3> &a, int s) {
        ans = min<ll>(ans, max<ll>(a[0] + a[1], a[2]) + s);
    };

    auto check = [&](int s) -> array<int, 3> {
        array<int, 3> now{};

        auto relax = [&](int i, int j) {
            if (i >= j) {
                now = neut;
            } else {
                now = now + mx[i][j - 1];
            }
        };

        if (x[0] > s || x.back() + s + 1 < R) {
            return neut;
        }

        for (int i = 0, j = 0; i < n; ++i) {
            while (j < n && x[j] - x[i] - 1 <= s) {
                j += 1;
            }
            relax(i, j);
            if (x[i] + s + 1 >= R) {
                break;
            }
        }

        return now;
    };

    auto checku = [&](int u) -> array<int, 3> {
        if (x[0] > u) {
            return neut;
        }

        int j = 0;

        while (j < n && x[j] <= u) {
            j += 1;
        }

        return mx[0][j - 1];
    };

    auto checkd = [&](int d) -> array<int, 3> {
        if (x.back() + d + 1 < R) {
            return neut;
        }

        int j = n;

        while (j > 0 && x[j - 1] + d + 1 >= R) {
            j -= 1;
        }

        return mx[j][n - 1];
    };

    vector<int> us, ds, sums;

    for (int i = 0; i < n; ++i) {
        us.push_back(x[i]);
        ds.push_back(R - x[i] - 1);
        for (int j = 0; j < n; ++j) {
            if (x[j] > x[i]) {
                sums.push_back(x[j] - x[i] - 1);
            }
        }
    }

    us.push_back(0);
    ds.push_back(0);
    sums.push_back(0);
    sort(us.begin(), us.end());
    sort(ds.begin(), ds.end());
    sort(sums.begin(), sums.end());
    us.resize(unique(us.begin(), us.end()) - us.begin());
    ds.resize(unique(ds.begin(), ds.end()) - ds.begin());
    sums.resize(unique(sums.begin(), sums.end()) - sums.begin());

    vector<array<int, 3>> cu, cd, cs;

    for (int u : us) {
        cu.push_back(checku(u));
    }
    for (int d : ds) {
        cd.push_back(checkd(d));
    }
    for (int s : sums) {
        cs.push_back(check(s));
    }

    for (int i = 0; i < size(cu); ++i) {
        for (int j = 0; j < size(cd); ++j) {
            int s = us[i] + ds[j];
//            int is = upper_bound(sums.begin(), sums.end(), s) - sums.begin() - 1;
            upd(cu[i] + cd[j] + check(s), us[i] + ds[j]);
        }
    }

    for (int i = 0; i < size(cs); ++i) {
        for (int j = 0; j < size(cd); ++j) {
            if (sums[i] >= ds[j]) {
                int u = sums[i] - ds[j];
                int iu = upper_bound(us.begin(), us.end(), u) - us.begin() - 1;
                upd(cs[i] + cd[j] + cu[iu], sums[i]);
            }
        }
        for (int j = 0; j < size(cu); ++j) {
            if (sums[i] >= us[j]) {
                int d = sums[i] - us[j];
                int id = upper_bound(ds.begin(), ds.end(), d) - ds.begin() - 1;
                upd(cs[i] + cu[j] + cd[id], sums[i]);
            }
        }
    }

    cout << ans << '\n';

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 5
Accepted
time: 1ms
memory: 3820kb

input:

2 4
2
1 1
1 4

output:

3

result:

ok single line: '3'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

4 1
1
2 1

output:

3

result:

ok single line: '3'

Test #3:

score: -5
Wrong Answer
time: 0ms
memory: 3624kb

input:

3 3
3
1 2
1 3
3 3

output:

2

result:

wrong answer 1st lines differ - expected: '3', found: '2'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #45:

score: 0
Wrong Answer
time: 1ms
memory: 3836kb

input:

1000000000 1000000000
17
822413671 70423910
260075513 431043546
300945721 793553248
142848049 163787897
392462410 831950868
699005697 111397300
444396260 130450496
642691616 595456084
467968916 463598810
159764248 611476406
929313754 539645102
365153650 964108073
906780716 373514044
970118116 655138...

output:

848766697

result:

wrong answer 1st lines differ - expected: '852626202', found: '848766697'

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%