답안 #961231

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
961231 2024-04-11T18:11:51 Z danikoynov Cultivation (JOI17_cultivation) C++14
60 / 100
2000 ms 860 KB
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;
typedef long long ll;

const ll maxn = 310;

ll n, r, c;
ll x[maxn], y[maxn];

ll used[maxn];

struct data
{

    ll atl_lf = 0, atl_rf = 0, atl_sum = 0;
    data(ll _atl_lf = 0, ll _atl_rf = 0, ll _atl_sum = 0)
    {
        atl_lf = _atl_lf;
        atl_rf = _atl_rf;
        atl_sum = _atl_sum;
    }
};

int ridx[maxn];
bool cmp(int id1, int id2)
{
    return y[id1] < y[id2];
}

void solve()
{
    cin >> r >> c;
    cin >> n;
    for (ll i = 1; i <= n; i ++)
        cin >> x[i] >> y[i];
    for (int i = 1; i <= n; i ++)
        ridx[i] = i;
    sort(ridx + 1, ridx + n + 1, cmp);
    int x1[maxn], y1[maxn];
    for (int i = 1; i <= n; i ++)
    {
        x1[i] = x[ridx[i]];
        y1[i] = y[ridx[i]];
    }
    for (int i = 1; i <= n; i ++)
    {
        x[i] = x1[i];
        y[i] = y1[i];
    }

    ll res = r + c - 2;
    set < ll > set_x;
    for (ll i = 1; i <= n; i ++)
        set_x.insert(x[i] - 1);

    set < ll > pos_sum;
    for (ll dw : set_x)
    {
        for (int i = 1; i <= n; i ++)
            pos_sum.insert(r - x[i] + dw);
    }

    for (int i = 1; i <= n; i ++)
        for (int j = 1; j <= n; j ++)
            if (x[i] < x[j])
                pos_sum.insert(x[j] - x[i] - 1);


    for (ll up : pos_sum)
    {


        set < ll > rel;
        for (ll i = 1; i <= n; i ++)
        {
            rel.insert(x[i]);
            rel.insert(x[i] + up + 1);
        }
        unordered_map < ll, data > tk;

        for (ll i : rel)
        {

            ll atl_sum = 0;
                        ll atl_lf = 0;
            ll atl_rf =  0;

            ll last = -1e9;
            for (ll j = 1; j <= n; j ++)
            {
                if (x[j] <= i && x[j] + up >= i)
                {
                    if (last == -1e9)
                        atl_lf = y[j] - 1;
                    atl_rf = c - y[j];
                    if (last != -1e9)
                    atl_sum = max(atl_sum, y[j] - last - 1);
                    last = y[j];
                }
            }

            if (last == -1e9)
            {

                tk[i] = data(4e9, 4e9, 4e9);
                break;
            }
            tk[i] = data(atl_lf, atl_rf, atl_sum);
        }

        vector < ll > p;
        for (ll cur : rel)
            p.push_back(cur);
        int sz = p.size();
        for (int i = 0; i < sz; i ++)
        {
            if (tk[p[i]].atl_lf == 4e9)
                continue;
            ll atl_lf = 0, atl_rf = 0, atl_sum = 0;
            bool el = false;
            for (int j = i; j < sz; j ++)
            {
                if (p[j] >= p[i] + r)
                {
                    el = true;
                    break;
                }
                atl_lf = max(atl_lf, tk[p[j]].atl_lf);
                atl_rf = max(atl_rf, tk[p[j]].atl_rf);
                atl_sum = max(atl_sum, tk[p[j]].atl_sum);
                if (p[j] == p[i] + r - 1)
                {
                    el = true;
                    break;
                }
            }
            if (!el)
                break;
            res = min(res, up + max(atl_lf + atl_rf, atl_sum));
        }
        ///res = min(res, up + dw + max(atl_sum, atl_lf + atl_rf));

    }

    cout << res << endl;
}
int main()
{
    solve();
    return 0;
}
/**
4 3
3
2 1
2 3
4 1

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 219254859
617032761 616107308
248155618 254253131
284599784 288724312
68437874 69050438
36863359 47496556
343816887 338965809
560430677 554034425
327115091 319475338
290706522 308826179
799518444 796166899
438981788 441006320



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 219254859
617032761 616107308
248155618 254253131
284599784 288724312
68437874 69050438
36863359 47496556
343816887 338965809
560430677 554034425
327115091 319475338
290706522 308826179
799518444 796166899
438981788 441006320

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 655138295
257280896 236115217
909808245 942097331
523555293 969550238


*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 404 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 404 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 4 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 6 ms 448 KB Output is correct
25 Correct 5 ms 348 KB Output is correct
26 Correct 9 ms 348 KB Output is correct
27 Correct 9 ms 348 KB Output is correct
28 Correct 5 ms 344 KB Output is correct
29 Correct 9 ms 344 KB Output is correct
30 Correct 9 ms 348 KB Output is correct
31 Correct 11 ms 348 KB Output is correct
32 Correct 9 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 404 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 4 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 6 ms 448 KB Output is correct
25 Correct 5 ms 348 KB Output is correct
26 Correct 9 ms 348 KB Output is correct
27 Correct 9 ms 348 KB Output is correct
28 Correct 5 ms 344 KB Output is correct
29 Correct 9 ms 344 KB Output is correct
30 Correct 9 ms 348 KB Output is correct
31 Correct 11 ms 348 KB Output is correct
32 Correct 9 ms 344 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 5 ms 348 KB Output is correct
35 Correct 9 ms 348 KB Output is correct
36 Correct 9 ms 348 KB Output is correct
37 Correct 8 ms 452 KB Output is correct
38 Correct 9 ms 348 KB Output is correct
39 Correct 9 ms 456 KB Output is correct
40 Correct 9 ms 344 KB Output is correct
41 Correct 4 ms 348 KB Output is correct
42 Correct 6 ms 348 KB Output is correct
43 Correct 11 ms 460 KB Output is correct
44 Correct 9 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 20 ms 488 KB Output is correct
3 Correct 21 ms 344 KB Output is correct
4 Correct 22 ms 348 KB Output is correct
5 Correct 22 ms 348 KB Output is correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 18 ms 484 KB Output is correct
9 Correct 10 ms 344 KB Output is correct
10 Correct 21 ms 344 KB Output is correct
11 Correct 25 ms 348 KB Output is correct
12 Correct 24 ms 348 KB Output is correct
13 Correct 3 ms 348 KB Output is correct
14 Correct 7 ms 348 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 23 ms 600 KB Output is correct
17 Correct 23 ms 488 KB Output is correct
18 Correct 8 ms 348 KB Output is correct
19 Correct 22 ms 460 KB Output is correct
20 Correct 22 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 20 ms 488 KB Output is correct
3 Correct 21 ms 344 KB Output is correct
4 Correct 22 ms 348 KB Output is correct
5 Correct 22 ms 348 KB Output is correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 18 ms 484 KB Output is correct
9 Correct 10 ms 344 KB Output is correct
10 Correct 21 ms 344 KB Output is correct
11 Correct 25 ms 348 KB Output is correct
12 Correct 24 ms 348 KB Output is correct
13 Correct 3 ms 348 KB Output is correct
14 Correct 7 ms 348 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 23 ms 600 KB Output is correct
17 Correct 23 ms 488 KB Output is correct
18 Correct 8 ms 348 KB Output is correct
19 Correct 22 ms 460 KB Output is correct
20 Correct 22 ms 348 KB Output is correct
21 Execution timed out 2021 ms 860 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 404 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 4 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 6 ms 448 KB Output is correct
25 Correct 5 ms 348 KB Output is correct
26 Correct 9 ms 348 KB Output is correct
27 Correct 9 ms 348 KB Output is correct
28 Correct 5 ms 344 KB Output is correct
29 Correct 9 ms 344 KB Output is correct
30 Correct 9 ms 348 KB Output is correct
31 Correct 11 ms 348 KB Output is correct
32 Correct 9 ms 344 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 5 ms 348 KB Output is correct
35 Correct 9 ms 348 KB Output is correct
36 Correct 9 ms 348 KB Output is correct
37 Correct 8 ms 452 KB Output is correct
38 Correct 9 ms 348 KB Output is correct
39 Correct 9 ms 456 KB Output is correct
40 Correct 9 ms 344 KB Output is correct
41 Correct 4 ms 348 KB Output is correct
42 Correct 6 ms 348 KB Output is correct
43 Correct 11 ms 460 KB Output is correct
44 Correct 9 ms 600 KB Output is correct
45 Correct 5 ms 344 KB Output is correct
46 Correct 20 ms 488 KB Output is correct
47 Correct 21 ms 344 KB Output is correct
48 Correct 22 ms 348 KB Output is correct
49 Correct 22 ms 348 KB Output is correct
50 Correct 8 ms 344 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 18 ms 484 KB Output is correct
53 Correct 10 ms 344 KB Output is correct
54 Correct 21 ms 344 KB Output is correct
55 Correct 25 ms 348 KB Output is correct
56 Correct 24 ms 348 KB Output is correct
57 Correct 3 ms 348 KB Output is correct
58 Correct 7 ms 348 KB Output is correct
59 Correct 3 ms 348 KB Output is correct
60 Correct 23 ms 600 KB Output is correct
61 Correct 23 ms 488 KB Output is correct
62 Correct 8 ms 348 KB Output is correct
63 Correct 22 ms 460 KB Output is correct
64 Correct 22 ms 348 KB Output is correct
65 Execution timed out 2021 ms 860 KB Time limit exceeded
66 Halted 0 ms 0 KB -