Submission #1195179

#TimeUsernameProblemLanguageResultExecution timeMemory
1195179nikulidSorting (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 next, first;
    bool already_sorted;
    vector<int> ns(N);
    for(int i=0; i<N; i++){
    	ns[i] = S[i];
    }

    for(int c=0; true; c++){
    	if(i>=N){i=N-1};
    	else{i=c};
    	already_sorted=true;
    	for(int j=0; j<N; j++){
    		if(ns[j] == i){
    			next = j;
    		}

    		if(j>0){
    			if(ns[j-1] > ns[j]){
    				already_sorted=false;
    			}
    		}
    	}
    	if(already_sorted){
    		return c;
    	}

    	first = ((i==1)?0:i);
    	P[i] = first;
    	Q[i] = next;
    	swap(ns[first], ns[next]);
    	// we have "swapped" positions `i` and `trans[i]`. whatever that means.
    }

    /*for(auto x:ns){
    	cout<<x<<" ";
    }cout<<"\n\n";*/
	return N;
}

Compilation message (stderr)

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:15:12: error: 'i' was not declared in this scope
   15 |         if(i>=N){i=N-1};
      |            ^
sorting.cpp:16:9: error: 'else' without a previous 'if'
   16 |         else{i=c};
      |         ^~~~
sorting.cpp:16:14: error: 'i' was not declared in this scope
   16 |         else{i=c};
      |              ^
sorting.cpp:19:29: error: 'i' was not declared in this scope
   19 |                 if(ns[j] == i){
      |                             ^
sorting.cpp:33:19: error: 'i' was not declared in this scope
   33 |         first = ((i==1)?0:i);
      |                   ^