Submission #56992

# Submission time Handle Problem Language Result Execution time Memory
56992 2018-07-13T12:32:55 Z hamzqq9 Amusement Park (JOI17_amusement_park) C++14
28 / 100
43 ms 11032 KB
#include "Joi.h"
 
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define st first
#define nd second
#define pb push_back
#define MAX 20005
#define sz(x) ((int)x.size())
#define pw(x) (1LL<<(x))
 
static int N,M,CurBit,A[MAX],B[MAX],Bit[69],VAL[MAX];
static bool COME[MAX];
static vector<int> v[MAX],v2[MAX];
static ll X;
static int CENTER,GMax;
 
static void CreateGraph() {
 
	for(int i=0;i<M;i++) {
 
		v[A[i]].pb(B[i]);
		v[B[i]].pb(A[i]);
 
	}
 
}
 
static void CreateBits() {
 
	for(int i=0;i<60;i++) {
 
		Bit[i]=((X&pw(i))>0);
 
	}
 
}
 
static int dist[MAX];
static bool vis[MAX];
 
static void findPath(int TO) {
 
	queue< pair<int,int> > Q;
 
	for(int i=0;i<N;i++) dist[i]=N+10,vis[i]=0;
 
	Q.push({TO,0});
 
	while(!Q.empty()) {
 
		pair<int,int> cur=Q.front();
 
		Q.pop();
 
		if(vis[cur.st]) continue ;
 
		vis[cur.st]=true;
 
		dist[cur.st]=cur.nd;
 
		for(int child:v[cur.st]) {
 
			Q.push({child,cur.nd+1});
 
		}
 
	}
 
}
 
static void dfs2(int node,int ata) {
 
	++CurBit;
 
	MessageBoard(node,Bit[CurBit]);
 
	VAL[node]=Bit[CurBit];	
 
	for(int child:v2[node]) {
 
		if(child==ata) continue ;
 
		dfs2(child,node);
 
	}
 
}
 
static int DEP[MAX];
 
static void dfs(int node,int ata) {
 
	int pos=-1;
 
	for(int i=0;i<sz(v2[node]);i++) {
 
		int child=v2[node][i];
 
		dfs(child,node);
 
		DEP[node]=max(DEP[node],DEP[child]);
 
		if(DEP[node]==DEP[child]) {

			pos=i;
 
		}
 
	}
 
	if(~pos) {
 
		swap(v2[node][pos],v2[node][sz(v2[node])-1]);
 
	}
 
	DEP[node]++;
 
}
 
static void SpanningTree(int node,int ata,bool SEND) {
 
	if(CurBit==59 || COME[node]) return ;
 
	COME[node]=true;
 
	if(~ata) {
 
		v2[ata].pb(node);
 
	}
 
	++CurBit;
 
	if(SEND) {
 
		MessageBoard(node,Bit[CurBit]);
 
		VAL[node]=Bit[CurBit];
	
	}
 
	for(int child:v[node]) {
 
		if(child==ata) continue ;
 
		SpanningTree(child,node,SEND);
 
	}
 
}
 
static void SUB2() {
 
	CreateGraph();
	CreateBits();
 
	CurBit=-1;
 
	SpanningTree(0,-1,true);
 
}
 
static void SUB3() {
 
	CreateBits();
 
	for(int i=0;i<N;i++) {
 
		VAL[i]=Bit[i%60];
 
		MessageBoard(i,VAL[i]);
 
	}
 
}
 
static void SUB4() {
 
	CreateGraph();
	CreateBits();
 
	CENTER=0;

	CurBit=-1;
 
	SpanningTree(CENTER,-1,false);
 
	dfs(CENTER,-1);
 
	CurBit=-1;
 
	dfs2(CENTER,-1);
 
}
 
void Joi(int N, int M, int A[], int B[], long long X, int T) {
  	
	::N=N;
	::M=M;
 
	::X=X;
 
	for(int i=0;i<M;i++) {
 
		::A[i]=A[i];
		::B[i]=B[i];
 
	}
 
	for(int i=0;i<N;i++) VAL[i]=-1;
 
	if(T==1 || T==4) SUB4();
 
	if(T==2) SUB2();
 
	if(T==3) SUB3();
 
	for(int i=0;i<N;i++) {
 
		if(VAL[i]!=-1) continue ;
 
		MessageBoard(i,0);
 
	}
 
}
#include "Ioi.h"
 
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define st first
#define nd second
#define pb push_back
#define MAX 20005
#define sz(x) ((int) x.size())
#define pw(x) (1LL<<(x))
 
