Submission #213467

# Submission time Handle Problem Language Result Execution time Memory
213467 2020-03-25T22:42:07 Z tri Broken Device (JOI17_broken_device) C++14
0 / 100
2000 ms 9336 KB
#include <bits/stdc++.h>
#include "Annalib.h"

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;

#define pb push_back
#define f first
#define s second

int N;

const int MAXN = 155;
const int MAXV = 1 << 20;

int data[MAXN];

mt19937 re(1377);
uniform_int_distribution<int> uniform_dist(0, MAXV);

int group[MAXN];
vi mem[3];

int broken[MAXN];

int pos[MAXV];

int output[MAXN];

void init() {
    for (int i = 0; i < N; i++) {
        data[i] = uniform_dist(re);
    }

    fill(group, group + N / 3, 0);
    fill(group + N / 3, group + 2 * N / 3, 1);
    fill(group + 2 * N / 3, group + N, 2);

    shuffle(group, group + N, re);

    for (int i = 0; i < 3; i++) {
        mem[i].clear();
    }

    for (int i = 0; i < N; i++) {
        if (!broken[i]) {
            mem[group[i]].pb(i);
        }
    }
}

// assert 20 bit frag
void calc(int group, int frag) {
    memset(pos, 0, sizeof(pos));

    vi &cMem = mem[group];
    assert(cMem.size() >= 20);

    if (cMem.size() >= 30) {
        cMem.erase(cMem.end() - (cMem.size() - 30), cMem.end());
    }

    int hSize = cMem.size() / 2;

//    cout << hSize << endl;

    for (int bSet = 0; bSet < (1 << hSize); bSet++) {
        int partial = 0;
        for (int j = 0; j < hSize; j++) {
            if (bSet & (1 << j)) {
                partial ^= data[cMem[j]];
            }
        }
        pos[partial] = bSet;
    }

    int rem = cMem.size() - hSize;

    for (int bSet = 0; bSet < (1 << rem); bSet++) {
        int partial = 0;
        for (int j = 0; j < rem; j++) {
            if (bSet & (1 << j)) {
                partial ^= data[cMem[hSize + j]];
            }
        }

        int desire = frag ^partial;
        if (pos[desire]) {
            int fSet = pos[desire];

            for (int j = 0; j < hSize; j++) {
                if (fSet & (1 << j)) {
                    output[cMem[j]] = 1;
                }
            }

            for (int j = 0; j < rem; j++) {
                if (bSet & (1 << j)) {
                    output[cMem[hSize + j]] = 1;
                }
            }

            return;
        }
    }

    assert(false);
}


void Anna(int iN, ll X, int K, int P[]) {
    N = iN;
    assert(N == 150);

    fill(broken, broken + N, 0);
    for (int i = 0; i < K; i++) {
        broken[P[i]] = true;
    }

//    cout << "read" << endl;

    init();

//    cout << "init" << endl;

    memset(output, 0, sizeof(output));

    for (int g = 0; g < 3; g++) {
        int frag = X & ((1 << 20) - 1);
        calc(g, frag);

        X >>= 20;
    }

    for (int i = 0; i < N; i++) {
        Set(i, output[i]);
    }

//    cout << "done" << endl;
//    ps(mem[0]);
}
#include <bits/stdc++.h>
#include "Brunolib.h"

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;

#define pb push_back
#define f first
#define s second

namespace debug {
    const int DEBUG = true;

    template<class T1, class T2>
    void pr(const pair<T1, T2> &x);

    template<class T, size_t SZ>
    void pr(const array<T, SZ> &x);

    template<class T>
    void pr(const vector<T> &x);

    template<class T>
    void pr(const set<T> &x);

    template<class T1, class T2>
    void pr(const map<T1, T2> &x);

    template<class T>
    void pr(const T &x) { if (DEBUG) cout << x; }

    template<class T, class... Ts>
    void pr(const T &first, const Ts &... rest) { pr(first), pr(rest...); }

    template<class T1, class T2>
    void pr(const pair<T1, T2> &x) { pr("{", x.f, ", ", x.s, "}"); }

    template<class T>
    void prIn(const T &x) {
        pr("{");
        bool fst = 1;
        for (auto &a : x) {
            pr(fst ? "" : ", ", a), fst = 0;
        }
        pr("}");
    }

    template<class T, size_t SZ>
    void pr(const array<T, SZ> &x) { prIn(x); }

    template<class T>
    void pr(const vector<T> &x) { prIn(x); }

    template<class T>
    void pr(const set<T> &x) { prIn(x); }

    template<class T1, class T2>
    void pr(const map<T1, T2> &x) { prIn(x); }

    void ps() { pr("\n"), cout << flush; }

