Submission #276843

#TimeUsernameProblemLanguageResultExecution timeMemory
276843richyrichArranging Shoes (IOI19_shoes)C++17
Compilation error
0 ms0 KiB
#include "shoes.h" #include<bits/stdc++.h> using namespace std; using ll = long long; const int inf = 1e9; ll sub_1_2(int n, vector<int> s) { map<int, set<int>> M; for(int i = 0; i < n; i++) M[s[i]].insert(i); int i = 0, f = 0, ans = 0, prev=-1; while(i < n) { if(!f) { int that, min_idx = inf; for(auto c : M) { int x = c.first; if(x > 0) break;; if(*M[c].begin() < min_idx) { min_idx=*M[c].begin(); that = c; } } M[that].erase(min_idx); prev = that; ans += abs(min_idx - i); for(auto c : M) { for(auto cc : c.second) { cc++: } } } else { int min_idx = *M[-prev].begin(); ans += (min_idx-i); M[-prev].erase(min_idx); } i++; f ^= 1; } return ans; } long long count_swaps(vector<int> s) { int n = s.size(); if(n<=16) return sub_1_2(n, s); return 1; }

Compilation message (stderr)

shoes.cpp: In function 'll sub_1_2(int, std::vector<int>)':
shoes.cpp:16:10: error: no match for 'operator[]' (operand types are 'std::map<int, std::set<int> >' and 'std::pair<const int, std::set<int> >')
   16 |     if(*M[c].begin() < min_idx) {
      |          ^
In file included from /usr/include/c++/9/map:61,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:81,
                 from shoes.cpp:2:
/usr/include/c++/9/bits/stl_map.h:490:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = int; _Tp = std::set<int>; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, std::set<int> > >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = std::set<int>; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = int]'
  490 |       operator[](const key_type& __k)
      |       ^~~~~~~~
/usr/include/c++/9/bits/stl_map.h:490:34: note:   no known conversion for argument 1 from 'std::pair<const int, std::set<int> >' to 'const key_type&' {aka 'const int&'}
  490 |       operator[](const key_type& __k)
      |                  ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/9/bits/stl_map.h:510:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](std::map<_Key, _Tp, _Compare, _Alloc>::key_type&&) [with _Key = int; _Tp = std::set<int>; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, std::set<int> > >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = std::set<int>; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = int]'
  510 |       operator[](key_type&& __k)
      |       ^~~~~~~~
/usr/include/c++/9/bits/stl_map.h:510:29: note:   no known conversion for argument 1 from 'std::pair<const int, std::set<int> >' to 'std::map<int, std::set<int> >::key_type&&' {aka 'int&&'}
  510 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~
shoes.cpp:17:16: error: no match for 'operator[]' (operand types are 'std::map<int, std::set<int> >' and 'std::pair<const int, std::set<int> >')
   17 |      min_idx=*M[c].begin();
      |                ^
In file included from /usr/include/c++/9/map:61,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:81,
                 from shoes.cpp:2:
/usr/include/c++/9/bits/stl_map.h:490:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = int; _Tp = std::set<int>; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, std::set<int> > >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = std::set<int>; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = int]'
  490 |       operator[](const key_type& __k)
      |       ^~~~~~~~
/usr/include/c++/9/bits/stl_map.h:490:34: note:   no known conversion for argument 1 from 'std::pair<const int, std::set<int> >' to 'const key_type&' {aka 'const int&'}
  490 |       operator[](const key_type& __k)
      |                  ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/9/bits/stl_map.h:510:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](std::map<_Key, _Tp, _Compare, _Alloc>::key_type&&) [with _Key = int; _Tp = std::set<int>; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, std::set<int> > >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = std::set<int>; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = int]'
  510 |       operator[](key_type&& __k)
      |       ^~~~~~~~
/usr/include/c++/9/bits/stl_map.h:510:29: note:   no known conversion for argument 1 from 'std::pair<const int, std::set<int> >' to 'std::map<int, std::set<int> >::key_type&&' {aka 'int&&'}
  510 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~
shoes.cpp:18:13: error: cannot convert 'std::pair<const int, std::set<int> >' to 'int' in assignment
   18 |      that = c;
      |             ^
      |             |
      |             std::pair<const int, std::set<int> >
shoes.cpp:26:10: error: expected ';' before ':' token
   26 |      cc++:
      |          ^
      |          ;