static int CurBit,M,N,P,V,CENTER,GMax;
static int A[MAX],B[MAX];
static bool COME[MAX];
static vector<int> v[MAX],v2[MAX];
static ll X;
 
static void CreateGraph() {
 
	for(int i=0;i<M;i++) {
 
		v[A[i]].pb(B[i]);
		v[B[i]].pb(A[i]);
 
	}
 
}
 
static void SpanningTree(int node,int ata) {
 
	if(CurBit==59 || COME[node]) return ;
 
	COME[node]=true;
 
	++CurBit;
 
	if(~ata) {
 
		v2[ata].pb(node);
 
	}
 
	for(int child:v[node]) {
 
		if(child==ata) continue ;
 
		SpanningTree(child,node);
 
	}
 
}
 
static void dfs(int node,int ata) {
 
	++CurBit;
 
	X+=pw(CurBit)*V;
 
	for(int child:v2[node]) {
 
		V=Move(child);
 
		dfs(child,node);
 
		if(CurBit<59) V=Move(node);
 
	}
 
}
 
static int dist[MAX];
static bool vis[MAX];
 
static void findPath(int TO,bool GOON) {
 
	queue< pair<int,int> > Q;
 
	for(int i=0;i<N;i++) dist[i]=N+10,vis[i]=0;
 
	Q.push({TO,0});
 
	while(!Q.empty()) {
 
		pair<int,int> cur=Q.front();
 
		Q.pop();
 
		if(vis[cur.st]) continue ;
 
		vis[cur.st]=true;
 
		dist[cur.st]=cur.nd;
 
		for(int child:v[cur.st]) {
 
			Q.push({child,cur.nd+1});
 
		}
 
	}
 
	if(!GOON) return ;
 
	while(P!=TO) {
 
		for(int child:v[P]) {
 
			if(dist[child]==dist[P]-1) {
 
				V=Move(child);
 
				P=child;
 
				break ;
 
			}
 
		}
 
	}
 
}
 
static int DEP[MAX];
 
void dfs2(int node,int ata) {

	int pos=-1;
 
	for(int i=0;i<sz(v2[node]);i++) {
 
		int child=v2[node][i];
 
		dfs2(child,node);
 
		DEP[node]=max(DEP[node],DEP[child]);
 
		if(DEP[node]==DEP[child]) {
 
			pos=i;
 
		}
 
	}
 
	if(~pos) {
 
		swap(v2[node][pos],v2[node][sz(v2[node])-1]);
 
	}
 
	DEP[node]++;
 
}
 
static ll SUB2() {
 
	CreateGraph();
 
	CurBit=-1;
 
	SpanningTree(0,-1);
 
	findPath(0,true);
 
	CurBit=-1;
 
	dfs(P,-1);
 
	return X;
 
}
 
static ll SUB4() {
 
	CreateGraph();
 
	CENTER=0;

	CurBit=-1;
 
	SpanningTree(CENTER,-1);
 
	dfs2(CENTER,-1);
 
	CurBit=-1;
 
	findPath(CENTER,true);
 
	dfs(CENTER,-1);
 
	return X;
 
}
 
static ll SUB3() {
 
	while(P%60 || P+59>=N) {
 
		P--;
 
		V=Move(P);
 
	}
 
	for(int i=P;i<P+60;i++) {
 
		X+=pw(i-P)*V;
 
		if(i+1<N) V=Move(i+1);
 
	}
 
	return X;
 
}
 
long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
  
	::N=N;
	::M=M;
	::P=P;
	::V=V;
 
	for(int i=0;i<M;i++) {
 
		::A[i]=A[i];
		::B[i]=B[i];
 
	}
 
	if(T==1 || T==4) return SUB4();
 
	if(T==2) return SUB2();
 
	if(T==3) return SUB3();	
 
	assert(0); 
 
}

Compilation message

