Submission #140487

# Submission time Handle Problem Language Result Execution time Memory
140487 2019-08-03T08:35:14 Z PedroBigMan Sorting (IOI15_sorting) C++14
0 / 100
9 ms 504 KB
#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 i;}
            //swap cells X[i],Y[i] because of E
            P[i]=i; Q[i]=oc[i];
            c1=S[i]; c2=S[oc[i]];
            S[i]=c2; S[oc[i]]=c1;
            oc[i]=i; oc[c1]=Q[i];
            //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

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:28:8: warning: unused variable 'last' [-Wunused-variable]
     ll last=0;
        ^~~~
sorting.cpp:36:8: warning: unused variable 'sP' [-Wunused-variable]
     ll sP=0;
        ^~
sorting.cpp:73:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Incorrect 2 ms 376 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Incorrect 2 ms 376 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Incorrect 2 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Incorrect 2 ms 376 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -