Submission #1068443

#TimeUsernameProblemLanguageResultExecution timeMemory
1068443mc061Highway Tolls (IOI18_highway)C++17
5 / 100
139 ms31556 KiB
#include <bits/stdc++.h> using namespace std; int m; long long a, b; long long ask(const std::vector<int> &w); long long get(const vector<int>& busy) { vector<int> q(m, 0); for (int i : busy) q[i] = 1; return ask(q); } void answer(int s, int t); void rec(vector<int> now, vector<vector<int>>& full, int path_le) { if (!now.size()) return; long long here = get(now); if (here == 1ll*path_le*a) return; if (here == 1ll*now.size()*b + 1ll*(path_le-now.size())*a) { full.push_back(now); return; } // random_shuffle(now.begin(), now.end()); vector<int> left, right; for (int i = 0; i < now.size()/2; ++i) { left.push_back(now[i]); } for (int i = now.size()/2; i < now.size(); ++i) { right.push_back(now[i]); } rec(left, full, path_le); rec(right, full, path_le); } void find_pair(int N, std::vector<int> U, std::vector<int> V, int A_, int B_) { a = A_; b = B_; m = U.size(); vector<int> v(U.size()); iota(v.begin(), v.end(), 0); map<pair<int, int>, int> ind; vector<vector<int>> gr(N); for (int i = 0; i < U.size(); ++i) { ind[{U[i], V[i]}] = ind[{V[i], U[i]}] = i; gr[U[i]].push_back(V[i]); gr[V[i]].push_back(U[i]); } vector<int> tour; vector<bool> vis(N, false); v.clear(); auto get_tour = [&] (auto&& self, int X) -> void { tour.push_back(X); vis[X] = true; for (int u : gr[X]) if (!vis[u]) { v.push_back(ind[{X, u}]); self(self, u); } }; get_tour(get_tour, 0); vector<vector<int>> full; long long path_le = get(v) / b; rec(v, full, path_le); map<int, int> c; for (auto& x : full) { for (int j : x) { c[U[j]]++; c[V[j]]++; } } vector<int> vs; for (auto [x, y] : c) { if (y == 1) vs.push_back(x); } answer(vs[0], vs[1]); }

Compilation message (stderr)

highway.cpp: In function 'void rec(std::vector<int>, std::vector<std::vector<int> >&, int)':
highway.cpp:19:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'long long unsigned int' [-Wsign-compare]
   19 |     if (here == 1ll*now.size()*b + 1ll*(path_le-now.size())*a) {
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
highway.cpp:25:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for (int i = 0; i < now.size()/2; ++i) {
      |                     ~~^~~~~~~~~~~~~~
highway.cpp:28:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for (int i = now.size()/2; i < now.size(); ++i) {
      |                                ~~^~~~~~~~~~~~
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:43:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for (int i = 0; i < U.size(); ++i) {
      |                     ~~^~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...