Submission #945816

# Submission time Handle Problem Language Result Execution time Memory
945816 2024-03-14T07:55:48 Z itslq Road Construction (JOI21_road_construction) C++17
11 / 100
10000 ms 1054600 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

int N;
vector<int> x;

int check(int d) {
    int S = 0;
    for (int i = 0; i < N; i++) {
        S += upper_bound(x.begin(), x.end(), x[i] + d) - x.begin() - i - 1;
    }
    return S;
}

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

    int K;
    cin >> N >> K;

    if (N <= 1000) {
        vector<int> dist;
        vector<pair<int, int>> pos(N);
        for (int i = 0; i < N; i++) cin >> pos[i].first >> pos[i].second;

        for (int i = 1; i < N; i++) {
            for (int j = 0; j < i; j++) {
                dist.push_back(abs(pos[i].first - pos[j].first) + abs(pos[i].second - pos[j].second));
            }
        }

        sort(dist.begin(), dist.end());
        for (int i = 0; i < K; i++) cout << dist[i] << '\n';

    } else {
        int j;
        x.resize(N);
        for (int i = 0; i < N; i++) cin >> x[i] >> j;
        sort(x.begin(), x.end());

        int l = 0, r = 2e9, m, ans;

        while (l <= r) {
            m = (l + r) >> 1;
            if (check(m) < K) {
                ans = m;
                l = ++m;
            } else {
                r = --m;
            }
        }

        vector<int> dist;
        dist.clear();

        for (int i = 0; i < N; i++) {
            j = i + 1;
            while (j < N && x[j] - x[i] <= ans) {
                dist.push_back(x[j] - x[i]);
                j++;
            }
        }

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

        for (int x: dist) cout << x << '\n';
        for (int i = dist.size(); i < K; i++) cout << ans + 1 << '\n';
    }
}

Compilation message

road_construction.cpp: In function 'int main()':
road_construction.cpp:70:61: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   70 |         for (int i = dist.size(); i < K; i++) cout << ans + 1 << '\n';
      |                                                             ^
# Verdict Execution time Memory Grader output
1 Correct 52 ms 6844 KB Output is correct
2 Correct 52 ms 7100 KB Output is correct
3 Correct 32 ms 5056 KB Output is correct
4 Correct 35 ms 5060 KB Output is correct
5 Correct 48 ms 5816 KB Output is correct
6 Correct 18 ms 6352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 412 ms 5600 KB Output is correct
2 Correct 420 ms 8628 KB Output is correct
3 Correct 32 ms 4908 KB Output is correct
4 Correct 395 ms 8364 KB Output is correct
5 Correct 389 ms 8528 KB Output is correct
6 Correct 396 ms 8784 KB Output is correct
7 Correct 387 ms 8140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 10026 ms 1054600 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 10026 ms 1054600 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 52 ms 6844 KB Output is correct
2 Correct 52 ms 7100 KB Output is correct
3 Correct 32 ms 5056 KB Output is correct
4 Correct 35 ms 5060 KB Output is correct
5 Correct 48 ms 5816 KB Output is correct
6 Correct 18 ms 6352 KB Output is correct
7 Incorrect 189 ms 6704 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 52 ms 6844 KB Output is correct
2 Correct 52 ms 7100 KB Output is correct
3 Correct 32 ms 5056 KB Output is correct
4 Correct 35 ms 5060 KB Output is correct
5 Correct 48 ms 5816 KB Output is correct
6 Correct 18 ms 6352 KB Output is correct
7 Correct 412 ms 5600 KB Output is correct
8 Correct 420 ms 8628 KB Output is correct
9 Correct 32 ms 4908 KB Output is correct
10 Correct 395 ms 8364 KB Output is correct
11 Correct 389 ms 8528 KB Output is correct
12 Correct 396 ms 8784 KB Output is correct
13 Correct 387 ms 8140 KB Output is correct
14 Execution timed out 10026 ms 1054600 KB Time limit exceeded
15 Halted 0 ms 0 KB -