# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
426853 | ollel | Sorting (IOI15_sorting) | C++17 | 2 ms | 332 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 <iostream>
using namespace std;
#define rep(i,a,b) for(int i = a; i < b; i++)
#define pb push_back
#define lso(x) x&(-x)
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define rep(i,a,b) for(int i = a; i < b; i++)
#define pb push_back
#define lso(x) x&(-x)
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
int findSwapPairsS(int n, int S[], int M, int X[], int Y[], int P[], int Q[]) {
vi to(n), from(n);
rep(i,0,n) to[i] = S[i];
rep(i,0,n) from[S[i]] = i;
int r = 0;
rep(i, 0, n) if (S[i] == 0) {
swap(S[i], S[0]);
P[r] = 0;
Q[r] = i;
swap(S[0], S[1]);
r++;
}
rep(i, 0, n) if (S[i] == 1) {
swap(S[i], S[0]);
P[r] = 0;
Q[r] = 1;
swap(S[0], S[1]);
r++;
}
rep(i,2,n) {
while (S[i] != i) {
int nw = S[S[i]];
P[r] = i; Q[r] = S[i];
swap(S[i], S[S[i]]);
swap(S[0], S[1]);
r++;
}
}
if (S[0] != 0) {
P[r] = Q[r] = 0;
r++;
}
return r;
}
int findSwapPairs(int n, int S[], int M, int X[], int Y[], int P[], int Q[]) {
if (Y[0] == 1) return findSwapPairsS(n, S, M, X, Y, P, Q);
vi to(n), from(n);
rep(i,0,n) to[i] = S[i];
rep(i,0,n) from[S[i]] = i;
int r = 0;
rep(i,0,n) {
while (S[i] != i) {
int nw = S[S[i]];
P[r] = i; Q[r] = S[i];
swap(S[i], S[S[i]]);
r++;
}
}
return r;
}
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... |