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 <bits/stdc++.h>
#include "Azer.h"
#define ff first
#define ss second
using namespace std;
struct Compare {
bool operator()(pair<int,int> a, pair<int,int> b) {
return a > b;
}
};
int GETTING_VAL= 0;
int GETTING_V = 1;
int ans[2001];
int n,m;
vector<pair<int,int>> graf[2001];
priority_queue<pair<int,int>, vector<pair<int,int>>, Compare> pri;
int akt_odl;
int oper;
int how_many_bits;
int num;
int new_v;
int tryb;
void SendNum(int x, int wiel)
{
for(int bit = 0; bit < wiel; bit++)
{
if(x & (1 << bit))
{
SendA(1);
}
else
{
SendA(0);
}
}
}
void InitA(int N, int M, std::vector<int> U, std::vector<int> V, std::vector<int> C)
{
// odw[0] = 1;
ans[0] = 0;
n = N;
m = M;
for(int i = 0; i < m; i++)
{
graf[U[i]].push_back({C[i],V[i]});
graf[V[i]].push_back({C[i],U[i]});
}
for(auto& it: graf[0])
{
pri.push(it);
}
pri.push({1e9,2000});
pair<int,int> t = pri.top();
SendNum(min(t.ff - akt_odl,501),9);
}
void ReceiveA(bool x)
{
if(tryb == GETTING_VAL)
{
if(x) num += (1 << how_many_bits);
how_many_bits++;
if(how_many_bits == 9)
{
oper++;
if(oper == n) return;
while((int)pri.size() != 0 && (ans[pri.top().ss] != 0 || pri.top().ss == 0)) pri.pop();
if(pri.size() == 0) pri.push({1e9,2000});
//cout << num << " val A\n";
//cout << "ja: " << pri.top().ff - akt_odl << ", B: " << num << " akt_odl:"<< akt_odl<<"\n";
if((pri.top().ff - akt_odl <= num && pri.top().ff != 1e9) || num == 501)
{
// cout << "Sending to B: " << pri.top().ss << " info about v\n";
SendNum(pri.top().ss,11);
akt_odl = pri.top().ff;
ans[pri.top().ss] = akt_odl;
for(auto& it: graf[pri.top().ss])
{
pri.push({it.ff + akt_odl, it.ss});
}
how_many_bits = 0;
num = 0;
pri.pop();
while((int)pri.size() != 0 && (ans[pri.top().ss] != 0 || pri.top().ss == 0)) pri.pop();
if(pri.size() == 0) pri.push({1e9,2000});
// cout << "Sending to B: " << min(pri.top().ff - akt_odl,501) << " info about min\n";
SendNum(min(pri.top().ff - akt_odl,501),9); //only for Azer
}
else
{
new_v = 0;
how_many_bits = 0;
tryb = GETTING_V;
}
}
}
else
{
if(x) new_v += (1 << how_many_bits);
how_many_bits++;
if(how_many_bits == 11)
{
// cout << new_v << "new_v A\n";
tryb = GETTING_VAL;
ans[new_v] = akt_odl+num;
akt_odl += num;
//odw[new_v] = 1;
// cout << akt_odl << " akt_odl A\n";
for(auto& it: graf[new_v])
{
pri.push({it.ff + akt_odl, it.ss});
}
how_many_bits = 0;
num = 0;
while((int)pri.size() != 0 && (ans[pri.top().ss] != 0 || pri.top().ss == 0)) pri.pop();
if(pri.size() == 0) pri.push({1e9,2000});
// cout << "Sending to B: " << min(pri.top().ff - akt_odl,501) << " info about min\n";
SendNum(min(pri.top().ff - akt_odl,501),9);
}
}
}
vector<int> Answer()
{
vector<int> ans2;
for(int i = 0; i < n; i++) ans2.push_back(ans[i]);
return ans2;
}
#include <bits/stdc++.h>
#include "Baijan.h"
#define ff first
#define ss second
using namespace std;
namespace {
struct Compare {
bool operator()(pair<int,int> a, pair<int,int> b) {
return a > b;
}
};
int GETTING_VAL= 0;
int GETTING_V = 1;
int ans[2001];
int n,m;
vector<pair<int,int>> graf[2001];
priority_queue<pair<int,int>, vector<pair<int,int>>, Compare> pri;
int akt_odl;
int oper;
int how_many_bits;
int num;
int new_v;
int tryb;
void SendNum(int x, int wiel)
{
for(int bit = 0; bit < wiel; bit++)
{
if(x & (1 << bit))
{
SendB(1);
}
else
{
SendB(0);
}
}
}
}
void InitB(int N, int M, vector<int> U, vector<int> V, vector<int> cost)
{
ans[0] = 0;
n = N;
m = M;
for(int i = 0; i < m; i++)
{
graf[U[i]].push_back({cost[i],V[i]});
graf[V[i]].push_back({cost[i],U[i]});
}
for(auto& it: graf[0])
{
pri.push(it);
}
pri.push({1e9,2000});
pair<int,int> t = pri.top();
SendNum(min(t.ff - akt_odl,501),9);
}
void ReceiveB(bool x)
{
if(tryb == GETTING_VAL)
{
if(x) num += (1 << how_many_bits);
how_many_bits++;
if(how_many_bits == 9)
{
// cout << num << " val B\n";
oper++;
if(oper == n) return;
while((int)pri.size() != 0 && (ans[pri.top().ss] != 0 || pri.top().ss == 0)) pri.pop();
if(pri.size() == 0) pri.push({1e9,2000});
// cout << "ja: " << pri.top().ff - akt_odl << ", A: " << num << " akt_odl:"<< akt_odl<<"\n";
if((pri.top().ff - akt_odl < num && pri.top().ff != 1e9)|| num == 501)
{
// cout << "Sending to A: " << pri.top().ss << " info about v\n";
SendNum(pri.top().ss,11);
akt_odl = pri.top().ff;
ans[pri.top().ss] = akt_odl;
for(auto& it: graf[pri.top().ss])
{
pri.push({it.ff + akt_odl, it.ss});
}
how_many_bits = 0;
num = 0;
pri.pop();
while((int)pri.size() != 0 && (ans[pri.top().ss] != 0 || pri.top().ss == 0)) pri.pop();
if(pri.size() == 0) pri.push({1e9,2000});
//cout << "Sending to A: " << min(pri.top().ff - akt_odl,501) << " info about min\n";
SendNum(min(pri.top().ff - akt_odl,501),9); //only for Azer
}
else
{
new_v = 0;
how_many_bits = 0;
tryb = GETTING_V;
}
}
}
else
{
if(x) new_v += (1 << how_many_bits);
how_many_bits++;
if(how_many_bits == 11)
{
//cout << new_v << "new_v B\n";
tryb = GETTING_VAL;
ans[new_v] = akt_odl+num;
akt_odl += num;
for(auto& it: graf[new_v])
{
pri.push({it.ff + akt_odl, it.ss});
// cout << it.ss << " nowy B\n";
}
how_many_bits = 0;
num = 0;
while((int)pri.size() != 0 && (ans[pri.top().ss] != 0 || pri.top().ss == 0)) pri.pop();
if(pri.size() == 0) pri.push({1e9,2000});
// cout << pri.top().ss << " nowy_max B\n";
// cout << "Sending to A: " << min(pri.top().ff - akt_odl,501) << " info about min\n";
SendNum(min(pri.top().ff - akt_odl,501),9);
}
}
}
# | 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... |