#include "grader.h"
#include "encoder.h"
#include <bits/stdc++.h>
using namespace std;
// macros
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define FOR(a,b) for(auto& a : b)
#define all(a) a.begin(), a.end()
#define INF 1e9
#define EPS 1e-9
#define pb push_back
#define popb pop_back
#define fi first
#define se second
void writeSmallInt(int x, int bits) {
RE(i,bits) {
bool b = false;
if(x & (1<<i)) b = 1;
encode_bit(b);
}
}
int maxBits(int x) {
int mx = 0;
RE(i,10) if(x&(1<<i)) mx = max(mx, i+1);
return mx;
}
void encode(int nv, int nh, int ne, int *v1, int *v2) {
vector<vi> adj; adj.resize(nv);
set<ii> difEdges;
RE(i,ne) {
adj[v1[i]].pb(v2[i]);
adj[v2[i]].pb(v1[i]);
difEdges.insert({v1[i],v2[i]});
difEdges.insert({v2[i],v1[i]});
}
set<ii> usedEdges;
RE(h,nh) {
// bfs
vi dist; dist.assign(nv, -1);
queue<int> q;
q.push(h); dist[h] = 0;
while(!q.empty()) {
int u = q.front(); q.pop();
FOR(v,adj[u]) {
if(dist[v] != -1) continue;
dist[v] = dist[u] + 1;
q.push(v);
}
}
vi prev = {h};
RE1(i,nv) {
vi cur;
RE(u,nv) if(dist[u] == i) cur.pb(u);
FOR(u,cur) {
bool found = false;
FOR(v,prev) if(usedEdges.count({min(u,v),max(u,v)})) {
found = true;
break;
}
if(!found) FOR(v,prev) if(difEdges.count({u,v})) {
usedEdges.insert({min(u,v),max(u,v)});
break;
}
}
if(cur.empty()) break;
prev = cur;
}
}
RE(i,nv) adj[i].clear();
FOR(p,usedEdges) adj[p.se].pb(p.fi);
RE(i,nv) {
writeSmallInt(adj[i].size(), 10);
FOR(v,adj[i]) writeSmallInt(v, maxBits(i-1));
}
}
#include "grader.h"
#include "decoder.h"
#include <bits/stdc++.h>
using namespace std;
// macros
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define FOR(a,b) for(auto& a : b)
#define all(a) a.begin(), a.end()
#define INF 1e9
#define EPS 1e-9
#define pb push_back
#define popb pop_back
#define fi first
#define se second
int readSmallInt(int bits) {
int res = 0;
RE(i,bits) {
bool b = decode_bit();
if(b) res |= (1<<i);
}
return res;
}
int maxBits(int x) {
int mx = 0;
RE(i,10) if(x&(1<<i)) mx = max(mx, i+1);
return mx;
}
void decode(int nv, int nh) {
// reconstruct graph
vector<vi> adj; adj.resize(nv);
RE(u,nv) {
int sz = readSmallInt(10);
RE(j,sz) {
int v = readSmallInt(maxBits(u-1));
adj[u].pb(v);
adj[v].pb(u);
}
}
RE(h,nh) {
// bfs
vi dist; dist.assign(nv, -1);
queue<int> q;
q.push(h); dist[h] = 0;
while(!q.empty()) {
int u = q.front(); q.pop();
hops(h,u,dist[u]);
FOR(v,adj[u]) {
if(dist[v] != -1) continue;
dist[v] = dist[u] + 1;
q.push(v);
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
597 ms |
35248 KB |
Output is partially correct - 171031 call(s) of encode_bit() |
2 |
Correct |
3 ms |
4596 KB |
Output is correct - 60 call(s) of encode_bit() |
3 |
Correct |
152 ms |
5712 KB |
Output is correct - 42093 call(s) of encode_bit() |
4 |
Correct |
3 ms |
4580 KB |
Output is correct - 64 call(s) of encode_bit() |
5 |
Correct |
157 ms |
6844 KB |
Output is partially correct - 82354 call(s) of encode_bit() |
6 |
Correct |
189 ms |
6920 KB |
Output is partially correct - 84902 call(s) of encode_bit() |
7 |
Correct |
195 ms |
9980 KB |
Output is partially correct - 151461 call(s) of encode_bit() |
8 |
Correct |
50 ms |
5212 KB |
Output is correct - 25924 call(s) of encode_bit() |
9 |
Correct |
53 ms |
5460 KB |
Output is correct - 25037 call(s) of encode_bit() |
10 |
Correct |
53 ms |
5324 KB |
Output is correct - 24649 call(s) of encode_bit() |
11 |
Correct |
68 ms |
6332 KB |
Output is correct - 39240 call(s) of encode_bit() |
12 |
Correct |
105 ms |
5000 KB |
Output is correct - 19646 call(s) of encode_bit() |
13 |
Correct |
175 ms |
10268 KB |
Output is partially correct - 87739 call(s) of encode_bit() |
14 |
Correct |
95 ms |
5452 KB |
Output is correct - 29129 call(s) of encode_bit() |
15 |
Correct |
93 ms |
5728 KB |
Output is correct - 30735 call(s) of encode_bit() |
16 |
Correct |
153 ms |
9092 KB |
Output is correct - 53891 call(s) of encode_bit() |
17 |
Correct |
132 ms |
8476 KB |
Output is correct - 48360 call(s) of encode_bit() |
18 |
Correct |
178 ms |
9992 KB |
Output is correct - 63514 call(s) of encode_bit() |
19 |
Correct |
122 ms |
7688 KB |
Output is correct - 67338 call(s) of encode_bit() |
20 |
Correct |
184 ms |
11496 KB |
Output is partially correct - 72434 call(s) of encode_bit() |
21 |
Correct |
244 ms |
12624 KB |
Output is partially correct - 77004 call(s) of encode_bit() |
22 |
Correct |
215 ms |
10304 KB |
Output is partially correct - 123599 call(s) of encode_bit() |
23 |
Correct |
234 ms |
13784 KB |
Output is partially correct - 104644 call(s) of encode_bit() |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
597 ms |
35248 KB |
Output is partially correct - 171031 call(s) of encode_bit() |
2 |
Correct |
3 ms |
4596 KB |
Output is correct - 60 call(s) of encode_bit() |
3 |
Correct |
152 ms |
5712 KB |
Output is correct - 42093 call(s) of encode_bit() |
4 |
Correct |
3 ms |
4580 KB |
Output is correct - 64 call(s) of encode_bit() |
5 |
Correct |
157 ms |
6844 KB |
Output is partially correct - 82354 call(s) of encode_bit() |
6 |
Correct |
189 ms |
6920 KB |
Output is partially correct - 84902 call(s) of encode_bit() |
7 |
Correct |
195 ms |
9980 KB |
Output is partially correct - 151461 call(s) of encode_bit() |
8 |
Correct |
50 ms |
5212 KB |
Output is correct - 25924 call(s) of encode_bit() |
9 |
Correct |
53 ms |
5460 KB |
Output is correct - 25037 call(s) of encode_bit() |
10 |
Correct |
53 ms |
5324 KB |
Output is correct - 24649 call(s) of encode_bit() |
11 |
Correct |
68 ms |
6332 KB |
Output is correct - 39240 call(s) of encode_bit() |
12 |
Correct |
105 ms |
5000 KB |
Output is correct - 19646 call(s) of encode_bit() |
13 |
Correct |
175 ms |
10268 KB |
Output is partially correct - 87739 call(s) of encode_bit() |
14 |
Correct |
95 ms |
5452 KB |
Output is correct - 29129 call(s) of encode_bit() |
15 |
Correct |
93 ms |
5728 KB |
Output is correct - 30735 call(s) of encode_bit() |
16 |
Correct |
153 ms |
9092 KB |
Output is correct - 53891 call(s) of encode_bit() |
17 |
Correct |
132 ms |
8476 KB |
Output is correct - 48360 call(s) of encode_bit() |
18 |
Correct |
178 ms |
9992 KB |
Output is correct - 63514 call(s) of encode_bit() |
19 |
Correct |
122 ms |
7688 KB |
Output is correct - 67338 call(s) of encode_bit() |
20 |
Correct |
184 ms |
11496 KB |
Output is partially correct - 72434 call(s) of encode_bit() |
21 |
Correct |
244 ms |
12624 KB |
Output is partially correct - 77004 call(s) of encode_bit() |
22 |
Correct |
215 ms |
10304 KB |
Output is partially correct - 123599 call(s) of encode_bit() |
23 |
Correct |
234 ms |
13784 KB |
Output is partially correct - 104644 call(s) of encode_bit() |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
597 ms |
35248 KB |
Output is partially correct - 171031 call(s) of encode_bit() |
2 |
Correct |
3 ms |
4596 KB |
Output is correct - 60 call(s) of encode_bit() |
3 |
Correct |
152 ms |
5712 KB |
Output is correct - 42093 call(s) of encode_bit() |
4 |
Correct |
3 ms |
4580 KB |
Output is correct - 64 call(s) of encode_bit() |
5 |
Correct |
157 ms |
6844 KB |
Output is partially correct - 82354 call(s) of encode_bit() |
6 |
Correct |
189 ms |
6920 KB |
Output is partially correct - 84902 call(s) of encode_bit() |
7 |
Correct |
195 ms |
9980 KB |
Output is partially correct - 151461 call(s) of encode_bit() |
8 |
Correct |
50 ms |
5212 KB |
Output is correct - 25924 call(s) of encode_bit() |
9 |
Correct |
53 ms |
5460 KB |
Output is correct - 25037 call(s) of encode_bit() |
10 |
Correct |
53 ms |
5324 KB |
Output is correct - 24649 call(s) of encode_bit() |
11 |
Correct |
68 ms |
6332 KB |
Output is correct - 39240 call(s) of encode_bit() |
12 |
Correct |
105 ms |
5000 KB |
Output is correct - 19646 call(s) of encode_bit() |
13 |
Correct |
175 ms |
10268 KB |
Output is partially correct - 87739 call(s) of encode_bit() |
14 |
Correct |
95 ms |
5452 KB |
Output is correct - 29129 call(s) of encode_bit() |
15 |
Correct |
93 ms |
5728 KB |
Output is correct - 30735 call(s) of encode_bit() |
16 |
Correct |
153 ms |
9092 KB |
Output is correct - 53891 call(s) of encode_bit() |
17 |
Correct |
132 ms |
8476 KB |
Output is correct - 48360 call(s) of encode_bit() |
18 |
Correct |
178 ms |
9992 KB |
Output is correct - 63514 call(s) of encode_bit() |
19 |
Correct |
122 ms |
7688 KB |
Output is correct - 67338 call(s) of encode_bit() |
20 |
Correct |
184 ms |
11496 KB |
Output is partially correct - 72434 call(s) of encode_bit() |
21 |
Correct |
244 ms |
12624 KB |
Output is partially correct - 77004 call(s) of encode_bit() |
22 |
Correct |
215 ms |
10304 KB |
Output is partially correct - 123599 call(s) of encode_bit() |
23 |
Correct |
234 ms |
13784 KB |
Output is partially correct - 104644 call(s) of encode_bit() |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
597 ms |
35248 KB |
Output is partially correct - 171031 call(s) of encode_bit() |
2 |
Correct |
3 ms |
4596 KB |
Output is correct - 60 call(s) of encode_bit() |
3 |
Correct |
152 ms |
5712 KB |
Output is correct - 42093 call(s) of encode_bit() |
4 |
Correct |
3 ms |
4580 KB |
Output is correct - 64 call(s) of encode_bit() |
5 |
Correct |
157 ms |
6844 KB |
Output is partially correct - 82354 call(s) of encode_bit() |
6 |
Correct |
189 ms |
6920 KB |
Output is partially correct - 84902 call(s) of encode_bit() |
7 |
Correct |
195 ms |
9980 KB |
Output is partially correct - 151461 call(s) of encode_bit() |
8 |
Correct |
50 ms |
5212 KB |
Output is correct - 25924 call(s) of encode_bit() |
9 |
Correct |
53 ms |
5460 KB |
Output is correct - 25037 call(s) of encode_bit() |
10 |
Correct |
53 ms |
5324 KB |
Output is correct - 24649 call(s) of encode_bit() |
11 |
Correct |
68 ms |
6332 KB |
Output is correct - 39240 call(s) of encode_bit() |
12 |
Correct |
105 ms |
5000 KB |
Output is correct - 19646 call(s) of encode_bit() |
13 |
Correct |
175 ms |
10268 KB |
Output is partially correct - 87739 call(s) of encode_bit() |
14 |
Correct |
95 ms |
5452 KB |
Output is correct - 29129 call(s) of encode_bit() |
15 |
Correct |
93 ms |
5728 KB |
Output is correct - 30735 call(s) of encode_bit() |
16 |
Correct |
153 ms |
9092 KB |
Output is correct - 53891 call(s) of encode_bit() |
17 |
Correct |
132 ms |
8476 KB |
Output is correct - 48360 call(s) of encode_bit() |
18 |
Correct |
178 ms |
9992 KB |
Output is correct - 63514 call(s) of encode_bit() |
19 |
Correct |
122 ms |
7688 KB |
Output is correct - 67338 call(s) of encode_bit() |
20 |
Correct |
184 ms |
11496 KB |
Output is partially correct - 72434 call(s) of encode_bit() |
21 |
Correct |
244 ms |
12624 KB |
Output is partially correct - 77004 call(s) of encode_bit() |
22 |
Correct |
215 ms |
10304 KB |
Output is partially correct - 123599 call(s) of encode_bit() |
23 |
Correct |
234 ms |
13784 KB |
Output is partially correct - 104644 call(s) of encode_bit() |