Submission #1155123

#TimeUsernameProblemLanguageResultExecution timeMemory
1155123alexddRail (IOI14_rail)C++20
30 / 100
171 ms30188 KiB
#include "rail.h"
#include<bits/stdc++.h>
using namespace std;
int mp[5005][5005];
const int INF = 1e9;
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)
    {
        //if(ramase==0)while(1);
        ramase--;
        mp[x][y] = getDistance(x,y);
    }
    return mp[x][y];
}
void findLocation(int N, int first, int location[], int stype[])
{
    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);
    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))
        {
            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))
                {
                    if(getd(0,j) == getd(0,i) + getd(i,j))
                    {
                        stype[j] = 2;
                        location[j] = location[i] + getd(i,j);
                        sure[j] = 1;
                    }
                    else
                    {
                        stype[j] = 1;
                        location[j] = location[p] - getd(0,j);
                    }
                    /*int x = getd(0,j) - getd(0,i);
                    if(gata[x]==1)
                    {

                    }
                    else if(gata[x]==2)
                    {
                        stype[j] = 2;
                        location[j] = location[i] + getd(i,j);
                    }
                    else
                    {
                        assert(gata[x]==0);
                        if(getd(0,j) == getd(0,i) + getd(i,j))
                        {
                            stype[j] = 2;
                            location[j] = location[i] + getd(i,j);
                            gata[x]=1;
                        }
                        else
                            gata[x]=2;
                    }*/
                }
                /*
                 .(..(.)....())(((((()()(()..)..
                     i         0     p
                */
            }
        }
        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;
                    }
                }
            }
        }
    }
    //for(int i=0;i<N;i++) cerr<<stype[i]<<" "<<location[i]<<" final\n";
}
/*

.(..(.).())(((((()()(()..(..)..
           0     p       j  i


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...