Submission #212179

# Submission time Handle Problem Language Result Execution time Memory
212179 2020-03-22T12:16:26 Z mode149256 Saveit (IOI10_saveit) C++14
50 / 100
269 ms 12016 KB
#include <bits/stdc++.h>
#include "grader.h"
#include "encoder.h"
using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef vector<pi> vpi;
typedef vector<vpi> vpii;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<pd> vpd;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef std::string str;
typedef std::vector<str> vs;

#define x first
#define y second
#define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n"

const int MOD = 1000000007;
const ll INF = std::numeric_limits<ll>::max();
const int MX = 100101;
const ld PI = 3.14159265358979323846264338327950288419716939937510582097494L;

template<typename T>
pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x + b.x, a.y + b.y); }
template<typename T>
pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x - b.x, a.y - b.y); }
template<typename T>
T operator*(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.x + a.y * b.y); }
template<typename T>
T operator^(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.y - a.y * b.x); }

template<typename T>
void print(vector<T> vec, string name = "") {
	cout << name;
	for (auto u : vec)
		cout << u << ' ';
	cout << '\n';
}


void dfs1(int x, int p, vii &ats, vii &fast, vii &edges, int N, int H, vi &par) {
	par[x] = p;
	// printf("einu x = %d, p = %d\n", x, p);
	for (int h = 0; h < H; ++h)
	{
		if (fast[h][x] == fast[h][p]) ats[h][x] = 0;
		else if (fast[h][x] + 1 == fast[h][p]) ats[h][x] = 1;
		else ats[h][x] = 2;
		// if (x == 1 and i == 0) printf("fx = %d, fp = %d, ats = %d\n", fast[x][i], fast[p][i], ats[x][i]);
	}

	for (auto u : edges[x])
		if (u != p)
			dfs1(u, x, ats, fast, edges, N, H, par);
}

void encode(int nv, int nh, int ne, int *v1, int *v2) {
	vii edges;
	int N, H;
	N = nv;
	H = nh;
	int P = ne;
	edges = vii(N);
	vii visos(N);

	for (int i = 0; i < P; ++i)
	{
		int a = v1[i];
		int b = v2[i];
		visos[a].emplace_back(b);
		visos[b].emplace_back(a);
	}

	vii fast(H, vi(N, MOD));

	for (int i = 0; i < H; ++i)
	{
		fast[i][i] = 0;
		queue<int> q;
		q.push(i);
		while (q.size()) {
			int c = q.front(); q.pop();
			for (auto u : visos[c]) {
				if (fast[i][c] + 1 < fast[i][u]) {
					fast[i][u] = fast[i][c] + 1;
					q.push(u);
					if (!i) {
						edges[c].emplace_back(u);
						edges[u].emplace_back(c);
					}
				}
			}
		}
	}

	// for (auto u : trans)
	// printf("%d %d\n", u.x, u.y);
	// assert((int)trans.size() == N - 1);

	auto encode = [&](int a) {
		for (int i = 0; i < 10; ++i)
			encode_bit((a >> i) & 1);
	};

	// 20*(N-1)

	// 0 - same
	// 1 - +1
	// 2 - -1
	vii ats(H, vi(N, MOD));

	vi par(N);
	dfs1(0, 0, ats, fast, edges, N, H, par);

	for (int i = 0; i < N; ++i)
		encode(par[i]);
	// for (auto u : edges[0])
	// dfs1(u, 0, ats, fast, edges, N, H);

	auto encode_sm = [&](int a) {
		for (int i = 0; i < 2; ++i)
			encode_bit((a >> i) & 1);
	};

	// printf("ats in encode\n");
	for (int i = 0; i < H; ++i)
	{
		for (int j = 0; j < N; ++j)
		{
			// printf("%d ", ats[i][j]);
			encode_sm(ats[i][j]);
		}
		// printf("\n");
	}
}
#include <bits/stdc++.h>
#include "grader.h"
#include "decoder.h"
using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef vector<pi> vpi;
typedef vector<vpi> vpii;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<pd> vpd;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef std::string str;
typedef std::vector<str> vs;

#define x first
#define y second
#define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n"

