Submission #530032

#TimeUsernameProblemLanguageResultExecution timeMemory
530032fhvirusTwo Transportations (JOI19_transportations)C++17
0 / 100
581 ms35732 KiB
#include "Azer.h" /* #include <bits/stdc++.h> using namespace std; */ // Knapsack DP is harder than FFT. #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; #define ff first #define ss second #define pb emplace_back #define AI(x) begin(x),end(x) #ifdef OWO #define debug(args...) SDF(#args, args) #define OIU(args...) ostream& operator<<(ostream&O,args) #define LKJ(S,B,E,F) template<class...T>OIU(S<T...>s){O<<B;int c=0;for(auto i:s)O<<(c++?", ":"")<<F;return O<<E;} LKJ(vector,'[',']',i)LKJ(deque,'[',']',i)LKJ(set,'{','}',i)LKJ(multiset,'{','}',i)LKJ(unordered_set,'{','}',i)LKJ(map,'{','}',i.ff<<':'<<i.ss)LKJ(unordered_map,'{','}',i.ff<<':'<<i.ss) template<class...T>void SDF(const char* s,T...a){int c=sizeof...(T);if(!c){cerr<<"\033[1;32mvoid\033[0m\n";return;}(cerr<<"\033[1;32m("<<s<<") = (",...,(cerr<<a<<(--c?", ":")\033[0m\n")));} template<class T,size_t N>OIU(array<T,N>a){return O<<vector<T>(AI(a));}template<class...T>OIU(pair<T...>p){return O<<'('<<p.ff<<','<<p.ss<<')';}template<class...T>OIU(tuple<T...>t){return O<<'(',apply([&O](T...s){int c=0;(...,(O<<(c++?", ":"")<<s));},t),O<<')';} #else #define debug(...) ((void)0) #endif namespace { const int kN = 2000; const int kLW = 9; const int kLN = 11; const int INF = INT_MAX; enum State{ sendW = 0, waitW = 1, sendV = 2, waitV = 3 }; int N; vector<pair<int, int>> adj[kN]; int dis[kN], vis[kN]; int lastDis, bestVA, bestWA, bestVB, bestWB; int relaxCount; State currentState; void relax(int u) { vis[u] = true; debug(vector<int>(dis, dis + N)); for (const auto& [v, c]: adj[u]) dis[v] = min(dis[u] + c, dis[v]); debug(vector<int>(dis, dis + N)); bestVA = -1; bestWA = INF; for (int i = 0; i < N; ++i) if (!vis[i] and dis[i] < bestWA) { bestVA = i; bestWA = dis[i]; } debug(bestVA, bestWA); ++relaxCount; } void tellW() { int w = (bestWA == INF ? (1 << kLW) - 1 : bestWA - lastDis); debug("A tellW", bestWA, lastDis, w); for (int l = kLW - 1; l >= 0; --l) SendA(w >> l & 1); } void tellV() { debug("A tellV", bestVA); for (int l = kLN - 1; l >= 0; --l) SendA(bestVA >> l & 1); } int receiveCount, receiveValue; } // namespace void InitA(int N, int A, vector<int> U, vector<int> V, vector<int> C) { ::N = N; for (int i = 0; i < A; ++i) { adj[U[i]].emplace_back(V[i], C[i]); adj[V[i]].emplace_back(U[i], C[i]); } fill(dis, dis + N, INF); fill(vis, vis + N, false); bestVA = -1; bestWA = INF; bestVB = -1; bestWB = INF; dis[0] = 0; lastDis = 0; relaxCount = 0; relax(0); receiveCount = 0; receiveValue = 0; currentState = sendW; tellW(); currentState = waitW; } void ReceiveA(bool x) { receiveValue <<= 1; receiveValue |= x; ++receiveCount; if (currentState == waitW and receiveCount == kLW) { if (receiveValue == (1 << kLW) - 1) bestWB = INF; else bestWB = receiveValue + lastDis; receiveCount = 0; receiveValue = 0; debug("Debug A:"); debug(bestVA, bestWA); debug(bestVB, bestWB); if (bestWA <= bestWB) { currentState = sendV; tellV(); bestVB = -1; bestWB = INF; lastDis = dis[bestVA]; relax(bestVA); if (relaxCount == N) return; currentState = sendW; tellW(); currentState = waitW; } else { currentState = waitV; } } else if (currentState == waitV and receiveCount == kLN) { bestVB = receiveValue; receiveCount = 0; receiveValue = 0; dis[bestVB] = bestWB; lastDis = dis[bestVB]; relax(bestVB); if (relaxCount == N) return; bestVB = -1; bestWB = INF; currentState = sendW; tellW(); currentState = waitW; } } vector<int> Answer() { vector<int> ans(dis, dis + N); return ans; }
#include "Baijan.h" /* #include <bits/stdc++.h> using namespace std; */ // Knapsack DP is harder than FFT. #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; #define ff first #define ss second #define pb emplace_back #define AI(x) begin(x),end(x) #ifdef OWO #define debug(args...) SDF(#args, args) #define OIU(args...) ostream& operator<<(ostream&O,args) #define LKJ(S,B,E,F) template<class...T>OIU(S<T...>s){O<<B;int c=0;for(auto i:s)O<<(c++?", ":"")<<F;return O<<E;} LKJ(vector,'[',']',i)LKJ(deque,'[',']',i)LKJ(set,'{','}',i)LKJ(multiset,'{','}',i)LKJ(unordered_set,'{','}',i)LKJ(map,'{','}',i.ff<<':'<<i.ss)LKJ(unordered_map,'{','}',i.ff<<':'<<i.ss) template<class...T>void SDF(const char* s,T...a){int c=sizeof...(T);if(!c){cerr<<"\033[1;32mvoid\033[0m\n";return;}(cerr<<"\033[1;32m("<<s<<") = (",...,(cerr<<a<<(--c?", ":")\033[0m\n")));} template<class T,size_t N>OIU(array<T,N>a){return O<<vector<T>(AI(a));}template<class...T>OIU(pair<T...>p){return O<<'('<<p.ff<<','<<p.ss<<')';}template<class...T>OIU(tuple<T...>t){return O<<'(',apply([&O](T...s){int c=0;(...,(O<<(c++?", ":"")<<s));},t),O<<')';} #else #define debug(...) ((void)0) #endif namespace { const int kN = 2000; const int kLW = 9; const int kLN = 11; const int INF = INT_MAX; enum State{ sendW = 0, waitW = 1, sendV = 2, waitV = 3 }; int N; vector<pair<int, int>> adj[kN]; int dis[kN], vis[kN]; int lastDis, bestVA, bestWA, bestVB, bestWB; State currentState; void relax(int u) { vis[u] = true; debug(vector<int>(dis, dis + N)); for (const auto& [v, c]: adj[u]) dis[v] = min(dis[u] + c, dis[v]); debug(vector<int>(dis, dis + N)); bestVB = -1; bestWB = INF; for (int i = 0; i < N; ++i) if (!vis[i] and dis[i] < bestWB) { bestVB = i; bestWB = dis[i]; } debug(bestVB, bestWB); } void tellW() { int w = (bestWB == INF ? (1 << kLW) - 1 : bestWB - lastDis); debug("B tellW", bestWB, lastDis, w); for (int l = kLW - 1; l >= 0; --l) SendB(w >> l & 1); } void tellV() { debug("B tellV", bestVB); for (int l = kLN - 1; l >= 0; --l) SendB(bestVB >> l & 1); } int receiveCount, receiveValue; } // namespace void InitB(int N, int B, vector<int> S, vector<int> T, vector<int> D) { ::N = N; for (int i = 0; i < B; ++i) { adj[S[i]].emplace_back(T[i], D[i]); adj[T[i]].emplace_back(S[i], D[i]); } fill(dis, dis + N, INF); fill(vis, vis + N, false); bestVA = -1; bestWA = INF; bestVB = -1; bestWB = INF; dis[0] = 0; lastDis = 0; relax(0); receiveCount = 0; receiveValue = 0; currentState = waitW; } void ReceiveB(bool y) { receiveValue <<= 1; receiveValue |= y; ++receiveCount; if (currentState == waitW and receiveCount == kLW) { if (receiveValue == (1 << kLW) - 1) bestWA = INF; else bestWA = receiveValue + lastDis; receiveCount = 0; receiveValue = 0; currentState = sendW; tellW(); debug("Debug B:"); debug(bestVA, bestWA); debug(bestVB, bestWB); if (bestWA <= bestWB) { currentState = waitV; } else { currentState = sendV; tellV(); bestVA = -1; bestWA = INF; lastDis = dis[bestVB]; relax(bestVB); currentState = waitW; } } else if (currentState == waitV and receiveCount == kLN) { bestVA = receiveValue; receiveCount = 0; receiveValue = 0; dis[bestVA] = bestWA; lastDis = dis[bestVA]; relax(bestVA); bestVA = -1; bestWA = INF; currentState = waitW; } }
#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...