Submission #684182

# Submission time Handle Problem Language Result Execution time Memory
684182 2023-01-20T15:31:55 Z rainboy City (JOI17_city) C
Compilation error
0 ms 0 KB
#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

Encoder.c:6:13: error: variably modified 'ej' at file scope
    6 | static int *ej[N], eo[N];
      |             ^~
Encoder.c:6:20: error: variably modified 'eo' at file scope
    6 | static int *ej[N], eo[N];
      |                    ^~
Encoder.c: In function 'append':
Encoder.c:10:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   10 |  if (o >= 2 && (o & o - 1) == 0)
      |                     ~~^~~
Encoder.c: At top level:
Encoder.c:15:12: error: variably modified 'ta' at file scope
   15 | static int ta[N], tb[N], time;
      |            ^~
Encoder.c:15:19: error: variably modified 'tb' at file scope
   15 | static int ta[N], tb[N], time;
      |                   ^~