Submission #333731

# Submission time Handle Problem Language Result Execution time Memory
333731 2020-12-07T14:53:09 Z LucaDantas Meetings (JOI19_meetings) C++17
100 / 100
1270 ms 1260 KB
#include<bits/stdc++.h>
using namespace std;
#include "meetings.h"

#define pb push_back
#define sz(a) (a).size()

std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count() ^ (long long) (make_unique<char>().get()));

constexpr int maxn = 2e3+10;

void solve(vector<int>& a) {
	if(sz(a) <= 1) return;
	if(sz(a) == 2) return (void)(Bridge(min(a[0], a[1]), max(a[0], a[1])));
	int divide = Query(a[0], a[1], a[2]);
	vector<int> head, top;
	if(divide == a[0]) head.pb(a[1]);
	else head.pb(a[0]);
	vector<vector<int>> grp;
	map<int,int> id;
	id[head[0]] = 0;
	grp.pb({head[0]});
	top.pb({head[0]});
	set<int> seen;
	seen.insert(head[0]);
	for(int x : a) {
		if(x != divide) {
			bool ok = 0;
			for(int y : head) {
				if(x == top[id[y]]) {
					if(!seen.count(x)) {
						grp[id[y]].pb(x);
						seen.insert(x);
					}
					ok = 1;
					break;
				}
				if(!seen.count(x)) {
					int opa = Query(divide, x, top[id[y]]);
					if(opa == divide) continue;
					ok = 1;
					grp[id[y]].pb(x);
					top[id[y]] = opa;
					seen.insert(x);
					break;
				} else {ok = 1; break;}
			}
			if(!ok) id[x] = sz(head), head.pb(x), grp.pb({x}), top.pb({x}), seen.insert(x);
		}
	}
	for(int y : head) {
		Bridge(min(divide, top[id[y]]), max(divide, top[id[y]]));
		solve(grp[id[y]]);
	}
}

void Solve(int n) {
	vector<int> a;
	for(int i = 0; i < n; i++)
		a.pb(i);
	shuffle(a.begin(), a.end(), rng);
	solve(a);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 13 ms 396 KB Output is correct
28 Correct 10 ms 492 KB Output is correct
29 Correct 13 ms 492 KB Output is correct
30 Correct 12 ms 512 KB Output is correct
31 Correct 10 ms 492 KB Output is correct
32 Correct 10 ms 364 KB Output is correct
33 Correct 21 ms 492 KB Output is correct
34 Correct 20 ms 364 KB Output is correct
35 Correct 18 ms 492 KB Output is correct
36 Correct 14 ms 492 KB Output is correct
37 Correct 14 ms 492 KB Output is correct
38 Correct 13 ms 492 KB Output is correct
39 Correct 15 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 937 ms 1004 KB Output is correct
2 Correct 880 ms 748 KB Output is correct
3 Correct 928 ms 1004 KB Output is correct
4 Correct 892 ms 876 KB Output is correct
5 Correct 925 ms 1132 KB Output is correct
6 Correct 837 ms 876 KB Output is correct
7 Correct 962 ms 748 KB Output is correct
8 Correct 1004 ms 748 KB Output is correct
9 Correct 1053 ms 1004 KB Output is correct
10 Correct 1069 ms 876 KB Output is correct
11 Correct 1040 ms 908 KB Output is correct
12 Correct 1051 ms 1132 KB Output is correct
13 Correct 1027 ms 1132 KB Output is correct
14 Correct 1010 ms 876 KB Output is correct
15 Correct 932 ms 876 KB Output is correct
16 Correct 1270 ms 1004 KB Output is correct
17 Correct 877 ms 1004 KB Output is correct
18 Correct 855 ms 1004 KB Output is correct
19 Correct 949 ms 1004 KB Output is correct
20 Correct 1044 ms 1132 KB Output is correct
21 Correct 1224 ms 1260 KB Output is correct
22 Correct 1165 ms 1052 KB Output is correct
23 Correct 1160 ms 1132 KB Output is correct
24 Correct 1163 ms 972 KB Output is correct
25 Correct 1125 ms 1132 KB Output is correct
26 Correct 946 ms 1004 KB Output is correct
27 Correct 1135 ms 1260 KB Output is correct
28 Correct 1160 ms 876 KB Output is correct
29 Correct 912 ms 1080 KB Output is correct
30 Correct 901 ms 876 KB Output is correct
31 Correct 1037 ms 1216 KB Output is correct
32 Correct 997 ms 1164 KB Output is correct
33 Correct 896 ms 1068 KB Output is correct
34 Correct 14 ms 492 KB Output is correct
35 Correct 11 ms 492 KB Output is correct
36 Correct 13 ms 492 KB Output is correct
37 Correct 10 ms 492 KB Output is correct
38 Correct 14 ms 492 KB Output is correct
39 Correct 10 ms 492 KB Output is correct
40 Correct 16 ms 492 KB Output is correct
41 Correct 19 ms 364 KB Output is correct
42 Correct 18 ms 492 KB Output is correct
43 Correct 13 ms 492 KB Output is correct
44 Correct 12 ms 492 KB Output is correct
45 Correct 13 ms 492 KB Output is correct
46 Correct 14 ms 492 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 1 ms 364 KB Output is correct
50 Correct 1 ms 384 KB Output is correct
51 Correct 1 ms 364 KB Output is correct
52 Correct 1 ms 364 KB Output is correct
53 Correct 1 ms 364 KB Output is correct
54 Correct 1 ms 364 KB Output is correct
55 Correct 1 ms 364 KB Output is correct
56 Correct 1 ms 364 KB Output is correct
57 Correct 1 ms 364 KB Output is correct
58 Correct 1 ms 364 KB Output is correct
59 Correct 1 ms 364 KB Output is correct
60 Correct 0 ms 364 KB Output is correct
61 Correct 1 ms 364 KB Output is correct
62 Correct 1 ms 364 KB Output is correct
63 Correct 1 ms 364 KB Output is correct
64 Correct 1 ms 364 KB Output is correct
65 Correct 1 ms 364 KB Output is correct
66 Correct 1 ms 364 KB Output is correct
67 Correct 1 ms 492 KB Output is correct
68 Correct 0 ms 364 KB Output is correct
69 Correct 0 ms 364 KB Output is correct
70 Correct 1 ms 364 KB Output is correct
71 Correct 1 ms 364 KB Output is correct
72 Correct 1 ms 364 KB Output is correct