Submission #763266

# Submission time Handle Problem Language Result Execution time Memory
763266 2023-06-22T07:30:26 Z cheat_when_I_was_young Xylophone (JOI18_xylophone) C++17
Compilation error
0 ms 0 KB
#include "xylophone.h"
#include "bits/stdc++.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:5:5: error: 'set' was not declared in this scope
    5 |     set<int> s;
      |     ^~~
xylophone.cpp:5:5: note: suggested alternatives:
In file included from /usr/include/c++/10/set:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:87,
                 from xylophone.cpp:2:
/usr/include/c++/10/bits/stl_set.h:94:11: note:   'std::set'
   94 |     class set
      |           ^~~
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:87,
                 from xylophone.cpp:2:
/usr/include/c++/10/set:78:13: note:   'std::pmr::set'
   78 |       using set = std::set<_Key, _Cmp, polymorphic_allocator<_Key>>;
      |             ^~~
xylophone.cpp:5:9: error: expected primary-expression before 'int'
    5 |     set<int> s;
      |         ^~~
xylophone.cpp:6:34: error: 's' was not declared in this scope
    6 |     for (int i = 1; i <= n; ++i) s.insert(a[i]);
      |                                  ^
xylophone.cpp:7:9: error: 's' was not declared in this scope
    7 |     if (s.size() != n) return false;
      |         ^
xylophone.cpp:8:11: error: 's' was not declared in this scope
    8 |     if (*(s.begin()) != 1) return false;
      |           ^
xylophone.cpp:9:14: error: 's' was not declared in this scope
    9 |     auto k = s.end();
      |              ^
xylophone.cpp: In function 'void build_permutation1(int)':
xylophone.cpp:27:12: error: 'min_element' was not declared in this scope; did you mean 'std::min_element'?
   27 |  int mi = *min_element(a+1, a+n+1) - 1;
      |            ^~~~~~~~~~~
      |            std::min_element
In file included from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from xylophone.cpp:2:
/usr/include/c++/10/pstl/glue_algorithm_defs.h:520:1: note: 'std::min_element' declared here
  520 | min_element(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last);
      | ^~~~~~~~~~~
xylophone.cpp: In function 'void build_permutation2(int)':
xylophone.cpp:42:12: error: 'min_element' was not declared in this scope; did you mean 'std::min_element'?
   42 |  int mi = *min_element(a+1, a+n+1) - 1;
      |            ^~~~~~~~~~~
      |            std::min_element
In file included from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from xylophone.cpp:2:
/usr/include/c++/10/pstl/glue_algorithm_defs.h:520:1: note: 'std::min_element' declared here
  520 | min_element(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last);
      | ^~~~~~~~~~~