Submission #581463

#TimeUsernameProblemLanguageResultExecution timeMemory
581463kamelfanger83Rail (IOI14_rail)C++14
0 / 100
73 ms1352 KiB
#include <iostream>
#include <vector>
#include <limits>
#include "rail.h"
#include <algorithm>
#include <cassert>

using namespace std;

void findLocation(int n, int first, int location[], int stype[]){
    
    int fl = numeric_limits<int>::max();
    int ifl;
    for(int c = 1; c < n; ++c){
        if(getDistance(0,c) < fl){
            fl = getDistance(0,c);
            ifl = c;
        }
    }
    location[ifl] = first + fl;
    stype[ifl] = 2;

    int fr = numeric_limits<int>::max();
    int ifr;
    for(int c = 0; c < n; c++){
        if(c != ifl && getDistance(ifl,c) < fr){
            fr = getDistance(ifl,c);
            ifr = c;
        }
    }

    location[ifr] = first + fl - fr;
    stype[ifr] = 1;

    vector<vector<int>> ts;

    for(int sol = 0; sol < n; sol++){
        int tu = getDistance(ifl,sol);
        int td = getDistance(ifr,sol);
        ts.push_back({tu, td, sol});
    }

    sort(ts.begin(), ts.end());

    vector<int> leftdowns;
    vector<int> rightups;
    for(vector<int> t : ts){
        int tu = t[0], td = t[1], sol = t[1];
        if(tu + fr == td){
            for(int uc : leftdowns){
                int d = getDistance(uc, sol);
                if(d + (location[ifl] - location[uc]) == tu){
                    location[sol] = location[uc] + d;
                    stype[sol] = 2;
                    goto done;
                }
            }
            location[sol] = location[ifl] - tu;
            stype[sol] = 1;
            leftdowns.push_back(sol);
            done:
            ;
        }
        if(td + fr == tu){
            for(int uc : rightups){
                int d = getDistance(uc, sol);
                if(d + (location[uc] - location[ifr]) == td){
                    location[sol] = location[uc] - d;
                    stype[sol] = 1;
                    goto alsodone;
                }
            }
            location[sol] = location[ifr] + td;
            stype[sol] = 2;
            rightups.push_back(sol);
            alsodone:
            ;
        }
        else{
            //assert(false);
        }
    }
}   

Compilation message (stderr)

rail.cpp: In function 'void findLocation(int, int, int*, int*)':
rail.cpp:20:14: warning: 'ifl' may be used uninitialized in this function [-Wmaybe-uninitialized]
   20 |     location[ifl] = first + fl;
      |              ^~~
rail.cpp:32:14: warning: 'ifr' may be used uninitialized in this function [-Wmaybe-uninitialized]
   32 |     location[ifr] = first + fl - fr;
      |              ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...