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[]
) {
map<string,int>mp;
for(int i=0;i<n;i++){
int ind=0;
string s;
while(names[i][ind]){
s.pb(names[i][ind++]);
}
mp[s]=numbers[i];
}
int i=0;
for(auto&[s,num]:mp){
for(int j=0;j<16;j++){
outputs_alice[i++]=(num>>j)&1;
}
}
return i;
}
// Bob
int // returns lb
bob(
/* in */ const int m,
/* in */ const char senders[][5],
/* in */ const char recipients[][5],
/* out */ bool outputs_bob[]
) {
string send[m];
vector<string>st;
for(int i=0;i<m;i++){
int ind=0;
string s;
while(senders[i][ind]){
s.pb(senders[i][ind++]);
}
st.pb(s);
send[i]=s;
}
string rec[m];
for(int i=0;i<m;i++){
int ind=0;
string s;
while(recipients[i][ind]){
s.pb(recipients[i][ind++]);
}
st.pb(s);
rec[i]=s;
}
sort(st.begin(),st.end());
int n=unique(st.begin(),st.end())-st.begin();
for(int i=0;i<n*n;i++){
outputs_bob[i]=0;
}
unordered_map<string,int>mp;
for(int i=0;i<n;i++){
mp[st[i]]=i;
}
for(int i=0;i<m;i++){
outputs_bob[ mp[rec[i]]*n + mp[send[i]] ]=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]
) {
const int n=la/16;
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=[&](vector<int>&x,vector<int>&y) -> vector<int> {
vector<int>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.pb(cur);
past=nextt;
}
return result;
};
auto createzeronum = [&]() -> vector<int> {
vector<int>result;
for(int i=0;i<16;i++){
result.pb(pushgate(0,0,OP_ZERO));
}
return result;
};
auto check = [&](vector<int>target, int g) -> vector<int> {
vector<int>result;
for(int i=0;i<16;i++){
result.pb(pushgate(target[i],g,OP_AND));
}
return result;
};
vector<int>alicenums[n];
for(int i=0;i<la;i++){
alicenums[i/16].pb(i);
}
vector<vector<int>>ans;
for(int i=0;i<n;i++){
ans.pb(createzeronum());
for(int j=0;j<n;j++){
vector<int>cpy=check(alicenums[j],la+ i*n + j );
ans.back()=sumgate(cpy,ans.back());
}
}
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... |