제출 #218396

#제출 시각아이디문제언어결과실행 시간메모리
218396rama_pangTwo Transportations (JOI19_transportations)C++14
100 / 100
2150 ms85368 KiB
#include "Azer.h" #include <bits/stdc++.h> using namespace std; namespace { const int WEIGHT = 9; const int VERTEX = 11; const int INF = (1 << WEIGHT) - 1; struct edge_t { int v, w; edge_t() {} edge_t(int v, int w) : v(v), w(w) {} }; int N; vector<int> dist; vector<bool> processed; vector<vector<edge_t>> adj; } // namespace void InitA(int N, int A, vector<int> U, vector<int> V, vector<int> C) { ::N = N; adj.resize(N); dist.assign(N, -1); processed.assign(N, false); for (int i = 0; i < A; i++) { adj[U[i]].emplace_back(V[i], C[i]); adj[V[i]].emplace_back(U[i], C[i]); } dist[0] = 0; for (int i = 0; i < WEIGHT; i++) SendA(false); } void ReceiveA(bool x) { static int prv = 0; // previous vertex that was processed static int cur = 0; // current vertex to be processed static int diff = 0; static int all_bits = 9; static int received = 0; static int information = 0; static int cnt_processed = 0; static auto reset = [&](int BITS) { received = information = 0; all_bits = BITS; }; received++; information = 2 * information + x; if (received < all_bits) return; // received all bits if (all_bits == WEIGHT) { if (diff <= information) { // the next vertex is from Azer, so we send its id to Baijan information = cur; received = all_bits = VERTEX; for (int i = VERTEX - 1; i >= 0; i--) SendA(cur & (1 << i)); } else { // the next vertex is from Baijan, so we recieve its id diff = information; reset(VERTEX); return; } } if (all_bits == VERTEX) { // we should process current node and relax its edges cur = information; dist[cur] = dist[prv] + diff; processed[cur] = true; if ((++cnt_processed) == N) return; // relax edges for (auto &nxt : adj[cur]) { if (dist[nxt.v] == -1 || dist[nxt.v] > dist[cur] + nxt.w) { dist[nxt.v] = dist[cur] + nxt.w; } } int nxt = -1; for (int i = 0; i < N; i++) { if (processed[i] || dist[i] == -1) continue; if (nxt == -1 || dist[nxt] > dist[i]) nxt = i; } prv = cur; cur = nxt; diff = (cur == -1 ? INF : dist[cur] - dist[prv]); // recieve minimum weight from Baijan reset(WEIGHT); // send minimum weight to Baijan for (int i = WEIGHT - 1; i >= 0; i--) SendA(diff & (1 << i)); } } vector<int> Answer() { vector<int> ans = dist; return ans; }
#include "Baijan.h" #include <bits/stdc++.h> using namespace std; namespace { const int WEIGHT = 9; const int VERTEX = 11; const int INF = (1 << WEIGHT) - 1; struct edge_t { int v, w; edge_t() {} edge_t(int v, int w) : v(v), w(w) {} }; int N; vector<int> dist; vector<bool> processed; vector<vector<edge_t>> adj; } // namespace void InitB(int N, int B, vector<int> S, vector<int> T, vector<int> D) { ::N = N; adj.resize(N); dist.assign(N, -1); processed.assign(N, false); for (int i = 0; i < B; i++) { adj[S[i]].emplace_back(T[i], D[i]); adj[T[i]].emplace_back(S[i], D[i]); } dist[0] = 0; for (int i = 0; i < WEIGHT; i++) SendB(false); } void ReceiveB(bool y) { static int prv = 0; // previous vertex that was processed static int cur = 0; // current vertex to be processed static int diff = 0; static int all_bits = 9; static int received = 0; static int information = 0; static int cnt_processed = 0; static auto reset = [&](int BITS) { received = information = 0; all_bits = BITS; }; received++; information = 2 * information + y; if (received < all_bits) return; // received all bits if (all_bits == WEIGHT) { if (diff < information) { // the next vertex is from Baijan, so we send its id to Azer information = cur; received = all_bits = VERTEX; for (int i = VERTEX - 1; i >= 0; i--) SendB(cur & (1 << i)); } else { // the next vertex is from Azer, so we recieve its id diff = information; reset(VERTEX); return; } } if (all_bits == VERTEX) { // we should process current node and relax its edges cur = information; dist[cur] = dist[prv] + diff; processed[cur] = true; if ((++cnt_processed) == N) return; // relax edges for (auto &nxt : adj[cur]) { if (dist[nxt.v] == -1 || dist[nxt.v] > dist[cur] + nxt.w) { dist[nxt.v] = dist[cur] + nxt.w; } } int nxt = -1; for (int i = 0; i < N; i++) { if (processed[i] || dist[i] == -1) continue; if (nxt == -1 || dist[nxt] > dist[i]) nxt = i; } prv = cur; cur = nxt; diff = (cur == -1 ? INF : dist[cur] - dist[prv]); // recieve minimum weight from Azer reset(WEIGHT); // send minimum weight to Azer for (int i = WEIGHT - 1; i >= 0; i--) SendB(diff & (1 << i)); } }
#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...