제출 #1030073

#제출 시각아이디문제언어결과실행 시간메모리
1030073_8_8_즐거운 행로 (APIO20_fun)C++17
0 / 100
0 ms604 KiB
#include "fun.h" #include <bits/stdc++.h> using namespace std; int n,q; int find_cen(){ vector<pair<int,int>> a; for(int i = 1;i < n;i++){ int s = attractionsBehind(0,i); if(s >= n / 2){ a.emplace_back(s,i); } } sort(a.begin(),a.end()); return a[0].second; } const int N = 1e5 + 12; int val[N]; vector<int> createFunTour(int nn, int qq) { n = nn;q = qq; int c = find_cen(); array<int,3> ver = {-1,-1,-1}; array<vector<pair<int,int>>,3> vec; for(int i = 0;i < n;i++){ if(i == c) continue; val[i] = hoursRequired(c,i); if(val[i] == 1){ for(int j = 0;j < 3;j++){ if(ver[j] == -1){ ver[j] = i; break; } } } } for(int i = 0;i < n;i++){ if(i == c) continue; if(val[i] == 1){ if(i == ver[0]){ vec[0].push_back({1,i}); }else if(i == ver[1]){ vec[1].push_back({1,i}); }else{ vec[2].push_back({1,i}); } continue; } int _ = -1; for(int k = 0;k < 2;k++){ if(val[i] - 1 == hoursRequired(i,ver[k])){ _=k; break; } } if(_ == -1) _ = 2; vec[_].push_back({val[i],i}); } int lst = -1; for(int i = 0;i < 3;i++){ sort(vec[i].begin(),vec[i].end()); } vector<int> res; while(true){ int _x = (int)vec[0].size(),_y = (int)vec[1].size(),_z = (int)vec[2].size(); if(_x == _y + _z || _y == _x + _z || _z == _x + _z){ break; } pair<int,int> mx = {-1,-1}; int id = -1; auto upd = [&](vector<pair<int,int>> &a,int j){ if(j != lst){ pair<int,int> nv = make_pair(a.back().first,(int)a.size()); if(nv > mx){ mx = nv; id = j; } } }; auto del = [&](vector<pair<int,int>> &x){ res.push_back(x.back().second); x.pop_back(); }; for(int i = 0;i < 3;i++){ upd(vec[i],i); } lst = id; del(vec[id]); } vector<int> X,Y; vector<pair<int,int>> bff; for(int i = 0;i < 3;i++){ bff.push_back({(int)vec[i].size(),i}); } sort(bff.begin(),bff.end()); bool ok = false; for(int i = 0;i < 3;i++){ int j = bff[i].second; if(i < 2){ if(lst == j) ok = 1; for(auto f:vec[j]){ X.push_back(f.second); } }else{ for(auto f:vec[j]){ Y.push_back(f.second); } } } if(ok){ X.swap(Y); } reverse(X.begin(),X.end()); reverse(Y.begin(),Y.end()); assert((int)X.size() == (int)Y.size()); for(int i = 0;i < (int)X.size();i++){ res.push_back(X[i]); res.push_back(Y[i]); } res.push_back(c); return res; }
#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...