const int MOD = 1000000007;
const ll INF = std::numeric_limits<ll>::max();
const int MX = 100101;
const ld PI = 3.14159265358979323846264338327950288419716939937510582097494L;

template<typename T>
pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x + b.x, a.y + b.y); }
template<typename T>
pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x - b.x, a.y - b.y); }
template<typename T>
T operator*(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.x + a.y * b.y); }
template<typename T>
T operator^(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.y - a.y * b.x); }

template<typename T>
void print(vector<T> vec, string name = "") {
	cout << name;
	for (auto u : vec)
		cout << u << ' ';
	cout << '\n';
}



void dfs2(int x, int p, vii &gautas, vii &ats, vii &edges, int N, int H) {

	for (int h = 0; h < H; ++h)
	{
		if (gautas[h][x] == 0) ats[h][x] = ats[h][p];
		else if (gautas[h][x] == 1) ats[h][x] = ats[h][p] - 1;
		else ats[h][x] = ats[h][p] + 1;
	}

	for (auto u : edges[x])
		if (u != p)
			dfs2(u, x, gautas, ats, edges, N, H);
}

void decode(int nv, int nh) {
	vii edges;
	int N, H;
	N = nv;
	H = nh;

	edges = vii(N);
	auto decode = [&]() -> int {
		int ret = 0;
		for (int i = 0; i < 10; ++i)
		{
			ret |= (decode_bit() << i);
		}
		// printf("decodinu %d\n", ret);
		return ret;
	};

	auto decode_sm = [&]() -> int {
		int ret = 0;
		for (int i = 0; i < 2; ++i)
			ret |= (decode_bit() << i);
		return ret;
	};

	for (int i = 0; i < N; ++i)
	{
		int a = decode();
		edges[a].emplace_back(i);
		edges[i].emplace_back(a);
	}

	vii ats(H, vi(N, 0));

	ats[0] = vi(N, MOD);
	ats[0][0] = 0;
	queue<int> q;
	q.push(0);
	while (q.size()) {
		int c = q.front(); q.pop();
		for (auto u : edges[c]) {
			if (ats[0][c] + 1 < ats[0][u]) {
				ats[0][u] = ats[0][c] + 1;
				if (u < H) ats[u][0] = ats[0][u];
				q.push(u);
			}
		}
	}

	// print(ats[0]);
	vii gautas(H, vi(N));
	for (int i = 0; i < H; ++i)
	{
		for (int j = 0; j < N; ++j)
		{
			gautas[i][j] = decode_sm();
		}
	}

	dfs2(0, 0, gautas, ats, edges, N, H);
	// for (auto u : edges[0])
	// dfs2(u, 0, gautas, ats, edges, N, H);

	// printf("ats in decode\n");
	for (int i = 0; i < H; ++i)
	{
		for (int j = 0; j < N; ++j)
		{
			// printf("%d ", ats[i][j]);
			hops(i, j, ats[i][j]);
		}
		// printf("\n");
	}
}
# Verdict Execution time Memory Grader output
1 Correct 269 ms 12016 KB Output is partially correct - 82000 call(s) of encode_bit()
2 Correct 12 ms 4608 KB Output is correct - 80 call(s) of encode_bit()
3 Correct 34 ms 6044 KB Output is partially correct - 73800 call(s) of encode_bit()
4 Correct 11 ms 4936 KB Output is correct - 100 call(s) of encode_bit()
5 Correct 38 ms 6400 KB Output is partially correct - 73800 call(s) of encode_bit()
6 Correct 40 ms 6408 KB Output is partially correct - 82000 call(s) of encode_bit()
7 Correct 60 ms 6812 KB Output is partially correct - 82000 call(s) of encode_bit()
8 Correct 38 ms 6144 KB Output is partially correct - 78802 call(s) of encode_bit()
9 Correct 41 ms 6272 KB Output is partially correct - 82000 call(s) of encode_bit()
10 Correct 44 ms 6272 KB Output is partially correct - 82000 call(s) of encode_bit()
11 Correct 45 ms 6400 KB Output is partially correct - 82000 call(s) of encode_bit()
12 Correct 38 ms 6272 KB Output is partially correct - 82000 call(s) of encode_bit()
13 Correct 73 ms 7048 KB Output is partially correct - 82000 call(s) of encode_bit()
14 Correct 45 ms 6340 KB Output is partially correct - 82000 call(s) of encode_bit()
15 Correct 43 ms 6500 KB Output is partially correct - 82000 call(s) of encode_bit()
16 Correct 62 ms 6912 KB Output is partially correct - 82000 call(s) of encode_bit()
17 Correct 61 ms 6856 KB Output is partially correct - 82000 call(s) of encode_bit()
18 Correct 70 ms 7136 KB Output is partially correct - 82000 call(s) of encode_bit()
19 Correct 64 ms 6520 KB Output is partially correct - 82000 call(s) of encode_bit()
20 Correct 97 ms 7356 KB Output is partially correct - 82000 call(s) of encode_bit()
21 Correct 86 ms 7524 KB Output is partially correct - 82000 call(s) of encode_bit()
22 Correct 69 ms 6904 KB Output is partially correct - 82000 call(s) of encode_bit()
23 Correct 105 ms 7680 KB Output is partially correct - 82000 call(s) of encode_bit()
# Verdict Execution time Memory Grader output
1 Correct 269 ms 12016 KB Output is partially correct - 82000 call(s) of encode_bit()
2 Correct 12 ms 4608 KB Output is correct - 80 call(s) of encode_bit()
3 Correct 34 ms 6044 KB Output is partially correct - 73800 call(s) of encode_bit()
4 Correct 11 ms 4936 KB Output is correct - 100 call(s) of encode_bit()
5 Correct 38 ms 6400 KB Output is partially correct - 73800 call(s) of encode_bit()
6 Correct 40 ms 6408 KB Output is partially correct - 82000 call(s) of encode_bit()
7 Correct 60 ms 6812 KB Output is partially correct - 82000 call(s) of encode_bit()
8 Correct 38 ms 6144 KB Output is partially correct - 78802 call(s) of encode_bit()
9 Correct 41 ms 6272 KB Output is partially correct - 82000 call(s) of encode_bit()
10 Correct 44 ms 6272 KB Output is partially correct - 82000 call(s) of encode_bit()
11 Correct 45 ms 6400 KB Output is partially correct - 82000 call(s) of encode_bit()
12 Correct 38 ms 6272 KB Output is partially correct - 82000 call(s) of encode_bit()
13 Correct 73 ms 7048 KB Output is partially correct - 82000 call(s) of encode_bit()
14 Correct 45 ms 6340 KB Output is partially correct - 82000 call(s) of encode_bit()
15 Correct 43 ms 6500 KB Output is partially correct - 82000 call(s) of encode_bit()
16 Correct 62 ms 6912 KB Output is partially correct - 82000 call(s) of encode_bit()
17 Correct 61 ms 6856 KB Output is partially correct - 82000 call(s) of encode_bit()
18 Correct 70 ms 7136 KB Output is partially correct - 82000 call(s) of encode_bit()
19 Correct 64 ms 6520 KB Output is partially correct - 82000 call(s) of encode_bit()
20 Correct 97 ms 7356 KB Output is partially correct - 82000 call(s) of encode_bit()
21 Correct 86 ms 7524 KB Output is partially correct - 82000 call(s) of encode_bit()
22 Correct 69 ms 6904 KB Output is partially correct - 82000 call(s) of encode_bit()
23 Correct 105 ms 7680 KB Output is partially correct - 82000 call(s) of encode_bit()
# Verdict Execution time Memory Grader output
1 Correct 269 ms 12016 KB Output is partially correct - 82000 call(s) of encode_bit()
2 Correct 12 ms 4608 KB Output is correct - 80 call(s) of encode_bit()
3 Correct 34 ms 6044 KB Output is partially correct - 73800 call(s) of encode_bit()
4 Correct 11 ms 4936 KB Output is correct - 100 call(s) of encode_bit()
5 Correct 38 ms 6400 KB Output is partially correct - 73800 call(s) of encode_bit()
6 Correct 40 ms 6408 KB Output is partially correct - 82000 call(s) of encode_bit()
7 Correct 60 ms 6812 KB Output is partially correct - 82000 call(s) of encode_bit()
8 Correct 38 ms 6144 KB Output is partially correct - 78802 call(s) of encode_bit()
9 Correct 41 ms 6272 KB Output is partially correct - 82000 call(s) of encode_bit()
10 Correct 44 ms 6272 KB Output is partially correct - 82000 call(s) of encode_bit()
11 Correct 45 ms 6400 KB Output is partially correct - 82000 call(s) of encode_bit()
12 Correct 38 ms 6272 KB Output is partially correct - 82000 call(s) of encode_bit()
13 Correct 73 ms 7048 KB Output is partially correct - 82000 call(s) of encode_bit()
14 Correct 45 ms 6340 KB Output is partially correct - 82000 call(s) of encode_bit()
15 Correct 43 ms 6500 KB Output is partially correct - 82000 call(s) of encode_bit()
16 Correct 62 ms 6912 KB Output is partially correct - 82000 call(s) of encode_bit()
17 Correct 61 ms 6856 KB Output is partially correct - 82000 call(s) of encode_bit()
18 Correct 70 ms 7136 KB Output is partially correct - 82000 call(s) of encode_bit()
19 Correct 64 ms 6520 KB Output is partially correct - 82000 call(s) of encode_bit()
20 Correct 97 ms 7356 KB Output is partially correct - 82000 call(s) of encode_bit()
21 Correct 86 ms 7524 KB Output is partially correct - 82000 call(s) of encode_bit()
22 Correct 69 ms 6904 KB Output is partially correct - 82000 call(s) of encode_bit()
23 Correct 105 ms 7680 KB Output is partially correct - 82000 call(s) of encode_bit()
# Verdict Execution time Memory Grader output
1 Correct 269 ms 12016 KB Output is partially correct - 82000 call(s) of encode_bit()
2 Correct 12 ms 4608 KB Output is correct - 80 call(s) of encode_bit()
3 Correct 34 ms 6044 KB Output is partially correct - 73800 call(s) of encode_bit()
4 Correct 11 ms 4936 KB Output is correct - 100 call(s) of encode_bit()
5 Correct 38 ms 6400 KB Output is partially correct - 73800 call(s) of encode_bit()
6 Correct 40 ms 6408 KB Output is partially correct - 82000 call(s) of encode_bit()
7 Correct 60 ms 6812 KB Output is partially correct - 82000 call(s) of encode_bit()
8 Correct 38 ms 6144 KB Output is partially correct - 78802 call(s) of encode_bit()
9 Correct 41 ms 6272 KB Output is partially correct - 82000 call(s) of encode_bit()
10 Correct 44 ms 6272 KB Output is partially correct - 82000 call(s) of encode_bit()
11 Correct 45 ms 6400 KB Output is partially correct - 82000 call(s) of encode_bit()
12 Correct 38 ms 6272 KB Output is partially correct - 82000 call(s) of encode_bit()
13 Correct 73 ms 7048 KB Output is partially correct - 82000 call(s) of encode_bit()
14 Correct 45 ms 6340 KB Output is partially correct - 82000 call(s) of encode_bit()
15 Correct 43 ms 6500 KB Output is partially correct - 82000 call(s) of encode_bit()
16 Correct 62 ms 6912 KB Output is partially correct - 82000 call(s) of encode_bit()
17 Correct 61 ms 6856 KB Output is partially correct - 82000 call(s) of encode_bit()
18 Correct 70 ms 7136 KB Output is partially correct - 82000 call(s) of encode_bit()
19 Correct 64 ms 6520 KB Output is partially correct - 82000 call(s) of encode_bit()
20 Correct 97 ms 7356 KB Output is partially correct - 82000 call(s) of encode_bit()
21 Correct 86 ms 7524 KB Output is partially correct - 82000 call(s) of encode_bit()
22 Correct 69 ms 6904 KB Output is partially correct - 82000 call(s) of encode_bit()
23 Correct 105 ms 7680 KB Output is partially correct - 82000 call(s) of encode_bit()