Submission #1303731

#TimeUsernameProblemLanguageResultExecution timeMemory
1303731JahonaliXArranging Shoes (IOI19_shoes)C++20
Compilation error
0 ms0 KiB
#include "shoes.h" using namespace std; long long count_swaps(vector<int> s) { int n = s.size() / 2; long long ans = 0; while (n) { map<int, int> mp; for (int i = n * 2 - 1; i >= 0; --i) mp[s[i]] = i; int x = 1e9; for (int i = 0; i < n; ++i) { if (s[i] < 0) continue; x = min(x, mp[-s[i]] + i + (mp[-s[i]] > i) - 1); } ans += x; for (int i = 0; i < n; ++i) { if (s[i] < 0) continue; if (x == mp[-s[i]] + i + (mp[-s[i]] > i) - 1) { s.erase(s.begin() + max(mp[-s[i]], i)); s.erase(s.begin() + min(i, mp[-s[i]])); break; } } } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:9:9: error: 'map' was not declared in this scope
    9 |         map<int, int> mp;
      |         ^~~
shoes.cpp:2:1: note: 'std::map' is defined in header '<map>'; did you forget to '#include <map>'?
    1 | #include "shoes.h"
  +++ |+#include <map>
    2 | 
shoes.cpp:9:13: error: expected primary-expression before 'int'
    9 |         map<int, int> mp;
      |             ^~~
shoes.cpp:10:46: error: 'mp' was not declared in this scope
   10 |         for (int i = n * 2 - 1; i >= 0; --i) mp[s[i]] = i;
      |                                              ^~
shoes.cpp:14:24: error: 'mp' was not declared in this scope
   14 |             x = min(x, mp[-s[i]] + i + (mp[-s[i]] > i) - 1);
      |                        ^~
shoes.cpp:19:22: error: 'mp' was not declared in this scope
   19 |             if (x == mp[-s[i]] + i + (mp[-s[i]] > i) - 1) {
      |                      ^~