Submission #898367

#TimeUsernameProblemLanguageResultExecution timeMemory
898367OAleksaFun Tour (APIO20_fun)C++14
26 / 100
312 ms524288 KiB
#include "fun.h" #include <bits/stdc++.h> #define f first #define s second using namespace std; vector<int> createFunTour(int N, int Q) { int n = N, q = Q; vector<int> ans(n); int d[n][n]; for (int i = 0;i < n;i++) { for (int j = 0;j < n;j++) { d[i][j] = hoursRequired(i, j); } } int mx = 0; for (int i = 0;i < n;i++) { for (int j = 0;j < n;j++) mx = max(mx, d[i][j]); } int p = -1, p1 = -1; for (int i = 0;i < n;i++) { int res = 0; for (int j = 0;j < n;j++) res = max(res, d[i][j]); if (res == mx) { for (int j = 0;j < n;j++) { if (d[i][j] == mx) p1 = j; } p = i; break; } } vector<int> vis(n); assert(p != -1 && p1 != -1); vis[p] = vis[p1] = 1; ans[0] = p; ans[1] = p1; for (int i = 2;i < n;i++) { int cur = 0, bst = 0; for (int j = 0;j < n;j++) { if (vis[j]) continue; if (d[p1][j] >= bst) { bst = d[p1][j]; cur = j; } } vis[cur] = 1; ans[i] = cur; p1 = cur; } return ans; } /* 7 400000 0 1 0 5 0 6 1 2 1 4 2 3 */

Compilation message (stderr)

fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:7:14: warning: unused variable 'q' [-Wunused-variable]
    7 |   int n = N, q = Q;
      |              ^
#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...