Submission #885844

# Submission time Handle Problem Language Result Execution time Memory
885844 2023-12-10T21:07:21 Z JakobZorz Sorting (IOI15_sorting) C++17
16 / 100
3 ms 600 KB
#include"sorting.h"
#include<iostream>
#include<vector>
using namespace std;

int n;
int*x,*y,*s;

vector<pair<int,int>>construct(int m){
    vector<pair<int,int>>ans(m);
    vector<int>perm(n),curr(n);
    for(int i=0;i<n;i++){
        perm[i]=i;
        curr[i]=s[i];
    }
    
    for(int i=0;i<m;i++)
        swap(curr[x[i]],curr[y[i]]);
    
    for(int i=m-1;i>=0;i--)
        swap(perm[x[i]],perm[y[i]]);
    
    for(int i=0;i<m;i++){
        swap(perm[x[i]],perm[y[i]]);
        for(int j=0;j<n;j++){
            if(curr[j]!=j){
                ans[i].first=perm[j];
                for(int k=0;k<n;k++){
                    if(curr[k]==j){
                        swap(curr[j],curr[k]);
                        ans[i].second=perm[k];
                        break;
                    }
                }
                break;
            }
        }
    }
    
    return ans;
}

int findSwapPairs(int N,int S[],int _,int X[],int Y[],int P[],int Q[]){
    n=N;
    x=X;
    y=Y;
    s=S;
    
    vector<pair<int,int>>res=construct(n);
    for(int i=0;i<n;i++){
        P[i]=res[i].first;
        Q[i]=res[i].second;
    }
    
    vector<int>test(n);
    for(int i=0;i<n;i++)
        test[i]=s[i];
    
    for(int i=0;i<n;i++){
        swap(test[x[i]],test[y[i]]);
        swap(test[P[i]],test[Q[i]]);
    }
    
    //for(int i:test)
        //cout<<i<<" ";
    //cout<<"\n";
	return n;
}


Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:43:37: warning: unused parameter '_' [-Wunused-parameter]
   43 | int findSwapPairs(int N,int S[],int _,int X[],int Y[],int P[],int Q[]){
      |                                 ~~~~^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -