제출 #957361

#제출 시각아이디문제언어결과실행 시간메모리
957361Soumya1Two Transportations (JOI19_transportations)C++17
100 / 100
611 ms49032 KiB
#include "Azer.h" #include <vector> #include <bits/stdc++.h> using namespace std; const int mxN = 2005; const int inf = mxN * 500; vector<pair<int, int>> ad[mxN]; int n; int dist[mxN]; int cur_dist = 0; bool done[mxN]; void send_node(int u) { for (int i = 0; i < 11; i++) { SendA(u >> i & 1); } } void send_weight(int w) { w = min(w, 511); for (int i = 0; i < 9; i++) { SendA(w >> i & 1); } } void relax(int u) { for (auto [v, w] : ad[u]) { dist[v] = min(dist[v], dist[u] + w); } } pair<int, int> get_best() { int who = -1, cur = inf; for (int i = 0; i < n; i++) { if (done[i]) continue; if (dist[i] < cur) { cur = dist[i]; who = i; } } return {who, cur}; } int need; void InitA(int N, int A, std::vector<int> U, std::vector<int> V, std::vector<int> C) { n = N; for (int i = 0; i < A; i++) { ad[U[i]].push_back({V[i], C[i]}); ad[V[i]].push_back({U[i], C[i]}); } for (int i = 0; i < n; i++) { dist[i] = inf; } dist[0] = 0; done[0] = 1; relax(0); int need = n - 1; if (need) send_weight(get_best().second); } bool rem() { for (int i = 0; i < n; i++) { if (!done[i]) return true; } return false; } int now = 1; vector<int> store; int cnt = 0; void ReceiveA(bool x) { store.push_back(x); cnt++; if (now == 1) { if (cnt == 9) { auto [who, cur] = get_best(); int val = 0; for (int j = 0; j < 9; j++) { if (store[j]) val |= (1 << j); } store.clear(); cnt = 0; if (val == 511) { send_node(who); dist[who] = cur; cur_dist = cur; done[who] = true; relax(who); if (rem()) { auto [w, cc] = get_best(); send_weight(cc - cur_dist); now = 1; } } else { cur_dist += val; now = 0; } } } else { if (cnt == 11) { int who = 0; for (int j = 0; j < 11; j++) { if (store[j]) who |= (1 << j); } store.clear(); cnt = 0; dist[who] = cur_dist; done[who] = true; relax(who); now = 1; if (rem()) { auto [w, cc] = get_best(); send_weight(cc - cur_dist); } } } } std::vector<int> Answer() { std::vector<int> ans(n); for (int k = 0; k < n; ++k) { ans[k] = dist[k]; } return ans; }
#include "Baijan.h" #include <vector> #include <bits/stdc++.h> using namespace std; const int mxN = 2005; const int inf = mxN * 500; vector<pair<int, int>> add[mxN]; int nn; int distt[mxN]; int cur_distt = 0; bool donee[mxN]; void send_nodee(int u) { for (int i = 0; i < 11; i++) { SendB(u >> i & 1); } } void send_weightt(int w) { w = min(w, 511); for (int i = 0; i < 9; i++) { SendB(w >> i & 1); } } void relaxx(int u) { for (auto [v, w] : add[u]) { distt[v] = min(distt[v], distt[u] + w); } } pair<int, int> get_bestt() { int who = -1, cur = inf; for (int i = 0; i < nn; i++) { if (donee[i]) continue; if (distt[i] < cur) { cur = distt[i]; who = i; } } return {who, cur}; } void InitB(int N, int B, std::vector<int> S, std::vector<int> T, std::vector<int> D) { nn = N; for (int i = 0; i < B; i++) { add[S[i]].push_back({T[i], D[i]}); add[T[i]].push_back({S[i], D[i]}); } for (int i = 0; i < nn; i++) { distt[i] = inf; } distt[0] = 0; donee[0] = 1; relaxx(0); } int noww = 1; vector<int> storee; int cntt = 0; void ReceiveB(bool y) { cntt++; storee.push_back(y); if (noww) { if (cntt == 9) { auto [who, cur] = get_bestt(); int val = 0; for (int j = 0; j < 9; j++) { if (storee[j]) val |= (1 << j); } storee.clear(); cntt = 0; if (val <= cur - cur_distt) { send_weightt(511); cur_distt += val; noww = 0; } else { send_weightt(cur - cur_distt); send_nodee(who); cur_distt = cur; distt[who] = cur; relaxx(who); donee[who] = true; noww = 1; } } } else { if (cntt == 11) { int who = 0; for (int j = 0; j < 11; j++) { if (storee[j]) who |= (1 << j); } storee.clear(); cntt = 0; distt[who] = cur_distt; donee[who] = true; relaxx(who); noww = 1; } } }
#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...