This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "fun.h"
#define wiwihorz
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse")
#pragma loop-opt(on)
#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define rrep(i, a, b) for(int i = b; i >= a; i --)
#define all(x) x.begin(), x.end()
#define ceil(a, b) ((a + b - 1) / (b))
#define ll long long int
#define lld long double
#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())
#define INF 2000000000
#define MOD 1000000007
#define eps (1e-9)
using namespace std;
#ifdef wiwihorz
#define print(a...)cerr<<"Line "<<__LINE__<<":",kout("["+string(#a)+"] = ", a)
void vprint(auto L,auto R){while(L<R)cerr<<*L<<" \n"[next(L) == R], ++L; }
void kout() { cerr << endl; }
template<class T1,class ... T2>void kout(T1 a,T2 ... e){cerr<<a<<" ",kout(e...);}
#else
#define print(...) 0
#define vprint(...) 0
#endif
vector<int> createFunTour(int N, int Q) {
if(N == 2) return {0, 1};
vector<int> sz(N, 0), dis(N, 0), id(N, -1), up;
vector<vector<int>> v(3, vector<int>());
int cen = 0, best = N, bad = -1;
rep(i, 1, N - 1) {
sz[i] = attractionsBehind(0, i);
if(sz[i] * 2 >= N && best >= sz[i]) {
cen = i, best = sz[i];
}
}
auto cmp = [&](int x, int y) {
if(dis[x] != dis[y]) return dis[x] > dis[y];
else return id[x] != bad;
};
rep(i, 0, N - 1) if(cen != i) {
dis[i] = hoursRequired(cen, i);
if(dis[i] == 1) up.push_back(i);
}
rep(i, 0, N - 1) if(i != cen) {
int L = hoursRequired(up[0], i);
int R = hoursRequired(up[1], i);
if(L + 1 == dis[i]) v[0].push_back(i), id[i] = 0;
else if(R + 1 == dis[i]) v[1].push_back(i), id[i] = 1;
else v[2].push_back(i), id[i] = 2;
}
vector<int> L, R, ans;
if(up.size() == 3) {
vector<int> piv(3, 0);
int a = v[0].size(), b = v[1].size(), c = v[2].size();
rep(i, 0, 2) sort(all(v[i]), cmp);
int pre = -1, cur = 0, tot = 0;
while(max({a - piv[0], b - piv[1], c - piv[2]})* 2 < a + b + c - tot) {
cur = -1;
rep(i, 0, 2) if(i != pre && piv[i] < v[i].size()) {
if(cur == -1 || dis[v[i][piv[i]]]
> dis[v[cur][piv[cur]]]) cur = i;
}
tot ++, pre = cur;
ans.push_back(v[cur][piv[cur] ++]);
}
rep(i, 1, 2) if(v[i].size() - piv[i]
> v[0].size() - piv[0]) {
swap(v[0], v[i]), swap(piv[0], piv[i]);
if(pre == i) pre = 0;
if(pre == 0) pre = i;
}
bad = pre;
rep(i, piv[0], v[0].size() - 1) L.push_back(v[0][i]);
rep(i, piv[1], v[1].size() - 1) R.push_back(v[1][i]);
rep(i, piv[2], v[2].size() - 1) R.push_back(v[2][i]);
sort(all(R), cmp);
if(dis[R[0]] > dis[L[0]] && id[R[0]] != pre) swap(L, R);
}
else L = v[0], R = v[1];
if(L.size() < R.size()) swap(L, R);
sort(all(R), cmp);
sort(all(L), cmp);
int l = 0, r = 0;
while(l < L.size()) {
if(l < L.size()) ans.push_back(L[l++]);
if(r < R.size()) ans.push_back(R[r++]);
}
ans.push_back(cen);
return ans;
}
Compilation message (stderr)
fun.cpp:6: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
6 | #pragma loop-opt(on)
|
fun.cpp:21:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
21 | void vprint(auto L,auto R){while(L<R)cerr<<*L<<" \n"[next(L) == R], ++L; }
| ^~~~
fun.cpp:21:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
21 | void vprint(auto L,auto R){while(L<R)cerr<<*L<<" \n"[next(L) == R], ++L; }
| ^~~~
fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:62:39: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | rep(i, 0, 2) if(i != pre && piv[i] < v[i].size()) {
fun.cpp:7:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
7 | #define rep(i, a, b) for(int i = a; i <= b; i ++)
......
76 | rep(i, piv[0], v[0].size() - 1) L.push_back(v[0][i]);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
fun.cpp:76:3: note: in expansion of macro 'rep'
76 | rep(i, piv[0], v[0].size() - 1) L.push_back(v[0][i]);
| ^~~
fun.cpp:7:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
7 | #define rep(i, a, b) for(int i = a; i <= b; i ++)
......
77 | rep(i, piv[1], v[1].size() - 1) R.push_back(v[1][i]);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
fun.cpp:77:3: note: in expansion of macro 'rep'
77 | rep(i, piv[1], v[1].size() - 1) R.push_back(v[1][i]);
| ^~~
fun.cpp:7:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
7 | #define rep(i, a, b) for(int i = a; i <= b; i ++)
......
78 | rep(i, piv[2], v[2].size() - 1) R.push_back(v[2][i]);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
fun.cpp:78:3: note: in expansion of macro 'rep'
78 | rep(i, piv[2], v[2].size() - 1) R.push_back(v[2][i]);
| ^~~
fun.cpp:87:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
87 | while(l < L.size()) {
| ~~^~~~~~~~~~
fun.cpp:88:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | if(l < L.size()) ans.push_back(L[l++]);
| ~~^~~~~~~~~~
fun.cpp:89:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
89 | if(r < R.size()) ans.push_back(R[r++]);
| ~~^~~~~~~~~~
# | 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... |