#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 = 1; 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 = 1; 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");
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
269 ms |
12016 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
2 |
Correct |
10 ms |
4744 KB |
Output is correct - 70 call(s) of encode_bit() |
3 |
Correct |
40 ms |
6016 KB |
Output is partially correct - 73790 call(s) of encode_bit() |
4 |
Correct |
11 ms |
4872 KB |
Output is correct - 90 call(s) of encode_bit() |
5 |
Correct |
41 ms |
6368 KB |
Output is partially correct - 73790 call(s) of encode_bit() |
6 |
Correct |
43 ms |
6528 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
7 |
Correct |
63 ms |
6776 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
8 |
Correct |
40 ms |
6176 KB |
Output is partially correct - 78792 call(s) of encode_bit() |
9 |
Correct |
39 ms |
6280 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
10 |
Correct |
38 ms |
6312 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
11 |
Correct |
62 ms |
6600 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
12 |
Correct |
38 ms |
6272 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
13 |
Correct |
66 ms |
7032 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
14 |
Correct |
50 ms |
6272 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
15 |
Correct |
46 ms |
6400 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
16 |
Correct |
62 ms |
6836 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
17 |
Correct |
59 ms |
6712 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
18 |
Correct |
67 ms |
7088 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
19 |
Correct |
49 ms |
6656 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
20 |
Correct |
94 ms |
7364 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
21 |
Correct |
92 ms |
7376 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
22 |
Correct |
65 ms |
6912 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
23 |
Correct |
91 ms |
7656 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
269 ms |
12016 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
2 |
Correct |
10 ms |
4744 KB |
Output is correct - 70 call(s) of encode_bit() |
3 |
Correct |
40 ms |
6016 KB |
Output is partially correct - 73790 call(s) of encode_bit() |
4 |
Correct |
11 ms |
4872 KB |
Output is correct - 90 call(s) of encode_bit() |
5 |
Correct |
41 ms |
6368 KB |
Output is partially correct - 73790 call(s) of encode_bit() |
6 |
Correct |
43 ms |
6528 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
7 |
Correct |
63 ms |
6776 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
8 |
Correct |
40 ms |
6176 KB |
Output is partially correct - 78792 call(s) of encode_bit() |
9 |
Correct |
39 ms |
6280 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
10 |
Correct |
38 ms |
6312 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
11 |
Correct |
62 ms |
6600 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
12 |
Correct |
38 ms |
6272 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
13 |
Correct |
66 ms |
7032 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
14 |
Correct |
50 ms |
6272 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
15 |
Correct |
46 ms |
6400 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
16 |
Correct |
62 ms |
6836 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
17 |
Correct |
59 ms |
6712 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
18 |
Correct |
67 ms |
7088 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
19 |
Correct |
49 ms |
6656 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
20 |
Correct |
94 ms |
7364 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
21 |
Correct |
92 ms |
7376 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
22 |
Correct |
65 ms |
6912 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
23 |
Correct |
91 ms |
7656 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
269 ms |
12016 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
2 |
Correct |
10 ms |
4744 KB |
Output is correct - 70 call(s) of encode_bit() |
3 |
Correct |
40 ms |
6016 KB |
Output is partially correct - 73790 call(s) of encode_bit() |
4 |
Correct |
11 ms |
4872 KB |
Output is correct - 90 call(s) of encode_bit() |
5 |
Correct |
41 ms |
6368 KB |
Output is partially correct - 73790 call(s) of encode_bit() |
6 |
Correct |
43 ms |
6528 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
7 |
Correct |
63 ms |
6776 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
8 |
Correct |
40 ms |
6176 KB |
Output is partially correct - 78792 call(s) of encode_bit() |
9 |
Correct |
39 ms |
6280 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
10 |
Correct |
38 ms |
6312 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
11 |
Correct |
62 ms |
6600 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
12 |
Correct |
38 ms |
6272 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
13 |
Correct |
66 ms |
7032 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
14 |
Correct |
50 ms |
6272 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
15 |
Correct |
46 ms |
6400 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
16 |
Correct |
62 ms |
6836 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
17 |
Correct |
59 ms |
6712 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
18 |
Correct |
67 ms |
7088 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
19 |
Correct |
49 ms |
6656 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
20 |
Correct |
94 ms |
7364 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
21 |
Correct |
92 ms |
7376 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
22 |
Correct |
65 ms |
6912 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
23 |
Correct |
91 ms |
7656 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
269 ms |
12016 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
2 |
Correct |
10 ms |
4744 KB |
Output is correct - 70 call(s) of encode_bit() |
3 |
Correct |
40 ms |
6016 KB |
Output is partially correct - 73790 call(s) of encode_bit() |
4 |
Correct |
11 ms |
4872 KB |
Output is correct - 90 call(s) of encode_bit() |
5 |
Correct |
41 ms |
6368 KB |
Output is partially correct - 73790 call(s) of encode_bit() |
6 |
Correct |
43 ms |
6528 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
7 |
Correct |
63 ms |
6776 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
8 |
Correct |
40 ms |
6176 KB |
Output is partially correct - 78792 call(s) of encode_bit() |
9 |
Correct |
39 ms |
6280 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
10 |
Correct |
38 ms |
6312 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
11 |
Correct |
62 ms |
6600 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
12 |
Correct |
38 ms |
6272 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
13 |
Correct |
66 ms |
7032 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
14 |
Correct |
50 ms |
6272 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
15 |
Correct |
46 ms |
6400 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
16 |
Correct |
62 ms |
6836 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
17 |
Correct |
59 ms |
6712 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
18 |
Correct |
67 ms |
7088 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
19 |
Correct |
49 ms |
6656 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
20 |
Correct |
94 ms |
7364 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
21 |
Correct |
92 ms |
7376 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
22 |
Correct |
65 ms |
6912 KB |
Output is partially correct - 81990 call(s) of encode_bit() |
23 |
Correct |
91 ms |
7656 KB |
Output is partially correct - 81990 call(s) of encode_bit() |