Submission #967371

# Submission time Handle Problem Language Result Execution time Memory
967371 2024-04-22T03:22:41 Z owoovo Fun Tour (APIO20_fun) C++17
100 / 100
198 ms 21196 KB
#include "fun.h"
#include<bits/stdc++.h>
#define ll long long 
#define F first 
#define S second 
using namespace std;
vector<int> createFunTour(int n, int q) {
    int root=0,hf=(n+1)/2,mn=n;
    for(int i=0;i<n;i++){
        int A=attractionsBehind(0,i);
        if(A>=hf&&A<mn){
            mn=A,root=i;
        }
    }
    int tr[100010],tc[3][100010];
    vector<int> ch;
    priority_queue<pair<int,int>> sub[3];
    for(int i=0;i<n;i++){
        tr[i]=hoursRequired(root,i);
        if(tr[i]==1)ch.push_back(i);
    }
    int chsz=ch.size();
    for(int j=0;j<n;j++){
        if(j==root)continue;
        int to=chsz-1;
        for(int i=0;i<chsz-1;i++){
            tc[i][j]=hoursRequired(ch[i],j);
            if(tc[i][j]<tr[j])to=i;
        }
        sub[to].push({tr[j],j});
    }
    int left=(n-1),mer=0,last=0;
    vector<int> ans;
    while(left>0){
        pair<int,int> best={0,-1};
        for(int j=0;j<chsz;j++){
            if(j!=last&&(!sub[j].empty())&&sub[j].top().F>best.F){
                best={sub[j].top().F,j};
            }
        }
        pair<int,int> mxsz={0,0};
        for(int j=0;j<chsz;j++){
            if(sub[j].size()>mxsz.F){
                mxsz={sub[j].size(),j};
            }
        }



        if(mer==0&&mxsz.F*2>=left&&last!=mxsz.S){
            mer=1;
            int lf=3-last-mxsz.S;
            if(((!sub[lf].empty())&&(!sub[last].empty()))&&sub[lf].top().F>sub[last].top().F){
                last=lf;
                auto [x,y]=sub[last].top();
                sub[last].pop();
                ans.push_back(y);
                left--;
            }
            lf=3-last-mxsz.S;
            //cout<<lf<<" "<<last<<" "<<mxsz.S<<"\n";
            assert(lf>=0&&lf<3);
            while(!sub[lf].empty()){
                sub[last].push(sub[lf].top());
                sub[lf].pop();
            }
            best.S=mxsz.S;
        }



        if(best.S==-1){
            for(int j=0;j<chsz;j++){
                if(!sub[j].empty())best.S=j;
            }
        }
        assert(!sub[best.S].empty());
        auto [x,y]=sub[best.S].top();
        sub[best.S].pop();
        ans.push_back(y);
        left--;
        last=best.S;
    }
    ans.push_back(root);
    return ans;
}

Compilation message

fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:43:29: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   43 |             if(sub[j].size()>mxsz.F){
      |                             ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 764 KB Output is correct
4 Correct 1 ms 756 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 0 ms 604 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 0 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 764 KB Output is correct
4 Correct 1 ms 756 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 0 ms 604 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 0 ms 604 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 0 ms 604 KB Output is correct
23 Correct 0 ms 604 KB Output is correct
24 Correct 1 ms 860 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 0 ms 604 KB Output is correct
29 Correct 1 ms 860 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 860 KB Output is correct
33 Correct 1 ms 696 KB Output is correct
34 Correct 1 ms 860 KB Output is correct
35 Correct 1 ms 860 KB Output is correct
36 Correct 1 ms 860 KB Output is correct
37 Correct 1 ms 600 KB Output is correct
38 Correct 1 ms 860 KB Output is correct
39 Correct 1 ms 604 KB Output is correct
40 Correct 1 ms 860 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 1 ms 764 KB Output is correct
3 Correct 1 ms 756 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 1 ms 860 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 1112 KB Output is correct
17 Correct 1 ms 860 KB Output is correct
18 Correct 99 ms 15544 KB Output is correct
19 Correct 1 ms 860 KB Output is correct
20 Correct 2 ms 860 KB Output is correct
21 Correct 3 ms 1368 KB Output is correct
22 Correct 5 ms 1596 KB Output is correct
23 Correct 10 ms 2652 KB Output is correct
24 Correct 13 ms 3420 KB Output is correct
25 Correct 56 ms 9764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 1 ms 764 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 860 KB Output is correct
12 Correct 1 ms 696 KB Output is correct
13 Correct 1 ms 856 KB Output is correct
14 Correct 8 ms 2140 KB Output is correct
15 Correct 104 ms 16392 KB Output is correct
16 Correct 110 ms 16336 KB Output is correct
17 Correct 19 ms 4440 KB Output is correct
18 Correct 46 ms 7972 KB Output is correct
19 Correct 85 ms 13216 KB Output is correct
20 Correct 4 ms 1368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 764 KB Output is correct
4 Correct 1 ms 756 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 0 ms 604 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 0 ms 604 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 0 ms 604 KB Output is correct
23 Correct 0 ms 604 KB Output is correct
24 Correct 1 ms 860 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 0 ms 604 KB Output is correct
29 Correct 1 ms 860 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 860 KB Output is correct
33 Correct 1 ms 696 KB Output is correct
34 Correct 1 ms 860 KB Output is correct
35 Correct 1 ms 860 KB Output is correct
36 Correct 1 ms 860 KB Output is correct
37 Correct 1 ms 600 KB Output is correct
38 Correct 1 ms 860 KB Output is correct
39 Correct 1 ms 604 KB Output is correct
40 Correct 1 ms 860 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 1112 KB Output is correct
43 Correct 1 ms 860 KB Output is correct
44 Correct 99 ms 15544 KB Output is correct
45 Correct 1 ms 860 KB Output is correct
46 Correct 2 ms 860 KB Output is correct
47 Correct 3 ms 1368 KB Output is correct
48 Correct 5 ms 1596 KB Output is correct
49 Correct 10 ms 2652 KB Output is correct
50 Correct 13 ms 3420 KB Output is correct
51 Correct 56 ms 9764 KB Output is correct
52 Correct 1 ms 856 KB Output is correct
53 Correct 8 ms 2140 KB Output is correct
54 Correct 104 ms 16392 KB Output is correct
55 Correct 110 ms 16336 KB Output is correct
56 Correct 19 ms 4440 KB Output is correct
57 Correct 46 ms 7972 KB Output is correct
58 Correct 85 ms 13216 KB Output is correct
59 Correct 4 ms 1368 KB Output is correct
60 Correct 109 ms 16436 KB Output is correct
61 Correct 131 ms 18632 KB Output is correct
62 Correct 128 ms 16812 KB Output is correct
63 Correct 128 ms 20168 KB Output is correct
64 Correct 129 ms 19984 KB Output is correct
65 Correct 136 ms 16836 KB Output is correct
66 Correct 146 ms 18644 KB Output is correct
67 Correct 139 ms 19888 KB Output is correct
68 Correct 161 ms 19400 KB Output is correct
69 Correct 198 ms 21096 KB Output is correct
70 Correct 121 ms 16692 KB Output is correct
71 Correct 143 ms 20168 KB Output is correct
72 Correct 147 ms 18892 KB Output is correct
73 Correct 150 ms 19292 KB Output is correct
74 Correct 174 ms 21076 KB Output is correct
75 Correct 131 ms 16948 KB Output is correct
76 Correct 138 ms 20220 KB Output is correct
77 Correct 147 ms 19960 KB Output is correct
78 Correct 145 ms 19708 KB Output is correct
79 Correct 150 ms 20580 KB Output is correct
80 Correct 194 ms 21196 KB Output is correct
81 Correct 128 ms 16408 KB Output is correct
82 Correct 130 ms 16900 KB Output is correct
83 Correct 144 ms 16948 KB Output is correct
84 Correct 53 ms 7336 KB Output is correct