Submission #240104

# Submission time Handle Problem Language Result Execution time Memory
240104 2020-06-18T05:08:05 Z kshitij_sodani Two Transportations (JOI19_transportations) C++17
0 / 100
724 ms 1536 KB
#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first 
#define b second
#include "Azer.h"



vector<pair<int,int>> adj[2001];
int dist[2001];
int vis[2001];
int num=0;
int cur=0;
int st=0;
int last=0;
pair<int,int> best;
int num2=0;
int cur2=0;
int n;
int kk=0;
vector<int> Answer(){
	vector<int> ans2;
	for(int i=0;i<n;i++){
		ans2.pb(dist[i]);
	}
	return ans2;

}
void ReceiveA(bool x){
	if(st==0){
		if(cur==0){
			for(auto j:adj[last]){
				if(dist[j.a]==-1 or dist[j.a]>dist[last]+j.b){
					dist[j.a]=dist[last]+j.b;
				}
			}
			best={-1,-1};
			for(int i=0;i<n;i++){
			//	////cout<<i<<":::"<<dist[i]<<endl;
				if(vis[i]==0 and dist[i]!=-1){
					if(best.a==-1){
						best={dist[i],i};
					}
					else{
						if(dist[i]<best.a){
							best={dist[i],i};
						}
					}
				}
			}
			if(best.a==-1){
				best.a=(1<<20)-1;
			}
			//cout<<best.a<<","<<best.b<<endl;
		}
		if(x){
			num+=(1<<(19-cur));
			////cout<<num<<endl;
			//cout<<cur<<"<<"<<num<<",,"<<best.a<<endl;
			if((best.a&(1<<(19-cur)))==0 and kk==0){
				st=3;
				//cout<<333<<endl;
				SendA(1);
				//cout<<444<<endl;
				ReceiveA(0);
				return;
			//	SendA(1);
			}	
		}
		else{
			if((best.a&(1<<(19-cur)))){
				kk=1;
			//	//cout<<1111<<endl;
			}
		}
		cur+=1;
		if(cur==20){
			cur=0;
			st=1;
		}
		else{
			return;
		}
		////cout<<cur<<"<"<<num<<endl;
	}
	if(st==1){
		
		////cout<<best.a<<"::"<<best.b<<"::"<<num<<endl;
		st=2;
		SendA(0);
		return;
		/*if(num==0){
			SendA(0);
			st=3;
		}
		else if(best.a==-1){
			SendA(1);
			st=2;
		}
		else if(best.a<num){
			SendA(0);
			st=3;
		}
		else{
			SendA(1);
			st=2;
		}
		////cout<<st<<"....."<<endl;
		if(st==2){
			return;
		}*/
	}
	if(st==2){
		if(x){
			num2+=(1<<cur2);
		}
		cur2+=1;
		////cout<<cur2<<";;;;;;;;;;;;;;;"<<endl;
		if(cur2==11){
			last=num2;
			////cout<<num2<<"//"<<endl;
			vis[last]=1;
			dist[last]=num;
		}
		else{
			return;
		}		
	}
	if(st==3){

		//cout<<"hello"<<endl;
		dist[best.b]=best.a;
		vis[best.b]=1;
		last=best.b;
		//cout<<cur+1<<endl;
		for(int i=cur+1;i<20;i++){
			if((1<<i)&best.a){
				SendA(1);
			}
			else{
				SendA(0);
			}
		}
		for(int i=0;i<11;i++){
			if((1<<i)&best.b){
				SendA(1);
			}
			else{
				SendA(0);
			}
		}

	}
	////cout<<last<<','<<dist[last]<<endl;
	st=0;
	num=0;
	num2=0;
	cur2=0;
	cur=0;
	kk=0;
/*	int kk=0;
	for(int i=0;i<n;i++){
		if(vis[i]==0){
			kk=1;
		}
	}
	if(kk){
		SendA(0);
	}*/
}
void InitA(int nn,int m,vector<int> aa,vector<int> bb,vector<int> cc){
	n=nn;
	for(int i=0;i<m;i++){
		adj[aa[i]].pb({bb[i],cc[i]});
		adj[bb[i]].pb({aa[i],cc[i]});
	}
	for(int i=1;i<n;i++){
		dist[i]=-1;
	}
	vis[0]=1;
	SendA(0);
}


/*int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	return 0;
}*/
#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
#include "Baijan.h"

