Submission #140498

#TimeUsernameProblemLanguageResultExecution timeMemory
140498PedroBigManSorting (IOI15_sorting)C++14
0 / 100
10 ms504 KiB
#include "sorting.h" #include <iostream> #include <vector> #include <cmath> #include <algorithm> #include <string> using namespace std; typedef int ll; typedef unsigned long long int ull; typedef long double ld; #define REP(i,a,b) for(ll i=a; i<b; i++) #define pb push_back #define mp make_pair #define pl pair<ll,ll> #define ff first #define ss second #define INF ((ll) pow(2,63) -1) ll insig; #define In(vecBRO, LENBRO) REP(IBRO,0,LENBRO) {cin>>insig; vecBRO.pb(insig);} void Out(vector<ll> x) {REP(i,0,x.size()) {cout<<x[i]<<" ";} cout<<endl;} int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { ll c1, c2; vector<ll> pos, oc; REP(i,0,N) {pos.pb(i);oc.pb(0);} REP(i,0,N) {oc[S[i]]=i;} ll last=0; REP(i,0,M) { c1=pos[X[i]]; c2=pos[Y[i]]; pos[X[i]]=c2; pos[Y[i]]=c1; } vector<ll> m; REP(i,0,N) {m.pb(0);} REP(i,0,N) {m[pos[i]]=i;} ll sP=0; if(Y[0]==0) { REP(i,0,INF) { bool srt = true; REP(j,0,N) {if(S[j]!=j) {srt=false;}} if(srt) {return last;} //swap cells X[i],Y[i] because of E if(oc[i]!=i) { P[last]=i; Q[last]=oc[i]; c1=S[i]; c2=S[oc[i]]; S[i]=c2; S[oc[i]]=c1; oc[i]=i; oc[c1]=Q[last]; last++; } else { P[last]=0; Q[last]=0; last++; } //oc[S[X[i]]]=Y[i]; oc[S[Y[i]]]=X[i]; //c1=S[X[i]]; c2=S[Y[i]]; S[X[i]]=c2; S[Y[i]]=c1; //c1=pos[m[X[i]]]; c2=pos[m[Y[i]]]; pos[m[X[i]]]=c2; pos[m[Y[i]]]=c1; //c1=m[X[i]]; c2=m[Y[i]]; m[X[i]]=c2; m[Y[i]]=c1; } } REP(i,0,INF) { bool srt = true; REP(j,0,N) {if(S[j]!=j) {srt=false;}} if(srt) {return i;} //swap cells X[i],Y[i] because of E oc[S[X[i]]]=Y[i]; oc[S[Y[i]]]=X[i]; c1=S[X[i]]; c2=S[Y[i]]; S[X[i]]=c2; S[Y[i]]=c1; c1=pos[m[X[i]]]; c2=pos[m[Y[i]]]; pos[m[X[i]]]=c2; pos[m[Y[i]]]=c1; c1=m[X[i]]; c2=m[Y[i]]; m[X[i]]=c2; m[Y[i]]=c1; //if i<N swap cells oc[i],pos[i] because of A if(i<N) { P[i] = oc[i]; Q[i] = pos[i]; oc[S[P[i]]] = Q[i]; oc[S[Q[i]]] = P[i]; c1=S[P[i]]; c2=S[Q[i]]; S[P[i]]=c2; S[Q[i]]=c1; } else {P[i]=0; Q[i]=0;} } } /*int main() { ll N,M; cin>>N>>M; int S[N]; REP(i,0,N) {cin>>S[i];} int X[M],Y[M]; REP(i,0,M) {cin>>X[i]>>Y[i];} int P[M], Q[M]; cout<<findSwapPairs(N,S,M,X,Y,P,Q)<<endl; }*/

Compilation message (stderr)

sorting.cpp: In function 'void Out(std::vector<int>)':
sorting.cpp:11:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define REP(i,a,b) for(ll i=a; i<b; i++)
sorting.cpp:20:29:
 void Out(vector<ll> x) {REP(i,0,x.size()) {cout<<x[i]<<" ";} cout<<endl;}
                             ~~~~~~~~~~~~
sorting.cpp:20:25: note: in expansion of macro 'REP'
 void Out(vector<ll> x) {REP(i,0,x.size()) {cout<<x[i]<<" ";} cout<<endl;}
                         ^~~
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:36:8: warning: unused variable 'sP' [-Wunused-variable]
     ll sP=0;
        ^~
sorting.cpp:81:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
#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...