Submission #143834

# Submission time Handle Problem Language Result Execution time Memory
143834 2019-08-15T09:52:11 Z dacin21 Split the Attractions (IOI19_split) C++14
40 / 100
1915 ms 18808 KB
#include "split.h"


#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using fl = long double;
template<typename T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template<typename S, typename T>
void xmin(S&a, T const&b){if(b<a) a=b;}
template<typename S, typename T>
void xmax(S&a, T const&b){if(b>a) a=b;}

template<bool enabled>
struct Debug{
    template<typename S, typename T = void> struct Tag_Printable : false_type {};
    template<typename S> struct Tag_Printable<S, decltype((void)(cerr << declval<S>()))> : true_type {};
    template<typename S, typename T = void> struct Tag_Iterable: false_type {};
    template<typename S> struct Tag_Iterable<S, decltype((void)(begin(declval<S>()), end(declval<S>())))> : true_type {};

    template<typename T, size_t N> struct Tuple_Printer{
        template<typename S>
        static S& print(S& stream, T const&t){
            return Tuple_Printer<T, N-1>::print(stream, t) << ", " << get<N>(t);
        }
    };
    template<typename T> struct Tuple_Printer<T, 0>{
        template<typename S>
        static S& print(S& stream, T const&t){
            return stream << get<0>(t);
        }
    };

    template<typename T, typename... Args>
    Debug& print(T const&x, true_type, Args...){
        #ifdef LOCAL_RUN
        if(enabled){
            cerr << boolalpha << x;
        }
        #endif // LOCAL_RUN
        return *this;
    }
    template<typename T>
    Debug& print(T const&x, false_type, true_type){
        *this << "[";
        bool first = true;
        for(auto &e:x){
            if(!first) *this << ", ";
            *this << e;
            first = false;
        }
        return *this << "]";
    }
    template<typename S, typename T>
    Debug& print(pair<S, T> const&x, false_type, false_type){
        return *this << "(" << x.first << ", " << x.second << ")";
    }
    template<typename... Args>
    Debug& print(tuple<Args...> const&t, false_type, false_type){
        return Tuple_Printer<decltype(t), sizeof...(Args)-1>::print(*this, t);
    }
    template<typename T>
    Debug& operator<<(T const&x){
        return print(x, Tag_Printable<T>{}, Tag_Iterable<T>{});
    }
};
 Debug<true> debug;
// Debug<false> debug; // disable debug printing
#define named(x) string(#x) << " : " <<  x


int n, a, b, c;
vector<bool> vis;
vector<vector<pair<int, int> > > g;

vector<int> L, R, deco;
vector<int> siz;
int tim;

mt19937 rng(4353215);
int get_rand(int l, int r){
    return uniform_int_distribution<int>(l, r)(rng);
}

int dfs(int u){
    assert(!vis[u]);
    vis[u] = 1;
    siz[u] = 1;
    L[u] = ++tim;
    deco[L[u]] = u;
    int ret = -1;
    for(auto &f:g[u]){
        auto const&e = f.second;
        if(!vis[e]){
            const int tmp = dfs(e);
            if(tmp>=0) ret = tmp;
            siz[u]+=siz[e];
            f.first+=get_rand(0, 100);
        }
    }
    R[u] = tim;
    if(a <= siz[u] && siz[u] <= n-b) ret = u;
    return ret;
}

