답안 #871417

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
871417 2023-11-10T19:13:22 Z rainboy Secret Permutation (RMI19_permutation) C
컴파일 오류
0 ms 0 KB
#include "permutation.h"
#include <cstring>
#include <vector>

using namespace std;

typedef vector<int> vi;

const int N = 256, M = 1024, INF = 0x3f3f3f3f;

int abs_(int a) { return a > 0 ? a : -a; }
int min(int a, int b) { return a < b ? a : b; }

unsigned int X = 12345;

int rand_() {
	return (X *= 3) >> 1;
}

char used[N]; int kk[N];

int check(int *aa, int n, int m) {
	int a = 0;
	for (int i = 0; i < m; i++)
		a = min(a, aa[i]);
	memset(used, 0, n * sizeof *used);
	for (int i = 0; i < m; i++) {
		if (aa[i] - a >= n || used[aa[i] - a])
			return 0;
		used[aa[i] - a] = 1;
	}
	return 1;
}

int rr[N], dd[N], aaa[M][N], aaa_[M][N], m, m_;

void solve(int n) {
	for (int i = 0; i < n; i++)
		rr[i] = i;
	for (int i = 0; i < n; i++) {
		int j = rand_() % (i + 1), tmp;
		tmp = rr[i], rr[i] = rr[j], rr[j] = tmp;
	}
	vi ii(n);
	for (int i = 0; i < n; i++) {
		for (int h = 0; h < n; h++)
			ii[h] = rr[(i + h) % n] + 1;
		dd[i] = query(ii);
	}
	int sum = 0;
	for (int i = 0; i < n; i++)
		sum += dd[i];
	sum /= n - 1;
	for (int i = 0; i < n; i++)
		dd[i] = sum - dd[i];
	vi aa(n), aa_(n);
	int m = 0;
	aaa[m][0] = 0, aaa[m][1] = dd[1], m++;
	int j = 2;
	while (1) {
		while (j < n) {
			m_ = 0;
			for (int h = 0; h < m; h++) {
				memcpy(aaa_[m_], aaa[h], j * sizeof *aaa[h]), aaa_[m_][j] = aaa[h][j - 1] + dd[j];
				if (check(aaa_[m_], n, j + 1))
					m_++;
				if (m_ >= M)
					goto out;
				memcpy(aaa_[m_], aaa[h], j * sizeof *aaa[h]), aaa_[m_][j] = aaa[h][j - 1] - dd[j];
				if (check(aaa_[m_], n, j + 1))
					m_++;
				if (m_ >= M)
					goto out;
			}
			m = m_;
			for (int h = 0; h < m_; h++)
				memcpy(aaa[h], aaa_[h], (j + 1) * sizeof *aaa_[h]);
			j++;
		}
out:
		if (j == n) {
			m_ = 0;
			for (int h = 0; h < m; h++)
				if (abs_(aaa[h][n - 1]) == dd[0])
					memcpy(aaa_[m_++], aaa[h], n * sizeof *aaa[h]);
			m = m_;
			for (int h = 0; h < m_; h++)
				memcpy(aaa[h], aaa_[h], n * sizeof *aaa_[h]);
			if (m == 1) {
				for (int i = 0; i < n; i++)
					aa[i] = aaa[0][i];
				break;
			}
		}
		int z_ = INF, i_ = -1;
		for (int i = 0; i < j; i++) {
			memset(kk, 0, n * sizeof *kk);
			for (int h = 0; h < m; h++)
				kk[abs_(aaa[h][i])]++;
			int z = 0;
			for (int a = 0; a < n; a++)
				z += kk[a] * kk[a];
			if (z_ > z)
				z_ = z, i_ = i;
		}
		for (int h = 0; h < n; h++)
			ii[h] = rr[h < i_ ? i_ - 1 - h : h] + 1;
		int a = query(ii) - (sum - dd[0]) + dd[i_];
		m_ = 0;
		for (int h = 0; h < m; h++)
			if (abs_(aaa[h][i_]) == a)
				memcpy(aaa_[m_++], aaa[h], n * sizeof *aaa[h]);
		m = m_;
		for (int h = 0; h < m_; h++)
			memcpy(aaa[h], aaa_[h], n * sizeof *aaa_[h]);
	}
	int a = 0;
	for (int i = 0; i < n; i++)
		a = min(a, aa[i]);
	for (int i = 0; i < n; i++)
		aa[i] -= a - 1;
	for (int i = 0; i < n; i++)
		aa_[rr[i]] = aa[i];
	for (int i = 0; i < n; i++)
		aa[i] = aa_[i];
	answer(aa);
}

Compilation message

In file included from permutation.c:1:
permutation.h:1:10: fatal error: vector: No such file or directory
    1 | #include <vector>
      |          ^~~~~~~~
compilation terminated.
In file included from stub.c:1:
stub.c:5:24: error: initializer element is not constant
    5 | static FILE *fifo_in = stdin, *fifo_out = stdout;
      |                        ^~~~~
stub.c:5:43: error: initializer element is not constant
    5 | static FILE *fifo_in = stdin, *fifo_out = stdout;
      |                                           ^~~~~~
stub.c: In function 'query':
stub.c:16:3: warning: ignoring return value of 'fscanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |   fscanf(fifo_in, "%d", &x);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~
stub.c: In function 'main':
stub.c:36:3: warning: ignoring return value of 'fscanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |   fscanf(fifo_in, "%d", &N);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~