Submission #893351

# Submission time Handle Problem Language Result Execution time Memory
893351 2023-12-27T03:08:14 Z vjudge1 Road Construction (JOI21_road_construction) C++17
5 / 100
10000 ms 14940 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;
const int N = 250001;

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    int x[n], y[n];
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i];
    }
    auto dist = [&](int i, int j) {
        return abs(x[i] - x[j]) + abs(y[i] - y[j]);
    };
    multiset<int> st;
    for (int i = 0; i < n; ++i) {
        priority_queue<pair<int, int>,
            vector<pair<int, int>>,
            greater<pair<int, int>>> q;
        q.push({0, i});
        vector<int> d(n, INF);
        d[i] = 0;
        while (!q.empty()) {
            int v = q.top().second;
            if (q.top().first) {
                st.insert(q.top().first);
                if (size(st) > k) {
                    st.erase(--st.end());
                }
            }
            q.pop();
            for (int j = i + 1; j < n; ++j) {
                if (chmin(d[j], d[v] + dist(v, j))) {
                    q.push({d[j], j});
                }
            }
        }
    }
    for (int i : st) {
        cout << i << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 633 ms 14672 KB Output is correct
2 Correct 638 ms 14940 KB Output is correct
3 Correct 255 ms 14676 KB Output is correct
4 Correct 255 ms 14856 KB Output is correct
5 Correct 629 ms 13516 KB Output is correct
6 Correct 511 ms 580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 10051 ms 11392 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 10062 ms 12160 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 10062 ms 12160 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 633 ms 14672 KB Output is correct
2 Correct 638 ms 14940 KB Output is correct
3 Correct 255 ms 14676 KB Output is correct
4 Correct 255 ms 14856 KB Output is correct
5 Correct 629 ms 13516 KB Output is correct
6 Correct 511 ms 580 KB Output is correct
7 Execution timed out 10013 ms 7568 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 633 ms 14672 KB Output is correct
2 Correct 638 ms 14940 KB Output is correct
3 Correct 255 ms 14676 KB Output is correct
4 Correct 255 ms 14856 KB Output is correct
5 Correct 629 ms 13516 KB Output is correct
6 Correct 511 ms 580 KB Output is correct
7 Execution timed out 10051 ms 11392 KB Time limit exceeded
8 Halted 0 ms 0 KB -