Submission #534023

#TimeUsernameProblemLanguageResultExecution timeMemory
534023sidonSaveit (IOI10_saveit)C++17
100 / 100
242 ms10688 KiB
#include <bits/stdc++.h>
using namespace std;
#include "grader.h"
#include "encoder.h"

const int Z = 1000;

int p[Z], d[Z];
bool vis[Z];
vector<int> g[Z];

void dfs(int u) {
	vis[u] = 1;
	for(const int &v : g[u]) if(!vis[v]) {
		dfs(v);
		p[v] = u;
	}
}

void encode(int n, int h, int m, int *a, int *b) {

	for(int i = 0; i < m; ++i) {
		g[a[i]].push_back(b[i]);
		g[b[i]].push_back(a[i]);
	}

	dfs(0);

	for(int i = 1; i < n; ++i)
		for(int j = 0; j < 10; ++j)
			encode_bit(bool(p[i] & (1<<j)));

	vector<int> x;

	for(int r = 0; r < h; ++r) {
		queue<int> q;
		fill(d, d + n, -1);
		q.push(r);
		d[r] = 0;

		while(!empty(q)) {
			int u = q.front(); q.pop();
			for(const int &v : g[u]) if(d[v] < 0)
				d[v] = d[u] + 1, q.push(v);
		}

		for(int u = 1; u < n; ++u)
			x.push_back(1 + d[u] - d[p[u]]);
	}

	while(size(x) % 3) x.push_back(0);

	for(int i = 0; i < int(size(x)); i += 3) {
		int num = x[i] + x[i + 1] * 3 + x[i + 2] * 9;
		for(int j = 0; j < 5; ++j)
			encode_bit(bool(num & (1<<j)));
	}
	return;
}
#include <bits/stdc++.h>
using namespace std;
#include "grader.h"
#include "decoder.h"

const int Z = 1000;

int p[Z], w[Z], r;
vector<int> g[Z], x;

void dfs(int u, int par, int d) {
	hops(r, u, d);
	for(const int &v : g[u]) if(v != par)
		dfs(v, u, d + (u == p[v] ? w[v] : -w[u]));
}

void decode(int n, int h) {

	for(int i = 1; i < n; ++i) {
		for(int j = 0; j < 10; ++j)
			if(decode_bit()) p[i] |= 1<<j;
		g[i].push_back(p[i]);
		g[p[i]].push_back(i);
	}

	x.resize(n * h - h);
	while(size(x) % 3) x.push_back(0);

	for(int i = 0; i < int(size(x)); i += 3) {
		int num {};
		for(int j = 0; j < 5; ++j)
			if(decode_bit()) num |= 1<<j;

		for(int j = 0; j < 3; ++j, num /= 3)
			x[i + j] = (num % 3) - 1;
	}


	for(int pt = r = 0; r < h; ++r) {
		for(int u = 1; u < n; ++u)
			w[u] = x[pt++];
		dfs(r, r, 0);
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...