# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1041881 | juicy | Two Transportations (JOI19_transportations) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "Azer.h"
#include <bits/stdc++.h>
using namespace std;
namespace {
void __print() {
cerr << "]\n";
}
template<class T, class... V>
void __print(T t, V... v) {
cerr << t;
if (sizeof...(v)) {
cerr << ", ";
}
__print(v...);
}
#define debug(x...) cerr << "[" << #x << "] = ["; __print(x);
const int inf = 1e9;
int N, MX, value, index, cur, best, ver;
vector<int> D;
vector<bool> vis;
vector<vector<array<int, 2>>> g;
void send(int x, int b) {
for (int i = 0; i < b; ++i) {
SendA(x >> i & 1);
}
}
void add(int u) {
vis[u] = 1;
MX = D[u];
for (auto [v, w] : g[u]) {
D[v] = min(D[v], D[u] + w);
}
}
void upd() {
index = -1;
for (int i = 0; i < N; ++i) {
if (!vis[i] && (index == -1 || D[i] < D[index])) {
index = i;
}
}
if (~index) {
best = min(501, D[index] - MX);
send(best, 9);
}
}
}
void ReceiveA(bool x) {
if (cur < 9) {
if (x) {
value += 1 << cur;
}
if (++cur == 9 && best < value) {
send(index, 11);
add(index);
value = cur = 0;
upd();
}
} else {
if (x) {
ver += 1 << cur - 9;
}
if (++cur == 20) {
D[ver] = min(D[ver], value + MX);
add(ver);
value = cur = ver = 0;
upd();
}
}
}
void InitA(int N, int M, std::vector<int> U, std::vector<int> V, std::vector<int> C) {
::N = N;
vis.resize(N);
g.resize(N);
D.resize(N, inf);
MX = 0;
for (int i = 0; i < M; ++i) {
g[U[i]].push_back({V[i], C[i]});
g[V[i]].push_back({U[i], C[i]});
}
vis[0] = 1;
D[0] = 0;
add(0);
upd();
}
vector<int> Answer() {
return D;
}
#include "Baijan.h"
#include <bits/stdc++.h>
using namespace std;
namespace {
void __print() {
cerr << "]\n";
}
template<class T, class... V>
void __print(T t, V... v) {
cerr << t;
if (sizeof...(v)) {
cerr << ", ";
}
__print(v...);
}
#define debug(x...) cerr << "[" << #x << "] = ["; __print(x);
const int inf = 1e9;
int N, MX, value, index, cur, best, ver;
vector<int> D;
vector<bool> vis;
vector<vector<array<int, 2>>> g;
void send(int x, int b) {
for (int i = 0; i < b; ++i) {
SendB(x >> i & 1);
}
}
void add(int u) {
vis[u] = 1;
MX = D[u];
for (auto [v, w] : g[u]) {
D[v] = min(D[v], D[u] + w);
}
}
void upd() {
index = -1;
for (int i = 0; i < N; ++i) {
if (!vis[i] && (index == -1 || D[i] < D[index])) {
index = i;
}
}
if (~index) {
best = min(501, D[index] - MX);
send(best, 9);
}
}
}
void InitB(int N, int M, std::vector<int> S, std::vector<int> T, std::vector<int> W) {
::N = N;
g.resize(N);
vis.resize(N);
D.resize(N, inf);
MX = 0;
for (int i = 0; i < M; ++i) {
g[S[i]].push_back({T[i], W[i]});
g[T[i]].push_back({S[i], W[i]});
}
vis[0] = 1;
D[0] = 0;
add(0);
upd();
}
void ReceiveB(bool y) {
if (cur < 9) {
if (y) {
value += 1 << cur;
}
if (++cur == 9 && best < value) {
send(index, 11);
add(index);
value = cur = 0;
upd();
}
} else {
if (y) {
ver += 1 << cur - 9;
}
if (++cur == 20) {
D[ver] = min(D[ver], value + MX);
add(ver);
value = cur = ver = 0;
upd();
}
}
}