#pragma GCC diagnostic warning "-std=c++11"
#include <bits/stdc++.h>
#include "longesttrip.h"
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
#define flush fflush(stdout)
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define pii pair<int,int>
using namespace std;
int n,m,T,k;
vector<int> longest_trip(int N, int D) {
if (D==2) {
vector<int> v;
int fix[N];
for (int i=0; i<N; i++) {
fix[i]=0;
}
vector<int> v1,v2;
for (int i=0; i<N; i++) {
for (int j=i+1; j<N; j++) {
vector<int> a,b; a.pb(i); b.pb(j);
if (!are_connected(a,b)) {
v1.pb(i); v2.pb(j);
fix[i]=1; fix[j]=1;
}
}
}
for (auto x:v1) v.pb(x);
for (int i=0; i<N; i++) if (!fix[i]) v.pb(i);
for (auto x:v2) v.pb(x);
return v;
}
vector<int> v;
int e[N][N];
for (int i=0; i<N; i++) {
for (int j=0; j<N; j++) {
e[i][j]=0;
}
}
vector<int> v1,v2;
for (int i=0; i<N; i++) {
for (int j=i+1; j<N; j++) {
vector<int> a,b; a.pb(i); b.pb(j);
if (are_connected(a,b)) {
e[i][j]=1; e[j][i]=1;
}
}
}
int cur=0,mx=0; v.pb(cur);
vector<int> c;
for (int i=1; i<N; i++) {
if (e[cur][i]) {
v.pb(i);
if (i-cur>1) {
int l=mx+1,r=i-1;
for (int j=l; j<=r; j++) c.pb(j);
}
cur=i; mx=i;
int check=-1;
for (auto j:c) {
if (e[i][j]) check=j;
}
if (check!=-1) {
v.pb(check);
for (auto j:c) {
if (j!=check) v.pb(j);
}
cur=v.back();
c.clear();
}
}
}
for (int i=mx+1; i<N; i++) c.pb(i);
if (c.size()>N/2) return c;
return v;
}
Compilation message
longesttrip.cpp:1:32: warning: '-std=c++11' is not an option that controls warnings [-Wpragmas]
1 | #pragma GCC diagnostic warning "-std=c++11"
| ^~~~~~~~~~~~
longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:79:14: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
79 | if (c.size()>N/2) return c;
| ~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
184 ms |
668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
31 ms |
532 KB |
Output is correct |
3 |
Correct |
126 ms |
344 KB |
Output is correct |
4 |
Correct |
371 ms |
344 KB |
Output is correct |
5 |
Correct |
726 ms |
672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
23 ms |
344 KB |
Output is correct |
3 |
Correct |
127 ms |
344 KB |
Output is correct |
4 |
Correct |
362 ms |
344 KB |
Output is correct |
5 |
Correct |
756 ms |
408 KB |
Output is correct |
6 |
Correct |
6 ms |
344 KB |
Output is correct |
7 |
Correct |
26 ms |
344 KB |
Output is correct |
8 |
Correct |
132 ms |
344 KB |
Output is correct |
9 |
Correct |
270 ms |
592 KB |
Output is correct |
10 |
Correct |
717 ms |
412 KB |
Output is correct |
11 |
Correct |
759 ms |
412 KB |
Output is correct |
12 |
Correct |
766 ms |
408 KB |
Output is correct |
13 |
Correct |
732 ms |
408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
344 KB |
Output is correct |
2 |
Correct |
19 ms |
344 KB |
Output is correct |
3 |
Correct |
121 ms |
344 KB |
Output is correct |
4 |
Correct |
357 ms |
344 KB |
Output is correct |
5 |
Correct |
714 ms |
668 KB |
Output is correct |
6 |
Correct |
6 ms |
344 KB |
Output is correct |
7 |
Correct |
23 ms |
344 KB |
Output is correct |
8 |
Correct |
124 ms |
344 KB |
Output is correct |
9 |
Correct |
270 ms |
344 KB |
Output is correct |
10 |
Correct |
758 ms |
668 KB |
Output is correct |
11 |
Correct |
723 ms |
668 KB |
Output is correct |
12 |
Correct |
737 ms |
668 KB |
Output is correct |
13 |
Correct |
699 ms |
668 KB |
Output is correct |
14 |
Correct |
7 ms |
344 KB |
Output is correct |
15 |
Correct |
11 ms |
344 KB |
Output is correct |
16 |
Correct |
43 ms |
344 KB |
Output is correct |
17 |
Correct |
79 ms |
504 KB |
Output is correct |
18 |
Correct |
123 ms |
344 KB |
Output is correct |
19 |
Correct |
264 ms |
344 KB |
Output is correct |
20 |
Correct |
267 ms |
344 KB |
Output is correct |
21 |
Correct |
722 ms |
668 KB |
Output is correct |
22 |
Correct |
714 ms |
668 KB |
Output is correct |
23 |
Correct |
759 ms |
668 KB |
Output is correct |
24 |
Correct |
804 ms |
664 KB |
Output is correct |
25 |
Correct |
8 ms |
344 KB |
Output is correct |
26 |
Correct |
9 ms |
344 KB |
Output is correct |
27 |
Correct |
33 ms |
344 KB |
Output is correct |
28 |
Correct |
19 ms |
344 KB |
Output is correct |
29 |
Correct |
25 ms |
344 KB |
Output is correct |
30 |
Correct |
173 ms |
344 KB |
Output is correct |
31 |
Correct |
174 ms |
344 KB |
Output is correct |
32 |
Correct |
188 ms |
344 KB |
Output is correct |
33 |
Correct |
279 ms |
344 KB |
Output is correct |
34 |
Correct |
271 ms |
344 KB |
Output is correct |
35 |
Correct |
272 ms |
344 KB |
Output is correct |
36 |
Correct |
802 ms |
668 KB |
Output is correct |
37 |
Correct |
787 ms |
664 KB |
Output is correct |
38 |
Correct |
708 ms |
664 KB |
Output is correct |
39 |
Correct |
770 ms |
668 KB |
Output is correct |
40 |
Correct |
747 ms |
668 KB |
Output is correct |
41 |
Correct |
762 ms |
600 KB |
Output is correct |
42 |
Correct |
729 ms |
848 KB |
Output is correct |
43 |
Correct |
771 ms |
668 KB |
Output is correct |
44 |
Correct |
717 ms |
664 KB |
Output is correct |
45 |
Correct |
10 ms |
344 KB |
Output is correct |
46 |
Correct |
11 ms |
344 KB |
Output is correct |
47 |
Correct |
22 ms |
344 KB |
Output is correct |
48 |
Correct |
20 ms |
344 KB |
Output is correct |
49 |
Correct |
23 ms |
344 KB |
Output is correct |
50 |
Correct |
152 ms |
344 KB |
Output is correct |
51 |
Correct |
156 ms |
344 KB |
Output is correct |
52 |
Correct |
155 ms |
344 KB |
Output is correct |
53 |
Correct |
266 ms |
344 KB |
Output is correct |
54 |
Correct |
265 ms |
600 KB |
Output is correct |
55 |
Correct |
269 ms |
344 KB |
Output is correct |
56 |
Correct |
712 ms |
668 KB |
Output is correct |
57 |
Correct |
752 ms |
664 KB |
Output is correct |
58 |
Correct |
751 ms |
664 KB |
Output is correct |
59 |
Correct |
800 ms |
664 KB |
Output is correct |
60 |
Correct |
749 ms |
664 KB |
Output is correct |
61 |
Correct |
706 ms |
668 KB |
Output is correct |
62 |
Correct |
737 ms |
664 KB |
Output is correct |
63 |
Correct |
734 ms |
668 KB |
Output is correct |
64 |
Correct |
744 ms |
668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
344 KB |
Output is correct |
2 |
Correct |
22 ms |
344 KB |
Output is correct |
3 |
Partially correct |
125 ms |
344 KB |
Output is partially correct |
4 |
Partially correct |
373 ms |
344 KB |
Output is partially correct |
5 |
Partially correct |
728 ms |
672 KB |
Output is partially correct |
6 |
Incorrect |
0 ms |
344 KB |
Incorrect |
7 |
Halted |
0 ms |
0 KB |
- |