# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
100614 | luciocf | Sorting (IOI15_sorting) | C++14 | 2 ms | 384 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "sorting.h"
using namespace std;
const int maxn = 2e5+10;
int pos[maxn];
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[])
{
for (int i = 0; i < N; i++)
{
if (S[i] != i) break;
if (i == N-1) return 0;
}
for (int i = 0; i < N; i++) pos[S[i]] = i;
if (Y[0] == 0)
{
for (int i = 0; i < N; i++)
{
int j = S[i];
P[i] = pos[i], Q[i] = i;
S[pos[i]] = j, S[i] = i;
pos[j] = pos[i], pos[i] = i;
}
return N;
}
pos[S[0]] = 1, pos[S[1]] = 0;
swap(S[0], S[1]);
int j = S[1];
P[0] = pos[0], Q[0] = 1;
S[pos[0]] = j, S[1] = 0;
pos[j] = pos[0], pos[0] = 1;
pos[S[0]] = 1, pos[S[1]] = 0;
swap(S[0], S[1]);
j = S[1];
P[1] = pos[1], Q[1] = 1;
S[pos[1]] = j, S[1] = 1;
pos[j] = pos[1], pos[1] = 1;
for (int i = 2; i < N; i++)
{
j = S[i];
P[i] = pos[i], Q[i] = i;
S[pos[i]] = j, S[i] = i;
pos[j] = pos[i], pos[i] = i;
}
if (N&1)
{
P[N] = 0, Q[N] = 0;
return N+1;
}
return N;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |