Submission #686665

#TimeUsernameProblemLanguageResultExecution timeMemory
686665etheningGondola (IOI14_gondola)C++17
Compilation error
0 ms0 KiB
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;

#define DEBUG 0

int subtask;
int n;
vector<int> a;

bool check(vector<int> &a) {
	unordered_map<int, int> pos;
	for (int i = 0; i < n; i++) {
		if (pos.count(a[i])) {
			return false;
		}
		else {
			pos[a[i]] = i;
		}
	}
	int mnVal = -1;
	int mnPos = -1;
	for (int i = 1; i <= n; i++) {
		if (pos.count(i)) continue;
		if (mnVal == -1) {
			mnVal = i;
			mnPos = pos[i];
		}
		else {
			int curVal = i;
			int curPos = pos[i];
			int expectPos = (mnPos + (curVal - mnVal)) % n;
			if (expectPos != curPos) return false;
		}
	}
	return true;
}

vector<int> rotate(vector<int> &a) {
	vector<int> ret(n);
	int mnDex = 0;
	int mnVal = a[0];
	for (int i = 0; i < n; i++) {
		if (a[i] < mnVal) {
			mnVal = a[i];
			mnDex = i;
		}
	}
	if (mnVal > n) return a;
	for (int i = mnDex, j = mnVal - 1; i < mnDex + n; i++, j++) {
		ret[j % n] = a[i % n];
	}
	return ret;
}

void construct(vector<int> &a) {
	const int MAXV = 250000;
	int mxDex = 0;
	int mxVal = a[0];
	vector<int> pos(MAXV + 5, -1);
	for (int i = 0; i < n; i++) {
		if (a[i] > mxVal) {
			mxVal = a[i];
			mxDex = i;
		}
		pos[a[i]] = i;
	}
	cout << mxVal - n << "\n";
	int tmp = mxDex + 1;
	for (int i = n + 1; i <= mxVal; i++) {
		if (pos[i] == -1 || i == mxVal) {
			cout << tmp << "\n";
			tmp = i;
		}
		else {
			cout << pos[i] + 1 << "\n";
		}
	}
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> subtask;
	cin >> n;
	a = vector<int>(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	if (subtask <= 3) {
		bool valid = check(a);
		cout << (valid ? 1 : 0) << "\n";
	}
	else if (subtask <= 6) {
		a = rotate(a);
		if (DEBUG) {
			for (int i = 0; i < n; i++) {
				cout << a[i] << " \n"[i == n - 1];
			}
		}
		construct(a);
	}
	else {
		bool valid = check(a);
		if (!valid) {
			cout << 0 << "\n";
			return 0;
		}
	}
}

Compilation message (stderr)

/usr/bin/ld: /tmp/ccnc21uQ.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccLvhtVS.o:gondola.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccnc21uQ.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