답안 #801565

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
801565 2023-08-02T06:38:33 Z 이동현(#10092) Cultivation (JOI17_cultivation) C++17
5 / 100
2000 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]);
    //     dpu.push_back(a[i][0] + 1);
    //     dpu.push_back(a[i][0] + 2);

    //     dpu.push_back(r - a[i][0] - 1);
    //     dpu.push_back(r - a[i][0]);
    //     dpu.push_back(r - a[i][0] + 1);
    //     for(int j = i + 1; j < n; ++j){
    //         dpu.push_back(a[j][0] - a[i][0]);
    //         dpu.push_back(a[j][0] - a[i][0] + 1);
    //         dpu.push_back(a[j][0] - a[i][0] + 2);
    //     }
    // }

    for(int i = 0; i <= r * 2; ++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;

        auto insol = [&](int stpos){
            int lmx = 0, rmx = 0, lenmx = 0;
            for(int i = stpos; i < stpos + 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]);
                    }
                }
            }

            rv = min(rv, max(lenmx - 1, lmx + rmx));
        };
        // for(int i = 0; i < r; ++i){
        //     insol(i);
        // }

        for(int i = 0; i < n; ++i){
            insol(a[i][0]);
        }

        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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 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 0 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 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 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 0 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 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 2 ms 212 KB Output is correct
18 Correct 40 ms 300 KB Output is correct
19 Correct 22 ms 320 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 63 ms 300 KB Output is correct
22 Correct 371 ms 296 KB Output is correct
23 Correct 32 ms 212 KB Output is correct
24 Correct 1462 ms 300 KB Output is correct
25 Correct 717 ms 300 KB Output is correct
26 Execution timed out 2060 ms 304 KB Time limit exceeded
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 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 0 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 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 2 ms 212 KB Output is correct
18 Correct 40 ms 300 KB Output is correct
19 Correct 22 ms 320 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 63 ms 300 KB Output is correct
22 Correct 371 ms 296 KB Output is correct
23 Correct 32 ms 212 KB Output is correct
24 Correct 1462 ms 300 KB Output is correct
25 Correct 717 ms 300 KB Output is correct
26 Execution timed out 2060 ms 304 KB Time limit exceeded
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 185 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 185 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 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 0 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 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 2 ms 212 KB Output is correct
18 Correct 40 ms 300 KB Output is correct
19 Correct 22 ms 320 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 63 ms 300 KB Output is correct
22 Correct 371 ms 296 KB Output is correct
23 Correct 32 ms 212 KB Output is correct
24 Correct 1462 ms 300 KB Output is correct
25 Correct 717 ms 300 KB Output is correct
26 Execution timed out 2060 ms 304 KB Time limit exceeded
27 Halted 0 ms 0 KB -