답안 #885830

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
885830 2023-12-10T20:40:17 Z JakobZorz 정렬하기 (IOI15_sorting) C++17
16 / 100
3 ms 448 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 M,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;
    }
    
	return N;
}


Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:43:37: warning: unused parameter 'M' [-Wunused-parameter]
   43 | int findSwapPairs(int N,int S[],int M,int X[],int Y[],int P[],int Q[]){
      |                                 ~~~~^
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 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
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 448 KB Output isn't correct
2 Halted 0 ms 0 KB -