Submission #108020

# Submission time Handle Problem Language Result Execution time Memory
108020 2019-04-26T22:25:18 Z tri Mechanical Doll (IOI18_doll) C++14
2 / 100
99 ms 14708 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef pair<int, vi> ivi;

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

namespace debug {
    const int DEBUG = false;

    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"); }

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

using namespace debug;

void answer(vi C, vi X, vi Y);

vi cAns;
vi xAns;
vi yAns;

int nS = 1;

ivi construct(int i) {
    if (i == 2) {
        ivi ret = {nS, {nS, -nS}};
        nS++;
        ps("vS1:", i, ret.s.size());
        return ret;
    } else if (i == 3) {
        ps(nS + 1, -nS);
        xAns[nS] = -(nS + 1);
        yAns[nS] = -(nS + 2);
        yAns[nS + 1] = -nS;
        ivi ret = {nS, {nS + 1, nS + 2, -(nS + 2)}};
        nS += 3;
        ps("vS2:", i, ret.s.size());
        return ret;
    }

    if (i & 1) {
        int n = (i + 1) / 2;
        ivi a = construct(n);
        ivi b = construct(n);

        xAns[nS] = -a.f;
        yAns[nS] = -b.f;

        int aLast = a.second[a.second.size() - 1];

        ps(aLast, nS);

        if (aLast >= 0) {
            xAns[aLast] = -nS;
        } else {
            yAns[-aLast] = -nS;
        }

        vi ret;
        for (int i = 0; i < n - 1; i++) {
            ret.pb(a.s[i]);
            ret.pb(b.s[i]);
        }
        ret.pb(b.s[n - 1]);

        ps("vS:", i, ret.size());
        return {nS++, ret};
    } else {
        int n = i / 2;
        ivi a = construct(n);
        ivi b = construct(n);

        xAns[nS] = -a.f;
        yAns[nS] = -b.f;

        vi ret;
        for (int j = 0; j < n; j++) {
            ret.pb(a.s[j]);
            ret.pb(b.s[j]);
        }

        return {nS++, ret};
    }
}

void create_circuit(int M, vi ord) {
    ps("acc");
    int N = ord.size();
    cAns.resize(M + 1);
    xAns.resize(2 * N + 1);
    yAns.resize(2 * N + 1);

    vi cnt(M + 1);

    for (int i = 0; i < N; i++) {
        cnt[ord[i]]++;
    }

    vector<vi> out(M);
    vi used(M);

    for (int i = 1; i <= M; i++) {
        if (cnt[i] > 1) {
            ivi inf = construct(cnt[i]);
            ps("inf:", i, inf);
            cAns[i] = -inf.f;
            out[i] = inf.s;
        }
    }

    ps("cnt[1]:", cnt[1]);
    ps("out:", out);
    ps("used:", used);

    ps(xAns);
    ps(yAns);

    cAns[0] = ord[0];
    for (int i = 0; i + 1 < N; i++) {
        int cV = ord[i];
        int nV = ord[i + 1];

        if (cnt[cV] == 1) {
            cAns[cV] = nV;
        } else {
            int link = out[cV][used[cV]++];
            ps("con", i, nV, link);
            if (link >= 0) {
                xAns[link] = nV;
            } else {
                yAns[-link] = nV;
            }
        }
    }

    int cV = ord[N - 1];
    int nV = 0;
    if (cnt[cV] == 1) {
        cAns[cV] = nV;
    } else {
        int link = out[cV][used[cV]++];
        if (link >= 0) {
            xAns[link] = nV;
        } else {
            yAns[-link] = nV;
        }
    }

    ps(xAns);
    ps(yAns);

    vi nX(xAns.begin() + 1, xAns.begin() + nS);
    vi nY(yAns.begin() + 1, yAns.begin() + nS);

    ps(nX);
    ps(nY);
    ps(cAns);
    answer(cAns, nX, nY);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 27 ms 6092 KB Output is correct
3 Correct 19 ms 4684 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 13 ms 4556 KB Output is correct
6 Correct 27 ms 6860 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 27 ms 6092 KB Output is correct
3 Correct 19 ms 4684 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 13 ms 4556 KB Output is correct
6 Correct 27 ms 6860 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 58 ms 9796 KB Output is correct
9 Correct 60 ms 9992 KB Output is correct
10 Correct 99 ms 14708 KB Output is correct
11 Runtime error 2 ms 332 KB Execution killed with signal 6
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 27 ms 6092 KB Output is correct
3 Correct 19 ms 4684 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 13 ms 4556 KB Output is correct
6 Correct 27 ms 6860 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 58 ms 9796 KB Output is correct
9 Correct 60 ms 9992 KB Output is correct
10 Correct 99 ms 14708 KB Output is correct
11 Runtime error 2 ms 332 KB Execution killed with signal 6
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -