Submission #724228

#TimeUsernameProblemLanguageResultExecution timeMemory
724228badontArranging Shoes (IOI19_shoes)C++17
Compilation error
0 ms0 KiB
#include "shoes.h"

long long count_swaps(std::vector<int> s) {
	using ll = long long;
	using namespace std;
	ll n = (int)s.size(); n /= 2;	

	vector<vector<ll>> pos(n, vector<ll>()), neg(n, vector<ll>());	

	for (int i = 0; i < 2 * n; i++) {
		ll x = abs(s[i]);
		if (s[i] < 0) {
			neg[x - 1].push_back(i);
		} else {
			pos[x - 1].push_back(i);
		}
	}

	ll op_1 = 0, op_2 = 0;
	for (int i = 0; i < n; i++) {
		assert(neg[i].size() == pos[i].size());
		for (int j = 0; j < (int)neg[i].size(); j++) {
			int x = neg[i][j], y = pos[i][j];
			op_1 += abs(x - y) - 1;
			if (x > y) op_2++;
		}
	}

	op_1 /= 2;

	return op_1 + op_2;
}

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:11:10: error: 'abs' was not declared in this scope
   11 |   ll x = abs(s[i]);
      |          ^~~
shoes.cpp:21:3: error: 'assert' was not declared in this scope
   21 |   assert(neg[i].size() == pos[i].size());
      |   ^~~~~~
shoes.cpp:2:1: note: 'assert' is defined in header '<cassert>'; did you forget to '#include <cassert>'?
    1 | #include "shoes.h"
  +++ |+#include <cassert>
    2 | 
shoes.cpp:24:12: error: 'abs' was not declared in this scope
   24 |    op_1 += abs(x - y) - 1;
      |            ^~~