이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "Azer.h"
#include <vector>
#include <queue>
using namespace std;
namespace{
struct edge{
int v,cost;
bool operator<(const edge &t)const{
return cost>t.cost;
}
};
const int INF=1e9,cnt_cost=9,cnt_v=11;
int N,cnt,cnt_query,receive_cost,receive_v,you_cost,sent_cost;
edge closest;
bool cur_mode;
vector<int> Dist;
vector<bool> Used;
vector<vector<edge>> Edge;
priority_queue<edge> Q;
void my_send(int cnt,int x){
for (int i=0; i<cnt; i++)
SendA(x&(1<<i));
}
edge get_closest(){
while (!Q.empty()){
if (!Used[Q.top().v])
return Q.top();
Q.pop();
}
return {-1,-1};
}
void update_and_send(edge t){
Dist[t.v]=t.cost;
Used[t.v]=true;
if (cnt_query==N-1)
return;
for (edge i:Edge[t.v]){
if (Used[i.v])
continue;
Q.push({i.v,Dist[t.v]+i.cost});
}
closest=get_closest();
if (closest.v==-1)
my_send(cnt_cost,-1);
else
my_send(cnt_cost,closest.cost-sent_cost);
}
}
void InitA(int n,int a,vector<int> u,vector<int> v,vector<int> c){
N=n;
cnt=cnt_query=receive_cost=receive_v=sent_cost=0;
cur_mode=false;
Dist.resize(N);
Used.resize(N);
Edge.resize(N);
for (int i=0; i<N; i++){
Dist[i]=INF;
Used[i]=false;
}
for (int i=0; i<a; i++){
Edge[u[i]].push_back({v[i],c[i]});
Edge[v[i]].push_back({u[i],c[i]});
}
update_and_send({0,0});
}
void ReceiveA(bool x){
if (!cur_mode&&cnt<cnt_cost){
receive_cost+=x*(1<<cnt);
cnt++;
}
if (cur_mode&&cnt<cnt_v){
receive_v+=x*(1<<cnt);
cnt++;
}
if (!cur_mode&&cnt==cnt_cost){
cnt_query++;
if (receive_cost!=(1<<cnt_cost)-1)
you_cost=sent_cost+receive_cost;
if (receive_cost==(1<<cnt_cost)-1||closest.cost!=-1&&you_cost>=closest.cost){
Q.pop();
my_send(cnt_v,closest.v);
sent_cost=closest.cost;
update_and_send(closest);
}
else{
sent_cost=you_cost;
cur_mode=true;
}
cnt=receive_cost=0;
}
if (cur_mode&&cnt==cnt_v){
update_and_send({receive_v,you_cost});
cnt=receive_v=0;
cur_mode=false;
}
}
vector<int> Answer(){
return Dist;
}
#include "Baijan.h"
#include <vector>
#include <queue>
using namespace std;
namespace{
struct edge{
int v,cost;
bool operator<(const edge &t)const{
return cost>t.cost;
}
};
const int INF=1e9,cnt_cost=9,cnt_v=11;
int N,cnt,receive_cost,receive_v,you_cost,sent_cost;
edge closest;
bool cur_mode;
vector<int> Dist;
vector<bool> Used;
vector<vector<edge>> Edge;
priority_queue<edge> Q;
void my_send(int cnt,int x){
for (int i=0; i<cnt; i++)
SendB(x&(1<<i));
}
edge get_closest(){
while (!Q.empty()){
if (!Used[Q.top().v])
return Q.top();
Q.pop();
}
return {-1,-1};
}
void update_closest(edge t){
Dist[t.v]=t.cost;
Used[t.v]=true;
for (edge i:Edge[t.v]){
if (Used[i.v])
continue;
Q.push({i.v,Dist[t.v]+i.cost});
}
}
}
void InitB(int n,int b,vector<int> s,vector<int> t,vector<int> d){
N=n;
cnt=receive_cost=receive_v=sent_cost=0;
cur_mode=false;
Dist.resize(N);
Used.resize(N);
Edge.resize(N);
for (int i=1; i<N; i++){
Dist[i]=INF;
Used[i]=false;
}
for (int i=0; i<b; i++){
Edge[s[i]].push_back({t[i],d[i]});
Edge[t[i]].push_back({s[i],d[i]});
}
update_closest({0,0});
}
void ReceiveB(bool y){
if (!cur_mode&&cnt<cnt_cost){
receive_cost+=y*(1<<cnt);
cnt++;
}
if (cur_mode&&cnt<cnt_v){
receive_v+=y*(1<<cnt);
cnt++;
}
if (!cur_mode&&cnt==cnt_cost){
if (receive_cost!=(1<<cnt_cost)-1)
you_cost=sent_cost+receive_cost;
closest=get_closest();
if (closest.v==-1)
my_send(cnt_cost,-1);
else
my_send(cnt_cost,closest.cost-sent_cost);
if (receive_cost==(1<<cnt_cost)-1||closest.cost!=-1&&you_cost>closest.cost){
Q.pop();
update_closest(closest);
sent_cost=closest.cost;
my_send(cnt_v,closest.v);
}
else{
sent_cost=you_cost;
cur_mode=true;
}
cnt=receive_cost=0;
}
if (cur_mode&&cnt==cnt_v){
update_closest({receive_v,you_cost});
cnt=receive_v=0;
cur_mode=false;
}
}
컴파일 시 표준 에러 (stderr) 메시지
Azer.cpp: In function 'void ReceiveA(bool)':
Azer.cpp:79:60: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
79 | if (receive_cost==(1<<cnt_cost)-1||closest.cost!=-1&&you_cost>=closest.cost){
| ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Baijan.cpp: In function 'void ReceiveB(bool)':
Baijan.cpp:76:60: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
76 | if (receive_cost==(1<<cnt_cost)-1||closest.cost!=-1&&you_cost>closest.cost){
| ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | 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... |