Submission #620480

#TimeUsernameProblemLanguageResultExecution timeMemory
620480Genius3435Gondola (IOI14_gondola)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; constexpr int N = 100005; constexpr int M = 250005; constexpr int MOD = 1000000009; int valid(int n, int a[]) { // Check that values \leq n are in order, and that there are no repeats set<int> contained; for (int i = 0; i < n; ++i) { if (contained.count(a[i])) return 0; contained.insert(a[i]); } int start_index = -1; for (int i = 0; i < n; ++i) { if (a[i] <= n) { int index = (a[i] - (i+1) + n) % n; if (start_index == -1) { start_index = index; } else if (start_index != index) { return 0; } } } return 1; } int replacement(int n, int a[], int b[]) { static int position[M]; auto it = max_element(a, a+n); int m = *it, max_idx = it-a; for (int i = 1; i <= m; ++i) { position[i] = -1; } for (int i = 0; i < n; ++i) { position[a[i]] = i; } int start_index = -1; for (int i = 0; i < n; ++i) { if (a[i] <= n) { start_index = (a[i] - (i+1) + n) % n; break; } } if (start_index == -1) { start_index = 0; } int *currSeq = new int[n]; for (int i = 0; i < n; ++i) { currSeq[i] = (start_index + i) % n + 1; } for (int i = n+1; i <= m; ++i) { if (position[i] == -1) { b[i-n-1] = currSeq[max_idx]; currSeq[max_idx] = i; } else { b[i-n-1] = currSeq[position[i]]; currSeq[position[i]] = i; } } delete[] currSeq; return m-n; } int pow(long long b, int e, int m) { long long p = 1; while (e) { if (e&1) p = p * b % m; e >>= 1, b = b * b % m; } return p; } int countReplacement(int n, int a[]) { if (!valid(n, a)) return 0; std::set<int> contained; for (int i = 0; i < n; ++i) { if (a[i] > n) { contained.insert(a[i]); } } int positions = contained.size(); long long ans = positions<n ? 1 : n; int prv = n; for (const int i : contained) { // All values in the interval (prv, i) have positions spots they could go in ans = ans * pow(positions, i-prv-1, MOD) % MOD; prv = i; positions--; } return ans; }

Compilation message (stderr)

/usr/bin/ld: /tmp/ccrxq0R9.o: in function `main':
grader.cpp:(.text.startup+0xb6): undefined reference to `valid'
/usr/bin/ld: grader.cpp:(.text.startup+0x108): undefined reference to `countReplacement'
/usr/bin/ld: grader.cpp:(.text.startup+0x132): undefined reference to `replacement'
collect2: error: ld returned 1 exit status