답안 #1030244

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1030244 2024-07-22T00:31:24 Z vjudge1 즐거운 행로 (APIO20_fun) C++17
66 / 100
107 ms 38860 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()==b.size())
            return a.back().first>b.back().first;
        if(a.size()==N_/2) return true;
        if(b.size()==N_/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:42: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]
   42 |         if(a.size()==N_/2) return true;
      |            ~~~~~~~~^~~~~~
fun.cpp:43: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]
   43 |         if(b.size()==N_/2) return false;
      |            ~~~~~~~~^~~~~~
fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:49:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   49 |     while(ans.size()<N-1){
      |           ~~~~~~~~~~^~~~
fun.cpp:78: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]
   78 |             } else if(why[A].size()>=tot/2){
      |                       ~~~~~~~~~~~~~^~~~~~~
fun.cpp:83: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]
   83 |             } else if(why[B].size()>=tot/2){
      |                       ~~~~~~~~~~~~~^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 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 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 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 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 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 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 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 348 KB Output is correct
20 Correct 0 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 0 ms 348 KB Output is correct
27 Correct 0 ms 348 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 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 436 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 348 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
# 결과 실행 시간 메모리 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 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 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 0 ms 348 KB Output is correct
15 Correct 0 ms 348 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 16076 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 860 KB Output is correct
22 Correct 4 ms 1372 KB Output is correct
23 Correct 7 ms 2392 KB Output is correct
24 Correct 10 ms 3164 KB Output is correct
25 Correct 45 ms 9392 KB Output is correct
# 결과 실행 시간 메모리 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 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 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 6 ms 1884 KB Output is correct
15 Correct 93 ms 15936 KB Output is correct
16 Correct 83 ms 15564 KB Output is correct
17 Correct 15 ms 3932 KB Output is correct
18 Correct 41 ms 7484 KB Output is correct
19 Correct 70 ms 12712 KB Output is correct
20 Correct 3 ms 856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 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 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 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 348 KB Output is correct
20 Correct 0 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 0 ms 348 KB Output is correct
27 Correct 0 ms 348 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 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 436 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 348 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 16076 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 860 KB Output is correct
48 Correct 4 ms 1372 KB Output is correct
49 Correct 7 ms 2392 KB Output is correct
50 Correct 10 ms 3164 KB Output is correct
51 Correct 45 ms 9392 KB Output is correct
52 Correct 1 ms 344 KB Output is correct
53 Correct 6 ms 1884 KB Output is correct
54 Correct 93 ms 15936 KB Output is correct
55 Correct 83 ms 15564 KB Output is correct
56 Correct 15 ms 3932 KB Output is correct
57 Correct 41 ms 7484 KB Output is correct
58 Correct 70 ms 12712 KB Output is correct
59 Correct 3 ms 856 KB Output is correct
60 Correct 105 ms 15820 KB Output is correct
61 Correct 107 ms 18120 KB Output is correct
62 Correct 104 ms 15752 KB Output is correct
63 Runtime error 99 ms 38860 KB Execution killed with signal 11
64 Halted 0 ms 0 KB -