답안 #428033

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
428033 2021-06-15T07:28:34 Z haxorman 정렬하기 (IOI15_sorting) C++14
컴파일 오류
0 ms 0 KB
#include "sorting.h"
#include "bits/stdc++.h"
using namespace std;

const int mxN = 2e5 + 7;

int n, m, arr[mxN];

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
	n = N, m = M;

	for (int i = 0; i < n; ++i) {
		arr[i] = S[i];
	}
	sort(S, S + n);

	int R = 0, ind = 0;

	bool ok = false;
	for (int iter = 1; iter <= m / n && !ok; ++iter) {
		swap(arr[X[ind], arr[Y[ind]]]);

		bool ok = true;
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				if (arr[j] == S[i] && i != j) {
					swap(arr[j], arr[i]);
					P[ind] = j, Q[ind] = i;
					++R;
					++ind;
					ok = false;
					break;
				}
			}
		}
	}

	return R;
}


Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:21:17: warning: value computed is not used [-Wunused-value]
   21 |   swap(arr[X[ind], arr[Y[ind]]]);
      |            ~~~~~^
sorting.cpp:21:17: warning: left operand of comma operator has no effect [-Wunused-value]
sorting.cpp:21:32: error: no matching function for call to 'swap(int&)'
   21 |   swap(arr[X[ind], arr[Y[ind]]]);
      |                                ^
