Submission #429296

# Submission time Handle Problem Language Result Execution time Memory
429296 2021-06-15T20:12:10 Z abdzag Stations (IOI20_stations) C++17
0 / 100
2 ms 932 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-1) / 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 ((1<<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];
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 832 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 932 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 840 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 912 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 832 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -