Submission #319494

# Submission time Handle Problem Language Result Execution time Memory
319494 2020-11-05T12:05:58 Z Vimmer Fun Tour (APIO20_fun) C++14
26 / 100
16 ms 2816 KB
#include <bits/stdc++.h>
#include "fun.h"
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")

#define N 100100
#define F first
#define S second
#define M ll(1e9 + 7)
#define endl '\n'
#define all(x) x.begin(), x.end()
#define PB push_back
#define sz(x) ll(x.size())
#define pw(x) (1ll << x)
#define pwr(x) ((1ll << x) - 1)
#define _ << " " <<
#define pri(s) cout << s << endl

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef short int si;
typedef unsigned long long ull;

//typedef tree<int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

vector <int> g[N];

int mx, nm;

bool mk[N];

set <int> sl, sr;

void dfs(int v, int p, int h)
{
    if (h > mx && !mk[v]) {mx = h; nm = v;}

    for (auto it : g[v])
    {
        if (it == p) continue;

        dfs(it, v, h + 1);
    }
}

void make(int n, int root)
{
    sl.clear();

    sr.clear();

    vector <int> vr; vr.clear();

    int j = 0;

    sl.insert(root);

    if (!mk[root + root])
    {
        sl.insert(root + root);

        vr.PB(root + root);
    }

    while (j < sz(vr))
    {
        int x = vr[j++];

        if (!mk[x + x] && x + x <= n) {sl.insert(x + x); vr.PB(x + x);}
        if (!mk[x + x + 1] && x + x + 1 <= n) {sl.insert(x + x + 1); vr.PB(x + x + 1);}
    }

    vr.clear();

    j = 0;

    sr.insert(root);

    if (!mk[root + root + 1])
    {
        sr.insert(root + root + 1);

        vr.PB(root + root + 1);
    }

    while (j < sz(vr))
    {
        int x = vr[j++];

        if (!mk[x + x] && x + x <= n) {sr.insert(x + x); vr.PB(x + x);}
        if (!mk[x + x + 1] && x + x + 1 <= n) {sr.insert(x + x + 1); vr.PB(x + x + 1);}
    }
}

vector <int> vr;

void dob(int v, bool f)
{
    mk[v] = 1;

    vr.PB(v);

    if (f) sr.erase(v);
      else sl.erase(v);
}

vector<int> createFunTour(int n, int q)
{
    if(n > 500)
    {
        int root = 1;

        make(n, root);

        int cur = *sl.rbegin();

        dob(cur, 0);

        while (sz(vr) < n)
        {
            int mx = *sr.rbegin();

            dob(mx, 1);

            cur = mx;

            if (sz(vr) == n) break;

            if (cur == root) {root *= 2; make(n, root);}

            mx = *sl.rbegin();

            dob(mx, 0);

            cur = mx;
        }

        for (int i = 0; i < sz(vr); i++) vr[i]--;

        return vr;
    }

    for (int i = 0; i < n; i++)
        for (int j = i + 1; j < n; j++)
          if (hoursRequired(i, j) == 1) {g[i].PB(j); g[j].PB(i);}

    dfs(0, -1, 1);

    int root = nm;

    mx = -1;

    dfs(root, -1, 1);

    root = nm;

    vr.PB(root);

    mk[root] = 1;

    while (sz(vr) < n)
    {
        mx = -1;

        dfs(root, -1, 1);

        root = nm;

        mk[root] = 1;

        vr.PB(root);
    }

    return vr;
}

