Submission #71839

# Submission time Handle Problem Language Result Execution time Memory
71839 2018-08-25T16:48:50 Z zadrga Amusement Park (JOI17_amusement_park) C++14
100 / 100
49 ms 25216 KB
/*
Idea:
- http://s3-ap-northeast-1.amazonaws.com/data.cms.ioi-jp.org/open-2017/2017-open-amusement_park-sol-en.pdf
*/

#include "Joi.h"
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (2e9)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 10111

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

vector<int> adj[maxn], tree[maxn], one, two, v;
int col[maxn], par[maxn], dep[maxn], max_dep, max_ind, cnt;
bool used[maxn];

void DFS(int x){
	used[x] = 1;
	if(max_dep < dep[x]){
		max_dep = dep[x];
		max_ind = x;
	}

	for(int u : adj[x]){
		if(!used[u]){
			tree[x].pb(u);
			dep[u] = dep[x] + 1;
			par[u] = x;
			DFS(u);
		}
	}
}

void colorBig(int x, ll num){
	int pos = dep[x] % 60;
	int val = (num >> pos) & 1;
	col[x] = val;

	for(int u : tree[x])
		colorBig(u, num);
}

void colorSmall(int x){
	v.pb(x);

	int last = -1;
	for(int u : tree[x]){
		if(used[u]){
			last = u;
			continue;
		}

		if(cnt <= 0)
			continue;
		
		cnt--;
		colorSmall(u);
	}

	if(last != -1)
		colorSmall(last);
}

void Joi(int N, int M, int A[], int B[], long long X, int T){
	memset(col, 0, sizeof(col));
	for(int i = 0; i < M; i++){
		adj[A[i]].pb(B[i]);
		adj[B[i]].pb(A[i]);
	}

	par[0] = -1;
	dep[0] = 0;
	max_dep = -1;
	DFS(0);

	if(max_dep >= 59)
		colorBig(0, X);
	else{
		memset(used, 0, sizeof(used));
		int cur = max_ind;
		while(cur != -1){
			one.pb(cur);
			used[cur] = 1;
 			cur = par[cur];
		}

		cnt = 60 - one.size();
		colorSmall(0);

		sort(v.begin(), v.end());

		for(int i = 0; i < v.size(); i++)
			col[v[i]] = (X >> i) & 1;
	}

	for(int i = 0; i < N; i++)
		MessageBoard(i, col[i]);
}
/*
Idea:
- http://s3-ap-northeast-1.amazonaws.com/data.cms.ioi-jp.org/open-2017/2017-open-amusement_park-sol-en.pdf
*/

#include "Ioi.h"
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (2e9)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 10011

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;


vector<int> adj1[maxn], tree1[maxn], one1, two1, v1;
int col1[maxn], par1[maxn], dep1[maxn], max_dep1, max_ind1, cnt1;
bool used1[maxn];

void DFS1(int x){
	used1[x] = 1;
	if(max_dep1 < dep1[x]){
		max_dep1 = dep1[x];
		max_ind1 = x;
	}

	for(int u : adj1[x]){
		if(!used1[u]){
			tree1[x].pb(u);
			dep1[u] = dep1[x] + 1;
			par1[u] = x;
			DFS1(u);
		}
	}
}

void getSmall(int x){
	v1.pb(x);

	int last = -1;
	for(int u : tree1[x]){
		if(used1[u]){
			last = u;
			continue;
		}

		if(cnt1 <= 0)
			continue;

		cnt1--;
		col1[u] = Move(u);
		getSmall(u);
		col1[x] = Move(x);
	}

	if(last != -1){
		col1[last] = Move(last);
		getSmall(last);
	}
}


long long Ioi(int N, int M, int A[], int B[], int P, int V, int T){
	ll ans = 0;
	memset(col1, 0, sizeof(col1));
	for(int i = 0; i < M; i++){
		adj1[A[i]].pb(B[i]);
		adj1[B[i]].pb(A[i]);
	}

	par1[0] = -1;
	dep1[0] = 0;
	max_dep1 = -1;
	DFS1(0);

	memset(used1, 0, sizeof(used1));
	int cur = max_ind1;
	while(cur != -1){
		one1.pb(cur);
		used1[cur] = 1;
		cur = par1[cur];
	}

	reverse(one1.begin(), one1.end());

	if(max_dep1 >= 59){
		if(dep1[P] >= 59){	// just go up
			int cur = P;
			int pos = dep1[cur] % 60;
			int val = V;

			ans += (1LL << pos) * val;
			for(int i = 1; i < 60; i++){
				cur = par1[cur];
				val = Move(cur);
				pos = dep1[cur] % 60;
				ans += (1LL << pos) * val;
			}
		}
		else{
			cur = par1[P];	// go to 1 and then down
			while(cur != -1){
				V = Move(cur);
				cur = par1[cur];
			}

			int cur = 0;
			int pos = dep1[cur] % 60;
			int val = V;
			ans += (1LL << pos) * val;
			for(int i = 1; i < 60; i++){
				cur = one1[i];
				val = Move(cur);
				pos = dep1[cur] % 60;
				ans += (1LL << pos) * val;
			}
		}
	}
	else{
		int cur = par1[P];	// Move to 1 and then do DFS traversal
		while(cur != -1){
			V = Move(cur);
			cur = par1[cur];
		}

		cnt1 = 60 - one1.size();
		col1[0] = V; 
		getSmall(0);

		sort(v1.begin(), v1.end());
		for(int i = 0; i < v1.size(); i++)
			ans += col1[v1[i]] * (1LL << i);
	}
	return ans;
}

