# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
840165 | 2023-08-31T07:39:30 Z | KLPP | Longest Trip (IOI23_longesttrip) | C++17 | 145 ms | 852 KB |
#include "longesttrip.h" #include<bits/stdc++.h> using namespace std; typedef long long int lld; #define rep(i,a,b) for(int i=a;i<b;i++) #define trav(a,v) for(auto a:v) int n; int p[1000]; vector<int> ord; bool visited[1000000]; vector<int> tr[1000]; bool table[1000][1000]; vector<int> nvis; vector<int> T; int get_vert(int node){ nvis.clear(); rep(i,0,n){ if(!visited[i])nvis.push_back(i); } if(nvis.empty())return -1; if(!are_connected({node},nvis))return -1; int lo=0; int hi=nvis.size()-1; while(hi-lo>0){ int mid=(hi+lo)/2; T.clear(); rep(i,lo,mid+1)T.push_back(nvis[i]); if(are_connected({node},T)){ hi=mid; }else{ lo=mid+1; } } return nvis[lo]; } void DFS(int node){ visited[node]=true; ord.push_back(node); while(true){ int a=get_vert(node); if(a==-1)break; DFS(a); tr[node].push_back(a); tr[a].push_back(node); p[a]=node; } } bool test(int a, int b){ if(are_connected({a},{b}))return true; return false; } std::vector<int> longest_trip(int N, int D) { n=N; rep(i,0,n){ rep(j,0,n)table[i][j]=false; p[i]=-1; visited[i]=false; tr[i].clear(); } vector<int> ans; rep(i,0,n){ if(!visited[i]){ ord.clear(); DFS(i); int cnt=0; int gt=-1; rep(j,0,n){ if((int)tr[j].size()>=3 || (j==i && (int)tr[j].size()>=2)){ cnt++; gt=j; } } pair<int,int> bot={-1,-1}; rep(j,0,n){ if(j!=i && (int)tr[j].size()==1){ if(bot.first==-1)bot.first=j; else{ if(bot.second!=-1)assert(false); bot.second=j; } } } assert(cnt<=1); assert((gt!=-1) || (bot.second==-1)); if(gt==-1){ if(ans.size()<ord.size())ans=ord; }else{ ord.clear(); vector<int> p1; vector<int> p2; vector<int> p3; int x=bot.first; int y=bot.second; int z=gt; while(x!=gt){ p1.push_back(x); x=p[x]; } while(y!=gt){ p2.push_back(y); y=p[y]; } while(p[z]!=-1){ p3.push_back(p[z]); z=p[z]; } reverse(p3.begin(),p3.end()); trav(a,p3)ord.push_back(a); if(p[gt]==-1){ reverse(p2.begin(),p2.end()); trav(a,p1){ ord.push_back(a); } ord.push_back(gt); trav(a,p2)ord.push_back(a); //~ rep(i,0,(int)ord.size()-1){ //~ if(!test(ord[i],ord[i+1]))assert(false); //~ } }else{ if(test(bot.first,p[gt])){ reverse(p2.begin(),p2.end()); trav(a,p1)ord.push_back(a); ord.push_back(gt); trav(a,p2)ord.push_back(a); //~ rep(i,0,(int)ord.size()-1){ //~ if(!test(ord[i],ord[i+1]))assert(false); //~ } }else{ reverse(p1.begin(),p1.end()); trav(a,p2)ord.push_back(a); ord.push_back(gt); trav(a,p1)ord.push_back(a); //~ rep(i,0,(int)ord.size()-1){ //~ if(!test(ord[i],ord[i+1]))assert(false); //~ } } } if(ans.size()<ord.size())ans=ord; } rep(j,0,n){ trav(a,tr[j]){ if(!test(a,j))assert(false); } tr[j].clear(); p[j]=-1; } } } return ans; }
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Correct | 22 ms | 592 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 18 ms | 336 KB | Output is correct |
2 | Correct | 44 ms | 336 KB | Output is correct |
3 | Correct | 63 ms | 336 KB | Output is correct |
4 | Correct | 76 ms | 476 KB | Output is correct |
5 | Correct | 80 ms | 608 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 18 ms | 208 KB | Output is correct |
2 | Correct | 43 ms | 336 KB | Output is correct |
3 | Correct | 63 ms | 336 KB | Output is correct |
4 | Correct | 81 ms | 476 KB | Output is correct |
5 | Correct | 100 ms | 612 KB | Output is correct |
6 | Correct | 23 ms | 336 KB | Output is correct |
7 | Correct | 34 ms | 336 KB | Output is correct |
8 | Correct | 65 ms | 336 KB | Output is correct |
9 | Correct | 60 ms | 336 KB | Output is correct |
10 | Correct | 87 ms | 592 KB | Output is correct |
11 | Correct | 85 ms | 628 KB | Output is correct |
12 | Correct | 99 ms | 592 KB | Output is correct |
13 | Correct | 107 ms | 600 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 18 ms | 336 KB | Output is correct |
2 | Correct | 31 ms | 336 KB | Output is correct |
3 | Correct | 65 ms | 388 KB | Output is correct |
4 | Correct | 90 ms | 464 KB | Output is correct |
5 | Correct | 107 ms | 744 KB | Output is correct |
6 | Correct | 25 ms | 336 KB | Output is correct |
7 | Correct | 34 ms | 336 KB | Output is correct |
8 | Correct | 60 ms | 336 KB | Output is correct |
9 | Correct | 57 ms | 336 KB | Output is correct |
10 | Correct | 80 ms | 616 KB | Output is correct |
11 | Correct | 109 ms | 612 KB | Output is correct |
12 | Correct | 88 ms | 612 KB | Output is correct |
13 | Correct | 111 ms | 592 KB | Output is correct |
14 | Correct | 18 ms | 208 KB | Output is correct |
15 | Correct | 21 ms | 336 KB | Output is correct |
16 | Correct | 36 ms | 336 KB | Output is correct |
17 | Correct | 49 ms | 336 KB | Output is correct |
18 | Correct | 67 ms | 336 KB | Output is correct |
19 | Correct | 79 ms | 336 KB | Output is correct |
20 | Correct | 73 ms | 336 KB | Output is correct |
21 | Correct | 105 ms | 616 KB | Output is correct |
22 | Correct | 82 ms | 592 KB | Output is correct |
23 | Correct | 76 ms | 728 KB | Output is correct |
24 | Correct | 77 ms | 720 KB | Output is correct |
25 | Correct | 27 ms | 336 KB | Output is correct |
26 | Correct | 19 ms | 460 KB | Output is correct |
27 | Correct | 48 ms | 336 KB | Output is correct |
28 | Correct | 47 ms | 336 KB | Output is correct |
29 | Correct | 47 ms | 336 KB | Output is correct |
30 | Correct | 83 ms | 336 KB | Output is correct |
31 | Correct | 58 ms | 336 KB | Output is correct |
32 | Correct | 62 ms | 336 KB | Output is correct |
33 | Correct | 77 ms | 448 KB | Output is correct |
34 | Correct | 90 ms | 336 KB | Output is correct |
35 | Correct | 70 ms | 336 KB | Output is correct |
36 | Correct | 103 ms | 852 KB | Output is correct |
37 | Correct | 102 ms | 612 KB | Output is correct |
38 | Correct | 87 ms | 604 KB | Output is correct |
39 | Correct | 81 ms | 624 KB | Output is correct |
40 | Correct | 74 ms | 592 KB | Output is correct |
41 | Correct | 145 ms | 620 KB | Output is correct |
42 | Correct | 120 ms | 620 KB | Output is correct |
43 | Correct | 95 ms | 616 KB | Output is correct |
44 | Correct | 89 ms | 592 KB | Output is correct |
45 | Correct | 30 ms | 336 KB | Output is correct |
46 | Correct | 26 ms | 208 KB | Output is correct |
47 | Correct | 36 ms | 336 KB | Output is correct |
48 | Correct | 33 ms | 336 KB | Output is correct |
49 | Correct | 38 ms | 336 KB | Output is correct |
50 | Correct | 75 ms | 336 KB | Output is correct |
51 | Correct | 38 ms | 336 KB | Output is correct |
52 | Correct | 58 ms | 400 KB | Output is correct |
53 | Correct | 89 ms | 336 KB | Output is correct |
54 | Correct | 58 ms | 444 KB | Output is correct |
55 | Correct | 68 ms | 336 KB | Output is correct |
56 | Correct | 79 ms | 636 KB | Output is correct |
57 | Correct | 119 ms | 628 KB | Output is correct |
58 | Correct | 72 ms | 612 KB | Output is correct |
59 | Correct | 101 ms | 592 KB | Output is correct |
60 | Correct | 110 ms | 664 KB | Output is correct |
61 | Correct | 75 ms | 592 KB | Output is correct |
62 | Correct | 98 ms | 624 KB | Output is correct |
63 | Correct | 96 ms | 624 KB | Output is correct |
64 | Correct | 103 ms | 620 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 460 KB | Output is correct |
2 | Correct | 38 ms | 336 KB | Output is correct |
3 | Correct | 48 ms | 336 KB | Output is correct |
4 | Partially correct | 50 ms | 476 KB | Output is partially correct |
5 | Partially correct | 69 ms | 628 KB | Output is partially correct |
6 | Correct | 12 ms | 336 KB | Output is correct |
7 | Correct | 40 ms | 336 KB | Output is correct |
8 | Correct | 50 ms | 336 KB | Output is correct |
9 | Partially correct | 38 ms | 444 KB | Output is partially correct |
10 | Partially correct | 82 ms | 604 KB | Output is partially correct |
11 | Partially correct | 111 ms | 616 KB | Output is partially correct |
12 | Partially correct | 101 ms | 616 KB | Output is partially correct |
13 | Partially correct | 95 ms | 616 KB | Output is partially correct |
14 | Correct | 18 ms | 336 KB | Output is correct |
15 | Correct | 32 ms | 336 KB | Output is correct |
16 | Correct | 41 ms | 336 KB | Output is correct |
17 | Correct | 57 ms | 336 KB | Output is correct |
18 | Correct | 45 ms | 336 KB | Output is correct |
19 | Partially correct | 85 ms | 336 KB | Output is partially correct |
20 | Partially correct | 72 ms | 336 KB | Output is partially correct |
21 | Correct | 21 ms | 336 KB | Output is correct |
22 | Correct | 25 ms | 336 KB | Output is correct |
23 | Correct | 46 ms | 336 KB | Output is correct |
24 | Correct | 37 ms | 336 KB | Output is correct |
25 | Correct | 24 ms | 336 KB | Output is correct |
26 | Partially correct | 62 ms | 336 KB | Output is partially correct |
27 | Partially correct | 68 ms | 336 KB | Output is partially correct |
28 | Partially correct | 58 ms | 400 KB | Output is partially correct |
29 | Partially correct | 83 ms | 448 KB | Output is partially correct |
30 | Partially correct | 86 ms | 336 KB | Output is partially correct |
31 | Partially correct | 86 ms | 452 KB | Output is partially correct |
32 | Correct | 33 ms | 336 KB | Output is correct |
33 | Correct | 29 ms | 336 KB | Output is correct |
34 | Correct | 44 ms | 336 KB | Output is correct |
35 | Correct | 46 ms | 336 KB | Output is correct |
36 | Correct | 35 ms | 336 KB | Output is correct |
37 | Partially correct | 50 ms | 336 KB | Output is partially correct |
38 | Partially correct | 81 ms | 336 KB | Output is partially correct |
39 | Partially correct | 43 ms | 404 KB | Output is partially correct |
40 | Partially correct | 82 ms | 444 KB | Output is partially correct |
41 | Partially correct | 78 ms | 448 KB | Output is partially correct |
42 | Partially correct | 70 ms | 448 KB | Output is partially correct |
43 | Partially correct | 81 ms | 592 KB | Output is partially correct |
44 | Partially correct | 109 ms | 616 KB | Output is partially correct |
45 | Partially correct | 81 ms | 592 KB | Output is partially correct |
46 | Partially correct | 96 ms | 612 KB | Output is partially correct |
47 | Partially correct | 94 ms | 620 KB | Output is partially correct |
48 | Partially correct | 103 ms | 608 KB | Output is partially correct |
49 | Partially correct | 90 ms | 624 KB | Output is partially correct |
50 | Partially correct | 126 ms | 632 KB | Output is partially correct |
51 | Partially correct | 101 ms | 592 KB | Output is partially correct |
52 | Partially correct | 73 ms | 592 KB | Output is partially correct |
53 | Partially correct | 107 ms | 592 KB | Output is partially correct |
54 | Partially correct | 62 ms | 636 KB | Output is partially correct |
55 | Partially correct | 116 ms | 592 KB | Output is partially correct |
56 | Partially correct | 106 ms | 592 KB | Output is partially correct |
57 | Partially correct | 115 ms | 608 KB | Output is partially correct |
58 | Partially correct | 96 ms | 740 KB | Output is partially correct |
59 | Partially correct | 112 ms | 592 KB | Output is partially correct |
60 | Partially correct | 107 ms | 616 KB | Output is partially correct |
61 | Partially correct | 107 ms | 616 KB | Output is partially correct |
62 | Partially correct | 119 ms | 632 KB | Output is partially correct |
63 | Partially correct | 90 ms | 632 KB | Output is partially correct |
64 | Partially correct | 123 ms | 632 KB | Output is partially correct |
65 | Partially correct | 86 ms | 620 KB | Output is partially correct |
66 | Partially correct | 95 ms | 632 KB | Output is partially correct |
67 | Partially correct | 93 ms | 624 KB | Output is partially correct |
68 | Partially correct | 115 ms | 620 KB | Output is partially correct |
69 | Partially correct | 103 ms | 612 KB | Output is partially correct |
70 | Partially correct | 113 ms | 616 KB | Output is partially correct |
71 | Partially correct | 98 ms | 624 KB | Output is partially correct |
72 | Partially correct | 116 ms | 624 KB | Output is partially correct |
73 | Partially correct | 88 ms | 752 KB | Output is partially correct |
74 | Partially correct | 107 ms | 632 KB | Output is partially correct |
75 | Partially correct | 100 ms | 748 KB | Output is partially correct |
76 | Partially correct | 104 ms | 604 KB | Output is partially correct |
77 | Partially correct | 104 ms | 608 KB | Output is partially correct |
78 | Partially correct | 106 ms | 628 KB | Output is partially correct |
79 | Partially correct | 86 ms | 592 KB | Output is partially correct |
80 | Partially correct | 70 ms | 732 KB | Output is partially correct |
81 | Partially correct | 119 ms | 616 KB | Output is partially correct |
82 | Partially correct | 63 ms | 624 KB | Output is partially correct |