제출 #917102

#제출 시각아이디문제언어결과실행 시간메모리
917102rxlfd314철로 (IOI14_rail)C++17
56 / 100
315 ms99208 KiB
#include "rail.h" #include <bits/stdc++.h> using namespace std; using ari2 = array<int, 2>; #define vt vector #define size(x) (int((x).size())) #define all(x) begin(x), end(x) #define REP(a, b, c, d) for (int a = (b); (d) > 0 ? a <= (c) : a >= (c); a += (d)) #define FOR(a, b, c) REP(a, b, c, 1) #define ROF(a, b, c) REP(a, b, c, -1) void findLocation(int N, int first, int location[], int stype[]) { FOR(i, 0, N-1) stype[i] = 0; location[0] = first; stype[0] = 1; if (N < 2) return; vt<vt<int>> D(N, vt<int>(N)); FOR(i, 0, N-1) FOR(j, i+1, N-1) { D[i][j] = getDistance(i, j); D[j][i] = D[i][j]; } int f[N]; FOR(i, 0, N-1) { ari2 best = {INT_MAX, 0}; FOR(j, 0, N-1) if (j != i) best = min(best, ari2{D[i][j], j}); f[i] = best[1]; } vt<int> adj[N]; FOR(i, 0, N-1) { adj[i].push_back(f[i]); if (i != f[f[i]]) adj[f[i]].push_back(i); } function<void(int)> dfs = [&](int i) { for (int j : adj[i]) { if (stype[j]) continue; location[j] = location[i] + (stype[i] == 1 ? 1 : -1) * D[i][j]; stype[j] = 3 - stype[i]; dfs(j); } }; dfs(0); FOR(i, 0, N-1) { if (stype[i] || i != f[f[i]]) continue; int j = f[i]; if (D[0][i] == D[0][f[0]] + D[f[0]][i]) { // to the left of 0 if (D[0][i] > D[0][j]) { // i is 2 stype[j] = 1; location[j] = location[f[0]] - D[f[0]][j]; dfs(j); } else { stype[i] = 1; location[i] = location[f[0]] - D[f[0]][i]; dfs(i); } } else { if (D[0][i] > D[0][j]) { // i is 1 stype[j] = 2; location[j] = location[0] + D[0][j]; dfs(j); } else { stype[i] = 2; location[i] = location[0] + D[0][i]; dfs(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...