Submission #801509

# Submission time Handle Problem Language Result Execution time Memory
801509 2023-08-02T06:24:31 Z 이동현(#10092) Cultivation (JOI17_cultivation) C++17
15 / 100
1400 ms 262144 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define int long long
using namespace std;

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int r, c, n;
    cin >> r >> c >> n;
    vector<array<int, 2>> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i][0] >> a[i][1];
        --a[i][0];
        --a[i][1];
    }

    vector<int> dpu;
    sort(a.begin(), a.end());
    for(int i = 0; i < n; ++i){
        dpu.push_back(a[i][0] + 1);
        dpu.push_back(r - a[i][0]);
        for(int j = i + 1; j < n; ++j){
            dpu.push_back(a[j][0] - a[i][0] + 1);
        }
    }

    for(int i = 1; i <= r; ++i) dpu.push_back(i);

    sort(dpu.begin(), dpu.end());
    dpu.erase(unique(dpu.begin(), dpu.end()), dpu.end());

    auto sol = [&](int dulen)->int{
        int rv = (int)1e18;
        for(int st = 0; st < n; ++st){
            int lmx = 0, rmx = 0, lenmx = 0;
            for(int i = a[st][0]; i < a[st][0] + r; ++i){
                vector<int> x;
                
                for(int j = 0; j < n; ++j){
                    if(a[j][0] > i - dulen && a[j][0] <= i){
                        x.push_back(a[j][1]);
                    }
                }

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

                if(!(int)x.size()){
                    lenmx = (int)1e9;
                }
                else{
                    lmx = max(lmx, x[0]);
                    rmx = max(rmx, c - x.back() - 1);
                    for(int j = 0; j + 1 < (int)x.size(); ++j){
                        lenmx = max(lenmx, x[j + 1] - x[j]);
                    }
                }
            }

            // cout << dulen << ' ' << a[st][0] << ' ' << max(lenmx - 1, lmx + rmx) << endl;

            rv = min(rv, max(lenmx - 1, lmx + rmx));
        }

        return rv;
    };

    int ans = (int)1e18;

    for(auto&dulen:dpu){
        // cout << dulen << endl;
        ans = min(ans, dulen - 1 + sol(dulen));
    }

    cout << ans << '\n';
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 272 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 272 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 15 ms 372 KB Output is correct
19 Correct 7 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 21 ms 348 KB Output is correct
22 Correct 141 ms 420 KB Output is correct
23 Correct 12 ms 328 KB Output is correct
24 Correct 546 ms 596 KB Output is correct
25 Correct 267 ms 468 KB Output is correct
26 Correct 1396 ms 856 KB Output is correct
27 Correct 1332 ms 856 KB Output is correct
28 Correct 524 ms 596 KB Output is correct
29 Correct 1194 ms 856 KB Output is correct
30 Correct 1376 ms 856 KB Output is correct
31 Correct 1388 ms 984 KB Output is correct
32 Correct 1400 ms 984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 272 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 15 ms 372 KB Output is correct
19 Correct 7 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 21 ms 348 KB Output is correct
22 Correct 141 ms 420 KB Output is correct
23 Correct 12 ms 328 KB Output is correct
24 Correct 546 ms 596 KB Output is correct
25 Correct 267 ms 468 KB Output is correct
26 Correct 1396 ms 856 KB Output is correct
27 Correct 1332 ms 856 KB Output is correct
28 Correct 524 ms 596 KB Output is correct
29 Correct 1194 ms 856 KB Output is correct
30 Correct 1376 ms 856 KB Output is correct
31 Correct 1388 ms 984 KB Output is correct
32 Correct 1400 ms 984 KB Output is correct
33 Incorrect 4 ms 856 KB Output isn't correct
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 168 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 168 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 272 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 15 ms 372 KB Output is correct
19 Correct 7 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 21 ms 348 KB Output is correct
22 Correct 141 ms 420 KB Output is correct
23 Correct 12 ms 328 KB Output is correct
24 Correct 546 ms 596 KB Output is correct
25 Correct 267 ms 468 KB Output is correct
26 Correct 1396 ms 856 KB Output is correct
27 Correct 1332 ms 856 KB Output is correct
28 Correct 524 ms 596 KB Output is correct
29 Correct 1194 ms 856 KB Output is correct
30 Correct 1376 ms 856 KB Output is correct
31 Correct 1388 ms 984 KB Output is correct
32 Correct 1400 ms 984 KB Output is correct
33 Incorrect 4 ms 856 KB Output isn't correct
34 Halted 0 ms 0 KB -