#include "fun.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1e5;
int N, Q;
vector<int> adj[MAXN+10];
map<pii, int> memo1;
int query1(int u, int v)
{
if(u>v) swap(u, v);
if(u==v) return 0;
if(memo1.find({u, v})!=memo1.end()) return memo1[{u, v}];
return memo1[{u, v}]=hoursRequired(u-1, v-1);
}
map<pii, int> memo2;
int query2(int u, int v)
{
if(u==v) return N;
if(memo2.find({u, v})!=memo2.end()) return memo2[{u, v}];
return memo2[{u, v}]=attractionsBehind(u-1, v-1);
}
bool vis[MAXN+10];
int D[MAXN+10];
void dfs(int now, int bef, int d)
{
D[now]=d;
for(int nxt : adj[now])
{
if(nxt==bef) continue;
if(vis[nxt]) continue;
dfs(nxt, now, d+1);
}
}
vector<int> createFunTour(int _N, int _Q)
{
N=_N; Q=_Q;
vector<int> ans;
for(int i=1; i<=N; i++) for(int j=i+1; j<=N; j++)
{
if(query1(i, j)==1)
{
adj[i].push_back(j);
adj[j].push_back(i);
}
}
int u=1;
dfs(1, 1, 1);
for(int i=1; i<=N; i++) if(D[u]<D[i]) u=i;
ans.push_back(u); vis[u]=true;
for(int i=2; i<=N; i++)
{
dfs(u, u, 1);
for(int i=1; i<=N; i++) if(D[u]<D[i]) u=i;
ans.push_back(u); vis[u]=true;
}
for(auto &it : ans) it--;
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Correct |
2 ms |
2688 KB |
Output is correct |
4 |
Correct |
2 ms |
2688 KB |
Output is correct |
5 |
Correct |
2 ms |
2688 KB |
Output is correct |
6 |
Correct |
2 ms |
2688 KB |
Output is correct |
7 |
Correct |
2 ms |
2688 KB |
Output is correct |
8 |
Correct |
2 ms |
2688 KB |
Output is correct |
9 |
Correct |
2 ms |
2688 KB |
Output is correct |
10 |
Correct |
2 ms |
2688 KB |
Output is correct |
11 |
Correct |
2 ms |
2688 KB |
Output is correct |
12 |
Correct |
2 ms |
2688 KB |
Output is correct |
13 |
Correct |
2 ms |
2688 KB |
Output is correct |
14 |
Correct |
2 ms |
2688 KB |
Output is correct |
15 |
Correct |
2 ms |
2688 KB |
Output is correct |
16 |
Correct |
2 ms |
2688 KB |
Output is correct |
17 |
Correct |
2 ms |
2688 KB |
Output is correct |
18 |
Correct |
2 ms |
2688 KB |
Output is correct |
19 |
Correct |
2 ms |
2688 KB |
Output is correct |
20 |
Correct |
2 ms |
2688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Correct |
2 ms |
2688 KB |
Output is correct |
4 |
Correct |
2 ms |
2688 KB |
Output is correct |
5 |
Correct |
2 ms |
2688 KB |
Output is correct |
6 |
Correct |
2 ms |
2688 KB |
Output is correct |
7 |
Correct |
2 ms |
2688 KB |
Output is correct |
8 |
Correct |
2 ms |
2688 KB |
Output is correct |
9 |
Correct |
2 ms |
2688 KB |
Output is correct |
10 |
Correct |
2 ms |
2688 KB |
Output is correct |
11 |
Correct |
2 ms |
2688 KB |
Output is correct |
12 |
Correct |
2 ms |
2688 KB |
Output is correct |
13 |
Correct |
2 ms |
2688 KB |
Output is correct |
14 |
Correct |
2 ms |
2688 KB |
Output is correct |
15 |
Correct |
2 ms |
2688 KB |
Output is correct |
16 |
Correct |
2 ms |
2688 KB |
Output is correct |
17 |
Correct |
2 ms |
2688 KB |
Output is correct |
18 |
Correct |
2 ms |
2688 KB |
Output is correct |
19 |
Correct |
2 ms |
2688 KB |
Output is correct |
20 |
Correct |
2 ms |
2688 KB |
Output is correct |
21 |
Correct |
2 ms |
2688 KB |
Output is correct |
22 |
Correct |
2 ms |
2688 KB |
Output is correct |
23 |
Correct |
2 ms |
2688 KB |
Output is correct |
24 |
Correct |
51 ms |
10488 KB |
Output is correct |
25 |
Correct |
2 ms |
2688 KB |
Output is correct |
26 |
Correct |
4 ms |
3072 KB |
Output is correct |
27 |
Correct |
7 ms |
3584 KB |
Output is correct |
28 |
Correct |
2 ms |
2688 KB |
Output is correct |
29 |
Correct |
52 ms |
10492 KB |
Output is correct |
30 |
Correct |
3 ms |
2816 KB |
Output is correct |
31 |
Correct |
9 ms |
3968 KB |
Output is correct |
32 |
Correct |
16 ms |
4992 KB |
Output is correct |
33 |
Correct |
5 ms |
3328 KB |
Output is correct |
34 |
Correct |
52 ms |
10616 KB |
Output is correct |
35 |
Correct |
52 ms |
10616 KB |
Output is correct |
36 |
Correct |
54 ms |
10616 KB |
Output is correct |
37 |
Correct |
5 ms |
3072 KB |
Output is correct |
38 |
Correct |
49 ms |
9848 KB |
Output is correct |
39 |
Correct |
16 ms |
4992 KB |
Output is correct |
40 |
Correct |
25 ms |
6528 KB |
Output is correct |
41 |
Correct |
8 ms |
3840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Correct |
2 ms |
2688 KB |
Output is correct |
4 |
Correct |
2 ms |
2688 KB |
Output is correct |
5 |
Correct |
2 ms |
2688 KB |
Output is correct |
6 |
Correct |
2 ms |
2688 KB |
Output is correct |
7 |
Correct |
2 ms |
2688 KB |
Output is correct |
8 |
Correct |
2 ms |
2688 KB |
Output is correct |
9 |
Correct |
2 ms |
2688 KB |
Output is correct |
10 |
Correct |
2 ms |
2688 KB |
Output is correct |
11 |
Correct |
2 ms |
2688 KB |
Output is correct |
12 |
Correct |
51 ms |
10488 KB |
Output is correct |
13 |
Correct |
2 ms |
2688 KB |
Output is correct |
14 |
Correct |
4 ms |
3072 KB |
Output is correct |
15 |
Correct |
7 ms |
3584 KB |
Output is correct |
16 |
Correct |
52 ms |
10616 KB |
Output is correct |
17 |
Correct |
52 ms |
10976 KB |
Output is correct |
18 |
Incorrect |
303 ms |
41840 KB |
Too many queries |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Correct |
2 ms |
2688 KB |
Output is correct |
4 |
Correct |
2 ms |
2688 KB |
Output is correct |
5 |
Correct |
2 ms |
2688 KB |
Output is correct |
6 |
Correct |
2 ms |
2688 KB |
Output is correct |
7 |
Correct |
2 ms |
2688 KB |
Output is correct |
8 |
Correct |
52 ms |
10492 KB |
Output is correct |
9 |
Correct |
3 ms |
2816 KB |
Output is correct |
10 |
Correct |
9 ms |
3968 KB |
Output is correct |
11 |
Correct |
16 ms |
4992 KB |
Output is correct |
12 |
Correct |
5 ms |
3328 KB |
Output is correct |
13 |
Incorrect |
173 ms |
27824 KB |
Too many queries |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Correct |
2 ms |
2688 KB |
Output is correct |
4 |
Correct |
2 ms |
2688 KB |
Output is correct |
5 |
Correct |
2 ms |
2688 KB |
Output is correct |
6 |
Correct |
2 ms |
2688 KB |
Output is correct |
7 |
Correct |
2 ms |
2688 KB |
Output is correct |
8 |
Correct |
2 ms |
2688 KB |
Output is correct |
9 |
Correct |
2 ms |
2688 KB |
Output is correct |
10 |
Correct |
2 ms |
2688 KB |
Output is correct |
11 |
Correct |
2 ms |
2688 KB |
Output is correct |
12 |
Correct |
2 ms |
2688 KB |
Output is correct |
13 |
Correct |
2 ms |
2688 KB |
Output is correct |
14 |
Correct |
2 ms |
2688 KB |
Output is correct |
15 |
Correct |
2 ms |
2688 KB |
Output is correct |
16 |
Correct |
2 ms |
2688 KB |
Output is correct |
17 |
Correct |
2 ms |
2688 KB |
Output is correct |
18 |
Correct |
2 ms |
2688 KB |
Output is correct |
19 |
Correct |
2 ms |
2688 KB |
Output is correct |
20 |
Correct |
2 ms |
2688 KB |
Output is correct |
21 |
Correct |
2 ms |
2688 KB |
Output is correct |
22 |
Correct |
2 ms |
2688 KB |
Output is correct |
23 |
Correct |
2 ms |
2688 KB |
Output is correct |
24 |
Correct |
51 ms |
10488 KB |
Output is correct |
25 |
Correct |
2 ms |
2688 KB |
Output is correct |
26 |
Correct |
4 ms |
3072 KB |
Output is correct |
27 |
Correct |
7 ms |
3584 KB |
Output is correct |
28 |
Correct |
2 ms |
2688 KB |
Output is correct |
29 |
Correct |
52 ms |
10492 KB |
Output is correct |
30 |
Correct |
3 ms |
2816 KB |
Output is correct |
31 |
Correct |
9 ms |
3968 KB |
Output is correct |
32 |
Correct |
16 ms |
4992 KB |
Output is correct |
33 |
Correct |
5 ms |
3328 KB |
Output is correct |
34 |
Correct |
52 ms |
10616 KB |
Output is correct |
35 |
Correct |
52 ms |
10616 KB |
Output is correct |
36 |
Correct |
54 ms |
10616 KB |
Output is correct |
37 |
Correct |
5 ms |
3072 KB |
Output is correct |
38 |
Correct |
49 ms |
9848 KB |
Output is correct |
39 |
Correct |
16 ms |
4992 KB |
Output is correct |
40 |
Correct |
25 ms |
6528 KB |
Output is correct |
41 |
Correct |
8 ms |
3840 KB |
Output is correct |
42 |
Correct |
52 ms |
10616 KB |
Output is correct |
43 |
Correct |
52 ms |
10976 KB |
Output is correct |
44 |
Incorrect |
303 ms |
41840 KB |
Too many queries |
45 |
Halted |
0 ms |
0 KB |
- |