답안 #1109173

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1109173 2024-11-06T06:51:48 Z juliany2 Cultivation (JOI17_cultivation) C++17
5 / 100
1 ms 532 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()

const int N = 307;
int n, m;
int k;
array<int, 2> a[N];
vector<int> b[N];
array<int, 3> c[N];

int main() {
    cin.tie(0)->sync_with_stdio(false);

    cin >> n >> m >> k;

    vector<int> v;
    for (int i = 1; i <= k; i++) {
        cin >> a[i][0] >> a[i][1];
        v.push_back(a[i][0]);
    }

    sort(all(v));
    v.erase(unique(all(v)), v.end());

    int l = v.size();

    auto get = [&](int x) {
        return lower_bound(all(v), x) - v.begin();
    };

    for (int i = 1; i <= k; i++) {
        b[get(a[i][0])].push_back(a[i][1]);
    }

    for (int i = 0; i < l; i++) {
        sort(all(b[i]));

        c[i][0] = b[i].front() - 1;
        c[i][1] = m - b[i].back();

        for (int j = 1; j < b[i].size(); j++) {
            c[i][2] = max(c[i][2], b[i][j] - b[i][j - 1] - 1);
        }
    }

    ll ans = 1e18;
    auto check = [&](int p, int q) {
        vector<int> d;
        for (int i = 0; i < l; i++) {
            if (p >= c[i][0] && q >= c[i][1] && p + q >= c[i][2]) {
                d.push_back(v[i]);
            }
        }

        if (d.empty())
            return;

        int s = d.front() - 1, t = n - d.back(), gap = 0;
        for (int i = 1; i < d.size(); i++) {
            gap = max(gap, d[i] - d[i - 1] - 1);
        }

        ans = min(ans, 0LL + p + q + max(s + t, gap));
    };

    for (int i = 0; i < l; i++) {
        for (int j = 0; j < l; j++) {
            check(c[i][0], c[j][1]);
            if (c[j][2] >= c[i][0])
                check(c[i][0], c[j][2] - c[i][0]);
        }
    }

    cout << ans << '\n';

    return 0;
}

Compilation message

cultivation.cpp: In function 'int main()':
cultivation.cpp:43:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |         for (int j = 1; j < b[i].size(); j++) {
      |                         ~~^~~~~~~~~~~~~
cultivation.cpp: In lambda function:
cultivation.cpp:61:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |         for (int i = 1; i < d.size(); i++) {
      |                         ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 532 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 476 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 476 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 500 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 532 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 476 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 476 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 500 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Incorrect 1 ms 504 KB Output isn't correct
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 532 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 476 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 476 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 500 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Incorrect 1 ms 504 KB Output isn't correct
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 532 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 476 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 476 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 500 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Incorrect 1 ms 504 KB Output isn't correct
18 Halted 0 ms 0 KB -