Submission #143320

# Submission time Handle Problem Language Result Execution time Memory
143320 2019-08-13T16:07:51 Z VladaMG98 Arranging Shoes (IOI19_shoes) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "shoes.h"
long long count_swaps(std::vector<int> s) {
	int n = (int)s.size() / 2;
	int N = 2 * n;
	long long ans = 0;
	for(int pos = 0; pos < n; pos++) {
        //printf("pos = %d\n", pos);
        int target = -s[2 * pos];
        int fnd = -1;
		for(int i = 2 * pos + 1; i < N; i++) {
			if(s[i] == target) {
				fnd = i;
				break;
			}
		}
		assert(fnd + 1);
		for(int i = fnd - 1; i >= 2 * pos + 1; i--) {
			swap(s[i], s[i + 1]);
			ans += 1;
		}
		if(s[2 * pos] > 0) {
            swap(s[2 * pos], s[2 * pos + 1]);
            ans += 1;
		}
        //printf("ans = %d\n", ans);
	}
	return ans;
}

Compilation message

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:19:4: error: 'swap' was not declared in this scope
    swap(s[i], s[i + 1]);
    ^~~~
shoes.cpp:19:4: note: suggested alternatives:
In file included from /usr/include/c++/7/complex:45:0,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from shoes.cpp:1:
/usr/include/c++/7/sstream:796:5: note:   'std::__cxx11::swap'
     swap(basic_stringbuf<_CharT, _Traits, _Allocator>& __x,
     ^~~~
In file included from /usr/include/c++/7/regex:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:110,
                 from shoes.cpp:1:
/usr/include/c++/7/bits/regex.h:1958:5: note:   'std::__cxx11::swap'
     swap(match_results<_Bi_iter, _Alloc>& __lhs,
     ^~~~
In file included from /usr/include/c++/7/bits/stl_pair.h:59:0,
                 from /usr/include/c++/7/bits/stl_algobase.h:64,
                 from /usr/include/c++/7/bits/specfun.h:45,
                 from /usr/include/c++/7/cmath:1914,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:41,
                 from shoes.cpp:1:
/usr/include/c++/7/bits/move.h:187:5: note:   'std::swap'
     swap(_Tp& __a, _Tp& __b)
     ^~~~
/usr/include/c++/7/bits/move.h:187:5: note:   'std::swap'
In file included from /usr/include/c++/7/exception:142:0,
                 from /usr/include/c++/7/ios:39,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from shoes.cpp:1:
/usr/include/c++/7/bits/exception_ptr.h:166:5: note:   'std::__exception_ptr::swap'
     swap(exception_ptr& __lhs, exception_ptr& __rhs)
     ^~~~
shoes.cpp:23:13: error: 'swap' was not declared in this scope
             swap(s[2 * pos], s[2 * pos + 1]);
             ^~~~
shoes.cpp:23:13: note: suggested alternatives:
In file included from /usr/include/c++/7/complex:45:0,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from shoes.cpp:1:
/usr/include/c++/7/sstream:796:5: note:   'std::__cxx11::swap'
     swap(basic_stringbuf<_CharT, _Traits, _Allocator>& __x,
     ^~~~
In file included from /usr/include/c++/7/regex:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:110,
                 from shoes.cpp:1:
/usr/include/c++/7/bits/regex.h:1958:5: note:   'std::__cxx11::swap'
     swap(match_results<_Bi_iter, _Alloc>& __lhs,
     ^~~~
In file included from /usr/include/c++/7/bits/stl_pair.h:59:0,
                 from /usr/include/c++/7/bits/stl_algobase.h:64,
                 from /usr/include/c++/7/bits/specfun.h:45,
                 from /usr/include/c++/7/cmath:1914,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:41,
                 from shoes.cpp:1:
/usr/include/c++/7/bits/move.h:187:5: note:   'std::swap'
     swap(_Tp& __a, _Tp& __b)
     ^~~~
/usr/include/c++/7/bits/move.h:187:5: note:   'std::swap'
In file included from /usr/include/c++/7/exception:142:0,
                 from /usr/include/c++/7/ios:39,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from shoes.cpp:1:
/usr/include/c++/7/bits/exception_ptr.h:166:5: note:   'std::__exception_ptr::swap'
     swap(exception_ptr& __lhs, exception_ptr& __rhs)
     ^~~~