Submission #1064104

#TimeUsernameProblemLanguageResultExecution timeMemory
1064104Theo830Rail (IOI14_rail)C++17
30 / 100
3060 ms196428 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9;
ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ii,ll>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
#include "rail.h"
void findLocation(int n, int first, int location[], int stype[]){
    location[0] = first;
    stype[0] = 1;
    ll dist[n][n];
    f(i,0,n){
        f(j,i+1,n){
            dist[i][j] = dist[j][i] = getDistance(i,j);
        }
    }
    ll mini = INF;
    ll pos;
    f(i,1,n){
        if(mini > dist[0][i]){
            mini = dist[0][i];
            pos = i;
        }
    }
    stype[pos] = 2;
    location[pos] = first + dist[0][pos];
    vector<ll>ex;
    bool v[n] = {0};
    ex.pb(0);
    ex.pb(pos);
    v[0] = v[pos] = 1;
    while(ex.size() != n){
        mini = INF;
        ll prev;
        f(i,0,n){
            if(!v[i]){
                for(auto x:ex){
                    if(mini > dist[i][x]){
                        mini = dist[i][x];
                        pos = i;
                        prev = x;
                    }
                }
            }
        }
        if(stype[prev] == 1){
            stype[pos] = 2;
            location[pos] = location[prev] + mini;
        }
        else{
            stype[pos] = 1;
            location[pos] = location[prev] - mini;
        }
        v[pos] = 1;
        ex.pb(pos);
    }
}

Compilation message (stderr)

rail.cpp: In function 'void findLocation(int, int, int*, int*)':
rail.cpp:50:21: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   50 |     while(ex.size() != n){
      |           ~~~~~~~~~~^~~~
rail.cpp:64:18: warning: 'prev' may be used uninitialized in this function [-Wmaybe-uninitialized]
   64 |         if(stype[prev] == 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...