#include "grader.h"
#include "encoder.h"
#include <bits/stdc++.h>
using namespace std;
void encode_number(int n,int N, int H)
{
for(int i = 1<<9; i > 0; i>>=1)
{
encode_bit((n&i)>0);
}
}
void encode(int N, int H, int P, int *A, int *B)
{
vector<vector<int>> neigh(N);
for(int i = 0; i < P; i++)
{
neigh[A[i]].push_back(B[i]);
neigh[B[i]].push_back(A[i]);
}
// BFS from all H
vector<vector<int>> distance(H,vector<int>(N,INT_MAX));
for(int h = 0; h < H; h++)
{
queue<pair<int,int>> q;
q.push({h,0});
while(q.size())
{
auto v = q.front();q.pop();
if(distance[h][v.first]!=INT_MAX) continue;
distance[h][v.first] = v.second;
for(auto i : neigh[v.first]) q.push({i,v.second+1});
}
}
vector<int> treep(N,-1);
queue<int> q;
q.push(0);
while(q.size())
{
auto v = q.front();q.pop();
for(auto i : neigh[v])
{
if(treep[i]!=-1) continue;
treep[i] = v;
q.push(i);
}
}
for(int i = 1; i < N; i++)
{
int p = treep[i];
encode_number(p,N,H);
}
for(int i = 1; i < N; i++)
{
int p = treep[i];
for(int h=1; h < H; h++)
{
switch(distance[h][i]-distance[h][p])// mostly 1, sometimes -1, rarely 0
{
case 1:
encode_bit(1);
break;
case -1:
encode_bit(0);encode_bit(1);
break;
case 0:
encode_bit(0);encode_bit(0);
break;
}
}
}
}
#include "grader.h"
#include "decoder.h"
#include <bits/stdc++.h>
using namespace std;
int decode_number(int N,int H)
{
int o=0;
for(int i = 0; i < 10; i++) o = (o<<1)+decode_bit();
return o;
}
void decode(int N, int H) {
vector<int> treep(N,-1);
vector<vector<int>> treec(N);
vector<vector<int>> distance(N,vector<int>(H,INT_MAX));
vector<vector<int>> delta(N,vector<int>(H,0));
for(int i = 0; i < H; i++) distance[i][i] = 0;
for(int i = 1; i < N; i++)
{
treep[i] = decode_number(N, H);
treec[treep[i]].push_back(i);
}
for(int i = 1; i < N; i++)
{
int p = treep[i];
delta[i][0] = 1;
for(int h = 1; h < H; h++)
{
if(decode_bit())
{
// 1
delta[i][h] = 1;
continue;
}
if(decode_bit())
{
delta[i][h] = -1;
}
else
{
delta[i][h] = 0;
}
}
}
for(int h = 1; h < H; h++)
{
int c = 0;
int t = h;
while(t!=0)
{
c += delta[t][h];
t = treep[t];
}
distance[0][h] = -c;
}
queue<int> q;
for(auto i : treec[0]) q.push(i);
while(q.size())
{
auto v = q.front(); q.pop();
for(int h = 0; h < H; h++)
{
distance[v][h] = distance[treep[v]][h] + delta[v][h];
}
for(auto i : treec[v]) q.push(i);
}
for(int h = 0; h < H; h++)
for(int c = 0; c < N; c++)
hops(h,c,distance[c][h]);
}
Compilation message
decoder.cpp: In function 'void decode(int, int)':
decoder.cpp:25:13: warning: unused variable 'p' [-Wunused-variable]
25 | int p = treep[i];
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
327 ms |
14212 KB |
Output is partially correct - 70402 call(s) of encode_bit() |
2 |
Correct |
3 ms |
4472 KB |
Output is correct - 54 call(s) of encode_bit() |
3 |
Correct |
20 ms |
5748 KB |
Output is correct - 60986 call(s) of encode_bit() |
4 |
Correct |
2 ms |
4616 KB |
Output is correct - 70 call(s) of encode_bit() |
5 |
Correct |
27 ms |
6028 KB |
Output is correct - 63441 call(s) of encode_bit() |
6 |
Correct |
34 ms |
6140 KB |
Output is partially correct - 71593 call(s) of encode_bit() |
7 |
Correct |
50 ms |
6696 KB |
Output is partially correct - 77200 call(s) of encode_bit() |
8 |
Correct |
19 ms |
5744 KB |
Output is correct - 51271 call(s) of encode_bit() |
9 |
Correct |
19 ms |
5756 KB |
Output is correct - 49156 call(s) of encode_bit() |
10 |
Correct |
20 ms |
5708 KB |
Output is correct - 48795 call(s) of encode_bit() |
11 |
Correct |
33 ms |
5984 KB |
Output is correct - 52512 call(s) of encode_bit() |
12 |
Correct |
18 ms |
5732 KB |
Output is correct - 54632 call(s) of encode_bit() |
13 |
Correct |
64 ms |
6876 KB |
Output is partially correct - 70506 call(s) of encode_bit() |
14 |
Correct |
23 ms |
5860 KB |
Output is correct - 57621 call(s) of encode_bit() |
15 |
Correct |
24 ms |
5904 KB |
Output is correct - 63702 call(s) of encode_bit() |
16 |
Correct |
56 ms |
6596 KB |
Output is correct - 62928 call(s) of encode_bit() |
17 |
Correct |
50 ms |
6500 KB |
Output is correct - 61726 call(s) of encode_bit() |
18 |
Correct |
69 ms |
6836 KB |
Output is correct - 63689 call(s) of encode_bit() |
19 |
Correct |
41 ms |
6432 KB |
Output is correct - 63697 call(s) of encode_bit() |
20 |
Correct |
84 ms |
7344 KB |
Output is correct - 69571 call(s) of encode_bit() |
21 |
Correct |
86 ms |
7668 KB |
Output is correct - 67715 call(s) of encode_bit() |
22 |
Correct |
63 ms |
6744 KB |
Output is partially correct - 74473 call(s) of encode_bit() |
23 |
Correct |
100 ms |
7912 KB |
Output is partially correct - 72871 call(s) of encode_bit() |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
327 ms |
14212 KB |
Output is partially correct - 70402 call(s) of encode_bit() |
2 |
Correct |
3 ms |
4472 KB |
Output is correct - 54 call(s) of encode_bit() |
3 |
Correct |
20 ms |
5748 KB |
Output is correct - 60986 call(s) of encode_bit() |
4 |
Correct |
2 ms |
4616 KB |
Output is correct - 70 call(s) of encode_bit() |
5 |
Correct |
27 ms |
6028 KB |
Output is correct - 63441 call(s) of encode_bit() |
6 |
Correct |
34 ms |
6140 KB |
Output is partially correct - 71593 call(s) of encode_bit() |
7 |
Correct |
50 ms |
6696 KB |
Output is partially correct - 77200 call(s) of encode_bit() |
8 |
Correct |
19 ms |
5744 KB |
Output is correct - 51271 call(s) of encode_bit() |
9 |
Correct |
19 ms |
5756 KB |
Output is correct - 49156 call(s) of encode_bit() |
10 |
Correct |
20 ms |
5708 KB |
Output is correct - 48795 call(s) of encode_bit() |
11 |
Correct |
33 ms |
5984 KB |
Output is correct - 52512 call(s) of encode_bit() |
12 |
Correct |
18 ms |
5732 KB |
Output is correct - 54632 call(s) of encode_bit() |
13 |
Correct |
64 ms |
6876 KB |
Output is partially correct - 70506 call(s) of encode_bit() |
14 |
Correct |
23 ms |
5860 KB |
Output is correct - 57621 call(s) of encode_bit() |
15 |
Correct |
24 ms |
5904 KB |
Output is correct - 63702 call(s) of encode_bit() |
16 |
Correct |
56 ms |
6596 KB |
Output is correct - 62928 call(s) of encode_bit() |
17 |
Correct |
50 ms |
6500 KB |
Output is correct - 61726 call(s) of encode_bit() |
18 |
Correct |
69 ms |
6836 KB |
Output is correct - 63689 call(s) of encode_bit() |
19 |
Correct |
41 ms |
6432 KB |
Output is correct - 63697 call(s) of encode_bit() |
20 |
Correct |
84 ms |
7344 KB |
Output is correct - 69571 call(s) of encode_bit() |
21 |
Correct |
86 ms |
7668 KB |
Output is correct - 67715 call(s) of encode_bit() |
22 |
Correct |
63 ms |
6744 KB |
Output is partially correct - 74473 call(s) of encode_bit() |
23 |
Correct |
100 ms |
7912 KB |
Output is partially correct - 72871 call(s) of encode_bit() |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
327 ms |
14212 KB |
Output is partially correct - 70402 call(s) of encode_bit() |
2 |
Correct |
3 ms |
4472 KB |
Output is correct - 54 call(s) of encode_bit() |
3 |
Correct |
20 ms |
5748 KB |
Output is correct - 60986 call(s) of encode_bit() |
4 |
Correct |
2 ms |
4616 KB |
Output is correct - 70 call(s) of encode_bit() |
5 |
Correct |
27 ms |
6028 KB |
Output is correct - 63441 call(s) of encode_bit() |
6 |
Correct |
34 ms |
6140 KB |
Output is partially correct - 71593 call(s) of encode_bit() |
7 |
Correct |
50 ms |
6696 KB |
Output is partially correct - 77200 call(s) of encode_bit() |
8 |
Correct |
19 ms |
5744 KB |
Output is correct - 51271 call(s) of encode_bit() |
9 |
Correct |
19 ms |
5756 KB |
Output is correct - 49156 call(s) of encode_bit() |
10 |
Correct |
20 ms |
5708 KB |
Output is correct - 48795 call(s) of encode_bit() |
11 |
Correct |
33 ms |
5984 KB |
Output is correct - 52512 call(s) of encode_bit() |
12 |
Correct |
18 ms |
5732 KB |
Output is correct - 54632 call(s) of encode_bit() |
13 |
Correct |
64 ms |
6876 KB |
Output is partially correct - 70506 call(s) of encode_bit() |
14 |
Correct |
23 ms |
5860 KB |
Output is correct - 57621 call(s) of encode_bit() |
15 |
Correct |
24 ms |
5904 KB |
Output is correct - 63702 call(s) of encode_bit() |
16 |
Correct |
56 ms |
6596 KB |
Output is correct - 62928 call(s) of encode_bit() |
17 |
Correct |
50 ms |
6500 KB |
Output is correct - 61726 call(s) of encode_bit() |
18 |
Correct |
69 ms |
6836 KB |
Output is correct - 63689 call(s) of encode_bit() |
19 |
Correct |
41 ms |
6432 KB |
Output is correct - 63697 call(s) of encode_bit() |
20 |
Correct |
84 ms |
7344 KB |
Output is correct - 69571 call(s) of encode_bit() |
21 |
Correct |
86 ms |
7668 KB |
Output is correct - 67715 call(s) of encode_bit() |
22 |
Correct |
63 ms |
6744 KB |
Output is partially correct - 74473 call(s) of encode_bit() |
23 |
Correct |
100 ms |
7912 KB |
Output is partially correct - 72871 call(s) of encode_bit() |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
327 ms |
14212 KB |
Output is partially correct - 70402 call(s) of encode_bit() |
2 |
Correct |
3 ms |
4472 KB |
Output is correct - 54 call(s) of encode_bit() |
3 |
Correct |
20 ms |
5748 KB |
Output is correct - 60986 call(s) of encode_bit() |
4 |
Correct |
2 ms |
4616 KB |
Output is correct - 70 call(s) of encode_bit() |
5 |
Correct |
27 ms |
6028 KB |
Output is correct - 63441 call(s) of encode_bit() |
6 |
Correct |
34 ms |
6140 KB |
Output is partially correct - 71593 call(s) of encode_bit() |
7 |
Correct |
50 ms |
6696 KB |
Output is partially correct - 77200 call(s) of encode_bit() |
8 |
Correct |
19 ms |
5744 KB |
Output is correct - 51271 call(s) of encode_bit() |
9 |
Correct |
19 ms |
5756 KB |
Output is correct - 49156 call(s) of encode_bit() |
10 |
Correct |
20 ms |
5708 KB |
Output is correct - 48795 call(s) of encode_bit() |
11 |
Correct |
33 ms |
5984 KB |
Output is correct - 52512 call(s) of encode_bit() |
12 |
Correct |
18 ms |
5732 KB |
Output is correct - 54632 call(s) of encode_bit() |
13 |
Correct |
64 ms |
6876 KB |
Output is partially correct - 70506 call(s) of encode_bit() |
14 |
Correct |
23 ms |
5860 KB |
Output is correct - 57621 call(s) of encode_bit() |
15 |
Correct |
24 ms |
5904 KB |
Output is correct - 63702 call(s) of encode_bit() |
16 |
Correct |
56 ms |
6596 KB |
Output is correct - 62928 call(s) of encode_bit() |
17 |
Correct |
50 ms |
6500 KB |
Output is correct - 61726 call(s) of encode_bit() |
18 |
Correct |
69 ms |
6836 KB |
Output is correct - 63689 call(s) of encode_bit() |
19 |
Correct |
41 ms |
6432 KB |
Output is correct - 63697 call(s) of encode_bit() |
20 |
Correct |
84 ms |
7344 KB |
Output is correct - 69571 call(s) of encode_bit() |
21 |
Correct |
86 ms |
7668 KB |
Output is correct - 67715 call(s) of encode_bit() |
22 |
Correct |
63 ms |
6744 KB |
Output is partially correct - 74473 call(s) of encode_bit() |
23 |
Correct |
100 ms |
7912 KB |
Output is partially correct - 72871 call(s) of encode_bit() |