Submission #1153450

#TimeUsernameProblemLanguageResultExecution timeMemory
1153450alexddRail (IOI14_rail)C++20
56 / 100
241 ms67564 KiB
#include "rail.h"
#include<bits/stdc++.h>
using namespace std;
int mp[5005][5005];
const int INF = 1e9;
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)
        mp[x][y] = getDistance(x,y);
    return mp[x][y];
}
void findLocation(int N, int first, int location[], int stype[])
{
    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;
    for(int pas=1;pas<d0.size();pas++)
    {
        int i = d0[pas].second;
        if(stype[i]!=0)
            continue;
        if(getd(0,i) == getd(0,p) + getd(p,i))
        {
            stype[i] = 1;
            location[i] = location[p] - getd(p,i);
            for(int j=0;j<N;j++)
            {
                if(stype[j]!=0)
                    continue;
                if(getd(0,j) == getd(0,p) + getd(p,i) + getd(i,j))
                {
                    stype[j] = 2;
                    location[j] = location[i] + getd(i,j);
                }
            }
        }
        else
        {
            stype[i] = 2;
            location[i] = location[0] + getd(0,i);
            for(int j=0;j<N;j++)
            {
                if(stype[j]!=0)
                    continue;
                if(getd(i,j) < getd(0,i) && getd(0,j) == getd(0,i) + getd(i,j))
                {
                    stype[j] = 1;
                    location[j] = location[i] - getd(i,j);
                }
            }
        }
    }
    //for(int i=0;i<N;i++) cerr<<stype[i]<<" "<<location[i]<<" final\n";
}
/*

........(((((()........
        0     p


..(..())(((((()()(()..)..
        0     p


2
6
1 10
1 7
1 3
2 12
2 15
2 20



*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...