답안 #731731

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
731731 2023-04-27T21:39:14 Z rainboy Fire drill (LMIO18_sauga) C
컴파일 오류
0 ms 0 KB
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define N	1000
#define MD	0x7fffffff

int *ej[N], *ed[N], eo[N];

void append(int i, int j, int d) {
	int o = eo[i]++;

	if (o >= 2 && (o & o - 1) == 0) {
		ej[i] = (int *) realloc(ej[i], o * 2 * sizeof *ej[i]);
		ed[i] = (int *) realloc(ed[i], o * 2 * sizeof *ed[i]);
	}
	ej[i][o] = j, ed[i][o] = d;
}

int ii[N], pp[N], dd[N], c, c_;

void swap(int i, int j) {
	int p = pp[i], q = pp[j], o;

	for (o = eo[i]; o--; ) {
		int k = ej[i][o], d = ed[i][o];

		if (d == 0) {
			if (pp[i] < pp[k] && --dd[i] == 0)
				c--;
		} else {
			if (pp[k] < pp[i] && --dd[k] == 0)
				c--;
		}
	}
	for (o = eo[j]; o--; ) {
		int k = ej[j][o], d = ed[j][o];

		if (k == i)
			continue;
		if (d == 0) {
			if (pp[j] < pp[k] && --dd[j] == 0)
				c--;
		} else {
			if (pp[k] < pp[j] && --dd[k] == 0)
				c--;
		}
	}
	ii[pp[i] = q] = i, ii[pp[j] = p] = j;
	for (o = eo[i]; o--; ) {
		int k = ej[i][o], d = ed[i][o];

		if (d == 0) {
			if (pp[i] < pp[k] && dd[i]++ == 0)
				c++;
		} else {
			if (pp[k] < pp[i] && dd[k]++ == 0)
				c++;
		}
	}
	for (o = eo[j]; o--; ) {
		int k = ej[j][o], d = ed[j][o];

		if (k == i)
			continue;
		if (d == 0) {
			if (pp[j] < pp[k] && dd[j]++ == 0)
				c++;
		} else {
			if (pp[k] < pp[j] && dd[k]++ == 0)
				c++;
		}
	}
}

int main() {
	int n, m, c1, i, j;
	clock_t beg;
	double temp;

	srand(12345);
	scanf("%*d%d%d", &n, &c1);
	for (i = 0; i < n; i++) {
		ej[i] = (int *) malloc(2 * sizeof *ej[i]);
		ed[i] = (int *) malloc(2 * sizeof *ed[i]);
	}
	for (i = 0; i < n; i++) {
		scanf("%d", &m);
		while (m--) {
			scanf("%d", &j), j--;
			append(i, j, 0), append(j, i, 1);
			if (i < j && dd[i]++ == 0)
				c++;
		}
	}
	for (i = 0; i < n; i++)
		ii[pp[i] = i] = i;
	beg = clock();
	while (c > c1 && (temp = 0.9 - (clock() - beg) / CLOCKS_PER_SEC) > 0) {
		i = rand() % n;
		while ((j = rand() % n) == i);
		c_ = c;
		swap(i, j);
		if (c > c_ && (rand() * 76543LL + rand()) % MD >= exp((c_ - c) / temp) * MD)
			swap(i, j), c = c_;
	}
	for (i = 0; i < n; i++)
		printf("%d\n", ii[i] + 1);
	return 0;
}

Compilation message

sauga.c: In function 'append':
sauga.c:14:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   14 |  if (o >= 2 && (o & o - 1) == 0) {
      |                     ~~^~~
sauga.c: In function 'main':
sauga.c:83:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |  scanf("%*d%d%d", &n, &c1);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~
sauga.c:89:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   89 |   scanf("%d", &m);
      |   ^~~~~~~~~~~~~~~
sauga.c:91:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |    scanf("%d", &j), j--;
      |    ^~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/cc6MPSBv.o: in function `main':
sauga.c:(.text.startup+0x236): undefined reference to `exp'
collect2: error: ld returned 1 exit status