#include <bits/stdc++.h>
#include "longesttrip.h"
using namespace std;
#define pb push_back
#define st first
#define nd second
typedef long long ll;
typedef long double ld;
const ll I = 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL;
const int II = 2 * 1000 * 1000 * 1000;
const int N = 1000 * 1000 + 7;
bool SQ(int a, int b)
{
vector<int> v1 = {a}, v2 = {b};
return are_connected(v1, v2);
}
void J(vector<int> &a, vector<int> &b)
{
for(int i = 0; i < (int)b.size(); ++i)
a.pb(b[i]);
b.clear();
}
void R(vector<int> &a, int r)
{
vector<int> nw;
for(int i = r; i < (int)a.size(); ++i)
nw.pb(a[i]);
for(int i = 0; i < r; ++i)
nw.pb(a[i]);
a = nw;
}
void Merge(vector<int> &a, vector<int> &b)
{
for(int r = 0; r < 2; ++r)
{
for(int l = 0; l < 2; ++l)
{
if(SQ(a.back(), b[0]))
{
J(a, b);
return;
}
reverse(b.begin(), b.end());
}
reverse(a.begin(), a.end());
}
int p, s, k;
vector<int> q1, qd;
p = 0, k = (int)a.size();
while(p < k)
{
s = (p + k) / 2;
q1.clear();
for(int i = 0; i <= s; ++i)
q1.pb(a[i]);
if(are_connected(q1, b))
k = s;
else
p = s + 1;
}
if(p == (int)a.size()) return;
R(a, p);
qd = {a[0]};
p = 0, k = (int)b.size();
while(p < k)
{
s = (p + k) / 2;
q1.clear();
for(int i = 0; i <= s; ++i)
q1.pb(b[i]);
if(are_connected(q1, qd))
k = s;
else
p = s + 1;
}
R(b, p);
reverse(a.begin(), a.end());
J(a, b);
}
vector<int> longest_trip(int _N, int _X_D)
{
int n = _N;
vector<int> l1, l2;
l1.pb(0);
if(n == 1) return l1;
for(int i = 1; i < n; ++i)
{
if(SQ(i, l1.back()))
{
l1.pb(i);
continue;
}
if((int)l2.size() == 0 || SQ(i, l2.back()))
{
l2.pb(i);
continue;
}
reverse(l2.begin(), l2.end());
J(l1, l2);
l2.pb(i);
}
if(l1.size() < l2.size())
swap(l1, l2);
if(l2.size() == 0)
return l1;
Merge(l1, l2);
return l1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
3 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
336 KB |
Output is correct |
2 |
Correct |
10 ms |
336 KB |
Output is correct |
3 |
Correct |
8 ms |
336 KB |
Output is correct |
4 |
Correct |
10 ms |
336 KB |
Output is correct |
5 |
Correct |
7 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
336 KB |
Output is correct |
2 |
Correct |
8 ms |
508 KB |
Output is correct |
3 |
Correct |
7 ms |
584 KB |
Output is correct |
4 |
Correct |
9 ms |
336 KB |
Output is correct |
5 |
Correct |
7 ms |
336 KB |
Output is correct |
6 |
Correct |
11 ms |
336 KB |
Output is correct |
7 |
Correct |
9 ms |
336 KB |
Output is correct |
8 |
Correct |
8 ms |
336 KB |
Output is correct |
9 |
Correct |
8 ms |
504 KB |
Output is correct |
10 |
Correct |
8 ms |
336 KB |
Output is correct |
11 |
Correct |
8 ms |
436 KB |
Output is correct |
12 |
Correct |
8 ms |
504 KB |
Output is correct |
13 |
Correct |
7 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
512 KB |
Output is correct |
2 |
Correct |
8 ms |
336 KB |
Output is correct |
3 |
Correct |
8 ms |
336 KB |
Output is correct |
4 |
Correct |
8 ms |
336 KB |
Output is correct |
5 |
Correct |
8 ms |
336 KB |
Output is correct |
6 |
Correct |
10 ms |
336 KB |
Output is correct |
7 |
Correct |
8 ms |
336 KB |
Output is correct |
8 |
Correct |
11 ms |
336 KB |
Output is correct |
9 |
Correct |
10 ms |
336 KB |
Output is correct |
10 |
Correct |
8 ms |
612 KB |
Output is correct |
11 |
Correct |
10 ms |
336 KB |
Output is correct |
12 |
Correct |
12 ms |
336 KB |
Output is correct |
13 |
Correct |
8 ms |
336 KB |
Output is correct |
14 |
Correct |
17 ms |
336 KB |
Output is correct |
15 |
Correct |
18 ms |
336 KB |
Output is correct |
16 |
Correct |
13 ms |
336 KB |
Output is correct |
17 |
Correct |
12 ms |
336 KB |
Output is correct |
18 |
Correct |
9 ms |
336 KB |
Output is correct |
19 |
Correct |
7 ms |
336 KB |
Output is correct |
20 |
Correct |
9 ms |
336 KB |
Output is correct |
21 |
Correct |
8 ms |
336 KB |
Output is correct |
22 |
Correct |
8 ms |
336 KB |
Output is correct |
23 |
Correct |
8 ms |
336 KB |
Output is correct |
24 |
Correct |
9 ms |
336 KB |
Output is correct |
25 |
Correct |
19 ms |
336 KB |
Output is correct |
26 |
Correct |
14 ms |
336 KB |
Output is correct |
27 |
Correct |
12 ms |
336 KB |
Output is correct |
28 |
Correct |
15 ms |
336 KB |
Output is correct |
29 |
Correct |
12 ms |
336 KB |
Output is correct |
30 |
Correct |
11 ms |
336 KB |
Output is correct |
31 |
Correct |
14 ms |
504 KB |
Output is correct |
32 |
Correct |
11 ms |
336 KB |
Output is correct |
33 |
Correct |
10 ms |
336 KB |
Output is correct |
34 |
Correct |
9 ms |
336 KB |
Output is correct |
35 |
Correct |
9 ms |
336 KB |
Output is correct |
36 |
Correct |
8 ms |
336 KB |
Output is correct |
37 |
Correct |
8 ms |
336 KB |
Output is correct |
38 |
Correct |
8 ms |
336 KB |
Output is correct |
39 |
Correct |
11 ms |
336 KB |
Output is correct |
40 |
Correct |
13 ms |
440 KB |
Output is correct |
41 |
Correct |
12 ms |
336 KB |
Output is correct |
42 |
Correct |
12 ms |
504 KB |
Output is correct |
43 |
Correct |
10 ms |
336 KB |
Output is correct |
44 |
Correct |
12 ms |
336 KB |
Output is correct |
45 |
Correct |
12 ms |
336 KB |
Output is correct |
46 |
Correct |
13 ms |
336 KB |
Output is correct |
47 |
Correct |
14 ms |
336 KB |
Output is correct |
48 |
Correct |
10 ms |
336 KB |
Output is correct |
49 |
Correct |
16 ms |
336 KB |
Output is correct |
50 |
Correct |
11 ms |
336 KB |
Output is correct |
51 |
Correct |
15 ms |
436 KB |
Output is correct |
52 |
Correct |
13 ms |
336 KB |
Output is correct |
53 |
Correct |
11 ms |
336 KB |
Output is correct |
54 |
Correct |
7 ms |
336 KB |
Output is correct |
55 |
Correct |
12 ms |
336 KB |
Output is correct |
56 |
Correct |
8 ms |
444 KB |
Output is correct |
57 |
Correct |
9 ms |
336 KB |
Output is correct |
58 |
Correct |
10 ms |
336 KB |
Output is correct |
59 |
Correct |
11 ms |
336 KB |
Output is correct |
60 |
Correct |
15 ms |
592 KB |
Output is correct |
61 |
Correct |
11 ms |
336 KB |
Output is correct |
62 |
Correct |
14 ms |
696 KB |
Output is correct |
63 |
Correct |
11 ms |
336 KB |
Output is correct |
64 |
Correct |
13 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
336 KB |
Output is correct |
2 |
Correct |
8 ms |
336 KB |
Output is correct |
3 |
Correct |
8 ms |
336 KB |
Output is correct |
4 |
Correct |
7 ms |
336 KB |
Output is correct |
5 |
Correct |
8 ms |
336 KB |
Output is correct |
6 |
Correct |
11 ms |
336 KB |
Output is correct |
7 |
Correct |
8 ms |
336 KB |
Output is correct |
8 |
Correct |
7 ms |
336 KB |
Output is correct |
9 |
Correct |
9 ms |
336 KB |
Output is correct |
10 |
Correct |
7 ms |
336 KB |
Output is correct |
11 |
Correct |
7 ms |
336 KB |
Output is correct |
12 |
Correct |
6 ms |
336 KB |
Output is correct |
13 |
Correct |
8 ms |
336 KB |
Output is correct |
14 |
Correct |
20 ms |
336 KB |
Output is correct |
15 |
Correct |
14 ms |
336 KB |
Output is correct |
16 |
Correct |
11 ms |
336 KB |
Output is correct |
17 |
Correct |
10 ms |
336 KB |
Output is correct |
18 |
Correct |
9 ms |
336 KB |
Output is correct |
19 |
Correct |
8 ms |
436 KB |
Output is correct |
20 |
Correct |
9 ms |
336 KB |
Output is correct |
21 |
Correct |
18 ms |
336 KB |
Output is correct |
22 |
Correct |
20 ms |
336 KB |
Output is correct |
23 |
Correct |
13 ms |
336 KB |
Output is correct |
24 |
Correct |
11 ms |
336 KB |
Output is correct |
25 |
Correct |
16 ms |
336 KB |
Output is correct |
26 |
Correct |
11 ms |
336 KB |
Output is correct |
27 |
Correct |
11 ms |
336 KB |
Output is correct |
28 |
Correct |
12 ms |
336 KB |
Output is correct |
29 |
Correct |
8 ms |
336 KB |
Output is correct |
30 |
Correct |
10 ms |
336 KB |
Output is correct |
31 |
Correct |
9 ms |
336 KB |
Output is correct |
32 |
Correct |
12 ms |
336 KB |
Output is correct |
33 |
Correct |
16 ms |
336 KB |
Output is correct |
34 |
Correct |
10 ms |
336 KB |
Output is correct |
35 |
Correct |
12 ms |
336 KB |
Output is correct |
36 |
Correct |
13 ms |
336 KB |
Output is correct |
37 |
Correct |
10 ms |
336 KB |
Output is correct |
38 |
Correct |
13 ms |
336 KB |
Output is correct |
39 |
Correct |
16 ms |
336 KB |
Output is correct |
40 |
Correct |
9 ms |
336 KB |
Output is correct |
41 |
Correct |
7 ms |
444 KB |
Output is correct |
42 |
Correct |
10 ms |
336 KB |
Output is correct |
43 |
Correct |
9 ms |
336 KB |
Output is correct |
44 |
Correct |
9 ms |
440 KB |
Output is correct |
45 |
Correct |
9 ms |
336 KB |
Output is correct |
46 |
Correct |
8 ms |
336 KB |
Output is correct |
47 |
Correct |
10 ms |
336 KB |
Output is correct |
48 |
Correct |
9 ms |
508 KB |
Output is correct |
49 |
Correct |
9 ms |
336 KB |
Output is correct |
50 |
Correct |
10 ms |
336 KB |
Output is correct |
51 |
Partially correct |
13 ms |
336 KB |
Output is partially correct |
52 |
Correct |
11 ms |
592 KB |
Output is correct |
53 |
Correct |
14 ms |
336 KB |
Output is correct |
54 |
Correct |
12 ms |
336 KB |
Output is correct |
55 |
Correct |
12 ms |
504 KB |
Output is correct |
56 |
Correct |
9 ms |
336 KB |
Output is correct |
57 |
Partially correct |
12 ms |
448 KB |
Output is partially correct |
58 |
Partially correct |
10 ms |
336 KB |
Output is partially correct |
59 |
Partially correct |
12 ms |
592 KB |
Output is partially correct |
60 |
Correct |
11 ms |
336 KB |
Output is correct |
61 |
Correct |
10 ms |
336 KB |
Output is correct |
62 |
Correct |
11 ms |
592 KB |
Output is correct |
63 |
Partially correct |
10 ms |
336 KB |
Output is partially correct |
64 |
Partially correct |
15 ms |
444 KB |
Output is partially correct |
65 |
Partially correct |
11 ms |
336 KB |
Output is partially correct |
66 |
Partially correct |
13 ms |
440 KB |
Output is partially correct |
67 |
Correct |
11 ms |
336 KB |
Output is correct |
68 |
Correct |
14 ms |
440 KB |
Output is correct |
69 |
Partially correct |
12 ms |
760 KB |
Output is partially correct |
70 |
Partially correct |
12 ms |
444 KB |
Output is partially correct |
71 |
Correct |
11 ms |
452 KB |
Output is correct |
72 |
Partially correct |
12 ms |
336 KB |
Output is partially correct |
73 |
Partially correct |
12 ms |
440 KB |
Output is partially correct |
74 |
Partially correct |
11 ms |
504 KB |
Output is partially correct |
75 |
Correct |
15 ms |
336 KB |
Output is correct |
76 |
Correct |
12 ms |
848 KB |
Output is correct |
77 |
Correct |
8 ms |
336 KB |
Output is correct |
78 |
Partially correct |
11 ms |
592 KB |
Output is partially correct |
79 |
Correct |
9 ms |
336 KB |
Output is correct |
80 |
Partially correct |
10 ms |
336 KB |
Output is partially correct |
81 |
Correct |
11 ms |
608 KB |
Output is correct |
82 |
Correct |
11 ms |
336 KB |
Output is correct |