Submission #901333

#TimeUsernameProblemLanguageResultExecution timeMemory
901333nguyentunglamTwo Transportations (JOI19_transportations)C++17
100 / 100
532 ms48892 KiB
#include "Azer.h" #include <vector> #include<bits/stdc++.h> using namespace std; const int M1 = 9, M2 = 11; int loop; namespace { const int N = 2e3 + 10; int n; int pre; int d[N]; bool mark[N]; vector<pair<int, int> > adj[N]; #define ii pair<int, int> priority_queue<ii, vector<ii>, greater<ii> > q; void init () { mark[0] = 1; d[0] = 0; for(int i = 1; i < n; i++) mark[i] = 0, d[i] = (1 << 20) - 1; for(auto &it : adj[0]) { int v, w; tie(v, w) = it; q.push({d[v] = w, v}); } } void add_edge (int u, int v, int w) { adj[u].emplace_back(v, w); adj[v].emplace_back(u, w); } pair<int, int> nxt; void add () { while (!q.empty() && mark[q.top().second]) q.pop(); if (q.empty()) { nxt = make_pair((1 << 20) - 1, (1 << 11) - 1); for(int i = 0; i < M1; i++) SendA(1); return; } int cost, u; tie(cost, u) = q.top(); nxt = make_pair(cost - pre, u); for(int i = 0; i < M1; i++) SendA(nxt.first >> i & 1); } void calc (int cost, int u) { mark[u] = 1; d[u] = cost + pre; pre = d[u]; if (cost > 1e6) assert(0); for(auto &it : adj[u]) { int v, w; tie(v, w) = it; if (d[v] > d[u] + w) q.push({d[v] = d[u] + w, v}); } } } // namespace 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 < N; i++) adj[i].clear(); for (int i = 0; i < A; ++i) { ::add_edge(U[i], V[i], C[i]); } ::init(); if (N > 1) ::add(); Answer(); } bool bitA[100]; int cntA, costB, uB; bool curA; void ReceiveA(bool x) { bitA[cntA++] = x; if (!curA && cntA == M1) { costB = 0; for(int i = 0; i < M1; i++) if (bitA[i]) costB |= (1 << i); // rec costB // cout << costB << " " << cntA << "#\n"; if (nxt.first <= costB) { for(int i = 0; i < M2; i++) SendA(nxt.second >> i & 1); // send uA calc(nxt.first, nxt.second); if (++loop < ::n - 1) ::add(); } else curA = 1; cntA = 0; // cout << costB << " " << curA << " #\n"; } if (curA && cntA == M2) { uB = 0; for(int i = 0; i < M2; i++) if (bitA[i]) uB |= (1 << i); // rec uB // for(int i = 0; i < M2; i++) cout << bitA[i]; cout << endl; // cout << costB << " " << uB << "\n"; // cout << curA << " " << cntA << "\n"; calc(costB, uB); cntA = curA = 0; if (++loop < ::n - 1) ::add(); } } std::vector<int> Answer() { std::vector<int> ans(::n); for (int k = 0; k < ::n; ++k) { ans[k] = ::d[k]; } return ans; }
#include "Baijan.h" #include <vector> #include<bits/stdc++.h> using namespace std; const int M1 = 9, M2 = 11; namespace { const int N = 2e3 + 10; int n; int cnt, pre; int d[N]; bool mark[N]; vector<pair<int, int> > adj[N]; #define ii pair<int, int> priority_queue<ii, vector<ii>, greater<ii> > q; void init () { mark[0] = 1; for(int i = 1; i < n; i++) mark[i] = 0, d[i] = (1 << 20) - 1; for(auto &it : adj[0]) { int v, w; tie(v, w) = it; q.push({d[v] = w, v}); } } void add_edge (int u, int v, int w) { adj[u].emplace_back(v, w); adj[v].emplace_back(u, w); } pair<int, int> nxt; void add () { while (!q.empty() && mark[q.top().second]) q.pop(); if (q.empty()) { nxt = make_pair((1 << 20) - 1, (1 << 11) - 1); return; } int cost, u; tie(cost, u) = q.top(); nxt = make_pair(cost - pre, u); } void calc (int cost, int u) { mark[u] = 1; d[u] = cost + pre; pre = d[u]; for(auto &it : adj[u]) { int v, w; tie(v, w) = it; if (d[v] > d[u] + w) q.push({d[v] = d[u] + w, v}); } } } // namespace void InitB(int N, int B, std::vector<int> S, std::vector<int> T, std::vector<int> D) { ::n = N; for(int i = 0; i < N; i++) adj[i].clear(); for(int i = 0; i < B; i++) { ::add_edge(S[i], T[i], D[i]); } ::init(); } bool bitB[100]; int cntB, costA, uA; bool curB; void ReceiveB(bool y) { bitB[cntB++] = y; if (!curB && cntB == M1) { costA = 0; ::add(); // cout << nxt.first << " " << nxt.second << "@@\n"; for(int i = 0; i < M1; i++) if (bitB[i]) costA |= (1 << i); // rec costA // cout << costA << "@\n"; // cout << nxt.first << " SendcostB\n"; for(int i = 0; i < M1; i++) SendB(nxt.first >> i & 1); // send costB if (costA <= nxt.first) curB = 1; else { // cout << nxt.second << " SendUB\n"; // for(int i = 0; i < M2; i++) cout << (nxt.second >> i & 1); cout << "??" << endl; for(int i = 0; i < M2; i++) SendB(nxt.second >> i & 1); // send uB calc(nxt.first, nxt.second); } cntB = 0; } if (curB && cntB == M2) { // rec uA uA = 0; for(int i = 0; i < M2; i++) if (bitB[i]) uA |= (1 << i); // rec uA calc(costA, uA); cntB = curB = 0; } }

Compilation message (stderr)

Baijan.cpp:12:5: warning: '{anonymous}::cnt' defined but not used [-Wunused-variable]
   12 | int cnt, pre;
      |     ^~~
#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...