# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
752800 | 2023-06-03T21:30:58 Z | jampm | 정렬하기 (IOI15_sorting) | C++17 | 1 ms | 340 KB |
#include "sorting.h" #include <bits/stdc++.h> using namespace std; const int LOGN = 30; int count_cycles(vector<int> & V, int N = 0) { N = (int)V.size(); int ans = 0; vector<bool> vis(N, false); for (int i = 0; i < N; i++) { if (vis[i]) continue; ans++; for (int j = V[i]; i != j; j = V[j]) vis[j] = true; } return ans; } int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { int ans = 0; for (int k = LOGN; k >= 0; k--) { if (ans + (1<<k) > M) continue; vector<int> V(N); for (int i = 0; i < N; i++) V[i] = S[i]; for (int i = 0; i < ans + (1<<k); i++) { swap(V[X[i]], V[Y[i]]); } if (count_cycles(V) + ans + (1<<k) < N) ans += (1<<k); } ans++; vector<int> V(N); for (int i = 0; i < N; i++) V[i] = S[i]; for (int i = 0; i < ans; i++) { swap(V[X[i]], V[Y[i]]); } vector<bool> vis(N, false); //tengo que ver bien el orden de los swaps vector<pair<int, int>> Ans(N - count_cycles(V)); int cnt = 0; for (int i = 0; i < N; i++) { if (vis[i]) continue; for (int j = V[i]; i != j; j = V[j]) { vis[j] = true; Ans[cnt++] = {j, V[j]}; } } random_shuffle(Ans.begin(), Ans.end()); for (int i = 0; i < Ans.size(); i++) { P[i] = Ans[i].first; Q[i] = Ans[i].second; } return ans; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 304 KB | Output is correct |
5 | Incorrect | 1 ms | 212 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 304 KB | Output is correct |
5 | Incorrect | 1 ms | 212 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Incorrect | 1 ms | 212 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 304 KB | Output is correct |
5 | Incorrect | 1 ms | 212 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |