#include <bits/stdc++.h>
#include "grader.h"
#include "encoder.h"
using namespace std;
typedef long long ll;
void encode(int n,int h,int m,int *A,int *B)
{
vector<int> v[n];
for(int i=0;i<m;i++)
{
int a=A[i],b=B[i];
v[a].push_back(b);
v[b].push_back(a);
}
vector<int> g[n];
vector<int> p(n,-1);
function<void(int)> dfs=[&](int a)
{
for(int to:v[a])
{
if(p[to]!=-1) continue;
g[a].push_back(to);
g[to].push_back(a);
p[to]=a;
dfs(to);
}
};
p[0]=-2;
dfs(0);
for(int i=1;i<n;i++) for(int j=9;j>=0;j--) encode_bit((p[i]>>j)&1);
for(int i=0;i<h;i++)
{
queue<int> q;
vector<int> d(n,-1);
auto add=[&](int a,int nd)
{
if(d[a]==-1)
{
d[a]=nd;
q.push(a);
}
};
add(i,0);
while(!q.empty())
{
int a=q.front();
q.pop();
for(int to:v[a]) add(to,d[a]+1);
}
vector<int> x(n+2,0);
function<void(int,int)> go=[&](int a,int u)
{
if(u!=-1) x[a]=(d[a]-d[u]+1);
for(int to:g[a]) if(to!=u) go(to,a);
};
go(i,-1);
for(int j=0;j<n;j+=3)
{
int t=(9*x[j]+3*x[j+1]+x[j+2]);
for(int k=4;k>=0;k--) encode_bit((t>>k)&1);
}
}
}
#include <bits/stdc++.h>
#include "grader.h"
#include "decoder.h"
using namespace std;
typedef long long ll;
void decode(int n,int h)
{
vector<int> v[n];
auto dec=[&](int c)->int
{
int t=0;
for(int i=0;i<c;i++) t=2*t+decode_bit();
return t;
};
for(int i=1;i<n;i++)
{
int p=dec(10);
v[i].push_back(p);
v[p].push_back(i);
}
for(int i=0;i<h;i++)
{
vector<int> x(n+2,0);
for(int j=0;j<n;j+=3)
{
int t=dec(5);
for(int k=2;k>=0;k--)
{
x[j+k]=(t%3)-1;
t/=3;
}
}
vector<int> d(n,0);
function<void(int,int)> go=[&](int a,int p)
{
if(p!=-1) d[a]=d[p]+x[a];
hops(i,a,d[a]);
for(int to:v[a]) if(to!=p) go(to,a);
};
go(i,-1);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
194 ms |
10268 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
2 |
Correct |
2 ms |
4604 KB |
Output is correct - 70 call(s) of encode_bit() |
3 |
Correct |
28 ms |
5584 KB |
Output is correct - 62990 call(s) of encode_bit() |
4 |
Correct |
3 ms |
4536 KB |
Output is correct - 90 call(s) of encode_bit() |
5 |
Correct |
27 ms |
5608 KB |
Output is correct - 62990 call(s) of encode_bit() |
6 |
Correct |
26 ms |
5668 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
7 |
Correct |
45 ms |
6160 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
8 |
Correct |
24 ms |
5544 KB |
Output is correct - 67380 call(s) of encode_bit() |
9 |
Correct |
33 ms |
5428 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
10 |
Correct |
27 ms |
5440 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
11 |
Correct |
33 ms |
5500 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
12 |
Correct |
25 ms |
5548 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
13 |
Correct |
51 ms |
6216 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
14 |
Correct |
28 ms |
5548 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
15 |
Correct |
26 ms |
5524 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
16 |
Correct |
54 ms |
6040 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
17 |
Correct |
48 ms |
6044 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
18 |
Correct |
51 ms |
6376 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
19 |
Correct |
41 ms |
5796 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
20 |
Correct |
63 ms |
6516 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
21 |
Correct |
68 ms |
6760 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
22 |
Correct |
44 ms |
6188 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
23 |
Correct |
87 ms |
6852 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
194 ms |
10268 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
2 |
Correct |
2 ms |
4604 KB |
Output is correct - 70 call(s) of encode_bit() |
3 |
Correct |
28 ms |
5584 KB |
Output is correct - 62990 call(s) of encode_bit() |
4 |
Correct |
3 ms |
4536 KB |
Output is correct - 90 call(s) of encode_bit() |
5 |
Correct |
27 ms |
5608 KB |
Output is correct - 62990 call(s) of encode_bit() |
6 |
Correct |
26 ms |
5668 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
7 |
Correct |
45 ms |
6160 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
8 |
Correct |
24 ms |
5544 KB |
Output is correct - 67380 call(s) of encode_bit() |
9 |
Correct |
33 ms |
5428 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
10 |
Correct |
27 ms |
5440 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
11 |
Correct |
33 ms |
5500 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
12 |
Correct |
25 ms |
5548 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
13 |
Correct |
51 ms |
6216 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
14 |
Correct |
28 ms |
5548 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
15 |
Correct |
26 ms |
5524 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
16 |
Correct |
54 ms |
6040 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
17 |
Correct |
48 ms |
6044 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
18 |
Correct |
51 ms |
6376 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
19 |
Correct |
41 ms |
5796 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
20 |
Correct |
63 ms |
6516 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
21 |
Correct |
68 ms |
6760 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
22 |
Correct |
44 ms |
6188 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
23 |
Correct |
87 ms |
6852 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
194 ms |
10268 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
2 |
Correct |
2 ms |
4604 KB |
Output is correct - 70 call(s) of encode_bit() |
3 |
Correct |
28 ms |
5584 KB |
Output is correct - 62990 call(s) of encode_bit() |
4 |
Correct |
3 ms |
4536 KB |
Output is correct - 90 call(s) of encode_bit() |
5 |
Correct |
27 ms |
5608 KB |
Output is correct - 62990 call(s) of encode_bit() |
6 |
Correct |
26 ms |
5668 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
7 |
Correct |
45 ms |
6160 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
8 |
Correct |
24 ms |
5544 KB |
Output is correct - 67380 call(s) of encode_bit() |
9 |
Correct |
33 ms |
5428 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
10 |
Correct |
27 ms |
5440 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
11 |
Correct |
33 ms |
5500 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
12 |
Correct |
25 ms |
5548 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
13 |
Correct |
51 ms |
6216 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
14 |
Correct |
28 ms |
5548 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
15 |
Correct |
26 ms |
5524 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
16 |
Correct |
54 ms |
6040 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
17 |
Correct |
48 ms |
6044 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
18 |
Correct |
51 ms |
6376 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
19 |
Correct |
41 ms |
5796 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
20 |
Correct |
63 ms |
6516 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
21 |
Correct |
68 ms |
6760 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
22 |
Correct |
44 ms |
6188 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
23 |
Correct |
87 ms |
6852 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
194 ms |
10268 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
2 |
Correct |
2 ms |
4604 KB |
Output is correct - 70 call(s) of encode_bit() |
3 |
Correct |
28 ms |
5584 KB |
Output is correct - 62990 call(s) of encode_bit() |
4 |
Correct |
3 ms |
4536 KB |
Output is correct - 90 call(s) of encode_bit() |
5 |
Correct |
27 ms |
5608 KB |
Output is correct - 62990 call(s) of encode_bit() |
6 |
Correct |
26 ms |
5668 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
7 |
Correct |
45 ms |
6160 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
8 |
Correct |
24 ms |
5544 KB |
Output is correct - 67380 call(s) of encode_bit() |
9 |
Correct |
33 ms |
5428 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
10 |
Correct |
27 ms |
5440 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
11 |
Correct |
33 ms |
5500 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
12 |
Correct |
25 ms |
5548 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
13 |
Correct |
51 ms |
6216 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
14 |
Correct |
28 ms |
5548 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
15 |
Correct |
26 ms |
5524 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
16 |
Correct |
54 ms |
6040 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
17 |
Correct |
48 ms |
6044 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
18 |
Correct |
51 ms |
6376 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
19 |
Correct |
41 ms |
5796 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
20 |
Correct |
63 ms |
6516 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
21 |
Correct |
68 ms |
6760 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
22 |
Correct |
44 ms |
6188 KB |
Output is partially correct - 70110 call(s) of encode_bit() |
23 |
Correct |
87 ms |
6852 KB |
Output is partially correct - 70110 call(s) of encode_bit() |