이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "fun.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6 + 10;
int sub[maxn], dis[maxn];
bool cmp(int a, int b)
{
return dis[a] < dis[b];
}
vector<int> createFunTour(int N, int Q)
{
for (int i = 0; i < N; i ++)
sub[i] = attractionsBehind(0, i);
int centroid = 0;
for (int i = 0; i < N; i ++)
{
if (sub[i] >= (N + 1) / 2 && sub[i] < sub[centroid])
centroid = i;
}
for (int i = 0; i < N; i ++)
dis[i] = hoursRequired(centroid, i);
vector < int > cp[3];
int p[3];
p[0] = p[1] = p[2] = -1;
for (int i = 0; i < N; i ++)
{
if (dis[i] == 1)
{
if (p[0] == -1)
p[0] = i;
else if (p[1] == -1)
p[1] = i;
else
p[2] = i;
}
}
for (int i = 0; i < N; i ++)
{
if (i == centroid)
continue;
if (i == p[0])
cp[0].push_back(i);
else if (i == p[1])
cp[1].push_back(i);
else if (i == p[2])
cp[2].push_back(i);
else
{
if (hoursRequired(p[0], i) + 1 == dis[i])
cp[0].push_back(i);
else if (hoursRequired(p[1], i) + 1 == dis[i])
cp[1].push_back(i);
else
cp[2].push_back(i);
}
}
/**for (int v : cp[0])
cout << v << " ";
cout << endl;
for (int v : cp[1])
cout << v << " ";
cout << endl;
for (int v : cp[2])
cout << v << " ";
cout << endl;*/
if (cp[0].size() < cp[1].size())
{
swap(p[0], p[1]);
swap(cp[0], cp[1]);
}
if (cp[0].size() < cp[2].size())
{
swap(p[0], p[2]);
swap(cp[0], cp[2]);
}
if (cp[1].size() < cp[2].size())
{
swap(p[1], p[2]);
swap(cp[1], cp[2]);
}
sort(cp[0].begin(), cp[0].end(), cmp);
sort(cp[1].begin(), cp[1].end(), cmp);
sort(cp[2].begin(), cp[2].end(), cmp);
vector < int > ans;
int last = -1, inside = 0;
if (p[2] == -1)
{
while(cp[1].size() > 0)
{
ans.push_back(cp[0].back());
ans.push_back(cp[1].back());
cp[0].pop_back();
cp[1].pop_back();
}
if (!cp[0].empty())
ans.push_back(cp[0].back());
}
else
{
int big = -1;
if (cp[0].size() > cp[1].size() + cp[2].size())
{
inside = 1;
cp[2].insert(cp[2].begin(), centroid);
}
while(true)
{
if (cp[0].size() == 0 || cp[1].size() == 0 || cp[2].size() == 0)
break;
if (cp[0].size() == cp[1].size() + cp[2].size())
{
big = 0;
break;
}
if (cp[1].size() == cp[0].size() + cp[2].size())
{
big = 1;
break;
}
if (cp[2].size() == cp[0].size() + cp[1].size())
{
big = 2;
break;
}
int cur = -1;
if (last != 0 && (cur == -1 || dis[cp[0].back()] > dis[cp[cur].back()]))
cur = 0;
if (last != 1 && (cur == -1 || dis[cp[1].back()] > dis[cp[cur].back()]))
cur = 1;
if (last != 2 && (cur == -1 || dis[cp[2].back()] > dis[cp[cur].back()]))
cur = 2;
ans.push_back(cp[cur].back());
cp[cur].pop_back();
last = cur;
}
if (cp[0].size() == 0 || cp[1].size() == 0 || cp[2].size() == 0)
{
if (cp[0].size() == 0)
swap(cp[0], cp[2]);
else if (cp[1].size() == 0)
swap(cp[1], cp[2]);
if (dis[cp[0].back()] < dis[cp[1].back()])
swap(cp[0], cp[1]);
while(cp[1].size() > 0)
{
ans.push_back(cp[0].back());
ans.push_back(cp[1].back());
cp[0].pop_back();
cp[1].pop_back();
}
if (!cp[0].empty())
ans.push_back(cp[0].back());
}
else
{
vector < int > sm;
for (int i = 0; i < 3; i ++)
{
if (i != big)
sm.push_back(i);
}
int v = sm[0], u = sm[1];
if (v == last)
v = sm[1], u = sm[0];
if (dis[cp[v].back()] > dis[cp[u].back()])
last = big;
while(!cp[v].empty())
{
cp[u].push_back(cp[v].back());
cp[v].pop_back();
}
sort(cp[u].begin(), cp[u].end(), cmp);
while(ans.size() < N - 1 + inside)
{
if (last == big)
{
ans.push_back(cp[u].back());
cp[u].pop_back();
last = u;
}
else
{
ans.push_back(cp[big].back());
cp[big].pop_back();
last = big;
}
}
}
}
if (inside == 0)
ans.push_back(centroid);
/*cout << "tour" << endl;
for (int v : ans)
cout << v << " ";
cout << endl;*/
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:197:30: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
197 | while(ans.size() < N - 1 + inside)
| ~~~~~~~~~~~^~~~~~~~~~~~~~~~
# | 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... |