Submission #684183

#TimeUsernameProblemLanguageResultExecution timeMemory
684183rainboyCity (JOI17_city)C++17
30 / 100
474 ms37024 KiB
#include "Encoder.h" #include <stdlib.h> static const int N = 250000; static int *ej[N], eo[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 int ta[N], tb[N], time; static void dfs(int p, int i) { ta[i] = time++; for (int o = eo[i]; o--; ) { int j = ej[i][o]; if (j != p) dfs(i, j); } tb[i] = time; } static long long f(int a, int b) { return (long long) b * (b - 1) / 2 + a; } void Encode(int n, int ii[], int jj[]) { 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]); time = 0, dfs(-1, 0); for (int i = 0; i < n; i++) Code(i, f(ta[i], tb[i])); }
#include "Device.h" static const int N = 250000; void InitDevice() {} static void g(long long x, int *a_, int *b_) { int lower = 1, upper = N + 2; while (upper - lower > 1) { int b = (lower + upper) / 2; if (x >= (long long) b * (b - 1) / 2) lower = b; else upper = b; } *b_ = lower, *a_ = x - (long long) lower * (lower - 1) / 2; } int Answer(long long x, long long y) { int tai, tbi, taj, tbj; g(x, &tai, &tbi), g(y, &taj, &tbj); if (taj <= tai && tbi <= tbj) return 0; if (tai <= taj && tbj <= tbi) return 1; return 2; }

Compilation message (stderr)

Encoder.cpp: In function 'void append(int, int)':
Encoder.cpp:10:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   10 |  if (o >= 2 && (o & o - 1) == 0)
      |                     ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...