제출 #415384

#제출 시각아이디문제언어결과실행 시간메모리
415384Kevin_Zhang_TWHighway Tolls (IOI18_highway)C++17
0 / 100
29 ms15044 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define pb emplace_back #define AI(i) begin(i), end(i) template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); } template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); } #ifdef KEV #define DE(args...) kout("[ " + string(#args) + " ] = ", args) void kout() { cerr << endl; } template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); } template<class T> void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l)==r], ++l; } #else #define DE(...) 0 #define debug(...) 0 #endif const int MAX_N = 300010; #include "highway.h" int n, m, dis; vector<int> edge[MAX_N]; vector<pair<int,int>> alle; ll A, B; // node is banned ll qry(vector<int> ban_list) { debug(AI(ban_list)); vector<int> ban(n); for (int u : ban_list) ban[u] = true; vector<int> w(m); for (int i = 0;i < m;++i) { auto [x, y] = alle[i]; w[i] = ban[x] || ban[y]; } return ask(w); } // edge is banned ll qry(vector<pair<int,int>> ban_list) { sort(AI(ban_list)); vector<int> w(m); for (int i = 0;i < m;++i) { auto [x, y] = alle[i]; if (binary_search(AI(ban_list), make_pair(x, y)) || binary_search(AI(ban_list), make_pair(y, x))) w[i] = true; } return ask(w); } int solve_tree_rt(int rt) { vector<int> stk; vector<pair<int,int>> be; function<void(int,int)> dfs = [&](int x, int lst) { stk.pb(x); be.pb(x, lst); for (int u : edge[x]) if (u != lst) dfs(u, x); }; dfs(rt, rt); int l = 0, r = n-1, mid; while (l < r) { mid = l + r >> 1; ll v = qry( vector<pair<int,int>>(begin(be), begin(be)+mid ) ); ll more = (v - dis * A) / (B-A); if (more < dis) l = mid+1; else r = mid; } return stk[l]; } void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) { ::A = A, ::B = B; n = N, m = U.size(); assert(m == n-1); for (int i = 0;i < m;++i) { alle.pb(U[i], V[i]); edge[U[i]].pb(V[i]); edge[V[i]].pb(U[i]); } dis = qry( vector<int>{} ) / A; int x = solve_tree_rt(0); answer(0, x); }

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

highway.cpp: In function 'll qry(std::vector<int>)':
highway.cpp:15:20: warning: statement has no effect [-Wunused-value]
   15 | #define debug(...) 0
      |                    ^
highway.cpp:28:2: note: in expansion of macro 'debug'
   28 |  debug(AI(ban_list));
      |  ^~~~~
highway.cpp: In function 'int solve_tree_rt(int)':
highway.cpp:66:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   66 |   mid = l + r >> 1;
      |         ~~^~~
#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...