제출 #568945

#제출 시각아이디문제언어결과실행 시간메모리
568945zaneyuTwo Transportations (JOI19_transportations)C++14
100 / 100
900 ms72304 KiB
#include "Azer.h" #include<bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; typedef tree<long long,null_type,less_equal<long long>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; #pragma GCC optimize("Ofast") //#pragma GCC target("avx2") //order_of_key #of elements less than x // find_by_order kth element using ll=long long; using ld=long double; using pii=pair<int,int>; #define f first #define s second #define pb push_back #define REP(i,n) for(int i=0;i<n;i++) #define REP1(i,n) for(int i=1;i<=n;i++) #define FILL(n,x) memset(n,x,sizeof(n)) #define ALL(_a) _a.begin(),_a.end() #define sz(x) (int)x.size() #define SORT_UNIQUE(c) (sort(c.begin(),c.end()),c.resize(distance(c.begin(),unique(c.begin(),c.end())))) const ll maxn=5e5+5; const ll maxlg=__lg(maxn)+2; const ll INF64=4e18; const int INF=0x3f3f3f3f; const int MOD=1e9+7; const ld PI=acos(-1); const ld eps=1e-6; #define lowb(x) x&(-x) #define MNTO(x,y) x=min(x,(__typeof__(x))y) #define MXTO(x,y) x=max(x,(__typeof__(x))y) template<typename T1,typename T2> ostream& operator<<(ostream& out,pair<T1,T2> P){ out<<P.f<<' '<<P.s; return out; } template<typename T> ostream& operator<<(ostream& out,vector<T> V){ REP(i,sz(V)) out<<V[i]<<((i!=sz(V)-1)?" ":""); return out; } namespace { int n; vector<pii> v[maxn]; int dist[maxn]; priority_queue<pii,vector<pii>,greater<pii>> pq; bool done[maxn]; void relax(int u){ done[u]=1; for(auto x:v[u]){ MNTO(dist[x.f],dist[u]+x.s); } } int cnt,idx,mn,p,pv; int val=0; void send(){ mn=INF+1; REP(i,n){ if(!done[i]){ if(mn>dist[i]){ mn=dist[i]; p=i; } } } if(mn==INF+1){ return; } mn-=pv; MNTO(mn,511); REP(i,9) SendA((mn>>(8-i))&1); idx=1; } } void InitA(int N, int A, std::vector<int> U, std::vector<int> V, std::vector<int> C) { n=N; REP(i,A){ v[U[i]].pb({V[i],C[i]}); v[V[i]].pb({U[i],C[i]}); } REP(i,n) dist[i]=INF; dist[0]=0; pv=0; relax(0); send(); } void ReceiveA(bool x) { val=val*2+x; ++cnt; if(idx==1){ if(cnt==9){ if(mn<=val){ REP(i,11) SendA((p>>(10-i))&1); pv+=mn; relax(p); send(); } else{ pv+=val; idx=2; } cnt=0; val=0; } } else if(idx==2){ if(cnt==11){ dist[val]=pv; relax(val); send(); cnt=0; val=0; } } } std::vector<int> Answer() { vector<int> ans; REP(i,n) ans.pb(dist[i]); return ans; }
#include "Baijan.h" #include<bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; typedef tree<long long,null_type,less_equal<long long>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; #pragma GCC optimize("Ofast") //#pragma GCC target("avx2") //order_of_key #of elements less than x // find_by_order kth element using ll=long long; using ld=long double; using pii=pair<int,int>; #define f first #define s second #define pb push_back #define REP(i,n) for(int i=0;i<n;i++) #define REP1(i,n) for(int i=1;i<=n;i++) #define FILL(n,x) memset(n,x,sizeof(n)) #define ALL(_a) _a.begin(),_a.end() #define sz(x) (int)x.size() #define SORT_UNIQUE(c) (sort(c.begin(),c.end()),c.resize(distance(c.begin(),unique(c.begin(),c.end())))) const ll maxn=5e5+5; const ll maxlg=__lg(maxn)+2; const ll INF64=4e18; const int INF=0x3f3f3f3f; const int MOD=1e9+7; const ld PI=acos(-1); const ld eps=1e-6; #define lowb(x) x&(-x) #define MNTO(x,y) x=min(x,(__typeof__(x))y) #define MXTO(x,y) x=max(x,(__typeof__(x))y) template<typename T1,typename T2> ostream& operator<<(ostream& out,pair<T1,T2> P){ out<<P.f<<' '<<P.s; return out; } template<typename T> ostream& operator<<(ostream& out,vector<T> V){ REP(i,sz(V)) out<<V[i]<<((i!=sz(V)-1)?" ":""); return out; } namespace { int n; vector<pii> v[maxn]; int dist[maxn]; priority_queue<pii,vector<pii>,greater<pii>> pq; bool done[maxn]; void relax(int u){ done[u]=1; for(auto x:v[u]){ MNTO(dist[x.f],dist[u]+x.s); } } int cnt,idx,mn,p,pv; int val=0; void send(){ mn=INF+1; REP(i,n){ if(!done[i]){ if(mn>dist[i]){ mn=dist[i]; p=i; } } } if(mn==INF+1){ return; } mn-=pv; MNTO(mn,511); REP(i,9) SendB((mn>>(8-i))&1); idx=1; } } void InitB(int N, int B, std::vector<int> S, std::vector<int> T, std::vector<int> D) { n=N; REP(i,B){ v[S[i]].pb({T[i],D[i]}); v[T[i]].pb({S[i],D[i]}); } REP(i,n) dist[i]=INF; dist[0]=0; pv=0; relax(0); send(); } void ReceiveB(bool y) { val=val*2+y; ++cnt; if(idx==1){ if(cnt==9){ if(mn<val){ REP(i,11) SendB((p>>(10-i))&1); pv+=mn; relax(p); send(); } else{ pv+=val; idx=2; } cnt=0; val=0; } } else if(idx==2){ if(cnt==11){ dist[val]=pv; relax(val); send(); cnt=0; val=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...
#Verdict Execution timeMemoryGrader output
Fetching results...