# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
24101 | jiaqiyang | City (JOI17_city) | C++14 | 549 ms | 57928 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 "Encoder.h"
#include <vector>
#include <algorithm>
static const int N = 250000 + 10;
typedef long long i64;
static std::vector<int> adj[N], r;
static void init() {
int i = 1;
for (; i < N; i += std::max<int>(1, .05 * i)) r.push_back(i);
for (int j = 20; j--; i += std::max<int>(1, .05 * i)) r.push_back(i);
}
static int left[N], right[N], tot;
static void dfs(int a, int fa = -1) {
left[a] = tot++;
for (int i = 0; i < adj[a].size(); ++i) if (adj[a][i] != fa) dfs(adj[a][i], a);
right[a] = tot = left[a] + *std::lower_bound(r.begin(), r.end(), tot - left[a]);
}
void Encode(int n, int a[], int b[]) {
init();
for (int i = 0; i < n - 1; ++i) adj[a[i]].push_back(b[i]), adj[b[i]].push_back(a[i]);
dfs(0);
for (int i = 0; i < n; ++i) {
int x = left[i], y = std::lower_bound(r.begin(), r.end(), right[i] - left[i]) - r.begin();
Code(i, y << 20 | x);
}
}
#include "Device.h"
#include <vector>
#include <algorithm>
static const int N = 250000 + 10;
typedef long long i64;
static std::vector<int> r;
void InitDevice() {
int i = 1;
for (; i < N; i += std::max<int>(1, .05 * i)) r.push_back(i);
for (int j = 20; j--; i += std::max<int>(1, .05 * i)) r.push_back(i);
}
static std::pair<int, int> solve(i64 x) {
int l = x & 0xfffff, y = x >> 20;
return std::make_pair(l, l + r[y]);
}
int Answer(i64 s, i64 t) {
std::pair<int, int> x = solve(s), y = solve(t);
if (y.first <= x.first && x.second <= y.second) return 0;
if (x.first <= y.first && y.second <= x.second) return 1;
return 2;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |