Submission #1013667

# Submission time Handle Problem Language Result Execution time Memory
1013667 2024-07-03T19:10:18 Z c2zi6 Mechanical Doll (IOI18_doll) C++14
62 / 100
67 ms 17492 KB
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "doll.h"

namespace TEST5 {
    void solve(int M, VI A) {
        int N = A.size();
        VI C;
        VI X;
        VI Y;
        if (A.size() == 1) {
            C.pb(1);
            C.pb(0);
            answer(C, X, Y);
            return;
        }
        C.pb(1);
        C.pb(-1);
        int s = 0;
        while ((1<<s) < N) s++;
        replr(i, 2, s+1) {
            X.pb(-1);
            Y.pb(-i);
        }
        Y.back() = 0;
        int n = N-1;
        rep(i, s) {
            if (n & (1<<i)) {
                X[s-1-i] = 1;
            }
        }
        answer(C, X, Y);
    }
};
namespace TEST3 {
    void solve(int M, VI A) {
        VI C, X, Y;
        C = VI(M+1);
        VI cnt(M+1);
        for (int x : A) cnt[x]++;
        VI sw(M+1, -1);
        VI turn(M+1);
        auto trans = [&](int x) {
            return -(x+1);
        };
        int u = 0;
        for (int v : A) {
            if (cnt[u] == 4) {
                if (turn[u] == 0) {
                    sw[u] = X.size();
                    C[u] = trans(sw[u]);
                    X.pb(0), Y.pb(0);
                    X.pb(0), Y.pb(0);
                    X.pb(0), Y.pb(0);
                    X[sw[u]] = trans(sw[u]+1);
                    Y[sw[u]] = trans(sw[u]+2);
                }
                if (turn[u] == 0) {
                    X[sw[u]+1] = v;
                } else if (turn[u] == 1) {
                    X[sw[u]+2] = v;
                } else if (turn[u] == 2) {
                    Y[sw[u]+1] = v;
                } else if (turn[u] == 3) {
                    Y[sw[u]+2] = v;
                }
            } else if (cnt[u] == 3) {
                if (turn[u] == 0) {
                    sw[u] = X.size();
                    C[u] = trans(sw[u]);
                    X.pb(0), Y.pb(0);
                    X.pb(0), Y.pb(0);
                    X.pb(0), Y.pb(0);
                    X[sw[u]] = trans(sw[u]+1);
                    Y[sw[u]] = trans(sw[u]+2);
                    X[sw[u]+1] = trans(sw[u]);
                }
                if (turn[u] == 0) {
                    X[sw[u]+2] = v;
                } else if (turn[u] == 1) {
                    Y[sw[u]+1] = v;
                } else if (turn[u] == 2) {
                    Y[sw[u]+2] = v;
                }
            } else if (cnt[u] == 2) {
                if (turn[u] == 0) {
                    sw[u] = X.size();
                    C[u] = trans(sw[u]);
                    X.pb(0), Y.pb(0);
                }
                if (turn[u] == 0) {
                    X[sw[u]] = v;
                } else if (turn[u] == 1) {
                    Y[sw[u]] = v;
                }
            } else {
                C[u] = v;
            }
            turn[u]++;
            u = v;
        }
        answer(C, X, Y);
    }
};
namespace TEST6 {
    typedef VI::iterator VIT;
    void solve(int M, VI A) {
        VI C, X, Y;
        X.reserve(2*A.size());
        Y.reserve(2*A.size());
        C = VI(M+1);
        
        VI cnt(M+1);
        for (int x : A) cnt[x]++;
        VI lwb(A.size()+1);
        replr(i, 0, A.size()) {
            int x = 0;
            while ((1<<x) < i) x++;
            lwb[i] = x;
        }

        VI sw(M+1, -1);
        vector<vector<VIT>> order(M+1);
        auto trans = [&](int x) {
            return -(x+1);
        };
        auto flip = [&](int x, int s) {
            rep(i, s/2) {
                int ch = bool(x&(1<<i))^bool(x&(1<<(s-1-i)));
                x ^= (ch<<i);
                x ^= (ch<<(s-1-i));
            }
            return x;
        };
        auto print = [&](VIT it) {
            if (X.begin() <= it && it < X.end()) {
                cout << "X[" << it-X.begin() << "]";
            } else {
                cout << "Y[" << it-Y.begin() << "]";
            }
        };
        VI turn(M+1);
        int u = 0;
        for (int v : A) {
            if (cnt[u] > 1) {
                int sz = lwb[cnt[u]];
                if (sw[u] == -1) {
                    sw[u] = X.size();
                    C[u] = trans(sw[u]);
                    int l = (1<<(sz-1))-1;
                    int r = (1<<sz)-2;
                    replr(i, 0, r) {
                        X.pb(0), Y.pb(0);
                    }
                    replr(i, 0, l-1) {
                        X[sw[u]+i] = trans(sw[u] + 2*i+1);
                        Y[sw[u]+i] = trans(sw[u] + 2*i+2);
                    }
                    order[u] = vector<VIT>(1<<sz);
                    replr(i, l, r) {
                        order[u][flip(i*2+1-(r+1), sz)] = X.begin() + sw[u]+i;
                        order[u][flip(i*2+2-(r+1), sz)] = Y.begin() + sw[u]+i;
                    }
                    rep(i, (1<<sz)-cnt[u]) {
                        *(order[u][i]) = trans(sw[u]);
                    }
                    turn[u] = (1<<sz)-cnt[u];
                }
                *(order[u][turn[u]++]) = v;
            } else {
                C[u] = v;
            }
            u = v;
        }
        /*rep(u, C.size()) cout << u << ": " << C[u] << endl;*/
        /*rep(u, X.size()) cout << trans(u) << ": " << X[u] << ", " << Y[u] << endl;*/
        answer(C, X, Y);
    }
};

void create_circuit(int M, VI A) {
    if (M == 1) TEST5::solve(M, A);
    else TEST6::solve(M, A);
}

Compilation message

doll.cpp: In function 'void TEST6::solve(int, VI)':
doll.cpp:164:14: warning: variable 'print' set but not used [-Wunused-but-set-variable]
  164 |         auto print = [&](VIT it) {
      |              ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 14 ms 6624 KB Output is correct
3 Correct 10 ms 4956 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 6 ms 4956 KB Output is correct
6 Correct 15 ms 7260 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 14 ms 6624 KB Output is correct
3 Correct 10 ms 4956 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 6 ms 4956 KB Output is correct
6 Correct 15 ms 7260 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 31 ms 10076 KB Output is correct
9 Correct 35 ms 10328 KB Output is correct
10 Correct 48 ms 15192 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 14 ms 6624 KB Output is correct
3 Correct 10 ms 4956 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 6 ms 4956 KB Output is correct
6 Correct 15 ms 7260 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 31 ms 10076 KB Output is correct
9 Correct 35 ms 10328 KB Output is correct
10 Correct 48 ms 15192 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 51 ms 15952 KB Output is correct
15 Correct 29 ms 8796 KB Output is correct
16 Correct 43 ms 13144 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 376 KB Output is correct
20 Correct 47 ms 14940 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 9 ms 2864 KB Output is correct
3 Correct 9 ms 2860 KB Output is correct
4 Correct 17 ms 4180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 9 ms 2864 KB Output is correct
3 Correct 9 ms 2860 KB Output is correct
4 Correct 17 ms 4180 KB Output is correct
5 Partially correct 56 ms 16476 KB Output is partially correct
6 Partially correct 63 ms 16980 KB Output is partially correct
7 Partially correct 66 ms 16724 KB Output is partially correct
8 Partially correct 67 ms 17240 KB Output is partially correct
9 Partially correct 36 ms 11612 KB Output is partially correct
10 Partially correct 61 ms 17236 KB Output is partially correct
11 Partially correct 53 ms 17492 KB Output is partially correct
12 Partially correct 35 ms 11612 KB Output is partially correct
13 Partially correct 37 ms 11088 KB Output is partially correct
14 Partially correct 35 ms 11092 KB Output is partially correct
15 Partially correct 35 ms 10840 KB Output is partially correct
16 Partially correct 1 ms 600 KB Output is partially correct
17 Partially correct 34 ms 9648 KB Output is partially correct
18 Partially correct 31 ms 9560 KB Output is partially correct
19 Partially correct 33 ms 10548 KB Output is partially correct
20 Partially correct 49 ms 13572 KB Output is partially correct
21 Partially correct 60 ms 15704 KB Output is partially correct
22 Partially correct 43 ms 12888 KB Output is partially correct