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 <vector>
#include <algorithm>
namespace AAA{
int N, r1 = 0, r2 = 0;
int w[2010][2010], D[2010], vis[2010];
int count = 0, bef = 0, ccc = 0, cur = 0, cpv = 0;
void Make(int num, int x) {
if (num == 9)ccc++;
int i;
for (i = 0; i < num; i++) {
SendA((x >> i) & 1);
}
}
void Calc() {
int i, Mn = 1e8, pv = -1, diff;
for (i = 0; i < N; i++) {
if (Mn > D[i] && !vis[i]) {
Mn = D[i], pv = i;
}
}
cur = Mn;
cpv = pv;
if (pv == -1) diff = 511, pv = 2047;
}
void receive(bool x) {
int tt = x;
count++;
if (count <= 9) {
r2 += (tt << (count-1));
}
if (count == 9) {
Calc();
if (bef + r2 >= cur) {
Make(11, cpv);
vis[cpv] = 1;
count = 0;
bef = cur;
r1 = r2 = 0;
if (ccc >= N)return;
for (int i = 0; i < N; i++) {
D[i] = std::min(D[i], D[cpv] + w[cpv][i]);
}
Calc();
Make(9, std::min(cur - bef,511));
return;
}
}
if (count <= 9)return;
r1 += (tt << (count - 10));
if (count == 20) {
D[r1] = std::min(D[r1], bef + r2);
vis[r1] = 1;
for (int i = 0; i < N; i++) {
D[i] = std::min(D[i], D[r1] + w[r1][i]);
}
bef = bef + r2;
count = 0;
r1 = r2 = 0;
if (ccc >= N)return;
Calc();
Make(9, std::min(cur - bef, 511));
return;
}
}
void init(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++) {
D[i] = 1e9;
vis[i] = 0;
for (int j = 0; j < N; j++) {
if (i != j)w[i][j] = 1e9;
else w[i][j] = 0;
}
}
D[0] = 0;
for (int i = 0; i < U.size(); i++) {
w[U[i]][V[i]] = std::min(w[U[i]][V[i]], C[i]);
w[V[i]][U[i]] = std::min(w[V[i]][U[i]], C[i]);
}
Calc();
Make(9, cur);
}
std::vector<int> answer() {
std::vector<int> ans(N);
for (int k = 0; k < N; ++k) {
ans[k] = D[k];
}
return ans;
}
}; // namespace
void InitA(int N, int A, std::vector<int> U, std::vector<int> V,
std::vector<int> C) {
AAA::init(N, A, U, V, C);
}
void ReceiveA(bool x) {
AAA::receive(x);
}
std::vector<int> Answer() {
return AAA::answer();
}
#include "Baijan.h"
#include <vector>
#include <algorithm>
namespace BBB{
int N, r1 = 0, r2 = 0;
int w[2010][2010], D[2010], vis[2010];
int count = 0, bef = 0, ccc = 0, cur = 0, cpv = 0;
void Make(int num, int x) {
if (num == 9)ccc++;
int i;
for (i = 0; i < num; i++) {
SendB((x >> i) & 1);
}
}
void Calc() {
int i, Mn = 1e8, pv = -1, diff;
for (i = 0; i < N; i++) {
if (Mn > D[i] && !vis[i]) {
Mn = D[i], pv = i;
}
}
cur = Mn;
cpv = pv;
if (pv == -1) diff = 511, pv = 2047;
}
void receive(bool y) {
int tt = y;
count++;
if (count <= 9) {
r2 += (tt << (count-1));
}
if (count == 9) {
Calc();
if (bef + r2 > cur) {
Make(11, cpv);
vis[cpv] = 1;
count = 0;
bef = cur;
r1 = r2 = 0;
if (ccc >= N)return;
for (int i = 0; i < N; i++) {
D[i] = std::min(D[i], D[cpv] + w[cpv][i]);
}
Calc();
Make(9, std::min(cur - bef, 511));
return;
}
}
if (count <= 9)return;
r1 += (tt << (count - 10));
if (count == 20) {
D[r1] = std::min(D[r1], bef + r2);
vis[r1] = 1;
for (int i = 0; i < N; i++) {
D[i] = std::min(D[i], D[r1] + w[r1][i]);
}
bef = bef + r2;
count = 0;
r1 = r2 = 0;
if (ccc >= N)return;
Calc();
Make(9, std::min(cur - bef,511));
return;
}
}
void init(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++) {
D[i] = 1e9;
vis[i] = 0;
for (int j = 0; j < N; j++) {
if (i != j)w[i][j] = 1e9;
else w[i][j] = 0;
}
}
D[0] = 0;
for (int i = 0; i < U.size(); i++) {
w[U[i]][V[i]] = std::min(w[U[i]][V[i]], C[i]);
w[V[i]][U[i]] = std::min(w[V[i]][U[i]], C[i]);
}
Calc();
Make(9, cur);
}
} // namespace
void InitB(int N, int B, std::vector<int> S, std::vector<int> T,
std::vector<int> D) {
BBB::init(N, B, S, T, D);
}
void ReceiveB(bool y) {
BBB::receive(y);
}
Compilation message (stderr)
Azer.cpp: In function 'void AAA::Calc()':
Azer.cpp:17:29: warning: variable 'diff' set but not used [-Wunused-but-set-variable]
int i, Mn = 1e8, pv = -1, diff;
^~~~
Azer.cpp: In function 'void AAA::init(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
Azer.cpp:84:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < U.size(); i++) {
~~^~~~~~~~~~
Baijan.cpp: In function 'void BBB::Calc()':
Baijan.cpp:18:29: warning: variable 'diff' set but not used [-Wunused-but-set-variable]
int i, Mn = 1e8, pv = -1, diff;
^~~~
Baijan.cpp: In function 'void BBB::init(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
Baijan.cpp:86:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < U.size(); i++) {
~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |