답안 #122011

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
122011 2019-06-27T11:18:57 Z egorlifar Amusement Park (JOI17_amusement_park) C++17
98 / 100
52 ms 5132 KB
#include "Joi.h"
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <chrono>
 
using namespace std;

template<class T1, class T2> inline int chkmin(T1 &x, const T2 &y) {
    if (x > y) {
        x = y;
        return 1;
    }
    else {
        return 0;
    }
}

template<class T1, class T2> inline int chkmax(T1 &x, const T2 &y) {
    if (x < y) {
        x = y;
        return 1;
    }
    else {
        return 0;
    }
}

#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define mp make_pair
#define pb push_back
const int MAXN = 10228;


vector<int> g1[MAXN];
bool used1[MAXN];
int it1 = 0;
long long x;


void dfs1(int u) {
	used1[u] = true;
	MessageBoard(u, (x & (1LL << (it1 % 60))) != 0);
	it1++;
	for (auto h: g1[u]) {
		if (!used1[h]) {
			dfs1(h);
		}
	}
}


void Joi(int N, int M, int A[], int B[], long long X, int T) {
	assert(T <= 10);
	x = X;
  	for(int i = 0; i < N; i++){
    	used1[i] = false;
  	}
  	for (int i = 0; i < M; i++) {
  		g1[A[i]].pb(B[i]);
  		g1[B[i]].pb(A[i]);
  	}
  	dfs1(0);
}
#include "Ioi.h"
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <chrono>
 
using namespace std;

template<class T1, class T2> inline int chkmin(T1 &x, const T2 &y) {
    if (x > y) {
        x = y;
        return 1;
    }
    else {
        return 0;
    }
}

template<class T1, class T2> inline int chkmax(T1 &x, const T2 &y) {
    if (x < y) {
        x = y;
        return 1;
    }
    else {
        return 0;
    }
}

#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define mp make_pair
#define pb push_back
const int MAXN = 10228;

vector<int> g[MAXN];
bool used[MAXN];
vector<int> v[MAXN];
int pr[MAXN];
int it = 0;
int who[MAXN];
int pos[MAXN];
bool was[MAXN];
long long kek[MAXN];
long long ft;


void dfs(int u) {
	used[u] = true;
	who[u] = it % 60;
	it++;
	kek[u] = 1LL << who[u];
	for (auto h: g[u]) {
		if (!used[h]) {
			pr[h] = u;
			v[u].pb(h);
			pos[h] = sz(v[u]) - 1;
			dfs(h);
			kek[u] |= kek[h];
		}
	}
}

int cnt;
long long res = 0;


bool bfs(int u) {
	for (auto h: v[u]) {
		if ((ft & kek[h]) == kek[h]) continue;
		int gg = Move(h);
		ft |= 1LL << who[h];
		if (!was[who[h]]) {
			cnt++;
			was[who[h]] = true;
			res += (1LL << who[h]) * gg;
		}	
		if (cnt == 60) {
			return true;
		}
		if (bfs(h)) {
			return true;
		}
		Move(u);
	}
	return false;
}

