Submission #432904

#TimeUsernameProblemLanguageResultExecution timeMemory
432904balbit정렬하기 (IOI15_sorting)C++14
0 / 100
2 ms588 KiB
#include "sorting.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int, int> #define f first #define s second #ifdef BALBIT #define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<"- ", _do(__VA_ARGS__) template<typename T> void _do( T && x) {cerr<<x<<endl;} template<typename T, typename ...S> void _do( T && x, S && ...y) {cerr<<x<<", "; _do(y...);} #else #define bug(...) #endif // BALBIT #define ALL(x) (x).begin(), (x).end() #define SZ(x) (int )((x).size()) #define pb push_back #define REP(i,n) for (int i = 0; i<n; ++i) #define REP1(i,n) for (int i = 1; i<=n; ++i) #define MX(a,b) a = max(a,b) #define MN(a,b) a = min(a,b) //signed main(){bug(1,2);} const int maxn = 2e5+5; bool seen[maxn]; int where[maxn]; int findSwapPairs(int n, int S[], int M, int X[], int Y[], int P[], int Q[]) { // int IT = 0; { int l = 0, r = M; while (l!=r) { int mid = (l+r)/2; vector<int> ts(n); REP(i,n) ts[i] = S[i]; for (int j = 0; j<mid; ++j) { swap(ts[X[j]], ts[Y[j]]); } memset(seen, 0, sizeof seen); int tt = n; REP(i,n) { if (!seen[i]) { --tt; for (int j = i; ; j = S[j]) { seen[j] = 1; if (S[j] == i) break; } } } if (tt <= mid) { r = mid; }else{ l = mid+1; } } bug(l); vector<int> ts(n); REP(i,n) ts[i] = S[i]; for (int j = 0; j<l; ++j) { swap(ts[X[j]], ts[Y[j]]); } int IT = 0; REP(i,n) where[S[i]] = i; for (int i = 0; i<n; ++i) { while (ts[i] != i) { { swap(where[S[X[IT]]], where[S[Y[IT]]]); swap(S[X[IT]], S[Y[IT]]); } int p1 = where[i], p2 = where[ts[i]]; P[IT] = p1; Q[IT] = p2; ++IT; { swap(where[S[p1]], where[S[p2]]); swap(S[p1], S[p2]); } swap(ts[i], ts[ts[i]]); bug(i, ts[i]); } } return IT; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...