# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
594608 | 2022-07-12T17:48:05 Z | davi_bart | Sorting (IOI15_sorting) | C++14 | 1 ms | 340 KB |
#pragma GCC optimize("O3") #include <bits/stdc++.h> #include "sorting.h" using namespace std; #define ll long long // #define int ll #define fi first #define se second #define ld long double #define pb push_back mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int N; vector<int> v; vector<int> ini; vector<pair<int, int>> scambi; vector<bool> vis(200010); void dfs(int pos, int ini) { vis[pos] = 1; scambi.pb({pos, v[pos]}); if (v[pos] == ini) return; dfs(v[pos], ini); } int findSwapPairs(int N, int S[], int M, int P[], int Q[], int X[], int Y[]) { ::N = N; for (int i = 0; i < N; i++) v.pb(S[i]); ini = v; int ans = 0; int l = 0, r = N + 2; while (l < r) { int m = (l + r) / 2; v = ini; fill(vis.begin(), vis.begin() + N + 10, 0); scambi.clear(); for (int i = 0; i < m; i++) { swap(v[P[i]], v[Q[i]]); } for (int j = 0; j < N; j++) { if (vis[j] || v[j] == j) continue; dfs(v[j], j); } if (scambi.size() <= m) r = m; else l = m + 1; } ans = l; v = ini; fill(vis.begin(), vis.begin() + N + 10, 0); scambi.clear(); for (int i = 0; i < l; i++) { swap(v[P[i]], v[Q[i]]); } for (int j = 0; j < N; j++) { if (vis[j] || v[j] == j) continue; dfs(v[j], j); } v = ini; vector<int> pos(N); for (int i = 0; i < N; i++) { pos[v[i]] = i; } for (int i = 0; i < ans; i++) { swap(v[P[i]], v[Q[i]]); pos[v[P[i]]] = Q[i]; pos[v[Q[i]]] = P[i]; if (i >= scambi.size()) { X[i] = 0; Y[i] = 0; continue; } X[i] = pos[scambi[i].fi]; Y[i] = pos[scambi[i].se]; // int k = pos[v[X[i]]]; pos[v[X[i]]] = Y[i]; pos[v[Y[i]]] = X[i]; swap(v[X[i]], v[Y[i]]); // swap(pos[v[X[i]]], pos[v[Y[i]]]); } return ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 224 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 224 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 340 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 0 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Incorrect | 1 ms | 340 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 224 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 340 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 0 ms | 340 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Incorrect | 1 ms | 340 KB | Output isn't correct |
15 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |