#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;
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]});
for(int x : a) {
if(x != divide) {
bool ok = 0;
for(int y : head) {
if(x != y) {
if(Query(divide, x, y) != divide)
ok = 1, grp[id[y]].pb(x);
} else ok = 1;
}
if(!ok) id[x] = sz(head), head.pb(x), grp.pb({x});
}
}
for(int y : head) {
int top = y;
for(int x : grp[id[y]])
if(x != top)
top = Query(divide, x, top);
Bridge(min(divide, top), max(divide, top));
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);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 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 |
0 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 |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
0 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 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 |
0 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 |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
0 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 |
384 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 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 |
0 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 |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
0 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 |
384 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 |
26 ms |
364 KB |
Output is correct |
28 |
Correct |
28 ms |
364 KB |
Output is correct |
29 |
Correct |
27 ms |
364 KB |
Output is correct |
30 |
Correct |
23 ms |
364 KB |
Output is correct |
31 |
Correct |
21 ms |
364 KB |
Output is correct |
32 |
Correct |
22 ms |
364 KB |
Output is correct |
33 |
Correct |
28 ms |
492 KB |
Output is correct |
34 |
Correct |
27 ms |
364 KB |
Output is correct |
35 |
Correct |
27 ms |
364 KB |
Output is correct |
36 |
Correct |
25 ms |
364 KB |
Output is correct |
37 |
Correct |
21 ms |
492 KB |
Output is correct |
38 |
Correct |
26 ms |
492 KB |
Output is correct |
39 |
Correct |
22 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2997 ms |
904 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |