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"
using namespace std;
typedef long long int ll;
namespace azer{
int n;
vector<pair<int,int>> graf[2009];
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> djikstra;
int poprz=0;
int dst[2009];
int wczyt=0,ter=0;
pair<int,int> cel;
int nr=0;
bool apuste=0,bpuste=0;
void napisz(int x){
for (int i=0;i<11;i++) SendA(x & (1<<i));
}
void nast(int v, int d){
//if (nr<10) cout << "A:" << v << ' ' << d << '\n';
dst[v] = d;
poprz = d;
for (pair<int,int> x:graf[v]){
if (dst[x.first] > d+x.second){
dst[x.first] = d+x.second;
djikstra.push({dst[x.first],x.first});
}
}
while(!djikstra.empty() && dst[djikstra.top().second] < djikstra.top().first) djikstra.pop();
if (djikstra.empty()){
apuste = 1;
napisz((1<<11)-1);
napisz(1);
nr++;
return;
//if (nr<10) cout << "A empty\n";
}
else apuste=0;
//if (nr<10) cout << "A->B " << djikstra.top().first-poprz << ' ' << djikstra.top().second << '\n';
napisz(djikstra.top().first-poprz);
napisz(djikstra.top().second);
nr++;
}
} // namespace
void InitA(int N, int A, vector<int> U, vector<int> V,
vector<int> C) {
azer::n = N;
for (int x=0;x<A;x++){
azer::graf[U[x]].push_back({V[x],C[x]});
azer::graf[V[x]].push_back({U[x],C[x]});
}
for (int x=0;x<=azer::n;x++) azer::dst[x] = 1e9+9;
azer::nast(0,0);
azer::cel = {-1,-1};
}
void ReceiveA(bool x) {
azer::wczyt += (1<<azer::ter) * x;
azer::ter++;
if (azer::ter==11){
if (azer::cel.second == -1){
azer::cel.second = azer::wczyt + azer::poprz;
if (azer::wczyt == (1<<11)-1) azer::bpuste=1;
else azer::bpuste = 0;
}
else{
azer::cel.first = azer::wczyt;
//if (nr<10) cout << "A ma:" << djikstra.top().first << ' ' << cel.second << '\n';
//if (nr<10) cout << "A dostalo: " << cel.first << ' ' << cel.second << '\n';
//if (nr<10) cout << "A twierdzi o empt: " << apuste << ' ' << bpuste << '\n';
if (azer::apuste && azer::bpuste) return;
if (!azer::apuste && (azer::djikstra.top().first < azer::cel.second || azer::bpuste)){
azer::cel.second = azer::djikstra.top().first;
azer::cel.first = azer::djikstra.top().second;
azer::djikstra.pop();
//if (nr<10) cout << "hi\n";
}
azer::nast(azer::cel.first,azer::cel.second);
azer::cel = {-1,-1};
}
azer::ter = 0;
azer::wczyt = 0;
}
}
vector<int> Answer() {
vector<int> odp;
for (int x=0;x<azer::n;x++) odp.push_back(azer::dst[x]);
return odp;
}
#include "Baijan.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
namespace b{
int n;
vector<pair<int,int>> graf[2009];
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> djikstra;
int poprz=0;
int dst[2009];
int wczyt=0,ter=0;
pair<int,int> cel;
pair<int,int> wczes;
int nr=0;
bool apuste=0,bpuste=0;
void napisz(int x){
for (int i=0;i<11;i++) SendB(x & (1<<i));
}
void nast(int v, int d){
//if (nr<10) cout << "B:" << v << ' ' << d << '\n';
dst[v] = d;
poprz = d;
//if (nr<10) cout << "lelum " << poprz << ' ' << d << '\n';
for (pair<int,int> x:graf[v]){
if (dst[x.first] > d+x.second){
dst[x.first] = d+x.second;
djikstra.push({dst[x.first],x.first});
}
}
while(!djikstra.empty() && dst[djikstra.top().second] < djikstra.top().first) djikstra.pop();
if (djikstra.empty()){
bpuste = 1;
napisz((1<<11)-1);
napisz(1);
nr++;
//if (nr<10) cout << "B empty\n";
return;
}
else bpuste=0;
//if (nr<10) cout << "B->A " << djikstra.top().first-poprz << ' ' << djikstra.top().second << '\n';
napisz(djikstra.top().first-poprz);
napisz(djikstra.top().second);
nr++;
}
} // namespace
void InitB(int N, int B, vector<int> S, vector<int> T,
vector<int> D) {
b::n = N;
for (int x=0;x<B;x++){
b::graf[T[x]].push_back({S[x],D[x]});
b::graf[S[x]].push_back({T[x],D[x]});
}
for (int x=0;x<=b::n;x++) b::dst[x] = 1e9+9;
b::cel = {-1,-1};
b::wczes = {0,0};
}
void ReceiveB(bool y) {
b::wczyt += (1<<b::ter) * y;
b::ter++;
if (b::ter==11){
if (b::cel.second == -1){
b::cel.second = b::wczyt;
if (b::cel.second == (1<<11)-1) b::apuste=1;
else b::apuste=0;
}
else{
int temb = b::poprz;
//if (nr<10) cout << "B jestem debilem: " << poprz << '\n';
b::nast(b::wczes.first,b::wczes.second);
b::cel.second += b::poprz;
b::cel.first = b::wczyt;
//if (nr<10) cout << "B dostalo: " << cel.first << ' ' << cel.second << '\n';
//if (nr<10) cout << "nr 2: " << apuste << ' ' << bpuste << '\n';
if (b::apuste && b::bpuste) return;
if (!b::bpuste && (b::djikstra.top().first < b::cel.second || b::apuste)){
b::cel.second = b::djikstra.top().first;
b::cel.first = b::djikstra.top().second;
b::djikstra.pop();
}
b::wczes = b::cel;
b::cel = {-1,-1};
}
b::ter = 0;
b::wczyt = 0;
}
}
Compilation message (stderr)
Baijan.cpp: In function 'void ReceiveB(bool)':
Baijan.cpp:75:17: warning: unused variable 'temb' [-Wunused-variable]
75 | int temb = b::poprz;
| ^~~~
# | 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... |