Submission #420244

# Submission time Handle Problem Language Result Execution time Memory
420244 2021-06-08T08:15:42 Z Aldas25 Sorting (IOI15_sorting) C++14
0 / 100
2 ms 332 KB
#include "sorting.h"
#include <bits/stdc++.h>

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define f first
#define s second
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;

const int MAXN = 200100;

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
    if (N == 1) return 0;
    int cnt = 0;
    swap(S[X[cnt]], S[Y[cnt]]);
    for (int i = N-1; i >= 0; i--) {
        if (i < 2) {
            //if (Y[0] == 0) break;

            P[cnt] = 0, Q[cnt] = 0;
            if (S[1] != 1) Q[cnt] = 1;
            cnt++;

            break;
        }

        if (S[i] == i) continue;
        for (int j = 0; j < i; j++) {
            if (S[j] == i) {
                P[cnt] = j;
                Q[cnt] = i;
                swap(S[i], S[j]);
                break;
            }
        }
        cnt++;
        swap(S[X[cnt]], S[Y[cnt]]);
    }
    return cnt;
}


Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:20:39: warning: unused parameter 'M' [-Wunused-parameter]
   20 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                   ~~~~^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -