답안 #1030502

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1030502 2024-07-22T06:08:38 Z _8_8_ 즐거운 행로 (APIO20_fun) C++17
66 / 100
167 ms 21960 KB
#include "fun.h"
#include <bits/stdc++.h>
using namespace std;
int n,q;
int find_cen(){
    vector<pair<int,int>> a;
    for(int i = 1;i < n;i++){
        int s = attractionsBehind(0,i); 
        if(s*2 > n){
            a.emplace_back(s,i);
        }
    }
    if(a.empty()) return 0;
    sort(a.begin(),a.end());
    return a[0].second;
}
const int N = 1e5 + 12;
int val[N];
vector<int> createFunTour(int nn, int qq) {
    if(nn == 2){
        return {0,1};
    }
    n = nn;q = qq;
    int c = find_cen();
    array<int,3> ver = {-1,-1,-1};
    array<vector<pair<int,int>>,3> vec;
    for(int i = 0;i < n;i++){
        if(i == c) continue;
        val[i] = hoursRequired(c,i);
        if(val[i] == 1){
            for(int j = 0;j < 3;j++){
                if(ver[j] == -1){
                    ver[j] = i;
                    break;
                }
            }
        }
    }
    vector<int> res;
    for(int i = 0;i < n;i++){
        if(i == c) continue;
        if(val[i] == 1){
            if(i == ver[0]){
                vec[0].push_back({1,i});
            }else if(i == ver[1]){
                vec[1].push_back({1,i});
            }else{
                vec[2].push_back({1,i});
            }
            continue;
        }
        int _ = -1;
        for(int k = 0;k < 2;k++){
            if(val[i] - 1 == hoursRequired(i,ver[k])){
                _=k;
                break;
            }
        }
        if(_ == -1) _ = 2;
        vec[_].push_back({val[i],i});
    }
    int lst = -1;
    int l = 0;
    bool OK = true;
    int _x = (int)vec[0].size(),_y = (int)vec[1].size(),_z = (int)vec[2].size();
    if(_x == _y + _z + 1 || _y  == _z + _x + 1 || _z == _x + _y + 1){
        OK = false;
        vector<pair<int,int>> cc;
        for(int i = 0;i < 3;i++){
            cc.push_back({(int)vec[i].size(),i});
        }
        sort(cc.begin(),cc.end());
        vec[(int)cc[0].second].push_back({0,c});
    }
    for(int i = 0;i < 3;i++){
        sort(vec[i].begin(),vec[i].end());
    }
    // cout << c << '\n';
    while(true){
        int _x = (int)vec[0].size(),_y = (int)vec[1].size(),_z = (int)vec[2].size();
        // cout << _x << ' ' << _y << ' ' << _z << '\n';
        if(_x == _y + _z || _y == _x + _z || _z == _x + _y){
            break;
        }
        if(!_x || !_y || !_z){
            int mx = max({_x,_y,_z});
            for(int i = 0;i < 3;i++){
                if((int)vec[i].size() == mx){
                    lst = i;
                    res.push_back(vec[i].back().second);
                    vec[i].pop_back();
                }
            }
            break;
        }
        pair<int,int> mx = {-1,-1};
        int id = -1;
        auto upd = [&](vector<pair<int,int>> &a,int j){
            if(j != lst && (int)a.size()){
                pair<int,int> nv = make_pair(a.back().first,(int)a.size());
                if(nv > mx){
                    mx = nv;
                    id = j;
                }
            }
        };
        auto del = [&](vector<pair<int,int>> &x){ 
            res.push_back(x.back().second);
            x.pop_back();
        };
        int cc = 0;
        for(int i = 0;i < 3;i++){
            if((int)vec[i].empty()) cc++;
            upd(vec[i],i);
        }
        lst = id;
        del(vec[id]);
    }
    vector<int> X,Y;
    vector<pair<int,int>> bff;
    for(int i = 0;i < 3;i++){
        bff.push_back({(int)vec[i].size(),i});
    }
    sort(bff.begin(),bff.end());
    bool ok = false;
    for(int i = 0;i < 3;i++){
        int j = bff[i].second;
        if(i < 2){
            if(lst == j) ok = 1;
            for(auto f:vec[j]){
                X.push_back(f.second);
            }
        }else{
            for(auto f:vec[j]){
                Y.push_back(f.second);
            }
        }
    }
    if(ok){
        X.swap(Y);
    }
    auto cmp = [&](int x,int y)->bool{
        return val[x] > val[y];
    };
    sort(X.begin(),X.end(),cmp);
    sort(Y.begin(),Y.end(),cmp);
    for(int i = 0;i < (int)X.size();i++){
        res.push_back(X[i]);
        res.push_back(Y[i]);
    }
    if(OK) res.push_back(c);
    return res;
}

