# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
170914 | socho | Sorting (IOI15_sorting) | C++14 | 53 ms | 632 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 "sorting.h"
#include "bits/stdc++.h"
using namespace std;
const int MXN = 200005;
int n, m;
int seq[MXN];
vector<pair<int, int> > plan;
vector<pair<int, int> > ans;
bool works(int sw) {
// cout << "try: " << sw << endl;
ans.clear();
int nsw[n];
for (int i=0; i<n; i++) nsw[i] = seq[i];
int where[n];
for (int i=0; i<sw; i++) {
int a = plan[i].first, b = plan[i].second;
swap(nsw[a], nsw[b]);
}
for (int i=0; i<n; i++) {
// cout << nsw[i] << ' ';
where[nsw[i]] = i;
}
// cout << endl;
int need = 0;
for (int i=0; i<n; i++) {
if (nsw[i] == i) continue;
need++;
int ati = nsw[i];
int whei = where[i];
where[ati] = whei;
where[i] = i;
nsw[i] = i;
nsw[whei] = ati;
ans.push_back(make_pair(i, whei));
}
// cout << "req: " << need << " have: " << sw << endl;
// if (sw == 3) return true;
return need <= sw;
}
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
n = N;
m = M;
for (int i=0; i<n; i++) seq[i] = S[i];
for (int i=0; i<m; i++) {
plan.push_back(make_pair(X[i], Y[i]));
}
for (int j=0; j<=M; j++) {
if (works(j)) {
for (int i=0; i<j; i++) {
if (i < ans.size()) {
P[i] = ans[i].first;
Q[i] = ans[i].second;
}
else {
P[i] = 0;
Q[i] = 0;
}
}
return j;
}
}
}
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... |