이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#include "Azer.h"
namespace {
const int N=2020;
const int SZ=20;
vector<pair<int,int>>g[N];
deque<int>q;
void send(int x,int len){
for(int i=len-1;i>=0;--i)
SendA(x>>i&1);
}
int receive(int len){
assert(q.size()>=len);
int ans=0;
for(int i=0;i<len;++i)
ans*=2,ans+=q.front(),q.pop_front();
return ans;
}
int d[N];
int n;
const int oo=(1<<SZ)-1;
int state=0;
int rest=0;
int kek,mem;
auto cmp=[&](const int a,const int b){
if(d[a]!=d[b])
return d[a]<d[b];
return a<b;
};
set<int,decltype(cmp)>st(cmp);
void relax(){
// cerr<<"a "<<kek<<' '<<mem<<'\n';
st.erase(kek);
d[kek]=mem;
for(auto& [a,b]:g[kek]){
if(d[kek]+b<d[a]){
st.erase(a);
d[a]=d[kek]+b;
st.insert(a);
}
}
}
void proc(){
int num=0;
for(int x:q)num*=2,num+=x;
q.clear();
if(!st.size())return;
if(state==0){
kek=*st.begin();
mem=d[kek];
// cerr<<"a "<<mem<<'\n';
send(mem,SZ);
state=1;
rest=1;
return;
}
if(state==1){
if(num==1){
send(kek,11);
relax();
state=0;
proc();
return;
}
else{
state=2;
rest=SZ;
return;
}
}
if(state==2){
mem=num;
state=3;
rest=11;
return;
}
if(state==3){
kek=num;
relax();
state=0;
proc();
return;
}
}
} // namespace
void InitA(int N, int A, std::vector<int> U, std::vector<int> V,
std::vector<int> C) {
n=N;
for(int i=0;i<A;++i){
g[U[i]].emplace_back(V[i],C[i]);
g[V[i]].emplace_back(U[i],C[i]);
}
fill(d,d+n,oo);
d[0]=0;
for(int i=0;i<n;++i)st.insert(i);
proc();
}
void ReceiveA(bool x) {
q.push_back(x);
if(--rest==0){
proc();
}
}
std::vector<int> Answer() {
vector<int>ans(d,d+n);
return ans;
}
#include<bits/stdc++.h>
using namespace std;
#include "Baijan.h"
namespace {
const int N=2020;
const int SZ=20;
vector<pair<int,int>>g[N];
deque<int>q;
void send(int x,int len){
for(int i=len-1;i>=0;--i)
SendB(x>>i&1);
}
int receive(int len){
assert(q.size()>=len);
int ans=0;
for(int i=0;i<len;++i)
ans*=2,ans+=q.front(),q.pop_front();
return ans;
}
int d[N];
int n;
const int oo=(1<<SZ)-1;
int rest=0;
int state=0;
int kek,mem;
auto cmp=[&](const int a,const int b){
if(d[a]!=d[b])
return d[a]<d[b];
return a<b;
};
set<int,decltype(cmp)>st(cmp);
void relax(){
// cerr<<kek<<' '<<mem<<'\n';
st.erase(kek);
d[kek]=mem;
for(auto& [a,b]:g[kek]){
if(d[kek]+b<d[a]){
st.erase(a);
d[a]=d[kek]+b;
st.insert(a);
}
}
}
void proc(){
int num=0;
for(int x:q)num*=2,num+=x;
q.clear();
// cerr<<num<<'\n';
if(!st.size())return;
if(state==0){
kek=*st.begin();
mem=d[kek];
int di=num;
// cerr<<di<<'\n';
if(mem>=di){
send(1,1);
mem=di;
state=1;
rest=11;
return;
}
else{
// cerr<<"rofl\n";
send(0,1);
send(mem,SZ);
send(kek,11);
state=0;
rest=SZ;
relax();
return;
}
}
if(state==1){
kek=num;
relax();
state=0;
rest=SZ;
return;
}
}
} // namespace
void InitB(int N, int B, std::vector<int> U, std::vector<int> V,
std::vector<int> C) {
n=N;
for(int i=0;i<B;++i){
g[U[i]].emplace_back(V[i],C[i]);
g[V[i]].emplace_back(U[i],C[i]);
}
fill(d,d+n,oo);
d[0]=0;
for(int i=0;i<n;++i)st.insert(i);
rest=SZ;
}
void ReceiveB(bool y) {
q.push_back(y);
if(--rest==0)proc();
}
컴파일 시 표준 에러 (stderr) 메시지
In file included from /usr/include/c++/7/cassert:44:0,
from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:33,
from Azer.cpp:1:
Azer.cpp: In function 'int {anonymous}::receive(int)':
Azer.cpp:15:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
assert(q.size()>=len);
~~~~~~~~^~~
Azer.cpp: At global scope:
Azer.cpp:14:5: warning: 'int {anonymous}::receive(int)' defined but not used [-Wunused-function]
int receive(int len){
^~~~~~~
In file included from /usr/include/c++/7/cassert:44:0,
from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:33,
from Baijan.cpp:1:
Baijan.cpp: In function 'int {anonymous}::receive(int)':
Baijan.cpp:15:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
assert(q.size()>=len);
~~~~~~~~^~~
Baijan.cpp: At global scope:
Baijan.cpp:14:5: warning: 'int {anonymous}::receive(int)' defined but not used [-Wunused-function]
int receive(int len){
^~~~~~~
# | 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... |