Submission #293846

#TimeUsernameProblemLanguageResultExecution timeMemory
293846TricksterHighway Tolls (IOI18_highway)C++14
0 / 100
35 ms11384 KiB
#include <algorithm> #include <highway.h> #include <string.h> #include <iostream> #include <stdio.h> #include <vector> #include <queue> #include <cmath> #include <set> #include <map> using namespace std; #define maxN 200010 #define ff first #define ss second #define ll long long #define pb push_back #define mod 1000000007 #define pii pair <ll, ll> // #pragma GCC target ("avx2") // #pragma GCC optimization ("O3") // #pragma GCC optimization ("unroll-loops") ll bigmod(ll a,ll e) {if(e==0)return 1;ll x=bigmod(a*a%mod,e>>1);return e&1?x*a%mod:x;} pii L[maxN]; int n, m, dis; vector <pii> E[maxN]; vector <int> T[maxN]; int tap(vector <pii> v) { int sz = v.size(); int l = 0, r = sz-1, md, in = 0; while(l <= r) { md = (l+r)/2; vector <int> arr; for(int i = 0; i < m; i++) arr.pb(0); for(int i = 0; i < sz; i++) for(auto h: T[v[i].ss]) arr[h] = (i <= md ? 1 : 0); int cur = ask(arr); if(dis != cur) r = md-1, in = md; else l = md+1; } return v[in].ss; } void find_pair(int N, vector <int> U, vector <int> V, int A, int B) { m = U.size(), n = N; for(int i = 0; i < m; i++) { E[U[i]].pb({V[i], i}); E[V[i]].pb({U[i], i}); } vector <int> arr; for(int i = 0; i < m; i++) arr.pb(0); dis = ask(arr); int l = 0, r = m-1, md, in = 0; while(l <= r) { md = (l+r)/2; vector <int> arr; for(int i = 0; i < m; i++) arr.pb((i <= md ? 1 : 0)); int cur = ask(arr); if(dis != cur) r = md-1, in = md; else l = md+1; } queue <pii> Q; Q.push({U[in], 1}); Q.push({V[in], 2}); L[U[in]] = {0, 1}; L[V[in]] = {0, 2}; while(!Q.empty()) { int nd = Q.front().ff; int tp = Q.front().ss; Q.pop(); for(auto i: E[nd]) { if(L[i.ff].ss) continue; L[i.ff] = {L[nd].ff+1, tp}; Q.push({i.ff, tp}); T[i.ff].pb(i.ss); T[nd].pb(i.ss); } } vector <pii> v; for(int i = 0; i < n; i++) if(L[i].ss == 1) v.pb({L[i].ff, i}); sort(v.begin(), v.end()); int s = tap(v); v.clear(); for(int i = 0; i < n; i++) if(L[i].ss == 2) v.pb({L[i].ff, i}); sort(v.begin(), v.end()); int t = tap(v); answer(s, t); }
#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...