제출 #530033

#제출 시각아이디문제언어결과실행 시간메모리
530033fhvirusTwo Transportations (JOI19_transportations)C++17
0 / 100
527 ms35640 KiB
#include "Azer.h"
#include <bits/stdc++.h>
using namespace std;

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;
	for (const auto& [v, c]: adj[u])
		dis[v] = min(dis[u] + c, dis[v]);
	bestVA = -1; bestWA = INF;
	for (int i = 0; i < N; ++i)
		if (!vis[i] and dis[i] < bestWA) {
			bestVA = i;
			bestWA = dis[i];
		}
	++relaxCount;
}

void tellW() {
	int w = (bestWA == INF ? (1 << kLW) - 1 : bestWA - lastDis);
	for (int l = kLW - 1; l >= 0; --l)
		SendA(w >> l & 1);
}
void tellV() {
	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;

		if (bestWA <= bestWB) {
			currentState = sendV;
			tellV();
			bestVB = -1; bestWB = INF;
			lastDis = dis[bestVA];

			if (relaxCount == N - 1)
				return;
			relax(bestVA);

			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];

		if (relaxCount == N - 1)
			return;
		relax(bestVB);

		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;

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;
	for (const auto& [v, c]: adj[u])
		dis[v] = min(dis[u] + c, dis[v]);
	bestVB = -1; bestWB = INF;
	for (int i = 0; i < N; ++i)
		if (!vis[i] and dis[i] < bestWB) {
			bestVB = i;
			bestWB = dis[i];
		}
}

void tellW() {
	int w = (bestWB == INF ? (1 << kLW) - 1 : bestWB - lastDis);
	for (int l = kLW - 1; l >= 0; --l)
		SendB(w >> l & 1);
}
void tellV() {
	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();

		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...