# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1030240 |
2024-07-22T00:26:23 Z |
vjudge1 |
Fun Tour (APIO20_fun) |
C++17 |
|
118 ms |
38116 KB |
#include "fun.h"
#include <bits/stdc++.h>
using namespace std;
int N_;
std::vector<int> createFunTour(int N, int Q) {
if(N==2) return{0,1};
pair<int,int>centroid{N,0};
for(int i=1;i<N;i++) {
int k=attractionsBehind(0,i);
if(k>=(N+1)/2)
centroid=min(centroid,{k,i});
}
int k=centroid.second;
vector<int>subtreez;
vector<pair<int,int>> why[3];
for(int i=0;i<N;i++){
if(i==k) continue;
int C=hoursRequired(k,i);
if(!subtreez.size()){
subtreez.push_back(i);
why[0].push_back({C,i});
} else if(subtreez.size()==1){
if(why[0][0].first+C-hoursRequired(why[0][0].second,i))
why[0].push_back({C,i});
else subtreez.push_back(i),why[1].push_back({C,i});
} else {
if(why[0][0].first+C-hoursRequired(why[0][0].second,i))
why[0].push_back({C,i});
else if(why[1][0].first+C-hoursRequired(why[1][0].second,i))
why[1].push_back({C,i});
else why[2].push_back({C,i});
}
}
sort(why[0].begin(),why[0].end());
sort(why[1].begin(),why[1].end());
sort(why[2].begin(),why[2].end());
sort(why,why+3,[](vector<pair<int,int>>&a,vector<pair<int,int>>&b){
if(a.empty()||b.empty()) return !a.empty();
if(a.size()==(N_+1)/2) return true;
if(b.size()==(N_+1)/2) return false;
return a.back().first>b.back().first;
});
vector<int>ans{why[0].back().second};
int prevdep=1e9,curdep=why[0].back().first,cursub=0;
why[0].pop_back();
while(ans.size()<N-1){
vector<int>compatible;
for(int i=0;i<3;i++)
if(why[i].size()&&i-cursub&&why[i].back().first<=prevdep)
compatible.push_back(i);
if(compatible.size()==1){
int c=compatible[0];
prevdep=curdep;cursub=c;
curdep=why[c].back().first;
ans.push_back(why[c].back().second);
why[c].pop_back();
} else {
int A=compatible[0];
int B=compatible[1];
int tot=why[0].size()+why[1].size()+why[2].size();
if(why[A].size()<why[B].size())
swap(A,B);
if(why[A].size()==why[B].size()){
if(why[A].back().first<why[B].back().first){
prevdep=curdep;cursub=B;
curdep=why[B].back().first;
ans.push_back(why[B].back().second);
why[B].pop_back();
} else {
prevdep=curdep;cursub=A;
curdep=why[A].back().first;
ans.push_back(why[A].back().second);
why[A].pop_back();
}
} else if(why[A].size()>=tot/2){
prevdep=curdep;cursub=A;
curdep=why[A].back().first;
ans.push_back(why[A].back().second);
why[A].pop_back();
} else if(why[B].size()>=tot/2){
prevdep=curdep;cursub=B;
curdep=why[B].back().first;
ans.push_back(why[B].back().second);
why[B].pop_back();
} else if(why[A].back().first<why[B].back().first){
prevdep=curdep;cursub=B;
curdep=why[B].back().first;
ans.push_back(why[B].back().second);
why[B].pop_back();
} else {
prevdep=curdep;cursub=A;
curdep=why[A].back().first;
ans.push_back(why[A].back().second);
why[A].pop_back();
}
}
}
ans.push_back(k);
return ans;
}
Compilation message
fun.cpp: In lambda function:
fun.cpp:40:20: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
40 | if(a.size()==(N_+1)/2) return true;
| ~~~~~~~~^~~~~~~~~~
fun.cpp:41:20: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
41 | if(b.size()==(N_+1)/2) return false;
| ~~~~~~~~^~~~~~~~~~
fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:47:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
47 | while(ans.size()<N-1){
| ~~~~~~~~~~^~~~
fun.cpp:76:36: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
76 | } else if(why[A].size()>=tot/2){
| ~~~~~~~~~~~~~^~~~~~~
fun.cpp:81:36: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
81 | } else if(why[B].size()>=tot/2){
| ~~~~~~~~~~~~~^~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
82 ms |
15164 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
2 ms |
604 KB |
Output is correct |
22 |
Correct |
4 ms |
1116 KB |
Output is correct |
23 |
Correct |
8 ms |
2136 KB |
Output is correct |
24 |
Correct |
10 ms |
2788 KB |
Output is correct |
25 |
Correct |
44 ms |
8812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
6 ms |
1628 KB |
Output is correct |
15 |
Correct |
89 ms |
15288 KB |
Output is correct |
16 |
Correct |
86 ms |
14800 KB |
Output is correct |
17 |
Correct |
15 ms |
3676 KB |
Output is correct |
18 |
Correct |
40 ms |
7064 KB |
Output is correct |
19 |
Correct |
69 ms |
11940 KB |
Output is correct |
20 |
Correct |
3 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
82 ms |
15164 KB |
Output is correct |
45 |
Correct |
1 ms |
344 KB |
Output is correct |
46 |
Correct |
1 ms |
604 KB |
Output is correct |
47 |
Correct |
2 ms |
604 KB |
Output is correct |
48 |
Correct |
4 ms |
1116 KB |
Output is correct |
49 |
Correct |
8 ms |
2136 KB |
Output is correct |
50 |
Correct |
10 ms |
2788 KB |
Output is correct |
51 |
Correct |
44 ms |
8812 KB |
Output is correct |
52 |
Correct |
1 ms |
348 KB |
Output is correct |
53 |
Correct |
6 ms |
1628 KB |
Output is correct |
54 |
Correct |
89 ms |
15288 KB |
Output is correct |
55 |
Correct |
86 ms |
14800 KB |
Output is correct |
56 |
Correct |
15 ms |
3676 KB |
Output is correct |
57 |
Correct |
40 ms |
7064 KB |
Output is correct |
58 |
Correct |
69 ms |
11940 KB |
Output is correct |
59 |
Correct |
3 ms |
860 KB |
Output is correct |
60 |
Correct |
103 ms |
15052 KB |
Output is correct |
61 |
Correct |
118 ms |
17352 KB |
Output is correct |
62 |
Correct |
104 ms |
15048 KB |
Output is correct |
63 |
Runtime error |
98 ms |
38116 KB |
Execution killed with signal 11 |
64 |
Halted |
0 ms |
0 KB |
- |