#include <bits/stdc++.h>
#include "longesttrip.h"
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define en '\n'
#define sp ' '
#define tb '\t'
#define ri(n) int n; cin >> n
#define rl(n) ll n; cin >> n
#define rs(s) string s; cin >> s
#define rc(c) char c; cin >> c
#define rv(v) for (auto &x : v) cin >> x
#define pven(v) for (auto x : v) cout << x << en
#define pv(v) for (auto x : v) cout << x << sp; cout << en
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yes cout << "YES" << en
#define no cout << "NO" << en
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define ssort(a, b) if (a < b) swap(a, b)
#define bitcnt(a) (__builtin_popcountll(a))
#define bithigh(a) (63-__builtin_clzll(a))
#define lg bithigh
#define highpow(a) (1LL << (ll)lg(a))
using namespace std;
const ll LINF = 2e18;
const int mxN = 300, INF = 2e9;
vector<int> Connect(const vector<int>& a, const vector<int>& b){
vector<int> v;
for (int s : a) v.pb(s);
reverse(all(v));
for (int s : b) v.pb(s);
return v;
}
vector<int> D3(int N){
vector<vector<int> > trips;
for (int i = 0; i < N; i++)
trips.pb({i});
while (trips.size() > 2){
array<vector<int>, 3> a;
for (int i = 0; i < 3; i++){
a[i] = trips.back();
trips.pop_back();
}
for (int i = 0; i < 3; i++){
bool f = 0;
for (int j = i+1; j < 3; j++){
if (are_connected({a[i][0]}, {a[j][0]})){
trips.pb(Connect(a[i], a[j]));
trips.pb(a[3-i-j]);
f = 1;
break;
}
}
if (f) break;
}
}
array<vector<int>, 2> a = {trips[0], trips[0]};
array<vector<int>, 2> b = {trips[1], trips[1]};
reverse(all(a[1])); reverse(all(b[1]));
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
if (are_connected({a[i][0]}, {b[j][0]}))
return Connect(a[i], b[j]);
return trips[0].size() > trips[1].size() ? trips[0] : trips[1];
}
vector<int> longest_trip(int N, int D){
if (D == 1) return D3(N);
vector<int> trip = {0};
for (int i = 1; i < N; i++){
bool f = are_connected({trip.back()}, {i});
if (f){
trip.pb(i);
continue;
}
if (i < N-1){
trip.pb(i+1);
trip.pb(i);
i++;
continue;
}
reverse(all(trip));
trip.pb(i);
}
return trip;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
596 KB |
Output is correct |
2 |
Correct |
5 ms |
344 KB |
Output is correct |
3 |
Correct |
4 ms |
344 KB |
Output is correct |
4 |
Correct |
4 ms |
344 KB |
Output is correct |
5 |
Correct |
4 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
344 KB |
Output is correct |
2 |
Correct |
6 ms |
344 KB |
Output is correct |
3 |
Correct |
4 ms |
344 KB |
Output is correct |
4 |
Correct |
5 ms |
344 KB |
Output is correct |
5 |
Correct |
5 ms |
344 KB |
Output is correct |
6 |
Correct |
5 ms |
344 KB |
Output is correct |
7 |
Correct |
4 ms |
344 KB |
Output is correct |
8 |
Correct |
4 ms |
344 KB |
Output is correct |
9 |
Correct |
4 ms |
344 KB |
Output is correct |
10 |
Correct |
4 ms |
344 KB |
Output is correct |
11 |
Correct |
4 ms |
344 KB |
Output is correct |
12 |
Correct |
4 ms |
344 KB |
Output is correct |
13 |
Correct |
4 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
344 KB |
Output is correct |
2 |
Correct |
6 ms |
344 KB |
Output is correct |
3 |
Correct |
6 ms |
344 KB |
Output is correct |
4 |
Correct |
5 ms |
600 KB |
Output is correct |
5 |
Correct |
5 ms |
996 KB |
Output is correct |
6 |
Correct |
11 ms |
540 KB |
Output is correct |
7 |
Correct |
5 ms |
344 KB |
Output is correct |
8 |
Correct |
5 ms |
344 KB |
Output is correct |
9 |
Correct |
5 ms |
344 KB |
Output is correct |
10 |
Correct |
6 ms |
736 KB |
Output is correct |
11 |
Correct |
5 ms |
744 KB |
Output is correct |
12 |
Correct |
6 ms |
860 KB |
Output is correct |
13 |
Correct |
5 ms |
856 KB |
Output is correct |
14 |
Correct |
10 ms |
344 KB |
Output is correct |
15 |
Correct |
11 ms |
344 KB |
Output is correct |
16 |
Correct |
10 ms |
600 KB |
Output is correct |
17 |
Correct |
7 ms |
344 KB |
Output is correct |
18 |
Correct |
8 ms |
612 KB |
Output is correct |
19 |
Correct |
7 ms |
596 KB |
Output is correct |
20 |
Correct |
6 ms |
344 KB |
Output is correct |
21 |
Correct |
6 ms |
1004 KB |
Output is correct |
22 |
Correct |
6 ms |
748 KB |
Output is correct |
23 |
Correct |
6 ms |
752 KB |
Output is correct |
24 |
Correct |
5 ms |
748 KB |
Output is correct |
25 |
Correct |
10 ms |
600 KB |
Output is correct |
26 |
Correct |
10 ms |
344 KB |
Output is correct |
27 |
Correct |
12 ms |
344 KB |
Output is correct |
28 |
Correct |
18 ms |
344 KB |
Output is correct |
29 |
Correct |
11 ms |
344 KB |
Output is correct |
30 |
Correct |
8 ms |
444 KB |
Output is correct |
31 |
Correct |
13 ms |
444 KB |
Output is correct |
32 |
Correct |
11 ms |
436 KB |
Output is correct |
33 |
Correct |
7 ms |
616 KB |
Output is correct |
34 |
Correct |
13 ms |
340 KB |
Output is correct |
35 |
Correct |
13 ms |
600 KB |
Output is correct |
36 |
Correct |
9 ms |
1116 KB |
Output is correct |
37 |
Correct |
16 ms |
720 KB |
Output is correct |
38 |
Correct |
14 ms |
1124 KB |
Output is correct |
39 |
Correct |
12 ms |
712 KB |
Output is correct |
40 |
Correct |
12 ms |
716 KB |
Output is correct |
41 |
Correct |
11 ms |
856 KB |
Output is correct |
42 |
Correct |
12 ms |
868 KB |
Output is correct |
43 |
Correct |
11 ms |
600 KB |
Output is correct |
44 |
Correct |
12 ms |
856 KB |
Output is correct |
45 |
Correct |
8 ms |
344 KB |
Output is correct |
46 |
Correct |
11 ms |
344 KB |
Output is correct |
47 |
Correct |
9 ms |
344 KB |
Output is correct |
48 |
Correct |
8 ms |
344 KB |
Output is correct |
49 |
Correct |
10 ms |
344 KB |
Output is correct |
50 |
Correct |
11 ms |
444 KB |
Output is correct |
51 |
Correct |
13 ms |
440 KB |
Output is correct |
52 |
Correct |
11 ms |
444 KB |
Output is correct |
53 |
Correct |
9 ms |
856 KB |
Output is correct |
54 |
Correct |
10 ms |
856 KB |
Output is correct |
55 |
Correct |
11 ms |
344 KB |
Output is correct |
56 |
Correct |
12 ms |
732 KB |
Output is correct |
57 |
Correct |
14 ms |
744 KB |
Output is correct |
58 |
Correct |
14 ms |
892 KB |
Output is correct |
59 |
Correct |
12 ms |
992 KB |
Output is correct |
60 |
Correct |
13 ms |
728 KB |
Output is correct |
61 |
Correct |
10 ms |
624 KB |
Output is correct |
62 |
Correct |
12 ms |
600 KB |
Output is correct |
63 |
Correct |
13 ms |
724 KB |
Output is correct |
64 |
Correct |
12 ms |
1112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
344 KB |
Output is correct |
2 |
Correct |
6 ms |
344 KB |
Output is correct |
3 |
Correct |
5 ms |
344 KB |
Output is correct |
4 |
Correct |
5 ms |
344 KB |
Output is correct |
5 |
Correct |
5 ms |
480 KB |
Output is correct |
6 |
Correct |
7 ms |
344 KB |
Output is correct |
7 |
Correct |
6 ms |
344 KB |
Output is correct |
8 |
Correct |
5 ms |
344 KB |
Output is correct |
9 |
Correct |
4 ms |
344 KB |
Output is correct |
10 |
Correct |
5 ms |
996 KB |
Output is correct |
11 |
Correct |
5 ms |
996 KB |
Output is correct |
12 |
Correct |
6 ms |
876 KB |
Output is correct |
13 |
Correct |
5 ms |
496 KB |
Output is correct |
14 |
Correct |
11 ms |
344 KB |
Output is correct |
15 |
Correct |
11 ms |
344 KB |
Output is correct |
16 |
Incorrect |
1 ms |
344 KB |
Incorrect |
17 |
Halted |
0 ms |
0 KB |
- |