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
#include<bits/stdc++.h>
using namespace std;
#define pi pair<int,int>
#define x first
#define y second
int rt(int n){
int i=0; while(i*i < n)i++;
return i;
}
void write_num(bool * p, int num, int len){
for(int i=0;i<len;i++){
p[i] = num&1;
num>>=1;
}
}
// Alice
int // returns la
alice(
/* in */ const int n,
/* in */ const char names[][5],
/* in */ const unsigned short numbers[],
/* out */ bool outputs_alice[]
) {
map<string,int> mp;
for(int i=0;i<n;i++){
mp[names[i]]=0;
}
int z=0; for(auto it : mp) mp[it.x] = z++;
//outputs_alice[0] = 0;
for(int i=0;i<n;i++) write_num(outputs_alice+16*i, numbers[i],16);
outputs_alice+=16*n;
for(int i=0;i<n;i++) write_num(outputs_alice+5*i, mp[names[i]],5);
//outputs_alice[1] = 0;
return 21*n;
}
// Bob
int // returns lb
bob(
/* in */ const int m,
/* in */ const char senders[][5],
/* in */ const char recipients[][5],
/* out */ bool outputs_bob[]
) {
map<string,int> mp;
for(int i=0;i<m;i++){
string s = senders[i]; mp[s]=0;
s=recipients[i]; mp[s]=0;
}
int z=0; for(auto it : mp) mp[it.x] = z++;
int n=z;
vector<vector<bool>> v(n,vector<bool>(n,0));
for(int i=0;i<m;i++){
v[mp[senders[i]]][mp[recipients[i]]]=1;
}
for(int i=0;i<n*n;i++){
outputs_bob[i]=v[i/n][i%n];
}
return n*n;
}
int * gate_op;
//auto gate_opnds;
int e;
pi ha(int a, int b,int gate_opnds[][2]){
int s = e;
gate_op[e]=OP_XOR; gate_opnds[e][0]=a; gate_opnds[e][1]=b; e++;
int c = e;
gate_op[e]=OP_AND; gate_opnds[e][0]=a; gate_opnds[e][1]=b; e++;
return {s,c};
}
pi fa(int a, int b, int c,int gate_opnds[][2]){
gate_op[e]=OP_XOR; gate_opnds[e][0]=a; gate_opnds[e][1]=b; e++;
int s=e;
gate_op[e]=OP_XOR; gate_opnds[e][0]=e-1; gate_opnds[e][1]=c; e++;
gate_op[e]=OP_AND; gate_opnds[e][0]=a; gate_opnds[e][1]=b; e++;
gate_op[e]=OP_AND; gate_opnds[e][0]=e-3; gate_opnds[e][1]=c; e++;
int ca = e;
gate_op[e]=OP_OR; gate_opnds[e][0]=e-1; gate_opnds[e][1]=e-2; e++;
return {s,ca};
}
vector<int> add(vector<int> a, vector<int> b, int op[][2]){
vector<int> c(16);
pi p = ha(a[0],b[0],op);
c[0]=p.x;
int u=p.y;
for(int i=1;i<16;i++){
p = fa(a[i],b[i],u,op);
c[i]=p.x;
u=p.y;
}
return c;
}
vector<int> do_all(vector<int> a, vector<int> b, int op[][2], int operat, int len){
vector<int> c(len);
for(int i=0;i<len;i++){
c[i]=e;
gate_op[e]=operat; op[e][0]=a[i]; op[e][1]=b[i]; e++;
}
return c;
}
int reduce(vector<int> a, int op[][2], int operat,int len){
int r = a[0];
for(int i=1;i<len;i++){
gate_op[e]=operat; op[e][0]=a[i]; op[e][1]=r; r=e; e++;
}
return r;
}
// 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]
) {
//auto gate_opnds=operands;
gate_op=operations;
e = la+lb;
int zero=e;
operations[e]=0; operands[e][0]=operands[e][1]=0; e++;
int one=e;
operations[e]=15; operands[e][0]=operands[e][1]=0; e++;
int n = la/21, z=16*n;
vector<vector<int>> sn(n);
for(int i=0;i<n;i++){
vector<int> cur(16,zero);
vector<int> nmi(5); for(int k=0;k<5;k++) nmi[k]=z+5*i+k;
for(int j=0;j<n;j++){
vector<int> nmj(5);for(int k=0;k<5;k++) nmj[k]=(j&(1<<k)) ? one : zero;
vector<int> same = do_all(nmi,nmj,operands,OP_EQUAL,5);
int sa = reduce(same,operands,OP_AND,5);
vector<int> mul(16,sa);
vector<int> numj(16); for(int u=0;u<16;u++) numj[u]=16*j+u;
vector<int> to_add = do_all(mul,numj,operands,OP_AND,16);
cur = add(cur,to_add,operands);
}
sn[i]=cur;
}
vector<vector<int>> curs(n);
for(int i=0;i<n;i++){
vector<int> cur(16,zero);
for(int j=0;j<n;j++){
vector<int> mul(16,la + n*j+i);
//vector<int> numj(16); for(int u=0;u<16;u++) numj[u]=16*j+u;
vector<int> numj = sn[j];
vector<int> to_add = do_all(mul, numj, operands,OP_AND,16);
cur = add(cur,to_add,operands);
}
curs[i]=cur;
}
for(int i=0;i<n;i++){
vector<int> cur(16,zero);
vector<int> nmi(5); for(int k=0;k<5;k++) nmi[k]=z+5*i+k;
for(int j=0;j<n;j++){
vector<int> nmj(5);for(int k=0;k<5;k++) nmj[k]=(j&(1<<k)) ? one : zero;
vector<int> same = do_all(nmi,nmj,operands,OP_EQUAL,5);
int sa = reduce(same,operands,OP_AND,5);
vector<int> mul(16,sa);
vector<int> to_add = do_all(mul,curs[j],operands,OP_AND,16);
cur = add(cur,to_add,operands);
}
for(int j=0;j<16;j++) outputs_circuit[i][j] = cur[j];
}
return e;
}
# | 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... |