답안 #565096

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
565096 2022-05-20T09:19:08 Z errorgorn Two Transportations (JOI19_transportations) C++17
38 / 100
484 ms 78908 KB
#include "Azer.h"

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ii pair<int,int>
#define fi first
#define se second

#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound

#define rep(x,s,e) for (int x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e))?x++:x--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()

namespace {

int n,m;
vector<ii> al[2005];
int w[2005];
priority_queue<ii,vector<ii>,greater<ii> > pq;

queue<int> q;
void send(int i,int k){
	rep(bit,0,k){
		if (i&(1<<bit)) SendA(1);
		else SendA(0);
	}
}

int get(int k){
	int res=0;
	rep(bit,0,k){
		res|=q.front()<<bit;
		q.pop();
	}
	return res;
}

bool flag=false;
int PREV=0;
int u,W,W_other;

void add(int i,int j){
	//cout<<"debug A: "<<i<<" "<<j<<endl;
	
	PREV=w[i]=j;
	for (auto [it,w2]:al[i]){
		pq.push({j+w2,it});
	}
}

void proc(){
	u=-1,W=1e18;
	while (!pq.empty()){
		tie(W,u)=pq.top();
		if (w[u]!=-1){
			u=-1,W=1e18;
			pq.pop();
		}
		else break;
	}
	
	if (u==-1) send(511,9);
	else send(W-PREV,9);
}

} 

void InitA(signed N, signed A, std::vector<signed> U, std::vector<signed> V,
           std::vector<signed> C) {
			   
	n=N,m=A;
	rep(x,0,m){
		al[U[x]].pub({V[x],C[x]});
		al[V[x]].pub({U[x],C[x]});
	}
	
	memset(w,-1,sizeof(w));
	add(0,0);
}

void ReceiveA(bool x){
	q.push(x);
	
	if (!flag){
		if (sz(q)!=9) return;
		
		proc();
		
		W_other=get(9)+PREV;
		
		if (W<=W_other){ //A wins
			send(u,10);
			add(u,W);
		}
		else{
			flag=true;
		}
	}
	else{
		if (sz(q)!=10) return;
		
		u=get(10);
		add(u,W_other);
		
		flag=false;
	}
}

std::vector<signed> Answer() {
	vector<signed> res;
	rep(x,0,n) res.pub(w[x]);
	return res;
}
#include "Baijan.h"

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ii pair<int,int>
#define fi first
#define se second

#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound

#define rep(x,s,e) for (int x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e))?x++:x--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()

namespace {

int n,m;
vector<ii> al[2005];
int w[2005];
priority_queue<ii,vector<ii>,greater<ii> > pq;

queue<int> q;
void send(int i,int k){
	rep(bit,0,k){
		if (i&(1<<bit)) SendB(1);
		else SendB(0);
	}
}

int get(int k){
	int res=0;
	rep(bit,0,k){
		res|=q.front()<<bit;
		q.pop();
	}
	return res;
}

bool flag=false;
int PREV=0;
int u,W,W_other;

void add(int i,int j){
	//cout<<"debug B: "<<i<<" "<<j<<endl;
	
	PREV=w[i]=j;
	for (auto [it,w2]:al[i]){
		pq.push({j+w2,it});
	}
}

int count=0;
void proc(){
	count++;
	if (count==n) return;
	
	u=-1,W=1e18;
	while (!pq.empty()){
		tie(W,u)=pq.top();
		if (w[u]!=-1){
			u=-1,W=1e18;
			pq.pop();
		}
		else break;
	}
	
	if (u==-1) send(511,9);
	else send(W-PREV,9);
}

};

void InitB(signed N, signed B, std::vector<signed> S, std::vector<signed> T,
           std::vector<signed> D) {

	n=N,m=B;
	rep(x,0,m){
		al[S[x]].pub({T[x],D[x]});
		al[T[x]].pub({S[x],D[x]});
	}
	
	memset(w,-1,sizeof(w));
	add(0,0);
	
	proc();
}

void ReceiveB(bool y){
	q.push(y);
	
	if (!flag){
		if (sz(q)!=9) return;
		
		W_other=get(9)+PREV;
		
		if (W<W_other){ //B wins
			add(u,W);
			send(u,10);
			proc();
		}
		else{
			flag=true;
		}
	}
	else{
		if (sz(q)!=10) return;
		
		u=get(10);
		add(u,W_other);
		
		flag=false;
		proc();
	}
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 436 ms 916 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 656 KB Output is correct
2 Incorrect 19 ms 752 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 357 ms 956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 229 ms 696 KB Output is correct
2 Correct 155 ms 668 KB Output is correct
3 Correct 330 ms 20808 KB Output is correct
4 Correct 204 ms 756 KB Output is correct
5 Correct 354 ms 14428 KB Output is correct
6 Correct 204 ms 708 KB Output is correct
7 Correct 169 ms 756 KB Output is correct
8 Correct 195 ms 656 KB Output is correct
9 Correct 361 ms 39832 KB Output is correct
10 Correct 294 ms 39764 KB Output is correct
11 Correct 484 ms 78908 KB Output is correct
12 Correct 429 ms 74836 KB Output is correct
13 Correct 181 ms 1012 KB Output is correct
14 Correct 0 ms 656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 229 ms 696 KB Output is correct
2 Correct 155 ms 668 KB Output is correct
3 Correct 330 ms 20808 KB Output is correct
4 Correct 204 ms 756 KB Output is correct
5 Correct 354 ms 14428 KB Output is correct
6 Correct 204 ms 708 KB Output is correct
7 Correct 169 ms 756 KB Output is correct
8 Correct 195 ms 656 KB Output is correct
9 Correct 361 ms 39832 KB Output is correct
10 Correct 294 ms 39764 KB Output is correct
11 Correct 484 ms 78908 KB Output is correct
12 Correct 429 ms 74836 KB Output is correct
13 Correct 181 ms 1012 KB Output is correct
14 Correct 0 ms 656 KB Output is correct
15 Incorrect 204 ms 768 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 229 ms 696 KB Output is correct
2 Correct 155 ms 668 KB Output is correct
3 Correct 330 ms 20808 KB Output is correct
4 Correct 204 ms 756 KB Output is correct
5 Correct 354 ms 14428 KB Output is correct
6 Correct 204 ms 708 KB Output is correct
7 Correct 169 ms 756 KB Output is correct
8 Correct 195 ms 656 KB Output is correct
9 Correct 361 ms 39832 KB Output is correct
10 Correct 294 ms 39764 KB Output is correct
11 Correct 484 ms 78908 KB Output is correct
12 Correct 429 ms 74836 KB Output is correct
13 Correct 181 ms 1012 KB Output is correct
14 Correct 0 ms 656 KB Output is correct
15 Incorrect 204 ms 768 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 436 ms 916 KB Output isn't correct
2 Halted 0 ms 0 KB -