# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
965611 | 2024-04-19T03:08:47 Z | fzyzzz_z | Saveit (IOI10_saveit) | C++17 | 0 ms | 0 KB |
#include "grader.h" #include "encoder.h" #include <bits/stdc++.h> using namespace std; void encode(int n, int nh, int ne, int *v1, int *v2){ int g[n][n]; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { g[i][j] = 0; } } for (int i = 0; i < ne; ++i) { g[v1[i]][v2[i]] = g[v2[i]][v1[i]] = 1; } int d[nh][n]; for (int i = 0; i < nh; ++i) { for (int j = 0; j < n; ++j) { d[i][j] = 1e9; } } for (int i = 0; i < nh; ++i) { vector<int> c(1, i); d[i][i] = 0; for (int cd = 0; cd < n; ++cd) { vector<int> nc; for (auto x: c) { for (int y = 0; y < n; ++y) { if (d[i][y] == inf && g[x][y] == 2) { d[i][y] = cd + 1; nc.push_back(y); } } } for (auto x: c) { for (int y = 0; y < n; ++y) { if (d[i][y] == inf && g[x][y] == 1) { d[i][y] = cd + 1; g[x][y] = g[y][x] = 2; nc.push_back(y); } } } c = nc; } } for (int i = 0; i < n; ++i) { int c = 0; for (int j = i + 1; j < n; ++j) { c += g[i][j] == 2; } if (n < c * 10) { encode_bit(0); for (int j = i + 1; j < n; ++j) { encode_bit(g[i][j] == 2); } } else { encode_bit(1); int mx = 0; for (int j = i + 1; j < n; ++j) if (g[i][j] == 2) mx = j; for (int j = i + 1; j < n; ++j) { if (g[i][j] != 2) continue; for (int b = 0; b < 10; ++b) { encode_bit(((1 << b) & j) >> b); } if (j < mx) encode_bit(1); } encode_bit(0); } } return; }