# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
252843 | SamAnd | Saveit (IOI10_saveit) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "grader.h"
//#include "encoder.h"
//#include "decoder.h"
#include <vector>
#include <algorithm>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
using namespace std;
const int N = 1002;
int nn, m, u;
vector<int> a[N];
int d[N];
bool c[N];
void bfs(int x)
{
for (int i = 0; i < nn; ++i)
{
c[i] = false;
d[i] = 0;
}
queue<int> q;
c[x] = true;
q.push(x);
while (!q.empty())
{
int x = q.front();
q.pop();
for (int i = 0; i < a[x].size(); ++i)
{
int h = a[x][i];
if (!c[h])
{
c[h] = true;
d[h] = d[x] + 1;
q.push(h);
}
}
}
}
void funkc()
{
encode_bit(1);
encode_bit(1);
encode_bit(1);
encode_bit(1);
encode_bit(1);
encode_bit(1);
encode_bit(1);
encode_bit(1);
encode_bit(1);
encode_bit(1);
}
void encode(int nv, int nh, int ne, int *v1, int *v2) {
nn = nv;
u = nh;
m = ne;
for (int i = 0; i < m; ++i)
{
a[v1[i]].push_back(v2[i]);
a[v2[i]].push_back(v1[i]);
}
for (int i = 0; i < u; ++i)
{
bfs(i);
for (int j = 0; j < nn; ++j)
{
vector<int> v;
if (!d[j])
{
for (int k = 0; k<9; ++k)
encode_bit(0);
encode_bit(0);
continue;
}
while (d[j])
{
v.push_back((d[j] % 2));
d[j] /= 2;
}
for (int k = 0; k < (10 - v.size()); ++k)
{
encode_bit(0);
}
for (int k = v.size() - 1; k >= 0; --k)
{
encode_bit(v[k]);
}
}
}
return;
}
void decode(int nv, int nh) {
int v = 0;
int u = 0;
int n = 0;
int i = 0;
while (1)
{
++i;
n *= 2;
n += decode_bit();
if (i % 10 == 0)
{
hops(v, u, n);
++u;
if (u == nv)
{
++v;
u = 0;
}
if (v == nh)
{
break;
}
n = 0;
}
}
}