제출 #132797

#제출 시각아이디문제언어결과실행 시간메모리
132797sebinkimTwo Transportations (JOI19_transportations)C++14
70 / 100
1538 ms85600 KiB
#include <bits/stdc++.h>
 
#include "Azer.h"
 
using namespace std;
 
typedef pair <int, int> pii;
 
const int ID = 11;
const int DIST = 9;
 
namespace{
	priority_queue <pii> Q;
	vector <pii> G[2020];
	vector <int> D;
	bool chk[2020];
	int v, c, t, _d;
	int n, z, m;

	bool turn() { return 1; }
 
	void sendint(int x, int l)
	{
		x = min(x, (1 << l) - 1);
		
		for(; l--; ){
			SendA((x & (1 << l))? 1 : 0);
		}
	}
 
	void check()
	{
		int p, d;
		
		for(; !Q.empty(); Q.pop()){
			tie(d, p) = Q.top(); d = -d;
			if(!chk[p] && d == D[p]) break;
		}
		
		if(Q.empty()) return;
		
		tie(d, p) = Q.top(); d = -d;
		
		sendint(d - z, DIST);
	}
 
	void apply(int p, int d)
	{
		chk[p] = 1; D[p] = d; z = d;
		
		for(pii &t: G[p]){
			if(!chk[t.first] && D[t.first] > d + t.second){
				D[t.first] = d + t.second;
				Q.emplace(-d - t.second, t.first);
			}
		}
		
		if(turn()){
			m = 1; check();
		}
		else m = 2;
	}

	void check(int d1)
	{
		int p2, d2;
		
		for(; !Q.empty(); Q.pop()){
			tie(d2, p2) = Q.top(); d2 = -d2;
			if(!chk[p2] && D[p2] == d2) break;
		}
		
		tie(d2, p2) = Q.top(); d2 = -d2;
		
		if(d1 < d2){
			SendA(0);
			_d = d1, t = 1;
		}
		else{
			SendA(1); Q.pop();
			sendint(p2, ID);
			sendint(d2 - z, DIST);
			apply(p2, d2);
		}
	}
}

void InitA(int N, int A, vector <int> U, vector <int> V, vector<int> C)
{
	n = N; D.resize(n, 0);
	
	int i;
	
	for(i=0; i<A; i++){
		G[U[i]].emplace_back(V[i], C[i]);
		G[V[i]].emplace_back(U[i], C[i]);
	}
	
	for(i=1; i<n; i++){
		D[i] = 1e9;
	}
	
	for(i=0; i<n; i++){
		Q.emplace(-D[i], i);
	}
	
	apply(0, 0);
}

void ReceiveA(bool x)
{
	if(m == 1){
		if(t == 0){
			if(!x){
				int d, p;
				tie(d, p) = Q.top();
				d = -d; Q.pop();
				sendint(p, ID);
				apply(p, d);
			}
			else t = 1;
		}
		else{
			v = v << 1 | x; c ++;
		
			if(c == ID + DIST){
				int p = v >> DIST;
				int d = z + (v & ((1 << DIST) - 1));
				v = 0; c = 0; t = 0;
				apply(p, d);
			}
		}
	}
	else{
		if(t == 0){
			v = v << 1 | x; c ++;
		
			if(c == DIST){
				int d = z + v;
				v = 0; c = 0;
				check(d);
			}
		}
		else{
			v = v << 1 | x; c ++;
		
			if(c == ID){
				int p = v, d = _d;
				v = 0; c = 0; t = 0;
				apply(p, d);
			}
		}
	}
}

vector <int> Answer() { return D; }
#include <bits/stdc++.h>
 
#include "Baijan.h"

using namespace std;
 
typedef pair <int, int> pii;
 
const int ID = 11;
const int DIST = 9;
 
namespace{
	priority_queue <pii> Q;
	vector <pii> G[2020];
	vector <int> D;
	bool chk[2020];
	int v, c, t, _d;
	int n, z, m;

	bool turn() { return 1; }
 
	void sendint(int x, int l)
	{
		x = min(x, (1 << l) - 1);
		
		for(; l--; ){
			SendB((x & (1 << l))? 1 : 0);
		}
	}
 
	void check()
	{
		int p, d;
		
		for(; !Q.empty(); Q.pop()){
			tie(d, p) = Q.top(); d = -d;
			if(!chk[p] && d == D[p]) break;
		}
		
		if(Q.empty()) return;
		
		tie(d, p) = Q.top(); d = -d;
		
		sendint(d - z, DIST);
	}
 
	void apply(int p, int d)
	{
		chk[p] = 1; D[p] = d; z = d;
		
		for(pii &t: G[p]){
			if(!chk[t.first] && D[t.first] > d + t.second){
				D[t.first] = d + t.second;
				Q.emplace(-d - t.second, t.first);
			}
		}
		
		if(!turn()){
			m = 1; check();
		}
		else m = 2;
	}

	void check(int d1)
	{
		int p2, d2;
		
		for(; !Q.empty(); Q.pop()){
			tie(d2, p2) = Q.top(); d2 = -d2;
			if(!chk[p2] && D[p2] == d2) break;
		}
		
		tie(d2, p2) = Q.top(); d2 = -d2;
		
		if(d1 < d2){
			SendB(0);
			_d = d1, t = 1;
		}
		else{
			SendB(1); Q.pop();
			sendint(p2, ID);
			sendint(d2 - z, DIST);
			apply(p2, d2);
		}
	}
}

void InitB(int N, int B, vector <int> S, vector<int> T, vector<int> C)
{
	n = N; D.resize(n, 0);
	
	int i;
	
	for(i=0; i<B; i++){
		G[S[i]].emplace_back(T[i], C[i]);
		G[T[i]].emplace_back(S[i], C[i]);
	}
	
	for(i=1; i<n; i++){
		D[i] = 1e9;
	}
	
	for(i=0; i<n; i++){
		Q.emplace(-D[i], i);
	}
	
	apply(0, 0);
}

void ReceiveB(bool x)
{
	if(m == 1){
		if(t == 0){
			if(!x){
				int d, p;
				tie(d, p) = Q.top();
				d = -d; Q.pop();
				sendint(p, ID);
				apply(p, d);
			}
			else t = 1;
		}
		else{
			v = v << 1 | x; c ++;
		
			if(c == ID + DIST){
				int p = v >> DIST;
				int d = z + (v & ((1 << DIST) - 1));
				v = 0; c = 0; t = 0;
				apply(p, d);
			}
		}
	}
	else{
		if(t == 0){
			v = v << 1 | x; c ++;
		
			if(c == DIST){
				int d = z + v;
				v = 0; c = 0;
				check(d);
			}
		}
		else{
			v = v << 1 | x; c ++;
		
			if(c == ID){
				int p = v, d = _d;
				v = 0; c = 0; t = 0;
				apply(p, d);
			}
		}
	}
}
#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...