제출 #135789

#제출 시각아이디문제언어결과실행 시간메모리
135789dndhkTwo Transportations (JOI19_transportations)C++14
100 / 100
2094 ms85288 KiB
#include "Azer.h" #include <bits/stdc++.h> #define pb push_back #define all(v) ((v).begin(), (v).end()) #define sortv(v) sort(all(v)) #define sz(v) ((int)(v).size()) #define uniqv(v) (v).erase(unique(all(v)), (v).end()) #define umax(a, b) (a)=max((a), (b)) #define umin(a, b) (a)=min((a), (b)) #define FOR(i,a,b) for(int i = (a); i <= (b); i++) #define rep(i,n) FOR(i,1,n) #define rep0(i,n) FOR(i,0,(int)(n)-1) #define FI first #define SE second #define INF 2000000 #define INFLL 1000000000000000000LL using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAX_N = 2000; const int LOG_N = 11; const int LOG_D = 9; namespace { int N; vector<pii> gp[MAX_N+1]; int dist[MAX_N+1]; int vst[MAX_N+1]; int n=0, d=0, cnt=0; int mx; int n2=0, d2=0; bool finish = false; int two = 1; void calc(){ vst[n] = true; mx = 0; for(int i=0; i<N; i++){ if(!vst[i]) continue; mx = max(mx, dist[i]); } for(int i=0; i<gp[n].size(); i++){ if(dist[gp[n][i].first]>dist[n] + gp[n][i].second){ dist[gp[n][i].first] = dist[n] + gp[n][i].second; } } n2 = 0; d2 = INF+1; finish = true; for(int i=0; i<N; i++){ if(!vst[i]) finish = false; if(vst[i]) continue; if(dist[i] < d2){ d2 = dist[i]; n2 = i; } } if(finish){ Answer(); return; } d2 -= mx; d2 = min(d2, (1<<9)-1); //cout<<"SendA "<<d2<<endl; for(int i=0; i<LOG_D; i++){ SendA((bool)(d2%2)); d2/=2; } } void make_ans(){ dist[n] = d; calc(); n = d = cnt = 0; two = 1; } void send_idx(){ //cout<<"SendA "<<n2<<endl; n = n2; for(int i=0; i<LOG_N; i++){ SendA((bool)(n2%2)); n2/=2; } calc(); } } void InitA(int N, int A, vector<int> U, vector<int> V, vector<int> C) { ::N = N; for (int i = 0; i < A; ++i) { gp[U[i]].pb({V[i], C[i]}); gp[V[i]].pb({U[i], C[i]}); } vst[0] = 1; dist[0] = 0; for(int i=1; i<N; i++){ dist[i] = INF; } mx = 0; calc(); } void ReceiveA(bool x) { if(cnt<LOG_D){ d += (int)x * two; two*=2; }else if(cnt < LOG_D+LOG_N){ n += (int)x * two; two*=2; } cnt++; if(cnt==LOG_D){ if(d > 500){ send_idx(); n = d = cnt = 0; } two = 1; } if(cnt==LOG_D+LOG_N){ d+=mx; make_ans(); } } vector<int> Answer() { vector<int> ans(N); for(int i=0; i<N; i++){ ans[i] = dist[i]; } return ans; }
#include "Baijan.h" #include <bits/stdc++.h> #define pb push_back #define all(v) ((v).begin(), (v).end()) #define sortv(v) sort(all(v)) #define sz(v) ((int)(v).size()) #define uniqv(v) (v).erase(unique(all(v)), (v).end()) #define umax(a, b) (a)=max((a), (b)) #define umin(a, b) (a)=min((a), (b)) #define FOR(i,a,b) for(int i = (a); i <= (b); i++) #define rep(i,n) FOR(i,1,n) #define rep0(i,n) FOR(i,0,(int)(n)-1) #define FI first #define SE second #define INF 2000000000 #define INFLL 1000000000000000000LL using namespace std; const int MAX_N = 2000; const int LOG_N = 11; const int LOG_D = 9; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; namespace { int N; vector<pii> gp[MAX_N+1]; int dist[MAX_N+1]; int vst[MAX_N+1]; int mx; int n=0, d=0, cnt=0; int n2=0, d2=0; int two = 1; bool finish = false; void calc2(){ mx = 0; for(int i=0; i<N; i++){ if(!vst[i]) continue; mx = max(mx, dist[i]); } for(int i=0; i<gp[n].size(); i++){ if(dist[gp[n][i].first]>dist[n] + gp[n][i].second){ dist[gp[n][i].first] = dist[n] + gp[n][i].second; } } n2 = 0; d2 = INF+1; for(int i=0; i<N; i++){ if(vst[i]) continue; if(dist[i] < d2){ d2 = dist[i]; n2 = i; } } } void make_ans2(){ vst[n] = true; dist[n] = d; //cout<<"*"<<n<<" "<<d<<" "<<mx<<endl<<endl; mx = 0; calc2(); //cout<<"*"<<n<<" "<<d<<" "<<mx<<endl; cnt = 0; } } void InitB(int N, int B, vector<int> S, vector<int> T, vector<int> D) { if(N==1) return; ::N = N; for(int i=0; i<B; i++){ gp[S[i]].pb({T[i], D[i]}); gp[T[i]].pb({S[i], D[i]}); } vst[0] = true; for(int i=1; i<N; i++) dist[i] = INF; mx = 0; calc2(); cnt = 0; } void ReceiveB(bool y) { if(cnt==0){ n = d = 0; two = 1; } //cout<<"#"<<cnt<<" "<<y<<endl; if(cnt<LOG_D){ d += (int)y*two; }else if(cnt<LOG_D+LOG_N){ n += (int)y*two; } two*=2; cnt++; if(cnt==LOG_D){ two = 1; d += mx; if(d<d2){ //cout<<"SendB 255"<<endl; for(int i=0; i<LOG_D; i++){ SendB(1); } }else{ d2-=mx; //cout<<"SendB "<<d2<<endl; for(int i=0; i<LOG_D; i++){ SendB((bool)(d2%2)); d2/=2; } //cout<<"SendB "<<n2<<endl; n = n2; vst[n] = true; for(int i=0; i<LOG_N; i++){ SendB((bool)(n2%2)); n2/=2; } calc2(); cnt = 0; } } if(cnt==LOG_D+LOG_N){ make_ans2(); } }

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

Azer.cpp: In function 'void {anonymous}::calc()':
Azer.cpp:50:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0; i<gp[n].size(); i++){
                      ~^~~~~~~~~~~~~

Baijan.cpp: In function 'void {anonymous}::calc2()':
Baijan.cpp:47:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0; i<gp[n].size(); i++){
                      ~^~~~~~~~~~~~~
Baijan.cpp: At global scope:
Baijan.cpp:39:10: warning: '{anonymous}::finish' defined but not used [-Wunused-variable]
     bool finish = false;
          ^~~~~~
#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...