Submission #24101

#TimeUsernameProblemLanguageResultExecution timeMemory
24101jiaqiyangCity (JOI17_city)C++14
100 / 100
549 ms57928 KiB
#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)

Encoder.cpp: In function 'void dfs(int, int)':
Encoder.cpp:21:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < adj[a].size(); ++i) if (adj[a][i] != fa) dfs(adj[a][i], a);
                   ~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...