제출 #1330242

#제출 시각아이디문제언어결과실행 시간메모리
1330242tsetsenbileg철로 (IOI14_rail)C++20
30 / 100
304 ms98648 KiB
#include "rail.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
using ll = long long;
using pr = pair<int, int>;
const int INF = 1e9+7, MOD = 1e9+7;
vector<vector<int>> dist;
vector<int> mind;
int n, f;

int get(int i, int j) {
    if (i == j) return 0;
    if (i > j) swap(i, j);
    if (dist[i][j] == -1) return dist[i][j] = getDistance(i, j);
    else return dist[i][j];
}

void findLocation(int N, int first, int location[], int stype[]) {
    n = N; f = first;
    location[0] = first; stype[0] = 0;
    dist.resize(n, vector<int>(n, -1));
    mind.resize(n);
    for (int i = 0; i < n; i++) {
        int d = INF, node;
        for (int j = 0; j < n; j++) {
            if (i == j) continue;
            int t = get(i, j);
            if (d > t) {
                d = t;
                node = j;
            }
        }
        mind[i] = node;
    }
    for (int i = 1; i < n; i++) {
        if (get(0, i) > get(mind[0], i) && mind[0] != i) {
            if (get(mind[0], i) > get(mind[0], mind[i]) && mind[0] != mind[i]) {
                stype[i] = 1;
                location[i] = first + get(0, mind[0]) - get(mind[0], mind[i]) + get(mind[i], i);
            }
            else {
                stype[i] = 0;
                location[i] = first + get(0, mind[0]) - get(mind[0], i);
            }
        }
        else {
            if (get(0, i) > get(0, mind[i]) && mind[i] != 0) {
                stype[i] = 0;
                location[i] = first + get(0, mind[i]) - get(mind[i], i);
            }
            else {
                stype[i] = 1;
                location[i] = first + get(0, i);
            }
        }
    }
    for (int i = 0; i < n; i++) stype[i]++;
    // for (int i = 0; i < n; i++) cout << location[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...