Submission #211994

#TimeUsernameProblemLanguageResultExecution timeMemory
211994mode149256Saveit (IOI10_saveit)C++14
0 / 100
370 ms12016 KiB
#include <bits/stdc++.h> #include "grader.h" #include "encoder.h" using namespace std; typedef long long ll; typedef long double ld; typedef complex<ld> cd; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef pair<ld, ld> pd; typedef vector<int> vi; typedef vector<vi> vii; typedef vector<ld> vd; typedef vector<ll> vl; typedef vector<vl> vll; typedef vector<pi> vpi; typedef vector<vpi> vpii; typedef vector<pl> vpl; typedef vector<cd> vcd; typedef vector<pd> vpd; typedef vector<bool> vb; typedef vector<vb> vbb; typedef std::string str; typedef std::vector<str> vs; #define x first #define y second #define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n" const int MOD = 1000000007; const ll INF = std::numeric_limits<ll>::max(); const int MX = 100101; const ld PI = 3.14159265358979323846264338327950288419716939937510582097494L; template<typename T> pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x + b.x, a.y + b.y); } template<typename T> pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x - b.x, a.y - b.y); } template<typename T> T operator*(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.x + a.y * b.y); } template<typename T> T operator^(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.y - a.y * b.x); } template<typename T> void print(vector<T> vec, string name = "") { cout << name; for (auto u : vec) cout << u << ' '; cout << '\n'; } void dfs(int x, int p, vii &ats, vii &fast, vii &edges, int N, int H) { // printf("einu x = %d, p = %d\n", x, p); if (x < H) { for (int i = 0; i < N; ++i) { if (fast[x][i] == fast[p][i]) ats[x][i] = 0; else if (fast[x][i] + 1 == fast[p][i]) ats[x][i] = 1; else ats[x][i] = 2; // if (x == 1 and i == 0) printf("fx = %d, fp = %d, ats = %d\n", fast[x][i], fast[p][i], ats[x][i]); } } for (auto u : edges[x]) if (u != p) dfs(u, x, ats, fast, edges, N, H); } void encode(int nv, int nh, int ne, int *v1, int *v2) { vii edges; int N, H; N = nv; H = nh; int P = ne; edges = vii(N); vii visos(N); vpi trans; for (int i = 0; i < P; ++i) { int a = v1[i]; int b = v2[i]; visos[a].emplace_back(b); visos[b].emplace_back(a); } vii fast(H, vi(N, MOD)); for (int i = 0; i < H; ++i) { fast[i][i] = 0; queue<int> q; q.push(i); while (q.size()) { int c = q.front(); q.pop(); for (auto u : visos[c]) { if (fast[i][c] + 1 < fast[i][u]) { fast[i][u] = fast[i][c] + 1; q.push(u); if (!i) { trans.emplace_back(c, u); edges[c].emplace_back(u); edges[u].emplace_back(c); } } } } } // for (auto u : trans) // printf("%d %d\n", u.x, u.y); // assert((int)trans.size() == N - 1); auto encode = [&](int a) { for (int i = 0; i < 10; ++i) encode_bit((a >> i) & 1); }; for (auto u : trans) { encode(u.x); encode(u.y); } // 0 - same // 1 - +1 // 2 - -1 vii ats(H, vi(N, 0)); for (auto u : edges[0]) { dfs(u, 0, ats, fast, edges, N, H); } auto encode_sm = [&](int a) { for (int i = 0; i < 2; ++i) encode_bit((a >> i) & 1); }; for (int i = 0; i < H; ++i) { for (int j = 0; j < N; ++j) { encode_sm(ats[i][j]); } } return; }
#include <bits/stdc++.h> #include "grader.h" #include "decoder.h" using namespace std; typedef long long ll; typedef long double ld; typedef complex<ld> cd; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef pair<ld, ld> pd; typedef vector<int> vi; typedef vector<vi> vii; typedef vector<ld> vd; typedef vector<ll> vl; typedef vector<vl> vll; typedef vector<pi> vpi; typedef vector<vpi> vpii; typedef vector<pl> vpl; typedef vector<cd> vcd; typedef vector<pd> vpd; typedef vector<bool> vb; typedef vector<vb> vbb; typedef std::string str; typedef std::vector<str> vs; #define x first #define y second #define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n" const int MOD = 1000000007; const ll INF = std::numeric_limits<ll>::max(); const int MX = 100101; const ld PI = 3.14159265358979323846264338327950288419716939937510582097494L; template<typename T> pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x + b.x, a.y + b.y); } template<typename T> pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x - b.x, a.y - b.y); } template<typename T> T operator*(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.x + a.y * b.y); } template<typename T> T operator^(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.y - a.y * b.x); } template<typename T> void print(vector<T> vec, string name = "") { cout << name; for (auto u : vec) cout << u << ' '; cout << '\n'; } void dfs(int x, int p, vii &gautas, vii &ats, vii &edges, int N, int H) { if (x < H) { for (int i = 0; i < N; ++i) { if (gautas[x][i] == 0) ats[x][i] = ats[p][i]; else if (gautas[x][i] == 1) ats[x][i] = ats[p][i] - 1; else ats[x][i] = ats[p][i] + 1; } } for (auto u : edges[x]) if (u != p) dfs(u, x, gautas, ats, edges, N, H); } void decode(int nv, int nh) { vii edges; int N, H; N = nv; H = nh; edges = vii(N); auto decode = [&]() -> int { int ret = 0; for (int i = 0; i < 10; ++i) { ret |= (decode_bit() << i); } // printf("decodinu %d\n", ret); return ret; }; auto decode_sm = [&]() -> int { int ret = 0; for (int i = 0; i < 2; ++i) ret |= (decode_bit() << i); return ret; }; for (int i = 0; i < N - 1; ++i) { int a = decode(); int b = decode(); edges[a].emplace_back(b); edges[b].emplace_back(a); } vii ats(H, vi(N, 0)); ats[0] = vi(N, MOD); ats[0][0] = 0; queue<int> q; q.push(0); while (q.size()) { int c = q.front(); q.pop(); for (auto u : edges[c]) { if (ats[0][c] + 1 < ats[0][u]) { ats[0][u] = ats[0][c] + 1; q.push(u); } } } // print(ats[0]); vii gautas(H, vi(N)); for (int i = 0; i < H; ++i) { for (int j = 0; j < N; ++j) { gautas[i][j] = decode_sm(); } } for (auto u : edges[0]) { dfs(u, 0, gautas, ats, edges, N, H); } for (int i = 0; i < H; ++i) { for (int j = 0; j < N; ++j) { hops(i, j, ats[i][j]); } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...