이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#define DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}
// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
public:
template<typename T>
_Debug& operator,(T val) {
cout << val << endl;
return *this;
}
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif
// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back
// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;
// ---------- END OF TEMPLATE ----------
#include "fun.h"
int dist[100000];
int same(int a,int b) {
return hoursRequired(a,b) < dist[a]+dist[b];
}
vpii cc[3];
int p[3];
vector<int> createFunTour(int N,int Q) {
if (N == 2) {
vi v;
v.pb(0),v.pb(1);
return v;
}
int i;
int b = N,c = 0,n = 0;
for (i = 1; i < N; i++) {
int s = attractionsBehind(0,i);
if ((2*s >= N) && (s < b)) b = s,c = i;
}
for (i = 0; i < N; i++) dist[i] = (c == i) ? 0:hoursRequired(c,i);
for (i = 0; i < N; i++) {
if (dist[i] == 1) cc[n++].pb(mp(dist[i],i));
}
for (i = 0; i < N; i++) {
if (dist[i] >= 2) {
int x = rand() % n;
if (same(cc[x][0].second,i)) cc[x].pb(mp(dist[i],i));
else {
if (n == 2) cc[!x].pb(mp(dist[i],i));
else if (same(cc[(x+1) % 3][0].second,i)) cc[(x+1) % 3].pb(mp(dist[i],i));
else cc[(x+2) % 3].pb(mp(dist[i],i));
}
}
}
b = 0;
vi ans;
for (i = 0; i < n; i++) {
sort(cc[i].begin(),cc[i].end(),greater<pii>());
if (cc[i].size() < cc[b].size()) b = i;
}
cc[b].pb(mp(0,c));
if (n == 2) {
int uc = (cc[1].size() > cc[0].size());
for (i = 0; i < N; i++) ans.pb(cc[uc][p[uc]].second),p[uc]++,uc ^= 1;
return ans;
}
else {
int uc = 0;
for (i = 0; i < n; i++) {
if (cc[i][0] > cc[uc][0]) uc = i;
}
for (i = 0; i < N; i++) {
ans.pb(cc[uc][p[uc]].second),p[uc]++;
int a = (p[(uc+1) % 3] < cc[(uc+1) % 3].size()) ? cc[(uc+1) % 3][p[(uc+1) % 3]].first:-1;
int b = (p[(uc+2) % 3] < cc[(uc+2) % 3].size()) ? cc[(uc+2) % 3][p[(uc+2) % 3]].first:-1;
if ((2*(cc[(uc+1) % 3].size()-p[(uc+1) % 3]) >= N-i-1) && (b <= dist[ans.back()])) uc = (uc+1) % 3;
else if ((2*(cc[(uc+2) % 3].size()-p[(uc+2) % 3]) >= N-i-1) && (a <= dist[ans.back()])) uc = (uc+2) % 3;
else if (a > b) uc = (uc+1) % 3;
else uc = (uc+2) % 3;
}
return ans;
}
}
컴파일 시 표준 에러 (stderr) 메시지
fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:113:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
113 | int a = (p[(uc+1) % 3] < cc[(uc+1) % 3].size()) ? cc[(uc+1) % 3][p[(uc+1) % 3]].first:-1;
| ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
fun.cpp:114:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
114 | int b = (p[(uc+2) % 3] < cc[(uc+2) % 3].size()) ? cc[(uc+2) % 3][p[(uc+2) % 3]].first:-1;
| ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
fun.cpp:115:58: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
115 | if ((2*(cc[(uc+1) % 3].size()-p[(uc+1) % 3]) >= N-i-1) && (b <= dist[ans.back()])) uc = (uc+1) % 3;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
fun.cpp:116:63: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
116 | else if ((2*(cc[(uc+2) % 3].size()-p[(uc+2) % 3]) >= N-i-1) && (a <= dist[ans.back()])) uc = (uc+2) % 3;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
# | 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... |