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"
// 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
using namespace std;
#include <vector>
#define vi vector<int>
#include <string>
#include <algorithm>
#include <map>
const int n = 26;
void mul(long long a, long long b,vi &ans) {
long long c = (a * b);
//c = c % (1 << 16);
for (int i = 0; i < 16; i++) {
ans[i] = (c % 2);
c /= 2;
}
}
// 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<string, int>> v;
vi num(n);
for (int i = 0; i < n; i++) {
string s;
for (char c : names[i])s.push_back(c);
v.push_back({ s,i });
}
for (int i = 0; i < 16 * n + n * n; i++)outputs_alice[i] = 0;
sort(v.begin(), v.end());
for (int i = 0; i < n ; i++) {
vi vec(16);
mul((long long)numbers[v[i].second], 1, vec);
for (int j = 0; j < 16; j++) {
outputs_alice[16 * i + j] = vec[j];
}
}
for (int i = 0; i < n; i++) {
outputs_alice[16 * n + n * v[i].second+i] = 1;
}
return 16*n + n*n;
}
#include <set>
#define ll long long
// Bob
int // returns lb
bob(
/* in */ const int m,
/* in */ const char senders[][5],
/* in */ const char recipients[][5],
/* out */ bool outputs_bob[]
) {
map<ll ,long long> ma1,ma2;
map<long long, ll>mapa;
for (int i = 0; i < m; i++) {
ll l1 = 0, l2=0,p=1;
for (int j = 0; j < 5; j++) {
l1 += p * senders[i][j];
l2 += p * recipients[i][j];
p *= 200;
}
mapa[l1] = 1, mapa[l2] = 1;
}
int it = 0;
for (pair<ll, ll> p: mapa) {
mapa[p.first] = it;
it++;
}
int n = mapa.size();
for (int i = 0; i < n*n; i++)outputs_bob[i] = 0;
for (int i = 0; i < m; i++) {
ll l1 = 0, l2 = 0, p = 1;
for (int j = 0; j < 5; j++) {
l1 += p * senders[i][j];
l2 += p * recipients[i][j];
p *= 200;
}
int in1 = mapa[l1], in2 = mapa[l2];
outputs_bob[n*in2 + in1] = 1;
}
return n*n;
}
// 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]
) {
// and = 8, xor= 6, or = 14,x1=12;
if (lb == 0) {
operands[17][0] = 0;
operands[17][1] = 0;
operations[17] = 0;
for (int k = 0; k < 16; k++)outputs_circuit[0][k] = 17;
return 18;
}
int n;
for (int i = 0; i < 40; i++)if (i * i == lb)n = i;
int last = la + lb;
vi l(n);
for (int i = 0; i < n; i++) {
for (int k = 0; k < 16; k++) {
operands[last + k][0] = 0;
operands[last + k][1] = 0;
operations[last + k] = 0;
}
last += 16;
for (int j = 0; j < n; j++) {
for (int k = last; k < last + 16; k++) {
operations[k] = OP_AND;
operands[k][0] = la+(n * i) + j;
operands[k][1] = 16 * j + (k-last);
}
// epsilon_i,j*a_i=operands[last,last+1,...last+15]
for (int k = 0; k < 16; k++) {
operations[last + 6*k+16] = OP_XOR;
operands[last + 6*k+16][0] = last-16+k;
operands[last + 6*k + 16][1] = last + k;
if (k>0)operations[last + 6 * k + 17] = OP_XOR; else operations[last + 6 * k + 17] = OP_X0;
operands[last + 6 * k + 17][0] = last + 16 + (6 * k);
operands[last + 6 * k + 17][1] = last + 6 * k + 15;
operations[last + 6 * k + 18] = OP_OR;
operands[last + 6 * k + 18][0] = last-16+k;
operands[last + 6 * k + 18][1] = last + k;
if (k)operations[last + 6 * k + 19] = OP_AND; else operations[last + 6 * k + 19] = 0;
operands[last + 6 * k + 19][0] = last + 6 * k + 18;
operands[last + 6 * k + 19][1] = last + 6 * k + 15;
operations[last + 6 * k + 20] = OP_AND;
operands[last + 6 * k + 20][0] = last -16+k;
operands[last + 6 * k + 20][1] = last + k;
operations[last + 6 * k + 21] = OP_OR;
operands[last + 6 * k + 21][0] = last + 6 * k + 20;
operands[last + 6 * k + 21][1] = last + 6 * k + 19;
}
l[i] = last + 112;
for (int k = last + 112; k < last + 112+16; k++) {
operations[k] = OP_X1;
operands[k][0] = 0;
operands[k][1] = 6*(k - last - 112) + last + 17;
}
last += 128;
}
for (int k = 0; k < 16; k++) {
//outputs_circuit[i][k] = last-16 + k;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int k = 0; k < 16; k++) {
operands[last + 16 * j + k][0] = 16 * n + n * i + j;
operands[last + 16 * j + k][1] = l[j] + k;
operations[last + 16 * j + k] = OP_AND;
}
}
for (int j = 0; j < n; j++) {
for (int k = 0; k < 16; k++) {
operands[16 * n + last + 16 * j + k][0] = last + 16 * j + k;
operands[16 * n+last + 16 * j + k][1] = 16 * n + last + 16 * j + k - 16;
if (j > 0)operations[16 * n + last + 16 * j + k] = OP_OR; else operations[16 * n + last + 16 * j + k] = OP_X0;
}
}
last += 32 * n;
for (int k = 0; k < 16; k++)outputs_circuit[i][k] = last - 16 + k;
}
return last;
}
Compilation message (stderr)
abc.cpp: In function 'int circuit(int, int, int*, int (*)[2], int (*)[16])':
abc.cpp:194:27: warning: 'n' may be used uninitialized in this function [-Wmaybe-uninitialized]
194 | for (int j = 0; j < n; j++) {
| ~~^~~
# | 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... |