#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128 lll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
#define MAX 9223372036854775807LL
#define MIN -9223372036854775807LL
#define INF 0x3f3f3f3f3f3f3f3f
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << fixed; cout.precision(10);
#define sp << " "
#define en << "\n"
#define compress(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end())
ll n, m;
pll a[1010];
priority_queue< pair<ll, pll> > pq;
ll chk[1010][1010];
int main(void)
{
fastio
cin >> n >> m;
for(ll i = 1 ; i <= n ; i++)
cin >> a[i].fi >> a[i].se;
sort(a + 1, a + 1 + n);
for(ll i = 1 ; i <= n ; i++)
{
ll minn = INF, idx = 0;
for(ll j = 1 ; j <= n ; j++)
{
if(i == j)
continue;
if(abs(a[i].fi - a[j].fi) + abs(a[i].se - a[j].se) < minn)
{
minn = abs(a[i].fi - a[j].fi) + abs(a[i].se - a[j].se);
idx = j;
}
}
pq.push({-minn, {i, idx}});
}
while(!pq.empty() && m)
{
pair<ll, pll> qq = pq.top();
pq.pop();
if(!chk[qq.se.fi][qq.se.se])
{
chk[qq.se.fi][qq.se.se] = chk[qq.se.se][qq.se.fi] = 1;
cout << -qq.fi en;
m--;
}
ll minn = INF, idx = 0;
for(ll j = 1 ; j <= n ; j++)
{
if(qq.se.fi == j || chk[qq.se.fi][j])
continue;
if(abs(a[qq.se.fi].fi - a[j].fi) + abs(a[qq.se.fi].se - a[j].se) < minn)
{
minn = abs(a[qq.se.fi].fi - a[j].fi) + abs(a[qq.se.fi].se - a[j].se);
idx = j;
}
}
pq.push({-minn, {qq.se.fi, idx}});
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1618 ms |
10924 KB |
Output is correct |
2 |
Correct |
1587 ms |
10956 KB |
Output is correct |
3 |
Correct |
1010 ms |
8592 KB |
Output is correct |
4 |
Correct |
774 ms |
8692 KB |
Output is correct |
5 |
Correct |
1247 ms |
8200 KB |
Output is correct |
6 |
Correct |
6 ms |
5468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
604 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
604 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1618 ms |
10924 KB |
Output is correct |
2 |
Correct |
1587 ms |
10956 KB |
Output is correct |
3 |
Correct |
1010 ms |
8592 KB |
Output is correct |
4 |
Correct |
774 ms |
8692 KB |
Output is correct |
5 |
Correct |
1247 ms |
8200 KB |
Output is correct |
6 |
Correct |
6 ms |
5468 KB |
Output is correct |
7 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1618 ms |
10924 KB |
Output is correct |
2 |
Correct |
1587 ms |
10956 KB |
Output is correct |
3 |
Correct |
1010 ms |
8592 KB |
Output is correct |
4 |
Correct |
774 ms |
8692 KB |
Output is correct |
5 |
Correct |
1247 ms |
8200 KB |
Output is correct |
6 |
Correct |
6 ms |
5468 KB |
Output is correct |
7 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |