이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |