제출 #168333

#제출 시각아이디문제언어결과실행 시간메모리
168333johutha철로 (IOI14_rail)C++14
8 / 100
423 ms872 KiB
#include "rail.h"
#include <queue>
#include <vector>
#include <iostream>
#include <set>

using namespace std;

void findLocation(int N, int first, int location[], int stype[])
{
	location[0] = first;
	stype[0] = 1;

	priority_queue<pair<int,pair<int,int>>> pq;
	vector<int> mindist(N, -1);
	mindist[0] = 0;
	set<int> notused;

	for (int i = 1; i < N; i++)
	{
		location[i] = -1;
		stype[i] = -1;
		int qdist = -getDistance(0, i);
		pq.emplace(qdist, make_pair(0, i));
		notused.insert(i);
	}

	while (!pq.empty())
	{
		auto curr = pq.top();
		pq.pop();

		int dist = -curr.first;
		int oldnr = curr.second.first;
		int newnr = curr.second.second;

		if (location[newnr] != -1) continue;

		int pos = location[oldnr] + dist*(stype[oldnr] == 1 ? 1 : -1);

		location[newnr] = pos;
		stype[newnr] = (stype[oldnr] == 1 ? 2 : 1);
		notused.erase(newnr);

		for (int i : notused)
		{
			int qdist = getDistance(newnr, i);
			if (mindist[i] != -1 || mindist[i] <= qdist) continue;
			mindist[i] = qdist;
			pq.emplace(-qdist, make_pair(newnr, i));
		}
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...