제출 #612647

#제출 시각아이디문제언어결과실행 시간메모리
612647evenvalue통행료 (IOI18_highway)C++17
51 / 100
184 ms22120 KiB
#include "highway.h" #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template<typename T> using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>; template<typename T> using max_heap = priority_queue<T, vector<T>, less<T>>; using int64 = long long; using ld = long double; constexpr int kInf = 1e9 + 10; constexpr int64 kInf64 = 1e15 + 10; constexpr int kMod = 1e9 + 7; int find_hidden_node(const vector<vector<pair<int, int>>> &g, const int s, const int64 all_a, const vector<int> &template_w, const int a, const int b) { vector<int> w = template_w; for (const auto &adj : g) { for (const auto &[_, i] : adj) { w[i] = 1; } } const int64 this_b = ask(w); const int depth = (int) ((this_b - all_a) / (b - a)); if (depth == 0) { return s; } vector<pair<int, int>> candidates; function<void(int, int, int, int)> dfs = [&](const int x, const int p, const int i, const int d) { if (d == depth) { candidates.emplace_back(x, i); return; } for (const auto &[y, idx] : g[x]) { if (y == p) continue; dfs(y, x, idx, d + 1); } }; dfs(s, -1, -1, 0); w = template_w; int lo = 0, hi = (int) candidates.size() - 1; while (lo < hi) { const int mid = (lo + hi) / 2; for (int i = 0; i < candidates.size(); i++) { w[candidates[i].second] = (i <= mid); } if (ask(w) > all_a) { hi = mid; } else { lo = mid + 1; } } return candidates[lo].first; } void find_pair(const int n, const vector<int> U, const vector<int> V, const int a, const int b) { const int m = (int) U.size(); vector<int> w(m); const int64 all_a = ask(w); int lo = 0, hi = m - 1; while (lo < hi) { const int mid = (lo + hi) / 2; for (int i = 0; i < m; i++) { w[i] = (i <= mid); } if (ask(w) > all_a) { hi = mid; } else { lo = mid + 1; } } assert(lo == hi); vector<vector<pair<int, int>>> g(n); for (int i = 0; i < m; i++) { g[U[i]].emplace_back(V[i], i); g[V[i]].emplace_back(U[i], i); } auto bfs = [&g](const int s) { vector<int> dist(g.size(), kInf); dist[s] = 0; queue<int> q; q.push(s); while (not q.empty()) { const int x = q.front(); for (const auto &[y, _] : g[x]) { if (dist[y] < kInf) continue; q.push(y); dist[y] = dist[x] + 1; } q.pop(); } return dist; }; auto bfs_tree = [&](const int s, vector<int> near) -> vector<vector<pair<int, int>>> { queue<int> q; q.push(s); vector<vector<pair<int, int>>> tree(n); near[s] = 0; while (not q.empty()) { const int x = q.front(); for (const auto &[y, i] : g[x]) { if (near[y] == 0) continue; q.push(y); tree[x].emplace_back(y, i); near[y] = 0; } q.pop(); } return tree; }; const int x = U[lo], y = V[lo]; const vector<int> distx = bfs(x), disty = bfs(y); vector<int> nearx(n), neary(n); for (int i = 0; i < n; i++) { nearx[i] = (distx[i] < disty[i]); neary[i] = (disty[i] < distx[i]); } const auto tx = bfs_tree(x, nearx); const auto ty = bfs_tree(y, neary); vector<int> template_w(m, 1); template_w[lo] = 0; for (int u = 0; u < n; u++) { for (const auto &[_, i] : tx[u]) { template_w[i] = 0; } for (const auto &[_, i] : ty[u]) { template_w[i] = 0; } } answer(find_hidden_node(tx, x, all_a, template_w, a, b), find_hidden_node(ty, y, all_a, template_w, a, b)); }

컴파일 시 표준 에러 (stderr) 메시지

highway.cpp: In function 'int find_hidden_node(const std::vector<std::vector<std::pair<int, int> > >&, int, int64, const std::vector<int>&, int, int)':
highway.cpp:61:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |     for (int i = 0; i < candidates.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...