Submission #410776

# Submission time Handle Problem Language Result Execution time Memory
410776 2021-05-23T17:39:26 Z AmineWeslati Amusement Park (JOI17_amusement_park) C++14
78 / 100
33 ms 6892 KB
#include "Joi.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int>vi; 
#define pb push_back
#define sz(v) (int)v.size()
#define all(x) begin(x),end(x)

#define FOR(i,a,b) for(int i=a; i<b; i++)
#define ROF(i,a,b) for(int i=b-1; i>=a; i--)

//------------------------------------------------//

const int MX=2e4+10;
const int LOG=60;

bitset<LOG>b;

int N; 
vi nei[MX];

vi par(MX),adj[MX],bit(MX),val(MX);
int cnt=-1;

vi viss(MX,0);

void dfs(int u, int p){
	viss[u]=1;
	par[u]=p;

	bit[u]=++cnt; bit[u]%=LOG;
	val[u]=b[bit[u]];

	for(int v: nei[u]) if(!viss[v]){
		adj[u].pb(v);
		dfs(v,u);
	}
}

void Joi(int N, int M, int A[], int B[], ll X, int T){
	::N=N; 
	FOR(i,0,M){
		int u=A[i],v=B[i];
		nei[u].pb(v);
		nei[v].pb(u);
	}
	FOR(i,0,LOG){
		b[i]=X%2;
		X/=2;
	}

	dfs(0,0);	

	FOR(i,0,N) MessageBoard(i,val[i]);
}
#include "Ioi.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int>vi; 
#define pb push_back
#define sz(v) (int)v.size()
#define all(x) begin(x),end(x)

#define FOR(i,a,b) for(int i=a; i<b; i++)
#define ROF(i,a,b) for(int i=b-1; i>=a; i--)

//------------------------------------------------//

const int MX=2e4+10;
const int LOG=60;

vi nei2[MX];

vi par2(MX),adj2[MX],bit2(MX);
int cnt2=-1;

vi visss(MX,0);
void dfs2(int u, int p){
	visss[u]=1;
	par2[u]=p;

	bit2[u]=++cnt2; bit2[u]%=LOG;

	for(int v: nei2[u]) if(!visss[v]){
		adj2[u].pb(v);
		dfs2(v,u);
	}
}

vi ans(LOG),vis(MX,0);
set<int>s;

void explore(int u, int x){
	

	vis[u]=1;
	s.insert(bit2[u]);
	ans[bit2[u]]=x; 

	if(sz(s)>=LOG) return; 
	

	int all=1,none=1;
	for(int v: adj2[u]){
		if(!vis[v]) all=0;
		if(vis[v]) none=0;
	}

	if(all){
		explore(par2[u],Move(par2[u]));
	}
	else if(none){
		explore(adj2[u][0],Move(adj2[u][0]));
	}
	else{
		int idx=-1;
		FOR(i,0,sz(adj2[u])) if(vis[adj2[u][i]]){
			idx=i;
			while(vis[adj2[u][idx]]){
				idx++; 
				idx%=sz(adj2[u]);
			}
			break;
		}
		assert(idx!=-1);

		explore(adj2[u][idx],Move(adj2[u][idx]));
	}
}