//int main()
//{
//    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//
//    int n;
//
//    cin >> n;
//
//    vector <int> vr = createFunTour(n, -1);
//
//    for (auto it : vr) cout << it << " ";
//}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2816 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 2 ms 2668 KB Output is correct
8 Correct 2 ms 2668 KB Output is correct
9 Correct 2 ms 2796 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
11 Correct 2 ms 2668 KB Output is correct
12 Correct 2 ms 2668 KB Output is correct
13 Correct 2 ms 2668 KB Output is correct
14 Correct 2 ms 2668 KB Output is correct
15 Correct 2 ms 2668 KB Output is correct
16 Correct 2 ms 2668 KB Output is correct
17 Correct 2 ms 2796 KB Output is correct
18 Correct 2 ms 2668 KB Output is correct
19 Correct 2 ms 2700 KB Output is correct
20 Correct 2 ms 2796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2816 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 2 ms 2668 KB Output is correct
8 Correct 2 ms 2668 KB Output is correct
9 Correct 2 ms 2796 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
11 Correct 2 ms 2668 KB Output is correct
12 Correct 2 ms 2668 KB Output is correct
13 Correct 2 ms 2668 KB Output is correct
14 Correct 2 ms 2668 KB Output is correct
15 Correct 2 ms 2668 KB Output is correct
16 Correct 2 ms 2668 KB Output is correct
17 Correct 2 ms 2796 KB Output is correct
18 Correct 2 ms 2668 KB Output is correct
19 Correct 2 ms 2700 KB Output is correct
20 Correct 2 ms 2796 KB Output is correct
21 Correct 2 ms 2668 KB Output is correct
22 Correct 2 ms 2668 KB Output is correct
23 Correct 2 ms 2668 KB Output is correct
24 Correct 13 ms 2796 KB Output is correct
25 Correct 2 ms 2668 KB Output is correct
26 Correct 3 ms 2668 KB Output is correct
27 Correct 3 ms 2668 KB Output is correct
28 Correct 2 ms 2668 KB Output is correct
29 Correct 14 ms 2796 KB Output is correct
30 Correct 2 ms 2668 KB Output is correct
31 Correct 4 ms 2668 KB Output is correct
32 Correct 6 ms 2668 KB Output is correct
33 Correct 3 ms 2668 KB Output is correct
34 Correct 15 ms 2796 KB Output is correct
35 Correct 16 ms 2796 KB Output is correct
36 Correct 16 ms 2796 KB Output is correct
37 Correct 3 ms 2796 KB Output is correct
38 Correct 15 ms 2816 KB Output is correct
39 Correct 6 ms 2668 KB Output is correct
40 Correct 9 ms 2668 KB Output is correct
41 Correct 4 ms 2668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 2 ms 2816 KB Output is correct
5 Correct 2 ms 2668 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 2 ms 2668 KB Output is correct
8 Correct 2 ms 2796 KB Output is correct
9 Correct 2 ms 2668 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
11 Correct 2 ms 2668 KB Output is correct
12 Correct 13 ms 2796 KB Output is correct
13 Correct 2 ms 2668 KB Output is correct
14 Correct 3 ms 2668 KB Output is correct
15 Correct 3 ms 2668 KB Output is correct
16 Incorrect 3 ms 2796 KB Tour is not fun
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2668 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 2 ms 2668 KB Output is correct
8 Correct 14 ms 2796 KB Output is correct
9 Correct 2 ms 2668 KB Output is correct
10 Correct 4 ms 2668 KB Output is correct
11 Correct 6 ms 2668 KB Output is correct
12 Correct 3 ms 2668 KB Output is correct
13 Incorrect 3 ms 2796 KB Tour is not fun
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2816 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 2 ms 2668 KB Output is correct
8 Correct 2 ms 2668 KB Output is correct
9 Correct 2 ms 2796 KB Output is correct
10 Correct 2 ms 2668 KB Output is correct
11 Correct 2 ms 2668 KB Output is correct
12 Correct 2 ms 2668 KB Output is correct
13 Correct 2 ms 2668 KB Output is correct
14 Correct 2 ms 2668 KB Output is correct
15 Correct 2 ms 2668 KB Output is correct
16 Correct 2 ms 2668 KB Output is correct
17 Correct 2 ms 2796 KB Output is correct
18 Correct 2 ms 2668 KB Output is correct
19 Correct 2 ms 2700 KB Output is correct
20 Correct 2 ms 2796 KB Output is correct
21 Correct 2 ms 2668 KB Output is correct
22 Correct 2 ms 2668 KB Output is correct
23 Correct 2 ms 2668 KB Output is correct
24 Correct 13 ms 2796 KB Output is correct
25 Correct 2 ms 2668 KB Output is correct
26 Correct 3 ms 2668 KB Output is correct
27 Correct 3 ms 2668 KB Output is correct
28 Correct 2 ms 2668 KB Output is correct
29 Correct 14 ms 2796 KB Output is correct
30 Correct 2 ms 2668 KB Output is correct
31 Correct 4 ms 2668 KB Output is correct
32 Correct 6 ms 2668 KB Output is correct
33 Correct 3 ms 2668 KB Output is correct
34 Correct 15 ms 2796 KB Output is correct
35 Correct 16 ms 2796 KB Output is correct
36 Correct 16 ms 2796 KB Output is correct
37 Correct 3 ms 2796 KB Output is correct
38 Correct 15 ms 2816 KB Output is correct
39 Correct 6 ms 2668 KB Output is correct
40 Correct 9 ms 2668 KB Output is correct
41 Correct 4 ms 2668 KB Output is correct
42 Incorrect 3 ms 2796 KB Tour is not fun
43 Halted 0 ms 0 KB -