In file included from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from sorting.cpp:2:
/usr/include/c++/10/sstream:849:5: note: candidate: 'template<class _CharT, class _Traits, class _Allocator> void std::__cxx11::swap(std::__cxx11::basic_stringbuf<_CharT, _Traits, _Alloc>&, std::__cxx11::basic_stringbuf<_CharT, _Traits, _Alloc>&)'
  849 |     swap(basic_stringbuf<_CharT, _Traits, _Allocator>& __x,
      |     ^~~~
/usr/include/c++/10/sstream:849:5: note:   template argument deduction/substitution failed:
sorting.cpp:21:32: note:   mismatched types 'std::__cxx11::basic_stringbuf<_CharT, _Traits, _Alloc>' and 'int'
   21 |   swap(arr[X[ind], arr[Y[ind]]]);
      |                                ^
In file included from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from sorting.cpp:2:
/usr/include/c++/10/sstream:856:5: note: candidate: 'template<class _CharT, class _Traits, class _Allocator> void std::__cxx11::swap(std::__cxx11::basic_istringstream<_CharT, _Traits, _Allocator>&, std::__cxx11::basic_istringstream<_CharT, _Traits, _Allocator>&)'
  856 |     swap(basic_istringstream<_CharT, _Traits, _Allocator>& __x,
      |     ^~~~
/usr/include/c++/10/sstream:856:5: note:   template argument deduction/substitution failed:
sorting.cpp:21:32: note:   mismatched types 'std::__cxx11::basic_istringstream<_CharT, _Traits, _Allocator>' and 'int'
   21 |   swap(arr[X[ind], arr[Y[ind]]]);
      |                                ^
In file included from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from sorting.cpp:2:
/usr/include/c++/10/sstream:863:5: note: candidate: 'template<class _CharT, class _Traits, class _Allocator> void std::__cxx11::swap(std::__cxx11::basic_ostringstream<_CharT, _Traits, _Allocator>&, std::__cxx11::basic_ostringstream<_CharT, _Traits, _Allocator>&)'
  863 |     swap(basic_ostringstream<_CharT, _Traits, _Allocator>& __x,
      |     ^~~~
/usr/include/c++/10/sstream:863:5: note:   template argument deduction/substitution failed:
sorting.cpp:21:32: note:   mismatched types 'std::__cxx11::basic_ostringstream<_CharT, _Traits, _Allocator>' and 'int'
   21 |   swap(arr[X[ind], arr[Y[ind]]]);
      |                                ^
In file included from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from sorting.cpp:2:
/usr/include/c++/10/sstream:870:5: note: candidate: 'template<class _CharT, class _Traits, class _Allocator> void std::__cxx11::swap(std::__cxx11::basic_stringstream<_CharT, _Traits, _Allocator>&, std::__cxx11::basic_stringstream<_CharT, _Traits, _Allocator>&)'
  870 |     swap(basic_stringstream<_CharT, _Traits, _Allocator>& __x,
      |     ^~~~
/usr/include/c++/10/sstream:870:5: note:   template argument deduction/substitution failed:
sorting.cpp:21:32: note:   mismatched types 'std::__cxx11::basic_stringstream<_CharT, _Traits, _Allocator>' and 'int'
   21 |   swap(arr[X[ind], arr[Y[ind]]]);
      |                                ^
In file included from /usr/include/c++/10/regex:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:110,
                 from sorting.cpp:2:
/usr/include/c++/10/bits/regex.h:849:5: note: candidate: 'template<class _Ch_type, class _Rx_traits> void std::__cxx11::swap(std::__cxx11::basic_regex<_Ch_type, _Rx_traits>&, std::__cxx11::basic_regex<_Ch_type, _Rx_traits>&)'
  849 |     swap(basic_regex<_Ch_type, _Rx_traits>& __lhs,
      |     ^~~~
/usr/include/c++/10/bits/regex.h:849:5: note:   template argument deduction/substitution failed:
sorting.cpp:21:32: note:   mismatched types 'std::__cxx11::basic_regex<_Ch_type, _Rx_traits>' and 'int'
   21 |   swap(arr[X[ind], arr[Y[ind]]]);
      |                                ^
In file included from /usr/include/c++/10/regex:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:110,
                 from sorting.cpp:2:
/usr/include/c++/10/bits/regex.h:2141:5: note: candidate: 'template<class _Bi_iter, class _Alloc> void std::__cxx11::swap(std::__cxx11::match_results<_BiIter, _Alloc>&, std::__cxx11::match_results<_BiIter, _Alloc>&)'
 2141 |     swap(match_results<_Bi_iter, _Alloc>& __lhs,
      |     ^~~~
/usr/include/c++/10/bits/regex.h:2141:5: note:   template argument deduction/substitution failed:
sorting.cpp:21:32: note:   mismatched types 'std::__cxx11::match_results<_BiIter, _Alloc>' and 'int'
   21 |   swap(arr[X[ind], arr[Y[ind]]]);
      |                                ^
In file included from /usr/include/c++/10/bits/nested_exception.h:40,
                 from /usr/include/c++/10/exception:148,
                 from /usr/include/c++/10/ios:39,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from sorting.cpp:2:
/usr/include/c++/10/bits/move.h:189:5: note: candidate: 'template<class _Tp> std::_Require<std::__not_<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std::swap(_Tp&, _Tp&)'
  189 |     swap(_Tp& __a, _Tp& __b)
      |     ^~~~
/usr/include/c++/10/bits/move.h:189:5: note:   template argument deduction/substitution failed:
sorting.cpp:21:32: note:   candidate expects 2 arguments, 1 provided
   21 |   swap(arr[X[ind], arr[Y[ind]]]);
      |                                ^
In file included from /usr/include/c++/10/bits/nested_exception.h:40,
                 from /usr/include/c++/10/exception:148,
                 from /usr/include/c++/10/ios:39,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from sorting.cpp:2:
/usr/include/c++/10/bits/move.h:213:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> std::__enable_if_t<std::__is_swappable<_Tp>::value> std::swap(_Tp (&)[_Nm], _Tp (&)[_Nm])'
  213 |     swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
      |     ^~~~
/usr/include/c++/10/bits/move.h:213:5: note:   template argument deduction/substitution failed:
sorting.cpp:21:32: note:   mismatched types '_Tp [_Nm]' and 'int'
   21 |   swap(arr[X[ind], arr[Y[ind]]]);
      |                                ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from sorting.cpp:2:
/usr/include/c++/10/bits/stl_pair.h:533:5: note: candidate: 'template<class _T1, class _T2> void std::swap(std::pair<_T1, _T2>&, std::pair<_T1, _T2>&)'
  533 |     swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
      |     ^~~~
/usr/include/c++/10/bits/stl_pair.h:533:5: note:   template argument deduction/substitution failed:
sorting.cpp:21:32: note:   mismatched types 'std::pair<_T1, _T2>' and 'int'
   21 |   swap(arr[X[ind], arr[Y[ind]]]);
      |                                ^
In file included from /usr/include/c++/10/string:55,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from sorting.cpp:2:
/usr/include/c++/10/bits/basic_string.h:6420:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> void std::swap(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)'
 6420 |     swap(basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~
/usr/include/c++/10/bits/basic_string.h:6420:5: note:   template argument deduction/substitution failed:
sorting.cpp:21:32: note:   mismatched types 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>' and 'int'
   21 |   swap(arr[X[ind], arr[Y[ind]]]);
      |                                ^
In file included from /usr/include/c++/10/deque:67,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:68,
                 from sorting.cpp:2:
/usr/include/c++/10/bits/stl_deque.h:2311:5: note: candidate: 'template<class _Tp, class _Alloc> void std::swap(std::deque<_Tp, _Alloc>&, std::deque<_Tp, _Alloc>&)'
 2311 |     swap(deque<_Tp,_Alloc>& __x, deque<_Tp,_Alloc>& __y)
      |     ^~~~
/usr/include/c++/10/bits/stl_deque.h:2311:5: note:   template argument deduction/substitution failed:
sorting.cpp:21:32: note:   mismatched types 'std::deque<_Tp, _Alloc>' and 'int'
   21 |   swap(arr[X[ind], arr[Y[ind]]]);
      |                                ^
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:70,
                 from sorting.cpp:2:
/usr/include/c++/10/fstream:1264:5: note: candidate: 'template<class _CharT, class _Traits> void std::swap(std::basic_filebuf<_CharT, _Traits>&, std::basic_filebuf<_CharT, _Traits>&)'
 1264 |     swap(basic_filebuf<_CharT, _Traits>& __x,
      |     ^~~~
/usr/include/c++/10/fstream:1264:5: note:   template argument deduction/substitution failed:
sorting.cpp:21:32: note:   mismatched types 'std::basic_filebuf<_CharT, _Traits>' and 'int'
   21 |   swap(arr[X[ind], arr[Y[ind]]]);
      |                                ^
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:70,
                 from sorting.cpp:2:
/usr/include/c++/10/fstream:1271:5: note: candidate: 'template<class _CharT, class _Traits> void std::swap(std::basic_ifstream<_CharT, _Traits>&, std::basic_ifstream<_CharT, _Traits>&)'
 1271 |     swap(basic_ifstream<_CharT, _Traits>& __x,
      |     ^~~~
/usr/include/c++/10/fstream:1271:5: note:   template argument deduction/substitution failed:
sorting.cpp:21:32: note:   mismatched types 'std::basic_ifstream<_CharT, _Traits>' and 'int'
   21 |   swap(arr[X[ind], arr[Y[ind]]]);
      |                                ^
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:70,
                 from sorting.cpp:2:
/usr/include/c++/10/fstream:1278:5: note: candidate: 'template<class _CharT, class _Traits> void std::swap(std::basic_ofstream<_CharT, _Traits>&, std::basic_ofstream<_CharT, _Traits>&)'
 1278 |     swap(basic_ofstream<_CharT, _Traits>& __x,
      |     ^~~~
/usr/include/c++/10/fstream:1278:5: note:   template argument deduction/substitution failed:
sorting.cpp:21:32: note:   mismatched types 'std::basic_ofstream<_CharT, _Traits>' and 'int'
   21 |   swap(arr[X[ind], arr[Y[ind]]]);
      |                                ^
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:70,
                 from sorting.cpp:2:
/usr/include/c++/10/fstream:1285:5: note: candidate: 'template<class _CharT, class _Traits> void std::swap(std::basic_fstream<_CharT, _Traits>&, std::basic_fstream<_CharT, _Traits>&)'
 1285 |     swap(basic_fstream<_CharT, _Traits>& __x,
      |     ^~~~
/usr/include/c++/10/fstream:1285:5: note:   template argument deduction/substitution failed:
sorting.cpp:21:32: note:   mismatched types 'std::basic_fstream<_CharT, _Traits>' and 'int'
   21 |   swap(arr[X[ind], arr[Y[ind]]]);
      |                                ^
In file included from /usr/include/c++/10/tuple:39,
                 from /usr/include/c++/10/functional:54,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:71,
                 from sorting.cpp:2:
/usr/include/c++/10/array:321:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> void std::swap(std::array<_Tp, _Nm>&, std::array<_Tp, _Nm>&)'
  321 |     swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two)
      |     ^~~~
/usr/include/c++/10/array:321:5: note:   template argument deduction/substitution failed:
sorting.cpp:21:32: note:   mismatched types 'std::array<_Tp, _Nm>' and 'int'
   21 |   swap(arr[X[ind], arr[Y[ind]]]);
      |                                ^
In file included from /usr/include/c++/10/functional:54,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:71,
                 from sorting.cpp:2:
/usr/include/c++/10/tuple:1629:5: note: candidate: 'template<class ... _Elements> void std::swap(std::tuple<_Tps ...>&, std::tuple<_Tps ...>&)'
 1629 |     swap(tuple<_Elements...>& __x, tuple<_Elements...>& __y)
      |     ^~~~
/usr/include/c++/10/tuple:1629:5: note:   template argument deduction/substitution failed:
sorting.cpp:21:32: note:   mismatched types 'std::tuple<_Tps ...>' and 'int'
   21 |   swap(arr[X[ind], arr[Y[ind]]]);
      |                                ^
In file included from /usr/include/c++/10/functional:59,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:71,
                 from sorting.cpp:2:
/usr/include/c++/10/bits/std_function.h:720:5: note: candidate: 'template<class _Res, class ... _Args> void std::swap(std::function<_Res(_ArgTypes ...)>&, std::function<_Res(_ArgTypes ...)>&)'
  720 |     swap(function<_Res(_Args...)>& __x, function<_Res(_Args...)>& __y) noexcept
      |     ^~~~
/usr/include/c++/10/bits/std_function.h:720:5: note:   template argument deduction/substitution failed:
sorting.cpp:21:32: note:   mismatched types 'std::function<_Res(_ArgTypes ...)>' and 'int'
   21 |   swap(arr[X[ind], arr[Y[ind]]]);
      |                                ^
In file included from /usr/include/c++/10/bits/locale_conv.h:41,
                 from /usr/include/c++/10/locale:43,
                 from /usr/include/c++/10/iomanip:43,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:72,
                 from sorting.cpp:2:
/usr/include/c++/10/bits/unique_ptr.h:738:5: note: candidate: 'template<class _Tp, class _Dp> void std::swap(std::unique_ptr<_Tp, _Dp>&, std::unique_ptr<_Tp, _Dp>&)'
  738 |     swap(unique_ptr<_Tp, _Dp>& __x,
      |     ^~~~
/usr/include/c++/10/bits/unique_ptr.h:738:5: note:   template argument deduction/substitution failed:
sorting.cpp:21:32: note:   mismatched types 'std::unique_ptr<_Tp, _Dp>' and 'int'
   21 |   swap(arr[X[ind], arr[Y[ind]]]);
      |                                ^
In file included from /usr/include/c++/10/list:63,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:79,
                 from sorting.cpp:2:
/usr/include/c++/10/bits/stl_list.h:2082:5: note: candidate: 'template<class _Tp, class _Alloc> void std::swap(std::__cxx11::list<_Tp, _Alloc>&, std::__cxx11::list<_Tp, _Alloc>&)'
 2082 |     swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y)
      |     ^~~~
/usr/include/c++/10/bits/stl_list.h:2082:5: note:   template argument deduction/substitution failed:
sorting.cpp:21:32: note:   mismatched types 'std::__cxx11::list<_Tp, _Alloc>' and 'int'
   21 |   swap(arr[X[ind], arr[Y[ind]]]);
      |                                ^
In file included from /usr/include/c++/10/map:60,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:81,
                 from sorting.cpp:2:
/usr/include/c++/10/bits/stl_tree.h:1655:5: note: candidate: 'template<class _Key, class _Val, class _KeyOfValue, class _Compare, class _Alloc> void std::swap(std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&, std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&)'
 1655 |     swap(_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x,
      |     ^~~~
/usr/include/c++/10/bits/stl_tree.h:1655:5: note:   template argument deduction/substitution failed:
sorting.cpp:21:32: note:   mismatched types 'std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>' and 'int'
   21 |   swap(arr[X[ind], arr[Y[ind]]]);
      |                                ^
In file included from /usr/include/c++/10/map:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:81,
                 from sorting.cpp:2:
/usr/include/c++/10/bits/stl_map.h:1537:5: note: candidate: 'template<class _Key, class _Tp, class _Compare, class _Alloc> void std::swap(std::map<_Key, _Tp, _Compare, _Alloc>&, std::map<_Key, _Tp, _Compare, _Alloc>&)'
 1537 |     swap(map<_Key, _Tp, _Compare, _Alloc>& __x,
      |     ^~~~
/usr/include/c++/10/bits/stl_map.h:1537:5: note:   template argument deduction/substitution failed:
sorting.cpp:21:32: note:   mismatched types 'std::map<_Key, _Tp, _Compare, _Alloc>' and 'int'
   21 |   swap(arr[X[ind], arr[Y[ind]]]);
      |                                ^
In file included from /usr/include/c++/10/map:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:81,
                 from sorting.cpp:2:
/usr/include/c++/10/bits/stl_multimap.h:1202:5: note: candidate: 'template<class _Key, class _Tp, class _Compare, class _Alloc> void std::swap(std::multimap<_Key, _Tp, _Compare, _Alloc>&, std::multimap<_Key, _Tp, _Compare, _Alloc>&)'
 1202 |     swap(multimap<_Key, _Tp, _Compare, _Alloc>& __x,
      |     ^~~~
/usr/include/c++/10/bits/stl_multimap.h:1202:5: note:   template argument deductio