이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "fun.h"
#include<bits/stdc++.h>
#define ll int
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ld long double
#define sz(a) ((ll)(a).size())
using namespace std;
const ll maxn=100005;
ll dist(ll a, ll b) {return hoursRequired(a, b);}
ll subcnt(ll a, ll b) {return attractionsBehind(a, b);}
vector<int> createFunTour(int n, int Q)
{
ll g=0;
// findcentroid
{
ll cr=n;
for (ll j=1; j<n; j++)
{
ll x=subcnt(0, j);
if (x*2>=n && x<=cr)
g=j, cr=x;
}
}
vector <pll> dis;
vector <vector <pll>> branch;
for (ll i=0; i<n; i++)
if (i!=g)
{
dis.pb({dist(g, i), i});
if (dis.back().fi==1) branch.pb(vector <pll> {{1, i}}), dis.pop_back();
}
for (auto [d, i]:dis)
for (ll j=0; j<sz(branch); j++)
{
if (j+1==sz(branch)) branch[j].pb({d, i});
else if (dist(i, branch[j][0].se)+1==d) {branch[j].pb({d, i}); break;}
}
for (ll j=0; j<sz(branch); j++)
sort(branch[j].begin(), branch[j].end(), greater<pll>());
ll first=0;
vector <ll> tour;
if (sz(branch)==3)
{
// case 2
ll ptr[3]={}, last=-1, fat=0;
while (1)
{
// check
{
ll sum=0, ok=1;
for (ll i=0; i<3; i++)
sum+=sz(branch[i])-ptr[i];
for (ll i=0; i<3; i++)
if ((sz(branch[i])-ptr[i])*2>=sum) fat=i, ok=0;
if (!ok || !sum) break;
}
ll big=-1;
for (ll i=0; i<3; i++)
if (i!=last && ptr[i]<sz(branch[i]))
if (big==-1 || branch[big][ptr[big]].fi<branch[i][ptr[i]].fi)
big=i;
tour.pb(branch[big][ptr[big]].se), ptr[big]++, last=big;
}
vector <pll> b1, b2;
for (ll i=0; i<3; i++)
{
if (i==fat) b1.insert(b1.end(), branch[i].begin()+ptr[i], branch[i].end());
else b2.insert(b2.end(), branch[i].begin()+ptr[i], branch[i].end());
}
sort(b2.begin(), b2.end(), greater<pll>());
branch[0]=b1, branch[1]=b2;
if (last==fat) swap(branch[0], branch[1]);
}
else if (sz(branch[0])<sz(branch[1])) swap(branch[0], branch[1]);
if (sz(branch[0])==sz(branch[1]) && sz(branch[0]) && branch[0][0].fi<branch[1][0].fi) swap(branch[0], branch[1]);
for (ll ptr[2]={}, t=0; ptr[0]<sz(branch[0]) || ptr[1]<sz(branch[1]); ptr[t]++, t^=1)
tour.pb(branch[t][ptr[t]].se);
tour.pb(g); return tour;
}
컴파일 시 표준 에러 (stderr) 메시지
fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:46:8: warning: unused variable 'first' [-Wunused-variable]
46 | ll first=0;
| ^~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |