제출 #916609

#제출 시각아이디문제언어결과실행 시간메모리
916609winter0101Two Transportations (JOI19_transportations)C++14
100 / 100
618 ms49120 KiB
#include<bits/stdc++.h> #include "Azer.h" using namespace std; #define all(fl) fl.begin(),fl.end() #define pb push_back #define fi first #define se second #define for1(i,j,k) for(int i=j;i<=k;i++) #define for2(i,j,k) for(int i=j;i>=k;i--) #define for3(i,j,k,l) for(int i=j;i<=k;i+=l) #define lb lower_bound #define ub upper_bound #define sz(a) (int)a.size() #define pii pair<int,int> #define pli pair<long long,int> #define gcd __gcd #define lcm(x,y) x*y/__gcd(x,y) namespace { int N; int reada=0,hra=0,nra=0,vertice=0,value=0,lst=0,dem=0,va=0; } // namespace const int maxn=2e3+9; const int inf=5e7; vector<pii>a[maxn]; int d[maxn]; bool vis[maxn]; void dit(){ int diff=value-lst; for1(i,0,8){ SendA(diff>>i&1); } reada=0; hra=0; nra=9; } void update(){ if (dem==N)return; int nw=-1; for1(i,0,N-1){ if (vis[i])continue; if (nw==-1)nw=i; if (d[nw]>d[i])nw=i; } reada=0; hra=0; nra=0; vertice=nw,value=d[nw]; if (value==inf)value=lst+(1<<9)-1; dem++; dit(); } void InitA(int N, int A, std::vector<int> U, std::vector<int> V,std::vector<int> C) { ::N=N; for1(i,0,N-1){ d[i]=inf; } for1(i,0,A-1){ a[U[i]].pb({V[i],C[i]}),a[V[i]].pb({U[i],C[i]}); } d[0]=0; update(); } void ReceiveA(bool x) { reada|=(x<<hra); hra++; if (hra==nra){ if (hra==9){ if (reada<value-lst){//need read vertice of b va=reada; reada=0; hra=0; nra=11; } else {//don't need nra=0; hra=0; for1(i,0,10)SendA(vertice>>i&1); vis[vertice]=1; lst=d[vertice]; for (auto v:a[vertice]){ if (d[vertice]+v.se<d[v.fi]){ d[v.fi]=d[vertice]+v.se; } } update(); return; } } else { //cerr<<vertice<<" "<<reada<<" "<<va<<" "<<lst<<'\n'; d[reada]=va+lst; vertice=reada; vis[vertice]=1; lst=d[vertice]; for (auto v:a[vertice]){ if (d[vertice]+v.se<d[v.fi]){ d[v.fi]=d[vertice]+v.se; } } reada=0; nra=0; hra=0; update(); return; } } } std::vector<int> Answer() { std::vector<int> ans(N); for (int k = 0; k < N; ++k) { ans[k] = d[k]; } return ans; }
#include<bits/stdc++.h> #include "Baijan.h" using namespace std; #define all(fl) fl.begin(),fl.end() #define pb push_back #define fi first #define se second #define for1(i,j,k) for(int i=j;i<=k;i++) #define for2(i,j,k) for(int i=j;i>=k;i--) #define for3(i,j,k,l) for(int i=j;i<=k;i+=l) #define lb lower_bound #define ub upper_bound #define sz(a) (int)a.size() #define pii pair<int,int> #define pli pair<long long,int> #define gcd __gcd #define lcm(x,y) x*y/__gcd(x,y) const int maxn=2e3+9; const int inf=5e6+9; namespace { int n; int readb=0,hrb=0,nrb=0,ver=0,vl=0,last=0,vb=0,demb=0; } // namespace vector<pii>g[maxn]; int dis[maxn]; bool visit[maxn]; void du(){ int diff=vl-last; //cerr<<diff<<'\n'; for1(i,0,8){ SendB(diff>>i&1); } } void add(){ if (demb==n)return; demb++; int nw=-1; for1(i,0,n-1){ if (visit[i])continue; if (nw==-1)nw=i; if (dis[nw]>dis[i])nw=i; } ver=nw; vl=dis[nw]; if (vl==inf)vl=last+(1<<9)-1; //if (ver==2)cout<<vl<<" "<<last<<'\n'; } void InitB(int N, int B, std::vector<int> S, std::vector<int> T,std::vector<int> D) { n=N; for1(i,0,n-1)dis[i]=inf; for1(i,0,B-1){ g[S[i]].pb({T[i],D[i]}); g[T[i]].pb({S[i],D[i]}); } dis[0]=0; readb=0; nrb=9; hrb=0; } void ReceiveB(bool y) { readb|=(y<<hrb); hrb++; if (hrb==nrb){ if (nrb==9){ add(); //cerr<<readb<<'\n'; du(); if (readb<=vl-last){ vb=readb; readb=0; nrb=11; hrb=0; } else { for1(i,0,10)SendB(ver>>i&1); //cerr<<ver<<" "<<dis[ver]<<'\n'; visit[ver]=1; last=dis[ver]; for (auto v:g[ver]){ if (dis[v.fi]>dis[ver]+v.se){ dis[v.fi]=dis[ver]+v.se; } } readb=0; nrb=9; hrb=0; return; } } else { //cerr<<readb<<'\n'; dis[readb]=vb+last; ver=readb; last=dis[ver]; visit[ver]=1; for (auto v:g[ver]){ if (dis[v.fi]>dis[ver]+v.se){ dis[v.fi]=dis[ver]+v.se; } } readb=0; nrb=9; hrb=0; return; } } }
#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...