Submission #284645

#TimeUsernameProblemLanguageResultExecution timeMemory
284645triplem5dsArranging Shoes (IOI19_shoes)C++14
Compilation error
0 ms0 KiB
#include "shoes.h"

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

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:5:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 |  for(int i = 0; i < s.size(); i += 2){
      |                 ~~^~~~~~~~~~
shoes.cpp:10:13: error: 'swap' was not declared in this scope
   10 |             swap(s[k], s[k+1]);
      |             ^~~~
shoes.cpp:10:13: note: suggested alternatives:
In file included from /usr/include/c++/9/vector:68,
                 from shoes.h:5,
                 from shoes.cpp:1:
/usr/include/c++/9/bits/stl_bvector.h:134:3: note:   'std::swap'
  134 |   swap(bool& __x, _Bit_reference __y) noexcept
      |   ^~~~
In file included from /usr/include/c++/9/bits/stl_pair.h:59,
                 from /usr/include/c++/9/bits/stl_algobase.h:64,
                 from /usr/include/c++/9/vector:60,
                 from shoes.h:5,
                 from shoes.cpp:1:
/usr/include/c++/9/bits/move.h:182:5: note:   'std::swap'
  182 |     swap(_Tp& __a, _Tp& __b)
      |     ^~~~
In file included from /usr/include/c++/9/exception:143,
                 from /usr/include/c++/9/new:40,
                 from /usr/include/c++/9/ext/new_allocator.h:33,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/c++allocator.h:33,
                 from /usr/include/c++/9/bits/allocator.h:46,
                 from /usr/include/c++/9/vector:64,
                 from shoes.h:5,
                 from shoes.cpp:1:
/usr/include/c++/9/bits/exception_ptr.h:166:5: note:   'std::__exception_ptr::swap'
  166 |     swap(exception_ptr& __lhs, exception_ptr& __rhs)
      |     ^~~~
shoes.cpp:11:13: error: 'cnt' was not declared in this scope; did you mean 'int'?
   11 |             cnt++;
      |             ^~~
      |             int
shoes.cpp:20:13: error: 'swap' was not declared in this scope
   20 |             swap(s[k], s[k+1]);
      |             ^~~~
shoes.cpp:20:13: note: suggested alternatives:
In file included from /usr/include/c++/9/vector:68,
                 from shoes.h:5,
                 from shoes.cpp:1:
/usr/include/c++/9/bits/stl_bvector.h:134:3: note:   'std::swap'
  134 |   swap(bool& __x, _Bit_reference __y) noexcept
      |   ^~~~
In file included from /usr/include/c++/9/bits/stl_pair.h:59,
                 from /usr/include/c++/9/bits/stl_algobase.h:64,
                 from /usr/include/c++/9/vector:60,
                 from shoes.h:5,
                 from shoes.cpp:1:
/usr/include/c++/9/bits/move.h:182:5: note:   'std::swap'
  182 |     swap(_Tp& __a, _Tp& __b)
      |     ^~~~
In file included from /usr/include/c++/9/exception:143,
                 from /usr/include/c++/9/new:40,
                 from /usr/include/c++/9/ext/new_allocator.h:33,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/c++allocator.h:33,
                 from /usr/include/c++/9/bits/allocator.h:46,
                 from /usr/include/c++/9/vector:64,
                 from shoes.h:5,
                 from shoes.cpp:1:
/usr/include/c++/9/bits/exception_ptr.h:166:5: note:   'std::__exception_ptr::swap'
  166 |     swap(exception_ptr& __lhs, exception_ptr& __rhs)
      |     ^~~~
shoes.cpp:21:13: error: 'cnt' was not declared in this scope; did you mean 'int'?
   21 |             cnt++;
      |             ^~~
      |             int
shoes.cpp:28:10: error: 'cnt' was not declared in this scope; did you mean 'int'?
   28 |   return cnt;
      |          ^~~
      |          int
shoes.cpp:4:12: warning: unused variable 'ans' [-Wunused-variable]
    4 |  long long ans = 0;
      |            ^~~