Submission #771536

#TimeUsernameProblemLanguageResultExecution timeMemory
771536canadavid1Saveit (IOI10_saveit)C++14
75 / 100
327 ms14212 KiB
#include "grader.h" #include "encoder.h" #include <bits/stdc++.h> using namespace std; void encode_number(int n,int N, int H) { for(int i = 1<<9; i > 0; i>>=1) { encode_bit((n&i)>0); } } void encode(int N, int H, int P, int *A, int *B) { vector<vector<int>> neigh(N); for(int i = 0; i < P; i++) { neigh[A[i]].push_back(B[i]); neigh[B[i]].push_back(A[i]); } // BFS from all H vector<vector<int>> distance(H,vector<int>(N,INT_MAX)); for(int h = 0; h < H; h++) { queue<pair<int,int>> q; q.push({h,0}); while(q.size()) { auto v = q.front();q.pop(); if(distance[h][v.first]!=INT_MAX) continue; distance[h][v.first] = v.second; for(auto i : neigh[v.first]) q.push({i,v.second+1}); } } vector<int> treep(N,-1); queue<int> q; q.push(0); while(q.size()) { auto v = q.front();q.pop(); for(auto i : neigh[v]) { if(treep[i]!=-1) continue; treep[i] = v; q.push(i); } } for(int i = 1; i < N; i++) { int p = treep[i]; encode_number(p,N,H); } for(int i = 1; i < N; i++) { int p = treep[i]; for(int h=1; h < H; h++) { switch(distance[h][i]-distance[h][p])// mostly 1, sometimes -1, rarely 0 { case 1: encode_bit(1); break; case -1: encode_bit(0);encode_bit(1); break; case 0: encode_bit(0);encode_bit(0); break; } } } }
#include "grader.h" #include "decoder.h" #include <bits/stdc++.h> using namespace std; int decode_number(int N,int H) { int o=0; for(int i = 0; i < 10; i++) o = (o<<1)+decode_bit(); return o; } void decode(int N, int H) { vector<int> treep(N,-1); vector<vector<int>> treec(N); vector<vector<int>> distance(N,vector<int>(H,INT_MAX)); vector<vector<int>> delta(N,vector<int>(H,0)); for(int i = 0; i < H; i++) distance[i][i] = 0; for(int i = 1; i < N; i++) { treep[i] = decode_number(N, H); treec[treep[i]].push_back(i); } for(int i = 1; i < N; i++) { int p = treep[i]; delta[i][0] = 1; for(int h = 1; h < H; h++) { if(decode_bit()) { // 1 delta[i][h] = 1; continue; } if(decode_bit()) { delta[i][h] = -1; } else { delta[i][h] = 0; } } } for(int h = 1; h < H; h++) { int c = 0; int t = h; while(t!=0) { c += delta[t][h]; t = treep[t]; } distance[0][h] = -c; } queue<int> q; for(auto i : treec[0]) q.push(i); while(q.size()) { auto v = q.front(); q.pop(); for(int h = 0; h < H; h++) { distance[v][h] = distance[treep[v]][h] + delta[v][h]; } for(auto i : treec[v]) q.push(i); } for(int h = 0; h < H; h++) for(int c = 0; c < N; c++) hops(h,c,distance[c][h]); }

Compilation message (stderr)

decoder.cpp: In function 'void decode(int, int)':
decoder.cpp:25:13: warning: unused variable 'p' [-Wunused-variable]
   25 |         int p = treep[i];
      |             ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...