Submission #417388

#TimeUsernameProblemLanguageResultExecution timeMemory
417388wiwihoHighway Tolls (IOI18_highway)C++14
5 / 100
3091 ms21860 KiB
#include "highway.h" #include <bits/stdc++.h> #include <bits/extc++.h> #define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define iter(a) a.begin(), a.end() #define riter(a) a.rbegin(), a.rend() #define lsort(a) sort(iter(a)) #define gsort(a) sort(riter(a)) #define pb(a) push_back(a) #define eb(a) emplace_back(a) #define pf(a) push_front(a) #define ef(a) emplace_front(a) #define pob pop_back() #define pof pop_front() #define mp(a, b) make_pair(a, b) #define F first #define S second #define mt make_tuple #define gt(t, i) get<i>(t) #define tomax(a, b) ((a) = max((a), (b))) #define tomin(a, b) ((a) = min((a), (b))) #define topos(a) ((a) = (((a) % MOD + MOD) % MOD)) #define uni(a) a.resize(unique(iter(a)) - a.begin()) #define printv(a, b) {bool pvaspace=false; \ for(auto pva : a){ \ if(pvaspace) b << " "; pvaspace=true;\ b << pva;\ }\ b << "\n";} using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef unsigned long long ull; typedef long double ld; using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<ld, ld>; using tiii = tuple<int, int, int>; const ll MOD = 1000000007; const ll MAX = 2147483647; template<typename A, typename B> ostream& operator<<(ostream& o, pair<A, B> p){ return o << '(' << p.F << ',' << p.S << ')'; } ll ifloor(ll a, ll b){ if(b < 0) a *= -1, b *= -1; if(a < 0) return (a - b + 1) / b; else return a / b; } ll iceil(ll a, ll b){ if(b < 0) a *= -1, b *= -1; if(a > 0) return (a + b - 1) / b; else return a / b; } int n, m; ll query(vector<int> qry){ ll tmp = ask(qry); // cerr << "query " << tmp << " "; // printv(qry, cerr); return tmp; } void find_pair(int N, vector<int> U, vector<int> V, int A, int B) { n = N; m = U.size(); vector<vector<pii>> g(n); for(int i = 0; i < m; i++){ int u = U[i], v = V[i]; g[u].eb(mp(v, i)); g[v].eb(mp(u, i)); } vector<int> qry(m); ll dis = query(qry); int l = 0, r = m - 1; while(l < r){ int mid = (l + r) / 2; fill(qry.begin() + l, qry.begin() + mid + 1, 1); // cerr << l << " " << r << " " << mid << "\n"; if(query(qry) != dis){ r = mid; fill(qry.begin() + l, qry.begin() + mid + 1, 0); } else l = mid + 1; } int e = l; int u = U[e], v = V[e]; // cerr << e << " " << u << " " << v << "\n"; auto getdis = [g](int s){ vector<int> d(n, -1); vector<int> p(n, -1); queue<int> q; q.push(s); d[s] = 0; while(!q.empty()){ int now = q.front(); q.pop(); for(pii i : g[now]){ if(d[i.F] != -1) continue; p[i.F] = i.S; d[i.F] = d[now] + 1; q.push(i.F); } } return mp(d, p); }; vector<int> du, pu, dv, pv; tie(du, pu) = getdis(u); tie(dv, pv) = getdis(v); vector<int> us, vs; for(int i = 0; i < n; i++){ if(du[i] < dv[i]) us.eb(i); else vs.eb(i); } fill(iter(qry), 1); for(int i : us) qry[pu[i]] = 0; for(int i : vs) qry[pv[i]] = 0; qry[e] = 0; // cerr << "u " << " "; // printv(us, cerr); // cerr << "v " << " "; // printv(vs, cerr); sort(iter(us), [du](int a, int b){ return du[a] < du[b]; }); sort(iter(vs), [dv](int a, int b){ return dv[a] < dv[b]; }); auto owo = [qry, dis](vector<int>& s, vector<int>& p){ int l = 0, r = (int)s.size() - 1; while(l < r){ int mid = (l + r + 1) / 2; vector<int> tmp = qry; for(int i = mid; i <= r; i++) tmp[p[s[i]]] = 1; // cerr << "test " << l << " " << r << " " << mid << "\n"; if(query(tmp) == dis) r = mid - 1; else l = mid; } return s[l]; }; int v1 = owo(us, pu); int v2 = owo(vs, pv); // cerr << v1 << " " << v2 << "\n"; answer(v1, v2); }
#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...