Submission #730263

#TimeUsernameProblemLanguageResultExecution timeMemory
730263ogibogi2004Rail (IOI14_rail)C++14
0 / 100
80 ms720 KiB
#include "rail.h"
#include<bits/stdc++.h>
using namespace std;

void findLocation(int N, int first, int location[], int stype[])
{
    location[0]=first;
    stype[0]=1;
    vector<pair<int,int> >distances;
    vector<int>dist_by_ind(N);
    for(int i=1;i<N;i++)
    {
        distances.push_back({getDistance(0, i),i});
        dist_by_ind[i]=distances.back().first;
    }
    sort(distances.begin(),distances.end());
    location[distances[0].second]=location[0]+distances[0].first;
    stype[distances[0].second]=2;
    set<int>cs;
    set<int>ds;
    int minc=0,maxd=distances[0].second;
    cs.insert(location[0]);
    ds.insert(location[distances[0].second]);
    for(int i=1;i<distances.size();i++)
    {
        int j=distances[i].second;
        int disl=getDistance(j,minc);
        int disr=getDistance(j,maxd);
        bool flag=1;
        if(true)
        {
            flag=0;
            //then next is D, it might be to the right of maxd or to the left
            //if dist(minc,maxd)>disl => its between L and R
            //otherwise it is after R
            location[j]=location[minc]+disl;
            int needed_locationC=(location[j]+location[maxd]-disr)/2;//location[j]+location[maxd]-2*ne=disr =>
            int needed_locationD=(disl-location[j]-location[minc])/2;//location[j]+location[maxd]-2*ne=disr =>
            if(cs.find(needed_locationC)==cs.end()||ds.find(needed_locationD)==ds.end())
            {
                //not possible
                //next case
                //cout<<"&& "<<j<<" "<<needed_location<<" "<<location[j]<<" "<<location[maxd]<<" "<<disr<<" "<<maxd<<endl;
                flag=1;
            }
            else
            {

                stype[j]=2;
                if(location[j]>location[maxd])maxd=j;
                ds.insert(location[j]);
            }
        }
        if(flag)
        {
            if(location[maxd]-location[minc]>disr)
            {
                location[j]=location[maxd]-disr;
                stype[j]=1;
                //=> k( L( R)
            }
            else
            {
                location[j]=location[maxd]-disr;
                stype[j]=1;
                //=> L( k) R)
            }
            if(location[j]<location[minc])minc=j;
            cs.insert(location[j]);

        }
    }
    /*for(int i=0;i<N;i++)
    {
        cout<<i<<": "<<location[i]<<" "<<stype[i]<<endl;
    }*/
}

Compilation message (stderr)

rail.cpp: In function 'void findLocation(int, int, int*, int*)':
rail.cpp:24:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for(int i=1;i<distances.size();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...