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>
#include "abc.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 encode(string s) {
int res = 0;
for (auto c: s) {
res = res * 26 + (c - 'a');
}
int pw = 1;
for (int i = 1; i <= (int)s.size() - 1; i++) {
pw = pw * 26;
res += pw;
}
return res;
}
// Alice
int // returns la
alice(
/* in */ const int n,
/* in */ const char names[][5],
/* in */ const unsigned short numbers[],
/* out */ bool outputs_alice[]
) {
vector<pair<int, int>> order(n);
for (int i = 0; i < n; i++) {
order[i] = make_pair(encode(names[i]), i);
}
sort(order.begin(), order.end());
for (int i = 0; i < n; i++) {
for (int j = 0; j < 19; j++) {
outputs_alice[i * 35 + j] = (order[i].first >> j) & 1;
}
for (int j = 0; j < 16; j++) {
outputs_alice[i * 35 + 19 + j] = (numbers[order[i].second] >> j) & 1;
}
}
return n * 35;
}
// Bob
int // returns lb
bob(
/* in */ const int m,
/* in */ const char senders[][5],
/* in */ const char recipients[][5],
/* out */ bool outputs_bob[]
) {
vector<int> names(m * 2);
for (int i = 0; i < m; i++) {
names[i * 2] = encode(senders[i]);
names[i * 2 + 1] = encode(recipients[i]);
}
sort(names.begin(), names.end());
names.erase(unique(names.begin(), names.end()), names.end());
int n = names.size();
for (int i = 0; i < n * n; i++) {
outputs_bob[i] = 0;
}
for (int i = 0; i < m; i++) {
int x = lower_bound(names.begin(), names.end(), encode(senders[i])) - names.begin();
int y = lower_bound(names.begin(), names.end(), encode(recipients[i])) - names.begin();
outputs_bob[y * n + x] = 1;
}
return n * n;
}
int *operations;
int (*operands)[2];
int ZERO_GATE;
int ONE_GATE;
int gate_cnt;
int gate(int op, int x, int y) {
operations[gate_cnt] = op;
operands[gate_cnt][0] = x;
operands[gate_cnt][1] = y;
return gate_cnt++;
}
pair<int, int> add(int x, int y, int z) {
int sum1 = gate(OP_XOR, x, y);
int rem1 = gate(OP_AND, x, y);
int sum2 = gate(OP_XOR, sum1, z);
int rem2 = gate(OP_AND, sum1, z);
return make_pair(sum2, gate(OP_OR, rem1, rem2));
}
vector<int> add(vector<int> num1, vector<int> num2) {
vector<int> res(16);
int rem = ZERO_GATE;
for (int i = 0; i < 16; i++) {
auto p = add(num1[i], num2[i], rem);
res[i] = p.first;
rem = p.second;
}
return res;
}
vector<int> mul(vector<int> num, int x) {
vector<int> res(16);
for (int i = 0; i < 16; i++) {
res[i] = gate(OP_AND, num[i], x);
}
return res;
}
// 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]
) {
operations = _operations;
operands = _operands;
gate_cnt = la + lb;
ZERO_GATE = gate(OP_ZERO, 0, 0);
ONE_GATE = gate(OP_ONE, 0, 0);
int n = la / 35;
vector<vector<int>> nums(n, vector<int>(16));
for (int i = 0; i < n; i++) {
for (int j = 0; j < 16; j++) {
nums[i][j] = i * 35 + 19 + j;
}
}
for (int i = 0; i < n; i++) {
vector<int> res(16, ZERO_GATE);
for (int j = 0; j < n; j++) {
res = add(res, mul(nums[j], la + i * n + j));
}
for (int j = 0; j < 16; j++) {
outputs_circuit[i][j] = res[j];
}
}
return gate_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... |