Submission #699314

#TimeUsernameProblemLanguageResultExecution timeMemory
699314tengiz05City (JOI17_city)C++17
100 / 100
398 ms32172 KiB
#include "Encoder.h" #include <cmath> #include <vector> #include <algorithm> constexpr int N = 700000; // complementing subtree sizes and using much smaller numbers denoting the size void Encode(int n, int A[], int B[]) { std::vector<int> f{1}; int cur = 1; while (cur < N) { cur = std::ceil(cur * 1.05); f.push_back(cur); } std::vector<std::vector<int>> e(n); for (int i = 0; i < n - 1; i++) { e[A[i]].push_back(B[i]); e[B[i]].push_back(A[i]); } std::vector<int> in(n), siz(n); int timeStamp = 0; std::function<void(int, int)> dfs = [&](int u, int p) { in[u] = timeStamp; siz[u] = 1; for (int v : e[u]) { if (v != p) { dfs(v, u); siz[u] += f[siz[v]]; } } int orig = siz[u]; siz[u] = std::lower_bound(f.begin(), f.end(), siz[u]) - f.begin(); timeStamp += f[siz[u]] - orig + 1; }; dfs(0, -1); for (int i = 0; i < n; i++) { Code(i, in[i] + siz[i] * 1LL * N); } }
#include "Device.h" #include <cmath> #include <vector> constexpr int N = 700000; std::vector<int> f; void InitDevice() { f = {1}; int cur = 1; while (cur < N) { cur = std::ceil(cur * 1.05); f.push_back(cur); } } int Answer(long long S, long long T) { int ina = S % N; int outa = ina + f[S / N]; int inb = T % N; int outb = inb + f[T / N]; if (inb <= ina && outa <= outb) { return 0; } else if (ina <= inb && outb <= outa) { return 1; } else { return 2; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...