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 "abc.h"
#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
vector<tuple<int, int, int>> &
operator+=(vector<tuple<int, int, int>> &x,
const vector<tuple<int, int, int>> &y) {
for (auto p : y)
x.push_back(p);
return x;
}
vector<tuple<int, int, int>> adder(int i1, int i2, int offs) {
// 16-bit-adder from i1..i1+15 and i2..i2+15
vector<tuple<int, int, int>> ret;
ret.push_back({OP_AND, i1, i2}); // offs
ret.push_back({OP_XOR, i1, i2}); // offs+1
for (int j = 1; j < 16; j++) {
int c = offs + 2 + 8 * (j - 1);
int carry = j == 1 ? offs : c - 1;
ret.push_back({OP_XOR, i1 + j, i2 + j}); // c
ret.push_back({OP_XOR, carry, c}); // c+1
ret.push_back({OP_OR, i1 + j, i2 + j}); // c+2
ret.push_back({OP_NOR, carry, c + 2}); // c+3
ret.push_back({OP_AND, i1 + j, i2 + j}); // c+4
ret.push_back({OP_AND, carry, c + 4}); // c+5
ret.push_back({OP_NOR, c + 1, c + 3}); // c+6
ret.push_back({OP_OR, c + 5, c + 6}); // c+7
// (c+1, c+7): (output, carry)
}
ret.push_back({OP_OR, offs + 1, offs + 1});
for (int j = 1; j < 16; j++) {
ret.push_back({OP_OR, offs + 3 + 8 * (j - 1), offs + 3 + 8 * (j - 1)});
}
return ret; // the last 16 bits is the result
}
vector<tuple<int, int, int>> multiplier(int i1, int i2, int offs) {
vector<tuple<int, int, int>> ret;
int last = i2;
for (int j = 1; j < 16; j++) {
ret += adder(last, last, offs + 138 * (j - 1));
last = offs + 138 * j - 16;
}
// i2, offs + 138*j - 16
int start = offs + 138 * 15;
for (int k = 0; k < 16; k++)
ret.push_back({OP_AND, i1, i2 + k});
for (int j = 1; j < 16; j++)
for (int k = 0; k < 16; k++)
ret.push_back({OP_AND, i1 + j, offs + 138 * j - 16 + k});
int stop = start + 256;
ret += adder(start, start + 16, stop);
for (int j = 2; j < 16; j++) {
ret += adder(stop + 138 * (j - 1) - 16, start + 16 * j,
stop + 138 * (j - 1));
}
// result: offs + 138*15 + 256 + 138*15 - 16
return ret; // the last 16 bits is the result
}
// Alice
int // returns la
alice(
/* in */ const int n,
/* in */ const char names[][5],
/* in */ const unsigned short numbers[],
/* out */ bool outputs_alice[]) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < 16; j++) {
outputs_alice[16 * i + j] = (numbers[i] & (1 << j)) ? 1 : 0;
}
}
return 16 * n;
}
// Bob
int // returns lb
bob(
/* in */ const int m,
/* in */ const char senders[][5],
/* in */ const char recipients[][5],
/* out */ bool outputs_bob[]) {
for (int i = 0; i < m; i++) {
outputs_bob[(senders[i][0] - 'a') * 26 + (recipients[i][0] - 'a')] = 1;
}
return 676;
}
// Circuit
int // returns l
circuit(
/* in */ const int la,
/* in */ const int lb,
/* out */ int operations[],
/* out */ int operands[][2],
/* out */ int outputs_circuit[][16]) {
int offs = la + lb;
for (int j = 0; j < la / 16; j++) {
for (int i = 0; i < la / 16; i++) {
for (int k = 0; k < 16; k++) {
operations[offs] = OP_AND;
operands[offs][0] = la + 26 * i + j;
operands[offs][1] = 16 * i + k;
offs++;
}
}
int pivot = offs - 16;
for (int i = 1; i < la / 16; i++) {
auto ret = adder(pivot - i * 16, offs - 16, offs);
for (int j = 0; j < 138; j++) {
operations[offs + j] = get<0>(ret[j]);
operands[offs + j][0] = get<1>(ret[j]);
operands[offs + j][1] = get<2>(ret[j]);
}
offs += 138;
}
for (int k = 0; k < 16; k++)
outputs_circuit[j][k] = offs - 16 + k;
}
return offs;
}
# | 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... |