Submission #996313

#TimeUsernameProblemLanguageResultExecution timeMemory
99631379brueTwo Transportations (JOI19_transportations)C++17
100 / 100
546 ms49276 KiB
#include "Azer.h" #include <bits/stdc++.h> using namespace std; const int INF = 2e9; namespace { int n, cnt; vector<pair<int, int> > link[2002]; int dist[2002]; bool visited[2002]; int recent_dist; int curr_node, curr_dist; int opp_node, opp_dist, opp_qidx, mode; void update(int x){ visited[x] = 1; for(auto [y, z]: link[x]){ dist[y] = min(dist[y], dist[x] + z); } recent_dist = dist[x]; } void send_info(){ curr_node = -1, curr_dist = INF; for(int i=0; i<n; i++) if(!visited[i] && curr_dist > dist[i]){ curr_node = i; curr_dist = dist[i]; } int diff = min(curr_dist - recent_dist, 511); assert((0 <= curr_dist - recent_dist && curr_dist - recent_dist < 512) || curr_dist == INF); for(int i=0; i<9; i++) SendA((diff >> i) & 1); opp_node = opp_qidx = mode = 0, opp_dist = recent_dist; } } void InitA(int N, int A, vector<int> U, vector<int> V, vector<int> C) { n = N; for(int i=0; i<A; i++){ link[U[i]].push_back(make_pair(V[i], C[i])); link[V[i]].push_back(make_pair(U[i], C[i])); } for(int i=1; i<n; i++) dist[i] = INF; update(0); cnt = 1; send_info(); } void ReceiveA(bool x) { if(!mode){ opp_dist += (int(x) << opp_qidx++); if(opp_qidx == 9){ /// 정보가 모두 전달되었다 opp_qidx = 0; // printf("Azer: my %d %d, opp %d\n", curr_node, curr_dist, opp_dist); if(curr_dist <= opp_dist){ /// 내가 정보를 보내고 업데이트 update(curr_node); for(int i=0; i<11; i++) SendA((curr_node >> i) & 1); if(++cnt == n) return; else send_info(); } else mode = 1; } } else{ opp_node += (int(x) << opp_qidx++); if(opp_qidx == 11){ dist[opp_node] = opp_dist; update(opp_node); if(++cnt == n) return; else send_info(); mode = 0; } } } vector<int> Answer(){ return vector<int> (dist, dist+n); }
#include "Baijan.h" #include <bits/stdc++.h> using namespace std; const int INF = 2e9; namespace{ int n, cnt; vector<pair<int, int> > link[2002]; int dist[2002]; bool visited[2002]; int recent_dist; int curr_node, curr_dist; int opp_node, opp_dist, opp_qidx, mode; void update(int x){ visited[x] = 1; for(auto [y, z]: link[x]){ dist[y] = min(dist[y], dist[x] + z); } recent_dist = dist[x]; } void send_info(){ curr_node = -1, curr_dist = INF; for(int i=0; i<n; i++) if(!visited[i] && curr_dist > dist[i]){ curr_node = i; curr_dist = dist[i]; } int diff = min(curr_dist - recent_dist, 511); assert((0 <= curr_dist - recent_dist && curr_dist - recent_dist < 512) || curr_dist == INF); for(int i=0; i<9; i++) SendB((diff >> i) & 1); opp_node = opp_qidx = mode = 0, opp_dist = recent_dist; } } void InitB(int N, int B, vector<int> S, vector<int> T, vector<int> D) { n = N; for(int i=0; i<B; i++){ link[S[i]].push_back(make_pair(T[i], D[i])); link[T[i]].push_back(make_pair(S[i], D[i])); } for(int i=1; i<n; i++) dist[i] = INF; update(0); cnt = 1; send_info(); } void ReceiveB(bool x) { if(!mode){ opp_dist += (int(x) << opp_qidx++); if(opp_qidx == 9){ /// 정보가 모두 전달되었다 opp_qidx = 0; // printf("Baijan: my %d %d, opp %d\n", curr_node, curr_dist, opp_dist); if(curr_dist < opp_dist){ /// 내가 정보를 보내고 업데이트 update(curr_node); for(int i=0; i<11; i++) SendB((curr_node >> i) & 1); if(++cnt == n) return; else send_info(); } else mode = 1; } } else{ opp_node += (int(x) << opp_qidx++); if(opp_qidx == 11){ dist[opp_node] = opp_dist; update(opp_node); if(++cnt == n) return; else send_info(); mode = 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...