Submission #558771

# Submission time Handle Problem Language Result Execution time Memory
558771 2022-05-08T09:58:28 Z Trunkty Amusement Park (JOI17_amusement_park) C++14
18 / 100
32 ms 6540 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

#define DEBUG
#ifdef DEBUG
  #define debug(x) cout << #x << ": " << x << endl
#else
  #define debug(x)
#endif

#include "Joi.h"

vector<int> roads[10005],tree[10005];
ll siz[100005],pos[100005],dia,pa,pb;
bool check[10005];

void dfs(int x){
	check[x] = true;
	siz[x] = 1;
	pos[x] = x;
	for(int i:roads[x]){
		if(!check[i]){
			tree[x].push_back(i);
			tree[i].push_back(x);
			dfs(i);
			if(siz[x]+siz[i]>dia){
				pa = pos[x];
				pb = pos[i];
				dia = max(dia,siz[x]+siz[i]);
			}
			if(siz[i]+1>siz[x]){
				siz[x] = siz[i]+1;
				pos[x] = pos[i];
			}
		}
	}
}

ll dep[100005],par[100005];

void one(int x, int p, ll d){
	par[x] = p;
	dep[x] = d;
	for(int i:tree[x]){
		if(i!=p){
			one(i,x,d+1);
		}
	}
}

ll nextnode,xx;

void two(int x, int p){
	if(nextnode<60){
		if((1LL<<nextnode)&xx){
			MessageBoard(x,1);
		}
		else{
			MessageBoard(x,0);
		}
		nextnode++;
	}
	else{
		MessageBoard(x,0);
	}
	for(int i:tree[x]){
		if(i!=p){
			two(i,x);
		}
	}
}

void Joi(int n, int m, int a[], int b[], ll x, int t){
	xx = x;
	for(int i=0;i<m;i++){
		roads[a[i]].push_back(b[i]);
		roads[b[i]].push_back(a[i]);
	}
	dfs(0);
	if(dia>=60){
		one(pa,-1,0);
		for(int i=0;i<n;i++){
			if((1LL<<(dep[i]%60LL))&x){
				MessageBoard(i,1);
			}
			else{
				MessageBoard(i,0);
			}
		}
	}
	else{
		one(0,-1,0);
		dia/=2;
		if(dep[pb]>dep[pa]){
			swap(pa,pb);
		}
		for(int i=1;i<=dia;i++){
			pa = par[pa];
		}
		one(pa,-1,0);
		two(pa,-1);
		return;
	}
}
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

#define DEBUG
#ifdef DEBUG
  #define debug(x) cout << #x << ": " << x << endl
#else
  #define debug(x)
#endif

#include "Ioi.h"

vector<int> roads[10005],tree[10005];
ll siz[100005],pos[100005],dia,pa,pb;
bool check[10005];

void dfs(int x){
	check[x] = true;
	siz[x] = 1;
	pos[x] = x;
	for(int i:roads[x]){
		if(!check[i]){
			tree[x].push_back(i);
			tree[i].push_back(x);
			dfs(i);
			if(siz[x]+siz[i]>dia){
				pa = pos[x];
				pb = pos[i];
				dia = max(dia,siz[x]+siz[i]);
			}
			if(siz[i]+1>siz[x]){
				siz[x] = siz[i]+1;
				pos[x] = pos[i];
			}
		}
	}
}

ll dep[100005],par[100005];

void one(int x, int p, ll d){
	par[x] = p;
	dep[x] = d;
	for(int i:tree[x]){
		if(i!=p){
			one(i,x,d+1);
		}
	}
}

ll ans=0,typ[100005],nextnode;

void two(int x, int p){
	if(nextnode<60){
		typ[x] = nextnode;
		nextnode++;
	}
	else{
		typ[x] = -1;
	}
	for(int i:tree[x]){
		if(i!=p){
			two(i,x);
		}
	}
}

int s;