ll Ioi(int N, int M, int A[], int B[], int P, int V, int T){
	FOR(i,0,M){
		int u=A[i],v=B[i];
		nei2[u].pb(v);
		nei2[v].pb(u);
	}
	dfs2(0,0);

	explore(P,V);

	ll x=0;
	ROF(i,0,LOG){
		x*=2;
		x+=ans[i];
	}
	return x;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3056 KB Output is correct
2 Correct 3 ms 3052 KB Output is correct
3 Correct 3 ms 3136 KB Output is correct
4 Correct 3 ms 3056 KB Output is correct
5 Correct 3 ms 3052 KB Output is correct
6 Correct 3 ms 3060 KB Output is correct
7 Correct 4 ms 3068 KB Output is correct
8 Correct 3 ms 3060 KB Output is correct
9 Correct 4 ms 3056 KB Output is correct
10 Correct 4 ms 3048 KB Output is correct
11 Correct 7 ms 3472 KB Output is correct
12 Correct 3 ms 3052 KB Output is correct
13 Correct 3 ms 3068 KB Output is correct
14 Correct 4 ms 3068 KB Output is correct
15 Correct 3 ms 3060 KB Output is correct
16 Correct 3 ms 3056 KB Output is correct
17 Correct 3 ms 3056 KB Output is correct
18 Correct 3 ms 3124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 6256 KB Output is correct
2 Correct 30 ms 6776 KB Output is correct
3 Correct 33 ms 6892 KB Output is correct
4 Correct 19 ms 5000 KB Output is correct
5 Correct 18 ms 5944 KB Output is correct
6 Correct 18 ms 5368 KB Output is correct
7 Correct 22 ms 5516 KB Output is correct
8 Correct 25 ms 5588 KB Output is correct
9 Correct 18 ms 5596 KB Output is correct
10 Correct 16 ms 4988 KB Output is correct
11 Correct 18 ms 5012 KB Output is correct
12 Correct 16 ms 4856 KB Output is correct
13 Correct 16 ms 4836 KB Output is correct
14 Correct 17 ms 4876 KB Output is correct
15 Correct 18 ms 5288 KB Output is correct
16 Correct 20 ms 5276 KB Output is correct
17 Correct 17 ms 5008 KB Output is correct
18 Correct 18 ms 5116 KB Output is correct
19 Correct 18 ms 5136 KB Output is correct
20 Correct 15 ms 5684 KB Output is correct
21 Correct 14 ms 5648 KB Output is correct
22 Correct 18 ms 5364 KB Output is correct
23 Correct 20 ms 5444 KB Output is correct
24 Correct 18 ms 5372 KB Output is correct
25 Correct 20 ms 5420 KB Output is correct
26 Correct 18 ms 5524 KB Output is correct
27 Correct 18 ms 5524 KB Output is correct
28 Correct 18 ms 5612 KB Output is correct
29 Correct 20 ms 5324 KB Output is correct
30 Correct 19 ms 5316 KB Output is correct
31 Correct 3 ms 3052 KB Output is correct
32 Correct 3 ms 3052 KB Output is correct
33 Correct 4 ms 3056 KB Output is correct
34 Correct 3 ms 3052 KB Output is correct
35 Correct 3 ms 3052 KB Output is correct
36 Correct 2 ms 3056 KB Output is correct
37 Correct 2 ms 3052 KB Output is correct
38 Correct 3 ms 3120 KB Output is correct
39 Correct 3 ms 3060 KB Output is correct
40 Correct 2 ms 3048 KB Output is correct
41 Correct 3 ms 3052 KB Output is correct
42 Correct 3 ms 3060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3048 KB Output is correct
2 Correct 2 ms 3048 KB Output is correct
3 Correct 3 ms 3080 KB Output is correct
4 Correct 4 ms 3596 KB Output is correct
5 Correct 4 ms 3588 KB Output is correct
6 Correct 4 ms 3588 KB Output is correct
7 Correct 5 ms 3592 KB Output is correct
8 Correct 4 ms 3596 KB Output is correct
9 Correct 15 ms 6316 KB Output is correct
10 Correct 15 ms 6324 KB Output is correct
11 Correct 15 ms 6244 KB Output is correct
12 Correct 2 ms 3048 KB Output is correct
13 Correct 3 ms 3060 KB Output is correct
14 Correct 2 ms 3048 KB Output is correct
15 Correct 4 ms 3052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 6268 KB Output is correct
2 Partially correct 30 ms 6760 KB Partially correct
3 Correct 29 ms 6652 KB Output is correct
4 Correct 17 ms 5112 KB Output is correct
5 Correct 20 ms 6096 KB Output is correct
6 Correct 20 ms 5576 KB Output is correct
7 Correct 20 ms 5664 KB Output is correct
8 Correct 18 ms 5284 KB Output is correct
9 Correct 18 ms 5388 KB Output is correct
10 Correct 16 ms 5012 KB Output is correct
11 Correct 17 ms 5024 KB Output is correct
12 Correct 16 ms 4864 KB Output is correct
13 Correct 16 ms 4856 KB Output is correct
14 Correct 16 ms 4860 KB Output is correct
15 Correct 18 ms 5224 KB Output is correct
16 Correct 23 ms 5216 KB Output is correct
17 Correct 18 ms 5136 KB Output is correct
18 Correct 17 ms 5196 KB Output is correct
19 Correct 19 ms 5208 KB Output is correct
20 Correct 15 ms 5688 KB Output is correct
21 Correct 14 ms 5692 KB Output is correct
22 Correct 20 ms 5368 KB Output is correct
23 Correct 20 ms 5332 KB Output is correct
24 Correct 20 ms 5336 KB Output is correct
25 Correct 18 ms 5596 KB Output is correct
26 Correct 18 ms 5536 KB Output is correct
27 Correct 18 ms 5636 KB Output is correct
28 Correct 19 ms 5456 KB Output is correct
29 Correct 16 ms 5260 KB Output is correct
30 Correct 17 ms 5440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 6288 KB Output is correct
2 Correct 28 ms 6772 KB Output is correct
3 Correct 28 ms 6776 KB Output is correct
4 Incorrect 20 ms 5040 KB Output isn't correct
5 Halted 0 ms 0 KB -