답안 #429278

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
429278 2021-06-15T19:55:51 Z abdzag 기지국 (IOI20_stations) C++17
0 / 100
2 ms 960 KB
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
#include "stations.h"
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
#define rrep(i,a,b) for(int i=int(a);i>int(b);i--)
#define trav(a,v) for(auto& a: v)
#define sz(v) v.size()
#define all(v) v.begin(),v.end()
#define vi vector<int>

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const long long inf = 2e9;

using namespace std;

vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	vector<int> ans;
	rep(i, 0, n)ans[i] = i;
	return ans;
}
bool done = 0;
vector<vector<ll>> parents(32, vector<ll>(1001));
vector<ll> depth(1001);
void dfs(ll cur, ll val) {
	if (cur > 1000)return;
	depth[cur] = val;
	dfs(cur * 2 + 2, val + 1);
	dfs(cur * 2 + 1, val + 1);
}
void init_parents() {
	rep(i, 0, 1001) {
		parents[0][i] = i / 2;
	}
	rep(i, 1, 32) {
		rep(j, 0, 1001) {
			parents[i][j] = parents[i-1][parents[i - 1][j]];
		}
	}
	dfs(0, 0);
}
ll lca(ll a, ll b) {
	if (depth[a] > depth[b])swap(a, b);
	ll diff = depth[b] - depth[a];
	rrep(i, 31, -1) {
		if (i & diff)b = parents[i][b];
	}
	if (a == b)return a;
	rep(i, 0, 31) {
		if (parents[i][a] != parents[i][b]) {
			a = parents[i][a];
			b = parents[i][b];
		}
	}
	return parents[0][a];
}
int find_next_station(int s, int t, vector<int> c) {
	if (!done)init_parents();
	done = 1;
	if (c.size() == 1)return c[0];
	else if (c.size() == 2) {
		if (t == c[1])return c[1];
		else return c[0];
	}
	if (lca(t, c[1]) == c[1])return c[1];
	if (lca(t, c[1]) == c[2])return c[2];
	return c[0];
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 960 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 928 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 840 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 796 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 928 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -