제출 #1229223

#제출 시각아이디문제언어결과실행 시간메모리
1229223badge881철로 (IOI14_rail)C++20
56 / 100
354 ms67176 KiB
#include "rail.h"
#include <bits/stdc++.h>
using namespace std;

const int INF = 1e9;

int mp[5005][5005];
int ramase;

int getd(int x, int y)
{
    if (x == y)
        return 0;
    if (x < 0 || y < 0)
        return INF;
    if (x > y)
        swap(x, y);
    if (mp[x][y] == 0)
    {
        ramase--;
        mp[x][y] = getDistance(x, y);
    }
    return mp[x][y];
}

void findLocation(int N, int first, int location[], int stype[])
{
    for (int i = 0; i < N; i++)
        location[i] = 0;
    ramase = 3 * (N - 1);
    location[0] = first;
    stype[0] = 1;
    vector<pair<int, int>> d0;
    for (int i = 1; i < N; i++)
        d0.push_back({getd(0, i), i});
    sort(d0.begin(), d0.end());
    int p = d0[0].second;
    location[p] = location[0] + getd(0, p);
    stype[p] = 2;
    vector<bool> sure(N, 0), semi(N, 0), rau(N, 0);
    sure[0] = sure[p] = 1;
    for (int pas = 1; pas < d0.size(); pas++)
    {
        int i = d0[pas].second;
        if (sure[i])
            continue;
        if (getd(0, i) == getd(0, p) + getd(p, i))
        {
            if (semi[i])
                assert(location[i] == location[p] - getd(p, i));

            stype[i] = 1;
            location[i] = location[p] - getd(p, i);
            sure[i] = 1;
            map<int, int> gata;
            for (auto [_, j] : d0)
            {
                if (stype[j] != 0)
                    continue;
                if (getd(0, j) == getd(0, p) + getd(p, j) && getd(0, i) < getd(0, j) && getd(0, j) < 2 * getd(0, i))
                {
                    int x = getd(0, j) - getd(0, i);
                    if (!gata[x] && getd(0, j) == getd(0, i) + getd(i, j))
                    {
                        stype[j] = 2;
                        location[j] = location[i] + getd(i, j);
                        sure[j] = 1;
                        gata[x] = 1;
                    }
                }
            }
        }
        else
        {
            stype[i] = 2;
            location[i] = location[0] + getd(0, i);
            sure[i] = 1;
            for (int j = 0; j < N; j++)
            {
                if (stype[j] != 0)
                    continue;
                if (getd(0, i) < getd(0, j) && getd(0, j) < 2 * getd(0, i))
                {
                    if (getd(0, j) == getd(0, i) + getd(i, j))
                    {
                        stype[j] = 1;
                        location[j] = location[i] - getd(i, j);
                        sure[j] = 1;
                    }
                }
            }
        }
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...