Submission #982355

# Submission time Handle Problem Language Result Execution time Memory
982355 2024-05-14T07:15:42 Z parlimoos Two Transportations (JOI19_transportations) C++14
0 / 100
241 ms 664 KB
//Be Name KHODA
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include "Azer.h"
using namespace std;

typedef long long ll;
typedef long double ld;
#define pb push_back
#define pp pop_back
#define lb lower_bound
#define ub upper_bound
#define cl clear
#define bg begin
#define arr(x) array<int , x>
#define endl '\n'

int nA , mA , dstA[2000];
vector<arr(2)> gA[2000];
set<arr(2)> qA;
int lstA = 0;
int rcvA[3] , xxA[2];
vector<int> AA;

void sendInfA(int x , int len){
  x = min(x , 501);
  // cout << "A : " << x << " " << len << ".\n";
	for(int bit = len - 1 ; bit >= 0 ; bit--) SendA((x >> bit) & 1);
}
vector<int> Answer(){
  return AA;
}
void addVtxA(int v , int x){
  qA.erase({dstA[v] , v});
	dstA[v] = x , lstA = x;
	for(auto &e : gA[v]){
		if(dstA[e[0]] > dstA[v] + e[1]){
			qA.erase({dstA[e[0]] , e[0]});
			dstA[e[0]] = dstA[v] + e[1];
			qA.insert({dstA[e[0]] , e[0]});
		}
	}
  if(qA.empty()){
    for(int i = 0 ; i < nA ; i++) AA.pb(dstA[i]);
    return;
  }
	auto itr = qA.bg();
	rcvA[0] = 9 , rcvA[1] = 0 , rcvA[2] = 0;
	xxA[0] = (*itr)[1] , xxA[1] = (*itr)[0] - lstA;
	sendInfA((*itr)[0] - lstA , 9);
}
void gotLenA(int len){
  // cout << len << "--\n";
	if(xxA[1] <= len){
    sendInfA(xxA[0] , 11);
    addVtxA(xxA[0] , xxA[1] + lstA);
	}else{
		xxA[1] = len , rcvA[0] = 11 , rcvA[1] = 0 , rcvA[2] = 1;
	}
}
void ReceiveA(bool x){
	if(rcvA[0] == 0) rcvA[0] = 11 , rcvA[1] = 0 , rcvA[1] = 1;
	rcvA[1] += (x << (rcvA[0] - 1));
	if(--rcvA[0] == 0){
		if(rcvA[2] == 0) gotLenA(rcvA[1]);
		else{
      addVtxA(rcvA[1] , xxA[1] + lstA);
    }
	}
}
void InitA(int N , int A , vector<int> U , vector<int> V , vector<int> C){
	nA = N , mA = A;
  fill(&dstA[0] , &dstA[nA] , int(1e9));
  for(int v = 0 ; v < nA ; v++) qA.insert({dstA[v] , v});
	for(int i = 0 ; i < mA ; i++) gA[U[i]].pb({V[i] , C[i]}) , gA[V[i]].pb({U[i] , C[i]});
	addVtxA(0 , 0);
}
//Be Name KHODA
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include "Baijan.h"
using namespace std;

typedef long long ll;
typedef long double ld;
#define pb push_back
#define pp pop_back
#define lb lower_bound
#define ub upper_bound
#define cl clear
#define bg begin
#define arr(x) array<int , x>
#define endl '\n'

int nB , mB , dstB[2000];
vector<arr(2)> gB[2000];
set<arr(2)> qB;
int lstB = 0;
int rcvB[3] , xxB[2];

void sendInfB(int x , int len){
  x = min(x , 501);
  // cout << "B : " << x << " " << len << ".\n";
	for(int bit = len - 1 ; bit >= 0 ; bit--) SendB((x >> bit) & 1);
}
void addVtxB(int v , int x){
  qB.erase({dstB[v] , v});
	dstB[v] = x , lstB = x;
	for(auto &e : gB[v]){
		if(dstB[e[0]] > dstB[v] + e[1]){
			qB.erase({dstB[e[0]] , e[0]});
			dstB[e[0]] = dstB[v] + e[1];
			qB.insert({dstB[e[0]] , e[0]});
		}
	}
	auto itr = qB.bg();
	rcvB[0] = 9 , rcvB[1] = 0 , rcvB[2] = 0;
	xxB[0] = (*itr)[1] , xxB[1] = (*itr)[0] - lstB;
}
void gotLenB(int len){
  // cout << len << "---\n";
	if(xxB[1] <= len){
		sendInfB(xxB[1] , 9);
    int d = xxB[0];
    addVtxB(xxB[0] , xxB[1] + lstB);
    sendInfB(d , 11);
	}else{
    int d = xxB[1];
    rcvB[0] = 11 , rcvB[1] = 0 , rcvB[2] = 1 , xxB[1] = len;
    sendInfB(d , 9);
	}
}
void ReceiveB(bool x){
  if(rcvB[0] == 0) rcvB[0] = 9 , rcvB[1] = 0 , rcvB[2] = 0;
	rcvB[1] += (x << (rcvB[0] - 1));
	if(--rcvB[0] == 0){
		if(rcvB[2] == 0) gotLenB(rcvB[1]);
		else addVtxB(rcvB[1] , xxB[1] + lstB);
	}
}
void InitB(int N , int B , vector<int> S , vector<int> T , vector<int> D){
	nB = N , mB = B;
  fill(&dstB[0] , &dstB[nB] , int(1e9));
  for(int v = 0 ; v < nB ; v++) qB.insert({dstB[v] , v});
	for(int i = 0 ; i < mB ; i++) gB[T[i]].pb({S[i] , D[i]}) , gB[S[i]].pb({T[i] , D[i]});
	addVtxB(0 , 0);
}
# Verdict Execution time Memory Grader output
1 Runtime error 241 ms 556 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 664 KB Output is correct
2 Incorrect 2 ms 588 KB Wrong Answer [1]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 13 ms 620 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 20 ms 548 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 20 ms 548 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 20 ms 548 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 241 ms 556 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -