#include "grader.h"
#include "encoder.h"
#include <bits/stdc++.h>
using namespace std;
int dst[44][1010];
vector<int> g[1010];
int par[1010];
int vis[1010];
void dfs(int v = 1){
vis[v] = 1;
for(auto i : g[v]) if(!vis[i]){
par[i] = v; dfs(i);
}
}
void bfs(int st){
dst[st][st] = 0;
queue<int> q; q.push(st);
while(q.size()){
int now = q.front(); q.pop();
for(auto nxt : g[now]) if(dst[st][nxt] == -1){
dst[st][nxt] = dst[st][now] + 1;
q.push(nxt);
}
}
}
void encode(int N, int H, int M, int *v1, int *v2){
int n = N, m = M, h = H;
for(int i=0; i<m; i++){
int s = v1[i] + 1, e = v2[i] + 1;
g[s].push_back(e); g[e].push_back(s);
}
dfs();
for(int i=2; i<=n; i++){
for(int k=0; k<10; k++) encode_bit(!!(par[i] & (1 << k)));
}
memset(dst, -1, sizeof dst);
for(int i=1; i<=h; i++) bfs(i);
for(int i=1; i<=h; i++) for(int j=2; j<=n; j+=5){
int t = 0;
for(int k=0; k<5; k++){
int now = dst[i][j+k] - dst[i][par[j+k]] + 1;
if(j + k > n) now = 0;
t = t * 3 + now;
}
for(int k=0; k<8; k++) encode_bit(!!(t & (1 << k)));
}
}
//g++ grader.h grader.cpp encoder.h encoder.cpp decoder.h decoder.cpp -o main -std=c++14
#include "grader.h"
#include "decoder.h"
#include <bits/stdc++.h>
using namespace std;
/*
dst[i][j] - dst[i][par[j]]
1 : 0
-1 : 11
0 : 10
*/
int p[1010];
int mm[44][1010];
int chk[1010];
int ans[44][1010];
void go(int hh, int v){
if(v == 1) return;
if(!chk[p[v]]) go(hh, p[v]);
ans[hh][v] = ans[hh][p[v]] + mm[hh][v];
chk[v] = 1;
}
void decode(int N, int H) {
int n = N, h = H;
for(int i=2; i<=n; i++){
for(int j=0; j<10; j++) p[i] += (decode_bit() << j);
}
for(int i=1; i<=h; i++) for(int j=2; j<=n; j+=5){
int ret = 0; for(int k=0; k<8; k++) ret += (decode_bit() << k);
for(int k=4; k>=0; k--){
mm[i][j+k] = ret % 3 - 1;
ret /= 3;
}
}
for(int i=1; i<=h; i++){
memset(chk, 0, sizeof chk);
chk[1] = 1;
for(int j=2; j<=n; j++) go(i, j);
}
for(int i=1; i<=h; i++) for(int j=1; j<=n; j++) hops(i-1, j-1, ans[i][j] - ans[i][i]);
}
//g++ grader.h grader.cpp encoder.h encoder.cpp decoder.h decoder.cpp -o main -std=c++14
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
246 ms |
11888 KB |
Output is correct - 67590 call(s) of encode_bit() |
2 |
Correct |
11 ms |
5112 KB |
Output is correct - 64 call(s) of encode_bit() |
3 |
Correct |
35 ms |
5892 KB |
Output is correct - 60830 call(s) of encode_bit() |
4 |
Correct |
11 ms |
5000 KB |
Output is correct - 80 call(s) of encode_bit() |
5 |
Correct |
34 ms |
6200 KB |
Output is correct - 60830 call(s) of encode_bit() |
6 |
Correct |
36 ms |
6248 KB |
Output is correct - 67590 call(s) of encode_bit() |
7 |
Correct |
53 ms |
6652 KB |
Output is correct - 67590 call(s) of encode_bit() |
8 |
Correct |
37 ms |
5888 KB |
Output is correct - 64896 call(s) of encode_bit() |
9 |
Correct |
35 ms |
6272 KB |
Output is correct - 67590 call(s) of encode_bit() |
10 |
Correct |
37 ms |
5920 KB |
Output is correct - 67590 call(s) of encode_bit() |
11 |
Correct |
41 ms |
6016 KB |
Output is correct - 67590 call(s) of encode_bit() |
12 |
Correct |
34 ms |
6324 KB |
Output is correct - 67590 call(s) of encode_bit() |
13 |
Correct |
62 ms |
6520 KB |
Output is correct - 67590 call(s) of encode_bit() |
14 |
Correct |
35 ms |
6144 KB |
Output is correct - 67590 call(s) of encode_bit() |
15 |
Correct |
38 ms |
6024 KB |
Output is correct - 67590 call(s) of encode_bit() |
16 |
Correct |
57 ms |
6520 KB |
Output is correct - 67590 call(s) of encode_bit() |
17 |
Correct |
57 ms |
6452 KB |
Output is correct - 67590 call(s) of encode_bit() |
18 |
Correct |
61 ms |
6676 KB |
Output is correct - 67590 call(s) of encode_bit() |
19 |
Correct |
46 ms |
6400 KB |
Output is correct - 67590 call(s) of encode_bit() |
20 |
Correct |
73 ms |
6904 KB |
Output is correct - 67590 call(s) of encode_bit() |
21 |
Correct |
107 ms |
7268 KB |
Output is correct - 67590 call(s) of encode_bit() |
22 |
Correct |
57 ms |
6664 KB |
Output is correct - 67590 call(s) of encode_bit() |
23 |
Correct |
86 ms |
7264 KB |
Output is correct - 67590 call(s) of encode_bit() |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
246 ms |
11888 KB |
Output is correct - 67590 call(s) of encode_bit() |
2 |
Correct |
11 ms |
5112 KB |
Output is correct - 64 call(s) of encode_bit() |
3 |
Correct |
35 ms |
5892 KB |
Output is correct - 60830 call(s) of encode_bit() |
4 |
Correct |
11 ms |
5000 KB |
Output is correct - 80 call(s) of encode_bit() |
5 |
Correct |
34 ms |
6200 KB |
Output is correct - 60830 call(s) of encode_bit() |
6 |
Correct |
36 ms |
6248 KB |
Output is correct - 67590 call(s) of encode_bit() |
7 |
Correct |
53 ms |
6652 KB |
Output is correct - 67590 call(s) of encode_bit() |
8 |
Correct |
37 ms |
5888 KB |
Output is correct - 64896 call(s) of encode_bit() |
9 |
Correct |
35 ms |
6272 KB |
Output is correct - 67590 call(s) of encode_bit() |
10 |
Correct |
37 ms |
5920 KB |
Output is correct - 67590 call(s) of encode_bit() |
11 |
Correct |
41 ms |
6016 KB |
Output is correct - 67590 call(s) of encode_bit() |
12 |
Correct |
34 ms |
6324 KB |
Output is correct - 67590 call(s) of encode_bit() |
13 |
Correct |
62 ms |
6520 KB |
Output is correct - 67590 call(s) of encode_bit() |
14 |
Correct |
35 ms |
6144 KB |
Output is correct - 67590 call(s) of encode_bit() |
15 |
Correct |
38 ms |
6024 KB |
Output is correct - 67590 call(s) of encode_bit() |
16 |
Correct |
57 ms |
6520 KB |
Output is correct - 67590 call(s) of encode_bit() |
17 |
Correct |
57 ms |
6452 KB |
Output is correct - 67590 call(s) of encode_bit() |
18 |
Correct |
61 ms |
6676 KB |
Output is correct - 67590 call(s) of encode_bit() |
19 |
Correct |
46 ms |
6400 KB |
Output is correct - 67590 call(s) of encode_bit() |
20 |
Correct |
73 ms |
6904 KB |
Output is correct - 67590 call(s) of encode_bit() |
21 |
Correct |
107 ms |
7268 KB |
Output is correct - 67590 call(s) of encode_bit() |
22 |
Correct |
57 ms |
6664 KB |
Output is correct - 67590 call(s) of encode_bit() |
23 |
Correct |
86 ms |
7264 KB |
Output is correct - 67590 call(s) of encode_bit() |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
246 ms |
11888 KB |
Output is correct - 67590 call(s) of encode_bit() |
2 |
Correct |
11 ms |
5112 KB |
Output is correct - 64 call(s) of encode_bit() |
3 |
Correct |
35 ms |
5892 KB |
Output is correct - 60830 call(s) of encode_bit() |
4 |
Correct |
11 ms |
5000 KB |
Output is correct - 80 call(s) of encode_bit() |
5 |
Correct |
34 ms |
6200 KB |
Output is correct - 60830 call(s) of encode_bit() |
6 |
Correct |
36 ms |
6248 KB |
Output is correct - 67590 call(s) of encode_bit() |
7 |
Correct |
53 ms |
6652 KB |
Output is correct - 67590 call(s) of encode_bit() |
8 |
Correct |
37 ms |
5888 KB |
Output is correct - 64896 call(s) of encode_bit() |
9 |
Correct |
35 ms |
6272 KB |
Output is correct - 67590 call(s) of encode_bit() |
10 |
Correct |
37 ms |
5920 KB |
Output is correct - 67590 call(s) of encode_bit() |
11 |
Correct |
41 ms |
6016 KB |
Output is correct - 67590 call(s) of encode_bit() |
12 |
Correct |
34 ms |
6324 KB |
Output is correct - 67590 call(s) of encode_bit() |
13 |
Correct |
62 ms |
6520 KB |
Output is correct - 67590 call(s) of encode_bit() |
14 |
Correct |
35 ms |
6144 KB |
Output is correct - 67590 call(s) of encode_bit() |
15 |
Correct |
38 ms |
6024 KB |
Output is correct - 67590 call(s) of encode_bit() |
16 |
Correct |
57 ms |
6520 KB |
Output is correct - 67590 call(s) of encode_bit() |
17 |
Correct |
57 ms |
6452 KB |
Output is correct - 67590 call(s) of encode_bit() |
18 |
Correct |
61 ms |
6676 KB |
Output is correct - 67590 call(s) of encode_bit() |
19 |
Correct |
46 ms |
6400 KB |
Output is correct - 67590 call(s) of encode_bit() |
20 |
Correct |
73 ms |
6904 KB |
Output is correct - 67590 call(s) of encode_bit() |
21 |
Correct |
107 ms |
7268 KB |
Output is correct - 67590 call(s) of encode_bit() |
22 |
Correct |
57 ms |
6664 KB |
Output is correct - 67590 call(s) of encode_bit() |
23 |
Correct |
86 ms |
7264 KB |
Output is correct - 67590 call(s) of encode_bit() |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
246 ms |
11888 KB |
Output is correct - 67590 call(s) of encode_bit() |
2 |
Correct |
11 ms |
5112 KB |
Output is correct - 64 call(s) of encode_bit() |
3 |
Correct |
35 ms |
5892 KB |
Output is correct - 60830 call(s) of encode_bit() |
4 |
Correct |
11 ms |
5000 KB |
Output is correct - 80 call(s) of encode_bit() |
5 |
Correct |
34 ms |
6200 KB |
Output is correct - 60830 call(s) of encode_bit() |
6 |
Correct |
36 ms |
6248 KB |
Output is correct - 67590 call(s) of encode_bit() |
7 |
Correct |
53 ms |
6652 KB |
Output is correct - 67590 call(s) of encode_bit() |
8 |
Correct |
37 ms |
5888 KB |
Output is correct - 64896 call(s) of encode_bit() |
9 |
Correct |
35 ms |
6272 KB |
Output is correct - 67590 call(s) of encode_bit() |
10 |
Correct |
37 ms |
5920 KB |
Output is correct - 67590 call(s) of encode_bit() |
11 |
Correct |
41 ms |
6016 KB |
Output is correct - 67590 call(s) of encode_bit() |
12 |
Correct |
34 ms |
6324 KB |
Output is correct - 67590 call(s) of encode_bit() |
13 |
Correct |
62 ms |
6520 KB |
Output is correct - 67590 call(s) of encode_bit() |
14 |
Correct |
35 ms |
6144 KB |
Output is correct - 67590 call(s) of encode_bit() |
15 |
Correct |
38 ms |
6024 KB |
Output is correct - 67590 call(s) of encode_bit() |
16 |
Correct |
57 ms |
6520 KB |
Output is correct - 67590 call(s) of encode_bit() |
17 |
Correct |
57 ms |
6452 KB |
Output is correct - 67590 call(s) of encode_bit() |
18 |
Correct |
61 ms |
6676 KB |
Output is correct - 67590 call(s) of encode_bit() |
19 |
Correct |
46 ms |
6400 KB |
Output is correct - 67590 call(s) of encode_bit() |
20 |
Correct |
73 ms |
6904 KB |
Output is correct - 67590 call(s) of encode_bit() |
21 |
Correct |
107 ms |
7268 KB |
Output is correct - 67590 call(s) of encode_bit() |
22 |
Correct |
57 ms |
6664 KB |
Output is correct - 67590 call(s) of encode_bit() |
23 |
Correct |
86 ms |
7264 KB |
Output is correct - 67590 call(s) of encode_bit() |