vector<pair<int,int>> adj2[2001];
int dist2[2001];
int st2=0;
int last2=0;
int vis2[2001];
pair<int,int> best2;
int ne;
int cur3=0;
int cur4=0;
int num3=0;
int num4=0;
int cot=0;
int lol=0;
void ReceiveB(bool x){
	if(st2==0){
		for(auto j:adj2[last2]){
			if(dist2[j.a]==-1 or dist2[j.a]>dist2[last2]+j.b){
				dist2[j.a]=dist2[last2]+j.b;
			}
		}
		best2={-1,-1};
		for(int i=0;i<ne;i++){
			if(vis2[i]==0 and dist2[i]!=-1){
				if(best2.a==-1){
					best2={dist2[i],i};
				}
				else{
					if(dist2[i]<best2.a){
						best2={dist2[i],i};
					}
				}
			}
		}
		//cout<<best2.a<<"::"<<best2.b<<endl;
		if(best2.a==-1){
			best2.a=(1<<20)-1;
		}
		//best2.a=max(best2.a,0);
		st2=7;
		for(int i=19;i>=0;i--){
			if(lol){
				return;
			}
			cot+=1;
			if(((1<<i)&best2.a)){
			//	cot+=1;
				//cout<<i<<"?//////////////////"<<"<"<<st2<<endl;
				SendB(1);
				if(lol){
					return;
				}
			}
			else{
				SendB(0);
			}
		}
		st2=2;

		return;
	}
	//cout<<st2<<"..........."<<endl;
	if(st2==2){
		if(x){
			st2=7;
		}
	}
	if(st2==7){
		lol=1;
		
		////cout<<cot<<endl;
		for(int i=0;i<cot-1;i++){
			if(((1<<(19-i))&best2.a)){
				num3+=(1<<(19-i));
			}
		}
		//cout<<111111111<<",,,"<<cot<<",,"<<num3<<endl;
		cur3=cot;
		st2=3;
		return;
	}
	/*if(st2==1){
		if(x){
			st2=2;
		}
		else{
			st2=3;
			return;
		}
	}*/
	if(st2==2){
		////cout<<1111<<endl;
		st2=0;
		dist2[best2.b]=best2.a;
		vis2[best2.b]=1;
		last2=best2.b;
		for(int i=0;i<11;i++){
			if((1<<i)&best2.b){
				SendB(1);
			}
			else{
				SendB(0);
			}
		}
	}
	if(st2==3){
		if(cur3<20){
			if(x){
				num3+=(1<<cur3);
			}
			cur3++;
			return;
		}
		else{
			if(x){
				num4+=(1<<cur4);
			}
			cur4++;

			if(cur4==11){
				//cout<<num4<<"?????"<<","<<num3<<endl;
				////cout<<20<<endl;

				////cout<<num4<<",,"<<num3<<endl;

				dist2[num4]=num3;
				vis2[num4]=1;
				last2=num4;
				
			}
			else{
				return;
			}
		}
	}
//	////cout<<last2<<"<<<>>>>"<<endl;
	num3=0;
	num4=0;
	cur3=0;
	cur4=0;
	st2=0;
	lol=0;
	cot=0;
	int ko=0;
	for(int i=0;i<ne;i++){
		if(vis2[i]==0){
			ko=1;
		}
	}
	if(ko){
		ReceiveB(0);
	}


}
void InitB(int nn,int m,vector<int> aa,vector<int> bb,vector<int> cc){
	ne=nn;
	for(int i=0;i<m;i++){
		adj2[aa[i]].pb({bb[i],cc[i]});
		adj2[bb[i]].pb({aa[i],cc[i]});
	}
	for(int i=1;i<ne;i++){
		dist2[i]=-1;
	}
	vis2[0]=1;
}


/*int main(){
	ios_base::sync_with_st2dio(false);
	cin.tie(NULL);

	return 0;
}*/
# Verdict Execution time Memory Grader output
1 Incorrect 724 ms 896 KB Wrong Answer [2]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 1536 KB Output is correct
2 Failed 61 ms 1192 KB Unexpected end of file - int32 expected (Baijan)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Failed 86 ms 1136 KB Unexpected end of file - int32 expected (Baijan)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Failed 59 ms 1008 KB Unexpected end of file - int32 expected (Baijan)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Failed 59 ms 1008 KB Unexpected end of file - int32 expected (Baijan)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Failed 59 ms 1008 KB Unexpected end of file - int32 expected (Baijan)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 724 ms 896 KB Wrong Answer [2]
2 Halted 0 ms 0 KB -