답안 #871381

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
871381 2023-11-10T16:46:54 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;

unsigned int X = 12345;

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

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

int rr[N], dd[N], ss[N];
char usedl[N * 2 + 1], usedr[N * 2 + 1];

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];
	memset(ss, 0, n * sizeof *ss);
	for (int t = 0; t < n; t++)
		for (int i = 1; i + 1 < n; i++)
			if (ss[i + 1] == 0) {
				memset(usedl, 0, (n * 2 + 1) * sizeof *usedl);
				ss[i + 1] = 1;
				int lmn = 0, lmx = 0;
				for (int h = i, s = -1, l = 0; h > 0 && ss[h + 1]; h--) {
					s *= ss[h + 1], l += s == 1 ? dd[h] : -dd[h], lmn = min(lmn, l), lmx = max(lmx, l);
					usedl[n + l] = 1;
				}
				memset(usedr, 0, (n * 2 + 1) * sizeof *usedr);
				int rmn = 0, rmx = 0;
				for (int j = i + 1, s = 1, r = 0; j < n && ss[j]; j++) {
					s *= ss[j], r += s == 1 ? dd[j] : -dd[j], rmn = min(rmn, r), rmx = max(rmx, r);
					usedr[n + r] = 1;
				}
				ss[i + 1] = 0;
				if (lmx - rmn >= n || rmx - lmn >= n)
					ss[i + 1] = -1;
				else if (lmx - -rmx >= n || -rmn - lmn >= n)
					ss[i + 1] = 1;
				else
					for (int x = -n; x <= n; x++) {
						if (usedl[n + x] && usedr[n + x]) {
							ss[i + 1] = -1;
							break;
						}
						if (usedl[n + x] && usedr[n - x]) {
							ss[i + 1] = 1;
							break;
						}
					}
			}
	vi pp(n), qq(n);
	pp[0] = 0, pp[1] = dd[1];
	for (int i = 2; i < n; i++)
		if (ss[i])
			pp[i] = pp[i - 1] + ((pp[i - 2] < pp[i - 1]) == (ss[i] == 1) ? dd[i] : -dd[i]);
		else {
			for (int h = 0; h < n; h++)
				ii[h] = rr[h < i ? i - 1 - h : h] + 1;
			pp[i] = query(ii) - (sum - dd[0]) + dd[i];
			if (abs_(pp[i] - pp[i - 1]) != dd[i])
				pp[i] = -pp[i];
		}
	int p = 0;
	for (int i = 0; i < n; i++)
		p = min(p, pp[i]);
	for (int i = 0; i < n; i++)
		pp[i] -= p - 1;
	for (int i = 0; i < n; i++)
		qq[rr[i]] = pp[i];
	for (int i = 0; i < n; i++)
		pp[i] = qq[i];
	answer(pp);
}

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);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~