QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#109855#360. Cultivationbashkort#5 1ms3916kbC++204.8kb2023-05-30 19:36:472024-05-31 13:52:07

Judging History

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

  • [2024-05-31 13:52:07]
  • 评测
  • 测评结果:5
  • 用时:1ms
  • 内存:3916kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-30 19:36:47]
  • 提交

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;) {
            while (j < n && x[j] - x[i] <= s) {
                j += 1;
            }
            relax(i, j);
            if (x[i] + s + 1 >= R) {
                break;
            }
            int xx = x[i];
            while (i < n && x[i] == xx) {
                i += 1;
            }
            if (j == n || x[j] > xx + s + 1) {
                relax(i, j);
            }
        }

        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;

    swap(us, ds);
    for (int u : us) {
        cu.push_back(checkd(u));
    }
    for (int d : ds) {
        cd.push_back(checku(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]);
        }
//        cout << ans << endl;
    }


    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: 5
Accepted

Test #1:

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

input:

2 4
2
1 1
1 4

output:

3

result:

ok single line: '3'

Test #2:

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

input:

4 1
1
2 1

output:

3

result:

ok single line: '3'

Test #3:

score: 5
Accepted
time: 0ms
memory: 3692kb

input:

3 3
3
1 2
1 3
3 3

output:

3

result:

ok single line: '3'

Test #4:

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

input:

2 2
1
1 2

output:

2

result:

ok single line: '2'

Test #5:

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

input:

4 4
10
4 2
2 3
2 4
4 1
1 2
2 1
4 3
3 3
3 1
1 4

output:

2

result:

ok single line: '2'

Test #6:

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

input:

4 4
1
4 1

output:

6

result:

ok single line: '6'

Test #7:

score: 5
Accepted
time: 0ms
memory: 3684kb

input:

4 4
3
2 2
3 3
1 4

output:

5

result:

ok single line: '5'

Test #8:

score: 5
Accepted
time: 0ms
memory: 3660kb

input:

4 4
15
4 3
2 4
4 4
4 1
3 3
1 2
3 1
2 1
3 4
3 2
4 2
2 3
1 3
2 2
1 4

output:

1

result:

ok single line: '1'

Test #9:

score: 5
Accepted
time: 0ms
memory: 3480kb

input:

4 3
3
2 1
2 3
4 1

output:

3

result:

ok single line: '3'

Test #10:

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

input:

4 4
2
3 4
2 4

output:

5

result:

ok single line: '5'

Test #11:

score: 5
Accepted
time: 0ms
memory: 3588kb

input:

2 4
1
1 2

output:

4

result:

ok single line: '4'

Test #12:

score: 5
Accepted
time: 0ms
memory: 3644kb

input:

3 3
4
2 1
1 1
3 2
3 1

output:

2

result:

ok single line: '2'

Test #13:

score: 5
Accepted
time: 0ms
memory: 3888kb

input:

3 4
3
1 4
3 3
3 4

output:

4

result:

ok single line: '4'

Test #14:

score: 5
Accepted
time: 0ms
memory: 3576kb

input:

3 3
2
2 1
3 3

output:

4

result:

ok single line: '4'

Test #15:

score: 5
Accepted
time: 0ms
memory: 3656kb

input:

4 4
2
2 4
3 1

output:

6

result:

ok single line: '6'

Test #16:

score: 5
Accepted
time: 0ms
memory: 3648kb

input:

4 4
3
2 2
2 1
4 2

output:

4

result:

ok single line: '4'

Subtask #2:

score: 0
Wrong Answer

Dependency #1:

100%
Accepted

Test #17:

score: 10
Accepted
time: 1ms
memory: 3656kb

input:

15 15
20
6 13
14 4
11 13
15 3
12 4
10 4
11 6
8 9
12 12
2 15
4 3
8 15
8 4
3 1
5 10
11 12
8 7
13 10
11 4
1 3

output:

13

result:

ok single line: '13'

Test #18:

score: 10
Accepted
time: 1ms
memory: 3664kb

input:

25 25
66
24 6
12 18
11 2
24 18
6 9
20 6
15 19
17 2
15 9
15 20
18 9
5 19
9 2
6 12
22 16
6 2
1 5
14 24
12 21
17 24
10 15
21 1
20 22
11 24
11 4
6 21
18 12
25 20
16 3
18 16
6 4
20 9
6 15
24 14
3 20
9 9
25 9
18 6
4 16
12 7
14 22
20 25
24 10
11 14
17 6
23 23
21 12
18 22
8 23
1 11
17 18
8 5
3 7
1 17
8 12
4...

output:

9

result:

ok single line: '9'

Test #19:

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

input:

36 38
28
30 5
4 23
29 20
1 36
8 28
8 9
5 26
23 16
26 1
24 38
22 36
4 26
9 7
10 24
20 11
31 5
24 30
26 30
18 15
14 1
23 31
20 7
23 30
33 9
27 33
8 7
9 16
33 5

output:

29

result:

wrong answer 1st lines differ - expected: '30', found: '29'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #45:

score: 30
Accepted
time: 0ms
memory: 3864kb

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:

852626202

result:

ok single line: '852626202'

Test #46:

score: 30
Accepted
time: 1ms
memory: 3916kb

input:

1000000000 1000000000
24
382358372 812500277
617637090 687506454
441176760 562497727
382346048 687504690
205880053 312504652
794110577 62497634
264714161 937490675
970587944 812502893
617647581 62504110
852944701 812498007
88227293 187492617
558814156 687495577
29403236 812494493
911761865 187491781...

output:

904419459

result:

ok single line: '904419459'

Test #47:

score: 30
Accepted
time: 1ms
memory: 3560kb

input:

1000000000 1000000000
25
59999964 299999989
740000035 100000111
139999972 499999797
740000159 899999809
940000104 899999905
459999870 299999853
139999925 899999750
260000183 300000150
260000200 699999915
940000072 99999821
340000223 900000130
739999776 499999813
59999984 700000029
539999767 90000023...

output:

480000793

result:

ok single line: '480000793'

Test #48:

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

input:

1000000000 1000000000
25
496770868 499466029
150245306 140351260
443861207 442170127
915815913 907024280
592352731 580300173
614771420 602707761
545759771 564678204
790963611 795646738
466306333 474998682
700037062 710428701
326403486 341417980
13108429 18468915
296795338 282907012
207909366 2192548...

output:

1967992015

result:

wrong answer 1st lines differ - expected: '1967193239', found: '1967992015'

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%