Submission #598971

#TimeUsernameProblemLanguageResultExecution timeMemory
598971promaRail (IOI14_rail)C++17
56 / 100
687 ms98444 KiB
#include "rail.h"
#include <bits/stdc++.h>

using namespace std;

int d[5001][5001], used[5001];

void findLocation(int N, int first, int location[], int stype[]) {
    for (int i = 0; i < N; i ++) {
        d[i][i] = 0;
        for (int j = i + 1; j < N; j ++) {
            d[i][j] = d[j][i] = getDistance(i, j);
        }
    }
    int nxt = -1, mn = 1e9;
    for (int i = 1; i < N; i ++) {
        if (mn > d[0][i]) {
            mn = d[0][i];
            nxt = i;
        }
    }
    stype[0] = 1;
    location[0] = first;
    stype[nxt] = 2;
    location[nxt] = first + mn;
    // finding D that go before 0
    for (int i = 1; i < N; i ++) {
        if (i == nxt) continue;
        int flag = 0;
        for (int j = 1; j < N; j ++) {
            if (j == i or j == nxt) continue;
            if (d[0][i] == d[0][nxt] + d[nxt][j] + d[j][i]) {
                flag = 1;
                stype[i] = 2;
                location[i] = first + d[0][nxt] - d[nxt][j] + d[j][i];
                break;
            }
        }
        if (!flag) {
            for (int j = 1; j < N; j ++) {
                if (i == j) continue;
                if (d[0][i] == d[0][j] + d[j][i]) {
                    flag = 1;
                    stype[i] = 1;
                    location[i] = first + d[0][j] - d[j][i];
                    break;
                }
            }
        }
        if (!flag) {
            stype[i] = 2;
            location[i] = first + d[0][i];
        }
//        cout << i << ": " << stype[i] << " " << location[i] << endl;
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...