vector<int> find_split(int n_, int a_, int b_, int c_, vector<int> p, vector<int> q) {
    n=n_;
    array<int, 3> pool{a_, b_, c_};
    array<int, 3> label{1,2,3};
    auto start = clock();
    g.assign(n, decltype(g)::value_type{});
    for(int i=0;i<(int)p.size();++i){
        auto const e = p[i], f = q[i];
        g[e].emplace_back(0, f);
        g[f].emplace_back(0, e);
    }
    for(auto &e:g) shuffle(e.begin(), e.end(), rng);
    while((clock()-start)*1.0/CLOCKS_PER_SEC < 1.8){
        do{
            a = pool[label[0]-1];
            b = pool[label[1]-1];
            c = pool[label[2]-1];
            if(c<a || c<b) continue;

            vis.assign(n, false);
            tim=-1;
            L.resize(n);
            R.resize(n);
            siz.resize(n);
            deco.resize(n);

            int tmp = dfs(get_rand(0, n-1));
            if(tmp == -1){
                continue;
            }
            // reconstruct
            vector<int> ret(n, label[2]);
            const int X = L[tmp], Y = R[tmp];
            for(int i=0;i<a;++i){
                ret[deco[X+i]] = label[0];
            }
            for(int i=0, j=0;i<b;++j){
                if(j<X || j>Y){
                    ret[deco[j]] = label[1];
                    ++i;
                }
            }
            assert(count(ret.begin(), ret.end(), label[0]) == a);
            assert(count(ret.begin(), ret.end(), label[1]) == b);
            assert(count(ret.begin(), ret.end(), label[2]) == c);
            return ret;
        } while(next_permutation(label.begin(), label.end()));
        for(auto &e:g) sort(e.begin(), e.end());
    }
    return vector<int>(n, 0);

}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB ok, correct split
2 Correct 2 ms 376 KB ok, correct split
3 Correct 2 ms 252 KB ok, correct split
4 Correct 2 ms 256 KB ok, correct split
5 Correct 2 ms 376 KB ok, correct split
6 Correct 2 ms 376 KB ok, correct split
7 Correct 126 ms 18576 KB ok, correct split
8 Correct 116 ms 15992 KB ok, correct split
9 Correct 124 ms 14456 KB ok, correct split
10 Correct 159 ms 18680 KB ok, correct split
11 Correct 116 ms 18808 KB ok, correct split
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB ok, correct split
2 Correct 2 ms 376 KB ok, correct split
3 Correct 2 ms 256 KB ok, correct split
4 Correct 154 ms 16120 KB ok, correct split
5 Correct 103 ms 9976 KB ok, correct split
6 Correct 116 ms 18704 KB ok, correct split
7 Correct 112 ms 18680 KB ok, correct split
8 Correct 172 ms 13560 KB ok, correct split
9 Correct 105 ms 9592 KB ok, correct split
10 Correct 89 ms 10220 KB ok, correct split
11 Correct 89 ms 10228 KB ok, correct split
12 Correct 96 ms 10168 KB ok, correct split
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB ok, correct split
2 Correct 129 ms 10004 KB ok, correct split
3 Correct 35 ms 4216 KB ok, correct split
4 Correct 2 ms 256 KB ok, correct split
5 Correct 146 ms 12792 KB ok, correct split
6 Correct 110 ms 13560 KB ok, correct split
7 Correct 109 ms 13688 KB ok, correct split
8 Correct 112 ms 13252 KB ok, correct split
9 Correct 102 ms 12664 KB ok, correct split
10 Correct 1834 ms 3596 KB ok, no valid answer
11 Correct 1832 ms 5212 KB ok, no valid answer
12 Correct 1858 ms 10224 KB ok, no valid answer
13 Correct 1915 ms 10100 KB ok, no valid answer
14 Correct 1853 ms 10092 KB ok, no valid answer
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB ok, correct split
2 Correct 1802 ms 376 KB ok, no valid answer
3 Correct 2 ms 376 KB ok, correct split
4 Correct 2 ms 376 KB ok, correct split
5 Correct 2 ms 376 KB ok, correct split
6 Correct 2 ms 376 KB ok, correct split
7 Correct 2 ms 424 KB ok, correct split
8 Correct 2 ms 376 KB ok, correct split
9 Correct 6 ms 888 KB ok, correct split
10 Correct 5 ms 632 KB ok, correct split
11 Correct 2 ms 376 KB ok, correct split
12 Correct 5 ms 632 KB ok, correct split
13 Correct 2 ms 376 KB ok, correct split
14 Correct 2 ms 256 KB ok, correct split
15 Correct 11 ms 376 KB ok, correct split
16 Correct 2 ms 376 KB ok, correct split
17 Correct 3 ms 376 KB ok, correct split
18 Correct 2 ms 256 KB ok, correct split
19 Correct 2 ms 380 KB ok, correct split
20 Correct 3 ms 504 KB ok, correct split
21 Correct 4 ms 632 KB ok, correct split
22 Correct 4 ms 632 KB ok, correct split
23 Correct 4 ms 632 KB ok, correct split
24 Correct 4 ms 560 KB ok, correct split
25 Correct 4 ms 632 KB ok, correct split
26 Incorrect 1804 ms 632 KB jury found a solution, contestant did not
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB ok, correct split
2 Correct 2 ms 376 KB ok, correct split
3 Correct 2 ms 252 KB ok, correct split
4 Correct 2 ms 256 KB ok, correct split
5 Correct 2 ms 376 KB ok, correct split
6 Correct 2 ms 376 KB ok, correct split
7 Correct 126 ms 18576 KB ok, correct split
8 Correct 116 ms 15992 KB ok, correct split
9 Correct 124 ms 14456 KB ok, correct split
10 Correct 159 ms 18680 KB ok, correct split
11 Correct 116 ms 18808 KB ok, correct split
12 Correct 2 ms 256 KB ok, correct split
13 Correct 2 ms 376 KB ok, correct split
14 Correct 2 ms 256 KB ok, correct split
15 Correct 154 ms 16120 KB ok, correct split
16 Correct 103 ms 9976 KB ok, correct split
17 Correct 116 ms 18704 KB ok, correct split
18 Correct 112 ms 18680 KB ok, correct split
19 Correct 172 ms 13560 KB ok, correct split
20 Correct 105 ms 9592 KB ok, correct split
21 Correct 89 ms 10220 KB ok, correct split
22 Correct 89 ms 10228 KB ok, correct split
23 Correct 96 ms 10168 KB ok, correct split
24 Correct 2 ms 256 KB ok, correct split
25 Correct 129 ms 10004 KB ok, correct split
26 Correct 35 ms 4216 KB ok, correct split
27 Correct 2 ms 256 KB ok, correct split
28 Correct 146 ms 12792 KB ok, correct split
29 Correct 110 ms 13560 KB ok, correct split
30 Correct 109 ms 13688 KB ok, correct split
31 Correct 112 ms 13252 KB ok, correct split
32 Correct 102 ms 12664 KB ok, correct split
33 Correct 1834 ms 3596 KB ok, no valid answer
34 Correct 1832 ms 5212 KB ok, no valid answer
35 Correct 1858 ms 10224 KB ok, no valid answer
36 Correct 1915 ms 10100 KB ok, no valid answer
37 Correct 1853 ms 10092 KB ok, no valid answer
38 Correct 2 ms 256 KB ok, correct split
39 Correct 1802 ms 376 KB ok, no valid answer
40 Correct 2 ms 376 KB ok, correct split
41 Correct 2 ms 376 KB ok, correct split
42 Correct 2 ms 376 KB ok, correct split
43 Correct 2 ms 376 KB ok, correct split
44 Correct 2 ms 424 KB ok, correct split
45 Correct 2 ms 376 KB ok, correct split
46 Correct 6 ms 888 KB ok, correct split
47 Correct 5 ms 632 KB ok, correct split
48 Correct 2 ms 376 KB ok, correct split
49 Correct 5 ms 632 KB ok, correct split
50 Correct 2 ms 376 KB ok, correct split
51 Correct 2 ms 256 KB ok, correct split
52 Correct 11 ms 376 KB ok, correct split
53 Correct 2 ms 376 KB ok, correct split
54 Correct 3 ms 376 KB ok, correct split
55 Correct 2 ms 256 KB ok, correct split
56 Correct 2 ms 380 KB ok, correct split
57 Correct 3 ms 504 KB ok, correct split
58 Correct 4 ms 632 KB ok, correct split
59 Correct 4 ms 632 KB ok, correct split
60 Correct 4 ms 632 KB ok, correct split
61 Correct 4 ms 560 KB ok, correct split
62 Correct 4 ms 632 KB ok, correct split
63 Incorrect 1804 ms 632 KB jury found a solution, contestant did not
64 Halted 0 ms 0 KB -