long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
	assert(T <= 10);
  	for (int i = 0; i < N; i++){
    	used[i] = false;
  	}
  	assert(M >= N - 1);
  	for (int i = 0; i < M; i++) {
  		g[A[i]].pb(B[i]);
  		g[B[i]].pb(A[i]);
  	}
  	for (int i = 0; i < 60; i++) {
  		was[i] = false;
  	}
  	pr[0] = -1;
  	dfs(0);
  	int cur = P;
  	was[who[cur]] = true;
  	res += (1LL << who[cur]) * V;
  	ft |= 1LL << who[cur];
  	cnt = 1;
  	if (bfs(cur)) {
  		return res;
  	}
  	while (true) {
  		int fk = pos[cur];
  		int gg = Move(pr[cur]);
  		ft |= 1LL << who[pr[cur]];
		if (!was[who[pr[cur]]]) {
			cnt++;
			was[who[pr[cur]]] = true;
			res += (1LL << who[pr[cur]]) * gg;
		}	
		cur = pr[cur];
		if (cnt == 60) {
			return res;
		}
		for (int i = fk + 1; i < sz(v[cur]); i++) {
			int h = v[cur][i];
			if ((ft & kek[h]) == kek[h]) {
				continue;
			}
			int gg = Move(h);
			ft |= 1LL << who[h];
			if (!was[who[h]]) {
				cnt++;
				was[who[h]] = true;
				res += (1LL << who[h]) * gg;
			}
			if (cnt == 60) {
				return res;
			}	
			if (bfs(h)) {
				return res;
			}
			Move(cur);
		}
		for (int i = 0; i < fk; i++) {
			int h = v[cur][i];
			if ((ft & kek[h]) == kek[h]) {
				continue;
			}
			int gg = Move(h);
			ft |= 1LL << who[h];
			if (!was[who[h]]) {
				cnt++;
				was[who[h]] = true;
				res += (1LL << who[h]) * gg;
			}
			if (cnt == 60) {
				return res;
			}	
			if (bfs(h)) {
				return res;
			}
			Move(cur);
		}
  	}
  	return 0LL;	
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1408 KB Output is correct
2 Correct 4 ms 1536 KB Output is correct
3 Correct 4 ms 1636 KB Output is correct
4 Correct 5 ms 1672 KB Output is correct
5 Correct 4 ms 1544 KB Output is correct
6 Correct 4 ms 1772 KB Output is correct
7 Correct 4 ms 1552 KB Output is correct
8 Correct 5 ms 1672 KB Output is correct
9 Correct 4 ms 1680 KB Output is correct
10 Correct 4 ms 1540 KB Output is correct
11 Correct 7 ms 1892 KB Output is correct
12 Correct 4 ms 1412 KB Output is correct
13 Correct 4 ms 1672 KB Output is correct
14 Correct 4 ms 1768 KB Output is correct
15 Correct 4 ms 1636 KB Output is correct
16 Correct 4 ms 1552 KB Output is correct
17 Correct 4 ms 1548 KB Output is correct
18 Correct 4 ms 1764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 4688 KB Output is correct
2 Correct 33 ms 4732 KB Output is correct
3 Correct 30 ms 4820 KB Output is correct
4 Correct 18 ms 3300 KB Output is correct
5 Correct 19 ms 3968 KB Output is correct
6 Correct 18 ms 3656 KB Output is correct
7 Correct 17 ms 3752 KB Output is correct
8 Correct 18 ms 3832 KB Output is correct
9 Correct 18 ms 3856 KB Output is correct
10 Correct 16 ms 3652 KB Output is correct
11 Correct 16 ms 3524 KB Output is correct
12 Correct 17 ms 3264 KB Output is correct
13 Correct 16 ms 3352 KB Output is correct
14 Correct 16 ms 3364 KB Output is correct
15 Correct 18 ms 3732 KB Output is correct
16 Correct 19 ms 3632 KB Output is correct
17 Correct 18 ms 3504 KB Output is correct
18 Correct 18 ms 3632 KB Output is correct
19 Correct 17 ms 3496 KB Output is correct
20 Correct 15 ms 4060 KB Output is correct
21 Correct 15 ms 4016 KB Output is correct
22 Correct 19 ms 3776 KB Output is correct
23 Correct 20 ms 3992 KB Output is correct
24 Correct 19 ms 3896 KB Output is correct
25 Correct 18 ms 3896 KB Output is correct
26 Correct 19 ms 4080 KB Output is correct
27 Correct 18 ms 3960 KB Output is correct
28 Correct 18 ms 3896 KB Output is correct
29 Correct 16 ms 3632 KB Output is correct
30 Correct 17 ms 3748 KB Output is correct
31 Correct 4 ms 1412 KB Output is correct
32 Correct 4 ms 1548 KB Output is correct
33 Correct 4 ms 1672 KB Output is correct
34 Correct 4 ms 1676 KB Output is correct
35 Correct 4 ms 1772 KB Output is correct
36 Correct 4 ms 1548 KB Output is correct
37 Correct 4 ms 1412 KB Output is correct
38 Correct 4 ms 1540 KB Output is correct
39 Correct 4 ms 1548 KB Output is correct
40 Correct 4 ms 1540 KB Output is correct
41 Correct 4 ms 1540 KB Output is correct
42 Correct 4 ms 1640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1536 KB Output is correct
2 Correct 4 ms 1544 KB Output is correct
3 Correct 5 ms 1536 KB Output is correct
4 Correct 6 ms 2152 KB Output is correct
5 Correct 6 ms 2076 KB Output is correct
6 Correct 6 ms 2076 KB Output is correct
7 Correct 6 ms 2184 KB Output is correct
8 Correct 6 ms 2076 KB Output is correct
9 Correct 14 ms 4416 KB Output is correct
10 Correct 15 ms 4416 KB Output is correct
11 Correct 16 ms 4552 KB Output is correct
12 Correct 5 ms 1672 KB Output is correct
13 Correct 5 ms 1536 KB Output is correct
14 Correct 6 ms 1644 KB Output is correct
15 Correct 4 ms 1644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 4848 KB Output is correct
2 Partially correct 28 ms 4828 KB Partially correct
3 Correct 28 ms 5132 KB Output is correct
4 Correct 18 ms 3668 KB Output is correct
5 Correct 18 ms 4636 KB Output is correct
6 Correct 18 ms 3888 KB Output is correct
7 Correct 18 ms 4016 KB Output is correct
8 Correct 18 ms 3768 KB Output is correct
9 Correct 18 ms 3996 KB Output is correct
10 Correct 17 ms 3516 KB Output is correct
11 Correct 16 ms 3396 KB Output is correct
12 Correct 17 ms 3360 KB Output is correct
13 Correct 18 ms 3352 KB Output is correct
14 Correct 18 ms 3456 KB Output is correct
15 Correct 19 ms 3504 KB Output is correct
16 Correct 18 ms 3504 KB Output is correct
17 Correct 20 ms 3560 KB Output is correct
18 Correct 18 ms 3640 KB Output is correct
19 Correct 20 ms 3504 KB Output is correct
20 Correct 16 ms 4016 KB Output is correct
21 Correct 22 ms 4064 KB Output is correct
22 Correct 20 ms 4016 KB Output is correct
23 Correct 20 ms 3896 KB Output is correct
24 Correct 19 ms 3896 KB Output is correct
25 Correct 18 ms 4016 KB Output is correct
26 Correct 18 ms 3972 KB Output is correct
27 Correct 18 ms 4016 KB Output is correct
28 Correct 18 ms 3632 KB Output is correct
29 Correct 17 ms 3736 KB Output is correct
30 Correct 17 ms 3872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 4820 KB Output is correct
2 Correct 30 ms 4792 KB Output is correct
3 Correct 30 ms 4820 KB Output is correct
4 Correct 18 ms 3272 KB Output is correct
5 Correct 20 ms 4336 KB Output is correct
6 Correct 19 ms 3772 KB Output is correct
7 Correct 18 ms 3648 KB Output is correct
8 Correct 19 ms 3784 KB Output is correct
9 Correct 19 ms 3776 KB Output is correct
10 Correct 17 ms 3144 KB Output is correct
11 Correct 18 ms 3264 KB Output is correct
12 Correct 17 ms 3256 KB Output is correct
13 Correct 17 ms 3220 KB Output is correct
14 Correct 17 ms 3256 KB Output is correct
15 Correct 18 ms 3264 KB Output is correct
16 Correct 19 ms 3696 KB Output is correct
17 Correct 18 ms 3512 KB Output is correct
18 Correct 17 ms 3512 KB Output is correct
19 Correct 18 ms 3556 KB Output is correct
20 Correct 16 ms 4024 KB Output is correct
21 Correct 14 ms 4016 KB Output is correct
22 Correct 18 ms 3808 KB Output is correct
23 Correct 18 ms 3896 KB Output is correct
24 Correct 18 ms 3888 KB Output is correct
25 Correct 18 ms 3888 KB Output is correct
26 Correct 19 ms 3920 KB Output is correct
27 Correct 19 ms 4068 KB Output is correct
28 Correct 18 ms 3936 KB Output is correct
29 Correct 17 ms 3736 KB Output is correct
30 Correct 18 ms 3748 KB Output is correct
31 Correct 4 ms 1412 KB Output is correct
32 Correct 4 ms 1548 KB Output is correct
33 Correct 5 ms 1672 KB Output is correct
34 Correct 4 ms 1668 KB Output is correct
35 Correct 4 ms 1700 KB Output is correct
36 Correct 5 ms 1644 KB Output is correct
37 Correct 5 ms 1676 KB Output is correct
38 Correct 4 ms 1544 KB Output is correct
39 Correct 6 ms 1676 KB Output is correct
40 Correct 5 ms 1640 KB Output is correct
41 Correct 4 ms 1768 KB Output is correct
42 Correct 4 ms 1540 KB Output is correct