제출 #405873

#제출 시각아이디문제언어결과실행 시간메모리
405873jk410정렬하기 (IOI15_sorting)C++17
컴파일 에러
0 ms0 KiB
#include <iostream> #include <vector> using namespace std; int N,M; int S[500],T[500],R[500]; bool Visited[500]; vector<pair<int,int>> SwapPair,Ans; bool f(int k){ Ans.clear(); for (int i=0; i<N; i++){ T[i]=S[i]; Visited[i]=0; } for (int i=0; i<k; i++) swap(T[SwapPair[i].first],T[SwapPair[i].second]); for (int i=0; i<N; i++){ if (T[i]!=i&&!Visited[i]){ Visited[i]=true; for (int j=T[i]; !Visited[j]; j=T[j]){ Visited[j]=true; Ans.push_back({j,T[j]}); } } } if (Ans.size()>k) return false; while (Ans.size()!=k) Ans.push_back({0,0}); return true; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>N; for (int i=0; i<N; i++){ cin>>S[i]; R[S[i]]=i; } cin>>M; for (int j=0; j<M; j++){ int x,y; cin>>x>>y; SwapPair.push_back({x,y}); } for (int i=0; i<=N; i++){ if (f(i)) break; } cout<<Ans.size(); for (int i=0; i<Ans.size(); i++){ swap(R[S[SwapPair[i].first]],R[S[SwapPair[i].second]]); swap(S[SwapPair[i].first],S[SwapPair[i].second]); cout<<"\n"<<R[Ans[i].first]<<" "<<R[Ans[i].second]; swap(S[R[Ans[i].first]],S[R[Ans[i].second]]); swap(R[Ans[i].first],R[Ans[i].second]); } return 0; }

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

sorting.cpp: In function 'bool f(int)':
sorting.cpp:25:19: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   25 |     if (Ans.size()>k)
      |         ~~~~~~~~~~^~
sorting.cpp:27:22: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   27 |     while (Ans.size()!=k)
      |            ~~~~~~~~~~^~~
sorting.cpp: In function 'int main()':
sorting.cpp:51:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     for (int i=0; i<Ans.size(); i++){
      |                   ~^~~~~~~~~~~
/usr/bin/ld: /tmp/ccklLoIt.o: in function `main':
grader.c:(.text.startup+0x0): multiple definition of `main'; /tmp/cc5k7Fpw.o:sorting.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccklLoIt.o: in function `main':
grader.c:(.text.startup+0x4eb): undefined reference to `findSwapPairs(int, int*, int, int*, int*, int*, int*)'
collect2: error: ld returned 1 exit status