QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#109807#360. Cultivationbashkort#0 69ms3888kbC++203.2kb2023-05-30 17:49:512024-05-31 13:50:47

Judging History

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

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

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

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

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

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

    int ans = R + C;

    auto check = [&](int u, int d) -> void {
        vector<pair<int, int>> events;

        for (int i = 0; i < n; ++i) {
            events.emplace_back(max(0, x[i] - u), i);
            events.emplace_back(min(R, x[i] + d + 1), ~i);
        }

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

        int mxl = 0, mxr = 0, mxs = 0;

        multiset<int> sy, diff;
        sy.insert(-1), sy.insert(C);
        diff.insert(C);

        auto ins = [&](int i) {
            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]);
        };

        auto er = [&](int i) {
            auto me = sy.find(y[i]);
            int nxt = *next(me);
            int prv = *prev(me);
            sy.erase(me);
            diff.extract(nxt - y[i] - 1);
            diff.extract(y[i] - prv - 1);
            diff.insert(nxt - prv - 1);
        };

        bool ok = true;

        for (int i = 0, j = 0; i < size(events); i = j) {
            while (j < size(events) && events[j].first == events[i].first) {
                if (events[j].second >= 0) {
                    ins(events[j].second);
                } else {
                    er(~events[j].second);
                }
                j += 1;
            }

            if (events[i].first < R) {
                if (size(sy) == 2) {
                    ok = false;
                    break;
                }
                int fi = *next(sy.begin());
                int la = *next(sy.rbegin());
                mxl = max(mxl, fi);
                mxr = max(mxr, C - la - 1);
                mxs = max(mxs, *diff.rbegin());
            }
        }

        if (ok) {
            ans = min(ans, max(mxl + mxr, mxs) + u + d);
        }
    };

    for (int k = 0; k < 2; ++k) {
        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]);
                }
            }
        }

        for (int u : us) {
            for (int d : ds) {
                check(u, d);
            }
        }

        for (int s : sums) {
            for (int u : us) {
                if (s >= u) {
                    check(u, s - u);
                }
            }
            for (int d : ds) {
                if (s >= d) {
                    check(s - d, d);
                }
            }
        }

        for (int i = 0; i < n; ++i) {
            swap(x[i], y[i]);
        }
        swap(R, C);
    }

    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: 3528kb

input:

2 4
2
1 1
1 4

output:

3

result:

ok single line: '3'

Test #2:

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

input:

4 1
1
2 1

output:

3

result:

ok single line: '3'

Test #3:

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

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: 30
Accepted
time: 16ms
memory: 3532kb

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: 59ms
memory: 3812kb

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: 69ms
memory: 3888kb

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: 30
Accepted
time: 53ms
memory: 3580kb

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:

1967193239

result:

ok single line: '1967193239'

Test #49:

score: 30
Accepted
time: 67ms
memory: 3828kb

input:

1000000000 1000000000
25
508699723 917649746
972134563 24654272
591574312 768222747
342111766 678842208
280650655 335101574
112108587 538128714
232733100 741988808
569340416 313541403
333183415 646381341
348331220 239049882
321253252 46884019
458715217 456559440
11396102 588839952
212356188 55359081...

output:

967430445

result:

ok single line: '967430445'

Test #50:

score: 30
Accepted
time: 69ms
memory: 3576kb

input:

1000000000 1000000000
25
87500002 928571428
712500002 71428571
212500002 71428570
837500001 71428573
912499999 214285715
287500002 785714285
37500003 785714285
962500002 357142856
787500000 785714288
787500003 500000003
462500002 71428570
462500001 357142859
37499999 500000000
462500002 642857144
37...

output:

660714282

result:

ok single line: '660714282'

Test #51:

score: 0
Wrong Answer
time: 48ms
memory: 3848kb

input:

1000000000 1000000000
25
499999999 565789472
499999990 250000002
499999996 749999995
499999999 144736850
499999993 513157893
499999992 644736853
500000010 13157889
499999998 118421056
499999993 197368414
499999990 592105269
499999994 486842107
500000005 276315783
499999994 539473685
499999990 618421...

output:

-2137072594

result:

wrong answer 1st lines differ - expected: '1131578975', found: '-2137072594'

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%