Submission #912454

# Submission time Handle Problem Language Result Execution time Memory
912454 2024-01-19T13:38:58 Z denniskim Road Construction (JOI21_road_construction) C++17
0 / 100
214 ms 2264 KB
#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;
 
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 = i + 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();
		
        cout << -qq.fi en;
        m--;
		
		ll minn = INF, idx = 0;
		
		for(ll j = qq.se.fi + 1 ; j <= n ; j++)
		{
			if(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;
}
# Verdict Execution time Memory Grader output
1 Incorrect 214 ms 2264 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 214 ms 2264 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 214 ms 2264 KB Output isn't correct
2 Halted 0 ms 0 KB -