답안 #787714

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
787714 2023-07-19T11:34:31 Z vnm06 정렬하기 (IOI15_sorting) C++14
0 / 100
1 ms 340 KB
#include "sorting.h"
#include<bits/stdc++.h>
using namespace std;

int n;
int a[200005];
int b[200005];

int prebroj()
{
    int ans=n;
    for(int i=0; i<n; i++)
    {
        if(!b[i]) continue;
        ans--;
        int t=b[i]-1;
        b[i]=0;
        while(b[t]!=0)
        {
            int t2=b[t];
            b[t]=0;
            t=t2-1;
        }
    }
    return ans;
}

int sp[2][200005], brsp=0;
int pos[200005];

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[])
{
    n=N;
    for(int i=0; i<n; i++) a[i]=S[i];
    int le=-1, ri=M;
    for(int i=0; i<n; i++) b[i]=a[i];
    ri=prebroj();
    for(int i=0; i<n; i++) pos[b[i]]=i;
    for(int i=0; i<n; i++)
    {
        if(b[i]==i+1) continue;
        sp[0][brsp]=b[i];
        sp[1][brsp]=i+1;
        brsp++;
        int tp=pos[i+1];
        pos[b[i]]=pos[i+1];
        pos[i+1]=i;
        swap(b[i], b[tp]);
    }
    for(int i=0; i<n; i++) pos[a[i]]=i;
    for(int i=0; i<brsp; i++)
    {
        P[i]=pos[sp[0][i]];
        Q[i]=pos[sp[1][i]];
        swap(pos[sp[0][i]], pos[sp[1][i]]);
        swap(a[pos[sp[0][i]]], a[pos[sp[1][i]]]);

    }
    for(int i=brsp; i<ri; i++) P[i]=Q[i]=0;
	return ri;
}



Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:35:9: warning: unused variable 'le' [-Wunused-variable]
   35 |     int le=-1, ri=M;
      |         ^~
sorting.cpp:31:46: warning: unused parameter 'X' [-Wunused-parameter]
   31 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[])
      |                                          ~~~~^~~
sorting.cpp:31:55: warning: unused parameter 'Y' [-Wunused-parameter]
   31 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[])
      |                                                   ~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -