Submission #893589

# Submission time Handle Problem Language Result Execution time Memory
893589 2023-12-27T07:16:27 Z vjudge1 Road Construction (JOI21_road_construction) C++17
5 / 100
10000 ms 19908 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
#define size(x) (int)x.size()

template<class S, class T>
bool chmin(S &a, const T &b) {
    return a > b && (a = b) == b;
}
template<class S, class T>
bool chmax(S &a, const T &b) {
    return a < b && (a = b) == b;
}
const int inf = 1e9 + 7;
const int INF = 1e18 + 7;
const int mod = 998244353;

int n, k;
vector<int> x, y;
multiset<int> res;

int dist(int i, int j) {
    return abs(x[i] - x[j]) + abs(y[i] - y[j]);
}

void get(int l, int r) {
    if (l >= r) return;
    int mid = (l + r) / 2;
    get(l, mid - 1), get(mid + 1, r);
    for (int i = l; i <= r; ++i) {
        if (i == mid) continue;
        res.insert(dist(i, mid));
        if (size(res) > k) res.erase(--res.end());
    }
    for (int i = l; i < mid; ++i) {
        for (int j = mid + 1; j <= r; ++j) {
            res.insert(dist(i, j));
            if (size(res) > k) res.erase(--res.end());
        }
    }
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> n >> k;
    x.resize(n), y.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i];
    }
    vector<pair<int, int>> v;
    for (int i = 0; i < n; ++i) {
        v.emplace_back(x[i], y[i]);
    }
    sort(all(v));
    for (int i = 0; i < n; ++i) {
        x[i] = v[i].first, y[i] = v[i].second;
    }
    get(0, n - 1);
    for (int i : res) {
        cout << i << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 197 ms 14676 KB Output is correct
2 Correct 204 ms 14772 KB Output is correct
3 Correct 113 ms 14676 KB Output is correct
4 Correct 84 ms 14760 KB Output is correct
5 Correct 130 ms 13488 KB Output is correct
6 Correct 26 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 10023 ms 19908 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 10041 ms 10444 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 10041 ms 10444 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 197 ms 14676 KB Output is correct
2 Correct 204 ms 14772 KB Output is correct
3 Correct 113 ms 14676 KB Output is correct
4 Correct 84 ms 14760 KB Output is correct
5 Correct 130 ms 13488 KB Output is correct
6 Correct 26 ms 344 KB Output is correct
7 Execution timed out 10012 ms 15308 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 197 ms 14676 KB Output is correct
2 Correct 204 ms 14772 KB Output is correct
3 Correct 113 ms 14676 KB Output is correct
4 Correct 84 ms 14760 KB Output is correct
5 Correct 130 ms 13488 KB Output is correct
6 Correct 26 ms 344 KB Output is correct
7 Execution timed out 10023 ms 19908 KB Time limit exceeded
8 Halted 0 ms 0 KB -