Submission #912452

# Submission time Handle Problem Language Result Execution time Memory
912452 2024-01-19T13:34:19 Z denniskim Road Construction (JOI21_road_construction) C++17
5 / 100
490 ms 10936 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;
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 = 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();
		
		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 = qq.se.fi + 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;
}
# Verdict Execution time Memory Grader output
1 Correct 486 ms 10936 KB Output is correct
2 Correct 490 ms 10772 KB Output is correct
3 Correct 343 ms 8532 KB Output is correct
4 Correct 265 ms 8840 KB Output is correct
5 Correct 392 ms 8272 KB Output is correct
6 Correct 5 ms 3160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 486 ms 10936 KB Output is correct
2 Correct 490 ms 10772 KB Output is correct
3 Correct 343 ms 8532 KB Output is correct
4 Correct 265 ms 8840 KB Output is correct
5 Correct 392 ms 8272 KB Output is correct
6 Correct 5 ms 3160 KB Output is correct
7 Runtime error 1 ms 600 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 486 ms 10936 KB Output is correct
2 Correct 490 ms 10772 KB Output is correct
3 Correct 343 ms 8532 KB Output is correct
4 Correct 265 ms 8840 KB Output is correct
5 Correct 392 ms 8272 KB Output is correct
6 Correct 5 ms 3160 KB Output is correct
7 Incorrect 1 ms 344 KB Output isn't correct
8 Halted 0 ms 0 KB -