이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define TASK ""
#include "fun.h"
#define bit(x) (1LL << (x))
#define getbit(x, i) (((x) >> (i)) & 1)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
template <typename T1, typename T2> bool mini(T1 &a, T2 b) {
if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maxi(T1 &a, T2 b) {
if (a < b) {a = b; return true;} return false;
}
mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r) {
return l + rd() % (r - l + 1);
}
const int Nmax = 1e5 + 5;
const int oo = 1e9;
const long long ooo = 1e18;
const int mod = 1e9 + 7; // 998244353;
const long double pi = acos(-1);
#define asksz attractionsBehind
#define askdis hoursRequired
vector <int> s[10];
int comp[Nmax];
int sz[Nmax];
int d[Nmax];
int n,q;
vector<int> createFunTour(int N, int Q) {
n = N;
q = Q;
if (n == 2)
return vector <int> {0, 1};
int cen = 0;
int minsz = n;
for (int i = 1; i < n; i++) {
sz[i] = asksz(0, i);
if (2 * sz[i] >= n) {
if (mini(minsz, sz[i]))
cen = i;
}
}
vector <int> cand;
for (int i = 0; i < n; i++) {
d[i] = askdis(cen, i);
if (d[i] == 1)
cand.push_back(i);
}
assert(cand.size() > 1);
for (int i = 0; i < n; i++) if (i != cen) {
int comp = 2;
for (int j = 0; j < 2; j++)
if (askdis(cand[j], i) + 1 == d[i])
comp = j;
s[comp].push_back(i);
}
for (int i = 0; i < 3; i++) {
sort(ALL(s[i]), [](int i, int j) {
return d[i] < d[j];
});
// for (int x : s[i])
// cerr << x << " ";
// cerr << "\n";
}
vector <int> res;
if (cand.size() == 3) {
bool rep = true;
for (int i = 0; i < 3; i++)
for (int j = i + 1; j < 3; j++)
if (s[i].size() > s[j].size())
swap(s[i], s[j]);
if ((int) s[2].size() == (n >> 1))
rep = false;
int las = -1;
while (rep) {
for (int i = 0; i < 3; i++)
for (int j = i + 1; j < 3; j++) {
if (s[i].size() > s[j].size()) {
swap(s[i], s[j]);
if (las == i || las == j)
las ^= i ^ j;
}
}
if (s[0].size() + s[1].size() == s[2].size())
break;
int maxd = -1;
int mx = -1;
for (int i = 0; i < 3; i++) if (i != las && s[i].size()) {
if (maxi(maxd, d[s[i].back()]))
mx = i;
}
assert(mx >= 0);
res.push_back(s[mx].back());
las = mx;
// cerr << mx << " " << s[mx].back() << "\n";
s[mx].pop_back();
}
if (las != -1 && las != 2) {
if (s[las ^ 1].size()) {
int a = d[res.back()];
int b = d[s[las ^ 1].back()];
int c = d[s[2].back()];
int mx = max({a, b, c});
if (a < b && b == mx) {
res.push_back(s[las ^ 1].back());
s[las ^ 1].pop_back();
res.push_back(s[2].back());
s[2].pop_back();
las = 2;
}
}
}
for (int x : s[1])
s[0].push_back(x);
sort(ALL(s[0]), [](int i, int j) {
return d[i] < d[j];
});
s[1] = s[2];
if (las != 2)
swap(s[0], s[1]);
}
if (s[0].size() > s[1].size())
swap(s[0], s[1]);
if (s[1].size() > s[0].size()) {
res.push_back(s[1].back());
s[1].pop_back();
}
while (s[0].size()) {
for (int i = 0; i < 2; i++) {
res.push_back(s[i].back());
s[i].pop_back();
}
}
res.push_back(cen);
return res;
}
//#include "grader.cpp"
# | 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... |