제출 #475737

#제출 시각아이디문제언어결과실행 시간메모리
475737jk410Two Transportations (JOI19_transportations)C++17
6 / 100
671 ms10008 KiB
#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,cur_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); sent_cost=closest.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=cur_cost=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) cur_cost+=receive_cost; if (receive_cost==(1<<cnt_cost)-1||closest.cost!=-1&&cur_cost>closest.cost){ Q.pop(); cur_cost=closest.cost; my_send(cnt_v,closest.v); update_and_send(closest); } else{ sent_cost=cur_cost; cur_mode=true; } cnt=receive_cost=0; } if (cur_mode&&cnt==cnt_v){ update_and_send({receive_v,cur_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,cur_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=cur_cost=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) cur_cost+=receive_cost; closest=get_closest(); if (closest.v==-1) my_send(cnt_cost,-1); else{ my_send(cnt_cost,closest.cost-sent_cost); sent_cost=closest.cost; } if (receive_cost==(1<<cnt_cost)-1||closest.cost!=-1&&cur_cost>closest.cost){ Q.pop(); cur_cost=closest.cost; update_closest(closest); my_send(cnt_v,closest.v); } else{ sent_cost=cur_cost; cur_mode=true; } cnt=receive_cost=0; } if (cur_mode&&cnt==cnt_v){ update_closest({receive_v,cur_cost}); cnt=receive_v=0; cur_mode=false; } }

컴파일 시 표준 에러 (stderr) 메시지

Azer.cpp: In function 'void ReceiveA(bool)':
Azer.cpp:81:60: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   81 |         if (receive_cost==(1<<cnt_cost)-1||closest.cost!=-1&&cur_cost>closest.cost){
      |                                            ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~

Baijan.cpp: In function 'void ReceiveB(bool)':
Baijan.cpp:78:60: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   78 |         if (receive_cost==(1<<cnt_cost)-1||closest.cost!=-1&&cur_cost>closest.cost){
      |                                            ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...