Submission #1195328

#TimeUsernameProblemLanguageResultExecution timeMemory
1195328nikulidSorting (IOI15_sorting)C++20
Compilation error
0 ms0 KiB
#include "sorting.h"
#include <vector>

using namespace std;

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
    int n=N;
    bool donene;
    vector<int> fns(n), cns(n);
    for(int i=0; i<n; i++){
        fns[i] = S[i];
        cns[i] = S[i];
    }


    for(int i=0; i<3*n; i++){
        swap(fns[X[i]], fns[Y[i]]);
    }
    // now we have N swaps to make until it must be sorted...
    // this is more than enough :p

    int target;

    for(int c=0; c<3*n; c++){
        i = c%n;

        if(1==1) // check to see if it's already sorted (how... goofy)
        {
            donene=true;
            for(int t=1; t<n; t++){
                if(cns[t-1] > cns[t]){
                    donene=false;
                    break;
                }
            }
            if(donene)return i;
        }


        swap(cns[X[i]], cns[Y[i]]);

        for(int _=0; _<n; _++){
            // only do swaps with respect to the final layout
            // we do not care about cns
            // cns only exists because the question is stupid
            if(fns[_]==i){
                target = _;
                break;
            }
        }
        P[i] = i;
        Q[i] = target;
        swap(fns[P[i]], fns[Q[i]]);
        swap(cns[P[i]], cns[Q[i]]);
    }

    return 3*n;
}

Compilation message (stderr)

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:25:9: error: 'i' was not declared in this scope
   25 |         i = c%n;
      |         ^