# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
601084 | l_reho | 저장 (Saveit) (IOI10_saveit) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> dist;
vector<vector<int>> graph;
struct info{
int d;
int node;
bool operator< (const info& rhs) const {
return d > rhs.d;
}
};
void solver(int hub){
queue<info> q;
q.push({0, hub});
dist[hub][hub] = 0;
while(!q.empty()){
info i = q.front();
q.pop();
int node = i.node;
int d = i.d;
vector<int> adj = graph[node];
for(int a : adj){
if(dist[hub][a] != INT_MAX) continue;
dist[hub][a] = d+1;
q.push({d+1, a});
}
}
}
void encode_bit(int bit);
int decode_bit();
void hops(int a, int b, int d);
void encode(int nv, int nh, int ne, int *v1, int *v2){
// per ogni hub calcolo la distanza da ogni altro hub
dist.assign(nv, vector<int>(nv, INT_MAX));
graph.assign(nv, vector<int>());
for(int i = 0; i < ne; i++){
graph[v1[i]].push_back(v2[i]);
graph[v2[i]].push_back(v1[i]);
}
for(int i = 0; i < nh; i++)
solver(i);
// adesso gli invio le informazioni
for(int h = 0; h < nh; h++){
for(int v = 0; v < nv; v++){
// faccio l'encode di dist[h][v]
string bts = "";
while(dist[h][v]){
// 11 bit
char c = (dist[h][v] & 1) + '0';
bts = c + bts;
dist[h][v] >>= 1;
}
bts = string(10-bts.length(), '0') + bts;
// cout<<"DEBUG-->"<<bts.length()<<endl;
for(char c : bts)
encode_bit(c-'0');
}
}
return;
}
void decode(int nv, int nh) {
/*
int a = decode_bit();
int b = decode_bit();
hops(0,0,0);
hops(1,2,3);
* */
for(int h = 0; h < nh; h++){
for(int v = 0; v < nv; v++){
int d = 0;
for(int i = 9; i >= 0; i--){
int b = decode_bit();
// cout<<"DEBUG-->"<<h<<" "<<v<<" "<<b<<endl;
if(b) d += (1<<i);
}
hops(h, v, d);
// decodifico e invio
}
}
}