Joi.cpp:44:13: warning: 'void findPath(int)' defined but not used [-Wunused-function]
 static void findPath(int TO) {
             ^~~~~~~~
Joi.cpp:18:19: warning: 'GMax' defined but not used [-Wunused-variable]
 static int CENTER,GMax;
                   ^~~~

Ioi.cpp:14:34: warning: 'GMax' defined but not used [-Wunused-variable]
 static int CurBit,M,N,P,V,CENTER,GMax;
                                  ^~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2664 KB Output is correct
2 Correct 7 ms 2792 KB Output is correct
3 Correct 6 ms 2816 KB Output is correct
4 Correct 7 ms 3072 KB Output is correct
5 Correct 7 ms 3072 KB Output is correct
6 Correct 6 ms 3072 KB Output is correct
7 Correct 8 ms 3088 KB Output is correct
8 Correct 7 ms 3124 KB Output is correct
9 Correct 6 ms 3148 KB Output is correct
10 Correct 7 ms 3200 KB Output is correct
11 Correct 11 ms 3796 KB Output is correct
12 Correct 7 ms 3824 KB Output is correct
13 Correct 7 ms 3824 KB Output is correct
14 Correct 6 ms 3824 KB Output is correct
15 Correct 7 ms 3824 KB Output is correct
16 Correct 9 ms 3824 KB Output is correct
17 Correct 8 ms 3824 KB Output is correct
18 Correct 8 ms 3824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 6612 KB Output is correct
2 Correct 37 ms 7044 KB Output is correct
3 Correct 43 ms 7444 KB Output is correct
4 Correct 20 ms 7576 KB Output is correct
5 Correct 28 ms 7576 KB Output is correct
6 Correct 31 ms 7576 KB Output is correct
7 Correct 24 ms 7576 KB Output is correct
8 Correct 25 ms 7576 KB Output is correct
9 Correct 20 ms 7576 KB Output is correct
10 Correct 24 ms 7576 KB Output is correct
11 Correct 28 ms 7576 KB Output is correct
12 Correct 20 ms 7576 KB Output is correct
13 Correct 28 ms 7576 KB Output is correct
14 Correct 30 ms 7576 KB Output is correct
15 Correct 24 ms 7576 KB Output is correct
16 Correct 27 ms 7576 KB Output is correct
17 Correct 22 ms 7576 KB Output is correct
18 Correct 30 ms 7608 KB Output is correct
19 Correct 24 ms 8280 KB Output is correct
20 Correct 20 ms 8280 KB Output is correct
21 Correct 22 ms 8280 KB Output is correct
22 Correct 26 ms 8396 KB Output is correct
23 Correct 30 ms 8592 KB Output is correct
24 Correct 27 ms 8780 KB Output is correct
25 Correct 28 ms 8872 KB Output is correct
26 Correct 30 ms 8872 KB Output is correct
27 Correct 24 ms 8872 KB Output is correct
28 Correct 25 ms 8872 KB Output is correct
29 Correct 27 ms 8872 KB Output is correct
30 Correct 23 ms 8872 KB Output is correct
31 Correct 8 ms 8872 KB Output is correct
32 Correct 6 ms 8872 KB Output is correct
33 Correct 8 ms 8872 KB Output is correct
34 Correct 6 ms 8872 KB Output is correct
35 Correct 7 ms 8872 KB Output is correct
36 Correct 6 ms 8872 KB Output is correct
37 Correct 5 ms 8872 KB Output is correct
38 Correct 6 ms 8872 KB Output is correct
39 Correct 5 ms 8872 KB Output is correct
40 Correct 7 ms 8872 KB Output is correct
41 Correct 7 ms 8872 KB Output is correct
42 Correct 8 ms 8872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 8872 KB Output is correct
2 Correct 7 ms 8872 KB Output is correct
3 Correct 6 ms 8872 KB Output is correct
4 Correct 9 ms 8872 KB Output is correct
5 Correct 8 ms 8872 KB Output is correct
6 Correct 8 ms 8872 KB Output is correct
7 Correct 7 ms 8872 KB Output is correct
8 Correct 8 ms 8872 KB Output is correct
9 Correct 17 ms 8872 KB Output is correct
10 Correct 20 ms 8872 KB Output is correct
11 Correct 18 ms 8872 KB Output is correct
12 Correct 7 ms 8872 KB Output is correct
13 Correct 6 ms 8872 KB Output is correct
14 Correct 6 ms 8872 KB Output is correct
15 Correct 7 ms 8872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 9956 KB Output is correct
2 Correct 35 ms 10176 KB Output is correct
3 Correct 38 ms 10176 KB Output is correct
4 Correct 28 ms 10176 KB Output is correct
5 Incorrect 28 ms 10176 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 28 ms 11032 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -