제출 #964293

#제출 시각아이디문제언어결과실행 시간메모리
964293steveonalex통행료 (IOI18_highway)C++17
51 / 100
238 ms262144 KiB
#include <bits/stdc++.h> #include "highway.h" using namespace std; typedef long long ll; typedef unsigned long long ull; #define ALL(v) (v).begin(), (v).end() #define MASK(i) (1LL << (i)) #define GETBIT(mask, i) (((mask) >> (i)) & 1) // mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); mt19937_64 rng(1); ll rngesus(ll l, ll r){return ((ull) rng()) % (r - l + 1) + l;} ll max(ll a, ll b){return (a > b) ? a : b;} ll min(ll a, ll b){return (a < b) ? a : b;} ll LASTBIT(ll mask){return mask & (-mask);} ll pop_cnt(ll mask){return __builtin_popcountll(mask);} ll ctz(ll mask){return __builtin_ctzll(mask);} ll clz(ll mask){return __builtin_clzll(mask);} ll logOf(ll mask){return 63 - clz(mask);} template <class T1, class T2> bool minimize(T1 &a, T2 b){ if (a > b){a = b; return true;} return false; } template <class T1, class T2> bool maximize(T1 &a, T2 b){ if (a < b){a = b; return true;} return false; } template <class T> void printArr(T& a, string separator = " ", string finish = "\n", ostream& out = cout){ for(auto i: a) out << i << separator; out << finish; } template <class T> void remove_dup(vector<T> &a){ sort(ALL(a)); a.resize(unique(ALL(a)) - a.begin()); } const int N = 1e5 + 69; int n, m; vector<pair<int, int>> graph[N]; int h[N]; void dfs(int u, int p, vector<int> &topo){ for(pair<int, int> v: graph[u]) if (v.first != p){ h[v.first] = h[u] + 1; dfs(v.first, u, topo); topo.push_back(v.second); } } struct P{ ll i, w; P(){} P(ll _i, ll _w){i = _i, w = _w;} }; struct compare{ bool operator () (P a, P b) {return a.w > b.w;} }; // namespace Grader{ // int n; // int s, t; // int x, y; // vector<int> U, V; // int A, B; // int o_cnt = 0; // ll ask(vector<int> w){ // o_cnt++; // vector<P> graph[n]; // for(int i = 0; i<w.size(); ++i){ // int u = U[i], v = V[i]; // int cur_w = A; // if (w[i]) cur_w = B; // graph[u].push_back(P(v, cur_w)); // graph[v].push_back(P(u, cur_w)); // } // vector<ll> dis(n+1, 1e18); // dis[s] = 0; // priority_queue<P, vector<P>, compare> pq; // pq.push(P(s, 0)); // while(pq.size()){ // P u= pq.top(); pq.pop(); // for(P v: graph[u.i]) if (minimize(dis[v.i], dis[u.i] + v.w)) // pq.push(P(v.i, dis[v.i])); // } // return dis[t]; // } // void answer(int _x, int _y){ // x = _x, y = _y; // } void find_pair(int _n, vector<int> U, vector<int> V, int A, int B) { n = _n, m = U.size(); for(int i = 0; i<n; ++i) graph[i].clear(); for(int i = 0; i<m; ++i){ int u = U[i], v = V[i]; graph[u].push_back({v, i}); graph[v].push_back({u, i}); } ll initial = ask(vector<int>(m)); vector<int> topo; dfs(0, 0, topo); int l= 0, r = topo.size(); while(l < r){ int mid = (l + r) >> 1; vector<int> w(m); for(int i = 0; i<=mid; ++i) w[topo[i]] = 1; if (ask(w) > initial) r = mid; else l = mid + 1; } int x; if (l == topo.size()) x = 0; else{ int e = topo[l]; if (h[U[e]] > h[V[e]]) x = U[e]; else x = V[e]; } topo.clear(); h[x] = 0; dfs(x, x, topo); l= 0, r = topo.size() - 1; while(l < r){ int mid = (l + r) >> 1; vector<int> w(m); for(int i = 0; i<=mid; ++i) w[topo[i]] = 1; if (ask(w) > initial) r = mid; else l = mid + 1; } int e = topo[l]; int y; if (h[U[e]] == initial / A) y = U[e]; else y = V[e]; answer(x, y); } // pair<bool, int> solve(int _n){ // n = _n; // U.clear(); V.clear(); // x = y = -1; // o_cnt = 0; // for(int i= 1; i<n; ++i){ // U.push_back(rngesus(0, i-1)); // V.push_back(i); // if (rngesus(0, 1)) swap(U.back(), V.back()); // } // s = rngesus(0, n-1); // t = s; // while(t == s) t = rngesus(0, n-1); // A = 1, B = 2; // find_pair(n, U, V, A, B); // if (x > y) swap(x, y); // if (s > t) swap(s, t); // return make_pair(make_pair(x, y) == make_pair(s, t), o_cnt); // } // } // int main(void){ // ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // for(int iteration = 1; iteration <= 100; ++iteration){ // pair<bool, int> verdict = Grader::solve(5); // if (verdict.first) cout << "AC\n"; // else cout << "WA\n"; // cout << "Operation count: " << verdict.second << "\n"; // } // return 0; // }

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

highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:128:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  128 |         if (l == topo.size()) x = 0;
      |             ~~^~~~~~~~~~~~~~
#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...