이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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()
{
pair<int,int> mn = {1e9, -1};
for(int i = 0; i < n; i++)
{
int ret = attractionsBehind(0, i);
if(ret > n / 2) mn = min(mn, {ret, i});
}
return mn.s;
}
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;
}
컴파일 시 표준 에러 (stderr) 메시지
fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:76:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
76 | for(int i = 0; i < head.size(); i++)
| ~~^~~~~~~~~~~~~
fun.cpp:94:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
94 | for(int j = 0; j < head.size(); j++)
| ~~^~~~~~~~~~~~~
fun.cpp:88:17: warning: 'cur' may be used uninitialized in this function [-Wmaybe-uninitialized]
88 | 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... |