제출 #60150

#제출 시각아이디문제언어결과실행 시간메모리
60150dukati8정렬하기 (IOI15_sorting)C++14
74 / 100
1077 ms9412 KiB
#include "sorting.h" #include <bits/stdc++.h> #define rep(i,a,b) for (int i=a; i<int(b); i++) using namespace std; vector<pair<int, int> > moves; int movestofix(int Ii[],int Ss[], int N) { int I[N], S[N]; rep (i,0,N) { I[i]=Ii[i];S[i]=Ss[i];} moves.clear(); //I[i] is not value at i, but index of value i in S int counter=0; rep(i,0,N) { if (S[i]==i) continue; counter++; int a,b; a=i; b=I[i]; //a och b byter plats int sa,sb; sa=S[a]; sb=S[b]; moves.push_back(make_pair(a,b)); S[a]=sb; S[b]=sa; I[sa]=b; I[sb]=a; } moves.push_back(make_pair(0,0)); return counter; } int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { int I[N]; rep (i,0,N) { I[S[i]]=i; } int i=0; while (movestofix(I,S,N)>i) { int a,b; a=X[i]; b=Y[i]; //a och b byter plats int sa,sb; sa=S[a]; sb=S[b]; S[a]=sb; S[b]=sa; I[sa]=b; I[sb]=a; i++; } rep (j,0,N) {S[j]=j;I[j]=j;} for (int j=i-1;j>=0; j--) { P[j]=S[moves[j].first]; Q[j]=S[moves[j].second]; //swap(switches[X[j]],switches[Y[j]]); int a,b; a=I[X[j]]; b=I[Y[j]]; //a och b byter plats int sa,sb; sa=S[a]; sb=S[b]; S[a]=sb; S[b]=sa; I[sa]=b; I[sb]=a; } return i; }

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

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:34:39: warning: unused parameter 'M' [-Wunused-parameter]
 int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
                                       ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...