void three(int x, int p){
	s++;
	vector<vector<ll>> ord;
	for(int i:tree[x]){
		if(i!=p and typ[i]!=-1){
			ord.push_back({typ[i],i});
		}
	}
	sort(ord.begin(),ord.end(),greater<vector<ll>>());
	for(vector<ll> i:ord){
		if(Move(i[1])){
			ans += (1LL<<(typ[i[1]]));
		}
		three(i[1],x);
	}
	if(s!=60){
		Move(p);
	}
}


ll Ioi(int n, int m, int a[], int b[], int p, int v, int t){
	for(int i=0;i<m;i++){
		roads[a[i]].push_back(b[i]);
		roads[b[i]].push_back(a[i]);
	}
	dfs(0);
	if(dia>=60){
		one(pa,-1,0);
		if(dep[p]<=60){
			if(p!=pa){
				while(par[p]!=pa){
					Move(par[p]);
					p = par[p];
				}
				p = par[p];
				if(Move(p)){
					ans += (1LL<<(dep[p]%60LL));
				}
			}
			else{
				if(v){
					ans += (1LL<<(dep[p]%60LL));
				}
			}
			for(int i=1;i<=59;i++){
				for(int x:tree[p]){
					if(dep[x]==i){
						p = x;
						if(Move(p)){
							ans += (1LL<<(dep[p]%60LL));
						}
						break;
					}
				}
			}
		}
		else{
			if(v){
				ans += (1LL<<(dep[p]%60LL));
			}
			for(int i=1;i<=59;i++){
				p = par[p];
				if(Move(p)){
					ans += (1LL<<(dep[p]%60LL));
				}
			}
		}
	}
	else{
		one(0,-1,0);
		dia/=2;
		if(dep[pb]>dep[pa]){
			swap(pa,pb);
		}
		for(int i=1;i<=dia;i++){
			pa = par[pa];
		}
		one(pa,-1,0);
			if(p!=pa){
				while(par[p]!=pa){
					Move(par[p]);
					p = par[p];
				}
				p = par[p];
				if(Move(p)){
					ans += (1LL<<(0LL%60LL));
				}
			}
			else{
				if(v){
					ans += (1LL<<(0LL%60LL));
				}
			}
		
		two(pa,-1);
		three(pa,-1);
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1480 KB Output is correct
2 Correct 2 ms 1552 KB Output is correct
3 Correct 2 ms 1808 KB Output is correct
4 Correct 2 ms 1544 KB Output is correct
5 Correct 2 ms 1544 KB Output is correct
6 Correct 2 ms 1544 KB Output is correct
7 Correct 2 ms 1736 KB Output is correct
8 Correct 2 ms 1804 KB Output is correct
9 Correct 2 ms 1780 KB Output is correct
10 Correct 2 ms 1544 KB Output is correct
11 Correct 5 ms 2012 KB Output is correct
12 Correct 2 ms 1544 KB Output is correct
13 Correct 2 ms 1804 KB Output is correct
14 Correct 2 ms 1816 KB Output is correct
15 Correct 2 ms 1812 KB Output is correct
16 Correct 2 ms 1812 KB Output is correct
17 Correct 2 ms 1736 KB Output is correct
18 Correct 2 ms 1804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 5988 KB Output is correct
2 Correct 25 ms 6476 KB Output is correct
3 Correct 24 ms 6448 KB Output is correct
4 Correct 17 ms 4592 KB Output is correct
5 Correct 16 ms 5288 KB Output is correct
6 Correct 16 ms 5016 KB Output is correct
7 Correct 16 ms 5144 KB Output is correct
8 Correct 18 ms 5188 KB Output is correct
9 Correct 18 ms 5196 KB Output is correct
10 Correct 16 ms 4596 KB Output is correct
11 Correct 14 ms 4716 KB Output is correct
12 Correct 15 ms 4264 KB Output is correct
13 Correct 14 ms 4308 KB Output is correct
14 Correct 15 ms 4328 KB Output is correct
15 Correct 17 ms 4568 KB Output is correct
16 Correct 18 ms 4648 KB Output is correct
17 Correct 18 ms 4644 KB Output is correct
18 Correct 20 ms 4580 KB Output is correct
19 Correct 16 ms 4576 KB Output is correct
20 Correct 18 ms 5440 KB Output is correct
21 Correct 16 ms 5368 KB Output is correct
22 Correct 19 ms 4864 KB Output is correct
23 Correct 16 ms 5148 KB Output is correct
24 Correct 20 ms 5024 KB Output is correct
25 Correct 17 ms 5144 KB Output is correct
26 Correct 16 ms 5148 KB Output is correct
27 Correct 15 ms 5160 KB Output is correct
28 Correct 15 ms 5152 KB Output is correct
29 Correct 14 ms 4888 KB Output is correct
30 Correct 17 ms 4876 KB Output is correct
31 Correct 2 ms 1544 KB Output is correct
32 Correct 2 ms 1548 KB Output is correct
33 Correct 2 ms 1812 KB Output is correct
34 Correct 2 ms 1544 KB Output is correct
35 Correct 2 ms 1552 KB Output is correct
36 Correct 2 ms 1552 KB Output is correct
37 Incorrect 2 ms 1552 KB Wrong Answer [7]
38 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1540 KB Output is correct
2 Correct 2 ms 1544 KB Output is correct
3 Correct 2 ms 1544 KB Output is correct
4 Correct 3 ms 2432 KB Output is correct
5 Correct 3 ms 2364 KB Output is correct
6 Correct 3 ms 2364 KB Output is correct
7 Correct 3 ms 2356 KB Output is correct
8 Correct 4 ms 2364 KB Output is correct
9 Correct 14 ms 6168 KB Output is correct
10 Correct 14 ms 6176 KB Output is correct
11 Correct 14 ms 6160 KB Output is correct
12 Correct 2 ms 1552 KB Output is correct
13 Correct 2 ms 1552 KB Output is correct
14 Correct 2 ms 1664 KB Output is correct
15 Correct 2 ms 1544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 6104 KB Output is correct
2 Correct 27 ms 6404 KB Output is correct
3 Correct 26 ms 6540 KB Output is correct
4 Correct 18 ms 4644 KB Output is correct
5 Correct 15 ms 5784 KB Output is correct
6 Incorrect 15 ms 5168 KB Wrong Answer [7]
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 6040 KB Output is correct
2 Correct 24 ms 6408 KB Output is correct
3 Correct 32 ms 6336 KB Output is correct
4 Correct 20 ms 4500 KB Output is correct
5 Correct 17 ms 5972 KB Output is correct
6 Correct 19 ms 5036 KB Output is correct
7 Correct 16 ms 4904 KB Output is correct
8 Correct 15 ms 5168 KB Output is correct
9 Correct 15 ms 5164 KB Output is correct
10 Correct 16 ms 4648 KB Output is correct
11 Correct 14 ms 4648 KB Output is correct
12 Correct 14 ms 4164 KB Output is correct
13 Correct 18 ms 4224 KB Output is correct
14 Correct 16 ms 4448 KB Output is correct
15 Correct 16 ms 4484 KB Output is correct
16 Correct 17 ms 4512 KB Output is correct
17 Correct 17 ms 4524 KB Output is correct
18 Correct 16 ms 4524 KB Output is correct
19 Correct 16 ms 4640 KB Output is correct
20 Correct 12 ms 5412 KB Output is correct
21 Correct 11 ms 5360 KB Output is correct
22 Correct 14 ms 5156 KB Output is correct
23 Correct 17 ms 5160 KB Output is correct
24 Correct 14 ms 5044 KB Output is correct
25 Correct 15 ms 5104 KB Output is correct
26 Correct 17 ms 4856 KB Output is correct
27 Correct 16 ms 5412 KB Output is correct
28 Correct 23 ms 5232 KB Output is correct
29 Correct 16 ms 5088 KB Output is correct
30 Correct 15 ms 5100 KB Output is correct
31 Correct 2 ms 1552 KB Output is correct
32 Correct 2 ms 1556 KB Output is correct
33 Correct 2 ms 1808 KB Output is correct
34 Correct 2 ms 1604 KB Output is correct
35 Correct 2 ms 1544 KB Output is correct
36 Incorrect 2 ms 1544 KB Wrong Answer [7]
37 Halted 0 ms 0 KB -