    template<class Arg, class... Args>
    void ps(const Arg &first, const Args &... rest) {
        pr(first, " ");
        ps(rest...);
    }
}
using namespace debug;


namespace rdup {

    int N;

    const int MAXN = 155;
    const int MAXV = 1 << 20;

    int data[MAXN];

    mt19937 re(1377);
    uniform_int_distribution<int> uniform_dist(0, MAXV);

    int group[MAXN];
    vi mem[3];

    int broken[MAXN];

    void init() {
        for (int i = 0; i < N; i++) {
            data[i] = uniform_dist(re);
        }

        fill(group, group + N / 3, 0);
        fill(group + N / 3, group + 2 * N / 3, 1);
        fill(group + 2 * N / 3, group + N, 2);

        shuffle(group, group + N, re);

        for (int i = 0; i < 3; i++) {
            mem[i].clear();
        }

        for (int i = 0; i < N; i++) {
            if (!broken[i]) {
                mem[group[i]].pb(i);
            }
        }
    }
}

ll Bruno(int iN, int A[]) {
    rdup::N = iN;
    assert(rdup::N == 150);

    fill(rdup::broken, rdup::broken + rdup::N, 0);

    rdup::init();

//    ps(rdup::mem[0]);

    ll ans = 0;
    for (int group = 2; group >= 0; group--) {
        ans <<= 20;
        ll frag = 0;
        for (int i : rdup::mem[group]) {
            if (A[i]) {
                frag ^= rdup::data[i];
            }
        }
        ans |= frag;
    }
//    cout << ans << endl;
    return ans;
}
# Verdict Execution time Memory Grader output
1 Runtime error 1485 ms 9208 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Execution timed out 2099 ms 4728 KB Time limit exceeded
3 Execution timed out 2099 ms 4740 KB Time limit exceeded
4 Execution timed out 2099 ms 4728 KB Time limit exceeded
5 Execution timed out 2099 ms 4728 KB Time limit exceeded
6 Execution timed out 2099 ms 4728 KB Time limit exceeded
7 Runtime error 523 ms 8952 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Execution timed out 2099 ms 4728 KB Time limit exceeded
9 Execution timed out 2099 ms 4728 KB Time limit exceeded
10 Execution timed out 2099 ms 4728 KB Time limit exceeded
11 Execution timed out 2100 ms 4728 KB Time limit exceeded
12 Runtime error 552 ms 8952 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Execution timed out 2099 ms 4600 KB Time limit exceeded
14 Execution timed out 2098 ms 4728 KB Time limit exceeded
15 Runtime error 70 ms 8824 KB Execution killed with signal 11 (could be triggered by violating memory limits)
16 Runtime error 667 ms 8952 KB Execution killed with signal 11 (could be triggered by violating memory limits)
17 Execution timed out 2099 ms 4728 KB Time limit exceeded
18 Runtime error 364 ms 8952 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Runtime error 1264 ms 9208 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Runtime error 2059 ms 9336 KB Execution killed with signal 11 (could be triggered by violating memory limits)
21 Execution timed out 2099 ms 4728 KB Time limit exceeded
22 Execution timed out 2099 ms 4728 KB Time limit exceeded
23 Execution timed out 2099 ms 4728 KB Time limit exceeded
24 Runtime error 275 ms 8952 KB Execution killed with signal 11 (could be triggered by violating memory limits)
25 Execution timed out 2099 ms 4728 KB Time limit exceeded
26 Execution timed out 2098 ms 4828 KB Time limit exceeded
27 Execution timed out 2099 ms 4856 KB Time limit exceeded
28 Execution timed out 2099 ms 4728 KB Time limit exceeded
29 Execution timed out 2099 ms 4728 KB Time limit exceeded
30 Execution timed out 2099 ms 4600 KB Time limit exceeded
31 Execution timed out 2098 ms 4728 KB Time limit exceeded
32 Execution timed out 2099 ms 4728 KB Time limit exceeded
33 Runtime error 524 ms 8952 KB Execution killed with signal 11 (could be triggered by violating memory limits)
34 Execution timed out 2099 ms 4728 KB Time limit exceeded
35 Runtime error 946 ms 9080 KB Execution killed with signal 11 (could be triggered by violating memory limits)
36 Execution timed out 2099 ms 4728 KB Time limit exceeded
37 Execution timed out 2099 ms 4728 KB Time limit exceeded
38 Execution timed out 2099 ms 4728 KB Time limit exceeded
39 Runtime error 520 ms 8952 KB Execution killed with signal 11 (could be triggered by violating memory limits)
40 Runtime error 1653 ms 9208 KB Execution killed with signal 11 (could be triggered by violating memory limits)