이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//by szh
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}
#include "fun.h"
const int maxn = 1e5+10;
int n;
int val[maxn];
int dis[maxn];
vector <int> rt;
vector <pii> node[3];
vector <int> solve(vector<vector <pii> > nodee) {
vector <int> ans;
int cur = 0;
if (SZ(nodee[1])>SZ(nodee[0])) cur = 1;
while (!nodee[cur].empty()) {
ans.pb(nodee[cur].back().se);
nodee[cur].pop_back();
cur ^= 1;
}
return ans;
}
std::vector<int> createFunTour(int N, int Q) {
if (N==2) {
vector <int> tmp = {0,1};
return tmp;
}
int cent = -1;
n = N;
rep(i,0,n) {
val[i] = attractionsBehind(0,i);
if (val[i]*2>=N)
if (cent==-1 or val[i]<val[cent]) cent=i;
}
rep(i,0,n) if (cent!=i) {
dis[i] = hoursRequired(cent,i);
if (dis[i]==1) rt.pb(i);
}
rep(i,0,n) if (cent!=i) {
bool ok = false;
rep(j,0,SZ(rt)-1) if (hoursRequired(rt[j],i)+1==dis[i]) {
ok = true;
node[j].pb({dis[i],i});
}
if (ok==false) node[SZ(rt)-1].pb({dis[i],i});
}
sort(ALL(node[0]));sort(ALL(node[1]));
vector <int> ans;
if (SZ(rt)==2) {
ans = solve({node[0],node[1]});
}
else {
sort(ALL(node[2]));
bool ok = false;
rep(i,0,3) {
if (SZ(node[i])==SZ(node[0])+SZ(node[1])+SZ(node[2]) - SZ(node[i])) {
vector <pii> small;
rep(j,0,3) if (i!=j) while (!node[j].empty()) small.pb(node[j].back()),node[j].pop_back();
sort(ALL(small));
vector <int> hmm = solve({small,node[i]});
for (auto it:hmm) ans.pb(it);
ok = true;
break;
}
}
if (ok==false) while (1) {
int tmp = 0;
if (node[1].back().fi > node[tmp].back().fi) tmp = 1;
if (node[2].back().fi > node[tmp].back().fi) tmp = 2;
ans.pb(node[tmp].back().se);
node[tmp].pop_back();
bool ok = false;
rep(i,0,3) {
if (SZ(node[i])==SZ(node[0])+SZ(node[1])+SZ(node[2]) - SZ(node[i])) {
vector <pii> small;
rep(j,0,3) if (i!=j) while (!node[j].empty()) small.pb(node[j].back()),node[j].pop_back();
sort(ALL(small));
if (small.back().fi>ans.back()) {
ans.pb(small.back().se);
small.pop_back();
}
vector <int> hmm = solve({small,node[i]});
for (auto it:hmm) ans.pb(it);
ok = true;
break;
}
}
if (ok) break;
}
}
ans.pb(cent);
return ans;
}
# | 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... |