This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
// you may find the definitions useful
const int OP_ZERO = 0;     // f(OP_ZERO,    x0, x1) = 0
const int OP_NOR = 1;      // f(OP_NOR,     x0, x1) = !(x0 || x1)
const int OP_GREATER = 2;  // f(OP_GREATER, x0, x1) = (x0 > x1)
const int OP_NOT_X1 = 3;   // f(OP_NOT_X1,  x0, x1) = !x1
const int OP_LESS = 4;     // f(OP_LESS,    x0, x1) = (x0 < x1)
const int OP_NOT_X0 = 5;   // f(OP_NOT_X0,  x0, x1) = !x0
const int OP_XOR = 6;      // f(OP_XOR,     x0, x1) = (x0 ^ x1)
const int OP_NAND = 7;     // f(OP_NAND,    x0, x1) = !(x0 && x1)
const int OP_AND = 8;      // f(OP_AND,     x0, x1) = (x0 && x1)
const int OP_EQUAL = 9;    // f(OP_EQUAL,   x0, x1) = (x0 == x1)
const int OP_X0 = 10;      // f(OP_X0,      x0, x1) = x0
const int OP_GEQ = 11;     // f(OP_GEQ,     x0, x1) = (x0 >= x1)
const int OP_X1 = 12;      // f(OP_X1,      x0, x1) = x1
const int OP_LEQ = 13;     // f(OP_LEQ,     x0, x1) = (x0 <= x1)
const int OP_OR = 14;      // f(OP_OR,      x0, x1) = (x0 || x1)
const int OP_ONE = 15;     // f(OP_ONE,     x0, x1) = 1
int alice(const int n, const char names[][5],
          const unsigned short numbers[], bool outputs_alice[]) {
    vector<string> name(n);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 5; ++j) {
            if (names[i][j] < 'a' || names[i][j] > 'z') {
                break;
            }
            name[i] += names[i][j];
        }
    }
    sort(name.begin(), name.end());
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 16; ++j) {
            outputs_alice[i * 21 + j] = (numbers[i] & (1 << j));
        }
        string nw = "";
        for (int j = 0; j < 5; ++j) {
            if (names[i][j] < 'a' || names[i][j] > 'z') {
                break;
            }
            nw += names[i][j];
        }
        int pos = lower_bound(name.begin(), name.end(), nw) - name.begin();
        for (int j = 0; j < 5; ++j) {
            outputs_alice[i * 21 + 16 + j] = (pos & (1 << j));
        }
    }
    return n * 21;
}
int bob(const int m, const char senders[][5],
        const char recipients[][5], bool outputs_bob[]) {
    vector<string> name(m * 2);
    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < 5; ++j) {
            if (senders[i][j] < 'a' || senders[i][j] > 'z') {
                break;
            }
            name[i * 2] += senders[i][j];
        }
        for (int j = 0; j < 5; ++j) {
            if (recipients[i][j] < 'a' || recipients[i][j] > 'z') {
                break;
            }
            name[i * 2 + 1] += recipients[i][j];
        }
    }
    sort(name.begin(), name.end());
    name.resize(unique(name.begin(), name.end()) - name.begin());
    for (int i = 0; i < m; ++i) {
        string nw = "";
        for (int j = 0; j < 5; ++j) {
            if (senders[i][j] < 'a' || senders[i][j] > 'z') {
                break;
            }
            nw += senders[i][j];
        }
        int pos = lower_bound(name.begin(), name.end(), nw) - name.begin();
        for (int j = 0; j < 5; ++j) {
            outputs_bob[i * 10 + j] = (pos & (1 << j));
        }
        nw = "";
        for (int j = 0; j < 5; ++j) {
            if (recipients[i][j] < 'a' || recipients[i][j] > 'z') {
                break;
            }
            nw += recipients[i][j];
        }
        pos = lower_bound(name.begin(), name.end(), nw) - name.begin();
        for (int j = 0; j < 5; ++j) {
            outputs_bob[i * 10 + 5 + j] = (pos & (1 << j));
        }
    }
    return m * 10;
}
int circuit(const int la, const int lb, int operations[],
            int operands[][2], int outputs_circuit[][16]) {
    int cnt = la + lb;
    auto f = [&](int tp, int x1, int x2) {
        operations[cnt] = tp;
        operands[cnt][0] = x1;
        operands[cnt][1] = x2;
        return cnt++;
    };
    auto get_sum = [&](array<int, 16> a, array<int, 16> b) {
        array<int, 16> ans;
        int trans = f(OP_ZERO, 0, 0);
        for (int i = 0; i < 16; ++i) {
            int trans_nw = f(OP_AND, a[i], b[i]);
            ans[i] = f(OP_XOR, a[i], b[i]);
            trans_nw = f(OP_OR, trans_nw, f(OP_AND, ans[i], trans));
            ans[i] = f(OP_XOR, ans[i], trans);
            trans = trans_nw;
        }
        return ans;
    };
    int n = la / 21, m = lb / 10;
    vector<array<int, 16>> ans(n), a(n);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 16; ++j) {
            ans[i][j] = f(OP_ZERO, 0, 0);
            a[i][j] = i * 21 + j;
        }
    }
    vector<vector<int>> used(n, vector<int>(n, f(OP_ZERO, 0, 0)));
    for (int i = 0; i < m; ++i) {
        for (int s = 0; s < n; ++s) {
            int s_eq = f(OP_ONE, 0, 0);
            for (int j = 0; j < 5; ++j) {
                s_eq = f(OP_AND, s_eq, f(OP_EQUAL, s * 21 + 16 + j, la + i * 10 + j));
            }
            for (int r = 0; r < n; ++r) {
                int r_eq = f(OP_ONE, 0, 0);
                for (int j = 0; j < 5; ++j) {
                    r_eq = f(OP_AND, r_eq, f(OP_EQUAL, r * 21 + 16 + j, la + i * 10 + 5 + j));
                }
                int need = f(OP_AND, s_eq, r_eq);
                used[s][r] = f(OP_OR, used[s][r], need);
            }
        }
    }
    for (int s = 0; s < n; ++s) {
        for (int r = 0; r < n; ++r) {
            array<int, 16> add;
            for (int j = 0; j < 16; ++j) {
                add[j] = f(OP_AND, a[s][j], used[s][r]);
            }
            ans[r] = get_sum(ans[r], add);
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 16; ++j) {
            outputs_circuit[i][j] = ans[i][j];
        }
    }
    return cnt;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |