Submission #724229

#TimeUsernameProblemLanguageResultExecution timeMemory
724229badontArranging Shoes (IOI19_shoes)C++17
Compilation error
0 ms0 KiB
#include "shoes.h" #include <cmath> #include <cstdlib> 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:23:3: error: 'assert' was not declared in this scope
   23 |   assert(neg[i].size() == pos[i].size());
      |   ^~~~~~
shoes.cpp:4:1: note: 'assert' is defined in header '<cassert>'; did you forget to '#include <cassert>'?
    3 | #include <cstdlib>
  +++ |+#include <cassert>
    4 |