Submission #926651

#TimeUsernameProblemLanguageResultExecution timeMemory
926651daoquanglinh2007Two Transportations (JOI19_transportations)C++17
100 / 100
637 ms61072 KiB
#include "Azer.h" #include <bits/stdc++.h> using namespace std; #define pii pair <int, int> #define fi first #define se second #define mp make_pair const int NM = 2000, inf = 1e9+7; namespace Azer{ int N; vector <pii> adj[NM+5]; int d[NM+5]; bool fix[NM+5]; priority_queue <pii, vector <pii>, greater <pii> > Q; int p = 0, cur = 0, pre; int log_od = 0, log_op = 0, od = 0, op = 0; void Update(int u, int val){ d[u] = val; fix[u] = 1; for (pii _ : adj[u]){ int v = _.fi, w = _.se; if (fix[v]) continue; if (d[u]+w < d[v]){ d[v] = d[u]+w; Q.push(mp(d[v], v)); } } pre = val; } void Getcur(){ cur = +inf; while (!Q.empty() && fix[Q.top().se]) Q.pop(); if (!Q.empty()){ p = Q.top().se; cur = d[p]; } } void SendInt(int LOG, int x){ for (int i = 0; i < LOG; i++) SendA((x>>i)&1); } void Init(int _N, int M, vector <int> U, vector <int> V, vector <int> C){ N = _N; for (int i = 0; i < M; i++){ adj[U[i]].push_back(mp(V[i], C[i])); adj[V[i]].push_back(mp(U[i], C[i])); } for (int i = 0; i < N; i++) d[i] = +inf; Update(0, 0); Getcur(); if (cur == +inf) SendInt(9, (1<<9)-1); else SendInt(9, cur-pre); } void Receive(bool x){ if (log_od < 9){ if (x) od += (1<<log_od); log_od++; } if (log_od < 9) return; if (od == (1<<9)-1 && cur == +inf) return; if (cur-pre <= od){ SendInt(11, p); Update(p, cur); Getcur(); log_od = log_op = od = op = 0; if (cur == +inf) SendInt(9, (1<<9)-1); else SendInt(9, cur-pre); return; } log_od++; if (log_od == 10) return; if (x) op += (1<<log_op); log_op++; if (log_op == 11){ Update(op, pre+od); Getcur(); log_od = log_op = od = op = 0; if (cur == +inf) SendInt(9, (1<<9)-1); else SendInt(9, cur-pre); } } vector <int> Get(){ vector <int> ans(N); for (int i = 0; i < N; i++) ans[i] = d[i]; return ans; } } void InitA(int N, int A, vector <int> U, vector <int> V, vector <int> C){ Azer::Init(N, A, U, V, C); } void ReceiveA(bool x){ Azer::Receive(x); } vector <int> Answer(){ return Azer::Get(); }
#include "Baijan.h" #include <bits/stdc++.h> using namespace std; #define pii pair <int, int> #define fi first #define se second #define mp make_pair const int NM = 2000, inf = 1e9+7; namespace Baijan{ int N; vector <pii> adj[NM+5]; int d[NM+5]; bool fix[NM+5]; priority_queue <pii, vector <pii>, greater <pii> > Q; int p = 0, cur = 0, pre; int log_od = 0, log_op = 0, od = 0, op = 0; void Update(int u, int val){ d[u] = val; fix[u] = 1; for (pii _ : adj[u]){ int v = _.fi, w = _.se; if (fix[v]) continue; if (d[u]+w < d[v]){ d[v] = d[u]+w; Q.push(mp(d[v], v)); } } pre = val; } void Getcur(){ cur = +inf; while (!Q.empty() && fix[Q.top().se]) Q.pop(); if (!Q.empty()){ p = Q.top().se; cur = d[p]; } } void SendInt(int LOG, int x){ for (int i = 0; i < LOG; i++) SendB((x>>i)&1); } void Init(int _N, int M, vector <int> U, vector <int> V, vector <int> C){ N = _N; for (int i = 0; i < M; i++){ adj[U[i]].push_back(mp(V[i], C[i])); adj[V[i]].push_back(mp(U[i], C[i])); } for (int i = 0; i < N; i++) d[i] = +inf; Update(0, 0); Getcur(); if (cur == +inf) SendInt(9, (1<<9)-1); else SendInt(9, cur-pre); } void Receive(bool x){ if (log_od < 9){ if (x) od += (1<<log_od); log_od++; } if (log_od < 9) return; if (od == (1<<9)-1 && cur == +inf) return; if (cur-pre < od){ SendInt(11, p); Update(p, cur); Getcur(); log_od = log_op = od = op = 0; if (cur == +inf) SendInt(9, (1<<9)-1); else SendInt(9, cur-pre); return; } log_od++; if (log_od == 10) return; if (x) op += (1<<log_op); log_op++; if (log_op == 11){ Update(op, pre+od); Getcur(); log_od = log_op = od = op = 0; if (cur == +inf) SendInt(9, (1<<9)-1); else SendInt(9, cur-pre); } } } void InitB(int N, int B, vector <int> S, vector <int> T, vector <int> D){ Baijan::Init(N, B, S, T, D); } void ReceiveB(bool y){ Baijan::Receive(y); }
#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...