Submission #385043

# Submission time Handle Problem Language Result Execution time Memory
385043 2021-04-03T05:08:25 Z qpwoeirut Sorting (IOI15_sorting) C++17
0 / 100
2 ms 620 KB
#include "sorting.h"
#include <algorithm>
#include <cassert>
#include <iostream>

using namespace std;

#define val first
#define idx second

typedef pair<int,int> pii;

const int MN = 200005;

pii A[MN];

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
    int K = 0;
    auto record_swaps = [&](pii& a, pii& b) {
        if (a.val > b.val) {
            P[K] = a.idx;
            Q[K] = b.idx;
            swap(a.idx, b.idx);
            ++K;
        }
        return a.val < b.val;
    };

    for (int i=0; i<N; ++i) {
        A[i] = pii(S[i], i);
    }

    if (X[0] == 0 && Y[0] == 0) {
        sort(A, A+N, record_swaps);
    } else if (X[0] == 0 && Y[0] == 1) {
        sort(A+2, A+N, record_swaps);

        if ((K & 1) == 0) swap(A[0], A[1]);

        while (A[0].val + A[1].val > 1) {
            if (A[0] < A[1]) {
                P[K] = 1;
                swap(A[1], A[2]);
            } else {
                P[K] = 0;
                swap(A[0], A[2]);
            }
            Q[K] = 2;
            ++K;
            swap(A[0], A[1]);

            for (int i=2; i+1<N; ++i) {
                if (!record_swaps(A[i], A[i+1])) {
                    swap(A[i], A[i+1]);
                    swap(A[0], A[1]);
                } else break;
            }
        }
    } else assert(0);

    assert(K <= M);
    return K;
}


# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 2 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 620 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 620 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -