Submission #1226044

#TimeUsernameProblemLanguageResultExecution timeMemory
1226044cpdreamerSorting (IOI15_sorting)C++20
Compilation error
0 ms0 KiB
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
    P[0] = 0;
    Q[0] = 0;
    int n=N,m=M;
    int p[n];
    int a[n];
    for (int i=0;i<n;i++) {
        a[i]=S[i];
    }
    for (int i=0;i<m;i++) {
        swap(a[X[i]],a[Y[i]]);
    }
    for (int i=0;i<n;i++) {
        p[a[i]]=i;
    }
    swap(S[X[0]],S[Y[0]]);
    int c=0;
    for (int i=0;i<n;i++) {
        int id1=-1;
        for (int j=0;j<n;j++) {
            if (S[j]==i) {
                id1=j;
            }
        }
        int id2=-1;
        for (int j=0;j<n;j++) {
            if (p[S[j]]==i) {
                id2=j;
            }
        }
        swap(p[i],p[S[id2]]);
        P[i]=id1,Q[i]=id2;
        swap(S[P[i]],S[Q[i]]);
        if (i<n-1) {
            swap(S[X[i+1]],S[Y[i+1]]);
        }
    }
    for (int i=n;i<m;i++) {
        P[i]=0,Q[i]=0;
    }
    return m;
}

Compilation message (stderr)

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:11:9: error: 'swap' was not declared in this scope
   11 |         swap(a[X[i]],a[Y[i]]);
      |         ^~~~
sorting.cpp:16:5: error: 'swap' was not declared in this scope
   16 |     swap(S[X[0]],S[Y[0]]);
      |     ^~~~