제출 #1168715

#제출 시각아이디문제언어결과실행 시간메모리
1168715anmattroi정렬하기 (IOI15_sorting)C++17
16 / 100
1 ms328 KiB
#include "sorting.h"
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
using ii = pair<int, int>;


int n;

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
    if (N == 1) return 0;
    n = N;
    int nt = 0;
    int p0 = -1, p1 = -1;
    for (int i = 0; i < n; i++)
        if (S[i] == 0) p0 = i;
        else if (S[i] == 1) p1 = i;
    if (p0 > 1 and p1 > 1) {
        swap(S[0], S[1]);
        P[nt] = 0; Q[nt] = p0; ++nt;
        swap(S[0], S[p0]);
        swap(S[0], S[1]);
        P[nt] = 0; Q[nt] = p1; ++nt;
        swap(S[0], S[p1]);
    } else if (p0 > 1 or p1 > 1) {
        swap(S[0], S[1]);
        swap(S[p0], S[p1]);
        P[nt] = p0; Q[nt] = p1; ++nt;
    }



    for (int i = 2; i < n; i++)
        if (S[i] != i)
            for (int j = i+1; j < n; j++)
        if (S[j] == i) {
            P[nt] = i; Q[nt] = j;
            ++nt;
            swap(S[0], S[1]);
            swap(S[i], S[j]);
            break;
        }

    if (S[0] != 0) {
        P[nt] = 0; Q[nt] = 0;
        ++nt;
    }

    return nt;
}


#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...