Compilation message

Joi.cpp: In function 'void Joi(int, int, int*, int*, long long int, int)':
Joi.cpp:102:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < v.size(); i++)
                  ~~^~~~~~~~~~

Ioi.cpp: In function 'long long int Ioi(int, int, int*, int*, int, int, int)':
Ioi.cpp:139:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < v1.size(); i++)
                  ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1900 KB Output is correct
2 Correct 7 ms 2272 KB Output is correct
3 Correct 7 ms 2544 KB Output is correct
4 Correct 4 ms 2544 KB Output is correct
5 Correct 7 ms 2544 KB Output is correct
6 Correct 6 ms 2544 KB Output is correct
7 Correct 6 ms 2556 KB Output is correct
8 Correct 6 ms 2588 KB Output is correct
9 Correct 7 ms 2744 KB Output is correct
10 Correct 6 ms 2744 KB Output is correct
11 Correct 10 ms 3080 KB Output is correct
12 Correct 7 ms 3192 KB Output is correct
13 Correct 7 ms 3192 KB Output is correct
14 Correct 7 ms 3192 KB Output is correct
15 Correct 8 ms 3192 KB Output is correct
16 Correct 6 ms 3192 KB Output is correct
17 Correct 6 ms 3192 KB Output is correct
18 Correct 6 ms 3192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 6828 KB Output is correct
2 Correct 45 ms 7212 KB Output is correct
3 Correct 48 ms 7608 KB Output is correct
4 Correct 32 ms 7752 KB Output is correct
5 Correct 24 ms 7752 KB Output is correct
6 Correct 31 ms 7752 KB Output is correct
7 Correct 37 ms 7752 KB Output is correct
8 Correct 26 ms 7752 KB Output is correct
9 Correct 29 ms 7784 KB Output is correct
10 Correct 23 ms 7784 KB Output is correct
11 Correct 24 ms 7784 KB Output is correct
12 Correct 23 ms 7784 KB Output is correct
13 Correct 32 ms 7784 KB Output is correct
14 Correct 26 ms 7784 KB Output is correct
15 Correct 28 ms 8356 KB Output is correct
16 Correct 27 ms 8760 KB Output is correct
17 Correct 28 ms 8760 KB Output is correct
18 Correct 30 ms 8768 KB Output is correct
19 Correct 34 ms 8912 KB Output is correct
20 Correct 26 ms 10004 KB Output is correct
21 Correct 22 ms 10264 KB Output is correct
22 Correct 26 ms 10392 KB Output is correct
23 Correct 27 ms 10392 KB Output is correct
24 Correct 27 ms 10392 KB Output is correct
25 Correct 26 ms 10608 KB Output is correct
26 Correct 32 ms 10856 KB Output is correct
27 Correct 28 ms 11048 KB Output is correct
28 Correct 31 ms 11416 KB Output is correct
29 Correct 28 ms 11416 KB Output is correct
30 Correct 30 ms 11500 KB Output is correct
31 Correct 7 ms 11584 KB Output is correct
32 Correct 6 ms 11584 KB Output is correct
33 Correct 8 ms 11584 KB Output is correct
34 Correct 7 ms 11584 KB Output is correct
35 Correct 5 ms 11584 KB Output is correct
36 Correct 7 ms 11584 KB Output is correct
37 Correct 9 ms 11584 KB Output is correct
38 Correct 7 ms 11584 KB Output is correct
39 Correct 6 ms 11584 KB Output is correct
40 Correct 6 ms 11584 KB Output is correct
41 Correct 6 ms 11584 KB Output is correct
42 Correct 7 ms 11584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 11584 KB Output is correct
2 Correct 8 ms 11584 KB Output is correct
3 Correct 7 ms 11584 KB Output is correct
4 Correct 9 ms 11584 KB Output is correct
5 Correct 8 ms 11584 KB Output is correct
6 Correct 9 ms 11584 KB Output is correct
7 Correct 10 ms 11584 KB Output is correct
8 Correct 11 ms 11584 KB Output is correct
9 Correct 28 ms 13336 KB Output is correct
10 Correct 20 ms 13652 KB Output is correct
11 Correct 22 ms 13796 KB Output is correct
12 Correct 5 ms 13816 KB Output is correct
13 Correct 8 ms 13816 KB Output is correct
14 Correct 6 ms 13816 KB Output is correct
15 Correct 5 ms 13816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 14076 KB Output is correct
2 Correct 46 ms 14460 KB Output is correct
3 Correct 41 ms 14868 KB Output is correct
4 Correct 26 ms 15024 KB Output is correct
5 Correct 29 ms 15024 KB Output is correct
6 Correct 29 ms 15024 KB Output is correct
7 Correct 30 ms 15024 KB Output is correct
8 Correct 22 ms 15024 KB Output is correct
9 Correct 23 ms 15024 KB Output is correct
10 Correct 20 ms 15024 KB Output is correct
11 Correct 20 ms 15024 KB Output is correct
12 Correct 20 ms 15024 KB Output is correct
13 Correct 23 ms 15024 KB Output is correct
14 Correct 32 ms 15032 KB Output is correct
15 Correct 23 ms 15640 KB Output is correct
16 Correct 24 ms 15848 KB Output is correct
17 Correct 25 ms 15848 KB Output is correct
18 Correct 26 ms 16072 KB Output is correct
19 Correct 33 ms 16260 KB Output is correct
20 Correct 22 ms 17164 KB Output is correct
21 Correct 20 ms 17496 KB Output is correct
22 Correct 26 ms 17496 KB Output is correct
23 Correct 23 ms 17504 KB Output is correct
24 Correct 27 ms 17784 KB Output is correct
25 Correct 26 ms 18056 KB Output is correct
26 Correct 26 ms 18072 KB Output is correct
27 Correct 25 ms 18504 KB Output is correct
28 Correct 25 ms 18536 KB Output is correct
29 Correct 23 ms 18536 KB Output is correct
30 Correct 32 ms 18776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 20404 KB Output is correct
2 Correct 35 ms 20844 KB Output is correct
3 Correct 49 ms 21348 KB Output is correct
4 Correct 26 ms 21496 KB Output is correct
5 Correct 28 ms 21552 KB Output is correct
6 Correct 31 ms 21608 KB Output is correct
7 Correct 38 ms 21608 KB Output is correct
8 Correct 25 ms 21608 KB Output is correct
9 Correct 24 ms 21608 KB Output is correct
10 Correct 30 ms 21608 KB Output is correct
11 Correct 34 ms 21608 KB Output is correct
12 Correct 24 ms 21608 KB Output is correct
13 Correct 25 ms 21608 KB Output is correct
14 Correct 25 ms 21608 KB Output is correct
15 Correct 25 ms 22056 KB Output is correct
16 Correct 30 ms 22276 KB Output is correct
17 Correct 28 ms 22304 KB Output is correct
18 Correct 30 ms 22408 KB Output is correct
19 Correct 27 ms 22856 KB Output is correct
20 Correct 26 ms 23532 KB Output is correct
21 Correct 27 ms 23880 KB Output is correct
22 Correct 32 ms 24040 KB Output is correct
23 Correct 28 ms 24040 KB Output is correct
24 Correct 34 ms 24224 KB Output is correct
25 Correct 28 ms 24492 KB Output is correct
26 Correct 35 ms 24584 KB Output is correct
27 Correct 27 ms 24724 KB Output is correct
28 Correct 32 ms 25096 KB Output is correct
29 Correct 30 ms 25128 KB Output is correct
30 Correct 28 ms 25196 KB Output is correct
31 Correct 7 ms 25216 KB Output is correct
32 Correct 6 ms 25216 KB Output is correct
33 Correct 7 ms 25216 KB Output is correct
34 Correct 6 ms 25216 KB Output is correct
35 Correct 6 ms 25216 KB Output is correct
36 Correct 6 ms 25216 KB Output is correct
37 Correct 7 ms 25216 KB Output is correct
38 Correct 9 ms 25216 KB Output is correct
39 Correct 6 ms 25216 KB Output is correct
40 Correct 7 ms 25216 KB Output is correct
41 Correct 6 ms 25216 KB Output is correct
42 Correct 7 ms 25216 KB Output is correct