# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
684272 | rainboy | City (JOI17_city) | C++17 | 292 ms | 83540 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "Encoder.h"
#include <stdlib.h>
static const int N = 250000, H = 18;
static int len[N + 1][H + 1], offset[N + 1][H + 1];
static void InitEncoder() {
for (int n = 1; n <= N; n++)
for (int h = 0; h <= H; h++)
len[n][h] = n * (h + 1);
int x = 0;
for (int n = 1; n <= N; n++)
for (int h = 0; h <= H; h++)
offset[n][h] = x, x += len[N][H] / n;
}
static int *ej[N], eo[N], sz[N], hh[N];
static void append(int i, int j) {
int o = eo[i]++;
if (o >= 2 && (o & o - 1) == 0)
ej[i] = (int *) realloc(ej[i], o * 2 * sizeof *ej[i]);
ej[i][o] = j;
}
static void dfs1(int p, int i, int h) {
sz[i] = 1, hh[i] = h;
for (int o = eo[i]; o--; ) {
int j = ej[i][o];
if (j != p) {
dfs1(i, j, h);
sz[i] += sz[j];
}
}
}
static void dfs2(int p, int i, int x) {
Code(i, offset[sz[i]][hh[i]] + x / sz[i]);
for (int o = eo[i]; o--; ) {
int j = ej[i][o];
if (j != p) {
x = (x + sz[j] - 1) / sz[j] * sz[j];
dfs2(i, j, x), x += len[sz[j]][hh[j]];
}
}
}
void Encode(int n, int *ii, int *jj) {
InitEncoder();
for (int i = 0; i < n; i++)
ej[i] = (int *) malloc(2 * sizeof *ej[i]);
for (int h = 0; h < n - 1; h++)
append(ii[h], jj[h]), append(jj[h], ii[h]);
dfs1(-1, 0, H);
dfs2(-1, 0, 0);
}
#include "Device.h"
static const int N = 250000, H = 18;
static int len[N + 1][H + 1], offset[N + 1][H + 1];
void InitDevice() {
for (int n = 1; n <= N; n++)
for (int h = 0; h <= H; h++)
len[n][h] = n * (h + 1);
int x = 0;
for (int n = 1; n <= N; n++)
for (int h = 0; h <= H; h++)
offset[n][h] = x, x += len[N][H] / n;
}
static void Decode(long long x, int *a, int *b) {
int lower = 1 * (H + 1) + 0, upper = (N + 1) * (H + 1);
while (upper - lower > 1) {
int nh = (lower + upper) / 2, n = nh / (H + 1), h = nh % (H + 1);
if (x < offset[n][h])
upper = nh;
else
lower = nh;
}
int nh = lower, n = nh / (H + 1), h = nh % (H + 1);
*a = (x - offset[n][h]) * n, *b = *a + len[n][h];
}
int Answer(long long x, long long y) {
int tai, tbi, taj, tbj;
Decode(x, &tai, &tbi), Decode(y, &taj, &tbj);
if (taj <= tai && tbi <= tbj)
return 0;
if (tai <= taj && tbj <= tbi)
return 1;
return 2;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |