Submission #348649

# Submission time Handle Problem Language Result Execution time Memory
348649 2021-01-15T11:28:09 Z denkendoemeer Fun Tour (APIO20_fun) C++14
100 / 100
340 ms 21220 KB
#include<bits/stdc++.h>
#include "fun.h"
using namespace std;
vector<int>ans,av(3),dist,grup[3];
int cmp(int a,int b)
{
    return dist[a]<dist[b];
}
int cmp2(int a,int b)
{
    return grup[a].size()>grup[b].size();
}
int cmp3(int a,int b)
{
    return dist[grup[a].back()]>dist[grup[b].back()];
}
vector<int>createFunTour(int n,int q)
{
    dist.resize(n);
    int cent=0,last=-1,i,j;
    for(i=1;i<n;i++)
        if (attractionsBehind(cent,i)>n/2)
            cent=i;
    for(i=0;i<n;i++)
        if (i!=cent)
            dist[i]=hoursRequired(i,cent);
    for(i=0;i<n;i++)
        if (i!=cent){
            for(j=0;j<3;j++)
                if (j==2 || grup[j].size()==0 || hoursRequired(grup[j][0],i)!=(dist[i]+dist[grup[j][0]])){
                    grup[j].push_back(i);
                    break;
                }
        }
    av[0]=0;
    av[1]=1;
    av[2]=2;
    for(i=0;i<3;i++)
        sort(grup[i].begin(),grup[i].end(),cmp);
    while(1){
        sort(av.begin(),av.end(),cmp2);
        if (grup[av[0]].size()>=grup[av[1]].size()+grup[av[2]].size())
            break;
        sort(av.begin(),av.end(),cmp3);
        if (last==av[0])
            last=av[1];
        else
            last=av[0];
        ans.push_back(grup[last].back());
        grup[last].pop_back();
    }
    grup[av[1]].insert(grup[av[1]].end(),grup[av[2]].begin(),grup[av[2]].end());
    sort(grup[av[1]].begin(),grup[av[1]].end(),cmp);
    int aux=0;
    if (ans.size()>1 && dist[ans.back()]<dist[grup[av[1]].back()])
        aux=1;
    while(grup[av[aux]].size()){
        ans.push_back(grup[av[aux]].back());
        grup[av[aux]].pop_back();
        aux=aux^1;
    }
    ans.push_back(cent);
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 0 ms 364 KB Output is correct
16 Correct 0 ms 364 KB Output is correct
17 Correct 0 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 0 ms 364 KB Output is correct
16 Correct 0 ms 364 KB Output is correct
17 Correct 0 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 0 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 0 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 141 ms 15076 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 2 ms 620 KB Output is correct
21 Correct 4 ms 748 KB Output is correct
22 Correct 7 ms 1260 KB Output is correct
23 Correct 14 ms 2284 KB Output is correct
24 Correct 19 ms 2944 KB Output is correct
25 Correct 79 ms 8836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 11 ms 1644 KB Output is correct
15 Correct 154 ms 15076 KB Output is correct
16 Correct 150 ms 14952 KB Output is correct
17 Correct 27 ms 3820 KB Output is correct
18 Correct 66 ms 6964 KB Output is correct
19 Correct 123 ms 11836 KB Output is correct
20 Correct 5 ms 876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 0 ms 364 KB Output is correct
16 Correct 0 ms 364 KB Output is correct
17 Correct 0 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 0 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 0 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 141 ms 15076 KB Output is correct
45 Correct 1 ms 364 KB Output is correct
46 Correct 2 ms 620 KB Output is correct
47 Correct 4 ms 748 KB Output is correct
48 Correct 7 ms 1260 KB Output is correct
49 Correct 14 ms 2284 KB Output is correct
50 Correct 19 ms 2944 KB Output is correct
51 Correct 79 ms 8836 KB Output is correct
52 Correct 1 ms 492 KB Output is correct
53 Correct 11 ms 1644 KB Output is correct
54 Correct 154 ms 15076 KB Output is correct
55 Correct 150 ms 14952 KB Output is correct
56 Correct 27 ms 3820 KB Output is correct
57 Correct 66 ms 6964 KB Output is correct
58 Correct 123 ms 11836 KB Output is correct
59 Correct 5 ms 876 KB Output is correct
60 Correct 195 ms 15204 KB Output is correct
61 Correct 233 ms 17508 KB Output is correct
62 Correct 217 ms 15332 KB Output is correct
63 Correct 228 ms 20580 KB Output is correct
64 Correct 224 ms 20452 KB Output is correct
65 Correct 209 ms 16228 KB Output is correct
66 Correct 217 ms 18660 KB Output is correct
67 Correct 240 ms 20312 KB Output is correct
68 Correct 238 ms 19612 KB Output is correct
69 Correct 318 ms 21220 KB Output is correct
70 Correct 217 ms 16228 KB Output is correct
71 Correct 237 ms 20324 KB Output is correct
72 Correct 237 ms 19044 KB Output is correct
73 Correct 226 ms 19428 KB Output is correct
74 Correct 304 ms 21196 KB Output is correct
75 Correct 203 ms 16492 KB Output is correct
76 Correct 234 ms 20212 KB Output is correct
77 Correct 226 ms 20440 KB Output is correct
78 Correct 220 ms 19428 KB Output is correct
79 Correct 340 ms 20964 KB Output is correct
80 Correct 310 ms 21220 KB Output is correct
81 Correct 214 ms 16228 KB Output is correct
82 Correct 203 ms 16228 KB Output is correct
83 Correct 216 ms 16612 KB Output is correct
84 Correct 77 ms 7108 KB Output is correct