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;
using ll = long long;
// 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
// Alice
int // returns la
alice(
/* in */ const int n,
/* in */ const char names[][5],
/* in */ const unsigned short numbers[],
/* out */ bool oa[]
) {
int i = 0;
vector < pair < string, pair < int, int > > > a (n);
for (int i = 0; i < n; ++i)
a[i].first = names[i], a[i].second.first = numbers[i], a[i].second.second = i;
sort (a.begin (), a.end ());
vector < int > od (n);
for (int j = 0; j < n; ++j)
{
od[a[j].second.second] = j;
for (int k = 0; k < 16; ++k)
oa[i++] = (a[j].second.first >> k) & 1;
}
for (int j = 0; j < n; ++j)
for (int k = 0; k < n; ++k)
oa[i++] = od[j] == k;
return i;
}
// Bob
int // returns lb
bob(
/* in */ const int m,
/* in */ const char s[][5],
/* in */ const char r[][5],
/* out */ bool oa[]
) {
map < string, int > mp;
for (int i = 0; i < m; ++i)
mp[s[i]] = mp[r[i]] = 0;
{
int i = 0;
for (auto &x : mp) x.second = i++;
}
for (int i = 0; i < mp.size () * mp.size (); ++i) oa[i] = false;
for (int i = 0; i < m; ++i)
oa[mp[r[i]] * mp.size () + mp[s[i]]] = true;
return mp.size () * mp.size ();
}
// Circuit
int // returns l
circuit(
/* in */ const int la,
/* in */ const int lb,
/* out */ int op[],
/* out */ int arg[][2],
/* out */ int oc[][16]
) {
int i = la + lb;
auto add = [&] (int a, int b)
{
// calc shit carries
int xori[16];
xori[0] = i;
arg[i][0] = a, arg[i][1] = b, op[i++] = OP_AND;
for (int j = 1; j < 15; ++j)
{
arg[i][0] = i - 1, arg[i][1] = a + j, op[i++] = OP_AND;
arg[i][0] = i - 2, arg[i][1] = b + j, op[i++] = OP_AND;
arg[i][0] = b + j, arg[i][1] = a + j, op[i++] = OP_AND;
arg[i][0] = i - 1, arg[i][1] = i - 2, op[i++] = OP_OR;
xori[j] = i;
arg[i][0] = i - 1, arg[i][1] = i - 4, op[i++] = OP_OR;
}
// add shits
for (int j = 15; j >= 0; --j)
arg[i][0] = a + j, arg[i][1] = b + j, op[i++] = OP_XOR;
// add shit carries to shits
for (int j = 1; j < 16; ++j)
arg[i][0] = i - j * 2, arg[i][1] = xori[j - 1], op[i++] = OP_XOR;
return i - 16;
};
auto nif = [&] (int c, int a)
{
for (int j = 0; j < 16; ++j)
arg[i][0] = c, arg[i][1] = a + j, op[i++] = OP_AND;
return i - 16;
};
auto or16 = [&] (int a, int b)
{
for (int j = 0; j < 16; ++j)
arg[i][0] = a + j, arg[i][1] = b + j, op[i++] = OP_OR;
return i - 16;
};
int n = la / 17, m = lb / n;
vector < int > aa (n);
for (int j = 0; j < n; ++j)
{
int p = nif (la + j * n, 0);
for (int k = 1; k < n; ++k)
p = add (p, nif (la + j * n + k, k * 16));
aa[j] = p;
}
for (int j = 0; j < n; ++j)
{
int p = nif (n * 16 + j * n, aa[0]);
for (int k = 1; k < n; ++k)
p = or16 (p, nif (n * 16 + j * n + k, aa[k]));
for (int k = 0; k < 16; ++k) oc[j][k] = p + k;
}
return i;
}
Compilation message (stderr)
abc.cpp: In function 'int bob(int, const char (*)[5], const char (*)[5], bool*)':
abc.cpp:67:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::map<std::__cxx11::basic_string<char>, int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for (int i = 0; i < mp.size () * mp.size (); ++i) oa[i] = false;
| ~~^~~~~~~~~~~~~~~~~~~~~~~~~
abc.cpp: In function 'int circuit(int, int, int*, int (*)[2], int (*)[16])':
abc.cpp:118:20: warning: unused variable 'm' [-Wunused-variable]
118 | int n = la / 17, m = lb / n;
| ^
# | 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... |