# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1281225 | repmann | 철로 (IOI14_rail) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
int N;
int DIST[5000][5000];
//int getDistance(int i, int j)
//{
// cout << i << ' ' << j << '\n';
// int ret;
// cin >> ret;
// return ret;
//}
void findLocation(int n, int location0, int location[], int stype[])
{
N = n;
stype[0] = 1;
location[0] = location0;
vector <pair <int, int>> V;
for(int i = 1; i < N; i++)
{
DIST[0][i] = DIST[i][0] = getDistance(0, i);
V.push_back({DIST[0][i], i});
}
sort(V.begin(), V.end());
int d = V.begin()->second;
stype[d] = 2;
location[d] = location[0] + V.begin()->first;
for(int i = 1; i < N; i++)
{
if(i == d) continue;
DIST[d][i] = DIST[i][d] = getDistance(d, i);
}
for(int i = 1; i < N; i++)
{
if(i == d) continue;
if(DIST[0][i] == (DIST[0][d] + DIST[d][i]))
{
stype[i] = 1;
location[i] = location[d] - DIST[d][i];
}
else
{
stype[i] = 2;
location[i] = location[0] + DIST[0][i];
}
}
return;
}
//int main()
//{
// int n, location0;
// cin >> n >> location0;
// int location[n], stype[n];
// findLocation(n, location0, location, stype);
// for(int i = 0; i < n; i++) cout << location[i] << " \n"[i == (n - 1)];
// for(int i = 0; i < n; i++) cout << stype[i] << " \n"[i == (n - 1)];
// return 0;
//}