제출 #1085401

#제출 시각아이디문제언어결과실행 시간메모리
1085401guagua0407정렬하기 (IOI15_sorting)C++17
20 / 100
1 ms604 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 #define all(x) x.begin(),x.end() #define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,m; vector<int> p; vector<int> x,y; vector<pair<int,int>> vec; bool check(int mid){ vector<int> pp=p; for(int i=0;i<mid;i++){ swap(pp[x[i]],pp[y[i]]); } vector<bool> vis(n); vec.clear(); for(int i=0;i<n;i++){ if(vis[i]) continue; int cur=i; while(!vis[cur]){ vis[cur]=true; cur=pp[cur]; if(cur!=i){ vec.push_back({i,cur}); } } } if((int)vec.size()<=mid) return true; else return false; } int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { n=N; m=M; p.resize(n); x.resize(m); y.resize(m); for(int i=0;i<n;i++){ p[i]=S[i]; } for(int i=0;i<m;i++){ x[i]=X[i]; y[i]=Y[i]; } int l=0,r=m; while(l<r){ int mid=(l+r)/2; if(check(mid)){ r=mid; } else{ l=mid+1; } } check(l); for(int i=0;i<(int)vec.size();i++){ P[i]=vec[i].f; Q[i]=vec[i].s; } return l; }
#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...