제출 #1121368

#제출 시각아이디문제언어결과실행 시간메모리
1121368PagodePaivaSwap (BOI16_swap)C++17
21 / 100
1066 ms11860 KiB
#include<bits/stdc++.h> using namespace std; const int N = 200010; vector <int> v[N]; int p[N]; int mark[N]; vector <int> g[N]; int mark2[N]; int matching[N]; int off[N]; bool kuhn(int v){ if(mark2[v]){ return false; } mark2[v] = true; for(auto x : g[v]){ if(off[x]) continue; if(matching[x] == -1){ matching[x] = v; return true; } if(kuhn(matching[x])){ matching[x] = v; return true; } } return false; } int main(){ int n; cin >> n; for(int i = 1;i <= n;i++){ cin >> p[i]; v[i].push_back(p[i]); } for(int i = 2;i <= n;i++){ set <int> s; for(auto x : v[i]){ s.insert(x); } for(auto x : v[i/2]){ s.insert(x); } v[i/2].clear(); v[i].clear(); for(auto x : s){ v[i/2].push_back(x); v[i].push_back(x); } } for(int i = 1;i <= n;i++){ for(auto x : v[i]){ g[x+n].push_back(i); g[i].push_back(x+n); } } for(int i = 1;i <= 2*n;i++){ sort(g[i].begin(), g[i].end()); } vector <pair <int, int>> res; for(int i = 1;i <= n;i++){ for(auto x : g[i]){ if(off[x]) continue; off[i] = 1; off[x] = 1; memset(matching, -1, sizeof matching); for(int i = 1;i <= n;i++){ if(off[i]) continue; memset(mark2, 0, sizeof mark2); kuhn(i); } bool aux = true; for(int i = n+1;i <= 2*n;i++){ if(off[i]) continue; if(matching[i] == -1) aux = false; } if(aux){ res.push_back({i, x}); break; } off[i] = 0; off[x] = 0; } } for(auto x : res){ cout << x.second-n << ' '; } cout << '\n'; return 0; }
#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...