Submission #135793

#TimeUsernameProblemLanguageResultExecution timeMemory
135793amiratouSorting (IOI15_sorting)C++14
36 / 100
4 ms508 KiB
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
	if((X[0]==Y[0])&&X[0]==0){
		map<int,int> pos;
	    for (int i = 0; i < N; ++i)
	    	pos[S[i]]=i;
	    int comp=0;
	    for (int i = 0; i < N; ++i)
	    {
	    	if(pos[i]==i)continue;
	    	P[comp]=pos[i],Q[comp]=i;
	    	pos[S[i]]=pos[i];
	    	pos[i]=i;
	    	swap(S[P[comp]],S[Q[comp]]);
	    	comp++;
	    }
		return comp;
	}
	map<int,int> pos;
    for (int i = 0; i < N; ++i)
    	pos[S[i]]=i;
    int comp=0,idx=0;
    for (int i = 2; i < N; ++i)
    {
    	if(pos[i]==i)continue;
    	swap(pos[S[X[idx]]],pos[S[Y[idx]]]);
    	swap(S[X[idx]],S[Y[idx++]]);
    	P[comp]=pos[i],Q[comp]=i;
    	pos[S[i]]=pos[i];
    	pos[i]=i;
    	swap(S[P[comp]],S[Q[comp]]);
    	comp++;
    }
    if(pos[0]!=0){
    	swap(pos[S[X[idx]]],pos[S[Y[idx]]]);
    	swap(S[X[idx]],S[Y[idx++]]);
    	P[comp]=0,Q[comp]=0;
    	comp++;
    	if(S[0]==0)return comp;
    	P[comp]=0,Q[comp]=1;
    	swap(pos[0],pos[1]);
    	swap(S[0],S[1]);
    	comp++;
    }
	return comp;
}


Compilation message (stderr)

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:30:28: warning: operation on 'idx' may be undefined [-Wsequence-point]
      swap(S[X[idx]],S[Y[idx++]]);
                         ~~~^~
sorting.cpp:39:28: warning: operation on 'idx' may be undefined [-Wsequence-point]
      swap(S[X[idx]],S[Y[idx++]]);
                         ~~~^~
sorting.cpp:5: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...