Submission #320193

# Submission time Handle Problem Language Result Execution time Memory
320193 2020-11-07T21:50:22 Z VEGAnn Fun Tour (APIO20_fun) C++14
47 / 100
143 ms 16988 KB
#include "fun.h"
#include <bits/stdc++.h>
#define PB push_back
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define i2 array<int,2>
using namespace std;
const int oo = 2e9;
const int N = 100100;
vector<int> ans, chld;
vector<i2> elms[3];
int dst[N];

void srt(){
    if (sz(elms[0]) < sz(elms[1])) swap(elms[0], elms[1]);
    if (sz(chld) == 3 && sz(elms[1]) < sz(elms[2])) swap(elms[1], elms[2]);
    if (sz(elms[0]) < sz(elms[1])) swap(elms[0], elms[1]);
}

vector<int> createFunTour(int n, int Q) {
    if (n == 2) return {0, 1};

    int cen = -1, mn = oo, hlf = (n + 1) / 2;

    for (int i = 0; i < n; i++){
        int now = attractionsBehind(0, i);

        if (now < mn && now >= hlf){
            mn = now;
            cen = i;
        }
    }

    chld.clear();

    for (int i = 0; i < n; i++){
        if (i == cen) continue;

        int now = hoursRequired(cen, i);

        dst[i] = now;

        if (now == 1)
            chld.PB(i);
    }

    for (int i = 0; i < n; i++){
        if (i == cen) continue;

        int who = 0;

        for (int it = 1; it < sz(chld); it++){
            int now = hoursRequired(chld[it], i);

            if (now + 1 == dst[i]){
                who = it;
                break;
            }
        }

        elms[who].PB({dst[i], i});
    }

    for (int i = 0; i < sz(chld); i++){
        sort(all(elms[i]));
    }

    srt();

    ans.clear();

    if (sz(chld) == 3 && sz(elms[0]) >= sz(elms[1]) + sz(elms[2])){
        chld.pop_back();

        for (i2 cr : elms[2])
            elms[1].PB(cr);

        sort(all(elms[1]));
    }

    if (sz(chld) == 3){
        int lst = -1;

        while (1){
            int bst = -1, id = -1;

            for (int it = 0; it < 3; it++){
                if (it == lst) continue;

                if (elms[it].back()[0] > bst){
                    bst = elms[it].back()[0];
                    id = it;
                }
            }

            ans.PB(elms[id].back()[1]);
            elms[id].pop_back();

            lst = id;

            if (sz(elms[0]) == sz(elms[1]) + sz(elms[2])) break;
            if (sz(elms[1]) == sz(elms[0]) + sz(elms[2])) break;
            if (sz(elms[2]) == sz(elms[0]) + sz(elms[1])) break;
        }

        int mx = -1, who = -1;

        for (int it = 0; it < 3; it++)
            if (sz(elms[it]) > mx){
                mx = sz(elms[it]);
                who = it;
            }

        int bst = -1, id = -1;

        for (int it = 0; it < 3; it++){
            if (it == lst || sz(elms[it]) == 0) continue;

            if (elms[it].back()[0] > bst){
                bst = elms[it].back()[0];
                id = it;
            }
        }

        ans.PB(elms[id].back()[1]);
        elms[id].pop_back();

//        srt();
        swap(elms[0], elms[who]);

        for (i2 cr : elms[2])
            elms[1].PB(cr);

        sort(all(elms[1]));

        if (sz(elms[0]) < sz(elms[1])) swap(elms[1], elms[0]);

        while (sz(elms[1]) > 0){
            ans.PB(elms[0].back()[1]);
            ans.PB(elms[1].back()[1]);

            elms[0].pop_back();
            elms[1].pop_back();
        }

        if (sz(elms[0]) > 0)
            ans.PB(elms[0][0][1]);
    } else {
        while (sz(elms[1]) > 0){
            ans.PB(elms[0].back()[1]);
            ans.PB(elms[1].back()[1]);

            elms[0].pop_back();
            elms[1].pop_back();
        }

        if (sz(elms[0]) > 0)
            ans.PB(elms[0][0][1]);
    }

    ans.PB(cen);

    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 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 1 ms 492 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 416 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 492 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 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 492 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 1 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 1 ms 492 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 416 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 492 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 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 268 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 380 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 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 492 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 620 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 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 416 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 268 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 380 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 143 ms 16988 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 3 ms 620 KB Output is correct
21 Correct 4 ms 748 KB Output is correct
22 Correct 9 ms 1388 KB Output is correct
23 Correct 14 ms 2412 KB Output is correct
24 Correct 19 ms 3180 KB Output is correct
25 Correct 82 ms 9856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 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 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 Incorrect 10 ms 1900 KB Tour is not fun
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 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 1 ms 492 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 416 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 492 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 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 268 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 380 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 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 492 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 620 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 143 ms 16988 KB Output is correct
45 Correct 1 ms 492 KB Output is correct
46 Correct 3 ms 620 KB Output is correct
47 Correct 4 ms 748 KB Output is correct
48 Correct 9 ms 1388 KB Output is correct
49 Correct 14 ms 2412 KB Output is correct
50 Correct 19 ms 3180 KB Output is correct
51 Correct 82 ms 9856 KB Output is correct
52 Correct 1 ms 492 KB Output is correct
53 Incorrect 10 ms 1900 KB Tour is not fun
54 Halted 0 ms 0 KB -