#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x,y) ((x+y-1)/(y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)
template<typename T>
void amin(T &a, T b) {
a = min(a,b);
}
template<typename T>
void amax(T &a, T b) {
a = max(a,b);
}
#ifdef LOCAL
#include "debug.h"
#else
#define debug(x) 42
#endif
/*
refs:
edi
*/
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;
#include "grader.h"
#include "encoder.h"
void encode(int n, int h, int m, int *U, int *V){
vector<int> adj[n];
rep(i,m){
int u = U[i], v = V[i];
adj[u].pb(v), adj[v].pb(u);
}
vector<int> par(n);
vector<bool> vis(n);
int dis[h][n];
rep(i,h){
queue<int> q;
fill(all(vis),0);
q.push(i);
vis[i] = 1;
dis[i][i] = 0;
while(!q.empty()){
int u = q.front();
q.pop();
trav(v,adj[u]){
if(vis[v]) conts;
if(i == 0){
par[v] = u;
}
q.push(v);
vis[v] = 1;
dis[i][v] = dis[i][u]+1;
}
}
}
rep1(u,n-1){
int p = par[u];
rep(bit,10){
int f = 1<<(9-bit);
int b = 0;
if(p&f) b = 1;
encode_bit(b);
}
}
rep(i,h){
vector<int> vals;
vals.pb(0);
rep1(u,n-1){
int p = par[u];
int d1 = dis[i][p], d2 = dis[i][u];
int add = d2-d1;
add++;
vals.pb(add);
}
while(sz(vals)%5){
vals.pb(0);
}
// encode 5 guys in 8 bits
rep(block,sz(vals)/5){
int mask = 0;
for(int j = block*5; j < (block+1)*5; ++j){
mask = mask*3+vals[j];
}
rep(bit,8){
int f = 1<<(7-bit);
int b = 0;
if(mask&f) b = 1;
encode_bit(b);
}
}
}
}
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x,y) ((x+y-1)/(y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)
template<typename T>
void amin(T &a, T b) {
a = min(a,b);
}
template<typename T>
void amax(T &a, T b) {
a = max(a,b);
}
#ifdef LOCAL
#include "debug.h"
#else
#define debug(x) 42
#endif
/*
refs:
edi
*/
const int MOD = 1e9 + 7;
const int N = 1e3 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;
#include "grader.h"
#include "decoder.h"
vector<pii> adj[N];
vector<int> dis(N);
void dfs(int u, int p){
for(auto [v,w] : adj[u]){
if(v == p) conts;
dis[v] = dis[u]+w;
dfs(v,u);
}
}
void decode(int n, int h) {
auto f = [&](int i){
int mask = 0;
rep1(iter,i){
int b = decode_bit();
mask = (mask<<1)|b;
}
return mask;
};
vector<int> par(n);
rep1(u,n-1){
par[u] = f(10);
}
rep(i,h){
int siz = ceil2(n,5)*5;
vector<int> state(n+15);
rep(block,siz/5){
int mask = f(8);
vector<int> curr;
rep(bit,5){
curr.pb(mask%3);
mask /= 3;
}
reverse(all(curr));
int ptr = 0;
for(int u = block*5; u < (block+1)*5; ++u){
state[u] = curr[ptr++];
}
}
rep(u,n){
adj[u].clear();
}
rep1(u,n-1){
int p = par[u];
int w = 0;
if(state[u] == 0) w = -1;
if(state[u] == 1) w = 0;
if(state[u] == 2) w = 1;
adj[p].pb({u,w}), adj[u].pb({p,-w});
}
dis[i] = 0;
dfs(i,-1);
rep(u,n){
hops(i,u,dis[u]);
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
155 ms |
16552 KB |
Output is correct - 67590 call(s) of encode_bit() |
2 |
Correct |
1 ms |
11268 KB |
Output is correct - 64 call(s) of encode_bit() |
3 |
Correct |
17 ms |
11520 KB |
Output is correct - 60830 call(s) of encode_bit() |
4 |
Correct |
2 ms |
11268 KB |
Output is correct - 80 call(s) of encode_bit() |
5 |
Correct |
20 ms |
12048 KB |
Output is correct - 60830 call(s) of encode_bit() |
6 |
Correct |
22 ms |
12584 KB |
Output is correct - 67590 call(s) of encode_bit() |
7 |
Correct |
42 ms |
11892 KB |
Output is correct - 67590 call(s) of encode_bit() |
8 |
Correct |
18 ms |
11712 KB |
Output is correct - 65184 call(s) of encode_bit() |
9 |
Correct |
19 ms |
11508 KB |
Output is correct - 67590 call(s) of encode_bit() |
10 |
Correct |
20 ms |
11636 KB |
Output is correct - 67590 call(s) of encode_bit() |
11 |
Correct |
19 ms |
11900 KB |
Output is correct - 67590 call(s) of encode_bit() |
12 |
Correct |
19 ms |
11492 KB |
Output is correct - 67590 call(s) of encode_bit() |
13 |
Correct |
49 ms |
12048 KB |
Output is correct - 67590 call(s) of encode_bit() |
14 |
Correct |
19 ms |
11768 KB |
Output is correct - 67590 call(s) of encode_bit() |
15 |
Correct |
22 ms |
11784 KB |
Output is correct - 67590 call(s) of encode_bit() |
16 |
Correct |
39 ms |
12268 KB |
Output is correct - 67590 call(s) of encode_bit() |
17 |
Correct |
45 ms |
12764 KB |
Output is correct - 67590 call(s) of encode_bit() |
18 |
Correct |
36 ms |
12520 KB |
Output is correct - 67590 call(s) of encode_bit() |
19 |
Correct |
25 ms |
11780 KB |
Output is correct - 67590 call(s) of encode_bit() |
20 |
Correct |
43 ms |
14560 KB |
Output is correct - 67590 call(s) of encode_bit() |
21 |
Correct |
48 ms |
14428 KB |
Output is correct - 67590 call(s) of encode_bit() |
22 |
Correct |
48 ms |
12124 KB |
Output is correct - 67590 call(s) of encode_bit() |
23 |
Correct |
67 ms |
15048 KB |
Output is correct - 67590 call(s) of encode_bit() |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
155 ms |
16552 KB |
Output is correct - 67590 call(s) of encode_bit() |
2 |
Correct |
1 ms |
11268 KB |
Output is correct - 64 call(s) of encode_bit() |
3 |
Correct |
17 ms |
11520 KB |
Output is correct - 60830 call(s) of encode_bit() |
4 |
Correct |
2 ms |
11268 KB |
Output is correct - 80 call(s) of encode_bit() |
5 |
Correct |
20 ms |
12048 KB |
Output is correct - 60830 call(s) of encode_bit() |
6 |
Correct |
22 ms |
12584 KB |
Output is correct - 67590 call(s) of encode_bit() |
7 |
Correct |
42 ms |
11892 KB |
Output is correct - 67590 call(s) of encode_bit() |
8 |
Correct |
18 ms |
11712 KB |
Output is correct - 65184 call(s) of encode_bit() |
9 |
Correct |
19 ms |
11508 KB |
Output is correct - 67590 call(s) of encode_bit() |
10 |
Correct |
20 ms |
11636 KB |
Output is correct - 67590 call(s) of encode_bit() |
11 |
Correct |
19 ms |
11900 KB |
Output is correct - 67590 call(s) of encode_bit() |
12 |
Correct |
19 ms |
11492 KB |
Output is correct - 67590 call(s) of encode_bit() |
13 |
Correct |
49 ms |
12048 KB |
Output is correct - 67590 call(s) of encode_bit() |
14 |
Correct |
19 ms |
11768 KB |
Output is correct - 67590 call(s) of encode_bit() |
15 |
Correct |
22 ms |
11784 KB |
Output is correct - 67590 call(s) of encode_bit() |
16 |
Correct |
39 ms |
12268 KB |
Output is correct - 67590 call(s) of encode_bit() |
17 |
Correct |
45 ms |
12764 KB |
Output is correct - 67590 call(s) of encode_bit() |
18 |
Correct |
36 ms |
12520 KB |
Output is correct - 67590 call(s) of encode_bit() |
19 |
Correct |
25 ms |
11780 KB |
Output is correct - 67590 call(s) of encode_bit() |
20 |
Correct |
43 ms |
14560 KB |
Output is correct - 67590 call(s) of encode_bit() |
21 |
Correct |
48 ms |
14428 KB |
Output is correct - 67590 call(s) of encode_bit() |
22 |
Correct |
48 ms |
12124 KB |
Output is correct - 67590 call(s) of encode_bit() |
23 |
Correct |
67 ms |
15048 KB |
Output is correct - 67590 call(s) of encode_bit() |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
155 ms |
16552 KB |
Output is correct - 67590 call(s) of encode_bit() |
2 |
Correct |
1 ms |
11268 KB |
Output is correct - 64 call(s) of encode_bit() |
3 |
Correct |
17 ms |
11520 KB |
Output is correct - 60830 call(s) of encode_bit() |
4 |
Correct |
2 ms |
11268 KB |
Output is correct - 80 call(s) of encode_bit() |
5 |
Correct |
20 ms |
12048 KB |
Output is correct - 60830 call(s) of encode_bit() |
6 |
Correct |
22 ms |
12584 KB |
Output is correct - 67590 call(s) of encode_bit() |
7 |
Correct |
42 ms |
11892 KB |
Output is correct - 67590 call(s) of encode_bit() |
8 |
Correct |
18 ms |
11712 KB |
Output is correct - 65184 call(s) of encode_bit() |
9 |
Correct |
19 ms |
11508 KB |
Output is correct - 67590 call(s) of encode_bit() |
10 |
Correct |
20 ms |
11636 KB |
Output is correct - 67590 call(s) of encode_bit() |
11 |
Correct |
19 ms |
11900 KB |
Output is correct - 67590 call(s) of encode_bit() |
12 |
Correct |
19 ms |
11492 KB |
Output is correct - 67590 call(s) of encode_bit() |
13 |
Correct |
49 ms |
12048 KB |
Output is correct - 67590 call(s) of encode_bit() |
14 |
Correct |
19 ms |
11768 KB |
Output is correct - 67590 call(s) of encode_bit() |
15 |
Correct |
22 ms |
11784 KB |
Output is correct - 67590 call(s) of encode_bit() |
16 |
Correct |
39 ms |
12268 KB |
Output is correct - 67590 call(s) of encode_bit() |
17 |
Correct |
45 ms |
12764 KB |
Output is correct - 67590 call(s) of encode_bit() |
18 |
Correct |
36 ms |
12520 KB |
Output is correct - 67590 call(s) of encode_bit() |
19 |
Correct |
25 ms |
11780 KB |
Output is correct - 67590 call(s) of encode_bit() |
20 |
Correct |
43 ms |
14560 KB |
Output is correct - 67590 call(s) of encode_bit() |
21 |
Correct |
48 ms |
14428 KB |
Output is correct - 67590 call(s) of encode_bit() |
22 |
Correct |
48 ms |
12124 KB |
Output is correct - 67590 call(s) of encode_bit() |
23 |
Correct |
67 ms |
15048 KB |
Output is correct - 67590 call(s) of encode_bit() |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
155 ms |
16552 KB |
Output is correct - 67590 call(s) of encode_bit() |
2 |
Correct |
1 ms |
11268 KB |
Output is correct - 64 call(s) of encode_bit() |
3 |
Correct |
17 ms |
11520 KB |
Output is correct - 60830 call(s) of encode_bit() |
4 |
Correct |
2 ms |
11268 KB |
Output is correct - 80 call(s) of encode_bit() |
5 |
Correct |
20 ms |
12048 KB |
Output is correct - 60830 call(s) of encode_bit() |
6 |
Correct |
22 ms |
12584 KB |
Output is correct - 67590 call(s) of encode_bit() |
7 |
Correct |
42 ms |
11892 KB |
Output is correct - 67590 call(s) of encode_bit() |
8 |
Correct |
18 ms |
11712 KB |
Output is correct - 65184 call(s) of encode_bit() |
9 |
Correct |
19 ms |
11508 KB |
Output is correct - 67590 call(s) of encode_bit() |
10 |
Correct |
20 ms |
11636 KB |
Output is correct - 67590 call(s) of encode_bit() |
11 |
Correct |
19 ms |
11900 KB |
Output is correct - 67590 call(s) of encode_bit() |
12 |
Correct |
19 ms |
11492 KB |
Output is correct - 67590 call(s) of encode_bit() |
13 |
Correct |
49 ms |
12048 KB |
Output is correct - 67590 call(s) of encode_bit() |
14 |
Correct |
19 ms |
11768 KB |
Output is correct - 67590 call(s) of encode_bit() |
15 |
Correct |
22 ms |
11784 KB |
Output is correct - 67590 call(s) of encode_bit() |
16 |
Correct |
39 ms |
12268 KB |
Output is correct - 67590 call(s) of encode_bit() |
17 |
Correct |
45 ms |
12764 KB |
Output is correct - 67590 call(s) of encode_bit() |
18 |
Correct |
36 ms |
12520 KB |
Output is correct - 67590 call(s) of encode_bit() |
19 |
Correct |
25 ms |
11780 KB |
Output is correct - 67590 call(s) of encode_bit() |
20 |
Correct |
43 ms |
14560 KB |
Output is correct - 67590 call(s) of encode_bit() |
21 |
Correct |
48 ms |
14428 KB |
Output is correct - 67590 call(s) of encode_bit() |
22 |
Correct |
48 ms |
12124 KB |
Output is correct - 67590 call(s) of encode_bit() |
23 |
Correct |
67 ms |
15048 KB |
Output is correct - 67590 call(s) of encode_bit() |