Submission #414650

#TimeUsernameProblemLanguageResultExecution timeMemory
414650hibye1217Arranging Shoes (IOI19_shoes)C++17
Compilation error
0 ms0 KiB
#include <vector>
#include <cstdio>
#include <cassert>

using namespace std;

long long count_swaps(std::vector<int> s);

int main() {
	int n;
	assert(1 == scanf("%d", &n));
	vector<int> S(2 * n);
	for (int i = 0; i < 2 * n; i++)
		assert(1 == scanf("%d", &S[i]));
	fclose(stdin);

	long long result = count_swaps(S);

	printf("%lld\n", result);
	fclose(stdout);
	return 0;
}

// #include "shoes.h"

int psh(std::vector<int>& s, int st, int ed){
	int res = 0;
	for (int j = st; j > ed; j--){
		swap(s[j], s[j-1]);
		res += 1;
	}
	return res;
}

long long count_swaps(std::vector<int> s) {
	int n = s.size();
	int ans = 0;
	for (int i = 0; i < n; i += 2){
		int p = 0;
		for (int j = i; j < n; j++){
			if (s[j] == -s[i]){ p = j; break; }
		}
		ans += psh(s, p, i+1);
		if (s[i] > s[i+1]){ swap(s[i], s[i+1]); ans += 1; }
	}
	return ans;
}

Compilation message (stderr)

/usr/bin/ld: /tmp/ccmORi2f.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc5y6cmc.o:shoes.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status