제출 #143781

#제출 시각아이디문제언어결과실행 시간메모리
143781jh05013Arranging Shoes (IOI19_shoes)C++17
컴파일 에러
0 ms0 KiB
#include "shoes.h" #include <bits/stdc++.h> long long count_swaps(std::vector<int> s) { int n = s.size(); long long ans = 0; for(int i=0; i<n; i++){ int j = -999; if(i%2 == 0){ for(j=i; j<n; j++) if(s[j] < 0) break; } else{ for(j=i; j<n; j++) if(s[j] == -s[i-1]) break; } for(int k=j-1; k>=i; k--) swap(s[k], s[k+1]), ans++; } return ans; }

컴파일 시 표준 에러 (stderr) 메시지

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:15:35: error: 'swap' was not declared in this scope
         for(int k=j-1; k>=i; k--) swap(s[k], s[k+1]), ans++;
                                   ^~~~
shoes.cpp:15:35: 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:2:
/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:2:
/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/vector:60,
                 from shoes.h:5,
                 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/new:40,
                 from /usr/include/c++/7/ext/new_allocator.h:33,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/c++allocator.h:33,
                 from /usr/include/c++/7/bits/allocator.h:46,
                 from /usr/include/c++/7/vector:61,
                 from shoes.h:5,
                 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)
     ^~~~