Submission #1020762

#TimeUsernameProblemLanguageResultExecution timeMemory
1020762mansurRoller Coaster Railroad (IOI16_railroad)C++17
Compilation error
0 ms0 KiB
#include "railroad.h" #include <bits/stdc++.h> using namespace std; #define rall(s) s.rbegin(), s.rend() #define all(s) s.begin(), s.end() #define sz(s) (int)s.size() #define s second #define f first using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; const ll inf = 1e18, N = 1e6; vector<int> ord, was(N), g[N]; void dfs(int u) { was[u] = 1; for (int to: g[u]) { if (!was[to]) dfs(to); } ord.push_back(u); } long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) { int n = sz(s); if (n <= 16) { ll dp[1 << n][n]; for (int msk = 0; msk < (1 << n); msk++) { for (int i = 0; i < n; i++) { dp[msk][i] = inf; } } for (int i = 0; i < n; i++) dp[1 << i][i] = 0; for (int msk = 1; msk < (1 << n); msk++) { for (int i = 0; i < n; i++) { if (msk >> i & 1) { for (int j = 0; j < n; j++) { if (msk >> j & 1) continue; int msk1 = msk + (1 << j); dp[msk1][j] = min(dp[msk1][j], dp[msk][i] + max(0, t[i] - s[j])); } } } } ll ans = inf; for (int i = 0; i < n; i++) ans = min(ans, dp[(1 << n) - 1][i]); return ans; } vector<pii> a; for (int i = 0; i < n; i++) a.push_back({t[i], s[i]}); sort(all(s)); for (int i = 0; i < n; i++) { g[i + n].push_back(i); if (i) g[i + n].push_back(i + n - 1); int p = upper_bound(all(a), {s[i], 0}) - a.begin() - 1; if (p >= 0) g[p + n - 1].push_back(i); } for (int i = 0; i < n; i++) { if (!was[i]) dfs(i); } reverse(all(ord)); int lst = ord[0]; for (int i = 1; i < sz(ord); i++) { if (ord[i] >= n) continue; if (a[ord[i]].s < a[lst].f) return 1; lst = ord[i]; } return 0; }

Compilation message (stderr)

railroad.cpp: In function 'long long int plan_roller_coaster(std::vector<int>, std::vector<int>)':
railroad.cpp:59:46: error: no matching function for call to 'upper_bound(std::vector<std::pair<int, int> >::iterator, std::vector<std::pair<int, int> >::iterator, <brace-enclosed initializer list>)'
   59 |         int p = upper_bound(all(a), {s[i], 0}) - a.begin() - 1;
      |                                              ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from railroad.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:2087:5: note: candidate: 'template<class _FIter, class _Tp> _FIter std::upper_bound(_FIter, _FIter, const _Tp&)'
 2087 |     upper_bound(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~~~~
/usr/include/c++/10/bits/stl_algo.h:2087:5: note:   template argument deduction/substitution failed:
railroad.cpp:59:46: note:   couldn't deduce template parameter '_Tp'
   59 |         int p = upper_bound(all(a), {s[i], 0}) - a.begin() - 1;
      |                                              ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from railroad.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:2118:5: note: candidate: 'template<class _FIter, class _Tp, class _Compare> _FIter std::upper_bound(_FIter, _FIter, const _Tp&, _Compare)'
 2118 |     upper_bound(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~~~~
/usr/include/c++/10/bits/stl_algo.h:2118:5: note:   template argument deduction/substitution failed:
railroad.cpp:59:46: note:   candidate expects 4 arguments, 3 provided
   59 |         int p = upper_bound(all(a), {s[i], 0}) - a.begin() - 1;
      |                                              ^