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;
#define pb push_back
// 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 outputs_alice[]
) {
int ind=0;
for(int i=0;i<n;i++){
int val=0;
int subind=0;
while(names[i][subind]){
val*=26;
val+=names[i][subind]-'a';
subind++;
}
for(int j=0;j<20;j++){
outputs_alice[ind++]=(val>>j)&1;
}
for(int j=0;j<16;j++){
outputs_alice[ind++]=(numbers[i]>>j)&1;
}
}
return ind;
}
// Bob
int // returns lb
bob(
/* in */ const int m,
/* in */ const char senders[][5],
/* in */ const char recipients[][5],
/* out */ bool outputs_bob[]
) {
int ind=0;
for(int i=0;i<m;i++){
int val=0;
int subind=0;
while(senders[i][subind]){
val*=26;
val+=senders[i][subind]-'a';
subind++;
}
for(int j=0;j<20;j++){
outputs_bob[ind++]=(val>>j)&1;
}
val=0;
subind=0;
while(recipients[i][subind]){
val*=26;
val+=recipients[i][subind]-'a';
subind++;
}
for(int j=0;j<20;j++){
outputs_bob[ind++]=(val>>j)&1;
}
}
return ind;
}
using str=array<int,20>;
using lint=array<int,16>;
// 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]
) {
const int n=la/36,m=lb/40;
int nextindex=la+lb;
auto pushgate=[&](int g1,int g2,int op) -> int {
operations[nextindex]=op;
operands[nextindex][0]=g1;
operands[nextindex][1]=g2;
return nextindex++;
};
auto sumgate=[&](lint&x,lint&y) -> lint {
lint result;
int past=-1;
for(int i=0;i<16;i++){
int cur=pushgate(x[i],y[i],OP_XOR);
int nextt=pushgate(x[i],y[i],OP_AND);
if(i){
int nexttt=pushgate(cur,past,OP_AND);
nextt=pushgate(nextt,nexttt,OP_OR);
cur=pushgate(cur,past,OP_XOR);
}
result[i]=cur;
past=nextt;
}
return result;
};
auto createzeronum = [&]() -> lint {
lint result;
result[0]=pushgate(0,0,OP_ZERO);
for(int i=1;i<16;i++){
result[i]=result[0];
}
return result;
};
auto check = [&](lint&target, int g) -> lint {
lint result;
for(int i=0;i<16;i++){
result[i]=pushgate(target[i],g,OP_AND);
}
return result;
};
auto compare=[&](str&g1,str&g2)->int {
int result=pushgate(g1[0],g2[0],OP_XOR);
for(int i=1;i<20;i++){
int cur=pushgate(g1[i],g2[i],OP_XOR);
result=pushgate(result,cur,OP_OR);
}
return pushgate(result,0,OP_NOT_X0);
};
auto orgate=[&](lint&g1,lint&g2)->lint {
lint result;
for(int i=0;i<16;i++){
result[i]=pushgate(g1[i],g2[i],OP_OR);
}
return result;
};
int last=0;
str names[n];
lint nums[n];
for(int i=0;i<n;i++){
for(int j=0;j<20;j++){
names[i][j]=last++;
}
for(int j=0;j<16;j++){
nums[i][j]=last++;
}
}
str from[m],to[m];
for(int i=0;i<m;i++){
for(int j=0;j<20;j++){
from[i][j]=last++;
}
for(int j=0;j<20;j++){
to[i][j]=last++;
}
}
lint allzeros=createzeronum();
lint canget[m];
for(int i=0;i<m;i++){
canget[i]=allzeros;
for(int j=0;j<n;j++){
lint toad=nums[j];
int cmp=compare(from[i],names[j]);
toad=check(toad,cmp);
canget[i]=orgate(canget[i],toad);
}
}
lint ans[n];
for(int i=0;i<n;i++){
ans[i]=allzeros;
for(int j=0;j<m;j++){
lint toad=canget[j];
int cmp=compare(to[j],names[i]);
toad=check(toad,cmp);
ans[i]=sumgate(ans[i],toad);
}
}
for(int i=0;i<n;i++){
for(int j=0;j<16;j++){
outputs_circuit[i][j]=ans[i][j];
}
}
return nextindex;
}
# | 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... |