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"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define f first
#define s second
int n,q,mid;
int dist[100005];
vector<int> head,sz,ans;
vector<pair<int,int> > nh[3];
int fi_mid()
{
int base = 0, po, best, midbase = n / 2;
int ret = attractionsBehind(1, 0);
int more = max(ret, n - ret + 1);
best = more - midbase;
po = 0;
for(int i = 1; i < n; i++)
{
ret = attractionsBehind(base, i);
more = max(ret, n - ret + 1);
if(more - midbase < best)
{
best = more - midbase;
po = i;
}
}
return po;
}
void fi_dist()
{
for(int i = 0; i < n; i++)
{
if(i == mid) dist[i] = 0;
else dist[i] = hoursRequired(i, mid);
if(dist[i] == 1)
{
head.pb(i);
sz.pb(n - attractionsBehind(i, mid));
}
}
}
void fi_nh()
{
int ti = 0;
for(int i = 0; i < n; i++)
{
if(i == mid) continue;
if(dist[i] == 1)
{
nh[ti++].pb({dist[i], i});
continue;
}
int ask0 = attractionsBehind(i, head[0]);
int ask1 = attractionsBehind(i, head[1]);
if(ask0 != sz[0])
nh[0].pb({dist[i],i});
else if(ask1 != sz[1])
nh[1].pb({dist[i],i});
else
nh[2].pb({dist[i],i});
}
}
vector<int> createFunTour(int N, int Q)
{
n = N, q = Q;
mid = fi_mid();
// printf("p1\n");
fi_dist();
// printf("p2\n");
fi_nh();
// printf("p3\n");
// printf("%d %d\n",mid,head.size());
// for(int i = 0; i < nh[2].size(); i++)
// printf("%d ",nh[2][i].s);
// printf("\n");
int idx_last[3] = {-1,-1,-1};
int cur,last,best = 0;
for(int i = 0; i < head.size(); i++)
{
sort(nh[i].begin(),nh[i].end());
idx_last[i] = nh[i].size() - 1;
if(nh[i][idx_last[i]].f > best)
{
cur = i;
last = nh[i][idx_last[i]].s;
best = nh[i][idx_last[i]].f;
}
}
ans.pb(last);
idx_last[cur]--;
// printf("%d\n",last);
for(int i = 1; i < n - 1; i++)
{
best = 0;
int prev_cur = cur;
for(int j = 0; j < head.size(); j++)
{
if(j == prev_cur || idx_last[j] == -1) continue;
if(nh[j][idx_last[j]].f > best)
{
cur = j;
last = nh[j][idx_last[j]].s;
best = nh[j][idx_last[j]].f;
}
}
ans.pb(last);
// printf("%d\n",last);
idx_last[cur]--;
}
ans.pb(mid);
// printf("%d\n",mid);
return ans;
}
Compilation message (stderr)
fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:85:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
85 | for(int i = 0; i < head.size(); i++)
| ~~^~~~~~~~~~~~~
fun.cpp:103:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
103 | for(int j = 0; j < head.size(); j++)
| ~~^~~~~~~~~~~~~
fun.cpp:97:17: warning: 'cur' may be used uninitialized in this function [-Wmaybe-uninitialized]
97 | idx_last[cur]--;
| ~~~~~~~~~~~~^
# | 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... |