답안 #669707

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
669707 2022-12-07T06:23:27 Z victor_gao 정렬하기 (IOI15_sorting) C++17
54 / 100
1 ms 480 KB
#include "sorting.h"
#include <bits/stdc++.h>
#define MAXN 200015
using namespace std;
int bk[MAXN],pos_bk[MAXN],pre[MAXN],pos_pre[MAXN];
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
    for (int i=0;i<N;i++){
        bk[i]=i; pos_bk[i]=i;
        pre[i]=S[i];  pos_pre[S[i]]=i;
    }
    for (int i=N-1;i>=0;i--){
        swap(bk[X[i]],bk[Y[i]]);
        pos_bk[bk[X[i]]]=X[i];
        pos_bk[bk[Y[i]]]=Y[i];
    }
    /*
    cout<<"Now : ";
    for (int j=0;j<N;j++)
        cout<<pre[j]<<" \n"[j==N-1];
    cout<<"pos_pre : ";
    for (int j=0;j<N;j++)
        cout<<pos_pre[j]<<" \n"[j==N-1];
    cout<<"from back : ";
    for (int j=0;j<N;j++)
        cout<<bk[j]<<" \n"[j==N-1];
    cout<<"from back pos : ";
    for (int j=0;j<N;j++)
        cout<<pos_bk[j]<<" \n"[j==N-1];
     */   
    for (int i=0;i<N;i++){
        bool flag=1;
        for (int j=0;j<N;j++){
            if (pre[j]!=j){
                flag=0;
                break;
            } 
        }
        if (flag)
            return i;
        swap(pre[X[i]],pre[Y[i]]);
        pos_pre[pre[X[i]]]=X[i];
        pos_pre[pre[Y[i]]]=Y[i];
        swap(bk[X[i]],bk[Y[i]]);
        pos_bk[bk[X[i]]]=X[i];
        pos_bk[bk[Y[i]]]=Y[i];
        int now=i+1;
        /*
        cout<<"Now : ";
        for (int j=0;j<N;j++)
            cout<<pre[j]<<" \n"[j==N-1];
        cout<<"pos_pre : ";
        for (int j=0;j<N;j++)
            cout<<pos_pre[j]<<" \n"[j==N-1];
        cout<<"from back : ";
        for (int j=0;j<N;j++)
            cout<<bk[j]<<" \n"[j==N-1];
        cout<<"from back pos : ";
        for (int j=0;j<N;j++)
            cout<<pos_bk[j]<<" \n"[j==N-1];
        cout<<"swap "<<pos_pre[now]<<" "<<pos_bk[now]<<'\n';
        */

        P[i]=pos_pre[now]; Q[i]=pos_bk[now];
        swap(pre[pos_pre[now]],pre[pos_bk[now]]);
        pos_pre[pre[pos_pre[now]]]=pos_pre[now];
        pos_pre[pre[pos_bk[now]]]=pos_bk[now];
    }
    return N;
}

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:7:39: warning: unused parameter 'M' [-Wunused-parameter]
    7 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                   ~~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 480 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 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 -