# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
341759 | ogibogi2004 | Saveit (IOI10_saveit) | C++14 | 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<bits/stdc++.h>
using namespace std;
string s;
int dist[40][1024];
vector<int>g[1024];
void bfs(int u)
{
queue<int>q;
q.push(u);
for(int i=0;i<1024;i++)
{
dist[u][i]=100000;
}
dist[u][u]=0;
while(!q.empty())
{
int u1=q.front();
q.pop();
for(auto v:g[u1])
{
if(dist[u][u1]+1<dist[u][v])
{
dist[u][v]=dist[u][u1]+1;
q.push(v);
}
}
}
}
void encode(int nv, int nh, int ne, int *v1, int *v2){
for(int i=0;i<ne;i++)
{
g[v1[i]].push_back(v2[i]);
g[v2[i]].push_back(v1[i]);
}
for(int i=0;i<nh;i++)
{
bfs(i);
}
for(int i=0;i<nh;i++)
{
for(int j=i+1;j<nh;j++)
{
for(int l=0;l<10;l++)
{
if((1<<l)&dist[i][j])
{
s+='1';
}
else s+='0';
}
}
}
for(int i=nh;i<n;i++)
{
pair<int,int>p={10000,10000};
for(int j=0;j<nh;j++)
{
p=min(p,{dist[j][i],j});
}
for(int l=0;l<6;l++)
{
if((1<<l)&p.second)
{
s+="1";
}
else s+="0";
}
for(int l=0;l<10;l++)
{
if((1<<l)&p.first)
{
s+="1";
}
else s+="0";
}
}
for(int i=0;i<s.size();i++)encode_bit(s[i]-'0');
return;
}
#include "grader.h"
#include "decoder.h"
#include<bits/stdc++.h>
using namespace std;
int dist[42][42];
int closest[1024],dist_to_closest[1024];
void decode(int nv, int nh) {
for(int i=0;i<nh;i++)
{
for(int j=i+1;j<nh;j++)
{
for(int l=0;l<10;l++)
{
int x=decode_bit();
dist[i][j]+=(x<<l);
}
dist[j][i]=dist[i][j];
}
}
for(int i=nh;i<n;i++)
{
for(int l=0;l<6;l++)
{
int x=decode_bit();
cloesest[i]+=(x<<l);
}
for(int l=0;l<10;l++)
{
int x=decode_bit();
dist_to_cloesest[i]+=(x<<l);
}
}
for(int i=0;i<nh;i++)
{
for(int j=0;j<nh;j++)
{
hops(i,j,dist[i][j]);
}
}
for(int i=nh;i<n;i++)
{
for(int j=0;j<nh;j++)
{
hops(j,i,dist_to_closest[i]+dist[closest[i]][j]);
}
}
}