Compilation message

fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:63:9: warning: unused variable 'l' [-Wunused-variable]
   63 |     int l = 0;
      |         ^
# 결과 실행 시간 메모리 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 1 ms 344 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 1 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 348 KB Output is correct
20 Correct 1 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 1 ms 344 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 1 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 348 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 396 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 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 444 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 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 1 ms 344 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 396 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 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 444 KB Output is correct
18 Correct 82 ms 16708 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 8 ms 2396 KB Output is correct
24 Correct 10 ms 3044 KB Output is correct
25 Correct 45 ms 9624 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 1 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 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 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 1708 KB Output is correct
15 Correct 89 ms 16428 KB Output is correct
16 Correct 93 ms 16332 KB Output is correct
17 Correct 16 ms 4188 KB Output is correct
18 Correct 38 ms 7772 KB Output is correct
19 Correct 63 ms 13068 KB Output is correct
20 Correct 3 ms 860 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 1 ms 344 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 1 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 348 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 396 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 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 444 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 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 444 KB Output is correct
44 Correct 82 ms 16708 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 8 ms 2396 KB Output is correct
50 Correct 10 ms 3044 KB Output is correct
51 Correct 45 ms 9624 KB Output is correct
52 Correct 1 ms 344 KB Output is correct
53 Correct 6 ms 1708 KB Output is correct
54 Correct 89 ms 16428 KB Output is correct
55 Correct 93 ms 16332 KB Output is correct
56 Correct 16 ms 4188 KB Output is correct
57 Correct 38 ms 7772 KB Output is correct
58 Correct 63 ms 13068 KB Output is correct
59 Correct 3 ms 860 KB Output is correct
60 Correct 113 ms 16844 KB Output is correct
61 Correct 127 ms 19212 KB Output is correct
62 Correct 113 ms 17340 KB Output is correct
63 Correct 120 ms 21044 KB Output is correct
64 Correct 126 ms 20724 KB Output is correct
65 Correct 115 ms 17096 KB Output is correct
66 Correct 138 ms 19396 KB Output is correct
67 Correct 137 ms 20996 KB Output is correct
68 Correct 143 ms 20172 KB Output is correct
69 Correct 152 ms 21704 KB Output is correct
70 Correct 103 ms 16840 KB Output is correct
71 Correct 126 ms 20428 KB Output is correct
72 Correct 154 ms 19656 KB Output is correct
73 Correct 133 ms 20168 KB Output is correct
74 Correct 149 ms 21396 KB Output is correct
75 Correct 116 ms 17096 KB Output is correct
76 Correct 127 ms 21220 KB Output is correct
77 Correct 127 ms 21196 KB Output is correct
78 Correct 115 ms 20168 KB Output is correct
79 Correct 141 ms 21632 KB Output is correct
80 Correct 167 ms 21960 KB Output is correct
81 Correct 110 ms 16584 KB Output is correct
82 Correct 109 ms 16844 KB Output is correct
83 Incorrect 111 ms 16724 KB Tour is not fun
84 Halted 0 ms 0 KB -