Submission #763264

# Submission time Handle Problem Language Result Execution time Memory
763264 2023-06-22T07:30:00 Z cheat_when_I_was_young Xylophone (JOI18_xylophone) C++17
Compilation error
0 ms 0 KB
#include "xylophone.h"
int q[5005][5005], a[5005];
bool check_permutation(int n) {
    set<int> s;
    for (int i = 1; i <= n; ++i) s.insert(a[i]);
    if (s.size() != n) return false;
    if (*(s.begin()) != 1) return false;
    auto k = s.end();
    --k;
    if (*k != n) return false;
    for (int i = 1; i < n; ++i) if (a[i+1] - a[i] != q[i+1][i]) return false;
    return true;
}
void build_permutation1(int n) {
    a[1] = 10000;
    a[2] = 10001;
    for (int i = 3; i <= n; ++i) {
		if (q[i-2][i-1] + q[i-1][i] == q[i-2][i]) {
			if (a[i-2] > a[i-1]) a[i] = a[i-1] - q[i-1][i];
			else a[i] = a[i-1] + q[i-1][i];
		} else {
			if (a[i-2] > a[i-1]) a[i] = a[i-1] + q[i-1][i];
			else a[i] = a[i-1] - q[i-1][i];
		}
	}
	int mi = *min_element(a+1, a+n+1) - 1;
	for (int i = 1; i <= n; ++i) a[i] -= mi;
}
void build_permutation2(int n) {
    a[1] = 10001;
    a[2] = 10000;
    for (int i = 3; i <= n; ++i) {
		if (q[i-2][i-1] + q[i-1][i] == q[i-2][i]) {
			if (a[i-2] > a[i-1]) a[i] = a[i-1] - q[i-1][i];
			else a[i] = a[i-1] + q[i-1][i];
		} else {
			if (a[i-2] > a[i-1]) a[i] = a[i-1] + q[i-1][i];
			else a[i] = a[i-1] - q[i-1][i];
		}
	}
	int mi = *min_element(a+1, a+n+1) - 1;
	for (int i = 1; i <= n; ++i) a[i] -= mi;
}
void solve(int n) {
	for (int i = 1; i <= n-1; ++i) q[i][i+1] = q[i+1][i] = query(i, i+1);
	for (int i = 1; i <= n-2; ++i) q[i][i+2] = q[i+2][i] = query(i, i+2);
	int pos = 1;
	for (int i = 1<<12; i > 0; i >>= 1) {
		if (pos + i > n) continue;
		if (query(pos + i, n) == n - 1) pos += i;
	}
	build_permutation1(n);
	if (check_permutation(n)) {
	    for (int i = 1; i <= n; ++i) answer(i, a[i]);
	    return;
	}
	build_permutation2(n);
	for (int i = 1; i <= n; ++i) answer(i, a[i]);
}

Compilation message

xylophone.cpp: In function 'bool check_permutation(int)':
xylophone.cpp:4:5: error: 'set' was not declared in this scope
    4 |     set<int> s;
      |     ^~~
xylophone.cpp:4:9: error: expected primary-expression before 'int'
    4 |     set<int> s;
      |         ^~~
xylophone.cpp:5:34: error: 's' was not declared in this scope
    5 |     for (int i = 1; i <= n; ++i) s.insert(a[i]);
      |                                  ^
xylophone.cpp:6:9: error: 's' was not declared in this scope
    6 |     if (s.size() != n) return false;
      |         ^
xylophone.cpp:7:11: error: 's' was not declared in this scope
    7 |     if (*(s.begin()) != 1) return false;
      |           ^
xylophone.cpp:8:14: error: 's' was not declared in this scope
    8 |     auto k = s.end();
      |              ^
xylophone.cpp: In function 'void build_permutation1(int)':
xylophone.cpp:26:12: error: 'min_element' was not declared in this scope
   26 |  int mi = *min_element(a+1, a+n+1) - 1;
      |            ^~~~~~~~~~~
xylophone.cpp: In function 'void build_permutation2(int)':
xylophone.cpp:41:12: error: 'min_element' was not declared in this scope
   41 |  int mi = *min_element(a+1, a+n+1) - 1;
      |            ^~~~~~~~~~~