Submission #298183

#TimeUsernameProblemLanguageResultExecution timeMemory
298183tmwilliamlin168Fun Tour (APIO20_fun)C++14
100 / 100
489 ms21940 KiB
#include "fun.h" #include <bits/stdc++.h> using namespace std; vector<int> createFunTour(int n, int q) { vector<int> d(n), ans, e; array<int, 2> c{n+1}; for(int i=0, s; i<n; ++i) { s=attractionsBehind(0, i); if(s>n/2) c=min(array<int, 2>{s, i}, c); } for(int i=0; i<n; ++i) { d[i]=hoursRequired(c[1], i); if(d[i]==1) e.push_back(i); } vector<vector<int>> d2(e.size()-1), f(3); for(int i=0; i<e.size()-1; ++i) for(int j=0; j<n; ++j) d2[i].push_back(hoursRequired(e[i], j)); for(int i=0; i<n; ++i) { if(i==c[1]) continue; int j=0; while(j<e.size()-1&&d2[j][i]>d[i]) ++j; f[j].push_back(i); } for(int i=0; i<e.size(); ++i) { sort(f[i].begin(), f[i].end(), [&](const int &i, const int &j) { return d[i]<d[j]; }); } int p[3]={0, 1, 2}, l=-1; while(1) { sort(p, p+3, [&](const int &i, const int &j) { return f[i].size()>f[j].size(); }); if(f[p[0]].size()<f[p[1]].size()+f[p[2]].size()) { sort(p, p+3, [&](const int &i, const int &j) { return d[f[i].back()]>d[f[j].back()]; }); int i=0; if(p[i]==l) ++i; ans.push_back(f[p[i]].back()); f[p[i]].pop_back(); l=p[i]; } else break; } f[p[1]].insert(f[p[1]].end(), f[p[2]].begin(), f[p[2]].end()); sort(f[p[1]].begin(), f[p[1]].end(), [&](const int &i, const int &j) { return d[i]<d[j]; }); l=l==p[0]; if(f[p[0]].size()&&f[p[1]].size()&&(ans.size()>1&&d[f[p[l]].back()]>d[ans[ans.size()-2]]||ans.size()&&d[f[p[l^1]].back()]>d[ans.back()])) l^=1; while(f[p[l]].size()) { ans.push_back(f[p[l]].back()); f[p[l]].pop_back(); l^=1; } ans.push_back(c[1]); return ans; }

Compilation message (stderr)

fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:19:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |  for(int i=0; i<e.size()-1; ++i)
      |               ~^~~~~~~~~~~
fun.cpp:26:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |   while(j<e.size()-1&&d2[j][i]>d[i])
      |         ~^~~~~~~~~~~
fun.cpp:30:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |  for(int i=0; i<e.size(); ++i) {
      |               ~^~~~~~~~~
fun.cpp:58:50: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   58 |  if(f[p[0]].size()&&f[p[1]].size()&&(ans.size()>1&&d[f[p[l]].back()]>d[ans[ans.size()-2]]||ans.size()&&d[f[p[l^1]].back()]>d[ans.back()]))
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...