이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "fun.h"
#include <bits/stdc++.h>
#define PB push_back
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define i2 array<int,2>
using namespace std;
const int oo = 2e9;
const int N = 100100;
vector<int> ans, chld;
vector<i2> elms[3];
int dst[N];
void srt(){
if (sz(elms[0]) < sz(elms[1])) swap(elms[0], elms[1]);
if (sz(chld) == 3 && sz(elms[1]) < sz(elms[2])) swap(elms[1], elms[2]);
if (sz(elms[0]) < sz(elms[1])) swap(elms[0], elms[1]);
}
vector<int> createFunTour(int n, int Q) {
if (n == 2) return {0, 1};
int cen = -1, mn = oo, hlf = (n + 1) / 2;
for (int i = 0; i < n; i++){
int now = attractionsBehind(0, i);
if (now < mn && now >= hlf){
mn = now;
cen = i;
}
}
chld.clear();
for (int i = 0; i < n; i++){
if (i == cen) continue;
int now = hoursRequired(cen, i);
dst[i] = now;
if (now == 1)
chld.PB(i);
}
for (int i = 0; i < n; i++){
if (i == cen) continue;
int who = 0;
for (int it = 1; it < sz(chld); it++){
int now = hoursRequired(chld[it], i);
if (now + 1 == dst[i]){
who = it;
break;
}
}
elms[who].PB({dst[i], i});
}
for (int i = 0; i < sz(chld); i++){
sort(all(elms[i]));
}
srt();
ans.clear();
if (sz(chld) == 3 && sz(elms[0]) >= sz(elms[1]) + sz(elms[2])){
chld.pop_back();
for (i2 cr : elms[2])
elms[1].PB(cr);
sort(all(elms[1]));
}
if (sz(chld) == 3){
int lst = -1;
while (1){
int bst = -1, id = -1;
for (int it = 0; it < 3; it++){
if (it == lst) continue;
if (elms[it].back()[0] > bst){
bst = elms[it].back()[0];
id = it;
}
}
ans.PB(elms[id].back()[1]);
elms[id].pop_back();
lst = id;
if (sz(elms[0]) == sz(elms[1]) + sz(elms[2])) break;
if (sz(elms[1]) == sz(elms[0]) + sz(elms[2])) break;
if (sz(elms[2]) == sz(elms[0]) + sz(elms[1])) break;
}
int mx = -1, who = -1;
for (int it = 0; it < 3; it++)
if (sz(elms[it]) > mx){
mx = sz(elms[it]);
who = it;
}
int bst = -1, id = -1;
for (int it = 0; it < 3; it++){
if (it == lst || sz(elms[it]) == 0) continue;
if (elms[it].back()[0] > bst){
bst = elms[it].back()[0];
id = it;
}
}
ans.PB(elms[id].back()[1]);
elms[id].pop_back();
// srt();
swap(elms[0], elms[mx]);
if (sz(elms[1]) < sz(elms[2])) swap(elms[1], elms[2]);
for (i2 cr : elms[2])
elms[1].PB(cr);
sort(all(elms[1]));
if (sz(elms[0]) < sz(elms[1])) swap(elms[1], elms[0]);
while (sz(elms[1]) > 0){
ans.PB(elms[0].back()[1]);
ans.PB(elms[1].back()[1]);
elms[0].pop_back();
elms[1].pop_back();
}
if (sz(elms[0]) > 0)
ans.PB(elms[0][0][1]);
} else {
while (sz(elms[1]) > 0){
ans.PB(elms[0].back()[1]);
ans.PB(elms[1].back()[1]);
elms[0].pop_back();
elms[1].pop_back();
}
if (sz(elms[0]) > 0)
ans.PB(elms[0][0][1]);
}
ans.PB(cen);
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:106:22: warning: variable 'who' set but not used [-Wunused-but-set-variable]
106 | int mx = -1, who = -1;
| ^~~
# | 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... |